Skip to content

Commit 8f94d1c

Browse files
ChaitanayaKulkarniaxboe
authored andcommitted
null_blk: create a helper for badblocks
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>
1 parent adb8428 commit 8f94d1c

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

‎drivers/block/null_blk_main.c‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,20 @@ static inline blk_status_t null_handle_throttled(struct nullb_cmd *cmd)
11541154
return sts;
11551155
}
11561156

1157+
static inline blk_status_t null_handle_badblocks(struct nullb_cmd *cmd,
1158+
sector_t sector,
1159+
sector_t nr_sectors)
1160+
{
1161+
struct badblocks *bb = &cmd->nq->dev->badblocks;
1162+
sector_t first_bad;
1163+
int bad_sectors;
1164+
1165+
if (badblocks_check(bb, sector, nr_sectors, &first_bad, &bad_sectors))
1166+
return BLK_STS_IOERR;
1167+
1168+
return BLK_STS_OK;
1169+
}
1170+
11571171
static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
11581172
sector_t nr_sectors, enum req_opf op)
11591173
{
@@ -1172,15 +1186,11 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
11721186
cmd->error = errno_to_blk_status(null_handle_flush(nullb));
11731187
goto out;
11741188
}
1175-
if (nullb->dev->badblocks.shift != -1) {
1176-
int bad_sectors;
1177-
sector_t first_bad;
11781189

1179-
if (badblocks_check(&nullb->dev->badblocks, sector, nr_sectors,
1180-
&first_bad, &bad_sectors)) {
1181-
cmd->error = BLK_STS_IOERR;
1190+
if (nullb->dev->badblocks.shift != -1) {
1191+
cmd->error = null_handle_badblocks(cmd, sector, nr_sectors);
1192+
if (cmd->error != BLK_STS_OK)
11821193
goto out;
1183-
}
11841194
}
11851195

11861196
if (dev->memory_backed) {

0 commit comments

Comments
 (0)