30 Dec, 2020

2 commits

  • commit fecc4559780d52d174ea05e3bf543669165389c3 upstream.

    fsnotify_parent() used to send two separate events to backends when a
    parent inode is watching children and the child inode is also watching.
    In an attempt to avoid duplicate events in fanotify, we unified the two
    backend callbacks to a single callback and handled the reporting of the
    two separate events for the relevant backends (inotify and dnotify).
    However the handling is buggy and can result in inotify and dnotify
    listeners receiving events of the type they never asked for or spurious
    events.

    The problem is the unified event callback with two inode marks (parent and
    child) is called when any of the parent and child inodes are watched and
    interested in the event, but the parent inode's mark that is interested
    in the event on the child is not necessarily the one we are currently
    reporting to (it could belong to a different group).

    So before reporting the parent or child event flavor to backend we need
    to check that the mark is really interested in that event flavor.

    The semantics of INODE and CHILD marks were hard to follow and made the
    logic more complicated than it should have been. Replace it with INODE
    and PARENT marks semantics to hopefully make the logic more clear.

    Thanks to Hugh Dickins for spotting a bug in the earlier version of this
    patch.

    Fixes: 497b0c5a7c06 ("fsnotify: send event to parent and child with single callback")
    CC: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20201202120713.702387-4-amir73il@gmail.com
    Reported-by: Hugh Dickins
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara
    Signed-off-by: Greg Kroah-Hartman

    Amir Goldstein
     
  • commit 950cc0d2bef078e1f6459900ca4d4b2a2e0e3c37 upstream.

    The handle_inode_event() interface was added as (quoting comment):
    "a simple variant of handle_event() for groups that only have inode
    marks and don't have ignore mask".

    In other words, all backends except fanotify. The inotify backend
    also falls under this category, but because it required extra arguments
    it was left out of the initial pass of backends conversion to the
    simple interface.

    This results in code duplication between the generic helper
    fsnotify_handle_event() and the inotify_handle_event() callback
    which also happen to be buggy code.

    Generalize the handle_inode_event() arguments and add the check for
    FS_EXCL_UNLINK flag to the generic helper, so inotify backend could
    be converted to use the simple interface.

    Link: https://lore.kernel.org/r/20201202120713.702387-2-amir73il@gmail.com
    CC: stable@vger.kernel.org
    Fixes: b9a1b9772509 ("fsnotify: create method handle_inode_event() in fsnotify_operations")
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara
    Signed-off-by: Greg Kroah-Hartman

    Amir Goldstein
     

09 Nov, 2020

1 commit

  • The victim inode's parent and name info is required when an event
    needs to be delivered to a group interested in filename info OR
    when the inode's parent is interested in an event on its children.

    Let us call the first condition 'parent_needed' and the second
    condition 'parent_interested'.

    In fsnotify_parent(), the condition where the inode's parent is
    interested in some events on its children, but not necessarily
    interested the specific event is called 'parent_watched'.

    fsnotify_parent() tests the condition (!parent_watched && !parent_needed)
    for sending the event without parent and name info, which is correct.

    It then wrongly assumes that parent_watched implies !parent_needed
    and tests the condition (parent_watched && !parent_interested)
    for sending the event without parent and name info, which is wrong,
    because parent may still be needed by some group.

    For example, after initializing a group with FAN_REPORT_DFID_NAME and
    adding a FAN_MARK_MOUNT with FAN_OPEN mask, open events on non-directory
    children of "testdir" are delivered with file name info.

    After adding another mark to the same group on the parent "testdir"
    with FAN_CLOSE|FAN_EVENT_ON_CHILD mask, open events on non-directory
    children of "testdir" are no longer delivered with file name info.

    Fix the logic and use auxiliary variables to clarify the conditions.

    Fixes: 9b93f33105f5 ("fsnotify: send event with parent/name info to sb/mount/non-dir marks")
    Cc: stable@vger.kernel.org#v5.9
    Link: https://lore.kernel.org/r/20201108105906.8493-1-amir73il@gmail.com
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

28 Jul, 2020

