From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>, Mike Snitzer <snitzer@kernel.org>,
Mikulas Patocka <mpatocka@redhat.com>, Song Liu <song@kernel.org>,
Yu Kuai <yukuai3@huawei.com>
Cc: dm-devel@lists.linux.dev, linux-block@vger.kernel.org,
linux-raid@vger.kernel.org
Subject: [PATCH 06/14] md: add a mddev_is_dm helper
Date: Wed, 28 Feb 2024 14:56:45 -0800 [thread overview]
Message-ID: <20240228225653.947152-7-hch@lst.de> (raw)
In-Reply-To: <20240228225653.947152-1-hch@lst.de>
Add a helper to check for a DM-mapped MD device instead of using
the obfuscated ->gendisk or ->queue NULL checks.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/md.c | 15 +++++++--------
drivers/md/md.h | 12 ++++++++++--
drivers/md/raid0.c | 2 +-
drivers/md/raid1.c | 13 +++++--------
drivers/md/raid10.c | 10 +++++-----
drivers/md/raid5.c | 21 ++++++++++-----------
6 files changed, 38 insertions(+), 35 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 409e57242b27f6..01a219b2559bdb 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2401,7 +2401,7 @@ int md_integrity_register(struct mddev *mddev)
if (list_empty(&mddev->disks))
return 0; /* nothing to do */
- if (!mddev->gendisk || blk_get_integrity(mddev->gendisk))
+ if (mddev_is_dm(mddev) || blk_get_integrity(mddev->gendisk))
return 0; /* shouldn't register, or already is */
rdev_for_each(rdev, mddev) {
/* skip spares and non-functional disks */
@@ -2454,7 +2454,7 @@ int md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev)
{
struct blk_integrity *bi_mddev;
- if (!mddev->gendisk)
+ if (mddev_is_dm(mddev))
return 0;
bi_mddev = blk_get_integrity(mddev->gendisk);
@@ -5923,7 +5923,7 @@ int md_run(struct mddev *mddev)
invalidate_bdev(rdev->bdev);
if (mddev->ro != MD_RDONLY && rdev_read_only(rdev)) {
mddev->ro = MD_RDONLY;
- if (mddev->gendisk)
+ if (!mddev_is_dm(mddev))
set_disk_ro(mddev->gendisk, 1);
}
@@ -6082,7 +6082,7 @@ int md_run(struct mddev *mddev)
}
}
- if (mddev->queue) {
+ if (!mddev_is_dm(mddev)) {
bool nonrot = true;
rdev_for_each(rdev, mddev) {
@@ -6338,7 +6338,7 @@ static void mddev_detach(struct mddev *mddev)
mddev->pers->quiesce(mddev, 0);
}
md_unregister_thread(mddev, &mddev->thread);
- if (mddev->queue)
+ if (!mddev_is_dm(mddev))
blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
}
@@ -7304,10 +7304,9 @@ static int update_size(struct mddev *mddev, sector_t num_sectors)
if (!rv) {
if (mddev_is_clustered(mddev))
md_cluster_ops->update_size(mddev, old_dev_sectors);
- else if (mddev->queue) {
+ else if (!mddev_is_dm(mddev))
set_capacity_and_notify(mddev->gendisk,
mddev->array_sectors);
- }
}
return rv;
}
@@ -9137,7 +9136,7 @@ void md_do_sync(struct md_thread *thread)
mddev->delta_disks > 0 &&
mddev->pers->finish_reshape &&
mddev->pers->size &&
- mddev->queue) {
+ !mddev_is_dm(mddev)) {
mddev_lock_nointr(mddev);
md_set_array_sectors(mddev, mddev->pers->size(mddev, 0, 0));
mddev_unlock(mddev);
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 91ee8951fc8dcb..b08e655f8bec41 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -864,16 +864,24 @@ int do_md_run(struct mddev *mddev);
extern const struct block_device_operations md_fops;
+/*
+ * MD devices can be used undeneath by DM, in which case ->gendisk is NULL.
+ */
+static inline bool mddev_is_dm(struct mddev *mddev)
+{
+ return !mddev->gendisk;
+}
+
static inline void mddev_trace_remap(struct mddev *mddev, struct bio *bio,
sector_t sector)
{
- if (mddev->gendisk)
+ if (!mddev_is_dm(mddev))
trace_block_bio_remap(bio, disk_devt(mddev->gendisk), sector);
}
#define mddev_add_trace_msg(mddev, fmt, args...) \
do { \
- if ((mddev)->gendisk) \
+ if (!mddev_is_dm(mddev)) \
blk_add_trace_msg((mddev)->queue, fmt, ##args); \
} while (0)
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index aff094de974347..9f787ae77ede88 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -399,7 +399,7 @@ static int raid0_run(struct mddev *mddev)
mddev->private = conf;
}
conf = mddev->private;
- if (mddev->queue) {
+ if (!mddev_is_dm(mddev)) {
struct md_rdev *rdev;
blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors);
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 3f47fe828b21bb..3b1227f67a6d61 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1782,7 +1782,7 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
for (mirror = first; mirror <= last; mirror++) {
p = conf->mirrors + mirror;
if (!p->rdev) {
- if (mddev->gendisk)
+ if (!mddev_is_dm(mddev))
disk_stack_limits(mddev->gendisk, rdev->bdev,
rdev->data_offset << 9);
@@ -3109,14 +3109,11 @@ static int raid1_run(struct mddev *mddev)
if (IS_ERR(conf))
return PTR_ERR(conf);
- if (mddev->queue)
+ if (!mddev_is_dm(mddev)) {
blk_queue_max_write_zeroes_sectors(mddev->queue, 0);
-
- rdev_for_each(rdev, mddev) {
- if (!mddev->gendisk)
- continue;
- disk_stack_limits(mddev->gendisk, rdev->bdev,
- rdev->data_offset << 9);
+ rdev_for_each(rdev, mddev)
+ disk_stack_limits(mddev->gendisk, rdev->bdev,
+ rdev->data_offset << 9);
}
mddev->degraded = 0;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index b6c5194c22308d..95fa9e728f95a9 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -2124,7 +2124,7 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)
continue;
}
- if (mddev->gendisk)
+ if (!mddev_is_dm(mddev))
disk_stack_limits(mddev->gendisk, rdev->bdev,
rdev->data_offset << 9);
@@ -2144,7 +2144,7 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)
set_bit(Replacement, &rdev->flags);
rdev->raid_disk = repl_slot;
err = 0;
- if (mddev->gendisk)
+ if (!mddev_is_dm(mddev))
disk_stack_limits(mddev->gendisk, rdev->bdev,
rdev->data_offset << 9);
conf->fullsync = 1;
@@ -4040,7 +4040,7 @@ static int raid10_run(struct mddev *mddev)
}
}
- if (mddev->queue) {
+ if (!mddev_is_dm(conf->mddev)) {
blk_queue_max_write_zeroes_sectors(mddev->queue, 0);
blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);
raid10_set_io_opt(conf);
@@ -4074,7 +4074,7 @@ static int raid10_run(struct mddev *mddev)
if (first || diff < min_offset_diff)
min_offset_diff = diff;
- if (mddev->gendisk)
+ if (!mddev_is_dm(mddev))
disk_stack_limits(mddev->gendisk, rdev->bdev,
rdev->data_offset << 9);
@@ -4959,7 +4959,7 @@ static void end_reshape(struct r10conf *conf)
conf->reshape_safe = MaxSector;
spin_unlock_irq(&conf->device_lock);
- if (conf->mddev->queue)
+ if (!mddev_is_dm(conf->mddev))
raid10_set_io_opt(conf);
conf->fullsync = 0;
}
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 969df5c584653e..287fc1540a8d32 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2416,12 +2416,12 @@ static int grow_stripes(struct r5conf *conf, int num)
size_t namelen = sizeof(conf->cache_name[0]);
int devs = max(conf->raid_disks, conf->previous_raid_disks);
- if (conf->mddev->gendisk)
+ if (mddev_is_dm(conf->mddev))
snprintf(conf->cache_name[0], namelen,
- "raid%d-%s", conf->level, mdname(conf->mddev));
+ "raid%d-%p", conf->level, conf->mddev);
else
snprintf(conf->cache_name[0], namelen,
- "raid%d-%p", conf->level, conf->mddev);
+ "raid%d-%s", conf->level, mdname(conf->mddev));
snprintf(conf->cache_name[1], namelen, "%.27s-alt", conf->cache_name[0]);
conf->active_name = 0;
@@ -4278,11 +4278,10 @@ static int handle_stripe_dirtying(struct r5conf *conf,
set_bit(STRIPE_DELAYED, &sh->state);
}
}
- if (rcw && conf->mddev->queue)
- mddev_add_trace_msg(conf->mddev,
- "raid5 rcw %llu %d %d %d",
- sh->sector, rcw, qread,
- test_bit(STRIPE_DELAYED, &sh->state));
+ if (rcw && !mddev_is_dm(conf->mddev))
+ 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));
}
if (rcw > disks && rmw > disks &&
@@ -5693,7 +5692,7 @@ static void raid5_unplug(struct blk_plug_cb *blk_cb, bool from_schedule)
}
release_inactive_stripe_list(conf, cb->temp_inactive_list,
NR_STRIPE_HASH_LOCKS);
- if (mddev->queue)
+ if (!mddev_is_dm(mddev))
trace_block_unplug(mddev->queue, cnt, !from_schedule);
kfree(cb);
}
@@ -7942,7 +7941,7 @@ static int raid5_run(struct mddev *mddev)
mdname(mddev));
md_set_array_sectors(mddev, raid5_size(mddev, 0, 0));
- if (mddev->queue) {
+ if (!mddev_is_dm(mddev)) {
int chunk_size;
/* read-ahead size must cover two whole stripes, which
* is 2 * (datadisks) * chunksize where 'n' is the
@@ -8546,7 +8545,7 @@ static void end_reshape(struct r5conf *conf)
spin_unlock_irq(&conf->device_lock);
wake_up(&conf->wait_for_overlap);
- if (conf->mddev->queue)
+ if (!mddev_is_dm(conf->mddev))
raid5_set_io_opt(conf);
}
}
--
2.39.2
next prev parent reply other threads:[~2024-02-28 22:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-28 22:56 atomic queue limit updates for stackable devices v3 Christoph Hellwig
2024-02-28 22:56 ` [PATCH 01/14] block: add a queue_limits_set helper Christoph Hellwig
2024-02-28 22:56 ` [PATCH 02/14] block: add a queue_limits_stack_bdev helper Christoph Hellwig
2024-02-28 22:56 ` [PATCH 03/14] dm: use queue_limits_set Christoph Hellwig
2024-02-28 22:56 ` [PATCH 04/14] md: add a mddev_trace_remap helper Christoph Hellwig
2024-02-28 22:56 ` [PATCH 05/14] md: add a mddev_add_trace_msg helper Christoph Hellwig
2024-02-28 22:56 ` Christoph Hellwig [this message]
2024-02-28 22:56 ` [PATCH 07/14] md: add queue limit helpers Christoph Hellwig
2024-02-28 22:56 ` [PATCH 08/14] md/raid0: use the atomic queue limit update APIs Christoph Hellwig
2024-02-28 22:56 ` [PATCH 09/14] md/raid1: " Christoph Hellwig
2024-02-28 22:56 ` [PATCH 10/14] md/raid5: " Christoph Hellwig
2024-02-28 22:56 ` [PATCH 11/14] md/raid10: " Christoph Hellwig
2024-02-28 22:56 ` [PATCH 12/14] md: don't initialize queue limits Christoph Hellwig
2024-02-28 22:56 ` [PATCH 13/14] md: remove mddev->queue Christoph Hellwig
2024-02-28 22:56 ` [PATCH 14/14] block: remove disk_stack_limits Christoph Hellwig
2024-02-29 19:40 ` atomic queue limit updates for stackable devices v3 Christoph Hellwig
2024-03-01 15:55 ` (subset) " Jens Axboe
2024-03-02 4:14 ` Song Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240228225653.947152-7-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=dm-devel@lists.linux.dev \
--cc=linux-block@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=snitzer@kernel.org \
--cc=song@kernel.org \
--cc=yukuai3@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).