Skip to content

Commit

Permalink
Add support for bind-mounts on Darwin
Browse files Browse the repository at this point in the history
Signed-off-by: Marat Radchenko <[email protected]>
  • Loading branch information
slonopotamus committed Dec 14, 2024
1 parent 88aa2f5 commit 285061b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

// HasBindMounts This is a flag to conditionally disable code that relies on working bind-mount support, so such code is easier to find across codebase.
const HasBindMounts = runtime.GOOS != "darwin" && runtime.GOOS != "openbsd"
const HasBindMounts = runtime.GOOS != "openbsd"

// Mount is the lingua franca of containerd. A mount represents a
// serialized mount syscall. Components either emit or consume mounts.
Expand Down
34 changes: 32 additions & 2 deletions core/mount/mount_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,39 @@

package mount

import "github.com/containerd/errdefs"
import (
"fmt"
"os/exec"
)

// Mount to the provided target.
func (m *Mount) mount(target string) error {
return errdefs.ErrNotImplemented
var commandName string
if m.Type == "bind" {
// macOS doesn't natively support bindfs/nullfs
// The way to emulate it is via FUSE fs named "bindfs"
commandName = "bindfs"
} else {
commandName = fmt.Sprintf("mount_%s", m.Type)
}

var args []string
for _, option := range m.Options {
if option == "rbind" {
// On one side, rbind is not supported by macOS mounting tools
// On the other, bindfs works as if rbind is enabled anyway
continue
}

args = append(args, "-o", option)
}
args = append(args, m.Source, target)

cmd := exec.Command(commandName, args...)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("%s [%v] failed: %q: %w", commandName, args, string(output), err)
}

return nil
}

0 comments on commit 285061b

Please sign in to comment.