gopkg.in/dotcloud/docker.v1@v1.13.1/daemon/graphdriver/driver_solaris.go (about)

     1  // +build solaris,cgo
     2  
     3  package graphdriver
     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  	"unsafe"
    21  
    22  	"github.com/Sirupsen/logrus"
    23  	"github.com/docker/docker/pkg/mount"
    24  )
    25  
    26  const (
    27  	// FsMagicZfs filesystem id for Zfs
    28  	FsMagicZfs = FsMagic(0x2fc12fc1)
    29  )
    30  
    31  var (
    32  	// Slice of drivers that should be used in an order
    33  	priority = []string{
    34  		"zfs",
    35  	}
    36  
    37  	// FsNames maps filesystem id to name of the filesystem.
    38  	FsNames = map[FsMagic]string{
    39  		FsMagicZfs: "zfs",
    40  	}
    41  )
    42  
    43  // GetFSMagic returns the filesystem id given the path.
    44  func GetFSMagic(rootpath string) (FsMagic, error) {
    45  	return 0, nil
    46  }
    47  
    48  type fsChecker struct {
    49  	t FsMagic
    50  }
    51  
    52  func (c *fsChecker) IsMounted(path string) bool {
    53  	m, _ := Mounted(c.t, path)
    54  	return m
    55  }
    56  
    57  // NewFsChecker returns a checker configured for the provied FsMagic
    58  func NewFsChecker(t FsMagic) Checker {
    59  	return &fsChecker{
    60  		t: t,
    61  	}
    62  }
    63  
    64  // NewDefaultChecker returns a check that parses /proc/mountinfo to check
    65  // if the specified path is mounted.
    66  // No-op on Solaris.
    67  func NewDefaultChecker() Checker {
    68  	return &defaultChecker{}
    69  }
    70  
    71  type defaultChecker struct {
    72  }
    73  
    74  func (c *defaultChecker) IsMounted(path string) bool {
    75  	m, _ := mount.Mounted(path)
    76  	return m
    77  }
    78  
    79  // Mounted checks if the given path is mounted as the fs type
    80  //Solaris supports only ZFS for now
    81  func Mounted(fsType FsMagic, mountPath string) (bool, error) {
    82  
    83  	cs := C.CString(filepath.Dir(mountPath))
    84  	buf := C.getstatfs(cs)
    85  
    86  	// on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
    87  	if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) ||
    88  		(buf.f_basetype[3] != 0) {
    89  		logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath)
    90  		C.free(unsafe.Pointer(buf))
    91  		return false, ErrPrerequisites
    92  	}
    93  
    94  	C.free(unsafe.Pointer(buf))
    95  	C.free(unsafe.Pointer(cs))
    96  	return true, nil
    97  }