[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 09/17] virtio-9p: Implement P9_TWRITE
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 09/17] virtio-9p: Implement P9_TWRITE |
Date: |
Wed, 3 Mar 2010 13:01:06 -0600 |
This gets write to file to work
Signed-off-by: Anthony Liguori <address@hidden>
Signed-off-by: Venkateswararao Jujjuri <address@hidden>
Signed-off-by: Aneesh Kumar K.V <address@hidden>
---
hw/virtio-9p-local.c | 7 ++++
hw/virtio-9p.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 102 insertions(+), 2 deletions(-)
diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index 90664a0..441d22d 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -129,6 +129,12 @@ static off_t local_lseek(void *opaque, int fd, off_t
offset, int whence)
return lseek(fd, offset, whence);
}
+static ssize_t local_writev(void *opaque, int fd, const struct iovec *iov,
+ int iovcnt)
+{
+ return writev(fd, iov, iovcnt);
+}
+
static V9fsPosixFileOperations ops = {
.lstat = local_lstat,
.setuid = local_setuid,
@@ -143,6 +149,7 @@ static V9fsPosixFileOperations ops = {
.seekdir = local_seekdir,
.readv = local_readv,
.lseek = local_lseek,
+ .writev = local_writev,
};
V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 7822a00..b0662ba 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -168,6 +168,12 @@ static off_t posix_lseek(V9fsState *s, int fd, off_t
offset, int whence)
return s->ops->lseek(s->ops->opaque, fd, offset, whence);
}
+static int posix_writev(V9fsState *s, int fd, const struct iovec *iov,
+ int iovcnt)
+{
+ return s->ops->writev(s->ops->opaque, fd, iov, iovcnt);
+}
+
static void v9fs_string_init(V9fsString *str)
{
str->data = NULL;
@@ -1321,10 +1327,97 @@ out:
complete_pdu(s, pdu, err);
}
+typedef struct V9fsWriteState {
+ V9fsPDU *pdu;
+ size_t offset;
+ int32_t fid;
+ 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)
+{
+ BUG_ON(vs->len < 0);
+ 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 = posix_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
+ } while (vs->len == -1 && errno == EINTR);
+ v9fs_write_post_writev(s, vs, err);
+ }
+ vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total);
+
+ err = vs->offset;
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
+static void v9fs_write_post_lseek(V9fsState *s, V9fsWriteState *vs, ssize_t
err)
+{
+ BUG_ON(err == -1);
+
+ 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 = posix_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
+ } while (vs->len == -1 && errno == EINTR);
+
+ v9fs_write_post_writev(s, vs, err);
+ return;
+ }
+
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
static void v9fs_write(V9fsState *s, V9fsPDU *pdu)
{
- if (debug_9p_pdu)
- pprint_pdu(pdu);
+ 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", &vs->fid, &vs->off, &vs->count,
+ vs->sg, &vs->cnt);
+
+ vs->fidp = lookup_fid(s, vs->fid);
+ if (vs->fidp == NULL) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ if (vs->fidp->fd == -1) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ err = posix_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)
--
1.6.5.2
- [Qemu-devel] [PATCH 06/17] virtio-9p: Implement P9_TOPEN, (continued)
- [Qemu-devel] [PATCH 06/17] virtio-9p: Implement P9_TOPEN, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 05/17] virtio-9p: Implement P9_TWALK, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 03/17] virtio-9p: Implement P9_TATTACH, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 16/17] virtio-9p: Add support for hardlink, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 07/17] virtio-9p: Implement P9_TREAD, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 14/17] virtio-9p: Add multiple mount point support, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 17/17] Implement sync support in 9p server, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 11/17] virtio-9p: Implement P9_TWSTAT, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 00/17][RFC] virtio-9p: paravirtual filesystem passthrough, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 13/17] virtio-9p: Implement P9_TFLUSH, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 09/17] virtio-9p: Implement P9_TWRITE,
Anthony Liguori <=
- [Qemu-devel] [PATCH 12/17] virtio-9p: Implement P9_TREMOVE, Anthony Liguori, 2010/03/03
- [Qemu-devel] [PATCH 15/17] virtio-9p: Use little endian format on virtio, Anthony Liguori, 2010/03/03