From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Waldemar Kozaczuk <jwkozac...@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 <jwkozac...@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");
 

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/0000000000009c2bb905a4642b20%40google.com.

Reply via email to