xfstests: resolve symlinked devices to real paths
authorEric Sandeen <sandeen@sandeen.net>
Tue, 8 Jun 2010 20:03:39 +0000 (20:03 +0000)
committerRich Johnston <rjohnston@sgi.com>
Fri, 26 Oct 2012 15:38:30 +0000 (10:38 -0500)
If you try running xfstests on lvm volumes which are symlinks,
it'll fail to run several tests because our _require_scratch
framework ultimately uses lstat not stat, and does not think
the lvm device (which is usually a symlink to a dm-X device)
is a block device.  Sigh.

Last try at this - just resolve any symlinked devicenames
into their realpath(3) in common.config.

This actually seems to work.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
Reviewed-by: Rich Johnston <rjohnston@sgi.com>
Signed-off-by: Rich Johnston <rjohnston@sgi.com>
common.config
src/realpath.c [new file with mode: 0644]

index 57f505de62d5f74669c5505288551592bb759e75..585b15050b59560ebaae9b2e2a06f1cf79bf3f36 100644 (file)
@@ -220,6 +220,15 @@ else
     known_hosts
 fi
 
     known_hosts
 fi
 
+# Scripts just don't deal well with symlinked devices
+if [ -L $TEST_DEV ]; then
+        TEST_DEV=`src/realpath $TEST_DEV`
+fi
+
+if [ -L $SCRATCH_DEV ]; then
+        SCRATCH_DEV=`src/realpath $SCRATCH_DEV`
+fi
+
 echo $TEST_DEV | grep -q ":" > /dev/null 2>&1
 if [ ! -b "$TEST_DEV" -a "$?" != "0" ]; then
     echo "common.config: Error: \$TEST_DEV ($TEST_DEV) is not a block device or a NFS filesystem"
 echo $TEST_DEV | grep -q ":" > /dev/null 2>&1
 if [ ! -b "$TEST_DEV" -a "$?" != "0" ]; then
     echo "common.config: Error: \$TEST_DEV ($TEST_DEV) is not a block device or a NFS filesystem"
diff --git a/src/realpath.c b/src/realpath.c
new file mode 100644 (file)
index 0000000..997b1aa
--- /dev/null
@@ -0,0 +1,32 @@
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+/*
+ * Simple wrapper around realpath(3) to get absolute path
+ * to a device name; many xfstests scripts don't cope well
+ * with symlinked devices due to differences in /proc/mounts,
+ * /etc/mtab, mount output, etc.
+ */
+
+int main(int argc, char *argv[])
+{
+       char path[PATH_MAX];
+       char resolved_path[PATH_MAX];
+
+       if (argc != 2) {
+               printf("Usage: %s <filename>\n", argv[0]);
+               return 1;
+       }
+
+       strncpy(path, argv[1], PATH_MAX-1);
+
+       if (!realpath(path, resolved_path)) {
+               perror("Failed to resolve path for %s");
+               return 1;
+       }
+
+       printf("%s\n", resolved_path);
+       return 0;
+}