diff options
author | Eric Rannaud | 2014-06-27 07:17:18 +0200 |
---|---|---|
committer | Karel Zak | 2014-07-01 10:03:40 +0200 |
commit | 0382ba32eda9e9d14d1e425390abf4b1fd1bda6b (patch) | |
tree | e1e5fb6d007d08628571e0b28e3557652711422e /libmount/src/fs.c | |
parent | libmount: mnt_resolve_path: don't canonicalize fs->target for swap (diff) | |
download | kernel-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/fs.c')
-rw-r--r-- | libmount/src/fs.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libmount/src/fs.c b/libmount/src/fs.c index 21ef0f747..82541083a 100644 --- a/libmount/src/fs.c +++ b/libmount/src/fs.c @@ -1413,7 +1413,9 @@ int mnt_fs_append_comment(struct libmnt_fs *fs, const char *comm) * 1) compare @target with @fs->target * 2) realpath(@target) with @fs->target * 3) realpath(@target) with realpath(@fs->target) if @fs is not from - * /proc/self/mountinfo. + * /proc/self/mountinfo. However, if mnt_cache_set_targets(cache, + * mtab) was called, and the path @fs->target is found in @mtab, + * this comparison is not performed (see mnt_resolve_target()). * * The 2nd and 3rd attempts are not performed when @cache is NULL. * @@ -1438,7 +1440,7 @@ int mnt_fs_match_target(struct libmnt_fs *fs, const char *target, /* 3) - canonicalized and canonicalized */ if (!rc && cn && !mnt_fs_is_kernel(fs) && !mnt_fs_is_swaparea(fs)) { - char *tcn = mnt_resolve_path(fs->target, cache); + char *tcn = mnt_resolve_target(fs->target, cache); rc = (tcn && strcmp(cn, tcn) == 0); } } |