@@ -263,6 +263,12 @@ struct vhost_scsi_tmf {
263
263
struct iovec resp_iov ;
264
264
int in_iovs ;
265
265
int vq_desc ;
266
+
267
+ /*
268
+ * Dirty write descriptors of this command.
269
+ */
270
+ struct vhost_log * tmf_log ;
271
+ unsigned int tmf_log_num ;
266
272
};
267
273
268
274
/*
@@ -452,6 +458,10 @@ static void vhost_scsi_release_tmf_res(struct vhost_scsi_tmf *tmf)
452
458
{
453
459
struct vhost_scsi_inflight * inflight = tmf -> inflight ;
454
460
461
+ /*
462
+ * tmf->tmf_log is default NULL unless VHOST_F_LOG_ALL is set.
463
+ */
464
+ kfree (tmf -> tmf_log );
455
465
kfree (tmf );
456
466
vhost_scsi_put_inflight (inflight );
457
467
}
@@ -1537,6 +1547,8 @@ static void vhost_scsi_tmf_resp_work(struct vhost_work *work)
1537
1547
mutex_lock (& tmf -> svq -> vq .mutex );
1538
1548
vhost_scsi_send_tmf_resp (tmf -> vhost , & tmf -> svq -> vq , tmf -> in_iovs ,
1539
1549
tmf -> vq_desc , & tmf -> resp_iov , resp_code );
1550
+ vhost_scsi_log_write (& tmf -> svq -> vq , tmf -> tmf_log ,
1551
+ tmf -> tmf_log_num );
1540
1552
mutex_unlock (& tmf -> svq -> vq .mutex );
1541
1553
1542
1554
vhost_scsi_release_tmf_res (tmf );
@@ -1560,7 +1572,8 @@ static void
1560
1572
vhost_scsi_handle_tmf (struct vhost_scsi * vs , struct vhost_scsi_tpg * tpg ,
1561
1573
struct vhost_virtqueue * vq ,
1562
1574
struct virtio_scsi_ctrl_tmf_req * vtmf ,
1563
- struct vhost_scsi_ctx * vc )
1575
+ struct vhost_scsi_ctx * vc ,
1576
+ struct vhost_log * log , unsigned int log_num )
1564
1577
{
1565
1578
struct vhost_scsi_virtqueue * svq = container_of (vq ,
1566
1579
struct vhost_scsi_virtqueue , vq );
@@ -1588,6 +1601,19 @@ vhost_scsi_handle_tmf(struct vhost_scsi *vs, struct vhost_scsi_tpg *tpg,
1588
1601
tmf -> in_iovs = vc -> in ;
1589
1602
tmf -> inflight = vhost_scsi_get_inflight (vq );
1590
1603
1604
+ if (unlikely (log && log_num )) {
1605
+ tmf -> tmf_log = kmalloc_array (log_num , sizeof (* tmf -> tmf_log ),
1606
+ GFP_KERNEL );
1607
+ if (tmf -> tmf_log ) {
1608
+ memcpy (tmf -> tmf_log , log , sizeof (* tmf -> tmf_log ) * log_num );
1609
+ tmf -> tmf_log_num = log_num ;
1610
+ } else {
1611
+ pr_err ("vhost_scsi tmf log allocation error\n" );
1612
+ vhost_scsi_release_tmf_res (tmf );
1613
+ goto send_reject ;
1614
+ }
1615
+ }
1616
+
1591
1617
if (target_submit_tmr (& tmf -> se_cmd , tpg -> tpg_nexus -> tvn_se_sess , NULL ,
1592
1618
vhost_buf_to_lun (vtmf -> lun ), NULL ,
1593
1619
TMR_LUN_RESET , GFP_KERNEL , 0 ,
@@ -1601,6 +1627,7 @@ vhost_scsi_handle_tmf(struct vhost_scsi *vs, struct vhost_scsi_tpg *tpg,
1601
1627
send_reject :
1602
1628
vhost_scsi_send_tmf_resp (vs , vq , vc -> in , vc -> head , & vq -> iov [vc -> out ],
1603
1629
VIRTIO_SCSI_S_FUNCTION_REJECTED );
1630
+ vhost_scsi_log_write (vq , log , log_num );
1604
1631
}
1605
1632
1606
1633
static void
@@ -1637,6 +1664,8 @@ vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1637
1664
struct vhost_scsi_ctx vc ;
1638
1665
size_t typ_size ;
1639
1666
int ret , c = 0 ;
1667
+ struct vhost_log * vq_log ;
1668
+ unsigned int log_num ;
1640
1669
1641
1670
mutex_lock (& vq -> mutex );
1642
1671
/*
@@ -1650,8 +1679,11 @@ vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1650
1679
1651
1680
vhost_disable_notify (& vs -> dev , vq );
1652
1681
1682
+ vq_log = unlikely (vhost_has_feature (vq , VHOST_F_LOG_ALL )) ?
1683
+ vq -> log : NULL ;
1684
+
1653
1685
do {
1654
- ret = vhost_scsi_get_desc (vs , vq , & vc , NULL , NULL );
1686
+ ret = vhost_scsi_get_desc (vs , vq , & vc , vq_log , & log_num );
1655
1687
if (ret )
1656
1688
goto err ;
1657
1689
@@ -1715,9 +1747,12 @@ vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1715
1747
goto err ;
1716
1748
1717
1749
if (v_req .type == VIRTIO_SCSI_T_TMF )
1718
- vhost_scsi_handle_tmf (vs , tpg , vq , & v_req .tmf , & vc );
1719
- else
1750
+ vhost_scsi_handle_tmf (vs , tpg , vq , & v_req .tmf , & vc ,
1751
+ vq_log , log_num );
1752
+ else {
1720
1753
vhost_scsi_send_an_resp (vs , vq , & vc );
1754
+ vhost_scsi_log_write (vq , vq_log , log_num );
1755
+ }
1721
1756
err :
1722
1757
/*
1723
1758
* ENXIO: No more requests, or read error, wait for next kick
@@ -1727,11 +1762,13 @@ vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1727
1762
*/
1728
1763
if (ret == - ENXIO )
1729
1764
break ;
1730
- else if (ret == - EIO )
1765
+ else if (ret == - EIO ) {
1731
1766
vhost_scsi_send_bad_target (vs , vq , & vc ,
1732
1767
v_req .type == VIRTIO_SCSI_T_TMF ?
1733
1768
TYPE_CTRL_TMF :
1734
1769
TYPE_CTRL_AN );
1770
+ vhost_scsi_log_write (vq , vq_log , log_num );
1771
+ }
1735
1772
} while (likely (!vhost_exceeds_weight (vq , ++ c , 0 )));
1736
1773
out :
1737
1774
mutex_unlock (& vq -> mutex );
0 commit comments