2.6.18-mm3 pktcdvd: reorder code for reability
PATCH 11/11 2.6.18-mm3 pktcdvd: reorder code for reability
Hello,
this patch reorders some functions and #defines
into groups for better readability.
It does not change any program logic.
http://people.freenet.de/BalaGi/download/pktcdvd-11-reorder_2.6.18.patch
Signed-off-by Thomas Maier<[email protected]>
-Thomas Maier
drivers/block/pktcdvd.c +227 -207
@@ -2586,154 +2586,6 @@ static int pkt_open_write(struct pktcdvdreturn 0 ; } -/* -* called at open time. -*/ -static int pkt_open_dev (struct pktcdvd_device *pd,int write) -{ -int ret; -long lba; -request_queue_t *q; - -/* -* We need to re-open the cdrom device without O_NONBLOCK to be able -* to read/write from/to it. It is already opened in O_NONBLOCK mode -* so bdget() can't fail. -*/ -bdget (pd->bdev->bd_dev); -if ((ret =blkdev_get (pd->bdev,FMODE_READ ,O_RDONLY ))) - goto out; - -if ((ret =bd_claim (pd->bdev, pd))) - goto out_putdev; - -if ((ret =pkt_get_last_written (pd, &lba))) { -printk (DRIVER_NAME ": pkt_get_last_written failed\n" ); - goto out_unclaim; - } - -set_capacity (pd->disk, lba <<2 ); -set_capacity (pd->bdev->bd_disk, lba <<2 ); -bd_set_size (pd->bdev, (loff_t )lba <<11 ); - - q =bdev_get_queue (pd->bdev); -if (write) { -if ((ret =pkt_open_write (pd))) - goto out_unclaim; -/* -* Some CDRW drives can not handle writes larger than one packet, -* even if the size is a multiple of the packet size. -*/ -spin_lock_irq (q->queue_lock); -blk_queue_max_sectors (q, pd->settings.size); -spin_unlock_irq (q->queue_lock); -set_bit (PACKET_WRITABLE , &pd->flags); - }else { -pkt_set_speed (pd,MAX_SPEED ,MAX_SPEED ); -clear_bit (PACKET_WRITABLE , &pd->flags); - } - -if ((ret =pkt_set_segment_merging (pd, q))) - goto out_unclaim; - -if (write) { -if (!pkt_grow_pktlist (pd, packet_buffers)) { -printk (DRIVER_NAME ": not enough memory for buffers\n" ); - ret = -ENOMEM ; - goto out_unclaim; - } -printk (DRIVER_NAME ": %lukB available on disc\n" , lba <<1 ); - } - -return 0 ; - -out_unclaim: -bd_release (pd->bdev); -out_putdev: -blkdev_put (pd->bdev); -out: -return ret; -} - -/* -* called when the device is closed. makes sure that the device flushes -* the internal cache before we close. -*/ -static void pkt_release_dev (struct pktcdvd_device *pd,int flush) -{ -if (flush &&pkt_flush_cache (pd)) -DPRINTK (DRIVER_NAME ": %s not flushing cache\n" , pd->name); - -pkt_lock_door (pd,0 ); - -pkt_set_speed (pd,MAX_SPEED ,MAX_SPEED ); -bd_release (pd->bdev); -blkdev_put (pd->bdev); - -pkt_shrink_pktlist (pd); -} - -static int pkt_open (struct inode *inode,struct file *file) -{ -struct pktcdvd_device *pd =NULL ; -int ret; - -VPRINTK (DRIVER_NAME ": entering open\n" ); - -mutex_lock (&ctl_mutex); - pd =pkt_find_dev_from_minor (iminor (inode)); -if (!pd) { - ret = -ENODEV ; - goto out; - } -BUG_ON (pd->refcnt <0 ); - - pd->refcnt++; -if (pd->refcnt >1 ) { -if ((file->f_mode &FMODE_WRITE ) && - !test_bit (PACKET_WRITABLE , &pd->flags)) { - ret = -EBUSY ; - goto out_dec; - } - }else { - ret =pkt_open_dev (pd, file->f_mode &FMODE_WRITE ); -if (ret) - goto out_dec; -/* -* needed here as well, since ext2 (among others) may change -* the blocksize at mount time -*/ -set_blocksize (inode->i_bdev,CD_FRAMESIZE ); - } - -mutex_unlock (&ctl_mutex); -return 0 ; - -out_dec: - pd->refcnt--; -out: -VPRINTK (DRIVER_NAME ": failed open (%d)\n" , ret); -mutex_unlock (&ctl_mutex); -return ret; -} - -static int pkt_close (struct inode *inode,struct file *file) -{ -struct pktcdvd_device *pd = inode->i_bdev->bd_disk->private_data; -int ret =0 ; - -mutex_lock (&ctl_mutex); - pd->refcnt--; -BUG_ON (pd->refcnt <0 ); -if (pd->refcnt ==0 ) { -int flush =test_bit (PACKET_WRITABLE , &pd->flags); -pkt_release_dev (pd, flush); - } -mutex_unlock (&ctl_mutex); -return ret; -} - -static int pkt_end_io_read_cloned (struct bio *bio,unsigned int bytes_done,int err) {struct packet_stacked_data *psd = bio->bi_private;
@@ -2905,8 +2757,6 @@ end_io:return 0 ; } - -static int pkt_merge_bvec (request_queue_t *q,struct bio *bio,struct bio_vec *bvec) {struct pktcdvd_device *pd = q->queuedata;
@@ -2926,6 +2776,223 @@ static int pkt_merge_bvec(request_queue_return remaining; } +/* +* called at open time. +*/ +static int pkt_open_dev (struct pktcdvd_device *pd,int write) +{ +int ret; +long lba; +request_queue_t *q; + +/* +* We need to re-open the cdrom device without O_NONBLOCK to be able +* to read/write from/to it. It is already opened in O_NONBLOCK mode +* so bdget() can't fail. +*/ +bdget (pd->bdev->bd_dev); +if ((ret =blkdev_get (pd->bdev,FMODE_READ ,O_RDONLY ))) + goto out; + +if ((ret =bd_claim (pd->bdev, pd))) + goto out_putdev; + +if ((ret =pkt_get_last_written (pd, &lba))) { +printk (DRIVER_NAME ": pkt_get_last_written failed\n" ); + goto out_unclaim; + } + +set_capacity (pd->disk, lba <<2 ); +set_capacity (pd->bdev->bd_disk, lba <<2 ); +bd_set_size (pd->bdev, (loff_t )lba <<11 ); + + q =bdev_get_queue (pd->bdev); +if (write) { +if ((ret =pkt_open_write (pd))) + goto out_unclaim; +/* +* Some CDRW drives can not handle writes larger than one packet, +* even if the size is a multiple of the packet size. +*/ +spin_lock_irq (q->queue_lock); +blk_queue_max_sectors (q, pd->settings.size); +spin_unlock_irq (q->queue_lock); +set_bit (PACKET_WRITABLE , &pd->flags); + }else { +pkt_set_speed (pd,MAX_SPEED ,MAX_SPEED ); +clear_bit (PACKET_WRITABLE , &pd->flags); + } + +if ((ret =pkt_set_segment_merging (pd, q))) + goto out_unclaim; + +if (write) { +if (!pkt_grow_pktlist (pd, packet_buffers)) { +printk (DRIVER_NAME ": not enough memory for buffers\n" ); + ret = -ENOMEM ; + goto out_unclaim; + } +printk (DRIVER_NAME ": %lukB available on disc\n" , lba <<1 ); + } + +return 0 ; + +out_unclaim: +bd_release (pd->bdev); +out_putdev: +blkdev_put (pd->bdev); +out: +return ret; +} + +/* +* called when the device is closed. makes sure that the device flushes +* the internal cache before we close. +*/ +static void pkt_release_dev (struct pktcdvd_device *pd,int flush) +{ +if (flush &&pkt_flush_cache (pd)) +DPRINTK (DRIVER_NAME ": %s not flushing cache\n" , pd->name); + +pkt_lock_door (pd,0 ); + +pkt_set_speed (pd,MAX_SPEED ,MAX_SPEED ); +bd_release (pd->bdev); +blkdev_put (pd->bdev); + +pkt_shrink_pktlist (pd); +} + +/****************************************************************** +* +* pktcdvd block device operations +* +*****************************************************************/ + +static int pkt_open (struct inode *inode,struct file *file) +{ +struct pktcdvd_device *pd =NULL ; +int ret; + +VPRINTK (DRIVER_NAME ": entering open\n" ); + +mutex_lock (&ctl_mutex); + pd =pkt_find_dev_from_minor (iminor (inode)); +if (!pd) { + ret = -ENODEV ; + goto out; + } +BUG_ON (pd->refcnt <0 ); + + pd->refcnt++; +if (pd->refcnt >1 ) { +if ((file->f_mode &FMODE_WRITE ) && + !test_bit (PACKET_WRITABLE , &pd->flags)) { + ret = -EBUSY ; + goto out_dec; + } + }else { + ret =pkt_open_dev (pd, file->f_mode &FMODE_WRITE ); +if (ret) + goto out_dec; +/* +* needed here as well, since ext2 (among others) may change +* the blocksize at mount time +*/ +set_blocksize (inode->i_bdev,CD_FRAMESIZE ); + } + +mutex_unlock (&ctl_mutex); +return 0 ; + +out_dec: + pd->refcnt--; +out: +VPRINTK (DRIVER_NAME ": failed open (%d)\n" , ret); +mutex_unlock (&ctl_mutex); +return ret; +} + +static int pkt_close (struct inode *inode,struct file *file) +{ +struct pktcdvd_device *pd = inode->i_bdev->bd_disk->private_data; +int ret =0 ; + +mutex_lock (&ctl_mutex); + pd->refcnt--; +BUG_ON (pd->refcnt <0 ); +if (pd->refcnt ==0 ) { +int flush =test_bit (PACKET_WRITABLE , &pd->flags); +pkt_release_dev (pd, flush); + } +mutex_unlock (&ctl_mutex); +return ret; +} + +static int pkt_ioctl (struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg) +{ +struct pktcdvd_device *pd = inode->i_bdev->bd_disk->private_data; + +VPRINTK ("pkt_ioctl: cmd %x, dev %d:%d\n" , cmd,imajor (inode),iminor (inode)); + +switch (cmd) { +/* +* forward selected CDROM ioctls to CD-ROM, for UDF +*/ +case CDROMMULTISESSION : +case CDROMREADTOCENTRY : +case CDROM_LAST_WRITTEN : +case CDROM_SEND_PACKET : +case SCSI_IOCTL_SEND_COMMAND : +return blkdev_ioctl (pd->bdev->bd_inode, file, cmd, arg); + +case CDROMEJECT : +/* +* The door gets locked when the device is opened, so we +* have to unlock it or else the eject command fails. +*/ +if (pd->refcnt ==1 ) +pkt_lock_door (pd,0 ); +return blkdev_ioctl (pd->bdev->bd_inode, file, cmd, arg); + +default : +VPRINTK (DRIVER_NAME ": Unknown ioctl for %s (%x)\n" , pd->name, cmd); +return -ENOTTY ; + } + +return 0 ; +} + +static int pkt_media_changed (struct gendisk *disk) +{ +struct pktcdvd_device *pd = disk->private_data; +struct gendisk *attached_disk; + +if (!pd) +return 0 ; +if (!pd->bdev) +return 0 ; + attached_disk = pd->bdev->bd_disk; +if (!attached_disk) +return 0 ; +return attached_disk->fops->media_changed (attached_disk); +} + +static struct block_device_operations pktcdvd_ops = { + .owner =THIS_MODULE , + .open = pkt_open, + .release = pkt_close, + .ioctl = pkt_ioctl, + .media_changed = pkt_media_changed, +}; + + +/*********************************************************************** +* +* packet device setup and removal +* +**********************************************************************/ +static void pkt_init_queue (struct pktcdvd_device *pd) {request_queue_t *q = pd->disk->queue;
@@ -3005,63 +3072,6 @@ out_mem:return ret; } -static int pkt_ioctl (struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg) -{ -struct pktcdvd_device *pd = inode->i_bdev->bd_disk->private_data; - -VPRINTK ("pkt_ioctl: cmd %x, dev %d:%d\n" , cmd,imajor (inode),iminor (inode)); - -switch (cmd) { -/* -* forward selected CDROM ioctls to CD-ROM, for UDF -*/ -case CDROMMULTISESSION : -case CDROMREADTOCENTRY : -case CDROM_LAST_WRITTEN : -case CDROM_SEND_PACKET : -case SCSI_IOCTL_SEND_COMMAND : -return blkdev_ioctl (pd->bdev->bd_inode, file, cmd, arg); - -case CDROMEJECT : -/* -* The door gets locked when the device is opened, so we -* have to unlock it or else the eject command fails. -*/ -if (pd->refcnt ==1 ) -pkt_lock_door (pd,0 ); -return blkdev_ioctl (pd->bdev->bd_inode, file, cmd, arg); - -default : -VPRINTK (DRIVER_NAME ": Unknown ioctl for %s (%x)\n" , pd->name, cmd); -return -ENOTTY ; - } - -return 0 ; -} - -static int pkt_media_changed (struct gendisk *disk) -{ -struct pktcdvd_device *pd = disk->private_data; -struct gendisk *attached_disk; - -if (!pd) -return 0 ; -if (!pd->bdev) -return 0 ; - attached_disk = pd->bdev->bd_disk; -if (!attached_disk) -return 0 ; -return attached_disk->fops->media_changed (attached_disk); -} - -static struct block_device_operations pktcdvd_ops = { - .owner =THIS_MODULE , - .open = pkt_open, - .release = pkt_close, - .ioctl = pkt_ioctl, - .media_changed = pkt_media_changed, -}; -/* * Set up mapping from pktcdvd device to CD-ROM device. */
@@ -3207,11 +3217,17 @@ out:return ret; } +/******************************************************** +* +* module init and exit +* +*******************************************************/ static int __init pkt_init (void ) {int ret; +/* check module parameters */ init_write_congestion_marks (&write_congestion_off, &write_congestion_on);init_packet_buffers (&packet_buffers);
@@ -3272,6 +3288,10 @@ static void __exit pkt_exit(void)mempool_destroy (psd_pool); } +/*************************************************************** +* module declaration +**************************************************************/ +MODULE_DESCRIPTION ("Packet writing layer for CD/DVD drives" );MODULE_AUTHOR ("Jens Axboe <[email protected]>,Peter Osterlund <[email protected]>," "Thomas Maier <[email protected]>" );
include/linux/pktcdvd.h +55 -53
132 lines not on this page · raw message