aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/lightnvm/gennvm.c14
-rw-r--r--include/linux/lightnvm.h2
2 files changed, 15 insertions, 1 deletions
diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c
index c0d0eb2357a8..43c01e0af887 100644
--- a/drivers/lightnvm/gennvm.c
+++ b/drivers/lightnvm/gennvm.c
@@ -60,6 +60,8 @@ static int gennvm_luns_init(struct nvm_dev *dev, struct gen_nvm *gn)
60 lun->vlun.lun_id = i % dev->luns_per_chnl; 60 lun->vlun.lun_id = i % dev->luns_per_chnl;
61 lun->vlun.chnl_id = i / dev->luns_per_chnl; 61 lun->vlun.chnl_id = i / dev->luns_per_chnl;
62 lun->vlun.nr_free_blocks = dev->blks_per_lun; 62 lun->vlun.nr_free_blocks = dev->blks_per_lun;
63 lun->vlun.nr_inuse_blocks = 0;
64 lun->vlun.nr_bad_blocks = 0;
63 } 65 }
64 return 0; 66 return 0;
65} 67}
@@ -87,6 +89,7 @@ static int gennvm_block_bb(struct ppa_addr ppa, int nr_blocks, u8 *blks,
87 } 89 }
88 90
89 list_move_tail(&blk->list, &lun->bb_list); 91 list_move_tail(&blk->list, &lun->bb_list);
92 lun->vlun.nr_bad_blocks++;
90 } 93 }
91 94
92 return 0; 95 return 0;
@@ -139,6 +142,7 @@ static int gennvm_block_map(u64 slba, u32 nlb, __le64 *entries, void *private)
139 list_move_tail(&blk->list, &lun->used_list); 142 list_move_tail(&blk->list, &lun->used_list);
140 blk->type = 1; 143 blk->type = 1;
141 lun->vlun.nr_free_blocks--; 144 lun->vlun.nr_free_blocks--;
145 lun->vlun.nr_inuse_blocks++;
142 } 146 }
143 } 147 }
144 148
@@ -167,8 +171,10 @@ static int gennvm_blocks_init(struct nvm_dev *dev, struct gen_nvm *gn)
167 block->id = cur_block_id++; 171 block->id = cur_block_id++;
168 172
169 /* First block is reserved for device */ 173 /* First block is reserved for device */
170 if (unlikely(lun_iter == 0 && blk_iter == 0)) 174 if (unlikely(lun_iter == 0 && blk_iter == 0)) {
175 lun->vlun.nr_free_blocks--;
171 continue; 176 continue;
177 }
172 178
173 list_add_tail(&block->list, &lun->free_list); 179 list_add_tail(&block->list, &lun->free_list);
174 } 180 }
@@ -266,6 +272,7 @@ static struct nvm_block *gennvm_get_blk(struct nvm_dev *dev,
266 blk->type = 1; 272 blk->type = 1;
267 273
268 lun->vlun.nr_free_blocks--; 274 lun->vlun.nr_free_blocks--;
275 lun->vlun.nr_inuse_blocks++;
269 276
270 spin_unlock(&vlun->lock); 277 spin_unlock(&vlun->lock);
271out: 278out:
@@ -283,16 +290,21 @@ static void gennvm_put_blk(struct nvm_dev *dev, struct nvm_block *blk)
283 case 1: 290 case 1:
284 list_move_tail(&blk->list, &lun->free_list); 291 list_move_tail(&blk->list, &lun->free_list);
285 lun->vlun.nr_free_blocks++; 292 lun->vlun.nr_free_blocks++;
293 lun->vlun.nr_inuse_blocks--;
286 blk->type = 0; 294 blk->type = 0;
287 break; 295 break;
288 case 2: 296 case 2:
289 list_move_tail(&blk->list, &lun->bb_list); 297 list_move_tail(&blk->list, &lun->bb_list);
298 lun->vlun.nr_bad_blocks++;
299 lun->vlun.nr_inuse_blocks--;
290 break; 300 break;
291 default: 301 default:
292 WARN_ON_ONCE(1); 302 WARN_ON_ONCE(1);
293 pr_err("gennvm: erroneous block type (%lu -> %u)\n", 303 pr_err("gennvm: erroneous block type (%lu -> %u)\n",
294 blk->id, blk->type); 304 blk->id, blk->type);
295 list_move_tail(&blk->list, &lun->bb_list); 305 list_move_tail(&blk->list, &lun->bb_list);
306 lun->vlun.nr_bad_blocks++;
307 lun->vlun.nr_inuse_blocks--;
296 } 308 }
297 309
298 spin_unlock(&vlun->lock); 310 spin_unlock(&vlun->lock);
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index cbe288acb1de..831a20cf070c 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -213,7 +213,9 @@ struct nvm_lun {
213 int lun_id; 213 int lun_id;
214 int chnl_id; 214 int chnl_id;
215 215
216 unsigned int nr_inuse_blocks; /* Number of used blocks */
216 unsigned int nr_free_blocks; /* Number of unused blocks */ 217 unsigned int nr_free_blocks; /* Number of unused blocks */
218 unsigned int nr_bad_blocks; /* Number of bad blocks */
217 struct nvm_block *blocks; 219 struct nvm_block *blocks;
218 220
219 spinlock_t lock; 221 spinlock_t lock;