Skip to content

Commit 6fd0ce7

Browse files
Mike ChristieNicholas Bellinger
authored andcommitted
tcmu: prep queue_cmd_ring to be used by unmap wq
In the next patches we will call queue_cmd_ring from the submitting context and also the completion path. This changes the queue_cmd_ring return code so in the next patches we can return a sense_reason_t and also signal if a command was requeued. Signed-off-by: Mike Christie <mchristi@redhat.com> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 3e60913 commit 6fd0ce7

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

drivers/target/target_core_user.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,16 @@ static int tcmu_setup_cmd_timer(struct tcmu_cmd *tcmu_cmd)
776776
return 0;
777777
}
778778

779-
static sense_reason_t
780-
tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
779+
/**
780+
* queue_cmd_ring - queue cmd to ring or internally
781+
* @tcmu_cmd: cmd to queue
782+
* @scsi_err: TCM error code if failure (-1) returned.
783+
*
784+
* Returns:
785+
* -1 we cannot queue internally or to the ring.
786+
* 0 success
787+
*/
788+
static sense_reason_t queue_cmd_ring(struct tcmu_cmd *tcmu_cmd, int *scsi_err)
781789
{
782790
struct tcmu_dev *udev = tcmu_cmd->tcmu_dev;
783791
struct se_cmd *se_cmd = tcmu_cmd->se_cmd;
@@ -791,8 +799,12 @@ tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
791799
bool copy_to_data_area;
792800
size_t data_length = tcmu_cmd_get_data_length(tcmu_cmd);
793801

794-
if (test_bit(TCMU_DEV_BIT_BROKEN, &udev->flags))
795-
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
802+
*scsi_err = TCM_NO_SENSE;
803+
804+
if (test_bit(TCMU_DEV_BIT_BROKEN, &udev->flags)) {
805+
*scsi_err = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
806+
return -1;
807+
}
796808

797809
/*
798810
* Must be a certain minimum size for response sense info, but
@@ -819,7 +831,8 @@ tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
819831
"cmd ring/data area\n", command_size, data_length,
820832
udev->cmdr_size, udev->data_size);
821833
mutex_unlock(&udev->cmdr_lock);
822-
return TCM_INVALID_CDB_FIELD;
834+
*scsi_err = TCM_INVALID_CDB_FIELD;
835+
return -1;
823836
}
824837

825838
while (!is_ring_space_avail(udev, tcmu_cmd, command_size, data_length)) {
@@ -845,7 +858,8 @@ tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
845858
finish_wait(&udev->wait_cmdr, &__wait);
846859
if (!ret) {
847860
pr_warn("tcmu: command timed out\n");
848-
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
861+
*scsi_err = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
862+
return -1;
849863
}
850864

851865
mutex_lock(&udev->cmdr_lock);
@@ -902,7 +916,9 @@ tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
902916
if (ret) {
903917
tcmu_cmd_free_data(tcmu_cmd, tcmu_cmd->dbi_cnt);
904918
mutex_unlock(&udev->cmdr_lock);
905-
return TCM_OUT_OF_RESOURCES;
919+
920+
*scsi_err = TCM_OUT_OF_RESOURCES;
921+
return -1;
906922
}
907923
entry->hdr.cmd_id = tcmu_cmd->cmd_id;
908924

@@ -933,27 +949,23 @@ tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
933949
mod_timer(&udev->timeout, round_jiffies_up(jiffies +
934950
msecs_to_jiffies(udev->cmd_time_out)));
935951

936-
return TCM_NO_SENSE;
952+
return 0;
937953
}
938954

939955
static sense_reason_t
940956
tcmu_queue_cmd(struct se_cmd *se_cmd)
941957
{
942958
struct tcmu_cmd *tcmu_cmd;
943-
sense_reason_t ret;
959+
sense_reason_t scsi_ret;
944960

945961
tcmu_cmd = tcmu_alloc_cmd(se_cmd);
946962
if (!tcmu_cmd)
947963
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
948964

949-
ret = tcmu_queue_cmd_ring(tcmu_cmd);
950-
if (ret != TCM_NO_SENSE) {
951-
pr_err("TCMU: Could not queue command\n");
952-
965+
if (queue_cmd_ring(tcmu_cmd, &scsi_ret) < 0)
953966
tcmu_free_cmd(tcmu_cmd);
954-
}
955967

956-
return ret;
968+
return scsi_ret;
957969
}
958970

959971
static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry *entry)

0 commit comments

Comments
 (0)