[PATCH] Add support for tracing multiple devices
[blktrace.git] / blktrace.h
CommitLineData
6fe4709e
JA
1#ifndef BLKTRACE_H
2#define BLKTRACE_H
d0ca268b 3
6fe4709e 4#include <byteswap.h>
d0ca268b 5#include <asm/types.h>
6fe4709e
JA
6#include <asm/byteorder.h>
7#include "blktrace_api.h"
d0ca268b 8
d0ca268b 9#define CHECK_MAGIC(t) (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
e7c9f3ff 10#define SUPPORTED_VERSION (0x05)
d0ca268b 11
6fe4709e
JA
12#if defined(__LITTLE_ENDIAN_BITFIELD)
13#define be16_to_cpu(x) __bswap_16(x)
14#define be32_to_cpu(x) __bswap_32(x)
15#define be64_to_cpu(x) __bswap_64(x)
16#define cpu_to_be16(x) __bswap_16(x)
17#define cpu_to_be32(x) __bswap_32(x)
18#define cpu_to_be64(x) __bswap_64(x)
19#elif defined(__BIG_ENDIAN_BITFIELD)
20#define be16_to_cpu(x) (x)
21#define be32_to_cpu(x) (x)
22#define be64_to_cpu(x) (x)
23#define cpu_to_be16(x) (x)
24#define cpu_to_be32(x) (x)
25#define cpu_to_be64(x) (x)
26#else
27#error "Bad arch"
28#endif
29
30static inline int verify_trace(struct blk_io_trace *t)
31{
32 if (!CHECK_MAGIC(t)) {
33 fprintf(stderr, "bad trace magic %x\n", t->magic);
34 return 1;
35 }
36 if ((t->magic & 0xff) != SUPPORTED_VERSION) {
37 fprintf(stderr, "unsupported trace version %x\n",
38 t->magic & 0xff);
39 return 1;
40 }
d0ca268b 41
6fe4709e
JA
42 return 0;
43}
d0ca268b 44
6fe4709e
JA
45static inline void trace_to_be(struct blk_io_trace *t)
46{
47 t->magic = cpu_to_be32(t->magic);
48 t->sequence = cpu_to_be32(t->sequence);
49 t->time = cpu_to_be64(t->time);
50 t->sector = cpu_to_be64(t->sector);
51 t->bytes = cpu_to_be32(t->bytes);
52 t->action = cpu_to_be32(t->action);
53 t->pid = cpu_to_be32(t->pid);
654aaa52 54 t->cpu = cpu_to_be32(t->cpu);
6fe4709e
JA
55 t->error = cpu_to_be16(t->error);
56 t->pdu_len = cpu_to_be16(t->pdu_len);
e7c9f3ff 57 t->device = cpu_to_be32(t->device);
654aaa52 58 /* t->comm is a string (endian neutral) */
6fe4709e 59}
d0ca268b 60
6fe4709e
JA
61static inline void trace_to_cpu(struct blk_io_trace *t)
62{
63 t->magic = be32_to_cpu(t->magic);
64 t->sequence = be32_to_cpu(t->sequence);
65 t->time = be64_to_cpu(t->time);
66 t->sector = be64_to_cpu(t->sector);
67 t->bytes = be32_to_cpu(t->bytes);
68 t->action = be32_to_cpu(t->action);
69 t->pid = be32_to_cpu(t->pid);
654aaa52 70 t->cpu = be32_to_cpu(t->cpu);
6fe4709e
JA
71 t->error = be16_to_cpu(t->error);
72 t->pdu_len = be16_to_cpu(t->pdu_len);
e7c9f3ff 73 t->device = be32_to_cpu(t->device);
654aaa52 74 /* t->comm is a string (endian neutral) */
6fe4709e 75}
d0ca268b
JA
76
77#endif