From patchwork Thu May 19 02:57:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jvrao X-Patchwork-Id: 96302 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 608DFB6F7B for ; Thu, 19 May 2011 13:05:16 +1000 (EST) Received: from localhost ([::1]:32917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QMtY1-00033L-MB for incoming@patchwork.ozlabs.org; Wed, 18 May 2011 23:05:13 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QMtQo-0005g1-KK for qemu-devel@nongnu.org; Wed, 18 May 2011 22:57:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QMtQm-0004xU-3r for qemu-devel@nongnu.org; Wed, 18 May 2011 22:57:46 -0400 Received: from e34.co.us.ibm.com ([32.97.110.152]:55734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QMtQl-0004xB-QY for qemu-devel@nongnu.org; Wed, 18 May 2011 22:57:44 -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 p4J2j9o5004307 for ; Wed, 18 May 2011 20:45:09 -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 p4J2vdDq157454 for ; Wed, 18 May 2011 20:57:39 -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 p4IKvBbl016132 for ; Wed, 18 May 2011 14:57:12 -0600 Received: from oc6675851006.ibm.com (sig-9-65-27-236.mts.ibm.com [9.65.27.236]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p4IKuo4c014807; Wed, 18 May 2011 14:57:11 -0600 From: "Venkateswararao Jujjuri (JV)" To: qemu-devel@nongnu.org Date: Wed, 18 May 2011 19:57:07 -0700 Message-Id: <1305773834-16359-18-git-send-email-jvrao@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1305773834-16359-1-git-send-email-jvrao@linux.vnet.ibm.com> References: <1305773834-16359-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: aliguori@us.ibm.com, "Venkateswararao Jujjuri \"" , stefanha@linux.vnet.ibm.com, "Aneesh Kumar K.V" Subject: [Qemu-devel] [V3 17/24] hw/9pfs: Update v9fs_xattrwalk to 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 | 198 ++++++++++++++++----------------------------------- 1 files changed, 63 insertions(+), 135 deletions(-) diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index 0f965b5..5336b8b 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -240,21 +240,6 @@ static int v9fs_do_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf) return s->ops->statfs(&s->ctx, path->data, stbuf); } -static ssize_t v9fs_do_lgetxattr(V9fsState *s, V9fsString *path, - V9fsString *xattr_name, - void *value, size_t size) -{ - return s->ops->lgetxattr(&s->ctx, path->data, - xattr_name->data, value, size); -} - -static ssize_t v9fs_do_llistxattr(V9fsState *s, V9fsString *path, - void *value, size_t size) -{ - return s->ops->llistxattr(&s->ctx, path->data, - value, size); -} - static int v9fs_do_lsetxattr(V9fsState *s, V9fsString *path, V9fsString *xattr_name, void *value, size_t size, int flags) @@ -3242,149 +3227,92 @@ out: v9fs_string_free(&name); } -static void v9fs_post_xattr_getvalue(V9fsState *s, V9fsXattrState *vs, int err) -{ - - if (err < 0) { - err = -errno; - free_fid(s, vs->xattr_fidp->fid); - goto out; - } - vs->offset += pdu_marshal(vs->pdu, vs->offset, "q", vs->size); - err = vs->offset; -out: - complete_pdu(s, vs->pdu, err); - v9fs_string_free(&vs->name); - qemu_free(vs); - return; -} - -static void v9fs_post_xattr_check(V9fsState *s, V9fsXattrState *vs, ssize_t err) -{ - if (err < 0) { - err = -errno; - free_fid(s, vs->xattr_fidp->fid); - goto out; - } - /* - * Read the xattr value - */ - vs->xattr_fidp->fs.xattr.len = vs->size; - vs->xattr_fidp->fid_type = P9_FID_XATTR; - vs->xattr_fidp->fs.xattr.copied_len = -1; - if (vs->size) { - vs->xattr_fidp->fs.xattr.value = qemu_malloc(vs->size); - err = v9fs_do_lgetxattr(s, &vs->xattr_fidp->path, - &vs->name, vs->xattr_fidp->fs.xattr.value, - vs->xattr_fidp->fs.xattr.len); - } - v9fs_post_xattr_getvalue(s, vs, err); - return; -out: - complete_pdu(s, vs->pdu, err); - v9fs_string_free(&vs->name); - qemu_free(vs); -} - -static void v9fs_post_lxattr_getvalue(V9fsState *s, - V9fsXattrState *vs, int err) -{ - if (err < 0) { - err = -errno; - free_fid(s, vs->xattr_fidp->fid); - goto out; - } - vs->offset += pdu_marshal(vs->pdu, vs->offset, "q", vs->size); - err = vs->offset; -out: - complete_pdu(s, vs->pdu, err); - v9fs_string_free(&vs->name); - qemu_free(vs); - return; -} - -static void v9fs_post_lxattr_check(V9fsState *s, - V9fsXattrState *vs, ssize_t err) -{ - if (err < 0) { - err = -errno; - free_fid(s, vs->xattr_fidp->fid); - goto out; - } - /* - * Read the xattr value - */ - vs->xattr_fidp->fs.xattr.len = vs->size; - vs->xattr_fidp->fid_type = P9_FID_XATTR; - vs->xattr_fidp->fs.xattr.copied_len = -1; - if (vs->size) { - vs->xattr_fidp->fs.xattr.value = qemu_malloc(vs->size); - err = v9fs_do_llistxattr(s, &vs->xattr_fidp->path, - vs->xattr_fidp->fs.xattr.value, - vs->xattr_fidp->fs.xattr.len); - } - v9fs_post_lxattr_getvalue(s, vs, err); - return; -out: - complete_pdu(s, vs->pdu, err); - v9fs_string_free(&vs->name); - qemu_free(vs); -} - static void v9fs_xattrwalk(void *opaque) { - V9fsPDU *pdu = opaque; - V9fsState *s = pdu->s; + int64_t size; + V9fsString name; ssize_t err = 0; - V9fsXattrState *vs; + size_t offset = 7; int32_t fid, newfid; + V9fsFidState *file_fidp; + V9fsFidState *xattr_fidp; + V9fsPDU *pdu = opaque; + V9fsState *s = pdu->s; - vs = qemu_malloc(sizeof(*vs)); - vs->pdu = pdu; - vs->offset = 7; - - pdu_unmarshal(vs->pdu, vs->offset, "dds", &fid, &newfid, &vs->name); - vs->file_fidp = lookup_fid(s, fid); - if (vs->file_fidp == NULL) { + pdu_unmarshal(pdu, offset, "dds", &fid, &newfid, &name); + file_fidp = lookup_fid(s, fid); + if (file_fidp == NULL) { err = -ENOENT; goto out; } - - vs->xattr_fidp = alloc_fid(s, newfid); - if (vs->xattr_fidp == NULL) { + xattr_fidp = alloc_fid(s, newfid); + if (xattr_fidp == NULL) { err = -EINVAL; goto out; } - - v9fs_string_copy(&vs->xattr_fidp->path, &vs->file_fidp->path); - if (vs->name.data[0] == 0) { + v9fs_string_copy(&xattr_fidp->path, &file_fidp->path); + if (name.data[0] == 0) { /* * listxattr request. Get the size first */ - vs->size = v9fs_do_llistxattr(s, &vs->xattr_fidp->path, - NULL, 0); - if (vs->size < 0) { - err = vs->size; + size = v9fs_co_llistxattr(s, &xattr_fidp->path, NULL, 0); + if (size < 0) { + err = size; + free_fid(s, xattr_fidp->fid); + goto out; } - v9fs_post_lxattr_check(s, vs, err); - return; + /* + * Read the xattr value + */ + xattr_fidp->fs.xattr.len = size; + xattr_fidp->fid_type = P9_FID_XATTR; + xattr_fidp->fs.xattr.copied_len = -1; + if (size) { + xattr_fidp->fs.xattr.value = qemu_malloc(size); + err = v9fs_co_llistxattr(s, &xattr_fidp->path, + xattr_fidp->fs.xattr.value, + xattr_fidp->fs.xattr.len); + if (err < 0) { + free_fid(s, xattr_fidp->fid); + goto out; + } + } + offset += pdu_marshal(pdu, offset, "q", size); + err = offset; } else { /* * specific xattr fid. We check for xattr * presence also collect the xattr size */ - vs->size = v9fs_do_lgetxattr(s, &vs->xattr_fidp->path, - &vs->name, NULL, 0); - if (vs->size < 0) { - err = vs->size; + size = v9fs_co_lgetxattr(s, &xattr_fidp->path, + &name, NULL, 0); + if (size < 0) { + err = size; + free_fid(s, xattr_fidp->fid); + goto out; } - v9fs_post_xattr_check(s, vs, err); - return; + /* + * Read the xattr value + */ + xattr_fidp->fs.xattr.len = size; + xattr_fidp->fid_type = P9_FID_XATTR; + xattr_fidp->fs.xattr.copied_len = -1; + if (size) { + xattr_fidp->fs.xattr.value = qemu_malloc(size); + err = v9fs_co_lgetxattr(s, &xattr_fidp->path, + &name, xattr_fidp->fs.xattr.value, + xattr_fidp->fs.xattr.len); + if (err < 0) { + free_fid(s, xattr_fidp->fid); + goto out; + } + } + offset += pdu_marshal(pdu, offset, "q", size); + err = offset; } out: - complete_pdu(s, vs->pdu, err); - v9fs_string_free(&vs->name); - qemu_free(vs); + complete_pdu(s, pdu, err); + v9fs_string_free(&name); } static void v9fs_xattrcreate(void *opaque)