@@ -106,21 +106,11 @@ struct vhost_scsi_inflight {
106
106
struct vhost_scsi_cmd {
107
107
/* Descriptor from vhost_get_vq_desc() for virt_queue segment */
108
108
int tvc_vq_desc ;
109
- /* virtio-scsi initiator task attribute */
110
- int tvc_task_attr ;
111
109
/* virtio-scsi response incoming iovecs */
112
110
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 ;
119
111
/* The number of scatterlists associated with this cmd */
120
112
u32 tvc_sgl_count ;
121
113
u32 tvc_prot_sgl_count ;
122
- /* Saved unpacked SCSI LUN for vhost_scsi_target_queue_cmd() */
123
- u32 tvc_lun ;
124
114
u32 copied_iov :1 ;
125
115
const void * saved_iter_addr ;
126
116
struct iov_iter saved_iter ;
@@ -130,16 +120,10 @@ struct vhost_scsi_cmd {
130
120
struct sg_table prot_table ;
131
121
/* Pointer to response header iovec */
132
122
struct iovec * tvc_resp_iov ;
133
- /* Pointer to vhost_scsi for our device */
134
- struct vhost_scsi * tvc_vhost ;
135
123
/* Pointer to vhost_virtqueue for the cmd */
136
124
struct vhost_virtqueue * tvc_vq ;
137
- /* Pointer to vhost nexus memory */
138
- struct vhost_scsi_nexus * tvc_nexus ;
139
125
/* The TCM I/O descriptor that is accessed via container_of() */
140
126
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 ];
143
127
/* Sense buffer that will be mapped into outgoing status */
144
128
unsigned char tvc_sense_buf [TRANSPORT_SENSE_BUFFER ];
145
129
/* Completed commands list, serviced from vhost worker thread */
@@ -375,9 +359,9 @@ static void vhost_scsi_release_cmd_res(struct se_cmd *se_cmd)
375
359
{
376
360
struct vhost_scsi_cmd * tv_cmd = container_of (se_cmd ,
377
361
struct vhost_scsi_cmd , tvc_se_cmd );
378
- struct vhost_scsi * vs = tv_cmd -> tvc_vhost ;
379
362
struct vhost_scsi_virtqueue * svq = container_of (tv_cmd -> tvc_vq ,
380
363
struct vhost_scsi_virtqueue , vq );
364
+ struct vhost_scsi * vs = svq -> vs ;
381
365
struct vhost_scsi_inflight * inflight = tv_cmd -> inflight ;
382
366
struct scatterlist * sg ;
383
367
struct page * page ;
@@ -671,24 +655,15 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
671
655
}
672
656
673
657
static struct vhost_scsi_cmd *
674
- vhost_scsi_get_cmd (struct vhost_virtqueue * vq , struct vhost_scsi_tpg * tpg ,
675
- unsigned char * cdb , u64 scsi_tag , u16 lun , u8 task_attr ,
676
- u32 exp_data_len , int data_direction )
658
+ vhost_scsi_get_cmd (struct vhost_virtqueue * vq , u64 scsi_tag )
677
659
{
678
660
struct vhost_scsi_virtqueue * svq = container_of (vq ,
679
661
struct vhost_scsi_virtqueue , vq );
680
662
struct vhost_scsi_cmd * cmd ;
681
- struct vhost_scsi_nexus * tv_nexus ;
682
663
struct scatterlist * sgl , * prot_sgl ;
683
664
struct iovec * tvc_resp_iov ;
684
665
int tag ;
685
666
686
- tv_nexus = tpg -> tpg_nexus ;
687
- if (!tv_nexus ) {
688
- pr_err ("Unable to locate active struct vhost_scsi_nexus\n" );
689
- return ERR_PTR (- EIO );
690
- }
691
-
692
667
tag = sbitmap_get (& svq -> scsi_tags );
693
668
if (tag < 0 ) {
694
669
pr_warn_once ("Guest sent too many cmds. Returning TASK_SET_FULL.\n" );
@@ -703,17 +678,9 @@ vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
703
678
cmd -> sgl = sgl ;
704
679
cmd -> prot_sgl = prot_sgl ;
705
680
cmd -> tvc_se_cmd .map_tag = tag ;
706
- cmd -> tvc_tag = scsi_tag ;
707
- cmd -> tvc_lun = lun ;
708
- cmd -> tvc_task_attr = task_attr ;
709
- cmd -> tvc_exp_data_len = exp_data_len ;
710
- cmd -> tvc_data_direction = data_direction ;
711
- cmd -> tvc_nexus = tv_nexus ;
712
681
cmd -> inflight = vhost_scsi_get_inflight (vq );
713
682
cmd -> tvc_resp_iov = tvc_resp_iov ;
714
683
715
- memcpy (cmd -> tvc_cdb , cdb , VHOST_SCSI_MAX_CDB_SIZE );
716
-
717
684
return cmd ;
718
685
}
719
686
@@ -831,15 +798,16 @@ vhost_scsi_calc_sgls(struct iov_iter *iter, size_t bytes, int max_sgls)
831
798
832
799
static int
833
800
vhost_scsi_copy_iov_to_sgl (struct vhost_scsi_cmd * cmd , struct iov_iter * iter ,
834
- struct sg_table * sg_table , int sg_count )
801
+ struct sg_table * sg_table , int sg_count ,
802
+ int data_dir )
835
803
{
836
804
size_t len = iov_iter_count (iter );
837
805
unsigned int nbytes = 0 ;
838
806
struct scatterlist * sg ;
839
807
struct page * page ;
840
808
int i , ret ;
841
809
842
- if (cmd -> tvc_data_direction == DMA_FROM_DEVICE ) {
810
+ if (data_dir == DMA_FROM_DEVICE ) {
843
811
cmd -> saved_iter_addr = dup_iter (& cmd -> saved_iter , iter ,
844
812
GFP_KERNEL );
845
813
if (!cmd -> saved_iter_addr )
@@ -856,7 +824,7 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
856
824
nbytes = min_t (unsigned int , PAGE_SIZE , len );
857
825
sg_set_page (sg , page , nbytes , 0 );
858
826
859
- if (cmd -> tvc_data_direction == DMA_TO_DEVICE &&
827
+ if (data_dir == DMA_TO_DEVICE &&
860
828
copy_page_from_iter (page , 0 , nbytes , iter ) != nbytes ) {
861
829
ret = - EFAULT ;
862
830
goto err ;
@@ -901,11 +869,10 @@ vhost_scsi_map_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
901
869
}
902
870
903
871
static int
904
- vhost_scsi_mapal (struct vhost_scsi_cmd * cmd ,
872
+ vhost_scsi_mapal (struct vhost_scsi * vs , struct vhost_scsi_cmd * cmd ,
905
873
size_t prot_bytes , struct iov_iter * prot_iter ,
906
- size_t data_bytes , struct iov_iter * data_iter )
874
+ size_t data_bytes , struct iov_iter * data_iter , int data_dir )
907
875
{
908
- struct vhost_scsi * vs = cmd -> tvc_vhost ;
909
876
int sgl_count , ret ;
910
877
911
878
if (prot_bytes ) {
@@ -951,7 +918,7 @@ vhost_scsi_mapal(struct vhost_scsi_cmd *cmd,
951
918
cmd -> tvc_sgl_count , false);
952
919
if (ret == - EINVAL )
953
920
ret = vhost_scsi_copy_iov_to_sgl (cmd , data_iter , & cmd -> table ,
954
- cmd -> tvc_sgl_count );
921
+ cmd -> tvc_sgl_count , data_dir );
955
922
if (ret < 0 ) {
956
923
sg_free_table_chained (& cmd -> table , vs -> inline_sg_cnt );
957
924
cmd -> tvc_sgl_count = 0 ;
@@ -977,10 +944,13 @@ static int vhost_scsi_to_tcm_attr(int attr)
977
944
return TCM_SIMPLE_TAG ;
978
945
}
979
946
980
- static void vhost_scsi_target_queue_cmd (struct vhost_scsi_cmd * cmd )
947
+ static void vhost_scsi_target_queue_cmd (struct vhost_scsi_nexus * nexus ,
948
+ struct vhost_scsi_cmd * cmd ,
949
+ unsigned char * cdb , u16 lun ,
950
+ int task_attr , int data_dir ,
951
+ u32 exp_data_len )
981
952
{
982
953
struct se_cmd * se_cmd = & cmd -> tvc_se_cmd ;
983
- struct vhost_scsi_nexus * tv_nexus ;
984
954
struct scatterlist * sg_ptr , * sg_prot_ptr = NULL ;
985
955
986
956
/* FIXME: BIDI operation */
@@ -994,15 +964,13 @@ static void vhost_scsi_target_queue_cmd(struct vhost_scsi_cmd *cmd)
994
964
} else {
995
965
sg_ptr = NULL ;
996
966
}
997
- tv_nexus = cmd -> tvc_nexus ;
998
967
999
968
se_cmd -> tag = 0 ;
1000
- target_init_cmd (se_cmd , tv_nexus -> tvn_se_sess , & cmd -> tvc_sense_buf [0 ],
1001
- cmd -> tvc_lun , cmd -> tvc_exp_data_len ,
1002
- vhost_scsi_to_tcm_attr (cmd -> tvc_task_attr ),
1003
- cmd -> tvc_data_direction , TARGET_SCF_ACK_KREF );
969
+ target_init_cmd (se_cmd , nexus -> tvn_se_sess , & cmd -> tvc_sense_buf [0 ],
970
+ lun , exp_data_len , vhost_scsi_to_tcm_attr (task_attr ),
971
+ data_dir , TARGET_SCF_ACK_KREF );
1004
972
1005
- if (target_submit_prep (se_cmd , cmd -> tvc_cdb , sg_ptr ,
973
+ if (target_submit_prep (se_cmd , cdb , sg_ptr ,
1006
974
cmd -> tvc_sgl_count , NULL , 0 , sg_prot_ptr ,
1007
975
cmd -> tvc_prot_sgl_count , GFP_KERNEL ))
1008
976
return ;
@@ -1159,6 +1127,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1159
1127
struct vhost_scsi_tpg * * vs_tpg , * tpg ;
1160
1128
struct virtio_scsi_cmd_req v_req ;
1161
1129
struct virtio_scsi_cmd_req_pi v_req_pi ;
1130
+ struct vhost_scsi_nexus * nexus ;
1162
1131
struct vhost_scsi_ctx vc ;
1163
1132
struct vhost_scsi_cmd * cmd ;
1164
1133
struct iov_iter in_iter , prot_iter , data_iter ;
@@ -1168,7 +1137,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1168
1137
u16 lun ;
1169
1138
u8 task_attr ;
1170
1139
bool t10_pi = vhost_has_feature (vq , VIRTIO_SCSI_F_T10_PI );
1171
- void * cdb ;
1140
+ u8 * cdb ;
1172
1141
1173
1142
mutex_lock (& vq -> mutex );
1174
1143
/*
@@ -1311,28 +1280,34 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1311
1280
scsi_command_size (cdb ), VHOST_SCSI_MAX_CDB_SIZE );
1312
1281
goto err ;
1313
1282
}
1314
- cmd = vhost_scsi_get_cmd (vq , tpg , cdb , tag , lun , task_attr ,
1315
- exp_data_len + prot_bytes ,
1316
- data_direction );
1283
+
1284
+ nexus = tpg -> tpg_nexus ;
1285
+ if (!nexus ) {
1286
+ vq_err (vq , "Unable to locate active struct vhost_scsi_nexus\n" );
1287
+ ret = - EIO ;
1288
+ goto err ;
1289
+ }
1290
+
1291
+ cmd = vhost_scsi_get_cmd (vq , tag );
1317
1292
if (IS_ERR (cmd )) {
1318
1293
ret = PTR_ERR (cmd );
1319
1294
vq_err (vq , "vhost_scsi_get_tag failed %dd\n" , ret );
1320
1295
goto err ;
1321
1296
}
1322
- cmd -> tvc_vhost = vs ;
1323
1297
cmd -> tvc_vq = vq ;
1324
1298
for (i = 0 ; i < vc .in ; i ++ )
1325
1299
cmd -> tvc_resp_iov [i ] = vq -> iov [vc .out + i ];
1326
1300
cmd -> tvc_in_iovs = vc .in ;
1327
1301
1328
1302
pr_debug ("vhost_scsi got command opcode: %#02x, lun: %d\n" ,
1329
- cmd -> tvc_cdb [0 ], cmd -> tvc_lun );
1303
+ cdb [0 ], lun );
1330
1304
pr_debug ("cmd: %p exp_data_len: %d, prot_bytes: %d data_direction:"
1331
1305
" %d\n" , cmd , exp_data_len , prot_bytes , data_direction );
1332
1306
1333
1307
if (data_direction != DMA_NONE ) {
1334
- ret = vhost_scsi_mapal (cmd , prot_bytes , & prot_iter ,
1335
- exp_data_len , & data_iter );
1308
+ ret = vhost_scsi_mapal (vs , cmd , prot_bytes , & prot_iter ,
1309
+ exp_data_len , & data_iter ,
1310
+ data_direction );
1336
1311
if (unlikely (ret )) {
1337
1312
vq_err (vq , "Failed to map iov to sgl\n" );
1338
1313
vhost_scsi_release_cmd_res (& cmd -> tvc_se_cmd );
@@ -1345,7 +1320,9 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1345
1320
* vhost_scsi_queue_data_in() and vhost_scsi_queue_status()
1346
1321
*/
1347
1322
cmd -> tvc_vq_desc = vc .head ;
1348
- vhost_scsi_target_queue_cmd (cmd );
1323
+ vhost_scsi_target_queue_cmd (nexus , cmd , cdb , lun , task_attr ,
1324
+ data_direction ,
1325
+ exp_data_len + prot_bytes );
1349
1326
ret = 0 ;
1350
1327
err :
1351
1328
/*
0 commit comments