SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fix(mount): gate directory nlink counting behind -posix.dirNLink option (#9026)
Chris Lu8aa58098249b
diff --git a/weed/command/mount.go b/weed/command/mount.goindex c82fbd9ec9..b769179689 100644--- a/weed/command/mount.go+++ b/weed/command/mount.go@@ -55,6 +55,9 @@ type MountOptions struct {// Distributed lock for cross-mount write coordinationdistributedLock *bool+ // POSIX compliance options+ posixDirNlink *bool+// FUSE performance optionswritebackCache *boolasyncDio *bool@@ -131,6 +134,9 @@ func init() {// Distributed lock for cross-mount write coordinationmountOptions.distributedLock = cmdMount.Flag.Bool("dlm", false, "enable distributed lock for cross-mount write coordination (only one mount can write a file at a time)")+ // POSIX compliance options+ mountOptions.posixDirNlink = cmdMount.Flag.Bool("posix.dirNLink", false, "report POSIX-compliant directory nlink (2 + subdirectory count); costs one directory listing per stat")+// FUSE performance optionsmountOptions.writebackCache = cmdMount.Flag.Bool("writebackCache", false, "enable FUSE writeback cache for improved write performance (at risk of data loss on crash)")mountOptions.asyncDio = cmdMount.Flag.Bool("asyncDio", false, "enable async direct I/O for better concurrency")diff --git a/weed/command/mount_std.go b/weed/command/mount_std.goindex 8228bbcd24..e0c0a6291d 100644--- a/weed/command/mount_std.go+++ b/weed/command/mount_std.go@@ -354,6 +354,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {DirIdleEvictSec: *option.dirIdleEvictSec,EnableDistributedLock: option.distributedLock != nil && *option.distributedLock,WritebackCache: option.writebackCache != nil && *option.writebackCache,+ PosixDirNlink: option.posixDirNlink != nil && *option.posixDirNlink,})// create mount rootdiff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.goindex ba6644f1f2..fbc91f1028 100644--- a/weed/mount/weedfs.go+++ b/weed/mount/weedfs.go@@ -93,6 +93,12 @@ type Option struct {// When true, Flush() returns immediately and data upload + metadata flush happen in background.WritebackCache bool+ // PosixDirNlink enables POSIX-compliant directory nlink counting+ // (nlink = 2 + number_of_subdirectories). This requires listing+ // cached directory entries on every stat, which has a performance cost.+ // When false (default), directories report nlink=2.+ PosixDirNlink bool+uniqueCacheDirForRead stringuniqueCacheDirForWrite string}diff --git a/weed/mount/weedfs_attr.go b/weed/mount/weedfs_attr.goindex cd4e77f6ca..95e39f836d 100644--- a/weed/mount/weedfs_attr.go+++ b/weed/mount/weedfs_attr.go@@ -17,7 +17,9 @@ func (wfs *WFS) GetAttr(cancel <-chan struct{}, input *fuse.GetAttrIn, out *fuseglog.V(4).Infof("GetAttr %v", input.NodeId)if input.NodeId == 1 {wfs.setRootAttr(out)- wfs.applyDirNlink(&out.Attr, util.FullPath(wfs.option.FilerMountRootPath))+ if wfs.option.PosixDirNlink {+ wfs.applyDirNlink(&out.Attr, util.FullPath(wfs.option.FilerMountRootPath))+ }return fuse.OK}@@ -27,7 +29,7 @@ func (wfs *WFS) GetAttr(cancel <-chan struct{}, input *fuse.GetAttrIn, out *fuseout.AttrValid = 1wfs.setAttrByPbEntry(&out.Attr, inode, entry, true)wfs.applyInMemoryAtime(&out.Attr, inode)- if entry.IsDirectory {+ if entry.IsDirectory && wfs.option.PosixDirNlink {wfs.applyDirNlink(&out.Attr, path)}return statusdiff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.goindex 43529176d6..2c29d907a3 100644--- a/weed/mount/weedfs_dir_lookup.go+++ b/weed/mount/weedfs_dir_lookup.go@@ -44,7 +44,7 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strinwfs.outputFilerEntry(out, inode, localEntry)- if localEntry.IsDirectory() {+ if localEntry.IsDirectory() && wfs.option.PosixDirNlink {wfs.applyDirNlink(&out.Attr, fullFilePath)}