Skip to content

Commit 28018c2

Browse files
James BottomleyJens Axboe
authored andcommitted
block: implement an unprep function corresponding directly to prep
Reviewed-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent e597cd0 commit 28018c2

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

‎block/blk-core.c‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ blk_init_allocated_queue_node(struct request_queue *q, request_fn_proc *rfn,
608608

609609
q->request_fn = rfn;
610610
q->prep_rq_fn = NULL;
611+
q->unprep_rq_fn = NULL;
611612
q->unplug_fn = generic_unplug_device;
612613
q->queue_flags = QUEUE_FLAG_DEFAULT;
613614
q->queue_lock = lock;
@@ -2133,6 +2134,26 @@ static bool blk_update_bidi_request(struct request *rq, int error,
21332134
return false;
21342135
}
21352136

2137+
/**
2138+
* blk_unprep_request - unprepare a request
2139+
* @req: the request
2140+
*
2141+
* This function makes a request ready for complete resubmission (or
2142+
* completion). It happens only after all error handling is complete,
2143+
* so represents the appropriate moment to deallocate any resources
2144+
* that were allocated to the request in the prep_rq_fn. The queue
2145+
* lock is held when calling this.
2146+
*/
2147+
void blk_unprep_request(struct request *req)
2148+
{
2149+
struct request_queue *q = req->q;
2150+
2151+
req->cmd_flags &= ~REQ_DONTPREP;
2152+
if (q->unprep_rq_fn)
2153+
q->unprep_rq_fn(q, req);
2154+
}
2155+
EXPORT_SYMBOL_GPL(blk_unprep_request);
2156+
21362157
/*
21372158
* queue lock must be held
21382159
*/
@@ -2148,6 +2169,10 @@ static void blk_finish_request(struct request *req, int error)
21482169

21492170
blk_delete_timer(req);
21502171

2172+
if (req->cmd_flags & REQ_DONTPREP)
2173+
blk_unprep_request(req);
2174+
2175+
21512176
blk_account_io_done(req);
21522177

21532178
if (req->end_io)

‎block/blk-settings.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ void blk_queue_prep_rq(struct request_queue *q, prep_rq_fn *pfn)
3636
}
3737
EXPORT_SYMBOL(blk_queue_prep_rq);
3838

39+
/**
40+
* blk_queue_unprep_rq - set an unprepare_request function for queue
41+
* @q: queue
42+
* @ufn: unprepare_request function
43+
*
44+
* It's possible for a queue to register an unprepare_request callback
45+
* which is invoked before the request is finally completed. The goal
46+
* of the function is to deallocate any data that was allocated in the
47+
* prepare_request callback.
48+
*
49+
*/
50+
void blk_queue_unprep_rq(struct request_queue *q, unprep_rq_fn *ufn)
51+
{
52+
q->unprep_rq_fn = ufn;
53+
}
54+
EXPORT_SYMBOL(blk_queue_unprep_rq);
55+
3956
/**
4057
* blk_queue_merge_bvec - set a merge_bvec function for queue
4158
* @q: queue

‎drivers/scsi/scsi_lib.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static void scsi_unprep_request(struct request *req)
8585
{
8686
struct scsi_cmnd *cmd = req->special;
8787

88-
req->cmd_flags &= ~REQ_DONTPREP;
88+
blk_unprep_request(req);
8989
req->special = NULL;
9090

9191
scsi_put_command(cmd);

‎include/linux/blkdev.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct request_pm_state
200200
typedef void (request_fn_proc) (struct request_queue *q);
201201
typedef int (make_request_fn) (struct request_queue *q, struct bio *bio);
202202
typedef int (prep_rq_fn) (struct request_queue *, struct request *);
203+
typedef void (unprep_rq_fn) (struct request_queue *, struct request *);
203204
typedef void (unplug_fn) (struct request_queue *);
204205

205206
struct bio_vec;
@@ -282,6 +283,7 @@ struct request_queue
282283
request_fn_proc *request_fn;
283284
make_request_fn *make_request_fn;
284285
prep_rq_fn *prep_rq_fn;
286+
unprep_rq_fn *unprep_rq_fn;
285287
unplug_fn *unplug_fn;
286288
merge_bvec_fn *merge_bvec_fn;
287289
prepare_flush_fn *prepare_flush_fn;
@@ -841,6 +843,7 @@ extern void blk_complete_request(struct request *);
841843
extern void __blk_complete_request(struct request *);
842844
extern void blk_abort_request(struct request *);
843845
extern void blk_abort_queue(struct request_queue *);
846+
extern void blk_unprep_request(struct request *);
844847

845848
/*
846849
* Access functions for manipulating queue properties
@@ -885,6 +888,7 @@ extern int blk_queue_dma_drain(struct request_queue *q,
885888
extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn);
886889
extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
887890
extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn);
891+
extern void blk_queue_unprep_rq(struct request_queue *, unprep_rq_fn *ufn);
888892
extern void blk_queue_merge_bvec(struct request_queue *, merge_bvec_fn *);
889893
extern void blk_queue_dma_alignment(struct request_queue *, int);
890894
extern void blk_queue_update_dma_alignment(struct request_queue *, int);

0 commit comments

Comments
 (0)