scsi: scsi_debug: Split corrupt_lbas()

Move the inner logic of corrupt_lbas() into a new helper function
__corrupt_lbas() and call it from separate locked and unlocked branches
in corrupt_lbas(). This patch prepares for enabling context analysis.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.garry@linux.dev>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://patch.msgid.link/fe8629d9d7d0a54e8c5c14539953b40c09a6855a.1791924924.git.bvanassche@acm.org
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>
This commit is contained in:
Bart Van Assche 2026-10-13 15:10:04 -07:00 committed by Martin K. Petersen (Oracle)
parent 2bc11c1d45
commit 06bce26589

View File

@ -4984,37 +4984,25 @@ static int resp_write_tape(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
return 0;
}
static int corrupt_lbas(struct sdebug_dev_info *devip, u64 lba, u32 num,
u32 nr_bit_errors, s32 reftag_adjust)
static int __corrupt_lbas(struct sdeb_store_info *sip, u64 lba, u32 num,
u32 nr_bit_errors, s32 reftag_adjust, bool lbp)
{
struct sdeb_store_info *sip = devip2sip(devip, false);
bool meta_data_locked = false;
bool lbp = scsi_debug_lbp();
u32 block, num_mapped, b, i;
int error = 0;
if (sdebug_dev_is_zoned(devip) || sdebug_dix || lbp) {
sdeb_meta_write_lock(sip);
meta_data_locked = true;
}
if (!sip) {
pr_err("can't corrupt with fake_rw\n");
error = -EINVAL;
goto out_unlock;
return -EINVAL;
}
if (num > sdebug_capacity || lba > sdebug_capacity - num) {
pr_err("logical blocks out of bounds: %llu:%u", lba, num);
error = -EINVAL;
goto out_unlock;
return -EINVAL;
}
if (lbp && (!map_state(sip, lba, &num_mapped) || num > num_mapped)) {
pr_err("can't modify unmapped logical blocks: %llu:%u",
lba, num);
error = -EINVAL;
goto out_unlock;
return -EINVAL;
}
/*
@ -5052,9 +5040,25 @@ static int corrupt_lbas(struct sdebug_dev_info *devip, u64 lba, u32 num,
}
sdeb_data_unlock(sip, false);
out_unlock:
if (meta_data_locked)
return 0;
}
static int corrupt_lbas(struct sdebug_dev_info *devip, u64 lba, u32 num,
u32 nr_bit_errors, s32 reftag_adjust)
{
struct sdeb_store_info *sip = devip2sip(devip, false);
const bool lbp = scsi_debug_lbp();
int error = 0;
if (sdebug_dev_is_zoned(devip) || sdebug_dix || lbp) {
sdeb_meta_write_lock(sip);
error = __corrupt_lbas(sip, lba, num, nr_bit_errors,
reftag_adjust, lbp);
sdeb_meta_write_unlock(sip);
} else {
error = __corrupt_lbas(sip, lba, num, nr_bit_errors,
reftag_adjust, lbp);
}
return error;
}