Commit 177d3b13 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] pf.c cleaned up

	* switched to private queue
	* got ->queue set
	* ->open() and friends are using ->bd_disk->private_data instead of
	  messing with DEVICE_NR(inode->i_rdev)
	* request handler uses ->rq_disk->private_data instead of DEVICE_NR(...)
	* DEVICE_NR() removed.
	* switched to new methods.
	* got rid of CURRENT
parent c4b2e85f
...@@ -191,7 +191,6 @@ MODULE_PARM(drive3, "1-7i"); ...@@ -191,7 +191,6 @@ MODULE_PARM(drive3, "1-7i");
/* set up defines for blk.h, why don't all drivers do it this way ? */ /* set up defines for blk.h, why don't all drivers do it this way ? */
#define MAJOR_NR major #define MAJOR_NR major
#define DEVICE_NR(device) minor(device)
#include <linux/blk.h> #include <linux/blk.h>
#include <linux/blkpg.h> #include <linux/blkpg.h>
...@@ -272,7 +271,7 @@ struct pf_unit units[PF_UNITS]; ...@@ -272,7 +271,7 @@ struct pf_unit units[PF_UNITS];
static int pf_identify(struct pf_unit *pf); static int pf_identify(struct pf_unit *pf);
static void pf_lock(struct pf_unit *pf, int func); static void pf_lock(struct pf_unit *pf, int func);
static void pf_eject(struct pf_unit *pf); static void pf_eject(struct pf_unit *pf);
static int pf_check_media(kdev_t dev); static int pf_check_media(struct gendisk *disk);
static char pf_scratch[512]; /* scratch block buffer */ static char pf_scratch[512]; /* scratch block buffer */
...@@ -294,11 +293,11 @@ static char *pf_buf; /* buffer for request in progress */ ...@@ -294,11 +293,11 @@ static char *pf_buf; /* buffer for request in progress */
/* kernel glue structures */ /* kernel glue structures */
static struct block_device_operations pf_fops = { static struct block_device_operations pf_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = pf_open, .open = pf_open,
.release = pf_release, .release = pf_release,
.ioctl = pf_ioctl, .ioctl = pf_ioctl,
.check_media_change = pf_check_media, .media_changed = pf_check_media,
}; };
void pf_init_units(void) void pf_init_units(void)
...@@ -328,8 +327,7 @@ void pf_init_units(void) ...@@ -328,8 +327,7 @@ void pf_init_units(void)
static int pf_open(struct inode *inode, struct file *file) static int pf_open(struct inode *inode, struct file *file)
{ {
int unit = DEVICE_NR(inode->i_rdev); struct pf_unit *pf = inode->i_bdev->bd_disk->private_data;
struct pf_unit *pf = units + unit;
pf_identify(pf); pf_identify(pf);
...@@ -348,10 +346,9 @@ static int pf_open(struct inode *inode, struct file *file) ...@@ -348,10 +346,9 @@ static int pf_open(struct inode *inode, struct file *file)
static int pf_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) static int pf_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{ {
int unit = DEVICE_NR(inode->i_rdev); struct pf_unit *pf = inode->i_bdev->bd_disk->private_data;
struct hd_geometry *geo = (struct hd_geometry *) arg; struct hd_geometry *geo = (struct hd_geometry *) arg;
struct hd_geometry g; struct hd_geometry g;
struct pf_unit *pf = units + unit;
sector_t capacity; sector_t capacity;
if (cmd == CDROMEJECT) { if (cmd == CDROMEJECT) {
...@@ -380,10 +377,9 @@ static int pf_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un ...@@ -380,10 +377,9 @@ static int pf_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
static int pf_release(struct inode *inode, struct file *file) static int pf_release(struct inode *inode, struct file *file)
{ {
int unit = DEVICE_NR(inode->i_rdev); struct pf_unit *pf = inode->i_bdev->bd_disk->private_data;
struct pf_unit *pf = units + unit;
if ((unit >= PF_UNITS) || (pf->access <= 0)) if (pf->access <= 0)
return -EINVAL; return -EINVAL;
pf->access--; pf->access--;
...@@ -395,7 +391,7 @@ static int pf_release(struct inode *inode, struct file *file) ...@@ -395,7 +391,7 @@ static int pf_release(struct inode *inode, struct file *file)
} }
static int pf_check_media(kdev_t dev) static int pf_check_media(struct gendisk *disk)
{ {
return 1; return 1;
} }
...@@ -784,25 +780,23 @@ static int pf_ready(void) ...@@ -784,25 +780,23 @@ static int pf_ready(void)
return (((status_reg(pf_current) & (STAT_BUSY | pf_mask)) == pf_mask)); return (((status_reg(pf_current) & (STAT_BUSY | pf_mask)) == pf_mask));
} }
static struct request_queue pf_queue;
static void do_pf_request(request_queue_t * q) static void do_pf_request(request_queue_t * q)
{ {
int unit;
if (pf_busy) if (pf_busy)
return; return;
repeat: repeat:
if (elv_queue_empty(QUEUE)) if (elv_queue_empty(q))
return; return;
pf_req = elv_next_request(QUEUE); pf_req = elv_next_request(q);
unit = DEVICE_NR(pf_req->rq_dev); pf_current = pf_req->rq_disk->private_data;
pf_current = units + unit;
pf_block = pf_req->sector; pf_block = pf_req->sector;
pf_run = pf_req->nr_sectors; pf_run = pf_req->nr_sectors;
pf_count = pf_req->current_nr_sectors; pf_count = pf_req->current_nr_sectors;
if ((unit >= PF_UNITS) || if (pf_block + pf_count > get_capacity(pf_req->rq_disk)) {
(pf_block + pf_count > get_capacity(pf_current->disk))) {
end_request(pf_req, 0); end_request(pf_req, 0);
goto repeat; goto repeat;
} }
...@@ -849,7 +843,7 @@ static inline void next_request(int success) ...@@ -849,7 +843,7 @@ static inline void next_request(int success)
spin_lock_irqsave(&pf_spin_lock, saved_flags); spin_lock_irqsave(&pf_spin_lock, saved_flags);
end_request(pf_req, success); end_request(pf_req, success);
pf_busy = 0; pf_busy = 0;
do_pf_request(NULL); do_pf_request(&pf_queue);
spin_unlock_irqrestore(&pf_spin_lock, saved_flags); spin_unlock_irqrestore(&pf_spin_lock, saved_flags);
} }
...@@ -960,7 +954,6 @@ static int __init pf_init(void) ...@@ -960,7 +954,6 @@ static int __init pf_init(void)
{ /* preliminary initialisation */ { /* preliminary initialisation */
struct pf_unit *pf; struct pf_unit *pf;
int unit; int unit;
request_queue_t *q;
if (disable) if (disable)
return -1; return -1;
...@@ -977,15 +970,16 @@ static int __init pf_init(void) ...@@ -977,15 +970,16 @@ static int __init pf_init(void)
put_disk(pf->disk); put_disk(pf->disk);
return -1; return -1;
} }
q = BLK_DEFAULT_QUEUE(MAJOR_NR); blk_init_queue(&pf_queue, do_pf_request, &pf_spin_lock);
blk_init_queue(q, do_pf_request, &pf_spin_lock); blk_queue_max_phys_segments(&pf_queue, cluster);
blk_queue_max_phys_segments(q, cluster); blk_queue_max_hw_segments(&pf_queue, cluster);
blk_queue_max_hw_segments(q, cluster);
for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
struct gendisk *disk = pf->disk; struct gendisk *disk = pf->disk;
if (!pf->present) if (!pf->present)
continue; continue;
disk->private_data = pf;
disk->queue = &pf_queue;
add_disk(disk); add_disk(disk);
} }
return 0; return 0;
...@@ -1003,6 +997,7 @@ static void __exit pf_exit(void) ...@@ -1003,6 +997,7 @@ static void __exit pf_exit(void)
put_disk(pf->disk); put_disk(pf->disk);
pi_release(pf->pi); pi_release(pf->pi);
} }
blk_cleanup_queue(&pf_queue);
} }
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment