Richard W.M. Jones
2011-Feb-03 10:40 UTC
[Libguestfs] [PATCH] daemon: Parse /proc/mounts instead of /etc/mtab
This is a better alternative to: https://www.redhat.com/archives/libguestfs/2011-February/msg00006.html Tested by running 'make check'. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org -------------- next part -------------->From 61a1a2b71c4811b9d6233a43db74229b9364f0c6 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Thu, 3 Feb 2011 09:39:49 +0000 Subject: [PATCH] daemon: Parse /proc/mounts instead of /etc/mtab Since Fedora util-linux 2.19, the %post script does: rm -f /etc/mtab ln -s /proc/mounts /etc/mtab We are no longer running %post scripts, so this means that /etc/mtab is a plain file in the appliance. Usual 'mount' still updates it, but for some reason mount.ntfs does *not* update it in Fedora 15, meaning that you couldn't mount and then operate on NTFS partitions. It seems better to always parse /proc/mounts (ie. what the kernel thinks is mounted) unconditionally, rather than relying on the capriciousness of the external mount command. Therefore, parse /proc/mounts instead of /etc/mtab, but add a note saying that in future we should really be parsing /proc/self/mountinfo, but that needs a custom parser, and the format is rather tricky: http://lxr.linux.no/#linux+v2.6.37/Documentation/filesystems/proc.txt#L1462 --- daemon/mount.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/daemon/mount.c b/daemon/mount.c index c584f81..0c990c3 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -40,9 +40,12 @@ is_root_mounted (void) FILE *fp; struct mntent *m; - fp = setmntent ("/etc/mtab", "r"); + /* NB: Eventually we should aim to parse /proc/self/mountinfo, but + * that requires custom parsing code. + */ + fp = setmntent ("/proc/mounts", "r"); if (fp == NULL) { - perror ("/etc/mtab"); + perror ("/proc/mounts"); exit (EXIT_FAILURE); } -- 1.7.3.5
Possibly Parallel Threads
- [PATCH] appliance: Force /etc/mtab to be a symlink to /proc/mounts
- [PATCH] daemon: Parse output of old parted which didn't support -m option (RHBZ#598309).
- [PATCH] umount-all: Use /proc/mounts instead of output of 'mount' command.
- [bug] mount and /proc/mounts disagrees
- Very high system load: Samba statfs call for filesystems in /etc/mtab in: fileid_load_mount_entries()