Browse Source

Make `weed-fuse` compatible with systemd-based mount (#6814)

* Make weed-fuse compatible with systemd-mount series

* fix: add missing type annotation on skipAutofs param in FreeBSD build

The parameter was declared without a type, causing a compile error on FreeBSD.

* fix: guard hasAutofs nil dereference and make FsName conditional on autofs mode

- Check option.hasAutofs for nil before dereferencing to prevent panic
  when RunMount is called without the flag initialized.
- Only set FsName to "fuse" when autofs mode is active; otherwise
  preserve the descriptive server:path name for mount/df output.
- Fix typo: recogize -> recognize.

* fix: consistent error handling for autofs option and log ignored _netdev

- Replace panic with fmt.Fprintf+return false for autofs parse errors,
  matching the pattern used by other fuse option parsers.
- Log when _netdev option is silently stripped to aid debugging.

---------

Co-authored-by: Chris Lu <chris.lu@gmail.com>
pull/8685/head
Weihao Jiang 10 hours ago
committed by GitHub
parent
commit
01987bcafd
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 14
      weed/command/fuse_std.go
  2. 6
      weed/command/mount.go
  3. 2
      weed/command/mount_darwin.go
  4. 2
      weed/command/mount_freebsd.go
  5. 10
      weed/command/mount_linux.go
  6. 12
      weed/command/mount_std.go

14
weed/command/fuse_std.go

@ -12,6 +12,7 @@ import (
"syscall"
"time"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/util"
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
)
@ -267,6 +268,19 @@ func runFuse(cmd *Command, args []string) bool {
fmt.Fprintf(os.Stderr, "failed to parse 'sys.novncache' value %q: %v\n", parameter.value, err)
return false
}
case "autofs":
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
mountOptions.hasAutofs = &parsed
} else {
fmt.Fprintf(os.Stderr, "failed to parse 'autofs' value %q: %v\n", parameter.value, err)
return false
}
case "_netdev":
// _netdev is used for systemd/fstab parser to signify that this is a network mount but systemd
// mount sometimes can't strip them off. Meanwhile, fuse3 would refuse to run with _netdev, we
// strip them here if it fails to be stripped by the caller.
//(See https://github.com/seaweedfs/seaweedfs/wiki/fstab/948a70df5c0d9d2d27561b96de53bde07a29d2db)
glog.V(0).Infof("ignoring _netdev mount option")
default:
t := parameter.name
if parameter.value != "true" {

6
weed/command/mount.go

@ -58,6 +58,11 @@ type MountOptions struct {
// macOS-specific FUSE options
novncache *bool
// if true, we assume autofs exists over current mount point. Autofs (the kernel one, used by systemd automount)
// is expected to be mounted as a shim between auto-mounted fs and original mount point to provide auto mount.
// with this option, we ignore autofs mounted on the same point.
hasAutofs *bool
}
var (
@ -98,6 +103,7 @@ func init() {
mountOptions.debugPort = cmdMount.Flag.Int("debug.port", 6061, "http port for debugging")
mountOptions.localSocket = cmdMount.Flag.String("localSocket", "", "default to /tmp/seaweedfs-mount-<mount_dir_hash>.sock")
mountOptions.disableXAttr = cmdMount.Flag.Bool("disableXAttr", false, "disable xattr")
mountOptions.hasAutofs = cmdMount.Flag.Bool("autofs", false, "ignore autofs mounted on the same mountpoint (useful when systemd.automount and autofs is used)")
mountOptions.fuseCommandPid = 0
// Periodic metadata flush to protect against orphan chunk cleanup

2
weed/command/mount_darwin.go

@ -1,5 +1,5 @@
package command
func checkMountPointAvailable(dir string) bool {
func checkMountPointAvailable(dir string, skipAutofs bool) bool {
return true
}

2
weed/command/mount_freebsd.go

@ -1,5 +1,5 @@
package command
func checkMountPointAvailable(dir string) bool {
func checkMountPointAvailable(dir string, skipAutofs bool) bool {
return true
}

10
weed/command/mount_linux.go

@ -69,7 +69,7 @@ type Info struct {
// Mounted determines if a specified mountpoint has been mounted.
// On Linux it looks at /proc/self/mountinfo and on Solaris at mnttab.
func mounted(mountPoint string) (bool, error) {
func mounted(mountPoint string, skipAutofs bool) (bool, error) {
entries, err := parseMountTable()
if err != nil {
return false, err
@ -78,6 +78,10 @@ func mounted(mountPoint string) (bool, error) {
// Search the table for the mountPoint
for _, e := range entries {
if e.Mountpoint == mountPoint {
// Check if the mountpoint is autofs
if skipAutofs && e.Fstype == "autofs" {
continue
}
return true, nil
}
}
@ -137,13 +141,13 @@ func parseInfoFile(r io.Reader) ([]*Info, error) {
return out, nil
}
func checkMountPointAvailable(dir string) bool {
func checkMountPointAvailable(dir string, skipAutofs bool) bool {
mountPoint := dir
if mountPoint != "/" && strings.HasSuffix(mountPoint, "/") {
mountPoint = mountPoint[0 : len(mountPoint)-1]
}
if mounted, err := mounted(mountPoint); err != nil || mounted {
if mounted, err := mounted(mountPoint, skipAutofs); err != nil || mounted {
if err != nil {
glog.Errorf("check %s: %v", mountPoint, err)
}

12
weed/command/mount_std.go

@ -223,13 +223,21 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
}
// Ensure target mount point availability
if isValid := checkMountPointAvailable(dir); !isValid {
skipAutofs := option.hasAutofs != nil && *option.hasAutofs
if isValid := checkMountPointAvailable(dir, skipAutofs); !isValid {
glog.Fatalf("Target mount point is not available: %s, please check!", dir)
return true
}
serverFriendlyName := strings.ReplaceAll(*option.filer, ",", "+")
// When autofs/systemd-mount is used, FsName must be "fuse" so util-linux/mount can recognize
// it as a pseudo filesystem. Otherwise, preserve the descriptive name for mount/df output.
fsName := serverFriendlyName + ":" + filerMountRootPath
if skipAutofs {
fsName = "fuse"
}
// mount fuse
fuseMountOptions := &fuse.MountOptions{
AllowOther: *option.allowOthers,
@ -239,7 +247,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
MaxReadAhead: 1024 * 1024 * 2,
IgnoreSecurityLabels: false,
RememberInodes: false,
FsName: serverFriendlyName + ":" + filerMountRootPath,
FsName: fsName,
Name: "seaweedfs",
SingleThreaded: false,
DisableXAttrs: *option.disableXAttr,

Loading…
Cancel
Save