summaryrefslogtreecommitdiff
path: root/blktrace.h
diff options
context:
space:
mode:
authorJens Axboe <axboe@apu.(none)>2005-08-29 09:45:41 +0200
committerJens Axboe <axboe@apu.(none)>2005-08-29 09:45:41 +0200
commit6fe4709e97f29162e075f029a2ce6a7c4a444ef1 (patch)
treea1e428720c0bda044ca5edd664ff763f6190c790 /blktrace.h
parent66fa7233b208860dae3c4ce7be1f5c1e93078720 (diff)
downloadblktrace-6fe4709e97f29162e075f029a2ce6a7c4a444ef1.tar.gz
blktrace-6fe4709e97f29162e075f029a2ce6a7c4a444ef1.tar.bz2
[PATCH] Always store trace data in big endian format
Diffstat (limited to 'blktrace.h')
-rw-r--r--blktrace.h128
1 files changed, 60 insertions, 68 deletions
diff --git a/blktrace.h b/blktrace.h
index 2f35a45..388f219 100644
--- a/blktrace.h
+++ b/blktrace.h
@@ -1,79 +1,71 @@
-#if !defined(__BLKTRACE_H__)
-#define __BLKTRACE_H__ 1
+#ifndef BLKTRACE_H
+#define BLKTRACE_H
+#include <byteswap.h>
#include <asm/types.h>
+#include <asm/byteorder.h>
+#include "blktrace_api.h"
-enum {
- BLK_TC_READ = 1 << 0, /* reads */
- BLK_TC_WRITE = 1 << 1, /* writes */
- BLK_TC_BARRIER = 1 << 2, /* barrier */
- BLK_TC_SYNC = 1 << 3, /* barrier */
- BLK_TC_QUEUE = 1 << 4, /* queueing/merging */
- BLK_TC_REQUEUE = 1 << 5, /* requeueing */
- BLK_TC_ISSUE = 1 << 6, /* issue */
- BLK_TC_COMPLETE = 1 << 7, /* completions */
- BLK_TC_FS = 1 << 8, /* fs requests */
- BLK_TC_PC = 1 << 9, /* pc requests */
-
- BLK_TC_END = 1 << 15, /* only 16-bits, reminder */
-};
-
-#define BLK_TC_SHIFT (16)
-#define BLK_TC_ACT(act) ((act) << BLK_TC_SHIFT)
-
-/*
- * Basic trace actions
- */
-enum {
- __BLK_TA_QUEUE = 1, /* queued */
- __BLK_TA_BACKMERGE, /* back merged to existing rq */
- __BLK_TA_FRONTMERGE, /* front merge to existing rq */
- __BLK_TA_GETRQ, /* allocated new request */
- __BLK_TA_SLEEPRQ, /* sleeping on rq allocation */
- __BLK_TA_REQUEUE, /* request requeued */
- __BLK_TA_ISSUE, /* sent to driver */
- __BLK_TA_COMPLETE, /* completed by driver */
-};
-
-/*
- * Trace actions in full. Additionally, read or write is masked
- */
-#define BLK_TA_QUEUE (__BLK_TA_QUEUE | BLK_TC_ACT(BLK_TC_QUEUE))
-#define BLK_TA_BACKMERGE (__BLK_TA_BACKMERGE | BLK_TC_ACT(BLK_TC_QUEUE))
-#define BLK_TA_FRONTMERGE (__BLK_TA_FRONTMERGE | BLK_TC_ACT(BLK_TC_QUEUE))
-#define BLK_TA_GETRQ (__BLK_TA_GETRQ | BLK_TC_ACT(BLK_TC_QUEUE))
-#define BLK_TA_SLEEPRQ (__BLK_TA_SLEEPRQ | BLK_TC_ACT(BLK_TC_QUEUE))
-#define BLK_TA_REQUEUE (__BLK_TA_REQUEUE | BLK_TC_ACT(BLK_TC_QUEUE))
-#define BLK_TA_ISSUE (__BLK_TA_ISSUE | BLK_TC_ACT(BLK_TC_ISSUE))
-#define BLK_TA_COMPLETE (__BLK_TA_COMPLETE| BLK_TC_ACT(BLK_TC_COMPLETE))
-
-#define BLK_IO_TRACE_MAGIC (0x65617400)
#define CHECK_MAGIC(t) (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
#define SUPPORTED_VERSION (0x02)
-struct blk_io_trace {
- __u32 magic;
- __u32 sequence;
- __u64 time;
- __u64 sector;
- __u32 bytes;
- __u32 action;
- __u32 pid;
- __u16 error;
- __u16 pdu_len;
-};
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+#define be16_to_cpu(x) __bswap_16(x)
+#define be32_to_cpu(x) __bswap_32(x)
+#define be64_to_cpu(x) __bswap_64(x)
+#define cpu_to_be16(x) __bswap_16(x)
+#define cpu_to_be32(x) __bswap_32(x)
+#define cpu_to_be64(x) __bswap_64(x)
+#elif defined(__BIG_ENDIAN_BITFIELD)
+#define be16_to_cpu(x) (x)
+#define be32_to_cpu(x) (x)
+#define be64_to_cpu(x) (x)
+#define cpu_to_be16(x) (x)
+#define cpu_to_be32(x) (x)
+#define cpu_to_be64(x) (x)
+#else
+#error "Bad arch"
+#endif
+
+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;
+ }
-struct blk_user_trace_setup {
- char name[32];
- __u16 act_mask;
- __u32 buf_size;
- __u32 buf_nr;
-};
+ return 0;
+}
+static inline void trace_to_be(struct blk_io_trace *t)
+{
+ t->magic = cpu_to_be32(t->magic);
+ t->sequence = cpu_to_be32(t->sequence);
+ t->time = cpu_to_be64(t->time);
+ t->sector = cpu_to_be64(t->sector);
+ t->bytes = cpu_to_be32(t->bytes);
+ t->action = cpu_to_be32(t->action);
+ t->pid = cpu_to_be32(t->pid);
+ t->error = cpu_to_be16(t->error);
+ t->pdu_len = cpu_to_be16(t->pdu_len);
+}
-#ifndef BLKSTARTTRACE
-#define BLKSTARTTRACE _IOWR(0x12,115,struct blk_user_trace_setup)
-#define BLKSTOPTRACE _IO(0x12,116)
-#endif
+static inline void trace_to_cpu(struct blk_io_trace *t)
+{
+ t->magic = be32_to_cpu(t->magic);
+ t->sequence = be32_to_cpu(t->sequence);
+ t->time = be64_to_cpu(t->time);
+ t->sector = be64_to_cpu(t->sector);
+ t->bytes = be32_to_cpu(t->bytes);
+ t->action = be32_to_cpu(t->action);
+ t->pid = be32_to_cpu(t->pid);
+ t->error = be16_to_cpu(t->error);
+ t->pdu_len = be16_to_cpu(t->pdu_len);
+}
#endif