7 commits

  • The method handle_event() grew a lot of complexity due to the design of
    fanotify and merging of ignore masks.

    Most backends do not care about this complex functionality, so we can hide
    this complexity from them.

    Introduce a method handle_inode_event() that serves those backends and
    passes a single inode mark and less arguments.

    This change converts all backends except fanotify and inotify to use the
    simplified handle_inode_event() method. In pricipal, inotify could have
    also used the new method, but that would require passing more arguments
    on the simple helper (data, data_type, cookie), so we leave it with the
    handle_event() method.

    Link: https://lore.kernel.org/r/20200722125849.17418-9-amir73il@gmail.com
    Suggested-by: Jan Kara
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • Similar to events "on child" to watching directory, send event
    with parent/name info if sb/mount/non-dir marks are interested in
    parent/name info.

    The FS_EVENT_ON_CHILD flag can be set on sb/mount/non-dir marks to specify
    interest in parent/name info for events on non-directory inodes.

    Events on "orphan" children (disconnected dentries) are sent without
    parent/name info.

    Events on directories are sent with parent/name info only if the parent
    directory is watching.

    After this change, even groups that do not subscribe to events on
    children could get an event with mark iterator type TYPE_CHILD and
    without mark iterator type TYPE_INODE if fanotify has marks on the same
    objects.

    dnotify and inotify event handlers can already cope with that situation.
    audit does not subscribe to events that are possible on child, so won't
    get to this situation. nfsd does not access the marks iterator from its
    event handler at the moment, so it is not affected.

    This is a bit too fragile, so we should prepare all groups to cope with
    mark type TYPE_CHILD preferably using a generic helper.

    Link: https://lore.kernel.org/r/20200716084230.30611-16-amir73il@gmail.com
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • The arguments of fsnotify() are overloaded and mean different things
    for different event types.

    Replace the to_tell argument with separate arguments @dir and @inode,
    because we may be sending to both dir and child. Using the @data
    argument to pass the child is not enough, because dirent events pass
    this argument (for audit), but we do not report to child.

    Document the new fsnotify() function argumenets.

    Link: https://lore.kernel.org/r/20200722125849.17418-7-amir73il@gmail.com
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • Simple helper to consolidate biolerplate code.

    Link: https://lore.kernel.org/r/20200722125849.17418-5-amir73il@gmail.com
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • Instead of calling fsnotify() twice, once with parent inode and once
    with child inode, if event should be sent to parent inode, send it
    with both parent and child inodes marks in object type iterator and call
    the backend handle_event() callback only once.

    The parent inode is assigned to the standard "inode" iterator type and
    the child inode is assigned to the special "child" iterator type.

    In that case, the bit FS_EVENT_ON_CHILD will be set in the event mask,
    the dir argument to handle_event will be the parent inode, the file_name
    argument to handle_event is non NULL and refers to the name of the child
    and the child inode can be accessed with fsnotify_data_inode().

    This will allow fanotify to make decisions based on child or parent's
    ignored mask. For example, when a parent is interested in a specific
    event on its children, but a specific child wishes to ignore this event,
    the event will not be reported. This is not what happens with current
    code, but according to man page, it is the expected behavior.

    Link: https://lore.kernel.org/r/20200716084230.30611-15-amir73il@gmail.com
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • It was never enabled in uapi and its functionality is about to be
    superseded by events FAN_CREATE, FAN_DELETE, FAN_MOVE with group
    flag FAN_REPORT_NAME.

    Keep a place holder variable name_event instead of removing the
    name recording code since it will be used by the new events.

    Link: https://lore.kernel.org/r/20200708111156.24659-17-amir73il@gmail.com
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • The 'inode' argument to handle_event(), sometimes referred to as
    'to_tell' is somewhat obsolete.
    It is a remnant from the times when a group could only have an inode mark
    associated with an event.

    We now pass an iter_info array to the callback, with all marks associated
    with an event.

    Most backends ignore this argument, with two exceptions:
    1. dnotify uses it for sanity check that event is on directory
    2. fanotify uses it to report fid of directory on directory entry
    modification events

    Remove the 'inode' argument and add a 'dir' argument.
    The callback function signature is deliberately changed, because
    the meaning of the argument has changed and the arguments have
    been documented.

    The 'dir' argument is set to when 'file_name' is specified and it is
    referring to the directory that the 'file_name' entry belongs to.

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

