Skip to content

Commit 4101f0a

Browse files
Christoph HellwigNicholas Bellinger
authored andcommitted
target: always allocate a single task
Simply transport_generic_new_cmd to only allocate a single task. For normal unidirection commands nothing changes except that the code is a lot simpler now. Any BIDI support that used to work will stop now for the next few patches at least. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent 6bb35e0 commit 4101f0a

File tree

1 file changed

+37
-120
lines changed

1 file changed

+37
-120
lines changed

drivers/target/target_core_transport.c

Lines changed: 37 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,29 +1474,6 @@ static inline void transport_generic_prepare_cdb(
14741474
}
14751475
}
14761476

1477-
static struct se_task *
1478-
transport_generic_get_task(struct se_cmd *cmd,
1479-
enum dma_data_direction data_direction)
1480-
{
1481-
struct se_task *task;
1482-
struct se_device *dev = cmd->se_dev;
1483-
1484-
task = dev->transport->alloc_task(cmd->t_task_cdb);
1485-
if (!task) {
1486-
pr_err("Unable to allocate struct se_task\n");
1487-
return NULL;
1488-
}
1489-
1490-
INIT_LIST_HEAD(&task->t_list);
1491-
INIT_LIST_HEAD(&task->t_execute_list);
1492-
INIT_LIST_HEAD(&task->t_state_list);
1493-
init_completion(&task->task_stop_comp);
1494-
task->task_se_cmd = cmd;
1495-
task->task_data_direction = data_direction;
1496-
1497-
return task;
1498-
}
1499-
15001477
static int transport_generic_cmd_sequencer(struct se_cmd *, unsigned char *);
15011478

