vdisk_blockio: Add support for unaligned buffers

This patch prevents that the following warning is reported when running the
libiscsi tests against the vdisk_blockio handler:

Refused bio with invalid length 4080 and/or offset 16.

WARNING: CPU: 3 PID: 16022 at /home/bvanassche/software/scst.git/scst/src/dev_handlers/scst_vdisk.c:6180 blockio_exec_rw+0xc89/0xcf0 [scst_vdisk]
Call Trace:
 blockio_exec_write+0x9c/0xe0 [scst_vdisk]
 vdev_do_job+0xe8/0x220 [scst_vdisk]
 blockio_exec+0x140/0x370 [scst_vdisk]
 scst_do_real_exec+0xf4/0x610 [scst]
 scst_exec_check_blocking+0x24e/0x6b0 [scst]
 scst_exec_check_sn+0x222/0x6c0 [scst]
 scst_process_active_cmd+0xdff/0x31c0 [scst]
 scst_cmd_thread+0x36f/0xb60 [scst]
 kthread+0x1bc/0x210
 ret_from_fork+0x24/0x30

See also https://github.com/sahlberg/libiscsi/issues/302.


git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8700 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2019-12-23 19:04:18 +00:00
parent 105ac34449
commit 85f8ac3a1e

View File

@@ -3312,6 +3312,14 @@ static enum compl_status_e fileio_exec_async(struct vdisk_cmd_params *p)
}
#endif
static void blockio_on_free_cmd(struct scst_cmd *cmd)
{
if (!scst_cmd_get_dh_data_buff_alloced(cmd))
return;
sgv_pool_free(cmd->sgv, &cmd->dev->dev_mem_lim);
cmd->sgv = NULL;
}
static void vdisk_on_free_cmd_params(const struct vdisk_cmd_params *p)
{
if (!p->execute_async) {
@@ -3403,6 +3411,29 @@ out:
return res;
}
static int blockio_alloc(struct scst_cmd *cmd)
{
struct scst_tgt_dev *tgt_dev = cmd->tgt_dev;
struct sgv_pool *pool = tgt_dev->pools[raw_smp_processor_id()];
int res = SCST_CMD_STATE_DEFAULT;
if (cmd->sg && (cmd->sg->offset & 511) == 0)
return res;
WARN_ON_ONCE(cmd->sgv);
cmd->sg = sgv_pool_alloc(pool, cmd->bufflen, cmd->cmd_gfp_mask, 0,
&cmd->sg_cnt, &cmd->sgv,
&cmd->dev->dev_mem_lim, NULL);
if (!cmd->sg) {
res = SCST_CMD_STATE_STOP;
goto out;
}
scst_cmd_set_dh_data_buff_alloced(cmd);
out:
return res;
}
static enum scst_exec_res blockio_exec(struct scst_cmd *cmd)
{
struct scst_vdisk_dev *virt_dev = cmd->dev->dh_priv;
@@ -9995,7 +10026,9 @@ static struct scst_dev_type vdisk_blk_devtype = {
.attach_tgt = vdisk_attach_tgt,
.detach_tgt = vdisk_detach_tgt,
.parse = non_fileio_parse,
.dev_alloc_data_buf = blockio_alloc,
.exec = blockio_exec,
.on_free_cmd = blockio_on_free_cmd,
.on_alua_state_change_start = blockio_on_alua_state_change_start,
.on_alua_state_change_finish = blockio_on_alua_state_change_finish,
.task_mgmt_fn_done = vdisk_task_mgmt_fn_done,