driver_solaris.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/docker/docker/pkg/mount"
  19. "github.com/sirupsen/logrus"
  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 provided 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. defer C.free(unsafe.Pointer(cs))
  69. buf := C.getstatfs(cs)
  70. defer C.free(unsafe.Pointer(buf))
  71. // on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
  72. if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) ||
  73. (buf.f_basetype[3] != 0) {
  74. logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath)
  75. return false, ErrPrerequisites
  76. }
  77. return true, nil
  78. }