From: Eric Sandeen <sandeen@redhat.com>
To: xfs-oss <xfs@oss.sgi.com>
Cc: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Subject: [PATCH] xfsprogs: handle symlinks etc in fs_table_initialise_mounts()
Date: Mon, 30 Sep 2013 12:01:19 -0500 [thread overview]
Message-ID: <5249AE5F.30305@redhat.com> (raw)
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
next reply other threads:[~2013-09-30 17:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-30 17:01 Eric Sandeen [this message]
2013-10-14 20:46 ` [PATCH] xfsprogs: handle symlinks etc in fs_table_initialise_mounts() Dave Chinner
2013-10-18 17:18 ` Rich Johnston
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5249AE5F.30305@redhat.com \
--to=sandeen@redhat.com \
--cc=takeuchi_satoru@jp.fujitsu.com \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox