Skip to contentSkip to conversation

virtiofs uuid and file handles

DISCUSSION Amir Goldstein 6 participants 26 messages Sep 23, 2020 – Feb 24, 2025 9 messages not in the archive VFS

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAOQ4uxgZ08ePA5WFOYFoLZaq_-Kjr-haNzBN5Aj3MfF=f9pjdg@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAOQ4uxieqnKENV_kJYwfcnPjNdVuqH3BnKVx_zLz=N_PdAguNg@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAOQ4uxg0XVEEzc+HyyC63WWZuA2AsRjJmbZBuNimtj=t+quVyg@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 1 line · Vivek Goyal

...

Quoted 7 lines
Quoted 7 lines

Note that if all overlayfs layers are on the same fs and that fs has null uuid, then the "disk copy" use case should just work, but I never tested that.

So far, there has been no filesystem with null uuid that could be used as upper+lower layers (even xfs with option nouuid has non null s_uuid).

Quoted 7 lines
Quoted 2 lines

Recently, virtiofs was added as a filesystem that could be used for upper+lower layers and virtiofs (which is fuse) has null uuid.

I guess I never paid attention to uuid part of virtiofs. Probably we are not using index or any of the advanced features of overlayfs yet, that's why.

I don't expect you should have a problem enabling index because of null uuid when all layers are on the same virtiofs. That setup is allowed.
We only ever start checking for null uuid on lower layers that are NOT on the same fs as upper layer.

What you are expected to have a problem with is that FUSE support for file handles is "problematic".

I found out the hard way that FUSE can decode NFS file handles to completely different object than the encoded object if the encoded inode was evicted from cache and its node id has been reused.

Another problem is that FUSE protocol does not have complete support for decoding file handles. FUSE implements decode file handle by LOOKUP(ino, ".") to server, but if server is proxying a local filesystem, there is not enough information to construct an open_by_handle_at() request.

I wrote a fuse filesystem whose file handles are persistent and reliable [1], but it is a specialized server that uses knowledge of the local filesystem file handle format and it requires that the local filesystem has a special feature to interpret a file handle with 0 generation as ANY generation (ext4 does that).

I think that the proper was to implement reliable persistent file handles in fuse/virtiofs would be to add ENCODE/DECODE to FUSE protocol and allow the server to handle this.

Thanks,
Amir,

[1] https://github.com/amir73il/libfuse/commits/cachegwfs

#8 lore raw
Quoted 3 lines · Amir Goldstein

I think that the proper was to implement reliable persistent file handles in fuse/virtiofs would be to add ENCODE/DECODE to FUSE protocol and allow the server to handle this.

Max Reitz (Cc-d) is currently looking into this.

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Thanks,
Miklos

#9 lore raw
Quoted 22 lines · Miklos Szeredi
Quoted 3 lines · Amir Goldstein

I think that the proper was to implement reliable persistent file handles in fuse/virtiofs would be to add ENCODE/DECODE to FUSE protocol and allow the server to handle this.

Max Reitz (Cc-d) is currently looking into this.

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Quoted 3 lines

Disadvantages being:

- cost of generating a file handle on all lookups

I never ran into a local fs implementation where this was expensive.

Quoted 6 lines

- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Sounds good.
I suppose flock() does need to keep the open fd on server.

Are there any other states for an open fd that must be preserved?

Thanks,
Amir.

#10 lore raw
Quoted 32 lines · Amir Goldstein
Quoted 22 lines · Miklos Szeredi
Quoted 3 lines · Amir Goldstein

I think that the proper was to implement reliable persistent file handles in fuse/virtiofs would be to add ENCODE/DECODE to FUSE protocol and allow the server to handle this.

Max Reitz (Cc-d) is currently looking into this.

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Quoted 3 lines

Disadvantages being:

- cost of generating a file handle on all lookups

I never ran into a local fs implementation where this was expensive.

Quoted 2 lines

- cost of storing file handle in kernel icache

Quoted 7 lines
Quoted 4 lines

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Sounds good.
I suppose flock() does need to keep the open fd on server.

Open files are a separate issue and do need an active object in the server.

The issue this solves is synchronizing "released" and "evicted" states of objects between server and client. I.e. when a file is closed (and no more open files exist referencing the same object) the
dentry refcount goes to zero but it remains in the cache. In this
state the server could really evict it's own cached object, but can't because the client can gain an active reference at any time via cached path lookup.

One other solution would be for the server to send a notification (NOTIFY_EVICT) that would try to clean out the object from the server
cache and respond with a FORGET if successful. But I sort of like
the file handle one better, since it solves multiple problems.

Thanks,
Miklos

Quoted 7 lines

Are there any other states for an open fd that must be preserved?

Thanks,
Amir.

#11 lore raw
Quoted 11 lines · Miklos Szeredi
Quoted 9 lines · Amir Goldstein
Quoted 7 lines · Miklos Szeredi
Quoted 3 lines · Amir Goldstein

I think that the proper was to implement reliable persistent file handles in fuse/virtiofs would be to add ENCODE/DECODE to FUSE protocol and allow the server to handle this.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Max Reitz (Cc-d) is currently looking into this.

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

Miklos, Max,

Any updates on LOOKUP_HANDLE work?

Quoted 34 lines
Quoted 16 lines
Quoted 11 lines

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups

I never ran into a local fs implementation where this was expensive.

Quoted 2 lines

- cost of storing file handle in kernel icache

Quoted 7 lines
Quoted 4 lines

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Sounds good.
I suppose flock() does need to keep the open fd on server.

Open files are a separate issue and do need an active object in the server.

The issue this solves is synchronizing "released" and "evicted" states of objects between server and client. I.e. when a file is closed (and no more open files exist referencing the same object) the
dentry refcount goes to zero but it remains in the cache. In this
state the server could really evict it's own cached object, but can't because the client can gain an active reference at any time via cached path lookup.

Quoted 5 lines

One other solution would be for the server to send a notification (NOTIFY_EVICT) that would try to clean out the object from the server
cache and respond with a FORGET if successful. But I sort of like
the file handle one better, since it solves multiple problems.

Even with LOOKUP_HANDLE, I am struggling to understand how we intend to invalidate all fuse dentries referring to ino X in case the server replies with reused ino X with a different generation that the one stored in fuse inode cache.

This is an issue that I encountered when running the passthrough_hp test, on my filesystem. In tst_readdir_big() for example, underlying files are being unlinked and new files created reusing the old inode numbers.

This creates a situation where server gets a lookup request for file B that uses the reused inode number X, while old file A is still in fuse dentry cache using the older generation of real inode number X which is still in fuse inode cache.

Now the server knows that the real inode has been rused, because the server caches the old generation value, but it cannot reply to the lookup request before the old fuse inode has been invalidated. IIUC, fuse_lowlevel_notify_inval_inode() is not enough(?). We would also need to change fuse_dentry_revalidate() to detect the case of reused/invalidated inode.

The straightforward way I can think of is to store inode generation in fuse_dentry. It won't even grow the size of the struct.

Am I over complicating this?

Thanks,
Amir.

#12 lore raw
Quoted 86 lines · Amir Goldstein
Quoted 11 lines · Miklos Szeredi
Quoted 9 lines · Amir Goldstein
Quoted 7 lines · Miklos Szeredi
Quoted 3 lines · Amir Goldstein