15 Jul, 2020

2 commits

  • All (two) callers of fsnotify_parent() also call fsnotify() to notify
    the child inode. Move the second fsnotify() call into fsnotify_parent().

    This will allow more flexibility in making decisions about which of the
    two event falvors should be sent.

    Using 'goto notify_child' in the inline helper seems a bit strange, but
    it mimics the code in __fsnotify_parent() for clarity and the goto
    pattern will become less strage after following patches are applied.

    Link: https://lore.kernel.org/r/20200708111156.24659-2-amir73il@gmail.com
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • The fsnotify paths are trivial to hit even when there are no watchers and
    they are surprisingly expensive. For example, every successful vfs_write()
    hits fsnotify_modify which calls both fsnotify_parent and fsnotify unless
    FMODE_NONOTIFY is set which is an internal flag invisible to userspace.
    As it stands, fsnotify_parent is a guaranteed functional call even if there
    are no watchers and fsnotify() does a substantial amount of unnecessary
    work before it checks if there are any watchers. A perf profile showed
    that applying mnt->mnt_fsnotify_mask in fnotify() was almost half of the
    total samples taken in that function during a test. This patch rearranges
    the fast paths to reduce the amount of work done when there are no
    watchers.

    The test motivating this was "perf bench sched messaging --pipe". Despite
    the fact the pipes are anonymous, fsnotify is still called a lot and
    the overhead is noticeable even though it's completely pointless. It's
    likely the overhead is negligible for real IO so this is an extreme
    example. This is a comparison of hackbench using processes and pipes on
    a 1-socket machine with 8 CPU threads without fanotify watchers.

    5.7.0 5.7.0
    vanilla fastfsnotify-v1r1
    Amean 1 0.4837 ( 0.00%) 0.4630 * 4.27%*
    Amean 3 1.5447 ( 0.00%) 1.4557 ( 5.76%)
    Amean 5 2.6037 ( 0.00%) 2.4363 ( 6.43%)
    Amean 7 3.5987 ( 0.00%) 3.4757 ( 3.42%)
    Amean 12 5.8267 ( 0.00%) 5.6983 ( 2.20%)
    Amean 18 8.4400 ( 0.00%) 8.1327 ( 3.64%)
    Amean 24 11.0187 ( 0.00%) 10.0290 * 8.98%*
    Amean 30 13.1013 ( 0.00%) 12.8510 ( 1.91%)
    Amean 32 13.9190 ( 0.00%) 13.2410 ( 4.87%)

    5.7.0 5.7.0
    vanilla fastfsnotify-v1r1
    Duration User 157.05 152.79
    Duration System 1279.98 1219.32
    Duration Elapsed 182.81 174.52

    This is showing that the latencies are improved by roughly 2-9%. The
    variability is not shown but some of these results are within the noise
    as this workload heavily overloads the machine. That said, the system CPU
    usage is reduced by quite a bit so it makes sense to avoid the overhead
    even if it is a bit tricky to detect at times. A perf profile of just 1
    group of tasks showed that 5.14% of samples taken were in either fsnotify()
    or fsnotify_parent(). With the patch, 2.8% of samples were in fsnotify,
    mostly function entry and the initial check for watchers. The check for
    watchers is complicated enough that inlining it may be controversial.

    [Amir] Slightly simplify with mnt_or_sb_mask => marks_mask

    Link: https://lore.kernel.org/r/20200708111156.24659-1-amir73il@gmail.com
    Signed-off-by: Mel Gorman
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Mel Gorman
     

25 Mar, 2020

