zfs_solaris.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // +build solaris,cgo
  2. package zfs
  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. "strings"
  18. "unsafe"
  19. "github.com/docker/docker/daemon/graphdriver"
  20. "github.com/sirupsen/logrus"
  21. )
  22. func checkRootdirFs(rootdir string) error {
  23. cs := C.CString(filepath.Dir(rootdir))
  24. defer C.free(unsafe.Pointer(cs))
  25. buf := C.getstatfs(cs)
  26. defer C.free(unsafe.Pointer(buf))
  27. // on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
  28. if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) ||
  29. (buf.f_basetype[3] != 0) {
  30. logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir)
  31. return graphdriver.ErrPrerequisites
  32. }
  33. return nil
  34. }
  35. /* rootfs is introduced to comply with the OCI spec
  36. which states that root filesystem must be mounted at <CID>/rootfs/ instead of <CID>/
  37. */
  38. func getMountpoint(id string) string {
  39. maxlen := 12
  40. // we need to preserve filesystem suffix
  41. suffix := strings.SplitN(id, "-", 2)
  42. if len(suffix) > 1 {
  43. return filepath.Join(id[:maxlen]+"-"+suffix[1], "rootfs", "root")
  44. }
  45. return filepath.Join(id[:maxlen], "rootfs", "root")
  46. }