All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: ericvh@gmail.com, aliguori@us.ibm.com, aneesh.kumar@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH -V4 16/21] virtio-9p: Add P9_TWRITE support
Date: Fri,  9 Apr 2010 17:13:19 +0530	[thread overview]
Message-ID: <1270813404-23004-17-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <1270813404-23004-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>

From: Anthony Liguori <aliguori@us.ibm.com>

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>
---
 hw/file-op-9p.h      |    1 +
 hw/virtio-9p-local.c |    7 +++
 hw/virtio-9p.c       |  112 +++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 118 insertions(+), 2 deletions(-)

diff --git a/hw/file-op-9p.h b/hw/file-op-9p.h
index c1f5e45..12503c1 100644
--- a/hw/file-op-9p.h
+++ b/hw/file-op-9p.h
@@ -39,6 +39,7 @@ typedef struct FileOperations
     struct dirent *(*readdir)(FsContext *, DIR *);
     void (*seekdir)(FsContext *, DIR *, off_t);
     ssize_t (*readv)(FsContext *, int, const struct iovec *, int);
+    ssize_t (*writev)(FsContext *, int, const struct iovec *, int);
     off_t (*lseek)(FsContext *, int, off_t, int);
     void *opaque;
 } FileOperations;
diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index 81d1971..87aeba8 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -127,6 +127,12 @@ static off_t local_lseek(FsContext *ctx, int fd, off_t offset, int whence)
     return lseek(fd, offset, whence);
 }
 
+static ssize_t local_writev(FsContext *ctx, int fd, const struct iovec *iov,
+                            int iovcnt)
+{
+    return writev(fd, iov, iovcnt);
+}
+
 FileOperations local_ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
@@ -141,4 +147,5 @@ FileOperations local_ops = {
     .seekdir = local_seekdir,
     .readv = local_readv,
     .lseek = local_lseek,
+    .writev = local_writev,
 };
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 480f68b..03d8696 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;
@@ -1536,11 +1542,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)
-- 
1.7.0.4.360.g11766c

  parent reply	other threads:[~2010-04-09 11:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-09 11:43 [Qemu-devel] [PATCH -V4 00/21] virtio-9p: paravirtual file system passthrough Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 01/21] virtio-9p: Create a commandline option -fsdev Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 02/21] virtio-9p: Add a virtio 9p device to qemu Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 03/21] virtio-9p: pdu processing support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 04/21] virtio-9p: Add string manipulation support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 05/21] virtio-9p: Add minimal set of FileOperations Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 06/21] virtio-9p: Add fid and qid management support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 07/21] virtio-9p: Add stat and mode related helper functions Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 08/21] virtio-9p: Add sg " Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 09/21] virtio-9p: Add P9_TVERSION support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 10/21] virtio-9p: Add P9_TATTACH support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 11/21] virtio-9p: Add P9_TSTAT support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 12/21] virtio-9p: Add P9_TWALK support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 13/21] virtio-9p: Add P9_TOPEN support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 14/21] virtio-9p: Add P9_TREAD support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 15/21] virtio-9p: Add P9_TCLUNK support Aneesh Kumar K.V
2010-04-09 11:43 ` Aneesh Kumar K.V [this message]
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 17/21] virtio-9p: Add P9_TCREATE support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 18/21] virtio-9p: Add P9_TWSTAT support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 19/21] virtio-9p: Add P9_TREMOVE support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 20/21] virtio-9p: Add P9_TFLUSH support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 21/21] virtio-9p: Create a syntactic shortcut for the file-system pass-thru Aneesh Kumar K.V

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1270813404-23004-17-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=ericvh@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.