Commit eae9acd13a8d14b50c00a961fa959606f34bbd92
Committed by
Jens Axboe
1 parent
8c540a96c1
Exists in
master
and in
4 other branches
Support 'discard sectors' operation in translation layer support core
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Showing 3 changed files with 19 additions and 0 deletions Side-by-side Diff
drivers/mtd/mtd_blkdevs.c
... | ... | @@ -32,6 +32,14 @@ |
32 | 32 | spinlock_t queue_lock; |
33 | 33 | }; |
34 | 34 | |
35 | +static int blktrans_discard_request(struct request_queue *q, | |
36 | + struct request *req) | |
37 | +{ | |
38 | + req->cmd_type = REQ_TYPE_LINUX_BLOCK; | |
39 | + req->cmd[0] = REQ_LB_OP_DISCARD; | |
40 | + return 0; | |
41 | +} | |
42 | + | |
35 | 43 | static int do_blktrans_request(struct mtd_blktrans_ops *tr, |
36 | 44 | struct mtd_blktrans_dev *dev, |
37 | 45 | struct request *req) |
... | ... | @@ -44,6 +52,10 @@ |
44 | 52 | |
45 | 53 | buf = req->buffer; |
46 | 54 | |
55 | + if (req->cmd_type == REQ_TYPE_LINUX_BLOCK && | |
56 | + req->cmd[0] == REQ_LB_OP_DISCARD) | |
57 | + return !tr->discard(dev, block, nsect); | |
58 | + | |
47 | 59 | if (!blk_fs_request(req)) |
48 | 60 | return 0; |
49 | 61 | |
... | ... | @@ -367,6 +379,10 @@ |
367 | 379 | |
368 | 380 | tr->blkcore_priv->rq->queuedata = tr; |
369 | 381 | blk_queue_hardsect_size(tr->blkcore_priv->rq, tr->blksize); |
382 | + if (tr->discard) | |
383 | + blk_queue_set_discard(tr->blkcore_priv->rq, | |
384 | + blktrans_discard_request); | |
385 | + | |
370 | 386 | tr->blkshift = ffs(tr->blksize) - 1; |
371 | 387 | |
372 | 388 | tr->blkcore_priv->thread = kthread_run(mtd_blktrans_thread, tr, |
include/linux/blkdev.h
include/linux/mtd/blktrans.h
... | ... | @@ -41,6 +41,8 @@ |
41 | 41 | unsigned long block, char *buffer); |
42 | 42 | int (*writesect)(struct mtd_blktrans_dev *dev, |
43 | 43 | unsigned long block, char *buffer); |
44 | + int (*discard)(struct mtd_blktrans_dev *dev, | |
45 | + unsigned long block, unsigned nr_blocks); | |
44 | 46 | |
45 | 47 | /* Block layer ioctls */ |
46 | 48 | int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo); |