md: add a mddev_add_trace_msg helper
authorChristoph Hellwig <hch@lst.de>
Sun, 3 Mar 2024 14:01:41 +0000 (07:01 -0700)
committerSong Liu <song@kernel.org>
Wed, 6 Mar 2024 16:59:52 +0000 (08:59 -0800)
Add a small wrapper around blk_add_trace_msg that hides some argument
dereferences and the check for a DM-mapped MD device.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed--by: Song Liu <song@kernel.org>
Tested-by: Song Liu <song@kernel.org>
Signed-off-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20240303140150.5435-3-hch@lst.de
drivers/md/md-bitmap.c
drivers/md/md.c
drivers/md/md.h
drivers/md/raid1.c
drivers/md/raid10.c
drivers/md/raid5.c

index a4976ceae8688a6080af12a3fc1c12f01459c7c2..059afc24c08bec85ba2739002043619053ca0f1d 100644 (file)
@@ -1046,9 +1046,8 @@ void md_bitmap_unplug(struct bitmap *bitmap)
                if (dirty || need_write) {
                        if (!writing) {
                                md_bitmap_wait_writes(bitmap);
-                               if (bitmap->mddev->queue)
-                                       blk_add_trace_msg(bitmap->mddev->queue,
-                                                         "md bitmap_unplug");
+                               mddev_add_trace_msg(bitmap->mddev,
+                                       "md bitmap_unplug");
                        }
                        clear_page_attr(bitmap, i, BITMAP_PAGE_PENDING);
                        filemap_write_page(bitmap, i, false);
@@ -1319,9 +1318,7 @@ void md_bitmap_daemon_work(struct mddev *mddev)
        }
        bitmap->allclean = 1;
 
-       if (bitmap->mddev->queue)
-               blk_add_trace_msg(bitmap->mddev->queue,
-                                 "md bitmap_daemon_work");
+       mddev_add_trace_msg(bitmap->mddev, "md bitmap_daemon_work");
 
        /* Any file-page which is PENDING now needs to be written.
         * So set NEEDWRITE now, then after we make any last-minute changes
index a52642ecd394eb3cb3de02a54852a935c6b554be..ab231537c476d754c8f66ad4ca53f1a84d3cc648 100644 (file)
@@ -2856,8 +2856,7 @@ repeat:
        pr_debug("md: updating %s RAID superblock on device (in sync %d)\n",
                 mdname(mddev), mddev->in_sync);
 
-       if (mddev->queue)
-               blk_add_trace_msg(mddev->queue, "md md_update_sb");
+       mddev_add_trace_msg(mddev, "md md_update_sb");
 rewrite:
        md_bitmap_update_sb(mddev->bitmap);
        rdev_for_each(rdev, mddev) {
index 928086b638a394596371a6ab417dd52a59280259..e2e1ddd397ea31d36a644f10022c75098c531547 100644 (file)
@@ -918,4 +918,10 @@ static inline void mddev_trace_remap(struct mddev *mddev, struct bio *bio,
                trace_block_bio_remap(bio, disk_devt(mddev->gendisk), sector);
 }
 
+#define mddev_add_trace_msg(mddev, fmt, args...)                       \
+do {                                                                   \
+       if ((mddev)->gendisk)                                           \
+               blk_add_trace_msg((mddev)->queue, fmt, ##args);         \
+} while (0)
+
 #endif /* _MD_MD_H */
index 421154430f241c1293e2bf6aa802da447a67b2b5..05870a4565fc71e2502f73cbafab5f01df66b232 100644 (file)
@@ -46,9 +46,6 @@
 static void allow_barrier(struct r1conf *conf, sector_t sector_nr);
 static void lower_barrier(struct r1conf *conf, sector_t sector_nr);
 
