Skip to content

Commit

Permalink
null_blk: create a helper for mem-backed ops
Browse files Browse the repository at this point in the history
This patch creates a helper for handling requests when null_blk is
memory backed in the null_handle_cmd(). Although the helper is very
simple right now, it makes the code flow consistent with the rest of
code in the null_handle_cmd() and provides a uniform code structure
for future code.

Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Chaitanya Kulkarni <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
ChaitanayaKulkarni authored and axboe committed Aug 23, 2019
1 parent 8f94d1c commit 7ea88e2
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions drivers/block/null_blk_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,13 +1168,26 @@ static inline blk_status_t null_handle_badblocks(struct nullb_cmd *cmd,
return BLK_STS_OK;
}

static inline blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd,
enum req_opf op)
{
struct nullb_device *dev = cmd->nq->dev;
int err;

if (dev->queue_mode == NULL_Q_BIO)
err = null_handle_bio(cmd);
else
err = null_handle_rq(cmd);

return errno_to_blk_status(err);
}

static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
sector_t nr_sectors, enum req_opf op)
{
struct nullb_device *dev = cmd->nq->dev;
struct nullb *nullb = dev->nullb;
blk_status_t sts;
int err = 0;

if (test_bit(NULLB_DEV_FL_THROTTLED, &dev->flags)) {
sts = null_handle_throttled(cmd);
Expand All @@ -1193,14 +1206,8 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
goto out;
}

if (dev->memory_backed) {
if (dev->queue_mode == NULL_Q_BIO)
err = null_handle_bio(cmd);
else
err = null_handle_rq(cmd);
}

cmd->error = errno_to_blk_status(err);
if (dev->memory_backed)
cmd->error = null_handle_memory_backed(cmd, op);

if (!cmd->error && dev->zoned) {
if (op == REQ_OP_WRITE)
Expand Down

0 comments on commit 7ea88e2

Please sign in to comment.