lightnvm: remove _unlocked variant of [get/put]_blk
authorMatias Bjørling <m@bjorling.me>
Thu, 7 Jul 2016 07:54:19 +0000 (09:54 +0200)
committerJens Axboe <axboe@fb.com>
Thu, 7 Jul 2016 14:51:52 +0000 (08:51 -0600)
The [get/put]_blk API enables targets to get ownership of blocks at
runtime. This information is currently not recorded on disk, and the
information is therefore lost on power failure. To restore the
metadata, the [get/put]_blk must persist its metadata. In that case,
we need to control the outer lock, so that we can disable them while
updating the on-disk metadata. Fortunately, the _unlocked versions can
be removed, which allows us to move the lock into the [get/put]_blk
functions.

Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/lightnvm/core.c
drivers/lightnvm/gennvm.c
drivers/lightnvm/rrpc.c
include/linux/lightnvm.h

index 04469e0c84ce2a4dbb9b6f238b414c8a931e2408..ddc809803084f687ad843f57bc44428c1ab6445e 100644 (file)
@@ -176,20 +176,6 @@ static struct nvm_dev *nvm_find_nvm_dev(const char *name)
        return NULL;
 }
 
-struct nvm_block *nvm_get_blk_unlocked(struct nvm_dev *dev, struct nvm_lun *lun,
-                                                       unsigned long flags)
-{
-       return dev->mt->get_blk_unlocked(dev, lun, flags);
-}
-EXPORT_SYMBOL(nvm_get_blk_unlocked);
-
-/* Assumes that all valid pages have already been moved on release to bm */
-void nvm_put_blk_unlocked(struct nvm_dev *dev, struct nvm_block *blk)
-{
-       return dev->mt->put_blk_unlocked(dev, blk);
-}
-EXPORT_SYMBOL(nvm_put_blk_unlocked);
-
 struct nvm_block *nvm_get_blk(struct nvm_dev *dev, struct nvm_lun *lun,
                                                        unsigned long flags)
 {
index 41760b24bea7605890b0a6f34f393399d2482349..c65fb675e37431bb98e484e75ad7719a240c7776 100644 (file)
@@ -473,15 +473,14 @@ static void gen_unregister(struct nvm_dev *dev)
        module_put(THIS_MODULE);
 }
 
-static struct nvm_block *gen_get_blk_unlocked(struct nvm_dev *dev,
+static struct nvm_block *gen_get_blk(struct nvm_dev *dev,
                                struct nvm_lun *vlun, unsigned long flags)
 {
        struct gen_lun *lun = container_of(vlun, struct gen_lun, vlun);
        struct nvm_block *blk = NULL;
        int is_gc = flags & NVM_IOTYPE_GC;
 
-       assert_spin_locked(&vlun->lock);
-
+       spin_lock(&vlun->lock);
        if (list_empty(&lun->free_list)) {
                pr_err_ratelimited("gen: lun %u have no free pages available",
                                                                lun->vlun.id);
@@ -496,29 +495,17 @@ static struct nvm_block *gen_get_blk_unlocked(struct nvm_dev *dev,
        list_move_tail(&blk->list, &lun->used_list);
        blk->state = NVM_BLK_ST_TGT;
        lun->vlun.nr_free_blocks--;
-
 out:
-       return blk;
-}
-
-static struct nvm_block *gen_get_blk(struct nvm_dev *dev,
-                               struct nvm_lun *vlun, unsigned long flags)
-{
-       struct nvm_block *blk;
-
-       spin_lock(&vlun->lock);
-       blk = gen_get_blk_unlocked(dev, vlun, flags);
        spin_unlock(&vlun->lock);
        return blk;
 }
 
-static void gen_put_blk_unlocked(struct nvm_dev *dev, struct nvm_block *blk)
+static void gen_put_blk(struct nvm_dev *dev, struct nvm_block *blk)
 {
        struct nvm_lun *vlun = blk->lun;
        struct gen_lun *lun = container_of(vlun, struct gen_lun, vlun);
 
-       assert_spin_locked(&vlun->lock);
-
+       spin_lock(&vlun->lock);
        if (blk->state & NVM_BLK_ST_TGT) {
                list_move_tail(&blk->list, &lun->free_list);
                lun->vlun.nr_free_blocks++;
@@ -532,14 +519,6 @@ static void gen_put_blk_unlocked(struct nvm_dev *dev, struct nvm_block *blk)
                                                        blk->id, blk->state);
                list_move_tail(&blk->list, &lun->bb_list);
        }
-}
-
-static void gen_put_blk(struct nvm_dev *dev, struct nvm_block *blk)
-{
-       struct nvm_lun *vlun = blk->lun;
-
-       spin_lock(&vlun->lock);
-       gen_put_blk_unlocked(dev, blk);
        spin_unlock(&vlun->lock);
 }
 
@@ -669,9 +648,6 @@ static struct nvmm_type gen = {
        .create_tgt             = gen_create_tgt,
        .remove_tgt             = gen_remove_tgt,
 
-       .get_blk_unlocked       = gen_get_blk_unlocked,
-       .put_blk_unlocked       = gen_put_blk_unlocked,
-
        .get_blk                = gen_get_blk,
        .put_blk                = gen_put_blk,
 
index 10ed22b9875dbf6b63ba486178e76cb608d9681d..fa8d5be2987c16fa4002ce9a3e8d96cfbf8a1eae 100644 (file)
@@ -192,21 +192,16 @@ static void rrpc_set_lun_cur(struct rrpc_lun *rlun, struct rrpc_block *rblk)
 static struct rrpc_block *rrpc_get_blk(struct rrpc *rrpc, struct rrpc_lun *rlun,
                                                        unsigned long flags)
 {
-       struct nvm_lun *lun = rlun->parent;
        struct nvm_block *blk;
        struct rrpc_block *rblk;
 
-       spin_lock(&lun->lock);
-       blk = nvm_get_blk_unlocked(rrpc->dev, rlun->parent, flags);
+       blk = nvm_get_blk(rrpc->dev, rlun->parent, flags);
        if (!blk) {
                pr_err("nvm: rrpc: cannot get new block from media manager\n");
-               spin_unlock(&lun->lock);
                return NULL;
        }
 
        rblk = rrpc_get_rblk(rlun, blk->id);
-       spin_unlock(&lun->lock);
-
        blk->priv = rblk;
        bitmap_zero(rblk->invalid_pages, rrpc->dev->sec_per_blk);
        rblk->next_page = 0;
@@ -218,12 +213,7 @@ static struct rrpc_block *rrpc_get_blk(struct rrpc *rrpc, struct rrpc_lun *rlun,
 
 static void rrpc_put_blk(struct rrpc *rrpc, struct rrpc_block *rblk)
 {
-       struct rrpc_lun *rlun = rblk->rlun;
-       struct nvm_lun *lun = rlun->parent;
-
-       spin_lock(&lun->lock);
-       nvm_put_blk_unlocked(rrpc->dev, rblk->parent);
-       spin_unlock(&lun->lock);
+       nvm_put_blk(rrpc->dev, rblk->parent);
 }
 
 static void rrpc_put_blks(struct rrpc *rrpc)
index d619f6dde7df1a897ff80889a70e6d2dad9f4284..e9836cfb6fdeb5098bb25ea22a33f46e9f7ffa02 100644 (file)
@@ -491,8 +491,6 @@ struct nvmm_type {
        nvmm_remove_tgt_fn *remove_tgt;
 
        /* Block administration callbacks */
-       nvmm_get_blk_fn *get_blk_unlocked;
-       nvmm_put_blk_fn *put_blk_unlocked;
        nvmm_get_blk_fn *get_blk;
        nvmm_put_blk_fn *put_blk;
        nvmm_open_blk_fn *open_blk;
@@ -522,10 +520,6 @@ struct nvmm_type {
 extern int nvm_register_mgr(struct nvmm_type *);
 extern void nvm_unregister_mgr(struct nvmm_type *);
 
-extern struct nvm_block *nvm_get_blk_unlocked(struct nvm_dev *,
-                                       struct nvm_lun *, unsigned long);
-extern void nvm_put_blk_unlocked(struct nvm_dev *, struct nvm_block *);
-
 extern struct nvm_block *nvm_get_blk(struct nvm_dev *, struct nvm_lun *,
                                                                unsigned long);
 extern void nvm_put_blk(struct nvm_dev *, struct nvm_block *);