aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/pktcdvd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block/pktcdvd.c')
-rw-r--r--drivers/block/pktcdvd.c197
1 files changed, 89 insertions, 108 deletions
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 93affeeef7bd..bc9b2bcd7dba 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -43,8 +43,6 @@
43 * 43 *
44 *************************************************************************/ 44 *************************************************************************/
45 45
46#define VERSION_CODE "v0.2.0a 2004-07-14 Jens Axboe (axboe@suse.de) and petero2@telia.com"
47
48#include <linux/pktcdvd.h> 46#include <linux/pktcdvd.h>
49#include <linux/config.h> 47#include <linux/config.h>
50#include <linux/module.h> 48#include <linux/module.h>
@@ -60,6 +58,7 @@
60#include <linux/suspend.h> 58#include <linux/suspend.h>
61#include <scsi/scsi_cmnd.h> 59#include <scsi/scsi_cmnd.h>
62#include <scsi/scsi_ioctl.h> 60#include <scsi/scsi_ioctl.h>
61#include <scsi/scsi.h>
63 62
64#include <asm/uaccess.h> 63#include <asm/uaccess.h>
65 64
@@ -131,7 +130,7 @@ static struct bio *pkt_bio_alloc(int nr_iovecs)
131/* 130/*
132 * Allocate a packet_data struct 131 * Allocate a packet_data struct
133 */ 132 */
134static struct packet_data *pkt_alloc_packet_data(void) 133static struct packet_data *pkt_alloc_packet_data(int frames)
135{ 134{
136 int i; 135 int i;
137 struct packet_data *pkt; 136 struct packet_data *pkt;
@@ -140,11 +139,12 @@ static struct packet_data *pkt_alloc_packet_data(void)
140 if (!pkt) 139 if (!pkt)
141 goto no_pkt; 140 goto no_pkt;
142 141
143 pkt->w_bio = pkt_bio_alloc(PACKET_MAX_SIZE); 142 pkt->frames = frames;
143 pkt->w_bio = pkt_bio_alloc(frames);
144 if (!pkt->w_bio) 144 if (!pkt->w_bio)
145 goto no_bio; 145 goto no_bio;
146 146
147 for (i = 0; i < PAGES_PER_PACKET; i++) { 147 for (i = 0; i < frames / FRAMES_PER_PAGE; i++) {
148 pkt->pages[i] = alloc_page(GFP_KERNEL|__GFP_ZERO); 148 pkt->pages[i] = alloc_page(GFP_KERNEL|__GFP_ZERO);
149 if (!pkt->pages[i]) 149 if (!pkt->pages[i])
150 goto no_page; 150 goto no_page;
@@ -152,7 +152,7 @@ static struct packet_data *pkt_alloc_packet_data(void)
152 152
153 spin_lock_init(&pkt->lock); 153 spin_lock_init(&pkt->lock);
154 154
155 for (i = 0; i < PACKET_MAX_SIZE; i++) { 155 for (i = 0; i < frames; i++) {
156 struct bio *bio = pkt_bio_alloc(1); 156 struct bio *bio = pkt_bio_alloc(1);
157 if (!bio) 157 if (!bio)
158 goto no_rd_bio; 158 goto no_rd_bio;
@@ -162,14 +162,14 @@ static struct packet_data *pkt_alloc_packet_data(void)
162 return pkt; 162 return pkt;
163 163
164no_rd_bio: 164no_rd_bio:
165 for (i = 0; i < PACKET_MAX_SIZE; i++) { 165 for (i = 0; i < frames; i++) {
166 struct bio *bio = pkt->r_bios[i]; 166 struct bio *bio = pkt->r_bios[i];
167 if (bio) 167 if (bio)
168 bio_put(bio); 168 bio_put(bio);
169 } 169 }
170 170
171no_page: 171no_page:
172 for (i = 0; i < PAGES_PER_PACKET; i++) 172 for (i = 0; i < frames / FRAMES_PER_PAGE; i++)
173 if (pkt->pages[i]) 173 if (pkt->pages[i])
174 __free_page(pkt->pages[i]); 174 __free_page(pkt->pages[i]);
175 bio_put(pkt->w_bio); 175 bio_put(pkt->w_bio);
@@ -186,12 +186,12 @@ static void pkt_free_packet_data(struct packet_data *pkt)
186{ 186{
187 int i; 187 int i;
188 188
189 for (i = 0; i < PACKET_MAX_SIZE; i++) { 189 for (i = 0; i < pkt->frames; i++) {
190 struct bio *bio = pkt->r_bios[i]; 190 struct bio *bio = pkt->r_bios[i];
191 if (bio) 191 if (bio)
192 bio_put(bio); 192 bio_put(bio);
193 } 193 }
194 for (i = 0; i < PAGES_PER_PACKET; i++) 194 for (i = 0; i < pkt->frames / FRAMES_PER_PAGE; i++)
195 __free_page(pkt->pages[i]); 195 __free_page(pkt->pages[i]);
196 bio_put(pkt->w_bio); 196 bio_put(pkt->w_bio);
197 kfree(pkt); 197 kfree(pkt);
@@ -206,17 +206,17 @@ static void pkt_shrink_pktlist(struct pktcdvd_device *pd)
206 list_for_each_entry_safe(pkt, next, &pd->cdrw.pkt_free_list, list) { 206 list_for_each_entry_safe(pkt, next, &pd->cdrw.pkt_free_list, list) {
207 pkt_free_packet_data(pkt); 207 pkt_free_packet_data(pkt);
208 } 208 }
209 INIT_LIST_HEAD(&pd->cdrw.pkt_free_list);
209} 210}
210 211
211static int pkt_grow_pktlist(struct pktcdvd_device *pd, int nr_packets) 212static int pkt_grow_pktlist(struct pktcdvd_device *pd, int nr_packets)
212{ 213{
213 struct packet_data *pkt; 214 struct packet_data *pkt;
214 215
215 INIT_LIST_HEAD(&pd->cdrw.pkt_free_list); 216 BUG_ON(!list_empty(&pd->cdrw.pkt_free_list));
216 INIT_LIST_HEAD(&pd->cdrw.pkt_active_list); 217
217 spin_lock_init(&pd->cdrw.active_list_lock);
218 while (nr_packets > 0) { 218 while (nr_packets > 0) {
219 pkt = pkt_alloc_packet_data(); 219 pkt = pkt_alloc_packet_data(pd->settings.size >> 2);
220 if (!pkt) { 220 if (!pkt) {
221 pkt_shrink_pktlist(pd); 221 pkt_shrink_pktlist(pd);
222 return 0; 222 return 0;
@@ -381,6 +381,7 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *
381 memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE); 381 memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE);
382 if (sizeof(rq->cmd) > CDROM_PACKET_SIZE) 382 if (sizeof(rq->cmd) > CDROM_PACKET_SIZE)
383 memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE); 383 memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE);
384 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
384 385
385 rq->ref_count++; 386 rq->ref_count++;
386 rq->flags |= REQ_NOMERGE; 387 rq->flags |= REQ_NOMERGE;
@@ -646,7 +647,7 @@ static void pkt_copy_bio_data(struct bio *src_bio, int seg, int offs, struct pag
646 * b) The data can be used as cache to avoid read requests if we receive a 647 * b) The data can be used as cache to avoid read requests if we receive a
647 * new write request for the same zone. 648 * new write request for the same zone.
648 */ 649 */
649static void pkt_make_local_copy(struct packet_data *pkt, struct page **pages, int *offsets) 650static void pkt_make_local_copy(struct packet_data *pkt, struct bio_vec *bvec)
650{ 651{
651 int f, p, offs; 652 int f, p, offs;
652 653
@@ -654,15 +655,15 @@ static void pkt_make_local_copy(struct packet_data *pkt, struct page **pages, in
654 p = 0; 655 p = 0;
655 offs = 0; 656 offs = 0;
656 for (f = 0; f < pkt->frames; f++) { 657 for (f = 0; f < pkt->frames; f++) {
657 if (pages[f] != pkt->pages[p]) { 658 if (bvec[f].bv_page != pkt->pages[p]) {
658 void *vfrom = kmap_atomic(pages[f], KM_USER0) + offsets[f]; 659 void *vfrom = kmap_atomic(bvec[f].bv_page, KM_USER0) + bvec[f].bv_offset;
659 void *vto = page_address(pkt->pages[p]) + offs; 660 void *vto = page_address(pkt->pages[p]) + offs;
660 memcpy(vto, vfrom, CD_FRAMESIZE); 661 memcpy(vto, vfrom, CD_FRAMESIZE);
661 kunmap_atomic(vfrom, KM_USER0); 662 kunmap_atomic(vfrom, KM_USER0);
662 pages[f] = pkt->pages[p]; 663 bvec[f].bv_page = pkt->pages[p];
663 offsets[f] = offs; 664 bvec[f].bv_offset = offs;
664 } else { 665 } else {
665 BUG_ON(offsets[f] != offs); 666 BUG_ON(bvec[f].bv_offset != offs);
666 } 667 }
667 offs += CD_FRAMESIZE; 668 offs += CD_FRAMESIZE;
668 if (offs >= PAGE_SIZE) { 669 if (offs >= PAGE_SIZE) {
@@ -951,7 +952,7 @@ try_next_bio:
951 952
952 pd->current_sector = zone + pd->settings.size; 953 pd->current_sector = zone + pd->settings.size;
953 pkt->sector = zone; 954 pkt->sector = zone;
954 pkt->frames = pd->settings.size >> 2; 955 BUG_ON(pkt->frames != pd->settings.size >> 2);
955 pkt->write_size = 0; 956 pkt->write_size = 0;
956 957
957 /* 958 /*
@@ -992,18 +993,17 @@ try_next_bio:
992static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) 993static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt)
993{ 994{
994 struct bio *bio; 995 struct bio *bio;
995 struct page *pages[PACKET_MAX_SIZE];
996 int offsets[PACKET_MAX_SIZE];
997 int f; 996 int f;
998 int frames_write; 997 int frames_write;
998 struct bio_vec *bvec = pkt->w_bio->bi_io_vec;
999 999
1000 for (f = 0; f < pkt->frames; f++) { 1000 for (f = 0; f < pkt->frames; f++) {
1001 pages[f] = pkt->pages[(f * CD_FRAMESIZE) / PAGE_SIZE]; 1001 bvec[f].bv_page = pkt->pages[(f * CD_FRAMESIZE) / PAGE_SIZE];
1002 offsets[f] = (f * CD_FRAMESIZE) % PAGE_SIZE; 1002 bvec[f].bv_offset = (f * CD_FRAMESIZE) % PAGE_SIZE;
1003 } 1003 }
1004 1004
1005 /* 1005 /*
1006 * Fill-in pages[] and offsets[] with data from orig_bios. 1006 * Fill-in bvec with data from orig_bios.
1007 */ 1007 */
1008 frames_write = 0; 1008 frames_write = 0;
1009 spin_lock(&pkt->lock); 1009 spin_lock(&pkt->lock);
@@ -1025,11 +1025,11 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt)
1025 } 1025 }
1026 1026
1027 if (src_bvl->bv_len - src_offs >= CD_FRAMESIZE) { 1027 if (src_bvl->bv_len - src_offs >= CD_FRAMESIZE) {
1028 pages[f] = src_bvl->bv_page; 1028 bvec[f].bv_page = src_bvl->bv_page;
1029 offsets[f] = src_bvl->bv_offset + src_offs; 1029 bvec[f].bv_offset = src_bvl->bv_offset + src_offs;
1030 } else { 1030 } else {
1031 pkt_copy_bio_data(bio, segment, src_offs, 1031 pkt_copy_bio_data(bio, segment, src_offs,
1032 pages[f], offsets[f]); 1032 bvec[f].bv_page, bvec[f].bv_offset);
1033 } 1033 }
1034 src_offs += CD_FRAMESIZE; 1034 src_offs += CD_FRAMESIZE;
1035 frames_write++; 1035 frames_write++;
@@ -1043,7 +1043,7 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt)
1043 BUG_ON(frames_write != pkt->write_size); 1043 BUG_ON(frames_write != pkt->write_size);
1044 1044
1045 if (test_bit(PACKET_MERGE_SEGS, &pd->flags) || (pkt->write_size < pkt->frames)) { 1045 if (test_bit(PACKET_MERGE_SEGS, &pd->flags) || (pkt->write_size < pkt->frames)) {
1046 pkt_make_local_copy(pkt, pages, offsets); 1046 pkt_make_local_copy(pkt, bvec);
1047 pkt->cache_valid = 1; 1047 pkt->cache_valid = 1;
1048 } else { 1048 } else {
1049 pkt->cache_valid = 0; 1049 pkt->cache_valid = 0;
@@ -1056,17 +1056,9 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt)
1056 pkt->w_bio->bi_bdev = pd->bdev; 1056 pkt->w_bio->bi_bdev = pd->bdev;
1057 pkt->w_bio->bi_end_io = pkt_end_io_packet_write; 1057 pkt->w_bio->bi_end_io = pkt_end_io_packet_write;
1058 pkt->w_bio->bi_private = pkt; 1058 pkt->w_bio->bi_private = pkt;
1059 for (f = 0; f < pkt->frames; f++) { 1059 for (f = 0; f < pkt->frames; f++)
1060 if ((f + 1 < pkt->frames) && (pages[f + 1] == pages[f]) && 1060 if (!bio_add_page(pkt->w_bio, bvec[f].bv_page, CD_FRAMESIZE, bvec[f].bv_offset))
1061 (offsets[f + 1] = offsets[f] + CD_FRAMESIZE)) { 1061 BUG();
1062 if (!bio_add_page(pkt->w_bio, pages[f], CD_FRAMESIZE * 2, offsets[f]))
1063 BUG();
1064 f++;
1065 } else {
1066 if (!bio_add_page(pkt->w_bio, pages[f], CD_FRAMESIZE, offsets[f]))
1067 BUG();
1068 }
1069 }
1070 VPRINTK("pktcdvd: vcnt=%d\n", pkt->w_bio->bi_vcnt); 1062 VPRINTK("pktcdvd: vcnt=%d\n", pkt->w_bio->bi_vcnt);
1071 1063
1072 atomic_set(&pkt->io_wait, 1); 1064 atomic_set(&pkt->io_wait, 1);
@@ -1505,40 +1497,42 @@ static int pkt_set_write_settings(struct pktcdvd_device *pd)
1505} 1497}
1506 1498
1507/* 1499/*
1508 * 0 -- we can write to this track, 1 -- we can't 1500 * 1 -- we can write to this track, 0 -- we can't
1509 */ 1501 */
1510static int pkt_good_track(track_information *ti) 1502static int pkt_writable_track(struct pktcdvd_device *pd, track_information *ti)
1511{ 1503{
1512 /* 1504 switch (pd->mmc3_profile) {
1513 * only good for CD-RW at the moment, not DVD-RW 1505 case 0x1a: /* DVD+RW */
1514 */ 1506 case 0x12: /* DVD-RAM */
1507 /* The track is always writable on DVD+RW/DVD-RAM */
1508 return 1;
1509 default:
1510 break;
1511 }
1515 1512
1516 /* 1513 if (!ti->packet || !ti->fp)
1517 * FIXME: only for FP
1518 */
1519 if (ti->fp == 0)
1520 return 0; 1514 return 0;
1521 1515
1522 /* 1516 /*
1523 * "good" settings as per Mt Fuji. 1517 * "good" settings as per Mt Fuji.
1524 */ 1518 */
1525 if (ti->rt == 0 && ti->blank == 0 && ti->packet == 1) 1519 if (ti->rt == 0 && ti->blank == 0)
1526 return 0; 1520 return 1;
1527 1521
1528 if (ti->rt == 0 && ti->blank == 1 && ti->packet == 1) 1522 if (ti->rt == 0 && ti->blank == 1)
1529 return 0; 1523 return 1;
1530 1524
1531 if (ti->rt == 1 && ti->blank == 0 && ti->packet == 1) 1525 if (ti->rt == 1 && ti->blank == 0)
1532 return 0; 1526 return 1;
1533 1527
1534 printk("pktcdvd: bad state %d-%d-%d\n", ti->rt, ti->blank, ti->packet); 1528 printk("pktcdvd: bad state %d-%d-%d\n", ti->rt, ti->blank, ti->packet);
1535 return 1; 1529 return 0;
1536} 1530}
1537 1531
1538/* 1532/*
1539 * 0 -- we can write to this disc, 1 -- we can't 1533 * 1 -- we can write to this disc, 0 -- we can't
1540 */ 1534 */
1541static int pkt_good_disc(struct pktcdvd_device *pd, disc_information *di) 1535static int pkt_writable_disc(struct pktcdvd_device *pd, disc_information *di)
1542{ 1536{
1543 switch (pd->mmc3_profile) { 1537 switch (pd->mmc3_profile) {
1544 case 0x0a: /* CD-RW */ 1538 case 0x0a: /* CD-RW */
@@ -1547,10 +1541,10 @@ static int pkt_good_disc(struct pktcdvd_device *pd, disc_information *di)
1547 case 0x1a: /* DVD+RW */ 1541 case 0x1a: /* DVD+RW */
1548 case 0x13: /* DVD-RW */ 1542 case 0x13: /* DVD-RW */
1549 case 0x12: /* DVD-RAM */ 1543 case 0x12: /* DVD-RAM */
1550 return 0;
1551 default:
1552 printk("pktcdvd: Wrong disc profile (%x)\n", pd->mmc3_profile);
1553 return 1; 1544 return 1;
1545 default:
1546 VPRINTK("pktcdvd: Wrong disc profile (%x)\n", pd->mmc3_profile);
1547 return 0;
1554 } 1548 }
1555 1549
1556 /* 1550 /*
@@ -1559,25 +1553,25 @@ static int pkt_good_disc(struct pktcdvd_device *pd, disc_information *di)
1559 */ 1553 */
1560 if (di->disc_type == 0xff) { 1554 if (di->disc_type == 0xff) {
1561 printk("pktcdvd: Unknown disc. No track?\n"); 1555 printk("pktcdvd: Unknown disc. No track?\n");
1562 return 1; 1556 return 0;
1563 } 1557 }
1564 1558
1565 if (di->disc_type != 0x20 && di->disc_type != 0) { 1559 if (di->disc_type != 0x20 && di->disc_type != 0) {
1566 printk("pktcdvd: Wrong disc type (%x)\n", di->disc_type); 1560 printk("pktcdvd: Wrong disc type (%x)\n", di->disc_type);
1567 return 1; 1561 return 0;
1568 } 1562 }
1569 1563
1570 if (di->erasable == 0) { 1564 if (di->erasable == 0) {
1571 printk("pktcdvd: Disc not erasable\n"); 1565 printk("pktcdvd: Disc not erasable\n");
1572 return 1; 1566 return 0;
1573 } 1567 }
1574 1568
1575 if (di->border_status == PACKET_SESSION_RESERVED) { 1569 if (di->border_status == PACKET_SESSION_RESERVED) {
1576 printk("pktcdvd: Can't write to last track (reserved)\n"); 1570 printk("pktcdvd: Can't write to last track (reserved)\n");
1577 return 1; 1571 return 0;
1578 } 1572 }
1579 1573
1580 return 0; 1574 return 1;
1581} 1575}
1582 1576
1583static int pkt_probe_settings(struct pktcdvd_device *pd) 1577static int pkt_probe_settings(struct pktcdvd_device *pd)
@@ -1602,23 +1596,9 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
1602 return ret; 1596 return ret;
1603 } 1597 }
1604 1598
1605 if (pkt_good_disc(pd, &di)) 1599 if (!pkt_writable_disc(pd, &di))
1606 return -ENXIO; 1600 return -EROFS;
1607 1601
1608 switch (pd->mmc3_profile) {
1609 case 0x1a: /* DVD+RW */
1610 printk("pktcdvd: inserted media is DVD+RW\n");
1611 break;
1612 case 0x13: /* DVD-RW */
1613 printk("pktcdvd: inserted media is DVD-RW\n");
1614 break;
1615 case 0x12: /* DVD-RAM */
1616 printk("pktcdvd: inserted media is DVD-RAM\n");
1617 break;
1618 default:
1619 printk("pktcdvd: inserted media is CD-R%s\n", di.erasable ? "W" : "");
1620 break;
1621 }
1622 pd->type = di.erasable ? PACKET_CDRW : PACKET_CDR; 1602 pd->type = di.erasable ? PACKET_CDRW : PACKET_CDR;
1623 1603
1624 track = 1; /* (di.last_track_msb << 8) | di.last_track_lsb; */ 1604 track = 1; /* (di.last_track_msb << 8) | di.last_track_lsb; */
@@ -1627,9 +1607,9 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
1627 return ret; 1607 return ret;
1628 } 1608 }
1629 1609
1630 if (pkt_good_track(&ti)) { 1610 if (!pkt_writable_track(pd, &ti)) {
1631 printk("pktcdvd: can't write to this track\n"); 1611 printk("pktcdvd: can't write to this track\n");
1632 return -ENXIO; 1612 return -EROFS;
1633 } 1613 }
1634 1614
1635 /* 1615 /*
@@ -1639,11 +1619,11 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
1639 pd->settings.size = be32_to_cpu(ti.fixed_packet_size) << 2; 1619 pd->settings.size = be32_to_cpu(ti.fixed_packet_size) << 2;
1640 if (pd->settings.size == 0) { 1620 if (pd->settings.size == 0) {
1641 printk("pktcdvd: detected zero packet size!\n"); 1621 printk("pktcdvd: detected zero packet size!\n");
1642 pd->settings.size = 128; 1622 return -ENXIO;
1643 } 1623 }
1644 if (pd->settings.size > PACKET_MAX_SECTORS) { 1624 if (pd->settings.size > PACKET_MAX_SECTORS) {
1645 printk("pktcdvd: packet size is too big\n"); 1625 printk("pktcdvd: packet size is too big\n");
1646 return -ENXIO; 1626 return -EROFS;
1647 } 1627 }
1648 pd->settings.fp = ti.fp; 1628 pd->settings.fp = ti.fp;
1649 pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1); 1629 pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
@@ -1685,7 +1665,7 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
1685 break; 1665 break;
1686 default: 1666 default:
1687 printk("pktcdvd: unknown data mode\n"); 1667 printk("pktcdvd: unknown data mode\n");
1688 return 1; 1668 return -EROFS;
1689 } 1669 }
1690 return 0; 1670 return 0;
1691} 1671}
@@ -1895,8 +1875,8 @@ static int pkt_open_write(struct pktcdvd_device *pd)
1895 unsigned int write_speed, media_write_speed, read_speed; 1875 unsigned int write_speed, media_write_speed, read_speed;
1896 1876
1897 if ((ret = pkt_probe_settings(pd))) { 1877 if ((ret = pkt_probe_settings(pd))) {
1898 DPRINTK("pktcdvd: %s failed probe\n", pd->name); 1878 VPRINTK("pktcdvd: %s failed probe\n", pd->name);
1899 return -EIO; 1879 return ret;
1900 } 1880 }
1901 1881
1902 if ((ret = pkt_set_write_settings(pd))) { 1882 if ((ret = pkt_set_write_settings(pd))) {
@@ -1987,8 +1967,14 @@ static int pkt_open_dev(struct pktcdvd_device *pd, int write)
1987 if ((ret = pkt_set_segment_merging(pd, q))) 1967 if ((ret = pkt_set_segment_merging(pd, q)))
1988 goto out_unclaim; 1968 goto out_unclaim;
1989 1969
1990 if (write) 1970 if (write) {
1971 if (!pkt_grow_pktlist(pd, CONFIG_CDROM_PKTCDVD_BUFFERS)) {
1972 printk("pktcdvd: not enough memory for buffers\n");
1973 ret = -ENOMEM;
1974 goto out_unclaim;
1975 }
1991 printk("pktcdvd: %lukB available on disc\n", lba << 1); 1976 printk("pktcdvd: %lukB available on disc\n", lba << 1);
1977 }
1992 1978
1993 return 0; 1979 return 0;
1994 1980
@@ -2014,6 +2000,8 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush)
2014 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); 2000 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED);
2015 bd_release(pd->bdev); 2001 bd_release(pd->bdev);
2016 blkdev_put(pd->bdev); 2002 blkdev_put(pd->bdev);
2003
2004 pkt_shrink_pktlist(pd);
2017} 2005}
2018 2006
2019static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor) 2007static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor)
@@ -2046,10 +2034,9 @@ static int pkt_open(struct inode *inode, struct file *file)
2046 goto out_dec; 2034 goto out_dec;
2047 } 2035 }
2048 } else { 2036 } else {
2049 if (pkt_open_dev(pd, file->f_mode & FMODE_WRITE)) { 2037 ret = pkt_open_dev(pd, file->f_mode & FMODE_WRITE);
2050 ret = -EIO; 2038 if (ret)
2051 goto out_dec; 2039 goto out_dec;
2052 }
2053 /* 2040 /*
2054 * needed here as well, since ext2 (among others) may change 2041 * needed here as well, since ext2 (among others) may change
2055 * the blocksize at mount time 2042 * the blocksize at mount time
@@ -2379,12 +2366,6 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
2379 /* This is safe, since we have a reference from open(). */ 2366 /* This is safe, since we have a reference from open(). */
2380 __module_get(THIS_MODULE); 2367 __module_get(THIS_MODULE);
2381 2368
2382 if (!pkt_grow_pktlist(pd, CONFIG_CDROM_PKTCDVD_BUFFERS)) {
2383 printk("pktcdvd: not enough memory for buffers\n");
2384 ret = -ENOMEM;
2385 goto out_mem;
2386 }
2387
2388 pd->bdev = bdev; 2369 pd->bdev = bdev;
2389 set_blocksize(bdev, CD_FRAMESIZE); 2370 set_blocksize(bdev, CD_FRAMESIZE);
2390 2371
@@ -2395,7 +2376,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
2395 if (IS_ERR(pd->cdrw.thread)) { 2376 if (IS_ERR(pd->cdrw.thread)) {
2396 printk("pktcdvd: can't start kernel thread\n"); 2377 printk("pktcdvd: can't start kernel thread\n");
2397 ret = -ENOMEM; 2378 ret = -ENOMEM;
2398 goto out_thread; 2379 goto out_mem;
2399 } 2380 }
2400 2381
2401 proc = create_proc_entry(pd->name, 0, pkt_proc); 2382 proc = create_proc_entry(pd->name, 0, pkt_proc);
@@ -2406,8 +2387,6 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
2406 DPRINTK("pktcdvd: writer %s mapped to %s\n", pd->name, bdevname(bdev, b)); 2387 DPRINTK("pktcdvd: writer %s mapped to %s\n", pd->name, bdevname(bdev, b));
2407 return 0; 2388 return 0;
2408 2389
2409out_thread:
2410 pkt_shrink_pktlist(pd);
2411out_mem: 2390out_mem:
2412 blkdev_put(bdev); 2391 blkdev_put(bdev);
2413 /* This is safe: open() is still holding a reference. */ 2392 /* This is safe: open() is still holding a reference. */
@@ -2437,11 +2416,12 @@ static int pkt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
2437 * The door gets locked when the device is opened, so we 2416 * The door gets locked when the device is opened, so we
2438 * have to unlock it or else the eject command fails. 2417 * have to unlock it or else the eject command fails.
2439 */ 2418 */
2440 pkt_lock_door(pd, 0); 2419 if (pd->refcnt == 1)
2420 pkt_lock_door(pd, 0);
2441 return blkdev_ioctl(pd->bdev->bd_inode, file, cmd, arg); 2421 return blkdev_ioctl(pd->bdev->bd_inode, file, cmd, arg);
2442 2422
2443 default: 2423 default:
2444 printk("pktcdvd: Unknown ioctl for %s (%x)\n", pd->name, cmd); 2424 VPRINTK("pktcdvd: Unknown ioctl for %s (%x)\n", pd->name, cmd);
2445 return -ENOTTY; 2425 return -ENOTTY;
2446 } 2426 }
2447 2427
@@ -2503,6 +2483,10 @@ static int pkt_setup_dev(struct pkt_ctrl_command *ctrl_cmd)
2503 goto out_mem; 2483 goto out_mem;
2504 pd->disk = disk; 2484 pd->disk = disk;
2505 2485
2486 INIT_LIST_HEAD(&pd->cdrw.pkt_free_list);
2487 INIT_LIST_HEAD(&pd->cdrw.pkt_active_list);
2488 spin_lock_init(&pd->cdrw.active_list_lock);
2489
2506 spin_lock_init(&pd->lock); 2490 spin_lock_init(&pd->lock);
2507 spin_lock_init(&pd->iosched.lock); 2491 spin_lock_init(&pd->iosched.lock);
2508 sprintf(pd->name, "pktcdvd%d", idx); 2492 sprintf(pd->name, "pktcdvd%d", idx);
@@ -2567,8 +2551,6 @@ static int pkt_remove_dev(struct pkt_ctrl_command *ctrl_cmd)
2567 2551
2568 blkdev_put(pd->bdev); 2552 blkdev_put(pd->bdev);
2569 2553
2570 pkt_shrink_pktlist(pd);
2571
2572 remove_proc_entry(pd->name, pkt_proc); 2554 remove_proc_entry(pd->name, pkt_proc);
2573 DPRINTK("pktcdvd: writer %s unmapped\n", pd->name); 2555 DPRINTK("pktcdvd: writer %s unmapped\n", pd->name);
2574 2556
@@ -2678,7 +2660,6 @@ static int __init pkt_init(void)
2678 2660
2679 pkt_proc = proc_mkdir("pktcdvd", proc_root_driver); 2661 pkt_proc = proc_mkdir("pktcdvd", proc_root_driver);
2680 2662
2681 DPRINTK("pktcdvd: %s\n", VERSION_CODE);
2682 return 0; 2663 return 0;
2683 2664
2684out: 2665out: