From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Howells Date: Tue, 04 Jun 2019 12:33:01 +0000 Subject: Re: [RFC][PATCH 0/7] Mount, FS, Block and Keyrings notifications Message-Id: <16167.1559651581@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit List-Id: References: <155905930702.7587.7100265859075976147.stgit@warthog.procyon.org.uk> <20190529142504.GC32147@quack2.suse.cz> In-Reply-To: To: Amir Goldstein Cc: dhowells@redhat.com, Jan Kara , Al Viro , Ian Kent , linux-fsdevel , linux-api@vger.kernel.org, linux-block , keyrings@vger.kernel.org, LSM List , linux-kernel Amir Goldstein wrote: > Well I am sure that ring buffer for fanotify events would be useful, so > seeing that David is proposing a generic notification mechanism, I wanted > to know how that mechanism could best share infrastructure with fsnotify. > > But apart from that I foresee the questions from users about why the > mount notification API and filesystem events API do not have better > integration. > > The way I see it, the notification queue can serve several classes > of notifications and fsnotify could be one of those classes > (at least FAN_CLASS_NOTIF fits nicely to the model). It could be done; the main thing that concerns me is that the buffer is of limited capacity. However, I could take this: struct fanotify_event_metadata { __u32 event_len; __u8 vers; __u8 reserved; __u16 metadata_len; __aligned_u64 mask; __s32 fd; __s32 pid; }; and map it to: struct fanotify_notification { struct watch_notification watch; /* WATCH_TYPE_FANOTIFY */ __aligned_u64 mask; __u16 metadata_len; __u8 vers; __u8 reserved; __u32 reserved2; __s32 fd; __s32 pid; }; and some of the watch::info bit could be used: n->watch.info & WATCH_INFO_OVERRUN watch queue overran n->watch.info & WATCH_INFO_LENGTH event_len n->watch.info & WATCH_INFO_RECURSIVE FAN_EVENT_ON_CHILD n->watch.info & WATCH_INFO_FLAG_0 FAN_*_PERM n->watch.info & WATCH_INFO_FLAG_1 FAN_Q_OVERFLOW n->watch.info & WATCH_INFO_FLAG_2 FAN_ON_DIR n->subtype ffs(n->mask) Ideally, I'd dispense with metadata_len, vers, reserved* and set the version when setting the watch. fanotify_watch(int watchfd, unsigned int flags, u64 *mask, int dirfd, const char *pathname, unsigned int at_flags); We might also want to extend the watch_filter to allow you to, say, filter on the first __u64 after the watch member so that you could filter on specific events: struct watch_notification_type_filter { __u32 type; __u32 info_filter; __u32 info_mask; __u32 subtype_filter[8]; __u64 payload_mask[1]; __u64 payload_set[1]; }; So, in this case, it would require: n->mask & wf->payload_mask[0] = wf->payload_set[0] to be true to record the message. David From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Howells Subject: Re: [RFC][PATCH 0/7] Mount, FS, Block and Keyrings notifications Date: Tue, 04 Jun 2019 13:33:01 +0100 Message-ID: <16167.1559651581@warthog.procyon.org.uk> References: <155905930702.7587.7100265859075976147.stgit@warthog.procyon.org.uk> <20190529142504.GC32147@quack2.suse.cz> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Return-path: In-Reply-To: Content-ID: <16166.1559651581.1@warthog.procyon.org.uk> Sender: linux-kernel-owner@vger.kernel.org To: Amir Goldstein Cc: dhowells@redhat.com, Jan Kara , Al Viro , Ian Kent , linux-fsdevel , linux-api@vger.kernel.org, linux-block , keyrings@vger.kernel.org, LSM List , linux-kernel List-Id: linux-api@vger.kernel.org Amir Goldstein wrote: > Well I am sure that ring buffer for fanotify events would be useful, so > seeing that David is proposing a generic notification mechanism, I wanted > to know how that mechanism could best share infrastructure with fsnotify. > > But apart from that I foresee the questions from users about why the > mount notification API and filesystem events API do not have better > integration. > > The way I see it, the notification queue can serve several classes > of notifications and fsnotify could be one of those classes > (at least FAN_CLASS_NOTIF fits nicely to the model). It could be done; the main thing that concerns me is that the buffer is of limited capacity. However, I could take this: struct fanotify_event_metadata { __u32 event_len; __u8 vers; __u8 reserved; __u16 metadata_len; __aligned_u64 mask; __s32 fd; __s32 pid; }; and map it to: struct fanotify_notification { struct watch_notification watch; /* WATCH_TYPE_FANOTIFY */ __aligned_u64 mask; __u16 metadata_len; __u8 vers; __u8 reserved; __u32 reserved2; __s32 fd; __s32 pid; }; and some of the watch::info bit could be used: n->watch.info & WATCH_INFO_OVERRUN watch queue overran n->watch.info & WATCH_INFO_LENGTH event_len n->watch.info & WATCH_INFO_RECURSIVE FAN_EVENT_ON_CHILD n->watch.info & WATCH_INFO_FLAG_0 FAN_*_PERM n->watch.info & WATCH_INFO_FLAG_1 FAN_Q_OVERFLOW n->watch.info & WATCH_INFO_FLAG_2 FAN_ON_DIR n->subtype ffs(n->mask) Ideally, I'd dispense with metadata_len, vers, reserved* and set the version when setting the watch. fanotify_watch(int watchfd, unsigned int flags, u64 *mask, int dirfd, const char *pathname, unsigned int at_flags); We might also want to extend the watch_filter to allow you to, say, filter on the first __u64 after the watch member so that you could filter on specific events: struct watch_notification_type_filter { __u32 type; __u32 info_filter; __u32 info_mask; __u32 subtype_filter[8]; __u64 payload_mask[1]; __u64 payload_set[1]; }; So, in this case, it would require: n->mask & wf->payload_mask[0] == wf->payload_set[0] to be true to record the message. David