1 commit

  • Dirent events are going to be supported in two flavors:

    1. Directory fid info + mask that includes the specific event types
    (e.g. FAN_CREATE) and an optional FAN_ONDIR flag.
    2. Directory fid info + name + mask that includes only FAN_DIR_MODIFY.

    To request the second event flavor, user needs to set the event type
    FAN_DIR_MODIFY in the mark mask.

    The first flavor is supported since kernel v5.1 for groups initialized
    with flag FAN_REPORT_FID. It is intended to be used for watching
    directories in "batch mode" - the watcher is notified when directory is
    changed and re-scans the directory content in response. This event
    flavor is stored more compactly in the event queue, so it is optimal
    for workloads with frequent directory changes.

    The second event flavor is intended to be used for watching large
    directories, where the cost of re-scan of the directory on every change
    is considered too high. The watcher getting the event with the directory
    fid and entry name is expected to call fstatat(2) to query the content of
    the entry after the change.

    Legacy inotify events are reported with name and event mask (e.g. "foo",
    FAN_CREATE | FAN_ONDIR). That can lead users to the conclusion that
    there is *currently* an entry "foo" that is a sub-directory, when in fact
    "foo" may be negative or non-dir by the time user gets the event.

    To make it clear that the current state of the named entry is unknown,
    when reporting an event with name info, fanotify obfuscates the specific
    event types (e.g. create,delete,rename) and uses a common event type -
    FAN_DIR_MODIFY to describe the change. This should make it harder for
    users to make wrong assumptions and write buggy filesystem monitors.

    At this point, name info reporting is not yet implemented, so trying to
    set FAN_DIR_MODIFY in mark mask will return -EINVAL.

    Link: https://lore.kernel.org/r/20200319151022.31456-12-amir73il@gmail.com
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

24 Mar, 2020

2 commits


18 Dec, 2019

2 commits

  • When a filesystem is unmounted, we currently call fsnotify_sb_delete()
    before evict_inodes(), which means that fsnotify_unmount_inodes()
    must iterate over all inodes on the superblock looking for any inodes
    with watches. This is inefficient and can lead to livelocks as it
    iterates over many unwatched inodes.

    At this point, SB_ACTIVE is gone and dropping refcount to zero kicks
    the inode out out immediately, so anything processed by
    fsnotify_sb_delete / fsnotify_unmount_inodes gets evicted in that loop.

    After that, the call to evict_inodes will evict everything else with a
    zero refcount.

    This should speed things up overall, and avoid livelocks in
    fsnotify_unmount_inodes().

    Signed-off-by: Eric Sandeen
    Reviewed-by: Jan Kara
    Signed-off-by: Al Viro

    Eric Sandeen
     
  • Anything that walks all inodes on sb->s_inodes list without rescheduling
    risks softlockups.

    Previous efforts were made in 2 functions, see:

    c27d82f fs/drop_caches.c: avoid softlockups in drop_pagecache_sb()
    ac05fbb inode: don't softlockup when evicting inodes

    but there hasn't been an audit of all walkers, so do that now. This
    also consistently moves the cond_resched() calls to the bottom of each
    loop in cases where it already exists.

    One loop remains: remove_dquot_ref(), because I'm not quite sure how
    to deal with that one w/o taking the i_lock.

    Signed-off-by: Eric Sandeen
    Reviewed-by: Jan Kara
    Signed-off-by: Al Viro

    Eric Sandeen
     

17 Oct, 2019

1 commit

  • Move fsnotify_mark_connector_cachep to fsnotify.h to properly
    share it with the user in mark.c and avoid the following warning
    from sparse:

    fs/notify/mark.c:82:19: warning: symbol 'fsnotify_mark_connector_cachep' was not declared. Should it be static?

    Link: https://lore.kernel.org/r/20191015132518.21819-1-ben.dooks@codethink.co.uk
    Signed-off-by: Ben Dooks
    Signed-off-by: Jan Kara

    Ben Dooks
     

20 Jun, 2019

1 commit

  • For all callers of fsnotify_{unlink,rmdir}(), we made sure that d_parent
    and d_name are stable. Therefore, fsnotify_{unlink,rmdir}() do not need
    the safety measures in fsnotify_nameremove() to stabilize parent and name.
    We can now simplify those hooks and get rid of fsnotify_nameremove().

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

21 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 or at your option any
    later version this program is distributed in the hope that it will
    be useful but without any warranty without even the implied warranty
    of merchantability or fitness for a particular purpose see the gnu
    general public license for more details you should have received a
    copy of the gnu general public license along with this program see
    the file copying if not write to the free software foundation 675
    mass ave cambridge ma 02139 usa

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 52 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Jilayne Lovejoy
    Reviewed-by: Steve Winslow
    Reviewed-by: Kate Stewart
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190519154042.342335923@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

14 May, 2019

1 commit


09 May, 2019

