summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2013-02-26 14:16:02 +0100
committerKarel Zak2013-02-26 14:16:53 +0100
commitdad88cb3573fd204971365fed6f7797c4b355946 (patch)
treecdb49606c0c0fa05ada3e5a3b6bbe9baea230ead
parentumount: improve --recursive docs (diff)
downloadkernel-qcow2-util-linux-dad88cb3573fd204971365fed6f7797c4b355946.tar.gz
kernel-qcow2-util-linux-dad88cb3573fd204971365fed6f7797c4b355946.tar.xz
kernel-qcow2-util-linux-dad88cb3573fd204971365fed6f7797c4b355946.zip
libmount: optimize tab files parsing
- ignore empty files - ignore empty tables Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--libmount/src/mountP.h2
-rw-r--r--libmount/src/tab_parse.c40
-rw-r--r--libmount/src/utils.c11
3 files changed, 33 insertions, 20 deletions
diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h
index 8eb677cdc..1b4ba687b 100644
--- a/libmount/src/mountP.h
+++ b/libmount/src/mountP.h
@@ -132,6 +132,8 @@ extern int endswith(const char *s, const char *sx)
extern int startswith(const char *s, const char *sx)
__attribute__((nonnull));
+extern int is_file_empty(const char *name);
+
extern int mkdir_p(const char *path, mode_t mode);
extern int mnt_is_readonly(const char *path)
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c
index a8b7b79d4..b4b647075 100644
--- a/libmount/src/tab_parse.c
+++ b/libmount/src/tab_parse.c
@@ -957,6 +957,7 @@ int mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename)
{
int rc;
const char *utab = NULL;
+ struct libmnt_table *u_tb;
if (mnt_has_regular_mtab(&filename, NULL)) {
@@ -980,34 +981,33 @@ int mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename)
return mnt_table_parse_file(tb, _PATH_PROC_MOUNTS);
}
+ if (mnt_table_get_nents(tb) == 0)
+ return 0; /* empty, ignore utab */
/*
* try to read user specific information from /run/mount/utabs
*/
utab = mnt_get_utab_path();
- if (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 (!utab || is_file_empty(utab))
+ return 0;
- if (u_tb) {
- struct libmnt_fs *u_fs;
- struct libmnt_iter itr;
+ u_tb = mnt_new_table();
+ if (!u_tb)
+ return -ENOMEM;
- mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
+ u_tb->fmt = MNT_FMT_UTAB;
+ mnt_table_set_parser_fltrcb(u_tb, tb->fltrcb, tb->fltrcb_data);
- /* merge user options into mountinfo from kernel */
- while(mnt_table_next_fs(u_tb, &itr, &u_fs) == 0)
- mnt_table_merge_user_fs(tb, u_fs);
+ if (mnt_table_parse_file(u_tb, utab) == 0) {
+ struct libmnt_fs *u_fs;
+ struct libmnt_iter itr;
- mnt_free_table(u_tb);
- }
+ mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
+
+ /* merge user options into mountinfo from kernel */
+ while(mnt_table_next_fs(u_tb, &itr, &u_fs) == 0)
+ mnt_table_merge_user_fs(tb, u_fs);
}
+
+ mnt_free_table(u_tb);
return 0;
}
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index 1c37062e6..1d4fd0e4b 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -54,6 +54,17 @@ int startswith(const char *s, const char *sx)
return !strncmp(s, sx, off);
}
+/*
+ * Return 1 if the file does not accessible of empty
+ */
+int is_file_empty(const char *name)
+{
+ struct stat st;
+ assert(name);
+
+ return (stat(name, &st) != 0 || st.st_size == 0);
+}
+
int mnt_parse_offset(const char *str, size_t len, uintmax_t *res)
{
char *p;