[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 29/38] qmp: introduce asynchronous command type
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v3 29/38] qmp: introduce asynchronous command type |
Date: |
Mon, 26 Mar 2018 17:09:07 +0200 |
Add a new type of command, QmpCommandFuncAsync: those commands can
return later thanks to QmpReturn. This commit introduces the new type
and register function and teach qmp_dipatch() to call it without
qmp_return().
Signed-off-by: Marc-André Lureau <address@hidden>
---
include/qapi/qmp/dispatch.h | 9 ++++++++-
qapi/qmp-dispatch.c | 4 +++-
qapi/qmp-registry.c | 27 ++++++++++++++++++++++++---
3 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h
index f6db06c164..e426317346 100644
--- a/include/qapi/qmp/dispatch.h
+++ b/include/qapi/qmp/dispatch.h
@@ -21,18 +21,23 @@
typedef struct QmpReturn QmpReturn;
typedef void (QmpCommandFunc)(QDict *, QObject **, Error **);
+typedef void (QmpCommandAsyncFunc)(QDict *, QmpReturn *);
typedef enum QmpCommandOptions
{
QCO_NO_OPTIONS = 0x0,
QCO_NO_SUCCESS_RESP = (1U << 0),
QCO_ALLOW_OOB = (1U << 1),
+ QCO_ASYNC = (1U << 2),
} QmpCommandOptions;
typedef struct QmpCommand
{
const char *name;
- QmpCommandFunc *fn;
+ union {
+ QmpCommandFunc *fn;
+ QmpCommandAsyncFunc *async_fn;
+ };
QmpCommandOptions options;
QTAILQ_ENTRY(QmpCommand) node;
bool enabled;
@@ -88,6 +93,8 @@ void qmp_return_error(QmpReturn *qret, Error *err);
void qmp_register_command(QmpCommandList *cmds, const char *name,
QmpCommandFunc *fn, QmpCommandOptions options);
+void qmp_register_async_command(QmpCommandList *cmds, const char *name,
+ QmpCommandAsyncFunc *fn, QmpCommandOptions options);
void qmp_unregister_command(QmpCommandList *cmds, const char *name);
QmpCommand *qmp_find_command(QmpCommandList *cmds, const char *name);
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index aa8b71a2c0..f7d9931734 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -195,7 +195,9 @@ void qmp_dispatch(QmpSession *session, QDict *req)
QINCREF(args);
}
- {
+ if (cmd->options & QCO_ASYNC) {
+ cmd->async_fn(args, qmp_return_new(session, req));
+ } else {
QObject *ret = NULL;
cmd->fn(args, &ret, &err);
if (err || cmd->options & QCO_NO_SUCCESS_RESP) {
diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c
index 5af484cd9a..180b1c1e69 100644
--- a/qapi/qmp-registry.c
+++ b/qapi/qmp-registry.c
@@ -15,16 +15,37 @@
#include "qemu/osdep.h"
#include "qapi/qmp/dispatch.h"
-void qmp_register_command(QmpCommandList *cmds, const char *name,
- QmpCommandFunc *fn, QmpCommandOptions options)
+
+static QmpCommand *qmp_command_new(QmpCommandList *cmds, const char *name,
+ QmpCommandOptions options)
{
QmpCommand *cmd = g_malloc0(sizeof(*cmd));
cmd->name = name;
- cmd->fn = fn;
cmd->enabled = true;
cmd->options = options;
QTAILQ_INSERT_TAIL(cmds, cmd, node);
+
+ return cmd;
+}
+
+
+void qmp_register_command(QmpCommandList *cmds, const char *name,
+ QmpCommandFunc *fn, QmpCommandOptions options)
+{
+ QmpCommand *cmd = qmp_command_new(cmds, name, options);
+
+ assert(!(options & QCO_ASYNC));
+ cmd->fn = fn;
+}
+
+void qmp_register_async_command(QmpCommandList *cmds, const char *name,
+ QmpCommandAsyncFunc *fn, QmpCommandOptions options)
+{
+ QmpCommand *cmd = qmp_command_new(cmds, name, options);
+
+ assert(options & QCO_ASYNC);
+ cmd->async_fn = fn;
}
void qmp_unregister_command(QmpCommandList *cmds, const char *name)
--
2.17.0.rc1.1.g4c4f2b46a3
- [Qemu-devel] [PATCH v3 19/38] QmpSession: add a return_cb, (continued)
- [Qemu-devel] [PATCH v3 19/38] QmpSession: add a return_cb, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 21/38] QmpSession: add a dispatch callback, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 22/38] monitor: use QmpSession parsing and common dispatch code, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 24/38] qmp: remove qmp_build_error_object(), Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 23/38] QmpSession: introduce QmpReturn, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 26/38] qmp: fold do_qmp_dispatch() in qmp_dispatch(), Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 27/38] QmpSession: keep a queue of pending commands, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 25/38] qmp: remove need for qobject_from_jsonf(), Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 28/38] QmpSession: return orderly, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 30/38] scripts: learn 'async' qapi commands, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 29/38] qmp: introduce asynchronous command type,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v3 31/38] qmp: add qmp_return_is_cancelled(), Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 33/38] console: graphic_hw_update return true if async, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 34/38] console: add graphic_hw_update_done(), Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 35/38] console: make screendump asynchronous, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 36/38] monitor: start making qmp_human_monitor_command() asynchronous, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 32/38] monitor: add qmp_return_get_monitor(), Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 37/38] monitor: teach HMP about asynchronous commands, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 38/38] hmp: call the asynchronous QMP screendump to fix outdated/glitches, Marc-André Lureau, 2018/03/26
- Re: [Qemu-devel] [PATCH v3 00/38] RFC: monitor: add asynchronous command type, Dr. David Alan Gilbert, 2018/03/26