qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PULL 03/11] char: add a QEMU_CHAR_FEATURE_GCONTEXT flag
Date: Wed, 12 Dec 2018 11:11:37 +0100	[thread overview]
Message-ID: <20181212101145.3496-4-armbru@redhat.com> (raw)
In-Reply-To: <20181212101145.3496-1-armbru@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

QEMU_CHAR_FEATURE_GCONTEXT declares the character device can switch
GMainContext.

Assert we don't switch context when the character device doesn't
provide this feature.  Character device users must not violate this
restriction.  In particular, user configurations that violate them
must be rejected.

Existing frontend that rely on context switching would now assert() if
the backend doesn't allow it (instead of silently producing undesired
events in the default context). Following patches improve the
situation by reporting an error earlier instead, on the frontend side.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20181205203737.9011-4-marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 chardev/char.c         | 11 +++++++++++
 include/chardev/char.h |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/chardev/char.c b/chardev/char.c
index 152dde5327..ccba36bafb 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -193,6 +193,8 @@ void qemu_chr_be_update_read_handlers(Chardev *s,
 {
     ChardevClass *cc = CHARDEV_GET_CLASS(s);
 
+    assert(qemu_chr_has_feature(s, QEMU_CHAR_FEATURE_GCONTEXT)
+           || !context);
     s->gcontext = context;
     if (cc->chr_update_read_handler) {
         cc->chr_update_read_handler(s);
@@ -240,6 +242,15 @@ static void char_init(Object *obj)
 
     chr->logfd = -1;
     qemu_mutex_init(&chr->chr_write_lock);
+
+    /*
+     * Assume if chr_update_read_handler is implemented it will
+     * take the updated gcontext into account.
+     */
+    if (CHARDEV_GET_CLASS(chr)->chr_update_read_handler) {
+        qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT);
+    }
+
 }
 
 static int null_chr_write(Chardev *chr, const uint8_t *buf, int len)
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 7becd8c80c..014566c3de 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -47,6 +47,9 @@ typedef enum {
     QEMU_CHAR_FEATURE_FD_PASS,
     /* Whether replay or record mode is enabled */
     QEMU_CHAR_FEATURE_REPLAY,
+    /* Whether the gcontext can be changed after calling
+     * qemu_chr_be_update_read_handlers() */
+    QEMU_CHAR_FEATURE_GCONTEXT,
 
     QEMU_CHAR_FEATURE_LAST,
 } ChardevFeature;
-- 
2.17.2

  parent reply	other threads:[~2018-12-12 10:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-12 10:11 [Qemu-devel] [PULL 00/11] Monitor patches for 2018-12-12 Markus Armbruster
2018-12-12 10:11 ` [Qemu-devel] [PULL 01/11] monitor: inline ambiguous helper functions Markus Armbruster
2018-12-12 10:11 ` [Qemu-devel] [PULL 02/11] monitor: accept chardev input from iothread Markus Armbruster
2018-12-12 10:11 ` Markus Armbruster [this message]
2018-12-12 10:11 ` [Qemu-devel] [PULL 04/11] monitor: check if chardev can switch gcontext for OOB Markus Armbruster
2018-12-12 10:11 ` [Qemu-devel] [PULL 05/11] colo: check chardev can switch context Markus Armbruster
2018-12-12 10:11 ` [Qemu-devel] [PULL 06/11] monitor: prevent inserting new monitors after cleanup Markus Armbruster
2018-12-12 10:11 ` [Qemu-devel] [PULL 07/11] monitor: avoid potential dead-lock when cleaning up Markus Armbruster
2018-12-12 10:11 ` [Qemu-devel] [PULL 08/11] monitor: Suspend monitor instead dropping commands Markus Armbruster
2018-12-12 10:11 ` [Qemu-devel] [PULL 09/11] monitor: Remove "x-oob", offer capability "oob" unconditionally Markus Armbruster
2018-12-12 10:11 ` [Qemu-devel] [PULL 10/11] Revert "tests: Add parameter to qtest_init_without_qmp_handshake" Markus Armbruster
2018-12-12 10:11 ` [Qemu-devel] [PULL 11/11] tests: add oob functional test for test-qmp-cmds Markus Armbruster
2018-12-13 17:50 ` [Qemu-devel] [PULL 00/11] Monitor patches for 2018-12-12 Peter Maydell
2018-12-13 18:12   ` Markus Armbruster

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=20181212101145.3496-4-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=marcandre.lureau@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).