diff options
| author | chrislu <chris.lu@gmail.com> | 2022-08-05 00:31:41 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-08-05 00:31:41 -0700 |
| commit | b278bb24d380fe8c6ea6a31e0250791abb97d807 (patch) | |
| tree | ae824dc39a17bae88e9343a9128c8f693f8b7cc9 | |
| parent | 4d08393b7ca8b1a34ed65532955de76cf8843ec2 (diff) | |
| download | seaweedfs-b278bb24d380fe8c6ea6a31e0250791abb97d807.tar.xz seaweedfs-b278bb24d380fe8c6ea6a31e0250791abb97d807.zip | |
mount: adjust df stats reporting when close to the limit
fix https://github.com/seaweedfs/seaweedfs/issues/3407
| -rw-r--r-- | weed/mount/weedfs_stats.go | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/weed/mount/weedfs_stats.go b/weed/mount/weedfs_stats.go index 9ef9072d6..1b47e5d86 100644 --- a/weed/mount/weedfs_stats.go +++ b/weed/mount/weedfs_stats.go @@ -10,7 +10,7 @@ import ( "time" ) -const blockSize = 512 +const blockSize = 4096 * 4 type statsCache struct { filer_pb.StatisticsResponse @@ -64,15 +64,43 @@ func (wfs *WFS) StatFs(cancel <-chan struct{}, in *fuse.InHeader, out *fuse.Stat } } + // http://man.he.net/man2/statfs + /* + struct statfs { + __fsword_t f_type; // Type of filesystem (see below) + __fsword_t f_bsize; // Optimal transfer block size + fsblkcnt_t f_blocks; // Total data blocks in filesystem + fsblkcnt_t f_bfree; // Free blocks in filesystem + fsblkcnt_t f_bavail; // Free blocks available to + unprivileged user + fsfilcnt_t f_files; // Total file nodes in filesystem + fsfilcnt_t f_ffree; // Free file nodes in filesystem + fsid_t f_fsid; // Filesystem ID + __fsword_t f_namelen; // Maximum length of filenames + __fsword_t f_frsize; // Fragment size (since Linux 2.6) + __fsword_t f_flags; // Mount flags of filesystem + (since Linux 2.6.36) + __fsword_t f_spare[xxx]; + // Padding bytes reserved for future use + }; + */ + // Compute the total number of available blocks out.Blocks = totalDiskSize / blockSize - + if out.Blocks <= 0 { + out.Blocks = 1 + } // Compute the number of used blocks - numBlocks := uint64(usedDiskSize / blockSize) + numBlocks := usedDiskSize / blockSize + + remainingBlocks := int64(out.Blocks) - int64(numBlocks) + if remainingBlocks < 0 { + remainingBlocks = 0 + } // Report the number of free and available blocks for the block size - out.Bfree = out.Blocks - numBlocks - out.Bavail = out.Blocks - numBlocks + out.Bfree = uint64(remainingBlocks) + out.Bavail = uint64(remainingBlocks) out.Bsize = uint32(blockSize) // Report the total number of possible files in the file system (and those free) |
