xfs
[Top] [All Lists]

[PATCH V2] xfstests: use stat not lstat when examining devices

To: xfs-oss <xfs@xxxxxxxxxxx>
Subject: [PATCH V2] xfstests: use stat not lstat when examining devices
From: Eric Sandeen <sandeen@xxxxxxxxxxx>
Date: Fri, 04 Jun 2010 12:36:57 -0500
In-reply-to: <4C091B4E.5030503@xxxxxxxxxxx>
References: <4C091B4E.5030503@xxxxxxxxxxx>
User-agent: Thunderbird 2.0.0.24 (Macintosh/20100228)
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.

Adding a -l option to lstat64 in order to call stat not lstat,
and stat the target of the link, should be a simple fix.

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxxx>
---

diff --git a/common.rc b/common.rc
index 6bf1e12..3539a43 100644
--- a/common.rc
+++ b/common.rc
@@ -584,7 +584,7 @@ _is_block_dev()
        exit 1
     fi
 
-    [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
+    [ -b $1 ] && src/lstat64 -l $1 | $AWK_PROG '/Device type:/ { print $9 }'
 }
 
 # Do a command, log it to $seq.full, optionally test return status
diff --git a/src/lstat64.c b/src/lstat64.c
index 3b68c66..c7c7106 100644
--- a/src/lstat64.c
+++ b/src/lstat64.c
@@ -49,7 +49,7 @@ timesince(long timesec)
 void
 usage(void)
 {
-       fprintf(stderr, "Usage: lstat64 [-t] filename ...\n");
+       fprintf(stderr, "Usage: lstat64 [-tl] filename ...\n");
        exit(1);
 }
 
@@ -59,13 +59,18 @@ main(int argc, char **argv)
        struct stat64   sbuf;
        int             i, c;
        int             terse_flag = 0;
+       int             follow_flag = 0;
 
-       while ((c = getopt(argc, argv, "t")) != EOF) {
+       while ((c = getopt(argc, argv, "tl")) != EOF) {
                switch (c) {
                        case 't':
                                terse_flag = 1;
                                break;
 
+                       case 'l':
+                               follow_flag = 1;
+                               break;
+
                        case '?':
                                usage();
                }
@@ -79,7 +84,10 @@ main(int argc, char **argv)
        for (i = optind; i < argc; i++) {
                char mode[] = "----------";
 
-               if( lstat64(argv[i], &sbuf) < 0) {
+               if (!follow_flag && lstat64(argv[i], &sbuf) < 0) {
+                       perror(argv[i]);
+                       continue;
+               } else if (follow_flag && stat64(argv[i], &sbuf) < 0) {
                        perror(argv[i]);
                        continue;
                }

<Prev in Thread] Current Thread [Next in Thread>