FUSE mount: make "nonempty" optional

https://github.com/chrislusf/seaweedfs/issues/1094
This commit is contained in:
Chris Lu 2020-03-21 19:14:25 -07:00
parent 3b3e063f25
commit 7c111f7b75
3 changed files with 20 additions and 27 deletions

View file

@ -12,6 +12,7 @@ type MountOptions struct {
dataCenter *string dataCenter *string
allowOthers *bool allowOthers *bool
umaskString *string umaskString *string
nonempty *bool
outsideContainerClusterMode *bool outsideContainerClusterMode *bool
} }
@ -34,6 +35,7 @@ func init() {
mountOptions.dataCenter = cmdMount.Flag.String("dataCenter", "", "prefer to write to the data center") mountOptions.dataCenter = cmdMount.Flag.String("dataCenter", "", "prefer to write to the data center")
mountOptions.allowOthers = cmdMount.Flag.Bool("allowOthers", true, "allows other users to access the file system") mountOptions.allowOthers = cmdMount.Flag.Bool("allowOthers", true, "allows other users to access the file system")
mountOptions.umaskString = cmdMount.Flag.String("umask", "022", "octal umask, e.g., 022, 0111") mountOptions.umaskString = cmdMount.Flag.String("umask", "022", "octal umask, e.g., 022, 0111")
mountOptions.nonempty = cmdMount.Flag.Bool("nonempty", false, "allows the mounting over a non-empty directory")
mountCpuProfile = cmdMount.Flag.String("cpuprofile", "", "cpu profile output file") mountCpuProfile = cmdMount.Flag.String("cpuprofile", "", "cpu profile output file")
mountMemProfile = cmdMount.Flag.String("memprofile", "", "memory profile output file") mountMemProfile = cmdMount.Flag.String("memprofile", "", "memory profile output file")
mountOptions.outsideContainerClusterMode = cmdMount.Flag.Bool("outsideContainerClusterMode", false, "allows other users to access the file system") mountOptions.outsideContainerClusterMode = cmdMount.Flag.Bool("outsideContainerClusterMode", false, "allows other users to access the file system")

View file

@ -138,9 +138,7 @@ func parseInfoFile(r io.Reader) ([]*Info, error) {
} }
func osSpecificMountOptions() []fuse.MountOption { func osSpecificMountOptions() []fuse.MountOption {
return []fuse.MountOption{ return []fuse.MountOption{}
fuse.AllowNonEmptyMount(),
}
} }
func checkMountPointAvailable(dir string) bool { func checkMountPointAvailable(dir string) bool {

View file

@ -35,24 +35,15 @@ func runMount(cmd *Command, args []string) bool {
return false return false
} }
return RunMount( return RunMount(&mountOptions, os.FileMode(umask))
*mountOptions.filer,
*mountOptions.filerMountRootPath,
*mountOptions.dir,
*mountOptions.collection,
*mountOptions.replication,
*mountOptions.dataCenter,
*mountOptions.chunkSizeLimitMB,
*mountOptions.allowOthers,
*mountOptions.ttlSec,
*mountOptions.dirListCacheLimit,
os.FileMode(umask),
*mountOptions.outsideContainerClusterMode,
)
} }
func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCenter string, chunkSizeLimitMB int, func RunMount(option *MountOptions, umask os.FileMode) bool {
allowOthers bool, ttlSec int, dirListCacheLimit int64, umask os.FileMode, outsideContainerClusterMode bool) bool {
filer := *option.filer
filerMountRootPath := *option.filerMountRootPath
dir := *option.dir
chunkSizeLimitMB := *mountOptions.chunkSizeLimitMB
util.LoadConfiguration("security", false) util.LoadConfiguration("security", false)
@ -114,14 +105,16 @@ func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCente
fuse.MaxReadahead(1024 * 128), fuse.MaxReadahead(1024 * 128),
fuse.AsyncRead(), fuse.AsyncRead(),
fuse.WritebackCache(), fuse.WritebackCache(),
fuse.AllowNonEmptyMount(),
} }
options = append(options, osSpecificMountOptions()...) options = append(options, osSpecificMountOptions()...)
if allowOthers { if *option.allowOthers {
options = append(options, fuse.AllowOther()) options = append(options, fuse.AllowOther())
} }
if *option.nonempty {
options = append(options, fuse.AllowNonEmptyMount())
}
c, err := fuse.Mount(dir, options...) c, err := fuse.Mount(dir, options...)
if err != nil { if err != nil {
@ -171,12 +164,12 @@ func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCente
FilerGrpcAddress: filerGrpcAddress, FilerGrpcAddress: filerGrpcAddress,
GrpcDialOption: grpcDialOption, GrpcDialOption: grpcDialOption,
FilerMountRootPath: mountRoot, FilerMountRootPath: mountRoot,
Collection: collection, Collection: *option.collection,
Replication: replication, Replication: *option.replication,
TtlSec: int32(ttlSec), TtlSec: int32(*option.ttlSec),
ChunkSizeLimit: int64(chunkSizeLimitMB) * 1024 * 1024, ChunkSizeLimit: int64(chunkSizeLimitMB) * 1024 * 1024,
DataCenter: dataCenter, DataCenter: *option.dataCenter,
DirListCacheLimit: dirListCacheLimit, DirListCacheLimit: *option.dirListCacheLimit,
EntryCacheTtl: 3 * time.Second, EntryCacheTtl: 3 * time.Second,
MountUid: uid, MountUid: uid,
MountGid: gid, MountGid: gid,
@ -184,7 +177,7 @@ func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCente
MountCtime: fileInfo.ModTime(), MountCtime: fileInfo.ModTime(),
MountMtime: time.Now(), MountMtime: time.Now(),
Umask: umask, Umask: umask,
OutsideContainerClusterMode: outsideContainerClusterMode, OutsideContainerClusterMode: *mountOptions.outsideContainerClusterMode,
Cipher: cipher, Cipher: cipher,
})) }))
if err != nil { if err != nil {