Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1396040

[PATCH 11/28] lightnvm: introduce nvm_for_each_lun_ppa() macro

From Matias Bjørling <m@bjorling.me>
Newsgroups linux.kernel
Subject [PATCH 11/28] lightnvm: introduce nvm_for_each_lun_ppa() macro
Date 2016-05-06 20:10 +0200
Message-ID <rvSmo-1A4-73@gated-at.bofh.it> (permalink)
References <rvSml-1A4-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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>
---
 drivers/lightnvm/sysblk.c | 56 +++++++++++++++++++----------------------------
 include/linux/lightnvm.h  |  7 ++++++
 2 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/drivers/lightnvm/sysblk.c b/drivers/lightnvm/sysblk.c
index 7fce588..a48093d 100644
--- a/drivers/lightnvm/sysblk.c
+++ b/drivers/lightnvm/sysblk.c
@@ -631,33 +631,28 @@ 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++) {
-				idx = factory_blk_offset(dev, ch, lun);
-				offset = &f->blks[idx];
+		nvm_for_each_lun_ppa(dev, ppa, ch, lun) {
+			idx = factory_blk_offset(dev, ch, lun);
+			offset = &f->blks[idx];
 
-				blkid = find_first_zero_bit(offset,
-							dev->blks_per_lun);
-				if (blkid >= dev->blks_per_lun)
-					continue;
-				set_bit(blkid, offset);
+			blkid = find_first_zero_bit(offset,
+						dev->blks_per_lun);
+			if (blkid >= dev->blks_per_lun)
+				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,
-								ppa.g.lun,
-								ppa.g.blk);
+			ppa.g.blk = blkid;
+			pr_debug("nvm: erase ppa (%u %u %u)\n",
+							ppa.g.ch,
+							ppa.g.lun,
+							ppa.g.blk);
 
-				erase_list[ppa_cnt] = ppa;
-				ppa_cnt++;
-				done = 0;
+			erase_list[ppa_cnt] = ppa;
+			ppa_cnt++;
+			done = 0;
 
-				if (ppa_cnt == max_ppas)
-					return ppa_cnt;
-			}
+			if (ppa_cnt == max_ppas)
+				return ppa_cnt;
 		}
 	}
 
@@ -684,17 +679,10 @@ 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);
-			if (ret)
-				return ret;
-		}
+	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;
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index 5eabdba..3f25635 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -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;
 
-- 
2.1.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/28] LightNVM fixes for 4.7 Matias Bjørling <m@bjorling.me> - 2016-05-06 20:10 +0200
  [PATCH 04/28] lightnvm: add fpg_size and pfpg_size to struct nvm_dev Matias Bjørling <m@bjorling.me> - 2016-05-06 20:10 +0200
  [PATCH 11/28] lightnvm: introduce nvm_for_each_lun_ppa() macro Matias Bjørling <m@bjorling.me> - 2016-05-06 20:10 +0200
  [PATCH 05/28] lightnvm: move block fold outside of get_bb_tbl() Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  [PATCH 10/28] lightnvm: refactor dev->online_target to global nvm_targets Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  [PATCH 13/28] lightnvm: remove struct factory_blks Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  [PATCH 07/28] lightnvm: calculate rrpc total blocks and sectors up front Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  [PATCH 09/28] lightnvm: rename nvm_targets to nvm_tgt_type Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  [PATCH 06/28] lightnvm: avoid memory leak when lun_map kcalloc fails Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  [PATCH 02/28] lightnvm: handle submit_io failure Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  [PATCH 12/28] lightnvm: refactor device ops->get_bb_tbl() Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  [PATCH 03/28] lightnvm: implement nvm_submit_ppa_list Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  [PATCH 14/28] lightnvm: make nvm_set_rqd_ppalist() aware of vblks Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  [PATCH 01/28] lightnvm: fix "warning: ‘ret’ may be used uninitialized" Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200
  Re: [PATCH 00/28] LightNVM fixes for 4.7 Jens Axboe <axboe@fb.com> - 2016-05-10 16:50 +0200

csiph-web