From patchwork Thu Apr 15 14:11:09 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: 50245 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 071C3B7BEE for ; Fri, 16 Apr 2010 00:27:33 +1000 (EST) Received: from localhost ([127.0.0.1]:41518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O2Px2-0004UD-0C for incoming@patchwork.ozlabs.org; Thu, 15 Apr 2010 10:21:52 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O2PtL-0003Qj-8Z for qemu-devel@nongnu.org; Thu, 15 Apr 2010 10:18:03 -0400 Received: from [140.186.70.92] (port=50361 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O2PtF-0003GA-35 for qemu-devel@nongnu.org; Thu, 15 Apr 2010 10:18:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O2Pn9-0000MX-AJ for qemu-devel@nongnu.org; Thu, 15 Apr 2010 10:12:00 -0400 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:50004) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O2Pn4-0000Ke-VJ for qemu-devel@nongnu.org; Thu, 15 Apr 2010 10:11:37 -0400 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by e28smtp07.in.ibm.com (8.14.3/8.13.1) with ESMTP id o3FEBWCi000318 for ; Thu, 15 Apr 2010 19:41:32 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o3FEBWgR3117184 for ; Thu, 15 Apr 2010 19:41:32 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o3FEBVSe030997 for ; Thu, 15 Apr 2010 19:41:32 +0530 Received: from skywalker.in.ibm.com ([9.77.204.187]) by d28av01.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o3FEBDaN030329; Thu, 15 Apr 2010 19:41:31 +0530 From: "Aneesh Kumar K.V" To: qemu-devel@nongnu.org Date: Thu, 15 Apr 2010 19:41:09 +0530 Message-Id: <1271340671-19558-20-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.4.360.g11766c In-Reply-To: <1271340671-19558-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1271340671-19558-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, aneesh.kumar@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH -V5 19/21] virtio-9p: Add P9_TREMOVE support. 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: Anthony Liguori Implement P9_TREMOVE support. This gets file deletion to work. [mohan@in.ibm.com: Fix truncate to use the relative path] Signed-off-by: Anthony Liguori Signed-off-by: Aneesh Kumar K.V --- hw/file-op-9p.h | 1 + hw/virtio-9p-local.c | 6 ++++++ hw/virtio-9p.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/hw/file-op-9p.h b/hw/file-op-9p.h index 8ba1927..f84767f 100644 --- a/hw/file-op-9p.h +++ b/hw/file-op-9p.h @@ -34,6 +34,7 @@ typedef struct FileOperations int (*mknod)(FsContext *, const char *, mode_t, dev_t); int (*mksock)(FsContext *, const char *); int (*utime)(FsContext *, const char *, const struct utimbuf *); + int (*remove)(FsContext *, const char *); int (*symlink)(FsContext *, const char *, const char *); int (*link)(FsContext *, const char *, const char *); int (*setuid)(FsContext *, uid_t); diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c index 5a011f3..1afb731 100644 --- a/hw/virtio-9p-local.c +++ b/hw/virtio-9p-local.c @@ -252,6 +252,11 @@ static int local_utime(FsContext *ctx, const char *path, return utime(rpath(ctx, path), buf); } +static int local_remove(FsContext *ctx, const char *path) +{ + return remove(rpath(ctx, path)); +} + static int local_fsync(FsContext *ctx, int fd) { return fsync(fd); @@ -284,5 +289,6 @@ FileOperations local_ops = { .rename = local_rename, .chown = local_chown, .utime = local_utime, + .remove = local_remove, .fsync = local_fsync, }; diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index b6a635b..94b7999 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -166,6 +166,11 @@ static int v9fs_do_utime(V9fsState *s, V9fsString *path, return s->ops->utime(&s->ctx, path->data, buf); } +static int v9fs_do_remove(V9fsState *s, V9fsString *path) +{ + return s->ops->remove(&s->ctx, path->data); +} + static int v9fs_do_fsync(V9fsState *s, int fd) { return s->ops->fsync(&s->ctx, fd); @@ -1962,11 +1967,52 @@ static void v9fs_flush(V9fsState *s, V9fsPDU *pdu) } } +typedef struct V9fsRemoveState { + V9fsPDU *pdu; + size_t offset; + V9fsFidState *fidp; +} V9fsRemoveState; + +static void v9fs_remove_post_remove(V9fsState *s, V9fsRemoveState *vs, + int err) +{ + /* For TREMOVE we need to clunk the fid even on failed remove */ + err = free_fid(s, vs->fidp->fid); + if (err < 0) { + goto out; + } + + err = vs->offset; +out: + complete_pdu(s, vs->pdu, err); + qemu_free(vs); +} + static void v9fs_remove(V9fsState *s, V9fsPDU *pdu) { - if (debug_9p_pdu) { - pprint_pdu(pdu); + int32_t fid; + V9fsRemoveState *vs; + int err = 0; + + vs = qemu_malloc(sizeof(*vs)); + vs->pdu = pdu; + vs->offset = 7; + + pdu_unmarshal(vs->pdu, vs->offset, "d", &fid); + + vs->fidp = lookup_fid(s, fid); + if (vs->fidp == NULL) { + err = -EINVAL; + goto out; } + + err = v9fs_do_remove(s, &vs->fidp->path); + v9fs_remove_post_remove(s, vs, err); + return; + +out: + complete_pdu(s, pdu, err); + qemu_free(vs); } typedef struct V9fsWstatState