15021479
/*
@@ -3704,68 +3681,6 @@ transport_generic_get_mem(struct se_cmd *cmd)
37043681
return -ENOMEM;
37053682
}
37063683

3707-
/*
3708-
* Break up cmd into chunks transport can handle
3709-
*/
3710-
static int
3711-
transport_allocate_data_tasks(struct se_cmd *cmd,
3712-
enum dma_data_direction data_direction,
3713-
struct scatterlist *cmd_sg, unsigned int sgl_nents)
3714-
{
3715-
struct se_device *dev = cmd->se_dev;
3716-
struct se_dev_attrib *attr = &dev->se_sub_dev->se_dev_attrib;
3717-
sector_t sectors;
3718-
struct se_task *task;
3719-
unsigned long flags;
3720-
3721-
if (transport_cmd_get_valid_sectors(cmd) < 0)
3722-
return -EINVAL;
3723-
3724-
sectors = DIV_ROUND_UP(cmd->data_length, attr->block_size);
3725-
3726-
BUG_ON(cmd->data_length % attr->block_size);
3727-
BUG_ON(sectors > attr->max_sectors);
3728-
3729-
task = transport_generic_get_task(cmd, data_direction);
3730-
if (!task)
3731-
return -ENOMEM;
3732-
3733-
task->task_sg = cmd_sg;
3734-
task->task_sg_nents = sgl_nents;
3735-
3736-
spin_lock_irqsave(&cmd->t_state_lock, flags);
3737-
list_add_tail(&task->t_list, &cmd->t_task_list);
3738-
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
3739-
3740-
return 1;
3741-
}
3742-
3743-
static int
3744-
transport_allocate_control_task(struct se_cmd *cmd)
3745-
{
3746-
struct se_task *task;
3747-
unsigned long flags;
3748-
3749-
/* Workaround for handling zero-length control CDBs */
3750-
if ((cmd->se_cmd_flags & SCF_SCSI_CONTROL_SG_IO_CDB) &&
3751-
!cmd->data_length)
3752-
return 0;
3753-
3754-
task = transport_generic_get_task(cmd, cmd->data_direction);
3755-
if (!task)
3756-
return -ENOMEM;
3757-
3758-
task->task_sg = cmd->t_data_sg;
3759-
task->task_sg_nents = cmd->t_data_nents;
3760-
3761-
spin_lock_irqsave(&cmd->t_state_lock, flags);
3762-
list_add_tail(&task->t_list, &cmd->t_task_list);
3763-
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
3764-
3765-
/* Success! Return number of tasks allocated */
3766-
return 1;
3767-
}
3768-
37693684
/*
37703685
* Allocate any required resources to execute the command. For writes we
37713686
* might not have the payload yet, so notify the fabric via a call to
@@ -3774,8 +3689,8 @@ transport_allocate_control_task(struct se_cmd *cmd)
37743689
int transport_generic_new_cmd(struct se_cmd *cmd)
37753690
{
37763691
struct se_device *dev = cmd->se_dev;
3777-
int task_cdbs, task_cdbs_bidi = 0;
3778-
int set_counts = 1;
3692+
struct se_task *task;
3693+
unsigned long flags;
37793694
int ret = 0;
37803695

37813696
/*
@@ -3790,35 +3705,9 @@ int transport_generic_new_cmd(struct se_cmd *cmd)
37903705
goto out_fail;
37913706
}
37923707

3793-
/*
3794-
* For BIDI command set up the read tasks first.
3795-
*/
3796-
if (cmd->t_bidi_data_sg &&
3797-
dev->transport->transport_type != TRANSPORT_PLUGIN_PHBA_PDEV) {
3798-
BUG_ON(!(cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB));
3799-
3800-
task_cdbs_bidi = transport_allocate_data_tasks(cmd,
3801-
DMA_FROM_DEVICE, cmd->t_bidi_data_sg,
3802-
cmd->t_bidi_data_nents);
3803-
if (task_cdbs_bidi <= 0)
3804-
goto out_fail;
3805-
3806-
atomic_inc(&cmd->t_fe_count);
3807-
atomic_inc(&cmd->t_se_count);
3808-
set_counts = 0;
3809-
}
3810-
3811-
if (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB) {
3812-
task_cdbs = transport_allocate_data_tasks(cmd,
3813-
cmd->data_direction, cmd->t_data_sg,
3814-
cmd->t_data_nents);
3815-
} else {
3816-
task_cdbs = transport_allocate_control_task(cmd);
3817-
}
3818-
3819-
if (task_cdbs < 0)
3820-
goto out_fail;
3821-
else if (!task_cdbs && (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB)) {
3708+
/* Workaround for handling zero-length control CDBs */
3709+
if ((cmd->se_cmd_flags & SCF_SCSI_CONTROL_SG_IO_CDB) &&
3710+
!cmd->data_length) {
38223711
spin_lock_irq(&cmd->t_state_lock);
38233712
cmd->t_state = TRANSPORT_COMPLETE;
38243713
cmd->transport_state |= CMD_T_ACTIVE;
@@ -3836,12 +3725,40 @@ int transport_generic_new_cmd(struct se_cmd *cmd)
38363725
return 0;
38373726
}
38383727

3839-
if (set_counts) {
3840-
atomic_inc(&cmd->t_fe_count);
3841-
atomic_inc(&cmd->t_se_count);
3728+
if (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB) {
3729+
struct se_dev_attrib *attr = &dev->se_sub_dev->se_dev_attrib;
3730+
3731+
if (transport_cmd_get_valid_sectors(cmd) < 0)
3732+
return -EINVAL;
3733+
3734+
BUG_ON(cmd->data_length % attr->block_size);
3735+
BUG_ON(DIV_ROUND_UP(cmd->data_length, attr->block_size) >
3736+
attr->max_sectors);
3737+
}
3738+
3739+
task = dev->transport->alloc_task(cmd->t_task_cdb);
3740+
if (!task) {
3741+
pr_err("Unable to allocate struct se_task\n");
3742+
goto out_fail;
38423743
}
38433744

3844-
cmd->t_task_list_num = (task_cdbs + task_cdbs_bidi);
3745+
INIT_LIST_HEAD(&task->t_list);
3746+
INIT_LIST_HEAD(&task->t_execute_list);
3747+
INIT_LIST_HEAD(&task->t_state_list);
3748+
init_completion(&task->task_stop_comp);
3749+
task->task_se_cmd = cmd;
3750+
task->task_data_direction = cmd->data_direction;
3751+
task->task_sg = cmd->t_data_sg;
3752+
task->task_sg_nents = cmd->t_data_nents;
3753+
3754+
spin_lock_irqsave(&cmd->t_state_lock, flags);
3755+
list_add_tail(&task->t_list, &cmd->t_task_list);
3756+
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
3757+
3758+
atomic_inc(&cmd->t_fe_count);
3759+
atomic_inc(&cmd->t_se_count);
3760+
3761+
cmd->t_task_list_num = 1;
38453762
atomic_set(&cmd->t_task_cdbs_left, cmd->t_task_list_num);
38463763
atomic_set(&cmd->t_task_cdbs_ex_left, cmd->t_task_list_num);
38473764

0 commit comments

Comments
 (0)