diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2010-04-29 17:44:58 +0530 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2010-05-03 12:17:39 -0500 |
commit | 8449360cbde906bb36ca2181d3723bae2fd10742 (patch) | |
tree | 34a5201925b8b9d83716f7d76a085828654f00ce /hw/virtio-9p.c | |
parent | bbd5697b8ea7e8795e83d3550cd1a11077c57fd4 (diff) |
virtio-9p: Add P9_TWRITE support
Implement P9_TWRITE support.
This gets write to file to work
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/virtio-9p.c')
-rw-r--r-- | hw/virtio-9p.c | 112 |
1 files changed, 110 insertions, 2 deletions
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index b9b892c318..252eaa9ec2 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -97,6 +97,12 @@ static off_t v9fs_do_lseek(V9fsState *s, int fd, off_t offset, int whence) return s->ops->lseek(&s->ctx, fd, offset, whence); } +static int v9fs_do_writev(V9fsState *s, int fd, const struct iovec *iov, + int iovcnt) +{ + return s->ops->writev(&s->ctx, fd, iov, iovcnt); +} + static void v9fs_string_init(V9fsString *str) { str->data = NULL; @@ -1534,11 +1540,113 @@ out: qemu_free(vs); } +typedef struct V9fsWriteState { + V9fsPDU *pdu; + size_t offset; + int32_t len; + int32_t count; + int32_t total; + int64_t off; + V9fsFidState *fidp; + struct iovec iov[128]; /* FIXME: bad, bad, bad */ + struct iovec *sg; + int cnt; +} V9fsWriteState; + +static void v9fs_write_post_writev(V9fsState *s, V9fsWriteState *vs, + ssize_t err) +{ + if (err < 0) { + /* IO error return the error */ + err = -errno; + goto out; + } + 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_writev(s, vs->fidp->fd, vs->sg, vs->cnt); + } while (vs->len == -1 && errno == EINTR); + if (vs->len == -1) { + err = -errno; + } + v9fs_write_post_writev(s, vs, err); + return; + } + vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total); + + err = vs->offset; +out: + complete_pdu(s, vs->pdu, err); + qemu_free(vs); +} + +static void v9fs_write_post_lseek(V9fsState *s, V9fsWriteState *vs, ssize_t err) +{ + if (err == -1) { + err = -errno; + goto out; + } + vs->sg = cap_sg(vs->sg, vs->count, &vs->cnt); + + if (vs->total < vs->count) { + do { + if (0) { + print_sg(vs->sg, vs->cnt); + } + vs->len = v9fs_do_writev(s, vs->fidp->fd, vs->sg, vs->cnt); + } while (vs->len == -1 && errno == EINTR); + if (vs->len == -1) { + err = -errno; + } + v9fs_write_post_writev(s, vs, err); + return; + } + +out: + complete_pdu(s, vs->pdu, err); + qemu_free(vs); +} + static void v9fs_write(V9fsState *s, V9fsPDU *pdu) { - if (debug_9p_pdu) { - pprint_pdu(pdu); + int32_t fid; + V9fsWriteState *vs; + ssize_t err; + + vs = qemu_malloc(sizeof(*vs)); + + vs->pdu = pdu; + vs->offset = 7; + vs->sg = vs->iov; + vs->total = 0; + vs->len = 0; + + 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; + goto out; } + + if (vs->fidp->fd == -1) { + err = -EINVAL; + goto out; + } + + err = v9fs_do_lseek(s, vs->fidp->fd, vs->off, SEEK_SET); + + v9fs_write_post_lseek(s, vs, err); + return; + +out: + complete_pdu(s, vs->pdu, err); + qemu_free(vs); } static void v9fs_create(V9fsState *s, V9fsPDU *pdu) |