| @@ -32,6 +32,14 @@ struct mtd_blkcore_priv { · 31 unmodified lines |
| 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 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr, · 6 unmodified lines |
| 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 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr) · 317 unmodified lines |
| 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, |