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>
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||||
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
|
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)
|
fmt.Fprintf(os.Stderr, "failed to parse 'sys.novncache' value %q: %v\n", parameter.value, err)
|
||||||
return false
|
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:
|
default:
|
||||||
t := parameter.name
|
t := parameter.name
|
||||||
if parameter.value != "true" {
|
if parameter.value != "true" {
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ type MountOptions struct {
|
|||||||
|
|
||||||
// macOS-specific FUSE options
|
// macOS-specific FUSE options
|
||||||
novncache *bool
|
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 (
|
var (
|
||||||
@@ -98,6 +103,7 @@ func init() {
|
|||||||
mountOptions.debugPort = cmdMount.Flag.Int("debug.port", 6061, "http port for debugging")
|
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.localSocket = cmdMount.Flag.String("localSocket", "", "default to /tmp/seaweedfs-mount-<mount_dir_hash>.sock")
|
||||||
mountOptions.disableXAttr = cmdMount.Flag.Bool("disableXAttr", false, "disable xattr")
|
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
|
mountOptions.fuseCommandPid = 0
|
||||||
|
|
||||||
// Periodic metadata flush to protect against orphan chunk cleanup
|
// Periodic metadata flush to protect against orphan chunk cleanup
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
func checkMountPointAvailable(dir string) bool {
|
func checkMountPointAvailable(dir string, skipAutofs bool) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
func checkMountPointAvailable(dir string) bool {
|
func checkMountPointAvailable(dir string, skipAutofs bool) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ type Info struct {
|
|||||||
|
|
||||||
// Mounted determines if a specified mountpoint has been mounted.
|
// Mounted determines if a specified mountpoint has been mounted.
|
||||||
// On Linux it looks at /proc/self/mountinfo and on Solaris at mnttab.
|
// 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()
|
entries, err := parseMountTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -78,6 +78,10 @@ func mounted(mountPoint string) (bool, error) {
|
|||||||
// Search the table for the mountPoint
|
// Search the table for the mountPoint
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
if e.Mountpoint == mountPoint {
|
if e.Mountpoint == mountPoint {
|
||||||
|
// Check if the mountpoint is autofs
|
||||||
|
if skipAutofs && e.Fstype == "autofs" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,13 +141,13 @@ func parseInfoFile(r io.Reader) ([]*Info, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkMountPointAvailable(dir string) bool {
|
func checkMountPointAvailable(dir string, skipAutofs bool) bool {
|
||||||
mountPoint := dir
|
mountPoint := dir
|
||||||
if mountPoint != "/" && strings.HasSuffix(mountPoint, "/") {
|
if mountPoint != "/" && strings.HasSuffix(mountPoint, "/") {
|
||||||
mountPoint = mountPoint[0 : len(mountPoint)-1]
|
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 {
|
if err != nil {
|
||||||
glog.Errorf("check %s: %v", mountPoint, err)
|
glog.Errorf("check %s: %v", mountPoint, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,13 +223,21 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure target mount point availability
|
// 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)
|
glog.Fatalf("Target mount point is not available: %s, please check!", dir)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
serverFriendlyName := strings.ReplaceAll(*option.filer, ",", "+")
|
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
|
// mount fuse
|
||||||
fuseMountOptions := &fuse.MountOptions{
|
fuseMountOptions := &fuse.MountOptions{
|
||||||
AllowOther: *option.allowOthers,
|
AllowOther: *option.allowOthers,
|
||||||
@@ -239,7 +247,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
|||||||
MaxReadAhead: 1024 * 1024 * 2,
|
MaxReadAhead: 1024 * 1024 * 2,
|
||||||
IgnoreSecurityLabels: false,
|
IgnoreSecurityLabels: false,
|
||||||
RememberInodes: false,
|
RememberInodes: false,
|
||||||
FsName: serverFriendlyName + ":" + filerMountRootPath,
|
FsName: fsName,
|
||||||
Name: "seaweedfs",
|
Name: "seaweedfs",
|
||||||
SingleThreaded: false,
|
SingleThreaded: false,
|
||||||
DisableXAttrs: *option.disableXAttr,
|
DisableXAttrs: *option.disableXAttr,
|
||||||
|
|||||||
Reference in New Issue
Block a user