[PATCH] blktrace: need to free ts->buf for networked transfer
[blktrace.git] / blkrawverify.c
index 79fa56778d488ffe061e34f0a159d09cf9cf2536..238c3ab7c7c71de0da739a827bc7e801b1e9a8ef 100644 (file)
@@ -33,6 +33,8 @@ struct trace_info {
        char *string;
 };
 
+int data_is_native = -1;
+
 #define TRACE_TO_STRING(f)     {.bit_field = f, .string = #f}
 static struct trace_info traces[] = {
        TRACE_TO_STRING( BLK_TC_READ ),
@@ -148,12 +150,21 @@ static int process(FILE *ofp, char *file, unsigned int cpu)
 
        ifp = fopen(file, "r");
        while ((n = fread(bit, sizeof(struct blk_io_trace), 1, ifp)) == 1) {
+               if (data_is_native == -1)
+                       check_data_endianness(bit->magic);
+
                trace_to_cpu(bit);
-               if (verify_trace(bit)) {
+
+               if (!CHECK_MAGIC(bit)) {
                        INC_BAD("bad trace");
                        continue;
                }
 
+               if ((bit->magic & 0xff) != SUPPORTED_VERSION) {
+                       fprintf(stderr, "unsupported trace version\n");
+                       break;
+               }
+
                if (bit->pdu_len) {
                        char *pdu_buf;
 
@@ -173,6 +184,12 @@ static int process(FILE *ofp, char *file, unsigned int cpu)
                        continue;
                }
 
+               /*
+                * skip notify traces, they don't have valid sequences
+                */
+               if (bit->action & BLK_TC_ACT(BLK_TC_NOTIFY))
+                       continue;
+
                if (ngood) {
                        if (bit->sequence <= save_sequence) {
                                INC_BAD("bad seq");
@@ -199,7 +216,7 @@ static int process(FILE *ofp, char *file, unsigned int cpu)
                SWAP_BITS();
        }
 
-       if (n == 0)
+       if (n == 0 && !feof(ifp))
                fprintf(stderr,"%s: fread failed %d/%s\n",
                        file, errno, strerror(errno));
        fclose(ifp);
@@ -268,6 +285,7 @@ int main(int argc, char *argv[])
                        printf("\n");
                }
                fclose(ofp);
+               fprintf(stdout, "Wrote output to %s\n", ofname);
        }
 
        return 0;