[-v2,19/22] virtio-9p: Get the correct count values from the pdu

Submitted by Aneesh Kumar K.V on March 16, 2010, 9:15 a.m.

Details

Message ID 1268730920-14584-20-git-send-email-aneesh.kumar@linux.vnet.ibm.com
State New
Headers show

Commit Message

Aneesh Kumar K.V March 16, 2010, 9:15 a.m.
From: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>

PDU contain little endian format for integer values. So
we need to make sure we map them to host format. Also the count
value can be in another sg offset other than 0. Use the righ
functions to get the count value

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 hw/virtio-9p-debug.c |   29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index ee222db..e8ede8e 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -181,20 +181,25 @@  static void pprint_stat(V9fsPDU *pdu, int rx, size_t *offsetp, const char *name)
 
 static void pprint_strs(V9fsPDU *pdu, int rx, size_t *offsetp, const char *name)
 {
+    int sg_count = get_sg_count(pdu, rx);
     struct iovec *sg = get_sg(pdu, rx);
     size_t offset = *offsetp;
-    int16_t count, i;
+    uint16_t tmp_count, count, i;
+    size_t copied = 0;
 
     fprintf(llogfile, "%s={", name);
 
-    BUG_ON((offset + 2) > sg[0].iov_len);
-    memcpy(&count, sg[0].iov_base + offset, 2);
-    offset += 2;
+    /* Get the count */
+    copied = do_pdu_unpack(&tmp_count, sg, sg_count, offset, sizeof(tmp_count));
+    BUG_ON(copied != sizeof(tmp_count));
+    count = le16_to_cpupu(&tmp_count);
+    offset += copied;
 
     for (i = 0; i < count; i++) {
         char str[512];
-        if (i)
+        if (i) {
             fprintf(llogfile, ", ");
+        }
         snprintf(str, sizeof(str), "[%d]", i);
         pprint_str(pdu, rx, &offset, str);
     }
@@ -206,20 +211,24 @@  static void pprint_strs(V9fsPDU *pdu, int rx, size_t *offsetp, const char *name)
 
 static void pprint_qids(V9fsPDU *pdu, int rx, size_t *offsetp, const char *name)
 {
+    int sg_count = get_sg_count(pdu, rx);
     struct iovec *sg = get_sg(pdu, rx);
     size_t offset = *offsetp;
-    int16_t count, i;
+    uint16_t tmp_count, count, i;
+    size_t copied = 0;
 
     fprintf(llogfile, "%s={", name);
 
-    BUG_ON((offset + 2) > sg[0].iov_len);
-    memcpy(&count, sg[0].iov_base + offset, 2);
-    offset += 2;
+    copied = do_pdu_unpack(&tmp_count, sg, sg_count, offset, sizeof(tmp_count));
+    BUG_ON(copied != sizeof(tmp_count));
+    count = le16_to_cpupu(&tmp_count);
+    offset += copied;
 
     for (i = 0; i < count; i++) {
         char str[512];
-        if (i)
+        if (i) {
             fprintf(llogfile, ", ");
+        }
         snprintf(str, sizeof(str), "[%d]", i);
         pprint_qid(pdu, rx, &offset, str);
     }