I think that the proper was to implement reliable persistent file handles in fuse/virtiofs would be to add ENCODE/DECODE to FUSE protocol and allow the server to handle this.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Max Reitz (Cc-d) is currently looking into this.

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

Miklos, Max,

Any updates on LOOKUP_HANDLE work?

Quoted 34 lines
Quoted 16 lines
Quoted 11 lines

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups

I never ran into a local fs implementation where this was expensive.

Quoted 2 lines

- cost of storing file handle in kernel icache

Quoted 7 lines
Quoted 4 lines

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Sounds good.
I suppose flock() does need to keep the open fd on server.

Open files are a separate issue and do need an active object in the server.

The issue this solves is synchronizing "released" and "evicted" states of objects between server and client. I.e. when a file is closed (and no more open files exist referencing the same object) the
dentry refcount goes to zero but it remains in the cache. In this
state the server could really evict it's own cached object, but can't because the client can gain an active reference at any time via cached path lookup.

Quoted 5 lines

One other solution would be for the server to send a notification (NOTIFY_EVICT) that would try to clean out the object from the server
cache and respond with a FORGET if successful. But I sort of like
the file handle one better, since it solves multiple problems.

Even with LOOKUP_HANDLE, I am struggling to understand how we intend to invalidate all fuse dentries referring to ino X in case the server replies with reused ino X with a different generation that the one stored in fuse inode cache.

This is an issue that I encountered when running the passthrough_hp test, on my filesystem. In tst_readdir_big() for example, underlying files are being unlinked and new files created reusing the old inode numbers.

This creates a situation where server gets a lookup request for file B that uses the reused inode number X, while old file A is still in fuse dentry cache using the older generation of real inode number X which is still in fuse inode cache.

Now the server knows that the real inode has been rused, because the server caches the old generation value, but it cannot reply to the lookup request before the old fuse inode has been invalidated. IIUC, fuse_lowlevel_notify_inval_inode() is not enough(?). We would also need to change fuse_dentry_revalidate() to detect the case of reused/invalidated inode.

Quoted 4 lines

The straightforward way I can think of is to store inode generation in fuse_dentry. It won't even grow the size of the struct.

Am I over complicating this?

In this scheme the generation number is already embedded in the file handle. If LOOKUP_HANDLE returns a nodeid that can be found in the icache, but which doesn't match the new file handle, then the old inode will be marked bad and a new one allocated.

Does that answer your worries? Or am I missing something?

Thanks,
Miklos

#13 lore raw
Quoted 91 lines · Miklos Szeredi
Quoted 89 lines · Amir Goldstein
Quoted 11 lines · Miklos Szeredi
Quoted 9 lines · Amir Goldstein
Quoted 7 lines · Miklos Szeredi
Quoted 3 lines · Amir Goldstein

I think that the proper was to implement reliable persistent file handles in fuse/virtiofs would be to add ENCODE/DECODE to FUSE protocol and allow the server to handle this.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Max Reitz (Cc-d) is currently looking into this.

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

Miklos, Max,

Any updates on LOOKUP_HANDLE work?

Quoted 34 lines
Quoted 16 lines
Quoted 11 lines

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups

I never ran into a local fs implementation where this was expensive.

Quoted 2 lines

- cost of storing file handle in kernel icache

Quoted 7 lines
Quoted 4 lines

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Sounds good.
I suppose flock() does need to keep the open fd on server.

Open files are a separate issue and do need an active object in the server.

The issue this solves is synchronizing "released" and "evicted" states of objects between server and client. I.e. when a file is closed (and no more open files exist referencing the same object) the
dentry refcount goes to zero but it remains in the cache. In this
state the server could really evict it's own cached object, but can't because the client can gain an active reference at any time via cached path lookup.

Quoted 5 lines

One other solution would be for the server to send a notification (NOTIFY_EVICT) that would try to clean out the object from the server
cache and respond with a FORGET if successful. But I sort of like
the file handle one better, since it solves multiple problems.

Even with LOOKUP_HANDLE, I am struggling to understand how we intend to invalidate all fuse dentries referring to ino X in case the server replies with reused ino X with a different generation that the one stored in fuse inode cache.

This is an issue that I encountered when running the passthrough_hp test, on my filesystem. In tst_readdir_big() for example, underlying files are being unlinked and new files created reusing the old inode numbers.

This creates a situation where server gets a lookup request for file B that uses the reused inode number X, while old file A is still in fuse dentry cache using the older generation of real inode number X which is still in fuse inode cache.

Now the server knows that the real inode has been rused, because the server caches the old generation value, but it cannot reply to the lookup request before the old fuse inode has been invalidated. IIUC, fuse_lowlevel_notify_inval_inode() is not enough(?). We would also need to change fuse_dentry_revalidate() to detect the case of reused/invalidated inode.

The straightforward way I can think of is to store inode generation in fuse_dentry. It won't even grow the size of the struct.

Quoted 8 lines
Quoted 1 line

Am I over complicating this?

In this scheme the generation number is already embedded in the file handle. If LOOKUP_HANDLE returns a nodeid that can be found in the icache, but which doesn't match the new file handle, then the old inode will be marked bad and a new one allocated.

Does that answer your worries? Or am I missing something?

It affirms my understanding of the future implementation, but does not help my implementation without protocol changes.
I thought I could get away without LOOKUP_HANDLE for
underlying fs that is able to resolve by ino, but seems that I still have an unhandled corner case, so will need to add some kernel patch. Unless there is already a way to signal from server to make the inode bad in a synchronous manner (I did not find any) before replying to LOOKUP with a new generation of the same ino.

Any idea about the timeline for LOOKUP_HANDLE?
I may be able to pick this up myself if there is no one actively working on it or plans for anyone to make this happen.

Thanks,
Amir.

#14 lore raw
Quoted 110 lines · Amir Goldstein
Quoted 91 lines · Miklos Szeredi
Quoted 89 lines · Amir Goldstein
Quoted 11 lines · Miklos Szeredi
Quoted 9 lines · Amir Goldstein
Quoted 7 lines · Miklos Szeredi
Quoted 3 lines · Amir Goldstein

I think that the proper was to implement reliable persistent file handles in fuse/virtiofs would be to add ENCODE/DECODE to FUSE protocol and allow the server to handle this.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Max Reitz (Cc-d) is currently looking into this.

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

Miklos, Max,

Any updates on LOOKUP_HANDLE work?

Quoted 34 lines
Quoted 16 lines
Quoted 11 lines

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups

I never ran into a local fs implementation where this was expensive.

Quoted 2 lines

- cost of storing file handle in kernel icache

Quoted 7 lines
Quoted 4 lines

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Sounds good.
I suppose flock() does need to keep the open fd on server.

Open files are a separate issue and do need an active object in the server.

The issue this solves is synchronizing "released" and "evicted" states of objects between server and client. I.e. when a file is closed (and no more open files exist referencing the same object) the
dentry refcount goes to zero but it remains in the cache. In this
state the server could really evict it's own cached object, but can't because the client can gain an active reference at any time via cached path lookup.

Quoted 5 lines

One other solution would be for the server to send a notification (NOTIFY_EVICT) that would try to clean out the object from the server
cache and respond with a FORGET if successful. But I sort of like
the file handle one better, since it solves multiple problems.

