Skip to contentSkip to conversation

blktrace: fix to trace a partition, instead of only disk

PATCH In review Shawn Du 2 participants 4 messages Dec 17, 2008 – Jan 5, 2009 Block layer

lore
Share & tools
lore

Shawn Du

author
#0 lore raw

PATCH 1/1 blktrace: fix to trace a partition, instead of only disk

I made some changes to block/blktrace.c to make it able to trace a partition as the -d option specified.
Doing so by simply using start_lba and end_lba, these two parameters are not passed in from user space,but figured out by do_blk_trace_setup() in kernel.

From: Shawn Du <[email protected]>
Date: Wed, 17 Dec 2008 11:57:46 +0800
Subject: [PATCH] Trace a partition

---
 block/blktrace.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
block/blktrace.c +6 -3
index 85049a7..b8ea04c 100644
@@ -420,10 +420,13 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
 	if (!bt->act_mask)
 		bt->act_mask = (u16) -1;
 
-	bt->start_lba = buts->start_lba;
-	bt->end_lba = buts->end_lba;
-	if (!bt->end_lba)
+	if (bdev->bd_part) {
+		bt->start_lba = bdev->bd_part->start_sect;
+		bt->end_lba = bt->start_lba + bdev->bd_part->nr_sects;
+	} else {
+		bt->start_lba = 0;
 		bt->end_lba = -1ULL;
+	}
 
 	bt->pid = buts->pid;
 	bt->trace_state = Blktrace_setup;
Signature · 1 line
1.5.2.5
#1 lore raw
Quoted 34 lines · Shawn Du

I made some changes to block/blktrace.c to make it able to trace a partition as the -d option specified.
Doing so by simply using start_lba and end_lba, these two parameters are not passed in from user space,but figured out by do_blk_trace_setup() in kernel.

From: Shawn Du <[email protected]>
Date: Wed, 17 Dec 2008 11:57:46 +0800
Subject: [PATCH] Trace a partition

---
 block/blktrace.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
block/blktrace.c +6 -3
index 85049a7..b8ea04c 100644
@@ -420,10 +420,13 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
 	if (!bt->act_mask)
 		bt->act_mask = (u16) -1;
 
-	bt->start_lba = buts->start_lba;
-	bt->end_lba = buts->end_lba;
-	if (!bt->end_lba)
+	if (bdev->bd_part) {
+		bt->start_lba = bdev->bd_part->start_sect;
+		bt->end_lba = bt->start_lba + bdev->bd_part->nr_sects;
+	} else {
+		bt->start_lba = 0;
 		bt->end_lba = -1ULL;
+	}
 
 	bt->pid = buts->pid;
 	bt->trace_state = Blktrace_setup;
Signature · 1 line
1.5.2.5

Very nice! The only problem with this is that we have actions that are, by definition, per device. So we probably want to include any sector that is within the range of the partition, AND a zero sector. So that means changing act_log_check() to something ala:

- if (sector < bt->start_lba || sector > bt->end_lba)
+ if (!sector || sector < bt->start_lba || sector > bt->end_lba)

                return 1;

in pseudo patch form.

Signature · 1 line
Jens Axboe
author
#2 lore raw

Re: Re: Re: [PATCH] blktrace: fix to trace a partition, instead of

In reply to Shawn Du
Quoted 10 lines

Very nice! The only problem with this is that we have actions that are, by definition, per device. So we probably want to include any sector that is within the range of the partition, AND a zero sector. So that means changing act_log_check() to something ala:

(quoted diff) +1 -1
-       if (sector < bt->start_lba || sector > bt->end_lba)
+       if (!sector || sector < bt->start_lba || sector > bt->end_lba)
               return 1;

in pseudo patch form.

Thank you sir. And perhaps, we change in __blk_add_trace():

- if (unlikely(act_log_check(bt, what, sector, pid)))
+ if (act_log_check(bt, what, sector, pid))

Sorry for the lateness.

Happy New Year.

Shawn

#3 lore raw
In reply to Shawn Du
Quoted 13 lines · Shawn Du
Quoted 10 lines

Very nice! The only problem with this is that we have actions that are, by definition, per device. So we probably want to include any sector that is within the range of the partition, AND a zero sector. So that means changing act_log_check() to something ala:

(quoted diff) +1 -1
-       if (sector < bt->start_lba || sector > bt->end_lba)
+       if (!sector || sector < bt->start_lba || sector > bt->end_lba)
               return 1;

in pseudo patch form.

Thank you sir. And perhaps, we change in __blk_add_trace():

Review

Quoted 2 lines
(quoted diff) +1 -1
-	if (unlikely(act_log_check(bt, what, sector, pid)))
+	if (act_log_check(bt, what, sector, pid))

Sure, lets get rid of it.

Signature · 1 line
Jens Axboe