[PATCH v2 0/7] fs/9p: Reuse inode based on path (in addition to qid)
Christian Schoenebeck
linux_oss at crudebyte.com
Tue Sep 16 13:43:33 UTC 2025
On Tuesday, September 16, 2025 2:44:27 PM CEST Tingmao Wang wrote:
> On 9/16/25 00:31, Dominique Martinet wrote:
[...]
> >> I tried mounting a qemu-exported 9pfs backed on ext4, with
> >> multidevs=remap, and created a file, used stat to note its inode number,
> >> deleted the file, created another file (of the same OR different name),
> >> and that new file will have the same inode number.
> >>
> >> (If I don't delete the file, then a newly created file would of course
> >> have a different ext4 inode number, and in that case QEMU exposes a
> >> different qid)
> >
> > Ok so from Christian's reply this is just ext4 reusing the same inode..
> > I briefly hinted at this above, but in this case ext4 will give the
> > inode a different generation number (so the ext4 file handle will be
> > different, and accessing the old one will get ESTALE); but that's not
> > something qemu currently tracks and it'd be a bit of an overhaul...
> > In theory qemu could hash mount_id + file handle to get a properly
> > unique qid, if we need to improve that, but that'd be limited to root
> > users (and to filesystems that support name_to_handle_at) so I don't
> > think it's really appropriate either... hmm..
>
> Actually I think I forgot that there is also qid.version, which in the
> case of a QEMU-exported 9pfs might just be the file modification time? In
> 9pfs currently we do reject a inode match if that version changed server
> side in cached mode:
>
> v9fs_test_inode_dotl:
> /* compare qid details */
> if (memcmp(&v9inode->qid.version,
> &st->qid.version, sizeof(v9inode->qid.version)))
> return 0;
>
> (not tested whether QEMU correctly sets this version yet)
Define "correctly". ;-) QEMU sets it like this since 2010:
qidp->version = stbuf->st_mtime ^ (stbuf->st_size << 8);
https://github.com/qemu/qemu/blob/190d5d7fd725ff754f94e8e0cbfb69f279c82b5d/hw/9pfs/9p.c#L1020
/Christian
More information about the Linux-security-module-archive
mailing list