Skip to content

Conversation

@dvdhrm
Copy link
Contributor

@dvdhrm dvdhrm commented Jun 14, 2015

Cc: @karelzak @poettering

This is a rebased and fixed version of Karel's original patch (see #53). It makes systemd use libmount to monitor utab and mountinfo files.

This is still not ready to be merged. It currently breaks systemd --user as libmount requires you to be root to monitor 'utab'. Reason for this is "userspace_monitor_get_fd()" in libmount, which calls open(O_CREAT) on the utab-lockfile (why?). Until this is fixed, I don't think we can merge this.

One possible workaround in systemd is to call "mnt_monitor_get_fd()" early. Then call "mnt_monitor_enable_userspace()" afterwards, and ignore EPERM. However, this will disable 'utab' monitoring for non-root systemd. @karelzak, can you explain why that O_CREAT is needed?

The current systemd core uses inotify directly to monitor
libmount-internal utab state. This is suboptimal as it relies on libmount
internals which are not ABI.

Since util-linux-2.26, libmount provides a monitor API to monitor both
kernel and user-space mount state. Use this to replace our own hard-coded
approach.

This patch was originally written by: Karel Zak <kzak@redhat.com>
@zonque
Copy link
Member

zonque commented Jun 14, 2015

Semaphore currently fails because their build VMs are based on Ubuntu 14.04 which ship util-linux (at with it, libmount) in version 2.20. A PPA I found would give us version 2.25, but not 2.26. Why the version bump, and which minimum libmount requirement does the new code have?

@dvdhrm
Copy link
Contributor Author

dvdhrm commented Jun 14, 2015

util-linux-2.26 is the version that introduced this monitor.

This is still WIP, so no reason to worry about Semaphore. If we end up merging it, we can always provide the old code as workaround.

@martinpitt
Copy link
Contributor

@dvdhrm @zonque : If it helps, I can provide a PPA with util-linux 2.26 backported to 14.04. It would be a shame to lose the semaphore builds from now on. (I run my distcheck tests in wily, i. e. the current development series; that has a current kernel, util-linux, etc.)

@dvdhrm
Copy link
Contributor Author

dvdhrm commented Jun 15, 2015

@martinpitt : That would be great! But lets first figure out how to solve the libmount root-only restriction. If that requires util-linux changes, we have to wait for a new release, anyway.

@karelzak
Copy link
Contributor

@dvdhrm:

This is still not ready to be merged. It currently breaks systemd --user as libmount
requires you to be root to monitor 'utab'. Reason for this is
userspace_monitor_get_fd()" in libmount, which calls open(O_CREAT) on the
utab-lockfile (why?).

inotify_add_watch() requires that the file you want to monitor already exists, otherwise you need to monitor all directory for all IN_CREATE events. It's painful because you need to care about filenames on event etc.

open(O_CREAT) is not problem for non-root user if the file already exists. So the question is why on "systemd --user" the file /run/mount/utab.lock does not exist if there is already running pid1 systemd that already monitoring the file. (or do you mix old pid1 systemd and new systemd --user? :-)

@poettering
Copy link
Member

@karelzak It's actually not that hard to handle situations where the dir doesn't exist. We recently added a similar fix to the sd-network stuff in 870395a. Please have a look!

@karelzak
Copy link
Contributor

@poettering I already had code to monitor all the directory, but it means that after each event you have to check filenames. The current implementation is simple and elegant, but unfortunately useless for non-root users :-(

I'll try to improve it...

@poettering
Copy link
Member

@karelzak the commit i linked avoids having to check file names. It only looks for IN_ISDIR, that's all...

@karelzak
Copy link
Contributor

@poettering I see, nice solution. Thanks.

The libmount should be fixed now (util-linux/util-linux@7dc0f5c). I guess we can wait for util-linux v2.27 (Jul/Aug 2015) rather than try to backport etc...

I'll send an updated version of the patch later (it's necessary to use mnt_monitor_next_change() to verify that an event is really about utab change).

BTW, I think there is a bug in sd_network_monitor_flush(), the code assumes that inotify_add_watch() always allocates a new FD so it's safe to remove the old watch
by inotify_rm_watch(fd, e->wd). But this is not true, for already monitored filesystem objects inotify_add_watch() returns the same (already used) FD.

I guess that "mkdir /run/systemd/netif/FOO" in situation you monitor /run/systemd/netif/ will remove the watch of the directory at all. IMHO you need something like:

karelzak@625671b (the patch is absolutely no tested, just my guess when I read the code :-))

@poettering
Copy link
Member

@karelzak hmm, makes sense... Though I figure we can simplify the patch a bit by simply returning the wd from monitor_add_inotify_watch() as return value, under the assumption it is strictly positive, and thus no ambiguity is created between returning an error and a wd.

@teg there's something to fix in sd-network!

@poettering poettering added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Jul 27, 2015
@karelzak
Copy link
Contributor

Please, close. Replaced by new version #986.

@dvdhrm dvdhrm closed this Aug 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pid1 reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks

Development

Successfully merging this pull request may close these issues.

5 participants