[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH-V2 17/24] virtio-9p: Add fidtype so that we can do t
From: |
Venkateswararao Jujjuri (JV) |
Subject: |
[Qemu-devel] [PATCH-V2 17/24] virtio-9p: Add fidtype so that we can do type specific operation |
Date: |
Wed, 21 Jul 2010 09:04:52 -0700 |
From: Aneesh Kumar K.V <address@hidden>
We want to add type specific operation during read/write
Signed-off-by: Aneesh Kumar K.V <address@hidden>
---
hw/virtio-9p.c | 110 ++++++++++++++++++++++++++++++--------------------------
hw/virtio-9p.h | 24 +++++++++++-
2 files changed, 81 insertions(+), 53 deletions(-)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index b4badc1..3e9c525 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -408,8 +408,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
f = qemu_mallocz(sizeof(V9fsFidState));
f->fid = fid;
- f->fd = -1;
- f->dir = NULL;
+ f->fid_type = P9_FID_NONE;
f->next = s->fid_list;
s->fid_list = f;
@@ -434,11 +433,20 @@ static int free_fid(V9fsState *s, int32_t fid)
fidp = *fidpp;
*fidpp = fidp->next;
- if (fidp->fd != -1) {
- v9fs_do_close(s, fidp->fd);
+ if (fidp->fid_type == P9_FID_FILE) {
+ if (fidp->fs.fd != -1) {
+ v9fs_do_close(s, fidp->fs.fd);
+ }
+ }
+ if (fidp->fid_type == P9_FID_DIR) {
+ if (fidp->fs.dir) {
+ v9fs_do_closedir(s, fidp->fs.dir);
+ }
}
- if (fidp->dir) {
- v9fs_do_closedir(s, fidp->dir);
+ if (fidp->fid_type == P9_FID_XATTR) {
+ if (fidp->fs.xattr.value) {
+ qemu_free(fidp->fs.xattr.value);
+ }
}
v9fs_string_free(&fidp->path);
qemu_free(fidp);
@@ -1519,8 +1527,7 @@ 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);
+ BUG_ON(vs->fidp->fid_type != P9_FID_NONE);
v9fs_string_init(&vs->path);
vs->name_idx = 0;
@@ -1584,11 +1591,12 @@ static int32_t get_iounit(V9fsState *s, V9fsString
*name)
static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err)
{
- if (vs->fidp->dir == NULL) {
+ if (vs->fidp->fs.dir == NULL) {
err = -errno;
goto out;
}
+ vs->fidp->fid_type = P9_FID_DIR;
vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0);
err = vs->offset;
out:
@@ -1608,11 +1616,11 @@ static void v9fs_open_post_getiounit(V9fsState *s,
V9fsOpenState *vs)
static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err)
{
- if (vs->fidp->fd == -1) {
+ if (vs->fidp->fs.fd == -1) {
err = -errno;
goto out;
}
-
+ vs->fidp->fid_type = P9_FID_FILE;
vs->iounit = get_iounit(s, &vs->fidp->path);
v9fs_open_post_getiounit(s, vs);
return;
@@ -1642,7 +1650,7 @@ static void v9fs_open_post_lstat(V9fsState *s,
V9fsOpenState *vs, int err)
stat_to_qid(&vs->stbuf, &vs->qid);
if (S_ISDIR(vs->stbuf.st_mode)) {
- vs->fidp->dir = v9fs_do_opendir(s, &vs->fidp->path);
+ vs->fidp->fs.dir = v9fs_do_opendir(s, &vs->fidp->path);
v9fs_open_post_opendir(s, vs, err);
} else {
if (s->proto_version == V9FS_PROTO_2000L) {
@@ -1654,7 +1662,7 @@ static void v9fs_open_post_lstat(V9fsState *s,
V9fsOpenState *vs, int err)
} else {
flags = omode_to_uflags(vs->mode);
}
- vs->fidp->fd = v9fs_do_open(s, &vs->fidp->path, flags);
+ vs->fidp->fs.fd = v9fs_do_open(s, &vs->fidp->path, flags);
v9fs_open_post_open(s, vs, err);
}
return;
@@ -1682,8 +1690,7 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
goto out;
}
- BUG_ON(vs->fidp->fd != -1);
- BUG_ON(vs->fidp->dir);
+ BUG_ON(vs->fidp->fid_type != P9_FID_NONE);
err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf);
@@ -1728,7 +1735,7 @@ out:
static void v9fs_lcreate_post_do_open2(V9fsState *s, V9fsLcreateState *vs,
int err)
{
- if (vs->fidp->fd == -1) {
+ if (vs->fidp->fs.fd == -1) {
err = -errno;
goto out;
}
@@ -1765,7 +1772,7 @@ static void v9fs_lcreate(V9fsState *s, V9fsPDU *pdu)
v9fs_string_sprintf(&vs->fullname, "%s/%s", vs->fidp->path.data,
vs->name.data);
- vs->fidp->fd = v9fs_do_open2(s, vs->fullname.data, vs->fidp->uid,
+ vs->fidp->fs.fd = v9fs_do_open2(s, vs->fullname.data, vs->fidp->uid,
gid, flags, mode);
v9fs_lcreate_post_do_open2(s, vs, err);
return;
@@ -1829,7 +1836,7 @@ static void v9fs_read_post_dir_lstat(V9fsState *s,
V9fsReadState *vs,
&vs->v9stat);
if ((vs->len != (vs->v9stat.size + 2)) ||
((vs->count + vs->len) > vs->max_count)) {
- v9fs_do_seekdir(s, vs->fidp->dir, vs->dir_pos);
+ v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->dir_pos);
v9fs_read_post_seekdir(s, vs, err);
return;
}
@@ -1837,11 +1844,11 @@ static void v9fs_read_post_dir_lstat(V9fsState *s,
V9fsReadState *vs,
v9fs_stat_free(&vs->v9stat);
v9fs_string_free(&vs->name);
vs->dir_pos = vs->dent->d_off;
- vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+ vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir);
v9fs_read_post_readdir(s, vs, err);
return;
out:
- v9fs_do_seekdir(s, vs->fidp->dir, vs->dir_pos);
+ v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->dir_pos);
v9fs_read_post_seekdir(s, vs, err);
return;
@@ -1869,7 +1876,7 @@ static void v9fs_read_post_readdir(V9fsState *s,
V9fsReadState *vs, ssize_t err)
static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t
err)
{
- vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+ vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir);
v9fs_read_post_readdir(s, vs, err);
return;
}
@@ -1877,7 +1884,7 @@ static void v9fs_read_post_telldir(V9fsState *s,
V9fsReadState *vs, ssize_t err)
static void v9fs_read_post_rewinddir(V9fsState *s, V9fsReadState *vs,
ssize_t err)
{
- vs->dir_pos = v9fs_do_telldir(s, vs->fidp->dir);
+ vs->dir_pos = v9fs_do_telldir(s, vs->fidp->fs.dir);
v9fs_read_post_telldir(s, vs, err);
return;
}
@@ -1896,7 +1903,7 @@ static void v9fs_read_post_readv(V9fsState *s,
V9fsReadState *vs, ssize_t err)
if (0) {
print_sg(vs->sg, vs->cnt);
}
- vs->len = v9fs_do_readv(s, vs->fidp->fd, vs->sg, vs->cnt);
+ vs->len = v9fs_do_readv(s, vs->fidp->fs.fd, vs->sg, vs->cnt);
} while (vs->len == -1 && errno == EINTR);
if (vs->len == -1) {
err = -errno;
@@ -1926,7 +1933,7 @@ static void v9fs_read_post_lseek(V9fsState *s,
V9fsReadState *vs, ssize_t err)
if (0) {
print_sg(vs->sg, vs->cnt);
}
- vs->len = v9fs_do_readv(s, vs->fidp->fd, vs->sg, vs->cnt);
+ vs->len = v9fs_do_readv(s, vs->fidp->fs.fd, vs->sg, vs->cnt);
} while (vs->len == -1 && errno == EINTR);
if (vs->len == -1) {
err = -errno;
@@ -1960,18 +1967,18 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
goto out;
}
- if (vs->fidp->dir) {
+ if (vs->fidp->fs.dir) {
vs->max_count = vs->count;
vs->count = 0;
if (vs->off == 0) {
- v9fs_do_rewinddir(s, vs->fidp->dir);
+ v9fs_do_rewinddir(s, vs->fidp->fs.dir);
}
v9fs_read_post_rewinddir(s, vs, err);
return;
- } else if (vs->fidp->fd != -1) {
+ } else if (vs->fidp->fs.fd != -1) {
vs->sg = vs->iov;
pdu_marshal(vs->pdu, vs->offset + 4, "v", vs->sg, &vs->cnt);
- err = v9fs_do_lseek(s, vs->fidp->fd, vs->off, SEEK_SET);
+ err = v9fs_do_lseek(s, vs->fidp->fs.fd, vs->off, SEEK_SET);
v9fs_read_post_lseek(s, vs, err);
return;
} else {
@@ -2020,7 +2027,7 @@ static void v9fs_readdir_post_readdir(V9fsState *s,
V9fsReadDirState *vs)
if ((vs->count + V9_READDIR_DATA_SZ) > vs->max_count) {
/* Ran out of buffer. Set dir back to old position and return */
- v9fs_do_seekdir(s, vs->fidp->dir, vs->saved_dir_pos);
+ v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->saved_dir_pos);
v9fs_readdir_post_seekdir(s, vs);
return;
}
@@ -2041,7 +2048,7 @@ static void v9fs_readdir_post_readdir(V9fsState *s,
V9fsReadDirState *vs)
vs->count += len;
v9fs_string_free(&vs->name);
vs->saved_dir_pos = vs->dent->d_off;
- vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+ vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir);
v9fs_readdir_post_readdir(s, vs);
return;
}
@@ -2055,14 +2062,14 @@ static void v9fs_readdir_post_readdir(V9fsState *s,
V9fsReadDirState *vs)
static void v9fs_readdir_post_telldir(V9fsState *s, V9fsReadDirState *vs)
{
- vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+ vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir);
v9fs_readdir_post_readdir(s, vs);
return;
}
static void v9fs_readdir_post_setdir(V9fsState *s, V9fsReadDirState *vs)
{
- vs->saved_dir_pos = v9fs_do_telldir(s, vs->fidp->dir);
+ vs->saved_dir_pos = v9fs_do_telldir(s, vs->fidp->fs.dir);
v9fs_readdir_post_telldir(s, vs);
return;
}
@@ -2083,15 +2090,15 @@ static void v9fs_readdir(V9fsState *s, V9fsPDU *pdu)
&vs->max_count);
vs->fidp = lookup_fid(s, fid);
- if (vs->fidp == NULL || !(vs->fidp->dir)) {
+ if (vs->fidp == NULL || !(vs->fidp->fs.dir)) {
err = -EINVAL;
goto out;
}
if (vs->initial_offset == 0) {
- v9fs_do_rewinddir(s, vs->fidp->dir);
+ v9fs_do_rewinddir(s, vs->fidp->fs.dir);
} else {
- v9fs_do_seekdir(s, vs->fidp->dir, vs->initial_offset);
+ v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->initial_offset);
}
v9fs_readdir_post_setdir(s, vs);
@@ -2118,7 +2125,7 @@ static void v9fs_write_post_writev(V9fsState *s,
V9fsWriteState *vs,
if (0) {
print_sg(vs->sg, vs->cnt);
}
- vs->len = v9fs_do_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
+ vs->len = v9fs_do_writev(s, vs->fidp->fs.fd, vs->sg, vs->cnt);
} while (vs->len == -1 && errno == EINTR);
if (vs->len == -1) {
err = -errno;
@@ -2147,7 +2154,7 @@ static void v9fs_write_post_lseek(V9fsState *s,
V9fsWriteState *vs, ssize_t err)
if (0) {
print_sg(vs->sg, vs->cnt);
}
- vs->len = v9fs_do_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
+ vs->len = v9fs_do_writev(s, vs->fidp->fs.fd, vs->sg, vs->cnt);
} while (vs->len == -1 && errno == EINTR);
if (vs->len == -1) {
err = -errno;
@@ -2184,12 +2191,12 @@ static void v9fs_write(V9fsState *s, V9fsPDU *pdu)
goto out;
}
- if (vs->fidp->fd == -1) {
+ if (vs->fidp->fs.fd == -1) {
err = -EINVAL;
goto out;
}
- err = v9fs_do_lseek(s, vs->fidp->fd, vs->off, SEEK_SET);
+ err = v9fs_do_lseek(s, vs->fidp->fs.fd, vs->off, SEEK_SET);
v9fs_write_post_lseek(s, vs, err);
return;
@@ -2241,9 +2248,10 @@ static void v9fs_create_post_perms(V9fsState *s,
V9fsCreateState *vs, int err)
static void v9fs_create_post_opendir(V9fsState *s, V9fsCreateState *vs,
int err)
{
- if (!vs->fidp->dir) {
+ if (!vs->fidp->fs.dir) {
err = -errno;
}
+ vs->fidp->fid_type = P9_FID_DIR;
v9fs_post_create(s, vs, err);
}
@@ -2255,7 +2263,7 @@ static void v9fs_create_post_dir_lstat(V9fsState *s,
V9fsCreateState *vs,
goto out;
}
- vs->fidp->dir = v9fs_do_opendir(s, &vs->fullname);
+ vs->fidp->fs.dir = v9fs_do_opendir(s, &vs->fullname);
v9fs_create_post_opendir(s, vs, err);
return;
@@ -2281,7 +2289,7 @@ out:
static void v9fs_create_post_fstat(V9fsState *s, V9fsCreateState *vs, int err)
{
if (err) {
- vs->fidp->fd = -1;
+ vs->fidp->fs.fd = -1;
err = -errno;
}
@@ -2291,12 +2299,12 @@ static void v9fs_create_post_fstat(V9fsState *s,
V9fsCreateState *vs, int err)
static void v9fs_create_post_open2(V9fsState *s, V9fsCreateState *vs, int err)
{
- if (vs->fidp->fd == -1) {
+ if (vs->fidp->fs.fd == -1) {
err = -errno;
goto out;
}
-
- err = v9fs_do_fstat(s, vs->fidp->fd, &vs->stbuf);
+ vs->fidp->fid_type = P9_FID_FILE;
+ err = v9fs_do_fstat(s, vs->fidp->fs.fd, &vs->stbuf);
v9fs_create_post_fstat(s, vs, err);
return;
@@ -2367,7 +2375,7 @@ static void v9fs_create_post_lstat(V9fsState *s,
V9fsCreateState *vs, int err)
0, vs->fidp->uid, -1);
v9fs_post_create(s, vs, err);
} else {
- vs->fidp->fd = v9fs_do_open2(s, vs->fullname.data, vs->fidp->uid,
+ vs->fidp->fs.fd = v9fs_do_open2(s, vs->fullname.data, vs->fidp->uid,
-1, omode_to_uflags(vs->mode)|O_CREAT, vs->perm);
v9fs_create_post_open2(s, vs, err);
@@ -2611,8 +2619,8 @@ static int v9fs_complete_rename(V9fsState *s,
V9fsRenameState *vs)
goto out;
}
- BUG_ON(dirfidp->fd != -1);
- BUG_ON(dirfidp->dir);
+ BUG_ON(dirfidp->fs.fd != -1);
+ BUG_ON(dirfidp->fs.dir);
new_name = qemu_mallocz(dirfidp->path.size + vs->name.size + 2);
@@ -2723,8 +2731,8 @@ static void v9fs_rename(V9fsState *s, V9fsPDU *pdu)
goto out;
}
- BUG_ON(vs->fidp->fd != -1);
- BUG_ON(vs->fidp->dir);
+ BUG_ON(vs->fidp->fs.fd != -1);
+ BUG_ON(vs->fidp->fs.dir);
err = v9fs_complete_rename(s, vs);
v9fs_rename_post_rename(s, vs, err);
@@ -2851,7 +2859,7 @@ static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu)
/* do we need to sync the file? */
if (donttouch_stat(&vs->v9stat)) {
- err = v9fs_do_fsync(s, vs->fidp->fd);
+ err = v9fs_do_fsync(s, vs->fidp->fs.fd);
v9fs_wstat_post_fsync(s, vs, err);
return;
}
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index 542d0bf..3edbdaa 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -155,12 +155,32 @@ typedef struct V9fsStat
int32_t n_muid;
} V9fsStat;
+enum {
+ P9_FID_NONE = 0,
+ P9_FID_FILE,
+ P9_FID_DIR,
+ P9_FID_XATTR,
+};
+
+typedef struct V9fsXattr
+{
+ int64_t copied_len;
+ int64_t len;
+ void *value;
+ V9fsString name;
+ int flags;
+} V9fsXattr;
+
struct V9fsFidState
{
+ int fid_type;
int32_t fid;
V9fsString path;
- int fd;
- DIR *dir;
+ union {
+ int fd;
+ DIR *dir;
+ V9fsXattr xattr;
+ } fs;
uid_t uid;
V9fsFidState *next;
};
--
1.6.5.2
- [Qemu-devel] [PATCH-V2 00/24] Consolidated VirtFS work, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 02/24] qemu: virtio-9p: Implement statfs support in server, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 01/24] qemu: virtio-9p: Recognize 9P2000.L protocol, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 11/24] [virtio-9p] Define and implement TSYMLINK for 9P2000.L, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 10/24] [virtio-9p] Implement TLINK for 9P2000.L, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 19/24] virtio-9p: Implement TXATTRCREATE, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 18/24] virtio-9p: Implement TXATTRWALK, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 03/24] virtio-9p: Return correct error from v9fs_remove, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 06/24] virtio-9p: getattr server implementation for 9P2000.L protocol., Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 17/24] virtio-9p: Add fidtype so that we can do type specific operation,
Venkateswararao Jujjuri (JV) <=
- [Qemu-devel] [PATCH-V2 08/24] [virtio-9p] Make v9fs_do_utimensat accept timespec structures instead of v9stat., Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 16/24] qemu: virtio-9p: Implement LOPEN, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 09/24] virtio-9p: Implement server side of setattr for 9P2000.L protocol., Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 24/24] virtio-9p: Fix formatting issues in v9fs_wstat_post_chown(), Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 23/24] virtio-9p: Fix the memset usage, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 21/24] virtio-9p: Add SM_NONE security model, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 13/24] qemu: virtio-9p: Implement TMKNOD, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 20/24] virtio-9p: Hide user.virtfs xattr in case of mapped security., Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 07/24] virtio-9p: Do not reset atime, Venkateswararao Jujjuri (JV), 2010/07/21
- [Qemu-devel] [PATCH-V2 12/24] [virtio-9p] This patch implements TLCREATE for 9p2000.L protocol., Venkateswararao Jujjuri (JV), 2010/07/21