From a74897efe616467bc2279f1c4c043a8659093748 Mon Sep 17 00:00:00 2001 From: Zheng Yan Date: Tue, 11 May 2021 22:05:19 +0800 Subject: [PATCH] qemu: implement qemuDomainGraphicsReload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 'display-reload' QMP command had been introduced from QEMU 6.0.0: https://gitlab.com/qemu-project/qemu/-/commit/9cc07651655ee86eca41059f5ead8c4e5607c734 Currently it only supports reloading TLS certificates for VNC. Resloves: https://issues.redhat.com/browse/RHEL-16333 Signed-off-by: Zheng Yan Signed-off-by: Ján Tomko Reviewed-by: Michal Privoznik --- src/qemu/qemu_driver.c | 63 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor.c | 10 ++++++ src/qemu/qemu_monitor.h | 5 +++ src/qemu/qemu_monitor_json.c | 23 +++++++++++++ src/qemu/qemu_monitor_json.h | 4 +++ 5 files changed, 105 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 448e6b1591..d01f788aea 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19932,6 +19932,68 @@ qemuDomainFDAssociate(virDomainPtr domain, return ret; } +static int +qemuDomainGraphicsReload(virDomainPtr domain, + unsigned int type, + unsigned int flags) +{ + int ret = -1; + virDomainObj *vm = NULL; + qemuDomainObjPrivate *priv; + + virCheckFlagsGoto(0, cleanup); + + if (type >= VIR_DOMAIN_GRAPHICS_RELOAD_TYPE_LAST) { + virReportInvalidArg(type, + _("type must be less than %1$d"), + VIR_DOMAIN_GRAPHICS_RELOAD_TYPE_LAST); + return -1; + } + + if (!(vm = qemuDomainObjFromDomain(domain))) + return -1; + + if (virDomainGraphicsReloadEnsureACL(domain->conn, vm->def)) + goto cleanup; + + if (type == VIR_DOMAIN_GRAPHICS_RELOAD_TYPE_ANY) { + size_t i; + + for (i = 0; i < vm->def->ngraphics; i++) { + if (vm->def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) + break; + } + + if (i == vm->def->ngraphics) { + ret = 0; + goto cleanup; + } + } + + if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) + goto cleanup; + + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); + goto endjob; + } + + priv = vm->privateData; + + qemuDomainObjEnterMonitor(vm); + + ret = qemuMonitorDisplayReload(priv->mon, "vnc", true); + + qemuDomainObjExitMonitor(vm); + + endjob: + virDomainObjEndJob(vm); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} static virHypervisorDriver qemuHypervisorDriver = { .name = QEMU_DRIVER_NAME, @@ -20182,6 +20244,7 @@ static virHypervisorDriver qemuHypervisorDriver = { .domainStartDirtyRateCalc = qemuDomainStartDirtyRateCalc, /* 7.2.0 */ .domainSetLaunchSecurityState = qemuDomainSetLaunchSecurityState, /* 8.0.0 */ .domainFDAssociate = qemuDomainFDAssociate, /* 9.0.0 */ + .domainGraphicsReload = qemuDomainGraphicsReload, /* 10.2.0 */ }; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 0f29fb02b4..34e2ccab97 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4501,3 +4501,13 @@ qemuMonitorGetStatsByQOMPath(virJSONValue *arr, return NULL; } + +int +qemuMonitorDisplayReload(qemuMonitor *mon, + const char *type, + bool tlsCerts) +{ + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONDisplayReload(mon, type, tlsCerts); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 981c609e9f..6e81945201 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1581,3 +1581,8 @@ qemuMonitorExtractQueryStats(virJSONValue *info); virJSONValue * qemuMonitorGetStatsByQOMPath(virJSONValue *arr, char *qom_path); + +int +qemuMonitorDisplayReload(qemuMonitor *mon, + const char *type, + bool tlsCerts); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 7aab34c7c4..eb84a3d938 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8873,3 +8873,26 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon, return virJSONValueObjectStealArray(reply, "return"); } + +int qemuMonitorJSONDisplayReload(qemuMonitor *mon, + const char *type, + bool tlsCerts) +{ + g_autoptr(virJSONValue) reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + + cmd = qemuMonitorJSONMakeCommand("display-reload", + "s:type", type, + "b:tls-certs", tlsCerts, + NULL); + if (!cmd) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return -1; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + return -1; + + return 0; +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index ed0027c118..9684660d86 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -825,3 +825,7 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon, qemuMonitorQueryStatsTargetType target, char **vcpus, GPtrArray *providers); + +int qemuMonitorJSONDisplayReload(qemuMonitor *mon, + const char *type, + bool tlsCerts);