This patch creates a helper for handling requests when null_blk is memory backed in the null_handle_cmd(). Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@xxxxxxx> --- drivers/block/null_blk_main.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 80c30bcf024f..e75d187c7393 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1194,10 +1194,29 @@ static inline blk_status_t null_handle_badblocks(struct nullb_cmd *cmd) return sts; } +static inline int nullb_handle_memory_backed(struct nullb_cmd *cmd) +{ + struct nullb_device *dev = cmd->nq->dev; + + if (!dev->memory_backed) + return 0; + + if (dev->queue_mode == NULL_Q_BIO) { + if (bio_op(cmd->bio) == REQ_OP_FLUSH) + return null_handle_flush(dev->nullb); + + return null_handle_bio(cmd); + } + + if (req_op(cmd->rq) == REQ_OP_FLUSH) + return null_handle_flush(dev->nullb); + + return null_handle_rq(cmd); +} + static blk_status_t null_handle_cmd(struct nullb_cmd *cmd) { struct nullb_device *dev = cmd->nq->dev; - struct nullb *nullb = dev->nullb; blk_status_t sts; int err = 0; @@ -1209,19 +1228,7 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd) if (sts != BLK_STS_OK) goto out; - if (dev->memory_backed) { - if (dev->queue_mode == NULL_Q_BIO) { - if (bio_op(cmd->bio) == REQ_OP_FLUSH) - err = null_handle_flush(nullb); - else - err = null_handle_bio(cmd); - } else { - if (req_op(cmd->rq) == REQ_OP_FLUSH) - err = null_handle_flush(nullb); - else - err = null_handle_rq(cmd); - } - } + err = nullb_handle_memory_backed(cmd); cmd->error = errno_to_blk_status(err); if (!cmd->error && dev->zoned) { -- 2.21.0