From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NnC4b-0006tC-LZ for qemu-devel@nongnu.org; Thu, 04 Mar 2010 09:30:45 -0500 Received: from [199.232.76.173] (port=60640 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnC4a-0006sb-Bl for qemu-devel@nongnu.org; Thu, 04 Mar 2010 09:30:44 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NnC4Z-0005B7-ED for qemu-devel@nongnu.org; Thu, 04 Mar 2010 09:30:44 -0500 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:37894) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NnC4Y-0005Ar-FQ for qemu-devel@nongnu.org; Thu, 04 Mar 2010 09:30:43 -0500 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by e28smtp02.in.ibm.com (8.14.3/8.13.1) with ESMTP id o24EUZ4l022868 for ; Thu, 4 Mar 2010 20:00:35 +0530 Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o24EUZJ71908836 for ; Thu, 4 Mar 2010 20:00:35 +0530 Received: from d28av05.in.ibm.com (loopback [127.0.0.1]) by d28av05.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o24EUYl5012889 for ; Fri, 5 Mar 2010 01:30:35 +1100 From: "Aneesh Kumar K. V" In-Reply-To: <20100304092324.GB1535@redhat.com> References: <1267642874-15001-1-git-send-email-aliguori@us.ibm.com> <1267642874-15001-4-git-send-email-aliguori@us.ibm.com> <20100304092324.GB1535@redhat.com> Date: Thu, 04 Mar 2010 20:00:32 +0530 Message-ID: <87tyswjh13.fsf@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] Re: [PATCH 02/17] vrtio-9p: Implement P9_TVERSION for 9P List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" , Anthony Liguori Cc: qemu-devel@nongnu.org On Thu, 4 Mar 2010 11:23:24 +0200, "Michael S. Tsirkin" wrote: > On Wed, Mar 03, 2010 at 01:00:59PM -0600, Anthony Liguori wrote: > > [kiran@linux.vnet.ibm.com: malloc to qemu_malloc coversion] > > > > Signed-off-by: Anthony Liguori > > Signed-off-by: Aneesh Kumar K.V > > --- > > hw/virtio-9p.c | 263 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- > > 1 files changed, 262 insertions(+), 1 deletions(-) > > > > diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c > > index 93402c5..a057fbb 100644 > > --- a/hw/virtio-9p.c > > +++ b/hw/virtio-9p.c > > @@ -111,10 +111,271 @@ static void free_pdu(V9fsState *s, V9fsPDU *pdu) > > } > > } > > > > -static void v9fs_version(V9fsState *s, V9fsPDU *pdu) > > +static void v9fs_string_free(V9fsString *str) > > +{ > > + free(str->data); > > + str->data = NULL; > > + str->size = 0; > > +} > > + > > +static size_t pdu_unpack(void *dst, V9fsPDU *pdu, size_t offset, size_t size) > > +{ > > + struct iovec *sg = pdu->elem.out_sg; > > + BUG_ON((offset + size) > sg[0].iov_len); > > + memcpy(dst, sg[0].iov_base + offset, size); > > + return size; > > +} > > + > > +/* FIXME i can do this with less variables */ > > +static size_t pdu_pack(V9fsPDU *pdu, size_t offset, const void *src, size_t size) > > Is the point of this functuion to copy size bytes starting > at offset? Maybe generalize this to work on any iovec? The 9p debug code also need a similar function. I have a bug fix patch that make sure we use all the elem.out_num elements in elem.out_sg array. That patch already does abstract this out for any iovec. But still keep the function in virtio-9p.c. > > > +{ > > + struct iovec *sg = pdu->elem.in_sg; > > + size_t off = 0; > > + size_t copied = 0; > > + int i = 0; > > + > > + for (i = 0; size && i < pdu->elem.in_num; i++) { > > + size_t len; > > indentation by tabs. Fixed > > > + > > + if (offset >= off && offset < (off + sg[i].iov_len)) { > > The above math might overflow. Not sure what the result will be. > > > + len = MIN(sg[i].iov_len - (offset - off), size); > > + memcpy(sg[i].iov_base + (offset - off), src, len); > > + size -= len; > > + offset += len; > > + off = offset; > > + copied += len; > > + src += len; > > + } else > > + off += sg[i].iov_len; > > {} Fixed > > > + } > > + > > + return copied; > > +} > > + > > +static int pdu_copy_sg(V9fsPDU *pdu, size_t offset, int rx, struct iovec *sg) > > +{ > > Maybe generalize this to work on any iovec? > > > + size_t pos = 0; > > + int i, j; > > + struct iovec *src_sg; > > + unsigned int num; > > + > > + if (rx) { > > + src_sg = pdu->elem.in_sg; > > + num = pdu->elem.in_num; > > + } else { > > + src_sg = pdu->elem.out_sg; > > + num = pdu->elem.out_num; > > + } > > + > > + j = 0;