* [PATCH] xfsprogs: handle symlinks etc in fs_table_initialise_mounts()
@ 2013-09-30 17:01 Eric Sandeen
2013-10-14 20:46 ` Dave Chinner
2013-10-18 17:18 ` Rich Johnston
0 siblings, 2 replies; 3+ messages in thread
From: Eric Sandeen @ 2013-09-30 17:01 UTC (permalink / raw)
To: xfs-oss; +Cc: Satoru Takeuchi
Commit:
6a23747d xfs_quota: support relative path as `path' arguments
used realpath() on the supplied pathname to handle things like
relative pathnames and pathnames ending in "/" which otherwise
caused the getmntent scanning to fail.
However, this regressed cases where a path in mtab was a symlink;
realpath() resolves this to the target, and so no match is found.
This causes i.e.:
# xfs_quota -x -c report /dev/mapper/testvg-testlv
to fail with:
xfs_quota: cannot setup path for mount /dev/mapper/testvg-testlv: No such device or address
because the scanning looks for /dev/dm-3, but the long symlink
name is what exists in mtab, and no match is found.
Fix this, but keep the intended enhancements, by testing *both* the
user-specified path (which might be relative, or contain a trailing
slash on a mountpoint) and the realpath-resolved path (which turns
a relative mountpoint into a full path, and removes trailing slashes),
to determine whether the user-specified path is an xfs mountpoint or
device.
While we're at it, add a few comments, and go back to the testing
of "path" not "rpath"; whether or not path is passed to the function
is what determines control flow. If path is specified, and realpath
succeeds, we're guaranteed to have rpath as well, so there is no need
to retest that. rpath is initialized to NULL, so an unconditional
free(rpath) is safe as well.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/libxcmd/paths.c b/libxcmd/paths.c
index bd84cde..7b0e434 100644
--- a/libxcmd/paths.c
+++ b/libxcmd/paths.c
@@ -266,6 +266,10 @@ out_nomem:
return ENOMEM;
}
+/*
+ * If *path is NULL, initialize the fs table with all xfs mount points in mtab
+ * If *path is specified, search for that path in mtab
+ */
static int
fs_table_initialise_mounts(
char *path)
@@ -288,6 +292,7 @@ fs_table_initialise_mounts(
if ((mtp = setmntent(mtab_file, "r")) == NULL)
return ENOENT;
+ /* Use realpath to resolve symlinks, relative paths, etc */
if (path)
if ((rpath = realpath(path, NULL)) == NULL)
return ENOENT;
@@ -295,31 +300,37 @@ fs_table_initialise_mounts(
while ((mnt = getmntent(mtp)) != NULL) {
if (strcmp(mnt->mnt_type, "xfs") != 0)
continue;
- if (rpath &&
- ((strcmp(rpath, mnt->mnt_dir) != 0) &&
+ if (path &&
+ ((strcmp(path, mnt->mnt_dir) != 0) &&
+ (strcmp(path, mnt->mnt_fsname) != 0) &&
+ (strcmp(rpath, mnt->mnt_dir) != 0) &&
(strcmp(rpath, mnt->mnt_fsname) != 0)))
continue;
if (fs_extract_mount_options(mnt, &fslog, &fsrt))
continue;
(void) fs_table_insert(mnt->mnt_dir, 0, FS_MOUNT_POINT,
mnt->mnt_fsname, fslog, fsrt);
- if (rpath) {
+ if (path) {
found = 1;
break;
}
}
endmntent(mtp);
- if (rpath) {
- free(rpath);
- if (!found)
- error = ENXIO;
- }
+ free(rpath);
+
+ if (path && !found)
+ error = ENXIO;
+
return error;
}
#elif defined(HAVE_GETMNTINFO)
#include <sys/mount.h>
+/*
+ * If *path is NULL, initialize the fs table with all xfs mount points in mtab
+ * If *path is specified, search for that path in mtab
+ */
static int
fs_table_initialise_mounts(
char *path)
@@ -335,6 +346,7 @@ fs_table_initialise_mounts(
return 0;
}
+ /* Use realpath to resolve symlinks, relative paths, etc */
if (path)
if ((rpath = realpath(path, NULL)) == NULL)
return ENOENT;
@@ -342,24 +354,24 @@ fs_table_initialise_mounts(
for (i = 0; i < count; i++) {
if (strcmp(stats[i].f_fstypename, "xfs") != 0)
continue;
- if (rpath &&
- ((strcmp(rpath, stats[i].f_mntonname) != 0) &&
+ if (path &&
+ ((strcmp(path, stats[i].f_mntonname) != 0) &&
+ (strcmp(path, stats[i].f_mntfromname) != 0) &&
+ (strcmp(rpath, stats[i].f_mntonname) != 0) &&
(strcmp(rpath, stats[i].f_mntfromname) != 0)))
continue;
/* TODO: external log and realtime device? */
(void) fs_table_insert(stats[i].f_mntonname, 0,
FS_MOUNT_POINT, stats[i].f_mntfromname,
NULL, NULL);
- if (rpath) {
+ if (path) {
found = 1;
break;
}
}
- if (rpath) {
- free(rpath);
- if (!found)
- error = ENXIO;
- }
+ free(rpath);
+ if (path && !found)
+ error = ENXIO;
return error;
}
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] xfsprogs: handle symlinks etc in fs_table_initialise_mounts()
2013-09-30 17:01 [PATCH] xfsprogs: handle symlinks etc in fs_table_initialise_mounts() Eric Sandeen
@ 2013-10-14 20:46 ` Dave Chinner
2013-10-18 17:18 ` Rich Johnston
1 sibling, 0 replies; 3+ messages in thread
From: Dave Chinner @ 2013-10-14 20:46 UTC (permalink / raw)
To: Eric Sandeen; +Cc: Satoru Takeuchi, xfs-oss
On Mon, Sep 30, 2013 at 12:01:19PM -0500, Eric Sandeen wrote:
> Commit:
>
> 6a23747d xfs_quota: support relative path as `path' arguments
>
> used realpath() on the supplied pathname to handle things like
> relative pathnames and pathnames ending in "/" which otherwise
> caused the getmntent scanning to fail.
>
> However, this regressed cases where a path in mtab was a symlink;
> realpath() resolves this to the target, and so no match is found.
>
> This causes i.e.:
>
> # xfs_quota -x -c report /dev/mapper/testvg-testlv
>
> to fail with:
>
> xfs_quota: cannot setup path for mount /dev/mapper/testvg-testlv: No such device or address
>
> because the scanning looks for /dev/dm-3, but the long symlink
> name is what exists in mtab, and no match is found.
>
> Fix this, but keep the intended enhancements, by testing *both* the
> user-specified path (which might be relative, or contain a trailing
> slash on a mountpoint) and the realpath-resolved path (which turns
> a relative mountpoint into a full path, and removes trailing slashes),
> to determine whether the user-specified path is an xfs mountpoint or
> device.
>
> While we're at it, add a few comments, and go back to the testing
> of "path" not "rpath"; whether or not path is passed to the function
> is what determines control flow. If path is specified, and realpath
> succeeds, we're guaranteed to have rpath as well, so there is no need
> to retest that. rpath is initialized to NULL, so an unconditional
> free(rpath) is safe as well.
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
Looks good. There's a bunch of minor cleanups that could be done to
this code, but save that for a rainy day...
Reviewed-by: Dave Chinner <dchinner@redhat.com>
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xfsprogs: handle symlinks etc in fs_table_initialise_mounts()
2013-09-30 17:01 [PATCH] xfsprogs: handle symlinks etc in fs_table_initialise_mounts() Eric Sandeen
2013-10-14 20:46 ` Dave Chinner
@ 2013-10-18 17:18 ` Rich Johnston
1 sibling, 0 replies; 3+ messages in thread
From: Rich Johnston @ 2013-10-18 17:18 UTC (permalink / raw)
To: Eric Sandeen, xfs-oss; +Cc: Satoru Takeuchi
This has been committed.
Thanks
--Rich
commit 050a7f1f79314470c18e9d11c28daf75dd959830
Author: Eric Sandeen <sandeen@redhat.com>
Date: Mon Sep 30 17:01:19 2013 +0000
xfsprogs: handle symlinks etc in fs_table_initialise_mounts()
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-10-18 17:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-30 17:01 [PATCH] xfsprogs: handle symlinks etc in fs_table_initialise_mounts() Eric Sandeen
2013-10-14 20:46 ` Dave Chinner
2013-10-18 17:18 ` Rich Johnston
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox