[PATCH] blktrace: better check for mounted relayfs
authorNathan Scott <nathans@sgi.com>
Thu, 15 Sep 2005 07:31:12 +0000 (09:31 +0200)
committerJens Axboe <axboe@suse.de>
Thu, 15 Sep 2005 07:31:12 +0000 (09:31 +0200)
Don't just check for the presence of the directory, also check whether
relayfs really is mounted there.

blktrace.c

index 0e12d10e0973e15fa23af3638aec2a384754d359..b03f7d1f144e91a4ab0acc0fad16608fce77ab24 100644 (file)
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <sys/ioctl.h>
 #include <sys/param.h>
+#include <sys/statfs.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sched.h>
@@ -39,6 +40,8 @@
 #define BUF_SIZE       (128 *1024)
 #define BUF_NR         (4)
 
+#define RELAYFS_TYPE   0xF0B4A981
+
 #define DECLARE_MASK_MAP(mask)          { BLK_TC_##mask, #mask, "BLK_TC_"#mask }
 #define COMPARE_MASK_MAP(mmp, str)                                      \
         (!strcasecmp((mmp)->short_form, (str)) ||                      \
@@ -533,7 +536,7 @@ static void handle_sigint(int sig)
 int main(int argc, char *argv[])
 {
        static char default_relay_path[] = "/relay";
-       struct stat st;
+       struct statfs st;
        int i, c;
        int stop_watch = 0;
        int act_mask_tmp = 0;
@@ -607,8 +610,13 @@ int main(int argc, char *argv[])
        if (act_mask_tmp != 0)
                act_mask = act_mask_tmp;
 
-       if (stat(relay_path, &st) < 0) {
-               fprintf(stderr,"%s does not appear to be mounted\n",
+       if (statfs(relay_path, &st) < 0) {
+               perror("statfs");
+               fprintf(stderr,"%s does not appear to be a valid path\n",
+                       relay_path);
+               return 1;
+       } else if (st.f_type != RELAYFS_TYPE) {
+               fprintf(stderr,"%s does not appear to be a relay filesystem\n",
                        relay_path);
                return 1;
        }