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

lightnvm: pblk: improve line helpers

The current helper to obtain a line from a ppa returns the line id,
which requires its users to explicitly retrieve the pointer to the line
with the id.

Make 2 different helpers: one returning the line id and one returning
the line directly.
Signed-off-by: default avatarJavier González <javier@cnexlabs.com>
Signed-off-by: default avatarMatias Bjørling <mb@lightnvm.io>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 2cf99bbd
...@@ -32,7 +32,7 @@ static void pblk_line_mark_bb(struct work_struct *work) ...@@ -32,7 +32,7 @@ static void pblk_line_mark_bb(struct work_struct *work)
struct pblk_line *line; struct pblk_line *line;
int pos; int pos;
line = &pblk->lines[pblk_ppa_to_line(*ppa)]; line = pblk_ppa_to_line(pblk, *ppa);
pos = pblk_ppa_to_pos(&dev->geo, *ppa); pos = pblk_ppa_to_pos(&dev->geo, *ppa);
pblk_err(pblk, "failed to mark bb, line:%d, pos:%d\n", pblk_err(pblk, "failed to mark bb, line:%d, pos:%d\n",
...@@ -80,7 +80,7 @@ static void __pblk_end_io_erase(struct pblk *pblk, struct nvm_rq *rqd) ...@@ -80,7 +80,7 @@ static void __pblk_end_io_erase(struct pblk *pblk, struct nvm_rq *rqd)
struct pblk_line *line; struct pblk_line *line;
int pos; int pos;
line = &pblk->lines[pblk_ppa_to_line(rqd->ppa_addr)]; line = pblk_ppa_to_line(pblk, rqd->ppa_addr);
pos = pblk_ppa_to_pos(geo, rqd->ppa_addr); pos = pblk_ppa_to_pos(geo, rqd->ppa_addr);
chunk = &line->chks[pos]; chunk = &line->chks[pos];
...@@ -192,7 +192,6 @@ void pblk_map_invalidate(struct pblk *pblk, struct ppa_addr ppa) ...@@ -192,7 +192,6 @@ void pblk_map_invalidate(struct pblk *pblk, struct ppa_addr ppa)
{ {
struct pblk_line *line; struct pblk_line *line;
u64 paddr; u64 paddr;
int line_id;
#ifdef CONFIG_NVM_PBLK_DEBUG #ifdef CONFIG_NVM_PBLK_DEBUG
/* Callers must ensure that the ppa points to a device address */ /* Callers must ensure that the ppa points to a device address */
...@@ -200,8 +199,7 @@ void pblk_map_invalidate(struct pblk *pblk, struct ppa_addr ppa) ...@@ -200,8 +199,7 @@ void pblk_map_invalidate(struct pblk *pblk, struct ppa_addr ppa)
BUG_ON(pblk_ppa_empty(ppa)); BUG_ON(pblk_ppa_empty(ppa));
#endif #endif
line_id = pblk_ppa_to_line(ppa); line = pblk_ppa_to_line(pblk, ppa);
line = &pblk->lines[line_id];
paddr = pblk_dev_ppa_to_line_addr(pblk, ppa); paddr = pblk_dev_ppa_to_line_addr(pblk, ppa);
__pblk_map_invalidate(pblk, line, paddr); __pblk_map_invalidate(pblk, line, paddr);
...@@ -1430,7 +1428,7 @@ void pblk_ppa_to_line_put(struct pblk *pblk, struct ppa_addr ppa) ...@@ -1430,7 +1428,7 @@ void pblk_ppa_to_line_put(struct pblk *pblk, struct ppa_addr ppa)
{ {
struct pblk_line *line; struct pblk_line *line;
line = &pblk->lines[pblk_ppa_to_line(ppa)]; line = pblk_ppa_to_line(pblk, ppa);
kref_put(&line->ref, pblk_line_put_wq); kref_put(&line->ref, pblk_line_put_wq);
} }
...@@ -1688,7 +1686,7 @@ int pblk_blk_erase_async(struct pblk *pblk, struct ppa_addr ppa) ...@@ -1688,7 +1686,7 @@ int pblk_blk_erase_async(struct pblk *pblk, struct ppa_addr ppa)
struct nvm_geo *geo = &dev->geo; struct nvm_geo *geo = &dev->geo;
pblk_err(pblk, "could not async erase line:%d,blk:%d\n", pblk_err(pblk, "could not async erase line:%d,blk:%d\n",
pblk_ppa_to_line(ppa), pblk_ppa_to_line_id(ppa),
pblk_ppa_to_pos(geo, ppa)); pblk_ppa_to_pos(geo, ppa));
} }
...@@ -2059,8 +2057,7 @@ void pblk_lookup_l2p_seq(struct pblk *pblk, struct ppa_addr *ppas, ...@@ -2059,8 +2057,7 @@ void pblk_lookup_l2p_seq(struct pblk *pblk, struct ppa_addr *ppas,
/* If the L2P entry maps to a line, the reference is valid */ /* If the L2P entry maps to a line, the reference is valid */
if (!pblk_ppa_empty(ppa) && !pblk_addr_in_cache(ppa)) { if (!pblk_ppa_empty(ppa) && !pblk_addr_in_cache(ppa)) {
int line_id = pblk_ppa_to_line(ppa); struct pblk_line *line = pblk_ppa_to_line(pblk, ppa);
struct pblk_line *line = &pblk->lines[line_id];
kref_get(&line->ref); kref_get(&line->ref);
} }
......
...@@ -225,7 +225,7 @@ static int __pblk_rb_update_l2p(struct pblk_rb *rb, unsigned int to_update) ...@@ -225,7 +225,7 @@ static int __pblk_rb_update_l2p(struct pblk_rb *rb, unsigned int to_update)
pblk_update_map_dev(pblk, w_ctx->lba, w_ctx->ppa, pblk_update_map_dev(pblk, w_ctx->lba, w_ctx->ppa,
entry->cacheline); entry->cacheline);
line = &pblk->lines[pblk_ppa_to_line(w_ctx->ppa)]; line = pblk_ppa_to_line(pblk, w_ctx->ppa);
kref_put(&line->ref, pblk_line_put); kref_put(&line->ref, pblk_line_put);
clean_wctx(w_ctx); clean_wctx(w_ctx);
rb->l2p_update = (rb->l2p_update + 1) & (rb->nr_entries - 1); rb->l2p_update = (rb->l2p_update + 1) & (rb->nr_entries - 1);
......
...@@ -252,9 +252,9 @@ static void pblk_end_partial_read(struct nvm_rq *rqd) ...@@ -252,9 +252,9 @@ static void pblk_end_partial_read(struct nvm_rq *rqd)
i = 0; i = 0;
hole = find_first_zero_bit(read_bitmap, nr_secs); hole = find_first_zero_bit(read_bitmap, nr_secs);
do { do {
int line_id = pblk_ppa_to_line(rqd->ppa_list[i]); struct pblk_line *line;
struct pblk_line *line = &pblk->lines[line_id];
line = pblk_ppa_to_line(pblk, rqd->ppa_list[i]);
kref_put(&line->ref, pblk_line_put); kref_put(&line->ref, pblk_line_put);
meta_list[hole].lba = lba_list_media[i]; meta_list[hole].lba = lba_list_media[i];
......
...@@ -113,7 +113,7 @@ static void pblk_map_remaining(struct pblk *pblk, struct ppa_addr *ppa) ...@@ -113,7 +113,7 @@ static void pblk_map_remaining(struct pblk *pblk, struct ppa_addr *ppa)
u64 paddr; u64 paddr;
int done = 0; int done = 0;
line = &pblk->lines[pblk_ppa_to_line(*ppa)]; line = pblk_ppa_to_line(pblk, *ppa);
spin_lock(&line->lock); spin_lock(&line->lock);
while (!done) { while (!done) {
...@@ -171,7 +171,7 @@ static void pblk_prepare_resubmit(struct pblk *pblk, unsigned int sentry, ...@@ -171,7 +171,7 @@ static void pblk_prepare_resubmit(struct pblk *pblk, unsigned int sentry,
/* Decrese the reference count to the line as we will /* Decrese the reference count to the line as we will
* re-map these entries * re-map these entries
*/ */
line = &pblk->lines[pblk_ppa_to_line(w_ctx->ppa)]; line = pblk_ppa_to_line(pblk, w_ctx->ppa);
kref_put(&line->ref, pblk_line_put); kref_put(&line->ref, pblk_line_put);
pos = (pos + 1) & (rb->nr_entries - 1); pos = (pos + 1) & (rb->nr_entries - 1);
......
...@@ -984,11 +984,17 @@ static inline int pblk_pad_distance(struct pblk *pblk) ...@@ -984,11 +984,17 @@ static inline int pblk_pad_distance(struct pblk *pblk)
return geo->mw_cunits * geo->all_luns * geo->ws_opt; return geo->mw_cunits * geo->all_luns * geo->ws_opt;
} }
static inline int pblk_ppa_to_line(struct ppa_addr p) static inline int pblk_ppa_to_line_id(struct ppa_addr p)
{ {
return p.a.blk; return p.a.blk;
} }
static inline struct pblk_line *pblk_ppa_to_line(struct pblk *pblk,
struct ppa_addr p)
{
return &pblk->lines[pblk_ppa_to_line_id(p)];
}
static inline int pblk_ppa_to_pos(struct nvm_geo *geo, struct ppa_addr p) static inline int pblk_ppa_to_pos(struct nvm_geo *geo, struct ppa_addr p)
{ {
return p.a.lun * geo->num_ch + p.a.ch; return p.a.lun * geo->num_ch + p.a.ch;
...@@ -1039,7 +1045,7 @@ static inline struct nvm_chk_meta *pblk_dev_ppa_to_chunk(struct pblk *pblk, ...@@ -1039,7 +1045,7 @@ static inline struct nvm_chk_meta *pblk_dev_ppa_to_chunk(struct pblk *pblk,
{ {
struct nvm_tgt_dev *dev = pblk->dev; struct nvm_tgt_dev *dev = pblk->dev;
struct nvm_geo *geo = &dev->geo; struct nvm_geo *geo = &dev->geo;
struct pblk_line *line = &pblk->lines[pblk_ppa_to_line(p)]; struct pblk_line *line = pblk_ppa_to_line(pblk, p);
int pos = pblk_ppa_to_pos(geo, p); int pos = pblk_ppa_to_pos(geo, p);
return &line->chks[pos]; return &line->chks[pos];
...@@ -1371,8 +1377,7 @@ static inline int pblk_check_io(struct pblk *pblk, struct nvm_rq *rqd) ...@@ -1371,8 +1377,7 @@ static inline int pblk_check_io(struct pblk *pblk, struct nvm_rq *rqd)
int i; int i;
for (i = 0; i < rqd->nr_ppas; i++) { for (i = 0; i < rqd->nr_ppas; i++) {
ppa = ppa_list[i]; line = pblk_ppa_to_line(pblk, ppa_list[i]);
line = &pblk->lines[pblk_ppa_to_line(ppa)];
spin_lock(&line->lock); spin_lock(&line->lock);
if (line->state != PBLK_LINESTATE_OPEN) { if (line->state != PBLK_LINESTATE_OPEN) {
......
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