Skip to contentSkip to conversation

Swapping fs root inode without unmounting

DISCUSSION tzsz 2 participants 2 messages Mar 7, 2025 – Mar 10, 2025 VFS

lore
Share & tools
lore

tzsz

author
#0 lore raw

Hello!

We are currently developing a snapshot feature for a small university project. And for this reason we are looking for a way to swap out the root inode of our (mounted) fs. Internally we have a set of root inodes and we'd like to swap them out at will without unmounting the entire filesystem.

Is there any function/way how to do this properly?

So far we tried the following:
 -> swapping dentry: setting sb->s_root
    -> causes a lot of problems regarding inode ref counting (I_CLEAR flag) -> looking into fs_context (doesnt seem like this is appropriate here) -> we did not find anything related within the vfs.rst docs

Furthermore, we cannot mount those other root inodes at different mountpoints. All changes have to be live and in-place.

Kind regards

#1 lore raw
Quoted 9 lines · tzsz

Hello!

We are currently developing a snapshot feature for a small university project. And for this reason we are looking for a way to swap out the root inode of our (mounted) fs.
Internally we have a set of root inodes and we'd like to swap them out at will without unmounting the entire filesystem.

Is there any function/way how to do this properly?

See btrfs_get_tree(), mount_subvol(), and mount_subtree() in fs/btrfs/super.c