Even with LOOKUP_HANDLE, I am struggling to understand how we intend to invalidate all fuse dentries referring to ino X in case the server replies with reused ino X with a different generation that the one stored in fuse inode cache.

This is an issue that I encountered when running the passthrough_hp test, on my filesystem. In tst_readdir_big() for example, underlying files are being unlinked and new files created reusing the old inode numbers.

This creates a situation where server gets a lookup request for file B that uses the reused inode number X, while old file A is still in fuse dentry cache using the older generation of real inode number X which is still in fuse inode cache.

Now the server knows that the real inode has been rused, because the server caches the old generation value, but it cannot reply to the lookup request before the old fuse inode has been invalidated. IIUC, fuse_lowlevel_notify_inval_inode() is not enough(?). We would also need to change fuse_dentry_revalidate() to detect the case of reused/invalidated inode.

The straightforward way I can think of is to store inode generation in fuse_dentry. It won't even grow the size of the struct.

Quoted 8 lines
Quoted 1 line

Am I over complicating this?

In this scheme the generation number is already embedded in the file handle. If LOOKUP_HANDLE returns a nodeid that can be found in the icache, but which doesn't match the new file handle, then the old inode will be marked bad and a new one allocated.

Does that answer your worries? Or am I missing something?

It affirms my understanding of the future implementation, but does not help my implementation without protocol changes.
I thought I could get away without LOOKUP_HANDLE for
underlying fs that is able to resolve by ino, but seems that I still have an unhandled corner case, so will need to add some kernel patch. Unless there is already a way to signal from server to make the inode bad in a synchronous manner (I did not find any) before replying to LOOKUP with a new generation of the same ino.

Quoted 3 lines

Any idea about the timeline for LOOKUP_HANDLE?
I may be able to pick this up myself if there is no one actively working on it or plans for anyone to make this happen.

AFAIK, right now max is not actively looking into LOOKUP_HANDLE.

To solve the issue of virtiofs server having too many fds open, he is now planning to store corresonding file handle in server and use that to open fd later.

But this does not help with persistent file handle issue for fuse client.

BTW, one concern with file handles coming from guest kernel was that how to trust those handles. Guest can create anything and use file server to open the files on same filesystem (but not shared with guest).

I am assuming same concern should be there with non-virtiofs use cases. Regular fuse client must be sending a file handle and file server is running with CAP_DAC_READ_SEARCH. How will it make sure that client is not able to access files not exported through shared directory but are present on same filesystem.

Thanks
Vivek

#15 lore raw
Quoted 116 lines · Vivek Goyal
Quoted 110 lines · Amir Goldstein
Quoted 91 lines · Miklos Szeredi
Quoted 89 lines · Amir Goldstein
Quoted 11 lines · Miklos Szeredi
Quoted 9 lines · Amir Goldstein
Quoted 7 lines · Miklos Szeredi
Quoted 3 lines · Amir Goldstein

I think that the proper was to implement reliable persistent file handles in fuse/virtiofs would be to add ENCODE/DECODE to FUSE protocol and allow the server to handle this.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Max Reitz (Cc-d) is currently looking into this.

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

Miklos, Max,

Any updates on LOOKUP_HANDLE work?

Quoted 34 lines
Quoted 16 lines
Quoted 11 lines

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups

I never ran into a local fs implementation where this was expensive.

Quoted 2 lines

- cost of storing file handle in kernel icache

Quoted 7 lines
Quoted 4 lines

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Sounds good.
I suppose flock() does need to keep the open fd on server.

Open files are a separate issue and do need an active object in the server.

The issue this solves is synchronizing "released" and "evicted" states of objects between server and client. I.e. when a file is closed (and no more open files exist referencing the same object) the
dentry refcount goes to zero but it remains in the cache. In this
state the server could really evict it's own cached object, but can't because the client can gain an active reference at any time via cached path lookup.

Quoted 5 lines

One other solution would be for the server to send a notification (NOTIFY_EVICT) that would try to clean out the object from the server
cache and respond with a FORGET if successful. But I sort of like
the file handle one better, since it solves multiple problems.

Even with LOOKUP_HANDLE, I am struggling to understand how we intend to invalidate all fuse dentries referring to ino X in case the server replies with reused ino X with a different generation that the one stored in fuse inode cache.

This is an issue that I encountered when running the passthrough_hp test, on my filesystem. In tst_readdir_big() for example, underlying files are being unlinked and new files created reusing the old inode numbers.

This creates a situation where server gets a lookup request for file B that uses the reused inode number X, while old file A is still in fuse dentry cache using the older generation of real inode number X which is still in fuse inode cache.

Now the server knows that the real inode has been rused, because the server caches the old generation value, but it cannot reply to the lookup request before the old fuse inode has been invalidated. IIUC, fuse_lowlevel_notify_inval_inode() is not enough(?). We would also need to change fuse_dentry_revalidate() to detect the case of reused/invalidated inode.

The straightforward way I can think of is to store inode generation in fuse_dentry. It won't even grow the size of the struct.

Quoted 8 lines
Quoted 1 line

Am I over complicating this?

In this scheme the generation number is already embedded in the file handle. If LOOKUP_HANDLE returns a nodeid that can be found in the icache, but which doesn't match the new file handle, then the old inode will be marked bad and a new one allocated.

Does that answer your worries? Or am I missing something?

It affirms my understanding of the future implementation, but does not help my implementation without protocol changes.
I thought I could get away without LOOKUP_HANDLE for
underlying fs that is able to resolve by ino, but seems that I still have an unhandled corner case, so will need to add some kernel patch. Unless there is already a way to signal from server to make the inode bad in a synchronous manner (I did not find any) before replying to LOOKUP with a new generation of the same ino.

Quoted 3 lines

Any idea about the timeline for LOOKUP_HANDLE?
I may be able to pick this up myself if there is no one actively working on it or plans for anyone to make this happen.

Quoted 9 lines

AFAIK, right now max is not actively looking into LOOKUP_HANDLE.

To solve the issue of virtiofs server having too many fds open, he is now planning to store corresonding file handle in server and use that to open fd later.

But this does not help with persistent file handle issue for fuse client.

I see. Yes that should work, but he'd still need to cope with reused inode numbers in case you allow unlinks from the host (do you?), because LOOKUP can find a host fs inode that does not match the file handle of a previously found inode of the same ino.

Quoting Miklos' response above:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

If LOOKUP_HANDLE returns a nodeid that can be found in the icache, but which doesn't match the new file handle, then the old inode will be marked bad and a new one allocated.

This statement, with minor adjustments is also true for LOOKUP:

"If LOOKUP returns a nodeid that can be found in the icache, but
whose i_generation doesn't match the generation returned in outarg, then the old inode should be marked bad and a new one allocated."

Quoted 11 lines

BTW, one concern with file handles coming from guest kernel was that how to trust those handles. Guest can create anything and use file server to open the files on same filesystem (but not shared with guest).

I am assuming same concern should be there with non-virtiofs use cases. Regular fuse client must be sending a file handle and file server is running with CAP_DAC_READ_SEARCH. How will it make sure that client is not able to access files not exported through shared directory but are present on same filesystem.

That is a concern.
It's the same concern for NFS clients that can guess file handles.