1 commit

  • __fsnotify_parent() has an optimization in place to avoid unneeded
    take_dentry_name_snapshot(). When fsnotify_nameremove() was changed
    not to call __fsnotify_parent(), we left out the optimization.
    Kernel test robot reported a 5% performance regression in concurrent
    unlink() workload.

    Reported-by: kernel test robot
    Link: https://lore.kernel.org/lkml/20190505062153.GG29809@shao2-debian/
    Link: https://lore.kernel.org/linux-fsdevel/20190104090357.GD22409@quack2.suse.cz/
    Fixes: 5f02a8776384 ("fsnotify: annotate directory entry modification events")
    CC: stable@vger.kernel.org
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

27 Apr, 2019

3 commits


06 Feb, 2019

1 commit

  • So far, existence of super block marks was checked only on events with
    data type FSNOTIFY_EVENT_PATH. Use the super block of the "to_tell" inode
    to report the events of all event types to super block marks.

    This change has no effect on current backends. Soon, this will allow
    fanotify backend to receive all event types on a super block mark.

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

14 Nov, 2018

2 commits

  • A new event mask FAN_OPEN_EXEC_PERM has been defined. This allows users
    to receive events and grant access to files that are intending to be
    opened for execution. Events of FAN_OPEN_EXEC_PERM type will be
    generated when a file has been opened by using either execve(),
    execveat() or uselib() system calls.

    This acts in the same manner as previous permission event mask, meaning
    that an access response is required from the user application in order
    to permit any further operations on the file.

    Signed-off-by: Matthew Bobrowski
    Reviewed-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Matthew Bobrowski
     
  • A new event mask FAN_OPEN_EXEC has been defined so that users have the
    ability to receive events specifically when a file has been opened with
    the intent to be executed. Events of FAN_OPEN_EXEC type will be
    generated when a file has been opened using either execve(), execveat()
    or uselib() system calls.

    The feature is implemented within fsnotify_open() by generating the
    FAN_OPEN_EXEC event type if __FMODE_EXEC is set within file->f_flags.

    Signed-off-by: Matthew Bobrowski
    Reviewed-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Matthew Bobrowski
     

08 Nov, 2018

1 commit

  • When an event is reported on a sub-directory and the parent inode has
    a mark mask with FS_EVENT_ON_CHILD|FS_ISDIR, the event will be sent to
    fsnotify() even if the event type is not in the parent mark mask
    (e.g. FS_OPEN).

    Further more, if that event happened on a mount or a filesystem with
    a mount/sb mark that does have that event type in their mask, the "on
    child" event will be reported on the mount/sb mark. That is not
    desired, because user will get a duplicate event for the same action.

    Note that the event reported on the victim inode is never merged with
    the event reported on the parent inode, because of the check in
    should_merge(): old_fsn->inode == new_fsn->inode.

    Fix this by looking for a match of an actual event type (i.e. not just
    FS_ISDIR) in parent's inode mark mask and by not reporting an "on child"
    event to group if event type is only found on mount/sb marks.

    [backport hint: The bug seems to have always been in fanotify, but this
    patch will only apply cleanly to v4.19.y]

    Cc: # v4.19
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

25 Oct, 2018

1 commit

  • Detaching of mark connector from fsnotify_put_mark() can race with
    unmounting of the filesystem like:

    CPU1 CPU2
    fsnotify_put_mark()
    spin_lock(&conn->lock);
    ...
    inode = fsnotify_detach_connector_from_object(conn)
    spin_unlock(&conn->lock);
    generic_shutdown_super()
    fsnotify_unmount_inodes()
    sees connector detached for inode
    -> nothing to do
    evict_inode()
    barfs on pending inode reference
    iput(inode);

    Resulting in "Busy inodes after unmount" message and possible kernel
    oops. Make fsnotify_unmount_inodes() properly wait for outstanding inode
    references from detached connectors.

    Note that the accounting of outstanding inode references in the
    superblock can cause some cacheline contention on the counter. OTOH it
    happens only during deletion of the last notification mark from an inode
    (or during unlinking of watched inode) and that is not too bad. I have
    measured time to create & delete inotify watch 100000 times from 64
    processes in parallel (each process having its own inotify group and its
    own file on a shared superblock) on a 64 CPU machine. Average and
    standard deviation of 15 runs look like:

    Avg Stddev
    Vanilla 9.817400 0.276165
    Fixed 9.710467 0.228294

    So there's no statistically significant difference.

    Fixes: 6b3f05d24d35 ("fsnotify: Detach mark from object list when last reference is dropped")
    CC: stable@vger.kernel.org
    Signed-off-by: Jan Kara

    Jan Kara
     

