Patchwork [-V4,19/21] virtio-9p: Add P9_TREMOVE support.

login
register
mail settings
Submitter Aneesh Kumar K.V
Date April 9, 2010, 11:43 a.m.
Message ID <1270813404-23004-20-git-send-email-aneesh.kumar@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/49837/
State New
Headers show

Comments

Aneesh Kumar K.V - April 9, 2010, 11:43 a.m.
From: Anthony Liguori <aliguori@us.ibm.com>

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 <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 hw/file-op-9p.h      |    1 +
 hw/virtio-9p-local.c |    6 +++++
 hw/virtio-9p.c       |   54 ++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 59 insertions(+), 2 deletions(-)

Patch

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..a2a9cd8 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,56 @@  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)
+{
+    if (err) {
+        err = -errno;
+        goto out;
+    }
+
+    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