Dhfs-fuse: report real filesystem space

This commit is contained in:
2025-05-14 11:32:00 +02:00
parent 84b1d57125
commit e7f5be689f
3 changed files with 30 additions and 13 deletions

View File

@@ -19,6 +19,7 @@ import com.usatiuk.dhfsfs.objects.JKleppmannTreeNodeMetaFile;
import com.usatiuk.objects.JData; import com.usatiuk.objects.JData;
import com.usatiuk.objects.JObjectKey; import com.usatiuk.objects.JObjectKey;
import com.usatiuk.objects.iterators.IteratorStart; import com.usatiuk.objects.iterators.IteratorStart;
import com.usatiuk.objects.stores.ObjectPersistentStore;
import com.usatiuk.objects.transaction.Transaction; import com.usatiuk.objects.transaction.Transaction;
import com.usatiuk.objects.transaction.TransactionManager; import com.usatiuk.objects.transaction.TransactionManager;
import com.usatiuk.utils.StatusRuntimeExceptionNoStacktrace; import com.usatiuk.utils.StatusRuntimeExceptionNoStacktrace;
@@ -69,6 +70,8 @@ public class DhfsFileService {
JKleppmannTreeManager jKleppmannTreeManager; JKleppmannTreeManager jKleppmannTreeManager;
@Inject @Inject
JMapHelper jMapHelper; JMapHelper jMapHelper;
@Inject
ObjectPersistentStore objectPersistentStore;
private JKleppmannTreeManager.JKleppmannTree getTree() { private JKleppmannTreeManager.JKleppmannTree getTree() {
return jKleppmannTreeManager.getTree(JObjectKey.of("fs"), () -> new JKleppmannTreeNodeMetaDirectory("")); return jKleppmannTreeManager.getTree(JObjectKey.of("fs"), () -> new JKleppmannTreeNodeMetaDirectory(""));
@@ -781,4 +784,22 @@ public class DhfsFileService {
public Long write(JObjectKey fileUuid, long offset, byte[] data) { public Long write(JObjectKey fileUuid, long offset, byte[] data) {
return write(fileUuid, offset, UnsafeByteOperations.unsafeWrap(data)); return write(fileUuid, offset, UnsafeByteOperations.unsafeWrap(data));
} }
/**
* Get the free space on the filesystem.
*
* @return the free space in bytes
*/
public long getFreeSpace() {
return objectPersistentStore.getFreeSpace();
}
/**
* Get the total space on the filesystem.
*
* @return the total space in bytes
*/
public long getTotalSpace() {
return objectPersistentStore.getTotalSpace();
}
} }

View File

@@ -54,13 +54,12 @@ public class DhfsFuse extends FuseStubFS {
boolean enabled; boolean enabled;
@ConfigProperty(name = "dhfs.fuse.debug") @ConfigProperty(name = "dhfs.fuse.debug")
Boolean debug; Boolean debug;
@ConfigProperty(name = "dhfs.files.target_chunk_size")
int targetChunkSize;
@Inject @Inject
DhfsFileService fileService; DhfsFileService fileService;
/** /**
* Allocate a handle for the given key. * Allocate a handle for the given key.
*
* @param key the key to allocate a handle for * @param key the key to allocate a handle for
* @return the allocated handle, not 0 * @return the allocated handle, not 0
*/ */
@@ -76,11 +75,12 @@ public class DhfsFuse extends FuseStubFS {
/** /**
* Get the key from the handle. * Get the key from the handle.
*
* @param handle the handle to get the key from * @param handle the handle to get the key from
* @return the key, or null if not found * @return the key, or null if not found
*/ */
private JObjectKey getFromHandle(long handle) { private JObjectKey getFromHandle(long handle) {
if(handle == 0) if (handle == 0)
throw new IllegalStateException("Handle is 0"); throw new IllegalStateException("Handle is 0");
return _openHandles.get(handle); return _openHandles.get(handle);
} }
@@ -112,7 +112,6 @@ public class DhfsFuse extends FuseStubFS {
opts.add("-o"); opts.add("-o");
opts.add("iosize=" + iosize); opts.add("iosize=" + iosize);
} else if (SystemUtils.IS_OS_LINUX) { } else if (SystemUtils.IS_OS_LINUX) {
// FIXME: There's something else missing: the writes still seem to be 32k max
// opts.add("-o"); // opts.add("-o");
// opts.add("large_read"); // opts.add("large_read");
opts.add("-o"); opts.add("-o");
@@ -144,13 +143,12 @@ public class DhfsFuse extends FuseStubFS {
try { try {
stbuf.f_frsize.set(blksize); stbuf.f_frsize.set(blksize);
stbuf.f_bsize.set(blksize); stbuf.f_bsize.set(blksize);
// FIXME: stbuf.f_blocks.set(fileService.getTotalSpace() / blksize); // total data blocks in file system
stbuf.f_blocks.set(1024 * 1024 * 1024 / blksize); // total data blocks in file system stbuf.f_bfree.set(fileService.getFreeSpace() / blksize); // free blocks in fs
stbuf.f_bfree.set(1024 * 1024 * 1024 / blksize); // free blocks in fs stbuf.f_bavail.set(fileService.getFreeSpace() / blksize); // avail blocks in fs
stbuf.f_bavail.set(1024 * 1024 * 1024 / blksize); // avail blocks in fs stbuf.f_files.set(1000); // TODO: Calculate real file counts?
stbuf.f_files.set(1000); //FIXME: stbuf.f_ffree.set(Integer.MAX_VALUE - 1000);
stbuf.f_ffree.set(Integer.MAX_VALUE - 2000); //FIXME: stbuf.f_favail.set(Integer.MAX_VALUE - 1000);
stbuf.f_favail.set(Integer.MAX_VALUE - 2000); //FIXME:
stbuf.f_namemax.set(2048); stbuf.f_namemax.set(2048);
return super.statfs(path, stbuf); return super.statfs(path, stbuf);
} catch (Throwable e) { } catch (Throwable e) {
@@ -186,7 +184,6 @@ public class DhfsFuse extends FuseStubFS {
} }
} }
// FIXME: Race?
stat.st_ctim.tv_sec.set(found.get().ctime() / 1000); stat.st_ctim.tv_sec.set(found.get().ctime() / 1000);
stat.st_ctim.tv_nsec.set((found.get().ctime() % 1000) * 1000); stat.st_ctim.tv_nsec.set((found.get().ctime() % 1000) * 1000);
stat.st_mtim.tv_sec.set(found.get().mtime() / 1000); stat.st_mtim.tv_sec.set(found.get().mtime() / 1000);

View File

@@ -66,7 +66,6 @@ public class ReachablePeerManager {
_disconnectedListeners = List.copyOf(disconnectedListeners.stream().toList()); _disconnectedListeners = List.copyOf(disconnectedListeners.stream().toList());
} }
// Note: keep priority updated with below
void init(@Observes @Priority(600) StartupEvent event) throws IOException { void init(@Observes @Priority(600) StartupEvent event) throws IOException {
_heartbeatExecutor = Executors.newVirtualThreadPerTaskExecutor(); _heartbeatExecutor = Executors.newVirtualThreadPerTaskExecutor();
} }