Commit 2a02e627 authored by Javier González's avatar Javier González Committed by Jens Axboe

lightnvm: eliminate nvm_block abstraction on mm

In order to naturally support multi-target instances on an Open-Channel
SSD, targets should own the LUNs they get blocks from and manage
provisioning internally. This is done in several steps.

A part of this transformation is that targets manage their blocks
internally. This patch eliminates the nvm_block abstraction and moves
block management to the target logic. The rrpc target is transformed.
Signed-off-by: default avatarJavier González <javier@cnexlabs.com>
Signed-off-by: default avatarMatias Bjørling <m@bjorling.me>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent eec44565
......@@ -176,12 +176,6 @@ static struct nvm_dev *nvm_find_nvm_dev(const char *name)
return NULL;
}
void nvm_mark_blk(struct nvm_dev *dev, struct ppa_addr ppa, int type)
{
return dev->mt->mark_blk(dev, ppa, type);
}
EXPORT_SYMBOL(nvm_mark_blk);
int nvm_set_bb_tbl(struct nvm_dev *dev, struct ppa_addr *ppas, int nr_ppas,
int type)
{
......@@ -215,9 +209,9 @@ int nvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd)
}
EXPORT_SYMBOL(nvm_submit_io);
int nvm_erase_blk(struct nvm_dev *dev, struct nvm_block *blk, int flags)
int nvm_erase_blk(struct nvm_dev *dev, struct ppa_addr *p, int flags)
{
return dev->mt->erase_blk(dev, blk, flags);
return dev->mt->erase_blk(dev, p, flags);
}
EXPORT_SYMBOL(nvm_erase_blk);
......
......@@ -306,19 +306,6 @@ static void gen_put_area(struct nvm_dev *dev, sector_t begin)
spin_unlock(&dev->lock);
}
static void gen_blocks_free(struct nvm_dev *dev)
{
struct gen_dev *gn = dev->mp;
struct nvm_lun *lun;
int i;
gen_for_each_lun(gn, lun, i) {
if (!lun->blocks)
break;
vfree(lun->blocks);
}
}
static void gen_luns_free(struct nvm_dev *dev)
{
struct gen_dev *gn = dev->mp;
......@@ -337,167 +324,17 @@ static int gen_luns_init(struct nvm_dev *dev, struct gen_dev *gn)
return -ENOMEM;
gen_for_each_lun(gn, lun, i) {
INIT_LIST_HEAD(&lun->free_list);
INIT_LIST_HEAD(&lun->used_list);
INIT_LIST_HEAD(&lun->bb_list);
INIT_LIST_HEAD(&lun->list);
spin_lock_init(&lun->lock);
lun->id = i;
lun->lun_id = i % geo->luns_per_chnl;
lun->chnl_id = i / geo->luns_per_chnl;
lun->nr_free_blocks = geo->blks_per_lun;
}
return 0;
}
static int gen_block_bb(struct gen_dev *gn, struct ppa_addr ppa,
u8 *blks, int nr_blks)
{
struct nvm_dev *dev = gn->dev;
struct nvm_lun *lun;
struct nvm_block *blk;
int i;
nr_blks = nvm_bb_tbl_fold(dev, blks, nr_blks);
if (nr_blks < 0)
return nr_blks;
lun = &gn->luns[(dev->geo.luns_per_chnl * ppa.g.ch) + ppa.g.lun];
for (i = 0; i < nr_blks; i++) {
if (blks[i] == NVM_BLK_T_FREE)
continue;
blk = &lun->blocks[i];
list_move_tail(&blk->list, &lun->bb_list);
blk->state = NVM_BLK_ST_BAD;
lun->nr_free_blocks--;
}
return 0;
}
static int gen_block_map(u64 slba, u32 nlb, __le64 *entries, void *private)
{
struct nvm_dev *dev = private;
struct nvm_geo *geo = &dev->geo;
struct gen_dev *gn = dev->mp;
u64 elba = slba + nlb;
struct nvm_lun *lun;
struct nvm_block *blk;
u64 i;
int lun_id;
if (unlikely(elba > dev->total_secs)) {
pr_err("gen: L2P data from device is out of bounds!\n");
return -EINVAL;
}
for (i = 0; i < nlb; i++) {
u64 pba = le64_to_cpu(entries[i]);
if (unlikely(pba >= dev->total_secs && pba != U64_MAX)) {
pr_err("gen: L2P data entry is out of bounds!\n");
return -EINVAL;
}
/* Address zero is a special one. The first page on a disk is
* protected. It often holds internal device boot
* information.
*/
if (!pba)
continue;
/* resolve block from physical address */
lun_id = div_u64(pba, geo->sec_per_lun);
lun = &gn->luns[lun_id];
/* Calculate block offset into lun */
pba = pba - (geo->sec_per_lun * lun_id);
blk = &lun->blocks[div_u64(pba, geo->sec_per_blk)];
if (!blk->state) {
/* at this point, we don't know anything about the
* block. It's up to the FTL on top to re-etablish the
* block state. The block is assumed to be open.
*/
list_move_tail(&blk->list, &lun->used_list);
blk->state = NVM_BLK_ST_TGT;
lun->nr_free_blocks--;
}
}
return 0;
}
static int gen_blocks_init(struct nvm_dev *dev, struct gen_dev *gn)
{
struct nvm_geo *geo = &dev->geo;
struct nvm_lun *lun;
struct nvm_block *block;
sector_t lun_iter, blk_iter, cur_block_id = 0;
int ret, nr_blks;
u8 *blks;
nr_blks = geo->blks_per_lun * geo->plane_mode;
blks = kmalloc(nr_blks, GFP_KERNEL);
if (!blks)
return -ENOMEM;
gen_for_each_lun(gn, lun, lun_iter) {
lun->blocks = vzalloc(sizeof(struct nvm_block) *
geo->blks_per_lun);
if (!lun->blocks) {
kfree(blks);
return -ENOMEM;
}
for (blk_iter = 0; blk_iter < geo->blks_per_lun; blk_iter++) {
block = &lun->blocks[blk_iter];
INIT_LIST_HEAD(&block->list);
block->lun = lun;
block->id = cur_block_id++;
list_add_tail(&block->list, &lun->free_list);
}
if (dev->ops->get_bb_tbl) {
struct ppa_addr ppa;
ppa.ppa = 0;
ppa.g.ch = lun->chnl_id;
ppa.g.lun = lun->lun_id;
ret = nvm_get_bb_tbl(dev, ppa, blks);
if (ret)
pr_err("gen: could not get BB table\n");
ret = gen_block_bb(gn, ppa, blks, nr_blks);
if (ret)
pr_err("gen: BB table map failed\n");
}
}
if ((dev->identity.dom & NVM_RSP_L2P) && dev->ops->get_l2p_tbl) {
ret = dev->ops->get_l2p_tbl(dev, 0, dev->total_secs,
gen_block_map, dev);
if (ret) {
pr_err("gen: could not read L2P table.\n");
pr_warn("gen: default block initialization");
}
}
kfree(blks);
return 0;
}
static void gen_free(struct nvm_dev *dev)
{
gen_blocks_free(dev);
gen_luns_free(dev);
kfree(dev->mp);
dev->mp = NULL;
......@@ -528,12 +365,6 @@ static int gen_register(struct nvm_dev *dev)
goto err;
}
ret = gen_blocks_init(dev, gn);
if (ret) {
pr_err("gen: could not initialize blocks\n");
goto err;
}
return 1;
err:
gen_free(dev);
......@@ -558,34 +389,6 @@ static void gen_unregister(struct nvm_dev *dev)
module_put(THIS_MODULE);
}
static void gen_mark_blk(struct nvm_dev *dev, struct ppa_addr ppa, int type)
{
struct nvm_geo *geo = &dev->geo;
struct gen_dev *gn = dev->mp;
struct nvm_lun *lun;
struct nvm_block *blk;
pr_debug("gen: ppa (ch: %u lun: %u blk: %u pg: %u) -> %u\n",
ppa.g.ch, ppa.g.lun, ppa.g.blk, ppa.g.pg, type);
if (unlikely(ppa.g.ch > geo->nr_chnls ||
ppa.g.lun > geo->luns_per_chnl ||
ppa.g.blk > geo->blks_per_lun)) {
WARN_ON_ONCE(1);
pr_err("gen: ppa broken (ch: %u > %u lun: %u > %u blk: %u > %u",
ppa.g.ch, geo->nr_chnls,
ppa.g.lun, geo->luns_per_chnl,
ppa.g.blk, geo->blks_per_lun);
return;
}
lun = &gn->luns[(geo->luns_per_chnl * ppa.g.ch) + ppa.g.lun];
blk = &lun->blocks[ppa.g.blk];
/* will be moved to bb list on put_blk from target */
blk->state = type;
}
static void gen_end_io(struct nvm_rq *rqd)
{
struct nvm_tgt_instance *ins = rqd->ins;
......@@ -606,11 +409,9 @@ static int gen_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd)
return dev->ops->submit_io(dev, rqd);
}
static int gen_erase_blk(struct nvm_dev *dev, struct nvm_block *blk, int flags)
static int gen_erase_blk(struct nvm_dev *dev, struct ppa_addr *p, int flags)
{
struct ppa_addr addr = block_to_ppa(dev, blk);
return nvm_erase_ppa(dev, &addr, 1, flags);
return nvm_erase_ppa(dev, p, 1, flags);
}
static struct nvmm_type gen = {
......@@ -626,8 +427,6 @@ static struct nvmm_type gen = {
.submit_io = gen_submit_io,
.erase_blk = gen_erase_blk,
.mark_blk = gen_mark_blk,
.get_area = gen_get_area,
.put_area = gen_put_area,
......
This diff is collapsed.
......@@ -52,8 +52,7 @@ struct rrpc_rq {
};
struct rrpc_block {
unsigned long id;
struct nvm_block *parent;
int id; /* id inside of LUN */
struct rrpc_lun *rlun;
struct list_head prio; /* LUN CG list */
......@@ -83,6 +82,16 @@ struct rrpc_lun {
struct list_head prio_list; /* Blocks that may be GC'ed */
struct list_head wblk_list; /* Queued blocks to be written to */
/* lun block lists */
struct list_head used_list; /* In-use blocks */
struct list_head free_list; /* Not used blocks i.e. released
* and ready for use
*/
struct list_head bb_list; /* Bad blocks. Mutually exclusive with
* free_list and used_list
*/
unsigned int nr_free_blocks; /* Number of unused blocks */
struct work_struct ws_gc;
int reserved_blocks;
......@@ -155,14 +164,14 @@ struct rrpc_rev_addr {
u64 addr;
};
static inline struct rrpc_block *rrpc_get_rblk(struct rrpc_lun *rlun,
int blk_id)
static inline u64 rrpc_blk_to_ppa(struct rrpc *rrpc, struct rrpc_block *rblk)
{
struct rrpc *rrpc = rlun->rrpc;
struct nvm_tgt_dev *dev = rrpc->dev;
int lun_blk = blk_id % dev->geo.blks_per_lun;
struct nvm_geo *geo = &dev->geo;
struct rrpc_lun *rlun = rblk->rlun;
struct nvm_lun *lun = rlun->parent;
return &rlun->blocks[lun_blk];
return (lun->id * geo->sec_per_lun) + (rblk->id * geo->sec_per_blk);
}
static inline sector_t rrpc_get_laddr(struct bio *bio)
......
......@@ -266,8 +266,6 @@ static inline void *nvm_rq_to_pdu(struct nvm_rq *rqdata)
return rqdata + 1;
}
struct nvm_block;
struct nvm_lun {
int id;
......@@ -275,19 +273,6 @@ struct nvm_lun {
int chnl_id;
struct list_head list;
spinlock_t lock;
/* lun block lists */
struct list_head used_list; /* In-use blocks */
struct list_head free_list; /* Not used blocks i.e. released
* and ready for use
*/
struct list_head bb_list; /* Bad blocks. Mutually exclusive with
* free_list and used_list
*/
unsigned int nr_free_blocks; /* Number of unused blocks */
struct nvm_block *blocks;
};
enum {
......@@ -296,15 +281,6 @@ enum {
NVM_BLK_ST_BAD = 0x8, /* Bad block */
};
struct nvm_block {
struct list_head list;
struct nvm_lun *lun;
unsigned long id;
void *priv;
int state;
};
/* system block cpu representation */
struct nvm_sb_info {
unsigned long seqnr;
......@@ -473,21 +449,6 @@ static inline void ppa_set_empty(struct ppa_addr *ppa_addr)
ppa_addr->ppa = ADDR_EMPTY;
}
static inline struct ppa_addr block_to_ppa(struct nvm_dev *dev,
struct nvm_block *blk)
{
struct nvm_geo *geo = &dev->geo;
struct ppa_addr ppa;
struct nvm_lun *lun = blk->lun;
ppa.ppa = 0;
ppa.g.blk = blk->id % geo->blks_per_lun;
ppa.g.lun = lun->lun_id;
ppa.g.ch = lun->chnl_id;
return ppa;
}
static inline int ppa_cmp_blk(struct ppa_addr ppa1, struct ppa_addr ppa2)
{
if (ppa_empty(ppa1) || ppa_empty(ppa2))
......@@ -539,8 +500,7 @@ typedef void (nvmm_unregister_fn)(struct nvm_dev *);
typedef int (nvmm_create_tgt_fn)(struct nvm_dev *, struct nvm_ioctl_create *);
typedef int (nvmm_remove_tgt_fn)(struct nvm_dev *, struct nvm_ioctl_remove *);
typedef int (nvmm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *, int);
typedef void (nvmm_mark_blk_fn)(struct nvm_dev *, struct ppa_addr, int);
typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct ppa_addr *, int);
typedef int (nvmm_get_area_fn)(struct nvm_dev *, sector_t *, sector_t);
typedef void (nvmm_put_area_fn)(struct nvm_dev *, sector_t);
......@@ -557,9 +517,6 @@ struct nvmm_type {
nvmm_submit_io_fn *submit_io;
nvmm_erase_blk_fn *erase_blk;
/* Bad block mgmt */
nvmm_mark_blk_fn *mark_blk;
nvmm_get_area_fn *get_area;
nvmm_put_area_fn *put_area;
......@@ -573,7 +530,6 @@ extern struct nvm_dev *nvm_alloc_dev(int);
extern int nvm_register(struct nvm_dev *);
extern void nvm_unregister(struct nvm_dev *);
extern void nvm_mark_blk(struct nvm_dev *dev, struct ppa_addr ppa, int type);
extern int nvm_set_bb_tbl(struct nvm_dev *dev, struct ppa_addr *ppas,
int nr_ppas, int type);
......@@ -584,7 +540,7 @@ extern int nvm_set_rqd_ppalist(struct nvm_dev *, struct nvm_rq *,
const struct ppa_addr *, int, int);
extern void nvm_free_rqd_ppalist(struct nvm_dev *, struct nvm_rq *);
extern int nvm_erase_ppa(struct nvm_dev *, struct ppa_addr *, int, int);
extern int nvm_erase_blk(struct nvm_dev *, struct nvm_block *, int);
extern int nvm_erase_blk(struct nvm_dev *, struct ppa_addr *, int);
extern void nvm_end_io(struct nvm_rq *, int);
extern int nvm_submit_ppa(struct nvm_dev *, struct ppa_addr *, int, int, int,
void *, int);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment