Skip to contentSkip to conversation

blk_end_request: changing ide-cd (take 2)

PATCH In review Kiyoshi Ueda 1 participant 1 message Sep 11, 2007

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 26/27 blk_end_request: changing ide-cd (take 2)

This patch converts ide-cd (cdrom_newpc_intr()) to use blk_end_request().

Due to the oddness of the driver, the patch adds a variant of the interface, blk_end_request_callback().

cdrom_newpc_intr() of ide-cd is the only function in the kernel tree which needs to call end_that_request_first() and end_that_request_last() separately. blk_end_request_callback() allows it to pass callback function to do something between end_that_request_first() and end_that_request_last().

ide-cd (cdrom_newpc_intr) needs to the followings:
1. call post_transform_command() to modify request contents
2. wait completing request until DRQ_STAT is cleared
after end_that_request_first() and before end_that_request_last().

As for the second one, ide-cd will wait for the interrupt from device. So blk_end_request() has to return without completing request even if no leftover in the request.

---
 block/ll_rw_blk.c      |   54 +++++++++++++++++++++++++++++++++
 drivers/ide/ide-cd.c   |   78 ++++++++++++++++++++++++++++++++++++++----------
 include/linux/blkdev.h |    3 +
 3 files changed, 118 insertions(+), 17 deletions(-)
block/ll_rw_blk.c +54 -0
diff -rupN 25-ide-normal-caller-change/block/ll_rw_blk.c 26-ide-odd-caller-change/block/ll_rw_blk.c
@@ -3845,6 +3845,60 @@ int __blk_end_request(struct request *rq
 }
 EXPORT_SYMBOL_GPL(__blk_end_request);
 
+/**
+ * blk_end_request_callback - Special helper function for the ide-cd driver
+ * @rq:           the request being processed
+ * @uptodate:     1 for success, 0 for I/O error, < 0 for specific error
+ * @nr_bytes:     number of bytes to complete
+ * @drv_callback: function called between completion of bios in the request
+ *                and completion of the request.
+ *                If the callback returns non 0, this helper returns without
+ *                completion of the request.
+ *
+ * Description:
+ *     Ends I/O on a number of bytes attached to @rq.
+ *     If @rq has leftover, sets it up for the next range of segments.
+ *
+ *     This special helper function for the ide-cd driver is used
+ *     to complete the request only in cdrom_newpc_intr().
+ *     This interface will be removed when cdrom_newpc_intr() is rewritten.
+ *     Don't use this interface in other places.
+ *
+ * Return:
+ *     0 - we are done with this request
+ *     1 - this request is not freed yet.
+ *         this request still has pending buffers or
+ *         the ide-cd driver doesn't want to finish this request yet.
+ **/
+int blk_end_request_callback(struct request *rq, int uptodate, int nr_bytes,
+			     int (drv_callback)(struct request *))
+{
+	struct request_queue *q = rq->q;
+	unsigned long flags = 0UL;
+
+	if (blk_fs_request(rq) || blk_pc_request(rq)) {
+		if (__end_that_request_first(rq, uptodate, nr_bytes))
+			return 1;
+	}
+
+	/* Special feature for drivers/ide/ide-cd.c:cdrom_newpc_intr() */
+	if (drv_callback && drv_callback(rq))
+		return 1;
+
+	/*
+	 * No need to check the argument here because it is done
+	 * in add_disk_randomness().
+	 */
+	add_disk_randomness(rq->rq_disk);
+
+	spin_lock_irqsave(q->queue_lock, flags);
+	complete_request(rq, uptodate);
+	spin_unlock_irqrestore(q->queue_lock, flags);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(blk_end_request_callback);
+
 void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
 		     struct bio *bio)
 {
drivers/ide/ide-cd.c +61 -17

108 lines not on this page · raw message

include/linux/blkdev.h +3 -0
diff -rupN 25-ide-normal-caller-change/include/linux/blkdev.h 26-ide-odd-caller-change/include/linux/blkdev.h
@@ -734,6 +734,9 @@ extern int end_that_request_chunk(struct
 extern void end_that_request_last(struct request *, int);
 extern void end_request(struct request *, int);
 extern void end_queued_request(struct request *, int);
+extern int blk_end_request_callback(struct request *rq, int uptodate,
+				    int nr_bytes,
+				    int (drv_callback)(struct request *));
 extern void blk_complete_request(struct request *);
 
 /*