Commit cdac1baf authored by Martin Dalecki's avatar Martin Dalecki Committed by Linus Torvalds

[PATCH] 2.5.18 QUEUE_EMPTY and the unpleasant friends.

 - Eliminate all usages of the obscure QUEUE_EMPTY macro.

 - Eliminate all unneccessary checks for RQ_INACTIVE, this can't happen during
   the time we run the request strategy routine of a single major number block
   device. Perhaps the still remaining usage in scsi and i2o_block.c should be
   killed as well, since the upper ll_rw_blk layer shouldn't pass inactive
   requests down.

Those are all places where we have deeply burried and hidden major number
indexed arrays. Let's deal with them slowly...
parent 5fb231d2
......@@ -591,7 +591,7 @@ static void fd_error(void)
{
printk("FDC1772: fd_error\n");
/*panic("fd1772: fd_error"); *//* DAG tmp */
if (QUEUE_EMPTY)
if (blk_queue_empty(QUEUE))
return;
CURRENT->errors++;
if (CURRENT->errors >= MAX_ERRORS) {
......@@ -1114,16 +1114,6 @@ static void finish_fdc_done(int dummy)
static int fd_ref[4];
static int fd_device[4];
/*
* Current device number. Taken either from the block header or from the
* format request descriptor.
*/
#define CURRENT_DEVICE (CURRENT->rq_dev)
/* Current error count. */
#define CURRENT_ERRORS (CURRENT->errors)
/* dummy for blk.h */
static void floppy_off(unsigned int nr)
{
......@@ -1145,7 +1135,7 @@ static int check_floppy_change(dev_t dev)
{
unsigned int drive = (dev & 0x03);
if (MAJOR(dev) != MAJOR_NR) {
if (major(dev) != MAJOR_NR) {
printk("floppy_changed: not a floppy\n");
return 0;
}
......@@ -1205,7 +1195,7 @@ static void setup_req_params(int drive)
ReqData = ReqBuffer + 512 * ReqCnt;
#ifdef TRACKBUFFER
read_track = (ReqCmd == READ && CURRENT_ERRORS == 0);
read_track = (ReqCmd == READ && CURRENT->errors == 0);
#endif
DPRINT(("Request params: Si=%d Tr=%d Se=%d Data=%08lx\n", ReqSide,
......@@ -1220,24 +1210,21 @@ static void redo_fd_request(void)
DPRINT(("redo_fd_request: CURRENT=%08lx CURRENT->rq_dev=%04x CURRENT->sector=%ld\n",
(unsigned long) CURRENT, CURRENT ? CURRENT->rq_dev : 0,
!QUEUE_EMPTY ? CURRENT->sector : 0));
if (!QUEUE_EMPTY && CURRENT->rq_status == RQ_INACTIVE)
goto the_end;
!blk_queue_empty(QUEUE) ? CURRENT->sector : 0));
repeat:
if (QUEUE_EMPTY)
if (blk_queue_empty(QUEUE))
goto the_end;
if (MAJOR(CURRENT->rq_dev) != MAJOR_NR)
if (major(CURRENT->rq_dev) != MAJOR_NR)
panic(DEVICE_NAME ": request list destroyed");
if (CURRENT->bh) {
if (!buffer_locked(CURRENT->bh))
panic(DEVICE_NAME ": block not locked");
}
device = MINOR(CURRENT_DEVICE);
device = minor(CURRENT->rq_dev);
drive = device & 3;
type = device >> 2;
floppy = &unit[drive];
......@@ -1343,7 +1330,7 @@ static int fd_ioctl(struct inode *inode, struct file *filp,
int drive, device;
device = inode->i_rdev;
drive = MINOR(device);
drive = minor(device);
switch (cmd) {
case FDFMTBEG:
return 0;
......@@ -1502,8 +1489,8 @@ static int floppy_open(struct inode *inode, struct file *filp)
DPRINT(("Weird, open called with filp=0\n"));
return -EIO;
}
drive = MINOR(inode->i_rdev) & 3;
if ((MINOR(inode->i_rdev) >> 2) > NUM_DISK_TYPES)
drive = minor(inode->i_rdev) & 3;
if ((minor(inode->i_rdev) >> 2) > NUM_DISK_TYPES)
return -ENXIO;
old_dev = fd_device[drive];
......@@ -1543,7 +1530,7 @@ static int floppy_open(struct inode *inode, struct file *filp)
static int floppy_release(struct inode *inode, struct file *filp)
{
int drive = MINOR(inode->i_rdev) & 3;
int drive = minor(inode->i_rdev) & 3;
if (fd_ref[drive] < 0)
fd_ref[drive] = 0;
......
......@@ -756,7 +756,7 @@ static void request_done(int uptodate)
/* No - its the end of the line */
/* end_request's should have happened at the end of sector DMAs */
/* Turns Drive LEDs off - may slow it down? */
if (QUEUE_EMPTY)
if (blk_queue_empty(QUEUE))
issue_command(CMD_CKV, block, 2);
Busy = 0;
......
......@@ -768,7 +768,7 @@ static void unexpected_acsi_interrupt( void )
static void bad_rw_intr( void )
{
if (QUEUE_EMPTY)
if (blk_queue_empty(QUEUE))
return;
if (++CURRENT->errors >= MAX_ERRORS)
......@@ -842,7 +842,8 @@ static void acsi_times_out( unsigned long dummy )
DEVICE_INTR = NULL;
printk( KERN_ERR "ACSI timeout\n" );
if (QUEUE_EMPTY) return;
if (blk_queue_empty(QUEUE))
return;
if (++CURRENT->errors >= MAX_ERRORS) {
#ifdef DEBUG
printk( KERN_ERR "ACSI: too many errors.\n" );
......@@ -951,40 +952,20 @@ static void redo_acsi_request( void )
char *buffer;
unsigned long pbuffer;
struct buffer_head *bh;
if (!QUEUE_EMPTY && CURRENT->rq_status == RQ_INACTIVE) {
if (!DEVICE_INTR) {
ENABLE_IRQ();
stdma_release();
}
return;
}
if (DEVICE_INTR)
return;
repeat:
CLEAR_TIMER();
/* Another check here: An interrupt or timer event could have
* happened since the last check!
*/
if (!QUEUE_EMPTY && CURRENT->rq_status == RQ_INACTIVE) {
if (!DEVICE_INTR) {
ENABLE_IRQ();
stdma_release();
}
return;
}
if (DEVICE_INTR)
return;
if (QUEUE_EMPTY) {
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
ENABLE_IRQ();
stdma_release();
return;
}
if (MAJOR(CURRENT->rq_dev) != MAJOR_NR)
panic(DEVICE_NAME ": request list destroyed");
if (CURRENT->bh) {
......
......@@ -208,17 +208,6 @@ static DECLARE_WAIT_QUEUE_HEAD(ms_wait);
static int fd_ref[4] = { 0,0,0,0 };
static kdev_t fd_device[4] = { NODEV, NODEV, NODEV, NODEV };
/*
* Current device number. Taken either from the block header or from the
* format request descriptor.
*/
#define CURRENT_DEVICE (CURRENT->rq_dev)
/* Current error count. */
#define CURRENT_ERRORS (CURRENT->errors)
/*
* Here come the actual hardware access and helper functions.
* They are not reentrant and single threaded because all drives
......@@ -1383,12 +1372,8 @@ static void redo_fd_request(void)
char *data;
unsigned long flags;
if (!QUEUE_EMPTY && CURRENT->rq_status == RQ_INACTIVE){
return;
}
repeat:
if (QUEUE_EMPTY) {
if (blk_queue_empty(QUEUE)) {
/* Nothing left to do */
return;
}
......@@ -1396,7 +1381,7 @@ static void redo_fd_request(void)
if (major(CURRENT->rq_dev) != MAJOR_NR)
panic(DEVICE_NAME ": request list destroyed");
device = minor(CURRENT_DEVICE);
device = minor(CURRENT->rq_dev);
if (device < 8) {
/* manual selection */
drive = device & 3;
......
......@@ -625,8 +625,10 @@ static void fd_error( void )
wake_up( &format_wait );
return;
}
if (QUEUE_EMPTY) return;
if (blk_queue_empty(QUEUE))
return;
CURRENT->errors++;
if (CURRENT->errors >= MAX_ERRORS) {
printk(KERN_ERR "fd%d: too many errors.\n", SelectedDrive );
......@@ -1335,16 +1337,6 @@ static void finish_fdc_done( int dummy )
static int fd_ref[4] = { 0,0,0,0 };
static int fd_device[4] = { 0,0,0,0 };
/*
* Current device number. Taken either from the block header or from the
* format request descriptor.
*/
#define CURRENT_DEVICE (CURRENT->rq_dev)
/* Current error count. */
#define CURRENT_ERRORS (CURRENT->errors)
/* dummy for blk.h */
static void floppy_off( unsigned int nr) {}
......@@ -1437,7 +1429,7 @@ static void setup_req_params( int drive )
ReqData = ReqBuffer + 512 * ReqCnt;
if (UseTrackbuffer)
read_track = (ReqCmd == READ && CURRENT_ERRORS == 0);
read_track = (ReqCmd == READ && CURRENT->errors == 0);
else
read_track = 0;
......@@ -1451,18 +1443,14 @@ static void redo_fd_request(void)
int device, drive, type;
DPRINT(("redo_fd_request: CURRENT=%08lx CURRENT->dev=%04x CURRENT->sector=%ld\n",
(unsigned long)CURRENT, !QUEUE_EMPTY ? CURRENT->rq_dev : 0,
!QUEUE_EMPTY ? CURRENT->sector : 0 ));
(unsigned long)CURRENT, !blk_queue_empty(QUEUE) ? CURRENT->rq_dev : 0,
!blk_queue_empty(QUEUE) ? CURRENT->sector : 0 ));
IsFormatting = 0;
if (!QUEUE_EMPTY && CURRENT->rq_status == RQ_INACTIVE){
return;
}
repeat:
if (QUEUE_EMPTY)
if (blk_queue_empty(QUEUE))
goto the_end;
if (major(CURRENT->rq_dev) != MAJOR_NR)
......@@ -1471,7 +1459,7 @@ static void redo_fd_request(void)
if (CURRENT->bh && !buffer_locked(CURRENT->bh))
panic(DEVICE_NAME ": block not locked");
device = minor(CURRENT_DEVICE);
device = minor(CURRENT->rq_dev);
drive = device & 3;
type = device >> 2;
......
......@@ -2918,14 +2918,8 @@ static void redo_fd_request(void)
if (current_drive < N_DRIVE)
floppy_off(current_drive);
if (!QUEUE_EMPTY && CURRENT->rq_status == RQ_INACTIVE){
CLEAR_INTR;
unlock_fdc();
return;
}
while(1){
if (QUEUE_EMPTY) {
for (;;) {
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
unlock_fdc();
return;
......
......@@ -323,7 +323,7 @@ static void do_nbd_request(request_queue_t * q)
int dev = 0;
struct nbd_device *lo;
while (!QUEUE_EMPTY) {
while (!blk_queue_empty(QUEUE)) {
req = CURRENT;
#ifdef PARANOIA
if (!req)
......
......@@ -877,10 +877,9 @@ static void pd_next_buf( int unit )
/* paranoia */
if (QUEUE_EMPTY ||
if (blk_queue_empty(QUEUE) ||
(rq_data_dir(CURRENT) != pd_cmd) ||
(minor(CURRENT->rq_dev) != pd_dev) ||
(CURRENT->rq_status == RQ_INACTIVE) ||
(CURRENT->sector != pd_block))
printk("%s: OUCH: request list changed unexpectedly\n",
PD.name);
......
......@@ -881,10 +881,9 @@ static void pf_next_buf( int unit )
/* paranoia */
if (QUEUE_EMPTY ||
if (blk_queue_empty(QUEUE) ||
(rq_data_dir(CURRENT) != pf_cmd) ||
(DEVICE_NR(CURRENT->rq_dev) != pf_unit) ||
(CURRENT->rq_status == RQ_INACTIVE) ||
(CURRENT->sector != pf_block))
printk("%s: OUCH: request list changed unexpectedly\n",
PF.name);
......
......@@ -466,7 +466,7 @@ static void do_ps2esdi_request(request_queue_t * q)
#if 0
printk("%s:got request. device : %d minor : %d command : %d sector : %ld count : %ld, buffer: %p\n",
DEVICE_NAME,
CURRENT_DEV, minor(CURRENT->rq_dev),
DEVICE_NR(CURRENT->rq_dev), minor(CURRENT->rq_dev),
CURRENT->cmd, CURRENT->sector,
CURRENT->current_nr_sectors, CURRENT->buffer);
#endif
......@@ -482,14 +482,14 @@ static void do_ps2esdi_request(request_queue_t * q)
printk("%s: DMA above 16MB not supported\n", DEVICE_NAME);
end_request(FAIL);
} /* check for above 16Mb dmas */
else if ((CURRENT_DEV < ps2esdi_drives) &&
else if ((DEVICE_NR(CURRENT->rq_dev) < ps2esdi_drives) &&
(CURRENT->sector + CURRENT->current_nr_sectors <=
ps2esdi[minor(CURRENT->rq_dev)].nr_sects) &&
CURRENT->flags & REQ_CMD) {
#if 0
printk("%s:got request. device : %d minor : %d command : %d sector : %ld count : %ld\n",
DEVICE_NAME,
CURRENT_DEV, minor(CURRENT->rq_dev),
DEVICE_NR(CURRENT->rq_dev), minor(CURRENT->rq_dev),
CURRENT->cmd, CURRENT->sector,
CURRENT->current_nr_sectors);
#endif
......@@ -499,10 +499,10 @@ static void do_ps2esdi_request(request_queue_t * q)
switch (rq_data_dir(CURRENT)) {
case READ:
ps2esdi_readwrite(READ, CURRENT_DEV, block, count);
ps2esdi_readwrite(READ, DEVICE_NR(CURRENT->rq_dev), block, count);
break;
case WRITE:
ps2esdi_readwrite(WRITE, CURRENT_DEV, block, count);
ps2esdi_readwrite(WRITE, DEVICE_NR(CURRENT->rq_dev), block, count);
break;
default:
printk("%s: Unknown command\n", DEVICE_NAME);
......
......@@ -313,7 +313,7 @@ static void start_request(struct floppy_state *fs)
wake_up(&fs->wait);
return;
}
while (!QUEUE_EMPTY && fs->state == idle) {
while (!blk_queue_empty(QUEUE) && fs->state == idle) {
if (major(CURRENT->rq_dev) != MAJOR_NR)
panic(DEVICE_NAME ": request list destroyed");
// if (CURRENT->bh && !buffer_locked(CURRENT->bh))
......
......@@ -552,7 +552,7 @@ static void start_request(struct floppy_state *fs)
wake_up(&fs->wait);
return;
}
while (!QUEUE_EMPTY && fs->state == idle) {
while (!blk_queue_empty(QUEUE) && fs->state == idle) {
if (MAJOR(CURRENT->rq_dev) != MAJOR_NR)
panic(DEVICE_NAME ": request list destroyed");
if (CURRENT->bh && !buffer_locked(CURRENT->bh))
......
......@@ -286,7 +286,7 @@ static void do_xd_request (request_queue_t * q)
return;
}
if (CURRENT_DEV < xd_drives
if (DEVICE_NR(CURRENT->rq_dev) < xd_drives
&& (CURRENT->flags & REQ_CMD)
&& CURRENT->sector + CURRENT->nr_sectors
<= xd_struct[minor(CURRENT->rq_dev)].nr_sects) {
......@@ -297,7 +297,8 @@ static void do_xd_request (request_queue_t * q)
case READ:
case WRITE:
for (retry = 0; (retry < XD_RETRIES) && !code; retry++)
code = xd_readwrite(rq_data_dir(CURRENT),CURRENT_DEV,CURRENT->buffer,block,count);
code = xd_readwrite(rq_data_dir(CURRENT),DEVICE_NR(CURRENT->rq_dev),
CURRENT->buffer,block,count);
break;
default:
printk("do_xd_request: unknown request\n");
......
......@@ -226,9 +226,13 @@
#define AZT_DEBUG_MULTISESSION
#endif
#define CURRENT_VALID \
(!QUEUE_EMPTY && major(CURRENT -> rq_dev) == MAJOR_NR && CURRENT -> cmd == READ \
&& CURRENT -> sector != -1)
static int current_valid(void)
{
return !blk_queue_empty(QUEUE) &&
major(CURRENT->rq_dev) == MAJOR_NR &&
CURRENT->cmd == READ &&
CURRENT->sector != -1;
}
#define AFL_STATUSorDATA (AFL_STATUS | AFL_DATA)
#define AZT_BUF_SIZ 16
......@@ -1554,34 +1558,33 @@ static void azt_transfer(void)
#ifdef AZT_TEST
printk("aztcd: executing azt_transfer Time:%li\n", jiffies);
#endif
if (CURRENT_VALID) {
while (CURRENT->nr_sectors) {
int bn = CURRENT->sector / 4;
int i;
for (i = 0; i < AZT_BUF_SIZ && azt_buf_bn[i] != bn;
++i);
if (i < AZT_BUF_SIZ) {
int offs =
(i * 4 + (CURRENT->sector & 3)) * 512;
int nr_sectors = 4 - (CURRENT->sector & 3);
if (azt_buf_out != i) {
azt_buf_out = i;
if (azt_buf_bn[i] != bn) {
azt_buf_out = -1;
continue;
}
if (!current_valid())
return;
while (CURRENT->nr_sectors) {
int bn = CURRENT->sector / 4;
int i;
for (i = 0; i < AZT_BUF_SIZ && azt_buf_bn[i] != bn; ++i);
if (i < AZT_BUF_SIZ) {
int offs = (i * 4 + (CURRENT->sector & 3)) * 512;
int nr_sectors = 4 - (CURRENT->sector & 3);
if (azt_buf_out != i) {
azt_buf_out = i;
if (azt_buf_bn[i] != bn) {
azt_buf_out = -1;
continue;
}
if (nr_sectors > CURRENT->nr_sectors)
nr_sectors = CURRENT->nr_sectors;
memcpy(CURRENT->buffer, azt_buf + offs,
nr_sectors * 512);
CURRENT->nr_sectors -= nr_sectors;
CURRENT->sector += nr_sectors;
CURRENT->buffer += nr_sectors * 512;
} else {
azt_buf_out = -1;
break;
}
if (nr_sectors > CURRENT->nr_sectors)
nr_sectors = CURRENT->nr_sectors;
memcpy(CURRENT->buffer, azt_buf + offs,
nr_sectors * 512);
CURRENT->nr_sectors -= nr_sectors;
CURRENT->sector += nr_sectors;
CURRENT->buffer += nr_sectors * 512;
} else {
azt_buf_out = -1;
break;
}
}
}
......@@ -1598,7 +1601,7 @@ static void do_aztcd_request(request_queue_t * q)
return;
}
azt_transfer_is_active = 1;
while (CURRENT_VALID) {
while (current_valid()) {
azt_transfer();
if (CURRENT->nr_sectors == 0) {
end_request(1);
......@@ -1607,7 +1610,7 @@ static void do_aztcd_request(request_queue_t * q)
if (azt_state == AZT_S_IDLE) {
if ((!aztTocUpToDate) || aztDiskChanged) {
if (aztUpdateToc() < 0) {
while (CURRENT_VALID)
while (current_valid())
end_request(0);
break;
}
......@@ -1991,7 +1994,7 @@ static void azt_poll(void)
AztTries = 0;
loop_ctl = 0;
}
if (CURRENT_VALID)
if (current_valid())
end_request(0);
AztTries = 5;
}
......@@ -2065,7 +2068,7 @@ static void azt_poll(void)
break;
}
azt_state = AZT_S_IDLE;
while (CURRENT_VALID)
while (current_valid())
end_request(0);
return;
}
......@@ -2120,12 +2123,12 @@ static void azt_poll(void)
break;
}
azt_state = AZT_S_IDLE;
while (CURRENT_VALID)
while (current_valid())
end_request(0);
return;
}
if (CURRENT_VALID) {
if (current_valid()) {
struct azt_Play_msf msf;
int i;
azt_next_bn = CURRENT->sector / 4;
......@@ -2218,7 +2221,7 @@ static void azt_poll(void)
AztTries = 0;
break;
}
if (CURRENT_VALID)
if (current_valid())
end_request(0);
AztTries = 5;
}
......@@ -2246,8 +2249,7 @@ static void azt_poll(void)
}
#endif
AztTries = 5;
if (!CURRENT_VALID
&& azt_buf_in == azt_buf_out) {
if (!current_valid() && azt_buf_in == azt_buf_out) {
azt_state = AZT_S_STOP;
loop_ctl = 1;
break;
......@@ -2319,7 +2321,7 @@ static void azt_poll(void)
}
}
if (!azt_transfer_is_active) {
while (CURRENT_VALID) {
while (current_valid()) {
azt_transfer();
if (CURRENT->nr_sectors ==
0)
......@@ -2329,7 +2331,7 @@ static void azt_poll(void)
}
}
if (CURRENT_VALID
if (current_valid()
&& (CURRENT->sector / 4 < azt_next_bn
|| CURRENT->sector / 4 >
azt_next_bn + AZT_BUF_SIZ)) {
......@@ -2403,10 +2405,10 @@ static void azt_poll(void)
#ifdef AZT_TEST3
printk("CURRENT_VALID %d azt_mode %d\n",
CURRENT_VALID, azt_mode);
current_valid(), azt_mode);
#endif
if (CURRENT_VALID) {
if (current_valid()) {
if (st != -1) {
if (azt_mode == 1) {
azt_state = AZT_S_READ;
......
......@@ -1563,11 +1563,6 @@ static void do_cdu31a_request(request_queue_t * q)
interruptible_sleep_on(&sony_wait);
if (signal_pending(current)) {
restore_flags(flags);
if (!QUEUE_EMPTY
&& CURRENT->rq_status != RQ_INACTIVE) {
end_request(0);
}
restore_flags(flags);
#if DEBUG
printk("Leaving do_cdu31a_request at %d\n",
__LINE__);
......
......@@ -288,7 +288,7 @@ static void __do_gscd_request(unsigned long dummy)
block = CURRENT->sector;
nsect = CURRENT->nr_sectors;
if (QUEUE_EMPTY || CURRENT->sector == -1)
if (CURRENT->sector == -1)
goto out;
if (CURRENT->cmd != READ) {
......
......@@ -119,9 +119,13 @@ static int mcdPresent;
#define QUICK_LOOP_DELAY udelay(45) /* use udelay */
#define QUICK_LOOP_COUNT 20
#define CURRENT_VALID \
(!QUEUE_EMPTY && major(CURRENT -> rq_dev) == MAJOR_NR && CURRENT -> cmd == READ \
&& CURRENT -> sector != -1)
static int current_valid(void)
{
return !blk_queue_empty(QUEUE) &&
major(CURRENT->rq_dev) == MAJOR_NR &&
CURRENT->cmd == READ &&
CURRENT->sector != -1;
}
#define MFL_STATUSorDATA (MFL_STATUS | MFL_DATA)
#define MCD_BUF_SIZ 16
......@@ -556,33 +560,33 @@ int mcd_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd,
static void mcd_transfer(void)
{
if (CURRENT_VALID) {
while (CURRENT->nr_sectors) {
int bn = CURRENT->sector / 4;
int i;
for (i = 0; i < MCD_BUF_SIZ && mcd_buf_bn[i] != bn;
++i);
if (i < MCD_BUF_SIZ) {
int offs =(i * 4 + (CURRENT->sector & 3)) * 512;
int nr_sectors = 4 - (CURRENT->sector & 3);
if (mcd_buf_out != i) {
mcd_buf_out = i;
if (mcd_buf_bn[i] != bn) {
mcd_buf_out = -1;
continue;
}
if (!current_valid())
return;
while (CURRENT->nr_sectors) {
int bn = CURRENT->sector / 4;
int i;
for (i = 0; i < MCD_BUF_SIZ && mcd_buf_bn[i] != bn; ++i)
;
if (i < MCD_BUF_SIZ) {
int offs =(i * 4 + (CURRENT->sector & 3)) * 512;
int nr_sectors = 4 - (CURRENT->sector & 3);
if (mcd_buf_out != i) {
mcd_buf_out = i;
if (mcd_buf_bn[i] != bn) {
mcd_buf_out = -1;
continue;
}
if (nr_sectors > CURRENT->nr_sectors)
nr_sectors = CURRENT->nr_sectors;
memcpy(CURRENT->buffer, mcd_buf + offs,
nr_sectors * 512);
CURRENT->nr_sectors -= nr_sectors;
CURRENT->sector += nr_sectors;
CURRENT->buffer += nr_sectors * 512;
} else {
mcd_buf_out = -1;
break;
}
if (nr_sectors > CURRENT->nr_sectors)
nr_sectors = CURRENT->nr_sectors;
memcpy(CURRENT->buffer, mcd_buf + offs, nr_sectors * 512);
CURRENT->nr_sectors -= nr_sectors;
CURRENT->sector += nr_sectors;
CURRENT->buffer += nr_sectors * 512;
} else {
mcd_buf_out = -1;
break;
}
}
}
......@@ -614,7 +618,7 @@ static void do_mcd_request(request_queue_t * q)
CURRENT->nr_sectors));
mcd_transfer_is_active = 1;
while (CURRENT_VALID) {
while (current_valid()) {
mcd_transfer();
if (CURRENT->nr_sectors == 0) {
end_request(1);
......@@ -623,7 +627,7 @@ static void do_mcd_request(request_queue_t * q)
if (mcd_state == MCD_S_IDLE) {
if (!tocUpToDate) {
if (updateToc() < 0) {
while (CURRENT_VALID)
while (current_valid())
end_request(0);
break;
}
......@@ -688,7 +692,7 @@ static void mcd_poll(unsigned long dummy)
McdTries = 0;
goto ret;
}
if (CURRENT_VALID)
if (current_valid())
end_request(0);
McdTries = MCD_RETRY_ATTEMPTS;
}
......@@ -745,7 +749,7 @@ static void mcd_poll(unsigned long dummy)
"mcd: door open\n" :
"mcd: disk removed\n");
mcd_state = MCD_S_IDLE;
while (CURRENT_VALID)
while (current_valid())
end_request(0);
goto out;
}
......@@ -779,12 +783,12 @@ static void mcd_poll(unsigned long dummy)
"mcd: door open\n" :
"mcd: disk removed\n");
mcd_state = MCD_S_IDLE;
while (CURRENT_VALID)
while (current_valid())
end_request(0);
goto out;
}
if (CURRENT_VALID) {
if (current_valid()) {
struct mcd_Play_msf msf;
mcd_next_bn = CURRENT->sector / 4;
hsg2msf(mcd_next_bn, &msf.start);
......@@ -820,7 +824,7 @@ static void mcd_poll(unsigned long dummy)
McdTries = 0;
break;
}
if (CURRENT_VALID)
if (current_valid())
end_request(0);
McdTries = 5;
}
......@@ -833,7 +837,7 @@ static void mcd_poll(unsigned long dummy)
default:
McdTries = 5;
if (!CURRENT_VALID && mcd_buf_in == mcd_buf_out) {
if (!current_valid() && mcd_buf_in == mcd_buf_out) {
mcd_state = MCD_S_STOP;
goto immediately;
}
......@@ -845,7 +849,7 @@ static void mcd_poll(unsigned long dummy)
mcd_buf_out = mcd_buf_in;
mcd_buf_in = mcd_buf_in + 1 == MCD_BUF_SIZ ? 0 : mcd_buf_in + 1;
if (!mcd_transfer_is_active) {
while (CURRENT_VALID) {
while (current_valid()) {
mcd_transfer();
if (CURRENT->nr_sectors == 0)
end_request(1);
......@@ -854,7 +858,7 @@ static void mcd_poll(unsigned long dummy)
}
}
if (CURRENT_VALID
if (current_valid()
&& (CURRENT->sector / 4 < mcd_next_bn ||
CURRENT->sector / 4 > mcd_next_bn + 16)) {
mcd_state = MCD_S_STOP;
......@@ -933,8 +937,9 @@ static void mcd_poll(unsigned long dummy)
st = -1;
do_not_work_around_mitsumi_bug_93_2:
test3(printk("CURRENT_VALID %d mcd_mode %d\n", CURRENT_VALID, mcd_mode));
if (CURRENT_VALID) {
test3(printk("CURRENT_VALID %d mcd_mode %d\n", current_valid(),
mcd_mode));
if (current_valid()) {
if (st != -1) {
if (mcd_mode == 1)
goto read_immediately;
......
......@@ -973,11 +973,13 @@ static int update_toc(void)
/* Request handling */
#define CURRENT_VALID \
(!QUEUE_EMPTY && major(CURRENT -> rq_dev) == MAJOR_NR \
&& CURRENT -> cmd == READ && CURRENT -> sector != -1)
static int current_valid(void)
{
return !blk_queue_empty(QUEUE) &&
major(CURRENT->rq_dev) == MAJOR_NR &&
CURRENT->cmd == READ &&
CURRENT->sector != -1;
}
/* Buffers for block size conversion. */
#define NOBUF -1
......@@ -1006,7 +1008,7 @@ static void transfer(void)
printk(KERN_DEBUG "optcd: executing transfer\n");
#endif
if (!CURRENT_VALID)
if (!current_valid())
return;
while (CURRENT -> nr_sectors) {
int bn = CURRENT -> sector / 4;
......@@ -1092,7 +1094,7 @@ static void poll(unsigned long data)
" Giving up\n", next_bn);
if (transfer_is_active)
loop_again = 0;
if (CURRENT_VALID)
if (current_valid())
end_request(0);
tries = 5;
}
......@@ -1126,7 +1128,7 @@ static void poll(unsigned long data)
break;
if (send_cmd(COMDRVST)) {
state = S_IDLE;
while (CURRENT_VALID)
while (current_valid())
end_request(0);
return;
}
......@@ -1153,11 +1155,11 @@ static void poll(unsigned long data)
? "door open"
: "disk removed");
state = S_IDLE;
while (CURRENT_VALID)
while (current_valid())
end_request(0);
return;
}
if (!CURRENT_VALID) {
if (!current_valid()) {
state = S_STOP;
loop_again = 1;
break;
......@@ -1208,7 +1210,7 @@ static void poll(unsigned long data)
tries = 0;
break;
}
if (CURRENT_VALID)
if (current_valid())
end_request(0);
tries = 5;
}
......@@ -1219,7 +1221,7 @@ static void poll(unsigned long data)
break;
default: /* DTEN low */
tries = 5;
if (!CURRENT_VALID && buf_in == buf_out) {
if (!current_valid() && buf_in == buf_out) {
state = S_STOP;
loop_again = 1;
break;
......@@ -1272,7 +1274,7 @@ static void poll(unsigned long data)
N_BUFS ? 0 : buf_in + 1;
}
if (!transfer_is_active) {
while (CURRENT_VALID) {
while (current_valid()) {
transfer();
if (CURRENT -> nr_sectors == 0)
end_request(1);
......@@ -1281,7 +1283,7 @@ static void poll(unsigned long data)
}
}
if (CURRENT_VALID
if (current_valid()
&& (CURRENT -> sector / 4 < next_bn ||
CURRENT -> sector / 4 >
next_bn + N_BUFS)) {
......@@ -1305,7 +1307,7 @@ static void poll(unsigned long data)
flush_data();
if (send_cmd(COMDRVST)) {
state = S_IDLE;
while (CURRENT_VALID)
while (current_valid())
end_request(0);
return;
}
......@@ -1320,7 +1322,7 @@ static void poll(unsigned long data)
toc_uptodate = 0;
opt_invalidate_buffers();
}
if (CURRENT_VALID) {
if (current_valid()) {
if (status >= 0) {
state = S_READ;
loop_again = 1;
......@@ -1346,7 +1348,7 @@ static void poll(unsigned long data)
state = S_STOP;
if (exec_cmd(COMSTOP) < 0) {
state = S_IDLE;
while (CURRENT_VALID)
while (current_valid())
end_request(0);
return;
}
......@@ -1368,7 +1370,7 @@ static void do_optcd_request(request_queue_t * q)
}
transfer_is_active = 1;
while (CURRENT_VALID) {
while (current_valid()) {
transfer(); /* First try to transfer block from buffers */
if (CURRENT -> nr_sectors == 0) {
end_request(1);
......@@ -1377,7 +1379,7 @@ static void do_optcd_request(request_queue_t * q)
if (state == S_IDLE) {
/* %% Should this block the request queue?? */
if (update_toc() < 0) {
while (CURRENT_VALID)
while (current_valid())
end_request(0);
break;
}
......
......@@ -4902,7 +4902,7 @@ static void DO_SBPCD_REQUEST(request_queue_t * q)
#ifdef DEBUG_GTL
xnr=++xx_nr;
if(QUEUE_EMPTY)
if(blk_queue_empty(QUEUE))
{
printk( "do_sbpcd_request[%di](NULL), Pid:%d, Time:%li\n",
xnr, current->pid, jiffies);
......
......@@ -1074,16 +1074,20 @@ static void sjcd_invalidate_buffers(void)
* When Linux gets variable block sizes this will probably go away.
*/
#define CURRENT_IS_VALID \
( !QUEUE_EMPTY && major( CURRENT->rq_dev ) == MAJOR_NR && \
CURRENT->cmd == READ && CURRENT->sector != -1 )
static int current_valid(void)
{
return !blk_queue_empty(QUEUE) &&
major(CURRENT->rq_dev) == MAJOR_NR &&
CURRENT->cmd == READ &&
CURRENT->sector != -1;
}
static void sjcd_transfer(void)
{
#if defined( SJCD_TRACE )
printk("SJCD: transfer:\n");
#endif
if (CURRENT_IS_VALID) {
if (current_valid()) {
while (CURRENT->nr_sectors) {
int i, bn = CURRENT->sector / 4;
for (i = 0;
......@@ -1239,7 +1243,7 @@ static void sjcd_poll(void)
}
}
if (CURRENT_IS_VALID) {
if (current_valid()) {
struct sjcd_play_msf msf;
sjcd_next_bn = CURRENT->sector / 4;
......@@ -1307,7 +1311,7 @@ static void sjcd_poll(void)
("SJCD: read block %d failed, maybe audio disk? Giving up\n",
sjcd_next_bn);
#endif
if (CURRENT_IS_VALID)
if (current_valid())
end_request(0);
#if defined( SJCD_TRACE )
printk
......@@ -1332,7 +1336,7 @@ static void sjcd_poll(void)
* Otherwise cdrom hangs up. Check to see if we have something to copy
* to.
*/
if (!CURRENT_IS_VALID
if (!current_valid()
&& sjcd_buf_in == sjcd_buf_out) {
#if defined( SJCD_TRACE )
printk
......@@ -1373,7 +1377,7 @@ static void sjcd_poll(void)
* OK, request seems to be precessed. Continue transferring...
*/
if (!sjcd_transfer_is_active) {
while (CURRENT_IS_VALID) {
while (current_valid()) {
/*
* Continue transferring.
*/
......@@ -1387,7 +1391,7 @@ static void sjcd_poll(void)
break;
}
}
if (CURRENT_IS_VALID &&
if (current_valid() &&
(CURRENT->sector / 4 <
sjcd_next_bn
|| CURRENT->sector / 4 >
......@@ -1450,7 +1454,7 @@ static void sjcd_poll(void)
sjcd_toc_uptodate = 0;
sjcd_invalidate_buffers();
}
if (CURRENT_IS_VALID) {
if (current_valid()) {
if (sjcd_status_valid)
sjcd_transfer_state =
SJCD_S_READ;
......@@ -1476,7 +1480,7 @@ static void sjcd_poll(void)
if (--sjcd_transfer_timeout == 0) {
printk("SJCD: timeout in state %d\n", sjcd_transfer_state);
while (CURRENT_IS_VALID)
while (current_valid())
end_request(0);
sjcd_send_cmd(SCMD_STOP);
sjcd_transfer_state = SJCD_S_IDLE;
......@@ -1497,7 +1501,7 @@ static void do_sjcd_request(request_queue_t * q)
CURRENT->sector, CURRENT->nr_sectors);
#endif
sjcd_transfer_is_active = 1;
while (CURRENT_IS_VALID) {
while (current_valid()) {
sjcd_transfer();
if (CURRENT->nr_sectors == 0)
end_request(1);
......@@ -1508,7 +1512,7 @@ static void do_sjcd_request(request_queue_t * q)
if (sjcd_update_toc() < 0) {
printk
("SJCD: transfer: discard\n");
while (CURRENT_IS_VALID)
while (current_valid())
end_request(0);
break;
}
......
......@@ -167,7 +167,7 @@ static void dump_status (const char *msg, unsigned int stat)
unsigned long flags;
char devc;
devc = !QUEUE_EMPTY ? 'a' + DEVICE_NR(CURRENT->rq_dev) : '?';
devc = !blk_queue_empty(QUEUE) ? 'a' + DEVICE_NR(CURRENT->rq_dev) : '?';
save_flags (flags);
sti();
#ifdef VERBOSE_ERRORS
......@@ -196,7 +196,7 @@ static void dump_status (const char *msg, unsigned int stat)
if (hd_error & (BBD_ERR|ECC_ERR|ID_ERR|MARK_ERR)) {
printk(", CHS=%d/%d/%d", (inb(HD_HCYL)<<8) + inb(HD_LCYL),
inb(HD_CURRENT) & 0xf, inb(HD_SECTOR));
if (!QUEUE_EMPTY)
if (!blk_queue_empty(QUEUE))
printk(", sector=%ld", CURRENT->sector);
}
printk("\n");
......@@ -373,7 +373,7 @@ static void bad_rw_intr(void)
{
int dev;
if (QUEUE_EMPTY)
if (blk_queue_empty(QUEUE))
return;
dev = DEVICE_NR(CURRENT->rq_dev);
if (++CURRENT->errors >= MAX_ERRORS || (hd_error & BBD_ERR)) {
......@@ -436,7 +436,7 @@ static void read_intr(void)
#if (HD_DELAY > 0)
last_req = read_timer();
#endif
if (!QUEUE_EMPTY)
if (!blk_queue_empty(QUEUE))
hd_request();
return;
}
......@@ -497,8 +497,10 @@ static void hd_times_out(unsigned long dummy)
unsigned int dev;
DEVICE_INTR = NULL;
if (QUEUE_EMPTY)
if (blk_queue_empty(QUEUE))
return;
disable_irq(HD_IRQ);
sti();
reset = 1;
......
......@@ -19,15 +19,6 @@
#define DEVICE_NR(device) (device)
#define LOCAL_END_REQUEST
#include <linux/blk.h>
/* for old kernels... */
#ifndef QUEUE_EMPTY
#define QUEUE_EMPTY (!CURRENT)
#endif
#if LINUX_VERSION_CODE < 0x20300
#define QUEUE_PLUGGED (blk_dev[MAJOR_NR].plug_tq.sync)
#else
#define QUEUE_PLUGGED (blk_queue_plugged(QUEUE))
#endif
#ifdef CONFIG_DEVFS_FS
#include <linux/devfs_fs_kernel.h>
......@@ -486,7 +477,7 @@ int mtdblock_thread(void *dummy)
add_wait_queue(&thr_wq, &wait);
set_current_state(TASK_INTERRUPTIBLE);
spin_lock_irq(QUEUE->queue_lock);
if (QUEUE_EMPTY || QUEUE_PLUGGED) {
if (blk_queue_empty(QUEUE) || blk_queue_plugged(QUEUE)) {
spin_unlock_irq(QUEUE->queue_lock);
schedule();
remove_wait_queue(&thr_wq, &wait);
......
......@@ -132,7 +132,7 @@ static void mtdblock_request(RQFUNC_ARG)
mtd = __get_mtd_device(NULL, minor(current_request->rq_dev));
if (!mtd) {
printk("MTD device %d doesn't appear to exist any more\n", CURRENT_DEV);
printk("MTD device %d doesn't appear to exist any more\n", DEVICE_NR(CURRENT->rq_dev));
mtdblock_end_request(current_request, 0);
}
......
......@@ -293,20 +293,15 @@ static void floppy_off(unsigned int nr);
#if !defined(IDE_DRIVER)
#ifndef CURRENT
#define CURRENT elv_next_request(&blk_dev[MAJOR_NR].request_queue)
# define CURRENT elv_next_request(&blk_dev[MAJOR_NR].request_queue)
#endif
#ifndef QUEUE
#define QUEUE (&blk_dev[MAJOR_NR].request_queue)
#endif
#ifndef QUEUE_EMPTY
#define QUEUE_EMPTY blk_queue_empty(QUEUE)
# define QUEUE (&blk_dev[MAJOR_NR].request_queue)
#endif
#ifndef DEVICE_NAME
#define DEVICE_NAME "unknown"
# define DEVICE_NAME "unknown"
#endif
#define CURRENT_DEV DEVICE_NR(CURRENT->rq_dev)
#ifdef DEVICE_INTR
static void (*DEVICE_INTR)(void) = NULL;
#endif
......
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