@@ -2459,37 +2459,41 @@ out:
return;
}
-static void v9fs_write_post_pwritev(V9fsState *s, V9fsWriteState *vs,
- ssize_t err)
+/************************ v9fs_write calls ************************/
+
+static void v9fs_write_do_pwritev(ThreadletWork *work)
+{
+ V9fsWriteState *vs;
+
+ vs = container_of(work, V9fsWriteState, work);
+ v9fs_do_pwritev(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_write_post_pwritev(void *opaque)
{
- if (err < 0) {
+ V9fsWriteState *vs = (V9fsWriteState *)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_pwritev(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_write_post_pwritev(s, vs, err);
+ v9fs_do_async_posix(&vs->work, v9fs_write_do_pwritev, &vs->post_fn,
+ v9fs_write_post_pwritev);
return;
}
vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total);
- 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);
}
@@ -2539,7 +2543,6 @@ static void v9fs_write(V9fsState *s, V9fsPDU *pdu)
{
int32_t fid;
V9fsWriteState *vs;
- ssize_t err;
vs = qemu_malloc(sizeof(*vs));
@@ -2548,19 +2551,20 @@ static void v9fs_write(V9fsState *s, V9fsPDU *pdu)
vs->sg = vs->iov;
vs->total = 0;
vs->len = 0;
+ vs->s = s;
pdu_unmarshal(vs->pdu, vs->offset, "dqdv", &fid, &vs->off, &vs->count,
vs->sg, &vs->cnt);
vs->fidp = lookup_fid(s, fid);
if (vs->fidp == NULL) {
- err = -EINVAL;
+ vs->err = -EINVAL;
goto out;
}
if (vs->fidp->fid_type == P9_FID_FILE) {
if (vs->fidp->fs.fd == -1) {
- err = -EINVAL;
+ vs->err = -EINVAL;
goto out;
}
} else if (vs->fidp->fid_type == P9_FID_XATTR) {
@@ -2570,21 +2574,18 @@ static void v9fs_write(V9fsState *s, V9fsPDU *pdu)
v9fs_xattr_write(s, vs);
return;
} else {
- err = -EINVAL;
+ vs->err = -EINVAL;
goto out;
}
vs->sg = cap_sg(vs->sg, vs->count, &vs->cnt);
if (vs->total <= vs->count) {
- vs->len = v9fs_do_pwritev(s, vs->fidp->fs.fd, vs->sg, vs->cnt, vs->off);
- if (vs->len > 0) {
- vs->off += vs->len;
- }
- err = vs->len;
- v9fs_write_post_pwritev(s, vs, err);
+ vs->err = vs->len;
+ v9fs_do_async_posix(&vs->work, v9fs_write_do_pwritev, &vs->post_fn,
+ v9fs_write_post_pwritev);
}
return;
out:
- complete_pdu(s, vs->pdu, err);
+ complete_pdu(vs->s, vs->pdu, vs->err);
qemu_free(vs);
}
@@ -343,6 +343,11 @@ typedef struct V9fsWriteState {
struct iovec iov[128]; /* FIXME: bad, bad, bad */
struct iovec *sg;
int cnt;
+ V9fsState *s;
+ int err;
+ int v9fs_errno;
+ ThreadletWork work;
+ void (*post_fn)(void *arg);
} V9fsWriteState;
typedef struct V9fsRemoveState {