Skip to content

Commit e604714

Browse files
Mike Christieaxboe
authored andcommitted
dm: use bio op accessors
Separate the op from the rq_flag_bits and have dm set/get the bio using bio_set_op_attrs/bio_op. Signed-off-by: Mike Christie <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 528ec5a commit e604714

File tree

14 files changed

+99
-80
lines changed

14 files changed

+99
-80
lines changed

drivers/md/dm-bufio.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ static void use_dmio(struct dm_buffer *b, int rw, sector_t block,
574574
{
575575
int r;
576576
struct dm_io_request io_req = {
577-
.bi_rw = rw,
577+
.bi_op = rw,
578+
.bi_op_flags = 0,
578579
.notify.fn = dmio_complete,
579580
.notify.context = b,
580581
.client = b->c->dm_io,
@@ -634,7 +635,7 @@ static void use_inline_bio(struct dm_buffer *b, int rw, sector_t block,
634635
* the dm_buffer's inline bio is local to bufio.
635636
*/
636637
b->bio.bi_private = end_io;
637-
b->bio.bi_rw = rw;
638+
bio_set_op_attrs(&b->bio, rw, 0);
638639

639640
/*
640641
* We assume that if len >= PAGE_SIZE ptr is page-aligned.
@@ -1327,7 +1328,8 @@ EXPORT_SYMBOL_GPL(dm_bufio_write_dirty_buffers);
13271328
int dm_bufio_issue_flush(struct dm_bufio_client *c)
13281329
{
13291330
struct dm_io_request io_req = {
1330-
.bi_rw = WRITE_FLUSH,
1331+
.bi_op = REQ_OP_WRITE,
1332+
.bi_op_flags = WRITE_FLUSH,
13311333
.mem.type = DM_IO_KMEM,
13321334
.mem.ptr.addr = NULL,
13331335
.client = c->dm_io,

drivers/md/dm-cache-target.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,8 @@ static void check_if_tick_bio_needed(struct cache *cache, struct bio *bio)
788788

789789
spin_lock_irqsave(&cache->lock, flags);
790790
if (cache->need_tick_bio &&
791-
!(bio->bi_rw & (REQ_FUA | REQ_FLUSH | REQ_DISCARD))) {
791+
!(bio->bi_rw & (REQ_FUA | REQ_FLUSH)) &&
792+
bio_op(bio) != REQ_OP_DISCARD) {
792793
pb->tick = true;
793794
cache->need_tick_bio = false;
794795
}
@@ -851,7 +852,7 @@ static void inc_ds(struct cache *cache, struct bio *bio,
851852
static bool accountable_bio(struct cache *cache, struct bio *bio)
852853
{
853854
return ((bio->bi_bdev == cache->origin_dev->bdev) &&
854-
!(bio->bi_rw & REQ_DISCARD));
855+
bio_op(bio) != REQ_OP_DISCARD);
855856
}
856857

857858
static void accounted_begin(struct cache *cache, struct bio *bio)
@@ -1067,7 +1068,8 @@ static void dec_io_migrations(struct cache *cache)
10671068

10681069
static bool discard_or_flush(struct bio *bio)
10691070
{
1070-
return bio->bi_rw & (REQ_FLUSH | REQ_FUA | REQ_DISCARD);
1071+
return bio_op(bio) == REQ_OP_DISCARD ||
1072+
bio->bi_rw & (REQ_FLUSH | REQ_FUA);
10711073
}
10721074

10731075
static void __cell_defer(struct cache *cache, struct dm_bio_prison_cell *cell)
@@ -1980,7 +1982,7 @@ static void process_deferred_bios(struct cache *cache)
19801982

19811983
if (bio->bi_rw & REQ_FLUSH)
19821984
process_flush_bio(cache, bio);
1983-
else if (bio->bi_rw & REQ_DISCARD)
1985+
else if (bio_op(bio) == REQ_OP_DISCARD)
19841986
process_discard_bio(cache, &structs, bio);
19851987
else
19861988
process_bio(cache, &structs, bio);

drivers/md/dm-crypt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ static void clone_init(struct dm_crypt_io *io, struct bio *clone)
11361136
clone->bi_private = io;
11371137
clone->bi_end_io = crypt_endio;
11381138
clone->bi_bdev = cc->dev->bdev;
1139-
clone->bi_rw = io->base_bio->bi_rw;
1139+
bio_set_op_attrs(clone, bio_op(io->base_bio), io->base_bio->bi_rw);
11401140
}
11411141

11421142
static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
@@ -1911,11 +1911,11 @@ static int crypt_map(struct dm_target *ti, struct bio *bio)
19111911
struct crypt_config *cc = ti->private;
19121912

19131913
/*
1914-
* If bio is REQ_FLUSH or REQ_DISCARD, just bypass crypt queues.
1914+
* If bio is REQ_FLUSH or REQ_OP_DISCARD, just bypass crypt queues.
19151915
* - for REQ_FLUSH device-mapper core ensures that no IO is in-flight
1916-
* - for REQ_DISCARD caller must use flush if IO ordering matters
1916+
* - for REQ_OP_DISCARD caller must use flush if IO ordering matters
19171917
*/
1918-
if (unlikely(bio->bi_rw & (REQ_FLUSH | REQ_DISCARD))) {
1918+
if (unlikely(bio->bi_rw & REQ_FLUSH || bio_op(bio) == REQ_OP_DISCARD)) {
19191919
bio->bi_bdev = cc->dev->bdev;
19201920
if (bio_sectors(bio))
19211921
bio->bi_iter.bi_sector = cc->start +

drivers/md/dm-io.c

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,9 @@ static void km_dp_init(struct dpages *dp, void *data)
278278
/*-----------------------------------------------------------------
279279
* IO routines that accept a list of pages.
280280
*---------------------------------------------------------------*/
281-
static void do_region(int rw, unsigned region, struct dm_io_region *where,
282-
struct dpages *dp, struct io *io)
281+
static void do_region(int op, int op_flags, unsigned region,
282+
struct dm_io_region *where, struct dpages *dp,
283+
struct io *io)
283284
{
284285
struct bio *bio;
285286
struct page *page;
@@ -295,24 +296,25 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
295296
/*
296297
* Reject unsupported discard and write same requests.
297298
*/
298-
if (rw & REQ_DISCARD)
299+
if (op == REQ_OP_DISCARD)
299300
special_cmd_max_sectors = q->limits.max_discard_sectors;
300-
else if (rw & REQ_WRITE_SAME)
301+
else if (op == REQ_OP_WRITE_SAME)
301302
special_cmd_max_sectors = q->limits.max_write_same_sectors;
302-
if ((rw & (REQ_DISCARD | REQ_WRITE_SAME)) && special_cmd_max_sectors == 0) {
303+
if ((op == REQ_OP_DISCARD || op == REQ_OP_WRITE_SAME) &&
304+
special_cmd_max_sectors == 0) {
303305
dec_count(io, region, -EOPNOTSUPP);
304306
return;
305307
}
306308

307309
/*
308-
* where->count may be zero if rw holds a flush and we need to
310+
* where->count may be zero if op holds a flush and we need to
309311
* send a zero-sized flush.
310312
*/
311313
do {
312314
/*
313315
* Allocate a suitably sized-bio.
314316
*/
315-
if ((rw & REQ_DISCARD) || (rw & REQ_WRITE_SAME))
317+
if ((op == REQ_OP_DISCARD) || (op == REQ_OP_WRITE_SAME))
316318
num_bvecs = 1;
317319
else
318320
num_bvecs = min_t(int, BIO_MAX_PAGES,
@@ -322,14 +324,14 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
322324
bio->bi_iter.bi_sector = where->sector + (where->count - remaining);
323325
bio->bi_bdev = where->bdev;
324326
bio->bi_end_io = endio;
325-
bio->bi_rw = rw;
327+
bio_set_op_attrs(bio, op, op_flags);
326328
store_io_and_region_in_bio(bio, io, region);
327329

328-
if (rw & REQ_DISCARD) {
330+
if (op == REQ_OP_DISCARD) {
329331
num_sectors = min_t(sector_t, special_cmd_max_sectors, remaining);
330332
bio->bi_iter.bi_size = num_sectors << SECTOR_SHIFT;
331333
remaining -= num_sectors;
332-
} else if (rw & REQ_WRITE_SAME) {
334+
} else if (op == REQ_OP_WRITE_SAME) {
333335
/*
334336
* WRITE SAME only uses a single page.
335337
*/
@@ -360,7 +362,7 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
360362
} while (remaining);
361363
}
362364

363-
static void dispatch_io(int rw, unsigned int num_regions,
365+
static void dispatch_io(int op, int op_flags, unsigned int num_regions,
364366
struct dm_io_region *where, struct dpages *dp,
365367
struct io *io, int sync)
366368
{
@@ -370,16 +372,16 @@ static void dispatch_io(int rw, unsigned int num_regions,
370372
BUG_ON(num_regions > DM_IO_MAX_REGIONS);
371373

372374
if (sync)
373-
rw |= REQ_SYNC;
375+
op_flags |= REQ_SYNC;
374376

375377
/*
376378
* For multiple regions we need to be careful to rewind
377379
* the dp object for each call to do_region.
378380
*/
379381
for (i = 0; i < num_regions; i++) {
380382
*dp = old_pages;
381-
if (where[i].count || (rw & REQ_FLUSH))
382-
do_region(rw, i, where + i, dp, io);
383+
if (where[i].count || (op_flags & REQ_FLUSH))
384+
do_region(op, op_flags, i, where + i, dp, io);
383385
}
384386

385387
/*
@@ -403,13 +405,13 @@ static void sync_io_complete(unsigned long error, void *context)
403405
}
404406

405407
static int sync_io(struct dm_io_client *client, unsigned int num_regions,
406-
struct dm_io_region *where, int rw, struct dpages *dp,
407-
unsigned long *error_bits)
408+
struct dm_io_region *where, int op, int op_flags,
409+
struct dpages *dp, unsigned long *error_bits)
408410
{
409411
struct io *io;
410412
struct sync_io sio;
411413

412-
if (num_regions > 1 && !op_is_write(rw)) {
414+
if (num_regions > 1 && !op_is_write(op)) {
413415
WARN_ON(1);
414416
return -EIO;
415417
}
@@ -426,7 +428,7 @@ static int sync_io(struct dm_io_client *client, unsigned int num_regions,
426428
io->vma_invalidate_address = dp->vma_invalidate_address;
427429
io->vma_invalidate_size = dp->vma_invalidate_size;
428430

429-
dispatch_io(rw, num_regions, where, dp, io, 1);
431+
dispatch_io(op, op_flags, num_regions, where, dp, io, 1);
430432

431433
wait_for_completion_io(&sio.wait);
432434

@@ -437,12 +439,12 @@ static int sync_io(struct dm_io_client *client, unsigned int num_regions,
437439
}
438440

439441
static int async_io(struct dm_io_client *client, unsigned int num_regions,
440-
struct dm_io_region *where, int rw, struct dpages *dp,
441-
io_notify_fn fn, void *context)
442+
struct dm_io_region *where, int op, int op_flags,
443+
struct dpages *dp, io_notify_fn fn, void *context)
442444
{
443445
struct io *io;
444446

445-
if (num_regions > 1 && !op_is_write(rw)) {
447+
if (num_regions > 1 && !op_is_write(op)) {
446448
WARN_ON(1);
447449
fn(1, context);
448450
return -EIO;
@@ -458,7 +460,7 @@ static int async_io(struct dm_io_client *client, unsigned int num_regions,
458460
io->vma_invalidate_address = dp->vma_invalidate_address;
459461
io->vma_invalidate_size = dp->vma_invalidate_size;
460462

461-
dispatch_io(rw, num_regions, where, dp, io, 0);
463+
dispatch_io(op, op_flags, num_regions, where, dp, io, 0);
462464
return 0;
463465
}
464466

@@ -481,7 +483,7 @@ static int dp_init(struct dm_io_request *io_req, struct dpages *dp,
481483

482484
case DM_IO_VMA:
483485
flush_kernel_vmap_range(io_req->mem.ptr.vma, size);
484-
if ((io_req->bi_rw & RW_MASK) == READ) {
486+
if (io_req->bi_op == REQ_OP_READ) {
485487
dp->vma_invalidate_address = io_req->mem.ptr.vma;
486488
dp->vma_invalidate_size = size;
487489
}
@@ -519,10 +521,12 @@ int dm_io(struct dm_io_request *io_req, unsigned num_regions,
519521

520522
if (!io_req->notify.fn)
521523
return sync_io(io_req->client, num_regions, where,
522-
io_req->bi_rw, &dp, sync_error_bits);
524+
io_req->bi_op, io_req->bi_op_flags, &dp,
525+
sync_error_bits);
523526

524-
return async_io(io_req->client, num_regions, where, io_req->bi_rw,
525-
&dp, io_req->notify.fn, io_req->notify.context);
527+
return async_io(io_req->client, num_regions, where, io_req->bi_op,
528+
io_req->bi_op_flags, &dp, io_req->notify.fn,
529+
io_req->notify.context);
526530
}
527531
EXPORT_SYMBOL(dm_io);
528532

drivers/md/dm-kcopyd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ static int run_io_job(struct kcopyd_job *job)
496496
{
497497
int r;
498498
struct dm_io_request io_req = {
499-
.bi_rw = job->rw,
499+
.bi_op = job->rw,
500+
.bi_op_flags = 0,
500501
.mem.type = DM_IO_PAGE_LIST,
501502
.mem.ptr.pl = job->pages,
502503
.mem.offset = 0,
@@ -734,7 +735,7 @@ int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
734735
/*
735736
* Use WRITE SAME to optimize zeroing if all dests support it.
736737
*/
737-
job->rw = WRITE | REQ_WRITE_SAME;
738+
job->rw = REQ_OP_WRITE_SAME;
738739
for (i = 0; i < job->num_dests; i++)
739740
if (!bdev_write_same(job->dests[i].bdev)) {
740741
job->rw = WRITE;

drivers/md/dm-log-writes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static int write_metadata(struct log_writes_c *lc, void *entry,
205205
bio->bi_bdev = lc->logdev->bdev;
206206
bio->bi_end_io = log_end_io;
207207
bio->bi_private = lc;
208-
bio->bi_rw = WRITE;
208+
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
209209

210210
page = alloc_page(GFP_KERNEL);
211211
if (!page) {
@@ -270,7 +270,7 @@ static int log_one_block(struct log_writes_c *lc,
270270
bio->bi_bdev = lc->logdev->bdev;
271271
bio->bi_end_io = log_end_io;
272272
bio->bi_private = lc;
273-
bio->bi_rw = WRITE;
273+
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
274274

275275
for (i = 0; i < block->vec_cnt; i++) {
276276
/*
@@ -292,7 +292,7 @@ static int log_one_block(struct log_writes_c *lc,
292292
bio->bi_bdev = lc->logdev->bdev;
293293
bio->bi_end_io = log_end_io;
294294
bio->bi_private = lc;
295-
bio->bi_rw = WRITE;
295+
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
296296

297297
ret = bio_add_page(bio, block->vecs[i].bv_page,
298298
block->vecs[i].bv_len, 0);
@@ -557,7 +557,7 @@ static int log_writes_map(struct dm_target *ti, struct bio *bio)
557557
int i = 0;
558558
bool flush_bio = (bio->bi_rw & REQ_FLUSH);
559559
bool fua_bio = (bio->bi_rw & REQ_FUA);
560-
bool discard_bio = (bio->bi_rw & REQ_DISCARD);
560+
bool discard_bio = (bio_op(bio) == REQ_OP_DISCARD);
561561

562562
pb->block = NULL;
563563

drivers/md/dm-log.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static void header_from_disk(struct log_header_core *core, struct log_header_dis
293293

294294
static int rw_header(struct log_c *lc, int rw)
295295
{
296-
lc->io_req.bi_rw = rw;
296+
lc->io_req.bi_op = rw;
297297

298298
return dm_io(&lc->io_req, 1, &lc->header_location, NULL);
299299
}
@@ -306,7 +306,8 @@ static int flush_header(struct log_c *lc)
306306
.count = 0,
307307
};
308308

309-
lc->io_req.bi_rw = WRITE_FLUSH;
309+
lc->io_req.bi_op = REQ_OP_WRITE;
310+
lc->io_req.bi_op_flags = WRITE_FLUSH;
310311

311312
return dm_io(&lc->io_req, 1, &null_location, NULL);
312313
}

drivers/md/dm-raid1.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ static int mirror_flush(struct dm_target *ti)
260260
struct dm_io_region io[ms->nr_mirrors];
261261
struct mirror *m;
262262
struct dm_io_request io_req = {
263-
.bi_rw = WRITE_FLUSH,
263+
.bi_op = REQ_OP_WRITE,
264+
.bi_op_flags = WRITE_FLUSH,
264265
.mem.type = DM_IO_KMEM,
265266
.mem.ptr.addr = NULL,
266267
.client = ms->io_client,
@@ -541,7 +542,8 @@ static void read_async_bio(struct mirror *m, struct bio *bio)
541542
{
542543
struct dm_io_region io;
543544
struct dm_io_request io_req = {
544-
.bi_rw = READ,
545+
.bi_op = REQ_OP_READ,
546+
.bi_op_flags = 0,
545547
.mem.type = DM_IO_BIO,
546548
.mem.ptr.bio = bio,
547549
.notify.fn = read_callback,
@@ -624,7 +626,7 @@ static void write_callback(unsigned long error, void *context)
624626
* If the bio is discard, return an error, but do not
625627
* degrade the array.
626628
*/
627-
if (bio->bi_rw & REQ_DISCARD) {
629+
if (bio_op(bio) == REQ_OP_DISCARD) {
628630
bio->bi_error = -EOPNOTSUPP;
629631
bio_endio(bio);
630632
return;
@@ -654,16 +656,17 @@ static void do_write(struct mirror_set *ms, struct bio *bio)
654656
struct dm_io_region io[ms->nr_mirrors], *dest = io;
655657
struct mirror *m;
656658
struct dm_io_request io_req = {
657-
.bi_rw = WRITE | (bio->bi_rw & WRITE_FLUSH_FUA),
659+
.bi_op = REQ_OP_WRITE,
660+
.bi_op_flags = bio->bi_rw & WRITE_FLUSH_FUA,
658661
.mem.type = DM_IO_BIO,
659662
.mem.ptr.bio = bio,
660663
.notify.fn = write_callback,
661664
.notify.context = bio,
662665
.client = ms->io_client,
663666
};
664667

665-
if (bio->bi_rw & REQ_DISCARD) {
666-
io_req.bi_rw |= REQ_DISCARD;
668+
if (bio_op(bio) == REQ_OP_DISCARD) {
669+
io_req.bi_op = REQ_OP_DISCARD;
667670
io_req.mem.type = DM_IO_KMEM;
668671
io_req.mem.ptr.addr = NULL;
669672
}
@@ -702,7 +705,7 @@ static void do_writes(struct mirror_set *ms, struct bio_list *writes)
702705

703706
while ((bio = bio_list_pop(writes))) {
704707
if ((bio->bi_rw & REQ_FLUSH) ||
705-
(bio->bi_rw & REQ_DISCARD)) {
708+
(bio_op(bio) == REQ_OP_DISCARD)) {
706709
bio_list_add(&sync, bio);
707710
continue;
708711
}
@@ -1250,7 +1253,7 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
12501253
* We need to dec pending if this was a write.
12511254
*/
12521255
if (rw == WRITE) {
1253-
if (!(bio->bi_rw & (REQ_FLUSH | REQ_DISCARD)))
1256+
if (!(bio->bi_rw & REQ_FLUSH) && bio_op(bio) != REQ_OP_DISCARD)
12541257
dm_rh_dec(ms->rh, bio_record->write_region);
12551258
return error;
12561259
}

0 commit comments

Comments
 (0)