Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'blk-end-request' of git://git.kernel.dk/linux-2.6-block

* 'blk-end-request' of git://git.kernel.dk/linux-2.6-block: (30 commits)
blk_end_request: changing xsysace (take 4)
blk_end_request: changing ub (take 4)
blk_end_request: cleanup of request completion (take 4)
blk_end_request: cleanup 'uptodate' related code (take 4)
blk_end_request: remove/unexport end_that_request_* (take 4)
blk_end_request: changing scsi (take 4)
blk_end_request: add bidi completion interface (take 4)
blk_end_request: changing ide-cd (take 4)
blk_end_request: add callback feature (take 4)
blk_end_request: changing ide normal caller (take 4)
blk_end_request: changing cpqarray (take 4)
blk_end_request: changing cciss (take 4)
blk_end_request: changing ide-scsi (take 4)
blk_end_request: changing s390 (take 4)
blk_end_request: changing mmc (take 4)
blk_end_request: changing i2o_block (take 4)
blk_end_request: changing viocd (take 4)
blk_end_request: changing xen-blkfront (take 4)
blk_end_request: changing viodasd (take 4)
blk_end_request: changing sx8 (take 4)
...

+419 -377
+6 -10
arch/arm/plat-omap/mailbox.c
··· 116 116 } 117 117 118 118 spin_lock(q->queue_lock); 119 - blkdev_dequeue_request(rq); 120 - end_that_request_last(rq, 0); 119 + if (__blk_end_request(rq, 0, 0)) 120 + BUG(); 121 121 spin_unlock(q->queue_lock); 122 122 } 123 123 } ··· 149 149 150 150 msg = (mbox_msg_t) rq->data; 151 151 152 - spin_lock_irqsave(q->queue_lock, flags); 153 - blkdev_dequeue_request(rq); 154 - end_that_request_last(rq, 0); 155 - spin_unlock_irqrestore(q->queue_lock, flags); 152 + if (blk_end_request(rq, 0, 0)) 153 + BUG(); 156 154 157 155 mbox->rxq->callback((void *)msg); 158 156 } ··· 261 263 262 264 *p = (mbox_msg_t) rq->data; 263 265 264 - spin_lock_irqsave(q->queue_lock, flags); 265 - blkdev_dequeue_request(rq); 266 - end_that_request_last(rq, 0); 267 - spin_unlock_irqrestore(q->queue_lock, flags); 266 + if (blk_end_request(rq, 0, 0)) 267 + BUG(); 268 268 269 269 if (unlikely(mbox_seq_test(mbox, *p))) { 270 270 pr_info("mbox: Illegal seq bit!(%08x) ignored\n", *p);
+4 -12
arch/um/drivers/ubd_kern.c
··· 475 475 /* Only changed by ubd_init, which is an initcall. */ 476 476 int thread_fd = -1; 477 477 478 - static void ubd_end_request(struct request *req, int bytes, int uptodate) 478 + static void ubd_end_request(struct request *req, int bytes, int error) 479 479 { 480 - if (!end_that_request_first(req, uptodate, bytes >> 9)) { 481 - struct ubd *dev = req->rq_disk->private_data; 482 - unsigned long flags; 483 - 484 - add_disk_randomness(req->rq_disk); 485 - spin_lock_irqsave(&dev->lock, flags); 486 - end_that_request_last(req, uptodate); 487 - spin_unlock_irqrestore(&dev->lock, flags); 488 - } 480 + blk_end_request(req, error, bytes); 489 481 } 490 482 491 483 /* Callable only from interrupt context - otherwise you need to do ··· 485 493 static inline void ubd_finish(struct request *req, int bytes) 486 494 { 487 495 if(bytes < 0){ 488 - ubd_end_request(req, 0, 0); 496 + ubd_end_request(req, 0, -EIO); 489 497 return; 490 498 } 491 - ubd_end_request(req, bytes, 1); 499 + ubd_end_request(req, bytes, 0); 492 500 } 493 501 494 502 static LIST_HEAD(restart);
+216 -88
block/ll_rw_blk.c
··· 347 347 void blk_ordered_complete_seq(struct request_queue *q, unsigned seq, int error) 348 348 { 349 349 struct request *rq; 350 - int uptodate; 351 350 352 351 if (error && !q->orderr) 353 352 q->orderr = error; ··· 360 361 /* 361 362 * Okay, sequence complete. 362 363 */ 363 - uptodate = 1; 364 - if (q->orderr) 365 - uptodate = q->orderr; 366 - 367 364 q->ordseq = 0; 368 365 rq = q->orig_bar_rq; 369 366 370 - end_that_request_first(rq, uptodate, rq->hard_nr_sectors); 371 - end_that_request_last(rq, uptodate); 367 + if (__blk_end_request(rq, q->orderr, blk_rq_bytes(rq))) 368 + BUG(); 372 369 } 373 370 374 371 static void pre_flush_end_io(struct request *rq, int error) ··· 481 486 * ORDERED_NONE while this request is on it. 482 487 */ 483 488 blkdev_dequeue_request(rq); 484 - end_that_request_first(rq, -EOPNOTSUPP, 485 - rq->hard_nr_sectors); 486 - end_that_request_last(rq, -EOPNOTSUPP); 489 + if (__blk_end_request(rq, -EOPNOTSUPP, 490 + blk_rq_bytes(rq))) 491 + BUG(); 487 492 *rqp = NULL; 488 493 return 0; 489 494 } ··· 3432 3437 } 3433 3438 } 3434 3439 3435 - static int __end_that_request_first(struct request *req, int uptodate, 3440 + /** 3441 + * __end_that_request_first - end I/O on a request 3442 + * @req: the request being processed 3443 + * @error: 0 for success, < 0 for error 3444 + * @nr_bytes: number of bytes to complete 3445 + * 3446 + * Description: 3447 + * Ends I/O on a number of bytes attached to @req, and sets it up 3448 + * for the next range of segments (if any) in the cluster. 3449 + * 3450 + * Return: 3451 + * 0 - we are done with this request, call end_that_request_last() 3452 + * 1 - still buffers pending for this request 3453 + **/ 3454 + static int __end_that_request_first(struct request *req, int error, 3436 3455 int nr_bytes) 3437 3456 { 3438 - int total_bytes, bio_nbytes, error, next_idx = 0; 3457 + int total_bytes, bio_nbytes, next_idx = 0; 3439 3458 struct bio *bio; 3440 3459 3441 3460 blk_add_trace_rq(req->q, req, BLK_TA_COMPLETE); 3442 - 3443 - /* 3444 - * extend uptodate bool to allow < 0 value to be direct io error 3445 - */ 3446 - error = 0; 3447 - if (end_io_error(uptodate)) 3448 - error = !uptodate ? -EIO : uptodate; 3449 3461 3450 3462 /* 3451 3463 * for a REQ_BLOCK_PC request, we want to carry any eventual ··· 3461 3459 if (!blk_pc_request(req)) 3462 3460 req->errors = 0; 3463 3461 3464 - if (!uptodate) { 3462 + if (error) { 3465 3463 if (blk_fs_request(req) && !(req->cmd_flags & REQ_QUIET)) 3466 3464 printk("end_request: I/O error, dev %s, sector %llu\n", 3467 3465 req->rq_disk ? req->rq_disk->disk_name : "?", ··· 3555 3553 return 1; 3556 3554 } 3557 3555 3558 - /** 3559 - * end_that_request_first - end I/O on a request 3560 - * @req: the request being processed 3561 - * @uptodate: 1 for success, 0 for I/O error, < 0 for specific error 3562 - * @nr_sectors: number of sectors to end I/O on 3563 - * 3564 - * Description: 3565 - * Ends I/O on a number of sectors attached to @req, and sets it up 3566 - * for the next range of segments (if any) in the cluster. 3567 - * 3568 - * Return: 3569 - * 0 - we are done with this request, call end_that_request_last() 3570 - * 1 - still buffers pending for this request 3571 - **/ 3572 - int end_that_request_first(struct request *req, int uptodate, int nr_sectors) 3573 - { 3574 - return __end_that_request_first(req, uptodate, nr_sectors << 9); 3575 - } 3576 - 3577 - EXPORT_SYMBOL(end_that_request_first); 3578 - 3579 - /** 3580 - * end_that_request_chunk - end I/O on a request 3581 - * @req: the request being processed 3582 - * @uptodate: 1 for success, 0 for I/O error, < 0 for specific error 3583 - * @nr_bytes: number of bytes to complete 3584 - * 3585 - * Description: 3586 - * Ends I/O on a number of bytes attached to @req, and sets it up 3587 - * for the next range of segments (if any). Like end_that_request_first(), 3588 - * but deals with bytes instead of sectors. 3589 - * 3590 - * Return: 3591 - * 0 - we are done with this request, call end_that_request_last() 3592 - * 1 - still buffers pending for this request 3593 - **/ 3594 - int end_that_request_chunk(struct request *req, int uptodate, int nr_bytes) 3595 - { 3596 - return __end_that_request_first(req, uptodate, nr_bytes); 3597 - } 3598 - 3599 - EXPORT_SYMBOL(end_that_request_chunk); 3600 - 3601 3556 /* 3602 3557 * splice the completion data to a local structure and hand off to 3603 3558 * process_completion_queue() to complete the requests ··· 3634 3675 /* 3635 3676 * queue lock must be held 3636 3677 */ 3637 - void end_that_request_last(struct request *req, int uptodate) 3678 + static void end_that_request_last(struct request *req, int error) 3638 3679 { 3639 3680 struct gendisk *disk = req->rq_disk; 3640 - int error; 3641 3681 3642 - /* 3643 - * extend uptodate bool to allow < 0 value to be direct io error 3644 - */ 3645 - error = 0; 3646 - if (end_io_error(uptodate)) 3647 - error = !uptodate ? -EIO : uptodate; 3682 + if (blk_rq_tagged(req)) 3683 + blk_queue_end_tag(req->q, req); 3684 + 3685 + if (blk_queued_rq(req)) 3686 + blkdev_dequeue_request(req); 3648 3687 3649 3688 if (unlikely(laptop_mode) && blk_fs_request(req)) 3650 3689 laptop_io_completion(); ··· 3661 3704 disk_round_stats(disk); 3662 3705 disk->in_flight--; 3663 3706 } 3707 + 3664 3708 if (req->end_io) 3665 3709 req->end_io(req, error); 3666 - else 3710 + else { 3711 + if (blk_bidi_rq(req)) 3712 + __blk_put_request(req->next_rq->q, req->next_rq); 3713 + 3667 3714 __blk_put_request(req->q, req); 3668 - } 3669 - 3670 - EXPORT_SYMBOL(end_that_request_last); 3671 - 3672 - static inline void __end_request(struct request *rq, int uptodate, 3673 - unsigned int nr_bytes, int dequeue) 3674 - { 3675 - if (!end_that_request_chunk(rq, uptodate, nr_bytes)) { 3676 - if (dequeue) 3677 - blkdev_dequeue_request(rq); 3678 - add_disk_randomness(rq->rq_disk); 3679 - end_that_request_last(rq, uptodate); 3680 3715 } 3681 3716 } 3682 3717 3683 - static unsigned int rq_byte_size(struct request *rq) 3718 + static inline void __end_request(struct request *rq, int uptodate, 3719 + unsigned int nr_bytes) 3720 + { 3721 + int error = 0; 3722 + 3723 + if (uptodate <= 0) 3724 + error = uptodate ? uptodate : -EIO; 3725 + 3726 + __blk_end_request(rq, error, nr_bytes); 3727 + } 3728 + 3729 + /** 3730 + * blk_rq_bytes - Returns bytes left to complete in the entire request 3731 + **/ 3732 + unsigned int blk_rq_bytes(struct request *rq) 3684 3733 { 3685 3734 if (blk_fs_request(rq)) 3686 3735 return rq->hard_nr_sectors << 9; 3687 3736 3688 3737 return rq->data_len; 3689 3738 } 3739 + EXPORT_SYMBOL_GPL(blk_rq_bytes); 3740 + 3741 + /** 3742 + * blk_rq_cur_bytes - Returns bytes left to complete in the current segment 3743 + **/ 3744 + unsigned int blk_rq_cur_bytes(struct request *rq) 3745 + { 3746 + if (blk_fs_request(rq)) 3747 + return rq->current_nr_sectors << 9; 3748 + 3749 + if (rq->bio) 3750 + return rq->bio->bi_size; 3751 + 3752 + return rq->data_len; 3753 + } 3754 + EXPORT_SYMBOL_GPL(blk_rq_cur_bytes); 3690 3755 3691 3756 /** 3692 3757 * end_queued_request - end all I/O on a queued request ··· 3723 3744 **/ 3724 3745 void end_queued_request(struct request *rq, int uptodate) 3725 3746 { 3726 - __end_request(rq, uptodate, rq_byte_size(rq), 1); 3747 + __end_request(rq, uptodate, blk_rq_bytes(rq)); 3727 3748 } 3728 3749 EXPORT_SYMBOL(end_queued_request); 3729 3750 ··· 3740 3761 **/ 3741 3762 void end_dequeued_request(struct request *rq, int uptodate) 3742 3763 { 3743 - __end_request(rq, uptodate, rq_byte_size(rq), 0); 3764 + __end_request(rq, uptodate, blk_rq_bytes(rq)); 3744 3765 } 3745 3766 EXPORT_SYMBOL(end_dequeued_request); 3746 3767 ··· 3766 3787 **/ 3767 3788 void end_request(struct request *req, int uptodate) 3768 3789 { 3769 - __end_request(req, uptodate, req->hard_cur_sectors << 9, 1); 3790 + __end_request(req, uptodate, req->hard_cur_sectors << 9); 3770 3791 } 3771 3792 EXPORT_SYMBOL(end_request); 3793 + 3794 + /** 3795 + * blk_end_io - Generic end_io function to complete a request. 3796 + * @rq: the request being processed 3797 + * @error: 0 for success, < 0 for error 3798 + * @nr_bytes: number of bytes to complete @rq 3799 + * @bidi_bytes: number of bytes to complete @rq->next_rq 3800 + * @drv_callback: function called between completion of bios in the request 3801 + * and completion of the request. 3802 + * If the callback returns non 0, this helper returns without 3803 + * completion of the request. 3804 + * 3805 + * Description: 3806 + * Ends I/O on a number of bytes attached to @rq and @rq->next_rq. 3807 + * If @rq has leftover, sets it up for the next range of segments. 3808 + * 3809 + * Return: 3810 + * 0 - we are done with this request 3811 + * 1 - this request is not freed yet, it still has pending buffers. 3812 + **/ 3813 + static int blk_end_io(struct request *rq, int error, int nr_bytes, 3814 + int bidi_bytes, int (drv_callback)(struct request *)) 3815 + { 3816 + struct request_queue *q = rq->q; 3817 + unsigned long flags = 0UL; 3818 + 3819 + if (blk_fs_request(rq) || blk_pc_request(rq)) { 3820 + if (__end_that_request_first(rq, error, nr_bytes)) 3821 + return 1; 3822 + 3823 + /* Bidi request must be completed as a whole */ 3824 + if (blk_bidi_rq(rq) && 3825 + __end_that_request_first(rq->next_rq, error, bidi_bytes)) 3826 + return 1; 3827 + } 3828 + 3829 + /* Special feature for tricky drivers */ 3830 + if (drv_callback && drv_callback(rq)) 3831 + return 1; 3832 + 3833 + add_disk_randomness(rq->rq_disk); 3834 + 3835 + spin_lock_irqsave(q->queue_lock, flags); 3836 + end_that_request_last(rq, error); 3837 + spin_unlock_irqrestore(q->queue_lock, flags); 3838 + 3839 + return 0; 3840 + } 3841 + 3842 + /** 3843 + * blk_end_request - Helper function for drivers to complete the request. 3844 + * @rq: the request being processed 3845 + * @error: 0 for success, < 0 for error 3846 + * @nr_bytes: number of bytes to complete 3847 + * 3848 + * Description: 3849 + * Ends I/O on a number of bytes attached to @rq. 3850 + * If @rq has leftover, sets it up for the next range of segments. 3851 + * 3852 + * Return: 3853 + * 0 - we are done with this request 3854 + * 1 - still buffers pending for this request 3855 + **/ 3856 + int blk_end_request(struct request *rq, int error, int nr_bytes) 3857 + { 3858 + return blk_end_io(rq, error, nr_bytes, 0, NULL); 3859 + } 3860 + EXPORT_SYMBOL_GPL(blk_end_request); 3861 + 3862 + /** 3863 + * __blk_end_request - Helper function for drivers to complete the request. 3864 + * @rq: the request being processed 3865 + * @error: 0 for success, < 0 for error 3866 + * @nr_bytes: number of bytes to complete 3867 + * 3868 + * Description: 3869 + * Must be called with queue lock held unlike blk_end_request(). 3870 + * 3871 + * Return: 3872 + * 0 - we are done with this request 3873 + * 1 - still buffers pending for this request 3874 + **/ 3875 + int __blk_end_request(struct request *rq, int error, int nr_bytes) 3876 + { 3877 + if (blk_fs_request(rq) || blk_pc_request(rq)) { 3878 + if (__end_that_request_first(rq, error, nr_bytes)) 3879 + return 1; 3880 + } 3881 + 3882 + add_disk_randomness(rq->rq_disk); 3883 + 3884 + end_that_request_last(rq, error); 3885 + 3886 + return 0; 3887 + } 3888 + EXPORT_SYMBOL_GPL(__blk_end_request); 3889 + 3890 + /** 3891 + * blk_end_bidi_request - Helper function for drivers to complete bidi request. 3892 + * @rq: the bidi request being processed 3893 + * @error: 0 for success, < 0 for error 3894 + * @nr_bytes: number of bytes to complete @rq 3895 + * @bidi_bytes: number of bytes to complete @rq->next_rq 3896 + * 3897 + * Description: 3898 + * Ends I/O on a number of bytes attached to @rq and @rq->next_rq. 3899 + * 3900 + * Return: 3901 + * 0 - we are done with this request 3902 + * 1 - still buffers pending for this request 3903 + **/ 3904 + int blk_end_bidi_request(struct request *rq, int error, int nr_bytes, 3905 + int bidi_bytes) 3906 + { 3907 + return blk_end_io(rq, error, nr_bytes, bidi_bytes, NULL); 3908 + } 3909 + EXPORT_SYMBOL_GPL(blk_end_bidi_request); 3910 + 3911 + /** 3912 + * blk_end_request_callback - Special helper function for tricky drivers 3913 + * @rq: the request being processed 3914 + * @error: 0 for success, < 0 for error 3915 + * @nr_bytes: number of bytes to complete 3916 + * @drv_callback: function called between completion of bios in the request 3917 + * and completion of the request. 3918 + * If the callback returns non 0, this helper returns without 3919 + * completion of the request. 3920 + * 3921 + * Description: 3922 + * Ends I/O on a number of bytes attached to @rq. 3923 + * If @rq has leftover, sets it up for the next range of segments. 3924 + * 3925 + * This special helper function is used only for existing tricky drivers. 3926 + * (e.g. cdrom_newpc_intr() of ide-cd) 3927 + * This interface will be removed when such drivers are rewritten. 3928 + * Don't use this interface in other places anymore. 3929 + * 3930 + * Return: 3931 + * 0 - we are done with this request 3932 + * 1 - this request is not freed yet. 3933 + * this request still has pending buffers or 3934 + * the driver doesn't want to finish this request yet. 3935 + **/ 3936 + int blk_end_request_callback(struct request *rq, int error, int nr_bytes, 3937 + int (drv_callback)(struct request *)) 3938 + { 3939 + return blk_end_io(rq, error, nr_bytes, 0, drv_callback); 3940 + } 3941 + EXPORT_SYMBOL_GPL(blk_end_request_callback); 3772 3942 3773 3943 static void blk_rq_bio_prep(struct request_queue *q, struct request *rq, 3774 3944 struct bio *bio)
+2 -9
drivers/block/DAC960.c
··· 3455 3455 bool SuccessfulIO) 3456 3456 { 3457 3457 struct request *Request = Command->Request; 3458 - int UpToDate; 3459 - 3460 - UpToDate = 0; 3461 - if (SuccessfulIO) 3462 - UpToDate = 1; 3458 + int Error = SuccessfulIO ? 0 : -EIO; 3463 3459 3464 3460 pci_unmap_sg(Command->Controller->PCIDevice, Command->cmd_sglist, 3465 3461 Command->SegmentCount, Command->DmaDirection); 3466 3462 3467 - if (!end_that_request_first(Request, UpToDate, Command->BlockCount)) { 3468 - add_disk_randomness(Request->rq_disk); 3469 - end_that_request_last(Request, UpToDate); 3470 - 3463 + if (!__blk_end_request(Request, Error, Command->BlockCount << 9)) { 3471 3464 if (Command->Completion) { 3472 3465 complete(Command->Completion); 3473 3466 Command->Completion = NULL;
+3 -22
drivers/block/cciss.c
··· 1187 1187 } 1188 1188 } 1189 1189 1190 - static inline void complete_buffers(struct bio *bio, int status) 1191 - { 1192 - while (bio) { 1193 - struct bio *xbh = bio->bi_next; 1194 - 1195 - bio->bi_next = NULL; 1196 - bio_endio(bio, status ? 0 : -EIO); 1197 - bio = xbh; 1198 - } 1199 - } 1200 - 1201 1190 static void cciss_check_queues(ctlr_info_t *h) 1202 1191 { 1203 1192 int start_queue = h->next_to_run; ··· 1252 1263 pci_unmap_page(h->pdev, temp64.val, cmd->SG[i].Len, ddir); 1253 1264 } 1254 1265 1255 - complete_buffers(rq->bio, (rq->errors == 0)); 1256 - 1257 - if (blk_fs_request(rq)) { 1258 - const int rw = rq_data_dir(rq); 1259 - 1260 - disk_stat_add(rq->rq_disk, sectors[rw], rq->nr_sectors); 1261 - } 1262 - 1263 1266 #ifdef CCISS_DEBUG 1264 1267 printk("Done with %p\n", rq); 1265 1268 #endif /* CCISS_DEBUG */ 1266 1269 1267 - add_disk_randomness(rq->rq_disk); 1270 + if (blk_end_request(rq, (rq->errors == 0) ? 0 : -EIO, blk_rq_bytes(rq))) 1271 + BUG(); 1272 + 1268 1273 spin_lock_irqsave(&h->lock, flags); 1269 - end_that_request_last(rq, (rq->errors == 0)); 1270 1274 cmd_free(h, cmd, 1); 1271 1275 cciss_check_queues(h); 1272 1276 spin_unlock_irqrestore(&h->lock, flags); ··· 2526 2544 } 2527 2545 cmd->rq->data_len = 0; 2528 2546 cmd->rq->completion_data = cmd; 2529 - blk_add_trace_rq(cmd->rq->q, cmd->rq, BLK_TA_COMPLETE); 2530 2547 blk_complete_request(cmd->rq); 2531 2548 } 2532 2549
+7 -29
drivers/block/cpqarray.c
··· 167 167 168 168 static inline void addQ(cmdlist_t **Qptr, cmdlist_t *c); 169 169 static inline cmdlist_t *removeQ(cmdlist_t **Qptr, cmdlist_t *c); 170 - static inline void complete_buffers(struct bio *bio, int ok); 171 170 static inline void complete_command(cmdlist_t *cmd, int timeout); 172 171 173 172 static irqreturn_t do_ida_intr(int irq, void *dev_id); ··· 979 980 } 980 981 } 981 982 982 - static inline void complete_buffers(struct bio *bio, int ok) 983 - { 984 - struct bio *xbh; 985 - 986 - while (bio) { 987 - xbh = bio->bi_next; 988 - bio->bi_next = NULL; 989 - 990 - bio_endio(bio, ok ? 0 : -EIO); 991 - 992 - bio = xbh; 993 - } 994 - } 995 983 /* 996 984 * Mark all buffers that cmd was responsible for 997 985 */ 998 986 static inline void complete_command(cmdlist_t *cmd, int timeout) 999 987 { 1000 988 struct request *rq = cmd->rq; 1001 - int ok=1; 989 + int error = 0; 1002 990 int i, ddir; 1003 991 1004 992 if (cmd->req.hdr.rcode & RCODE_NONFATAL && ··· 997 1011 if (cmd->req.hdr.rcode & RCODE_FATAL) { 998 1012 printk(KERN_WARNING "Fatal error on ida/c%dd%d\n", 999 1013 cmd->ctlr, cmd->hdr.unit); 1000 - ok = 0; 1014 + error = -EIO; 1001 1015 } 1002 1016 if (cmd->req.hdr.rcode & RCODE_INVREQ) { 1003 1017 printk(KERN_WARNING "Invalid request on ida/c%dd%d = (cmd=%x sect=%d cnt=%d sg=%d ret=%x)\n", 1004 1018 cmd->ctlr, cmd->hdr.unit, cmd->req.hdr.cmd, 1005 1019 cmd->req.hdr.blk, cmd->req.hdr.blk_cnt, 1006 1020 cmd->req.hdr.sg_cnt, cmd->req.hdr.rcode); 1007 - ok = 0; 1021 + error = -EIO; 1008 1022 } 1009 - if (timeout) ok = 0; 1023 + if (timeout) 1024 + error = -EIO; 1010 1025 /* unmap the DMA mapping for all the scatter gather elements */ 1011 1026 if (cmd->req.hdr.cmd == IDA_READ) 1012 1027 ddir = PCI_DMA_FROMDEVICE; ··· 1017 1030 pci_unmap_page(hba[cmd->ctlr]->pci_dev, cmd->req.sg[i].addr, 1018 1031 cmd->req.sg[i].size, ddir); 1019 1032 1020 - complete_buffers(rq->bio, ok); 1021 - 1022 - if (blk_fs_request(rq)) { 1023 - const int rw = rq_data_dir(rq); 1024 - 1025 - disk_stat_add(rq->rq_disk, sectors[rw], rq->nr_sectors); 1026 - } 1027 - 1028 - add_disk_randomness(rq->rq_disk); 1029 - 1030 1033 DBGPX(printk("Done with %p\n", rq);); 1031 - end_that_request_last(rq, ok ? 1 : -EIO); 1034 + if (__blk_end_request(rq, error, blk_rq_bytes(rq))) 1035 + BUG(); 1032 1036 } 1033 1037 1034 1038 /*
+7 -9
drivers/block/floppy.c
··· 2287 2287 * ============================= 2288 2288 */ 2289 2289 2290 - static void floppy_end_request(struct request *req, int uptodate) 2290 + static void floppy_end_request(struct request *req, int error) 2291 2291 { 2292 2292 unsigned int nr_sectors = current_count_sectors; 2293 + unsigned int drive = (unsigned long)req->rq_disk->private_data; 2293 2294 2294 2295 /* current_count_sectors can be zero if transfer failed */ 2295 - if (!uptodate) 2296 + if (error) 2296 2297 nr_sectors = req->current_nr_sectors; 2297 - if (end_that_request_first(req, uptodate, nr_sectors)) 2298 + if (__blk_end_request(req, error, nr_sectors << 9)) 2298 2299 return; 2299 - add_disk_randomness(req->rq_disk); 2300 - floppy_off((long)req->rq_disk->private_data); 2301 - blkdev_dequeue_request(req); 2302 - end_that_request_last(req, uptodate); 2303 2300 2304 2301 /* We're done with the request */ 2302 + floppy_off(drive); 2305 2303 current_req = NULL; 2306 2304 } 2307 2305 ··· 2330 2332 2331 2333 /* unlock chained buffers */ 2332 2334 spin_lock_irqsave(q->queue_lock, flags); 2333 - floppy_end_request(req, 1); 2335 + floppy_end_request(req, 0); 2334 2336 spin_unlock_irqrestore(q->queue_lock, flags); 2335 2337 } else { 2336 2338 if (rq_data_dir(req) == WRITE) { ··· 2344 2346 DRWE->last_error_generation = DRS->generation; 2345 2347 } 2346 2348 spin_lock_irqsave(q->queue_lock, flags); 2347 - floppy_end_request(req, 0); 2349 + floppy_end_request(req, -EIO); 2348 2350 spin_unlock_irqrestore(q->queue_lock, flags); 2349 2351 } 2350 2352 }
+3 -5
drivers/block/nbd.c
··· 100 100 101 101 static void nbd_end_request(struct request *req) 102 102 { 103 - int uptodate = (req->errors == 0) ? 1 : 0; 103 + int error = req->errors ? -EIO : 0; 104 104 struct request_queue *q = req->q; 105 105 unsigned long flags; 106 106 107 107 dprintk(DBG_BLKDEV, "%s: request %p: %s\n", req->rq_disk->disk_name, 108 - req, uptodate? "done": "failed"); 108 + req, error ? "failed" : "done"); 109 109 110 110 spin_lock_irqsave(q->queue_lock, flags); 111 - if (!end_that_request_first(req, uptodate, req->nr_sectors)) { 112 - end_that_request_last(req, uptodate); 113 - } 111 + __blk_end_request(req, error, req->nr_sectors << 9); 114 112 spin_unlock_irqrestore(q->queue_lock, flags); 115 113 } 116 114
+4 -8
drivers/block/ps3disk.c
··· 229 229 struct ps3_storage_device *dev = data; 230 230 struct ps3disk_private *priv; 231 231 struct request *req; 232 - int res, read, uptodate; 232 + int res, read, error; 233 233 u64 tag, status; 234 234 unsigned long num_sectors; 235 235 const char *op; ··· 270 270 if (status) { 271 271 dev_dbg(&dev->sbd.core, "%s:%u: %s failed 0x%lx\n", __func__, 272 272 __LINE__, op, status); 273 - uptodate = 0; 273 + error = -EIO; 274 274 } else { 275 275 dev_dbg(&dev->sbd.core, "%s:%u: %s completed\n", __func__, 276 276 __LINE__, op); 277 - uptodate = 1; 277 + error = 0; 278 278 if (read) 279 279 ps3disk_scatter_gather(dev, req, 0); 280 280 } 281 281 282 282 spin_lock(&priv->lock); 283 - if (!end_that_request_first(req, uptodate, num_sectors)) { 284 - add_disk_randomness(req->rq_disk); 285 - blkdev_dequeue_request(req); 286 - end_that_request_last(req, uptodate); 287 - } 283 + __blk_end_request(req, error, num_sectors << 9); 288 284 priv->req = NULL; 289 285 ps3disk_do_request(dev, priv->queue); 290 286 spin_unlock(&priv->lock);
+4 -7
drivers/block/sunvdc.c
··· 212 212 vdc_finish(&port->vio, -err, WAITING_FOR_GEN_CMD); 213 213 } 214 214 215 - static void vdc_end_request(struct request *req, int uptodate, int num_sectors) 215 + static void vdc_end_request(struct request *req, int error, int num_sectors) 216 216 { 217 - if (end_that_request_first(req, uptodate, num_sectors)) 218 - return; 219 - add_disk_randomness(req->rq_disk); 220 - end_that_request_last(req, uptodate); 217 + __blk_end_request(req, error, num_sectors << 9); 221 218 } 222 219 223 220 static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr, ··· 239 242 240 243 rqe->req = NULL; 241 244 242 - vdc_end_request(req, !desc->status, desc->size >> 9); 245 + vdc_end_request(req, (desc->status ? -EIO : 0), desc->size >> 9); 243 246 244 247 if (blk_queue_stopped(port->disk->queue)) 245 248 blk_start_queue(port->disk->queue); ··· 453 456 454 457 blkdev_dequeue_request(req); 455 458 if (__send_request(req) < 0) 456 - vdc_end_request(req, 0, req->hard_nr_sectors); 459 + vdc_end_request(req, -EIO, req->hard_nr_sectors); 457 460 } 458 461 } 459 462
+28 -30
drivers/block/sx8.c
··· 744 744 745 745 static inline void carm_end_request_queued(struct carm_host *host, 746 746 struct carm_request *crq, 747 - int uptodate) 747 + int error) 748 748 { 749 749 struct request *req = crq->rq; 750 750 int rc; 751 751 752 - rc = end_that_request_first(req, uptodate, req->hard_nr_sectors); 752 + rc = __blk_end_request(req, error, blk_rq_bytes(req)); 753 753 assert(rc == 0); 754 - 755 - end_that_request_last(req, uptodate); 756 754 757 755 rc = carm_put_request(host, crq); 758 756 assert(rc == 0); ··· 791 793 } 792 794 793 795 static inline void carm_end_rq(struct carm_host *host, struct carm_request *crq, 794 - int is_ok) 796 + int error) 795 797 { 796 - carm_end_request_queued(host, crq, is_ok); 798 + carm_end_request_queued(host, crq, error); 797 799 if (max_queue == 1) 798 800 carm_round_robin(host); 799 801 else if ((host->n_msgs <= CARM_MSG_LOW_WATER) && ··· 871 873 sg = &crq->sg[0]; 872 874 n_elem = blk_rq_map_sg(q, rq, sg); 873 875 if (n_elem <= 0) { 874 - carm_end_rq(host, crq, 0); 876 + carm_end_rq(host, crq, -EIO); 875 877 return; /* request with no s/g entries? */ 876 878 } 877 879 878 880 /* map scatterlist to PCI bus addresses */ 879 881 n_elem = pci_map_sg(host->pdev, sg, n_elem, pci_dir); 880 882 if (n_elem <= 0) { 881 - carm_end_rq(host, crq, 0); 883 + carm_end_rq(host, crq, -EIO); 882 884 return; /* request with no s/g entries? */ 883 885 } 884 886 crq->n_elem = n_elem; ··· 939 941 940 942 static void carm_handle_array_info(struct carm_host *host, 941 943 struct carm_request *crq, u8 *mem, 942 - int is_ok) 944 + int error) 943 945 { 944 946 struct carm_port *port; 945 947 u8 *msg_data = mem + sizeof(struct carm_array_info); ··· 950 952 951 953 DPRINTK("ENTER\n"); 952 954 953 - carm_end_rq(host, crq, is_ok); 955 + carm_end_rq(host, crq, error); 954 956 955 - if (!is_ok) 957 + if (error) 956 958 goto out; 957 959 if (le32_to_cpu(desc->array_status) & ARRAY_NO_EXIST) 958 960 goto out; ··· 999 1001 1000 1002 static void carm_handle_scan_chan(struct carm_host *host, 1001 1003 struct carm_request *crq, u8 *mem, 1002 - int is_ok) 1004 + int error) 1003 1005 { 1004 1006 u8 *msg_data = mem + IOC_SCAN_CHAN_OFFSET; 1005 1007 unsigned int i, dev_count = 0; ··· 1007 1009 1008 1010 DPRINTK("ENTER\n"); 1009 1011 1010 - carm_end_rq(host, crq, is_ok); 1012 + carm_end_rq(host, crq, error); 1011 1013 1012 - if (!is_ok) { 1014 + if (error) { 1013 1015 new_state = HST_ERROR; 1014 1016 goto out; 1015 1017 } ··· 1031 1033 } 1032 1034 1033 1035 static void carm_handle_generic(struct carm_host *host, 1034 - struct carm_request *crq, int is_ok, 1036 + struct carm_request *crq, int error, 1035 1037 int cur_state, int next_state) 1036 1038 { 1037 1039 DPRINTK("ENTER\n"); 1038 1040 1039 - carm_end_rq(host, crq, is_ok); 1041 + carm_end_rq(host, crq, error); 1040 1042 1041 1043 assert(host->state == cur_state); 1042 - if (is_ok) 1043 - host->state = next_state; 1044 - else 1044 + if (error) 1045 1045 host->state = HST_ERROR; 1046 + else 1047 + host->state = next_state; 1046 1048 schedule_work(&host->fsm_task); 1047 1049 } 1048 1050 1049 1051 static inline void carm_handle_rw(struct carm_host *host, 1050 - struct carm_request *crq, int is_ok) 1052 + struct carm_request *crq, int error) 1051 1053 { 1052 1054 int pci_dir; 1053 1055 ··· 1060 1062 1061 1063 pci_unmap_sg(host->pdev, &crq->sg[0], crq->n_elem, pci_dir); 1062 1064 1063 - carm_end_rq(host, crq, is_ok); 1065 + carm_end_rq(host, crq, error); 1064 1066 } 1065 1067 1066 1068 static inline void carm_handle_resp(struct carm_host *host, ··· 1069 1071 u32 handle = le32_to_cpu(ret_handle_le); 1070 1072 unsigned int msg_idx; 1071 1073 struct carm_request *crq; 1072 - int is_ok = (status == RMSG_OK); 1074 + int error = (status == RMSG_OK) ? 0 : -EIO; 1073 1075 u8 *mem; 1074 1076 1075 1077 VPRINTK("ENTER, handle == 0x%x\n", handle); ··· 1088 1090 /* fast path */ 1089 1091 if (likely(crq->msg_type == CARM_MSG_READ || 1090 1092 crq->msg_type == CARM_MSG_WRITE)) { 1091 - carm_handle_rw(host, crq, is_ok); 1093 + carm_handle_rw(host, crq, error); 1092 1094 return; 1093 1095 } 1094 1096 ··· 1098 1100 case CARM_MSG_IOCTL: { 1099 1101 switch (crq->msg_subtype) { 1100 1102 case CARM_IOC_SCAN_CHAN: 1101 - carm_handle_scan_chan(host, crq, mem, is_ok); 1103 + carm_handle_scan_chan(host, crq, mem, error); 1102 1104 break; 1103 1105 default: 1104 1106 /* unknown / invalid response */ ··· 1110 1112 case CARM_MSG_MISC: { 1111 1113 switch (crq->msg_subtype) { 1112 1114 case MISC_ALLOC_MEM: 1113 - carm_handle_generic(host, crq, is_ok, 1115 + carm_handle_generic(host, crq, error, 1114 1116 HST_ALLOC_BUF, HST_SYNC_TIME); 1115 1117 break; 1116 1118 case MISC_SET_TIME: 1117 - carm_handle_generic(host, crq, is_ok, 1119 + carm_handle_generic(host, crq, error, 1118 1120 HST_SYNC_TIME, HST_GET_FW_VER); 1119 1121 break; 1120 1122 case MISC_GET_FW_VER: { 1121 1123 struct carm_fw_ver *ver = (struct carm_fw_ver *) 1122 1124 mem + sizeof(struct carm_msg_get_fw_ver); 1123 - if (is_ok) { 1125 + if (!error) { 1124 1126 host->fw_ver = le32_to_cpu(ver->version); 1125 1127 host->flags |= (ver->features & FL_FW_VER_MASK); 1126 1128 } 1127 - carm_handle_generic(host, crq, is_ok, 1129 + carm_handle_generic(host, crq, error, 1128 1130 HST_GET_FW_VER, HST_PORT_SCAN); 1129 1131 break; 1130 1132 } ··· 1138 1140 case CARM_MSG_ARRAY: { 1139 1141 switch (crq->msg_subtype) { 1140 1142 case CARM_ARRAY_INFO: 1141 - carm_handle_array_info(host, crq, mem, is_ok); 1143 + carm_handle_array_info(host, crq, mem, error); 1142 1144 break; 1143 1145 default: 1144 1146 /* unknown / invalid response */ ··· 1157 1159 err_out: 1158 1160 printk(KERN_WARNING DRV_NAME "(%s): BUG: unhandled message type %d/%d\n", 1159 1161 pci_name(host->pdev), crq->msg_type, crq->msg_subtype); 1160 - carm_end_rq(host, crq, 0); 1162 + carm_end_rq(host, crq, -EIO); 1161 1163 } 1162 1164 1163 1165 static inline void carm_handle_responses(struct carm_host *host)
+5 -5
drivers/block/ub.c
··· 808 808 809 809 static void ub_end_rq(struct request *rq, unsigned int scsi_status) 810 810 { 811 - int uptodate; 811 + int error; 812 812 813 813 if (scsi_status == 0) { 814 - uptodate = 1; 814 + error = 0; 815 815 } else { 816 - uptodate = 0; 816 + error = -EIO; 817 817 rq->errors = scsi_status; 818 818 } 819 - end_that_request_first(rq, uptodate, rq->hard_nr_sectors); 820 - end_that_request_last(rq, uptodate); 819 + if (__blk_end_request(rq, error, blk_rq_bytes(rq))) 820 + BUG(); 821 821 } 822 822 823 823 static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun,
+6 -9
drivers/block/viodasd.c
··· 229 229 /* 230 230 * End a request 231 231 */ 232 - static void viodasd_end_request(struct request *req, int uptodate, 232 + static void viodasd_end_request(struct request *req, int error, 233 233 int num_sectors) 234 234 { 235 - if (end_that_request_first(req, uptodate, num_sectors)) 236 - return; 237 - add_disk_randomness(req->rq_disk); 238 - end_that_request_last(req, uptodate); 235 + __blk_end_request(req, error, num_sectors << 9); 239 236 } 240 237 241 238 /* ··· 371 374 blkdev_dequeue_request(req); 372 375 /* check that request contains a valid command */ 373 376 if (!blk_fs_request(req)) { 374 - viodasd_end_request(req, 0, req->hard_nr_sectors); 377 + viodasd_end_request(req, -EIO, req->hard_nr_sectors); 375 378 continue; 376 379 } 377 380 /* Try sending the request */ 378 381 if (send_request(req) != 0) 379 - viodasd_end_request(req, 0, req->hard_nr_sectors); 382 + viodasd_end_request(req, -EIO, req->hard_nr_sectors); 380 383 } 381 384 } 382 385 ··· 588 591 num_req_outstanding--; 589 592 spin_unlock_irqrestore(&viodasd_spinlock, irq_flags); 590 593 591 - error = event->xRc != HvLpEvent_Rc_Good; 594 + error = (event->xRc == HvLpEvent_Rc_Good) ? 0 : -EIO; 592 595 if (error) { 593 596 const struct vio_error_entry *err; 594 597 err = vio_lookup_rc(viodasd_err_table, bevent->sub_result); ··· 598 601 } 599 602 qlock = req->q->queue_lock; 600 603 spin_lock_irqsave(qlock, irq_flags); 601 - viodasd_end_request(req, !error, num_sect); 604 + viodasd_end_request(req, error, num_sect); 602 605 spin_unlock_irqrestore(qlock, irq_flags); 603 606 604 607 /* Finally, try to get more requests off of this device's queue */
+4 -6
drivers/block/xen-blkfront.c
··· 452 452 RING_IDX i, rp; 453 453 unsigned long flags; 454 454 struct blkfront_info *info = (struct blkfront_info *)dev_id; 455 - int uptodate; 455 + int error; 456 456 457 457 spin_lock_irqsave(&blkif_io_lock, flags); 458 458 ··· 477 477 478 478 add_id_to_freelist(info, id); 479 479 480 - uptodate = (bret->status == BLKIF_RSP_OKAY); 480 + error = (bret->status == BLKIF_RSP_OKAY) ? 0 : -EIO; 481 481 switch (bret->operation) { 482 482 case BLKIF_OP_WRITE_BARRIER: 483 483 if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) { 484 484 printk(KERN_WARNING "blkfront: %s: write barrier op failed\n", 485 485 info->gd->disk_name); 486 - uptodate = -EOPNOTSUPP; 486 + error = -EOPNOTSUPP; 487 487 info->feature_barrier = 0; 488 488 xlvbd_barrier(info); 489 489 } ··· 494 494 dev_dbg(&info->xbdev->dev, "Bad return from blkdev data " 495 495 "request: %x\n", bret->status); 496 496 497 - ret = end_that_request_first(req, uptodate, 498 - req->hard_nr_sectors); 497 + ret = __blk_end_request(req, error, blk_rq_bytes(req)); 499 498 BUG_ON(ret); 500 - end_that_request_last(req, uptodate); 501 499 break; 502 500 default: 503 501 BUG();
+1 -4
drivers/block/xsysace.c
··· 703 703 704 704 /* bio finished; is there another one? */ 705 705 i = ace->req->current_nr_sectors; 706 - if (end_that_request_first(ace->req, 1, i)) { 706 + if (__blk_end_request(ace->req, 0, i)) { 707 707 /* dev_dbg(ace->dev, "next block; h=%li c=%i\n", 708 708 * ace->req->hard_nr_sectors, 709 709 * ace->req->current_nr_sectors); ··· 718 718 break; 719 719 720 720 case ACE_FSM_STATE_REQ_COMPLETE: 721 - /* Complete the block request */ 722 - blkdev_dequeue_request(ace->req); 723 - end_that_request_last(ace->req, 1); 724 721 ace->req = NULL; 725 722 726 723 /* Finished request; go to idle state */
+6 -9
drivers/cdrom/viocd.c
··· 289 289 return 0; 290 290 } 291 291 292 - static void viocd_end_request(struct request *req, int uptodate) 292 + static void viocd_end_request(struct request *req, int error) 293 293 { 294 294 int nsectors = req->hard_nr_sectors; 295 295 ··· 302 302 if (!nsectors) 303 303 nsectors = 1; 304 304 305 - if (end_that_request_first(req, uptodate, nsectors)) 305 + if (__blk_end_request(req, error, nsectors << 9)) 306 306 BUG(); 307 - add_disk_randomness(req->rq_disk); 308 - blkdev_dequeue_request(req); 309 - end_that_request_last(req, uptodate); 310 307 } 311 308 312 309 static int rwreq; ··· 314 317 315 318 while ((rwreq == 0) && ((req = elv_next_request(q)) != NULL)) { 316 319 if (!blk_fs_request(req)) 317 - viocd_end_request(req, 0); 320 + viocd_end_request(req, -EIO); 318 321 else if (send_request(req) < 0) { 319 322 printk(VIOCD_KERN_WARNING 320 323 "unable to send message to OS/400!"); 321 - viocd_end_request(req, 0); 324 + viocd_end_request(req, -EIO); 322 325 } else 323 326 rwreq++; 324 327 } ··· 529 532 "with rc %d:0x%04X: %s\n", 530 533 req, event->xRc, 531 534 bevent->sub_result, err->msg); 532 - viocd_end_request(req, 0); 535 + viocd_end_request(req, -EIO); 533 536 } else 534 - viocd_end_request(req, 1); 537 + viocd_end_request(req, 0); 535 538 536 539 /* restart handling of incoming requests */ 537 540 spin_unlock_irqrestore(&viocd_reqlock, flags);
+38 -17
drivers/ide/ide-cd.c
··· 655 655 BUG(); 656 656 } else { 657 657 spin_lock_irqsave(&ide_lock, flags); 658 - end_that_request_chunk(failed, 0, 659 - failed->data_len); 660 - end_that_request_last(failed, 0); 658 + if (__blk_end_request(failed, -EIO, 659 + failed->data_len)) 660 + BUG(); 661 661 spin_unlock_irqrestore(&ide_lock, flags); 662 662 } 663 663 } else ··· 1647 1647 return 1; 1648 1648 } 1649 1649 1650 + /* 1651 + * Called from blk_end_request_callback() after the data of the request 1652 + * is completed and before the request is completed. 1653 + * By returning value '1', blk_end_request_callback() returns immediately 1654 + * without completing the request. 1655 + */ 1656 + static int cdrom_newpc_intr_dummy_cb(struct request *rq) 1657 + { 1658 + return 1; 1659 + } 1660 + 1650 1661 typedef void (xfer_func_t)(ide_drive_t *, void *, u32); 1651 1662 1652 1663 /* ··· 1696 1685 return ide_error(drive, "dma error", stat); 1697 1686 } 1698 1687 1699 - end_that_request_chunk(rq, 1, rq->data_len); 1700 - rq->data_len = 0; 1701 - goto end_request; 1688 + spin_lock_irqsave(&ide_lock, flags); 1689 + if (__blk_end_request(rq, 0, rq->data_len)) 1690 + BUG(); 1691 + HWGROUP(drive)->rq = NULL; 1692 + spin_unlock_irqrestore(&ide_lock, flags); 1693 + 1694 + return ide_stopped; 1702 1695 } 1703 1696 1704 1697 /* ··· 1720 1705 /* 1721 1706 * If DRQ is clear, the command has completed. 1722 1707 */ 1723 - if ((stat & DRQ_STAT) == 0) 1724 - goto end_request; 1708 + if ((stat & DRQ_STAT) == 0) { 1709 + spin_lock_irqsave(&ide_lock, flags); 1710 + if (__blk_end_request(rq, 0, 0)) 1711 + BUG(); 1712 + HWGROUP(drive)->rq = NULL; 1713 + spin_unlock_irqrestore(&ide_lock, flags); 1714 + 1715 + return ide_stopped; 1716 + } 1725 1717 1726 1718 /* 1727 1719 * check which way to transfer data ··· 1781 1759 rq->data_len -= blen; 1782 1760 1783 1761 if (rq->bio) 1784 - end_that_request_chunk(rq, 1, blen); 1762 + /* 1763 + * The request can't be completed until DRQ is cleared. 1764 + * So complete the data, but don't complete the request 1765 + * using the dummy function for the callback feature 1766 + * of blk_end_request_callback(). 1767 + */ 1768 + blk_end_request_callback(rq, 0, blen, 1769 + cdrom_newpc_intr_dummy_cb); 1785 1770 else 1786 1771 rq->data += blen; 1787 1772 } ··· 1809 1780 1810 1781 ide_set_handler(drive, cdrom_newpc_intr, rq->timeout, NULL); 1811 1782 return ide_started; 1812 - 1813 - end_request: 1814 - spin_lock_irqsave(&ide_lock, flags); 1815 - blkdev_dequeue_request(rq); 1816 - end_that_request_last(rq, 1); 1817 - HWGROUP(drive)->rq = NULL; 1818 - spin_unlock_irqrestore(&ide_lock, flags); 1819 - return ide_stopped; 1820 1783 } 1821 1784 1822 1785 static ide_startstop_t cdrom_write_intr(ide_drive_t *drive)
+12 -13
drivers/ide/ide-io.c
··· 58 58 int uptodate, unsigned int nr_bytes, int dequeue) 59 59 { 60 60 int ret = 1; 61 + int error = 0; 62 + 63 + if (uptodate <= 0) 64 + error = uptodate ? uptodate : -EIO; 61 65 62 66 /* 63 67 * if failfast is set on a request, override number of sectors and 64 68 * complete the whole request right now 65 69 */ 66 - if (blk_noretry_request(rq) && end_io_error(uptodate)) 70 + if (blk_noretry_request(rq) && error) 67 71 nr_bytes = rq->hard_nr_sectors << 9; 68 72 69 - if (!blk_fs_request(rq) && end_io_error(uptodate) && !rq->errors) 73 + if (!blk_fs_request(rq) && error && !rq->errors) 70 74 rq->errors = -EIO; 71 75 72 76 /* ··· 82 78 ide_dma_on(drive); 83 79 } 84 80 85 - if (!end_that_request_chunk(rq, uptodate, nr_bytes)) { 86 - add_disk_randomness(rq->rq_disk); 87 - if (dequeue) { 88 - if (!list_empty(&rq->queuelist)) 89 - blkdev_dequeue_request(rq); 81 + if (!__blk_end_request(rq, error, nr_bytes)) { 82 + if (dequeue) 90 83 HWGROUP(drive)->rq = NULL; 91 - } 92 - end_that_request_last(rq, uptodate); 93 84 ret = 0; 94 85 } 95 86 ··· 289 290 drive->blocked = 0; 290 291 blk_start_queue(drive->queue); 291 292 } 292 - blkdev_dequeue_request(rq); 293 293 HWGROUP(drive)->rq = NULL; 294 - end_that_request_last(rq, 1); 294 + if (__blk_end_request(rq, 0, 0)) 295 + BUG(); 295 296 spin_unlock_irqrestore(&ide_lock, flags); 296 297 } 297 298 ··· 386 387 } 387 388 388 389 spin_lock_irqsave(&ide_lock, flags); 389 - blkdev_dequeue_request(rq); 390 390 HWGROUP(drive)->rq = NULL; 391 391 rq->errors = err; 392 - end_that_request_last(rq, !rq->errors); 392 + if (__blk_end_request(rq, (rq->errors ? -EIO : 0), 0)) 393 + BUG(); 393 394 spin_unlock_irqrestore(&ide_lock, flags); 394 395 } 395 396
+8 -12
drivers/message/i2o/i2o_block.c
··· 412 412 /** 413 413 * i2o_block_end_request - Post-processing of completed commands 414 414 * @req: request which should be completed 415 - * @uptodate: 1 for success, 0 for I/O error, < 0 for specific error 415 + * @error: 0 for success, < 0 for error 416 416 * @nr_bytes: number of bytes to complete 417 417 * 418 418 * Mark the request as complete. The lock must not be held when entering. 419 419 * 420 420 */ 421 - static void i2o_block_end_request(struct request *req, int uptodate, 421 + static void i2o_block_end_request(struct request *req, int error, 422 422 int nr_bytes) 423 423 { 424 424 struct i2o_block_request *ireq = req->special; ··· 426 426 struct request_queue *q = req->q; 427 427 unsigned long flags; 428 428 429 - if (end_that_request_chunk(req, uptodate, nr_bytes)) { 429 + if (blk_end_request(req, error, nr_bytes)) { 430 430 int leftover = (req->hard_nr_sectors << KERNEL_SECTOR_SHIFT); 431 431 432 432 if (blk_pc_request(req)) 433 433 leftover = req->data_len; 434 434 435 - if (end_io_error(uptodate)) 436 - end_that_request_chunk(req, 0, leftover); 435 + if (error) 436 + blk_end_request(req, -EIO, leftover); 437 437 } 438 438 439 - add_disk_randomness(req->rq_disk); 440 - 441 439 spin_lock_irqsave(q->queue_lock, flags); 442 - 443 - end_that_request_last(req, uptodate); 444 440 445 441 if (likely(dev)) { 446 442 dev->open_queue_depth--; ··· 464 468 struct i2o_message *msg) 465 469 { 466 470 struct request *req; 467 - int uptodate = 1; 471 + int error = 0; 468 472 469 473 req = i2o_cntxt_list_get(c, le32_to_cpu(msg->u.s.tcntxt)); 470 474 if (unlikely(!req)) { ··· 497 501 498 502 req->errors++; 499 503 500 - uptodate = 0; 504 + error = -EIO; 501 505 } 502 506 503 - i2o_block_end_request(req, uptodate, le32_to_cpu(msg->body[1])); 507 + i2o_block_end_request(req, error, le32_to_cpu(msg->body[1])); 504 508 505 509 return 1; 506 510 };
+5 -19
drivers/mmc/card/block.c
··· 348 348 * A block was successfully transferred. 349 349 */ 350 350 spin_lock_irq(&md->lock); 351 - ret = end_that_request_chunk(req, 1, brq.data.bytes_xfered); 352 - if (!ret) { 353 - /* 354 - * The whole request completed successfully. 355 - */ 356 - add_disk_randomness(req->rq_disk); 357 - blkdev_dequeue_request(req); 358 - end_that_request_last(req, 1); 359 - } 351 + ret = __blk_end_request(req, 0, brq.data.bytes_xfered); 360 352 spin_unlock_irq(&md->lock); 361 353 } while (ret); 362 354 ··· 378 386 else 379 387 bytes = blocks << 9; 380 388 spin_lock_irq(&md->lock); 381 - ret = end_that_request_chunk(req, 1, bytes); 389 + ret = __blk_end_request(req, 0, bytes); 382 390 spin_unlock_irq(&md->lock); 383 391 } 384 392 } else if (rq_data_dir(req) != READ && 385 393 (card->host->caps & MMC_CAP_MULTIWRITE)) { 386 394 spin_lock_irq(&md->lock); 387 - ret = end_that_request_chunk(req, 1, brq.data.bytes_xfered); 395 + ret = __blk_end_request(req, 0, brq.data.bytes_xfered); 388 396 spin_unlock_irq(&md->lock); 389 397 } 390 398 391 399 mmc_release_host(card->host); 392 400 393 401 spin_lock_irq(&md->lock); 394 - while (ret) { 395 - ret = end_that_request_chunk(req, 0, 396 - req->current_nr_sectors << 9); 397 - } 398 - 399 - add_disk_randomness(req->rq_disk); 400 - blkdev_dequeue_request(req); 401 - end_that_request_last(req, 0); 402 + while (ret) 403 + ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req)); 402 404 spin_unlock_irq(&md->lock); 403 405 404 406 return 0;
+2 -2
drivers/mmc/card/queue.c
··· 94 94 printk(KERN_ERR "MMC: killing requests for dead queue\n"); 95 95 while ((req = elv_next_request(q)) != NULL) { 96 96 do { 97 - ret = end_that_request_chunk(req, 0, 98 - req->current_nr_sectors << 9); 97 + ret = __blk_end_request(req, -EIO, 98 + blk_rq_cur_bytes(req)); 99 99 } while (ret); 100 100 } 101 101 return;
+9 -8
drivers/s390/block/dasd.c
··· 1595 1595 /* 1596 1596 * posts the buffer_cache about a finalized request 1597 1597 */ 1598 - static inline void dasd_end_request(struct request *req, int uptodate) 1598 + static inline void dasd_end_request(struct request *req, int error) 1599 1599 { 1600 - if (end_that_request_first(req, uptodate, req->hard_nr_sectors)) 1600 + if (__blk_end_request(req, error, blk_rq_bytes(req))) 1601 1601 BUG(); 1602 - add_disk_randomness(req->rq_disk); 1603 - end_that_request_last(req, uptodate); 1604 1602 } 1605 1603 1606 1604 /* ··· 1655 1657 "Rejecting write request %p", 1656 1658 req); 1657 1659 blkdev_dequeue_request(req); 1658 - dasd_end_request(req, 0); 1660 + dasd_end_request(req, -EIO); 1659 1661 continue; 1660 1662 } 1661 1663 cqr = basedev->discipline->build_cp(basedev, block, req); ··· 1684 1686 "on request %p", 1685 1687 PTR_ERR(cqr), req); 1686 1688 blkdev_dequeue_request(req); 1687 - dasd_end_request(req, 0); 1689 + dasd_end_request(req, -EIO); 1688 1690 continue; 1689 1691 } 1690 1692 /* ··· 1703 1705 { 1704 1706 struct request *req; 1705 1707 int status; 1708 + int error = 0; 1706 1709 1707 1710 req = (struct request *) cqr->callback_data; 1708 1711 dasd_profile_end(cqr->block, cqr, req); 1709 1712 status = cqr->memdev->discipline->free_cp(cqr, req); 1710 - dasd_end_request(req, status); 1713 + if (status <= 0) 1714 + error = status ? status : -EIO; 1715 + dasd_end_request(req, error); 1711 1716 } 1712 1717 1713 1718 /* ··· 2010 2009 spin_lock_irq(&block->request_queue_lock); 2011 2010 while ((req = elv_next_request(block->request_queue))) { 2012 2011 blkdev_dequeue_request(req); 2013 - dasd_end_request(req, 0); 2012 + dasd_end_request(req, -EIO); 2014 2013 } 2015 2014 spin_unlock_irq(&block->request_queue_lock); 2016 2015 }
+6 -7
drivers/s390/char/tape_block.c
··· 74 74 * Post finished request. 75 75 */ 76 76 static void 77 - tapeblock_end_request(struct request *req, int uptodate) 77 + tapeblock_end_request(struct request *req, int error) 78 78 { 79 - if (end_that_request_first(req, uptodate, req->hard_nr_sectors)) 79 + if (__blk_end_request(req, error, blk_rq_bytes(req))) 80 80 BUG(); 81 - end_that_request_last(req, uptodate); 82 81 } 83 82 84 83 static void ··· 90 91 91 92 device = ccw_req->device; 92 93 req = (struct request *) data; 93 - tapeblock_end_request(req, ccw_req->rc == 0); 94 + tapeblock_end_request(req, (ccw_req->rc == 0) ? 0 : -EIO); 94 95 if (ccw_req->rc == 0) 95 96 /* Update position. */ 96 97 device->blk_data.block_position = ··· 118 119 ccw_req = device->discipline->bread(device, req); 119 120 if (IS_ERR(ccw_req)) { 120 121 DBF_EVENT(1, "TBLOCK: bread failed\n"); 121 - tapeblock_end_request(req, 0); 122 + tapeblock_end_request(req, -EIO); 122 123 return PTR_ERR(ccw_req); 123 124 } 124 125 ccw_req->callback = __tapeblock_end_request; ··· 131 132 * Start/enqueueing failed. No retries in 132 133 * this case. 133 134 */ 134 - tapeblock_end_request(req, 0); 135 + tapeblock_end_request(req, -EIO); 135 136 device->discipline->free_bread(ccw_req); 136 137 } 137 138 ··· 176 177 if (rq_data_dir(req) == WRITE) { 177 178 DBF_EVENT(1, "TBLOCK: Rejecting write request\n"); 178 179 blkdev_dequeue_request(req); 179 - tapeblock_end_request(req, 0); 180 + tapeblock_end_request(req, -EIO); 180 181 continue; 181 182 } 182 183 spin_unlock_irq(&device->blk_data.request_queue_lock);
+4 -4
drivers/scsi/ide-scsi.c
··· 919 919 } 920 920 921 921 /* kill current request */ 922 - blkdev_dequeue_request(req); 923 - end_that_request_last(req, 0); 922 + if (__blk_end_request(req, -EIO, 0)) 923 + BUG(); 924 924 if (blk_sense_request(req)) 925 925 kfree(scsi->pc->buffer); 926 926 kfree(scsi->pc); ··· 929 929 930 930 /* now nuke the drive queue */ 931 931 while ((req = elv_next_request(drive->queue))) { 932 - blkdev_dequeue_request(req); 933 - end_that_request_last(req, 0); 932 + if (__blk_end_request(req, -EIO, 0)) 933 + BUG(); 934 934 } 935 935 936 936 HWGROUP(drive)->rq = NULL;
+11 -20
drivers/scsi/scsi_lib.c
··· 634 634 * of upper level post-processing and scsi_io_completion). 635 635 * 636 636 * Arguments: cmd - command that is complete. 637 - * uptodate - 1 if I/O indicates success, <= 0 for I/O error. 637 + * error - 0 if I/O indicates success, < 0 for I/O error. 638 638 * bytes - number of bytes of completed I/O 639 639 * requeue - indicates whether we should requeue leftovers. 640 640 * ··· 649 649 * at some point during this call. 650 650 * Notes: If cmd was requeued, upon return it will be a stale pointer. 651 651 */ 652 - static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int uptodate, 652 + static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error, 653 653 int bytes, int requeue) 654 654 { 655 655 struct request_queue *q = cmd->device->request_queue; 656 656 struct request *req = cmd->request; 657 - unsigned long flags; 658 657 659 658 /* 660 659 * If there are blocks left over at the end, set up the command 661 660 * to queue the remainder of them. 662 661 */ 663 - if (end_that_request_chunk(req, uptodate, bytes)) { 662 + if (blk_end_request(req, error, bytes)) { 664 663 int leftover = (req->hard_nr_sectors << 9); 665 664 666 665 if (blk_pc_request(req)) 667 666 leftover = req->data_len; 668 667 669 668 /* kill remainder if no retrys */ 670 - if (!uptodate && blk_noretry_request(req)) 671 - end_that_request_chunk(req, 0, leftover); 669 + if (error && blk_noretry_request(req)) 670 + blk_end_request(req, error, leftover); 672 671 else { 673 672 if (requeue) { 674 673 /* ··· 681 682 return cmd; 682 683 } 683 684 } 684 - 685 - add_disk_randomness(req->rq_disk); 686 - 687 - spin_lock_irqsave(q->queue_lock, flags); 688 - if (blk_rq_tagged(req)) 689 - blk_queue_end_tag(q, req); 690 - end_that_request_last(req, uptodate); 691 - spin_unlock_irqrestore(q->queue_lock, flags); 692 685 693 686 /* 694 687 * This will goose the queue request function at the end, so we don't ··· 883 892 * are leftovers and there is some kind of error 884 893 * (result != 0), retry the rest. 885 894 */ 886 - if (scsi_end_request(cmd, 1, good_bytes, result == 0) == NULL) 895 + if (scsi_end_request(cmd, 0, good_bytes, result == 0) == NULL) 887 896 return; 888 897 889 898 /* good_bytes = 0, or (inclusive) there were leftovers and ··· 897 906 * and quietly refuse further access. 898 907 */ 899 908 cmd->device->changed = 1; 900 - scsi_end_request(cmd, 0, this_count, 1); 909 + scsi_end_request(cmd, -EIO, this_count, 1); 901 910 return; 902 911 } else { 903 912 /* Must have been a power glitch, or a ··· 929 938 scsi_requeue_command(q, cmd); 930 939 return; 931 940 } else { 932 - scsi_end_request(cmd, 0, this_count, 1); 941 + scsi_end_request(cmd, -EIO, this_count, 1); 933 942 return; 934 943 } 935 944 break; ··· 957 966 "Device not ready", 958 967 &sshdr); 959 968 960 - scsi_end_request(cmd, 0, this_count, 1); 969 + scsi_end_request(cmd, -EIO, this_count, 1); 961 970 return; 962 971 case VOLUME_OVERFLOW: 963 972 if (!(req->cmd_flags & REQ_QUIET)) { ··· 967 976 scsi_print_sense("", cmd); 968 977 } 969 978 /* See SSC3rXX or current. */ 970 - scsi_end_request(cmd, 0, this_count, 1); 979 + scsi_end_request(cmd, -EIO, this_count, 1); 971 980 return; 972 981 default: 973 982 break; ··· 988 997 scsi_print_sense("", cmd); 989 998 } 990 999 } 991 - scsi_end_request(cmd, 0, this_count, !result); 1000 + scsi_end_request(cmd, -EIO, this_count, !result); 992 1001 } 993 1002 994 1003 /*
+18 -13
include/linux/blkdev.h
··· 464 464 #define blk_fua_rq(rq) ((rq)->cmd_flags & REQ_FUA) 465 465 #define blk_bidi_rq(rq) ((rq)->next_rq != NULL) 466 466 #define blk_empty_barrier(rq) (blk_barrier_rq(rq) && blk_fs_request(rq) && !(rq)->hard_nr_sectors) 467 + /* rq->queuelist of dequeued request must be list_empty() */ 468 + #define blk_queued_rq(rq) (!list_empty(&(rq)->queuelist)) 467 469 468 470 #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist) 469 471 ··· 645 643 } 646 644 647 645 /* 648 - * end_request() and friends. Must be called with the request queue spinlock 649 - * acquired. All functions called within end_request() _must_be_ atomic. 646 + * blk_end_request() and friends. 647 + * __blk_end_request() and end_request() must be called with 648 + * the request queue spinlock acquired. 650 649 * 651 650 * Several drivers define their own end_request and call 652 - * end_that_request_first() and end_that_request_last() 653 - * for parts of the original function. This prevents 654 - * code duplication in drivers. 651 + * blk_end_request() for parts of the original function. 652 + * This prevents code duplication in drivers. 655 653 */ 656 - extern int end_that_request_first(struct request *, int, int); 657 - extern int end_that_request_chunk(struct request *, int, int); 658 - extern void end_that_request_last(struct request *, int); 654 + extern int blk_end_request(struct request *rq, int error, int nr_bytes); 655 + extern int __blk_end_request(struct request *rq, int error, int nr_bytes); 656 + extern int blk_end_bidi_request(struct request *rq, int error, int nr_bytes, 657 + int bidi_bytes); 659 658 extern void end_request(struct request *, int); 660 659 extern void end_queued_request(struct request *, int); 661 660 extern void end_dequeued_request(struct request *, int); 661 + extern int blk_end_request_callback(struct request *rq, int error, int nr_bytes, 662 + int (drv_callback)(struct request *)); 662 663 extern void blk_complete_request(struct request *); 663 664 664 665 /* 665 - * end_that_request_first/chunk() takes an uptodate argument. we account 666 - * any value <= as an io error. 0 means -EIO for compatability reasons, 667 - * any other < 0 value is the direct error type. An uptodate value of 668 - * 1 indicates successful io completion 666 + * blk_end_request() takes bytes instead of sectors as a complete size. 667 + * blk_rq_bytes() returns bytes left to complete in the entire request. 668 + * blk_rq_cur_bytes() returns bytes left to complete in the current segment. 669 669 */ 670 - #define end_io_error(uptodate) (unlikely((uptodate) <= 0)) 670 + extern unsigned int blk_rq_bytes(struct request *rq); 671 + extern unsigned int blk_rq_cur_bytes(struct request *rq); 671 672 672 673 static inline void blkdev_dequeue_request(struct request *req) 673 674 {