2 * Functions related to setting various queue properties from drivers
4 #include <linux/kernel.h>
5 #include <linux/module.h>
7 #include <linux/blkdev.h>
14 #include <scsi/scsi_cmnd.h>
17 * blk_end_sync_rq - executes a completion event on a request
18 * @rq: request to complete
19 * @error: end io status of the request
21 void blk_end_sync_rq(struct request *rq, int error)
23 struct completion *waiting = rq->end_io_data;
25 rq->end_io_data = NULL;
26 __blk_put_request(rq->q, rq);
29 * complete last, if this is a stack request the process (and thus
30 * the rq pointer) could be invalid right after this complete()
34 EXPORT_SYMBOL(blk_end_sync_rq);
37 * blk_execute_rq_nowait - insert a request into queue for execution
38 * @q: queue to insert the request in
39 * @bd_disk: matching gendisk
40 * @rq: request to insert
41 * @at_head: insert request at head or tail of queue
42 * @done: I/O completion handler
45 * Insert a fully prepared request at the back of the io scheduler queue
46 * for execution. Don't wait for completion.
48 void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
49 struct request *rq, int at_head,
52 int where = at_head ? ELEVATOR_INSERT_FRONT : ELEVATOR_INSERT_BACK;
54 rq->rq_disk = bd_disk;
55 rq->cmd_flags |= REQ_NOMERGE;
57 WARN_ON(irqs_disabled());
58 spin_lock_irq(q->queue_lock);
59 __elv_add_request(q, rq, where, 1);
60 __generic_unplug_device(q);
61 spin_unlock_irq(q->queue_lock);
63 EXPORT_SYMBOL_GPL(blk_execute_rq_nowait);
66 * blk_execute_rq - insert a request into queue for execution
67 * @q: queue to insert the request in
68 * @bd_disk: matching gendisk
69 * @rq: request to insert
70 * @at_head: insert request at head or tail of queue
73 * Insert a fully prepared request at the back of the io scheduler queue
74 * for execution and wait for completion.
76 int blk_execute_rq(struct request_queue *q, struct gendisk *bd_disk,
77 struct request *rq, int at_head)
79 DECLARE_COMPLETION_ONSTACK(wait);
80 char sense[SCSI_SENSE_BUFFERSIZE];
84 * we need an extra reference to the request, so we can look at
85 * it after io completion
90 memset(sense, 0, sizeof(sense));
95 rq->end_io_data = &wait;
96 blk_execute_rq_nowait(q, bd_disk, rq, at_head, blk_end_sync_rq);
97 wait_for_completion(&wait);
104 EXPORT_SYMBOL(blk_execute_rq);