[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 04/13] char: forbid direct chardevice access for
From: |
Anton Nefedov |
Subject: |
[Qemu-devel] [PATCH v4 04/13] char: forbid direct chardevice access for hotswap devices |
Date: |
Mon, 26 Jun 2017 19:45:41 +0300 |
qemu_chr_fe_get_driver() is unsafe, frontends with hotswap support
should not access CharDriver ptr directly as CharDriver might change.
Signed-off-by: Anton Nefedov <address@hidden>
Reviewed-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
---
include/chardev/char-fe.h | 10 ++++++++++
chardev/char-fe.c | 7 +++++++
2 files changed, 17 insertions(+)
diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h
index 0314870..385aa99 100644
--- a/include/chardev/char-fe.h
+++ b/include/chardev/char-fe.h
@@ -63,10 +63,20 @@ bool qemu_chr_fe_connect(CharBackend *b, Chardev *s, Error
**errp);
*
* Returns the driver associated with a CharBackend or NULL if no
* associated Chardev.
+ * Note: avoid this function as the driver should never be accessed directly,
+ * especially by the frontends that support chardevice hotswap.
+ * Consider qemu_chr_fe_backend_connected() to check for driver existence
*/
Chardev *qemu_chr_fe_get_driver(CharBackend *be);
/**
+ * @qemu_chr_fe_backend_connected:
+ *
+ * Returns true if there is a chardevice associated with @be.
+ */
+bool qemu_chr_fe_backend_connected(CharBackend *be);
+
+/**
* @qemu_chr_fe_set_handlers:
* @b: a CharBackend
* @fd_can_read: callback to get the amount of data the frontend may
diff --git a/chardev/char-fe.c b/chardev/char-fe.c
index 86a878b..be96fb5 100644
--- a/chardev/char-fe.c
+++ b/chardev/char-fe.c
@@ -183,9 +183,16 @@ void qemu_chr_fe_printf(CharBackend *be, const char *fmt,
...)
Chardev *qemu_chr_fe_get_driver(CharBackend *be)
{
+ /* this is unsafe for the users that support chardev hotswap */
+ assert(be->chr_be_change == NULL);
return be->chr;
}
+bool qemu_chr_fe_backend_connected(CharBackend *be)
+{
+ return !!be->chr;
+}
+
bool qemu_chr_fe_connect(CharBackend *b, Chardev *s, Error **errp)
{
int tag = 0;
--
2.7.4
- [Qemu-devel] [PATCH v4 00/13] chardevice hotswap, Anton Nefedov, 2017/06/26
- [Qemu-devel] [PATCH v4 01/13] char: move QemuOpts->ChardevBackend translation to a separate func, Anton Nefedov, 2017/06/26
- [Qemu-devel] [PATCH v4 02/13] char: add backend hotswap handler, Anton Nefedov, 2017/06/26
- [Qemu-devel] [PATCH v4 04/13] char: forbid direct chardevice access for hotswap devices,
Anton Nefedov <=
- [Qemu-devel] [PATCH v4 03/13] char: chardevice hotswap, Anton Nefedov, 2017/06/26
- [Qemu-devel] [PATCH v4 06/13] test-char: unref chardev-udp after test, Anton Nefedov, 2017/06/26
- [Qemu-devel] [PATCH v4 05/13] char: avoid chardevice direct access, Anton Nefedov, 2017/06/26
- [Qemu-devel] [PATCH v4 07/13] test-char: split char_udp_test, Anton Nefedov, 2017/06/26
- [Qemu-devel] [PATCH v4 08/13] test-char: split char_file_test, Anton Nefedov, 2017/06/26
- [Qemu-devel] [PATCH v4 09/13] test-char: add hotswap test, Anton Nefedov, 2017/06/26
- [Qemu-devel] [PATCH v4 10/13] hmp: add hmp analogue for qmp-chardev-change, Anton Nefedov, 2017/06/26
- [Qemu-devel] [PATCH v4 11/13] virtio-console: chardev hotswap support, Anton Nefedov, 2017/06/26