Re: Upcoming: Notifications, FS notifications and fsinfo()

From: David Howells
Date: Thu Apr 02 2020 - 11:51:39 EST


Lennart Poettering <mzxreary@xxxxxxxxxxx> wrote:

> systemd cares about all mount points in PID1's mount namespace.
>
> The fact that mount tables can grow large is why we want something
> better than constantly reparsing the whole /proc/self/mountinfo. But
> filtering subsets of that is something we don't really care about.

With the notifications stuff I've done, you can do, for example:

pipe2(pipefd, O_NOTIFICATION_PIPE);
ioctl(pipefd[0], IOC_WATCH_QUEUE_SET_SIZE, 256);
watch_mount(AT_FDCWD, "/", 0, pipefd[0], 0x02);

And that will catch all mount object changes in the subtree rooted at the
given path, in this case "/".

If you want to limit it to just the notifications on that mount, you would
need to install a filter:

struct watch_notification_filter filter = {
.nr_filters = 1,
.filters = {
[0] = {
.type = WATCH_TYPE_MOUNT_NOTIFY,
.subtype_filter[0]= UINT_MAX,
.info_mask = NOTIFY_MOUNT_IS_RECURSIVE,
.info_filter = 0,
},
},
};
ioctl(fd, IOC_WATCH_QUEUE_SET_FILTER, &filter);

Note that this doesn't monitor for superblock changes and events. They must
be watched individually with something like:

watch_sb(AT_FDCWD, "/afs", AT_NO_AUTOMOUNT, pipefd[0], 0x27);

David