History

blk_end_request: add callback feature (take 4)

This patch adds a variant of the interface, blk_end_request_callback(), which has driver callback feature. Drivers may need to do special works between end_that_request_first() and end_that_request_last(). For such drivers, blk_end_request_callback() allows it to pass a callback function which is called between end_that_request_first() and end_that_request_last(). This interface is only for fallback of other blk_end_request interfaces. Drivers should avoid their tricky behaviors and use other interfaces as much as possible. Currently, only one driver, ide-cd, needs this interface. So this interface should/will be removed, after the driver removes such tricky behaviors. o ide-cd (cdrom_newpc_intr()) In PIO mode, cdrom_newpc_intr() needs to defer end_that_request_last() until the device clears DRQ_STAT and raises an interrupt after end_that_request_first(). So end_that_request_first() and end_that_request_last() are called separately in cdrom_newpc_intr(). This means blk_end_request_callback() has to return without completing request even if no leftover in the request. To satisfy the requirement, callback function has return value so that drivers can tell blk_end_request_callback() to return without completing request.

Kiyoshi Ueda committed 18 years ago

Commit e19a3ab1 parent 5e36bb62 files · +68 −6Browse files

Unified · Split

2 files
  1. block/ll_rw_blk.c +66 −6
  2. include/linux/blkdev.h +2 −0
block/ll_rw_blk.c+66−6
@@ -3825,10 +3825,14 @@ static void complete_request(struct request *rq, int error) · 3824 unmodified lines
38253825 }
38263826
38273827 /**
3828− * blk_end_request - Helper function for drivers to complete the request.
3829− * @rq: the request being processed
3830− * @error: 0 for success, < 0 for error
3831− * @nr_bytes: number of bytes to complete
3828+ * blk_end_io - Generic end_io function to complete a request.
3829+ * @rq: the request being processed
3830+ * @error: 0 for success, < 0 for error
3831+ * @nr_bytes: number of bytes to complete
3832+ * @drv_callback: function called between completion of bios in the request
3833+ * and completion of the request.
3834+ * If the callback returns non 0, this helper returns without
3835+ * completion of the request.
38323836 *
38333837 * Description:
38343838 * Ends I/O on a number of bytes attached to @rq.
@@ -3836,9 +3840,10 @@ static void complete_request(struct request *rq, int error) · 1 unmodified line
38363840 *
38373841 * Return:
38383842 * 0 - we are done with this request
3839− * 1 - still buffers pending for this request
3843+ * 1 - this request is not freed yet, it still has pending buffers.
38403844 **/
3841−int blk_end_request(struct request *rq, int error, int nr_bytes)
3845+static int blk_end_io(struct request *rq, int error, int nr_bytes,
3846+ int (drv_callback)(struct request *))
38423847 {
38433848 struct request_queue *q = rq->q;
38443849 unsigned long flags = 0UL;
@@ -3855,6 +3860,10 @@ int blk_end_request(struct request *rq, int error, int nr_bytes) · 10 unmodified lines
38553860 return 1;
38563861 }
38573862
3863+ /* Special feature for tricky drivers */
3864+ if (drv_callback && drv_callback(rq))
3865+ return 1;
3866+
38583867 add_disk_randomness(rq->rq_disk);
38593868
38603869 spin_lock_irqsave(q->queue_lock, flags);
@@ -3863,6 +3872,25 @@ int blk_end_request(struct request *rq, int error, int nr_bytes) · 2 unmodified lines
38633872
38643873 return 0;
38653874 }
3875+
3876+/**
3877+ * blk_end_request - Helper function for drivers to complete the request.
3878+ * @rq: the request being processed
3879+ * @error: 0 for success, < 0 for error
3880+ * @nr_bytes: number of bytes to complete
3881+ *
3882+ * Description:
3883+ * Ends I/O on a number of bytes attached to @rq.
3884+ * If @rq has leftover, sets it up for the next range of segments.
3885+ *
3886+ * Return:
3887+ * 0 - we are done with this request
3888+ * 1 - still buffers pending for this request
3889+ **/
3890+int blk_end_request(struct request *rq, int error, int nr_bytes)
3891+{
3892+ return blk_end_io(rq, error, nr_bytes, NULL);
3893+}
38663894 EXPORT_SYMBOL_GPL(blk_end_request);
38673895
38683896 /**
@@ -3901,6 +3929,38 @@ int __blk_end_request(struct request *rq, int error, int nr_bytes) · 32 unmodified lines
39013929 }
39023930 EXPORT_SYMBOL_GPL(__blk_end_request);
39033931
3932+/**
3933+ * blk_end_request_callback - Special helper function for tricky drivers
3934+ * @rq: the request being processed
3935+ * @error: 0 for success, < 0 for error
3936+ * @nr_bytes: number of bytes to complete
3937+ * @drv_callback: function called between completion of bios in the request
3938+ * and completion of the request.
3939+ * If the callback returns non 0, this helper returns without
3940+ * completion of the request.
3941+ *
3942+ * Description:
3943+ * Ends I/O on a number of bytes attached to @rq.
3944+ * If @rq has leftover, sets it up for the next range of segments.
3945+ *
3946+ * This special helper function is used only for existing tricky drivers.
3947+ * (e.g. cdrom_newpc_intr() of ide-cd)
3948+ * This interface will be removed when such drivers are rewritten.
3949+ * Don't use this interface in other places anymore.
3950+ *
3951+ * Return:
3952+ * 0 - we are done with this request
3953+ * 1 - this request is not freed yet.
3954+ * this request still has pending buffers or
3955+ * the driver doesn't want to finish this request yet.
3956+ **/
3957+int blk_end_request_callback(struct request *rq, int error, int nr_bytes,
3958+ int (drv_callback)(struct request *))
3959+{
3960+ return blk_end_io(rq, error, nr_bytes, drv_callback);
3961+}
3962+EXPORT_SYMBOL_GPL(blk_end_request_callback);
3963+
39043964 static void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
39053965 struct bio *bio)
39063966 {
include/linux/blkdev.h+2−0
@@ -734,6 +734,8 @@ extern void end_that_request_last(struct request *, int); · 733 unmodified lines
734734 extern void end_request(struct request *, int);
735735 extern void end_queued_request(struct request *, int);
736736 extern void end_dequeued_request(struct request *, int);
737+extern int blk_end_request_callback(struct request *rq, int error, int nr_bytes,
738+ int (drv_callback)(struct request *));
737739 extern void blk_complete_request(struct request *);
738740
739741 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t