All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Karel Zak <kzak@redhat.com>, Miklos Szeredi <mszeredi@redhat.com>,
	linux-fsdevel@vger.kernel.org, Jan Kara <jack@suse.cz>,
	Lennart Poettering <lennart@poettering.net>,
	Ian Kent <raven@themaw.net>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>
Subject: Re: [RFC PATCH] fanotify: notify on mount attach and detach
Date: Tue, 3 Dec 2024 17:42:04 +0100	[thread overview]
Message-ID: <20241203164204.nfscpnxbfwvfpmts@quack3> (raw)
In-Reply-To: <CAOQ4uxh0QevMgHur1MOOL2uXjivGEneyW2UfD+QOWj1Ozz5B1g@mail.gmail.com>

On Tue 03-12-24 14:03:24, Amir Goldstein wrote:
> On Tue, Dec 3, 2024 at 12:40 PM Karel Zak <kzak@redhat.com> wrote:
> > Thank you for working on this.
> >
> > On Thu, Nov 28, 2024 at 03:39:59PM GMT, Miklos Szeredi wrote:
> > > To monitor an entire mount namespace with this new interface, watches need
> > > to be added to all existing mounts.  This can be done by performing
> > > listmount()/statmount() recursively at startup and when a new mount is
> > > added.
> >
> > It seems that maintaining a complete tree of nodes on large systems
> > with thousands of mountpoints is quite costly for userspace. It also
> > appears to be fragile, as any missed new node (due to a race or other
> > reason) would result in the loss of the ability to monitor that part
> > of the hierarchy. Let's imagine that there are new mount nodes added
> > between the listmount() and fanotify_mark() calls. These nodes
> > will be invisible.
> 
> That should not happen if the monitor does:
> 1. set fanotify_mark() on parent mount to get notified on new child mounts
> 2. listmount() on parent mount to list existing children mounts

Right, that works in principle. But it will have all those headaches as
trying to do recursive subtree watching with inotify directory watches
(mounts can also be moved, added, removed, etc. while we are trying to
capture them). It is possible to do but properly handling all the possible
races was challenging to say the least. That's why I have my doubts whether
this is really the interface we want to offer to userspace...

> > It would be beneficial to have a "recursive" flag that would allow for
> > opening only one mount node and receiving notifications for the entire
> > hierarchy. (I have no knowledge about fanotify, so it is possible that
> > this may not be feasible due to the internal design of fanotify.)
> 
> This can be challenging, but if it is acceptable to hold the namespace
> mutex while setting all the marks (?) then maybe.

So for mounts, given the relative rarity of mount / umount events and depth
of a mount tree (compared to the situation with ordinary inodes and
standard fanotify events), I think it might be even acceptable to walk up
the mount tree and notify everybody along that path.

> What should be possible is to set a mark on the mount namespace
> to get all the mount attach/detach events in the mount namespace
> and let userspace filter out the events that are not relevant to the
> subtree of interest.

Or this.

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2024-12-03 16:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-28 14:39 [RFC PATCH] fanotify: notify on mount attach and detach Miklos Szeredi
2024-11-28 16:43 ` Amir Goldstein
2024-11-29  7:16   ` Miklos Szeredi
2024-11-29 10:23     ` Amir Goldstein
2024-12-03 15:36       ` Miklos Szeredi
2024-11-28 19:57 ` Al Viro
2024-11-29  7:10   ` Miklos Szeredi
2024-11-29  9:25 ` Christian Brauner
2024-12-03 11:40 ` Karel Zak
2024-12-03 13:03   ` Amir Goldstein
2024-12-03 16:42     ` Jan Kara [this message]
2024-12-04 11:30       ` Christian Brauner
2024-12-06 15:18         ` Miklos Szeredi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241203164204.nfscpnxbfwvfpmts@quack3 \
    --to=jack@suse.cz \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=kzak@redhat.com \
    --cc=lennart@poettering.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mszeredi@redhat.com \
    --cc=raven@themaw.net \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.