Commit 8f94d1c1 authored by Chaitanya Kulkarni's avatar Chaitanya Kulkarni Committed by Jens Axboe

null_blk: create a helper for badblocks

This patch creates a helper for handling badblocks code in the
null_handle_cmd().
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent adb84284
...@@ -1154,6 +1154,20 @@ static inline blk_status_t null_handle_throttled(struct nullb_cmd *cmd) ...@@ -1154,6 +1154,20 @@ static inline blk_status_t null_handle_throttled(struct nullb_cmd *cmd)
return sts; 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, static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
sector_t nr_sectors, enum req_opf op) sector_t nr_sectors, enum req_opf op)
{ {
...@@ -1172,16 +1186,12 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, ...@@ -1172,16 +1186,12 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
cmd->error = errno_to_blk_status(null_handle_flush(nullb)); cmd->error = errno_to_blk_status(null_handle_flush(nullb));
goto out; goto out;
} }
if (nullb->dev->badblocks.shift != -1) {
int bad_sectors;
sector_t first_bad;
if (badblocks_check(&nullb->dev->badblocks, sector, nr_sectors, if (nullb->dev->badblocks.shift != -1) {
&first_bad, &bad_sectors)) { cmd->error = null_handle_badblocks(cmd, sector, nr_sectors);
cmd->error = BLK_STS_IOERR; if (cmd->error != BLK_STS_OK)
goto out; goto out;
} }
}
if (dev->memory_backed) { if (dev->memory_backed) {
if (dev->queue_mode == NULL_Q_BIO) if (dev->queue_mode == NULL_Q_BIO)
......
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