The ways to address this concern with NFS is the export option subtree_check, but that uses non unique file handles to an inode which include a parent handle, so that's probably not a good fit for LOOKUP_HANDLE.

If there are no plans to go forward with LOOKUP_HANDLE, I may respin my protosal to add ENCODE/DECODE to FUSE protocol in place of the lookup(".") command.

Thanks,
Amir.

#16 lore raw
Quoted 14 lines · Amir Goldstein
Quoted 13 lines · Vivek Goyal
Quoted 12 lines · Amir Goldstein
Quoted 11 lines · Miklos Szeredi
Quoted 10 lines · Amir Goldstein
Quoted 9 lines · Miklos Szeredi
Quoted 8 lines · Amir Goldstein
Quoted 7 lines · Miklos Szeredi
Quoted 3 lines · Amir Goldstein

I think that the proper was to implement reliable persistent file handles in fuse/virtiofs would be to add ENCODE/DECODE to FUSE protocol and allow the server to handle this.

Max Reitz (Cc-d) is currently looking into this.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

Miklos, Max,

Any updates on LOOKUP_HANDLE work?

Unfortunately not :(

Quoted 76 lines
Quoted 76 lines
Quoted 76 lines
Quoted 60 lines
Quoted 60 lines
Quoted 31 lines
Quoted 13 lines
Quoted 11 lines

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups

I never ran into a local fs implementation where this was expensive.

Quoted 8 lines
Quoted 6 lines

- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Sounds good.
I suppose flock() does need to keep the open fd on server.

Open files are a separate issue and do need an active object in the server.

The issue this solves is synchronizing "released" and "evicted" states of objects between server and client. I.e. when a file is closed (and no more open files exist referencing the same object) the
dentry refcount goes to zero but it remains in the cache. In this
state the server could really evict it's own cached object, but can't because the client can gain an active reference at any time via cached path lookup.

Quoted 5 lines

One other solution would be for the server to send a notification (NOTIFY_EVICT) that would try to clean out the object from the server
cache and respond with a FORGET if successful. But I sort of like
the file handle one better, since it solves multiple problems.

Even with LOOKUP_HANDLE, I am struggling to understand how we intend to invalidate all fuse dentries referring to ino X in case the server replies with reused ino X with a different generation that the one stored in fuse inode cache.

This is an issue that I encountered when running the passthrough_hp test, on my filesystem. In tst_readdir_big() for example, underlying files are being unlinked and new files created reusing the old inode numbers.

This creates a situation where server gets a lookup request for file B that uses the reused inode number X, while old file A is still in fuse dentry cache using the older generation of real inode number X which is still in fuse inode cache.

Now the server knows that the real inode has been rused, because the server caches the old generation value, but it cannot reply to the lookup request before the old fuse inode has been invalidated. IIUC, fuse_lowlevel_notify_inval_inode() is not enough(?). We would also need to change fuse_dentry_revalidate() to detect the case of reused/invalidated inode.

The straightforward way I can think of is to store inode generation in fuse_dentry. It won't even grow the size of the struct.

Quoted 7 lines
Quoted 1 line

Am I over complicating this?

In this scheme the generation number is already embedded in the file handle. If LOOKUP_HANDLE returns a nodeid that can be found in the icache, but which doesn't match the new file handle, then the old inode will be marked bad and a new one allocated.

Does that answer your worries? Or am I missing something?

It affirms my understanding of the future implementation, but does not help my implementation without protocol changes.
I thought I could get away without LOOKUP_HANDLE for
underlying fs that is able to resolve by ino, but seems that I still have an unhandled corner case, so will need to add some kernel patch. Unless there is already a way to signal from server to make the inode bad in a synchronous manner (I did not find any) before replying to LOOKUP with a new generation of the same ino.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Any idea about the timeline for LOOKUP_HANDLE?
I may be able to pick this up myself if there is no one actively working on it or plans for anyone to make this happen.

AFAIK, right now max is not actively looking into LOOKUP_HANDLE.

To solve the issue of virtiofs server having too many fds open, he is now planning to store corresonding file handle in server and use that to open fd later.

Yes, that’s right. Initially, I had hoped these things could tie into each other, but it turns out they’re largely separate issue, so for now I’m only working on replacing our O_PATH fds by file handles.

Quoted 7 lines
Quoted 3 lines

But this does not help with persistent file handle issue for fuse client.

I see. Yes that should work, but he'd still need to cope with reused inode numbers in case you allow unlinks from the host (do you?), because LOOKUP can find a host fs inode that does not match the file handle of a previously found inode of the same ino.

That’s indeed an issue.  My current approach is to use the file handle (if available) as the key for lookups, so that the generation ID is included.

Right now, we use st_ino+st_dev+mnt_id as the key.  st_dev is just a fallback for the mount ID, basically, so what we’d really need is inode ID + generation ID + mount ID, and that’s basically the file handle + mount ID.  So different generation IDs will lead to lookup finding/creating a different inode object (lo_inode in C virtiofsd, InodeData in virtiofsd-rs), and thus returning different fuse_ino IDs to the guest.

(See also: https://gitlab.com/mreitz/virtiofsd-rs/-/blob/handles-for-inodes-v4/src/passthrough/mod.rs#L594)

Quoted 21 lines

Quoting Miklos' response above:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

If LOOKUP_HANDLE returns a nodeid that can be found in the icache, but which doesn't match the new file handle, then the old inode will be marked bad and a new one allocated.

This statement, with minor adjustments is also true for LOOKUP:

"If LOOKUP returns a nodeid that can be found in the icache, but
whose i_generation doesn't match the generation returned in outarg, then the old inode should be marked bad and a new one allocated."

Quoted 11 lines

BTW, one concern with file handles coming from guest kernel was that how to trust those handles. Guest can create anything and use file server to open the files on same filesystem (but not shared with guest).

I am assuming same concern should be there with non-virtiofs use cases. Regular fuse client must be sending a file handle and file server is running with CAP_DAC_READ_SEARCH. How will it make sure that client is not able to access files not exported through shared directory but are present on same filesystem.

Quoted 7 lines

That is a concern.
It's the same concern for NFS clients that can guess file handles.

The ways to address this concern with NFS is the export option subtree_check, but that uses non unique file handles to an inode which include a parent handle, so that's probably not a good fit for LOOKUP_HANDLE.

There was a mail thread on the topic of securing file handles in March:

https://listman.redhat.com/archives/virtio-fs/2021-March/msg00022.html

The problem I see with the subtree_check option is that file handles are invalidated when files are moved to a different parent.

So far the consensus was to append a MAC to file handles, generated with some secret key, so that only file handles that have been generated before can later be opened. Ideally, that MAC would be managed by the kernel, so that we could allow virtiofsd to use such MAC-ed file handles even when it doesn’t have CAP_DAC_READ_SEARCH.

Max

#17 lore raw
Quoted 20 lines
Quoted 7 lines
Quoted 3 lines

But this does not help with persistent file handle issue for fuse client.

I see. Yes that should work, but he'd still need to cope with reused inode numbers in case you allow unlinks from the host (do you?), because LOOKUP can find a host fs inode that does not match the file handle of a previously found inode of the same ino.

That’s indeed an issue. My current approach is to use the file handle (if available) as the key for lookups, so that the generation ID is included.

Right now, we use st_ino+st_dev+mnt_id as the key. st_dev is just a fallback for the mount ID, basically, so what we’d really need is inode ID + generation ID + mount ID, and that’s basically the file handle + mount ID. So different generation IDs will lead to lookup finding/creating a different inode object (lo_inode in C virtiofsd, InodeData in virtiofsd-rs), and thus returning different fuse_ino IDs to the guest.

Quoted 3 lines

(See also:
https://gitlab.com/mreitz/virtiofsd-rs/-/blob/handles-for-inodes-v4/src/passthrough/mod.rs#L594)

I see, because you do not require persistent inode numbers. That makes sense if you do not need to export file handles to NFS and if you are not evicting inode objects from the server inodes map.

Please keep me posted if there are any updates on LOOKUP_HANDLE.

Thanks,
Amir.

#18 lore raw

Re: Persistent FUSE file handles (Was: virtiofs uuid and file handles)

In reply to Miklos Szeredi
Quoted 14 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Quoted 9 lines

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

The purpose is "proper" NFS export support for FUSE. "proper" being survives server restart.

I realize there is an ongoing effort to use file handles in the virtiofsd instead of open fds and that LOOKUP_HANDLE could assist in that effort, but that is an added benefit.

I have a C++ implementation [1] which sort of supports persistent file handles, but not in a generic manner.

If anyone knows of any WIP on LOOKUP_HANDLE please let me know.

Thanks,
Amir.

[1] https://github.com/amir73il/libfuse/commits/fuse_passthrough

#19 lore raw

Re: Persistent FUSE file handles (Was: virtiofs uuid and file handles)

Quoted 25 lines · Amir Goldstein
Quoted 14 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Quoted 9 lines

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Quoted 5 lines

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

The purpose is "proper" NFS export support for FUSE. "proper" being survives server restart.

Wouldn't fuse just need to get struct export_operations additions to encode and decode handles?

Quoted 7 lines

I realize there is an ongoing effort to use file handles in the virtiofsd instead of open fds and that LOOKUP_HANDLE could assist in that effort, but that is an added benefit.

I have a C++ implementation [1] which sort of supports persistent file handles, but not in a generic manner.

How does this interact with exportfs?

Quoted 7 lines

If anyone knows of any WIP on LOOKUP_HANDLE please let me know.

Thanks,
Amir.

[1] https://github.com/amir73il/libfuse/commits/fuse_passthrough

Thanks,
Bernd

#20 lore raw

Re: Persistent FUSE file handles (Was: virtiofs uuid and file handles)

Quoted 29 lines · Bernd Schubert
Quoted 25 lines · Amir Goldstein
Quoted 23 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Quoted 9 lines
Quoted 5 lines

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

The purpose is "proper" NFS export support for FUSE. "proper" being survives server restart.

Wouldn't fuse just need to get struct export_operations additions to encode and decode handles?

FUSE already implements those, but not in a "proper" way, because there is nothing guaranteeing the persistence of the FUSE file handles.

As a result, when exporting some FUSE fs to NFS and the server is restarted, NFS client may read a file A and get the content of file B, because after server restart, FUSE file B got the node id that file A had before restart.

This is not a hypothetical use case, I have seen this happen.

Quoted 10 lines
Quoted 7 lines

I realize there is an ongoing effort to use file handles in the virtiofsd instead of open fds and that LOOKUP_HANDLE could assist in that effort, but that is an added benefit.

I have a C++ implementation [1] which sort of supports persistent file handles, but not in a generic manner.

How does this interact with exportfs?

It makes use of internal fs knowledge to encode/decode ext4/xfs file handles into the 64bit FUSE node id.

This sort of works, but it is not generic.

Thanks,
Amir.

#21 lore raw

Re: Persistent FUSE file handles (Was: virtiofs uuid and file handles)

Quoted 41 lines · Amir Goldstein
Quoted 29 lines · Bernd Schubert
Quoted 25 lines · Amir Goldstein
Quoted 23 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Quoted 9 lines
Quoted 5 lines

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

The purpose is "proper" NFS export support for FUSE. "proper" being survives server restart.

Wouldn't fuse just need to get struct export_operations additions to encode and decode handles?

Quoted 7 lines

FUSE already implements those, but not in a "proper" way, because there is nothing guaranteeing the persistence of the FUSE file handles.

As a result, when exporting some FUSE fs to NFS and the server is restarted, NFS client may read a file A and get the content of file B, because after server restart, FUSE file B got the node id that file A had before restart.

Sorry, right, it is just not passed through to user space. For the file systems I'm working on that doesn't work at all.

Quoted 11 lines

This is not a hypothetical use case, I have seen this happen.

Quoted 8 lines
Quoted 7 lines

I realize there is an ongoing effort to use file handles in the virtiofsd instead of open fds and that LOOKUP_HANDLE could assist in that effort, but that is an added benefit.

I have a C++ implementation [1] which sort of supports persistent file handles, but not in a generic manner.

Quoted 7 lines
Quoted 2 lines

How does this interact with exportfs?

It makes use of internal fs knowledge to encode/decode ext4/xfs file handles into the 64bit FUSE node id.

This sort of works, but it is not generic.

Hmm, I guess I need to look at it.

Thanks,
Bernd

#22 lore raw

Re: Persistent FUSE file handles (Was: virtiofs uuid and file handles)

In reply to Amir Goldstein
Quoted 20 lines · Amir Goldstein
Quoted 19 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

Quoted 7 lines
Quoted 4 lines

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

Hi Amir,

I was going throug the proposal above for LOOKUP_HANDLE and I was wondering how nodeid reuse is handled. IOW, if server decides to drop nodeid from its cache and reuse it for some other file, how will we differentiate between two. Some sort of generation id encoded in nodeid?

Quoted 3 lines

The purpose is "proper" NFS export support for FUSE. "proper" being survives server restart.

Sounds like a good enhancement.

Quoted 4 lines

I realize there is an ongoing effort to use file handles in the virtiofsd instead of open fds and that LOOKUP_HANDLE could assist in that effort, but that is an added benefit.

Using file handles (instead of keeping O_PATH fds open), is now available in virtriofsd. (option --inode-file-handles). Thanks to Hanna for this work.

https://gitlab.com/virtio-fs/virtiofsd/-/blob/main/README.md

With LOOKUP_HANDLE implemented, we can afford to implement a mixed approach where we can keep O_PATH fd open but if there are too many fds open, then close some of these fds. So this is sort of hybrid approach between fd and file handles.

Quoted 5 lines

I have a C++ implementation [1] which sort of supports persistent file handles, but not in a generic manner.

If anyone knows of any WIP on LOOKUP_HANDLE please let me know.

I am not aware of any. Will be good if you make it happen upstream :-)

Thanks
Vivek

Quoted 6 lines

Thanks,
Amir.

[1] https://github.com/amir73il/libfuse/commits/fuse_passthrough

#23 lore raw

Re: Persistent FUSE file handles (Was: virtiofs uuid and file handles)

Quoted 27 lines · Vivek Goyal
Quoted 25 lines · Amir Goldstein
Quoted 23 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

Quoted 7 lines
Quoted 2 lines

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

Hi Amir,

I was going throug the proposal above for LOOKUP_HANDLE and I was wondering how nodeid reuse is handled.

LOOKUP_HANDLE extends the 64bit node id to be variable size id. A server that declares support for LOOKUP_HANDLE must never reuse a handle.

That's the basic idea. Just as a filesystem that declares to support exportfs must never reuse a file handle.

Quoted 5 lines

IOW, if server decides to drop
nodeid from its cache and reuse it for some other file, how will we differentiate between two. Some sort of generation id encoded in nodeid?

That's usually the way that file handles are implemented in local fs. The inode number is the internal lookup index and the generation part is advanced on reuse.

But for passthrough fs like virtiofsd, the LOOKUP_HANDLE will just use the native fs file handles, so virtiofsd can evict the inodes entry from its cache completely, not only close the open fds.

That is what my libfuse_passthough POC does.

Thanks,
Amir.

#24 lore raw

Re: Persistent FUSE file handles (Was: virtiofs uuid and file handles)

Quoted 31 lines · Amir Goldstein
Quoted 30 lines · Vivek Goyal
Quoted 27 lines · Amir Goldstein
Quoted 14 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Quoted 9 lines

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

Quoted 6 lines
Quoted 4 lines

Hi Amir,

I was going throug the proposal above for LOOKUP_HANDLE and I was wondering how nodeid reuse is handled.

LOOKUP_HANDLE extends the 64bit node id to be variable size id.

Ok. So this variable size id is basically file handle returned by host?

So this looks little different from what Miklos had suggested. IIUC, he wanted LOOKUP_HANDLE to return both file handle as well as *node id*.

*********************************
One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.
***************************************

Quoted 13 lines

A server that declares support for LOOKUP_HANDLE must never reuse a handle.

That's the basic idea. Just as a filesystem that declares to support exportfs must never reuse a file handle.

Quoted 5 lines

IOW, if server decides to drop
nodeid from its cache and reuse it for some other file, how will we differentiate between two. Some sort of generation id encoded in nodeid?

Quoted 7 lines

That's usually the way that file handles are implemented in local fs. The inode number is the internal lookup index and the generation part is advanced on reuse.

But for passthrough fs like virtiofsd, the LOOKUP_HANDLE will just use the native fs file handles, so virtiofsd can evict the inodes entry from its cache completely, not only close the open fds.

Ok, got it. Will be interesting to see how kernel fuse changes look to accomodate this variable sized nodeid.

Quoted 2 lines

That is what my libfuse_passthough POC does.

Where have you hosted corresponding kernel changes?

Thanks
Vivek

#25 lore raw

Re: Persistent FUSE file handles (Was: virtiofs uuid and file handles)

Quoted 46 lines · Vivek Goyal
Quoted 31 lines · Amir Goldstein
Quoted 30 lines · Vivek Goyal
Quoted 27 lines · Amir Goldstein
Quoted 14 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Quoted 9 lines

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

Quoted 6 lines
Quoted 4 lines

Hi Amir,

I was going throug the proposal above for LOOKUP_HANDLE and I was wondering how nodeid reuse is handled.

LOOKUP_HANDLE extends the 64bit node id to be variable size id.

Ok. So this variable size id is basically file handle returned by host?

So this looks little different from what Miklos had suggested. IIUC, he wanted LOOKUP_HANDLE to return both file handle as well as *node id*.

Quoted 7 lines

*********************************
One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.
***************************************

Ha! Thanks for reminding me about that.
It's been a while since I looked at what actually needs to be done. That means that evicting server inodes from cache may not be as easy as I had imagined.

Quoted 17 lines
Quoted 17 lines

A server that declares support for LOOKUP_HANDLE must never reuse a handle.

That's the basic idea. Just as a filesystem that declares to support exportfs must never reuse a file handle.

Quoted 5 lines

IOW, if server decides to drop
nodeid from its cache and reuse it for some other file, how will we differentiate between two. Some sort of generation id encoded in nodeid?

That's usually the way that file handles are implemented in local fs. The inode number is the internal lookup index and the generation part is advanced on reuse.

Quoted 7 lines
Quoted 3 lines

But for passthrough fs like virtiofsd, the LOOKUP_HANDLE will just use the native fs file handles, so virtiofsd can evict the inodes entry from its cache completely, not only close the open fds.

Ok, got it. Will be interesting to see how kernel fuse changes look to accomodate this variable sized nodeid.

It may make sense to have a FUSE protocol dialect where nodeid is variable size for all commands, but it probably won't be part of the initial LOOKUP_HANDLE work.

Quoted 5 lines
Quoted 2 lines

That is what my libfuse_passthough POC does.

Where have you hosted corresponding kernel changes?

There are no kernel changes.

For xfs and ext4 I know how to implement open_by_ino() and I know how to parse the opaque fs file handle to extract ino+generation from it and return them in FUSE_LOOKUP response.

So I could manage to implement persistent NFS file handles over the existing FUSE protocol with 64bit node id.

Thanks,
Amir.

#26 lore raw

Re: Persistent FUSE file handles (Was: virtiofs uuid and file handles)

Quoted 95 lines · Amir Goldstein
Quoted 46 lines · Vivek Goyal
Quoted 31 lines · Amir Goldstein
Quoted 30 lines · Vivek Goyal
Quoted 27 lines · Amir Goldstein
Quoted 14 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Quoted 9 lines

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

Quoted 6 lines
Quoted 4 lines

Hi Amir,

I was going throug the proposal above for LOOKUP_HANDLE and I was wondering how nodeid reuse is handled.

LOOKUP_HANDLE extends the 64bit node id to be variable size id.

Ok. So this variable size id is basically file handle returned by host?

So this looks little different from what Miklos had suggested. IIUC, he wanted LOOKUP_HANDLE to return both file handle as well as *node id*.

Quoted 7 lines

*********************************
One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.
***************************************

Ha! Thanks for reminding me about that.
It's been a while since I looked at what actually needs to be done. That means that evicting server inodes from cache may not be as easy as I had imagined.

Quoted 17 lines
Quoted 17 lines

A server that declares support for LOOKUP_HANDLE must never reuse a handle.

That's the basic idea. Just as a filesystem that declares to support exportfs must never reuse a file handle.

Quoted 5 lines

IOW, if server decides to drop
nodeid from its cache and reuse it for some other file, how will we differentiate between two. Some sort of generation id encoded in nodeid?

That's usually the way that file handles are implemented in local fs. The inode number is the internal lookup index and the generation part is advanced on reuse.

Quoted 7 lines
Quoted 3 lines

But for passthrough fs like virtiofsd, the LOOKUP_HANDLE will just use the native fs file handles, so virtiofsd can evict the inodes entry from its cache completely, not only close the open fds.

Ok, got it. Will be interesting to see how kernel fuse changes look to accomodate this variable sized nodeid.

It may make sense to have a FUSE protocol dialect where nodeid is variable size for all commands, but it probably won't be part of the initial LOOKUP_HANDLE work.

Quoted 5 lines
Quoted 2 lines

That is what my libfuse_passthough POC does.

Where have you hosted corresponding kernel changes?

Quoted 6 lines

There are no kernel changes.

For xfs and ext4 I know how to implement open_by_ino() and I know how to parse the opaque fs file handle to extract ino+generation from it and return them in FUSE_LOOKUP response.

Aha, interesting. So is this filesystem specific. Works on xfs/ext4 but not necessarily on other filesystems like nfs. (Because they have their own way of encoding things in file handle).

Quoted 3 lines

So I could manage to implement persistent NFS file handles over the existing FUSE protocol with 64bit node id.

And that explains that why you did not have to make kernel changes. But this does not allow sever to close the fd associate with nodeid? Or there is a way for server to generate file handle and then call open_by_handle_at().

Thanks
Vivek

#27 lore raw

Re: Persistent FUSE file handles (Was: virtiofs uuid and file handles)

Quoted 99 lines · Vivek Goyal
Quoted 97 lines · Amir Goldstein
Quoted 46 lines · Vivek Goyal
Quoted 31 lines · Amir Goldstein
Quoted 30 lines · Vivek Goyal
Quoted 27 lines · Amir Goldstein
Quoted 14 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Quoted 9 lines

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

Quoted 6 lines
Quoted 4 lines

Hi Amir,

I was going throug the proposal above for LOOKUP_HANDLE and I was wondering how nodeid reuse is handled.

LOOKUP_HANDLE extends the 64bit node id to be variable size id.

Ok. So this variable size id is basically file handle returned by host?

So this looks little different from what Miklos had suggested. IIUC, he wanted LOOKUP_HANDLE to return both file handle as well as *node id*.

Quoted 7 lines

*********************************
One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.
***************************************

Ha! Thanks for reminding me about that.
It's been a while since I looked at what actually needs to be done. That means that evicting server inodes from cache may not be as easy as I had imagined.

Quoted 17 lines
Quoted 17 lines

A server that declares support for LOOKUP_HANDLE must never reuse a handle.

That's the basic idea. Just as a filesystem that declares to support exportfs must never reuse a file handle.

Quoted 5 lines

IOW, if server decides to drop
nodeid from its cache and reuse it for some other file, how will we differentiate between two. Some sort of generation id encoded in nodeid?

That's usually the way that file handles are implemented in local fs. The inode number is the internal lookup index and the generation part is advanced on reuse.

Quoted 7 lines
Quoted 3 lines

But for passthrough fs like virtiofsd, the LOOKUP_HANDLE will just use the native fs file handles, so virtiofsd can evict the inodes entry from its cache completely, not only close the open fds.

Ok, got it. Will be interesting to see how kernel fuse changes look to accomodate this variable sized nodeid.

It may make sense to have a FUSE protocol dialect where nodeid is variable size for all commands, but it probably won't be part of the initial LOOKUP_HANDLE work.

Quoted 5 lines
Quoted 2 lines

That is what my libfuse_passthough POC does.

Where have you hosted corresponding kernel changes?

There are no kernel changes.

Quoted 8 lines
Quoted 4 lines

For xfs and ext4 I know how to implement open_by_ino() and I know how to parse the opaque fs file handle to extract ino+generation from it and return them in FUSE_LOOKUP response.

Aha, interesting. So is this filesystem specific. Works on xfs/ext4 but not necessarily on other filesystems like nfs. (Because they have their own way of encoding things in file handle).

Correct.
If it is not xfs/ext4, the passthrough implementation uses open fds. In the non xfs/ext4 case, an NFS client may get ESTALE errors after server restart and worse - get the content of the wrong object if server has reused nodeid+genration after restart.

Quoted 10 lines
Quoted 4 lines

So I could manage to implement persistent NFS file handles over the existing FUSE protocol with 64bit node id.

And that explains that why you did not have to make kernel changes. But this does not allow sever to close the fd associate with nodeid? Or there is a way for server to generate file handle and then call open_by_handle_at().

Yes, that's what the server does in case of ext4/xfs:
https://github.com/amir73il/libfuse/blob/fuse_passthrough/passthrough/fuse_passthrough.cpp#L912

Thanks,
Amir.

#28 lore raw

Re: LOOKUP_HANDLE and FUSE passthrough (was: Persistent FUSE file handles)

In reply to Amir Goldstein
Quoted 21 lines · Amir Goldstein
Quoted 19 lines · Miklos Szeredi

One proposal was to add LOOKUP_HANDLE operation that is similar to LOOKUP except it takes a {variable length handle, name} as input and returns a variable length handle *and* a u64 node_id that can be used normally for all other operations.

The advantage of such a scheme for virtio-fs (and possibly other fuse based fs) would be that userspace need not keep a refcounted object around until the kernel sends a FORGET, but can prune its node ID
based cache at any time. If that happens and a request from the
client (kernel) comes in with a stale node ID, the server will return -ESTALE and the client can ask for a new node ID with a special lookup_handle(fh, NULL).

Disadvantages being:

- cost of generating a file handle on all lookups
- cost of storing file handle in kernel icache

Quoted 8 lines
Quoted 4 lines

I don't think either of those are problematic in the virtiofs case. The cost of having to keep fds open while the client has them in its cache is much higher.

I was thinking of taking a stab at LOOKUP_HANDLE for a generic implementation of persistent file handles for FUSE.

Hi Miklos,

I circled back to this. I don't suppose you know of any patches in the works?

I was thinking about LOOKUP_HANDLE in the context of our discussion at Plumbers on readdirplus passthrough.

What we discussed is that kernel could instantiate some FUSE inodes (populated during readdirplus passthrough) and at some later time, kernel will notify server about those inodes via FUSE_INSTANTIATE or similar command, which will instantiate a fuse server inode with pre-defined nodeid.

My thinking was to simplify a bit and require a 1-to-1 mapping of kernel-server inode numbers to enable the feature of FUSE_PASSTHOUGH_INODE (operations), meaning that every FUSE inode has at least a potential backing inode which reserves its inode number.

But I think that 1-to-1 mapping of ino is not enough and to avoid races it is better to have 1-to-1 mapping of file handles so FUSE_INSTANTIATE would look a bit like LOOKUP_HANDLE but "found" server inode must match the kernel's file handle.

Is any of this making any sense to you?
Do you think that the 1-to-1 ino mapping restriction is acceptable for the first version of inode operations passthrough?

Thanks,
Amir.

#29 lore raw

Re: LOOKUP_HANDLE and FUSE passthrough (was: Persistent FUSE file handles)

Quoted 2 lines · Amir Goldstein

I circled back to this. I don't suppose you know of any patches in the works?

I'm not aware of any.

Quoted 15 lines

I was thinking about LOOKUP_HANDLE in the context of our discussion at Plumbers on readdirplus passthrough.

What we discussed is that kernel could instantiate some FUSE inodes (populated during readdirplus passthrough) and at some later time, kernel will notify server about those inodes via FUSE_INSTANTIATE or similar command, which will instantiate a fuse server inode with pre-defined nodeid.

My thinking was to simplify a bit and require a 1-to-1 mapping of kernel-server inode numbers to enable the feature of FUSE_PASSTHOUGH_INODE (operations), meaning that every FUSE inode has at least a potential backing inode which reserves its inode number.

Quoted 6 lines

But I think that 1-to-1 mapping of ino is not enough and to avoid races it is better to have 1-to-1 mapping of file handles so FUSE_INSTANTIATE would look a bit like LOOKUP_HANDLE but "found" server inode must match the kernel's file handle.

Is any of this making any sense to you?

Not yet. I remember you explaining why FUSE_INSTANTIATE is needed, but I don't really remember.

Can you please remind me how exactly you envision readdir/lookup passthrough?

Thanks,
Miklos

#30 lore raw

Re: LOOKUP_HANDLE and FUSE passthrough (was: Persistent FUSE file handles)

Quoted 29 lines · Miklos Szeredi
Quoted 2 lines · Amir Goldstein

I circled back to this. I don't suppose you know of any patches in the works?

I'm not aware of any.

Quoted 20 lines

I was thinking about LOOKUP_HANDLE in the context of our discussion at Plumbers on readdirplus passthrough.

What we discussed is that kernel could instantiate some FUSE inodes (populated during readdirplus passthrough) and at some later time, kernel will notify server about those inodes via FUSE_INSTANTIATE or similar command, which will instantiate a fuse server inode with pre-defined nodeid.

My thinking was to simplify a bit and require a 1-to-1 mapping of kernel-server inode numbers to enable the feature of FUSE_PASSTHOUGH_INODE (operations), meaning that every FUSE inode has at least a potential backing inode which reserves its inode number.

But I think that 1-to-1 mapping of ino is not enough and to avoid races it is better to have 1-to-1 mapping of file handles so FUSE_INSTANTIATE would look a bit like LOOKUP_HANDLE but "found" server inode must match the kernel's file handle.

Quoted 7 lines
Quoted 1 line

Is any of this making any sense to you?

Not yet. I remember you explaining why FUSE_INSTANTIATE is needed, but I don't really remember.

Can you please remind me how exactly you envision readdir/lookup passthrough?

- readdirplus passthrough iterates on backing dir inode and populates fuse inodes with nodeid that is taken from backing dir's children ino (hence 1-to-1 mapping from all backing inodes to fuse ino/nodeid)
- stat()/getattr() on those children is served directly from backing inodes
- Let's call one those kernel instantiated child inodes C1
- Before any fuse command is sent to server with nodeid C1, server needs to be notified about the entry that only the kernel knows about
- kernel could send a regular LOOKUP for the child and expect to get a nodeid from the server that is matching C1 or mark the inode bad

Open questions:
1. Is a regular LOOKUP appropriate here or if this needs to be a new INSTANTIATE command which tells the server about the C1 nodeid.
2. Does this need to be a LOOKUP_HANDLE command to verify that not only the server's child has the same ino as the kernel's child but also that they have the same file handle.
3. What is the proper API for binding a backing id to a fuse inode regardless of readdirplus?
Extend the regular LOOKUP out args?
Require LOOKUP_HANDLE and use its out args?
4. When a child fuse inode is instantiated via readdirplus passthrough it automatically passthrough getattr(). What about other inode ops? are they decided only after the response of LOOKUP/INSTANTIATE?
5. Does this response need to reaffirm the binding to the backing inode and if not, association is broken and getattr passthrough is stopped?

I have a WIP branch [1] with some of the concepts implemented. only compile tested!

Thanks,
Amir.

[1] https://github.com/amir73il/linux/commits/fuse-backing-inode-wip/

#31 lore raw

Re: LOOKUP_HANDLE and FUSE passthrough (was: Persistent FUSE file handles)

Quoted 3 lines · Amir Goldstein

- readdirplus passthrough iterates on backing dir inode and populates fuse inodes with nodeid that is taken from backing dir's children ino (hence 1-to-1 mapping from all backing inodes to fuse ino/nodeid)

If nodeid == st_ino, then in theory no LOOKUP is needed, the kernel can just assume that the fuse server can look up the object based on st_ino. The problem with that is: looking up by st_ino can only be done by doing a complete scan of the filesystem, which is often not practical.

Quoted 6 lines

- stat()/getattr() on those children is served directly from backing inodes
- Let's call one those kernel instantiated child inodes C1
- Before any fuse command is sent to server with nodeid C1, server needs to be notified about the entry that only the kernel knows about
- kernel could send a regular LOOKUP for the child and expect to get a nodeid from the server that is matching C1 or mark the inode bad

A regular LOOKUP assumes that the parent is already known by the server. Of course, this could be done recursively up to the fs root, but it looks really tricky due to locking assumptions.

Quoted 4 lines

Open questions:
1. Is a regular LOOKUP appropriate here or if this needs to be a new INSTANTIATE command which tells the server about the C1 nodeid.

How would this INSTANTIATE work? Telling the server about the nodeid
won't help, it has the same problems as if the server was just using the nodeid (st_ino) directly.

Quoted 3 lines

2. Does this need to be a LOOKUP_HANDLE command to verify that not only the server's child has the same ino as the kernel's child but also that they have the same file handle.

Hmm, you mean the kernel queries the backing inode's fh, then sends a LOOKUP_HANDLE with that fh?

I guess that might work.

Quoted 3 lines

3. What is the proper API for binding a backing id to a fuse inode regardless of readdirplus?
Extend the regular LOOKUP out args?

Yes, this is how I'd imagine this (which doesn't mean it's the best option).

Quoted 6 lines

Require LOOKUP_HANDLE and use its out args?
4. When a child fuse inode is instantiated via readdirplus passthrough it automatically passthrough getattr(). What about other inode ops? are they decided only after the response of LOOKUP/INSTANTIATE?
5. Does this response need to reaffirm the binding to the backing inode and if not, association is broken and getattr passthrough is stopped?

I don't know. It would be good to see what this will be used for.

Quoted 3 lines

I have a WIP branch [1] with some of the concepts implemented. only compile tested!

Will have a look...

Thanks,
Miklos

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAOQ4uxjp6NpF_Q0QqUTzE5=YiKz9w6JbUVyROG+rNFcHPAThFg@mail.gmail.com

#34 lore raw

Re: Copying overlayfs directories with index=on

Hi, I've sent a patch which is trying to acheive what Amir had suggested. Please take a look:

[PATCH] ovl: introduce new "index=nouuid" option for inodes index feature

Quoted 31 lines · Amir Goldstein
Quoted 10 lines · Vivek Goyal

On Tue, Sep 22, 2020 at 02:15:55PM +0300, Amir Goldstein wrote:

[..]

Quoted 5 lines

No objection, but if I were you I wouldn't bother re-writing new ovl_fh. If you know you don't care about matching uuid in the first place, it is better to add a mount option to overlayfs 'index=nouuid' to relax the uuid comparison check for ovl_fh.

Quoted 7 lines

So is it possible that somebody uses "nouuid" and then a different file got same file handle (as stored in upper). I think that's one issue you were worried about while addressing squashfs fix. IIRC, Miklos had said with-in same filesystem it will not happen and across filesystems sb->uuid check will ensure this does not happen. IOW, "nouuid" will open the possibility of upper file handle matching a different file?

Well, to be accurate, I did write that when cloning a base lower fs (like with dm-thinp) the problem reported with re-created lower squashfs still exists but that it is a corner case [1].

But what I suggested is that index=nouuid will only be allowed for all layers on the same fs, where this is not a problem.

Thanks,
Amir.

[1] https://lore.kernel.org/linux-unionfs/CAOQ4uxiq7hkaew4LoFZkf4R73iH_pU7OHOriycLCnnywtA0O0w@mail.gmail.com/

Signature · 2 lines
Best regards, Tikhomirov Pavel
Software Developer, Virtuozzo.