[systemd-devel] [PATCH v2 5/5] mount: auto-detect iSCSI and FCoE as requiring network
Karel Zak
kzak at redhat.com
Wed Dec 17 04:13:05 PST 2014
On Fri, Dec 12, 2014 at 08:11:54PM +0100, Lennart Poettering wrote:
> > I guess it's enough to add the 'fd' to systmed sd_event_add_io() and
> > call mnt_table_parse_mtab() when a change is detected. (As already
> > implemeted in the original Chris' patch.)
>
> Karel, if I got this right, then the new monitor stuff will only wrap
> inotify on utab, right? I think it would be useful if it would also
> abstract notifications via /proc/self/mountinfo in it. To make the
> interface easy for this and to be able to just hand out a single fd,
> this would mean creating an epoll fd inside the lib, then adding the
> inotify fd for utab to it, and then on top the EPOLLPRI watch on
> /proc/self/mountinfo.
>
> This way apps would get the full set of notifications via your
> library, without knowing what's going on underneath, and userspace
> notifications and kernel notifications would come the same way.
OK, implemented (util-linux "monitor" branch on github).
But I have changed the userspace monitor to care about
/run/mount/utab.lock file. It's better than the original Chris idea
(monitor all /run/mount directory for utab rename changes). This new
solution is without possible false positives.
This is important details, because if you use epoll file descriptor
in another epoll then you're correctly notified on the top-level epoll,
but you lost information about which underneath file descriptor is active
-- then it was impossible to verify the inotify IN_MOVED_TO utab event.
The another advantage is that the event is triggered really after utab
update (the update is covered by flock, and close() means unlock).
Now:
your-epoll
|
library-epoll-FD
/ \
mountinfo-FD utab.lock-inotify-FD
Note that after notification it's necessary to cleanup (drain) inotify
bufferes, so I have added mnt_monitor_event_cleanup().
Example:
mn = mnt_new_monitor();
mnt_monitor_enable_userspace(mn, TRUE);
mnt_monitor_enable_kernel(mn, TRUE);
fd = mnt_monitor_get_fd(mn);
<...add 'fd' to your epoll...>
n = epoll_wait(your_efd, events, 1, -1);
...
if (events[0].data.fd == fd) {
mnt_monitor_event_cleanup(mn);
printf("libmount notification\n");
<...parse mount tables...>
}
...
mnt_unref_monitor(mn);
The API also provides mnt_monitor_wait() for users who don't want to
own epoll, but this is irrelevant for systemd.
Karel
--
Karel Zak <kzak at redhat.com>
http://karelzak.blogspot.com
More information about the systemd-devel
mailing list