From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: Re: [PATCH] tools/kvm/9p: Add encode/decode routines for protocol data Date: Fri, 24 Jun 2011 19:26:48 -0400 Message-ID: <1308958008.10806.6.camel@lappy> References: <1308651608-13534-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> <1308923238.8038.5.camel@lappy> <87wrgbrzi1.fsf@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: penberg@kernel.org, kvm@vger.kernel.org To: "Aneesh Kumar K.V" Return-path: Received: from mail-qw0-f46.google.com ([209.85.216.46]:50956 "EHLO mail-qw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755132Ab1FXX0x (ORCPT ); Fri, 24 Jun 2011 19:26:53 -0400 Received: by qwk3 with SMTP id 3so1542414qwk.19 for ; Fri, 24 Jun 2011 16:26:52 -0700 (PDT) In-Reply-To: <87wrgbrzi1.fsf@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: On Fri, 2011-06-24 at 21:30 +0530, Aneesh Kumar K.V wrote: > On Fri, 24 Jun 2011 09:47:18 -0400, Sasha Levin wrote: > > On Tue, 2011-06-21 at 15:50 +0530, Aneesh Kumar K.V wrote: > > > +static void virtio_p9_pdu_read(struct p9_pdu *pdu, void *data, size_t size) > > > +{ > > > + size_t len; > > > + int i, copied = 0; > > > + u16 iov_cnt = pdu->out_iov_cnt; > > > + size_t offset = pdu->read_offset; > > > + struct iovec *iov = pdu->out_iov; > > > + > > > + for (i = 0; i < iov_cnt && size; i++) { > > > + if (offset >= iov[i].iov_len) { > > > + offset -= iov[i].iov_len; > > > + continue; > > > + } else { > > > + len = MIN(iov[i].iov_len - offset, size); > > > + memcpy(data, iov[i].iov_base + offset, len); > > > + size -= len; > > > + data += len; > > > + offset = 0; > > > + copied += len; > > > + } > > > + } > > > + pdu->read_offset += copied; > > > +} > > > + > > > +static void virtio_p9_pdu_write(struct p9_pdu *pdu, > > > + const void *data, size_t size) > > > +{ > > > + size_t len; > > > + int i, copied = 0; > > > + u16 iov_cnt = pdu->in_iov_cnt; > > > + size_t offset = pdu->write_offset; > > > + struct iovec *iov = pdu->in_iov; > > > + > > > + for (i = 0; i < iov_cnt && size; i++) { > > > + if (offset >= iov[i].iov_len) { > > > + offset -= iov[i].iov_len; > > > + continue; > > > + } else { > > > + len = MIN(iov[i].iov_len - offset, size); > > > + memcpy(iov[i].iov_base + offset, data, len); > > > + size -= len; > > > + data += len; > > > + offset = 0; > > > + copied += len; > > > + } > > > + } > > > + pdu->write_offset += copied; > > > +} > > > + > > > > Just wondering here, can we use pipes (read/write/vmsplice) instead of a > > scatter-gather list? > > Can you elaborate on this. The function is to encode/decode data out of > protocol buffer. I was just thinking about storing the data in a pipe instead of a scatter-gather list. This would turn virtio_p9_pdu_read() into a simple wrapper for read() from a pipe and virtio_p9_pdu_write() into a wrapper for write(). Something like this: void virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name) { [...] pipe(p9_pipe); [...] } static void virtio_p9_pdu_read(struct p9_pdu *pdu, void *data, size_t size) { read(p9_pipe[0], data, size); } static void virtio_p9_pdu_write(struct p9_pdu *pdu, const void *data, size_t size) { write(p9_pipe[1], data, size); } -- Sasha.