From patchwork Wed Mar 3 19:01:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 46870 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 EF03CB7CE6 for ; Thu, 4 Mar 2010 06:40:46 +1100 (EST) Received: from localhost ([127.0.0.1]:56561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmuNK-0003my-MZ for incoming@patchwork.ozlabs.org; Wed, 03 Mar 2010 14:36:54 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NmtpZ-0007b0-8N for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:02:01 -0500 Received: from [199.232.76.173] (port=60477 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmtpX-0007ZG-Dz for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:01:59 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NmtpW-0001c0-7S for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:01:59 -0500 Received: from e35.co.us.ibm.com ([32.97.110.153]:40687) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NmtpV-0001bm-S7 for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:01:58 -0500 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e35.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id o23IvvlV010245 for ; Wed, 3 Mar 2010 11:57:57 -0700 Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o23J1jT3047566 for ; Wed, 3 Mar 2010 12:01:45 -0700 Received: from d03av06.boulder.ibm.com (loopback [127.0.0.1]) by d03av06.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o23J3kue010260 for ; Wed, 3 Mar 2010 12:03:47 -0700 Received: from localhost.localdomain (sig-9-76-214-227.mts.ibm.com [9.76.214.227]) by d03av06.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o23J3daL009640; Wed, 3 Mar 2010 12:03:46 -0700 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 3 Mar 2010 13:01:09 -0600 Message-Id: <1267642874-15001-14-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1267642874-15001-1-git-send-email-aliguori@us.ibm.com> References: <1267642874-15001-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Anthony Liguori , "Aneesh Kumar K.V" , Gautham R Shenoy Subject: [Qemu-devel] [PATCH 12/17] virtio-9p: Implement P9_TREMOVE 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 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: Gautham R Shenoy Signed-off-by: Aneesh Kumar K.V --- hw/virtio-9p-local.c | 7 ++++++ hw/virtio-9p.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c index 0a9f111..43867be 100644 --- a/hw/virtio-9p-local.c +++ b/hw/virtio-9p-local.c @@ -245,6 +245,12 @@ static int local_utime(void *opaque, const char *path, return utime(rpath(path), buf); } +static int local_remove(void *opaque, const char *path) +{ + return remove(rpath(path)); +} + + static V9fsPosixFileOperations ops = { .lstat = local_lstat, .setuid = local_setuid, @@ -272,6 +278,7 @@ static V9fsPosixFileOperations ops = { .rename = local_rename, .chown = local_chown, .utime = local_utime, + .remove = local_remove, }; V9fsPosixFileOperations *virtio_9p_init_local(const char *path) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 836d65b..50ee82a 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -237,6 +237,11 @@ static int posix_utime(V9fsState *s, V9fsString *path, return s->ops->utime(s->ops->opaque, path->data, buf); } +static int posix_remove(V9fsState *s, V9fsString *path) +{ + return s->ops->remove(s->ops->opaque, path->data); +} + static void v9fs_string_init(V9fsString *str) { str->data = NULL; @@ -1719,10 +1724,55 @@ static void v9fs_flush(V9fsState *s, V9fsPDU *pdu) pprint_pdu(pdu); } +typedef struct V9fsRemoveState { + V9fsPDU *pdu; + size_t offset; + int32_t fid; + V9fsFidState *fidp; +} V9fsRemoveState; + +static void v9fs_remove_post_remove(V9fsState *s, V9fsRemoveState *vs, + int err) +{ + if (err) { + err = -errno; + goto out; + } + + err = free_fid(s, vs->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); + V9fsRemoveState *vs; + int err = 0; + + vs = qemu_malloc(sizeof(*vs)); + vs->pdu = pdu; + vs->offset = 7; + + pdu_unmarshal(vs->pdu, vs->offset, "d", &vs->fid); + + vs->fidp = lookup_fid(s, vs->fid); + if (vs->fidp == NULL) { + err = -EINVAL; + goto out; + } + + err = posix_remove(s, &vs->fidp->path); + v9fs_remove_post_remove(s, vs, err); + return; + +out: + complete_pdu(s, pdu, err); + qemu_free(vs); } static mode_t v9mode_to_mode(uint32_t mode, V9fsString *extension)