lightnvm: introduce nvm_for_each_lun_ppa() macro

Users that wish to iterate all luns on a device. Must create a
struct ppa_addr and separate iterators for channels and luns. To set the
iterators, two loops are required, one to iterate channels, and another
to iterate luns. This leads to decrease in readability.

Introduce nvm_for_each_lun_ppa, which implements the nested loop and
sets ppa, channel, and lun variable for each loop body, eliminating
the boilerplate code.

Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@fb.com>
This commit is contained in:
Matias Bjørling 2016-05-06 20:03:04 +02:00 committed by Jens Axboe
parent 6f8645cba5
commit 5136061ce7
2 changed files with 29 additions and 34 deletions

View File

@ -631,8 +631,7 @@ static int nvm_fact_get_blks(struct nvm_dev *dev, struct ppa_addr *erase_list,
while (!done) {
done = 1;
for (ch = 0; ch < dev->nr_chnls; ch++) {
for (lun = 0; lun < dev->luns_per_chnl; lun++) {
nvm_for_each_lun_ppa(dev, ppa, ch, lun) {
idx = factory_blk_offset(dev, ch, lun);
offset = &f->blks[idx];
@ -642,9 +641,6 @@ static int nvm_fact_get_blks(struct nvm_dev *dev, struct ppa_addr *erase_list,
continue;
set_bit(blkid, offset);
ppa.ppa = 0;
ppa.g.ch = ch;
ppa.g.lun = lun;
ppa.g.blk = blkid;
pr_debug("nvm: erase ppa (%u %u %u)\n",
ppa.g.ch,
@ -659,7 +655,6 @@ static int nvm_fact_get_blks(struct nvm_dev *dev, struct ppa_addr *erase_list,
return ppa_cnt;
}
}
}
return ppa_cnt;
}
@ -684,18 +679,11 @@ static int nvm_fact_select_blks(struct nvm_dev *dev, struct factory_blks *f)
int ch, lun, ret;
struct ppa_addr ppa;
ppa.ppa = 0;
for (ch = 0; ch < dev->nr_chnls; ch++) {
for (lun = 0; lun < dev->luns_per_chnl; lun++) {
ppa.g.ch = ch;
ppa.g.lun = lun;
ret = nvm_fact_get_bb_tbl(dev, ppa, nvm_factory_blks,
f);
nvm_for_each_lun_ppa(dev, ppa, ch, lun) {
ret = nvm_fact_get_bb_tbl(dev, ppa, nvm_factory_blks, f);
if (ret)
return ret;
}
}
return 0;
}

View File

@ -559,6 +559,13 @@ extern int nvm_update_sysblock(struct nvm_dev *, struct nvm_sb_info *);
extern int nvm_init_sysblock(struct nvm_dev *, struct nvm_sb_info *);
extern int nvm_dev_factory(struct nvm_dev *, int flags);
#define nvm_for_each_lun_ppa(dev, ppa, chid, lunid) \
for ((chid) = 0, (ppa).ppa = 0; (chid) < (dev)->nr_chnls; \
(chid)++, (ppa).g.ch = (chid)) \
for ((lunid) = 0; (lunid) < (dev)->luns_per_chnl; \
(lunid)++, (ppa).g.lun = (lunid))
#else /* CONFIG_NVM */
struct nvm_dev_ops;