summaryrefslogtreecommitdiffstats
path: root/drivers/lightnvm/gennvm.c
diff options
context:
space:
mode:
authorWenwei Tao <ww.tao0320@gmail.com>2016-03-03 15:06:38 +0100
committerJens Axboe <axboe@fb.com>2016-03-18 18:10:38 -0700
commitda1e284919b0b99c5bf0618b6c98cbaf2c17e62e (patch)
treeef1d8fe8821376dd57fbd4d3319a747841df38e6 /drivers/lightnvm/gennvm.c
parent4c9dacb82d5aa36aa2568df60d897f2eb3d8819b (diff)
downloadlinux-da1e284919b0b99c5bf0618b6c98cbaf2c17e62e.tar.bz2
lightnvm: add a bitmap of luns
Add a bitmap of luns to indicate the status of luns: inuse/available. When create targets do the necessary check to avoid allocating luns that are already allocated. Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com> Freed dev->lun_map if nvm_core_init later failed in the init process. Signed-off-by: Matias Bjørling <m@bjorling.me> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/lightnvm/gennvm.c')
-rw-r--r--drivers/lightnvm/gennvm.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c
index d460b37bb016..b97801c00099 100644
--- a/drivers/lightnvm/gennvm.c
+++ b/drivers/lightnvm/gennvm.c
@@ -192,6 +192,9 @@ static int gennvm_block_map(u64 slba, u32 nlb, __le64 *entries, void *private)
lun_id = div_u64(pba, dev->sec_per_lun);
lun = &gn->luns[lun_id];
+ if (!test_bit(lun_id, dev->lun_map))
+ __set_bit(lun_id, dev->lun_map);
+
/* Calculate block offset into lun */
pba = pba - (dev->sec_per_lun * lun_id);
blk = &lun->vlun.blocks[div_u64(pba, dev->sec_per_blk)];
@@ -482,10 +485,23 @@ static int gennvm_erase_blk(struct nvm_dev *dev, struct nvm_block *blk,
return nvm_erase_ppa(dev, &addr, 1);
}
+static int gennvm_reserve_lun(struct nvm_dev *dev, int lunid)
+{
+ return test_and_set_bit(lunid, dev->lun_map);
+}
+
+static void gennvm_release_lun(struct nvm_dev *dev, int lunid)
+{
+ WARN_ON(!test_and_clear_bit(lunid, dev->lun_map));
+}
+
static struct nvm_lun *gennvm_get_lun(struct nvm_dev *dev, int lunid)
{
struct gen_nvm *gn = dev->mp;
+ if (unlikely(lunid >= dev->nr_luns))
+ return NULL;
+
return &gn->luns[lunid].vlun;
}
@@ -527,6 +543,8 @@ static struct nvmm_type gennvm = {
.erase_blk = gennvm_erase_blk,
.get_lun = gennvm_get_lun,
+ .reserve_lun = gennvm_reserve_lun,
+ .release_lun = gennvm_release_lun,
.lun_info_print = gennvm_lun_info_print,
.get_area = gennvm_get_area,