[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/6] This patch converts v9fs_read() to make use of
From: |
Arun R Bharadwaj |
Subject: |
[Qemu-devel] [PATCH 3/6] This patch converts v9fs_read() to make use of the threadlets infrastructure. |
Date: |
Wed, 13 Oct 2010 22:39:55 +0530 |
User-agent: |
StGit/0.15 |
From: Gautham R Shenoy <address@hidden>
This patch offloads all the blocking calls invoked for v9fs_read onto the
helper threads belonging to the threadlets infrastructure. The handling of
the v9fs_post_*read* calls is done from the io-thread context.
Signed-off-by: Gautham R Shenoy <address@hidden>
Signed-off-by: Arun R Bharadwaj <address@hidden>
---
hw/virtio-9p.c | 218 +++++++++++++++++++++++++++++++++++++++++---------------
hw/virtio-9p.h | 5 +
2 files changed, 164 insertions(+), 59 deletions(-)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index cf7e012..da185c3 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -2037,33 +2037,136 @@ out:
complete_pdu(s, pdu, err);
}
-static void v9fs_read_post_readdir(V9fsState *, V9fsReadState *, ssize_t);
+/********************** v9fs_read calls ******************************/
+static void v9fs_read_do_preadv(ThreadletWork *work)
+{
+ V9fsReadState *vs;
+
+ vs = container_of(work, V9fsReadState, work);
+ v9fs_do_preadv(vs->s, vs->fidp->fs.fd, vs->sg, vs->cnt, vs->off);
+ vs->v9fs_errno = errno;
+
+ v9fs_async_helper_done(vs->post_fn, vs);
+}
+
+static void v9fs_read_do_rewinddir(ThreadletWork *work)
+ {
+ V9fsReadState *vs;
+
+ vs = container_of(work, V9fsReadState, work);
+ v9fs_do_rewinddir(vs->s, vs->fidp->fs.dir);
+ vs->v9fs_errno = errno;
-static void v9fs_read_post_seekdir(V9fsState *s, V9fsReadState *vs, ssize_t
err)
+ v9fs_async_helper_done(vs->post_fn, vs);
+}
+
+static void v9fs_read_do_lseek(ThreadletWork *work)
{
- if (err) {
+ V9fsReadState *vs;
+
+ vs = container_of(work, V9fsReadState, work);
+ vs->err = v9fs_do_lseek(vs->s, vs->fidp->fs.fd, vs->off, SEEK_SET);
+ vs->v9fs_errno = errno;
+
+ v9fs_async_helper_done(vs->post_fn, vs);
+}
+
+static void v9fs_read_do_readv(ThreadletWork *work)
+{
+ V9fsReadState *vs;
+
+ vs = container_of(work, V9fsReadState, work);
+ do {
+ if (0) {
+ print_sg(vs->sg, vs->cnt);
+ }
+ vs->len = v9fs_do_readv(vs->s, vs->fidp->fs.fd, vs->sg, vs->cnt);
+ } while (vs->len == -1 && errno == EINTR);
+ vs->v9fs_errno = errno;
+
+ if (vs->len == -1) {
+ vs->err = -vs->v9fs_errno;
+ }
+
+ v9fs_async_helper_done(vs->post_fn, vs);
+}
+
+static void v9fs_read_do_telldir(ThreadletWork *work)
+{
+ V9fsReadState *vs;
+
+ vs = container_of(work, V9fsReadState, work);
+ vs->dir_pos = v9fs_do_telldir(vs->s, vs->fidp->fs.dir);
+ vs->v9fs_errno = errno;
+
+ v9fs_async_helper_done(vs->post_fn, vs);
+}
+
+static void v9fs_read_do_readdir(ThreadletWork *work)
+{
+ V9fsReadState *vs;
+
+ vs = container_of(work, V9fsReadState, work);
+ vs->dent = v9fs_do_readdir(vs->s, vs->fidp->fs.dir);
+ vs->v9fs_errno = errno;
+
+ v9fs_async_helper_done(vs->post_fn, vs);
+}
+
+static void v9fs_read_do_lstat(ThreadletWork *work)
+{
+ V9fsReadState *vs;
+
+ vs = container_of(work, V9fsReadState, work);
+ vs->err = v9fs_do_lstat(vs->s, &vs->name, &vs->stbuf);
+ vs->v9fs_errno = errno;
+
+ v9fs_async_helper_done(vs->post_fn, vs);
+}
+
+static void v9fs_read_do_seekdir(ThreadletWork *work)
+{
+ V9fsReadState *vs;
+
+ vs = container_of(work, V9fsReadState, work);
+ v9fs_do_seekdir(vs->s, vs->fidp->fs.dir, vs->dir_pos);
+ vs->v9fs_errno = errno;
+
+ v9fs_async_helper_done(vs->post_fn, vs);
+}
+
+
+
+static void v9fs_read_post_readdir(void *);
+
+static void v9fs_read_post_seekdir(void *opaque)
+{
+ V9fsReadState *vs = (V9fsReadState *)opaque;
+
+ if (vs->err) {
goto out;
}
v9fs_stat_free(&vs->v9stat);
v9fs_string_free(&vs->name);
vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->count);
vs->offset += vs->count;
- err = vs->offset;
+ vs->err = vs->offset;
out:
- complete_pdu(s, vs->pdu, err);
+ complete_pdu(vs->s, vs->pdu, vs->err);
qemu_free(vs);
return;
}
-static void v9fs_read_post_dir_lstat(V9fsState *s, V9fsReadState *vs,
- ssize_t err)
+static void v9fs_read_post_dir_lstat(void *opaque)
{
- if (err) {
- err = -errno;
+ V9fsReadState *vs = (V9fsReadState *)opaque;
+
+ if (vs->err) {
+ vs->err = -vs->v9fs_errno;
goto out;
}
- err = stat_to_v9stat(s, &vs->name, &vs->stbuf, &vs->v9stat);
- if (err) {
+ vs->err = stat_to_v9stat(vs->s, &vs->name, &vs->stbuf, &vs->v9stat);
+ if (vs->err) {
goto out;
}
@@ -2071,26 +2174,28 @@ 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->fs.dir, vs->dir_pos);
- v9fs_read_post_seekdir(s, vs, err);
+ v9fs_do_async_posix(&vs->work, v9fs_read_do_seekdir, &vs->post_fn,
+ v9fs_read_post_seekdir);
return;
}
vs->count += vs->len;
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->fs.dir);
- v9fs_read_post_readdir(s, vs, err);
+ v9fs_do_async_posix(&vs->work, v9fs_read_do_readdir, &vs->post_fn,
+ v9fs_read_post_readdir);
return;
out:
- v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->dir_pos);
- v9fs_read_post_seekdir(s, vs, err);
+ v9fs_do_async_posix(&vs->work, v9fs_read_do_seekdir, &vs->post_fn,
+ v9fs_read_post_seekdir);
return;
}
-static void v9fs_read_post_readdir(V9fsState *s, V9fsReadState *vs, ssize_t
err)
+static void v9fs_read_post_readdir(void *opaque)
{
+ V9fsReadState *vs = (V9fsReadState *)opaque;
+
if (vs->dent) {
memset(&vs->v9stat, 0, sizeof(vs->v9stat));
v9fs_string_init(&vs->name);
@@ -2098,64 +2203,61 @@ static void v9fs_read_post_readdir(V9fsState *s,
V9fsReadState *vs, ssize_t err)
vs->dent->d_name);
err = v9fs_do_lstat(s, &vs->name, &vs->stbuf);
v9fs_read_post_dir_lstat(s, vs, err);
+ v9fs_do_async_posix(&vs->work, v9fs_read_do_lstat, &vs->post_fn,
+ v9fs_read_post_dir_lstat);
return;
}
vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->count);
vs->offset += vs->count;
- err = vs->offset;
- complete_pdu(s, vs->pdu, err);
+ vs->err = vs->offset;
+ complete_pdu(vs->s, vs->pdu, vs->err);
qemu_free(vs);
return;
}
-static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t
err)
+static void v9fs_read_post_telldir(void *opaque)
{
- vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir);
- v9fs_read_post_readdir(s, vs, err);
+ V9fsReadState *vs = (V9fsReadState *)opaque;
+
+ v9fs_do_async_posix(&vs->work, v9fs_read_do_readdir, &vs->post_fn,
+ v9fs_read_post_readdir);
return;
}
-static void v9fs_read_post_rewinddir(V9fsState *s, V9fsReadState *vs,
- ssize_t err)
+static void v9fs_read_post_rewinddir(void *opaque)
{
- vs->dir_pos = v9fs_do_telldir(s, vs->fidp->fs.dir);
- v9fs_read_post_telldir(s, vs, err);
+ V9fsReadState *vs = (V9fsReadState *)opaque;
+
+ v9fs_do_async_posix(&vs->work, v9fs_read_do_telldir, &vs->post_fn,
+ v9fs_read_post_telldir);
return;
}
-static void v9fs_read_post_preadv(V9fsState *s, V9fsReadState *vs, ssize_t err)
+static void v9fs_read_post_preadv(void *opaque)
{
- if (err < 0) {
+ V9fsReadState *vs = (V9fsReadState *)opaque;
+
+ if (vs->err < 0) {
/* IO error return the error */
- err = -errno;
+ vs->err = -errno;
goto out;
+ } else {
+ vs->off += vs->len;
}
vs->total += vs->len;
vs->sg = adjust_sg(vs->sg, vs->len, &vs->cnt);
if (vs->total < vs->count && vs->len > 0) {
- do {
- if (0) {
- print_sg(vs->sg, vs->cnt);
- }
- vs->len = v9fs_do_preadv(s, vs->fidp->fs.fd, vs->sg, vs->cnt,
- vs->off);
- if (vs->len > 0) {
- vs->off += vs->len;
- }
- } while (vs->len == -1 && errno == EINTR);
- if (vs->len == -1) {
- err = -errno;
- }
- v9fs_read_post_preadv(s, vs, err);
+ v9fs_do_async_posix(&vs->work, v9fs_read_do_preadv, &vs->post_fn,
+ v9fs_read_post_preadv);
return;
}
vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total);
vs->offset += vs->count;
- err = vs->offset;
+ vs->err = vs->offset;
out:
- complete_pdu(s, vs->pdu, err);
+ complete_pdu(vs->s, vs->pdu, vs->err);
qemu_free(vs);
}
@@ -2188,7 +2290,6 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
{
int32_t fid;
V9fsReadState *vs;
- ssize_t err = 0;
vs = qemu_malloc(sizeof(*vs));
vs->pdu = pdu;
@@ -2196,12 +2297,13 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
vs->total = 0;
vs->len = 0;
vs->count = 0;
+ vs->s = s;
pdu_unmarshal(vs->pdu, vs->offset, "dqd", &fid, &vs->off, &vs->count);
vs->fidp = lookup_fid(s, fid);
if (vs->fidp == NULL) {
- err = -EINVAL;
+ vs->err = -EINVAL;
goto out;
}
@@ -2209,32 +2311,30 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
vs->max_count = vs->count;
vs->count = 0;
if (vs->off == 0) {
- v9fs_do_rewinddir(s, vs->fidp->fs.dir);
+ v9fs_do_async_posix(&vs->work, v9fs_read_do_rewinddir,
+ &vs->post_fn, v9fs_read_post_rewinddir);
+ return;
}
- v9fs_read_post_rewinddir(s, vs, err);
+ v9fs_read_post_rewinddir(vs);
return;
} else if (vs->fidp->fid_type == P9_FID_FILE) {
vs->sg = vs->iov;
pdu_marshal(vs->pdu, vs->offset + 4, "v", vs->sg, &vs->cnt);
vs->sg = cap_sg(vs->sg, vs->count, &vs->cnt);
if (vs->total <= vs->count) {
- vs->len = v9fs_do_preadv(s, vs->fidp->fs.fd, vs->sg, vs->cnt,
- vs->off);
- if (vs->len > 0) {
- vs->off += vs->len;
- }
- err = vs->len;
- v9fs_read_post_preadv(s, vs, err);
+ vs->err = vs->len;
+ v9fs_do_async_posix(&vs->work, v9fs_read_do_preadv,
+ &vs->post_fn, v9fs_read_post_preadv);
}
return;
} else if (vs->fidp->fid_type == P9_FID_XATTR) {
v9fs_xattr_read(s, vs);
return;
} else {
- err = -EINVAL;
+ vs->err = -EINVAL;
}
out:
- complete_pdu(s, pdu, err);
+ complete_pdu(s, pdu, vs->err);
qemu_free(vs);
}
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index 74d7b68..fcea434 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -325,6 +325,11 @@ typedef struct V9fsReadState {
int32_t len;
int32_t cnt;
int32_t max_count;
+ V9fsState *s;
+ int err;
+ int v9fs_errno;
+ ThreadletWork work;
+ void (*post_fn)(void *arg);
} V9fsReadState;
typedef struct V9fsWriteState {
- [Qemu-devel] [RFC PATCH 0/6] First Threading Model, Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 1/6] This patch converts v9fs_stat() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 2/6] This patch converts v9fs_wstat() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 3/6] This patch converts v9fs_read() to make use of the threadlets infrastructure.,
Arun R Bharadwaj <=
- [Qemu-devel] [PATCH 4/6] This patch converts v9fs_write() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 5/6] This patch converts v9fs_open() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 6/6] This patch converts v9fs_walk() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [RFC PATCH 0/6] First threading model, Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 1/6] This patch converts v9fs_stat() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 2/6] This patch converts v9fs_wstat() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 3/6] This patch converts v9fs_read() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 4/6] This patch converts v9fs_write() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 5/6] This patch converts v9fs_open() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13
- [Qemu-devel] [PATCH 6/6] This patch converts v9fs_walk() to make use of the threadlets infrastructure., Arun R Bharadwaj, 2010/10/13