Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm io: remove code duplication between sync_io and aysnc_io

The only difference between the code to setup and dispatch the io in
sync_io() and async_io() is the sync argument to dispatch_io(), which
is used to update the opf argument.

Update the opf argument direcly in sync_io(), and remove the sync
argument from dispatch_io(). Then, make sync_io() call async_io()
instead of duplicting all of its code.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

authored by

Benjamin Marzinski and committed by
Mikulas Patocka
babe69e8 b0042ba7

+34 -47
+34 -47
drivers/md/dm-io.c
··· 384 384 385 385 static void dispatch_io(blk_opf_t opf, unsigned int num_regions, 386 386 struct dm_io_region *where, struct dpages *dp, 387 - struct io *io, int sync, unsigned short ioprio) 387 + struct io *io, unsigned short ioprio) 388 388 { 389 389 int i; 390 390 struct dpages old_pages = *dp; 391 391 392 392 BUG_ON(num_regions > DM_IO_MAX_REGIONS); 393 - 394 - if (sync) 395 - opf |= REQ_SYNC; 396 393 397 394 /* 398 395 * For multiple regions we need to be careful to rewind ··· 406 409 * the io being completed too early. 407 410 */ 408 411 dec_count(io, 0, 0); 409 - } 410 - 411 - struct sync_io { 412 - unsigned long error_bits; 413 - struct completion wait; 414 - }; 415 - 416 - static void sync_io_complete(unsigned long error, void *context) 417 - { 418 - struct sync_io *sio = context; 419 - 420 - sio->error_bits = error; 421 - complete(&sio->wait); 422 - } 423 - 424 - static int sync_io(struct dm_io_client *client, unsigned int num_regions, 425 - struct dm_io_region *where, blk_opf_t opf, struct dpages *dp, 426 - unsigned long *error_bits, unsigned short ioprio) 427 - { 428 - struct io *io; 429 - struct sync_io sio; 430 - 431 - init_completion(&sio.wait); 432 - 433 - io = mempool_alloc(&client->pool, GFP_NOIO); 434 - io->error_bits = 0; 435 - atomic_set(&io->count, 1); /* see dispatch_io() */ 436 - io->client = client; 437 - io->callback = sync_io_complete; 438 - io->context = &sio; 439 - 440 - io->vma_invalidate_address = dp->vma_invalidate_address; 441 - io->vma_invalidate_size = dp->vma_invalidate_size; 442 - 443 - dispatch_io(opf, num_regions, where, dp, io, 1, ioprio); 444 - 445 - wait_for_completion_io(&sio.wait); 446 - 447 - if (error_bits) 448 - *error_bits = sio.error_bits; 449 - 450 - return sio.error_bits ? -EIO : 0; 451 412 } 452 413 453 414 static void async_io(struct dm_io_client *client, unsigned int num_regions, ··· 425 470 io->vma_invalidate_address = dp->vma_invalidate_address; 426 471 io->vma_invalidate_size = dp->vma_invalidate_size; 427 472 428 - dispatch_io(opf, num_regions, where, dp, io, 0, ioprio); 473 + dispatch_io(opf, num_regions, where, dp, io, ioprio); 474 + } 475 + 476 + struct sync_io { 477 + unsigned long error_bits; 478 + struct completion wait; 479 + }; 480 + 481 + static void sync_io_complete(unsigned long error, void *context) 482 + { 483 + struct sync_io *sio = context; 484 + 485 + sio->error_bits = error; 486 + complete(&sio->wait); 487 + } 488 + 489 + static int sync_io(struct dm_io_client *client, unsigned int num_regions, 490 + struct dm_io_region *where, blk_opf_t opf, struct dpages *dp, 491 + unsigned long *error_bits, unsigned short ioprio) 492 + { 493 + struct sync_io sio; 494 + 495 + init_completion(&sio.wait); 496 + 497 + async_io(client, num_regions, where, opf | REQ_SYNC, dp, 498 + sync_io_complete, &sio, ioprio); 499 + 500 + wait_for_completion_io(&sio.wait); 501 + 502 + if (error_bits) 503 + *error_bits = sio.error_bits; 504 + 505 + return sio.error_bits ? -EIO : 0; 429 506 } 430 507 431 508 static int dp_init(struct dm_io_request *io_req, struct dpages *dp,