From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, eblake@redhat.com,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH v2 09/20] char: introduce generic qemu_chr_get_kind()
Date: Tue, 10 Jan 2017 18:47:59 +0100 [thread overview]
Message-ID: <20170110174810.17748-10-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20170110174810.17748-1-marcandre.lureau@redhat.com>
This allows to remove the "is_mux" field from CharDriverState.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
include/sysemu/char.h | 15 +++++++++++++--
monitor.c | 2 +-
qemu-char.c | 21 ++++++++++-----------
3 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index 2dd05642fb..7d841ad879 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -96,7 +96,6 @@ struct CharDriverState {
char *filename;
int logfd;
int be_open;
- int is_mux;
guint fd_in_tag;
bool replay;
DECLARE_BITMAP(features, QEMU_CHAR_FEATURE_LAST);
@@ -455,7 +454,19 @@ void qemu_chr_be_generic_open(CharDriverState *s);
void qemu_chr_fe_accept_input(CharBackend *be);
int qemu_chr_add_client(CharDriverState *s, int fd);
CharDriverState *qemu_chr_find(const char *name);
-bool chr_is_ringbuf(const CharDriverState *chr);
+
+/**
+ * @qemu_chr_get_kind:
+ *
+ * Returns the kind of char backend, or -1 if unspecified.
+ */
+ChardevBackendKind qemu_chr_get_kind(const CharDriverState *chr);
+
+static inline bool qemu_chr_is_ringbuf(const CharDriverState *chr)
+{
+ return qemu_chr_get_kind(chr) == CHARDEV_BACKEND_KIND_RINGBUF ||
+ qemu_chr_get_kind(chr) == CHARDEV_BACKEND_KIND_MEMORY;
+}
bool qemu_chr_has_feature(CharDriverState *chr,
CharDriverFeature feature);
diff --git a/monitor.c b/monitor.c
index 0841d436b0..17948f5289 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3194,7 +3194,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)
if (!strncmp(chr_info->label, str, len)) {
CharDriverState *chr = qemu_chr_find(chr_info->label);
- if (chr && chr_is_ringbuf(chr)) {
+ if (chr && qemu_chr_is_ringbuf(chr)) {
readline_add_completion(rs, chr_info->label);
}
}
diff --git a/qemu-char.c b/qemu-char.c
index 305f410c73..a9ef28c370 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -781,7 +781,7 @@ static void muxes_realize_done(Notifier *notifier, void *unused)
CharDriverState *chr;
QTAILQ_FOREACH(chr, &chardevs, next) {
- if (chr->is_mux) {
+ if (qemu_chr_get_kind(chr) == CHARDEV_BACKEND_KIND_MUX) {
MuxDriver *d = chr->opaque;
int i;
@@ -888,7 +888,6 @@ static CharDriverState *qemu_chr_open_mux(const CharDriver *driver,
* set of muxes
*/
*be_opened = muxes_realized;
- chr->is_mux = 1;
if (!qemu_chr_fe_init(&d->chr, drv, errp)) {
qemu_chr_free(chr);
return NULL;
@@ -906,7 +905,7 @@ bool qemu_chr_fe_init(CharBackend *b, CharDriverState *s, Error **errp)
{
int tag = 0;
- if (s->is_mux) {
+ if (qemu_chr_get_kind(s) == CHARDEV_BACKEND_KIND_MUX) {
MuxDriver *d = s->opaque;
if (d->mux_cnt >= MAX_MUX) {
@@ -933,7 +932,7 @@ unavailable:
static bool qemu_chr_is_busy(CharDriverState *s)
{
- if (s->is_mux) {
+ if (qemu_chr_get_kind(s) == CHARDEV_BACKEND_KIND_MUX) {
MuxDriver *d = s->opaque;
return d->mux_cnt >= 0;
} else {
@@ -950,7 +949,7 @@ void qemu_chr_fe_deinit(CharBackend *b)
if (b->chr->be == b) {
b->chr->be = NULL;
}
- if (b->chr->is_mux) {
+ if (qemu_chr_get_kind(b->chr) == CHARDEV_BACKEND_KIND_MUX) {
MuxDriver *d = b->chr->opaque;
d->backends[b->tag] = NULL;
}
@@ -1001,7 +1000,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
}
}
- if (s->is_mux) {
+ if (qemu_chr_get_kind(s) == CHARDEV_BACKEND_KIND_MUX) {
mux_chr_set_handlers(s, context);
}
}
@@ -1012,7 +1011,7 @@ void qemu_chr_fe_take_focus(CharBackend *b)
return;
}
- if (b->chr->is_mux) {
+ if (qemu_chr_get_kind(b->chr) == CHARDEV_BACKEND_KIND_MUX) {
mux_set_focus(b->chr, b->tag);
}
}
@@ -3557,9 +3556,9 @@ fail:
return NULL;
}
-bool chr_is_ringbuf(const CharDriverState *chr)
+ChardevBackendKind qemu_chr_get_kind(const CharDriverState *chr)
{
- return chr->driver->chr_write == ringbuf_chr_write;
+ return chr->driver->kind;
}
void qmp_ringbuf_write(const char *device, const char *data,
@@ -3577,7 +3576,7 @@ void qmp_ringbuf_write(const char *device, const char *data,
return;
}
- if (!chr_is_ringbuf(chr)) {
+ if (!qemu_chr_is_ringbuf(chr)) {
error_setg(errp,"%s is not a ringbuf device", device);
return;
}
@@ -3621,7 +3620,7 @@ char *qmp_ringbuf_read(const char *device, int64_t size,
return NULL;
}
- if (!chr_is_ringbuf(chr)) {
+ if (!qemu_chr_is_ringbuf(chr)) {
error_setg(errp,"%s is not a ringbuf device", device);
return NULL;
}
--
2.11.0
next prev parent reply other threads:[~2017-01-10 17:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-10 17:47 [Qemu-devel] [PATCH v2 00/20] chardev: qom-ify Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 01/20] tests: fix linking test-char on win32 Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 02/20] qemu-options: stdio is available " Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 03/20] char: add qemu_chr_fe_add_watch() Returns description Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 04/20] doc: fix spelling Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 05/20] char: use a const CharDriver Marc-André Lureau
2017-01-10 18:01 ` Eric Blake
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 06/20] char: use a static array for backends Marc-André Lureau
2017-01-10 18:03 ` Eric Blake
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 07/20] char: move callbacks in CharDriver Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 08/20] char: fold single-user functions in caller Marc-André Lureau
2017-01-10 17:47 ` Marc-André Lureau [this message]
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 10/20] char: use a feature bit for replay Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 11/20] char: allocate CharDriverState as a single object Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 12/20] bt: use qemu_chr_alloc() Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 13/20] char: rename CharDriverState Chardev Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 14/20] char: rename TCPChardev and NetChardev Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 15/20] spice-char: improve error reporting Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 16/20] char: use error_report() Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 17/20] gtk: overwrite the console.c char driver Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 18/20] baum: use a common prefix for chr callbacks Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 19/20] vc: " Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 20/20] chardev: qom-ify Marc-André Lureau
2017-01-11 21:27 ` Eric Blake
2017-01-12 15:19 ` Marc-André Lureau
2017-01-24 13:59 ` [Qemu-devel] [PATCH v2 00/20] " Paolo Bonzini
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=20170110174810.17748-10-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=eblake@redhat.com \
--cc=pbonzini@redhat.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 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).