[PATCH] Don't overwrite magic in trace
authorJens Axboe <axboe@wiggum>
Mon, 29 Aug 2005 08:14:11 +0000 (10:14 +0200)
committerJens Axboe <axboe@wiggum>
Mon, 29 Aug 2005 08:14:11 +0000 (10:14 +0200)
Leave the _dat file traces completely intact, get the CPU number from the
file in blkparse instead. Without this change, it's impossible for other
users to verify the sanity and version of a trace.

CHANGELOG
blkparse.c
blktrace.c

index 2202b6a249779a2f8001c8012335cbb0cf47b87b..8975f71379e99f4dad5669561bd5c8ee3ebaf721 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,8 +1,11 @@
-20050828:
+20050829:
        - Improved error handling
        - Remove _dat files, include the payload in _out
        - Support for payload > 64 bytes
        - Add install target
+       - Fix RELAYFS Kconfig selection (kernel patch)
+       - blktrace: Don't touch the stored trace, leave magic and version
+         for blkparse to see as well.
 20050827:
        - Various cleanups and killing unused variables
 20050826:
index 342f5f61e9130f60ab1e399ef5acf754703c7895..9f60dcf48e098b271fa5470015f2703a1545adc9 100644 (file)
@@ -28,6 +28,7 @@ static struct rb_root rb_root;
 
 struct trace {
        struct blk_io_trace *bit;
+       unsigned int cpu;
        struct rb_node rb_node;
 };
 
@@ -290,7 +291,22 @@ static inline int trace_rb_insert(struct trace *t)
        return 0;
 }
 
-static int sort_entries(void *traces, unsigned long offset)
+static inline int verify_trace(struct blk_io_trace *t)
+{
+       if (!CHECK_MAGIC(t)) {
+               fprintf(stderr, "bad trace magic %x\n", t->magic);
+               return 1;
+       }
+       if ((t->magic & 0xff) != SUPPORTED_VERSION) {
+               fprintf(stderr, "unsupported trace version %x\n", 
+                       t->magic & 0xff);
+               return 1;
+       }
+
+       return 0;
+}
+
+static int sort_entries(void *traces, unsigned long offset, int cpu)
 {
        struct blk_io_trace *bit;
        struct trace *t;
@@ -303,8 +319,12 @@ static int sort_entries(void *traces, unsigned long offset)
                bit = traces;
                t = malloc(sizeof(*t));
                t->bit = bit;
+               t->cpu = cpu;
                memset(&t->rb_node, 0, sizeof(t->rb_node));
 
+               if (verify_trace(bit))
+                       break;
+
                if (trace_rb_insert(t))
                        return -1;
 
@@ -330,7 +350,7 @@ static void show_entries(void)
                t = rb_entry(n, struct trace, rb_node);
                bit = t->bit;
 
-               cpu = bit->magic;
+               cpu = t->cpu;
                if (cpu > max_cpus) {
                        fprintf(stderr, "CPU number too large (%d)\n", cpu);
                        break;
@@ -400,7 +420,7 @@ int main(int argc, char *argv[])
                        break;
                }
 
-               ret = sort_entries(tb, st.st_size);
+               ret = sort_entries(tb, st.st_size, i);
                if (ret == -1)
                        break;
 
index 58ae2222d22b3de8ed0d643ad9a5dbd82b748fef..1064bd4ae9382c0b0e6d890e484dd893b79e64ec 100644 (file)
@@ -176,8 +176,6 @@ static void *extract(void *arg)
                if (verify_trace(&t))
                        exit(1);
 
-               /* version is verified, stuff with CPU number now */
-               t.magic = tip->cpu;
                ret = write(ofd, &t, sizeof(t));
                if (ret < 0) {
                        perror(op);