[PATCH spice-gtk v2 14/33] fixup! usb-redir: add files for SCSI and USB MSC implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Remove num_luns, fix cd_scsi_cmd_report_luns.
num_luns was used only in cd_scsi_cmd_report_luns.
In cd_scsi_cmd_report_luns the length of the list is expressed in
bytes and the format of the LUN can be quite complicated
(the more simple is used now).
---
 src/cd-scsi.c | 48 +++++++++++++++++++++---------------------------
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/src/cd-scsi.c b/src/cd-scsi.c
index dbb78e54..616c65da 100644
--- a/src/cd-scsi.c
+++ b/src/cd-scsi.c
@@ -107,7 +107,6 @@ struct CdScsiTarget {
     CdScsiRequest *cur_req;
     GCancellable *cancellable;
 
-    uint32_t num_luns;
     uint32_t max_luns;
     CdScsiLU units[MAX_LUNS];
 };
@@ -439,7 +438,7 @@ static inline gboolean cd_scsi_target_lun_legal(const CdScsiTarget *st, uint32_t
 
 static inline gboolean cd_scsi_target_lun_realized(const CdScsiTarget *st, uint32_t lun)
 {
-    return (st->num_luns == 0 || !st->units[lun].realized) ? FALSE : TRUE;
+    return st->units[lun].realized;
 }
 
 int cd_scsi_dev_realize(CdScsiTarget *st, uint32_t lun,
@@ -480,8 +479,6 @@ int cd_scsi_dev_realize(CdScsiTarget *st, uint32_t lun,
 
     cd_scsi_dev_sense_set_power_on(dev);
 
-    st->num_luns ++;
-
     SPICE_DEBUG("Realize lun:%u bs:%u VR:[%s] PT:[%s] ver:[%s] SN[%s]",
                 lun, dev->block_size, dev->vendor,
                 dev->product, dev->version, dev->serial);
@@ -658,8 +655,6 @@ int cd_scsi_dev_unrealize(CdScsiTarget *st, uint32_t lun)
     dev->realized = FALSE;
     dev->power_cond = CD_SCSI_POWER_STOPPED;
 
-    st->num_luns --;
-
     SPICE_DEBUG("Unrealize lun:%u", lun);
     return 0;
 }
@@ -874,37 +869,36 @@ static void cd_scsi_cmd_report_luns(CdScsiTarget *st, CdScsiLU *dev,
                                     CdScsiRequest *req)
 {
     uint8_t *out_buf = req->buf;
-    uint32_t num_luns = st->num_luns;
+    uint32_t max_luns = st->max_luns;
     uint32_t buflen = 8; /* header length */
     uint32_t lun;
 
     req->req_len = scsi_cdb_xfer_length(req->cdb, 12);
     req->xfer_dir = SCSI_XFER_FROM_DEV;
 
-    if (req->cdb[0] == 0x01) {
+    /* check SELECT REPORT field */
+    if (req->cdb[2] == 0x01) {
         /* only well known logical units */
-        num_luns = 0;
-    }
-
-    out_buf[0] = (uint8_t)(num_luns >> 24);
-    out_buf[1] = (uint8_t)(num_luns >> 16);
-    out_buf[2] = (uint8_t)(num_luns >> 8);
-    out_buf[3] = (uint8_t)(num_luns);
-    memset(&out_buf[4], 0, 4);
-
-    if (num_luns > 0) {
-        for (lun = 0; lun < num_luns; lun++) {
-            if (st->units[lun].realized) {
-                out_buf[buflen++] = (uint8_t)(num_luns >> 24);
-                out_buf[buflen++] = (uint8_t)(num_luns >> 16);
-                out_buf[buflen++] = (uint8_t)(num_luns >> 8);
-                out_buf[buflen++] = (uint8_t)(num_luns);
-                memset(&out_buf[buflen], 0, 4);
-                buflen += 4;
-            }
+        max_luns = 0;
+    }
+
+    memset(out_buf, 0, 8);
+
+    for (lun = 0; lun < max_luns; lun++) {
+        if (st->units[lun].realized) {
+            out_buf[buflen++] = 0;
+            out_buf[buflen++] = (uint8_t)(lun);
+            memset(&out_buf[buflen], 0, 6);
+            buflen += 6;
         }
     }
 
+    /* fill LUN LIST LENGTH */
+    out_buf[0] = (uint8_t)((buflen-8) >> 24);
+    out_buf[1] = (uint8_t)((buflen-8) >> 16);
+    out_buf[2] = (uint8_t)((buflen-8) >> 8);
+    out_buf[3] = (uint8_t)((buflen-8));
+
     req->in_len = buflen;
     cd_scsi_cmd_complete_good(dev, req);
 }
-- 
2.20.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]