mount.go 679 B

123456789101112131415161718192021222324252627282930
  1. //go:build linux
  2. package overlay2 // import "github.com/docker/docker/daemon/graphdriver/overlay2"
  3. import (
  4. "runtime"
  5. "golang.org/x/sys/unix"
  6. )
  7. func mountFrom(dir, device, target, mType string, flags uintptr, label string) error {
  8. chErr := make(chan error, 1)
  9. go func() {
  10. runtime.LockOSThread()
  11. // Do not unlock this thread as the thread state cannot be restored
  12. // We do not want go to re-use this thread for anything else.
  13. if err := unix.Unshare(unix.CLONE_FS); err != nil {
  14. chErr <- err
  15. return
  16. }
  17. if err := unix.Chdir(dir); err != nil {
  18. chErr <- err
  19. return
  20. }
  21. chErr <- unix.Mount(device, target, mType, flags, label)
  22. }()
  23. return <-chErr
  24. }