zfs_solaris.go 1.3 KB

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