[COMMIT osv master] rofs: report fsid (filesystem ID) properly

2 views
Skip to first unread message

Commit Bot

unread,
Apr 28, 2020, 9:50:21 PM4/28/20
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

rofs: report fsid (filesystem ID) properly

This patch slightly enhances ROFS to report non-zero
unique fsid which is important to later integrate it with pagecache
laye that relies on unique combination of inode and st_dev that comes
from fsid.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/fs/rofs/rofs_vfsops.cc b/fs/rofs/rofs_vfsops.cc
--- a/fs/rofs/rofs_vfsops.cc
+++ b/fs/rofs/rofs_vfsops.cc
@@ -26,6 +26,7 @@
#include <sys/types.h>
#include <osv/device.h>
#include <osv/debug.h>
+#include <fs/vfs/vfs_id.h>
#include <iomanip>
#include <iostream>

@@ -44,6 +45,8 @@ std::atomic<long> rofs_cache_reads(0);
std::atomic<long> rofs_cache_misses(0);
#endif

+std::atomic<long> rofs_mounts(0);
+
struct vfsops rofs_vfsops = {
rofs_mount, /* mount */
rofs_unmount, /* unmount */
@@ -168,6 +171,10 @@ rofs_mount(struct mount *mp, const char *dev, int flags, const void *data)
mp->m_data = rofs;
mp->m_dev = device;

+ rofs_mounts += 1;
+ mp->m_fsid.__val[0] = rofs_mounts.load();
+ mp->m_fsid.__val[1] = ROFS_ID >> 32;
+
rofs_set_vnode(mp->m_root->d_vnode, rofs->inodes);

print("[rofs] returning from mount\n");
@@ -197,6 +204,9 @@ static int rofs_statfs(struct mount *mp, struct statfs *statp)

statp->f_namelen = 0; //FIXME - unlimited ROFS_FILENAME_MAXLEN;

+ statp->f_fsid.__val[0] = mp->m_fsid.__val[0];
+ statp->f_fsid.__val[1] = mp->m_fsid.__val[1];
+
return 0;
}

diff --git a/fs/rofs/rofs_vnops.cc b/fs/rofs/rofs_vnops.cc
--- a/fs/rofs/rofs_vnops.cc
+++ b/fs/rofs/rofs_vnops.cc
@@ -269,6 +269,9 @@ static int rofs_getattr(struct vnode *vnode, struct vattr *attr)
attr->va_nodeid = vnode->v_ino;
attr->va_size = vnode->v_size;

+ auto *fsid = &vnode->v_mount->m_fsid;
+ attr->va_fsid = ((uint32_t)fsid->__val[0]) | ((dev_t) ((uint32_t)fsid->__val[1]) << 32);
+
return 0;
}

diff --git a/tests/tst-zfs-mount.cc b/tests/tst-zfs-mount.cc
--- a/tests/tst-zfs-mount.cc
+++ b/tests/tst-zfs-mount.cc
@@ -173,6 +173,7 @@ int main(int argc, char **argv)

printf("file size = %lld\n", s.st_size);

+ report(statfs("/tmp", &st) == 0, "stat /tmp");
dev_t f_fsid = ((uint32_t)st.f_fsid.__val[0]) | ((dev_t) ((uint32_t)st.f_fsid.__val[1]) << 32);
report(f_fsid == s.st_dev, "st_dev must be equals to f_fsid");

Reply all
Reply to author
Forward
0 new messages