From patchwork Wed May 25 23:53:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jvrao X-Patchwork-Id: 97468 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CC496B6F94 for ; Thu, 26 May 2011 09:59:45 +1000 (EST) Received: from localhost ([::1]:40323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPNzL-0005lQ-7s for incoming@patchwork.ozlabs.org; Wed, 25 May 2011 19:59:43 -0400 Received: from eggs.gnu.org ([140.186.70.92]:49178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPNtb-0008Mj-3P for qemu-devel@nongnu.org; Wed, 25 May 2011 19:53:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QPNtT-0007Xj-O1 for qemu-devel@nongnu.org; Wed, 25 May 2011 19:53:47 -0400 Received: from e34.co.us.ibm.com ([32.97.110.152]:39675) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPNtT-0007Ws-Bs for qemu-devel@nongnu.org; Wed, 25 May 2011 19:53:39 -0400 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by e34.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p4PNexc5030229 for ; Wed, 25 May 2011 17:40:59 -0600 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p4PNrYeX151868 for ; Wed, 25 May 2011 17:53:34 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p4PHr7tM018599 for ; Wed, 25 May 2011 11:53:07 -0600 Received: from oc6675851006.ibm.com (dyn9041079012.austin.ibm.com [9.41.79.12]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p4PHqwLv018178; Wed, 25 May 2011 11:53:06 -0600 From: "Venkateswararao Jujjuri (JV)" To: qemu-devel@nongnu.org Date: Wed, 25 May 2011 16:53:12 -0700 Message-Id: <1306367597-797-25-git-send-email-jvrao@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1306367597-797-1-git-send-email-jvrao@linux.vnet.ibm.com> References: <1306367597-797-1-git-send-email-jvrao@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 32.97.110.152 Cc: "Venkateswararao Jujjuri \"" , stefanha@linux.vnet.ibm.com, "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH 24/29] hw/9pfs: Update v9fs_write to use coroutines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Aneesh Kumar K.V Signed-off-by: Aneesh Kumar K.V Signed-off-by: Venkateswararao Jujjuri " --- hw/9pfs/virtio-9p.c | 147 ++++++++++++++++++++------------------------------ 1 files changed, 59 insertions(+), 88 deletions(-) diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index 7fa253c..c4e9efb 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -103,12 +103,6 @@ static int v9fs_do_preadv(V9fsState *s, int fd, const struct iovec *iov, return s->ops->preadv(&s->ctx, fd, iov, iovcnt, offset); } -static int v9fs_do_pwritev(V9fsState *s, int fd, const struct iovec *iov, - int iovcnt, int64_t offset) -{ - return s->ops->pwritev(&s->ctx, fd, iov, iovcnt, offset); -} - static int v9fs_do_chmod(V9fsState *s, V9fsString *path, mode_t mode) { FsCred cred; @@ -1835,51 +1829,21 @@ out: complete_pdu(s, pdu, retval); } -static void v9fs_write_post_pwritev(V9fsState *s, V9fsWriteState *vs, - ssize_t err) -{ - if (err < 0) { - /* IO error return the error */ - err = -errno; - goto out; - } - vs->total += vs->len; - vs->sg = adjust_sg(vs->sg, vs->len, &vs->cnt); - if (vs->total < vs->count && vs->len > 0) { - do { - if (0) { - print_sg(vs->sg, vs->cnt); - } - vs->len = v9fs_do_pwritev(s, vs->fidp->fs.fd, vs->sg, vs->cnt, - vs->off); - if (vs->len > 0) { - vs->off += vs->len; - } - } while (vs->len == -1 && errno == EINTR); - if (vs->len == -1) { - err = -errno; - } - v9fs_write_post_pwritev(s, vs, err); - return; - } - vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total); - err = vs->offset; -out: - complete_pdu(s, vs->pdu, err); - qemu_free(vs); -} - -static void v9fs_xattr_write(V9fsState *s, V9fsWriteState *vs) +static int v9fs_xattr_write(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, + int64_t off, int32_t count, + struct iovec *sg, int cnt) { int i, to_copy; ssize_t err = 0; int write_count; int64_t xattr_len; + size_t offset = 7; - xattr_len = vs->fidp->fs.xattr.len; - write_count = xattr_len - vs->off; - if (write_count > vs->count) { - write_count = vs->count; + + xattr_len = fidp->fs.xattr.len; + write_count = xattr_len - off; + if (write_count > count) { + write_count = count; } else if (write_count < 0) { /* * write beyond XATTR value len specified in @@ -1888,82 +1852,89 @@ static void v9fs_xattr_write(V9fsState *s, V9fsWriteState *vs) err = -ENOSPC; goto out; } - vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", write_count); - err = vs->offset; - vs->fidp->fs.xattr.copied_len += write_count; + offset += pdu_marshal(pdu, offset, "d", write_count); + err = offset; + fidp->fs.xattr.copied_len += write_count; /* * Now copy the content from sg list */ - for (i = 0; i < vs->cnt; i++) { - if (write_count > vs->sg[i].iov_len) { - to_copy = vs->sg[i].iov_len; + for (i = 0; i < cnt; i++) { + if (write_count > sg[i].iov_len) { + to_copy = sg[i].iov_len; } else { to_copy = write_count; } - memcpy((char *)vs->fidp->fs.xattr.value + vs->off, - vs->sg[i].iov_base, to_copy); + memcpy((char *)fidp->fs.xattr.value + off, sg[i].iov_base, to_copy); /* updating vs->off since we are not using below */ - vs->off += to_copy; + off += to_copy; write_count -= to_copy; } out: - complete_pdu(s, vs->pdu, err); - qemu_free(vs); + return err; } static void v9fs_write(void *opaque) { + int cnt; + ssize_t err; + int32_t fid; + int64_t off; + int32_t count; + int32_t len = 0; + int32_t total = 0; + size_t offset = 7; + V9fsFidState *fidp; + struct iovec iov[128]; /* FIXME: bad, bad, bad */ + struct iovec *sg = iov; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; - int32_t fid; - V9fsWriteState *vs; - ssize_t err; - vs = qemu_malloc(sizeof(*vs)); + pdu_unmarshal(pdu, offset, "dqdv", &fid, &off, &count, sg, &cnt); - vs->pdu = pdu; - vs->offset = 7; - vs->sg = vs->iov; - vs->total = 0; - vs->len = 0; - - pdu_unmarshal(vs->pdu, vs->offset, "dqdv", &fid, &vs->off, &vs->count, - vs->sg, &vs->cnt); - - vs->fidp = lookup_fid(s, fid); - if (vs->fidp == NULL) { + fidp = lookup_fid(s, fid); + if (fidp == NULL) { err = -EINVAL; goto out; } - - if (vs->fidp->fid_type == P9_FID_FILE) { - if (vs->fidp->fs.fd == -1) { + if (fidp->fid_type == P9_FID_FILE) { + if (fidp->fs.fd == -1) { err = -EINVAL; goto out; } - } else if (vs->fidp->fid_type == P9_FID_XATTR) { + } else if (fidp->fid_type == P9_FID_XATTR) { /* * setxattr operation */ - v9fs_xattr_write(s, vs); - return; + err = v9fs_xattr_write(s, pdu, fidp, off, count, sg, cnt); + goto out; } else { err = -EINVAL; goto out; } - vs->sg = cap_sg(vs->sg, vs->count, &vs->cnt); - if (vs->total <= vs->count) { - vs->len = v9fs_do_pwritev(s, vs->fidp->fs.fd, vs->sg, vs->cnt, vs->off); - if (vs->len > 0) { - vs->off += vs->len; + sg = cap_sg(sg, count, &cnt); + do { + if (0) { + print_sg(sg, cnt); } - err = vs->len; - v9fs_write_post_pwritev(s, vs, err); - } - return; + /* Loop in case of EINTR */ + do { + len = v9fs_co_pwritev(s, fidp, sg, cnt, off); + if (len >= 0) { + off += len; + total += len; + } + } while (len == -EINTR); + if (len < 0) { + /* IO error return the error */ + err = len; + goto out; + } + sg = adjust_sg(sg, len, &cnt); + } while (total < count && len > 0); + offset += pdu_marshal(pdu, offset, "d", total); + err = offset + total; out: - complete_pdu(s, vs->pdu, err); - qemu_free(vs); + complete_pdu(s, pdu, err); } static void v9fs_create(void *opaque)