From: "Venkateswararao Jujjuri (JV)" <jvrao@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, "M. Mohan Kumar" <mohan@in.ibm.com>,
Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH -V4 15/26] rename - change name of file or directory
Date: Sun, 29 Aug 2010 12:02:41 -0700 [thread overview]
Message-ID: <1283108572-20228-16-git-send-email-jvrao@linux.vnet.ibm.com> (raw)
In-Reply-To: <1283108572-20228-1-git-send-email-jvrao@linux.vnet.ibm.com>
From: M. Mohan Kumar <mohan@in.ibm.com>
size[4] Trename tag[2] fid[4] newdirfid[4] name[s]
size[4] Rrename tag[2]
Implement the 2000.L rename operation. A new function
v9fs_complete_rename is introduced that acts as a common entry point
for 2000.L rename operation and 2000.U rename opearation (via wstat).
As part of this change the field 'nname' (used only for rename) is
removed from the structure V9fsWstatState. Instead a new structure
V9fsRenameState is used for rename operations both by 2000.U and 2000.L
code paths. Both 2000.U and 2000.L rename code paths construct the
V9fsRenameState structure and passes that to v9fs_complete_rename
function.
Changes from previous version:
Use qemu_mallocz to initialize
Use strcpy,strcat functions instead of memcpy
Changed the variable name to newdirfid
Introduced post rename function
Error checking
Removed nname field from V9fsWstatState
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
---
hw/virtio-9p.c | 156 ++++++++++++++++++++++++++++++++++++++++---------------
hw/virtio-9p.h | 11 ++++-
2 files changed, 123 insertions(+), 44 deletions(-)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 7ea0e96..88dd496 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -2563,11 +2563,6 @@ static void v9fs_wstat_post_rename(V9fsState *s, V9fsWstatState *vs, int err)
if (err < 0) {
goto out;
}
-
- if (vs->v9stat.name.size != 0) {
- v9fs_string_free(&vs->nname);
- }
-
if (vs->v9stat.length != -1) {
if (v9fs_do_truncate(s, &vs->fidp->path, vs->v9stat.length) < 0) {
err = -errno;
@@ -2582,17 +2577,30 @@ out:
qemu_free(vs);
}
-static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err)
+static int v9fs_complete_rename(V9fsState *s, V9fsRenameState *vs)
{
- V9fsFidState *fidp;
- if (err < 0) {
- goto out;
- }
+ int err = 0;
+ char *old_name, *new_name;
+ char *end;
- if (vs->v9stat.name.size != 0) {
- char *old_name, *new_name;
- char *end;
+ if (vs->newdirfid != -1) {
+ V9fsFidState *dirfidp;
+ dirfidp = lookup_fid(s, vs->newdirfid);
+
+ if (dirfidp == NULL) {
+ err = -ENOENT;
+ goto out;
+ }
+
+ BUG_ON(dirfidp->fd != -1);
+ BUG_ON(dirfidp->dir);
+ new_name = qemu_mallocz(dirfidp->path.size + vs->name.size + 2);
+
+ strcpy(new_name, dirfidp->path.data);
+ strcat(new_name, "/");
+ strcat(new_name + dirfidp->path.size, vs->name.data);
+ } else {
old_name = vs->fidp->path.data;
end = strrchr(old_name, '/');
if (end) {
@@ -2600,43 +2608,75 @@ static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err)
} else {
end = old_name;
}
+ new_name = qemu_mallocz(end - old_name + vs->name.size + 1);
- new_name = qemu_mallocz(end - old_name + vs->v9stat.name.size + 1);
+ strncat(new_name, old_name, end - old_name);
+ strncat(new_name + (end - old_name), vs->name.data, vs->name.size);
+ }
- memcpy(new_name, old_name, end - old_name);
- memcpy(new_name + (end - old_name), vs->v9stat.name.data,
- vs->v9stat.name.size);
- vs->nname.data = new_name;
- vs->nname.size = strlen(new_name);
+ v9fs_string_free(&vs->name);
+ vs->name.data = qemu_strdup(new_name);
+ vs->name.size = strlen(new_name);
- if (strcmp(new_name, vs->fidp->path.data) != 0) {
- if (v9fs_do_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));
- }
+ if (strcmp(new_name, vs->fidp->path.data) != 0) {
+ if (v9fs_do_rename(s, &vs->fidp->path, &vs->name)) {
+ err = -errno;
+ } else {
+ V9fsFidState *fidp;
+ /*
+ * 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->name,
+ strlen(vs->fidp->path.data));
}
- v9fs_string_copy(&vs->fidp->path, &vs->nname);
}
+ v9fs_string_copy(&vs->fidp->path, &vs->name);
}
}
+out:
+ v9fs_string_free(&vs->name);
+ return err;
+}
+
+static void v9fs_rename_post_rename(V9fsState *s, V9fsRenameState *vs, int err)
+{
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
+static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err)
+{
+ if (err < 0) {
+ goto out;
+ }
+
+ if (vs->v9stat.name.size != 0) {
+ V9fsRenameState *vr;
+
+ vr = qemu_malloc(sizeof(V9fsRenameState));
+ memset(vr, sizeof(*vr), 0);
+ vr->newdirfid = -1;
+ vr->pdu = vs->pdu;
+ vr->fidp = vs->fidp;
+ vr->offset = vs->offset;
+ vr->name.size = vs->v9stat.name.size;
+ vr->name.data = qemu_strdup(vs->v9stat.name.data);
+
+ err = v9fs_complete_rename(s, vr);
+ qemu_free(vr);
+ }
v9fs_wstat_post_rename(s, vs, err);
return;
@@ -2646,6 +2686,35 @@ out:
qemu_free(vs);
}
+static void v9fs_rename(V9fsState *s, V9fsPDU *pdu)
+{
+ int32_t fid;
+ V9fsRenameState *vs;
+ ssize_t err = 0;
+
+ vs = qemu_malloc(sizeof(*vs));
+ vs->pdu = pdu;
+ vs->offset = 7;
+
+ pdu_unmarshal(vs->pdu, vs->offset, "dds", &fid, &vs->newdirfid, &vs->name);
+
+ vs->fidp = lookup_fid(s, fid);
+ if (vs->fidp == NULL) {
+ err = -ENOENT;
+ goto out;
+ }
+
+ BUG_ON(vs->fidp->fd != -1);
+ BUG_ON(vs->fidp->dir);
+
+ err = v9fs_complete_rename(s, vs);
+ v9fs_rename_post_rename(s, vs, err);
+ return;
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
static void v9fs_wstat_post_utime(V9fsState *s, V9fsWstatState *vs, int err)
{
if (err < 0) {
@@ -3004,6 +3073,7 @@ static pdu_handler_t *pdu_handlers[] = {
[P9_TGETATTR] = v9fs_getattr,
[P9_TSETATTR] = v9fs_setattr,
[P9_TMKNOD] = v9fs_mknod,
+ [P9_TRENAME] = v9fs_rename,
[P9_TMKDIR] = v9fs_mkdir,
[P9_TVERSION] = v9fs_version,
[P9_TATTACH] = v9fs_attach,
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index 91cc0ae..4d179b7 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -21,6 +21,8 @@ enum {
P9_RSYMLINK,
P9_TMKNOD = 18,
P9_RMKNOD,
+ P9_TRENAME = 20,
+ P9_RRENAME,
P9_TGETATTR = 24,
P9_RGETATTR,
P9_TSETATTR = 26,
@@ -310,7 +312,6 @@ typedef struct V9fsWstatState
V9fsStat v9stat;
V9fsFidState *fidp;
struct stat stbuf;
- V9fsString nname;
} V9fsWstatState;
typedef struct V9fsSymlinkState
@@ -385,6 +386,14 @@ typedef struct V9fsMkState {
V9fsString fullname;
} V9fsMkState;
+typedef struct V9fsRenameState {
+ V9fsPDU *pdu;
+ V9fsFidState *fidp;
+ size_t offset;
+ int32_t newdirfid;
+ V9fsString name;
+} V9fsRenameState;
+
extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
size_t offset, size_t size, int pack);
--
1.6.5.2
next prev parent reply other threads:[~2010-08-29 18:53 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-29 19:02 [Qemu-devel] [PATCH-V4 00/26] Consolidated VirtFS work Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 01/26] qemu: virtio-9p: Recognize 9P2000.L protocol Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 02/26] qemu: virtio-9p: Implement statfs support in server Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 03/26] virtio-9p: Return correct error from v9fs_remove Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 04/26] [V4] virtio-9p: readdir implementation for 9p2000.L Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 05/26] virtio-9p: Compute iounit based on host filesystem block size Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 06/26] virtio-9p: getattr server implementation for 9P2000.L protocol Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 07/26] virtio-9p: Do not reset atime Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 08/26] [virtio-9p] Make v9fs_do_utimensat accept timespec structures instead of v9stat Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 09/26] virtio-9p: Implement server side of setattr for 9P2000.L protocol Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 10/26] [virtio-9p] Implement TLINK for 9P2000.L Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 11/26] [virtio-9p] Define and implement TSYMLINK " Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 12/26] [virtio-9p] This patch implements TLCREATE for 9p2000.L protocol Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 13/26] qemu: virtio-9p: Implement TMKNOD Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 14/26] qemu: virtio-9p: Implement TMKDIR Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` Venkateswararao Jujjuri (JV) [this message]
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 16/26] [virtio-9p] qemu: virtio-9p: Implement LOPEN Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 17/26] virtio-9p: Add fidtype so that we can do type specific operation Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 18/26] virtio-9p: Implement TXATTRWALK Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 19/26] virtio-9p: Implement TXATTRCREATE Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 20/26] virtio-9p: Hide user.virtfs xattr in case of mapped security Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 21/26] virtio-9p: Add SM_NONE security model Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 22/26] virtio-9p: Use lchown which won't follow symlink Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 23/26] virtio-9p: Fix the memset usage Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 24/26] [virtio-9p] Remove all instances of unnecessary dotu variable Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 25/26] [virtio-9p] This patch implements TLERROR/RLERROR on the qemu 9P server Venkateswararao Jujjuri (JV)
2010-08-29 19:02 ` [Qemu-devel] [PATCH -V4 26/26] virtio-9p: Change handling of flags in open() path for 9P2000.L Venkateswararao Jujjuri (JV)
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=1283108572-20228-16-git-send-email-jvrao@linux.vnet.ibm.com \
--to=jvrao@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=mohan@in.ibm.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).