04 Oct, 2018

2 commits

  • The BUG_ON() statements to verify number of bits in ALL_FSNOTIFY_BITS
    and ALL_INOTIFY_BITS are converted to build time check of the constant.

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • FS_EVENT_ON_CHILD gets a special treatment in fsnotify() because it is
    not a flag specifying an event type, but rather an extra flags that may
    be reported along with another event and control the handling of the
    event by the backend.

    FS_ISDIR is also an "extra flag" and not an "event type" and therefore
    desrves the same treatment. With inotify/dnotify backends it was never
    possible to set FS_ISDIR in mark masks, so it did not matter.
    With fanotify backend, mark adding code jumps through hoops to avoid
    setting the FS_ISDIR in the commulative object mask.

    Separate the constant ALL_FSNOTIFY_EVENTS to ALL_FSNOTIFY_FLAGS and
    ALL_FSNOTIFY_EVENTS, so the latter can be used to test for specific
    event types.

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

03 Sep, 2018

3 commits

  • Send events to group if super block mark mask matches the event
    and unless the same group has an ignore mask on the vfsmount or
    the inode on which the event occurred.

    Soon, fanotify backend is going to support super block marks and
    fanotify backend only supports path type events.

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • Add the infrastructure to attach a mark to a super_block struct
    and detach all attached marks when super block is destroyed.

    This is going to be used by fanotify backend to setup super block
    marks.

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • Commit 92183a42898d ("fsnotify: fix ignore mask logic in
    send_to_group()") acknoledges the use case of ignoring an event on
    an inode mark, because of an ignore mask on a mount mark of the same
    group (i.e. I want to get all events on this file, except for the events
    that came from that mount).

    This change depends on correctly merging the inode marks and mount marks
    group lists, so that the mount mark ignore mask would be tested in
    send_to_group(). Alas, the merging of the lists did not take into
    account the case where event in question is not in the mask of any of
    the mount marks.

    To fix this, completely remove the tests for inode and mount event masks
    from the lists merging code.

    Fixes: 92183a42898d ("fsnotify: fix ignore mask logic in send_to_group")
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

18 May, 2018

4 commits

  • Use fsnotify_foreach_obj_type macros to generalize the code that filters
    events by marks mask and ignored_mask.

    This is going to be used for adding mark of super block object type.

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • Make some code that handles marks of object types inode and vfsmount
    generic, so it can handle other object types.

    Introduce fsnotify_foreach_obj_type macro to iterate marks by object type
    and fsnotify_iter_{should|set}_report_type macros to set/test report_mask.

    This is going to be used for adding mark of another object type
    (super block mark).

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • Introduce helpers fsnotify_iter_select_report_types() and
    fsnotify_iter_next() to abstract the inode/vfsmount marks merged
    list iteration.

    This is a preparation patch before generalizing mark list
    iteration to more mark object types (i.e. super block marks).

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • inode_mark and vfsmount_mark arguments are passed to handle_event()
    operation as function arguments as well as on iter_info struct.
    The difference is that iter_info struct may contain marks that should
    not be handled and are represented as NULL arguments to inode_mark or
    vfsmount_mark.

    Instead of passing the inode_mark and vfsmount_mark arguments, add
    a report_mask member to iter_info struct to indicate which marks should
    be handled, versus marks that should only be kept alive during user
    wait.

    This change is going to be used for passing more mark types
    with handle_event() (i.e. super block marks).

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

13 Apr, 2018

1 commit

  • The ignore mask logic in send_to_group() does not match the logic
    in fanotify_should_send_event(). In the latter, a vfsmount mark ignore
    mask precedes an inode mark mask and in the former, it does not.

    That difference may cause events to be sent to fanotify backend for no
    reason. Fix the logic in send_to_group() to match that of
    fanotify_should_send_event().

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein