path: root/block/blk-settings.c
diff options
authorDavid Woodhouse <>2008-08-05 18:01:53 +0100
committerJens Axboe <>2008-10-09 08:56:01 +0200
commitfb2dce862d9f9a68e6b9374579056ec9eca02a63 (patch)
tree888e0fd7248c9329fa1aa3981043a2dc2457d488 /block/blk-settings.c
parentd628eaef310533767ce68664873869c2d7f78f09 (diff)
Add 'discard' request handling
Some block devices benefit from a hint that they can forget the contents of certain sectors. Add basic support for this to the block core, along with a 'blkdev_issue_discard()' helper function which issues such requests. The caller doesn't get to provide an end_io functio, since blkdev_issue_discard() will automatically split the request up into multiple bios if appropriate. Neither does the function wait for completion -- it's expected that callers won't care about when, or even _if_, the request completes. It's only a hint to the device anyway. By definition, the file system doesn't _care_ about these sectors any more. [With feedback from OGAWA Hirofumi <> and Jens Axboe <] Signed-off-by: David Woodhouse <> Signed-off-by: Jens Axboe <>
Diffstat (limited to 'block/blk-settings.c')
1 files changed, 17 insertions, 0 deletions
diff --git a/block/blk-settings.c b/block/blk-settings.c
index dfc77012843f..539d873c820d 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -33,6 +33,23 @@ void blk_queue_prep_rq(struct request_queue *q, prep_rq_fn *pfn)
+ * blk_queue_set_discard - set a discard_sectors function for queue
+ * @q: queue
+ * @dfn: prepare_discard function
+ *
+ * It's possible for a queue to register a discard callback which is used
+ * to transform a discard request into the appropriate type for the
+ * hardware. If none is registered, then discard requests are failed
+ * with %EOPNOTSUPP.
+ *
+ */
+void blk_queue_set_discard(struct request_queue *q, prepare_discard_fn *dfn)
+ q->prepare_discard_fn = dfn;
* blk_queue_merge_bvec - set a merge_bvec function for queue
* @q: queue
* @mbfn: merge_bvec_fn