Skip to content

Commit 79cdb13

Browse files
mikechristieBrian Maly
authored andcommitted
vhost-scsi: Stop duplicating se_cmd fields
When setting up the command we will initially set values like lun and data direction on the vhost scsi command. We then pass them to LIO which stores them again on the LIO se_cmd. The se_cmd is actually stored in the vhost scsi command so we are storing these values twice on the same struct. So this patch has stop duplicating the storing of SCSI values like lun, data dir, data len, cdb, etc on the vhost scsi command and just pass them to LIO which will store them on the se_cmd. Signed-off-by: Mike Christie <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Stefan Hajnoczi <[email protected]> (cherry picked from commit ddc5b5f68ec553a037a822f81150acbbdefa3ad1) Orabug: 37980690 Conflicts: - commit 48ae70d ("vhost_scsi: make SCSI cmd completion per vq") is not merged in UEK7 so we have to handle the tvc_vhost removal like is done in vhost_scsi_release_cmd_res where we get to the vs pointer from the cmd's vq pointer. Signed-off-by: Mike Christie <[email protected]> Reviewed-by: Dongli Zhang <[email protected]> Signed-off-by: Brian Maly <[email protected]>
1 parent 4100fe1 commit 79cdb13

File tree

1 file changed

+40
-60
lines changed

1 file changed

+40
-60
lines changed

drivers/vhost/scsi.c

