From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Alexey Kardashevskiy <aik@ozlabs.ru>, Alex Graf <agraf@suse.de>,
qemu-ppc@nongnu.org, Paul Mackerras <paulus@samba.org>,
Andreas Faerber <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH 01/12] chardev: ringbuf: add optional save parameter to save state
Date: Wed, 19 Jun 2013 15:40:24 -0500 [thread overview]
Message-ID: <1371674435-14973-2-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1371674435-14973-1-git-send-email-aliguori@us.ibm.com>
It is very useful to use the ringbuf chardev for writing test
cases and even more useful if the state of the ringbuf is migrated
with the guest. Otherwise it's hard to detect data loss in a test
case.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
qapi-schema.json | 3 ++-
qemu-char.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/qapi-schema.json b/qapi-schema.json
index a80ee40..90602d1 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3280,10 +3280,11 @@
# Configuration info for memory chardevs
#
# @size: #optional Ringbuffer size, must be power of two, default is 65536
+# @save: #optional Register a savevm handler, default false
#
# Since: 1.5
##
-{ 'type': 'ChardevMemory', 'data': { '*size' : 'int' } }
+{ 'type': 'ChardevMemory', 'data': { '*size' : 'int', '*save': 'bool' } }
##
# @ChardevBackend:
diff --git a/qemu-char.c b/qemu-char.c
index 2c3cfe6..87ba24f 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2793,7 +2793,32 @@ static void ringbuf_chr_close(struct CharDriverState *chr)
chr->opaque = NULL;
}
-static CharDriverState *qemu_chr_open_memory(ChardevMemory *opts,
+static void ringbuf_save(QEMUFile *f, void *opaque)
+{
+ CharDriverState *chr = opaque;
+ RingBufCharDriver *d = chr->opaque;
+
+ qemu_put_be32(f, d->prod);
+ qemu_put_be32(f, d->cons);
+ qemu_put_be32(f, d->size);
+ qemu_put_buffer(f, d->cbuf, d->size);
+}
+
+static int ringbuf_load(QEMUFile *f, void *opaque, int version_id)
+{
+ CharDriverState *chr = opaque;
+ RingBufCharDriver *d = chr->opaque;
+
+ d->prod = qemu_get_be32(f);
+ d->cons = qemu_get_be32(f);
+ d->size = qemu_get_be32(f);
+ qemu_get_buffer(f, d->cbuf, d->size);
+
+ return 0;
+}
+
+static CharDriverState *qemu_chr_open_memory(const char *id,
+ ChardevMemory *opts,
Error **errp)
{
CharDriverState *chr;
@@ -2804,6 +2829,14 @@ static CharDriverState *qemu_chr_open_memory(ChardevMemory *opts,
d->size = opts->has_size ? opts->size : 65536;
+ if (opts->has_save && opts->save) {
+ char *idstr;
+
+ g_assert(id != NULL);
+ idstr = g_strdup_printf("memchar-%s", id);
+ register_savevm(NULL, idstr, 0, 1, ringbuf_save, ringbuf_load, chr);
+ }
+
/* The size must be power of 2 */
if (d->size & (d->size - 1)) {
error_setg(errp, "size of memory chardev must be power of two");
@@ -3120,6 +3153,11 @@ static void qemu_chr_parse_memory(QemuOpts *opts, ChardevBackend *backend,
backend->memory->has_size = true;
backend->memory->size = val;
}
+
+ if (qemu_opt_get_bool(opts, "save", false)) {
+ backend->memory->has_save = true;
+ backend->memory->save = true;
+ }
}
typedef struct CharDriver {
@@ -3489,6 +3527,9 @@ QemuOptsList qemu_chardev_opts = {
},{
.name = "size",
.type = QEMU_OPT_SIZE,
+ }, {
+ .name = "save",
+ .type = QEMU_OPT_BOOL,
},
{ /* end of list */ }
},
@@ -3711,7 +3752,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
chr = vc_init(backend->vc);
break;
case CHARDEV_BACKEND_KIND_MEMORY:
- chr = qemu_chr_open_memory(backend->memory, errp);
+ chr = qemu_chr_open_memory(id, backend->memory, errp);
break;
default:
error_setg(errp, "unknown chardev backend (%d)", backend->kind);
--
1.8.0
next prev parent reply other threads:[~2013-06-19 20:40 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-19 20:40 [Qemu-devel] [PATCH 00/12] spapr: add qtest support and refactor vty Anthony Liguori
2013-06-19 20:40 ` Anthony Liguori [this message]
2013-06-20 19:49 ` [Qemu-devel] [PATCH 01/12] chardev: ringbuf: add optional save parameter to save state Eric Blake
2013-06-19 20:40 ` [Qemu-devel] [PATCH 02/12] qtest: add spapr hypercall support Anthony Liguori
2013-06-20 15:20 ` Andreas Färber
2013-06-20 15:42 ` Anthony Liguori
2013-06-20 18:43 ` Alexander Graf
2013-06-20 18:58 ` Anthony Liguori
2013-06-20 19:28 ` [Qemu-devel] [Qemu-ppc] " Scott Wood
2013-06-20 21:57 ` [Qemu-devel] " Alexander Graf
2013-06-19 20:40 ` [Qemu-devel] [PATCH 03/12] qtest: return string from QMP commands Anthony Liguori
2013-06-20 15:24 ` Andreas Färber
2013-06-20 15:43 ` Anthony Liguori
2013-06-19 20:40 ` [Qemu-devel] [PATCH 04/12] qtest: add interface to save/restore Anthony Liguori
2013-06-20 15:38 ` Andreas Färber
2013-06-19 20:40 ` [Qemu-devel] [PATCH 05/12] spapr-vty: add qtest test case Anthony Liguori
2013-06-19 21:13 ` Alexander Graf
2013-06-19 21:43 ` Anthony Liguori
2013-06-19 21:47 ` Alexander Graf
2013-06-19 20:40 ` [Qemu-devel] [PATCH 06/12] spapr-vty: add copyright and license Anthony Liguori
2013-06-20 1:45 ` Michael Ellerman
2013-06-20 4:08 ` Alexey Kardashevskiy
2013-06-20 4:43 ` David Gibson
2013-06-20 8:52 ` Paolo Bonzini
2013-06-20 15:47 ` Andreas Färber
2013-06-19 20:40 ` [Qemu-devel] [PATCH 07/12] spapr-rtas: add CPU argument to RTAS calls Anthony Liguori
2013-06-19 21:15 ` Alexander Graf
2013-06-20 15:51 ` Andreas Färber
2013-06-20 16:10 ` Anthony Liguori
2013-06-19 20:40 ` [Qemu-devel] [PATCH 08/12] spapr-rtas: use hypercall interface and remove special vty interfaces Anthony Liguori
2013-06-19 21:24 ` Alexander Graf
2013-06-19 21:45 ` Anthony Liguori
2013-06-19 21:48 ` Alexander Graf
2013-06-19 20:40 ` [Qemu-devel] [PATCH 09/12] spapr-vio: move special case handling for reg=0 to vio Anthony Liguori
2013-06-19 21:28 ` Alexander Graf
2013-06-19 21:49 ` Anthony Liguori
2013-06-19 21:53 ` Alexander Graf
2013-06-19 23:20 ` Anthony Liguori
2013-06-19 23:07 ` Benjamin Herrenschmidt
2013-06-19 20:40 ` [Qemu-devel] [PATCH 10/12] spapr-vty: refactor the code to improve consistency Anthony Liguori
2013-06-19 21:37 ` Alexander Graf
2013-06-19 20:40 ` [Qemu-devel] [PATCH 11/12] spapr-vio: pass type to spapr_vio_find_by_reg() Anthony Liguori
2013-06-19 21:38 ` Alexander Graf
2013-06-19 21:56 ` Anthony Liguori
2013-06-19 20:40 ` [Qemu-devel] [PATCH 12/12] spapr-vty: remove unfixable FIXME Anthony Liguori
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=1371674435-14973-2-git-send-email-aliguori@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aik@ozlabs.ru \
--cc=paulus@samba.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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 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).