From patchwork Thu Mar 25 16:43:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 48568 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D7DE0B7CF9 for ; Fri, 26 Mar 2010 05:04:33 +1100 (EST) Received: from localhost ([127.0.0.1]:36149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NurPx-00053r-DA for incoming@patchwork.ozlabs.org; Thu, 25 Mar 2010 14:04:29 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NuqAd-0007Dm-CS for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:35 -0400 Received: from [140.186.70.92] (port=50596 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NuqAX-0007Ba-VT for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NuqAS-0005A2-2E for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:29 -0400 Received: from e23smtp05.au.ibm.com ([202.81.31.147]:46631) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NuqAR-00059d-3x for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:23 -0400 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp05.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2PGeg9L009469 for ; Fri, 26 Mar 2010 03:40:42 +1100 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2PGiLYn1724610 for ; Fri, 26 Mar 2010 03:44:21 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2PGiKB4031510 for ; Fri, 26 Mar 2010 03:44:21 +1100 Received: from localhost.localdomain ([9.77.125.24]) by d23av03.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o2PGhgOq030935; Fri, 26 Mar 2010 03:44:19 +1100 From: "Aneesh Kumar K.V" To: qemu-devel@nongnu.org Date: Thu, 25 Mar 2010 22:13:25 +0530 Message-Id: <1269535420-31206-18-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.2.323.g0d092 In-Reply-To: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: ericvh@gmail.com, aliguori@us.ibm.com, "M. Mohan Kumar" , "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH -V3 17/32] Implement sync support in 9p server X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: M. Mohan Kumar When wstat is called with stat field values set to 'don't touch' pattern, 9p Server interprets it as a request to guarantee that the contents of the associated file are committed to stable storage before the Rwstat message is returned. Implement this feature in the server side. [jvrao@linux.vnet.ibm.com: Proper error handling and state friendliness] Signed-off-by: M. Mohan Kumar Signed-off-by: Aneesh Kumar K.V --- hw/virtio-9p-local.c | 6 ++++++ hw/virtio-9p.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p.h | 1 + 3 files changed, 52 insertions(+), 0 deletions(-) diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c index 4dd6b22..4584bf6 100644 --- a/hw/virtio-9p-local.c +++ b/hw/virtio-9p-local.c @@ -249,6 +249,11 @@ static int local_remove(V9fsState *s, const char *path) } +static int local_fsync(V9fsState *s, int fd) +{ + return fsync(fd); +} + static V9fsPosixFileOperations ops = { .lstat = local_lstat, .setuid = local_setuid, @@ -277,6 +282,7 @@ static V9fsPosixFileOperations ops = { .chown = local_chown, .utime = local_utime, .remove = local_remove, + .fsync = local_fsync, }; V9fsPosixFileOperations *virtio_9p_init_local(const char *path) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 3ddf2b9..3a5b3f0 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -172,6 +172,11 @@ static int posix_remove(V9fsState *s, V9fsString *path) return s->ops->remove(s, path->data); } +static int posix_fsync(V9fsState *s, int fd) +{ + return s->ops->fsync(s, fd); +} + static void v9fs_string_init(V9fsString *str) { str->data = NULL; @@ -1889,6 +1894,39 @@ out: 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 int donttouch_stat(V9fsStat *stat) +{ + if (stat->type == -1 && + stat->dev == -1 && + stat->qid.type == -1 && + stat->qid.version == -1 && + stat->qid.path == -1 && + stat->mode == -1 && + stat->atime == -1 && + stat->mtime == -1 && + stat->length == -1 && + !stat->name.size && + !stat->uid.size && + !stat->gid.size && + !stat->muid.size && + stat->n_uid == -1 && + stat->n_gid == -1 && + stat->n_muid == -1) + return 1; + else + return 0; +} + static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu) { V9fsWstatState *vs; @@ -1906,6 +1944,13 @@ static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu) goto out; } + /* do we need to sync the file? */ + if (donttouch_stat(&vs->v9stat)) { + err = posix_fsync(s, vs->fidp->fd); + v9fs_wstat_post_fsync(s, vs, err); + return; + } + if (vs->v9stat.mode != -1) { if (vs->v9stat.mode & P9_STAT_MODE_DIR && vs->fidp->dir == NULL) { err = -EIO; diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index 3fc88a4..da0aa64 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -182,6 +182,7 @@ typedef struct V9fsPosixFileOpertions int (*fstat)(V9fsState *, int, struct stat *); int (*rename)(V9fsState *, const char *, const char *); int (*truncate)(V9fsState *, const char *, off_t); + int (*fsync)(V9fsState *, int); void *opaque; } V9fsPosixFileOperations;