Lines changed: 40 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,11 @@ struct vhost_scsi_inflight {
106106
struct vhost_scsi_cmd {
107107
/* Descriptor from vhost_get_vq_desc() for virt_queue segment */
108108
int tvc_vq_desc;
109-
/* virtio-scsi initiator task attribute */
110-
int tvc_task_attr;
111109
/* virtio-scsi response incoming iovecs */
112110
int tvc_in_iovs;
113-
/* virtio-scsi initiator data direction */
114-
enum dma_data_direction tvc_data_direction;
115-
/* Expected data transfer length from virtio-scsi header */
116-
u32 tvc_exp_data_len;
117-
/* The Tag from include/linux/virtio_scsi.h:struct virtio_scsi_cmd_req */
118-
u64 tvc_tag;
119111
/* The number of scatterlists associated with this cmd */
120112
u32 tvc_sgl_count;
121113
u32 tvc_prot_sgl_count;
122-
/* Saved unpacked SCSI LUN for vhost_scsi_target_queue_cmd() */
123-
u32 tvc_lun;
124114
u32 copied_iov:1;
125115
const void *saved_iter_addr;
126116
struct iov_iter saved_iter;
@@ -130,16 +120,10 @@ struct vhost_scsi_cmd {
130120
struct sg_table prot_table;
131121
/* Pointer to response header iovec */
132122
struct iovec *tvc_resp_iov;
133-
/* Pointer to vhost_scsi for our device */
134-
struct vhost_scsi *tvc_vhost;
135123
/* Pointer to vhost_virtqueue for the cmd */
136124
struct vhost_virtqueue *tvc_vq;
137-
/* Pointer to vhost nexus memory */
138-
struct vhost_scsi_nexus *tvc_nexus;
139125
/* The TCM I/O descriptor that is accessed via container_of() */
140126
struct se_cmd tvc_se_cmd;
141-
/* Copy of the incoming SCSI command descriptor block (CDB) */
142-
unsigned char tvc_cdb[VHOST_SCSI_MAX_CDB_SIZE];
143127
/* Sense buffer that will be mapped into outgoing status */
144128
unsigned char tvc_sense_buf[TRANSPORT_SENSE_BUFFER];
145129
/* Completed commands list, serviced from vhost worker thread */
@@ -385,9 +369,9 @@ static void vhost_scsi_release_cmd_res(struct se_cmd *se_cmd)
385369
{
386370
struct vhost_scsi_cmd *tv_cmd = container_of(se_cmd,
387371
struct vhost_scsi_cmd, tvc_se_cmd);
388-
struct vhost_scsi *vs = tv_cmd->tvc_vhost;
389372
struct vhost_scsi_virtqueue *svq = container_of(tv_cmd->tvc_vq,
390373
struct vhost_scsi_virtqueue, vq);
374+
struct vhost_scsi *vs = svq->vs;
391375
struct vhost_scsi_inflight *inflight = tv_cmd->inflight;
392376
struct scatterlist *sg;
393377
struct page *page;
@@ -441,7 +425,10 @@ static void vhost_scsi_release_cmd(struct se_cmd *se_cmd)
441425
} else {
442426
struct vhost_scsi_cmd *cmd = container_of(se_cmd,
443427
struct vhost_scsi_cmd, tvc_se_cmd);
444-
struct vhost_scsi *vs = cmd->tvc_vhost;
428+
struct vhost_scsi_virtqueue *svq = container_of(cmd->tvc_vq,
429+
struct vhost_scsi_virtqueue,
430+
vq);
431+
struct vhost_scsi *vs = svq->vs;
445432

446433
llist_add(&cmd->tvc_completion_list, &vs->vs_completion_list);
447434
vhost_work_queue(&vs->dev, &vs->vs_completion_work);
@@ -685,24 +672,15 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
685672
}
686673

687674
static struct vhost_scsi_cmd *
688-
vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
689-
unsigned char *cdb, u64 scsi_tag, u16 lun, u8 task_attr,
690-
u32 exp_data_len, int data_direction)
675+
vhost_scsi_get_cmd(struct vhost_virtqueue *vq, u64 scsi_tag)
691676
{
692677
struct vhost_scsi_virtqueue *svq = container_of(vq,
693678
struct vhost_scsi_virtqueue, vq);
694679
struct vhost_scsi_cmd *cmd;
695-
struct vhost_scsi_nexus *tv_nexus;
696680
struct scatterlist *sgl, *prot_sgl;
697681
struct iovec *tvc_resp_iov;
698682
int tag;
699683

700-
tv_nexus = tpg->tpg_nexus;
701-
if (!tv_nexus) {
702-
pr_err("Unable to locate active struct vhost_scsi_nexus\n");
703-
return ERR_PTR(-EIO);
704-
}
705-
706684
tag = sbitmap_get(&svq->scsi_tags);
707685
if (tag < 0) {
708686
pr_warn_once("Guest sent too many cmds. Returning TASK_SET_FULL.\n");
@@ -717,17 +695,9 @@ vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
717695
cmd->sgl = sgl;
718696
cmd->prot_sgl = prot_sgl;
719697
cmd->tvc_se_cmd.map_tag = tag;
720-
cmd->tvc_tag = scsi_tag;
721-
cmd->tvc_lun = lun;
722-
cmd->tvc_task_attr = task_attr;
723-
cmd->tvc_exp_data_len = exp_data_len;
724-
cmd->tvc_data_direction = data_direction;
725-
cmd->tvc_nexus = tv_nexus;
726698
cmd->inflight = vhost_scsi_get_inflight(vq);
727699
cmd->tvc_resp_iov = tvc_resp_iov;
728700

729-
memcpy(cmd->tvc_cdb, cdb, VHOST_SCSI_MAX_CDB_SIZE);
730-
731701
return cmd;
732702
}
733703

@@ -847,15 +817,16 @@ vhost_scsi_calc_sgls(struct iov_iter *iter, size_t bytes, int max_sgls)
847817

848818
static int
849819
vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
850-
struct sg_table *sg_table, int sg_count)
820+
struct sg_table *sg_table, int sg_count,
821+
int data_dir)
851822
{
852823
size_t len = iov_iter_count(iter);
853824
unsigned int nbytes = 0;
854825
struct scatterlist *sg;
855826
struct page *page;
856827
int i, ret;
857828

858-
if (cmd->tvc_data_direction == DMA_FROM_DEVICE) {
829+
if (data_dir == DMA_FROM_DEVICE) {
859830
cmd->saved_iter_addr = dup_iter(&cmd->saved_iter, iter,
860831
GFP_KERNEL);
861832
if (!cmd->saved_iter_addr)
@@ -872,7 +843,7 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
872843
nbytes = min_t(unsigned int, PAGE_SIZE, len);
873844
sg_set_page(sg, page, nbytes, 0);
874845

875-
if (cmd->tvc_data_direction == DMA_TO_DEVICE &&
846+
if (data_dir == DMA_TO_DEVICE &&
876847
copy_page_from_iter(page, 0, nbytes, iter) != nbytes) {
877848
ret = -EFAULT;
878849
goto err;
@@ -917,11 +888,10 @@ vhost_scsi_map_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
917888
}
918889

919890
static int
920-
vhost_scsi_mapal(struct vhost_scsi_cmd *cmd,
891+
vhost_scsi_mapal(struct vhost_scsi *vs, struct vhost_scsi_cmd *cmd,
921892
size_t prot_bytes, struct iov_iter *prot_iter,
922-
size_t data_bytes, struct iov_iter *data_iter)
893+
size_t data_bytes, struct iov_iter *data_iter, int data_dir)
923894
{
924-
struct vhost_scsi *vs = cmd->tvc_vhost;
925895
int sgl_count, ret;
926896

927897
if (prot_bytes) {
@@ -967,7 +937,7 @@ vhost_scsi_mapal(struct vhost_scsi_cmd *cmd,
967937
cmd->tvc_sgl_count, false);
968938
if (ret == -EINVAL)
969939
ret = vhost_scsi_copy_iov_to_sgl(cmd, data_iter, &cmd->table,
970-
cmd->tvc_sgl_count);
940+
cmd->tvc_sgl_count, data_dir);
971941
if (ret < 0) {
972942
sg_free_table_chained(&cmd->table, vs->inline_sg_cnt);
973943
cmd->tvc_sgl_count = 0;
@@ -993,10 +963,13 @@ static int vhost_scsi_to_tcm_attr(int attr)
993963
return TCM_SIMPLE_TAG;
994964
}
995965

996-
static void vhost_scsi_target_queue_cmd(struct vhost_scsi_cmd *cmd)
966+
static void vhost_scsi_target_queue_cmd(struct vhost_scsi_nexus *nexus,
967+
struct vhost_scsi_cmd *cmd,
968+
unsigned char *cdb, u16 lun,
969+
int task_attr, int data_dir,
970+
u32 exp_data_len)
997971
{
998972
struct se_cmd *se_cmd = &cmd->tvc_se_cmd;
999-
struct vhost_scsi_nexus *tv_nexus;
1000973
struct scatterlist *sg_ptr, *sg_prot_ptr = NULL;
1001974

1002975
/* FIXME: BIDI operation */
@@ -1010,15 +983,13 @@ static void vhost_scsi_target_queue_cmd(struct vhost_scsi_cmd *cmd)
1010983
} else {
1011984
sg_ptr = NULL;
1012985
}
1013-
tv_nexus = cmd->tvc_nexus;
1014986

1015987
se_cmd->tag = 0;
1016-
target_init_cmd(se_cmd, tv_nexus->tvn_se_sess, &cmd->tvc_sense_buf[0],
1017-
cmd->tvc_lun, cmd->tvc_exp_data_len,
1018-
vhost_scsi_to_tcm_attr(cmd->tvc_task_attr),
1019-
cmd->tvc_data_direction, TARGET_SCF_ACK_KREF);
988+
target_init_cmd(se_cmd, nexus->tvn_se_sess, &cmd->tvc_sense_buf[0],
989+
lun, exp_data_len, vhost_scsi_to_tcm_attr(task_attr),
990+
data_dir, TARGET_SCF_ACK_KREF);
1020991

1021-
if (target_submit_prep(se_cmd, cmd->tvc_cdb, sg_ptr,
992+
if (target_submit_prep(se_cmd, cdb, sg_ptr,
1022993
cmd->tvc_sgl_count, NULL, 0, sg_prot_ptr,
1023994
cmd->tvc_prot_sgl_count, GFP_KERNEL))
1024995
return;
@@ -1175,6 +1146,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
11751146
struct vhost_scsi_tpg **vs_tpg, *tpg;
11761147
struct virtio_scsi_cmd_req v_req;
11771148
struct virtio_scsi_cmd_req_pi v_req_pi;
1149+
struct vhost_scsi_nexus *nexus;
11781150
struct vhost_scsi_ctx vc;
11791151
struct vhost_scsi_cmd *cmd;
11801152
struct iov_iter in_iter, prot_iter, data_iter;
@@ -1184,7 +1156,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
11841156
u16 lun;
11851157
u8 task_attr;
11861158
bool t10_pi = vhost_has_feature(vq, VIRTIO_SCSI_F_T10_PI);
1187-
void *cdb;
1159+
u8 *cdb;
11881160

11891161
mutex_lock(&vq->mutex);
11901162
/*
@@ -1327,28 +1299,34 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
13271299
scsi_command_size(cdb), VHOST_SCSI_MAX_CDB_SIZE);
13281300
goto err;
13291301
}
1330-
cmd = vhost_scsi_get_cmd(vq, tpg, cdb, tag, lun, task_attr,
1331-
exp_data_len + prot_bytes,
1332-
data_direction);
1302+
1303+
nexus = tpg->tpg_nexus;
1304+
if (!nexus) {
1305+
vq_err(vq, "Unable to locate active struct vhost_scsi_nexus\n");
1306+
ret = -EIO;
1307+
goto err;
1308+
}
1309+
1310+
cmd = vhost_scsi_get_cmd(vq, tag);
13331311
if (IS_ERR(cmd)) {
13341312
ret = PTR_ERR(cmd);
13351313
vq_err(vq, "vhost_scsi_get_tag failed %dd\n", ret);
13361314
goto err;
13371315
}
1338-
cmd->tvc_vhost = vs;
13391316
cmd->tvc_vq = vq;
13401317
for (i = 0; i < vc.in ; i++)
13411318
cmd->tvc_resp_iov[i] = vq->iov[vc.out + i];
13421319
cmd->tvc_in_iovs = vc.in;
13431320

13441321
pr_debug("vhost_scsi got command opcode: %#02x, lun: %d\n",
1345-
cmd->tvc_cdb[0], cmd->tvc_lun);
1322+
cdb[0], lun);
13461323
pr_debug("cmd: %p exp_data_len: %d, prot_bytes: %d data_direction:"
13471324
" %d\n", cmd, exp_data_len, prot_bytes, data_direction);
13481325

13491326
if (data_direction != DMA_NONE) {
1350-
ret = vhost_scsi_mapal(cmd, prot_bytes, &prot_iter,
1351-
exp_data_len, &data_iter);
1327+
ret = vhost_scsi_mapal(vs, cmd, prot_bytes, &prot_iter,
1328+
exp_data_len, &data_iter,
1329+
data_direction);
13521330
if (unlikely(ret)) {
13531331
vq_err(vq, "Failed to map iov to sgl\n");
13541332
vhost_scsi_release_cmd_res(&cmd->tvc_se_cmd);
@@ -1361,7 +1339,9 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
13611339
* vhost_scsi_queue_data_in() and vhost_scsi_queue_status()
13621340
*/
13631341
cmd->tvc_vq_desc = vc.head;
1364-
vhost_scsi_target_queue_cmd(cmd);
1342+
vhost_scsi_target_queue_cmd(nexus, cmd, cdb, lun, task_attr,
1343+
data_direction,
1344+
exp_data_len + prot_bytes);
13651345
ret = 0;
13661346
err:
13671347
/*

0 commit comments

Comments
 (0)