driver_solaris.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // +build solaris,cgo
  2. package graphdriver
  3. /*
  4. #include <sys/statvfs.h>
  5. #include <stdlib.h>
  6. static inline struct statvfs *getstatfs(char *s) {
  7. struct statvfs *buf;
  8. int err;
  9. buf = (struct statvfs *)malloc(sizeof(struct statvfs));
  10. err = statvfs(s, buf);
  11. return buf;
  12. }
  13. */
  14. import "C"
  15. import (
  16. "path/filepath"
  17. "unsafe"
  18. "github.com/Sirupsen/logrus"
  19. "github.com/docker/docker/pkg/mount"
  20. )
  21. const (
  22. // FsMagicZfs filesystem id for Zfs
  23. FsMagicZfs = FsMagic(0x2fc12fc1)
  24. )
  25. var (
  26. // Slice of drivers that should be used in an order
  27. priority = []string{
  28. "zfs",
  29. }
  30. // FsNames maps filesystem id to name of the filesystem.
  31. FsNames = map[FsMagic]string{
  32. FsMagicZfs: "zfs",
  33. }
  34. )
  35. // GetFSMagic returns the filesystem id given the path.
  36. func GetFSMagic(rootpath string) (FsMagic, error) {
  37. return 0, nil
  38. }
  39. type fsChecker struct {
  40. t FsMagic
  41. }
  42. func (c *fsChecker) IsMounted(path string) bool {
  43. m, _ := Mounted(c.t, path)
  44. return m
  45. }
  46. // NewFsChecker returns a checker configured for the provied FsMagic
  47. func NewFsChecker(t FsMagic) Checker {
  48. return &fsChecker{
  49. t: t,
  50. }
  51. }
  52. // NewDefaultChecker returns a check that parses /proc/mountinfo to check
  53. // if the specified path is mounted.
  54. // No-op on Solaris.
  55. func NewDefaultChecker() Checker {
  56. return &defaultChecker{}
  57. }
  58. type defaultChecker struct {
  59. }
  60. func (c *defaultChecker) IsMounted(path string) bool {
  61. m, _ := mount.Mounted(path)
  62. return m
  63. }
  64. // Mounted checks if the given path is mounted as the fs type
  65. //Solaris supports only ZFS for now
  66. func Mounted(fsType FsMagic, mountPath string) (bool, error) {
  67. cs := C.CString(filepath.Dir(mountPath))
  68. buf := C.getstatfs(cs)
  69. // on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
  70. if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) ||
  71. (buf.f_basetype[3] != 0) {
  72. logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath)
  73. C.free(unsafe.Pointer(buf))
  74. return false, ErrPrerequisites
  75. }
  76. C.free(unsafe.Pointer(buf))
  77. C.free(unsafe.Pointer(cs))
  78. return true, nil
  79. }