lightnvm: introduce nvm_rq_to_ppa_list
PATCH 1/1 lightnvm: introduce nvm_rq_to_ppa_list
There is a number of places in the lightnvm subsystem where the user iterates over the ppa list. Before iterating, the user must know if it is a single or multiple LBAs due to vector commands using either the nvm_rq ->ppa_addr or ->ppa_list fields on command submission, which leads to open-coding the if/else statement.
Instead of having multiple if/else's, move it into a function that can be called by its users.
--- drivers/lightnvm/pblk-read.c | 4 +--- drivers/lightnvm/pblk-write.c | 5 +---- drivers/lightnvm/pblk.h | 4 +--- include/linux/lightnvm.h | 5 +++++ 4 files changed, 8 insertions(+), 10 deletions(-)
drivers/lightnvm/pblk-read.c +1 -3
@@ -175,11 +175,9 @@ static void __pblk_read_put_line(struct pblk *pblk, struct ppa_addr ppa)static void pblk_read_put_line (struct pblk *pblk,struct nvm_rq *rqd) { -struct ppa_addr *ppa_list; +struct ppa_addr *ppa_list =nvm_rq_to_ppa_list (rqd);int i; - ppa_list = (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; -for (i =0 ; i < rqd->nr_ppas; i++)__pblk_read_put_line (pblk, ppa_list[i]); }
drivers/lightnvm/pblk-write.c +1 -4
@@ -212,10 +212,7 @@ static void pblk_submit_rec(struct work_struct *work)pblk_log_write_err (pblk, rqd); -if (rqd->nr_ppas ==1 ) - ppa_list = &rqd->ppa_addr; -else - ppa_list = rqd->ppa_list; + ppa_list =nvm_rq_to_ppa_list (rqd);pblk_map_remaining (pblk, ppa_list);pblk_queue_resubmit (pblk, c_ctx);
drivers/lightnvm/pblk.h +1 -3
@@ -1335,9 +1335,7 @@ static inline int pblk_boundary_ppa_checks(struct nvm_tgt_dev *tgt_dev,static inline int pblk_check_io (struct pblk *pblk,struct nvm_rq *rqd) {struct nvm_tgt_dev *dev = pblk->dev; -struct ppa_addr *ppa_list; - - ppa_list = (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; +struct ppa_addr *ppa_list =nvm_rq_to_ppa_list (rqd);if (pblk_boundary_ppa_checks (dev, ppa_list, rqd->nr_ppas)) {WARN_ON (1 );
include/linux/lightnvm.h +5 -0
@@ -487,6 +487,11 @@ static inline struct ppa_addr dev_to_generic_addr(struct nvm_dev *dev,return l; } +static inline struct ppa_addr *nvm_rq_to_ppa_list (struct nvm_rq *rqd) +{ +return (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; +} +typedef blk_qc_t (nvm_tgt_make_rq_fn )(struct request_queue *,struct bio *);typedef sector_t (nvm_tgt_capacity_fn )(void *); typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *,
Signature · 1 line
2.11.0
Quoted 84 lines · Matias Bjørling
There is a number of places in the lightnvm subsystem where the user iterates over the ppa list. Before iterating, the user must know if it is a single or multiple LBAs due to vector commands using either the
nvm_rq->ppa_addr or ->ppa_list fields on command submission, which leads to open-coding the if/else statement.Instead of having multiple if/else's, move it into a function that can be called by its users.
Signed-off-by Matias Bjørling <[email protected]>---
drivers/lightnvm/pblk-read.c | 4 +--- drivers/lightnvm/pblk-write.c | 5 +---- drivers/lightnvm/pblk.h | 4 +--- include/linux/lightnvm.h | 5 +++++ 4 files changed, 8 insertions(+), 10 deletions(-)drivers/lightnvm/pblk-read.c +1
-3@@ -175,11 +175,9 @@ static void __pblk_read_put_line(struct pblk *pblk, struct ppa_addr ppa)static void pblk_read_put_line (struct pblk *pblk,struct nvm_rq *rqd) { -struct ppa_addr *ppa_list; +struct ppa_addr *ppa_list =nvm_rq_to_ppa_list (rqd);int i; - ppa_list = (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; -for (i =0 ; i < rqd->nr_ppas; i++)__pblk_read_put_line (pblk, ppa_list[i]); }drivers/lightnvm/pblk-write.c +1
-4@@ -212,10 +212,7 @@ static void pblk_submit_rec(struct work_struct *work)pblk_log_write_err (pblk, rqd); -if (rqd->nr_ppas ==1 ) - ppa_list = &rqd->ppa_addr; -else - ppa_list = rqd->ppa_list; + ppa_list =nvm_rq_to_ppa_list (rqd);pblk_map_remaining (pblk, ppa_list);pblk_queue_resubmit (pblk, c_ctx);drivers/lightnvm/pblk.h +1
-3@@ -1335,9 +1335,7 @@ static inline int pblk_boundary_ppa_checks(struct nvm_tgt_dev *tgt_dev,static inline int pblk_check_io (struct pblk *pblk,struct nvm_rq *rqd) {struct nvm_tgt_dev *dev = pblk->dev; -struct ppa_addr *ppa_list; - - ppa_list = (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; +struct ppa_addr *ppa_list =nvm_rq_to_ppa_list (rqd);if (pblk_boundary_ppa_checks (dev, ppa_list, rqd->nr_ppas)) {WARN_ON (1 );include/linux/lightnvm.h +5
-1@@ -487,6 +487,11 @@ static inline struct ppa_addr dev_to_generic_addr(struct nvm_dev *dev,return l; } +static inline struct ppa_addr *nvm_rq_to_ppa_list (struct nvm_rq *rqd) +{ +return (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; +} +typedef blk_qc_t (nvm_tgt_make_rq_fn )(struct request_queue *,struct bio *);typedef sector_t (nvm_tgt_capacity_fn )(void *); typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *, --
Quoted 1 line
2.11.0
Hans made a similar patch some time ago. There are a number of places where you want to use this helper too, also outside of pblk. You can look at it here [1]
[1] https://github.com/OpenChannelSSD/linux/commits/for-4.20/pblk
fdd88185bfed
17609afb2db9
Javier
Quoted 90 lines · Javier Gonzalez
Quoted 84 lines · Matias Bjørling
There is a number of places in the lightnvm subsystem where the user iterates over the ppa list. Before iterating, the user must know if it is a single or multiple LBAs due to vector commands using either the
nvm_rq->ppa_addr or ->ppa_list fields on command submission, which leads to open-coding the if/else statement.Instead of having multiple if/else's, move it into a function that can be called by its users.
Signed-off-by Matias Bjørling <[email protected]>---
drivers/lightnvm/pblk-read.c | 4 +--- drivers/lightnvm/pblk-write.c | 5 +---- drivers/lightnvm/pblk.h | 4 +--- include/linux/lightnvm.h | 5 +++++ 4 files changed, 8 insertions(+), 10 deletions(-)drivers/lightnvm/pblk-read.c +1
-3@@ -175,11 +175,9 @@ static void __pblk_read_put_line(struct pblk *pblk, struct ppa_addr ppa)static void pblk_read_put_line (struct pblk *pblk,struct nvm_rq *rqd) { -struct ppa_addr *ppa_list; +struct ppa_addr *ppa_list =nvm_rq_to_ppa_list (rqd);int i; - ppa_list = (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; -for (i =0 ; i < rqd->nr_ppas; i++)__pblk_read_put_line (pblk, ppa_list[i]); }drivers/lightnvm/pblk-write.c +1
-4@@ -212,10 +212,7 @@ static void pblk_submit_rec(struct work_struct *work)pblk_log_write_err (pblk, rqd); -if (rqd->nr_ppas ==1 ) - ppa_list = &rqd->ppa_addr; -else - ppa_list = rqd->ppa_list; + ppa_list =nvm_rq_to_ppa_list (rqd);pblk_map_remaining (pblk, ppa_list);pblk_queue_resubmit (pblk, c_ctx);drivers/lightnvm/pblk.h +1
-3@@ -1335,9 +1335,7 @@ static inline int pblk_boundary_ppa_checks(struct nvm_tgt_dev *tgt_dev,static inline int pblk_check_io (struct pblk *pblk,struct nvm_rq *rqd) {struct nvm_tgt_dev *dev = pblk->dev; -struct ppa_addr *ppa_list; - - ppa_list = (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; +struct ppa_addr *ppa_list =nvm_rq_to_ppa_list (rqd);if (pblk_boundary_ppa_checks (dev, ppa_list, rqd->nr_ppas)) {WARN_ON (1 );include/linux/lightnvm.h +5
-1@@ -487,6 +487,11 @@ static inline struct ppa_addr dev_to_generic_addr(struct nvm_dev *dev,return l; } +static inline struct ppa_addr *nvm_rq_to_ppa_list (struct nvm_rq *rqd) +{ +return (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; +} +typedef blk_qc_t (nvm_tgt_make_rq_fn )(struct request_queue *,struct bio *);typedef sector_t (nvm_tgt_capacity_fn )(void *); typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *, --Quoted 1 line
2.11.0
Hans made a similar patch some time ago. There are a number of places where you want to use this helper too, also outside of pblk. You can look at it here [1]
Quoted 7 lines
[1] https://github.com/OpenChannelSSD/linux/commits/for-4.20/pblk
fdd88185bfed 17609afb2db9Javier
I like Hans' better. Hans, could you please merge my patch with yours? I prefer the nvm_rq_to_ppa_list naming, rqdata -> rqd, and if short-hand.
Will do. i'll squash your patch with my two. Your commit message is better, so i hope you don't mind me using it :)
All the best,
Hans
Quoted 110 lines · Matias Bjørling
Quoted 98 lines · Javier Gonzalez
Quoted 86 lines · Matias Bjørling
There is a number of places in the lightnvm subsystem where the user iterates over the ppa list. Before iterating, the user must know if it is a single or multiple LBAs due to vector commands using either the
nvm_rq->ppa_addr or ->ppa_list fields on command submission, which leads to open-coding the if/else statement.Instead of having multiple if/else's, move it into a function that can be called by its users.
Signed-off-by Matias Bjørling <[email protected]>---
drivers/lightnvm/pblk-read.c | 4 +--- drivers/lightnvm/pblk-write.c | 5 +---- drivers/lightnvm/pblk.h | 4 +--- include/linux/lightnvm.h | 5 +++++ 4 files changed, 8 insertions(+), 10 deletions(-)drivers/lightnvm/pblk-read.c +1
-3@@ -175,11 +175,9 @@ static void __pblk_read_put_line(struct pblk *pblk, struct ppa_addr ppa)static void pblk_read_put_line (struct pblk *pblk,struct nvm_rq *rqd) { -struct ppa_addr *ppa_list; +struct ppa_addr *ppa_list =nvm_rq_to_ppa_list (rqd);int i; - ppa_list = (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; -for (i =0 ; i < rqd->nr_ppas; i++)__pblk_read_put_line (pblk, ppa_list[i]);}
drivers/lightnvm/pblk-write.c +1
-4@@ -212,10 +212,7 @@ static void pblk_submit_rec(struct work_struct *work)pblk_log_write_err (pblk, rqd); -if (rqd->nr_ppas ==1 ) - ppa_list = &rqd->ppa_addr; -else - ppa_list = rqd->ppa_list; + ppa_list =nvm_rq_to_ppa_list (rqd);pblk_map_remaining (pblk, ppa_list);pblk_queue_resubmit(pblk, c_ctx);drivers/lightnvm/pblk.h +1
-3@@ -1335,9 +1335,7 @@ static inline int pblk_boundary_ppa_checks(structnvm_tgt_dev *tgt_dev, static inline int pblk_check_io(struct pblk *pblk, struct nvm_rq *rqd) { struct nvm_tgt_dev *dev = pblk->dev; -struct ppa_addr *ppa_list; - - ppa_list = (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; +struct ppa_addr *ppa_list =nvm_rq_to_ppa_list (rqd);if (pblk_boundary_ppa_checks (dev, ppa_list, rqd->nr_ppas)) {WARN_ON(1);include/linux/lightnvm.h +5
-0@@ -487,6 +487,11 @@ static inline struct ppa_addr dev_to_generic_addr(struct nvm_dev *dev, return l; } +static inline struct ppa_addr *nvm_rq_to_ppa_list (struct nvm_rq *rqd) +{ +return (rqd->nr_ppas >1 ) ? rqd->ppa_list : &rqd->ppa_addr; +} +Quoted 6 lines
typedef
blk_qc_t(nvm_tgt_make_rq_fn)(structrequest_queue*, struct bio *);
typedefsector_t(nvm_tgt_capacity_fn)(void *);
typedef void *(nvm_tgt_init_fn)(structnvm_tgt_dev*, struct gendisk *, --
2.11.0Hans made a similar patch some time ago. There are a number of places where you want to use this helper too, also outside of pblk. You can look at it here [1]
Quoted 7 lines
[1] https://github.com/OpenChannelSSD/linux/commits/for-4.20/pblk
fdd88185bfed 17609afb2db9Javier
I like Hans' better. Hans, could you please merge my patch with yours? I prefer the
nvm_rq_to_ppa_listnaming, rqdata -> rqd, and if short-hand.