From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrSt3-0002Cc-CY for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:16:29 -0400 Received: from [199.232.76.173] (port=57584 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrSt2-0002Br-Jq for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:16:28 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NrSt0-0001zs-9Z for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:16:28 -0400 Received: from mx20.gnu.org ([199.232.41.8]:47236) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NrSsz-0001wv-OM for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:16:25 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NrSsp-0001Ya-2w for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:16:15 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp07.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2G9G6XQ009909 for ; Tue, 16 Mar 2010 20:16:06 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2G9ACwm1400904 for ; Tue, 16 Mar 2010 20:10:12 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2G9G6GV007072 for ; Tue, 16 Mar 2010 20:16:06 +1100 From: "Aneesh Kumar K.V" Date: Tue, 16 Mar 2010 14:45:17 +0530 Message-Id: <1268730920-14584-20-git-send-email-aneesh.kumar@linux.vnet.ibm.com> In-Reply-To: <1268730920-14584-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1268730920-14584-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH -v2 19/22] virtio-9p: Get the correct count values from the pdu List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: ericvh@gmail.com, aliguori@us.ibm.com, Venkateswararao Jujjuri , "Aneesh Kumar K.V" From: Venkateswararao Jujjuri 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 Signed-off-by: Aneesh Kumar K.V --- hw/virtio-9p-debug.c | 29 +++++++++++++++++++---------- 1 files changed, 19 insertions(+), 10 deletions(-) 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); } -- 1.7.0.2.273.gc2413