Skip to content

Commit b7f8dff

Browse files
committed
dm: simplify dm_sumbit_bio_remap interface
Remove the from_wq argument from dm_sumbit_bio_remap(). Eliminates the need for dm_sumbit_bio_remap() callers to know whether they are calling for a workqueue or from the original dm_submit_bio(). Add map_task to dm_io struct, record the map_task in alloc_io and clear it after all target ->map() calls have completed. Update dm_sumbit_bio_remap to check if 'current' matches io->map_task rather than rely on passed 'from_rq' argument. This change really simplifies the chore of porting each DM target to using dm_sumbit_bio_remap() because there is no longer the risk of programming error by not completely knowing all the different contexts a particular method that calls dm_sumbit_bio_remap() might be used in. Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent a925128 commit b7f8dff

6 files changed

Lines changed: 12 additions & 11 deletions

File tree

drivers/md/dm-core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ struct dm_io {
237237
unsigned long start_time;
238238
void *data;
239239
struct hlist_node node;
240+
struct task_struct *map_task;
240241
spinlock_t endio_lock;
241242
struct dm_stats_aux stats_aux;
242243
/* last member of dm_target_io is 'struct bio' */

drivers/md/dm-crypt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
18571857
return 1;
18581858
}
18591859

1860-
dm_submit_bio_remap(io->base_bio, clone, (gfp != CRYPT_MAP_READ_GFP));
1860+
dm_submit_bio_remap(io->base_bio, clone);
18611861
return 0;
18621862
}
18631863

@@ -1883,7 +1883,7 @@ static void kcryptd_io_write(struct dm_crypt_io *io)
18831883
{
18841884
struct bio *clone = io->ctx.bio_out;
18851885

1886-
dm_submit_bio_remap(io->base_bio, clone, true);
1886+
dm_submit_bio_remap(io->base_bio, clone);
18871887
}
18881888

18891889
#define crypt_io_from_node(node) rb_entry((node), struct dm_crypt_io, rb_node)
@@ -1962,7 +1962,7 @@ static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io, int async)
19621962

19631963
if ((likely(!async) && test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags)) ||
19641964
test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags)) {
1965-
dm_submit_bio_remap(io->base_bio, clone, true);
1965+
dm_submit_bio_remap(io->base_bio, clone);
19661966
return;
19671967
}
19681968

drivers/md/dm-delay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static void flush_bios(struct bio *bio)
7272
while (bio) {
7373
n = bio->bi_next;
7474
bio->bi_next = NULL;
75-
dm_submit_bio_remap(bio, NULL, true);
75+
dm_submit_bio_remap(bio, NULL);
7676
bio = n;
7777
}
7878
}

drivers/md/dm-thin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ static void issue(struct thin_c *tc, struct bio *bio)
755755
struct pool *pool = tc->pool;
756756

757757
if (!bio_triggers_commit(tc, bio)) {
758-
dm_submit_bio_remap(bio, NULL, true);
758+
dm_submit_bio_remap(bio, NULL);
759759
return;
760760
}
761761

@@ -2383,7 +2383,7 @@ static void process_deferred_bios(struct pool *pool)
23832383
if (bio->bi_opf & REQ_PREFLUSH)
23842384
bio_endio(bio);
23852385
else
2386-
dm_submit_bio_remap(bio, NULL, true);
2386+
dm_submit_bio_remap(bio, NULL);
23872387
}
23882388
}
23892389

drivers/md/dm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio)
574574
this_cpu_inc(*md->pending_io);
575575
io->orig_bio = NULL;
576576
io->md = md;
577+
io->map_task = current;
577578
spin_lock_init(&io->endio_lock);
578579

579580
io->start_time = jiffies;
@@ -1189,15 +1190,13 @@ static inline void __dm_submit_bio_remap(struct bio *clone,
11891190
/*
11901191
* @clone: clone bio that DM core passed to target's .map function
11911192
* @tgt_clone: clone of @clone bio that target needs submitted
1192-
* @from_wq: caller is a workqueue thread managed by DM target
11931193
*
11941194
* Targets should use this interface to submit bios they take
11951195
* ownership of when returning DM_MAPIO_SUBMITTED.
11961196
*
11971197
* Target should also enable ti->accounts_remapped_io
11981198
*/
1199-
void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone,
1200-
bool from_wq)
1199+
void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone)
12011200
{
12021201
struct dm_target_io *tio = clone_to_tio(clone);
12031202
struct dm_io *io = tio->io;
@@ -1212,7 +1211,7 @@ void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone,
12121211
* Account io->origin_bio to DM dev on behalf of target
12131212
* that took ownership of IO with DM_MAPIO_SUBMITTED.
12141213
*/
1215-
if (!from_wq) {
1214+
if (io->map_task == current) {
12161215
/* Still in target's map function */
12171216
io->start_io_acct = true;
12181217
} else {
@@ -1568,6 +1567,7 @@ static void dm_split_and_process_bio(struct mapped_device *md,
15681567
}
15691568

15701569
error = __split_and_process_bio(&ci);
1570+
ci.io->map_task = NULL;
15711571
if (error || !ci.sector_count)
15721572
goto out;
15731573

include/linux/device-mapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ int dm_suspended(struct dm_target *ti);
471471
int dm_post_suspending(struct dm_target *ti);
472472
int dm_noflush_suspending(struct dm_target *ti);
473473
void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors);
474-
void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone, bool from_wq);
474+
void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone);
475475
union map_info *dm_get_rq_mapinfo(struct request *rq);
476476

477477
#ifdef CONFIG_BLK_DEV_ZONED

0 commit comments

Comments
 (0)