summaryrefslogtreecommitdiffstats
path: root/libmount/src/context_umount.c
diff options
context:
space:
mode:
authorKarel Zak2012-09-25 16:47:18 +0200
committerKarel Zak2012-09-25 16:47:18 +0200
commit4709c9e6a19f46bbd085199607438b5ec9f0b0f6 (patch)
tree3176bafe0b5e6377efff421c46672d7b1415a54d /libmount/src/context_umount.c
parentlibmount: user-mounted loopback fs cannot be unmounted by user (diff)
downloadkernel-qcow2-util-linux-4709c9e6a19f46bbd085199607438b5ec9f0b0f6.tar.gz
kernel-qcow2-util-linux-4709c9e6a19f46bbd085199607438b5ec9f0b0f6.tar.xz
kernel-qcow2-util-linux-4709c9e6a19f46bbd085199607438b5ec9f0b0f6.zip
libmount: optimize mtab and utab parsing in umount
create 8000 NFS mountpoints: #!/bin/bash mount=/tmp/mount if [ ! -d $mount ]; then mkdir -p $mount fi for dir in {1..8000}; do if [ ! -d $mount/$dir ]; then mkdir -p $mount/$dir fi echo mount $dir mount -t nfs 127.0.0.1:/ $mount/$dir done old version: time ./umount /tmp/mount/2255 real 0m1.254s user 0m1.002s sys 0m0.238s new version: time ./umount /tmp/mount/2244 real 0m0.332s user 0m0.111s sys 0m0.218s Reported-by: chenditang <chendt.fnst@cn.fujitsu.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/context_umount.c')
-rw-r--r--libmount/src/context_umount.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index 17ec1f0a4..566bb2115 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -38,6 +38,20 @@
# define UMOUNT_UNUSED 0x80000000 /* Flag guaranteed to be unused */
#endif
+/*
+ * Called by mtab parser to filter out entries, nonzero means that
+ * entry has to be filter out.
+ */
+static int mtab_filter(struct libmnt_fs *fs, void *data)
+{
+ if (!fs || !data)
+ return 0;
+ if (mnt_fs_streq_target(fs, data))
+ return 0;
+ if (mnt_fs_streq_srcpath(fs, data))
+ return 0;
+ return 1;
+}
static int lookup_umount_fs(struct libmnt_context *cxt)
{
@@ -45,6 +59,8 @@ static int lookup_umount_fs(struct libmnt_context *cxt)
const char *tgt;
struct libmnt_table *mtab = NULL;
struct libmnt_fs *fs;
+ struct libmnt_cache *cache = NULL;
+ char *cn_tgt = NULL;
assert(cxt);
assert(cxt->fs);
@@ -56,7 +72,32 @@ static int lookup_umount_fs(struct libmnt_context *cxt)
DBG(CXT, mnt_debug_h(cxt, "umount: undefined target"));
return -EINVAL;
}
+
+ /*
+ * The mtab file maybe huge and on systems with utab we have to merge
+ * userspace mount options into /proc/self/mountinfo. This all is
+ * expensive. The mtab filter allows to filter out entries, then
+ * mtab and utab are very tiny files.
+ *
+ * *but*... the filter uses mnt_fs_streq_{target,srcpath} functions
+ * where LABEL, UUID or symlinks are to canonicalized. It means that
+ * it's usable only for canonicalized stuff (e.g. kernel mountinfo).
+ */
+ if (!cxt->mtab_writable && *tgt == '/') {
+ /* we'll canonicalized /proc/self/mountinfo */
+ cache = mnt_context_get_cache(cxt);
+ cn_tgt = mnt_resolve_path(tgt, cache);
+ if (cn_tgt)
+ mnt_context_set_tabfilter(cxt, mtab_filter, cn_tgt);
+ }
rc = mnt_context_get_mtab(cxt, &mtab);
+
+ if (cn_tgt) {
+ mnt_context_set_tabfilter(cxt, NULL, NULL);
+ if (!cache)
+ free(cn_tgt);
+ }
+
if (rc) {
DBG(CXT, mnt_debug_h(cxt, "umount: failed to read mtab"));
return rc;