qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: ericvh@gmail.com, aliguori@us.ibm.com,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH -v2 22/22] virtio-9p: Update existing fid path on rename
Date: Tue, 16 Mar 2010 14:45:20 +0530	[thread overview]
Message-ID: <1268730920-14584-23-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <1268730920-14584-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>

We need to make sure that we update the path component of the existing
fid's when we rename a file. The client is not expected to clunk these fids
pointing to the old name. If we don't update any operation on the old unopened
fid will point to the old name and will fail

Add BUG_ON to make sure when we clone a fid, we don't have open descriptor
attached to the fid. We also need to make sure that when we open a fid, the
specified fid should not already be opened. Capture the case by adding a BUG_ON

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 hw/virtio-9p.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index c8ab6b6..9aa4b72 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -955,6 +955,9 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
 
     /* FIXME: is this really valid? */
     if (fid == newfid) {
+
+        BUG_ON(vs->fidp->fd != -1);
+        BUG_ON(vs->fidp->dir);
         v9fs_string_init(&vs->path);
         vs->name_idx = 0;
 
@@ -1120,6 +1123,9 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
         goto out;
     }
 
+    BUG_ON(vs->fidp->fd != -1);
+    BUG_ON(vs->fidp->dir);
+
     err = posix_lstat(s, &vs->fidp->path, &vs->stbuf);
 
     v9fs_open_post_lstat(s, vs, err);
@@ -1877,8 +1883,19 @@ out:
     qemu_free(vs);
 }
 
+static void v9fs_fix_path(V9fsString *dst, V9fsString *src, int len)
+{
+    V9fsString str;
+    v9fs_string_init(&str);
+    v9fs_string_copy(&str, dst);
+    v9fs_string_sprintf(dst, "%s%s", src->data, str.data+len);
+    v9fs_string_free(&str);
+}
+
+
 static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err)
 {
+    V9fsFidState *fidp;
     if (err < 0) {
         goto out;
     }
@@ -1905,6 +1922,28 @@ static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err)
         if (strcmp(new_name, vs->fidp->path.data) != 0) {
             if (posix_rename(s, &vs->fidp->path, &vs->nname)) {
                 err = -errno;
+            } else {
+                /*
+                 * Fixup fid's pointing to the old name to
+                 * start pointing to the new name
+                 */
+                for (fidp = s->fid_list; fidp; fidp = fidp->next) {
+
+                    if (vs->fidp == fidp) {
+                        /*
+                         * we replace name of this fid towards the end
+                         * so that our below strcmp will work
+                         */
+                        continue;
+                    }
+                    if (!strncmp(vs->fidp->path.data, fidp->path.data,
+                                 strlen(vs->fidp->path.data))) {
+                        /* replace the name */
+                        v9fs_fix_path(&fidp->path, &vs->nname,
+                                      strlen(vs->fidp->path.data));
+                    }
+                }
+                v9fs_string_copy(&vs->fidp->path, &vs->nname);
             }
         }
     }
-- 
1.7.0.2.273.gc2413

  parent reply	other threads:[~2010-03-16  9:16 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-16  9:14 [Qemu-devel] [PATCH -V2 00/22] virtio-9p: paravirtual file system passthrough Aneesh Kumar K.V
2010-03-16  9:14 ` [Qemu-devel] [PATCH -v2 01/22] vitio-9p: Add a virtio 9p device to qemu Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 02/22] vrtio-9p: Implement P9_TVERSION for 9P Aneesh Kumar K.V
2010-03-26 16:15   ` Anthony Liguori
2010-03-29  7:01     ` Aneesh Kumar K. V
2010-03-29 14:51       ` Anthony Liguori
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 03/22] virtio-9p: Implement P9_TATTACH Aneesh Kumar K.V
2010-03-26 16:17   ` Anthony Liguori
2010-03-26 19:12     ` jvrao
2010-03-26 20:06     ` jvrao
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 04/22] virtio-9p: Implement P9_TSTAT Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 05/22] virtio-9p: Implement P9_TWALK Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 06/22] virtio-9p: Implement P9_TOPEN Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 07/22] virtio-9p: Implement P9_TREAD Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 08/22] virtio-9p: Implement P9_TCLUNK Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 09/22] virtio-9p: Implement P9_TWRITE Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 10/22] virtio-9p: Implement P9_TCREATE Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 11/22] virtio-9p: Implement P9_TWSTAT Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 12/22] virtio-9p: Implement P9_TREMOVE Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 13/22] virtio-9p: Implement P9_TFLUSH Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 14/22] virtio-9p: Add multiple mount point support Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 15/22] virtio-9p: Use little endian format on virtio Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 16/22] virtio-9p: Add support for hardlink Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 17/22] Implement sync support in 9p server Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 18/22] virtio-9p: Fix sg usage in the code Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 19/22] virtio-9p: Get the correct count values from the pdu Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 20/22] virtio-9p: Remove BUG_ON and add proper error handling Aneesh Kumar K.V
2010-03-16  9:15 ` [Qemu-devel] [PATCH -v2 21/22] virtio-9p: Remove unnecessary definition of fid Aneesh Kumar K.V
2010-03-16  9:15 ` Aneesh Kumar K.V [this message]
2010-03-23 23:17 ` [Qemu-devel] [PATCH -V2 00/22] virtio-9p: paravirtual file system passthrough Luiz Capitulino
2010-03-24  3:58   ` Aneesh Kumar K. V
2010-03-24 15:04     ` Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1268730920-14584-23-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=ericvh@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).