Support 'discard sectors' operation in translation layer support core
authorDavid Woodhouse <David.Woodhouse@intel.com>
Tue, 5 Aug 2008 17:08:25 +0000 (18:08 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 9 Oct 2008 06:56:01 +0000 (08:56 +0200)
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
drivers/mtd/mtd_blkdevs.c
include/linux/blkdev.h
include/linux/mtd/blktrans.h

index 9ff007c4962c9f3c58868385729a915ba6b28222..681d5aca2af436630fda1d5124d8a3d6a1e70ce4 100644 (file)
@@ -32,6 +32,14 @@ struct mtd_blkcore_priv {
        spinlock_t queue_lock;
 };
 
+static int blktrans_discard_request(struct request_queue *q,
+                                   struct request *req)
+{
+       req->cmd_type = REQ_TYPE_LINUX_BLOCK;
+       req->cmd[0] = REQ_LB_OP_DISCARD;
+       return 0;
+}
+
 static int do_blktrans_request(struct mtd_blktrans_ops *tr,
                               struct mtd_blktrans_dev *dev,
                               struct request *req)
@@ -44,6 +52,10 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 
        buf = req->buffer;
 
+       if (req->cmd_type == REQ_TYPE_LINUX_BLOCK &&
+           req->cmd[0] == REQ_LB_OP_DISCARD)
+               return !tr->discard(dev, block, nsect);
+
        if (!blk_fs_request(req))
                return 0;
 
@@ -367,6 +379,10 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
 
        tr->blkcore_priv->rq->queuedata = tr;
        blk_queue_hardsect_size(tr->blkcore_priv->rq, tr->blksize);
+       if (tr->discard)
+               blk_queue_set_discard(tr->blkcore_priv->rq,
+                                     blktrans_discard_request);
+
        tr->blkshift = ffs(tr->blksize) - 1;
 
        tr->blkcore_priv->thread = kthread_run(mtd_blktrans_thread, tr,
index 26ececbbebe2a73fb8bd5242597af13eb2855022..727886d25c4eaf42379e379c1bb747fa1080a3e9 100644 (file)
@@ -81,6 +81,7 @@ enum {
         */
        REQ_LB_OP_EJECT = 0x40,         /* eject request */
        REQ_LB_OP_FLUSH = 0x41,         /* flush device */
+       REQ_LB_OP_DISCARD = 0x42,       /* discard sectors */
 };
 
 /*
index 310e616064158d68afb3e3fcdfcc31a56421b1bb..8b4aa0523db76d22f821d07037e36bdcf2eb62be 100644 (file)
@@ -41,6 +41,8 @@ struct mtd_blktrans_ops {
                    unsigned long block, char *buffer);
        int (*writesect)(struct mtd_blktrans_dev *dev,
                     unsigned long block, char *buffer);
+       int (*discard)(struct mtd_blktrans_dev *dev,
+                      unsigned long block, unsigned nr_blocks);
 
        /* Block layer ioctls */
        int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo);