diff options
author | Kent Overstreet <koverstreet@google.com> | 2012-09-07 16:44:02 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-09-09 04:35:39 -0400 |
commit | ccc5c9ca6aac08218b1ba52afd07a1a9864c8c5d (patch) | |
tree | 44f89900ffc44f63471412f52d10435789fefaaf /drivers/block/pktcdvd.c | |
parent | f44b48c7691be7643877d1f881b5eeace654d05d (diff) |
pktcdvd: Switch to bio_kmalloc()
This is prep work for killing bi_destructor - previously, pktcdvd had
its own pkt_bio_alloc which was basically duplication bio_kmalloc(),
necessitating its own bi_destructor implementation.
v5: Un-reorder some functions, to make the patch easier to review
Signed-off-by: Kent Overstreet <koverstreet@google.com>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/block/pktcdvd.c')
-rw-r--r-- | drivers/block/pktcdvd.c | 52 |
1 files changed, 7 insertions, 45 deletions
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index ba66e4445f41..2e7de7a59bfc 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c | |||
@@ -522,38 +522,6 @@ static void pkt_bio_finished(struct pktcdvd_device *pd) | |||
522 | } | 522 | } |
523 | } | 523 | } |
524 | 524 | ||
525 | static void pkt_bio_destructor(struct bio *bio) | ||
526 | { | ||
527 | kfree(bio->bi_io_vec); | ||
528 | kfree(bio); | ||
529 | } | ||
530 | |||
531 | static struct bio *pkt_bio_alloc(int nr_iovecs) | ||
532 | { | ||
533 | struct bio_vec *bvl = NULL; | ||
534 | struct bio *bio; | ||
535 | |||
536 | bio = kmalloc(sizeof(struct bio), GFP_KERNEL); | ||
537 | if (!bio) | ||
538 | goto no_bio; | ||
539 | bio_init(bio); | ||
540 | |||
541 | bvl = kcalloc(nr_iovecs, sizeof(struct bio_vec), GFP_KERNEL); | ||
542 | if (!bvl) | ||
543 | goto no_bvl; | ||
544 | |||
545 | bio->bi_max_vecs = nr_iovecs; | ||
546 | bio->bi_io_vec = bvl; | ||
547 | bio->bi_destructor = pkt_bio_destructor; | ||
548 | |||
549 | return bio; | ||
550 | |||
551 | no_bvl: | ||
552 | kfree(bio); | ||
553 | no_bio: | ||
554 | return NULL; | ||
555 | } | ||
556 | |||
557 | /* | 525 | /* |
558 | * Allocate a packet_data struct | 526 | * Allocate a packet_data struct |
559 | */ | 527 | */ |
@@ -567,7 +535,7 @@ static struct packet_data *pkt_alloc_packet_data(int frames) | |||
567 | goto no_pkt; | 535 | goto no_pkt; |
568 | 536 | ||
569 | pkt->frames = frames; | 537 | pkt->frames = frames; |
570 | pkt->w_bio = pkt_bio_alloc(frames); | 538 | pkt->w_bio = bio_kmalloc(GFP_KERNEL, frames); |
571 | if (!pkt->w_bio) | 539 | if (!pkt->w_bio) |
572 | goto no_bio; | 540 | goto no_bio; |
573 | 541 | ||
@@ -581,9 +549,10 @@ static struct packet_data *pkt_alloc_packet_data(int frames) | |||
581 | bio_list_init(&pkt->orig_bios); | 549 | bio_list_init(&pkt->orig_bios); |
582 | 550 | ||
583 | for (i = 0; i < frames; i++) { | 551 | for (i = 0; i < frames; i++) { |
584 | struct bio *bio = pkt_bio_alloc(1); | 552 | struct bio *bio = bio_kmalloc(GFP_KERNEL, 1); |
585 | if (!bio) | 553 | if (!bio) |
586 | goto no_rd_bio; | 554 | goto no_rd_bio; |
555 | |||
587 | pkt->r_bios[i] = bio; | 556 | pkt->r_bios[i] = bio; |
588 | } | 557 | } |
589 | 558 | ||
@@ -1111,21 +1080,17 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt) | |||
1111 | * Schedule reads for missing parts of the packet. | 1080 | * Schedule reads for missing parts of the packet. |
1112 | */ | 1081 | */ |
1113 | for (f = 0; f < pkt->frames; f++) { | 1082 | for (f = 0; f < pkt->frames; f++) { |
1114 | struct bio_vec *vec; | ||
1115 | |||
1116 | int p, offset; | 1083 | int p, offset; |
1084 | |||
1117 | if (written[f]) | 1085 | if (written[f]) |
1118 | continue; | 1086 | continue; |
1087 | |||
1119 | bio = pkt->r_bios[f]; | 1088 | bio = pkt->r_bios[f]; |
1120 | vec = bio->bi_io_vec; | 1089 | bio_reset(bio); |
1121 | bio_init(bio); | ||
1122 | bio->bi_max_vecs = 1; | ||
1123 | bio->bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9); | 1090 | bio->bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9); |
1124 | bio->bi_bdev = pd->bdev; | 1091 | bio->bi_bdev = pd->bdev; |
1125 | bio->bi_end_io = pkt_end_io_read; | 1092 | bio->bi_end_io = pkt_end_io_read; |
1126 | bio->bi_private = pkt; | 1093 | bio->bi_private = pkt; |
1127 | bio->bi_io_vec = vec; | ||
1128 | bio->bi_destructor = pkt_bio_destructor; | ||
1129 | 1094 | ||
1130 | p = (f * CD_FRAMESIZE) / PAGE_SIZE; | 1095 | p = (f * CD_FRAMESIZE) / PAGE_SIZE; |
1131 | offset = (f * CD_FRAMESIZE) % PAGE_SIZE; | 1096 | offset = (f * CD_FRAMESIZE) % PAGE_SIZE; |
@@ -1418,14 +1383,11 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) | |||
1418 | } | 1383 | } |
1419 | 1384 | ||
1420 | /* Start the write request */ | 1385 | /* Start the write request */ |
1421 | bio_init(pkt->w_bio); | 1386 | bio_reset(pkt->w_bio); |
1422 | pkt->w_bio->bi_max_vecs = PACKET_MAX_SIZE; | ||
1423 | pkt->w_bio->bi_sector = pkt->sector; | 1387 | pkt->w_bio->bi_sector = pkt->sector; |
1424 | pkt->w_bio->bi_bdev = pd->bdev; | 1388 | pkt->w_bio->bi_bdev = pd->bdev; |
1425 | pkt->w_bio->bi_end_io = pkt_end_io_packet_write; | 1389 | pkt->w_bio->bi_end_io = pkt_end_io_packet_write; |
1426 | pkt->w_bio->bi_private = pkt; | 1390 | pkt->w_bio->bi_private = pkt; |
1427 | pkt->w_bio->bi_io_vec = bvec; | ||
1428 | pkt->w_bio->bi_destructor = pkt_bio_destructor; | ||
1429 | for (f = 0; f < pkt->frames; f++) | 1391 | for (f = 0; f < pkt->frames; f++) |
1430 | if (!bio_add_page(pkt->w_bio, bvec[f].bv_page, CD_FRAMESIZE, bvec[f].bv_offset)) | 1392 | if (!bio_add_page(pkt->w_bio, bvec[f].bv_page, CD_FRAMESIZE, bvec[f].bv_offset)) |
1431 | BUG(); | 1393 | BUG(); |