Skip to content

Commit

Permalink
Merge pull request #1219 from dfr/freebsd
Browse files Browse the repository at this point in the history
FreeBSD fixes for pkg/mount
  • Loading branch information
rhatdan committed Apr 27, 2022
2 parents a9c061d + fa5a456 commit 572ad81
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
16 changes: 3 additions & 13 deletions drivers/zfs/zfs_freebsd.go
Expand Up @@ -2,7 +2,6 @@ package zfs

import (
"fmt"
"strings"

"github.com/containers/storage/drivers"
"github.com/pkg/errors"
Expand All @@ -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)
}
3 changes: 2 additions & 1 deletion pkg/mount/flags_freebsd.go
Expand Up @@ -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
Expand All @@ -43,5 +45,4 @@ const (
RSHARED = 0
RELATIME = 0
STRICTATIME = 0
mntDetach = 0
)
21 changes: 16 additions & 5 deletions pkg/mount/mounter_freebsd.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 572ad81

Please sign in to comment.