aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/lightnvm
diff options
context:
space:
mode:
authorJavier Gonzalez <javier@javigon.com>2015-11-20 07:47:56 -0500
committerJens Axboe <axboe@fb.com>2015-11-20 10:33:20 -0500
commit0b59733b95f9d7af6bee6e6a4d0d444eb694c514 (patch)
tree8cc6efa06ebc51e8fc15021c46821be456913f23 /drivers/lightnvm
parent47b3115ae7b799be8b77b0f024215ad4f68d6460 (diff)
lightnvm: keep track of block counts
Maintain number of in use blocks, free blocks, and bad blocks in a per lun basis. This allows the upper layers to get information about the state of each lun. Also, account for blocks reserved to the device on the free block count. nr_free_blocks matches now the actual number of blocks on the free list when the device is booted. Signed-off-by: Javier Gonzalez <javier@cnexlabs.com> Signed-off-by: Matias Bjørling <m@bjorling.me> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/lightnvm')
-rw-r--r--drivers/lightnvm/gennvm.c14
1 files changed, 13 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);