summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab.c
diff options
context:
space:
mode:
authorEric Rannaud2014-06-27 07:17:18 +0200
committerKarel Zak2014-07-01 10:03:40 +0200
commit0382ba32eda9e9d14d1e425390abf4b1fd1bda6b (patch)
treee1e5fb6d007d08628571e0b28e3557652711422e /libmount/src/tab.c
parentlibmount: mnt_resolve_path: don't canonicalize fs->target for swap (diff)
downloadkernel-qcow2-util-linux-0382ba32eda9e9d14d1e425390abf4b1fd1bda6b.tar.gz
kernel-qcow2-util-linux-0382ba32eda9e9d14d1e425390abf4b1fd1bda6b.tar.xz
kernel-qcow2-util-linux-0382ba32eda9e9d14d1e425390abf4b1fd1bda6b.zip
libmount: mnt_resolve_target: tiptoe around active mount points
Current code in mnt_fs_match_target() and mnt_table_find_target() already does not canonicalize active mount points (when read from mountinfo), because they are already canonicalized by the kernel. Calling realpath(fs->target) on a mount point can hang -- e.g. if the NFS server is unreachable. This patch optionally extends this strategy to the general case, that is when @fs does not directly come from the kernel through mountinfo (for instance, it may have been parsed from /etc/fstab). Given @mtab parsed from mountinfo, and if mnt_cache_set_targets(cache, mtab) is used, then mnt_fs_match_target() and mnt_table_find_target() check whether @fs->target is a known mount point in the cached mountinfo, before attempting to canonicalize @fs->target, no matter where @fs itself comes from. If found in the cached mountinfo, @fs->target is not canonicalized. [kzak@redhat.com: - don't allocate libmnt_iter, - add docs for mnt_cache_set_targets(), - fallback to mnt_resolve_path() if no cache->mtab specified, - use streq_except_trailing_slash() to compare paths] Signed-off-by: Eric Rannaud <e@nanocritical.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab.c')
-rw-r--r--libmount/src/tab.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/libmount/src/tab.c b/libmount/src/tab.c
index 77260ab96..fd6a7d8e2 100644
--- a/libmount/src/tab.c
+++ b/libmount/src/tab.c
@@ -880,8 +880,10 @@ struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
*
* Try to lookup an entry in the given tab, three iterations are possible, the first
* with @path, the second with realpath(@path) and the third with realpath(@path)
- * against realpath(fs->target). The 2nd and 3rd iterations are not performed
- * when the @tb cache is not set (see mnt_table_set_cache()).
+ * against realpath(fs->target). The 2nd and 3rd iterations are not performed when
+ * the @tb cache is not set (see mnt_table_set_cache()). If
+ * mnt_cache_set_targets(cache, mtab) was called, the 3rd iteration skips any
+ * @fs->target found in @mtab (see mnt_resolve_target()).
*
* Returns: a tab entry or NULL.
*/
@@ -933,7 +935,7 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
|| (*fs->target == '/' && *(fs->target + 1) == '\0'))
continue;
- p = mnt_resolve_path(fs->target, tb->cache);
+ p = mnt_resolve_target(fs->target, tb->cache);
/* both canonicalized, strcmp() is fine here */
if (p && strcmp(cn, p) == 0)
return fs;