Skip to content

Commit 8a12c4a

Browse files
htejunJens Axboe
authored andcommitted
hd: dequeue and track in-flight request
hd has at most single request in flight. Till now, whenever it needs to access the in-flight request it called elv_next_request(). This patch makes hd track the in-flight request directly and dequeue it when processing starts. The added complexity is minimal and this will help future block layer changes. [ Impact: dequeue in-flight request, one elv_next_request() per request ] Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
1 parent 5b36ad6 commit 8a12c4a

1 file changed

Lines changed: 40 additions & 23 deletions

File tree

‎drivers/block/hd.c‎

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@
9898

9999
static DEFINE_SPINLOCK(hd_lock);
100100
static struct request_queue *hd_queue;
101+
static struct request *hd_req;
101102

102103
#define MAJOR_NR HD_MAJOR
103-
#define QUEUE (hd_queue)
104-
#define CURRENT elv_next_request(hd_queue)
105104

106105
#define TIMEOUT_VALUE (6*HZ)
107106
#define HD_DELAY 0
@@ -195,11 +194,24 @@ static void __init hd_setup(char *str, int *ints)
195194
NR_HD = hdind+1;
196195
}
197196

197+
static bool hd_end_request(int err, unsigned int bytes)
198+
{
199+
if (__blk_end_request(hd_req, err, bytes))
200+
return true;
201+
hd_req = NULL;
202+
return false;
203+
}
204+
205+
static bool hd_end_request_cur(int err)
206+
{
207+
return hd_end_request(err, blk_rq_cur_bytes(hd_req));
208+
}
209+
198210
static void dump_status(const char *msg, unsigned int stat)
199211
{
200212
char *name = "hd?";
201-
if (CURRENT)
202-
name = CURRENT->rq_disk->disk_name;
213+
if (hd_req)
214+
name = hd_req->rq_disk->disk_name;
203215

204216
#ifdef VERBOSE_ERRORS
205217
printk("%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
@@ -227,8 +239,8 @@ static void dump_status(const char *msg, unsigned int stat)
227239
if (hd_error & (BBD_ERR|ECC_ERR|ID_ERR|MARK_ERR)) {
228240
printk(", CHS=%d/%d/%d", (inb(HD_HCYL)<<8) + inb(HD_LCYL),
229241
inb(HD_CURRENT) & 0xf, inb(HD_SECTOR));
230-
if (CURRENT)
231-
printk(", sector=%ld", blk_rq_pos(CURRENT));
242+
if (hd_req)
243+
printk(", sector=%ld", blk_rq_pos(hd_req));
232244
}
233245
printk("\n");
234246
}
@@ -406,11 +418,12 @@ static void unexpected_hd_interrupt(void)
406418
*/
407419
static void bad_rw_intr(void)
408420
{
409-
struct request *req = CURRENT;
421+
struct request *req = hd_req;
422+
410423
if (req != NULL) {
411424
struct hd_i_struct *disk = req->rq_disk->private_data;
412425
if (++req->errors >= MAX_ERRORS || (hd_error & BBD_ERR)) {
413-
__blk_end_request_cur(req, -EIO);
426+
hd_end_request_cur(-EIO);
414427
disk->special_op = disk->recalibrate = 1;
415428
} else if (req->errors % RESET_FREQ == 0)
416429
reset = 1;
@@ -454,14 +467,14 @@ static void read_intr(void)
454467
return;
455468

456469
ok_to_read:
457-
req = CURRENT;
470+
req = hd_req;
458471
insw(HD_DATA, req->buffer, 256);
459472
#ifdef DEBUG
460473
printk("%s: read: sector %ld, remaining = %u, buffer=%p\n",
461474
req->rq_disk->disk_name, blk_rq_pos(req) + 1,
462475
blk_rq_sectors(req) - 1, req->buffer+512);
463476
#endif
464-
if (__blk_end_request(req, 0, 512)) {
477+
if (hd_end_request(0, 512)) {
465478
SET_HANDLER(&read_intr);
466479
return;
467480
}
@@ -475,7 +488,7 @@ static void read_intr(void)
475488

476489
static void write_intr(void)
477490
{
478-
struct request *req = CURRENT;
491+
struct request *req = hd_req;
479492
int i;
480493
int retries = 100000;
481494

@@ -494,7 +507,7 @@ static void write_intr(void)
494507
return;
495508

496509
ok_to_write:
497-
if (__blk_end_request(req, 0, 512)) {
510+
if (hd_end_request(0, 512)) {
498511
SET_HANDLER(&write_intr);
499512
outsw(HD_DATA, req->buffer, 256);
500513
return;
@@ -525,18 +538,18 @@ static void hd_times_out(unsigned long dummy)
525538

526539
do_hd = NULL;
527540

528-
if (!CURRENT)
541+
if (!hd_req)
529542
return;
530543

531544
spin_lock_irq(hd_queue->queue_lock);
532545
reset = 1;
533-
name = CURRENT->rq_disk->disk_name;
546+
name = hd_req->rq_disk->disk_name;
534547
printk("%s: timeout\n", name);
535-
if (++CURRENT->errors >= MAX_ERRORS) {
548+
if (++hd_req->errors >= MAX_ERRORS) {
536549
#ifdef DEBUG
537550
printk("%s: too many errors\n", name);
538551
#endif
539-
__blk_end_request_cur(CURRENT, -EIO);
552+
hd_end_request_cur(-EIO);
540553
}
541554
hd_request();
542555
spin_unlock_irq(hd_queue->queue_lock);
@@ -551,7 +564,7 @@ static int do_special_op(struct hd_i_struct *disk, struct request *req)
551564
}
552565
if (disk->head > 16) {
553566
printk("%s: cannot handle device with more than 16 heads - giving up\n", req->rq_disk->disk_name);
554-
__blk_end_request_cur(req, -EIO);
567+
hd_end_request_cur(-EIO);
555568
}
556569
disk->special_op = 0;
557570
return 1;
@@ -578,11 +591,15 @@ static void hd_request(void)
578591
repeat:
579592
del_timer(&device_timer);
580593

581-
req = CURRENT;
582-
if (!req) {
583-
do_hd = NULL;
584-
return;
594+
if (!hd_req) {
595+
hd_req = elv_next_request(hd_queue);
596+
if (!hd_req) {
597+
do_hd = NULL;
598+
return;
599+
}
600+
blkdev_dequeue_request(hd_req);
585601
}
602+
req = hd_req;
586603

587604
if (reset) {
588605
reset_hd();
@@ -595,7 +612,7 @@ static void hd_request(void)
595612
((block+nsect) > get_capacity(req->rq_disk))) {
596613
printk("%s: bad access: block=%d, count=%d\n",
597614
req->rq_disk->disk_name, block, nsect);
598-
__blk_end_request_cur(req, -EIO);
615+
hd_end_request_cur(-EIO);
599616
goto repeat;
600617
}
601618

@@ -635,7 +652,7 @@ static void hd_request(void)
635652
break;
636653
default:
637654
printk("unknown hd-command\n");
638-
__blk_end_request_cur(req, -EIO);
655+
hd_end_request_cur(-EIO);
639656
break;
640657
}
641658
}

0 commit comments

Comments
 (0)