From 6a52473ecd877227f6f7da2b95da0b51593ffec1 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 3 Mar 2014 10:36:15 +0100 Subject: umount: don't use mountinfo if possible The umount(8) always parses /proc/self/mountinfo to get fstype and to merge kernel mount options with userspace mount options from /run/mount/utab. This behavior is overkill in many cases and it's pretty expensive as kernel has to always compose *whole* mountinfo. This performance disadvantage is visible for crazy use-cases with huge number of mountpoints and frequently called umount(8). It seems that we can bypass /proc/self/mountinfo by statfs() to get filesystem type (statfs.f_type magic) and analyze /run/mount/utab before we parse mountinfo. This optimization is not used when: * umount(8) executed by non-root (as user= in utab is expected) * umount --lazy / --force (target is probably unreachable NFS, then use statfs() is pretty bad idea) * target is not a directory (e.g. umount /dev/sda1) * there is (deprecated) writeable mtab Reported-by: Al Viro Signed-off-by: Karel Zak --- libmount/src/context.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'libmount/src/context.c') diff --git a/libmount/src/context.c b/libmount/src/context.c index 2ef3d3001..f1077968f 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -136,12 +136,14 @@ int mnt_reset_context(struct libmnt_context *cxt) mnt_unref_fs(cxt->fs); mnt_unref_table(cxt->mtab); + mnt_unref_table(cxt->utab); free(cxt->helper); free(cxt->orig_user); cxt->fs = NULL; cxt->mtab = NULL; + cxt->utab = NULL; cxt->helper = NULL; cxt->orig_user = NULL; cxt->mountflags = 0; @@ -158,7 +160,9 @@ int mnt_reset_context(struct libmnt_context *cxt) } mnt_context_reset_status(cxt); - mnt_context_set_tabfilter(cxt, NULL, NULL); + + if (cxt->table_fltrcb) + mnt_context_set_tabfilter(cxt, NULL, NULL); /* restore non-resettable flags */ cxt->flags |= (fl & MNT_FL_NOMTAB); @@ -980,7 +984,12 @@ int mnt_context_get_mtab(struct libmnt_context *cxt, struct libmnt_table **tb) cxt->table_fltrcb_data); mnt_table_set_cache(cxt->mtab, mnt_context_get_cache(cxt)); - rc = mnt_table_parse_mtab(cxt->mtab, cxt->mtab_path); + if (cxt->utab) + /* utab already parsed, don't parse it again */ + rc = __mnt_table_parse_mtab(cxt->mtab, + cxt->mtab_path, cxt->utab); + else + rc = mnt_table_parse_mtab(cxt->mtab, cxt->mtab_path); if (rc) return rc; } @@ -1013,7 +1022,7 @@ int mnt_context_set_tabfilter(struct libmnt_context *cxt, cxt->table_fltrcb, cxt->table_fltrcb_data); - DBG(CXT, mnt_debug_h(cxt, "tabfiler %s", fltr ? "ENABLED!" : "disabled")); + DBG(CXT, mnt_debug_h(cxt, "tabfilter %s", fltr ? "ENABLED!" : "disabled")); return 0; } -- cgit v1.2.3-55-g7522