-#define raid1_log(md, fmt, args...)                            \
-       do { if ((md)->queue) blk_add_trace_msg((md)->queue, "raid1 " fmt, ##args); } while (0)
-
 #define RAID_1_10_NAME "raid1"
 #include "raid1-10.c"
 
@@ -1196,7 +1193,7 @@ static void freeze_array(struct r1conf *conf, int extra)
         */
        spin_lock_irq(&conf->resync_lock);
        conf->array_frozen = 1;
-       raid1_log(conf->mddev, "wait freeze");
+       mddev_add_trace_msg(conf->mddev, "raid1 wait freeze");
        wait_event_lock_irq_cmd(
                conf->wait_barrier,
                get_unqueued_pending(conf) == extra,
@@ -1385,7 +1382,7 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
                 * Reading from a write-mostly device must take care not to
                 * over-take any writes that are 'behind'
                 */
-               raid1_log(mddev, "wait behind writes");
+               mddev_add_trace_msg(mddev, "raid1 wait behind writes");
                wait_event(bitmap->behind_wait,
                           atomic_read(&bitmap->behind_writes) == 0);
        }
@@ -1568,7 +1565,8 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
                        bio_wouldblock_error(bio);
                        return;
                }
-               raid1_log(mddev, "wait rdev %d blocked", blocked_rdev->raid_disk);
+               mddev_add_trace_msg(mddev, "raid1 wait rdev %d blocked",
+                               blocked_rdev->raid_disk);
                md_wait_for_blocked_rdev(blocked_rdev, mddev);
                wait_barrier(conf, bio->bi_iter.bi_sector, false);
                goto retry_write;
index 9335a1620e6c106617f055f64a0581c3a643b6fa..1447cb1e441455a636041b968a8b69673abb7acf 100644 (file)
@@ -76,9 +76,6 @@ static void reshape_request_write(struct mddev *mddev, struct r10bio *r10_bio);
 static void end_reshape_write(struct bio *bio);
 static void end_reshape(struct r10conf *conf);
 
-#define raid10_log(md, fmt, args...)                           \
-       do { if ((md)->queue) blk_add_trace_msg((md)->queue, "raid10 " fmt, ##args); } while (0)
-
 #include "raid1-10.c"
 
 #define NULL_CMD
@@ -1019,7 +1016,7 @@ static bool wait_barrier(struct r10conf *conf, bool nowait)
                        ret = false;
                } else {
                        conf->nr_waiting++;
-                       raid10_log(conf->mddev, "wait barrier");
+                       mddev_add_trace_msg(conf->mddev, "raid10 wait barrier");
                        wait_event_barrier(conf, stop_waiting_barrier(conf));
                        conf->nr_waiting--;
                }
@@ -1138,7 +1135,7 @@ static bool regular_request_wait(struct mddev *mddev, struct r10conf *conf,
                        bio_wouldblock_error(bio);
                        return false;
                }
-               raid10_log(conf->mddev, "wait reshape");
+               mddev_add_trace_msg(conf->mddev, "raid10 wait reshape");
                wait_event(conf->wait_barrier,
                           conf->reshape_progress <= bio->bi_iter.bi_sector ||
                           conf->reshape_progress >= bio->bi_iter.bi_sector +
@@ -1336,8 +1333,9 @@ retry_wait:
        if (unlikely(blocked_rdev)) {
                /* Have to wait for this device to get unblocked, then retry */
                allow_barrier(conf);
-               raid10_log(conf->mddev, "%s wait rdev %d blocked",
-                               __func__, blocked_rdev->raid_disk);
+               mddev_add_trace_msg(conf->mddev,
+                       "raid10 %s wait rdev %d blocked",
+                       __func__, blocked_rdev->raid_disk);
                md_wait_for_blocked_rdev(blocked_rdev, mddev);
                wait_barrier(conf, false);
                goto retry_wait;
@@ -1392,7 +1390,8 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
                        bio_wouldblock_error(bio);
                        return;
                }
-               raid10_log(conf->mddev, "wait reshape metadata");
+               mddev_add_trace_msg(conf->mddev,
+                       "raid10 wait reshape metadata");
                wait_event(mddev->sb_wait,
                           !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags));
 
index f0bc96f68665b49161458315802975df90465028..c082b07d3f635de35331fe8cc5526a4b59c800f3 100644 (file)
@@ -4195,10 +4195,9 @@ static int handle_stripe_dirtying(struct r5conf *conf,
        set_bit(STRIPE_HANDLE, &sh->state);
        if ((rmw < rcw || (rmw == rcw && conf->rmw_level == PARITY_PREFER_RMW)) && rmw > 0) {
                /* prefer read-modify-write, but need to get some data */
-               if (conf->mddev->queue)
-                       blk_add_trace_msg(conf->mddev->queue,
-                                         "raid5 rmw %llu %d",
-                                         (unsigned long long)sh->sector, rmw);
+               mddev_add_trace_msg(conf->mddev, "raid5 rmw %llu %d",
+                               sh->sector, rmw);
+
                for (i = disks; i--; ) {
                        struct r5dev *dev = &sh->dev[i];
                        if (test_bit(R5_InJournal, &dev->flags) &&
@@ -4276,9 +4275,10 @@ static int handle_stripe_dirtying(struct r5conf *conf,
                        }
                }
                if (rcw && conf->mddev->queue)
-                       blk_add_trace_msg(conf->mddev->queue, "raid5 rcw %llu %d %d %d",
-                                         (unsigned long long)sh->sector,
-                                         rcw, qread, test_bit(STRIPE_DELAYED, &sh->state));
+                       mddev_add_trace_msg(conf->mddev,
+                               "raid5 rcw %llu %d %d %d",
+                               sh->sector, rcw, qread,
+                               test_bit(STRIPE_DELAYED, &sh->state));
        }
 
        if (rcw > disks && rmw > disks &&