github.com/hms58/moby@v1.13.1/daemon/graphdriver/zfs/zfs_solaris.go (about)

     1  // +build solaris,cgo
     2  
     3  package zfs
     4  
     5  /*
     6  #include <sys/statvfs.h>
     7  #include <stdlib.h>
     8  
     9  static inline struct statvfs *getstatfs(char *s) {
    10          struct statvfs *buf;
    11          int err;
    12          buf = (struct statvfs *)malloc(sizeof(struct statvfs));
    13          err = statvfs(s, buf);
    14          return buf;
    15  }
    16  */
    17  import "C"
    18  import (
    19  	"path/filepath"
    20  	"strings"
    21  	"unsafe"
    22  
    23  	"github.com/Sirupsen/logrus"
    24  	"github.com/docker/docker/daemon/graphdriver"
    25  )
    26  
    27  func checkRootdirFs(rootdir string) error {
    28  
    29  	cs := C.CString(filepath.Dir(rootdir))
    30  	buf := C.getstatfs(cs)
    31  
    32  	// on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
    33  	if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) ||
    34  		(buf.f_basetype[3] != 0) {
    35  		logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir)
    36  		C.free(unsafe.Pointer(buf))
    37  		return graphdriver.ErrPrerequisites
    38  	}
    39  
    40  	C.free(unsafe.Pointer(buf))
    41  	C.free(unsafe.Pointer(cs))
    42  	return nil
    43  }
    44  
    45  /* rootfs is introduced to comply with the OCI spec
    46  which states that root filesystem must be mounted at <CID>/rootfs/ instead of <CID>/
    47  */
    48  func getMountpoint(id string) string {
    49  	maxlen := 12
    50  
    51  	// we need to preserve filesystem suffix
    52  	suffix := strings.SplitN(id, "-", 2)
    53  
    54  	if len(suffix) > 1 {
    55  		return filepath.Join(id[:maxlen]+"-"+suffix[1], "rootfs", "root")
    56  	}
    57  
    58  	return filepath.Join(id[:maxlen], "rootfs", "root")
    59  }