From: Jens Axboe Date: Mon, 29 Aug 2005 08:14:11 +0000 (+0200) Subject: [PATCH] Don't overwrite magic in trace X-Git-Tag: blktrace-0.99~235 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=66fa7233b208860dae3c4ce7be1f5c1e93078720;p=blktrace.git [PATCH] Don't overwrite magic in trace 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. --- diff --git a/CHANGELOG b/CHANGELOG index 2202b6a..8975f71 100644 --- 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: diff --git a/blkparse.c b/blkparse.c index 342f5f6..9f60dcf 100644 --- a/blkparse.c +++ b/blkparse.c @@ -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; diff --git a/blktrace.c b/blktrace.c index 58ae222..1064bd4 100644 --- a/blktrace.c +++ b/blktrace.c @@ -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);