Skip to content

Commit

Permalink
null_blk: create a helper for badblocks
Browse files Browse the repository at this point in the history
This patch creates a helper for handling badblocks code in the
null_handle_cmd().

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Chaitanya Kulkarni authored and Jens Axboe committed Aug 23, 2019
1 parent adb8428 commit 8f94d1c
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions drivers/block/null_blk_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,20 @@ static inline blk_status_t null_handle_throttled(struct nullb_cmd *cmd)
return sts;
}

static inline blk_status_t null_handle_badblocks(struct nullb_cmd *cmd,
sector_t sector,
sector_t nr_sectors)
{
struct badblocks *bb = &cmd->nq->dev->badblocks;
sector_t first_bad;
int bad_sectors;

if (badblocks_check(bb, sector, nr_sectors, &first_bad, &bad_sectors))
return BLK_STS_IOERR;

return BLK_STS_OK;
}

static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
sector_t nr_sectors, enum req_opf op)
{
Expand All @@ -1172,15 +1186,11 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
cmd->error = errno_to_blk_status(null_handle_flush(nullb));
goto out;
}
if (nullb->dev->badblocks.shift != -1) {
int bad_sectors;
sector_t first_bad;

if (badblocks_check(&nullb->dev->badblocks, sector, nr_sectors,
&first_bad, &bad_sectors)) {
cmd->error = BLK_STS_IOERR;
if (nullb->dev->badblocks.shift != -1) {
cmd->error = null_handle_badblocks(cmd, sector, nr_sectors);
if (cmd->error != BLK_STS_OK)
goto out;
}
}

if (dev->memory_backed) {
Expand Down

0 comments on commit 8f94d1c

Please sign in to comment.