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

pktcdvd: use BIO list management functions

Now that the bio list management stuff is generic, convert pktcdvd to
use bio lists instead of its own private bio list implementation.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Acked-by: Peter Osterlund <petero2@telia.com>
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>

authored by

Akinobu Mita and committed by
Jens Axboe
c5ecc484 bddd87c7

+25 -74
+21 -68
drivers/block/pktcdvd.c
··· 569 569 } 570 570 571 571 spin_lock_init(&pkt->lock); 572 + bio_list_init(&pkt->orig_bios); 572 573 573 574 for (i = 0; i < frames; i++) { 574 575 struct bio *bio = pkt_bio_alloc(1); ··· 722 721 } 723 722 724 723 /* 725 - * Add a bio to a single linked list defined by its head and tail pointers. 726 - */ 727 - static void pkt_add_list_last(struct bio *bio, struct bio **list_head, struct bio **list_tail) 728 - { 729 - bio->bi_next = NULL; 730 - if (*list_tail) { 731 - BUG_ON((*list_head) == NULL); 732 - (*list_tail)->bi_next = bio; 733 - (*list_tail) = bio; 734 - } else { 735 - BUG_ON((*list_head) != NULL); 736 - (*list_head) = bio; 737 - (*list_tail) = bio; 738 - } 739 - } 740 - 741 - /* 742 - * Remove and return the first bio from a single linked list defined by its 743 - * head and tail pointers. 744 - */ 745 - static inline struct bio *pkt_get_list_first(struct bio **list_head, struct bio **list_tail) 746 - { 747 - struct bio *bio; 748 - 749 - if (*list_head == NULL) 750 - return NULL; 751 - 752 - bio = *list_head; 753 - *list_head = bio->bi_next; 754 - if (*list_head == NULL) 755 - *list_tail = NULL; 756 - 757 - bio->bi_next = NULL; 758 - return bio; 759 - } 760 - 761 - /* 762 724 * Send a packet_command to the underlying block device and 763 725 * wait for completion. 764 726 */ ··· 840 876 static void pkt_queue_bio(struct pktcdvd_device *pd, struct bio *bio) 841 877 { 842 878 spin_lock(&pd->iosched.lock); 843 - if (bio_data_dir(bio) == READ) { 844 - pkt_add_list_last(bio, &pd->iosched.read_queue, 845 - &pd->iosched.read_queue_tail); 846 - } else { 847 - pkt_add_list_last(bio, &pd->iosched.write_queue, 848 - &pd->iosched.write_queue_tail); 849 - } 879 + if (bio_data_dir(bio) == READ) 880 + bio_list_add(&pd->iosched.read_queue, bio); 881 + else 882 + bio_list_add(&pd->iosched.write_queue, bio); 850 883 spin_unlock(&pd->iosched.lock); 851 884 852 885 atomic_set(&pd->iosched.attention, 1); ··· 878 917 int reads_queued, writes_queued; 879 918 880 919 spin_lock(&pd->iosched.lock); 881 - reads_queued = (pd->iosched.read_queue != NULL); 882 - writes_queued = (pd->iosched.write_queue != NULL); 920 + reads_queued = !bio_list_empty(&pd->iosched.read_queue); 921 + writes_queued = !bio_list_empty(&pd->iosched.write_queue); 883 922 spin_unlock(&pd->iosched.lock); 884 923 885 924 if (!reads_queued && !writes_queued) ··· 888 927 if (pd->iosched.writing) { 889 928 int need_write_seek = 1; 890 929 spin_lock(&pd->iosched.lock); 891 - bio = pd->iosched.write_queue; 930 + bio = bio_list_peek(&pd->iosched.write_queue); 892 931 spin_unlock(&pd->iosched.lock); 893 932 if (bio && (bio->bi_sector == pd->iosched.last_write)) 894 933 need_write_seek = 0; ··· 911 950 } 912 951 913 952 spin_lock(&pd->iosched.lock); 914 - if (pd->iosched.writing) { 915 - bio = pkt_get_list_first(&pd->iosched.write_queue, 916 - &pd->iosched.write_queue_tail); 917 - } else { 918 - bio = pkt_get_list_first(&pd->iosched.read_queue, 919 - &pd->iosched.read_queue_tail); 920 - } 953 + if (pd->iosched.writing) 954 + bio = bio_list_pop(&pd->iosched.write_queue); 955 + else 956 + bio = bio_list_pop(&pd->iosched.read_queue); 921 957 spin_unlock(&pd->iosched.lock); 922 958 923 959 if (!bio) ··· 1072 1114 int f; 1073 1115 char written[PACKET_MAX_SIZE]; 1074 1116 1075 - BUG_ON(!pkt->orig_bios); 1117 + BUG_ON(bio_list_empty(&pkt->orig_bios)); 1076 1118 1077 1119 atomic_set(&pkt->io_wait, 0); 1078 1120 atomic_set(&pkt->io_errors, 0); ··· 1082 1124 */ 1083 1125 memset(written, 0, sizeof(written)); 1084 1126 spin_lock(&pkt->lock); 1085 - for (bio = pkt->orig_bios; bio; bio = bio->bi_next) { 1127 + bio_list_for_each(bio, &pkt->orig_bios) { 1086 1128 int first_frame = (bio->bi_sector - pkt->sector) / (CD_FRAMESIZE >> 9); 1087 1129 int num_frames = bio->bi_size / CD_FRAMESIZE; 1088 1130 pd->stats.secs_w += num_frames * (CD_FRAMESIZE >> 9); ··· 1321 1363 break; 1322 1364 pkt_rbtree_erase(pd, node); 1323 1365 spin_lock(&pkt->lock); 1324 - pkt_add_list_last(bio, &pkt->orig_bios, &pkt->orig_bios_tail); 1366 + bio_list_add(&pkt->orig_bios, bio); 1325 1367 pkt->write_size += bio->bi_size / CD_FRAMESIZE; 1326 1368 spin_unlock(&pkt->lock); 1327 1369 } ··· 1367 1409 */ 1368 1410 frames_write = 0; 1369 1411 spin_lock(&pkt->lock); 1370 - for (bio = pkt->orig_bios; bio; bio = bio->bi_next) { 1412 + bio_list_for_each(bio, &pkt->orig_bios) { 1371 1413 int segment = bio->bi_idx; 1372 1414 int src_offs = 0; 1373 1415 int first_frame = (bio->bi_sector - pkt->sector) / (CD_FRAMESIZE >> 9); ··· 1430 1472 1431 1473 static void pkt_finish_packet(struct packet_data *pkt, int uptodate) 1432 1474 { 1433 - struct bio *bio, *next; 1475 + struct bio *bio; 1434 1476 1435 1477 if (!uptodate) 1436 1478 pkt->cache_valid = 0; 1437 1479 1438 1480 /* Finish all bios corresponding to this packet */ 1439 - bio = pkt->orig_bios; 1440 - while (bio) { 1441 - next = bio->bi_next; 1442 - bio->bi_next = NULL; 1481 + while ((bio = bio_list_pop(&pkt->orig_bios))) 1443 1482 bio_endio(bio, uptodate ? 0 : -EIO); 1444 - bio = next; 1445 - } 1446 - pkt->orig_bios = pkt->orig_bios_tail = NULL; 1447 1483 } 1448 1484 1449 1485 static void pkt_run_state_machine(struct pktcdvd_device *pd, struct packet_data *pkt) ··· 2519 2567 spin_lock(&pkt->lock); 2520 2568 if ((pkt->state == PACKET_WAITING_STATE) || 2521 2569 (pkt->state == PACKET_READ_WAIT_STATE)) { 2522 - pkt_add_list_last(bio, &pkt->orig_bios, 2523 - &pkt->orig_bios_tail); 2570 + bio_list_add(&pkt->orig_bios, bio); 2524 2571 pkt->write_size += bio->bi_size / CD_FRAMESIZE; 2525 2572 if ((pkt->write_size >= pkt->frames) && 2526 2573 (pkt->state == PACKET_WAITING_STATE)) { ··· 2849 2898 2850 2899 spin_lock_init(&pd->lock); 2851 2900 spin_lock_init(&pd->iosched.lock); 2901 + bio_list_init(&pd->iosched.read_queue); 2902 + bio_list_init(&pd->iosched.write_queue); 2852 2903 sprintf(pd->name, DRIVER_NAME"%d", idx); 2853 2904 init_waitqueue_head(&pd->wqueue); 2854 2905 pd->bio_queue = RB_ROOT;
+4 -6
include/linux/pktcdvd.h
··· 163 163 atomic_t attention; /* Set to non-zero when queue processing is needed */ 164 164 int writing; /* Non-zero when writing, zero when reading */ 165 165 spinlock_t lock; /* Protecting read/write queue manipulations */ 166 - struct bio *read_queue; 167 - struct bio *read_queue_tail; 168 - struct bio *write_queue; 169 - struct bio *write_queue_tail; 166 + struct bio_list read_queue; 167 + struct bio_list write_queue; 170 168 sector_t last_write; /* The sector where the last write ended */ 171 169 int successive_reads; 172 170 }; ··· 204 206 spinlock_t lock; /* Lock protecting state transitions and */ 205 207 /* orig_bios list */ 206 208 207 - struct bio *orig_bios; /* Original bios passed to pkt_make_request */ 208 - struct bio *orig_bios_tail;/* that will be handled by this packet */ 209 + struct bio_list orig_bios; /* Original bios passed to pkt_make_request */ 210 + /* that will be handled by this packet */ 209 211 int write_size; /* Total size of all bios in the orig_bios */ 210 212 /* list, measured in number of frames */ 211 213