From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrSsp-00021n-Of for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:16:15 -0400 Received: from [199.232.76.173] (port=57570 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrSsp-00021V-5b for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:16:15 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NrSsm-0001MH-SK for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:16:13 -0400 Received: from mx20.gnu.org ([199.232.41.8]:47223) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NrSsm-0001Fl-0i for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:16:12 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NrSsV-0001Xb-SJ for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:15:56 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp01.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2G9Dlj8009432 for ; Tue, 16 Mar 2010 20:13:47 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2G9A3Eg1736878 for ; Tue, 16 Mar 2010 20:10:03 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2G9FrvB006697 for ; Tue, 16 Mar 2010 20:15:53 +1100 From: "Aneesh Kumar K.V" Date: Tue, 16 Mar 2010 14:45:10 +0530 Message-Id: <1268730920-14584-13-git-send-email-aneesh.kumar@linux.vnet.ibm.com> In-Reply-To: <1268730920-14584-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1268730920-14584-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH -v2 12/22] virtio-9p: Implement P9_TREMOVE List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: ericvh@gmail.com, aliguori@us.ibm.com, "Aneesh Kumar K.V" , Gautham R Shenoy From: Anthony Liguori 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 829e79a..dca6175 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 c8995a3..4478e57 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; @@ -1716,10 +1721,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) -- 1.7.0.2.273.gc2413