diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index cc8e7c986..e333a7b16 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -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,