qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, quintela@redhat.com
Subject: [Qemu-devel] [PATCH 10/13] virtio-blk: convert save/load to visitors
Date: Thu, 27 Oct 2011 13:17:22 -0500	[thread overview]
Message-ID: <1319739445-17629-11-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1319739445-17629-1-git-send-email-mdroth@linux.vnet.ibm.com>


Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 hw/virtio-blk.c |   76 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 2a5d1a9..2ddcc1e 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -511,37 +511,97 @@ static void virtio_blk_save(QEMUFile *f, void *opaque)
 {
     VirtIOBlock *s = opaque;
     VirtIOBlockReq *req = s->rq;
+    Visitor *v = qemu_file_get_visitor(f);
+    Error *err = NULL;
+    uint8_t *buf, marker;
+    int i;
+
+    visit_start_struct(v, NULL, NULL, "virtio_blk", 0, &err);
 
     virtio_save(&s->vdev, f);
     
+    visit_start_list(v, "requests", &err);
     while (req) {
-        qemu_put_sbyte(f, 1);
-        qemu_put_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
+        visit_start_struct(v, NULL, NULL, NULL, 0, &err);
+
+        marker = 1;
+        visit_type_uint8(v, &marker, "marker", &err);
+        visit_start_array(v, NULL, "elem", sizeof(req->elem), 1, &err);
+        buf = (uint8_t *)&req->elem;
+        for (i = 0; i < sizeof(req->elem); i++) {
+            visit_type_uint8(v, &buf[i], NULL, &err);
+        }
+        visit_end_array(v, &err);
+
+        visit_end_struct(v, &err);
         req = req->next;
     }
-    qemu_put_sbyte(f, 0);
+    visit_start_struct(v, NULL, NULL, NULL, 0, &err);
+    marker = 0;
+    visit_type_uint8(v, &marker, "marker", &err);
+    visit_end_struct(v, &err);
+    visit_end_list(v, &err);
+
+    visit_end_struct(v, &err);
+
+    if (err) {
+        error_report("error saving virtio-blk state: %s", error_get_pretty(err));
+        error_free(err);
+    }
 }
 
 static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
 {
     VirtIOBlock *s = opaque;
+    Visitor *v = qemu_file_get_visitor(f);
+    Error *err = NULL;
+    uint8_t marker, *buf;
+    int i;
 
-    if (version_id != 2)
+    if (version_id != 2) {
         return -EINVAL;
+    }
+
+    visit_start_struct(v, NULL, NULL, "virtio_blk", 0, &err);
 
     virtio_load(&s->vdev, f);
-    while (qemu_get_sbyte(f)) {
+
+    visit_start_list(v, "requests", &err);
+    while (1) {
+        visit_start_struct(v, NULL, NULL, NULL, 0, &err);
+
+        visit_type_uint8(v, &marker, "marker", &err);
+        if (!marker) {
+            visit_end_struct(v, &err);
+            break;
+        }
         VirtIOBlockReq *req = virtio_blk_alloc_request(s);
-        qemu_get_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
+        visit_start_array(v, NULL, "elem", sizeof(req->elem), 1, &err);
+        buf = (uint8_t *)&req->elem;
+        for (i = 0; i < sizeof(req->elem); i++) {
+            visit_type_uint8(v, &buf[i], NULL, &err);
+        }
+        visit_end_array(v, &err);
+
+        visit_end_struct(v, &err);
+
         req->next = s->rq;
         s->rq = req;
 
         virtqueue_map_sg(req->elem.in_sg, req->elem.in_addr,
-            req->elem.in_num, 1);
+                         req->elem.in_num, 1);
         virtqueue_map_sg(req->elem.out_sg, req->elem.out_addr,
-            req->elem.out_num, 0);
+                         req->elem.out_num, 0);
     }
+    visit_end_list(v, &err);
 
+    visit_end_struct(v, &err);
+
+    if (err) {
+        error_report("error loading virtio-blk state: %s", error_get_pretty(err));
+        error_free(err);
+        return -1;
+    }
     return 0;
 }
 
-- 
1.7.4.1

  parent reply	other threads:[~2011-10-27 18:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-27 18:17 [Qemu-devel] [PATCH 00/13] Convert slirp/ivshmem/virtio save/load to Visitors Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 01/13] slirp: convert save/load function to visitor interface Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 02/13] ivshmem: convert save/load to visitor Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 03/13] virtio-pci: convert save/load to visitors Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 04/13] msix: convert save/load to visitors (including interfaces) Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 05/13] openpic: convert save/load to visitors Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 06/13] i440fx: " Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 07/13] pci: convert pci_device_(save|load) interfaces to accept Visitors Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 08/13] virtio: convert common virtio save/load to visitors Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 09/13] virtio-balloon: convert " Michael Roth
2011-10-27 18:17 ` Michael Roth [this message]
2011-10-27 18:17 ` [Qemu-devel] [PATCH 11/13] virtio-net: " Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 12/13] virtio-serial: " Michael Roth
2011-10-27 18:17 ` [Qemu-devel] [PATCH 13/13] virtio: convert virtio_save/virtio_load interfaces to accept Visitors Michael Roth

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=1319739445-17629-11-git-send-email-mdroth@linux.vnet.ibm.com \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).