* [PATCH 11/11] 2.6.18-mm3 pktcdvd: reorder code for reability
@ 2006-10-03 15:26 Thomas Maier
0 siblings, 0 replies; only message in thread
From: Thomas Maier @ 2006-10-03 15:26 UTC (permalink / raw)
To: linux-kernel@vger.kernel.org; +Cc: petero2@telia.com, akpm@osdl.org
[-- Attachment #1: Type: text/plain, Size: 268 bytes --]
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<balagi@justmail.de>
-Thomas Maier
[-- Attachment #2: pktcdvd-11-reorder_2.6.18.patch --]
[-- Type: application/octet-stream, Size: 15756 bytes --]
diff -urpN 10-module-params/drivers/block/pktcdvd.c 11-reorder/drivers/block/pktcdvd.c
--- 10-module-params/drivers/block/pktcdvd.c 2006-10-03 13:55:14.000000000 +0200
+++ 11-reorder/drivers/block/pktcdvd.c 2006-10-03 14:17:01.000000000 +0200
@@ -2586,154 +2586,6 @@ static int pkt_open_write(struct pktcdvd
return 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 <axboe@suse.de>,Peter Osterlund <petero2@telia.com>,"
"Thomas Maier <balagi@justmail.de>");
diff -urpN 10-module-params/include/linux/pktcdvd.h 11-reorder/include/linux/pktcdvd.h
--- 10-module-params/include/linux/pktcdvd.h 2006-10-03 13:50:02.000000000 +0200
+++ 11-reorder/include/linux/pktcdvd.h 2006-10-03 14:11:14.000000000 +0200
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2000 Jens Axboe <axboe@suse.de>
* Copyright (C) 2001-2004 Peter Osterlund <petero2@telia.com>
+ * Copyright (C) 2006 Thomas Maier <balagi@justmail.de>
*
* May be copied or modified under the terms of the GNU General Public
* License. See linux/COPYING for more information.
@@ -14,6 +15,38 @@
#include <linux/types.h>
+#define PKT_CTRL_CMD_SETUP 0
+#define PKT_CTRL_CMD_TEARDOWN 1
+#define PKT_CTRL_CMD_STATUS 2
+
+struct pkt_ctrl_command {
+ __u32 command; /* in: Setup, teardown, status */
+ __u32 dev_index; /* in/out: Device index */
+ __u32 dev; /* in/out: Device nr for cdrw device */
+ __u32 pkt_dev; /* in/out: Device nr for packet device */
+ __u32 num_devices; /* out: Largest device index + 1 */
+ __u32 padding; /* Not used */
+};
+
+/*
+ * packet ioctls
+ */
+#define PACKET_IOCTL_MAGIC ('X')
+#define PACKET_CTRL_CMD _IOWR(PACKET_IOCTL_MAGIC, 1, struct pkt_ctrl_command)
+
+
+
+/*************************************************************************
+ * defines and structs used in the kernel only
+ *************************************************************************/
+#ifdef __KERNEL__
+#include <linux/config.h>
+#include <linux/blkdev.h>
+#include <linux/completion.h>
+#include <linux/cdrom.h>
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
+
/*
* 1 for normal debug messages, 2 is very verbose. 0 to turn it off.
*/
@@ -39,9 +72,28 @@
#define USE_WCACHING 0
#endif
-/*
- * No user-servicable parts beyond this point ->
- */
+/* use (old) procfs interface? */
+#ifdef CONFIG_CDROM_PKTCDVD_PROCINTF
+#define PKT_USE_PROCFS 1
+#else
+#define PKT_USE_PROCFS 0
+#endif
+
+/* use concurrent packets per device */
+#ifdef CONFIG_CDROM_PKTCDVD_BUFFERS
+#define PKT_BUFFERS_DEFAULT CONFIG_CDROM_PKTCDVD_BUFFERS
+#else
+#define PKT_BUFFERS_DEFAULT 8
+#endif
+
+
+/* default bio write queue congestion marks */
+#define PKT_WRITE_CONGESTION_ON 5000
+#define PKT_WRITE_CONGESTION_OFF 4500
+#define PKT_WRITE_CONGESTION_MAX (1024*1024)
+#define PKT_WRITE_CONGESTION_MIN 100
+#define PKT_WRITE_CONGESTION_THRESHOLD 25
+
/*
* device types
@@ -88,56 +140,6 @@
#undef PACKET_USE_LS
-#define PKT_CTRL_CMD_SETUP 0
-#define PKT_CTRL_CMD_TEARDOWN 1
-#define PKT_CTRL_CMD_STATUS 2
-
-struct pkt_ctrl_command {
- __u32 command; /* in: Setup, teardown, status */
- __u32 dev_index; /* in/out: Device index */
- __u32 dev; /* in/out: Device nr for cdrw device */
- __u32 pkt_dev; /* in/out: Device nr for packet device */
- __u32 num_devices; /* out: Largest device index + 1 */
- __u32 padding; /* Not used */
-};
-
-/*
- * packet ioctls
- */
-#define PACKET_IOCTL_MAGIC ('X')
-#define PACKET_CTRL_CMD _IOWR(PACKET_IOCTL_MAGIC, 1, struct pkt_ctrl_command)
-
-#ifdef __KERNEL__
-#include <linux/config.h>
-#include <linux/blkdev.h>
-#include <linux/completion.h>
-#include <linux/cdrom.h>
-#include <linux/kobject.h>
-#include <linux/sysfs.h>
-
-/* use (old) procfs interface? */
-#ifdef CONFIG_CDROM_PKTCDVD_PROCINTF
-#define PKT_USE_PROCFS 1
-#else
-#define PKT_USE_PROCFS 0
-#endif
-
-/* use concurrent packets per device */
-#ifdef CONFIG_CDROM_PKTCDVD_BUFFERS
-#define PKT_BUFFERS_DEFAULT CONFIG_CDROM_PKTCDVD_BUFFERS
-#else
-#define PKT_BUFFERS_DEFAULT 8
-#endif
-
-
-/* default bio write queue congestion marks */
-#define PKT_WRITE_CONGESTION_ON 5000
-#define PKT_WRITE_CONGESTION_OFF 4500
-#define PKT_WRITE_CONGESTION_MAX (1024*1024)
-#define PKT_WRITE_CONGESTION_MIN 100
-#define PKT_WRITE_CONGESTION_THRESHOLD 25
-
-
struct packet_settings
{
__u32 size; /* packet size in (512 byte) sectors */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-10-03 15:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-03 15:26 [PATCH 11/11] 2.6.18-mm3 pktcdvd: reorder code for reability Thomas Maier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox