[systemd-devel] [PATCH] Re: fstab mounts get unmounted during boot (.device unit bouncing?) -- solution

Martin Pitt martin.pitt at ubuntu.com
Thu Feb 12 02:58:31 PST 2015


Lennart Poettering [2015-02-12 11:22 +0100]:
> > To make systemd robust against this, I fixed
> > mount_load_proc_self_mountinfo() to actually do what it intends to do,
> > instead of loading /etc/mtab (which is still util-linux' default for
> > mnt_table_parse_mtab()).
> 
> Urks, we never want to read /etc/mtab from PID 1, indeed. I am a bit
> puzzled by mnt_table_parse_mtab() thiugh. The name suggests it parses
> /etc/mtab files (which have the same format as /proc/self/mounts). But
> Can we really just arse /proc/self/mountinfo to it, which has a very
> different format?

Yes, it arses it just fine :-) It supports the mtab, the fstab, and
the mountinfo format:

  https://github.com/karelzak/util-linux/blob/master/libmount/src/tab_parse.c#L1047

If you don't specify a file name, it defaults to /etc/mtab;
mnt_has_regular_mtab() checks if /etc/mtab is a regular file, and if
so, parses it as mtab format; if it's a symlink, then
mnt_has_regular_mtab() is false. (See
https://github.com/karelzak/util-linux/blob/master/libmount/src/utils.c#L772)

If the passed filename (or /etc/mtab default) is a symlink, it falls
back to line 1068 ff. where it ignores filename entirely. It first
tries to parse /proc/self/mountinfo as MNT_FMT_MOUNTINFO, and if that
fails, it falls back to parsing /proc/mounts (in old _PATH_PROC_MOUNTS
format, i. e. mtab).

So it doesn't matter that much what filename is, as long as it's not
NULL or /etc/mtab, but for readability I still suggest using
"/proc/self/mountinfo", as that's what it will actually end up
reading.

FTR, I added a log_debug() to it (not contained in the submitted
patch) and tested it with regular /etc/mtab, a symlink to /proc/mounts
and a symlink to /proc/self/mountinfo, and it comes out just fine.

Thanks,

Martin

-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)


More information about the systemd-devel mailing list