diff options
author | Karel Zak | 2014-11-19 11:07:11 +0100 |
---|---|---|
committer | Karel Zak | 2014-11-19 11:07:11 +0100 |
commit | e713e11d4c468efd19b6532821d2003eafa7ca94 (patch) | |
tree | 072a26c69c2bfab96178fe7d6e2b624ba53f3aaf /libmount/src/tab_parse.c | |
parent | libmount: improve mnt_reset_fs() (diff) | |
download | kernel-qcow2-util-linux-e713e11d4c468efd19b6532821d2003eafa7ca94.tar.gz kernel-qcow2-util-linux-e713e11d4c468efd19b6532821d2003eafa7ca94.tar.xz kernel-qcow2-util-linux-e713e11d4c468efd19b6532821d2003eafa7ca94.zip |
libmount: reuse allocated fs in parser
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab_parse.c')
-rw-r--r-- | libmount/src/tab_parse.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 06c5bd469..58b71ca4e 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -599,6 +599,7 @@ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filenam int rc = -1; int flags = 0; pid_t tid = -1; + struct libmnt_fs *fs = NULL; assert(tb); assert(f); @@ -615,10 +616,11 @@ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filenam flags = MNT_FS_KERNEL; while (!feof(f)) { - struct libmnt_fs *fs = mnt_new_fs(); - - if (!fs) - goto err; + if (!fs) { + fs = mnt_new_fs(); + if (!fs) + goto err; + } rc = mnt_table_parse_next(tb, f, fs, filename, &nlines); @@ -632,15 +634,21 @@ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filenam if (rc == 0 && tb->fmt == MNT_FMT_MOUNTINFO) rc = kernel_fs_postparse(tb, fs, &tid, filename); } - mnt_unref_fs(fs); if (rc) { - if (rc == 1) - continue; /* recoverable error */ + if (rc == 1) { + mnt_reset_fs(fs); + assert(fs->refcount == 1); + continue; /* recoverable error, reuse fs*/ + } + + mnt_unref_fs(fs); if (feof(f)) break; goto err; /* fatal error */ } + mnt_unref_fs(fs); + fs = NULL; } DBG(TAB, ul_debugobj(tb, "%s: stop parsing (%d entries)", |