From: Sasha Levin <levinsasha928@gmail.com>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: penberg@kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH] tools/kvm/9p: Add encode/decode routines for protocol data
Date: Fri, 24 Jun 2011 19:26:48 -0400 [thread overview]
Message-ID: <1308958008.10806.6.camel@lappy> (raw)
In-Reply-To: <87wrgbrzi1.fsf@linux.vnet.ibm.com>
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 <levinsasha928@gmail.com> 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.
next prev parent reply other threads:[~2011-06-24 23:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-21 10:20 [PATCH] tools/kvm/9p: Add encode/decode routines for protocol data Aneesh Kumar K.V
2011-06-24 13:47 ` Sasha Levin
2011-06-24 16:00 ` Aneesh Kumar K.V
2011-06-24 23:26 ` Sasha Levin [this message]
2011-06-28 6:39 ` Aneesh Kumar K.V
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1308958008.10806.6.camel@lappy \
--to=levinsasha928@gmail.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=penberg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox