1 diff --git a/block/Kconfig b/block/Kconfig
2 index 377f6dd..27eaed9 100644
5 @@ -11,4 +11,15 @@ config LBD
6 your machine, or if you want to have a raid or loopback device
7 bigger than 2TB. Otherwise say N.
9 +config BLK_DEV_IO_TRACE
10 + bool "Support for tracing block io actions"
13 + Say Y here, if you want to be able to trace the block layer actions
14 + on a given queue. Tracing allows you to see any traffic happening
15 + on a block device queue. For more information (and the user space
16 + support tools needed), fetch the blktrace app from:
18 + git://brick.kernel.dk/data/git/blktrace.git
20 source block/Kconfig.iosched
21 diff --git a/block/Makefile b/block/Makefile
22 index 7e4f93e..c05de0e 100644
25 @@ -8,3 +8,5 @@ obj-$(CONFIG_IOSCHED_NOOP) += noop-iosch
26 obj-$(CONFIG_IOSCHED_AS) += as-iosched.o
27 obj-$(CONFIG_IOSCHED_DEADLINE) += deadline-iosched.o
28 obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o
30 +obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o
31 diff --git a/block/blktrace.c b/block/blktrace.c
33 index 0000000..d12d166
35 +++ b/block/blktrace.c
37 +#include <linux/config.h>
38 +#include <linux/kernel.h>
39 +#include <linux/blkdev.h>
40 +#include <linux/blktrace_api.h>
41 +#include <linux/percpu.h>
42 +#include <linux/init.h>
43 +#include <linux/mutex.h>
44 +#include <asm/uaccess.h>
46 +static DEFINE_PER_CPU(unsigned long long, blk_trace_cpu_offset) = { 0, };
48 +void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
49 + int rw, u32 what, int error, int pdu_len, void *pdu_data)
51 + struct blk_io_trace t;
52 + unsigned long flags;
57 + if (rw & (1 << BIO_RW_BARRIER))
58 + what |= BLK_TC_ACT(BLK_TC_BARRIER);
59 + if (rw & (1 << BIO_RW_SYNC))
60 + what |= BLK_TC_ACT(BLK_TC_SYNC);
63 + what |= BLK_TC_ACT(BLK_TC_WRITE);
65 + what |= BLK_TC_ACT(BLK_TC_READ);
67 + if (((bt->act_mask << BLK_TC_SHIFT) & what) == 0)
69 + if (sector < bt->start_lba || sector > bt->end_lba)
73 + if (bt->pid && pid != bt->pid)
76 + t.magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION;
83 + t.pdu_len = pdu_len;
86 + memcpy(t.comm, current->comm, sizeof(t.comm));
89 + * need to serialize this part completely to prevent multiple CPUs
90 + * from misordering events
92 + spin_lock_irqsave(&bt->lock, flags);
94 + t.sequence = ++bt->sequence;
96 + cpu = smp_processor_id();
98 + t.time = sched_clock() - per_cpu(blk_trace_cpu_offset, cpu);
100 + rbuf = relay_reserve(bt->rchan, sizeof(t) + pdu_len);
102 + memcpy(rbuf, &t, sizeof(t));
104 + memcpy(rbuf + sizeof(t), pdu_data, pdu_len);
107 + spin_unlock_irqrestore(&bt->lock, flags);
110 +EXPORT_SYMBOL_GPL(__blk_add_trace);
112 +static struct dentry *blk_tree_root;
113 +static struct mutex blk_tree_mutex;
115 +static inline void blk_remove_root(void)
117 + if (relayfs_remove_dir(blk_tree_root) != -ENOTEMPTY)
118 + blk_tree_root = NULL;
121 +static void blk_remove_tree(struct dentry *dir)
123 + mutex_lock(&blk_tree_mutex);
124 + relayfs_remove_dir(dir);
126 + mutex_unlock(&blk_tree_mutex);
129 +static struct dentry *blk_create_tree(const char *blk_name)
131 + struct dentry *dir = NULL;
133 + mutex_lock(&blk_tree_mutex);
135 + if (!blk_tree_root) {
136 + blk_tree_root = relayfs_create_dir("block", NULL);
137 + if (!blk_tree_root)
141 + dir = relayfs_create_dir(blk_name, blk_tree_root);
146 + mutex_unlock(&blk_tree_mutex);
150 +void blk_cleanup_trace(struct blk_trace *bt)
152 + relay_close(bt->rchan);
153 + relayfs_remove_file(bt->dropped_file);
154 + blk_remove_tree(bt->dir);
158 +int blk_stop_trace(struct block_device *bdev)
160 + request_queue_t *q = bdev_get_queue(bdev);
161 + struct blk_trace *bt = NULL;
167 + down(&bdev->bd_sem);
169 + if (q->blk_trace) {
171 + q->blk_trace = NULL;
178 + blk_cleanup_trace(bt);
183 +static int blk_dropped_open(struct inode *inode, struct file *filp)
185 + filp->private_data = inode->u.generic_ip;
190 +static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
191 + size_t count, loff_t *ppos)
193 + struct blk_trace *bt = filp->private_data;
196 + snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
198 + return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
201 +static struct file_operations blk_dropped_fops = {
202 + .owner = THIS_MODULE,
203 + .open = blk_dropped_open,
204 + .read = blk_dropped_read,
207 +static int blk_subbuf_start_callback (struct rchan_buf *buf,
210 + size_t prev_padding)
212 + if (relay_buf_full(buf)) {
213 + struct blk_trace *bt = buf->chan->private_data;
215 + atomic_inc(&bt->dropped);
222 +static struct rchan_callbacks blk_relay_callbacks = {
223 + .subbuf_start = blk_subbuf_start_callback,
226 +int blk_start_trace(struct block_device *bdev, char __user *arg)
228 + request_queue_t *q = bdev_get_queue(bdev);
229 + struct blk_user_trace_setup buts;
230 + struct blk_trace *bt = NULL;
231 + struct dentry *dir = NULL;
232 + char b[BDEVNAME_SIZE];
238 + if (copy_from_user(&buts, arg, sizeof(buts)))
241 + if (!buts.buf_size || !buts.buf_nr)
244 + strcpy(buts.name, bdevname(bdev, b));
247 + * some device names have larger paths - convert the slashes
248 + * to underscores for this to work as expected
250 + for (i = 0; i < strlen(buts.name); i++)
251 + if (buts.name[i] == '/')
252 + buts.name[i] = '_';
254 + if (copy_to_user(arg, &buts, sizeof(buts)))
257 + down(&bdev->bd_sem);
263 + bt = kmalloc(sizeof(*bt), GFP_KERNEL);
268 + dir = blk_create_tree(buts.name);
273 + bt->dev = bdev->bd_dev;
275 + spin_lock_init(&bt->lock);
276 + atomic_set(&bt->dropped, 0);
279 + bt->dropped_file = relayfs_create_file("dropped", dir, 0, &blk_dropped_fops, bt);
280 + if (!bt->dropped_file)
283 + bt->rchan = relay_open("trace", dir, buts.buf_size, buts.buf_nr, &blk_relay_callbacks);
286 + bt->rchan->private_data = bt;
288 + bt->act_mask = buts.act_mask;
290 + bt->act_mask = (u16) -1;
292 + bt->start_lba = buts.start_lba;
293 + bt->end_lba = buts.end_lba;
295 + bt->end_lba = -1ULL;
297 + bt->pid = buts.pid;
304 + if (bt && bt->dropped_file)
305 + relayfs_remove_file(bt->dropped_file);
307 + blk_remove_tree(dir);
314 + * Average offset over two calls to sched_clock() with a gettimeofday()
317 +static void blk_check_time(unsigned long long *t)
319 + unsigned long long a, b;
323 + do_gettimeofday(&tv);
326 + *t = tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
330 +static void blk_trace_check_cpu_time(void *data)
332 + unsigned long long *t;
333 + int cpu = get_cpu();
335 + t = &per_cpu(blk_trace_cpu_offset, cpu);
338 + * Just call it twice, hopefully the second call will be cache hot
339 + * and a little more precise
348 + * Call blk_trace_check_cpu_time() on each CPU to calibrate our inter-CPU
351 +static void blk_trace_calibrate_offsets(void)
353 + unsigned long flags;
355 + smp_call_function(blk_trace_check_cpu_time, NULL, 1, 1);
356 + local_irq_save(flags);
357 + blk_trace_check_cpu_time(NULL);
358 + local_irq_restore(flags);
361 +static void blk_trace_set_ht_offsets(void)
363 +#if defined(CONFIG_SCHED_SMT)
367 + * now make sure HT siblings have the same time offset
370 + for_each_online_cpu(cpu) {
371 + unsigned long long *cpu_off, *sibling_off;
373 + for_each_cpu_mask(i, cpu_sibling_map[cpu]) {
377 + cpu_off = &per_cpu(blk_trace_cpu_offset, cpu);
378 + sibling_off = &per_cpu(blk_trace_cpu_offset, i);
379 + *sibling_off = *cpu_off;
386 +static __init int blk_trace_init(void)
388 + mutex_init(&blk_tree_mutex);
389 + blk_trace_calibrate_offsets();
390 + blk_trace_set_ht_offsets();
395 +module_init(blk_trace_init);
397 diff --git a/block/elevator.c b/block/elevator.c
398 index c9f424d..793c686 100644
399 --- a/block/elevator.c
400 +++ b/block/elevator.c
402 #include <linux/init.h>
403 #include <linux/compiler.h>
404 #include <linux/delay.h>
405 +#include <linux/blktrace_api.h>
407 #include <asm/uaccess.h>
409 @@ -333,6 +334,8 @@ void __elv_add_request(request_queue_t *
410 struct list_head *pos;
413 + blk_add_trace_rq(q, rq, BLK_TA_INSERT);
416 rq->flags |= REQ_ORDERED_COLOR;
418 @@ -491,6 +494,7 @@ struct request *elv_next_request(request
419 * not be passed by new incoming requests
421 rq->flags |= REQ_STARTED;
422 + blk_add_trace_rq(q, rq, BLK_TA_ISSUE);
425 if (!q->boundary_rq || q->boundary_rq == rq) {
426 diff --git a/block/ioctl.c b/block/ioctl.c
427 index e110949..63e67a2 100644
431 #include <linux/backing-dev.h>
432 #include <linux/buffer_head.h>
433 #include <linux/smp_lock.h>
434 +#include <linux/blktrace_api.h>
435 #include <asm/uaccess.h>
437 static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user *arg)
438 @@ -189,6 +190,10 @@ static int blkdev_locked_ioctl(struct fi
439 return put_ulong(arg, bdev->bd_inode->i_size >> 9);
441 return put_u64(arg, bdev->bd_inode->i_size);
442 + case BLKSTARTTRACE:
443 + return blk_start_trace(bdev, (char __user *) arg);
445 + return blk_stop_trace(bdev);
449 diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
450 index 8e27d0a..bfcde0f 100644
451 --- a/block/ll_rw_blk.c
452 +++ b/block/ll_rw_blk.c
454 #include <linux/writeback.h>
455 #include <linux/interrupt.h>
456 #include <linux/cpu.h>
457 +#include <linux/blktrace_api.h>
461 @@ -1555,8 +1556,10 @@ void blk_plug_device(request_queue_t *q)
462 if (test_bit(QUEUE_FLAG_STOPPED, &q->queue_flags))
465 - if (!test_and_set_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags))
466 + if (!test_and_set_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags)) {
467 mod_timer(&q->unplug_timer, jiffies + q->unplug_delay);
468 + blk_add_trace_generic(q, NULL, 0, BLK_TA_PLUG);
472 EXPORT_SYMBOL(blk_plug_device);
473 @@ -1620,14 +1623,21 @@ static void blk_backing_dev_unplug(struc
475 * devices don't necessarily have an ->unplug_fn defined
478 + if (q->unplug_fn) {
479 + blk_add_trace_pdu_int(q, BLK_TA_UNPLUG_IO, NULL,
480 + q->rq.count[READ] + q->rq.count[WRITE]);
486 static void blk_unplug_work(void *data)
488 request_queue_t *q = data;
490 + blk_add_trace_pdu_int(q, BLK_TA_UNPLUG_IO, NULL,
491 + q->rq.count[READ] + q->rq.count[WRITE]);
496 @@ -1635,6 +1645,9 @@ static void blk_unplug_timeout(unsigned
498 request_queue_t *q = (request_queue_t *)data;
500 + blk_add_trace_pdu_int(q, BLK_TA_UNPLUG_TIMER, NULL,
501 + q->rq.count[READ] + q->rq.count[WRITE]);
503 kblockd_schedule_work(&q->unplug_work);
506 @@ -1757,6 +1770,11 @@ void blk_cleanup_queue(request_queue_t *
508 __blk_queue_free_tags(q);
510 + if (q->blk_trace) {
511 + blk_cleanup_trace(q->blk_trace);
512 + q->blk_trace = NULL;
515 kmem_cache_free(requestq_cachep, q);
518 @@ -2108,6 +2126,8 @@ rq_starved:
523 + blk_add_trace_generic(q, bio, rw, BLK_TA_GETRQ);
527 @@ -2136,6 +2156,8 @@ static struct request *get_request_wait(
529 struct io_context *ioc;
531 + blk_add_trace_generic(q, bio, rw, BLK_TA_SLEEPRQ);
533 __generic_unplug_device(q);
534 spin_unlock_irq(q->queue_lock);
536 @@ -2189,6 +2211,8 @@ EXPORT_SYMBOL(blk_get_request);
538 void blk_requeue_request(request_queue_t *q, struct request *rq)
540 + blk_add_trace_rq(q, rq, BLK_TA_REQUEUE);
542 if (blk_rq_tagged(rq))
543 blk_queue_end_tag(q, rq);
545 @@ -2820,6 +2844,8 @@ static int __make_request(request_queue_
546 if (!q->back_merge_fn(q, req, bio))
549 + blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE);
551 req->biotail->bi_next = bio;
553 req->nr_sectors = req->hard_nr_sectors += nr_sectors;
554 @@ -2835,6 +2861,8 @@ static int __make_request(request_queue_
555 if (!q->front_merge_fn(q, req, bio))
558 + blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE);
560 bio->bi_next = req->bio;
563 @@ -2952,6 +2980,7 @@ void generic_make_request(struct bio *bi
566 int ret, nr_sectors = bio_sectors(bio);
570 /* Test device or partition size, when known. */
571 @@ -2978,6 +3007,8 @@ void generic_make_request(struct bio *bi
572 * NOTE: we don't repeat the blk_size check for each new device.
573 * Stacking drivers are expected to know what they are doing.
578 char b[BDEVNAME_SIZE];
580 @@ -3010,6 +3041,15 @@ end_io:
582 blk_partition_remap(bio);
584 + if (maxsector != -1)
585 + blk_add_trace_remap(q, bio, old_dev, bio->bi_sector,
588 + blk_add_trace_bio(q, bio, BLK_TA_QUEUE);
590 + maxsector = bio->bi_sector;
591 + old_dev = bio->bi_bdev->bd_dev;
593 ret = q->make_request_fn(q, bio);
596 @@ -3129,6 +3169,8 @@ static int __end_that_request_first(stru
597 int total_bytes, bio_nbytes, error, next_idx = 0;
600 + blk_add_trace_rq(req->q, req, BLK_TA_COMPLETE);
603 * extend uptodate bool to allow < 0 value to be direct io error
605 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
606 index 12d7b9b..880892a 100644
607 --- a/drivers/block/cciss.c
608 +++ b/drivers/block/cciss.c
610 #include <linux/hdreg.h>
611 #include <linux/spinlock.h>
612 #include <linux/compat.h>
613 +#include <linux/blktrace_api.h>
614 #include <asm/uaccess.h>
617 @@ -2330,6 +2331,7 @@ static inline void complete_command( ctl
619 cmd->rq->completion_data = cmd;
620 cmd->rq->errors = status;
621 + blk_add_trace_rq(cmd->rq->q, cmd->rq, BLK_TA_COMPLETE);
622 blk_complete_request(cmd->rq);
625 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
626 index 8c16359..8c979c2 100644
627 --- a/drivers/md/dm.c
628 +++ b/drivers/md/dm.c
630 #include <linux/mempool.h>
631 #include <linux/slab.h>
632 #include <linux/idr.h>
633 +#include <linux/blktrace_api.h>
635 static const char *_name = DM_NAME;
637 @@ -303,6 +304,8 @@ static void dec_pending(struct dm_io *io
638 /* nudge anyone waiting on suspend queue */
639 wake_up(&io->md->wait);
641 + blk_add_trace_bio(io->md->queue, io->bio, BLK_TA_COMPLETE);
643 bio_endio(io->bio, io->bio->bi_size, io->error);
646 @@ -361,6 +364,7 @@ static void __map_bio(struct dm_target *
647 struct target_io *tio)
654 @@ -376,10 +380,17 @@ static void __map_bio(struct dm_target *
657 atomic_inc(&tio->io->io_count);
658 + sector = clone->bi_sector;
659 r = ti->type->map(ti, clone, &tio->info);
662 /* the bio has been remapped so dispatch it */
664 + blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone,
665 + tio->io->bio->bi_bdev->bd_dev, sector,
668 generic_make_request(clone);
672 /* error the io and bail out */
673 diff --git a/fs/bio.c b/fs/bio.c
674 index bbc442b..8a1b0b6 100644
678 #include <linux/module.h>
679 #include <linux/mempool.h>
680 #include <linux/workqueue.h>
681 +#include <linux/blktrace_api.h>
682 #include <scsi/sg.h> /* for struct sg_iovec */
684 #define BIO_POOL_SIZE 256
685 @@ -1094,6 +1095,9 @@ struct bio_pair *bio_split(struct bio *b
689 + blk_add_trace_pdu_int(bdev_get_queue(bi->bi_bdev), BLK_TA_SPLIT, bi,
690 + bi->bi_sector + first_sectors);
692 BUG_ON(bi->bi_vcnt != 1);
693 BUG_ON(bi->bi_idx != 0);
694 atomic_set(&bp->cnt, 3);
695 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
696 index 5dd0207..010e02b 100644
697 --- a/fs/compat_ioctl.c
698 +++ b/fs/compat_ioctl.c
700 #include <linux/i2c-dev.h>
701 #include <linux/wireless.h>
702 #include <linux/atalk.h>
703 +#include <linux/blktrace_api.h>
705 #include <net/sock.h> /* siocdevprivate_ioctl */
706 #include <net/bluetooth/bluetooth.h>
707 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
708 index 02a585f..195c3b9 100644
709 --- a/include/linux/blkdev.h
710 +++ b/include/linux/blkdev.h
711 @@ -22,6 +22,7 @@ typedef struct request_queue request_que
712 struct elevator_queue;
713 typedef struct elevator_queue elevator_t;
714 struct request_pm_state;
717 #define BLKDEV_MIN_RQ 4
718 #define BLKDEV_MAX_RQ 128 /* Default maximum */
719 @@ -416,6 +417,8 @@ struct request_queue
720 unsigned int sg_reserved_size;
723 + struct blk_trace *blk_trace;
726 * reserved for flush operations
728 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
730 index 0000000..d6b4317
732 +++ b/include/linux/blktrace_api.h
737 +#include <linux/config.h>
738 +#include <linux/blkdev.h>
739 +#include <linux/relayfs_fs.h>
745 + BLK_TC_READ = 1 << 0, /* reads */
746 + BLK_TC_WRITE = 1 << 1, /* writes */
747 + BLK_TC_BARRIER = 1 << 2, /* barrier */
748 + BLK_TC_SYNC = 1 << 3, /* barrier */
749 + BLK_TC_QUEUE = 1 << 4, /* queueing/merging */
750 + BLK_TC_REQUEUE = 1 << 5, /* requeueing */
751 + BLK_TC_ISSUE = 1 << 6, /* issue */
752 + BLK_TC_COMPLETE = 1 << 7, /* completions */
753 + BLK_TC_FS = 1 << 8, /* fs requests */
754 + BLK_TC_PC = 1 << 9, /* pc requests */
756 + BLK_TC_END = 1 << 15, /* only 16-bits, reminder */
759 +#define BLK_TC_SHIFT (16)
760 +#define BLK_TC_ACT(act) ((act) << BLK_TC_SHIFT)
763 + * Basic trace actions
766 + __BLK_TA_QUEUE = 1, /* queued */
767 + __BLK_TA_BACKMERGE, /* back merged to existing rq */
768 + __BLK_TA_FRONTMERGE, /* front merge to existing rq */
769 + __BLK_TA_GETRQ, /* allocated new request */
770 + __BLK_TA_SLEEPRQ, /* sleeping on rq allocation */
771 + __BLK_TA_REQUEUE, /* request requeued */
772 + __BLK_TA_ISSUE, /* sent to driver */
773 + __BLK_TA_COMPLETE, /* completed by driver */
774 + __BLK_TA_PLUG, /* queue was plugged */
775 + __BLK_TA_UNPLUG_IO, /* queue was unplugged by io */
776 + __BLK_TA_UNPLUG_TIMER, /* queue was unplugged by timer */
777 + __BLK_TA_INSERT, /* insert request */
778 + __BLK_TA_SPLIT, /* bio was split */
779 + __BLK_TA_BOUNCE, /* bio was bounced */
780 + __BLK_TA_REMAP, /* bio was remapped */
784 + * Trace actions in full. Additionally, read or write is masked
786 +#define BLK_TA_QUEUE (__BLK_TA_QUEUE | BLK_TC_ACT(BLK_TC_QUEUE))
787 +#define BLK_TA_BACKMERGE (__BLK_TA_BACKMERGE | BLK_TC_ACT(BLK_TC_QUEUE))
788 +#define BLK_TA_FRONTMERGE (__BLK_TA_FRONTMERGE | BLK_TC_ACT(BLK_TC_QUEUE))
789 +#define BLK_TA_GETRQ (__BLK_TA_GETRQ | BLK_TC_ACT(BLK_TC_QUEUE))
790 +#define BLK_TA_SLEEPRQ (__BLK_TA_SLEEPRQ | BLK_TC_ACT(BLK_TC_QUEUE))
791 +#define BLK_TA_REQUEUE (__BLK_TA_REQUEUE | BLK_TC_ACT(BLK_TC_REQUEUE))
792 +#define BLK_TA_ISSUE (__BLK_TA_ISSUE | BLK_TC_ACT(BLK_TC_ISSUE))
793 +#define BLK_TA_COMPLETE (__BLK_TA_COMPLETE| BLK_TC_ACT(BLK_TC_COMPLETE))
794 +#define BLK_TA_PLUG (__BLK_TA_PLUG | BLK_TC_ACT(BLK_TC_QUEUE))
795 +#define BLK_TA_UNPLUG_IO (__BLK_TA_UNPLUG_IO | BLK_TC_ACT(BLK_TC_QUEUE))
796 +#define BLK_TA_UNPLUG_TIMER (__BLK_TA_UNPLUG_TIMER | BLK_TC_ACT(BLK_TC_QUEUE))
797 +#define BLK_TA_INSERT (__BLK_TA_INSERT | BLK_TC_ACT(BLK_TC_QUEUE))
798 +#define BLK_TA_SPLIT (__BLK_TA_SPLIT)
799 +#define BLK_TA_BOUNCE (__BLK_TA_BOUNCE)
800 +#define BLK_TA_REMAP (__BLK_TA_REMAP | BLK_TC_ACT(BLK_TC_QUEUE))
802 +#define BLK_IO_TRACE_MAGIC 0x65617400
803 +#define BLK_IO_TRACE_VERSION 0x05
808 +struct blk_io_trace {
809 + u32 magic; /* MAGIC << 8 | version */
810 + u32 sequence; /* event number */
811 + u64 time; /* in microseconds */
812 + u64 sector; /* disk offset */
813 + u32 bytes; /* transfer length */
814 + u32 action; /* what happened */
815 + u32 pid; /* who did it */
816 + u32 cpu; /* on what cpu did it happen */
817 + u16 error; /* completion error */
818 + u16 pdu_len; /* length of data after this trace */
819 + u32 device; /* device number */
820 + char comm[16]; /* task command name (TASK_COMM_LEN) */
826 +struct blk_io_trace_remap {
833 + struct dentry *dir;
834 + struct rchan *rchan;
835 + struct dentry *dropped_file;
838 + unsigned long sequence;
847 + * User setup structure passed with BLKSTARTTRACE
849 +struct blk_user_trace_setup {
850 + char name[BDEVNAME_SIZE]; /* output */
851 + u16 act_mask; /* input */
852 + u32 buf_size; /* input */
853 + u32 buf_nr; /* input */
859 +#if defined(CONFIG_BLK_DEV_IO_TRACE)
860 +extern int blk_start_trace(struct block_device *, char __user *);
861 +extern int blk_stop_trace(struct block_device *);
862 +extern void blk_cleanup_trace(struct blk_trace *);
863 +extern void __blk_add_trace(struct blk_trace *, sector_t, int, int, u32, int, int, void *);
865 +static inline void blk_add_trace_rq(struct request_queue *q, struct request *rq,
868 + struct blk_trace *bt = q->blk_trace;
869 + int rw = rq->flags & 0x07;
874 + if (blk_pc_request(rq)) {
875 + what |= BLK_TC_ACT(BLK_TC_PC);
876 + __blk_add_trace(bt, 0, rq->data_len, rw, what, rq->errors, sizeof(rq->cmd), rq->cmd);
878 + what |= BLK_TC_ACT(BLK_TC_FS);
879 + __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9, rw, what, rq->errors, 0, NULL);
883 +static inline void blk_add_trace_bio(struct request_queue *q, struct bio *bio,
886 + struct blk_trace *bt = q->blk_trace;
891 + __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw, what, !bio_flagged(bio, BIO_UPTODATE), 0, NULL);
894 +static inline void blk_add_trace_generic(struct request_queue *q,
895 + struct bio *bio, int rw, u32 what)
897 + struct blk_trace *bt = q->blk_trace;
903 + blk_add_trace_bio(q, bio, what);
905 + __blk_add_trace(bt, 0, 0, rw, what, 0, 0, NULL);
908 +static inline void blk_add_trace_pdu_int(struct request_queue *q, u32 what,
909 + struct bio *bio, unsigned int pdu)
911 + struct blk_trace *bt = q->blk_trace;
912 + u64 rpdu = cpu_to_be64(pdu);
918 + __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw, what, !bio_flagged(bio, BIO_UPTODATE), sizeof(rpdu), &rpdu);
920 + __blk_add_trace(bt, 0, 0, 0, what, 0, sizeof(rpdu), &rpdu);
923 +static inline void blk_add_trace_remap(struct request_queue *q, struct bio *bio,
924 + dev_t dev, sector_t from, sector_t to)
926 + struct blk_trace *bt = q->blk_trace;
927 + struct blk_io_trace_remap r;
932 + r.device = cpu_to_be32(dev);
933 + r.sector = cpu_to_be64(to);
935 + __blk_add_trace(bt, from, bio->bi_size, bio->bi_rw, BLK_TA_REMAP, !bio_flagged(bio, BIO_UPTODATE), sizeof(r), &r);
938 +#else /* !CONFIG_BLK_DEV_IO_TRACE */
939 +#define blk_start_trace(bdev, arg) (-EINVAL)
940 +#define blk_stop_trace(bdev) (-EINVAL)
941 +#define blk_cleanup_trace(bt) do { } while (0)
942 +#define blk_add_trace_rq(q, rq, what) do { } while (0)
943 +#define blk_add_trace_bio(q, rq, what) do { } while (0)
944 +#define blk_add_trace_generic(q, rq, rw, what) do { } while (0)
945 +#define blk_add_trace_pdu_int(q, what, bio, pdu) do { } while (0)
946 +#define blk_add_trace_remap(q, bio, dev, f, t) do {} while (0)
947 +#endif /* CONFIG_BLK_DEV_IO_TRACE */
950 diff --git a/include/linux/compat_ioctl.h b/include/linux/compat_ioctl.h
951 index 8fad50f..5bed09a 100644
952 --- a/include/linux/compat_ioctl.h
953 +++ b/include/linux/compat_ioctl.h
954 @@ -97,6 +97,8 @@ COMPATIBLE_IOCTL(BLKRRPART)
955 COMPATIBLE_IOCTL(BLKFLSBUF)
956 COMPATIBLE_IOCTL(BLKSECTSET)
957 COMPATIBLE_IOCTL(BLKSSZGET)
958 +COMPATIBLE_IOCTL(BLKSTARTTRACE)
959 +COMPATIBLE_IOCTL(BLKSTOPTRACE)
960 ULONG_IOCTL(BLKRASET)
961 ULONG_IOCTL(BLKFRASET)
963 diff --git a/include/linux/fs.h b/include/linux/fs.h
964 index b77f260..5575284 100644
965 --- a/include/linux/fs.h
966 +++ b/include/linux/fs.h
967 @@ -196,6 +196,8 @@ extern int dir_notify_enable;
968 #define BLKBSZGET _IOR(0x12,112,size_t)
969 #define BLKBSZSET _IOW(0x12,113,size_t)
970 #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
971 +#define BLKSTARTTRACE _IOWR(0x12,115,struct blk_user_trace_setup)
972 +#define BLKSTOPTRACE _IO(0x12,116)
974 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
975 #define FIBMAP _IO(0x00,1) /* bmap access */
976 diff --git a/mm/highmem.c b/mm/highmem.c
977 index ce2e7e8..d0ea1ee 100644
981 #include <linux/init.h>
982 #include <linux/hash.h>
983 #include <linux/highmem.h>
984 +#include <linux/blktrace_api.h>
985 #include <asm/tlbflush.h>
987 static mempool_t *page_pool, *isa_page_pool;
988 @@ -483,6 +484,8 @@ void blk_queue_bounce(request_queue_t *q
989 pool = isa_page_pool;
992 + blk_add_trace_bio(q, *bio_orig, BLK_TA_BOUNCE);