On Fri, Jul 3, 2020 at 7:02 PM Jan Kara <jack@xxxxxxx> wrote: > > On Fri 12-06-20 12:33:42, Amir Goldstein wrote: > > An fanotify event name is always recorded relative to a dir fh. > > Move the name_len members of fanotify_name_event into unused space > > in struct fanotify_fh. > > > > We add a name_offset member to allow packing a binary blob before > > the name string in the variable size buffer. We are going to use > > that space to store the child fid. > > So how much is this packing going to save us? Currently it is 1 byte for > name events (modulo that fanotify_alloc_name_event_bug() you mention > below). With the additional fanotify_fh in the event, we'll save two more > bytes by the packing. So that doesn't really seem to be worth it to me. > Am I missing some other benefit? > > Maybe your main motivation (which is not mentioned in the changelog at all > BTW) is that the whole game of inline vs out of line file handles is > pointless when we kmalloc() the event anyway because of the name? The only motivation, which is written in the commit message is to make space to store the child file handle. Saving space is just a by product. In fact, the new parceling code looses this space back to alignment and I am perfectly fine with that. > And it's > actively wasteful in case handles don't fit in the inline space. I agree > with that and it's good observation. But I'd rather leave fanotify_fh > struct alone for the cases where we want to bother with inline vs out of line > file handles and define new way of partitioning space at the end of the > event among one or two file handles and name. Something like: > > struct fanotify_dynamic_info { I called this fanotify_info. There is no ambiguity that justifies _dynamic_. The encapsulations are: fanotify_fid_event { ..., fanotify_fid { ..,buf[INLINE_BUF] } } fanotify_name_event { ..., fanotify_info { fanotify_fid { ..,buf[..] }+, name[..] } > u8 dirfh_len; > u8 filefh_len; I called these {dir,file}_fh_totlen to distinguish from fh->len, which does not include the size of the fanotify_fh header fields. > u8 name_len; > unsigned char buf[]; This had to be 4 bytes aligned to contain fanotify_fh. > }; > > And at appropriate offsets (0, dirfh_len, dirfh_len + filefh_len) there > would be additional info (e.g. type + fh for file handles). Maybe this > format will require some tweaking so that processing of both storage types > of file handles can be reasonably uniform but at this point it seems > cleaner than what you try to do fanotify_fh with combining lenghts and > offsets and some blobs in the middle... > I tried your suggestion (with the minor modifications above) and I like the result. Pushed prep series with 2 last patches changed to branch fanotify_prep. Old prep series is at fanotify_prep-v2. Pushed tested full series adapted to this change to fanotify_name_fid. Old full series is at fanotify_name_fid-v4. There was almost no changes to the fanotify_name_fid patches besides adapting the accessors, e.g.: - fanotify_fh_blob(&FANOTIFY_NE(event)->dir_fh); + fanotify_info_file_fh(&FANOTIFY_NE(event)->info); Please let me know if you want me to post fanotify_name_fid-v5 with these changes. Thanks, Amir.