From patchwork Thu Mar 25 16:43:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 48572 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3CA66B7067 for ; Fri, 26 Mar 2010 05:12:35 +1100 (EST) Received: from localhost ([127.0.0.1]:40273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NurVv-0007RM-HO for incoming@patchwork.ozlabs.org; Thu, 25 Mar 2010 14:10:39 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NuqAl-0007G4-E1 for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:43 -0400 Received: from [140.186.70.92] (port=50659 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NuqAe-0007EF-B4 for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NuqAV-0005Ah-Qp for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:36 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:40988) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NuqAV-0005AO-0m for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:27 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp09.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2PGiPpw028298 for ; Fri, 26 Mar 2010 03:44:25 +1100 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2PGcJnR1650714 for ; Fri, 26 Mar 2010 03:38:19 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2PGiPAL031559 for ; Fri, 26 Mar 2010 03:44:25 +1100 Received: from localhost.localdomain ([9.77.125.24]) by d23av03.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o2PGhgOs030935; Fri, 26 Mar 2010 03:44:23 +1100 From: "Aneesh Kumar K.V" To: qemu-devel@nongnu.org Date: Thu, 25 Mar 2010 22:13:27 +0530 Message-Id: <1269535420-31206-20-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.2.323.g0d092 In-Reply-To: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: ericvh@gmail.com, aliguori@us.ibm.com, Venkateswararao Jujjuri , "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH -V3 19/32] virtio-9p: Get the correct count values from the pdu X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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); }