From 123b55e9ced5e34cef47628ef8047e2aaa7bbf13 Mon Sep 17 00:00:00 2001 From: Doug Rabson Date: Sun, 24 Apr 2022 14:12:01 +0100 Subject: [PATCH 1/2] Use MNT_FORCE as an approximate equivalent to MNT_DETACH Also, we don't need to truncate the path name for zfs mount points. FreeBSD versions prior to 12.0 had a limitation of 88 characters for mount points but this has been increased to 1024. Signed-off-by: Doug Rabson --- drivers/zfs/zfs_freebsd.go | 16 +++------------- pkg/mount/flags_freebsd.go | 3 ++- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/zfs/zfs_freebsd.go b/drivers/zfs/zfs_freebsd.go index fd98ad305c..61a2ed871a 100644 --- a/drivers/zfs/zfs_freebsd.go +++ b/drivers/zfs/zfs_freebsd.go @@ -2,7 +2,6 @@ package zfs import ( "fmt" - "strings" "github.com/containers/storage/drivers" "github.com/pkg/errors" @@ -26,19 +25,10 @@ func checkRootdirFs(rootdir string) error { } func getMountpoint(id string) string { - maxlen := 12 - - // we need to preserve filesystem suffix - suffix := strings.SplitN(id, "-", 2) - - if len(suffix) > 1 { - return id[:maxlen] + "-" + suffix[1] - } - - return id[:maxlen] + return id } func detachUnmount(mountpoint string) error { - // FreeBSD doesn't have an equivalent to MNT_DETACH - return unix.Unmount(mountpoint, 0) + // FreeBSD's MNT_FORCE is roughly equivalent to MNT_DETACH + return unix.Unmount(mountpoint, unix.MNT_FORCE) } diff --git a/pkg/mount/flags_freebsd.go b/pkg/mount/flags_freebsd.go index 630d313dcd..3ba99cf935 100644 --- a/pkg/mount/flags_freebsd.go +++ b/pkg/mount/flags_freebsd.go @@ -27,6 +27,8 @@ const ( // NOATIME will not update the file access time when reading from a file. NOATIME = unix.MNT_NOATIME + mntDetach = unix.MNT_FORCE + NODIRATIME = 0 NODEV = 0 DIRSYNC = 0 @@ -43,5 +45,4 @@ const ( RSHARED = 0 RELATIME = 0 STRICTATIME = 0 - mntDetach = 0 ) From fa5a456f8a691b670a87e4023ee832b42c03d9a6 Mon Sep 17 00:00:00 2001 From: Doug Rabson Date: Wed, 27 Apr 2022 14:58:46 +0100 Subject: [PATCH 2/2] Parse key=value pairs from data and pass through to nmount Signed-off-by: Doug Rabson --- pkg/mount/mounter_freebsd.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pkg/mount/mounter_freebsd.go b/pkg/mount/mounter_freebsd.go index b31cf99d0f..72ceec3dda 100644 --- a/pkg/mount/mounter_freebsd.go +++ b/pkg/mount/mounter_freebsd.go @@ -28,14 +28,25 @@ func allocateIOVecs(options []string) []C.struct_iovec { func mount(device, target, mType string, flag uintptr, data string) error { isNullFS := false - xs := strings.Split(data, ",") - for _, x := range xs { - if x == "bind" { - isNullFS = true + options := []string{"fspath", target} + + if data != "" { + xs := strings.Split(data, ",") + for _, x := range xs { + if x == "bind" { + isNullFS = true + continue + } + opt := strings.SplitN(x, "=", 2) + options = append(options, opt[0]) + if len(opt) == 2 { + options = append(options, opt[1]) + } else { + options = append(options, "") + } } } - options := []string{"fspath", target} if isNullFS { options = append(options, "fstype", "nullfs", "target", device) } else {