From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Mike Snitzer <snitzer@redhat.com>,
Philipp Reisner <philipp.reisner@linbit.com>,
linux-block@vger.kernel.org, dm-devel@redhat.com,
Lars Ellenberg <lars.ellenberg@linbit.com>,
Pavel Begunkov <asml.silence@gmail.com>,
drbd-dev@lists.linbit.com
Subject: [Drbd-dev] [PATCH 02/14] dm: add a clone_to_tio helper
Date: Thu, 27 Jan 2022 07:35:34 +0100 [thread overview]
Message-ID: <20220127063546.1314111-3-hch@lst.de> (raw)
In-Reply-To: <20220127063546.1314111-1-hch@lst.de>
Add a helper to stop open coding the container_of operations to get
from the clone bio to the tio structure.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/dm.c | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 09d9b674bd851..692a06156c927 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -79,10 +79,14 @@ struct clone_info {
#define DM_IO_BIO_OFFSET \
(offsetof(struct dm_target_io, clone) + offsetof(struct dm_io, tio))
+static inline struct dm_target_io *clone_to_tio(struct bio *clone)
+{
+ return container_of(clone, struct dm_target_io, clone);
+}
+
void *dm_per_bio_data(struct bio *bio, size_t data_size)
{
- struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
- if (!tio->inside_dm_io)
+ if (!clone_to_tio(bio)->inside_dm_io)
return (char *)bio - DM_TARGET_IO_BIO_OFFSET - data_size;
return (char *)bio - DM_IO_BIO_OFFSET - data_size;
}
@@ -477,10 +481,7 @@ static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,
u64 dm_start_time_ns_from_clone(struct bio *bio)
{
- struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
- struct dm_io *io = tio->io;
-
- return jiffies_to_nsecs(io->start_time);
+ return jiffies_to_nsecs(clone_to_tio(bio)->io->start_time);
}
EXPORT_SYMBOL_GPL(dm_start_time_ns_from_clone);
@@ -521,7 +522,7 @@ static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio)
clone = bio_alloc_bioset(NULL, 0, 0, GFP_NOIO, &md->io_bs);
- tio = container_of(clone, struct dm_target_io, clone);
+ tio = clone_to_tio(clone);
tio->inside_dm_io = true;
tio->io = NULL;
@@ -557,7 +558,7 @@ static struct dm_target_io *alloc_tio(struct clone_info *ci, struct dm_target *t
if (!clone)
return NULL;
- tio = container_of(clone, struct dm_target_io, clone);
+ tio = clone_to_tio(clone);
tio->inside_dm_io = false;
}
@@ -878,7 +879,7 @@ static bool swap_bios_limit(struct dm_target *ti, struct bio *bio)
static void clone_endio(struct bio *bio)
{
blk_status_t error = bio->bi_status;
- struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
+ struct dm_target_io *tio = clone_to_tio(bio);
struct dm_io *io = tio->io;
struct mapped_device *md = tio->io->md;
dm_endio_fn endio = tio->ti->type->end_io;
@@ -1084,7 +1085,7 @@ static int dm_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
*/
void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors)
{
- struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
+ struct dm_target_io *tio = clone_to_tio(bio);
unsigned bi_size = bio->bi_iter.bi_size >> SECTOR_SHIFT;
BUG_ON(bio->bi_opf & REQ_PREFLUSH);
@@ -1257,10 +1258,8 @@ static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci,
if (bio_nr == num_bios)
return;
- while ((bio = bio_list_pop(blist))) {
- tio = container_of(bio, struct dm_target_io, clone);
- free_tio(tio);
- }
+ while ((bio = bio_list_pop(blist)))
+ free_tio(clone_to_tio(bio));
}
}
@@ -1282,14 +1281,11 @@ static void __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti,
{
struct bio_list blist = BIO_EMPTY_LIST;
struct bio *bio;
- struct dm_target_io *tio;
alloc_multiple_bios(&blist, ci, ti, num_bios);
- while ((bio = bio_list_pop(&blist))) {
- tio = container_of(bio, struct dm_target_io, clone);
- __clone_and_map_simple_bio(ci, tio, len);
- }
+ while ((bio = bio_list_pop(&blist)))
+ __clone_and_map_simple_bio(ci, clone_to_tio(bio), len);
}
static int __send_empty_flush(struct clone_info *ci)
--
2.30.2
next prev parent reply other threads:[~2022-01-27 6:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-27 6:35 [Drbd-dev] improve the bio cloning interface Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 01/14] drbd: set ->bi_bdev in drbd_req_new Christoph Hellwig
2022-01-27 6:35 ` Christoph Hellwig [this message]
2022-01-27 6:35 ` [Drbd-dev] [PATCH 03/14] dm: fold clone_bio into __clone_and_map_data_bio Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 04/14] dm: fold __send_duplicate_bios into __clone_and_map_simple_bio Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 05/14] dm: move cloning the bio into alloc_tio Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 06/14] dm: pass the bio instead of tio to __map_bio Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 07/14] dm: retun the clone bio from alloc_tio Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 08/14] dm: simplify the single bio fast path in __send_duplicate_bios Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 09/14] dm: add a missing bio initialization to alloc_tio Christoph Hellwig
2022-01-29 5:06 ` [Drbd-dev] [dm] 3826813630: BUG:KASAN:double-free_or_invalid-free_in_dm_io_dec_pending kernel test robot
2022-01-27 6:35 ` [Drbd-dev] [PATCH 10/14] dm-cache: remove __remap_to_origin_clear_discard Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 11/14] block: clone crypto and integrity data in __bio_clone_fast Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 12/14] dm: use bio_clone_fast in alloc_tio Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 13/14] block: initialize the target bio in __bio_clone_fast Christoph Hellwig
2022-01-27 6:35 ` [Drbd-dev] [PATCH 14/14] block: pass a block_device to bio_clone_fast Christoph Hellwig
2022-01-27 16:52 ` [Drbd-dev] improve the bio cloning interface Mike Snitzer
2022-01-27 19:58 ` Christoph Hellwig
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=20220127063546.1314111-3-hch@lst.de \
--to=hch@lst.de \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=dm-devel@redhat.com \
--cc=drbd-dev@lists.linbit.com \
--cc=lars.ellenberg@linbit.com \
--cc=linux-block@vger.kernel.org \
--cc=philipp.reisner@linbit.com \
--cc=snitzer@redhat.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