Inotify support in FUSE and virtiofs
Subsystems (5)
cover Inotify support in FUSE and virtiofs
Hello,
I am a PhD student currently interning at Red Hat and working on the virtiofs file system. I am trying to add support for the Inotify notification subsystem in virtiofs. I seek your feedback and suggestions on what is the right direction to take.
Currently, virtiofs does not support the Inotify API and there are applications which look for the Inotify support in virtiofs (e.g., Kata containers).
However, all the event notification subsystems (Dnotify/Inotify/Fanotify) are supported by only by local kernel file systems.
--Proposed solution
With this RFC patch we add the inotify support to the FUSE kernel module so that the remote virtiofs file system (based on FUSE) used by a QEMU guest VM can make use of this feature.
Specifically, we enhance FUSE to add/modify/delete watches on the FUSE server and also receive remote inotify events. To achieve this we modify the fsnotify subsystem so that it calls specific hooks in FUSE when a remote watch is added/modified/deleted and FUSE calls into fsnotify when a remote event is received to send the event to user space.
In our case the FUSE server is virtiofsd.
We also considered an out of band approach for implementing the remote notifications (e.g., FAM, Gamin), however this approach would break applications that are already compatible with inotify, and thus would require an update.
These kernel patches depend on the patch series posted by Vivek Goyal:
https://lore.kernel.org/linux-fsdevel/[email protected]/
My PoC Linux kernel patches are here:
https://github.com/iangelak/linux/commits/inotify_v1
My PoC virtiofsd corresponding patches are here:
https://github.com/iangelak/qemu/commits/inotify_v1
--Advantages
1) Our approach is compatible with existing applications that rely on Inotify, thus improves portability.
2) Everything is implemented in one place (virtiofs and virtiofsd) and there is no need to run additional processes (daemons) specifically to handle the remote notifications.
--Weaknesses
1) Both a local (QEMU guest) and a remote (Host/Virtiofsd) watch on the target inode have to be active at the same time. The local watch guarantees that events are going to be sent to the guest user space while the remote watch captures events occurring on the host (and will be sent to the guest).
As a result, when an event occures on a inode within the exported directory by virtiofs, two events will be generated at the same time; a local event (generated by the guest kernel) and a remote event (generated by the host), thus the guest will receive duplicate events.
To account for this issue we implemented two modes; one where local events function as expected (when virtiofsd does not support the remote inotify) and one where the local events are suppressed and only the remote events originating from the host side are let through (when virtiofsd supports the remote inotify).
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest does not receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the watch). In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the guest kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore). On top of that, virtiofsd keeps an open proc file descriptor for each inode that is not immediately closed on a inode deletion request by the guest. As a result no IN_DELETE_SELF is generated by virtiofsd and sent to the guest kernel in this case.
4) Because virtiofsd implements additional operations during the servicing of a request from the guest, additional inotify events might be generated and sent to the guest other than the ones the guest expects. However, this is not technically a limitation and it is dependent on the implementation of the remote file system server (in this case virtiofsd).
5) The current implementation only supports Inotify, due to its simplicity and not Fanotify. Fanotify's complexity requires support from virtiofsd that is not currently available. One such example is Fsnotify's access permission decision capabilities, which could conflict with virtiofsd's current access permission implementation.
Ioannis Angelakopoulos (7):
FUSE: Add the fsnotify opcode and in/out structs to FUSE
FUSE: Add the remote inotify support capability to FUSE FUSE,Inotify,Fsnotify,VFS: Add the fuse_fsnotify_update_mark inode
operation
FUSE: Add the fuse_fsnotify_send_request to FUSE
Fsnotify: Add a wrapper around the fsnotify function FUSE,Fsnotify: Add the fuse_fsnotify_event inode operation
virtiofs: Add support for handling the remote fsnotify notifications
fs/fuse/dev.c | 37 ++++++++++++++++++ fs/fuse/dir.c | 56 ++++++++++++++++++++++++++++ fs/fuse/fuse_i.h | 10 +++++ fs/fuse/inode.c | 6 +++ fs/fuse/virtio_fs.c | 64 +++++++++++++++++++++++++++++++- fs/notify/fsnotify.c | 35 ++++++++++++++++- fs/notify/inotify/inotify_user.c | 11 ++++++ fs/notify/mark.c | 10 +++++ include/linux/fs.h | 5 +++ include/linux/fsnotify_backend.h | 14 ++++++- include/uapi/linux/fuse.h | 23 +++++++++++- 11 files changed, 265 insertions(+), 6 deletions(-)
Signature · 1 line
2.33.0
RFC PATCH 1/7 FUSE: Add the fsnotify opcode and in/out structs to FUSE
Since fsnotify is the backend for the inotify subsystem all the backend code implementation we add is related to fsnotify.
To support an fsnotify request in FUSE and specifically virtiofs we add a new opcode for the FSNOTIFY (51) operation request in the "fuse.h" header.
Also add the "fuse_notify_fsnotify_in" and "fuse_notify_fsnotify_out" structs that are responsible for passing the fsnotify/inotify related data to and from the FUSE server.
--- include/uapi/linux/fuse.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
include/uapi/linux/fuse.h +22 -1
@@ -186,6 +186,9 @@* - add FUSE_SYNCFS * 7.35 * - add FUSE_NOTIFY_LOCK +* 7.36 +* - add FUSE_HAVE_FSNOTIFY +* - add fuse_notify_fsnotify_(in,out) */ #ifndef _LINUX_FUSE_H
@@ -221,7 +224,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 35 +#define FUSE_KERNEL_MINOR_VERSION 36/** The node ID of the root inode */ #define FUSE_ROOT_ID 1
@@ -338,6 +341,7 @@ struct fuse_file_lock {* write/truncate sgid is killed only if file has group * execute permission. (Same as Linux VFS behavior). * FUSE_SETXATTR_EXT: Server supports extended struct fuse_setxattr_in +* FUSE_HAVE_FSNOTIFY: remote fsnotify/inotify event subsystem support */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)
@@ -369,6 +373,7 @@ struct fuse_file_lock {#define FUSE_SUBMOUNTS (1 << 27)#define FUSE_HANDLE_KILLPRIV_V2 (1 << 28)#define FUSE_SETXATTR_EXT (1 << 29) +#define FUSE_HAVE_FSNOTIFY (1 << 30)/** * CUSE INIT request/reply flags
@@ -515,6 +520,7 @@ enum fuse_opcode {FUSE_SETUPMAPPING =48 ,FUSE_REMOVEMAPPING =49 ,FUSE_SYNCFS =50 , +FUSE_FSNOTIFY =51 ,/* CUSE specific operations */ CUSE_INIT = 4096,
@@ -532,6 +538,7 @@ enum fuse_notify_code {FUSE_NOTIFY_RETRIEVE =5 ,FUSE_NOTIFY_DELETE =6 ,FUSE_NOTIFY_LOCK =7 , +FUSE_NOTIFY_FSNOTIFY =8 , FUSE_NOTIFY_CODE_MAX, };
@@ -571,6 +578,20 @@ struct fuse_getattr_in {uint64_t fh; }; +struct fuse_notify_fsnotify_out { +uint64_t inode; +uint64_t mask; +uint32_t namelen; +uint32_t cookie; +}; + +struct fuse_notify_fsnotify_in { +uint64_t mask; +uint64_t group; +uint32_t action; +uint32_t padding; +}; +#define FUSE_COMPAT_ATTR_OUT_SIZE 96struct fuse_attr_out {
Signature · 1 line
2.33.0
Amir Goldstein
reviewerRe: [RFC PATCH 1/7] FUSE: Add the fsnotify opcode and in/out structs to FUSE
Quoted 72 lines · Ioannis Angelakopoulos
Since fsnotify is the backend for the inotify subsystem all the backend code implementation we add is related to fsnotify.
To support an fsnotify request in FUSE and specifically virtiofs we add a new opcode for the FSNOTIFY (51) operation request in the "
fuse.h" header.Also add the "
fuse_notify_fsnotify_in" and "fuse_notify_fsnotify_out" structs that are responsible for passing the fsnotify/inotify related data to and from the FUSE server.Signed-off-by Ioannis Angelakopoulos <[email protected]>--- include/uapi/linux/fuse.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)include/uapi/linux/fuse.h +8
-1@@ -186,6 +186,9 @@* - add FUSE_SYNCFS * 7.35 * - add FUSE_NOTIFY_LOCK +* 7.36 +* - add FUSE_HAVE_FSNOTIFY +* - add fuse_notify_fsnotify_(in,out) */ #ifndef _LINUX_FUSE_H@@ -221,7 +224,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 35 +#define FUSE_KERNEL_MINOR_VERSION 36/** The node ID of the root inode */ #define FUSE_ROOT_ID 1@@ -338,6 +341,7 @@ struct fuse_file_lock {* write/truncate sgid is killed only if file has group * execute permission. (Same as Linux VFS behavior). * FUSE_SETXATTR_EXT: Server supports extended struct fuse_setxattr_in +* FUSE_HAVE_FSNOTIFY: remote fsnotify/inotify event subsystem support */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)@@ -369,6 +373,7 @@ struct fuse_file_lock {#define FUSE_SUBMOUNTS (1 << 27)#define FUSE_HANDLE_KILLPRIV_V2 (1 << 28)#define FUSE_SETXATTR_EXT (1 << 29) +#define FUSE_HAVE_FSNOTIFY (1 << 30)/** * CUSE INIT request/reply flags @@ -515,6 +520,7 @@ enum fuse_opcode {FUSE_SETUPMAPPING =48 ,FUSE_REMOVEMAPPING =49 ,FUSE_SYNCFS =50 , +FUSE_FSNOTIFY =51 ,/* CUSE specific operations */ CUSE_INIT = 4096,@@ -532,6 +538,7 @@ enum fuse_notify_code {FUSE_NOTIFY_RETRIEVE =5 ,FUSE_NOTIFY_DELETE =6 ,FUSE_NOTIFY_LOCK =7 , +FUSE_NOTIFY_FSNOTIFY =8 , FUSE_NOTIFY_CODE_MAX, };
include/uapi/linux/fuse.h struct fuse_getattr_in { · line 582
Quoted 5 lines
include/uapi/linux/fuse.h +2
-0@@ -571,6 +578,20 @@ struct fuse_getattr_in {uint64_t fh; }; +struct fuse_notify_fsnotify_out { +uint64_t inode;
64bit inode is not a good unique identifier of the object. you need to either include the generation in object identifier or much better use the object's nfs file handle, the same way that fanotify stores object identifiers.
include/uapi/linux/fuse.h struct fuse_getattr_in { · line 585
Quoted 3 lines
include/uapi/linux/fuse.h +3
-0+uint64_t mask; +uint32_t namelen; +uint32_t cookie;
I object to persisting with the two-events-joined-by-cookie design. Any new design should include a single event for rename with information about src and dst.
I know this is inconvenient, but we are NOT going to create a "remote inotify" interface, we need to create a "remote fsnotify" interface and if server wants to use inotify, it will need to join the disjoined MOVE_FROM/TO event into a single "remote event", that FUSE will use to call fsnotify_move().
Thanks,
Amir.
Amir Goldstein
reviewerRe: [RFC PATCH 1/7] FUSE: Add the fsnotify opcode and in/out structs to FUSE
Quoted 90 lines · Amir Goldstein
Quoted 72 lines · Ioannis Angelakopoulos
Since fsnotify is the backend for the inotify subsystem all the backend code implementation we add is related to fsnotify.
To support an fsnotify request in FUSE and specifically virtiofs we add a new opcode for the FSNOTIFY (51) operation request in the "
fuse.h" header.Also add the "
fuse_notify_fsnotify_in" and "fuse_notify_fsnotify_out" structs that are responsible for passing the fsnotify/inotify related data to and from the FUSE server.Signed-off-by Ioannis Angelakopoulos <[email protected]>--- include/uapi/linux/fuse.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)include/uapi/linux/fuse.h +8
-1@@ -186,6 +186,9 @@* - add FUSE_SYNCFS * 7.35 * - add FUSE_NOTIFY_LOCK +* 7.36 +* - add FUSE_HAVE_FSNOTIFY +* - add fuse_notify_fsnotify_(in,out) */ #ifndef _LINUX_FUSE_H@@ -221,7 +224,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 35 +#define FUSE_KERNEL_MINOR_VERSION 36/** The node ID of the root inode */ #define FUSE_ROOT_ID 1@@ -338,6 +341,7 @@ struct fuse_file_lock {* write/truncate sgid is killed only if file has group * execute permission. (Same as Linux VFS behavior). * FUSE_SETXATTR_EXT: Server supports extended struct fuse_setxattr_in +* FUSE_HAVE_FSNOTIFY: remote fsnotify/inotify event subsystem support */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)@@ -369,6 +373,7 @@ struct fuse_file_lock {#define FUSE_SUBMOUNTS (1 << 27)#define FUSE_HANDLE_KILLPRIV_V2 (1 << 28)#define FUSE_SETXATTR_EXT (1 << 29) +#define FUSE_HAVE_FSNOTIFY (1 << 30)/** * CUSE INIT request/reply flags @@ -515,6 +520,7 @@ enum fuse_opcode {FUSE_SETUPMAPPING =48 ,FUSE_REMOVEMAPPING =49 ,FUSE_SYNCFS =50 , +FUSE_FSNOTIFY =51 ,/* CUSE specific operations */ CUSE_INIT = 4096,@@ -532,6 +538,7 @@ enum fuse_notify_code {FUSE_NOTIFY_RETRIEVE =5 ,FUSE_NOTIFY_DELETE =6 ,FUSE_NOTIFY_LOCK =7 , +FUSE_NOTIFY_FSNOTIFY =8 , FUSE_NOTIFY_CODE_MAX, };include/uapi/linux/fuse.h struct fuse_getattr_in { · line 582
Quoted 5 lines
include/uapi/linux/fuse.h +2
-0@@ -571,6 +578,20 @@ struct fuse_getattr_in {uint64_t fh; }; +struct fuse_notify_fsnotify_out { +uint64_t inode;64bit inode is not a good unique identifier of the object. you need to either include the generation in object identifier or much better use the object's nfs file handle, the same way that fanotify stores object identifiers.
include/uapi/linux/fuse.h struct fuse_getattr_in { · line 585
Quoted 3 lines
include/uapi/linux/fuse.h +3
-0+uint64_t mask; +uint32_t namelen; +uint32_t cookie;
Quoted 9 lines
I object to persisting with the two-events-joined-by-cookie design. Any new design should include a single event for rename with information about src and dst.
I know this is inconvenient, but we are NOT going to create a "remote inotify" interface, we need to create a "remote fsnotify" interface and if server wants to use inotify, it will need to join the disjoined MOVE_FROM/TO event into a single "remote event", that FUSE will use to call
fsnotify_move().
TBH, the disjoint vs. joint from/to event is an unfinished business for fanotify.
So my objection above is more of a strong wish.
But I admit that if existing network protocols already encode the disjoint from/to events semantics, I may need to fold back on that objection.
Thanks,
Amir.
Re: [Virtio-fs] [RFC PATCH 1/7] FUSE: Add the fsnotify opcode and in/out structs to FUSE
In reply to Amir GoldsteinQuoted 80 lines · Amir Goldstein
Quoted 6 lines · Ioannis Angelakopoulos
Since fsnotify is the backend for the inotify subsystem all the backend code implementation we add is related to fsnotify.
To support an fsnotify request in FUSE and specifically virtiofs we add a new opcode for the FSNOTIFY (51) operation request in the "
fuse.h"header.
Quoted 3 lines
Also add the "
fuse_notify_fsnotify_in" and "fuse_notify_fsnotify_out" structs that are responsible for passing the fsnotify/inotify relateddata
Quoted 31 lines
to and from the FUSE server.
Signed-off-by Ioannis Angelakopoulos <[email protected]>--- include/uapi/linux/fuse.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)include/uapi/linux/fuse.h +4
-1@@ -186,6 +186,9 @@* - add FUSE_SYNCFS * 7.35 * - add FUSE_NOTIFY_LOCK +* 7.36 +* - add FUSE_HAVE_FSNOTIFY +* - add fuse_notify_fsnotify_(in,out) */ #ifndef _LINUX_FUSE_H@@ -221,7 +224,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 35 +#define FUSE_KERNEL_MINOR_VERSION 36/** The node ID of the root inode */ #define FUSE_ROOT_ID 1include/uapi/linux/fuse.h struct fuse_file_lock { · line 341
Quoted 1 line
include/uapi/linux/fuse.h +0
-0@@ -338,6 +341,7 @@ struct fuse_file_lock {* write/truncate sgid is killed only if file has group
Quoted 34 lines
include/uapi/linux/fuse.h +4
-0* execute permission. (Same as Linux VFS behavior). * FUSE_SETXATTR_EXT: Server supports extended struct fuse_setxattr_in +* FUSE_HAVE_FSNOTIFY: remote fsnotify/inotify event subsystem support */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)@@ -369,6 +373,7 @@ struct fuse_file_lock {#define FUSE_SUBMOUNTS (1 << 27)#define FUSE_HANDLE_KILLPRIV_V2 (1 << 28)#define FUSE_SETXATTR_EXT (1 << 29) +#define FUSE_HAVE_FSNOTIFY (1 << 30)/** * CUSE INIT request/reply flags @@ -515,6 +520,7 @@ enum fuse_opcode {FUSE_SETUPMAPPING =48 ,FUSE_REMOVEMAPPING =49 ,FUSE_SYNCFS =50 , +FUSE_FSNOTIFY =51 ,/* CUSE specific operations */ CUSE_INIT = 4096,@@ -532,6 +538,7 @@ enum fuse_notify_code {FUSE_NOTIFY_RETRIEVE =5 ,FUSE_NOTIFY_DELETE =6 ,FUSE_NOTIFY_LOCK =7 , +FUSE_NOTIFY_FSNOTIFY =8 , FUSE_NOTIFY_CODE_MAX, };@@ -571,6 +578,20 @@ struct fuse_getattr_in {uint64_t fh; };
Quoted 8 lines
include/uapi/linux/fuse.h struct fuse_getattr_in { · line 582
Quoted 2 lines
include/uapi/linux/fuse.h +2
-0+struct fuse_notify_fsnotify_out { +uint64_t inode;64bit inode is not a good unique identifier of the object. you need to either include the generation in object identifier or much better use the object's nfs file handle, the same way that fanotify stores object identifiers.
Ok thank you for pointing that out. I will change this implementation to include either the generation or use the object's nfs file handle.
Quoted 8 lines
include/uapi/linux/fuse.h struct fuse_getattr_in { · line 585
Quoted 3 lines
include/uapi/linux/fuse.h +3
-0+uint64_t mask; +uint32_t namelen; +uint32_t cookie;I object to persisting with the two-events-joined-by-cookie design. Any new design should include a single event for rename with information about src and dst.
Quoted 8 lines
I know this is inconvenient, but we are NOT going to create a "remote inotify"
interface, we need to create a "remote fsnotify" interface and if server wants
to use inotify, it will need to join the disjoined MOVE_FROM/TO event into a single "remote event", that FUSE will use to callfsnotify_move().I do not fully understand this. Should we define a new "remote" event
that corresponds to the merged MOVE_FROM/TO events and send that to the guest instead?
If that is the case, wouldn't that require that user space processes be aware of this newly added "remote"
event? Also in the inotify man page there is a limitations case that states that it is possible for one of these events
to be missing. What should the server do in this case?
Thanks,
Ioannis
Quoted 4 lines
Thanks,
Amir.
Signature · 2 lines
Ioannis Angelakopoulos Software Engineer Intern at Red Hat
Amir Goldstein
reviewerRe: [RFC PATCH 1/7] FUSE: Add the fsnotify opcode and in/out structs to FUSE
Quoted 8 lines
Quoted 8 lines
include/uapi/linux/fuse.h struct fuse_getattr_in { · line 585
Quoted 3 lines
include/uapi/linux/fuse.h +3
-0+uint64_t mask; +uint32_t namelen; +uint32_t cookie;I object to persisting with the two-events-joined-by-cookie design. Any new design should include a single event for rename with information about src and dst.
Quoted 7 lines
Quoted 5 lines
I know this is inconvenient, but we are NOT going to create a "remote inotify" interface, we need to create a "remote fsnotify" interface and if server wants to use inotify, it will need to join the disjoined MOVE_FROM/TO event into a single "remote event", that FUSE will use to call
fsnotify_move().I do not fully understand this. Should we define a new "remote" event that corresponds to the merged MOVE_FROM/TO events and send that to the guest instead?
Yes.
First of all, my objection to the old cookie API stems from seeing applications that do not use it correctly and because I find that it can be hard to use it.
For those reasons, when we extended fanotify to provide "inotify compatible" semantics, the cookie API was not carried over to fanotify.
You can see an example of "inotify compatible" API in the implementation of fsnotifywatch [1].
That said, the functionality of joining to/from events is still missing in fanotify and I have posted several proposals for an API extension that will solve it using an event that contains information on both src and dst [2].
Quoted 2 lines
If that is the case, wouldn't that require that user space processes be aware of this newly added "remote" event?
No, the application will not be aware of the FUSE notify protocol at all. If application is using inotify, it will get the old from+to+cookie events, but FUSE server will notify the guest {MOVE, inode, from_path, to_path} and FUSE client will call fsnotify_mode() or a variant.
Then inotify watchers will get what they are used to and fsnotify watchers will get whatever information the existing or future API will provide.
To explain this from another perspective, you currently implemented the virtiofsd watch using inotify, but you should not limit virtiofsd to inotify. Once you learn the benefits of fanotify, you may consider implementing the virtiofsd watches using fanotify. It should not matter for the inotify application in the guest at all.
With the current implementation of watch in virtiofsd using inotify, that will cause the inconvenience of having to match the from/to events before reporting the event to guest, but inconvenience for a specific implementation is not what should be driving the API design.
Quoted 3 lines
Also in the inotify man page there is a limitations case that states that it is possible for one of these events to be missing. What should the server do in this case?
The protocol should be able to carry src and dst information, but you could leave src (of moved_to) or dst (of moved_from) empty. In that case, FUSE client cannot call fsnotify_move() as is, so we can either change fsnotify_move() or use a variant for reporting remote rename events.
The extra info for rename events with the FAN_REPORT_TARGET_FID proposal is also designed to be optional.
Thanks,
Amir.
[1] https://man7.org/linux/man-pages/man1/fsnotifywatch.1.html
[2] https://lore.kernel.org/linux-fsdevel/CAOQ4uxjYDDk00VPdWtRB1_tf+gCoPFgSQ9O0p0fGaW_JiFUUKA@mail.gmail.com/
Vivek Goyal
maintainerRe: [RFC PATCH 1/7] FUSE: Add the fsnotify opcode and in/out structs to FUSE
In reply to Amir GoldsteinQuoted 73 lines · Amir Goldstein
Quoted 71 lines · Ioannis Angelakopoulos
Since fsnotify is the backend for the inotify subsystem all the backend code implementation we add is related to fsnotify.
To support an fsnotify request in FUSE and specifically virtiofs we add a new opcode for the FSNOTIFY (51) operation request in the "
fuse.h" header.Also add the "
fuse_notify_fsnotify_in" and "fuse_notify_fsnotify_out" structs that are responsible for passing the fsnotify/inotify related data to and from the FUSE server.Signed-off-by Ioannis Angelakopoulos <[email protected]>--- include/uapi/linux/fuse.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)include/uapi/linux/fuse.h +8
-1@@ -186,6 +186,9 @@* - add FUSE_SYNCFS * 7.35 * - add FUSE_NOTIFY_LOCK +* 7.36 +* - add FUSE_HAVE_FSNOTIFY +* - add fuse_notify_fsnotify_(in,out) */ #ifndef _LINUX_FUSE_H@@ -221,7 +224,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 35 +#define FUSE_KERNEL_MINOR_VERSION 36/** The node ID of the root inode */ #define FUSE_ROOT_ID 1@@ -338,6 +341,7 @@ struct fuse_file_lock {* write/truncate sgid is killed only if file has group * execute permission. (Same as Linux VFS behavior). * FUSE_SETXATTR_EXT: Server supports extended struct fuse_setxattr_in +* FUSE_HAVE_FSNOTIFY: remote fsnotify/inotify event subsystem support */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)@@ -369,6 +373,7 @@ struct fuse_file_lock {#define FUSE_SUBMOUNTS (1 << 27)#define FUSE_HANDLE_KILLPRIV_V2 (1 << 28)#define FUSE_SETXATTR_EXT (1 << 29) +#define FUSE_HAVE_FSNOTIFY (1 << 30)/** * CUSE INIT request/reply flags @@ -515,6 +520,7 @@ enum fuse_opcode {FUSE_SETUPMAPPING =48 ,FUSE_REMOVEMAPPING =49 ,FUSE_SYNCFS =50 , +FUSE_FSNOTIFY =51 ,/* CUSE specific operations */ CUSE_INIT = 4096,@@ -532,6 +538,7 @@ enum fuse_notify_code {FUSE_NOTIFY_RETRIEVE =5 ,FUSE_NOTIFY_DELETE =6 ,FUSE_NOTIFY_LOCK =7 , +FUSE_NOTIFY_FSNOTIFY =8 , FUSE_NOTIFY_CODE_MAX, };
Quoted 8 lines
include/uapi/linux/fuse.h struct fuse_getattr_in { · line 582
Quoted 6 lines
include/uapi/linux/fuse.h +2
-0@@ -571,6 +578,20 @@ struct fuse_getattr_in {uint64_t fh; }; +struct fuse_notify_fsnotify_out { +uint64_t inode;64bit inode is not a good unique identifier of the object.
I think he wants to store 64bit nodeid (internal to fuse so that client and server can figure out which inode they are talking about). But I think you are concerned about what happens if an event arrived for an inode after inode has been released and nodeid possibly used for some other inode. And then we will find that new inode in guest cache and end up associating event with wrong inode.
Generation number will help in the sense that server has a chance to always update generation number on lookup. So even if nodeid is reused, generation number will make make sure we don't end up associating this event with reused node id inode. I guess makes sense.
Quoted 3 lines
you need to either include the generation in object identifier or much better use the object's nfs file handle, the same way that fanotify stores object identifiers.
I think nfs file handle is much more complicated and its a separate project altogether. I am assuming we are talking about persistent nfs file handle as generated by host. I think biggest issue we faced with that is that guest is untrusted and we don't want to resolve file handle provided by guest on host otherwise guest can craft file handles and possibly be able to open other files on same filesystem outside shared dir.
Quoted 5 lines
include/uapi/linux/fuse.h struct fuse_getattr_in { · line 585
Quoted 4 lines
include/uapi/linux/fuse.h +3
-0+uint64_t mask; +uint32_t namelen; +uint32_t cookie;
Quoted 8 lines
I object to persisting with the two-events-joined-by-cookie design. Any new design should include a single event for rename with information about src and dst.
I know this is inconvenient, but we are NOT going to create a "remote inotify" interface, we need to create a "remote fsnotify" interface and if server wants to use inotify, it will need to join the disjoined MOVE_FROM/TO event into a single "remote event", that FUSE will use to call
fsnotify_move().
man inotify says following.
" Matching up the IN_MOVED_FROM and IN_MOVED_TO event pair generated by
rename(2) is thus inherently racy. (Don't forget that if an object is renamed outside of a monitored directory, there may not even be an IN_MOVED_TO event.)"
So if guest is no monitoring target dir of renamed file, then we will not even get IN_MOVED_TO. In that case we can't merge two events into one.
And this sounds like inotify/fanotify interface needs to come up with an merged event and in that case remote filesystem will simply propagate that event. (Instead of coming up with a new event only for remote filesystems. Sounds like this is not a problem limited to remote filesystems only).
Thanks
Vivek
Amir Goldstein
reviewerRe: [RFC PATCH 1/7] FUSE: Add the fsnotify opcode and in/out structs to FUSE
Quoted 4 lines
Quoted 3 lines
you need to either include the generation in object identifier or much better use the object's nfs file handle, the same way that fanotify stores object identifiers.
Quoted 8 lines
I think nfs file handle is much more complicated and its a separate project altogether. I am assuming we are talking about persistent nfs file handle as generated by host. I think biggest issue we faced with that is that guest is untrusted and we don't want to resolve file handle provided by guest on host otherwise guest can craft file handles and possibly be able to open other files on same filesystem outside shared dir.
Right now, virtiofsd keeps all inodes and dentries of live client inodes pinned in cache on the server.
If you switch to file handles design, virtiofsd only need to keep a map of all the file handles that server handed out to client to address this concern.
For directories, this practice is not even needed for security, because a decoded directory file handle can be verified to be within the shared dir. It is only needed to prevent DoS, because a crafted directory file handle (outside of shared dir) can be used to generate extra IO and thrash the inode/dentry cache on the server.
Quoted 21 lines
Quoted 5 lines
include/uapi/linux/fuse.h struct fuse_getattr_in { · line 585
Quoted 4 lines
include/uapi/linux/fuse.h +3
-0+uint64_t mask; +uint32_t namelen; +uint32_t cookie;Quoted 8 lines
I object to persisting with the two-events-joined-by-cookie design. Any new design should include a single event for rename with information about src and dst.
I know this is inconvenient, but we are NOT going to create a "remote inotify" interface, we need to create a "remote fsnotify" interface and if server wants to use inotify, it will need to join the disjoined MOVE_FROM/TO event into a single "remote event", that FUSE will use to call
fsnotify_move().man inotify says following.
" Matching up the
IN_MOVED_FROMandIN_MOVED_TOevent pair generated by
rename(2) is thus inherently racy. (Don't forget that if an object is renamed outside of a monitored directory, there may not even be anIN_MOVED_TOevent.)"
Quoted 9 lines
So if guest is no monitoring target dir of renamed file, then we will not even get
IN_MOVED_TO. In that case we can't merge two events into one.And this sounds like inotify/fanotify interface needs to come up with an merged event and in that case remote filesystem will simply propagate that event. (Instead of coming up with a new event only for remote filesystems. Sounds like this is not a problem limited to remote filesystems only).
I don't see it that way.
I see the "internal protocol" for filesystems/vfs to report rename is fsnotify_move() which carries information about both src and target. I would like the remote protocol to carry the same information. It is then up to the userspace API whether to report the rename as two events or a unified event.
For example, debugfs, calls fsnotify_move() when an object is renamed from underneath the vfs. It does not call fsnotify() twice with a cookie, because we would not want to change local filesystem nor remote protocols when we want to add new userspace APIs for reporting fsevents.
That comes down to my feeling that this claims to be a proposal for "remote fsnotify", but it looks and sounds like a proposal for "remote inotify" and this is the core of my objection to passing the rename cookie in the protocol.
Regarding the issue that the src/dst path may not be known
to the server, as I wrote, it is fine if either the src/dst path information is omitted from an event, but the protocol should provide the placeholder to report them.
After sufficient arguing, I might be convinced that the cookie may be included as an optional field in addition to the fields that I requested.
I understand why you write that this sounds like an fanotify interface that needs to be resolved and you are correct, but the reason that the fanotify interface issue was not yet resolved is that we are trying to not repeat the mistakes of the past and for that same reason, I am insisting on the protocol.
Thanks,
Amir.
Vivek Goyal
maintainerRe: [RFC PATCH 1/7] FUSE: Add the fsnotify opcode and in/out structs to FUSE
Quoted 13 lines · Amir Goldstein
Quoted 4 lines
Quoted 3 lines
you need to either include the generation in object identifier or much better use the object's nfs file handle, the same way that fanotify stores object identifiers.
Quoted 8 lines
I think nfs file handle is much more complicated and its a separate project altogether. I am assuming we are talking about persistent nfs file handle as generated by host. I think biggest issue we faced with that is that guest is untrusted and we don't want to resolve file handle provided by guest on host otherwise guest can craft file handles and possibly be able to open other files on same filesystem outside shared dir.
Quoted 5 lines
Right now, virtiofsd keeps all inodes and dentries of live client inodes pinned in cache on the server.
If you switch to file handles design, virtiofsd only need to keep a map of all the file handles that server handed out to client to address this concern.
Keeping a map of all file handles server handed out to client, should work. But that means these file handles are not persistent and can't be used after a vritiofsd restart (virtiofsd will lose its map over restart). And that means one can not pass these file handles to user space. And that rules out giving file handle to user space as part of fanotify API, IIUC.
So in practice it is as good as (nodeid, generation) solution. And using file handles means giving CAP_DAC_READ_SEARCH to virtiofsd daemon. Will really like to run virtiofsd unrpviliged (in a user namespace) and be able to support as many features as possible.
Quoted 6 lines
For directories, this practice is not even needed for security, because a decoded directory file handle can be verified to be within the shared dir. It is only needed to prevent DoS, because a crafted directory file handle (outside of shared dir) can be used to generate extra IO and thrash the inode/dentry cache on the server.
Good to know that for directories only DOS is a concern.
Quoted 32 lines
Quoted 22 lines
Quoted 6 lines
include/uapi/linux/fuse.h struct fuse_getattr_in { · line 585
Quoted 5 lines
include/uapi/linux/fuse.h +3
-0+uint64_t mask; +uint32_t namelen; +uint32_t cookie;Quoted 8 lines
I object to persisting with the two-events-joined-by-cookie design. Any new design should include a single event for rename with information about src and dst.
I know this is inconvenient, but we are NOT going to create a "remote inotify" interface, we need to create a "remote fsnotify" interface and if server wants to use inotify, it will need to join the disjoined MOVE_FROM/TO event into a single "remote event", that FUSE will use to call
fsnotify_move().man inotify says following.
" Matching up the
IN_MOVED_FROMandIN_MOVED_TOevent pair generated by
rename(2) is thus inherently racy. (Don't forget that if an object is renamed outside of a monitored directory, there may not even be anIN_MOVED_TOevent.)"Quoted 9 lines
So if guest is no monitoring target dir of renamed file, then we will not even get
IN_MOVED_TO. In that case we can't merge two events into one.And this sounds like inotify/fanotify interface needs to come up with an merged event and in that case remote filesystem will simply propagate that event. (Instead of coming up with a new event only for remote filesystems. Sounds like this is not a problem limited to remote filesystems only).
Quoted 6 lines
I don't see it that way.
I see the "internal protocol" for filesystems/vfs to report rename isfsnotify_move()which carries information about both src and target. I would like the remote protocol to carry the same information. It is then up to the userspace API whether to report the rename as two events or a unified event.
Sure not a bad idea and allowing "cookie" does not stop remote filesystems from reporting single rename event.
In this case virtiofs is just a passthrough filesystem. It simply reports back what underlying filesystem is reporting. So if inotify interface reports two events, it will simply send that. In fact old users will expect that.
I understand that you don't like two separate events and hence wants to kill cookie. But how will we fix that when underlying inotify API reports two separate events. If we try to merge these there is no guarantee that we can do that because we might get only one events as we might not be watching either source/target directory. We place watches only as specified by client.
Quoted 10 lines
For example, debugfs, calls
fsnotify_move()when an object is renamed from underneath the vfs. It does not callfsnotify()twice with a cookie, because we would not want to change local filesystem nor remote protocols when we want to add new userspace APIs for reporting fsevents.That comes down to my feeling that this claims to be a proposal for "remote fsnotify", but it looks and sounds like a proposal for "remote inotify" and this is the core of my objection to passing the rename cookie in the protocol.
We are starting with remote inotify support and hoping it can be extended to remote fanotify in limited feature form. So want to make modifications in such a way so that one can easily extend it for fanotify as well.
Now question is, that should there be separate fuse commands for inotify and fanotify request/events. Or we should try to merge these two and design fuse_notify_fsnotify_out{} and fuse_notify_fsnotify_in{} in such a way so that it could support both inotify/fanotify. I guess later will make more sense. Just that it will be more complicated as well because fanotify API can send much more information to user space. Like, file handles, "fd", "pid" etc.
I think "pid" might not make much sense in the context of remote filesystem. In case of virtiofsd, it will simply be pid of another virtiofsd instance most likely which does not mean anything for guest process. In fact, there is a chance that it could be same pid as of guest process.
Quoted 5 lines
Regarding the issue that the src/dst path may not be known
to the server, as I wrote, it is fine if either the src/dst path information is omitted from an event, but the protocol should provide the placeholder to report them.
This kind of makes more sense. That protocol should have capability to report a rename event with both src/dst path to future proof it. That way when inotify/fanotify APIs start reporting a single rename event, we will be able to simply send it back to client without any fuse protocol modifications.
One risk of adding space for src/dst path info in fuse_notify_fsnotify_out{} is that we don't know how this information will end up looking like when inotify/fanotify actually start supporting single rename event. It is possible that we add some fields now and final single event format looks different and now we have unused fields.
Quoted 3 lines
After sufficient arguing, I might be convinced that the cookie may be included as an optional field in addition to the fields that I requested.
But we should allow cookie as well so that older inotify API continues to be supported as well.
Quoted 6 lines
I understand why you write that this sounds like an fanotify interface that needs to be resolved and you are correct, but the reason that the fanotify interface issue was not yet resolved is that we are trying to not repeat the mistakes of the past and for that same reason, I am insisting on the protocol.
Right now we are writing protocol fields based on what inotify (and possibly fanotify) are supporting. But if you want to extend it further so that it can report something which you intend to introduce in future, I think that's fine too.
So how will additional fields will look like to support this signle rename event.
Vivek
RFC PATCH 2/7 FUSE: Add the remote inotify support capability to FUSE
In reply to Ioannis AngelakopoulosAdd the remote inotify support capability to FUSE init flags, which is supported by the kernel only when the "CONFIG_INOTIFY_USER" config option is enabled in the guest kernel.
If virtiofsd wants the remote inotify support feature enabled only then the guest kernel will enable it. However, this means that the kernel will suppress the local inotify events related to inodes within the directory exported through virtiofs. The suppression of local events prevents the guest from receiving duplicate events; one from the guest kernel and one from virtiofsd.
--- fs/fuse/fuse_i.h | 7 +++++++ fs/fuse/inode.c | 6 ++++++ 2 files changed, 13 insertions(+)
fs/fuse/fuse_i.h +7 -0
@@ -649,6 +649,13 @@ struct fuse_conn {*/ unsigned handle_killpriv_v2:1; +/* Is the remote inotify capability supported by the filesystem? +* If yes then all the local inotify events related to inodes +* in the FUSE filesystem will be suppressed and only the remote +* events will be let through. +*/ + unsigned no_fsnotify:1; +/* * The following bitfields are only for optimization purposes * and hence races in setting them will not cause malfunction
fs/fuse/inode.c +6 -0
@@ -1143,6 +1143,9 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, }if (arg->flags &FUSE_SETXATTR_EXT ) fc->setxattr_ext =1 ; +if (!(arg->flags &FUSE_HAVE_FSNOTIFY )) { + fc->no_fsnotify =1 ; + } }else { ra_pages = fc->max_read /PAGE_SIZE ; fc->no_lock =1 ;
@@ -1190,6 +1193,9 @@ void fuse_send_init(struct fuse_mount *fm)#ifdef CONFIG_FUSE_DAX if (fm->fc->dax) ia->in.flags |=FUSE_MAP_ALIGNMENT ; +#endif +#ifdef CONFIG_INOTIFY_USER + ia->in.flags |=FUSE_HAVE_FSNOTIFY ;#endif if (fm->fc->auto_submounts) ia->in.flags |=FUSE_SUBMOUNTS ;
Signature · 1 line
2.33.0
RFC PATCH 3/7 FUSE,Inotify,Fsnotify,VFS: Add the fuse_fsnotify_update_mark inode operation
In reply to Ioannis AngelakopoulosEvery time a local watch is placed/modified/removed on/from an inode the same operation has to take place in the FUSE server.
Thus add the inode operation "fuse_fsnotify_update_mark", which is specific to FUSE inodes. This operation is called from the "inotify_add_watch" system call in the inotify subsystem.
Specifically, the operation is called when a process tries to add, modify or remove a watch from a FUSE inode and the remote fsnotify support is enabled both in the guest kernel and the FUSE server (virtiofsd).
Essentially, when the kernel adds/modifies a watch locally, also send a fsnotify request to the FUSE server to do the same. We keep the local watch placement since it is essential for the functionality of the fsnotify notification subsystem. However, the local events generated by the guest kernel will be suppressed if they affect FUSE inodes and the remote fsnotify support is enabled.
Also modify the "fsnotify_detach_mark" function in fs/notify/mark.c to add support for the remote deletion of watches for FUSE inodes. In contrast to the add/modify operation we do not modify the inotify subsystem, but the fsnotify subsystem. That is because there are two ways of deleting a watch from an inode. The first is by manually calling the "inotify_rm_watch" system call and the second is automatically by the kernel when the process that has created an inotify instance exits. In that case the kernel is responsible for deleting all the watches corresponding to said inotify instance.
Thus we send the fsnotify request for the deletion of the remote watch at the lowest level within "fsnotify_detach_mark" to catch both watch removal cases.
The "fuse_fsnotify_update_mark" function in turn calls the "fuse_fsnotify_send_request" function, to send an fsnotify request to the FUSE server related to an inode watch.
--- fs/fuse/dir.c | 29 +++++++++++++++++++++++++++++ fs/notify/inotify/inotify_user.c | 11 +++++++++++ fs/notify/mark.c | 10 ++++++++++ include/linux/fs.h | 2 ++ 4 files changed, 52 insertions(+)
fs/fuse/dir.c +29 -0
@@ -17,6 +17,8 @@#include <linux/xattr.h> #include <linux/iversion.h> #include <linux/posix_acl.h> +#include <linux/fsnotify_backend.h> +#include <linux/inotify.h> static void fuse_advise_use_readdirplus (struct inode *dir) {
@@ -1805,6 +1807,30 @@ static int fuse_getattr(struct user_namespace *mnt_userns,return fuse_update_get_attr (inode,NULL , stat, request_mask, flags); } +static int fuse_fsnotify_update_mark (struct inode *inode,uint32_t action, +uint64_t group,uint32_t mask) +{ +/* +* We have to remove the bits added to the mask before being attached +* or detached to the inode, since these bits are going to be +* added by the "remote" host kernel. If these bits were still enabled +* in the mask that was sent to the "remote" kernel then the watch would +* be rejected as an unsupported value. These bits are added by the +* fsnotify subsystem thus we use the corresponding fsnotify bits here. +*/ + mask = mask & ~(FS_IN_IGNORED |FS_UNMOUNT |FS_IN_ONESHOT | +FS_EXCL_UNLINK |FS_EVENT_ON_CHILD ); + +if (!(mask &IN_ALL_EVENTS )) +return -EINVAL ; + +/* +* Action 0: Remove a watch +* Action 1: Add/Modify watch +*/ +return fuse_fsnotify_send_request (inode, mask, action, group); +} +static const struct inode_operations fuse_dir_inode_operations = { .lookup = fuse_lookup, .mkdir = fuse_mkdir,
@@ -1824,6 +1850,7 @@ static const struct inode_operations fuse_dir_inode_operations = { .set_acl = fuse_set_acl, .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set, + .fsnotify_update = fuse_fsnotify_update_mark, };static const struct file_operations fuse_dir_operations = {
@@ -1846,6 +1873,7 @@ static const struct inode_operations fuse_common_inode_operations = { .set_acl = fuse_set_acl, .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set, + .fsnotify_update = fuse_fsnotify_update_mark, };static const struct inode_operations fuse_symlink_inode_operations = {
@@ -1853,6 +1881,7 @@ static const struct inode_operations fuse_symlink_inode_operations = { .get_link = fuse_get_link, .getattr = fuse_getattr, .listxattr = fuse_listxattr, + .fsnotify_update = fuse_fsnotify_update_mark, };void fuse_init_common (struct inode *inode)
fs/notify/inotify/inotify_user.c +11 -0
@@ -46,6 +46,8 @@#define INOTIFY_WATCH_COST (sizeof(struct inotify_inode_mark) + \ 2 * sizeof(struct inode)) +#define FSNOTIFY_ADD_MODIFY_MARK 1 +/* configurable via /proc/sys/fs/inotify/ */ static int inotify_max_queued_events__read_mostly ;
@@ -764,6 +766,15 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,/* create/update an inode mark */ ret =inotify_update_watch (group, inode, mask); +/* +* If the inode belongs to a remote filesystem/server that supports +* remote inotify events then send the mark to the remote server +*/ +if (ret >=0 && inode->i_op->fsnotify_update) { + inode->i_op->fsnotify_update (inode, +FSNOTIFY_ADD_MODIFY_MARK , + (uint64_t )group, mask); + }path_put (&path); fput_and_out:fdput (f);
fs/notify/mark.c +10 -0
@@ -77,6 +77,7 @@#include "fsnotify.h" #define FSNOTIFY_REAPER_DELAY (1)/* 1 jiffy */ +#define FSNOTIFY_DELETE_MARK 0/* Delete a mark in remote fsnotify */ struct srcu_struct fsnotify_mark_srcu;struct kmem_cache *fsnotify_mark_connector_cachep;
@@ -399,6 +400,7 @@ void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info)void fsnotify_detach_mark (struct fsnotify_mark *mark) {struct fsnotify_group *group = mark->group; +struct inode *inode =NULL ;WARN_ON_ONCE (!mutex_is_locked (&group->mark_mutex)); WARN_ON_ONCE(!srcu_read_lock_held(&fsnotify_mark_srcu) &&
@@ -411,6 +413,14 @@ void fsnotify_detach_mark(struct fsnotify_mark *mark)spin_unlock (&mark->lock);return ; } + +/* Only if the object is an inode send a request to FUSE server */ + inode =fsnotify_conn_inode (mark->connector); +if (inode && inode->i_op->fsnotify_update) { + inode->i_op->fsnotify_update (inode,FSNOTIFY_DELETE_MARK , + (uint64_t )group, mark->mask); + } + mark->flags &= ~FSNOTIFY_MARK_FLAG_ATTACHED ;list_del_init (&mark->g_list);spin_unlock (&mark->lock);
include/linux/fs.h +2 -0
@@ -2149,6 +2149,8 @@ struct inode_operations {int (*fileattr_set)(struct user_namespace *mnt_userns,struct dentry *dentry,struct fileattr *fa);int (*fileattr_get)(struct dentry *dentry,struct fileattr *fa); +int (*fsnotify_update)(struct inode *inode,uint32_t action, +uint64_t group,uint32_t mask); }____cacheline_aligned ; static inline ssize_t call_read_iter(struct file *file, struct kiocb *kio,
Signature · 1 line
2.33.0
Amir Goldstein
reviewerRe: [RFC PATCH 3/7] FUSE,Inotify,Fsnotify,VFS: Add the fuse_fsnotify_update_mark inode operation
Quoted 148 lines · Ioannis Angelakopoulos
Every time a local watch is placed/modified/removed on/from an inode the same operation has to take place in the FUSE server.
Thus add the inode operation "
fuse_fsnotify_update_mark", which is specific to FUSE inodes. This operation is called from the "inotify_add_watch" system call in the inotify subsystem.Specifically, the operation is called when a process tries to add, modify or remove a watch from a FUSE inode and the remote fsnotify support is enabled both in the guest kernel and the FUSE server (virtiofsd).
Essentially, when the kernel adds/modifies a watch locally, also send a fsnotify request to the FUSE server to do the same. We keep the local watch placement since it is essential for the functionality of the fsnotify notification subsystem. However, the local events generated by the guest kernel will be suppressed if they affect FUSE inodes and the remote fsnotify support is enabled.
Also modify the "
fsnotify_detach_mark" function infs/notify/mark.cto add support for the remote deletion of watches for FUSE inodes. In contrast to the add/modify operation we do not modify the inotify subsystem, but the fsnotify subsystem. That is because there are two ways of deleting a watch from an inode. The first is by manually calling the "inotify_rm_watch" system call and the second is automatically by the kernel when the process that has created an inotify instance exits. In that case the kernel is responsible for deleting all the watches corresponding to said inotify instance.Thus we send the fsnotify request for the deletion of the remote watch at the lowest level within "
fsnotify_detach_mark" to catch both watch removal cases.The "
fuse_fsnotify_update_mark" function in turn calls the "fuse_fsnotify_send_request" function, to send an fsnotify request to the FUSE server related to an inode watch.Signed-off-by Ioannis Angelakopoulos <[email protected]>--- fs/fuse/dir.c | 29 +++++++++++++++++++++++++++++ fs/notify/inotify/inotify_user.c | 11 +++++++++++ fs/notify/mark.c | 10 ++++++++++ include/linux/fs.h | 2 ++ 4 files changed, 52 insertions(+)fs/fuse/dir.c +29
-0@@ -17,6 +17,8 @@#include <linux/xattr.h> #include <linux/iversion.h> #include <linux/posix_acl.h> +#include <linux/fsnotify_backend.h> +#include <linux/inotify.h> static void fuse_advise_use_readdirplus (struct inode *dir) {@@ -1805,6 +1807,30 @@ static int fuse_getattr(struct user_namespace *mnt_userns,return fuse_update_get_attr (inode,NULL , stat, request_mask, flags); } +static int fuse_fsnotify_update_mark (struct inode *inode,uint32_t action, +uint64_t group,uint32_t mask) +{ +/* +* We have to remove the bits added to the mask before being attached +* or detached to the inode, since these bits are going to be +* added by the "remote" host kernel. If these bits were still enabled +* in the mask that was sent to the "remote" kernel then the watch would +* be rejected as an unsupported value. These bits are added by the +* fsnotify subsystem thus we use the corresponding fsnotify bits here. +*/ + mask = mask & ~(FS_IN_IGNORED |FS_UNMOUNT |FS_IN_ONESHOT | +FS_EXCL_UNLINK |FS_EVENT_ON_CHILD ); + +if (!(mask &IN_ALL_EVENTS )) +return -EINVAL ; + +/* +* Action 0: Remove a watch +* Action 1: Add/Modify watch +*/ +return fuse_fsnotify_send_request (inode, mask, action, group); +} +static const struct inode_operations fuse_dir_inode_operations = { .lookup = fuse_lookup, .mkdir = fuse_mkdir,@@ -1824,6 +1850,7 @@ static const struct inode_operations fuse_dir_inode_operations = { .set_acl = fuse_set_acl, .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set, + .fsnotify_update = fuse_fsnotify_update_mark, };static const struct file_operations fuse_dir_operations = {@@ -1846,6 +1873,7 @@ static const struct inode_operations fuse_common_inode_operations = { .set_acl = fuse_set_acl, .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set, + .fsnotify_update = fuse_fsnotify_update_mark, };static const struct inode_operations fuse_symlink_inode_operations = {@@ -1853,6 +1881,7 @@ static const struct inode_operations fuse_symlink_inode_operations = { .get_link = fuse_get_link, .getattr = fuse_getattr, .listxattr = fuse_listxattr, + .fsnotify_update = fuse_fsnotify_update_mark, };void fuse_init_common (struct inode *inode)fs/notify/inotify/inotify_user.c +11
-0@@ -46,6 +46,8 @@#define INOTIFY_WATCH_COST (sizeof(struct inotify_inode_mark) + \ 2 * sizeof(struct inode)) +#define FSNOTIFY_ADD_MODIFY_MARK 1 +/* configurable via /proc/sys/fs/inotify/ */ static int inotify_max_queued_events__read_mostly ;@@ -764,6 +766,15 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,/* create/update an inode mark */ ret =inotify_update_watch (group, inode, mask); +/* +* If the inode belongs to a remote filesystem/server that supports +* remote inotify events then send the mark to the remote server +*/ +if (ret >=0 && inode->i_op->fsnotify_update) { + inode->i_op->fsnotify_update (inode, +FSNOTIFY_ADD_MODIFY_MARK , + (uint64_t )group, mask); + }path_put (&path); fput_and_out:fdput (f);fs/notify/mark.c +0
-0
fs/notify/mark.c line 80
Quoted 4 lines
fs/notify/mark.c +1
-0@@ -77,6 +77,7 @@#include "fsnotify.h" #define FSNOTIFY_REAPER_DELAY (1)/* 1 jiffy */ +#define FSNOTIFY_DELETE_MARK 0/* Delete a mark in remote fsnotify */
This define is part of the vfs API it should be in an include file along side FSNOTIFY_ADD_MODIFY_MARK (if we keep them in the API).
Quoted 31 lines
fs/notify/mark.c +9
-0struct srcu_struct fsnotify_mark_srcu;struct kmem_cache *fsnotify_mark_connector_cachep;@@ -399,6 +400,7 @@ void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info)void fsnotify_detach_mark (struct fsnotify_mark *mark) {struct fsnotify_group *group = mark->group; +struct inode *inode =NULL ;WARN_ON_ONCE (!mutex_is_locked (&group->mark_mutex)); WARN_ON_ONCE(!srcu_read_lock_held(&fsnotify_mark_srcu) &&@@ -411,6 +413,14 @@ void fsnotify_detach_mark(struct fsnotify_mark *mark)spin_unlock (&mark->lock);return ; } + +/* Only if the object is an inode send a request to FUSE server */ + inode =fsnotify_conn_inode (mark->connector); +if (inode && inode->i_op->fsnotify_update) { + inode->i_op->fsnotify_update (inode,FSNOTIFY_DELETE_MARK , + (uint64_t )group, mark->mask); + } + mark->flags &= ~FSNOTIFY_MARK_FLAG_ATTACHED ;list_del_init (&mark->g_list);spin_unlock (&mark->lock);include/linux/fs.h +0
-0
include/linux/fs.h struct inode_operations { · line 2155
Quoted 7 lines
include/linux/fs.h +2
-0@@ -2149,6 +2149,8 @@ struct inode_operations {int (*fileattr_set)(struct user_namespace *mnt_userns,struct dentry *dentry,struct fileattr *fa);int (*fileattr_get)(struct dentry *dentry,struct fileattr *fa); +int (*fsnotify_update)(struct inode *inode,uint32_t action, +uint64_t group,uint32_t mask); }____cacheline_aligned ;
Please split the patch that introduces the API from the FUSE implementation.
Regarding the API, group does not belong in this interface. The inode object has an "aggregated mask" at i_fsnotify_mask indicating an interest for an event from any group. Remote servers should be notified when the aggregated mask changes.
Hence, Miklos has proposed a "remote fsnotify update" API which does not carry the mask nor the action, only the watched object:
https://lore.kernel.org/linux-fsdevel/[email protected]/
On that same thread, you will see that I also proposed the API to support full filesystem watch (by passing sb).
I am not requiring that you implement sb watch for FUSE/virtiofs, but the API should take this future extension into account.
Thanks,
Amir.
Vivek Goyal
maintainerRe: [RFC PATCH 3/7] FUSE,Inotify,Fsnotify,VFS: Add the fuse_fsnotify_update_mark inode operation
Quoted 199 lines · Amir Goldstein
Quoted 148 lines · Ioannis Angelakopoulos
Every time a local watch is placed/modified/removed on/from an inode the same operation has to take place in the FUSE server.
Thus add the inode operation "
fuse_fsnotify_update_mark", which is specific to FUSE inodes. This operation is called from the "inotify_add_watch" system call in the inotify subsystem.Specifically, the operation is called when a process tries to add, modify or remove a watch from a FUSE inode and the remote fsnotify support is enabled both in the guest kernel and the FUSE server (virtiofsd).
Essentially, when the kernel adds/modifies a watch locally, also send a fsnotify request to the FUSE server to do the same. We keep the local watch placement since it is essential for the functionality of the fsnotify notification subsystem. However, the local events generated by the guest kernel will be suppressed if they affect FUSE inodes and the remote fsnotify support is enabled.
Also modify the "
fsnotify_detach_mark" function infs/notify/mark.cto add support for the remote deletion of watches for FUSE inodes. In contrast to the add/modify operation we do not modify the inotify subsystem, but the fsnotify subsystem. That is because there are two ways of deleting a watch from an inode. The first is by manually calling the "inotify_rm_watch" system call and the second is automatically by the kernel when the process that has created an inotify instance exits. In that case the kernel is responsible for deleting all the watches corresponding to said inotify instance.Thus we send the fsnotify request for the deletion of the remote watch at the lowest level within "
fsnotify_detach_mark" to catch both watch removal cases.The "
fuse_fsnotify_update_mark" function in turn calls the "fuse_fsnotify_send_request" function, to send an fsnotify request to the FUSE server related to an inode watch.Signed-off-by Ioannis Angelakopoulos <[email protected]>--- fs/fuse/dir.c | 29 +++++++++++++++++++++++++++++ fs/notify/inotify/inotify_user.c | 11 +++++++++++ fs/notify/mark.c | 10 ++++++++++ include/linux/fs.h | 2 ++ 4 files changed, 52 insertions(+)fs/fuse/dir.c +29
-0@@ -17,6 +17,8 @@#include <linux/xattr.h> #include <linux/iversion.h> #include <linux/posix_acl.h> +#include <linux/fsnotify_backend.h> +#include <linux/inotify.h> static void fuse_advise_use_readdirplus (struct inode *dir) {@@ -1805,6 +1807,30 @@ static int fuse_getattr(struct user_namespace *mnt_userns,return fuse_update_get_attr (inode,NULL , stat, request_mask, flags); } +static int fuse_fsnotify_update_mark (struct inode *inode,uint32_t action, +uint64_t group,uint32_t mask) +{ +/* +* We have to remove the bits added to the mask before being attached +* or detached to the inode, since these bits are going to be +* added by the "remote" host kernel. If these bits were still enabled +* in the mask that was sent to the "remote" kernel then the watch would +* be rejected as an unsupported value. These bits are added by the +* fsnotify subsystem thus we use the corresponding fsnotify bits here. +*/ + mask = mask & ~(FS_IN_IGNORED |FS_UNMOUNT |FS_IN_ONESHOT | +FS_EXCL_UNLINK |FS_EVENT_ON_CHILD ); + +if (!(mask &IN_ALL_EVENTS )) +return -EINVAL ; + +/* +* Action 0: Remove a watch +* Action 1: Add/Modify watch +*/ +return fuse_fsnotify_send_request (inode, mask, action, group); +} +static const struct inode_operations fuse_dir_inode_operations = { .lookup = fuse_lookup, .mkdir = fuse_mkdir,@@ -1824,6 +1850,7 @@ static const struct inode_operations fuse_dir_inode_operations = { .set_acl = fuse_set_acl, .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set, + .fsnotify_update = fuse_fsnotify_update_mark, };static const struct file_operations fuse_dir_operations = {@@ -1846,6 +1873,7 @@ static const struct inode_operations fuse_common_inode_operations = { .set_acl = fuse_set_acl, .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set, + .fsnotify_update = fuse_fsnotify_update_mark, };static const struct inode_operations fuse_symlink_inode_operations = {@@ -1853,6 +1881,7 @@ static const struct inode_operations fuse_symlink_inode_operations = { .get_link = fuse_get_link, .getattr = fuse_getattr, .listxattr = fuse_listxattr, + .fsnotify_update = fuse_fsnotify_update_mark, };void fuse_init_common (struct inode *inode)fs/notify/inotify/inotify_user.c +11
-0@@ -46,6 +46,8 @@#define INOTIFY_WATCH_COST (sizeof(struct inotify_inode_mark) + \ 2 * sizeof(struct inode)) +#define FSNOTIFY_ADD_MODIFY_MARK 1 +/* configurable via /proc/sys/fs/inotify/ */ static int inotify_max_queued_events__read_mostly ;@@ -764,6 +766,15 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,/* create/update an inode mark */ ret =inotify_update_watch (group, inode, mask); +/* +* If the inode belongs to a remote filesystem/server that supports +* remote inotify events then send the mark to the remote server +*/ +if (ret >=0 && inode->i_op->fsnotify_update) { + inode->i_op->fsnotify_update (inode, +FSNOTIFY_ADD_MODIFY_MARK , + (uint64_t )group, mask); + }path_put (&path); fput_and_out:fdput (f);fs/notify/mark.c +0
-0fs/notify/mark.c line 80
Quoted 4 lines
fs/notify/mark.c +1
-0@@ -77,6 +77,7 @@#include "fsnotify.h" #define FSNOTIFY_REAPER_DELAY (1)/* 1 jiffy */ +#define FSNOTIFY_DELETE_MARK 0/* Delete a mark in remote fsnotify */ This define is part of the vfs API it should be in an include file along side
FSNOTIFY_ADD_MODIFY_MARK(if we keep them in the API).Quoted 31 lines
fs/notify/mark.c +9
-0struct srcu_struct fsnotify_mark_srcu;struct kmem_cache *fsnotify_mark_connector_cachep;@@ -399,6 +400,7 @@ void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info)void fsnotify_detach_mark (struct fsnotify_mark *mark) {struct fsnotify_group *group = mark->group; +struct inode *inode =NULL ;WARN_ON_ONCE (!mutex_is_locked (&group->mark_mutex)); WARN_ON_ONCE(!srcu_read_lock_held(&fsnotify_mark_srcu) &&@@ -411,6 +413,14 @@ void fsnotify_detach_mark(struct fsnotify_mark *mark)spin_unlock (&mark->lock);return ; } + +/* Only if the object is an inode send a request to FUSE server */ + inode =fsnotify_conn_inode (mark->connector); +if (inode && inode->i_op->fsnotify_update) { + inode->i_op->fsnotify_update (inode,FSNOTIFY_DELETE_MARK , + (uint64_t )group, mark->mask); + } + mark->flags &= ~FSNOTIFY_MARK_FLAG_ATTACHED ;list_del_init (&mark->g_list);spin_unlock (&mark->lock);include/linux/fs.h +0
-0include/linux/fs.h struct inode_operations { · line 2155
Quoted 7 lines
include/linux/fs.h +2
-0@@ -2149,6 +2149,8 @@ struct inode_operations {int (*fileattr_set)(struct user_namespace *mnt_userns,struct dentry *dentry,struct fileattr *fa);int (*fileattr_get)(struct dentry *dentry,struct fileattr *fa); +int (*fsnotify_update)(struct inode *inode,uint32_t action, +uint64_t group,uint32_t mask); }____cacheline_aligned ;Please split the patch that introduces the API from the FUSE implementation.
Quoted 4 lines
Regarding the API, group does not belong in this interface. The inode object has an "aggregated mask" at
i_fsnotify_maskindicating an interest for an event from any group. Remote servers should be notified when the aggregated mask changes.
Is aggregated mask updated when nobody is watching for that event. I am not familiar with the code yet but Ioannis says that it does not seem to happen. That means once an event is being watched, it will continue to be generated on server and will continue to travel to guest and ultimately guest will drop that event because no application is watching.
If number of events generated are significant, it is a problem. Storing and forwarding so many events can consume significant amount of memory and cpu and also trigger dropping of some of the events.
Having said that, probably right fix is in fsnotify API so that "aggregated mask" is updated to remove events as well. And then remote file systems can update server aggreated mask too.
Quoted 7 lines
Hence, Miklos has proposed a "remote fsnotify update" API which does not carry the mask nor the action, only the watched object:
https://lore.kernel.org/linux-fsdevel/[email protected]/On that same thread, you will see that I also proposed the API to support full filesystem watch (by passing sb).
When you say API, you just mean signature of inode operation function. Say ->notify_update(). If we were to support "sb" later, updating inode operations should be easy. But I get the point that from VFS API point of view, pass whole inode to filesystems.
Thanks
Vivek
Quoted 6 lines
I am not requiring that you implement sb watch for FUSE/virtiofs, but the API should take this future extension into account.
Thanks,
Amir.
Amir Goldstein
reviewerRe: [RFC PATCH 3/7] FUSE,Inotify,Fsnotify,VFS: Add the fuse_fsnotify_update_mark inode operation
Quoted 201 lines · Vivek Goyal
Quoted 199 lines · Amir Goldstein
Quoted 148 lines · Ioannis Angelakopoulos
Every time a local watch is placed/modified/removed on/from an inode the same operation has to take place in the FUSE server.
Thus add the inode operation "
fuse_fsnotify_update_mark", which is specific to FUSE inodes. This operation is called from the "inotify_add_watch" system call in the inotify subsystem.Specifically, the operation is called when a process tries to add, modify or remove a watch from a FUSE inode and the remote fsnotify support is enabled both in the guest kernel and the FUSE server (virtiofsd).
Essentially, when the kernel adds/modifies a watch locally, also send a fsnotify request to the FUSE server to do the same. We keep the local watch placement since it is essential for the functionality of the fsnotify notification subsystem. However, the local events generated by the guest kernel will be suppressed if they affect FUSE inodes and the remote fsnotify support is enabled.
Also modify the "
fsnotify_detach_mark" function infs/notify/mark.cto add support for the remote deletion of watches for FUSE inodes. In contrast to the add/modify operation we do not modify the inotify subsystem, but the fsnotify subsystem. That is because there are two ways of deleting a watch from an inode. The first is by manually calling the "inotify_rm_watch" system call and the second is automatically by the kernel when the process that has created an inotify instance exits. In that case the kernel is responsible for deleting all the watches corresponding to said inotify instance.Thus we send the fsnotify request for the deletion of the remote watch at the lowest level within "
fsnotify_detach_mark" to catch both watch removal cases.The "
fuse_fsnotify_update_mark" function in turn calls the "fuse_fsnotify_send_request" function, to send an fsnotify request to the FUSE server related to an inode watch.Signed-off-by Ioannis Angelakopoulos <[email protected]>--- fs/fuse/dir.c | 29 +++++++++++++++++++++++++++++ fs/notify/inotify/inotify_user.c | 11 +++++++++++ fs/notify/mark.c | 10 ++++++++++ include/linux/fs.h | 2 ++ 4 files changed, 52 insertions(+)fs/fuse/dir.c +29
-0@@ -17,6 +17,8 @@#include <linux/xattr.h> #include <linux/iversion.h> #include <linux/posix_acl.h> +#include <linux/fsnotify_backend.h> +#include <linux/inotify.h> static void fuse_advise_use_readdirplus (struct inode *dir) {@@ -1805,6 +1807,30 @@ static int fuse_getattr(struct user_namespace *mnt_userns,return fuse_update_get_attr (inode,NULL , stat, request_mask, flags); } +static int fuse_fsnotify_update_mark (struct inode *inode,uint32_t action, +uint64_t group,uint32_t mask) +{ +/* +* We have to remove the bits added to the mask before being attached +* or detached to the inode, since these bits are going to be +* added by the "remote" host kernel. If these bits were still enabled +* in the mask that was sent to the "remote" kernel then the watch would +* be rejected as an unsupported value. These bits are added by the +* fsnotify subsystem thus we use the corresponding fsnotify bits here. +*/ + mask = mask & ~(FS_IN_IGNORED |FS_UNMOUNT |FS_IN_ONESHOT | +FS_EXCL_UNLINK |FS_EVENT_ON_CHILD ); + +if (!(mask &IN_ALL_EVENTS )) +return -EINVAL ; + +/* +* Action 0: Remove a watch +* Action 1: Add/Modify watch +*/ +return fuse_fsnotify_send_request (inode, mask, action, group); +} +static const struct inode_operations fuse_dir_inode_operations = { .lookup = fuse_lookup, .mkdir = fuse_mkdir,@@ -1824,6 +1850,7 @@ static const struct inode_operations fuse_dir_inode_operations = { .set_acl = fuse_set_acl, .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set, + .fsnotify_update = fuse_fsnotify_update_mark, };static const struct file_operations fuse_dir_operations = {@@ -1846,6 +1873,7 @@ static const struct inode_operations fuse_common_inode_operations = { .set_acl = fuse_set_acl, .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set, + .fsnotify_update = fuse_fsnotify_update_mark, };static const struct inode_operations fuse_symlink_inode_operations = {@@ -1853,6 +1881,7 @@ static const struct inode_operations fuse_symlink_inode_operations = { .get_link = fuse_get_link, .getattr = fuse_getattr, .listxattr = fuse_listxattr, + .fsnotify_update = fuse_fsnotify_update_mark, };void fuse_init_common (struct inode *inode)fs/notify/inotify/inotify_user.c +11
-0@@ -46,6 +46,8 @@#define INOTIFY_WATCH_COST (sizeof(struct inotify_inode_mark) + \ 2 * sizeof(struct inode)) +#define FSNOTIFY_ADD_MODIFY_MARK 1 +/* configurable via /proc/sys/fs/inotify/ */ static int inotify_max_queued_events__read_mostly ;@@ -764,6 +766,15 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,/* create/update an inode mark */ ret =inotify_update_watch (group, inode, mask); +/* +* If the inode belongs to a remote filesystem/server that supports +* remote inotify events then send the mark to the remote server +*/ +if (ret >=0 && inode->i_op->fsnotify_update) { + inode->i_op->fsnotify_update (inode, +FSNOTIFY_ADD_MODIFY_MARK , + (uint64_t )group, mask); + }path_put (&path); fput_and_out:fdput (f);fs/notify/mark.c +0
-0fs/notify/mark.c line 80
Quoted 4 lines
fs/notify/mark.c +1
-0@@ -77,6 +77,7 @@#include "fsnotify.h" #define FSNOTIFY_REAPER_DELAY (1)/* 1 jiffy */ +#define FSNOTIFY_DELETE_MARK 0/* Delete a mark in remote fsnotify */ This define is part of the vfs API it should be in an include file along side
FSNOTIFY_ADD_MODIFY_MARK(if we keep them in the API).Quoted 31 lines
fs/notify/mark.c +9
-0struct srcu_struct fsnotify_mark_srcu;struct kmem_cache *fsnotify_mark_connector_cachep;@@ -399,6 +400,7 @@ void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info)void fsnotify_detach_mark (struct fsnotify_mark *mark) {struct fsnotify_group *group = mark->group; +struct inode *inode =NULL ;WARN_ON_ONCE (!mutex_is_locked (&group->mark_mutex)); WARN_ON_ONCE(!srcu_read_lock_held(&fsnotify_mark_srcu) &&@@ -411,6 +413,14 @@ void fsnotify_detach_mark(struct fsnotify_mark *mark)spin_unlock (&mark->lock);return ; } + +/* Only if the object is an inode send a request to FUSE server */ + inode =fsnotify_conn_inode (mark->connector); +if (inode && inode->i_op->fsnotify_update) { + inode->i_op->fsnotify_update (inode,FSNOTIFY_DELETE_MARK , + (uint64_t )group, mark->mask); + } + mark->flags &= ~FSNOTIFY_MARK_FLAG_ATTACHED ;list_del_init (&mark->g_list);spin_unlock (&mark->lock);include/linux/fs.h +0
-0include/linux/fs.h struct inode_operations { · line 2155
Quoted 7 lines
include/linux/fs.h +2
-0@@ -2149,6 +2149,8 @@ struct inode_operations {int (*fileattr_set)(struct user_namespace *mnt_userns,struct dentry *dentry,struct fileattr *fa);int (*fileattr_get)(struct dentry *dentry,struct fileattr *fa); +int (*fsnotify_update)(struct inode *inode,uint32_t action, +uint64_t group,uint32_t mask); }____cacheline_aligned ;Please split the patch that introduces the API from the FUSE implementation.
Quoted 6 lines
Quoted 4 lines
Regarding the API, group does not belong in this interface. The inode object has an "aggregated mask" at
i_fsnotify_maskindicating an interest for an event from any group. Remote servers should be notified when the aggregated mask changes.Is aggregated mask updated when nobody is watching for that event. I
It should, that's the whole point of the i_fsnotify_mask.
To optimize at the lowest level possible and do nothing if no subscriber is interested in event X.
Quoted 2 lines
am not familiar with the code yet but Ioannis says that it does not seem to happen.
Details please.
The object interest mask is updated in __fsnotify_recalc_mask() and fsnotify_detach_connector_from_object().
For inotify those calls should be coming from:inotify_rm_watch() => (final) fsnotify_put_mark()
Or from:inotify_release() => fsnotify_destroy_group() =>
fsnotify_clear_marks_by_group()
Quoted 5 lines
That means once an event is being watched, it will
continue to be generated on server and will continue to travel to guest and ultimately guest will drop that event because no application is watching.
There is alway going to be some lag between a process losing interest is an event and the producer getting notified of the loss of interest, but the API/protocol is supposed to publish the interest of subscribers to publishers.
Quoted 8 lines
If number of events generated are significant, it is a problem. Storing and forwarding so many events can consume significant amount of memory and cpu and also trigger dropping of some of the events.
Having said that, probably right fix is in fsnotify API so that "aggregated mask" is updated to remove events as well. And then remote file systems can update server aggreated mask too.
Yes, if it is broken, it definitely needs to be fixed. At this time, I am not sure if this is the case.
Quoted 5 lines
Quoted 5 lines
Hence, Miklos has proposed a "remote fsnotify update" API which does not carry the mask nor the action, only the watched object:
https://lore.kernel.org/linux-fsdevel/[email protected]/
Quoted 7 lines
Quoted 2 lines
On that same thread, you will see that I also proposed the API to support full filesystem watch (by passing sb).
When you say API, you just mean signature of inode operation function. Say ->notify_update(). If we were to support "sb" later, updating inode operations should be easy. But I get the point that from VFS API point of view, pass whole inode to filesystems.
Right.
This is internal fs/vfs API, but still it is a nuisance to create an operation and add another one later or change the signature in all filesystems, although in this case it's probably only fuse so less of a problem. TBH, I think this API might be a better fit for super_operations and I don't think that we need an inode_operation as well:
int (*fsnotify_update)(struct super_block *sb, struct inode *inode,
uint32_t action, uint32_t mask);
I only left 'action' as a hint, because maybe filesystem wants to treat additions to mask differently than removals, but it is optional or rather a generic UPDATE value could be used when the change is the nature of the mask change unknown.
'sb' is mandatory because it will determine to which server the mask update is intended.
'inode' is optional, where a NULL value could be interpreted as "any inode" or "global filesystem watch mask".
In my view, the remote filesystem is the event generator 'inode' and 'mask' are just two parameters of event filters. The view that perceives an 'inode' as the event generator is a view that matches an "inotify watch" as the source of events, which is the core of my objection.
Keep in mind that virtiofsd (and any fuse filesystem) can implement the remote fsnotify backend without any host OS support for fs notifications - By publishing to interested guests the operations performed by other guests. The server only needs the host OS support for publishing to guests changes performed by the host.
Thanks,
Amir.
RFC PATCH 4/7 FUSE: Add the fuse_fsnotify_send_request to FUSE
In reply to Ioannis AngelakopoulosThe function "fuse_fsnotify_send_request" is responsible for sending an fsnotify FUSE request to the FUSE server (virtiofsd).
The request contains all the information that is stored within the "fuse_notify_fsnotify_in" struct, i.e., the event mask for the inotify watch, the action to be performed on the watch (create, modify or delete) and the group identifier which is essentially the 64bit (fsnotify_group) pointer that corresponds to one inotify instance created by a user space process.
Since each group identifier is unique, the FUSE server can create an equal number of inotify instances to the ones created by the user space processes.
--- fs/fuse/dev.c | 37 +++++++++++++++++++++++++++++++++++++ fs/fuse/fuse_i.h | 3 +++ 2 files changed, 40 insertions(+)
fs/fuse/dev.c +37 -0
@@ -1795,6 +1795,43 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code, } } +/* Send a request for a watch placement to the FUSE server */ +int fuse_fsnotify_send_request (struct inode *inode,uint32_t mask, +uint32_t action,uint64_t group) +{ +struct fuse_mount *fm =get_fuse_mount (inode); +struct fuse_notify_fsnotify_in inarg; +int err; +FUSE_ARGS (args); + +/* The server does not support remote fsnotify events */ +if (fm->fc->no_fsnotify) +return 0 ; + +/* +* Send the mask the action (remove, add, modify) and the +* unique identifier that is the fsnotify group that is +* interested in the watch to the FUSE server +*/ +memset (&inarg,0 ,sizeof (struct fuse_notify_fsnotify_in )); + inarg.mask = mask; + inarg.action = action; + inarg.group = (uint64_t )group; + + args.opcode =FUSE_FSNOTIFY ; + args.nodeid =get_node_id (inode); + args.in_numargs =1 ; + args.in_args[0 ].size =sizeof (struct fuse_notify_fsnotify_in ); + args.in_args[0 ].value = &inarg; + args.out_numargs =0 ; + args.force = true; + + err =fuse_simple_request (fm, &args); + +return err; +} +EXPORT_SYMBOL (fuse_fsnotify_send_request); +/* Look up request on processing list by unique ID */ static struct fuse_req *request_find (struct fuse_pqueue *fpq,u64 unique) {
fs/fuse/fuse_i.h +3 -0
@@ -1243,6 +1243,9 @@ struct posix_acl *fuse_get_acl(struct inode *inode, int type, bool rcu);int fuse_set_acl (struct user_namespace *mnt_userns,struct inode *inode,struct posix_acl *acl,int type); +int fuse_fsnotify_send_request (struct inode *inode,uint32_t mask, +uint32_t action,uint64_t group); +/* readdir.c */ int fuse_readdir (struct file *file,struct dir_context *ctx);
Signature · 1 line
2.33.0
RFC PATCH 5/7 Fsnotify: Add a wrapper around the fsnotify function
In reply to Ioannis AngelakopoulosGenerally, inotify events are generated locally by calling the "fsnotify" function in fs/notify/fsnotify.c and various helper functions. However, now we expect events to arrive from the FUSE server. Thus, without any intervention a user space application will receive two events. One event is generated locally and one arrives from the server.
Hence, to avoid duplicate events we need to "suppress" the local events generated by the guest kernel for FUSE inodes. To achieve this we add a wrapper around the "fsnotify" function in fs/notify/fsnotify.c that checks if the remote inotify is enabled and based on the check either it "suppresses" or lets through a local event.
The wrapper will be called in the place of the original "fsnotify" call that is responsible for the event notification (now renamed as "__fsnotify").
When the remote inotify is not enabled, all local events will be let through as expected. This process is completely transparent to user space.
--- fs/notify/fsnotify.c | 35 ++++++++++++++++++++++++++++++-- include/linux/fsnotify_backend.h | 14 ++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-)
fs/notify/fsnotify.c +33 -2
@@ -440,7 +440,7 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info) }/* -* fsnotify - This is the main call to fsnotify. +* __fsnotify - This is the main call to fsnotify. * * The VFS calls into hook specific functions in linux/fsnotify.h. * Those functions then in turn call here. Here will call out to all of the
@@ -459,7 +459,7 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info)* if both are non-NULL event may be reported to both. * @cookie: inotify rename cookie */ -int fsnotify (__u32 mask,const void *data,int data_type,struct inode *dir, +int __fsnotify (__u32 mask,const void *data,int data_type,struct inode *dir,const struct qstr *file_name,struct inode *inode,u32 cookie) {const struct path *path =fsnotify_data_path (data, data_type);
@@ -552,6 +552,37 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,return ret; } + +/* +* Wrapper around fsnotify. The main functionality is to filter local events in +* case the inode belongs to a filesystem that supports remote events +*/ +int fsnotify (__u32 mask,const void *data,int data_type,struct inode *dir, +const struct qstr *file_name,struct inode *inode,u32 cookie) +{ + +if (inode !=NULL || dir !=NULL ) { +/* +* Check if the fsnotify_event operation is available which +* will let the remote inotify events go through and suppress +* the local events +*/ +if (inode && inode->i_op->fsnotify_event) { +return inode->i_op->fsnotify_event (mask, data, + data_type, dir, + file_name, inode, + cookie); + } +if (dir && dir->i_op->fsnotify_event) { +return dir->i_op->fsnotify_event (mask, data, + data_type, dir, + file_name, inode, + cookie); + } + } + +return __fsnotify (mask, data, data_type, dir, file_name, inode, cookie); +}EXPORT_SYMBOL_GPL (fsnotify);static __init int fsnotify_init (void )
include/linux/fsnotify_backend.h +13 -1
@@ -408,10 +408,15 @@ struct fsnotify_mark {/* called from the vfs helpers */ -/* main fsnotify call to send events */ +/* fsnotify call wrapper */ extern int fsnotify (__u32 mask,const void *data,int data_type,struct inode *dir,const struct qstr *name,struct inode *inode,u32 cookie); + +/* main fsnotify call to send events */ +extern int __fsnotify (__u32 mask,const void *data,int data_type, +struct inode *dir,const struct qstr *name, +struct inode *inode,u32 cookie);extern int __fsnotify_parent (struct dentry *dentry,__u32 mask,const void *data,int data_type);extern void __fsnotify_inode_delete (struct inode *inode);
@@ -595,6 +600,13 @@ static inline int fsnotify(__u32 mask, const void *data, int data_type,return 0 ; } +static inline int __fsnotify (__u32 mask,const void *data,int data_type, +struct inode *dir,const struct qstr *name, +struct inode *inode,u32 cookie) +{ +return 0 ; +} +static inline int __fsnotify_parent (struct dentry *dentry,__u32 mask,const void *data,int data_type) {
Signature · 1 line
2.33.0
Amir Goldstein
reviewerRe: [RFC PATCH 5/7] Fsnotify: Add a wrapper around the fsnotify function
Quoted 71 lines · Ioannis Angelakopoulos
Generally, inotify events are generated locally by calling the "fsnotify" function in
fs/notify/fsnotify.cand various helper functions. However, now we expect events to arrive from the FUSE server. Thus, without any intervention a user space application will receive two events. One event is generated locally and one arrives from the server.Hence, to avoid duplicate events we need to "suppress" the local events generated by the guest kernel for FUSE inodes. To achieve this we add a wrapper around the "fsnotify" function in
fs/notify/fsnotify.cthat checks if the remote inotify is enabled and based on the check either it "suppresses" or lets through a local event.The wrapper will be called in the place of the original "fsnotify" call that is responsible for the event notification (now renamed as "
__fsnotify").When the remote inotify is not enabled, all local events will be let through as expected. This process is completely transparent to user space.
Signed-off-by Ioannis Angelakopoulos <[email protected]>--- fs/notify/fsnotify.c | 35 ++++++++++++++++++++++++++++++-- include/linux/fsnotify_backend.h | 14 ++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-)fs/notify/fsnotify.c +21
-2@@ -440,7 +440,7 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info) }/* -* fsnotify - This is the main call to fsnotify. +* __fsnotify - This is the main call to fsnotify. * * The VFS calls into hook specific functions in linux/fsnotify.h. * Those functions then in turn call here. Here will call out to all of the @@ -459,7 +459,7 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info)* if both are non-NULL event may be reported to both. * @cookie: inotify rename cookie */ -int fsnotify (__u32 mask,const void *data,int data_type,struct inode *dir, +int __fsnotify (__u32 mask,const void *data,int data_type,struct inode *dir,const struct qstr *file_name,struct inode *inode,u32 cookie) {const struct path *path =fsnotify_data_path (data, data_type);@@ -552,6 +552,37 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,return ret; } + +/* +* Wrapper around fsnotify. The main functionality is to filter local events in +* case the inode belongs to a filesystem that supports remote events +*/ +int fsnotify (__u32 mask,const void *data,int data_type,struct inode *dir, +const struct qstr *file_name,struct inode *inode,u32 cookie) +{ + +if (inode !=NULL || dir !=NULL ) { +/* +* Check if the fsnotify_event operation is available which +* will let the remote inotify events go through and suppress +* the local events +*/ +if (inode && inode->i_op->fsnotify_event) { + return inode->i_op->fsnotify_event(mask, data, + data_type, dir, + file_name, inode,
fs/notify/fsnotify.c int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, · line 583
Quoted 10 lines
fs/notify/fsnotify.c +10
-0+ cookie); + } +if (dir && dir->i_op->fsnotify_event) { +return dir->i_op->fsnotify_event (mask, data, + data_type, dir, + file_name, inode, + cookie); + } + } +
That's not the way to accomplish what you want to do.
Assuming that we agree to let filesystem silence VFS fsnotify hooks it should be done using an inode flag, similar to file flag FMODE_NONOTIFY.
But the reason you want to do that seems a bit odd. Duplicate events are going to be merged with fanotify and I think that you ruled out fanotify for the wrong reasons
(you should have only ruled out permission events)
Thanks,
Amir.
Vivek Goyal
maintainerRe: [RFC PATCH 5/7] Fsnotify: Add a wrapper around the fsnotify function
Quoted 86 lines · Amir Goldstein
Quoted 71 lines · Ioannis Angelakopoulos
Generally, inotify events are generated locally by calling the "fsnotify" function in
fs/notify/fsnotify.cand various helper functions. However, now we expect events to arrive from the FUSE server. Thus, without any intervention a user space application will receive two events. One event is generated locally and one arrives from the server.Hence, to avoid duplicate events we need to "suppress" the local events generated by the guest kernel for FUSE inodes. To achieve this we add a wrapper around the "fsnotify" function in
fs/notify/fsnotify.cthat checks if the remote inotify is enabled and based on the check either it "suppresses" or lets through a local event.The wrapper will be called in the place of the original "fsnotify" call that is responsible for the event notification (now renamed as "
__fsnotify").When the remote inotify is not enabled, all local events will be let through as expected. This process is completely transparent to user space.
Signed-off-by Ioannis Angelakopoulos <[email protected]>--- fs/notify/fsnotify.c | 35 ++++++++++++++++++++++++++++++-- include/linux/fsnotify_backend.h | 14 ++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-)fs/notify/fsnotify.c +21
-2@@ -440,7 +440,7 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info) }/* -* fsnotify - This is the main call to fsnotify. +* __fsnotify - This is the main call to fsnotify. * * The VFS calls into hook specific functions in linux/fsnotify.h. * Those functions then in turn call here. Here will call out to all of the @@ -459,7 +459,7 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info)* if both are non-NULL event may be reported to both. * @cookie: inotify rename cookie */ -int fsnotify (__u32 mask,const void *data,int data_type,struct inode *dir, +int __fsnotify (__u32 mask,const void *data,int data_type,struct inode *dir,const struct qstr *file_name,struct inode *inode,u32 cookie) {const struct path *path =fsnotify_data_path (data, data_type);@@ -552,6 +552,37 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,return ret; } + +/* +* Wrapper around fsnotify. The main functionality is to filter local events in +* case the inode belongs to a filesystem that supports remote events +*/ +int fsnotify (__u32 mask,const void *data,int data_type,struct inode *dir, +const struct qstr *file_name,struct inode *inode,u32 cookie) +{ + +if (inode !=NULL || dir !=NULL ) { +/* +* Check if the fsnotify_event operation is available which +* will let the remote inotify events go through and suppress +* the local events +*/ +if (inode && inode->i_op->fsnotify_event) { + return inode->i_op->fsnotify_event(mask, data, + data_type, dir, + file_name, inode,fs/notify/fsnotify.c int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, · line 583
Quoted 10 lines
fs/notify/fsnotify.c +10
-0+ cookie); + } +if (dir && dir->i_op->fsnotify_event) { +return dir->i_op->fsnotify_event (mask, data, + data_type, dir, + file_name, inode, + cookie); + } + } +That's not the way to accomplish what you want to do.
Quoted 2 lines
Assuming that we agree to let filesystem silence VFS fsnotify hooks it should be done using an inode flag, similar to file flag
FMODE_NONOTIFY.
Ok, so basically define a new flag say FMODE_FOO and check that in fsnotify() and ignore event if flag is set. And filesystem can set that flag if remote events are enabled. And then vfs will ignore local events. Sounds reasonable.
Quoted 2 lines
But the reason you want to do that seems a bit odd.
I gave this idea to Ioannis. But defining a inode flag probably is much cheaper as comapred to inode operation.
Quoted 3 lines
Duplicate events are going to be merged with fanotify and I think that you ruled out fanotify for the wrong reasons
(you should have only ruled out permission events)
Ioannis was looking at fanoity and wondering if fanotify can be supported as well. fanotify seemed to be much more powerful as compared to inotify and some of the things looked like not feasible to be supported for remote filesystems.
But if it is acceptable to support only limited functionality/events, then it probably is a good idea to keep fanotify in mind and somebody can extend it for fanotify as well.
Ideally it will be nice to support fanoity as well (as much as possible). Just that it seemed more complicated. So we thought that let us start with a simpler API (inotify) and try to implement that first.
I don't understand "Duplicate events are going to be merged with fanotify". So fanotiy has something to figure out there are duplicate events and merge these and user space never sees duplicate events.
Vivek
RFC PATCH 6/7 FUSE,Fsnotify: Add the fuse_fsnotify_event inode operation
In reply to Ioannis AngelakopoulosTo avoid duplicate events we need to "suppress" the local events generated by the guest kernel for FUSE inodes. To achieve this we introduce a new inode operation "fuse_fsnotify_event". Any VFS operation on a FUSE inode that calls the fsnotify subsystem will call this function.
Specifically, the new inode operation "fuse_fsnotify_event" is called by the "fsnotify" wrapper function in fsnotify.c, if the inode is a FUSE inode. In turn "fuse_fsnotify_event" will check if the remote inotify is enabled and if yes the event will be dropped, since the local inotify events should be "suppressed". If the remote inotify is not enabled the event will go through as expected.
In the case where the remote inotify is enabled, FUSE will directly call "__fsnotify" to send the remote events to user space and not the "fsnotify" wrapper.
--- fs/fuse/dir.c | 27 +++++++++++++++++++++++++++ include/linux/fs.h | 3 +++ 2 files changed, 30 insertions(+)
fs/fuse/dir.c +27 -0
@@ -1831,6 +1831,30 @@ static int fuse_fsnotify_update_mark(struct inode *inode, uint32_t action,return fuse_fsnotify_send_request (inode, mask, action, group); } +static int fuse_fsnotify_event (__u32 mask,const void *data,int data_type, +struct inode *dir,const struct qstr *file_name, +struct inode *inode,u32 cookie) +{ +struct fuse_mount *fm =NULL ; + +if (inode !=NULL ) + fm =get_fuse_mount (inode); +else + fm =get_fuse_mount (dir); + +/* Remote inotify supported. Do nothing */ +if (!(fm->fc->no_fsnotify)) { +return 0 ; +/* +* Remote inotify not supported. Call the __fsnotify function +* directly +*/ + }else { +return __fsnotify (mask, data, data_type, dir, file_name, + inode, cookie); + } +} +static const struct inode_operations fuse_dir_inode_operations = { .lookup = fuse_lookup, .mkdir = fuse_mkdir,
@@ -1851,6 +1875,7 @@ static const struct inode_operations fuse_dir_inode_operations = { .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set, .fsnotify_update = fuse_fsnotify_update_mark, + .fsnotify_event = fuse_fsnotify_event, };static const struct file_operations fuse_dir_operations = {
@@ -1874,6 +1899,7 @@ static const struct inode_operations fuse_common_inode_operations = { .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set, .fsnotify_update = fuse_fsnotify_update_mark, + .fsnotify_event = fuse_fsnotify_event, };static const struct inode_operations fuse_symlink_inode_operations = {
@@ -1882,6 +1908,7 @@ static const struct inode_operations fuse_symlink_inode_operations = { .getattr = fuse_getattr, .listxattr = fuse_listxattr, .fsnotify_update = fuse_fsnotify_update_mark, + .fsnotify_event = fuse_fsnotify_event, };void fuse_init_common (struct inode *inode)
include/linux/fs.h +3 -0
@@ -2151,6 +2151,9 @@ struct inode_operations {int (*fileattr_get)(struct dentry *dentry,struct fileattr *fa);int (*fsnotify_update)(struct inode *inode,uint32_t action,uint64_t group,uint32_t mask); +int (*fsnotify_event)(__u32 mask,const void *data,int data_type, +struct inode *dir,const struct qstr *file_name, +struct inode *inode,u32 cookie); }____cacheline_aligned ; static inline ssize_t call_read_iter(struct file *file, struct kiocb *kio,
Signature · 1 line
2.33.0
RFC PATCH 7/7 virtiofs: Add support for handling the remote fsnotify notifications
In reply to Ioannis AngelakopoulosFUSE and specifically virtiofs should be able to handle the asynchronous event notifications originating from the FUSE server. To this end we add the FUSE_NOTIFY_FSNOTIFY switch case to the "virtio_fs_handle_notify" in fs/fuse/virtio_fs.c to handle these specific notifications.
The event notification contains the information that a user space application would receive when monitoring an inode for events. The information is the mask of the inode watch, a file name corresponding to the inode the remote event was generated for and finally, the inotify cookie.
Then a new event should be generated corresponding to the event notification received from the FUSE server. Specifically, FUSE in the guest kernel will call the "__fsnotify" function in fs/notify/fsnotify.c to send the event to user space.
--- fs/fuse/virtio_fs.c | 64 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-)
fs/fuse/virtio_fs.c +62 -2
@@ -16,6 +16,7 @@#include <linux/fs_parser.h> #include <linux/highmem.h> #include <linux/uio.h> +#include <linux/fsnotify_backend.h> #include "fuse_i.h" /* Used to help calculate the FUSE connection's max_pages limit for a request's
@@ -655,14 +656,69 @@ static void notify_node_reuse(struct virtio_fs_vq *notify_fsvq,spin_unlock (¬ify_fsvq->lock); } +static int fsnotify_remote_event (struct inode *inode,uint32_t mask, +struct qstr *filename,uint32_t cookie) +{ +return __fsnotify (mask,NULL ,0 ,NULL , + (const struct qstr *)filename, inode, cookie); +} + +/* +* Function to generate a new event when a fsnotify notification comes from the +* fuse server +*/ +static int generate_fsnotify_event (struct fuse_conn *fc, +struct fuse_notify_fsnotify_out *fsnotify_out) +{ +struct inode *inode; +uint32_t mask, cookie; +struct fuse_mount *fm; +int ret =-1 ; +struct qstr name; + +down_read (&fc->killsb); + inode =fuse_ilookup (fc, fsnotify_out->inode, &fm); +/* +* The inode that corresponds to the event does not exist in this case +* so do not generate any new event and just return an error +*/ +if (!inode) + goto out; + + mask = fsnotify_out->mask; + cookie = fsnotify_out->cookie; + +/* +* If the notification contained the name of the file/dir the event +* occurred for, it will be placed after the fsnotify_out struct in the +* notification message +*/ +if (fsnotify_out->namelen >0 ) { + name.len = fsnotify_out->namelen; + name.name = (char *)fsnotify_out +sizeof (struct fuse_notify_fsnotify_out ); + ret =fsnotify_remote_event (inode, mask, &name, cookie); + }else { + ret =fsnotify_remote_event (inode, mask,NULL , cookie); + } + +up_read (&fc->killsb); +out: +if (ret <0 ) +return -EINVAL ; + +return ret; +} +static int virtio_fs_handle_notify (struct virtio_fs *vfs, -struct virtio_fs_notify_node *notifyn) +struct virtio_fs_notify_node *notifyn, +struct fuse_conn *fc) {int ret =0 , no_reuse =0 ;struct virtio_fs_notify *notify = ¬ifyn->notify;struct virtio_fs_vq *notify_fsvq = &vfs->vqs[VQ_NOTIFY_IDX ];struct fuse_out_header *oh = ¬ify->out_hdr;struct fuse_notify_lock_out *lo; +struct fuse_notify_fsnotify_out *fsnotify_out;/* * For notifications, oh.unique is 0 and oh->error contains code
@@ -673,6 +729,10 @@ static int virtio_fs_handle_notify(struct virtio_fs *vfs, lo = (struct fuse_notify_lock_out *) ¬ify->outarg; no_reuse =notify_complete_waiting_req (vfs, lo);break ; +case FUSE_NOTIFY_FSNOTIFY : + fsnotify_out = (struct fuse_notify_fsnotify_out *) ¬ify->outarg; +generate_fsnotify_event (fc, fsnotify_out); +break ;default :pr_err ("virtio-fs: Unexpected notification %d\n" , oh->error); }
@@ -711,7 +771,7 @@ static void virtio_fs_notify_done_work(struct work_struct *work)WARN_ON (oh->unique);list_del_init (¬ifyn->list);/* Handle notification */ -virtio_fs_handle_notify (vfs, notifyn); +virtio_fs_handle_notify (vfs, notifyn, fsvq->fud->fc);spin_lock (&fsvq->lock);dec_in_flight_req (fsvq);spin_unlock (&fsvq->lock);
Signature · 1 line
2.33.0
Amir Goldstein
reviewerQuoted 8 lines · Ioannis Angelakopoulos
Hello,
I am a PhD student currently interning at Red Hat and working on the virtiofs file system. I am trying to add support for the Inotify notification subsystem in virtiofs. I seek your feedback and suggestions on what is the right direction to take.
Hi Ioannis!
I am very happy that you have taken on this task. People have been requesting this functionality in the past [1] Not specifically for FUSE, but FUSE is a very good place to start.
Quoted 21 lines
Currently, virtiofs does not support the Inotify API and there are applications which look for the Inotify support in virtiofs (e.g., Kata containers).
However, all the event notification subsystems (Dnotify/Inotify/Fanotify) are supported by only by local kernel file systems.
--Proposed solution
With this RFC patch we add the inotify support to the FUSE kernel module so that the remote virtiofs file system (based on FUSE) used by a QEMU guest VM can make use of this feature.
Specifically, we enhance FUSE to add/modify/delete watches on the FUSE server and also receive remote inotify events. To achieve this we modify the fsnotify subsystem so that it calls specific hooks in FUSE when a remote watch is added/modified/deleted and FUSE calls into fsnotify when a remote event is received to send the event to user space.
In our case the FUSE server is virtiofsd.
Quoted 7 lines
We also considered an out of band approach for implementing the remote notifications (e.g., FAM, Gamin), however this approach would break applications that are already compatible with inotify, and thus would require an update.
These kernel patches depend on the patch series posted by Vivek Goyal:
https://lore.kernel.org/linux-fsdevel/[email protected]/
It would be a shame if remote fsnotify was not added as a generic capability to FUSE filesystems and not only virtiofs. Is there a way to get rid of this dependency?
Quoted 29 lines
My PoC Linux kernel patches are here:
https://github.com/iangelak/linux/commits/inotify_v1My PoC virtiofsd corresponding patches are here:
https://github.com/iangelak/qemu/commits/inotify_v1--Advantages
1) Our approach is compatible with existing applications that rely on Inotify, thus improves portability.
2) Everything is implemented in one place (virtiofs and virtiofsd) and there is no need to run additional processes (daemons) specifically to handle the remote notifications.
--Weaknesses
1) Both a local (QEMU guest) and a remote (Host/Virtiofsd) watch on the target inode have to be active at the same time. The local watch guarantees that events are going to be sent to the guest user space while the remote watch captures events occurring on the host (and will be sent to the guest).
As a result, when an event occures on a inode within the exported directory by virtiofs, two events will be generated at the same time; a local event (generated by the guest kernel) and a remote event (generated by the host), thus the guest will receive duplicate events.
Quoted 5 lines
To account for this issue we implemented two modes; one where local events function as expected (when virtiofsd does not support the remote inotify) and one where the local events are suppressed and only the remote events originating from the host side are let through (when virtiofsd supports the remote inotify).
Dropping events from the local side would be weird. Avoiding duplicate events is not a good enough reason IMO compared to the problems this could cause.
I am not convinced this is worth it.
Quoted 21 lines
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest does not receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the watch). In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the guest kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore). On top of that, virtiofsd keeps an open proc file descriptor for each inode that is not immediately closed on a inode deletion request by the guest. As a result no
IN_DELETE_SELFis generated by virtiofsd and sent to the guest kernel in this case.4) Because virtiofsd implements additional operations during the servicing of a request from the guest, additional inotify events might be generated and sent to the guest other than the ones the guest expects. However, this is not technically a limitation and it is dependent on the implementation of the remote file system server (in this case virtiofsd).
Quoted 5 lines
5) The current implementation only supports Inotify, due to its simplicity and not Fanotify. Fanotify's complexity requires support from virtiofsd that is not currently available. One such example is Fsnotify's access permission decision capabilities, which could conflict with virtiofsd's current access permission implementation.
Good example, bad decision.
It is perfectly fine for a remote server to provide a "supported event mask" and leave permission events out of the game.
Imagine a remote SMB server, it also does not support all of the events that the local application would like to set.
That should not be a reason to rule out fanotify, only specific fanotify events.
Same goes to FAN_MARK_MOUNT and FAN_MARK_FILESYSTEM
remote server may or may not support anything other than watching inode objects, but it should not be a limit of the "remote fsnotify" API.
Thanks,
Amir.
Vivek Goyal
maintainerQuoted 11 lines · Amir Goldstein
Quoted 8 lines · Ioannis Angelakopoulos
Hello,
I am a PhD student currently interning at Red Hat and working on the virtiofs file system. I am trying to add support for the Inotify notification subsystem in virtiofs. I seek your feedback and suggestions on what is the right direction to take.
Quoted 7 lines
Hi Ioannis!
I am very happy that you have taken on this task. People have been requesting this functionality in the past [1] Not specifically for FUSE, but FUSE is a very good place to start.
Hi Amir,
Aha, good to know that other remote filesystems are looking for similar functionality. So there can be a common design so that other remote filesystems can support remote inotify/fanotify events too.
Quoted 27 lines
Quoted 27 lines
Currently, virtiofs does not support the Inotify API and there are applications which look for the Inotify support in virtiofs (e.g., Kata containers).
However, all the event notification subsystems (Dnotify/Inotify/Fanotify) are supported by only by local kernel file systems.
--Proposed solution
With this RFC patch we add the inotify support to the FUSE kernel module so that the remote virtiofs file system (based on FUSE) used by a QEMU guest VM can make use of this feature.
Specifically, we enhance FUSE to add/modify/delete watches on the FUSE server and also receive remote inotify events. To achieve this we modify the fsnotify subsystem so that it calls specific hooks in FUSE when a remote watch is added/modified/deleted and FUSE calls into fsnotify when a remote event is received to send the event to user space.
In our case the FUSE server is virtiofsd.
We also considered an out of band approach for implementing the remote notifications (e.g., FAM, Gamin), however this approach would break applications that are already compatible with inotify, and thus would require an update.
Quoted 6 lines
Quoted 2 lines
These kernel patches depend on the patch series posted by Vivek Goyal:
https://lore.kernel.org/linux-fsdevel/[email protected]/It would be a shame if remote fsnotify was not added as a generic capability to FUSE filesystems and not only virtiofs. Is there a way to get rid of this dependency?
Agreed. I think currently he has just added support for virtiofs. But it should be possible to extend it to other fuse filesystems as well. All they need to do is send notification and regular fuse already has support for allowing server to send notifications to fuse client kernel.
Quoted 36 lines
Quoted 30 lines
My PoC Linux kernel patches are here:
https://github.com/iangelak/linux/commits/inotify_v1My PoC virtiofsd corresponding patches are here:
https://github.com/iangelak/qemu/commits/inotify_v1--Advantages
1) Our approach is compatible with existing applications that rely on Inotify, thus improves portability.
2) Everything is implemented in one place (virtiofs and virtiofsd) and there is no need to run additional processes (daemons) specifically to handle the remote notifications.
--Weaknesses
1) Both a local (QEMU guest) and a remote (Host/Virtiofsd) watch on the target inode have to be active at the same time. The local watch guarantees that events are going to be sent to the guest user space while the remote watch captures events occurring on the host (and will be sent to the guest).
As a result, when an event occures on a inode within the exported directory by virtiofs, two events will be generated at the same time; a local event (generated by the guest kernel) and a remote event (generated by the host), thus the guest will receive duplicate events.
Quoted 5 lines
To account for this issue we implemented two modes; one where local events function as expected (when virtiofsd does not support the remote inotify) and one where the local events are suppressed and only the remote events originating from the host side are let through (when virtiofsd supports the remote inotify).
Quoted 4 lines
Dropping events from the local side would be weird. Avoiding duplicate events is not a good enough reason IMO compared to the problems this could cause.
I am not convinced this is worth it.
So what should be done? If we don't drop local events, then application will see both local and remote events. And then we will have to build this knowledge in API that an event can be either local or remote. Application should be able to distinguish between these two and act accordingly. That sounds like a lot. And I am not even sure if application cares about local events in case of a remote shared filesystem.
I have no experience with inotify/fanotify/fsnotify and what people expect from inotify/fanotify API. So we are open to all the ideas w.r.t what will be a good design to support this thing on remote filesystems. Currently whole infrastructure seems to be written with local filesystems in mind.
Quoted 35 lines
Quoted 22 lines
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest does not receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the watch). In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the guest kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore). On top of that, virtiofsd keeps an open proc file descriptor for each inode that is not immediately closed on a inode deletion request by the guest. As a result no
IN_DELETE_SELFis generated by virtiofsd and sent to the guest kernel in this case.4) Because virtiofsd implements additional operations during the servicing of a request from the guest, additional inotify events might be generated and sent to the guest other than the ones the guest expects. However, this is not technically a limitation and it is dependent on the implementation of the remote file system server (in this case virtiofsd).
Quoted 5 lines
5) The current implementation only supports Inotify, due to its simplicity and not Fanotify. Fanotify's complexity requires support from virtiofsd that is not currently available. One such example is Fsnotify's access permission decision capabilities, which could conflict with virtiofsd's current access permission implementation.
Good example, bad decision.
It is perfectly fine for a remote server to provide a "supported event mask" and leave permission events out of the game.Imagine a remote SMB server, it also does not support all of the events that the local application would like to set.
Quoted 6 lines
That should not be a reason to rule out fanotify, only specific fanotify events.
Same goes to
FAN_MARK_MOUNTandFAN_MARK_FILESYSTEM
remote server may or may not support anything other than watching inode objects, but it should not be a limit of the "remote fsnotify" API.
Agreed. If limited fanotify functionality is acceptable, then it should be written in such a way so that one can easily extend it to support limited fanotify support.
Thanks
Vivek
Amir Goldstein
reviewerQuoted 16 lines
Quoted 11 lines
Quoted 10 lines
As a result, when an event occures on a inode within the exported directory by virtiofs, two events will be generated at the same time; a local event (generated by the guest kernel) and a remote event (generated by the host), thus the guest will receive duplicate events.
To account for this issue we implemented two modes; one where local events function as expected (when virtiofsd does not support the remote inotify) and one where the local events are suppressed and only the remote events originating from the host side are let through (when virtiofsd supports the remote inotify).
Quoted 4 lines
Dropping events from the local side would be weird. Avoiding duplicate events is not a good enough reason IMO compared to the problems this could cause.
I am not convinced this is worth it.
Quoted 7 lines
So what should be done? If we don't drop local events, then application will see both local and remote events. And then we will have to build this knowledge in API that an event can be either local or remote. Application should be able to distinguish between these two and act accordingly. That sounds like a lot. And I am not even sure if application cares about local events in case of a remote shared filesystem.
I am not completely ruling out the S_NONOTIFY inode flag, but I am not yet convinced that it is needed.
So what if applications get duplicate events? What's the worst thing that could happen?
And once again, merging most of the duplicate events is pretty easy and fanotify does that already.
Quoted 6 lines
I have no experience with inotify/fanotify/fsnotify and what people expect from inotify/fanotify API. So we are open to all the ideas w.r.t what will be a good design to support this thing on remote filesystems. Currently whole infrastructure seems to be written with local filesystems in mind.
I have no control of what users expect from inotify/fanotify but I do know that some users' expectations are misaligned with how inotify/fanotify actually works.
For example, some users may expect events not to be reordered, but there is no such guarantee.
Some inotify users would expect to find a file with the filename in the event without realizing that this is a snapshot of a past filename, that may now not exist or be a completely different object.
Those are some misconceptions that we tried to address with the fanotify FAN_REPORT_DFID_NAME APIs and hopefully we also documented the expectations better in the man page.
The use of NFS file handles to identify objects in the FAN_REPORT_FID modes enables getting events also for already dead objects (without keeping the inode alive like inotify).
I didn't want to complicate Ioannis in this early stage, but I think that FUSE fsnotify should be tied to LOOKUP_HANDLE.
All FUSE remote objects should be described by file handles which is the same manner in which network protocols work and file handles should be used to describe objects in fsnotify FUSE events.
But I am getting ahead of myself with a lot of hand waving....
Thanks,
Amir.
Vivek Goyal
maintainerOn Tue, Oct 26, 2021 at 06:23:50PM +0300, Amir Goldstein wrote:
[..]
Quoted 8 lines
Quoted 8 lines
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest does not receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the watch). In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the guest kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore).
So this is one of the issues which has been haunting us in virtiofs. If a file is removed, for local events, event is generated first and then watch is removed. But in case of remote filesystems, it is racy. It is possible that by the time event arrives, watch is already gone and application never sees the delete event.
Not sure how to address this issue.
Vivek
Amir Goldstein
reviewerQuoted 13 lines · Vivek Goyal
On Tue, Oct 26, 2021 at 06:23:50PM +0300, Amir Goldstein wrote:
[..]
Quoted 8 lines
Quoted 8 lines
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest does not receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the watch). In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the guest kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore).
Quoted 7 lines
So this is one of the issues which has been haunting us in virtiofs. If a file is removed, for local events, event is generated first and then watch is removed. But in case of remote filesystems, it is racy. It is possible that by the time event arrives, watch is already gone and application never sees the delete event.
Not sure how to address this issue.
Can you take me through the scenario step by step. I am not sure I understand the exact sequence of the race. If it is local file removal that causes watch to be removed, then don't drop local events and you are good to go. Is it something else?
Thanks,
Amir.
Vivek Goyal
maintainerQuoted 20 lines · Amir Goldstein
Quoted 19 lines · Vivek Goyal
On Tue, Oct 26, 2021 at 06:23:50PM +0300, Amir Goldstein wrote:
[..]
Quoted 8 lines
Quoted 8 lines
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest does not receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the watch). In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the guest kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore).
So this is one of the issues which has been haunting us in virtiofs. If a file is removed, for local events, event is generated first and then watch is removed. But in case of remote filesystems, it is racy. It is possible that by the time event arrives, watch is already gone and application never sees the delete event.
Quoted 5 lines
Quoted 1 line
Not sure how to address this issue.
Can you take me through the scenario step by step. I am not sure I understand the exact sequence of the race.
Ioannis, please correct me If I get something wrong. You know exact details much more than me.
A. Say a guest process unlinks a file.
B. Fuse sends an unlink request to server (virtiofsd)
C. File is unlinked on host. Assume there are no other users so inode
will be freed as well. And event will be generated on host and watch removed.
D. Now Fuse server will send a unlink request reply. unlink notification
might still be in kernel buffers or still be in virtiofsd or could be in virtiofs virtqueue.
E. Fuse client will receive unlink reply and remove local watch.
Fuse reply and notification event are now traveling in parallel on different virtqueues and there is no connection between these two. And it could very well happen that fuse reply comes first, gets processed first and local watch is removed. And notification is processed right after but by then local watch is gone and filesystem will be forced to drop event.
As of now situation is more complicated in virtiofsd. We don't keep file handle open for file and keep an O_PATH fd open for each file. That means in step D above, inode on host is not freed yet and unlink event is not generated yet. When unlink reply reaches fuse client, it sends FORGET messages to server, and then server closes O_PATH fd and then host generates unlink events. By that time its too late, guest has already remove local watches (and triggered removal of remote watches too).
This second problem probably can be solved by using file handles, but basic race will still continue to be there.
Quoted 3 lines
If it is local file removal that causes watch to be removed, then don't drop local events and you are good to go. Is it something else?
- If remote events are enabled, then idea will be that user space gets and event when file is actually removed from server, right? Now it is possible that another VM has this file open and file has not been yet removed. So local event only tells you that file has been removed in guest VM (or locally) but does not tell anything about the state of file on server. (It has been unlinked on server but inode continues to be alive internall).
- If user receives both local and remote delete event, it will be confusing. I guess if we want to see both the events, then there has to be some sort of info in event which classifies whether event is local or remote. And let application act accordingly.
Thanks
Vivek
Amir Goldstein
reviewerQuoted 72 lines · Vivek Goyal
Quoted 20 lines · Amir Goldstein
Quoted 19 lines · Vivek Goyal
On Tue, Oct 26, 2021 at 06:23:50PM +0300, Amir Goldstein wrote:
[..]
Quoted 8 lines
Quoted 8 lines
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest does not receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the watch). In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the guest kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore).
So this is one of the issues which has been haunting us in virtiofs. If a file is removed, for local events, event is generated first and then watch is removed. But in case of remote filesystems, it is racy. It is possible that by the time event arrives, watch is already gone and application never sees the delete event.
Quoted 5 lines
Quoted 1 line
Not sure how to address this issue.
Can you take me through the scenario step by step. I am not sure I understand the exact sequence of the race.
Ioannis, please correct me If I get something wrong. You know exact details much more than me.
A. Say a guest process unlinks a file.
B. Fuse sends an unlink request to server (virtiofsd)
C. File is unlinked on host. Assume there are no other users so inode
will be freed as well. And event will be generated on host and watch removed.
D. Now Fuse server will send a unlink request reply. unlink notification
might still be in kernel buffers or still be in virtiofsd or could be in virtiofs virtqueue.
E. Fuse client will receive unlink reply and remove local watch.Fuse reply and notification event are now traveling in parallel on different virtqueues and there is no connection between these two. And it could very well happen that fuse reply comes first, gets processed first and local watch is removed. And notification is processed right after but by then local watch is gone and filesystem will be forced to drop event.
As of now situation is more complicated in virtiofsd. We don't keep file handle open for file and keep an
O_PATHfd open for each file. That means in step D above, inode on host is not freed yet and unlink event is not generated yet. When unlink reply reaches fuse client, it sends FORGET messages to server, and then server closesO_PATHfd and then host generates unlink events. By that time its too late, guest has already remove local watches (and triggered removal of remote watches too).This second problem probably can be solved by using file handles, but basic race will still continue to be there.
Quoted 3 lines
If it is local file removal that causes watch to be removed, then don't drop local events and you are good to go. Is it something else?
- If remote events are enabled, then idea will be that user space gets and event when file is actually removed from server, right? Now it is possible that another VM has this file open and file has not been yet removed. So local event only tells you that file has been removed in guest VM (or locally) but does not tell anything about the state of file on server. (It has been unlinked on server but inode continues to be alive internall).
Quoted 5 lines
- If user receives both local and remote delete event, it will be confusing. I guess if we want to see both the events, then there has to be some sort of info in event which classifies whether event is local or remote. And let application act accordingly.
Maybe. Not sure this is the way to go.
There are several options to deal with this situation. The thing is that applications cannot usually rely on getting DELETE_SELF events for many different reasons that might keep the inode reflink elevated also on local filesystems.
Perhaps the only way for FUSE (or any network) client to know if object on server was really deleted is to issue a lookup request to the file handle and when getting ESTALE.
It really sounds to me like DELETE_SELF should not be reported at all for the first implementation.
It is very easy to deal with DELETE_SELF events scenario with a filesystem watch, so bare that in mind as a possible application level solution.
Thanks,
Amir.
Quoted 74 lines · Vivek Goyal
Quoted 7 lines · Amir Goldstein
Quoted 6 lines · Vivek Goyal
On Tue, Oct 26, 2021 at 06:23:50PM +0300, Amir Goldstein wrote:
[..]
Quoted 2 lines
Quoted 2 lines
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest
does not
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the
watch).
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the
guest
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore).
So this is one of the issues which has been haunting us in virtiofs. If a file is removed, for local events, event is generated first and then watch is removed. But in case of remote filesystems, it is racy. It is possible that by the time event arrives, watch is already gone and application never sees the delete event.
Quoted 5 lines
Quoted 1 line
Not sure how to address this issue.
Can you take me through the scenario step by step. I am not sure I understand the exact sequence of the race.
Ioannis, please correct me If I get something wrong. You know exact details much more than me.
A. Say a guest process unlinks a file.
B. Fuse sends an unlink request to server (virtiofsd)
C. File is unlinked on host. Assume there are no other users so inode
will be freed as well. And event will be generated on host and watch removed.
D. Now Fuse server will send a unlink request reply. unlink notification
might still be in kernel buffers or still be in virtiofsd or could be in virtiofs virtqueue.
E. Fuse client will receive unlink reply and remove local watch.Fuse reply and notification event are now traveling in parallel on different virtqueues and there is no connection between these two. And it could very well happen that fuse reply comes first, gets processed first and local watch is removed. And notification is processed right after but by then local watch is gone and filesystem will be forced to drop event.
As of now situation is more complicated in virtiofsd. We don't keep file handle open for file and keep an
O_PATHfd open for each file. That means in step D above, inode on host is not freed yet and unlink event is not generated yet. When unlink reply reaches fuse client, it sends FORGET messages to server, and then server closesO_PATHfd and then host generates unlink events. By that time its too late, guest has already remove local watches (and triggered removal of remote watches too).This second problem probably can be solved by using file handles, but basic race will still continue to be there.
Quoted 3 lines
If it is local file removal that causes watch to be removed, then don't drop local events and you are good to go. Is it something else?
- If remote events are enabled, then idea will be that user space gets and event when file is actually removed from server, right? Now it is possible that another VM has this file open and file has not been yet removed. So local event only tells you that file has been removed in guest VM (or locally) but does not tell anything about the state of file on server. (It has been unlinked on server but inode continues to be alive internall).
Quoted 9 lines
- If user receives both local and remote delete event, it will be confusing. I guess if we want to see both the events, then there has to be some sort of info in event which classifies whether event is local or remote. And let application act accordingly.
Thanks
Vivek
Hello Amir!
Sorry for taking part in the conversation a bit late. Vivek was on point with the
example he gave but the race is a bit more generic than only the DELETE event.
Let's say that a guest process monitors an inode for OPEN events:
1) The same guest process or another guest process opens the file (related to the
monitored inode), and then closes and immediately deletes the file/inode.
2) The FUSE server (virtiofsd) will mimic the operations of the guest process:
a) Will open the file on the host side and thus a remote OPEN event is
going to
be generated on the host and sent to the guest.
b) Will unlink the remote inode and if no other host process uses the
inode then the
inode will be freed and a DELETE event is going to be generated on the
host and sent
to the guest (However, due to how virtiofsd works and Vivek mentioned,
this step won't
happen immediately)
The problem here is that the OPEN event might still be travelling towards the guest in the
virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.
Signature · 2 lines
Ioannis Angelakopoulos Software Engineer Intern at Red Hat
Amir Goldstein
reviewerQuoted 92 lines · Ioannis Angelakopoulos
Quoted 72 lines · Vivek Goyal
Quoted 20 lines · Amir Goldstein
Quoted 19 lines · Vivek Goyal
On Tue, Oct 26, 2021 at 06:23:50PM +0300, Amir Goldstein wrote:
[..]
Quoted 8 lines
Quoted 8 lines
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest does not receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the watch). In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the guest kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore).
So this is one of the issues which has been haunting us in virtiofs. If a file is removed, for local events, event is generated first and then watch is removed. But in case of remote filesystems, it is racy. It is possible that by the time event arrives, watch is already gone and application never sees the delete event.
Quoted 5 lines
Quoted 1 line
Not sure how to address this issue.
Can you take me through the scenario step by step. I am not sure I understand the exact sequence of the race.
Ioannis, please correct me If I get something wrong. You know exact details much more than me.
A. Say a guest process unlinks a file.
B. Fuse sends an unlink request to server (virtiofsd)
C. File is unlinked on host. Assume there are no other users so inode
will be freed as well. And event will be generated on host and watch removed.
D. Now Fuse server will send a unlink request reply. unlink notification
might still be in kernel buffers or still be in virtiofsd or could be in virtiofs virtqueue.
E. Fuse client will receive unlink reply and remove local watch.Fuse reply and notification event are now traveling in parallel on different virtqueues and there is no connection between these two. And it could very well happen that fuse reply comes first, gets processed first and local watch is removed. And notification is processed right after but by then local watch is gone and filesystem will be forced to drop event.
As of now situation is more complicated in virtiofsd. We don't keep file handle open for file and keep an
O_PATHfd open for each file. That means in step D above, inode on host is not freed yet and unlink event is not generated yet. When unlink reply reaches fuse client, it sends FORGET messages to server, and then server closesO_PATHfd and then host generates unlink events. By that time its too late, guest has already remove local watches (and triggered removal of remote watches too).This second problem probably can be solved by using file handles, but basic race will still continue to be there.
Quoted 3 lines
If it is local file removal that causes watch to be removed, then don't drop local events and you are good to go. Is it something else?
- If remote events are enabled, then idea will be that user space gets and event when file is actually removed from server, right? Now it is possible that another VM has this file open and file has not been yet removed. So local event only tells you that file has been removed in guest VM (or locally) but does not tell anything about the state of file on server. (It has been unlinked on server but inode continues to be alive internall).
Quoted 8 lines
- If user receives both local and remote delete event, it will be confusing. I guess if we want to see both the events, then there has to be some sort of info in event which classifies whether event is local or remote. And let application act accordingly.
Thanks
VivekHello Amir!
Sorry for taking part in the conversation a bit late. Vivek was on point with the example he gave but the race is a bit more generic than only the DELETE event.
Let's say that a guest process monitors an inode for OPEN events:
Quoted 10 lines
1) The same guest process or another guest process opens the file (related to the monitored inode), and then closes and immediately deletes the file/inode.
2) The FUSE server (virtiofsd) will mimic the operations of the guest process:
a) Will open the file on the host side and thus a remote OPEN event is going to be generated on the host and sent to the guest.
b) Will unlink the remote inode and if no other host process uses the inode then the inode will be freed and a DELETE event is going to be generated on the host and sent to the guest (However, due to how virtiofsd works and Vivek mentioned, this step won't happen immediately)
You are confusing DELETE with DELETE_SELF.
DELETE corresponds to unlink(), so you get a DELETE event even if inode is a hardlink
with nlink > 0 after unlink().
The DELETE event is reported (along with filename) against the parent directory inode, so the test case above won't drop the event.
Quoted 5 lines
The problem here is that the OPEN event might still be travelling towards the guest in the virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.
I have a feeling that we are mixing issues related to shared server and remote fsnotify.
Does virtiofsd support multiple guests already? There are many other issues related
to cache coherency that should be dealt with in this case, some of them overlap the
problem that you describe, so solving the narrow problem of dropped remote events
seems like the wrong way to approach the problem.
I think that in a shared server situation, the simple LOOKUP/FORGET protocol will not suffice. I will not even try to solve the generic problem, but will just
mentioned that SMB/NFS protocols use delegations/oplocks in the protocol to advertise object usage by other clients to all clients.
I think this issue is far outside the scope of your project and you should just leave the dropped events as a known limitation at this point. inotify has the event IN_IGNORED that application can use as a hint that some events could have been dropped.
Thanks,
Amir.
Jan Kara
maintainerQuoted 11 lines · Amir Goldstein
Quoted 6 lines · Ioannis Angelakopoulos
On Tue, Oct 26, 2021 at 2:27 PM Vivek Goyal <[email protected]> wrote:
The problem here is that the OPEN event might still be travelling towards the guest in the virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.I have a feeling that we are mixing issues related to shared server and remote fsnotify.
I don't think Ioannis was speaking about shared server case here. I think he says that in a simple FUSE remote notification setup we can loose OPEN events (or basically any other) if the inode for which the event happens gets deleted sufficiently early after the event being generated. That seems indeed somewhat unexpected and could be confusing if it happens e.g. for some directory operations.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Vivek Goyal
maintainerQuoted 13 lines · Jan Kara
Quoted 11 lines · Amir Goldstein
Quoted 6 lines · Ioannis Angelakopoulos
On Tue, Oct 26, 2021 at 2:27 PM Vivek Goyal <[email protected]> wrote:
The problem here is that the OPEN event might still be travelling towards the guest in the virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.I have a feeling that we are mixing issues related to shared server and remote fsnotify.
Quoted 6 lines
I don't think Ioannis was speaking about shared server case here. I think he says that in a simple FUSE remote notification setup we can loose OPEN events (or basically any other) if the inode for which the event happens gets deleted sufficiently early after the event being generated. That seems indeed somewhat unexpected and could be confusing if it happens e.g. for some directory operations.
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
With local filesystems we have a control that we can first queue up the event in buffer before we remove local watches. With events travelling from a remote server, there is no such control/synchronization. It can very well happen that events got delayed in the communication path somewhere and local watches went away and now there is no way to deliver those events to the application.
Thanks
Vivek
Vivek Goyal
maintainerQuoted 21 lines · Vivek Goyal
Quoted 13 lines · Jan Kara
Quoted 11 lines · Amir Goldstein
Quoted 6 lines · Ioannis Angelakopoulos
On Tue, Oct 26, 2021 at 2:27 PM Vivek Goyal <[email protected]> wrote:
The problem here is that the OPEN event might still be travelling towards the guest in the virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.I have a feeling that we are mixing issues related to shared server and remote fsnotify.
Quoted 6 lines
I don't think Ioannis was speaking about shared server case here. I think he says that in a simple FUSE remote notification setup we can loose OPEN events (or basically any other) if the inode for which the event happens gets deleted sufficiently early after the event being generated. That seems indeed somewhat unexpected and could be confusing if it happens e.g. for some directory operations.
Quoted 5 lines
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
Thinking more about it, one will need remote fsnotify support only if this is a case of shared direcotry. If there are no clients doing parallel operations in shared dir (like dropping some new files), then local inotify should be good enough. And I think Ioannis mentioned that local inotify already work with fuse.
For example, kata container developers wanted to use inotify on virtiofs, because a process on host (kubernetes?) will update some sort of config file in shared directory. They wanted to monitor that config in guest, get an inotify event and then act on updated config file. That's the case of shared dir.
Given we do not support inotify yet, I think they went ahead with some sort of polling mechanism to take care of there use case.
Thanks
Vivek
Jan Kara
maintainerQuoted 27 lines · Vivek Goyal
Quoted 13 lines · Jan Kara
Quoted 11 lines · Amir Goldstein
Quoted 6 lines · Ioannis Angelakopoulos
On Tue, Oct 26, 2021 at 2:27 PM Vivek Goyal <[email protected]> wrote:
The problem here is that the OPEN event might still be travelling towards the guest in the virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.I have a feeling that we are mixing issues related to shared server and remote fsnotify.
Quoted 6 lines
I don't think Ioannis was speaking about shared server case here. I think he says that in a simple FUSE remote notification setup we can loose OPEN events (or basically any other) if the inode for which the event happens gets deleted sufficiently early after the event being generated. That seems indeed somewhat unexpected and could be confusing if it happens e.g. for some directory operations.
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
Quoted 6 lines
With local filesystems we have a control that we can first queue up the event in buffer before we remove local watches. With events travelling from a remote server, there is no such control/synchronization. It can very well happen that events got delayed in the communication path somewhere and local watches went away and now there is no way to deliver those events to the application.
So after thinking for some time about this I have the following question about the architecture of this solution: Why do you actually have local fsnotify watches at all? They seem to cause quite some trouble... I mean cannot we have fsnotify marks only on FUSE server and generate all events there? When e.g. file is created from the client, client tells the server about creation, the server performs the creation which generates the fsnotify event, that is received by the server and forwared back to the client which just queues it into notification group's queue for userspace to read it.
Now with this architecture there's no problem with duplicate events for local & server notification marks, similarly there's no problem with lost events after inode deletion because events received by the client are directly queued into notification queue without any checking whether inode is still alive etc. Would this work or am I missing something?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Amir Goldstein
reviewerQuoted 46 lines · Jan Kara
Quoted 27 lines · Vivek Goyal
Quoted 13 lines · Jan Kara
Quoted 11 lines · Amir Goldstein
Quoted 6 lines · Ioannis Angelakopoulos
On Tue, Oct 26, 2021 at 2:27 PM Vivek Goyal <[email protected]> wrote:
The problem here is that the OPEN event might still be travelling towards the guest in the virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.I have a feeling that we are mixing issues related to shared server and remote fsnotify.
Quoted 6 lines
I don't think Ioannis was speaking about shared server case here. I think he says that in a simple FUSE remote notification setup we can loose OPEN events (or basically any other) if the inode for which the event happens gets deleted sufficiently early after the event being generated. That seems indeed somewhat unexpected and could be confusing if it happens e.g. for some directory operations.
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
Quoted 6 lines
With local filesystems we have a control that we can first queue up the event in buffer before we remove local watches. With events travelling from a remote server, there is no such control/synchronization. It can very well happen that events got delayed in the communication path somewhere and local watches went away and now there is no way to deliver those events to the application.
So after thinking for some time about this I have the following question about the architecture of this solution: Why do you actually have local fsnotify watches at all? They seem to cause quite some trouble... I mean cannot we have fsnotify marks only on FUSE server and generate all events there? When e.g. file is created from the client, client tells the server about creation, the server performs the creation which generates the fsnotify event, that is received by the server and forwared back to the client which just queues it into notification group's queue for userspace to read it.
Quoted 6 lines
Now with this architecture there's no problem with duplicate events for local & server notification marks, similarly there's no problem with lost events after inode deletion because events received by the client are directly queued into notification queue without any checking whether inode is still alive etc. Would this work or am I missing something?
What about group #1 that wants mask A and group #2 that wants mask B events?
Do you propose to maintain separate event queues over the protocol? Attach a "recipient list" to each event?
I just don't see how this can scale other than:
- Local marks and connectors manage the subscriptions on local machine
- Protocol updates the server with the combined masks for watched objects
I think that the "post-mortem events" issue could be solved by keeping an S_DEAD fuse inode object in limbo just for the mark.
When a remote server sends FS_IN_IGNORED or FS_DELETE_SELF for an inode, the fuse client inode can be finally evicted.
I haven't tried to see how hard that would be to implement.
Thanks,
Amir.
Vivek Goyal
maintainerQuoted 37 lines · Amir Goldstein
Quoted 36 lines · Jan Kara
Quoted 33 lines · Vivek Goyal
Quoted 13 lines · Jan Kara
Quoted 11 lines · Amir Goldstein
Quoted 6 lines · Ioannis Angelakopoulos
On Tue, Oct 26, 2021 at 2:27 PM Vivek Goyal <[email protected]> wrote:
The problem here is that the OPEN event might still be travelling towards the guest in the virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.I have a feeling that we are mixing issues related to shared server and remote fsnotify.
Quoted 6 lines
I don't think Ioannis was speaking about shared server case here. I think he says that in a simple FUSE remote notification setup we can loose OPEN events (or basically any other) if the inode for which the event happens gets deleted sufficiently early after the event being generated. That seems indeed somewhat unexpected and could be confusing if it happens e.g. for some directory operations.
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
With local filesystems we have a control that we can first queue up the event in buffer before we remove local watches. With events travelling from a remote server, there is no such control/synchronization. It can very well happen that events got delayed in the communication path somewhere and local watches went away and now there is no way to deliver those events to the application.
Quoted 5 lines
Quoted 5 lines
So after thinking for some time about this I have the following question about the architecture of this solution: Why do you actually have local fsnotify watches at all? They seem to cause quite some trouble... I mean cannot we have fsnotify marks only on FUSE server and generate all events there?
I think currently we are already implementing this part of the proposal. We are sending "group" pointer to server while updating a watch. And server is managing watches per inode per group. IOW, if client has group1 wanting mask A and group2 wanting mask B, then server is going to add two watches with two masks on same inotify fd instance.
Admittedly we did this because we did not know that an aggregate mask exists. And using an aggregate mask in guest kernel and then server putting a single watch for that inode based on aggregate mask simplifies server implementation.
One downside of this approach is more complexity on server. Also more number of events will be travelling from host to guest. So if two groups are watching same events on same inode, then I think two copies of events will travel to guest. One for the group1 and one for group2 (as we are having separate watches on host). If we use aggregate watch on host, then only one event can travel between host and guest and I am assuming same event can be replicated among multiple groups, depending on their interest.
Quoted 5 lines
When e.g. file is created from the client, client tells the server
Quoted 4 lines
about creation, the server performs the creation which generates the fsnotify event, that is received by the server and forwared back to the client which just queues it into notification group's queue for userspace to read it.
This is the part we have not implemented. When we generate the event, we just generate the event for the inode. There is no notion of that this event has been generated for a specific group with-in this inode. As of now that's left to the local fsnotify code to manage and figure out.
So the idea is, that when event arrives from remote, queue it up directly into the group (without having to worry about inode). Hmm.., how do we do that. That means we need to return that group identifier in notification event atleast so that client can find out the group (without having to worry about inode?).
So group will basically become part of the remote protocol if we were to go this way. And implementation becomes more complicated.
Quoted 3 lines
Quoted 3 lines
Now with this architecture there's no problem with duplicate events for local & server notification marks,
I guess supressing local events is really trivial. Either we have that inode flag Amir suggested or have an inode operation to let file system decide.
Quoted 4 lines
similarly there's no problem with lost
Quoted 3 lines
events after inode deletion because events received by the client are directly queued into notification queue without any checking whether inode is still alive etc. Would this work or am I missing something?
So when will the watches on remote go away. When a file is unlinked and inode is going away we call fsnotify_inoderemove(). This generates FS_DELETE_SELF and then seems to remove all local marks on the inode.
Now if we don't have local marks and guest inode is going away, and client sends FUSE_FORGET message, I am assuming that will be the time to cleanup all the remote watches and groups etc. And if file is open by some other guest, then DELETE_SELF event will not have been generated by then and we will clean remote watches.
Even if other guest did not have file open, cleanup of remote watches and DELETE_SELF will be parallel operation and can be racy. So if thread reading inotify descriptor gets little late in reading DELETE_SELF, it is possible another thread in virtiofsd cleaned up all remote watches and associated groups. And now there is no way to send event back to guest and we lost event?
My understanding of this notification magic is very primitive. So it is very much possible I am misunderstanding how remote watches and groups will be managed and reported back. But my current assumption is that their life time will have to be tied to remote inode we are managing. Otherwise when will remote server clean its own internal state (watch descriptors), when inode goes away.
Quoted 8 lines
Quoted 1 line
What about group #1 that wants mask A and group #2 that wants mask B events?
Do you propose to maintain separate event queues over the protocol? Attach a "recipient list" to each event?
Quoted 8 lines
I just don't see how this can scale other than:
- Local marks and connectors manage the subscriptions on local machine
- Protocol updates the server with the combined masks for watched objectsI think that the "post-mortem events" issue could be solved by keeping an
S_DEADfuse inode object in limbo just for the mark.
When a remote server sendsFS_IN_IGNOREDorFS_DELETE_SELFfor an inode, the fuse client inode can be finally evicted.
There is no guarantee that FS_IN_IGNORED or FS_DELETE_SELF will come or when will it come. If another guest has reference on inode it might not come for a long time. And this will kind of become a mechanism for one guest to keep other's inode cache full of such objects.
If event queue becomes too full, we might drop these events. But I guess in that case we will have to generate IN_Q_OVERFLOW and that can somehow be used to cleanup such S_DEAD inodes?
nodeid is managed by server. So I am assuming that FORGET messages will not be sent to server for this inode till we have seen FS_IN_IGNORED and FS_DELETE_SELF events?
Thanks
Vivek
Quoted 5 lines
I haven't tried to see how hard that would be to implement.
Thanks,
Amir.
Amir Goldstein
reviewerQuoted 17 lines
Quoted 8 lines
Quoted 1 line
What about group #1 that wants mask A and group #2 that wants mask B events?
Do you propose to maintain separate event queues over the protocol? Attach a "recipient list" to each event?
Quoted 8 lines
I just don't see how this can scale other than:
- Local marks and connectors manage the subscriptions on local machine
- Protocol updates the server with the combined masks for watched objectsI think that the "post-mortem events" issue could be solved by keeping an
S_DEADfuse inode object in limbo just for the mark.
When a remote server sendsFS_IN_IGNOREDorFS_DELETE_SELFfor an inode, the fuse client inode can be finally evicted.
Quoted 8 lines
There is no guarantee that
FS_IN_IGNOREDorFS_DELETE_SELFwill come or when will it come. If another guest has reference on inode it might not come for a long time. And this will kind of become a mechanism for one guest to keep other's inode cache full of such objects.If event queue becomes too full, we might drop these events. But I guess in that case we will have to generate
IN_Q_OVERFLOWand that can somehow be used to cleanup suchS_DEADinodes?
That depends on the server implementation.
If the server is watching host fs using fanotify filesystem mark, then an overflow
event does NOT mean that other new events on inode may be missed only that old events could have been missed.
Server should know about all the watched inodes, so it can check on overflow if any of the watched inodes were deleted and notify the client using a reliable channel.
Given the current server implementation with inotify, IN_Q_OVERFLOW means server may have lost an IN_IGNORED event and may not get any more events on inode, so server should check all the watched inodes after overflow, notify the client of all deleted inodes and try to re-create the watches
for all inodes with known path or use magic /prod/pid/fd path if that works (??).
Quoted 5 lines
nodeid is managed by server. So I am assuming that FORGET messages will not be sent to server for this inode till we have seen
FS_IN_IGNOREDandFS_DELETE_SELFevents?
Or until the application that requested the watch calls inotify_rm_watch() or closes
the inotify fd.
IOW, when fs implements remote fsnotify, the local watch keeps the local deleted inode object in limbo until the local watch is removed.
When the remote fsnotify server informs that the remote watch (or remote inode) is gone, the local watch is removed as well and then the inotify application also gets
an FS_IN_IGNORED event.
Lifetime of local inode is complicated and lifetime of this "shared inode" is much more complicated, so I am not pretending to claim that I have this all figured out or that it could be reliably done at all.
Thanks,
Amir.
Vivek Goyal
maintainerQuoted 26 lines · Amir Goldstein
Quoted 17 lines
Quoted 8 lines
Quoted 1 line
What about group #1 that wants mask A and group #2 that wants mask B events?
Do you propose to maintain separate event queues over the protocol? Attach a "recipient list" to each event?
Quoted 8 lines
I just don't see how this can scale other than:
- Local marks and connectors manage the subscriptions on local machine
- Protocol updates the server with the combined masks for watched objectsI think that the "post-mortem events" issue could be solved by keeping an
S_DEADfuse inode object in limbo just for the mark.
When a remote server sendsFS_IN_IGNOREDorFS_DELETE_SELFfor an inode, the fuse client inode can be finally evicted.Quoted 8 lines
There is no guarantee that
FS_IN_IGNOREDorFS_DELETE_SELFwill come or when will it come. If another guest has reference on inode it might not come for a long time. And this will kind of become a mechanism for one guest to keep other's inode cache full of such objects.If event queue becomes too full, we might drop these events. But I guess in that case we will have to generate
IN_Q_OVERFLOWand that can somehow be used to cleanup suchS_DEADinodes?
Quoted 8 lines
That depends on the server implementation.
If the server is watching host fs using fanotify filesystem mark, then an overflow
event does NOT mean that other new events on inode may be missed only that old events could have been missed.
Server should know about all the watched inodes, so it can check on overflow if any of the watched inodes were deleted and notify the client using a reliable channel.
Ok. We have only one channel for notifications. I guess we can program the channel in such a way so that it does not drop overflow events but can drop other kind of events if things get crazy. If too many overflow events and we allocate too much of memory, I guess at some point of time, oom killer will kick in a kill server.
Quoted 8 lines
Given the current server implementation with inotify,
IN_Q_OVERFLOWmeans server may have lost anIN_IGNOREDevent and may not get any more events on inode, so server should check all the watched inodes after overflow, notify the client of all deleted inodes and try to re-create the watches
for all inodes with known path or use magic /prod/pid/fd path if that works (??).
Re-doing the watches sounds very painful. That means we will need to keep track of aggregated mask in server side inode as well. As of now we just pass mask to kernel using inotify_add_watch() and forget about it.
/proc/pid/fd should work because I think that's how ioannis is putting current watches on inodes. We don't send path info to server.
Quoted 11 lines
Quoted 6 lines
nodeid is managed by server. So I am assuming that FORGET messages will not be sent to server for this inode till we have seen
FS_IN_IGNOREDandFS_DELETE_SELFevents?Or until the application that requested the watch calls
inotify_rm_watch()or closes
the inotify fd.
Quoted 6 lines
IOW, when fs implements remote fsnotify, the local watch keeps the local deleted inode object in limbo until the local watch is removed.
When the remote fsnotify server informs that the remote watch (or remote inode) is gone, the local watch is removed as well and then the inotify application also gets
anFS_IN_IGNOREDevent.
Hmm.., I guess remote server will simply send IN_DELETE event when it gets it and forward to client. And client will have to then cleanup this S_DEAD inode which is in limbo waiting for IN_DELETE_SELF event. And that should trigger cleanup of marks/local-watches on the inode, IIUC.
Quoted 4 lines
Lifetime of local inode is complicated and lifetime of this "shared inode" is much more complicated, so I am not pretending to claim that I have this all figured out or that it could be reliably done at all.
Yes this handling of IN_DELETE_SELF is turning out to be the most complicated piece of this proposal. I wish initial implementation could just be designed that it does not send IN_DELETE_SELF and IN_INGORED is generated locally. And later enhance it to support reliable delivery of IN_DELETE_SELF.
Thanks
Vivek
Amir Goldstein
reviewerQuoted 13 lines
Quoted 4 lines
Quoted 3 lines
If event queue becomes too full, we might drop these events. But I guess in that case we will have to generate
IN_Q_OVERFLOWand that can somehow be used to cleanup suchS_DEADinodes?Quoted 8 lines
That depends on the server implementation.
If the server is watching host fs using fanotify filesystem mark, then an overflow
event does NOT mean that other new events on inode may be missed only that old events could have been missed.
Server should know about all the watched inodes, so it can check on overflow if any of the watched inodes were deleted and notify the client using a reliable channel.
Quoted 6 lines
Ok. We have only one channel for notifications. I guess we can program the channel in such a way so that it does not drop overflow events but can drop other kind of events if things get crazy. If too many overflow events and we allocate too much of memory, I guess at some point of time, oom killer will kick in a kill server.
The kernel implementation of fsnotify events queue pre-allocates a single overflow event and never queues more than a single overflow event. IN_Q_OVERFLOW must be delivered reliably, but delivering one overflow event is enough (until it is consumed).
Quoted 10 lines
Quoted 8 lines
Given the current server implementation with inotify,
IN_Q_OVERFLOWmeans server may have lost anIN_IGNOREDevent and may not get any more events on inode, so server should check all the watched inodes after overflow, notify the client of all deleted inodes and try to re-create the watches
for all inodes with known path or use magic /prod/pid/fd path if that works (??).Re-doing the watches sounds very painful.
Event overflow is a painful incident and systems usually pay a large penalty when it happens (e.g. full recrawl of watched tree).
If virtiofsd is going to use inotify, it is no different than any other inotify application that needs to bear the consequence of event overflow.
Quoted 5 lines
That means we will need to
keep track of aggregated mask in server side inode as well. As of now we just pass mask to kernel usinginotify_add_watch()and forget about it.
It costs nothing to keep the aggregated mask in server side inode and it makes sense to do that anyway.
This allows an implementation to notify about changes that the server itself handles even if there is no backing filesystem behind it or host OS has no fs notification support.
Quoted 21 lines
/proc/pid/fdshould work because I think that's how ioannis is putting current watches on inodes. We don't send path info to server.Quoted 11 lines
Quoted 6 lines
nodeid is managed by server. So I am assuming that FORGET messages will not be sent to server for this inode till we have seen
FS_IN_IGNOREDandFS_DELETE_SELFevents?Or until the application that requested the watch calls
inotify_rm_watch()or closes
the inotify fd.Quoted 6 lines
IOW, when fs implements remote fsnotify, the local watch keeps the local deleted inode object in limbo until the local watch is removed.
When the remote fsnotify server informs that the remote watch (or remote inode) is gone, the local watch is removed as well and then the inotify application also gets
anFS_IN_IGNOREDevent.
Quoted 5 lines
Hmm.., I guess remote server will simply send
IN_DELETEevent when it gets it and forward to client. And client will have to then cleanup thisS_DEADinode which is in limbo waiting forIN_DELETE_SELFevent. And that should trigger cleanup of marks/local-watches on the inode, IIUC.
In very broad lines, but the server notification must be delivered reliably.
Quoted 11 lines
Quoted 4 lines
Lifetime of local inode is complicated and lifetime of this "shared inode" is much more complicated, so I am not pretending to claim that I have this all figured out or that it could be reliably done at all.
Yes this handling of
IN_DELETE_SELFis turning out to be the most complicated piece of this proposal. I wish initial implementation could just be designed that it does not sendIN_DELETE_SELFandIN_INGOREDis generated locally. And later enhance it to support reliable delivery ofIN_DELETE_SELF.
Not allowing DELETE_SELF in the mask sounds reasonable, but as Ioannis explained, other events can be missed on local file delete. If you want to preserve inotify semantics, you could queue an overflow event if a fuse inode that gets evicted still has inotify marks. That's a bit harsh though.
Alternatively, you could document in inotify man page that IN_INGORED could mean that some events were dropped and hope for the best...
Thanks,
Amir.
Jan Kara
maintainerQuoted 54 lines · Amir Goldstein
Quoted 46 lines · Jan Kara
Quoted 27 lines · Vivek Goyal
Quoted 13 lines · Jan Kara
Quoted 11 lines · Amir Goldstein
Quoted 6 lines · Ioannis Angelakopoulos
On Tue, Oct 26, 2021 at 2:27 PM Vivek Goyal <[email protected]> wrote:
The problem here is that the OPEN event might still be travelling towards the guest in the virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.I have a feeling that we are mixing issues related to shared server and remote fsnotify.
Quoted 6 lines
I don't think Ioannis was speaking about shared server case here. I think he says that in a simple FUSE remote notification setup we can loose OPEN events (or basically any other) if the inode for which the event happens gets deleted sufficiently early after the event being generated. That seems indeed somewhat unexpected and could be confusing if it happens e.g. for some directory operations.
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
Quoted 6 lines
With local filesystems we have a control that we can first queue up the event in buffer before we remove local watches. With events travelling from a remote server, there is no such control/synchronization. It can very well happen that events got delayed in the communication path somewhere and local watches went away and now there is no way to deliver those events to the application.
So after thinking for some time about this I have the following question about the architecture of this solution: Why do you actually have local fsnotify watches at all? They seem to cause quite some trouble... I mean cannot we have fsnotify marks only on FUSE server and generate all events there? When e.g. file is created from the client, client tells the server about creation, the server performs the creation which generates the fsnotify event, that is received by the server and forwared back to the client which just queues it into notification group's queue for userspace to read it.
Quoted 6 lines
Now with this architecture there's no problem with duplicate events for local & server notification marks, similarly there's no problem with lost events after inode deletion because events received by the client are directly queued into notification queue without any checking whether inode is still alive etc. Would this work or am I missing something?
Quoted 5 lines
What about group #1 that wants mask A and group #2 that wants mask B events?
Do you propose to maintain separate event queues over the protocol? Attach a "recipient list" to each event?
Yes, that was my idea. Essentially when we see group A creates mark on FUSE for path P, we notify server, it will create notification group A on the server (if not already existing - there we need some notification group identifier unique among all clients), and place mark for it on path P. Then the full stream of notification events generated for group A on the server will just be forwarded to the client and inserted into the A's notification queue. IMO this is very simple solution to implement - you just need to forward mark addition / removal events from the client to the server and you forward event stream from the server to the client. Everything else is handled by the fsnotify infrastructure on the server.
Quoted 3 lines
I just don't see how this can scale other than:
- Local marks and connectors manage the subscriptions on local machine
- Protocol updates the server with the combined masks for watched objects
I agree that depending on the usecase and particular FUSE filesystem performance of this solution may be a concern. OTOH the only additional cost of this solution I can see (compared to all those processes just watching files locally) is the passing of the events from the server to the client. For local FUSE filesystems such as virtiofs this should be rather cheap since you have to do very little processing for each generated event. For filesystems such as sshfs, I can imagine this would be a bigger deal.
Also one problem I can see with my proposal is that it will have problems with stuff such as leases - i.e., if the client does not notify the server of the changes quickly but rather batches local operations and tells the server about them only on special occasions. I don't know enough about FUSE filesystems to tell whether this is a frequent problem or not.
Quoted 5 lines
I think that the "post-mortem events" issue could be solved by keeping an
S_DEADfuse inode object in limbo just for the mark.
When a remote server sendsFS_IN_IGNOREDorFS_DELETE_SELFfor an inode, the fuse client inode can be finally evicted.
I haven't tried to see how hard that would be to implement.
Sure, there can be other solutions to this particular problem. I just want to discuss the other architecture to see why we cannot to it in a simple way :).
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Amir Goldstein
reviewerQuoted 71 lines
Quoted 30 lines
Quoted 23 lines
Quoted 6 lines
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
Quoted 6 lines
With local filesystems we have a control that we can first queue up the event in buffer before we remove local watches. With events travelling from a remote server, there is no such control/synchronization. It can very well happen that events got delayed in the communication path somewhere and local watches went away and now there is no way to deliver those events to the application.
So after thinking for some time about this I have the following question about the architecture of this solution: Why do you actually have local fsnotify watches at all? They seem to cause quite some trouble... I mean cannot we have fsnotify marks only on FUSE server and generate all events there? When e.g. file is created from the client, client tells the server about creation, the server performs the creation which generates the fsnotify event, that is received by the server and forwared back to the client which just queues it into notification group's queue for userspace to read it.
Quoted 6 lines
Now with this architecture there's no problem with duplicate events for local & server notification marks, similarly there's no problem with lost events after inode deletion because events received by the client are directly queued into notification queue without any checking whether inode is still alive etc. Would this work or am I missing something?
Quoted 5 lines
What about group #1 that wants mask A and group #2 that wants mask B events?
Do you propose to maintain separate event queues over the protocol? Attach a "recipient list" to each event?
Yes, that was my idea. Essentially when we see group A creates mark on FUSE for path P, we notify server, it will create notification group A on the server (if not already existing - there we need some notification group identifier unique among all clients), and place mark for it on path P. Then the full stream of notification events generated for group A on the server will just be forwarded to the client and inserted into the A's notification queue. IMO this is very simple solution to implement - you just need to forward mark addition / removal events from the client to the server and you forward event stream from the server to the client. Everything else is handled by the fsnotify infrastructure on the server.
Quoted 3 lines
I just don't see how this can scale other than:
- Local marks and connectors manage the subscriptions on local machine
- Protocol updates the server with the combined masks for watched objectsI agree that depending on the usecase and particular FUSE filesystem performance of this solution may be a concern. OTOH the only additional cost of this solution I can see (compared to all those processes just watching files locally) is the passing of the events from the server to the client. For local FUSE filesystems such as virtiofs this should be rather cheap since you have to do very little processing for each generated event. For filesystems such as sshfs, I can imagine this would be a bigger deal.
Also one problem I can see with my proposal is that it will have problems with stuff such as leases - i.e., if the client does not notify the server of the changes quickly but rather batches local operations and tells the server about them only on special occasions. I don't know enough about FUSE filesystems to tell whether this is a frequent problem or not.
Quoted 5 lines
I think that the "post-mortem events" issue could be solved by keeping an
S_DEADfuse inode object in limbo just for the mark.
When a remote server sendsFS_IN_IGNOREDorFS_DELETE_SELFfor an inode, the fuse client inode can be finally evicted.
I haven't tried to see how hard that would be to implement.
Quoted 4 lines
Sure, there can be other solutions to this particular problem. I just want to discuss the other architecture to see why we cannot to it in a simple way :).
Fair enough.
Beyond the scalability aspects, I think that a design that exposes the group to the remote server and allows to "inject" events to the group queue will prevent
users from useful features going forward.
For example, fanotify ignored_mask could be added to a group, even on a mount mark, even if the remote server only supports inode marks and it would just work.
Another point of view for the post-mortem events:
As Miklos once noted and as you wrote above, for cache coherency and leases, an async notification queue is not adequate and synchronous notifications are too costly, so there needs to be some shared memory solution involving guest cache invalidation by host.
Suppose said cache invalidation solution would be able to set a variety of "dirty" flags, not just one type of dirty or to call in another way - an "event mask".
If that is available, then when a fuse inode gets evicted, the events from the "event mask" can be queued before destroying the inode and mark - post mortem event issue averted...
Thanks,
Amir.
Vivek Goyal
maintainerQuoted 87 lines · Amir Goldstein
Quoted 71 lines
Quoted 30 lines
Quoted 23 lines
Quoted 6 lines
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
Quoted 6 lines
With local filesystems we have a control that we can first queue up the event in buffer before we remove local watches. With events travelling from a remote server, there is no such control/synchronization. It can very well happen that events got delayed in the communication path somewhere and local watches went away and now there is no way to deliver those events to the application.
So after thinking for some time about this I have the following question about the architecture of this solution: Why do you actually have local fsnotify watches at all? They seem to cause quite some trouble... I mean cannot we have fsnotify marks only on FUSE server and generate all events there? When e.g. file is created from the client, client tells the server about creation, the server performs the creation which generates the fsnotify event, that is received by the server and forwared back to the client which just queues it into notification group's queue for userspace to read it.
Quoted 6 lines
Now with this architecture there's no problem with duplicate events for local & server notification marks, similarly there's no problem with lost events after inode deletion because events received by the client are directly queued into notification queue without any checking whether inode is still alive etc. Would this work or am I missing something?
Quoted 5 lines
What about group #1 that wants mask A and group #2 that wants mask B events?
Do you propose to maintain separate event queues over the protocol? Attach a "recipient list" to each event?
Yes, that was my idea. Essentially when we see group A creates mark on FUSE for path P, we notify server, it will create notification group A on the server (if not already existing - there we need some notification group identifier unique among all clients), and place mark for it on path P. Then the full stream of notification events generated for group A on the server will just be forwarded to the client and inserted into the A's notification queue. IMO this is very simple solution to implement - you just need to forward mark addition / removal events from the client to the server and you forward event stream from the server to the client. Everything else is handled by the fsnotify infrastructure on the server.
Quoted 3 lines
I just don't see how this can scale other than:
- Local marks and connectors manage the subscriptions on local machine
- Protocol updates the server with the combined masks for watched objectsI agree that depending on the usecase and particular FUSE filesystem performance of this solution may be a concern. OTOH the only additional cost of this solution I can see (compared to all those processes just watching files locally) is the passing of the events from the server to the client. For local FUSE filesystems such as virtiofs this should be rather cheap since you have to do very little processing for each generated event. For filesystems such as sshfs, I can imagine this would be a bigger deal.
Also one problem I can see with my proposal is that it will have problems with stuff such as leases - i.e., if the client does not notify the server of the changes quickly but rather batches local operations and tells the server about them only on special occasions. I don't know enough about FUSE filesystems to tell whether this is a frequent problem or not.
Quoted 5 lines
I think that the "post-mortem events" issue could be solved by keeping an
S_DEADfuse inode object in limbo just for the mark.
When a remote server sendsFS_IN_IGNOREDorFS_DELETE_SELFfor an inode, the fuse client inode can be finally evicted.
I haven't tried to see how hard that would be to implement.Quoted 4 lines
Sure, there can be other solutions to this particular problem. I just want to discuss the other architecture to see why we cannot to it in a simple way :).
Fair enough.
Beyond the scalability aspects, I think that a design that exposes the group to the remote server and allows to "inject" events to the group queue will prevent
users from useful features going forward.For example, fanotify
ignored_maskcould be added to a group, even on a mount mark, even if the remote server only supports inode marks and it would just work.
Quoted 5 lines
Another point of view for the post-mortem events:
As Miklos once noted and as you wrote above, for cache coherency and leases, an async notification queue is not adequate and synchronous notifications are too costly, so there needs to be some shared memory solution involving guest cache invalidation by host.
Any shared memory solution works only limited setup. If server is remote on other machine, there is no sharing. I am hoping that this can be generic enough to support other remote filesystems down the line.
Quoted 7 lines
Suppose said cache invalidation solution would be able to set a variety of "dirty" flags, not just one type of dirty or to call in another way - an "event mask".
If that is available, then when a fuse inode gets evicted, the events from the "event mask" can be queued before destroying the inode and mark - post mortem event issue averted...
This is assuming that that server itself got the "IN_DELETE_SELF" event when fuse is destroying its inode. But if inode might be alive due to other client having fd open.
Even if other client does not have fd open, this still sounds racy. By the time we set inode event_mask (using shared memory, instead of sending an event notifiation), fuse might have cleaned up its inode.
There is a good chance I completely misunderstood what you are suggesting here. :-)
Thanks
Vivek
Amir Goldstein
reviewerQuoted 95 lines · Vivek Goyal
Quoted 87 lines · Amir Goldstein
Quoted 71 lines
Quoted 30 lines
Quoted 23 lines
Quoted 6 lines
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
Quoted 6 lines
With local filesystems we have a control that we can first queue up the event in buffer before we remove local watches. With events travelling from a remote server, there is no such control/synchronization. It can very well happen that events got delayed in the communication path somewhere and local watches went away and now there is no way to deliver those events to the application.
So after thinking for some time about this I have the following question about the architecture of this solution: Why do you actually have local fsnotify watches at all? They seem to cause quite some trouble... I mean cannot we have fsnotify marks only on FUSE server and generate all events there? When e.g. file is created from the client, client tells the server about creation, the server performs the creation which generates the fsnotify event, that is received by the server and forwared back to the client which just queues it into notification group's queue for userspace to read it.
Quoted 6 lines
Now with this architecture there's no problem with duplicate events for local & server notification marks, similarly there's no problem with lost events after inode deletion because events received by the client are directly queued into notification queue without any checking whether inode is still alive etc. Would this work or am I missing something?
Quoted 5 lines
What about group #1 that wants mask A and group #2 that wants mask B events?
Do you propose to maintain separate event queues over the protocol? Attach a "recipient list" to each event?
Yes, that was my idea. Essentially when we see group A creates mark on FUSE for path P, we notify server, it will create notification group A on the server (if not already existing - there we need some notification group identifier unique among all clients), and place mark for it on path P. Then the full stream of notification events generated for group A on the server will just be forwarded to the client and inserted into the A's notification queue. IMO this is very simple solution to implement - you just need to forward mark addition / removal events from the client to the server and you forward event stream from the server to the client. Everything else is handled by the fsnotify infrastructure on the server.
Quoted 3 lines
I just don't see how this can scale other than:
- Local marks and connectors manage the subscriptions on local machine
- Protocol updates the server with the combined masks for watched objectsI agree that depending on the usecase and particular FUSE filesystem performance of this solution may be a concern. OTOH the only additional cost of this solution I can see (compared to all those processes just watching files locally) is the passing of the events from the server to the client. For local FUSE filesystems such as virtiofs this should be rather cheap since you have to do very little processing for each generated event. For filesystems such as sshfs, I can imagine this would be a bigger deal.
Also one problem I can see with my proposal is that it will have problems with stuff such as leases - i.e., if the client does not notify the server of the changes quickly but rather batches local operations and tells the server about them only on special occasions. I don't know enough about FUSE filesystems to tell whether this is a frequent problem or not.
Quoted 5 lines
I think that the "post-mortem events" issue could be solved by keeping an
S_DEADfuse inode object in limbo just for the mark.
When a remote server sendsFS_IN_IGNOREDorFS_DELETE_SELFfor an inode, the fuse client inode can be finally evicted.
I haven't tried to see how hard that would be to implement.Quoted 4 lines
Sure, there can be other solutions to this particular problem. I just want to discuss the other architecture to see why we cannot to it in a simple way :).
Fair enough.
Beyond the scalability aspects, I think that a design that exposes the group to the remote server and allows to "inject" events to the group queue will prevent
users from useful features going forward.For example, fanotify
ignored_maskcould be added to a group, even on a mount mark, even if the remote server only supports inode marks and it would just work.Quoted 5 lines
Another point of view for the post-mortem events:
As Miklos once noted and as you wrote above, for cache coherency and leases, an async notification queue is not adequate and synchronous notifications are too costly, so there needs to be some shared memory solution involving guest cache invalidation by host.
Quoted 4 lines
Any shared memory solution works only limited setup. If server is remote on other machine, there is no sharing. I am hoping that this can be generic enough to support other remote filesystems down the line.
I do too :)
Quoted 8 lines
Quoted 7 lines
Suppose said cache invalidation solution would be able to set a variety of "dirty" flags, not just one type of dirty or to call in another way - an "event mask".
If that is available, then when a fuse inode gets evicted, the events from the "event mask" can be queued before destroying the inode and mark - post mortem event issue averted...
Quoted 8 lines
This is assuming that that server itself got the "
IN_DELETE_SELF" event when fuse is destroying its inode. But if inode might be alive due to other client having fd open.Even if other client does not have fd open, this still sounds racy. By the time we set inode
event_mask(using shared memory, instead of sending an event notifiation), fuse might have cleaned up its inode.
There is no escape from some sort of leases design for a reliable and efficient shared remote fs.
Unless the client has an exclusive lease on the inode, it must provide enough grace period before cleaning the inode to wait for an update from the server if the client cares about getting all events on inode.
Quoted 3 lines
There is a good chance I completely misunderstood what you are suggesting here. :-)
There is a good chance that I am talking nonsense :-)
Thanks,
Amir.
Jan Kara
maintainerQuoted 94 lines · Vivek Goyal
Quoted 87 lines · Amir Goldstein
Quoted 71 lines
Quoted 30 lines
Quoted 23 lines
Quoted 6 lines
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
Quoted 6 lines
With local filesystems we have a control that we can first queue up the event in buffer before we remove local watches. With events travelling from a remote server, there is no such control/synchronization. It can very well happen that events got delayed in the communication path somewhere and local watches went away and now there is no way to deliver those events to the application.
So after thinking for some time about this I have the following question about the architecture of this solution: Why do you actually have local fsnotify watches at all? They seem to cause quite some trouble... I mean cannot we have fsnotify marks only on FUSE server and generate all events there? When e.g. file is created from the client, client tells the server about creation, the server performs the creation which generates the fsnotify event, that is received by the server and forwared back to the client which just queues it into notification group's queue for userspace to read it.
Quoted 6 lines
Now with this architecture there's no problem with duplicate events for local & server notification marks, similarly there's no problem with lost events after inode deletion because events received by the client are directly queued into notification queue without any checking whether inode is still alive etc. Would this work or am I missing something?
Quoted 5 lines
What about group #1 that wants mask A and group #2 that wants mask B events?
Do you propose to maintain separate event queues over the protocol? Attach a "recipient list" to each event?
Yes, that was my idea. Essentially when we see group A creates mark on FUSE for path P, we notify server, it will create notification group A on the server (if not already existing - there we need some notification group identifier unique among all clients), and place mark for it on path P. Then the full stream of notification events generated for group A on the server will just be forwarded to the client and inserted into the A's notification queue. IMO this is very simple solution to implement - you just need to forward mark addition / removal events from the client to the server and you forward event stream from the server to the client. Everything else is handled by the fsnotify infrastructure on the server.
Quoted 3 lines
I just don't see how this can scale other than:
- Local marks and connectors manage the subscriptions on local machine
- Protocol updates the server with the combined masks for watched objectsI agree that depending on the usecase and particular FUSE filesystem performance of this solution may be a concern. OTOH the only additional cost of this solution I can see (compared to all those processes just watching files locally) is the passing of the events from the server to the client. For local FUSE filesystems such as virtiofs this should be rather cheap since you have to do very little processing for each generated event. For filesystems such as sshfs, I can imagine this would be a bigger deal.
Also one problem I can see with my proposal is that it will have problems with stuff such as leases - i.e., if the client does not notify the server of the changes quickly but rather batches local operations and tells the server about them only on special occasions. I don't know enough about FUSE filesystems to tell whether this is a frequent problem or not.
Quoted 5 lines
I think that the "post-mortem events" issue could be solved by keeping an
S_DEADfuse inode object in limbo just for the mark.
When a remote server sendsFS_IN_IGNOREDorFS_DELETE_SELFfor an inode, the fuse client inode can be finally evicted.
I haven't tried to see how hard that would be to implement.Quoted 4 lines
Sure, there can be other solutions to this particular problem. I just want to discuss the other architecture to see why we cannot to it in a simple way :).
Fair enough.
Beyond the scalability aspects, I think that a design that exposes the group to the remote server and allows to "inject" events to the group queue will prevent
users from useful features going forward.For example, fanotify
ignored_maskcould be added to a group, even on a mount mark, even if the remote server only supports inode marks and it would just work.Quoted 5 lines
Another point of view for the post-mortem events:
As Miklos once noted and as you wrote above, for cache coherency and leases, an async notification queue is not adequate and synchronous notifications are too costly, so there needs to be some shared memory solution involving guest cache invalidation by host.
Quoted 3 lines
Any shared memory solution works only limited setup. If server is remote on other machine, there is no sharing. I am hoping that this can be generic enough to support other remote filesystems down the line.
OK, so do I understand both you and Amir correctly that you think that always relying on the FUSE server for generating the events and just piping them to the client is not long-term viable design for FUSE? Mostly because caching of modifications on the client is essentially inevitable and hence generating events from the server would be unreliable (delayed too much)?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Vivek Goyal
maintainerQuoted 99 lines · Jan Kara
Quoted 94 lines · Vivek Goyal
Quoted 87 lines · Amir Goldstein
Quoted 71 lines
Quoted 30 lines
Quoted 23 lines
Quoted 6 lines
Hi Jan,
Agreed. That's what Ioannis is trying to say. That some of the remote events can be lost if fuse/guest local inode is unlinked. I think problem exists both for shared and non-shared directory case.
Quoted 6 lines
With local filesystems we have a control that we can first queue up the event in buffer before we remove local watches. With events travelling from a remote server, there is no such control/synchronization. It can very well happen that events got delayed in the communication path somewhere and local watches went away and now there is no way to deliver those events to the application.
So after thinking for some time about this I have the following question about the architecture of this solution: Why do you actually have local fsnotify watches at all? They seem to cause quite some trouble... I mean cannot we have fsnotify marks only on FUSE server and generate all events there? When e.g. file is created from the client, client tells the server about creation, the server performs the creation which generates the fsnotify event, that is received by the server and forwared back to the client which just queues it into notification group's queue for userspace to read it.
Quoted 6 lines
Now with this architecture there's no problem with duplicate events for local & server notification marks, similarly there's no problem with lost events after inode deletion because events received by the client are directly queued into notification queue without any checking whether inode is still alive etc. Would this work or am I missing something?
Quoted 5 lines
What about group #1 that wants mask A and group #2 that wants mask B events?
Do you propose to maintain separate event queues over the protocol? Attach a "recipient list" to each event?
Yes, that was my idea. Essentially when we see group A creates mark on FUSE for path P, we notify server, it will create notification group A on the server (if not already existing - there we need some notification group identifier unique among all clients), and place mark for it on path P. Then the full stream of notification events generated for group A on the server will just be forwarded to the client and inserted into the A's notification queue. IMO this is very simple solution to implement - you just need to forward mark addition / removal events from the client to the server and you forward event stream from the server to the client. Everything else is handled by the fsnotify infrastructure on the server.
Quoted 3 lines
I just don't see how this can scale other than:
- Local marks and connectors manage the subscriptions on local machine
- Protocol updates the server with the combined masks for watched objectsI agree that depending on the usecase and particular FUSE filesystem performance of this solution may be a concern. OTOH the only additional cost of this solution I can see (compared to all those processes just watching files locally) is the passing of the events from the server to the client. For local FUSE filesystems such as virtiofs this should be rather cheap since you have to do very little processing for each generated event. For filesystems such as sshfs, I can imagine this would be a bigger deal.
Also one problem I can see with my proposal is that it will have problems with stuff such as leases - i.e., if the client does not notify the server of the changes quickly but rather batches local operations and tells the server about them only on special occasions. I don't know enough about FUSE filesystems to tell whether this is a frequent problem or not.
Quoted 5 lines
I think that the "post-mortem events" issue could be solved by keeping an
S_DEADfuse inode object in limbo just for the mark.
When a remote server sendsFS_IN_IGNOREDorFS_DELETE_SELFfor an inode, the fuse client inode can be finally evicted.
I haven't tried to see how hard that would be to implement.Quoted 4 lines
Sure, there can be other solutions to this particular problem. I just want to discuss the other architecture to see why we cannot to it in a simple way :).
Fair enough.
Beyond the scalability aspects, I think that a design that exposes the group to the remote server and allows to "inject" events to the group queue will prevent
users from useful features going forward.For example, fanotify
ignored_maskcould be added to a group, even on a mount mark, even if the remote server only supports inode marks and it would just work.Quoted 5 lines
Another point of view for the post-mortem events:
As Miklos once noted and as you wrote above, for cache coherency and leases, an async notification queue is not adequate and synchronous notifications are too costly, so there needs to be some shared memory solution involving guest cache invalidation by host.Quoted 3 lines
Any shared memory solution works only limited setup. If server is remote on other machine, there is no sharing. I am hoping that this can be generic enough to support other remote filesystems down the line.
Quoted 5 lines
OK, so do I understand both you and Amir correctly that you think that always relying on the FUSE server for generating the events and just piping them to the client is not long-term viable design for FUSE? Mostly because caching of modifications on the client is essentially inevitable and hence generating events from the server would be unreliable (delayed too much)?
Hi Jan,
Actually I had not even thought about operation caching in clients. IIUC, as of now we only have modes to support caching of buffered writes in fuse (which can be flushed later, -o writeback). Other file operations should go to server.
To me, it sounds reasonable for FUSE server to generate events and that's what we are doing in this RFC proposal. So idea is that an application is effectively watching and receiving events for changes happening at remote server.
As of now local events will be supressed so if some operations are local to client only, then events will not be generated or will be generated late when server sees those changes.
I am not sure if supressing all local events will serve all use cases in long term though. For example, Amir was mentioning about fanotify, events on mount objects and it might make sense to generate local events there.
So initial implementation could be about, application either get local events or remote events (based on filesystem). Down the line more complicated modes can emerge where some combination of local and remote events could be generated and applications could specify it. That probably will be extension of fanotiy/inotify API.
Thanks
Vivek
Amir Goldstein
reviewerQuoted 5 lines
Quoted 5 lines
OK, so do I understand both you and Amir correctly that you think that always relying on the FUSE server for generating the events and just piping them to the client is not long-term viable design for FUSE? Mostly because caching of modifications on the client is essentially inevitable and hence generating events from the server would be unreliable (delayed too much)?
This is one aspect, but we do not have to tie remote notifications to the cache coherency problem that is more complicated.
OTOH, if virtiofs take the route of "remote groups", why not take it one step further and implement "remote event queue".
Then, it does not need to push event notifications from the server into fsnotify at all.
Instead, FUSE client can communicate with the server using ioctl or a new command to implement new_group() that returns a special FUSE file and use FUSE POLL/READ to check/read the server's event queue.
There is already a precedent of this model with CIFS_IOC_NOTIFY and SMB2_CHANGE_NOTIFY - SMB protocol, samba server and Windows server support watching a directory or a subtree. I think it is a "oneshot" watch, so there is no polling nor queue involved.
Quoted 7 lines
So initial implementation could be about, application either get local events or remote events (based on filesystem). Down the line more complicated modes can emerge where some combination of local and remote events could be generated and applications could specify it. That probably will be extension of fanotiy/inotify API.
There is one more problem with this approach.
We cannot silently change the behavior of existing FUSE filesystems. What if a system has antivirus configured to scan access to virtiofs mounts? Do you consider it reasonable that on system upgrade, the capability of adding local watches would go away?
I understand the desire to have existing inotify applications work out of the box to get remote notifications, but I have doubts if this goal is even worth pursuing. Considering that the existing known use case described in this thread is already using polling to identify changes to config files on the host, it could just as well be using a new API to get the job done.
If we had to plan an interface without considering existing applications, I think it would look something like:
#define FAN_MARK_INODE 0x00000000
#define FAN_MARK_MOUNT 0x00000010
#define FAN_MARK_FILESYSTEM 0x00000100
#define FAN_MARK_REMOTE_INODE 0x00001000
#define FAN_MARK_REMOTE_FILESYSTEM 0x00001100
Then, the application can choose to add a remote mark with a certain event mask and a local mark with a different event mask without any ambiguity. The remote events could be tagged with a flag (turn reserved member of fanotify_event_metadata into flags).
We have made a lot of effort to make fanotify a super set of inotify functionality removing old UAPI mistakes and baggage along the way, so I'd really hate to see us going down the path of ambiguous UAPI again.
IMO, the work that Ioannis has already done to support remote notifications with virtiofsd is perfectly valid as a private functionality of virtiofs, just like cifs CIFS_IOC_NOTIFY.
If we want to go further and implement a "remote notification subsystem" then I think we should take other fs (e.g.cifs) into consideration and think about functionality beyond the plain remote watch and create an UAPI that can be used to extend the functionality further.
Thanks,
Amir.
Jan Kara
maintainerQuoted 9 lines · Amir Goldstein
Quoted 5 lines
Quoted 5 lines
OK, so do I understand both you and Amir correctly that you think that always relying on the FUSE server for generating the events and just piping them to the client is not long-term viable design for FUSE? Mostly because caching of modifications on the client is essentially inevitable and hence generating events from the server would be unreliable (delayed too much)?
This is one aspect, but we do not have to tie remote notifications to the cache coherency problem that is more complicated.
Quoted 7 lines
OTOH, if virtiofs take the route of "remote groups", why not take it one step further and implement "remote event queue".
Then, it does not need to push event notifications from the server into fsnotify at all.
Instead, FUSE client can communicate with the server using ioctl or a new command to implementnew_group()that returns a special FUSE file and use FUSE POLL/READ to check/read the server's event queue.
Yes, that could work. But I don't see how you want to avoid pushing events to fsnotify on the client side. Suppose app creates fanotify group G, it adds mark for some filesystem F1 to it, then in adds marks for another filesystem F2 - this time it is FUSE based fs. App wants to receive events for both F1 and F2 but events for F2 are actually coming from the server and somehow they have to get into G's queue for an app to read them.
Quoted 4 lines
There is already a precedent of this model with
CIFS_IOC_NOTIFYandSMB2_CHANGE_NOTIFY- SMB protocol, samba server and Windows server support watching a directory or a subtree. I think it is a "oneshot" watch, so there is no polling nor queue involved.
OK, are you aiming at completely separate notification API for userspace for FUSE-based filesystems? Then I see why you don't need to push events to fsnotify but I don't quite like that for a few reasons:
1) Application has to be aware whether the filesystem it operates on is FUSE based or not. That is IMO unnecessary burden for the applications.
2) If application wants to watch for several paths potentially on multiple filesystems, it would now need to somehow merge the event streams from FUSE API and {fa/i}notify API.
3) It would potentially duplicate quite some parts of fsnotify API handling.
Quoted 11 lines
Quoted 5 lines
So initial implementation could be about, application either get local events or remote events (based on filesystem). Down the line more complicated modes can emerge where some combination of local and remote events could be generated and applications could specify it. That probably will be extension of fanotiy/inotify API.
There is one more problem with this approach.
We cannot silently change the behavior of existing FUSE filesystems. What if a system has antivirus configured to scan access to virtiofs mounts? Do you consider it reasonable that on system upgrade, the capability of adding local watches would go away?
I agree we have to be careful there. If fanotify / inotify is currently usable with virtiofs, just missing events coming from host changes (which are presumably rare for lots of setups), it is likely used by someone and we should not regress it.
Quoted 20 lines
I understand the desire to have existing inotify applications work out of the box to get remote notifications, but I have doubts if this goal is even worth pursuing. Considering that the existing known use case described in this thread is already using polling to identify changes to config files on the host, it could just as well be using a new API to get the job done.
If we had to plan an interface without considering existing applications, I think it would look something like:
#define
FAN_MARK_INODE0x00000000
#defineFAN_MARK_MOUNT0x00000010
#defineFAN_MARK_FILESYSTEM0x00000100
#defineFAN_MARK_REMOTE_INODE0x00001000
#defineFAN_MARK_REMOTE_FILESYSTEM0x00001100Then, the application can choose to add a remote mark with a certain event mask and a local mark with a different event mask without any ambiguity. The remote events could be tagged with a flag (turn reserved member of
fanotify_event_metadatainto flags).
Quoted 4 lines
We have made a lot of effort to make fanotify a super set of inotify functionality removing old UAPI mistakes and baggage along the way, so I'd really hate to see us going down the path of ambiguous UAPI again.
So there's a question: Does application care whether the event comes from local or remote side? I'd say generally no - a file change is simply a file change and it does not matter who did it. Also again this API implies the application has to be aware it runs on a filesystem that may generate remote events to ask for them. But presumably knowledgeable app can always ask for local & remote events and if that fails (fs does not support remote events), ask only for local. That's not a big burden.
The question is why would we make remote events explicit (and thus complicate the API and usage) when generally apps cannot be bothered who did the change. I suppose it makes implementation and some of the consequences on the stream of events more obvious. Also it allows functionality such as permission or mount events which are only local when the server does not support them which could be useful for "mostly local" filesystems. Hum...
Quoted 8 lines
IMO, the work that Ioannis has already done to support remote notifications with virtiofsd is perfectly valid as a private functionality of virtiofs, just like cifs
CIFS_IOC_NOTIFY.If we want to go further and implement a "remote notification subsystem" then I think we should take other fs (e.g.cifs) into consideration and think about functionality beyond the plain remote watch and create an UAPI that can be used to extend the functionality further.
So I agree that if we go for "remote notification subsystem", then we better consider cases like other FUSE filesystems, cifs, or NFS. I haven't yet made up my mind whether we cannot somehow seamlessly incorporate remote events into fsnotify because it seems to me they are identical to local events from app point of view. But I agree that if we cannot find a way to integrate remote events without many rough edges, then it is better to make remote events explicit.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Amir Goldstein
reviewerQuoted 26 lines · Jan Kara
Quoted 9 lines · Amir Goldstein
Quoted 5 lines
Quoted 5 lines
OK, so do I understand both you and Amir correctly that you think that always relying on the FUSE server for generating the events and just piping them to the client is not long-term viable design for FUSE? Mostly because caching of modifications on the client is essentially inevitable and hence generating events from the server would be unreliable (delayed too much)?
This is one aspect, but we do not have to tie remote notifications to the cache coherency problem that is more complicated.
Quoted 7 lines
OTOH, if virtiofs take the route of "remote groups", why not take it one step further and implement "remote event queue".
Then, it does not need to push event notifications from the server into fsnotify at all.
Instead, FUSE client can communicate with the server using ioctl or a new command to implementnew_group()that returns a special FUSE file and use FUSE POLL/READ to check/read the server's event queue.Yes, that could work. But I don't see how you want to avoid pushing events to fsnotify on the client side. Suppose app creates fanotify group G, it adds mark for some filesystem F1 to it, then in adds marks for another filesystem F2 - this time it is FUSE based fs. App wants to receive events for both F1 and F2 but events for F2 are actually coming from the server and somehow they have to get into G's queue for an app to read them.
Quoted 7 lines
Quoted 4 lines
There is already a precedent of this model with
CIFS_IOC_NOTIFYandSMB2_CHANGE_NOTIFY- SMB protocol, samba server and Windows server support watching a directory or a subtree. I think it is a "oneshot" watch, so there is no polling nor queue involved.OK, are you aiming at completely separate notification API for userspace for FUSE-based filesystems?
Yes, if the group is "remote" then all the marks are "remote" and event queue is also remote.
Quoted 6 lines
Then I see why you don't need to push events
to fsnotify but I don't quite like that for a few reasons:1) Application has to be aware whether the filesystem it operates on is FUSE based or not. That is IMO unnecessary burden for the applications.
Quoted 7 lines
2) If application wants to watch for several paths potentially on multiple filesystems, it would now need to somehow merge the event streams from FUSE API and {fa/i}notify API.
3) It would potentially duplicate quite some parts of fsnotify API handling.
I don't like so much either, but virtiofs developers are free to pursue this direction without involving the fsnotify subsystem (like cifs). One can even implement userspace wrappers for inotify library functions that know how to utilize remote cifs/fuse watches...
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
So initial implementation could be about, application either get local events or remote events (based on filesystem). Down the line more complicated modes can emerge where some combination of local and remote events could be generated and applications could specify it. That probably will be extension of fanotiy/inotify API.
There is one more problem with this approach.
We cannot silently change the behavior of existing FUSE filesystems. What if a system has antivirus configured to scan access to virtiofs mounts? Do you consider it reasonable that on system upgrade, the capability of adding local watches would go away?
Quoted 5 lines
I agree we have to be careful there. If fanotify / inotify is currently usable with virtiofs, just missing events coming from host changes (which are presumably rare for lots of setups), it is likely used by someone and we should not regress it.
I don't see why it wouldn't be usable.
I think we have to assume that someone is using inotify/fanotify on virtiofs.
Quoted 33 lines
Quoted 20 lines
I understand the desire to have existing inotify applications work out of the box to get remote notifications, but I have doubts if this goal is even worth pursuing. Considering that the existing known use case described in this thread is already using polling to identify changes to config files on the host, it could just as well be using a new API to get the job done.
If we had to plan an interface without considering existing applications, I think it would look something like:
#define
FAN_MARK_INODE0x00000000
#defineFAN_MARK_MOUNT0x00000010
#defineFAN_MARK_FILESYSTEM0x00000100
#defineFAN_MARK_REMOTE_INODE0x00001000
#defineFAN_MARK_REMOTE_FILESYSTEM0x00001100Then, the application can choose to add a remote mark with a certain event mask and a local mark with a different event mask without any ambiguity. The remote events could be tagged with a flag (turn reserved member of
fanotify_event_metadatainto flags).Quoted 4 lines
We have made a lot of effort to make fanotify a super set of inotify functionality removing old UAPI mistakes and baggage along the way, so I'd really hate to see us going down the path of ambiguous UAPI again.
So there's a question: Does application care whether the event comes from local or remote side? I'd say generally no - a file change is simply a file change and it does not matter who did it. Also again this API implies the application has to be aware it runs on a filesystem that may generate remote events to ask for them. But presumably knowledgeable app can always ask for local & remote events and if that fails (fs does not support remote events), ask only for local. That's not a big burden.
Quoted 8 lines
The question is why would we make remote events explicit (and thus complicate the API and usage) when generally apps cannot be bothered who did the change. I suppose it makes implementation and some of the consequences on the stream of events more obvious. Also it allows functionality such as permission or mount events which are only local when the server does not support them which could be useful for "mostly local" filesystems. Hum...
Yeh, it is not clear at all what's the best approach.
Maybe the application would just need to specify FAN_REMOTE_EVENTS in fanotify_init() to opt-in for any new behavior to avoid surprises and not be any more explicit than that for the common use case.
Thanks,
Amir.
Hi Ioannis,
I see that you have been working on making fsnotify work on virtiofs. Earlier you contacted me since I've written this:
https://github.com/libfuse/libfuse/wiki/Fsnotify-and-FUSE
and send you my patches on 23 june.
I want to mention first that I would have appreciated it if you would have reacted to me after I've sent you my patches. I did not get any reaction from you. Maybe these patches (which differ from what you propose now, but there is also a lot in common) have been an inspiration for you.
Second, what I've written about is that with network filesystems (eg a backend shared with other systems) fsnotify support in FUSE has some drawbacks.
In a network environment, where a network fs is part of making people collaborate, it's very useful to have information on who did what on which host, and also when. Simply a message "a file has been created in the folder you watch" is not enough. For example, if you are part of a team, and assigned to your team is a directory on a server where you can work on some shared documents. Now in this example there is a planning, and some documents have to be written. In that case you want to be informed that someone in your team has started a document (by creating it) by the system.
This "extended" information will never get through fsnotify.
Other info useful to you as team member:
- you have become member of another team: [email protected] - diskspace and/or quota shortage reported by networksystem - new teammember, teammember left - your "rights" or role in the network/team have been changed (for
example from reader to reader and writer to some documents)
What I want to say is that in a network where lots of people work together in teams/projects, (and I want Linux to play a role there, as desktop/workstation) communication is very important, and all these messages should be supported by the system. My idea is the support of watching fs events with FUSE filesystems should go through userspace, and not via the kernel (cause fs events are part of your setup in the network, together with all other tools to make people collaborate like chat/call/text, and because mentioned above extended info about the who on what host etc is not supported by fsnotify).
There should be a fs event watcher which takes care of all watches on behalf of applications during a session, similar to gamin and FAM once did (not used anymore?).
When receiving a request from one of the applications this fsevent watcher will use inotify and/or fanotify for local fs's only. With a FUSE fs, it should contact (via a socket) this fs that a watch has been set on an inode with a certain mask.
If the FUSE fs does not support this, fallback on normal inotify/fanotify. This way extended info is possible.
Is this extended information also useful for virtiofs?
Stef Bon
Hi Stef,
I am terribly sorry, I should have mentioned you and your contribution in the cover letter for the patches. It was not intentional, but a mistake from my part and I take full responsibility for it. I am very new to this whole process and I make a lot of mistakes.
You are correct, we have been in contact with you in the past about your "Fsnotify-and-FUSE" post
https://github.com/libfuse/libfuse/wiki/Fsnotify-and-FUSE
and you also kindly provided your initial patches for FUSE fsnotify and shared some concerns/limitations of the implementation with us. We also have stumbled upon these limitations during our implementation and discussed them in these patch series. You also informed us then that you were already working on an out of band notification approach.
Both the Wiki and patches have been a big inspiration for our own RFC patches, especially in the case where we have to decide which data we should transmit between the FUSE server (virtiofsd) and client (QEMU guest).
I do not have an official/public link to cite your patches here so you can reply to this email if you want and post a link to your patches.
To support inotify/fsnotify in virtiofs we had to take a slightly different implementation route, albeit with many limitations. Our main goal with the RFC patches was to get insights from the kernel developers on how to proceed with our project. Our implementation will change further based on what Amir and Jan have already proposed.
I am sorry again for not giving you the credit you deserve.
Thanks,
Ioannis
Quoted 61 lines · Stef Bon
Hi Ioannis,
I see that you have been working on making fsnotify work on virtiofs. Earlier you contacted me since I've written this:
https://github.com/libfuse/libfuse/wiki/Fsnotify-and-FUSE
and send you my patches on 23 june.
I want to mention first that I would have appreciated it if you would have reacted to me after I've sent you my patches. I did not get any reaction from you. Maybe these patches (which differ from what you propose now, but there is also a lot in common) have been an inspiration for you.Second, what I've written about is that with network filesystems (eg a backend shared with other systems) fsnotify support in FUSE has some drawbacks.
In a network environment, where a network fs is part of making people collaborate, it's very useful to have information on who did what on which host, and also when. Simply a message "a file has been created in the folder you watch" is not enough. For example, if you are part of a team, and assigned to your team is a directory on a server where you can work on some shared documents. Now in this example there is a planning, and some documents have to be written. In that case you want to be informed that someone in your team has started a document (by creating it) by the system.This "extended" information will never get through fsnotify.
Other info useful to you as team member:
(quoted diff) +0
-4- you have become member of another team: [email protected] - diskspace and/or quota shortage reported by networksystem - new teammember, teammember left - your "rights" or role in the network/team have been changed (forexample from reader to reader and writer to some documents)
What I want to say is that in a network where lots of people work together in teams/projects, (and I want Linux to play a role there, as desktop/workstation) communication is very important, and all these messages should be supported by the system. My idea is the support of watching fs events with FUSE filesystems should go through userspace, and not via the kernel (cause fs events are part of your setup in the network, together with all other tools to make people collaborate like chat/call/text, and because mentioned above extended info about the who on what host etc is not supported by fsnotify).
There should be a fs event watcher which takes care of all watches on behalf of applications during a session, similar to gamin and FAM once did (not used anymore?).
When receiving a request from one of the applications this fsevent watcher will use inotify and/or fanotify for local fs's only. With a FUSE fs, it should contact (via a socket) this fs that a watch has been set on an inode with a certain mask.
If the FUSE fs does not support this, fallback on normal inotify/fanotify. This way extended info is possible.Is this extended information also useful for virtiofs?
Stef Bon
Signature · 2 lines
Ioannis Angelakopoulos Software Engineer Intern at Red Hat
Quoted 27 lines · Stef Bon
Hi Ioannis,
I see that you have been working on making fsnotify work on virtiofs. Earlier you contacted me since I've written this:
https://github.com/libfuse/libfuse/wiki/Fsnotify-and-FUSE
and send you my patches on 23 june.
I want to mention first that I would have appreciated it if you would have reacted to me after I've sent you my patches. I did not get any reaction from you. Maybe these patches (which differ from what you propose now, but there is also a lot in common) have been an inspiration for you.Second, what I've written about is that with network filesystems (eg a backend shared with other systems) fsnotify support in FUSE has some drawbacks.
In a network environment, where a network fs is part of making people collaborate, it's very useful to have information on who did what on which host, and also when. Simply a message "a file has been created in the folder you watch" is not enough. For example, if you are part of a team, and assigned to your team is a directory on a server where you can work on some shared documents. Now in this example there is a planning, and some documents have to be written. In that case you want to be informed that someone in your team has started a document (by creating it) by the system.
Quoted 1 line
I agree that the out of band approach you propose is actually more
powerful, since it can
provide the client with more information than remote fsnotify. However, in the virtiofs setup
your approach might not be as efficient.
Specifically, the information on who did what might not make sense to the guest within QEMU, since all the
virtiofs filesystem operations are handled by viritofsd on the host and the guest does not know about the
server or any other guests. Vivek, correct me here if I am wrong.
Thus, for now at least, it might be sufficient for the guest to know that just a remote event
occurred.
This "extended" information will never get through fsnotify.
Quoted 28 lines
Other info useful to you as team member:
(quoted diff) +0
-4- you have become member of another team: [email protected] - diskspace and/or quota shortage reported by networksystem - new teammember, teammember left - your "rights" or role in the network/team have been changed (forexample from reader to reader and writer to some documents)
What I want to say is that in a network where lots of people work together in teams/projects, (and I want Linux to play a role there, as desktop/workstation) communication is very important, and all these messages should be supported by the system. My idea is the support of watching fs events with FUSE filesystems should go through userspace, and not via the kernel (cause fs events are part of your setup in the network, together with all other tools to make people collaborate like chat/call/text, and because mentioned above extended info about the who on what host etc is not supported by fsnotify).
There should be a fs event watcher which takes care of all watches on behalf of applications during a session, similar to gamin and FAM once did (not used anymore?).
When receiving a request from one of the applications this fsevent watcher will use inotify and/or fanotify for local fs's only. With a FUSE fs, it should contact (via a socket) this fs that a watch has been set on an inode with a certain mask.
If the FUSE fs does not support this, fallback on normal inotify/fanotify. This way extended info is possible.
Quoted 3 lines
Is this extended information also useful for virtiofs?
Also based on your explanation, your out of band approach is specific to
FUSE filesystems.
Granted, with your approach there is less complexity in the kernel and more flexibility since
the event notification occurs solely in user-space.
However, during the discussion with Amir and Jan about potential routes we could take to support the remote
fanotify/inotify/fsnotify one important concern was that the API should be able to support other
network/remote filesystems if needed and not only FUSE filesystems. It seems that your approach would require a lot of work (correct me if I am wrong) to be adopted
by other network filesystems.
Finally, user-space applications should also be aware of your new API, which will probably result in a non-negligible effort by app developers to adopt it or change their existing apps. The remote inotify/fsnotify ( the current implementation) even though it has many limitations, relies on the existing API and should require less modifications in user space apps. That is why we chose the remote inotify/fsnotify route.
That said, I do not see a reason why both implementations cannot co-exist and have the user-space applications choose which approach they want.
Thanks,
Ioannis
Quoted 3 lines
Stef Bon
Signature · 2 lines
Ioannis Angelakopoulos Software Engineer Intern at Red Hat
Amir Goldstein
reviewerQuoted 83 lines · Ioannis Angelakopoulos
Quoted 15 lines · Stef Bon
Hi Ioannis,
I see that you have been working on making fsnotify work on virtiofs. Earlier you contacted me since I've written this:
https://github.com/libfuse/libfuse/wiki/Fsnotify-and-FUSE
and send you my patches on 23 june.
I want to mention first that I would have appreciated it if you would have reacted to me after I've sent you my patches. I did not get any reaction from you. Maybe these patches (which differ from what you propose now, but there is also a lot in common) have been an inspiration for you.Quoted 13 lines
Second, what I've written about is that with network filesystems (eg a backend shared with other systems) fsnotify support in FUSE has some drawbacks.
In a network environment, where a network fs is part of making people collaborate, it's very useful to have information on who did what on which host, and also when. Simply a message "a file has been created in the folder you watch" is not enough. For example, if you are part of a team, and assigned to your team is a directory on a server where you can work on some shared documents. Now in this example there is a planning, and some documents have to be written. In that case you want to be informed that someone in your team has started a document (by creating it) by the system.I agree that the out of band approach you propose is actually more powerful, since it can provide the client with more information than remote fsnotify. However, in the virtiofs setup your approach might not be as efficient.
Specifically, the information on who did what might not make sense to the guest within QEMU, since all the virtiofs filesystem operations are handled by viritofsd on the host and the guest does not know about the server or any other guests. Vivek, correct me here if I am wrong.
Thus, for now at least, it might be sufficient for the guest to know that just a remote event occurred.
Quoted 29 lines
This "extended" information will never get through fsnotify.
Other info useful to you as team member:
(quoted diff) +0
-4- you have become member of another team: [email protected] - diskspace and/or quota shortage reported by networksystem - new teammember, teammember left - your "rights" or role in the network/team have been changed (forexample from reader to reader and writer to some documents)
What I want to say is that in a network where lots of people work together in teams/projects, (and I want Linux to play a role there, as desktop/workstation) communication is very important, and all these messages should be supported by the system. My idea is the support of watching fs events with FUSE filesystems should go through userspace, and not via the kernel (cause fs events are part of your setup in the network, together with all other tools to make people collaborate like chat/call/text, and because mentioned above extended info about the who on what host etc is not supported by fsnotify).
There should be a fs event watcher which takes care of all watches on behalf of applications during a session, similar to gamin and FAM once did (not used anymore?).
When receiving a request from one of the applications this fsevent watcher will use inotify and/or fanotify for local fs's only. With a FUSE fs, it should contact (via a socket) this fs that a watch has been set on an inode with a certain mask.
If the FUSE fs does not support this, fallback on normal inotify/fanotify. This way extended info is possible.Quoted 2 lines
Is this extended information also useful for virtiofs?
Also based on your explanation, your out of band approach is specific to FUSE filesystems. Granted, with your approach there is less complexity in the kernel and more flexibility since the event notification occurs solely in user-space.
However, during the discussion with Amir and Jan about potential routes we could take to support the remote fanotify/inotify/fsnotify one important concern was that the API should be able to support other network/remote filesystems if needed and not only FUSE filesystems.
It seems that your approach would require a lot of work (correct me if I am wrong) to be adopted by other network filesystems.
Quoted 2 lines
Finally, user-space applications should also be aware of your new API, which will probably result in a non-negligible effort by app developers to adopt it or change their existing apps. The remote inotify/fsnotify ( the current implementation) even though it has many limitations, relies on the existing API and should require less modifications in user space apps. That is why we chose the remote inotify/fsnotify route.
The way you depict the options seems like either applications are not aware of the UAPI
changes or they need to be modified to adapt to the changes.
I actually think that the much better approach would be to deal with most of the UAPI
complexity in a library, so applications may need to be rebuilt or adapted to use a new
library, but going forward, the library would abstract most of the complexity from the
applications.
The holy grail would be a portable library, such as this go library [1]. It is quite hard to design an API that would abstract all the different capabilities
on Linux-inotify/Linux-fanotify/MacOS-fsevents/Win-USNJournal and more.
The second best would be a library to abstract the ever growing complexity of Linux inotify/fanotify UAPI from applications.
I had already made the first step with adapting libinotifytools to fanotify [2]. We could continue down that path or start creating/improving a different library.
The point is that abstracting different capabilities of remote fs notifications (i.e. cifs, virtiofs, generic FUSE) is going to be challenging, so starting the design from a user library API and deriving the needed pieces from the kernel UAPI is the right way to go IMO.
The library approach will have the advantage that some remote fs capabilities (e.g. for cifs) will be available for old kernels as well and in theory, the library
could also use some standardized OOB notifications channel to get changed made on the host from VM guest tools as Stef proposed.
Quoted 3 lines
That said, I do not see a reason why both implementations cannot co-exist and have the user-space applications choose which approach they want.
True, an OOB channel and kernel generic remote fs support can both exist, but it would be best if the application was not aware of either. The library would pick the facility based on the requested functionality, availability of the facilities in the filesystem and sysadmin/user policy.
Thanks,
Amir.
[1] https://github.com/fsnotify/fsnotify
[2] https://github.com/inotify-tools/inotify-tools/pull/134
Vivek Goyal
maintainerQuoted 122 lines · Amir Goldstein
Quoted 83 lines · Ioannis Angelakopoulos
Quoted 15 lines · Stef Bon
Hi Ioannis,
I see that you have been working on making fsnotify work on virtiofs. Earlier you contacted me since I've written this:
https://github.com/libfuse/libfuse/wiki/Fsnotify-and-FUSE
and send you my patches on 23 june.
I want to mention first that I would have appreciated it if you would have reacted to me after I've sent you my patches. I did not get any reaction from you. Maybe these patches (which differ from what you propose now, but there is also a lot in common) have been an inspiration for you.Quoted 13 lines
Second, what I've written about is that with network filesystems (eg a backend shared with other systems) fsnotify support in FUSE has some drawbacks.
In a network environment, where a network fs is part of making people collaborate, it's very useful to have information on who did what on which host, and also when. Simply a message "a file has been created in the folder you watch" is not enough. For example, if you are part of a team, and assigned to your team is a directory on a server where you can work on some shared documents. Now in this example there is a planning, and some documents have to be written. In that case you want to be informed that someone in your team has started a document (by creating it) by the system.I agree that the out of band approach you propose is actually more powerful, since it can provide the client with more information than remote fsnotify. However, in the virtiofs setup your approach might not be as efficient.
Specifically, the information on who did what might not make sense to the guest within QEMU, since all the virtiofs filesystem operations are handled by viritofsd on the host and the guest does not know about the server or any other guests. Vivek, correct me here if I am wrong.
Thus, for now at least, it might be sufficient for the guest to know that just a remote event occurred.
Quoted 29 lines
This "extended" information will never get through fsnotify.
Other info useful to you as team member:
(quoted diff) +0
-4- you have become member of another team: [email protected] - diskspace and/or quota shortage reported by networksystem - new teammember, teammember left - your "rights" or role in the network/team have been changed (forexample from reader to reader and writer to some documents)
What I want to say is that in a network where lots of people work together in teams/projects, (and I want Linux to play a role there, as desktop/workstation) communication is very important, and all these messages should be supported by the system. My idea is the support of watching fs events with FUSE filesystems should go through userspace, and not via the kernel (cause fs events are part of your setup in the network, together with all other tools to make people collaborate like chat/call/text, and because mentioned above extended info about the who on what host etc is not supported by fsnotify).
There should be a fs event watcher which takes care of all watches on behalf of applications during a session, similar to gamin and FAM once did (not used anymore?).
When receiving a request from one of the applications this fsevent watcher will use inotify and/or fanotify for local fs's only. With a FUSE fs, it should contact (via a socket) this fs that a watch has been set on an inode with a certain mask.
If the FUSE fs does not support this, fallback on normal inotify/fanotify. This way extended info is possible.Quoted 2 lines
Is this extended information also useful for virtiofs?
Also based on your explanation, your out of band approach is specific to FUSE filesystems. Granted, with your approach there is less complexity in the kernel and more flexibility since the event notification occurs solely in user-space.
However, during the discussion with Amir and Jan about potential routes we could take to support the remote fanotify/inotify/fsnotify one important concern was that the API should be able to support other network/remote filesystems if needed and not only FUSE filesystems.
It seems that your approach would require a lot of work (correct me if I am wrong) to be adopted by other network filesystems.Quoted 2 lines
Finally, user-space applications should also be aware of your new API, which will probably result in a non-negligible effort by app developers to adopt it or change their existing apps. The remote inotify/fsnotify ( the current implementation) even though it has many limitations, relies on the existing API and should require less modifications in user space apps. That is why we chose the remote inotify/fsnotify route.
The way you depict the options seems like either applications are not aware of the UAPI
changes or they need to be modified to adapt to the changes.I actually think that the much better approach would be to deal with most of the UAPI
complexity in a library, so applications may need to be rebuilt or adapted to use a new
library, but going forward, the library would abstract most of the complexity from the
applications.The holy grail would be a portable library, such as this go library [1]. It is quite hard to design an API that would abstract all the different capabilities
on Linux-inotify/Linux-fanotify/MacOS-fsevents/Win-USNJournal and more.The second best would be a library to abstract the ever growing complexity of Linux inotify/fanotify UAPI from applications.
I had already made the first step with adapting libinotifytools to fanotify [2]. We could continue down that path or start creating/improving a different library.The point is that abstracting different capabilities of remote fs notifications (i.e. cifs, virtiofs, generic FUSE) is going to be challenging, so starting the design from a user library API and deriving the needed pieces from the kernel UAPI is the right way to go IMO.
The library approach will have the advantage that some remote fs capabilities (e.g. for cifs) will be available for old kernels as well and in theory, the library
could also use some standardized OOB notifications channel to get changed made on the host from VM guest tools as Stef proposed.
Quoted 8 lines
Quoted 3 lines
That said, I do not see a reason why both implementations cannot co-exist and have the user-space applications choose which approach they want.
True, an OOB channel and kernel generic remote fs support can both exist, but it would be best if the application was not aware of either. The library would pick the facility based on the requested functionality, availability of the facilities in the filesystem and sysadmin/user policy.
Sure. A library will be nice to abstract kernel generic remote fs and OOB channel. This sounds like another project for somebody to work on.
IIUC, it looks like that both the approaches can make progress in parallel. Advantange of OOB channel approach seems that it will be easier to make changes in user space and add more events and send extra information.
While advantage of remote fsnotify is that its a known existing events API and it makes it easier for applications to use same API for remote fs (however limited it might be).
Thanks
Vivek
Quoted 6 lines
Thanks,
Amir.[1] https://github.com/fsnotify/fsnotify
[2] https://github.com/inotify-tools/inotify-tools/pull/134
Hello Amir and Jan,
After testing some of your proposals, related to extending the remote notification to fanotify as well, we came across some issues that are not straightforward to overcome:
1) Currently fuse does not support persistent file handles. This means that file handles become stale if an inode is flushed out of the cache. The file handle support is very limited at the moment in fuse. Thus, the only option left is to implement fanotify both in server and guest with file descriptors.
2) Since we can only use file descriptors, to support fanotify in viritofsd we need CAP_SYS_ADMIN enabled. The virtiofs developers are not very positive about the idea of using CAP_SYS_ADMIN for security reasons. Thus we attempted to support some basic fanotify functionality on the client/guest by modifying our existing implementation with inotify/fsnotify.
3) Basically, we continue to use inotify on the virtiofsd/fuse server but we add support on the client/guest kernel to be able to support simple fanotify events (i.e., for now the same events as inotify). However, two important problems arise from the use of the fanotify file descriptor mode in a guest process:
3a) First, to be able to support fanotify in the file descriptor mode we need to pass to a "struct path" to the fsnotify call (within the guest kernel) that corresponds to the inode that we are monitoring. Unfortunately, when the guest receives the remote event from the server it only has information about the target inode. Since there is more than one mapping of "struct path" to a "struct inode" we do not know which path information to pass to the fsnotify call.
3b) Second, since the guest kernel needs to pass an open file descriptor back to the guest user space as part of the fanotify event data, internally the guest kernel (through fanotify's "create_fd" function) issues a "dentry_open" which will result in an additional FUSE_OPEN call to the server and subsequently the generation of an open event on the server (If the server monitors for an open event). This will inevitably cause an infinite loop of FUSE_OPEN requests and generation of open events on the server. One idea was to modify the open syscall (on the host kernel) to allow the use of FMODE_NONOTIFY flag from user space (currently it is used internally in the kernel code only), to be able to suppress open events. However, a malicious guest might be able to exploit that flag to disrupt the event generation for a file (I am not entirely sure if this is possible, yet).
To sum up, it seems that the support for fanotify causes some problems that are very difficult to mitigate at the moment. The fanotify file handles mode would probably solve most if not all of the above problems we are facing, however as Vivek pointed out the file handle support in virtiofs/fuse is another project altogether.
So we would like to ask you for any suggestions related to the aforementioned problems. If there are no "easy" solutions in sight for these fanotify issues, we would like to at least continue to support the remote inotify in the next version of the patches and try to solve issues around it.
Thanks,
Ioannis
Quoted 179 lines · Vivek Goyal
Quoted 34 lines · Amir Goldstein
Quoted 32 lines · Ioannis Angelakopoulos
Quoted 28 lines · Stef Bon
Hi Ioannis,
I see that you have been working on making fsnotify work on virtiofs. Earlier you contacted me since I've written this:
https://github.com/libfuse/libfuse/wiki/Fsnotify-and-FUSE
and send you my patches on 23 june.
I want to mention first that I would have appreciated it if you would have reacted to me after I've sent you my patches. I did not get any reaction from you. Maybe these patches (which differ from what you propose now, but there is also a lot in common) have been an inspiration for you.Second, what I've written about is that with network filesystems (eg a backend shared with other systems) fsnotify support in FUSE has some drawbacks.
In a network environment, where a network fs is part of making people collaborate, it's very useful to have information on who did what on which host, and also when. Simply a message "a file has been created in the folder you watch" is not enough. For example, if you are part of a team, and assigned to your team is a directory on a server where you can work on some shared documents. Now in this example there is a planning, and some documents have to be written. In that case you want to be informed that someone in your team has started a document (by creating it) by the system.Quoted 1 line
Quoted 1 line
I agree that the out of band approach you propose is actually more
powerful, since it can
Quoted 1 line
Quoted 1 line
provide the client with more information than remote fsnotify.
However, in the virtiofs setup
Quoted 3 lines
Quoted 3 lines
your approach might not be as efficient.
Specifically, the information on who did what might not make sense to
the guest within QEMU, since all the
Quoted 1 line
Quoted 1 line
virtiofs filesystem operations are handled by viritofsd on the host
and the guest does not know about the
Quoted 3 lines
Quoted 3 lines
server or any other guests. Vivek, correct me here if I am wrong.
Thus, for now at least, it might be sufficient for the guest to know
that just a remote event
Quoted 7 lines
Quoted 7 lines
occurred.
Quoted 5 lines
This "extended" information will never get through fsnotify.
Other info useful to you as team member:
- you have become member of another team:
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
(quoted diff) +0
-3- diskspace and/or quota shortage reported by networksystem - new teammember, teammember left - your "rights" or role in the network/team have been changed (forexample from reader to reader and writer to some documents)
What I want to say is that in a network where lots of people work together in teams/projects, (and I want Linux to play a role there, as desktop/workstation) communication is very important, and all these messages should be supported by the system. My idea is the support of watching fs events with FUSE filesystems should go through userspace, and not via the kernel (cause fs events are part of your setup in the network, together with all other tools to make people collaborate like chat/call/text, and because mentioned above extended info about the who on what host etc is not supported by fsnotify).
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
There should be a fs event watcher which takes care of all watches on behalf of applications during a session, similar to gamin and FAM once did (not used anymore?).
When receiving a request from one of the applications this fsevent watcher will use inotify and/or fanotify for local fs's only. With a FUSE fs, it should contact (via a socket) this fs that a watch has been set on an inode with a certain mask.
If the FUSE fs does not support this, fallback on normalinotify/fanotify.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
This way extended info is possible.
Is this extended information also useful for virtiofs?
Also based on your explanation, your out of band approach is specific
to FUSE filesystems.
Quoted 1 line
Quoted 1 line
Granted, with your approach there is less complexity in the kernel and
more flexibility since
Quoted 2 lines
Quoted 2 lines
the event notification occurs solely in user-space. However, during the discussion with Amir and Jan about potential
routes we could take to support the remote
Quoted 1 line
Quoted 1 line
fanotify/inotify/fsnotify one important concern was that the API
should be able to support other
Quoted 2 lines
Quoted 2 lines
network/remote filesystems if needed and not only FUSE filesystems. It seems that your approach would require a lot of work (correct me if
I am wrong) to be adopted
Quoted 3 lines
Quoted 3 lines
by other network filesystems.
Finally, user-space applications should also be aware of your new API,
which will probably result in a non-negligible effort by app developers to adopt it or change their existing apps. The remote inotify/fsnotify ( the current implementation) even though it has many limitations, relies on the existing API and should require less modifications in user space apps. That is why we chose the remote inotify/fsnotify route.
Quoted 14 lines
Quoted 1 line
The way you depict the options seems like either applications are not aware of the UAPI
changes or they need to be modified to adapt to the changes.I actually think that the much better approach would be to deal with most of the UAPI
complexity in a library, so applications may need to be rebuilt or adapted to use a new
library, but going forward, the library would abstract most of the complexity from the
applications.Quoted 6 lines
The holy grail would be a portable library, such as this go library [1]. It is quite hard to design an API that would abstract all the different capabilities
on Linux-inotify/Linux-fanotify/MacOS-fsevents/Win-USNJournal and more.The second best would be a library to abstract the ever growing
complexity
Quoted 2 lines
of Linux inotify/fanotify UAPI from applications.
I had already made the first step with adapting libinotifytools tofanotify [2].
Quoted 4 lines
We could continue down that path or start creating/improving a different library.
The point is that abstracting different capabilities of remote fs
notifications
Quoted 1 line
(i.e. cifs, virtiofs, generic FUSE) is going to be challenging, so
starting the
Quoted 4 lines
design from a user library API and deriving the needed pieces from the kernel UAPI is the right way to go IMO.
The library approach will have the advantage that some remote fs
capabilities
Quoted 6 lines
(e.g. for cifs) will be available for old kernels as well and in theory, the library
could also use some standardized OOB notifications channel to get changed made on the host from VM guest tools as Stef proposed.Quoted 1 line
That said, I do not see a reason why both implementations cannot
co-exist
Quoted 7 lines
Quoted 2 lines
and have the user-space applications choose which approach they want.
True, an OOB channel and kernel generic remote fs support can both exist, but it would be best if the application was not aware of either. The library would pick the facility based on the requested functionality, availability of the facilities in the filesystem and sysadmin/user
policy.
Sure. A library will be nice to abstract kernel generic remote fs and OOB channel. This sounds like another project for somebody to work on.
IIUC, it looks like that both the approaches can make progress in parallel. Advantange of OOB channel approach seems that it will be easier to
make changes in user space and add more events and send extra information.While advantage of remote fsnotify is that its a known existing events API and it makes it easier for applications to use same API for remote fs (however limited it might be).
Thanks
VivekQuoted 6 lines
Thanks,
Amir.[1] https://github.com/fsnotify/fsnotify
[2] https://github.com/inotify-tools/inotify-tools/pull/134
Signature · 2 lines
Ioannis Angelakopoulos Software Engineer Intern at Red Hat
Amir Goldstein
reviewerQuoted 6 lines · Ioannis Angelakopoulos
Hello Amir and Jan,
After testing some of your proposals, related to extending the remote notification to fanotify as well, we came across some issues that are not straightforward to overcome:
1) Currently fuse does not support persistent file handles. This means that file handles become stale if an inode is flushed out of the cache. The file handle support is very limited at the moment in fuse. Thus, the only option left is to implement fanotify both in server and guest with file descriptors.
That premise is not completely accurate...
Quoted 4 lines
2) Since we can only use file descriptors, to support fanotify in viritofsd we need
CAP_SYS_ADMINenabled. The virtiofs developers are not very positive about the idea of usingCAP_SYS_ADMINfor security reasons. Thus we attempted to support some basic fanotify functionality on the client/guest by modifying our existing implementation with inotify/fsnotify.3) Basically, we continue to use inotify on the virtiofsd/fuse server but we add support on the client/guest kernel to be able to support simple fanotify events (i.e., for now the same events as inotify). However, two important problems arise from the use of the fanotify file descriptor mode in a guest process:
You may use whatever implementation you like is the server. inotify, fanotify, pub/sub to notify one client on changes from other clients. My comments are only about the protocol and vfs API, which affect all other FUSE servers
that would want to implement fsnotify support in the future and other remote filesystems that would want to implement remote fsnotify in the future.
Quoted 5 lines
3a) First, to be able to support fanotify in the file descriptor mode we need to pass to a "struct path" to the fsnotify call (within the guest kernel) that corresponds to the inode that we are monitoring. Unfortunately, when the guest receives the remote event from the server it only has information about the target inode. Since there is more than one mapping of "struct path" to a "struct inode" we do not know which path information to pass to the fsnotify call.
3b) Second, since the guest kernel needs to pass an open file descriptor back to the guest user space as part of the fanotify event data, internally the guest kernel (through fanotify's "
create_fd" function) issues a "dentry_open" which will result in an additionalFUSE_OPENcall to the server and subsequently the generation of an open event on the server (If the server monitors for an open event). This will inevitably cause an infinite loop ofFUSE_OPENrequests and generation of open events on the server. One idea was to modify the open syscall (on the host kernel) to allow the use ofFMODE_NONOTIFYflag from user space (currently it is used internally in the kernel code only), to be able to suppress open events. However, a malicious guest might be able to exploit that flag to disrupt the event generation for a file (I am not entirely sure if this is possible, yet).
Supporting event->fd and permission events for that matter was never my intention when I suggested limited fanotify support.
Quoted 4 lines
To sum up, it seems that the support for fanotify causes some problems that are very difficult to mitigate at the moment. The fanotify file handles mode would probably solve most if not all of the above problems we are facing, however as Vivek pointed out the file handle support in virtiofs/fuse is another project altogether.
So we would like to ask you for any suggestions related to the aforementioned problems. If there are no "easy" solutions in sight for these fanotify issues, we would like to at least continue to support the remote inotify in the next version of the patches and try to solve issues around it.
The mistake in your premise at 1) is to state that "fuse does not support persistent file handles"
without looking into what that statement means.
What it really means is that user cannot always open_by_handle_at() from a previously
obtained file handle, which has obvious impact on exporting fuse to NFS (*).
But there is no requirement of fanotify for the user to be able to open_by_handle_at()
from the information in the event, in fact, it is a non-requirement, because open_by_handle_at() requires CAP_DAC_READ_SEARCH and fanotify supports non privileged users.
Quoting the fanotify.7 man page:
"file_handle
...It is an opaque handle that corresponds to a
specified object on a filesystem
as returned by name_to_handle_at(2). It can be used
to uniquely identify a file
on a filesystem and can be passed as an argument toopen_by_handle_at(2).
"
It CAN be passed to open_by_handle_at() - it does not have to be passed, because a unique object id is useful enough without being able to open_by_handle_at() as long as the user who set up the watch on the object keeps a record of that unique id.
So the project of file handle support in virtiofs/fuse is completely independent and complementary to supporting remote fanotify in file handle mode.
I hope I was able to explain myself.
Let me know if anything is not clear.
Thanks,
Amir.
(*) It is correct to state that "FUSE support for persistent file handles is limited",
and FUSE protocol does need to be extended to provide better file handle support,
but actually, it would be more accurate to say that virtiofs (and most other fuse servers)
support for persistent file handles is limited.
I wrote a generic framework called fuse_passthrough [1] that can be used to write a fuse
server that does export persistent file handles to NFS when passing through to xfs/ext4
(and the server has CAP_SYS_ADMIN).
[1] https://github.com/amir73il/libfuse/commits/fuse_passthrough
Vivek Goyal
maintainerQuoted 37 lines · Amir Goldstein
Quoted 6 lines · Ioannis Angelakopoulos
Hello Amir and Jan,
After testing some of your proposals, related to extending the remote notification to fanotify as well, we came across some issues that are not straightforward to overcome:
1) Currently fuse does not support persistent file handles. This means that file handles become stale if an inode is flushed out of the cache. The file handle support is very limited at the moment in fuse. Thus, the only option left is to implement fanotify both in server and guest with file descriptors.
That premise is not completely accurate...
Quoted 4 lines
2) Since we can only use file descriptors, to support fanotify in viritofsd we need
CAP_SYS_ADMINenabled. The virtiofs developers are not very positive about the idea of usingCAP_SYS_ADMINfor security reasons. Thus we attempted to support some basic fanotify functionality on the client/guest by modifying our existing implementation with inotify/fsnotify.3) Basically, we continue to use inotify on the virtiofsd/fuse server but we add support on the client/guest kernel to be able to support simple fanotify events (i.e., for now the same events as inotify). However, two important problems arise from the use of the fanotify file descriptor mode in a guest process:
You may use whatever implementation you like is the server. inotify, fanotify, pub/sub to notify one client on changes from other clients. My comments are only about the protocol and vfs API, which affect all other FUSE servers
that would want to implement fsnotify support in the future and other remote filesystems that would want to implement remote fsnotify in the future.Quoted 5 lines
3a) First, to be able to support fanotify in the file descriptor mode we need to pass to a "struct path" to the fsnotify call (within the guest kernel) that corresponds to the inode that we are monitoring. Unfortunately, when the guest receives the remote event from the server it only has information about the target inode. Since there is more than one mapping of "struct path" to a "struct inode" we do not know which path information to pass to the fsnotify call.
3b) Second, since the guest kernel needs to pass an open file descriptor back to the guest user space as part of the fanotify event data, internally the guest kernel (through fanotify's "
create_fd" function) issues a "dentry_open" which will result in an additionalFUSE_OPENcall to the server and subsequently the generation of an open event on the server (If the server monitors for an open event). This will inevitably cause an infinite loop ofFUSE_OPENrequests and generation of open events on the server. One idea was to modify the open syscall (on the host kernel) to allow the use ofFMODE_NONOTIFYflag from user space (currently it is used internally in the kernel code only), to be able to suppress open events. However, a malicious guest might be able to exploit that flag to disrupt the event generation for a file (I am not entirely sure if this is possible, yet).Supporting
event->fdand permission events for that matter was never my intention when I suggested limited fanotify support.Quoted 4 lines
To sum up, it seems that the support for fanotify causes some problems that are very difficult to mitigate at the moment. The fanotify file handles mode would probably solve most if not all of the above problems we are facing, however as Vivek pointed out the file handle support in virtiofs/fuse is another project altogether.
So we would like to ask you for any suggestions related to the aforementioned problems. If there are no "easy" solutions in sight for these fanotify issues, we would like to at least continue to support the remote inotify in the next version of the patches and try to solve issues around it.
Quoted 6 lines
The mistake in your premise at 1) is to state that "fuse does not support persistent file handles"
without looking into what that statement means.
What it really means is that user cannot alwaysopen_by_handle_at()from a previously
obtained file handle, which has obvious impact on exporting fuse to NFS (*).
Hi Amir,
What good is file handle if one can't use it for open_by_handle_at(). I mean, are there other use cases?
IIUC, file handle for the same object can change if inode had been flushed out of guest cache and brought back in later. So if application say generated file handle for an object and saved it and later put a watch on that object, by that time file handle of the object might have changed (as seen by fuse). So one can't even use to match it with previous saved file handle.
So I can't use file handle for open_by_handle_at(). I can't use it to match it with previously saved file handle. So what can I use it for?
IOW, I could not imagine supporting fanotify file handles without fixing the file handles properly in fuse. And it needs fixing in virtiofs as well as we can't trust random file handles from guest for regular files.
Quoted 11 lines
But there is no requirement of fanotify for the user to be able to
open_by_handle_at()
from the information in the event, in fact, it is a non-requirement, becauseopen_by_handle_at()requiresCAP_DAC_READ_SEARCHand fanotify supports non privileged users.
Quoting the fanotify.7 man page:
"file_handle
...It is an opaque handle that corresponds to a
specified object on a filesystem
as returned byname_to_handle_at(2). It can be used
Quoted 8 lines
to uniquely identify a file
on a filesystem and can be passed as an argument toopen_by_handle_at(2).
"
It CAN be passed toopen_by_handle_at()- it does not have to be passed, because a unique object id is useful enough without being able toopen_by_handle_at()as long as the user who set up the watch on the object keeps a record of that unique id.
I think this is what I am referring to above. This unique id can change between user generating file handle and fanotify reporting the unique id. Now there might be limited ways where you somehow ensure that inode can't be flushed out of guest and for that duration file handle will be valid and ramain same. But that sounds like a very narrow use case and very fragile.
Quoted 2 lines
So the project of file handle support in virtiofs/fuse is completely independent and complementary to supporting remote fanotify in file handle mode.
I think it is base which needs to be fixed properly before supporting fanotify, until and unless we are ready to live with a very narrow use case where file handle for all objects being watched are saved in such a way that they can't change between saving the file handle and event generation.
Vivek
Quoted 22 lines
I hope I was able to explain myself.
Let me know if anything is not clear.Thanks,
Amir.(*) It is correct to state that "FUSE support for persistent file handles is limited",
and FUSE protocol does need to be extended to provide better file handle support,
but actually, it would be more accurate to say that virtiofs (and most other fuse servers)
support for persistent file handles is limited.
I wrote a generic framework calledfuse_passthrough[1] that can be used to write a fuse
server that does export persistent file handles to NFS when passing through to xfs/ext4
(and the server hasCAP_SYS_ADMIN).[1] https://github.com/amir73il/libfuse/commits/fuse_passthrough
Amir Goldstein
reviewerQuoted 8 lines
Quoted 7 lines
The mistake in your premise at 1) is to state that "fuse does not support persistent file handles"
without looking into what that statement means.
What it really means is that user cannot alwaysopen_by_handle_at()from a previously
obtained file handle, which has obvious impact on exporting fuse to NFS (*).
Quoted 4 lines
Hi Amir,
What good is file handle if one can't use it for
open_by_handle_at(). I mean, are there other use cases?
commit 44d705b0:
"...There are several ways that an application can use this information:
1. When watching a single directory, the name is always relative to the watched directory, so application need to fstatat(2) the name relative to the watched directory.
2. When watching a set of directories, the application could keep a map of dirfd for all watched directories and hash the map by fid obtained with name_to_handle_at(2). When getting a name event, the fid in the event info could be used to lookup the base dirfd in the map and then call fstatat(2) with that dirfd.
3. When watching a filesystem (FAN_MARK_FILESYSTEM) or a large set of directories, the application could use open_by_handle_at(2) with the fid in event info to obtain dirfd for the directory where event happened and call fstatat(2) with this dirfd.
The last option scales better for a large number of watched directories. The first two options may be available in the future also for non privileged fanotify watchers, because open_by_handle_at(2) requires the CAP_DAC_READ_SEARCH capability.
"
fsnotifywait [1] has an example of use case #2.
Essentially, when watching inodes, the fanotify file identifier is not very much different from the inotify "watch descriptor" - it identifies the watched object and the watched object is pinned to cache as long as the inode mark is set so file handle would not change also in fuse.
[1] https://github.com/inotify-tools/inotify-tools/pull/134
Quoted 8 lines
IIUC, file handle for the same object can change if inode had been flushed out of guest cache and brought back in later. So if application say generated file handle for an object and saved it and later put a watch on that object, by that time file handle of the object might have changed (as seen by fuse). So one can't even use to match it with previous saved file handle.
The argument is not applicable for inode watches.
Filesystem and mount watches are not going to be supported with virtiofs or any filesystem that does not support persistent file handles.
Quoted 8 lines
So I can't use file handle for
open_by_handle_at(). I can't use it to match it with previously saved file handle. So what can I use it for?IOW, I could not imagine supporting fanotify file handles without fixing the file handles properly in fuse. And it needs fixing in virtiofs as well as we can't trust random file handles from guest for regular files.
Partly correct statements, but when looking at the details, they are not relevant to the case of fanotify inode watch.
Note that at the moment, fuse does not even support local fanotify watch with file handles because of fanotify_test_fsid() - fuse does not set f_fsid (not s_uuid), so it's not really about supporting fanotify on fuse now.
It's about the vfs APIs for remote fsnotify that should not be inotify specific.
Thanks,
Amir.
Vivek Goyal
maintainerQuoted 20 lines · Amir Goldstein
Quoted 8 lines
Quoted 7 lines
The mistake in your premise at 1) is to state that "fuse does not support persistent file handles"
without looking into what that statement means.
What it really means is that user cannot alwaysopen_by_handle_at()from a previously
obtained file handle, which has obvious impact on exporting fuse to NFS (*).Quoted 4 lines
Hi Amir,
What good is file handle if one can't use it for
open_by_handle_at(). I mean, are there other use cases?commit
44d705b0:
"...There are several ways that an application can use this information:1. When watching a single directory, the name is always relative to the watched directory, so application need to fstatat(2) the name relative to the watched directory.
Quoted 5 lines
2. When watching a set of directories, the application could keep a map of dirfd for all watched directories and hash the map by fid obtained with
name_to_handle_at(2). When getting a name event, the fid in the event info could be used to lookup the base dirfd in the map and then call fstatat(2) with that dirfd.
Ok, so case 1 and 2 still might be doable.
Quoted 11 lines
3. When watching a filesystem (
FAN_MARK_FILESYSTEM) or a large set of directories, the application could useopen_by_handle_at(2)with the fid in event info to obtain dirfd for the directory where event happened and call fstatat(2) with this dirfd.The last option scales better for a large number of watched directories. The first two options may be available in the future also for non privileged fanotify watchers, because
open_by_handle_at(2)requires theCAP_DAC_READ_SEARCHcapability.
"
This is one is not possible as it needs open_by_handle_at().
Quoted 6 lines
fsnotifywait [1] has an example of use case #2.
Essentially, when watching inodes, the fanotify file identifier is not very much different from the inotify "watch descriptor" - it identifies the watched object and the watched object is pinned to cache as long as the inode mark is set so file handle would not change also in fuse.
Ok, so if we are maintaining a hash map keyed by file handle, then first we need to pin down the inode and then call name_to_handle_at() for the watched object and add to hash table. Something like this.
A. foo_fd = open(foo.txt)
B. name_to_handle_at(.., foo.txt,...)
C. Add info in hash table using foo_handle as key. D. Add watch on foo.txt (fanotify_mark()). E. close(foo_fd).
One could probably skip step A and E. And do this instead.
A. Add watch on foo.txt (fanotify_mark()) B. name_to_handle_at(.., foo.txt,...)
C. Add info in hash table using foo_handle as key.
But this is little bit racy. You might start getting events with file handles of foo.txt before you could complete B or C.
Quoted 12 lines
[1] https://github.com/inotify-tools/inotify-tools/pull/134
Quoted 8 lines
IIUC, file handle for the same object can change if inode had been flushed out of guest cache and brought back in later. So if application say generated file handle for an object and saved it and later put a watch on that object, by that time file handle of the object might have changed (as seen by fuse). So one can't even use to match it with previous saved file handle.
Quoted 1 line
The argument is not applicable for inode watches.
Fair enough. I could see a very limited use case and thought that's not enough. But looks like you seem to be ok with that.
Quoted 2 lines
Filesystem and mount watches are not going to be supported with virtiofs or any filesystem that does not support persistent file handles.
Ok, so no filesystem and mount watches for virtiofs to begin with.
Quoted 10 lines
Quoted 9 lines
So I can't use file handle for
open_by_handle_at(). I can't use it to match it with previously saved file handle. So what can I use it for?IOW, I could not imagine supporting fanotify file handles without fixing the file handles properly in fuse. And it needs fixing in virtiofs as well as we can't trust random file handles from guest for regular files.
Quoted 7 lines
Partly correct statements, but when looking at the details, they are not relevant to the case of fanotify inode watch.
Note that at the moment, fuse does not even support local fanotify watch with file handles because of
fanotify_test_fsid()- fuse does not setf_fsid(nots_uuid), so it's not really about supporting fanotify on fuse now.
Hmm..., that means we first will have to look into supporting local fanotify events with file handles on fuse. Without that we can't even test our remote fsnotify changes looks like.
This sounds like another blocker (or dependency project to complete first) before one can make progress with remote inotify/fanotify/fsnotify.
Quoted 2 lines
It's about the vfs APIs for remote fsnotify that should not be inotify specific.
I understand that part. But at the same time, remote fsnotify API will probably evolve as you keep on adding more functionality. What if there is another notification mechanism tomorrow say newfancynotify(), we might have to modify remote fsnoitfy again to accomodate that.
IOW, fsnotify seems to be just underlying plumbing and whatever you add today might not be enough to support tomorrow's features. That's why I wanted to start with a minimal set of functionality and add more to it later.
Thanks
Vivek
Amir Goldstein
reviewerQuoted 61 lines · Vivek Goyal
Quoted 20 lines · Amir Goldstein
Quoted 8 lines
Quoted 7 lines
The mistake in your premise at 1) is to state that "fuse does not support persistent file handles"
without looking into what that statement means.
What it really means is that user cannot alwaysopen_by_handle_at()from a previously
obtained file handle, which has obvious impact on exporting fuse to NFS (*).Quoted 4 lines
Hi Amir,
What good is file handle if one can't use it for
open_by_handle_at(). I mean, are there other use cases?commit
44d705b0:
"...There are several ways that an application can use this information:1. When watching a single directory, the name is always relative to the watched directory, so application need to fstatat(2) the name relative to the watched directory.
Quoted 5 lines
2. When watching a set of directories, the application could keep a map of dirfd for all watched directories and hash the map by fid obtained with
name_to_handle_at(2). When getting a name event, the fid in the event info could be used to lookup the base dirfd in the map and then call fstatat(2) with that dirfd.Ok, so case 1 and 2 still might be doable.
Quoted 11 lines
3. When watching a filesystem (
FAN_MARK_FILESYSTEM) or a large set of directories, the application could useopen_by_handle_at(2)with the fid in event info to obtain dirfd for the directory where event happened and call fstatat(2) with this dirfd.The last option scales better for a large number of watched directories. The first two options may be available in the future also for non privileged fanotify watchers, because
open_by_handle_at(2)requires theCAP_DAC_READ_SEARCHcapability.
"This is one is not possible as it needs
open_by_handle_at().Quoted 6 lines
fsnotifywait [1] has an example of use case #2.
Essentially, when watching inodes, the fanotify file identifier is not very much different from the inotify "watch descriptor" - it identifies the watched object and the watched object is pinned to cache as long as the inode mark is set so file handle would not change also in fuse.Ok, so if we are maintaining a hash map keyed by file handle, then first we need to pin down the inode and then call
name_to_handle_at()for the watched object and add to hash table. Something like this.A.
foo_fd= open(foo.txt)
B.name_to_handle_at(.., foo.txt,...)
C. Add info in hash table usingfoo_handleas key. D. Add watch on foo.txt (fanotify_mark()). E.close(foo_fd).
Quoted 9 lines
One could probably skip step A and E. And do this instead.
A. Add watch on foo.txt (
fanotify_mark()) B.name_to_handle_at(.., foo.txt,...)
C. Add info in hash table usingfoo_handleas key.But this is little bit racy. You might start getting events with file handles of foo.txt before you could complete B or C.
I suppose you can also use O_PATH fd to name_to_handle_at() with AT_EMPTY_PATH if you are concerned with races, but the races of name_to_handle_at() vs read events are pretty easy to handle in userspace.
Quoted 14 lines
Quoted 12 lines
[1] https://github.com/inotify-tools/inotify-tools/pull/134
Quoted 8 lines
IIUC, file handle for the same object can change if inode had been flushed out of guest cache and brought back in later. So if application say generated file handle for an object and saved it and later put a watch on that object, by that time file handle of the object might have changed (as seen by fuse). So one can't even use to match it with previous saved file handle.
Quoted 1 line
The argument is not applicable for inode watches.
Quoted 8 lines
Fair enough. I could see a very limited use case and thought that's not enough. But looks like you seem to be ok with that.
Quoted 2 lines
Filesystem and mount watches are not going to be supported with virtiofs or any filesystem that does not support persistent file handles.
Ok, so no filesystem and mount watches for virtiofs to begin with.
No, but I do expect the remote fsnotify vfs API design to take those into account as future extensions.
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
So I can't use file handle for
open_by_handle_at(). I can't use it to match it with previously saved file handle. So what can I use it for?IOW, I could not imagine supporting fanotify file handles without fixing the file handles properly in fuse. And it needs fixing in virtiofs as well as we can't trust random file handles from guest for regular files.
Quoted 7 lines
Partly correct statements, but when looking at the details, they are not relevant to the case of fanotify inode watch.
Note that at the moment, fuse does not even support local fanotify watch with file handles because of
fanotify_test_fsid()- fuse does not setf_fsid(nots_uuid), so it's not really about supporting fanotify on fuse now.
Quoted 7 lines
Hmm..., that means we first will have to look into supporting local fanotify events with file handles on fuse. Without that we can't even test our remote fsnotify changes looks like.
This sounds like another blocker (or dependency project to complete first) before one can make progress with remote inotify/fanotify/fsnotify.
I am not saying you need to do any of those things, but you need to take into account that someone else will want to implement them in virtiofs, other fuse server or other remote fs.
All I am asking is that the vfs API and to some extent also the FUSE fsnotify protocol extension will not be limited to inotify terminology.
Quoted 8 lines
Quoted 2 lines
It's about the vfs APIs for remote fsnotify that should not be inotify specific.
I understand that part. But at the same time, remote fsnotify API will probably evolve as you keep on adding more functionality. What if there is another notification mechanism tomorrow say
newfancynotify(), we might have to modify remote fsnoitfy again to accomodate that.
Quoted 5 lines
IOW, fsnotify seems to be just underlying plumbing and whatever you add today might not be enough to support tomorrow's features. That's why I wanted to start with a minimal set of functionality and add more to it later.
I do want to start with minimal functionality.
I did not request that you implement more functionality than what inotify provides.
TBH, I can't even remember the specific details that made me say "this is remote inotify not remote fsnotify", but there were such details. I remember inotify rename cookie being one of them.
I guess this discussion is not very productive at this point as none of us are saying anything very specific about what should and should not be done, so let me try to suggest something -
Try to see if you could replace the server side implementation with fanotify even if you use CAP_SYS_ADMIN for the experiment. fanotify should be almost a drop-in replacement for inotify at this point If you think that you cannot make this experiment with your current protocol and vfs extensions then you must have done something wrong and tied the protocol and/or the vfs API to inotify terminology.
Thanks,
Amir.
Amir Goldstein
reviewerQuoted 11 lines
Quoted 10 lines
I understand that part. But at the same time, remote fsnotify API will probably evolve as you keep on adding more functionality. What if there is another notification mechanism tomorrow say
newfancynotify(), we might have to modify remote fsnoitfy again to accomodate that.IOW, fsnotify seems to be just underlying plumbing and whatever you add today might not be enough to support tomorrow's features. That's why I wanted to start with a minimal set of functionality and add more to it later.
Quoted 8 lines
I do want to start with minimal functionality.
I did not request that you implement more functionality than what inotify provides.TBH, I can't even remember the specific details that made me say "this is remote inotify not remote fsnotify", but there were such details. I remember inotify rename cookie being one of them.
Let me repeat my concern about the rename cookie API.
As Jan has convinced me to create a new event FS_RENAME for fanotify, there is no harm in FUSE passing the rename cookie along with FS_MOVE events, but the FUSE out args:
struct fuse_notify_fsnotify_out {
uint64_t inode;
uint64_t mask;
uint32_t namelen;
uint32_t cookie;
};
How do you expect to extend it when somebody wants to implement the FS_RENAME event that carries two names and two dir inodes (and no cookie)?
Will they need to use a new out struct? a union?
Unlike inotify, fanotify can sometimes report the inode of the child along with inode of the parent in events (e.g. FS_OPEN) when watching a parent directory.
How will this out args struct be extended if we would want to pass that information?
There is no need to address this now. I just want to know that the design you suggest is extendable to future needs and if it is not, I would prefer to reserve enough fields in the FUSE event struct for the common needs of all current fsnotify backends, just as we pass all the relevant info to the fsnotify_XXX() hooks.
Quoted 11 lines
I guess this discussion is not very productive at this point as none of us are saying anything very specific about what should and should not be done, so let me try to suggest something -
Try to see if you could replace the server side implementation with fanotify even if you use
CAP_SYS_ADMINfor the experiment. fanotify should be almost a drop-in replacement for inotify at this point If you think that you cannot make this experiment with your current protocol and vfs extensions then you must have done something wrong and tied the protocol and/or the vfs API to inotify terminology.
So I did this thought experiment myself.
I did not find any obvious issues with implementing the backend as fanotify. If anything, mapping fhandle to inode is even a bit easier than mapping wd to inode if you know the fhandle encoding.
For event reporting, besides generalizing the out args, implementation would be similar. Since FUSE uses nodeid to identify the object in events, there is no problem for fanotify to report fhandle and inotify to report wd.
For setting watches, protocol seems generic enough, although I dislike how fuse_fsnotify_update_mark() masks out inotify specific flags.
inotify back should mask out its own private flags when calling into a generic vfs API for registering remote watches. Also, masking out FS_EVENT_ON_CHILD is pretty weird, because requesting a watch on children is functionally completely different than requesting to watch the directory itself.
I think I gave you enough comments already for a new revision. Are there any open questions left unanswered?
And please grep your kernel patches for "inotify" and "remote inotify" in particular. When this term is used in comments and commit messages, it is very likely that either the code or documentation is inaccurate.
Thanks,
Amir.
Vivek Goyal
maintainerQuoted 33 lines · Amir Goldstein
Quoted 11 lines
Quoted 10 lines
I understand that part. But at the same time, remote fsnotify API will probably evolve as you keep on adding more functionality. What if there is another notification mechanism tomorrow say
newfancynotify(), we might have to modify remote fsnoitfy again to accomodate that.IOW, fsnotify seems to be just underlying plumbing and whatever you add today might not be enough to support tomorrow's features. That's why I wanted to start with a minimal set of functionality and add more to it later.
Quoted 8 lines
I do want to start with minimal functionality.
I did not request that you implement more functionality than what inotify provides.TBH, I can't even remember the specific details that made me say "this is remote inotify not remote fsnotify", but there were such details. I remember inotify rename cookie being one of them.
Let me repeat my concern about the rename cookie API.
As Jan has convinced me to create a new event
FS_RENAMEfor fanotify, there is no harm in FUSE passing the rename cookie along withFS_MOVEevents, but the FUSE out args:struct
fuse_notify_fsnotify_out{
uint64_tinode;
uint64_tmask;
uint32_tnamelen;
uint32_tcookie;
};
Quoted 4 lines
How do you expect to extend it when somebody wants to implement the
FS_RENAMEevent that carries two names and two dir inodes (and no cookie)?
Will they need to use a new out struct? a union?
I was thinking of defining a new struct say "fuse_notify_fsnotify_out_ext" when one reached to a state where fanotify can be supported. Because fanotify seems much more rich as compared to inotify and more data needs to be transferred in fuse events. Without being able to test fanotify, its little hard to design and test this struct to meet fanotify needs as well.
Quoted 7 lines
Unlike inotify, fanotify can sometimes report the inode of the child along with inode of the parent in events (e.g.
FS_OPEN) when watching a parent directory.How will this out args struct be extended if we would want to pass that information?
I was thinking of a new struct which takes care of all of fanotify needs.
Quoted 6 lines
There is no need to address this now. I just want to know that the design you suggest is extendable to future needs and if it is not, I would prefer to reserve enough fields in the FUSE event struct for the common needs of all current fsnotify backends, just as we pass all the relevant info to the
fsnotify_XXX()hooks.
So there are two ways.
- Either we now define a struct which meeds the needs of inotify only. And make remote inotify work.
- Or we try to make it generic enough so that both inotify and fanotify can be supported. Given local fanotify does not work on fuse yet, it will be hard to test it. And without testing it will be hard to ascertain, have we met all the needs of fanotify. It will be just sort of a guess.
IMHO, first choice also seems reasonable. This is small enough to make progress and take care of other pending issues like events coming after inode unlink etc.
Quoted 13 lines
Quoted 5 lines
I guess this discussion is not very productive at this point as none of us are saying anything very specific about what should and should not be done, so let me try to suggest something -
Quoted 7 lines
Try to see if you could replace the server side implementation with fanotify even if you use
CAP_SYS_ADMINfor the experiment. fanotify should be almost a drop-in replacement for inotify at this point If you think that you cannot make this experiment with your current protocol and vfs extensions then you must have done something wrong and tied the protocol and/or the vfs API to inotify terminology.
Quoted 4 lines
So I did this thought experiment myself.
I did not find any obvious issues with implementing the backend as fanotify. If anything, mapping fhandle to inode is even a bit easier than mapping wd to inode if you know the fhandle encoding.
Fair enough. I think Ioannis is trying to replace inotify backend with fanotify backend. If we run into issues with this, we will let you know.
Quoted 5 lines
For event reporting, besides generalizing the out args, implementation would be similar. Since FUSE uses nodeid to identify the object in events, there is no problem for fanotify to report fhandle and inotify to report wd.
I think hardes part is generalizing out_args. One thing I am not sure about is, will we be carrying file handles in this struct? I thought that we will be sending nodeid to refer to inodes because that seems to be the fuse interface. And if fanotify requires file handles, they will use fuse interface to convert nodeid/generation into a file handle and report to user space. Is that a reasonable thing to do.
So how much information we need to carry which covers all the existing events. So for the case of rename, looks
For the case of rename, it sounds like we will need to report "node ids" of two directories and two names. Once we have space to report two "node ids", this could also be used to report node ids of parent dir as well as node id of file in question (if needed). So will this be good enough.
Carrying names will be little tricky I guess because namelen will be variable. Until and unless we reserve some fixed amount of space for each name say PATH_MAX. But that sounds like a lot of space.
Quoted 10 lines
For setting watches, protocol seems generic enough, although I dislike how
fuse_fsnotify_update_mark()masks out inotify specific flags.inotify back should mask out its own private flags when calling into a generic vfs API for registering remote watches. Also, masking out
FS_EVENT_ON_CHILDis pretty weird, because requesting a watch on children is functionally completely different than requesting to watch the directory itself.
I will look into above two points. I need to familiarize myself with the code better before I can understand the issue.
Quoted 3 lines
I think I gave you enough comments already for a new revision. Are there any open questions left unanswered?
Thank you. After initial round of review, one of our biggest take away was that try to make basic fanotify work in V2 of the posting and Ioannis started looking into it and ran into various issues.
And that's why we opened this conversation again mentioning the issues we are facing with fanotify and trying to figure out if supporting fanotify is a basic requirement for this implementation. We personally are happy to even support remote inotify only in first round of implementation.
So looks like supporting fanotify is not a strict requirement. Though you will perfer that fuse notification message is generic enough so that it carries enough information to support fanotify. We can try that, but I am not 100% sure. Maybe two node ids and two names are generic enough to support fanotify rename and other cases were two file handles can be reported.
Quoted 4 lines
And please grep your kernel patches for "inotify" and "remote inotify" in particular. When this term is used in comments and commit messages, it is very likely that either the code or documentation is inaccurate.
IIUC, you want all the comments to call it "remote fsnotify" and not "remote inotify", right? Will do.
Thanks
Vivek
Amir Goldstein
reviewerQuoted 64 lines · Vivek Goyal
Quoted 33 lines · Amir Goldstein
Quoted 11 lines
Quoted 10 lines
I understand that part. But at the same time, remote fsnotify API will probably evolve as you keep on adding more functionality. What if there is another notification mechanism tomorrow say
newfancynotify(), we might have to modify remote fsnoitfy again to accomodate that.IOW, fsnotify seems to be just underlying plumbing and whatever you add today might not be enough to support tomorrow's features. That's why I wanted to start with a minimal set of functionality and add more to it later.
Quoted 8 lines
I do want to start with minimal functionality.
I did not request that you implement more functionality than what inotify provides.TBH, I can't even remember the specific details that made me say "this is remote inotify not remote fsnotify", but there were such details. I remember inotify rename cookie being one of them.
Let me repeat my concern about the rename cookie API.
As Jan has convinced me to create a new event
FS_RENAMEfor fanotify, there is no harm in FUSE passing the rename cookie along withFS_MOVEevents, but the FUSE out args:struct
fuse_notify_fsnotify_out{
uint64_tinode;
uint64_tmask;
uint32_tnamelen;
uint32_tcookie;
};Quoted 4 lines
How do you expect to extend it when somebody wants to implement the
FS_RENAMEevent that carries two names and two dir inodes (and no cookie)?
Will they need to use a new out struct? a union?I was thinking of defining a new struct say "
fuse_notify_fsnotify_out_ext" when one reached to a state where fanotify can be supported. Because fanotify seems much more rich as compared to inotify and more data needs to be transferred in fuse events. Without being able to test fanotify, its little hard to design and test this struct to meet fanotify needs as well.Quoted 7 lines
Unlike inotify, fanotify can sometimes report the inode of the child along with inode of the parent in events (e.g.
FS_OPEN) when watching a parent directory.How will this out args struct be extended if we would want to pass that information?
I was thinking of a new struct which takes care of all of fanotify needs.
Quoted 6 lines
There is no need to address this now. I just want to know that the design you suggest is extendable to future needs and if it is not, I would prefer to reserve enough fields in the FUSE event struct for the common needs of all current fsnotify backends, just as we pass all the relevant info to the
fsnotify_XXX()hooks.
Quoted 7 lines
So there are two ways.
- Either we now define a struct which meeds the needs of inotify only. And make remote inotify work.
- Or we try to make it generic enough so that both inotify and fanotify can be supported. Given local fanotify does not work on fuse yet,
It's a one liner patch to make it work on fuse.
Just need to set f_fsid. that's all.
So testing is not really a problem.
Mind you the event FS_RENAME I mentioned has only now
queued for-next, so you can leave it out of scope for testing. I can still discuss the extendability of the design w.r.t that event...
Quoted 4 lines
it will be hard to test it. And without testing it will be hard to ascertain, have we met all the needs of fanotify. It will be just sort of a guess.
I think the info I listed above is all there is to it and it is not that much, so I think it is not a good choice to extend the struct later.
Quoted 17 lines
IMHO, first choice also seems reasonable. This is small enough to make progress and take care of other pending issues like events coming after inode unlink etc.
Quoted 13 lines
Quoted 12 lines
I guess this discussion is not very productive at this point as none of us are saying anything very specific about what should and should not be done, so let me try to suggest something -
Try to see if you could replace the server side implementation with fanotify even if you use
CAP_SYS_ADMINfor the experiment. fanotify should be almost a drop-in replacement for inotify at this point If you think that you cannot make this experiment with your current protocol and vfs extensions then you must have done something wrong and tied the protocol and/or the vfs API to inotify terminology.
Quoted 9 lines
Quoted 4 lines
So I did this thought experiment myself.
I did not find any obvious issues with implementing the backend as fanotify. If anything, mapping fhandle to inode is even a bit easier than mapping wd to inode if you know the fhandle encoding.Fair enough. I think Ioannis is trying to replace inotify backend with fanotify backend. If we run into issues with this, we will let you know.
You will have a problem placing a value in the rename cookie because fanotify does not provide one.
Quoted 8 lines
Quoted 5 lines
For event reporting, besides generalizing the out args, implementation would be similar. Since FUSE uses nodeid to identify the object in events, there is no problem for fanotify to report fhandle and inotify to report wd.
I think hardes part is generalizing
out_args. One thing I am not sure about is, will we be carrying file handles in this struct? I thought
No.
Quoted 4 lines
that we will be sending nodeid to refer to inodes because that seems to be the fuse interface. And if fanotify requires file handles, they will use fuse interface to convert nodeid/generation into a file handle and report to user space. Is that a reasonable thing to do.
It is the right thing to do.
Quoted 10 lines
So how much information we need to carry which covers all the existing events. So for the case of rename, looks
For the case of rename, it sounds like we will need to report "node ids" of two directories and two names. Once we have space to report two "node ids", this could also be used to report node ids of parent dir as well as node id of file in question (if needed). So will this be good enough.
Quoted 4 lines
Carrying names will be little tricky I guess because namelen will be variable. Until and unless we reserve some fixed amount of space for each name say
PATH_MAX. But that sounds like a lot of space.
I thought you passed the name as buffer in iov array. Or maybe that's not how it works?
My suggestion:
1. Reserve a zero padded 64bit member for future child nodeid in struct fuse_notify_fsnotify_out
2. For FS_RENAME, will we be able to pass 4 buffers in iov? src_fuse_notify_fsnotify_out, src_name, dst_fuse_notify_fsnotify_out, dst_name
Quoted 36 lines
Quoted 10 lines
For setting watches, protocol seems generic enough, although I dislike how
fuse_fsnotify_update_mark()masks out inotify specific flags.inotify back should mask out its own private flags when calling into a generic vfs API for registering remote watches. Also, masking out
FS_EVENT_ON_CHILDis pretty weird, because requesting a watch on children is functionally completely different than requesting to watch the directory itself.I will look into above two points. I need to familiarize myself with the code better before I can understand the issue.
Quoted 3 lines
I think I gave you enough comments already for a new revision. Are there any open questions left unanswered?
Thank you. After initial round of review, one of our biggest take away was that try to make basic fanotify work in V2 of the posting and Ioannis started looking into it and ran into various issues.
And that's why we opened this conversation again mentioning the issues we are facing with fanotify and trying to figure out if supporting fanotify is a basic requirement for this implementation. We personally are happy to even support remote inotify only in first round of implementation.
So looks like supporting fanotify is not a strict requirement. Though you will perfer that fuse notification message is generic enough so that it carries enough information to support fanotify. We can try that, but I am not 100% sure. Maybe two node ids and two names are generic enough to support fanotify rename and other cases were two file handles can be reported.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
And please grep your kernel patches for "inotify" and "remote inotify" in particular. When this term is used in comments and commit messages, it is very likely that either the code or documentation is inaccurate.
IIUC, you want all the comments to call it "remote fsnotify" and not "remote inotify", right? Will do.
Yes and for the code to match that description ;)
Thanks,
Amir.
Vivek Goyal
maintainerOn Thu, Dec 16, 2021 at 08:22:19PM +0200, Amir Goldstein wrote:
[..]
Quoted 9 lines
Quoted 9 lines
So how much information we need to carry which covers all the existing events. So for the case of rename, looks
For the case of rename, it sounds like we will need to report "node ids" of two directories and two names. Once we have space to report two "node ids", this could also be used to report node ids of parent dir as well as node id of file in question (if needed). So will this be good enough.
Quoted 4 lines
Quoted 4 lines
Carrying names will be little tricky I guess because namelen will be variable. Until and unless we reserve some fixed amount of space for each name say
PATH_MAX. But that sounds like a lot of space.
Ok, lets spend some time on figuring out how the fsnotify_out struct should look like to meet the needs of fanotify as well.
Quoted 7 lines
I thought you passed the name as buffer in iov array. Or maybe that's not how it works?
My suggestion:
1. Reserve a zero padded 64bit member for future child nodeid in structfuse_notify_fsnotify_out
Ok, I think this doable. So right now it can send only one nodeid. You basically want to have capability to send two 64bit nodeids in same event, right. This is useful where you might want to send nodeid of dir and nodeid of child object, IIUC.
Maybe we should add a 64bit field for some sort of flags also which might give additional informatin about the event.
It might look like.
struct fuse_notify_fsnotify_out {
uint64_t inode;
uint64_t mask;
uint32_t namelen;
uint32_t cookie;
/* Can carry additional info about the event */
uint64_t flags;
/* Reserved for future use. Possibly another inode node id */
uint64_t reserved;
};Quoted 3 lines
2. For
FS_RENAME, will we be able to pass 4 buffers in iov?src_fuse_notify_fsnotify_out,src_name,dst_fuse_notify_fsnotify_out,dst_name
So it is sort of two fsnotify events travelling in same event. We will have to have some sort of information in the src_fuse_notify_fsnotify_out which signals that another fsnotify_out is following. May be that's where fsnotify_flags->field can be used. Set a bit to signal another fsnotify_out is part of same event and this will also mean first one is src and second one is dst.
Challenge I see is "src_name" and "dst_name", especially in the context of virtio queues.
So we have a notification queue and for each notification, driver allocates a fixed amount of memory for each element and queues these elements in virtqueue. Server side pops these elements, places notification info in this vq element and sends back.
So basically size of notification buffer needs to be known in advance, because these are allocated by driver (and not device/server). And that's the reason virtio spec has added a new filed "notify_buf_size" in device configuration space. Using this field device lets the driver know how much memory to allocate for each notification element.
IOW, we can put variable sized elements in notifiation but max size of that variable length needs to be fixed in advance and needs to be told to driver at device initialization time.
So what can be the max length of "src_name" and "dst_name"? Is it fair to use NAME_MAX to determine max length of name. So say "255" bytes (not including null) for each name. That means notify_buf_size will be.
notify_buf_size = 2 * 255 + 2 * sizeof(struct fuse_notify_fsnotify_out);
I am currently creating 16 notification elements (VQ_NOTIFY_ELEMS) in driver and pushing on notification queue. This number is arbitrary and in future might have to be raised so that more events can travel on notification queue in parallel.
Memory usage looks little high per notification due to name but not too bad I guess.
Thanks
Vivek
Amir Goldstein
reviewerQuoted 7 lines
Ok, lets spend some time on figuring out how the
fsnotify_outstruct should look like to meet the needs of fanotify as well.Quoted 4 lines
I thought you passed the name as buffer in iov array. Or maybe that's not how it works?
Quoted 8 lines
Quoted 3 lines
My suggestion:
1. Reserve a zero padded 64bit member for future child nodeid in structfuse_notify_fsnotify_outOk, I think this doable. So right now it can send only one nodeid. You basically want to have capability to send two 64bit nodeids in same event, right. This is useful where you might want to send nodeid of dir and nodeid of child object, IIUC.
Correct, but I forgot to mention (I mentioned it earlier in review) that the protocol should send nodeid+generation
this is not related to file handles.
It is needed to avoid reporting an event on the wrong object when FUSE reuses nodeid.
Quoted 9 lines
Maybe we should add a 64bit field for some sort of flags also which might give additional informatin about the event.
It might look like.
struct fuse_notify_fsnotify_out { uint64_t inode; uint64_t mask;
So you may want to cram 32bit gen above and make mask 32bit depending on how much you really need to save space in the event queue.
Quoted 6 lines
uint32_t namelen;
uint32_t cookie;
/* Can carry additional info about the event */
uint64_t flags;
/* Reserved for future use. Possibly another inode node id */
uint64_t reserved;Same here, we will need ino+gen for child
Quoted 31 lines
};
Quoted 3 lines
2. For
FS_RENAME, will we be able to pass 4 buffers in iov?src_fuse_notify_fsnotify_out,src_name,dst_fuse_notify_fsnotify_out,dst_nameSo it is sort of two fsnotify events travelling in same event. We will have to have some sort of information in the
src_fuse_notify_fsnotify_outwhich signals that anotherfsnotify_outis following. May be that's wherefsnotify_flags->fieldcan be used. Set a bit to signal anotherfsnotify_outis part of same event and this will also mean first one is src and second one is dst.Challenge I see is "
src_name" and "dst_name", especially in the context of virtio queues.So we have a notification queue and for each notification, driver allocates a fixed amount of memory for each element and queues these elements in virtqueue. Server side pops these elements, places notification info in this vq element and sends back.
So basically size of notification buffer needs to be known in advance, because these are allocated by driver (and not device/server). And that's the reason virtio spec has added a new filed "
notify_buf_size" in device configuration space. Using this field device lets the driver know how much memory to allocate for each notification element.IOW, we can put variable sized elements in notifiation but max size of that variable length needs to be fixed in advance and needs to be told to driver at device initialization time.
Quoted 7 lines
So what can be the max length of "
src_name" and "dst_name"? Is it fair to useNAME_MAXto determine max length of name. So say "255" bytes (not including null) for each name. That meansnotify_buf_sizewill be.
notify_buf_size= 2 * 255 + 2 *sizeof(struct fuse_notify_fsnotify_out);
Can you push two subsequent elements to the events queue atomically? If you can, then it is not a problem to queue the FS_MOVED_FROM event (with one name) followed by FS_MOVED_TO event with a self generated cookie in response to FAN_RENAME event on virtiofsd server and rejoin them in virtiofs client.
You see, I don't mind using the rename cookie API as long as rejoining the disjoint events is possible for reporting the joint event to fanotify user.
In case virtiofsd backend is implemented with inotify, it will receive and report only disjoint events and in that case, FAN_RENAME cannot be requested by fanotify user which is fine, as long as it will be possible with another implementation of virtiofsd server down the road.
Thanks,
Amir.
Vivek Goyal
maintainerQuoted 16 lines · Amir Goldstein
Quoted 7 lines
Ok, lets spend some time on figuring out how the
fsnotify_outstruct should look like to meet the needs of fanotify as well.Quoted 4 lines
I thought you passed the name as buffer in iov array. Or maybe that's not how it works?
Quoted 8 lines
Quoted 3 lines
My suggestion:
1. Reserve a zero padded 64bit member for future child nodeid in structfuse_notify_fsnotify_outOk, I think this doable. So right now it can send only one nodeid. You basically want to have capability to send two 64bit nodeids in same event, right. This is useful where you might want to send nodeid of dir and nodeid of child object, IIUC.
Quoted 5 lines
Correct, but I forgot to mention (I mentioned it earlier in review) that the protocol should send nodeid+generation
this is not related to file handles.
It is needed to avoid reporting an event on the wrong object when FUSE reuses nodeid.
Makes sense. Will add generation id as well for each nodeid.
Quoted 5 lines
Quoted 5 lines
Maybe we should add a 64bit field for some sort of flags also which might give additional informatin about the event.
Quoted 8 lines
Quoted 5 lines
It might look like.
struct fuse_notify_fsnotify_out { uint64_t inode; uint64_t mask;So you may want to cram 32bit gen above and make mask 32bit depending on how much you really need to save space in the event queue.
May be. Not sure if mask needs to be 64bit or not.
Alternatively, use 32bit generation and reserve 32bit for future use.
uint32_t generation;uint32_t reserved;uint64_t mask
I think our biggest memory usage will come from "name" and rest seems very small in comparison. So I am not too worried about saving little bit of space here.
Quoted 9 lines
Quoted 7 lines
uint32_t namelen; uint32_t cookie; /* Can carry additional info about the event */ uint64_t flags; /* Reserved for future use. Possibly another inode node id */ uint64_t reserved;Same here, we will need ino+gen for child
Right. May be I can reduce the flag to 32 bit instead and use rest 32bit for generation.
uint32_t flagsuint32_t reserved (for genearation possibly)uint64_t reserved (for another inode id).
So this might look as follows.
struct fuse_notify_fsnotify_out {
uint64_t inode;
uint32_t generation;
uint32_t reserved;
uint64_t mask;
uint32_t namelen;
uint32_t cookie;
/* Can carry additional info about the event */
uint32_t flags;
/* Reserved for future use. Another inode node id and generation */
uint32_t reserved;
uint64_t reserved;
};Quoted 37 lines
Quoted 37 lines
};
Quoted 3 lines
2. For
FS_RENAME, will we be able to pass 4 buffers in iov?src_fuse_notify_fsnotify_out,src_name,dst_fuse_notify_fsnotify_out,dst_nameSo it is sort of two fsnotify events travelling in same event. We will have to have some sort of information in the
src_fuse_notify_fsnotify_outwhich signals that anotherfsnotify_outis following. May be that's wherefsnotify_flags->fieldcan be used. Set a bit to signal anotherfsnotify_outis part of same event and this will also mean first one is src and second one is dst.Challenge I see is "
src_name" and "dst_name", especially in the context of virtio queues.So we have a notification queue and for each notification, driver allocates a fixed amount of memory for each element and queues these elements in virtqueue. Server side pops these elements, places notification info in this vq element and sends back.
So basically size of notification buffer needs to be known in advance, because these are allocated by driver (and not device/server). And that's the reason virtio spec has added a new filed "
notify_buf_size" in device configuration space. Using this field device lets the driver know how much memory to allocate for each notification element.IOW, we can put variable sized elements in notifiation but max size of that variable length needs to be fixed in advance and needs to be told to driver at device initialization time.
So what can be the max length of "
src_name" and "dst_name"? Is it fair to useNAME_MAXto determine max length of name. So say "255" bytes (not including null) for each name. That meansnotify_buf_sizewill be.
Quoted 8 lines
Quoted 2 lines
notify_buf_size= 2 * 255 + 2 *sizeof(struct fuse_notify_fsnotify_out);Can you push two subsequent elements to the events queue atomically? If you can, then it is not a problem to queue the
FS_MOVED_FROMevent (with one name) followed byFS_MOVED_TOevent with a self generated cookie in response toFAN_RENAMEevent on virtiofsd server and rejoin them in virtiofs client.
Hmm..., so basically break down FAN_RENAME event into two events joined by cookie and send them separately. I guess sounds reasonable because it helps reduce the max size of event.
What do you mean by "atomically"? Do you mean strict ordering and these two events are right after each other. But if they are joined by cookie, we don't have to enforce it. Driver should be able to maintain an internal list and queue the event and wait for pair event to arrive. This also means that these broken down events will have to be joined back, possibly by some fsnotify helper.
We will probably need a flag to differentiate whether its the case of broken down FAN_RENAME or not. Because in this case driver will wait for second event to arrive. But if it is regular FS_MOVED_FROM event, then don't wait and deliver it to user space.
Driver will have to be careful to not block actual event queue event while waiting for pair event to arrive. It should create a copy and add virtqueue element back to notification queue. Otherwise deadlock is possible where all elements in virtqueue are being used to wait for pair event and no free elements are available to actually send paired event.
Quoted 3 lines
You see, I don't mind using the rename cookie API as long as rejoining the disjoint events is possible for reporting the joint event to fanotify user.
Right this will allow server to join independent FAN_MOVED_FROM and FAN_MOVED_TO if need be.
Quoted 5 lines
In case virtiofsd backend is implemented with inotify, it will receive and report only disjoint events and in that case,
FAN_RENAMEcannot be requested by fanotify user which is fine, as long as it will be possible with another implementation of virtiofsd server down the road.
Fair enough. In simplest form, virtiofsd will support FAN_RENAME only if host kernel fanotify supports FAN_RENAME.
In more advanced form, virtiofsd (or other server) can wait for two events and then join and report as FAN_RENAME with user space generated cookie.
I think I like this idea of reporting two events joined by cookie to reduce the size of event. Will give it a try.
Thanks
Vivek
Amir Goldstein
reviewerQuoted 44 lines
Quoted 35 lines
Quoted 35 lines
Quoted 4 lines
2. For
FS_RENAME, will we be able to pass 4 buffers in iov?src_fuse_notify_fsnotify_out,src_name,dst_fuse_notify_fsnotify_out,dst_nameSo it is sort of two fsnotify events travelling in same event. We will have to have some sort of information in the
src_fuse_notify_fsnotify_outwhich signals that anotherfsnotify_outis following. May be that's wherefsnotify_flags->fieldcan be used. Set a bit to signal anotherfsnotify_outis part of same event and this will also mean first one is src and second one is dst.Challenge I see is "
src_name" and "dst_name", especially in the context of virtio queues.So we have a notification queue and for each notification, driver allocates a fixed amount of memory for each element and queues these elements in virtqueue. Server side pops these elements, places notification info in this vq element and sends back.
So basically size of notification buffer needs to be known in advance, because these are allocated by driver (and not device/server). And that's the reason virtio spec has added a new filed "
notify_buf_size" in device configuration space. Using this field device lets the driver know how much memory to allocate for each notification element.IOW, we can put variable sized elements in notifiation but max size of that variable length needs to be fixed in advance and needs to be told to driver at device initialization time.
So what can be the max length of "
src_name" and "dst_name"? Is it fair to useNAME_MAXto determine max length of name. So say "255" bytes (not including null) for each name. That meansnotify_buf_sizewill be.Quoted 8 lines
Quoted 2 lines
notify_buf_size= 2 * 255 + 2 *sizeof(struct fuse_notify_fsnotify_out);Can you push two subsequent elements to the events queue atomically? If you can, then it is not a problem to queue the
FS_MOVED_FROMevent (with one name) followed byFS_MOVED_TOevent with a self generated cookie in response toFAN_RENAMEevent on virtiofsd server and rejoin them in virtiofs client.
Quoted 8 lines
Hmm..., so basically break down
FAN_RENAMEevent into two events joined by cookie and send them separately. I guess sounds reasonable because it helps reduce the max size of event.What do you mean by "atomically"? Do you mean strict ordering and these two events are right after each other. But if they are joined by cookie, we don't have to enforce it. Driver should be able to maintain an internal list and queue the event and wait for pair event to arrive. This also
This is what I would consider repeating mistakes of past APIs (i.e. inotify). Why should the driver work hard to join events that were already joint before the queue? Is there really a technical challenge in queueing the two events together?
Quoted 3 lines
means that these broken down events will have to be joined back, possibly by some fsnotify helper.
Currently, for local events, fsnotify() gets from vfs old dir inode and old name and the moved dentry, from which fanotify extracts all other information. Same for events on child (e.g. FS_OPEN).
Getting that moved (or opened) fuse dentry may be a challenge. Driver can look for a dentry with the parent dir and child inode and name, but there may not be such an entry in dcache or no such entry at all, by the time the event is read by the driver.
I guess in that case, we could allow passing a disconnected dentry and teach fanotify how to deal with it and not report the NEW_DFID record or the child FID record, so I think it's doable.
Quoted 5 lines
We will probably need a flag to differentiate whether its the case of broken down
FAN_RENAMEor not. Because in this case driver will wait for second event to arrive. But if it is regularFS_MOVED_FROMevent, then don't wait and deliver it to user space.
Yes, a "multi part event" flag.
Quoted 7 lines
Driver will have to be careful to not block actual event queue event while waiting for pair event to arrive. It should create a copy and add virtqueue element back to notification queue. Otherwise deadlock is possible where all elements in virtqueue are being used to wait for pair event and no free elements are available to actually send paired event.
See, this is the unneeded complexity I am talking about. Letting the server wait until there are swo slots available in the queue and always queue the two parts together seems a lot easier, unless I am missing something?
Quoted 7 lines
Quoted 3 lines
You see, I don't mind using the rename cookie API as long as rejoining the disjoint events is possible for reporting the joint event to fanotify user.
Right this will allow server to join independent
FAN_MOVED_FROMandFAN_MOVED_TOif need be.
Yes, if the server wants, it can work harder to join independent inotify events, but it is not a must.
Quoted 8 lines
Quoted 5 lines
In case virtiofsd backend is implemented with inotify, it will receive and report only disjoint events and in that case,
FAN_RENAMEcannot be requested by fanotify user which is fine, as long as it will be possible with another implementation of virtiofsd server down the road.Fair enough. In simplest form, virtiofsd will support
FAN_RENAMEonly if host kernel fanotify supportsFAN_RENAME.
Correct.
Or as I wrote before, a multi-client server can also report FS_RENAME after executing a rename request from another client.
You need to think of the remote fsnotify service in a manner that is completely detached from the backend facility used to provide the notifications.
Quoted 5 lines
In more advanced form, virtiofsd (or other server) can wait for two events and then join and report as
FAN_RENAMEwith user space generated cookie.
Yeh, that's possible.
Quoted 3 lines
I think I like this idea of reporting two events joined by cookie to reduce the size of event. Will give it a try.
I am glad we seem to be converging :)
Thanks,
Amir.
Vivek Goyal
maintainerQuoted 53 lines · Amir Goldstein
Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
Quoted 4 lines
2. For
FS_RENAME, will we be able to pass 4 buffers in iov?src_fuse_notify_fsnotify_out,src_name,dst_fuse_notify_fsnotify_out,dst_nameSo it is sort of two fsnotify events travelling in same event. We will have to have some sort of information in the
src_fuse_notify_fsnotify_outwhich signals that anotherfsnotify_outis following. May be that's wherefsnotify_flags->fieldcan be used. Set a bit to signal anotherfsnotify_outis part of same event and this will also mean first one is src and second one is dst.Challenge I see is "
src_name" and "dst_name", especially in the context of virtio queues.So we have a notification queue and for each notification, driver allocates a fixed amount of memory for each element and queues these elements in virtqueue. Server side pops these elements, places notification info in this vq element and sends back.
So basically size of notification buffer needs to be known in advance, because these are allocated by driver (and not device/server). And that's the reason virtio spec has added a new filed "
notify_buf_size" in device configuration space. Using this field device lets the driver know how much memory to allocate for each notification element.IOW, we can put variable sized elements in notifiation but max size of that variable length needs to be fixed in advance and needs to be told to driver at device initialization time.
So what can be the max length of "
src_name" and "dst_name"? Is it fair to useNAME_MAXto determine max length of name. So say "255" bytes (not including null) for each name. That meansnotify_buf_sizewill be.Quoted 8 lines
Quoted 2 lines
notify_buf_size= 2 * 255 + 2 *sizeof(struct fuse_notify_fsnotify_out);Can you push two subsequent elements to the events queue atomically? If you can, then it is not a problem to queue the
FS_MOVED_FROMevent (with one name) followed byFS_MOVED_TOevent with a self generated cookie in response toFAN_RENAMEevent on virtiofsd server and rejoin them in virtiofs client.Quoted 8 lines
Hmm..., so basically break down
FAN_RENAMEevent into two events joined by cookie and send them separately. I guess sounds reasonable because it helps reduce the max size of event.What do you mean by "atomically"? Do you mean strict ordering and these two events are right after each other. But if they are joined by cookie, we don't have to enforce it. Driver should be able to maintain an internal list and queue the event and wait for pair event to arrive. This also
Quoted 4 lines
This is what I would consider repeating mistakes of past APIs (i.e. inotify). Why should the driver work hard to join events that were already joint before the queue? Is there really a technical challenge in queueing the two events together?
We can try queuing these together but it might not be that easy. If two elements are not available at the time of the queuing, then you will to let go the lock, put that element back in the queue and retry later.
To me, it is much simpler and more flexible to not guarantee strict ordering and let the events be joined by cookie. BTW, we are using cookie anyway. So strict ordering should not be required.
All I am saying is that implementation can still choose to send two events together one after the other, but this probably should not be a requirement on the part of the protocol.
So what's the concern with joining the event with cookie API? I am not aware what went wrong in the past.
One thing simpler with atomic event is that if second event does not come right away, we can probably discard first event saying some error happened. But if we join them by cookie and second event does not come, its not clear how do to error handling and how long guest driver should wait for second event to arrive.
With the notion of enforcing atomicity, I am concerned about some deadlock/starvation possibility where you can't get two elements together at all. For example, some guest driver decides to instantiate queue only with 1 element.
So is it doable, it most likely is. Still, I am not sure we should try to enforce atomicity. Apart from error handling, I am unable to seek what other issues exist with non-atomic joined events. Maybe you can help me understand better why requiring atomicity is a better option.
Quoted 34 lines
Quoted 4 lines
means that these broken down events will have to be joined back, possibly by some fsnotify helper.
Currently, for local events,
fsnotify()gets from vfs old dir inode and old name and the moved dentry, from which fanotify extracts all other information. Same for events on child (e.g.FS_OPEN).Getting that moved (or opened) fuse dentry may be a challenge. Driver can look for a dentry with the parent dir and child inode and name, but there may not be such an entry in dcache or no such entry at all, by the time the event is read by the driver.
I guess in that case, we could allow passing a disconnected dentry and teach fanotify how to deal with it and not report the
NEW_DFIDrecord or the child FID record, so I think it's doable.Quoted 5 lines
We will probably need a flag to differentiate whether its the case of broken down
FAN_RENAMEor not. Because in this case driver will wait for second event to arrive. But if it is regularFS_MOVED_FROMevent, then don't wait and deliver it to user space.Yes, a "multi part event" flag.
Quoted 7 lines
Driver will have to be careful to not block actual event queue event while waiting for pair event to arrive. It should create a copy and add virtqueue element back to notification queue. Otherwise deadlock is possible where all elements in virtqueue are being used to wait for pair event and no free elements are available to actually send paired event.
Quoted 4 lines
See, this is the unneeded complexity I am talking about. Letting the server wait until there are swo slots available in the queue and always queue the two parts together seems a lot easier, unless I am missing something?
This reminds me that in remote posix lock patches (not merged yet), I had to deal with similar complexity. It was possible that lock notification arrives before request reply came. So in that case, I was queuing notification in an internal list and pair it later with a request reponse. Difference was that I was not creating a copy and instead holding that virtqueue element back.
I am not sure whether waiting for two consecutive elements is more complex or waiting in driver for second event is more complex. Anyway, I am not particular about it. Anything is fine as long as it does not add too much of complexity.
Quoted 18 lines
Quoted 8 lines
Quoted 4 lines
You see, I don't mind using the rename cookie API as long as rejoining the disjoint events is possible for reporting the joint event to fanotify user.
Right this will allow server to join independent
FAN_MOVED_FROMandFAN_MOVED_TOif need be.Yes, if the server wants, it can work harder to join independent inotify events, but it is not a must.
Quoted 6 lines
Quoted 5 lines
In case virtiofsd backend is implemented with inotify, it will receive and report only disjoint events and in that case,
FAN_RENAMEcannot be requested by fanotify user which is fine, as long as it will be possible with another implementation of virtiofsd server down the road.
Quoted 8 lines
Quoted 2 lines
Fair enough. In simplest form, virtiofsd will support
FAN_RENAMEonly if host kernel fanotify supportsFAN_RENAME.Correct.
Or as I wrote before, a multi-client server can also reportFS_RENAMEafter executing a rename request from another client.
You need to think of the remote fsnotify service in a manner that is completely detached from the backend facility used to provide the notifications.
Fair enough. One can imagine a single daemon servicing multiple clients and in that case it can report FS_RENAME event without relying on kernel notifications.
Quoted 7 lines
Quoted 6 lines
In more advanced form, virtiofsd (or other server) can wait for two events and then join and report as
FAN_RENAMEwith user space generated cookie.
Quoted 7 lines
Yeh, that's possible.
Quoted 3 lines
I think I like this idea of reporting two events joined by cookie to reduce the size of event. Will give it a try.
I am glad we seem to be converging :)
Me too. I think there are many low level issues to be figured out. Once we implement it these will surface and we will ping you back. But for now atleast we agree on fsnotify_out so that it can support both inotify/fanotify and that's good. Time to look into making those changes.
Vivek
Amir Goldstein
reviewerQuoted 86 lines · Vivek Goyal
Quoted 53 lines · Amir Goldstein
Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
Quoted 4 lines
2. For
FS_RENAME, will we be able to pass 4 buffers in iov?src_fuse_notify_fsnotify_out,src_name,dst_fuse_notify_fsnotify_out,dst_nameSo it is sort of two fsnotify events travelling in same event. We will have to have some sort of information in the
src_fuse_notify_fsnotify_outwhich signals that anotherfsnotify_outis following. May be that's wherefsnotify_flags->fieldcan be used. Set a bit to signal anotherfsnotify_outis part of same event and this will also mean first one is src and second one is dst.Challenge I see is "
src_name" and "dst_name", especially in the context of virtio queues.So we have a notification queue and for each notification, driver allocates a fixed amount of memory for each element and queues these elements in virtqueue. Server side pops these elements, places notification info in this vq element and sends back.
So basically size of notification buffer needs to be known in advance, because these are allocated by driver (and not device/server). And that's the reason virtio spec has added a new filed "
notify_buf_size" in device configuration space. Using this field device lets the driver know how much memory to allocate for each notification element.IOW, we can put variable sized elements in notifiation but max size of that variable length needs to be fixed in advance and needs to be told to driver at device initialization time.
So what can be the max length of "
src_name" and "dst_name"? Is it fair to useNAME_MAXto determine max length of name. So say "255" bytes (not including null) for each name. That meansnotify_buf_sizewill be.Quoted 8 lines
Quoted 2 lines
notify_buf_size= 2 * 255 + 2 *sizeof(struct fuse_notify_fsnotify_out);Can you push two subsequent elements to the events queue atomically? If you can, then it is not a problem to queue the
FS_MOVED_FROMevent (with one name) followed byFS_MOVED_TOevent with a self generated cookie in response toFAN_RENAMEevent on virtiofsd server and rejoin them in virtiofs client.Quoted 8 lines
Hmm..., so basically break down
FAN_RENAMEevent into two events joined by cookie and send them separately. I guess sounds reasonable because it helps reduce the max size of event.What do you mean by "atomically"? Do you mean strict ordering and these two events are right after each other. But if they are joined by cookie, we don't have to enforce it. Driver should be able to maintain an internal list and queue the event and wait for pair event to arrive. This also
Quoted 4 lines
This is what I would consider repeating mistakes of past APIs (i.e. inotify). Why should the driver work hard to join events that were already joint before the queue? Is there really a technical challenge in queueing the two events together?
We can try queuing these together but it might not be that easy. If two elements are not available at the time of the queuing, then you will to let go the lock, put that element back in the queue and retry later.
To me, it is much simpler and more flexible to not guarantee strict ordering and let the events be joined by cookie. BTW, we are using cookie anyway. So strict ordering should not be required.
All I am saying is that implementation can still choose to send two events together one after the other, but this probably should not be a requirement on the part of the protocol.
So what's the concern with joining the event with cookie API? I am not aware what went wrong in the past.
One thing simpler with atomic event is that if second event does not come right away, we can probably discard first event saying some error happened. But if we join them by cookie and second event does not come, its not clear how do to error handling and how long guest driver should wait for second event to arrive.
With the notion of enforcing atomicity, I am concerned about some deadlock/starvation possibility where you can't get two elements together at all. For example, some guest driver decides to instantiate queue only with 1 element.
Quoted 5 lines
So is it doable, it most likely is. Still, I am not sure we should try to enforce atomicity. Apart from error handling, I am unable to seek what other issues exist with non-atomic joined events. Maybe you can help me understand better why requiring atomicity is a better option.
As UAPI the cookie interface is non reliable and users don't know how long they would need to wait for the other part and how many rename states to maintain and generally, most applications got it wrong and assumed to many things about ordering and such.
As an internal virtio protocol you can do whatever ends up being more easy for you as long as you are able to call the vfs fsnotify() API with both src and dst dirs.
My feeling is that it is easier to queue two elements together. I think it is possible to prevent starvation, by some reservation. For example, if you allocate N+1 slots, but treat the queue as "full" when there are N elements in the queue -
only a 2-elements push can dip into the +1 reservation if the queue is not "full".
You can try this way or the other and choose for yourself.
Thanks,
Amir.
Quoted 9 lines · Vivek Goyal
Quoted 7 lines · Amir Goldstein
Quoted 5 lines · Ioannis Angelakopoulos
Quoted 1 line · Stef Bon
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Hi Ioannis,
I see that you have been working on making fsnotify work on virtiofs. Earlier you contacted me since I've written this:
We had a few customer requests recently to fix inotify for network fs which reminded me of Miklos's earlier patch to fix the VFS layer, but if changes to extend inotify in userspace were also done it would be important to tie them in with network/cluster filesystems that expose
change notification over their network API. Most or all major SMB
servers support change notification today so it is extremely common
over SMB3.1.1 (and earlier dialects as well). If you have userspace
inotify libraries while we wait for changes to the VFS layer to enable remote change notification - in the interim you can use an existing fsspecific ioctl for some filesystems like cifs.ko. See
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/fs/cifs/ioctl.c?id=d26c2ddd33569667e3eeb577c4c1d966ca9192e2
Vivek Goyal
maintainerQuoted 5 lines · Stef Bon
Hi Ioannis,
I see that you have been working on making fsnotify work on virtiofs. Earlier you contacted me since I've written this:
Quoted 8 lines
https://github.com/libfuse/libfuse/wiki/Fsnotify-and-FUSE
and send you my patches on 23 june.
I want to mention first that I would have appreciated it if you would have reacted to me after I've sent you my patches. I did not get any reaction from you. Maybe these patches (which differ from what you propose now, but there is also a lot in common) have been an inspiration for you.
Hi Stef,
Sorry about not giving you the credit you deserved. We definitely made a mistake here. We will be more careful in future and not repeat such things.
Quoted 14 lines
Second, what I've written about is that with network filesystems (eg a backend shared with other systems) fsnotify support in FUSE has some drawbacks.
In a network environment, where a network fs is part of making people collaborate, it's very useful to have information on who did what on which host, and also when. Simply a message "a file has been created in the folder you watch" is not enough. For example, if you are part of a team, and assigned to your team is a directory on a server where you can work on some shared documents. Now in this example there is a planning, and some documents have to be written. In that case you want to be informed that someone in your team has started a document (by creating it) by the system.
Quoted 1 line
This "extended" information will never get through fsnotify.
Wondering fsnotify can be extended to carry this info when available.
Quoted 8 lines
Other info useful to you as team member:
(quoted diff) +0
-4- you have become member of another team: [email protected] - diskspace and/or quota shortage reported by networksystem - new teammember, teammember left - your "rights" or role in the network/team have been changed (forexample from reader to reader and writer to some documents)
All these sound useful. Some of them like change of team/group or change of rights/role seem outside the scope of filesystem notificaitons as such. Some sort of notifications for diskspace/quota could be applicable to local filesystems too.
Quoted 11 lines
What I want to say is that in a network where lots of people work together in teams/projects, (and I want Linux to play a role there, as desktop/workstation) communication is very important, and all these messages should be supported by the system. My idea is the support of watching fs events with FUSE filesystems should go through userspace, and not via the kernel (cause fs events are part of your setup in the network, together with all other tools to make people collaborate like chat/call/text, and because mentioned above extended info about the who on what host etc is not supported by fsnotify).
Quoted 3 lines
There should be a fs event watcher which takes care of all watches on behalf of applications during a session, similar to gamin and FAM once did (not used anymore?).
So how does the API look like for this OOB channel? Have you published it somewhere.
Thanks
Vivek
Quoted 11 lines
When receiving a request from one of the applications this fsevent watcher will use inotify and/or fanotify for local fs's only. With a FUSE fs, it should contact (via a socket) this fs that a watch has been set on an inode with a certain mask.
If the FUSE fs does not support this, fallback on normal inotify/fanotify. This way extended info is possible.Is this extended information also useful for virtiofs?
Stef Bon
Vivek Goyal
maintainerQuoted 105 lines · Amir Goldstein
Quoted 92 lines · Ioannis Angelakopoulos
Quoted 72 lines · Vivek Goyal
Quoted 20 lines · Amir Goldstein
Quoted 19 lines · Vivek Goyal
On Tue, Oct 26, 2021 at 06:23:50PM +0300, Amir Goldstein wrote:
[..]
Quoted 8 lines
Quoted 8 lines
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest does not receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the watch). In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the guest kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore).
So this is one of the issues which has been haunting us in virtiofs. If a file is removed, for local events, event is generated first and then watch is removed. But in case of remote filesystems, it is racy. It is possible that by the time event arrives, watch is already gone and application never sees the delete event.
Quoted 5 lines
Quoted 1 line
Not sure how to address this issue.
Can you take me through the scenario step by step. I am not sure I understand the exact sequence of the race.
Ioannis, please correct me If I get something wrong. You know exact details much more than me.
A. Say a guest process unlinks a file.
B. Fuse sends an unlink request to server (virtiofsd)
C. File is unlinked on host. Assume there are no other users so inode
will be freed as well. And event will be generated on host and watch removed.
D. Now Fuse server will send a unlink request reply. unlink notification
might still be in kernel buffers or still be in virtiofsd or could be in virtiofs virtqueue.
E. Fuse client will receive unlink reply and remove local watch.Fuse reply and notification event are now traveling in parallel on different virtqueues and there is no connection between these two. And it could very well happen that fuse reply comes first, gets processed first and local watch is removed. And notification is processed right after but by then local watch is gone and filesystem will be forced to drop event.
As of now situation is more complicated in virtiofsd. We don't keep file handle open for file and keep an
O_PATHfd open for each file. That means in step D above, inode on host is not freed yet and unlink event is not generated yet. When unlink reply reaches fuse client, it sends FORGET messages to server, and then server closesO_PATHfd and then host generates unlink events. By that time its too late, guest has already remove local watches (and triggered removal of remote watches too).This second problem probably can be solved by using file handles, but basic race will still continue to be there.
Quoted 3 lines
If it is local file removal that causes watch to be removed, then don't drop local events and you are good to go. Is it something else?
- If remote events are enabled, then idea will be that user space gets and event when file is actually removed from server, right? Now it is possible that another VM has this file open and file has not been yet removed. So local event only tells you that file has been removed in guest VM (or locally) but does not tell anything about the state of file on server. (It has been unlinked on server but inode continues to be alive internall).
Quoted 8 lines
- If user receives both local and remote delete event, it will be confusing. I guess if we want to see both the events, then there has to be some sort of info in event which classifies whether event is local or remote. And let application act accordingly.
Thanks
VivekHello Amir!
Sorry for taking part in the conversation a bit late. Vivek was on point with the example he gave but the race is a bit more generic than only the DELETE event.
Let's say that a guest process monitors an inode for OPEN events:
Quoted 10 lines
1) The same guest process or another guest process opens the file (related to the monitored inode), and then closes and immediately deletes the file/inode.
2) The FUSE server (virtiofsd) will mimic the operations of the guest process:
a) Will open the file on the host side and thus a remote OPEN event is going to be generated on the host and sent to the guest.
b) Will unlink the remote inode and if no other host process uses the inode then the inode will be freed and a DELETE event is going to be generated on the host and sent to the guest (However, due to how virtiofsd works and Vivek mentioned, this step won't happen immediately)
Quoted 7 lines
You are confusing DELETE with
DELETE_SELF.
DELETE corresponds tounlink(), so you get a DELETE event even if inode is a hardlink
with nlink > 0 afterunlink().The DELETE event is reported (along with filename) against the parent directory inode, so the test case above won't drop the event.
Hi Amir,
Agreed that there is confusion between DELETE and DELETE_SELF events. I think Ioannis is referring to DELETE_SELF event. With this example he is trying to emphasize that due to races, problem is not limited to DELETE_SELF events only and other events could arrive little later after the local watch in guest has been removed and then all those events will be dropped as well. So he gave example of OPEN event. And I think remote IN_IGNORED might face the same fate.
In the case of IN_IGNORED, I am wondering is it ok to generate that event locally instead.
Quoted 10 lines
Quoted 6 lines
The problem here is that the OPEN event might still be travelling towards the guest in the virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.
I have a feeling that we are mixing issues related to shared server and remote fsnotify.
Does virtiofsd support multiple guests already?
I would like to think that there are not many basic issues with shared directory configuration. So we don't stop users from using it.
Quoted 7 lines
There are many other
issues related
to cache coherency that should be dealt with in this case, some of them overlap the
problem that you describe, so solving the narrow problem of dropped remote events
seems like the wrong way to approach the problem.
Dropped remote event problem/race will exist even if it was not shared server. Remote events travel through different virtqueue as comapred to fuse request reply. So there is no guarantee in what order events or replies will processed.
Quoted 3 lines
I think that in a shared server situation, the simple LOOKUP/FORGET protocol will not suffice.
Hmm.., So what's the problem with LOOKUP/FORGET in shared dir case?
Quoted 4 lines
I will not even try to solve the generic problem,
but will just
mentioned that SMB/NFS protocols use delegations/oplocks in the protocol to advertise object usage by other clients to all clients.
I think Miklos was looking into the idea of some sort of file leases on fuse for creating equivalent of delegations. Not sure if that work made any progress.
Quoted 3 lines
I think this issue is far outside the scope of your project and you should just leave the dropped events as a known limitation at this point.
May be that's what we should do to begin with and just say these events can be lost or never arrive.
Quoted 2 lines
inotify has the event
IN_IGNOREDthat application can use as a hint that some events could have been dropped.
That probably will require generating IN_IGNORED locally when local watch goes away (and not rely on remote IN_IGNORED), IIUC.
Thanks
Vivek
Amir Goldstein
reviewerQuoted 125 lines · Vivek Goyal
Quoted 105 lines · Amir Goldstein
Quoted 92 lines · Ioannis Angelakopoulos
Quoted 72 lines · Vivek Goyal
Quoted 20 lines · Amir Goldstein
Quoted 19 lines · Vivek Goyal
On Tue, Oct 26, 2021 at 06:23:50PM +0300, Amir Goldstein wrote:
[..]
Quoted 8 lines
Quoted 8 lines
3) The lifetime of the local watch in the guest kernel is very important. Specifically, there is a possibility that the guest does not receive remote events on time, if it removes its local watch on the target or deletes the inode (and thus the guest kernel removes the watch). In these cases the guest kernel removes the local watch before the remote events arrive from the host (virtiofsd) and as such the guest kernel drops all the remote events for the target inode (since the corresponding local watch does not exist anymore).
So this is one of the issues which has been haunting us in virtiofs. If a file is removed, for local events, event is generated first and then watch is removed. But in case of remote filesystems, it is racy. It is possible that by the time event arrives, watch is already gone and application never sees the delete event.
Quoted 5 lines
Quoted 1 line
Not sure how to address this issue.
Can you take me through the scenario step by step. I am not sure I understand the exact sequence of the race.
Ioannis, please correct me If I get something wrong. You know exact details much more than me.
A. Say a guest process unlinks a file.
B. Fuse sends an unlink request to server (virtiofsd)
C. File is unlinked on host. Assume there are no other users so inode
will be freed as well. And event will be generated on host and watch removed.
D. Now Fuse server will send a unlink request reply. unlink notification
might still be in kernel buffers or still be in virtiofsd or could be in virtiofs virtqueue.
E. Fuse client will receive unlink reply and remove local watch.Fuse reply and notification event are now traveling in parallel on different virtqueues and there is no connection between these two. And it could very well happen that fuse reply comes first, gets processed first and local watch is removed. And notification is processed right after but by then local watch is gone and filesystem will be forced to drop event.
As of now situation is more complicated in virtiofsd. We don't keep file handle open for file and keep an
O_PATHfd open for each file. That means in step D above, inode on host is not freed yet and unlink event is not generated yet. When unlink reply reaches fuse client, it sends FORGET messages to server, and then server closesO_PATHfd and then host generates unlink events. By that time its too late, guest has already remove local watches (and triggered removal of remote watches too).This second problem probably can be solved by using file handles, but basic race will still continue to be there.
Quoted 3 lines
If it is local file removal that causes watch to be removed, then don't drop local events and you are good to go. Is it something else?
- If remote events are enabled, then idea will be that user space gets and event when file is actually removed from server, right? Now it is possible that another VM has this file open and file has not been yet removed. So local event only tells you that file has been removed in guest VM (or locally) but does not tell anything about the state of file on server. (It has been unlinked on server but inode continues to be alive internall).
Quoted 8 lines
- If user receives both local and remote delete event, it will be confusing. I guess if we want to see both the events, then there has to be some sort of info in event which classifies whether event is local or remote. And let application act accordingly.
Thanks
VivekHello Amir!
Sorry for taking part in the conversation a bit late. Vivek was on point with the example he gave but the race is a bit more generic than only the DELETE event.
Let's say that a guest process monitors an inode for OPEN events:
Quoted 10 lines
1) The same guest process or another guest process opens the file (related to the monitored inode), and then closes and immediately deletes the file/inode.
2) The FUSE server (virtiofsd) will mimic the operations of the guest process:
a) Will open the file on the host side and thus a remote OPEN event is going to be generated on the host and sent to the guest.
b) Will unlink the remote inode and if no other host process uses the inode then the inode will be freed and a DELETE event is going to be generated on the host and sent to the guest (However, due to how virtiofsd works and Vivek mentioned, this step won't happen immediately)Quoted 7 lines
You are confusing DELETE with
DELETE_SELF.
DELETE corresponds tounlink(), so you get a DELETE event even if inode is a hardlink
with nlink > 0 afterunlink().The DELETE event is reported (along with filename) against the parent directory inode, so the test case above won't drop the event.
Hi Amir,
Agreed that there is confusion between DELETE and
DELETE_SELFevents. I think Ioannis is referring toDELETE_SELFevent. With this example he is trying to emphasize that due to races, problem is not limited toDELETE_SELFevents only and other events could arrive little later after the local watch in guest has been removed and then all those events will be dropped as well. So he gave example of OPEN event. And I think remoteIN_IGNOREDmight face the same fate.
Quoted 3 lines
In the case of
IN_IGNORED, I am wondering is it ok to generate that event locally instead.
Yes, that is what I meant.
Local watch removed can be used as a hint to applications that events might have been lost.
Quoted 28 lines
Quoted 10 lines
Quoted 6 lines
The problem here is that the OPEN event might still be travelling towards the guest in the virtqueues and arrives after the guest has already deleted its local inode. While the remote event (OPEN) received by the guest is valid, its fsnotify subsystem will drop it since the local inode is not there.
I have a feeling that we are mixing issues related to shared server and remote fsnotify.
Does virtiofsd support multiple guests already?I would like to think that there are not many basic issues with shared directory configuration. So we don't stop users from using it.
Quoted 7 lines
There are many other
issues related
to cache coherency that should be dealt with in this case, some of them overlap the
problem that you describe, so solving the narrow problem of dropped remote events
seems like the wrong way to approach the problem.Dropped remote event problem/race will exist even if it was not shared server. Remote events travel through different virtqueue as comapred to fuse request reply. So there is no guarantee in what order events or replies will processed.
Quoted 1 line
Quoted 5 lines
Quoted 2 lines
I think that in a shared server situation, the simple LOOKUP/FORGET protocol will not suffice.
Hmm.., So what's the problem with LOOKUP/FORGET in shared dir case?
I guess when we say "shared dir" case, we mean different things. I was thinking about "shared between different client" and about the fact the information about the server refcount of objects is obscured from the client.
For example, LOOKUP_INC/DEC requests that report back the server's shared object refcount could prevent a guest inode from being evicted in case inode has a remote watch.
But you were mentioning "shared dir with guest and host", so LOOKUP refcount is not relevant in that case.
Quoted 13 lines
Quoted 4 lines
I will not even try to solve the generic problem,
but will just
mentioned that SMB/NFS protocols use delegations/oplocks in the protocol to advertise object usage by other clients to all clients.I think Miklos was looking into the idea of some sort of file leases on fuse for creating equivalent of delegations. Not sure if that work made any progress.
Quoted 3 lines
I think this issue is far outside the scope of your project and you should just leave the dropped events as a known limitation at this point.
Quoted 9 lines
May be that's what we should do to begin with and just say these events can be lost or never arrive.
Quoted 2 lines
inotify has the event
IN_IGNOREDthat application can use as a hint that some events could have been dropped.That probably will require generating
IN_IGNOREDlocally when local watch goes away (and not rely on remoteIN_IGNORED), IIUC.
Right.
Thanks,
Amir.