Skip to content

Commit c396b90

Browse files
Christoph Hellwigliu-song-6
authored andcommitted
md: add a mddev_trace_remap helper
Add a helper to trace bio remapping that hides some argument dereferences and the check for a DM-mapped MD device. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed--by: Song Liu <[email protected]> Tested-by: Song Liu <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3a889fd commit c396b90

File tree

6 files changed

+17
-37
lines changed

6 files changed

+17
-37
lines changed

drivers/md/md.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
#include <linux/percpu-refcount.h>
6666
#include <linux/part_stat.h>
6767

68-
#include <trace/events/block.h>
6968
#include "md.h"
7069
#include "md-bitmap.h"
7170
#include "md-cluster.h"
@@ -8686,10 +8685,7 @@ void md_submit_discard_bio(struct mddev *mddev, struct md_rdev *rdev,
86868685

86878686
bio_chain(discard_bio, bio);
86888687
bio_clone_blkg_association(discard_bio, bio);
8689-
if (mddev->gendisk)
8690-
trace_block_bio_remap(discard_bio,
8691-
disk_devt(mddev->gendisk),
8692-
bio->bi_iter.bi_sector);
8688+
mddev_trace_remap(mddev, discard_bio, bio->bi_iter.bi_sector);
86938689
submit_bio_noacct(discard_bio);
86948690
}
86958691
EXPORT_SYMBOL_GPL(md_submit_discard_bio);

drivers/md/md.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/timer.h>
1919
#include <linux/wait.h>
2020
#include <linux/workqueue.h>
21+
#include <trace/events/block.h>
2122
#include "md-cluster.h"
2223

2324
#define MaxSector (~(sector_t)0)
@@ -910,4 +911,11 @@ int do_md_run(struct mddev *mddev);
910911

911912
extern const struct block_device_operations md_fops;
912913

914+
static inline void mddev_trace_remap(struct mddev *mddev, struct bio *bio,
915+
sector_t sector)
916+
{
917+
if (mddev->gendisk)
918+
trace_block_bio_remap(bio, disk_devt(mddev->gendisk), sector);
919+
}
920+
913921
#endif /* _MD_MD_H */

drivers/md/raid0.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,7 @@ static void raid0_map_submit_bio(struct mddev *mddev, struct bio *bio)
578578
bio_set_dev(bio, tmp_dev->bdev);
579579
bio->bi_iter.bi_sector = sector + zone->dev_start +
580580
tmp_dev->data_offset;
581-
582-
if (mddev->gendisk)
583-
trace_block_bio_remap(bio, disk_devt(mddev->gendisk),
584-
bio_sector);
581+
mddev_trace_remap(mddev, bio, bio_sector);
585582
mddev_check_write_zeroes(mddev, bio);
586583
submit_bio_noacct(bio);
587584
}

drivers/md/raid1.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,11 +1418,7 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
14181418
test_bit(R1BIO_FailFast, &r1_bio->state))
14191419
read_bio->bi_opf |= MD_FAILFAST;
14201420
read_bio->bi_private = r1_bio;
1421-
1422-
if (mddev->gendisk)
1423-
trace_block_bio_remap(read_bio, disk_devt(mddev->gendisk),
1424-
r1_bio->sector);
1425-
1421+
mddev_trace_remap(mddev, read_bio, r1_bio->sector);
14261422
submit_bio_noacct(read_bio);
14271423
}
14281424

@@ -1655,10 +1651,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
16551651
mbio->bi_private = r1_bio;
16561652

16571653
atomic_inc(&r1_bio->remaining);
1658-
1659-
if (mddev->gendisk)
1660-
trace_block_bio_remap(mbio, disk_devt(mddev->gendisk),
1661-
r1_bio->sector);
1654+
mddev_trace_remap(mddev, mbio, r1_bio->sector);
16621655
/* flush_pending_writes() needs access to the rdev so...*/
16631656
mbio->bi_bdev = (void *)rdev;
16641657
if (!raid1_add_bio_to_plug(mddev, mbio, raid1_unplug, disks)) {

drivers/md/raid10.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,10 +1235,7 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,
12351235
test_bit(R10BIO_FailFast, &r10_bio->state))
12361236
read_bio->bi_opf |= MD_FAILFAST;
12371237
read_bio->bi_private = r10_bio;
1238-
1239-
if (mddev->gendisk)
1240-
trace_block_bio_remap(read_bio, disk_devt(mddev->gendisk),
1241-
r10_bio->sector);
1238+
mddev_trace_remap(mddev, read_bio, r10_bio->sector);
12421239
submit_bio_noacct(read_bio);
12431240
return;
12441241
}
@@ -1274,10 +1271,7 @@ static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
12741271
&& enough(conf, devnum))
12751272
mbio->bi_opf |= MD_FAILFAST;
12761273
mbio->bi_private = r10_bio;
1277-
1278-
if (conf->mddev->gendisk)
1279-
trace_block_bio_remap(mbio, disk_devt(conf->mddev->gendisk),
1280-
r10_bio->sector);
1274+
mddev_trace_remap(mddev, mbio, r10_bio->sector);
12811275
/* flush_pending_writes() needs access to the rdev so...*/
12821276
mbio->bi_bdev = (void *)rdev;
12831277

drivers/md/raid5.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,10 +1295,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
12951295
if (rrdev)
12961296
set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags);
12971297

1298-
if (conf->mddev->gendisk)
1299-
trace_block_bio_remap(bi,
1300-
disk_devt(conf->mddev->gendisk),
1301-
sh->dev[i].sector);
1298+
mddev_trace_remap(conf->mddev, bi, sh->dev[i].sector);
13021299
if (should_defer && op_is_write(op))
13031300
bio_list_add(&pending_bios, bi);
13041301
else
@@ -1342,10 +1339,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
13421339
*/
13431340
if (op == REQ_OP_DISCARD)
13441341
rbi->bi_vcnt = 0;
1345-
if (conf->mddev->gendisk)
1346-
trace_block_bio_remap(rbi,
1347-
disk_devt(conf->mddev->gendisk),
1348-
sh->dev[i].sector);
1342+
mddev_trace_remap(conf->mddev, rbi, sh->dev[i].sector);
13491343
if (should_defer && op_is_write(op))
13501344
bio_list_add(&pending_bios, rbi);
13511345
else
@@ -5523,9 +5517,7 @@ static int raid5_read_one_chunk(struct mddev *mddev, struct bio *raid_bio)
55235517
spin_unlock_irq(&conf->device_lock);
55245518
}
55255519

5526-
if (mddev->gendisk)
5527-
trace_block_bio_remap(align_bio, disk_devt(mddev->gendisk),
5528-
raid_bio->bi_iter.bi_sector);
5520+
mddev_trace_remap(mddev, align_bio, raid_bio->bi_iter.bi_sector);
55295521
submit_bio_noacct(align_bio);
55305522
return 1;
55315523
}

0 commit comments

Comments
 (0)