Skip to content

Commit

Permalink
Add fake numbers for statfs
Browse files Browse the repository at this point in the history
```
$ df -h /mnt/fuse/
Filesystem      Size  Used Avail Use% Mounted on
alluxio-fuse    910T     0  910T   0% /mnt/fuse
```

### What changes are proposed in this pull request?

Add fake numbers for statfs

### Why are the changes needed?

Some application checks the available space in a file system before continuing to do file operations.

### Does this PR introduce any user facing changes?

A fake number (1 Petabytes) is provided to statfs. This number does not reflect real available storage space.

			pr-link: #18482
			change-id: cid-9f60d185393b616be02bf8f473b2026f2047f28c
  • Loading branch information
huanghua78 authored Jan 8, 2024
1 parent 726f812 commit 9ef7552
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class AlluxioJniFuseFileSystem extends AbstractFuseFileSystem {
private final boolean mUfsEnabled;
private final FuseOptions mFuseOptions;

private static final BlockMasterInfo ZERO_BLOCK_MASTER_INFO = new BlockMasterInfo();
private final BlockMasterInfo mFakeBlockMasterInfo;

/** df command will treat -1 as an unknown value. */
@VisibleForTesting
Expand Down Expand Up @@ -149,6 +149,13 @@ public AlluxioJniFuseFileSystem(FileSystemContext fsContext, FileSystem fs,
LOG.error("Failed to set AlluxioJniFuseFileSystem log to debug level", e);
}
}

// Alluxio 3.0 does not keep valid nor useful block info at this moment.
// Fake numbers for some applications which require a non-zero free space.
mFakeBlockMasterInfo = new BlockMasterInfo();
mFakeBlockMasterInfo.setCapacityBytes(1_000_000_000_000_000L); // 1 petabytes
mFakeBlockMasterInfo.setFreeBytes(1_000_000_000_000_000L); // 1 petabytes

MetricsSystem.registerGaugeIfAbsent(
MetricsSystem.getMetricName(MetricKey.FUSE_READ_WRITE_FILE_COUNT.getName()),
mFileEntries::size);
Expand Down Expand Up @@ -656,31 +663,22 @@ public int statfs(String path, Statvfs stbuf) {
}

private int statfsInternal(String path, Statvfs stbuf) {
if (mUfsEnabled) {
return 0;
}
final AlluxioURI uri = mPathResolverCache.getUnchecked(path);
int res = AlluxioFuseUtils.checkNameLength(uri);
if (res != 0) {
return res;
}

// Alluxio does not keep valid nor useful block info at this moment.
BlockMasterInfo info = ZERO_BLOCK_MASTER_INFO;
if (info == null) {
LOG.error("Failed to statfs {}: cannot get block master info", path);
return -ErrorCodes.EIO();
}
long blockSize = 16L * Constants.KB;
// fs block size
// The size in bytes of the minimum unit of allocation on this file system
stbuf.f_bsize.set(blockSize);
// The preferred length of I/O requests for files on this file system.
stbuf.f_frsize.set(blockSize);
// total data blocks in fs
stbuf.f_blocks.set(info.getCapacityBytes() / blockSize);
stbuf.f_blocks.set(mFakeBlockMasterInfo.getCapacityBytes() / blockSize);
// free blocks in fs
long freeBlocks = info.getFreeBytes() / blockSize;
long freeBlocks = mFakeBlockMasterInfo.getFreeBytes() / blockSize;
stbuf.f_bfree.set(freeBlocks);
stbuf.f_bavail.set(freeBlocks);
// inode info in fs
Expand Down

0 comments on commit 9ef7552

Please sign in to comment.