pktcdvd.c (64b9fb5704a479d98a59f2a1d45d3331a8f847f8) | pktcdvd.c (086fa5ff0854c676ec333760f4c0154b3b242616) |
---|---|
1/* 2 * Copyright (C) 2000 Jens Axboe <axboe@suse.de> 3 * Copyright (C) 2001-2004 Peter Osterlund <petero2@telia.com> 4 * Copyright (C) 2006 Thomas Maier <balagi@justmail.de> 5 * 6 * May be copied or modified under the terms of the GNU General Public 7 * License. See linux/COPYING for more information. 8 * --- 555 unchanged lines hidden (view full) --- 564 565 for (i = 0; i < frames / FRAMES_PER_PAGE; i++) { 566 pkt->pages[i] = alloc_page(GFP_KERNEL|__GFP_ZERO); 567 if (!pkt->pages[i]) 568 goto no_page; 569 } 570 571 spin_lock_init(&pkt->lock); | 1/* 2 * Copyright (C) 2000 Jens Axboe <axboe@suse.de> 3 * Copyright (C) 2001-2004 Peter Osterlund <petero2@telia.com> 4 * Copyright (C) 2006 Thomas Maier <balagi@justmail.de> 5 * 6 * May be copied or modified under the terms of the GNU General Public 7 * License. See linux/COPYING for more information. 8 * --- 555 unchanged lines hidden (view full) --- 564 565 for (i = 0; i < frames / FRAMES_PER_PAGE; i++) { 566 pkt->pages[i] = alloc_page(GFP_KERNEL|__GFP_ZERO); 567 if (!pkt->pages[i]) 568 goto no_page; 569 } 570 571 spin_lock_init(&pkt->lock); |
572 bio_list_init(&pkt->orig_bios); |
|
572 573 for (i = 0; i < frames; i++) { 574 struct bio *bio = pkt_bio_alloc(1); 575 if (!bio) 576 goto no_rd_bio; 577 pkt->r_bios[i] = bio; 578 } 579 --- 136 unchanged lines hidden (view full) --- 716 p = &(*p)->rb_right; 717 } 718 rb_link_node(&node->rb_node, parent, p); 719 rb_insert_color(&node->rb_node, &pd->bio_queue); 720 pd->bio_queue_size++; 721} 722 723/* | 573 574 for (i = 0; i < frames; i++) { 575 struct bio *bio = pkt_bio_alloc(1); 576 if (!bio) 577 goto no_rd_bio; 578 pkt->r_bios[i] = bio; 579 } 580 --- 136 unchanged lines hidden (view full) --- 717 p = &(*p)->rb_right; 718 } 719 rb_link_node(&node->rb_node, parent, p); 720 rb_insert_color(&node->rb_node, &pd->bio_queue); 721 pd->bio_queue_size++; 722} 723 724/* |
724 * Add a bio to a single linked list defined by its head and tail pointers. 725 */ 726static void pkt_add_list_last(struct bio *bio, struct bio **list_head, struct bio **list_tail) 727{ 728 bio->bi_next = NULL; 729 if (*list_tail) { 730 BUG_ON((*list_head) == NULL); 731 (*list_tail)->bi_next = bio; 732 (*list_tail) = bio; 733 } else { 734 BUG_ON((*list_head) != NULL); 735 (*list_head) = bio; 736 (*list_tail) = bio; 737 } 738} 739 740/* 741 * Remove and return the first bio from a single linked list defined by its 742 * head and tail pointers. 743 */ 744static inline struct bio *pkt_get_list_first(struct bio **list_head, struct bio **list_tail) 745{ 746 struct bio *bio; 747 748 if (*list_head == NULL) 749 return NULL; 750 751 bio = *list_head; 752 *list_head = bio->bi_next; 753 if (*list_head == NULL) 754 *list_tail = NULL; 755 756 bio->bi_next = NULL; 757 return bio; 758} 759 760/* | |
761 * Send a packet_command to the underlying block device and 762 * wait for completion. 763 */ 764static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc) 765{ 766 struct request_queue *q = bdev_get_queue(pd->bdev); 767 struct request *rq; 768 int ret = 0; --- 102 unchanged lines hidden (view full) --- 871 872/* 873 * Queue a bio for processing by the low-level CD device. Must be called 874 * from process context. 875 */ 876static void pkt_queue_bio(struct pktcdvd_device *pd, struct bio *bio) 877{ 878 spin_lock(&pd->iosched.lock); | 725 * Send a packet_command to the underlying block device and 726 * wait for completion. 727 */ 728static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc) 729{ 730 struct request_queue *q = bdev_get_queue(pd->bdev); 731 struct request *rq; 732 int ret = 0; --- 102 unchanged lines hidden (view full) --- 835 836/* 837 * Queue a bio for processing by the low-level CD device. Must be called 838 * from process context. 839 */ 840static void pkt_queue_bio(struct pktcdvd_device *pd, struct bio *bio) 841{ 842 spin_lock(&pd->iosched.lock); |
879 if (bio_data_dir(bio) == READ) { 880 pkt_add_list_last(bio, &pd->iosched.read_queue, 881 &pd->iosched.read_queue_tail); 882 } else { 883 pkt_add_list_last(bio, &pd->iosched.write_queue, 884 &pd->iosched.write_queue_tail); 885 } | 843 if (bio_data_dir(bio) == READ) 844 bio_list_add(&pd->iosched.read_queue, bio); 845 else 846 bio_list_add(&pd->iosched.write_queue, bio); |
886 spin_unlock(&pd->iosched.lock); 887 888 atomic_set(&pd->iosched.attention, 1); 889 wake_up(&pd->wqueue); 890} 891 892/* 893 * Process the queued read/write requests. This function handles special --- 18 unchanged lines hidden (view full) --- 912 return; 913 atomic_set(&pd->iosched.attention, 0); 914 915 for (;;) { 916 struct bio *bio; 917 int reads_queued, writes_queued; 918 919 spin_lock(&pd->iosched.lock); | 847 spin_unlock(&pd->iosched.lock); 848 849 atomic_set(&pd->iosched.attention, 1); 850 wake_up(&pd->wqueue); 851} 852 853/* 854 * Process the queued read/write requests. This function handles special --- 18 unchanged lines hidden (view full) --- 873 return; 874 atomic_set(&pd->iosched.attention, 0); 875 876 for (;;) { 877 struct bio *bio; 878 int reads_queued, writes_queued; 879 880 spin_lock(&pd->iosched.lock); |
920 reads_queued = (pd->iosched.read_queue != NULL); 921 writes_queued = (pd->iosched.write_queue != NULL); | 881 reads_queued = !bio_list_empty(&pd->iosched.read_queue); 882 writes_queued = !bio_list_empty(&pd->iosched.write_queue); |
922 spin_unlock(&pd->iosched.lock); 923 924 if (!reads_queued && !writes_queued) 925 break; 926 927 if (pd->iosched.writing) { 928 int need_write_seek = 1; 929 spin_lock(&pd->iosched.lock); | 883 spin_unlock(&pd->iosched.lock); 884 885 if (!reads_queued && !writes_queued) 886 break; 887 888 if (pd->iosched.writing) { 889 int need_write_seek = 1; 890 spin_lock(&pd->iosched.lock); |
930 bio = pd->iosched.write_queue; | 891 bio = bio_list_peek(&pd->iosched.write_queue); |
931 spin_unlock(&pd->iosched.lock); 932 if (bio && (bio->bi_sector == pd->iosched.last_write)) 933 need_write_seek = 0; 934 if (need_write_seek && reads_queued) { 935 if (atomic_read(&pd->cdrw.pending_bios) > 0) { 936 VPRINTK(DRIVER_NAME": write, waiting\n"); 937 break; 938 } --- 6 unchanged lines hidden (view full) --- 945 VPRINTK(DRIVER_NAME": read, waiting\n"); 946 break; 947 } 948 pd->iosched.writing = 1; 949 } 950 } 951 952 spin_lock(&pd->iosched.lock); | 892 spin_unlock(&pd->iosched.lock); 893 if (bio && (bio->bi_sector == pd->iosched.last_write)) 894 need_write_seek = 0; 895 if (need_write_seek && reads_queued) { 896 if (atomic_read(&pd->cdrw.pending_bios) > 0) { 897 VPRINTK(DRIVER_NAME": write, waiting\n"); 898 break; 899 } --- 6 unchanged lines hidden (view full) --- 906 VPRINTK(DRIVER_NAME": read, waiting\n"); 907 break; 908 } 909 pd->iosched.writing = 1; 910 } 911 } 912 913 spin_lock(&pd->iosched.lock); |
953 if (pd->iosched.writing) { 954 bio = pkt_get_list_first(&pd->iosched.write_queue, 955 &pd->iosched.write_queue_tail); 956 } else { 957 bio = pkt_get_list_first(&pd->iosched.read_queue, 958 &pd->iosched.read_queue_tail); 959 } | 914 if (pd->iosched.writing) 915 bio = bio_list_pop(&pd->iosched.write_queue); 916 else 917 bio = bio_list_pop(&pd->iosched.read_queue); |
960 spin_unlock(&pd->iosched.lock); 961 962 if (!bio) 963 continue; 964 965 if (bio_data_dir(bio) == READ) 966 pd->iosched.successive_reads += bio->bi_size >> 10; 967 else { --- 141 unchanged lines hidden (view full) --- 1109 */ 1110static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt) 1111{ 1112 int frames_read = 0; 1113 struct bio *bio; 1114 int f; 1115 char written[PACKET_MAX_SIZE]; 1116 | 918 spin_unlock(&pd->iosched.lock); 919 920 if (!bio) 921 continue; 922 923 if (bio_data_dir(bio) == READ) 924 pd->iosched.successive_reads += bio->bi_size >> 10; 925 else { --- 141 unchanged lines hidden (view full) --- 1067 */ 1068static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt) 1069{ 1070 int frames_read = 0; 1071 struct bio *bio; 1072 int f; 1073 char written[PACKET_MAX_SIZE]; 1074 |
1117 BUG_ON(!pkt->orig_bios); | 1075 BUG_ON(bio_list_empty(&pkt->orig_bios)); |
1118 1119 atomic_set(&pkt->io_wait, 0); 1120 atomic_set(&pkt->io_errors, 0); 1121 1122 /* 1123 * Figure out which frames we need to read before we can write. 1124 */ 1125 memset(written, 0, sizeof(written)); 1126 spin_lock(&pkt->lock); | 1076 1077 atomic_set(&pkt->io_wait, 0); 1078 atomic_set(&pkt->io_errors, 0); 1079 1080 /* 1081 * Figure out which frames we need to read before we can write. 1082 */ 1083 memset(written, 0, sizeof(written)); 1084 spin_lock(&pkt->lock); |
1127 for (bio = pkt->orig_bios; bio; bio = bio->bi_next) { | 1085 bio_list_for_each(bio, &pkt->orig_bios) { |
1128 int first_frame = (bio->bi_sector - pkt->sector) / (CD_FRAMESIZE >> 9); 1129 int num_frames = bio->bi_size / CD_FRAMESIZE; 1130 pd->stats.secs_w += num_frames * (CD_FRAMESIZE >> 9); 1131 BUG_ON(first_frame < 0); 1132 BUG_ON(first_frame + num_frames > pkt->frames); 1133 for (f = first_frame; f < first_frame + num_frames; f++) 1134 written[f] = 1; 1135 } --- 222 unchanged lines hidden (view full) --- 1358 while ((node = pkt_rbtree_find(pd, zone)) != NULL) { 1359 bio = node->bio; 1360 VPRINTK("pkt_handle_queue: found zone=%llx\n", 1361 (unsigned long long)ZONE(bio->bi_sector, pd)); 1362 if (ZONE(bio->bi_sector, pd) != zone) 1363 break; 1364 pkt_rbtree_erase(pd, node); 1365 spin_lock(&pkt->lock); | 1086 int first_frame = (bio->bi_sector - pkt->sector) / (CD_FRAMESIZE >> 9); 1087 int num_frames = bio->bi_size / CD_FRAMESIZE; 1088 pd->stats.secs_w += num_frames * (CD_FRAMESIZE >> 9); 1089 BUG_ON(first_frame < 0); 1090 BUG_ON(first_frame + num_frames > pkt->frames); 1091 for (f = first_frame; f < first_frame + num_frames; f++) 1092 written[f] = 1; 1093 } --- 222 unchanged lines hidden (view full) --- 1316 while ((node = pkt_rbtree_find(pd, zone)) != NULL) { 1317 bio = node->bio; 1318 VPRINTK("pkt_handle_queue: found zone=%llx\n", 1319 (unsigned long long)ZONE(bio->bi_sector, pd)); 1320 if (ZONE(bio->bi_sector, pd) != zone) 1321 break; 1322 pkt_rbtree_erase(pd, node); 1323 spin_lock(&pkt->lock); |
1366 pkt_add_list_last(bio, &pkt->orig_bios, &pkt->orig_bios_tail); | 1324 bio_list_add(&pkt->orig_bios, bio); |
1367 pkt->write_size += bio->bi_size / CD_FRAMESIZE; 1368 spin_unlock(&pkt->lock); 1369 } 1370 /* check write congestion marks, and if bio_queue_size is 1371 below, wake up any waiters */ 1372 wakeup = (pd->write_congestion_on > 0 1373 && pd->bio_queue_size <= pd->write_congestion_off); 1374 spin_unlock(&pd->lock); --- 29 unchanged lines hidden (view full) --- 1404 bvec[f].bv_offset = (f * CD_FRAMESIZE) % PAGE_SIZE; 1405 } 1406 1407 /* 1408 * Fill-in bvec with data from orig_bios. 1409 */ 1410 frames_write = 0; 1411 spin_lock(&pkt->lock); | 1325 pkt->write_size += bio->bi_size / CD_FRAMESIZE; 1326 spin_unlock(&pkt->lock); 1327 } 1328 /* check write congestion marks, and if bio_queue_size is 1329 below, wake up any waiters */ 1330 wakeup = (pd->write_congestion_on > 0 1331 && pd->bio_queue_size <= pd->write_congestion_off); 1332 spin_unlock(&pd->lock); --- 29 unchanged lines hidden (view full) --- 1362 bvec[f].bv_offset = (f * CD_FRAMESIZE) % PAGE_SIZE; 1363 } 1364 1365 /* 1366 * Fill-in bvec with data from orig_bios. 1367 */ 1368 frames_write = 0; 1369 spin_lock(&pkt->lock); |
1412 for (bio = pkt->orig_bios; bio; bio = bio->bi_next) { | 1370 bio_list_for_each(bio, &pkt->orig_bios) { |
1413 int segment = bio->bi_idx; 1414 int src_offs = 0; 1415 int first_frame = (bio->bi_sector - pkt->sector) / (CD_FRAMESIZE >> 9); 1416 int num_frames = bio->bi_size / CD_FRAMESIZE; 1417 BUG_ON(first_frame < 0); 1418 BUG_ON(first_frame + num_frames > pkt->frames); 1419 for (f = first_frame; f < first_frame + num_frames; f++) { 1420 struct bio_vec *src_bvl = bio_iovec_idx(bio, segment); --- 46 unchanged lines hidden (view full) --- 1467 1468 atomic_set(&pkt->io_wait, 1); 1469 pkt->w_bio->bi_rw = WRITE; 1470 pkt_queue_bio(pd, pkt->w_bio); 1471} 1472 1473static void pkt_finish_packet(struct packet_data *pkt, int uptodate) 1474{ | 1371 int segment = bio->bi_idx; 1372 int src_offs = 0; 1373 int first_frame = (bio->bi_sector - pkt->sector) / (CD_FRAMESIZE >> 9); 1374 int num_frames = bio->bi_size / CD_FRAMESIZE; 1375 BUG_ON(first_frame < 0); 1376 BUG_ON(first_frame + num_frames > pkt->frames); 1377 for (f = first_frame; f < first_frame + num_frames; f++) { 1378 struct bio_vec *src_bvl = bio_iovec_idx(bio, segment); --- 46 unchanged lines hidden (view full) --- 1425 1426 atomic_set(&pkt->io_wait, 1); 1427 pkt->w_bio->bi_rw = WRITE; 1428 pkt_queue_bio(pd, pkt->w_bio); 1429} 1430 1431static void pkt_finish_packet(struct packet_data *pkt, int uptodate) 1432{ |
1475 struct bio *bio, *next; | 1433 struct bio *bio; |
1476 1477 if (!uptodate) 1478 pkt->cache_valid = 0; 1479 1480 /* Finish all bios corresponding to this packet */ | 1434 1435 if (!uptodate) 1436 pkt->cache_valid = 0; 1437 1438 /* Finish all bios corresponding to this packet */ |
1481 bio = pkt->orig_bios; 1482 while (bio) { 1483 next = bio->bi_next; 1484 bio->bi_next = NULL; | 1439 while ((bio = bio_list_pop(&pkt->orig_bios))) |
1485 bio_endio(bio, uptodate ? 0 : -EIO); | 1440 bio_endio(bio, uptodate ? 0 : -EIO); |
1486 bio = next; 1487 } 1488 pkt->orig_bios = pkt->orig_bios_tail = NULL; | |
1489} 1490 1491static void pkt_run_state_machine(struct pktcdvd_device *pd, struct packet_data *pkt) 1492{ 1493 int uptodate; 1494 1495 VPRINTK("run_state_machine: pkt %d\n", pkt->id); 1496 --- 858 unchanged lines hidden (view full) --- 2355 if (write) { 2356 if ((ret = pkt_open_write(pd))) 2357 goto out_unclaim; 2358 /* 2359 * Some CDRW drives can not handle writes larger than one packet, 2360 * even if the size is a multiple of the packet size. 2361 */ 2362 spin_lock_irq(q->queue_lock); | 1441} 1442 1443static void pkt_run_state_machine(struct pktcdvd_device *pd, struct packet_data *pkt) 1444{ 1445 int uptodate; 1446 1447 VPRINTK("run_state_machine: pkt %d\n", pkt->id); 1448 --- 858 unchanged lines hidden (view full) --- 2307 if (write) { 2308 if ((ret = pkt_open_write(pd))) 2309 goto out_unclaim; 2310 /* 2311 * Some CDRW drives can not handle writes larger than one packet, 2312 * even if the size is a multiple of the packet size. 2313 */ 2314 spin_lock_irq(q->queue_lock); |
2363 blk_queue_max_sectors(q, pd->settings.size); | 2315 blk_queue_max_hw_sectors(q, pd->settings.size); |
2364 spin_unlock_irq(q->queue_lock); 2365 set_bit(PACKET_WRITABLE, &pd->flags); 2366 } else { 2367 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); 2368 clear_bit(PACKET_WRITABLE, &pd->flags); 2369 } 2370 2371 if ((ret = pkt_set_segment_merging(pd, q))) --- 190 unchanged lines hidden (view full) --- 2562 */ 2563 spin_lock(&pd->cdrw.active_list_lock); 2564 blocked_bio = 0; 2565 list_for_each_entry(pkt, &pd->cdrw.pkt_active_list, list) { 2566 if (pkt->sector == zone) { 2567 spin_lock(&pkt->lock); 2568 if ((pkt->state == PACKET_WAITING_STATE) || 2569 (pkt->state == PACKET_READ_WAIT_STATE)) { | 2316 spin_unlock_irq(q->queue_lock); 2317 set_bit(PACKET_WRITABLE, &pd->flags); 2318 } else { 2319 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); 2320 clear_bit(PACKET_WRITABLE, &pd->flags); 2321 } 2322 2323 if ((ret = pkt_set_segment_merging(pd, q))) --- 190 unchanged lines hidden (view full) --- 2514 */ 2515 spin_lock(&pd->cdrw.active_list_lock); 2516 blocked_bio = 0; 2517 list_for_each_entry(pkt, &pd->cdrw.pkt_active_list, list) { 2518 if (pkt->sector == zone) { 2519 spin_lock(&pkt->lock); 2520 if ((pkt->state == PACKET_WAITING_STATE) || 2521 (pkt->state == PACKET_READ_WAIT_STATE)) { |
2570 pkt_add_list_last(bio, &pkt->orig_bios, 2571 &pkt->orig_bios_tail); | 2522 bio_list_add(&pkt->orig_bios, bio); |
2572 pkt->write_size += bio->bi_size / CD_FRAMESIZE; 2573 if ((pkt->write_size >= pkt->frames) && 2574 (pkt->state == PACKET_WAITING_STATE)) { 2575 atomic_inc(&pkt->run_sm); 2576 wake_up(&pd->wqueue); 2577 } 2578 spin_unlock(&pkt->lock); 2579 spin_unlock(&pd->cdrw.active_list_lock); --- 77 unchanged lines hidden (view full) --- 2657} 2658 2659static void pkt_init_queue(struct pktcdvd_device *pd) 2660{ 2661 struct request_queue *q = pd->disk->queue; 2662 2663 blk_queue_make_request(q, pkt_make_request); 2664 blk_queue_logical_block_size(q, CD_FRAMESIZE); | 2523 pkt->write_size += bio->bi_size / CD_FRAMESIZE; 2524 if ((pkt->write_size >= pkt->frames) && 2525 (pkt->state == PACKET_WAITING_STATE)) { 2526 atomic_inc(&pkt->run_sm); 2527 wake_up(&pd->wqueue); 2528 } 2529 spin_unlock(&pkt->lock); 2530 spin_unlock(&pd->cdrw.active_list_lock); --- 77 unchanged lines hidden (view full) --- 2608} 2609 2610static void pkt_init_queue(struct pktcdvd_device *pd) 2611{ 2612 struct request_queue *q = pd->disk->queue; 2613 2614 blk_queue_make_request(q, pkt_make_request); 2615 blk_queue_logical_block_size(q, CD_FRAMESIZE); |
2665 blk_queue_max_sectors(q, PACKET_MAX_SECTORS); | 2616 blk_queue_max_hw_sectors(q, PACKET_MAX_SECTORS); |
2666 blk_queue_merge_bvec(q, pkt_merge_bvec); 2667 q->queuedata = pd; 2668} 2669 2670static int pkt_seq_show(struct seq_file *m, void *p) 2671{ 2672 struct pktcdvd_device *pd = m->private; 2673 char *msg; --- 219 unchanged lines hidden (view full) --- 2893 goto out_mem; 2894 2895 INIT_LIST_HEAD(&pd->cdrw.pkt_free_list); 2896 INIT_LIST_HEAD(&pd->cdrw.pkt_active_list); 2897 spin_lock_init(&pd->cdrw.active_list_lock); 2898 2899 spin_lock_init(&pd->lock); 2900 spin_lock_init(&pd->iosched.lock); | 2617 blk_queue_merge_bvec(q, pkt_merge_bvec); 2618 q->queuedata = pd; 2619} 2620 2621static int pkt_seq_show(struct seq_file *m, void *p) 2622{ 2623 struct pktcdvd_device *pd = m->private; 2624 char *msg; --- 219 unchanged lines hidden (view full) --- 2844 goto out_mem; 2845 2846 INIT_LIST_HEAD(&pd->cdrw.pkt_free_list); 2847 INIT_LIST_HEAD(&pd->cdrw.pkt_active_list); 2848 spin_lock_init(&pd->cdrw.active_list_lock); 2849 2850 spin_lock_init(&pd->lock); 2851 spin_lock_init(&pd->iosched.lock); |
2852 bio_list_init(&pd->iosched.read_queue); 2853 bio_list_init(&pd->iosched.write_queue); |
|
2901 sprintf(pd->name, DRIVER_NAME"%d", idx); 2902 init_waitqueue_head(&pd->wqueue); 2903 pd->bio_queue = RB_ROOT; 2904 2905 pd->write_congestion_on = write_congestion_on; 2906 pd->write_congestion_off = write_congestion_off; 2907 2908 disk = alloc_disk(1); --- 231 unchanged lines hidden --- | 2854 sprintf(pd->name, DRIVER_NAME"%d", idx); 2855 init_waitqueue_head(&pd->wqueue); 2856 pd->bio_queue = RB_ROOT; 2857 2858 pd->write_congestion_on = write_congestion_on; 2859 pd->write_congestion_off = write_congestion_off; 2860 2861 disk = alloc_disk(1); --- 231 unchanged lines hidden --- |