diff options
author | Karel Zak | 2012-09-25 16:47:18 +0200 |
---|---|---|
committer | Karel Zak | 2012-09-25 16:47:18 +0200 |
commit | 4709c9e6a19f46bbd085199607438b5ec9f0b0f6 (patch) | |
tree | 3176bafe0b5e6377efff421c46672d7b1415a54d /libmount/src/tab_parse.c | |
parent | libmount: user-mounted loopback fs cannot be unmounted by user (diff) | |
download | kernel-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/tab_parse.c')
-rw-r--r-- | libmount/src/tab_parse.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index ab5d51acd..a9a8f0fb2 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -487,6 +487,10 @@ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filenam goto err; rc = mnt_table_parse_next(tb, f, fs, filename, &nlines); + + if (!rc && tb->fltrcb && tb->fltrcb(fs, tb->fltrcb_data)) + rc = 1; /* filtered out by callback... */ + if (!rc) { rc = mnt_table_add_fs(tb, fs); fs->flags |= flags; @@ -756,6 +760,22 @@ int mnt_table_set_parser_errcb(struct libmnt_table *tb, return 0; } +/* + * Filter out entries during tab file parsing. If @cb returns 1 then the entry + * is ignored. + */ +int mnt_table_set_parser_fltrcb(struct libmnt_table *tb, + int (*cb)(struct libmnt_fs *, void *), + void *data) +{ + assert(tb); + + DBG(TAB, mnt_debug_h(tb, "set table parser filter")); + tb->fltrcb = cb; + tb->fltrcb_data = data; + return 0; +} + /** * mnt_table_parse_swaps: * @tb: table @@ -925,7 +945,16 @@ int mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename) */ utab = mnt_get_utab_path(); if (utab) { - struct libmnt_table *u_tb = __mnt_new_table_from_file(utab, MNT_FMT_UTAB); + struct libmnt_table *u_tb = mnt_new_table(); + if (u_tb) { + u_tb->fmt = MNT_FMT_UTAB; + mnt_table_set_parser_fltrcb(u_tb, tb->fltrcb, tb->fltrcb_data); + + if (mnt_table_parse_file(u_tb, utab) != 0) { + mnt_free_table(u_tb); + u_tb = NULL; + } + } if (u_tb) { struct libmnt_fs *u_fs; |