From patchwork Wed May 25 23:53:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jvrao X-Patchwork-Id: 97470 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 14F0FB6F94 for ; Thu, 26 May 2011 10:00:25 +1000 (EST) Received: from localhost ([::1]:43349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPNzy-0007OK-IZ for incoming@patchwork.ozlabs.org; Wed, 25 May 2011 20:00:22 -0400 Received: from eggs.gnu.org ([140.186.70.92]:49166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPNta-0008KZ-B9 for qemu-devel@nongnu.org; Wed, 25 May 2011 19:53:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QPNtW-0007ZK-Qk for qemu-devel@nongnu.org; Wed, 25 May 2011 19:53:46 -0400 Received: from e36.co.us.ibm.com ([32.97.110.154]:38533) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPNtW-0007Z6-Br for qemu-devel@nongnu.org; Wed, 25 May 2011 19:53:42 -0400 Received: from d03relay05.boulder.ibm.com (d03relay05.boulder.ibm.com [9.17.195.107]) by e36.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p4PNlnfm025242 for ; Wed, 25 May 2011 17:47:49 -0600 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p4PNrZR3277360 for ; Wed, 25 May 2011 17:53:35 -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 p4PHr7IO018608 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 p4PHqwLw018178; Wed, 25 May 2011 11:53:07 -0600 From: "Venkateswararao Jujjuri (JV)" To: qemu-devel@nongnu.org Date: Wed, 25 May 2011 16:53:13 -0700 Message-Id: <1306367597-797-26-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.154 Cc: "Venkateswararao Jujjuri \"" , stefanha@linux.vnet.ibm.com, "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH 25/29] hw/9pfs: Update v9fs_wstat 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 | 265 ++++++++++++-------------------------------------- hw/9pfs/virtio-9p.h | 10 -- 2 files changed, 64 insertions(+), 211 deletions(-) diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index c4e9efb..b378fc8 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -103,40 +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_chmod(V9fsState *s, V9fsString *path, mode_t mode) -{ - FsCred cred; - cred_init(&cred); - cred.fc_mode = mode; - return s->ops->chmod(&s->ctx, path->data, &cred); -} - -static int v9fs_do_truncate(V9fsState *s, V9fsString *path, off_t size) -{ - return s->ops->truncate(&s->ctx, path->data, size); -} - -static int v9fs_do_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid) -{ - FsCred cred; - cred_init(&cred); - cred.fc_uid = uid; - cred.fc_gid = gid; - - return s->ops->chown(&s->ctx, path->data, &cred); -} - -static int v9fs_do_utimensat(V9fsState *s, V9fsString *path, - const struct timespec times[2]) -{ - return s->ops->utimensat(&s->ctx, path->data, times); -} - -static int v9fs_do_fsync(V9fsState *s, int fd, int datasync) -{ - return s->ops->fsync(&s->ctx, fd, datasync); -} - static void v9fs_string_init(V9fsString *str) { str->data = NULL; @@ -2183,39 +2149,6 @@ out: complete_pdu(pdu->s, pdu, err); } -static void v9fs_wstat_post_truncate(V9fsState *s, V9fsWstatState *vs, int err) -{ - if (err < 0) { - goto out; - } - - err = vs->offset; - -out: - v9fs_stat_free(&vs->v9stat); - complete_pdu(s, vs->pdu, err); - qemu_free(vs); -} - -static void v9fs_wstat_post_rename(V9fsState *s, V9fsWstatState *vs, int err) -{ - if (err < 0) { - goto out; - } - if (vs->v9stat.length != -1) { - if (v9fs_do_truncate(s, &vs->fidp->path, vs->v9stat.length) < 0) { - err = -errno; - } - } - v9fs_wstat_post_truncate(s, vs, err); - return; - -out: - v9fs_stat_free(&vs->v9stat); - complete_pdu(s, vs->pdu, err); - qemu_free(vs); -} - static int v9fs_complete_rename(V9fsState *s, V9fsFidState *fidp, int32_t newdirfid, V9fsString *name) { @@ -2284,24 +2217,6 @@ out: return err; } -static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err) -{ - if (err < 0) { - goto out; - } - - if (vs->v9stat.name.size != 0) { - err = v9fs_complete_rename(s, vs->fidp, -1, &vs->v9stat.name); - } - v9fs_wstat_post_rename(s, vs, err); - return; - -out: - v9fs_stat_free(&vs->v9stat); - complete_pdu(s, vs->pdu, err); - qemu_free(vs); -} - static void v9fs_rename(void *opaque) { int32_t fid; @@ -2333,143 +2248,91 @@ out: v9fs_string_free(&name); } -static void v9fs_wstat_post_utime(V9fsState *s, V9fsWstatState *vs, int err) +static void v9fs_wstat(void *opaque) { - if (err < 0) { - goto out; - } - - if (vs->v9stat.n_gid != -1 || vs->v9stat.n_uid != -1) { - if (v9fs_do_chown(s, &vs->fidp->path, vs->v9stat.n_uid, - vs->v9stat.n_gid)) { - err = -errno; - } - } - v9fs_wstat_post_chown(s, vs, err); - return; + int32_t fid; + int err = 0; + int16_t unused; + V9fsStat v9stat; + size_t offset = 7; + struct stat stbuf; + V9fsFidState *fidp; + V9fsPDU *pdu = opaque; + V9fsState *s = pdu->s; -out: - v9fs_stat_free(&vs->v9stat); - complete_pdu(s, vs->pdu, err); - qemu_free(vs); -} + pdu_unmarshal(pdu, offset, "dwS", &fid, &unused, &v9stat); -static void v9fs_wstat_post_chmod(V9fsState *s, V9fsWstatState *vs, int err) -{ - if (err < 0) { + fidp = lookup_fid(s, fid); + if (fidp == NULL) { + err = -EINVAL; goto out; } - - if (vs->v9stat.mtime != -1 || vs->v9stat.atime != -1) { + /* do we need to sync the file? */ + if (donttouch_stat(&v9stat)) { + err = v9fs_co_fsync(s, fidp, 0); + goto out; + } + if (v9stat.mode != -1) { + uint32_t v9_mode; + err = v9fs_co_lstat(s, &fidp->path, &stbuf); + if (err < 0) { + goto out; + } + v9_mode = stat_to_v9mode(&stbuf); + if ((v9stat.mode & P9_STAT_MODE_TYPE_BITS) != + (v9_mode & P9_STAT_MODE_TYPE_BITS)) { + /* Attempting to change the type */ + err = -EIO; + goto out; + } + err = v9fs_co_chmod(s, &fidp->path, + v9mode_to_mode(v9stat.mode, + &v9stat.extension)); + if (err < 0) { + goto out; + } + } + if (v9stat.mtime != -1 || v9stat.atime != -1) { struct timespec times[2]; - if (vs->v9stat.atime != -1) { - times[0].tv_sec = vs->v9stat.atime; + if (v9stat.atime != -1) { + times[0].tv_sec = v9stat.atime; times[0].tv_nsec = 0; } else { times[0].tv_nsec = UTIME_OMIT; } - if (vs->v9stat.mtime != -1) { - times[1].tv_sec = vs->v9stat.mtime; + if (v9stat.mtime != -1) { + times[1].tv_sec = v9stat.mtime; times[1].tv_nsec = 0; } else { times[1].tv_nsec = UTIME_OMIT; } - - if (v9fs_do_utimensat(s, &vs->fidp->path, times)) { - err = -errno; + err = v9fs_co_utimensat(s, &fidp->path, times); + if (err < 0) { + goto out; } } - - v9fs_wstat_post_utime(s, vs, err); - return; - -out: - v9fs_stat_free(&vs->v9stat); - complete_pdu(s, vs->pdu, err); - qemu_free(vs); -} - -static void v9fs_wstat_post_fsync(V9fsState *s, V9fsWstatState *vs, int err) -{ - if (err == -1) { - err = -errno; - } - v9fs_stat_free(&vs->v9stat); - complete_pdu(s, vs->pdu, err); - qemu_free(vs); -} - -static void v9fs_wstat_post_lstat(V9fsState *s, V9fsWstatState *vs, int err) -{ - uint32_t v9_mode; - - if (err == -1) { - err = -errno; - goto out; - } - - v9_mode = stat_to_v9mode(&vs->stbuf); - - if ((vs->v9stat.mode & P9_STAT_MODE_TYPE_BITS) != - (v9_mode & P9_STAT_MODE_TYPE_BITS)) { - /* Attempting to change the type */ - err = -EIO; + if (v9stat.n_gid != -1 || v9stat.n_uid != -1) { + err = v9fs_co_chown(s, &fidp->path, v9stat.n_uid, v9stat.n_gid); + if (err < 0) { goto out; + } } - - if (v9fs_do_chmod(s, &vs->fidp->path, v9mode_to_mode(vs->v9stat.mode, - &vs->v9stat.extension))) { - err = -errno; - } - v9fs_wstat_post_chmod(s, vs, err); - return; - -out: - v9fs_stat_free(&vs->v9stat); - complete_pdu(s, vs->pdu, err); - qemu_free(vs); -} - -static void v9fs_wstat(void *opaque) -{ - V9fsPDU *pdu = opaque; - V9fsState *s = pdu->s; - int32_t fid; - V9fsWstatState *vs; - int err = 0; - - vs = qemu_malloc(sizeof(*vs)); - vs->pdu = pdu; - vs->offset = 7; - - pdu_unmarshal(pdu, vs->offset, "dwS", &fid, &vs->unused, &vs->v9stat); - - vs->fidp = lookup_fid(s, fid); - if (vs->fidp == NULL) { - err = -EINVAL; - goto out; - } - - /* do we need to sync the file? */ - if (donttouch_stat(&vs->v9stat)) { - err = v9fs_do_fsync(s, vs->fidp->fs.fd, 0); - v9fs_wstat_post_fsync(s, vs, err); - return; + if (v9stat.name.size != 0) { + err = v9fs_complete_rename(s, fidp, -1, &v9stat.name); + if (err < 0) { + goto out; + } } - - if (vs->v9stat.mode != -1) { - err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf); - v9fs_wstat_post_lstat(s, vs, err); - return; + if (v9stat.length != -1) { + err = v9fs_co_truncate(s, &fidp->path, v9stat.length); + if (err < 0) { + goto out; + } } - - v9fs_wstat_post_chmod(s, vs, err); - return; - + err = offset; out: - v9fs_stat_free(&vs->v9stat); - complete_pdu(s, vs->pdu, err); - qemu_free(vs); + v9fs_stat_free(&v9stat); + complete_pdu(s, pdu, err); } static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf) diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h index 29f3184..1d8c1b1 100644 --- a/hw/9pfs/virtio-9p.h +++ b/hw/9pfs/virtio-9p.h @@ -295,16 +295,6 @@ typedef struct V9fsWriteState { int cnt; } V9fsWriteState; -typedef struct V9fsWstatState -{ - V9fsPDU *pdu; - size_t offset; - int16_t unused; - V9fsStat v9stat; - V9fsFidState *fidp; - struct stat stbuf; -} V9fsWstatState; - typedef struct V9fsIattr { int32_t valid;