Skip to content

Commit

Permalink
rofs: report fsid (filesystem ID) properly
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wkozaczuk committed Apr 29, 2020
1 parent c193437 commit 80be3ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fs/rofs/rofs_vfsops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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 */
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions fs/rofs/rofs_vnops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions tests/tst-zfs-mount.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit 80be3ce

Please sign in to comment.