[libvirt] [PATCH V2 0/3] qemu: support update graphic device persistently

We can change vnc password by using virDomainUpdateDeviceFlags API with live flag. But it can't be changed with config flag. v1: https://www.redhat.com/archives/libvir-list/2014-November/msg00627.html diff to v1: according to Jan's suggestion, 1. (patch 1/3) change error number to VIR_ERR_OPERATION_UNSUPPORTED 2. (patch 3/3) add 'VIR_DOMAIN_XML_SECURE' to flags in initialization. 3. (patch 3/3) Introduce a new function qemuDomainFindGraphicsIndex. Free the old graphics def and replace it with the new one as what we did for DEVICE_NET. Wang Rui (3): qemu: report properer error number when change graphics failed qemu: fix alignment of qemuDomainFindGraphics qemu: make persistent update of graphics device supported src/conf/domain_conf.c | 2 +- src/qemu/qemu_driver.c | 18 +++++++++++++++++- src/qemu/qemu_hotplug.c | 36 ++++++++++++++++++++++++------------ src/qemu/qemu_hotplug.h | 2 ++ 4 files changed, 44 insertions(+), 14 deletions(-) -- 1.7.12.4

It's not supported to change some graphics arguments with '--live'. Replace some error code VIR_ERR_INTERNAL_ERROR and VIR_ERR_INVALID_ARG with VIR_ERR_OPERATION_UNSUPPORTED. Signed-off-by: Wang Rui <moon.wangrui@huawei.com> --- src/qemu/qemu_hotplug.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 9467d7d..d1767bb 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2330,7 +2330,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver, } if (dev->nListens != olddev->nListens) { - virReportError(VIR_ERR_INVALID_ARG, "%s", + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot change the number of listen addresses")); goto cleanup; } @@ -2340,7 +2340,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver, virDomainGraphicsListenDefPtr oldlisten = &olddev->listens[i]; if (newlisten->type != oldlisten->type) { - virReportError(VIR_ERR_INVALID_ARG, "%s", + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot change the type of listen address")); goto cleanup; } @@ -2348,7 +2348,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver, switch ((virDomainGraphicsListenType) newlisten->type) { case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: if (STRNEQ_NULLABLE(newlisten->address, oldlisten->address)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", dev->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ? _("cannot change listen address setting on vnc graphics") : _("cannot change listen address setting on spice graphics")); @@ -2358,7 +2358,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver, case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: if (STRNEQ_NULLABLE(newlisten->network, oldlisten->network)) { - virReportError(VIR_ERR_INVALID_ARG, "%s", + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", dev->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ? _("cannot change listen network setting on vnc graphics") : _("cannot change listen network setting on spice graphics")); @@ -2378,12 +2378,12 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver, if ((olddev->data.vnc.autoport != dev->data.vnc.autoport) || (!dev->data.vnc.autoport && (olddev->data.vnc.port != dev->data.vnc.port))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot change port settings on vnc graphics")); goto cleanup; } if (STRNEQ_NULLABLE(olddev->data.vnc.keymap, dev->data.vnc.keymap)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot change keymap setting on vnc graphics")); goto cleanup; } @@ -2424,13 +2424,13 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver, (olddev->data.spice.port != dev->data.spice.port)) || (!dev->data.spice.autoport && (olddev->data.spice.tlsPort != dev->data.spice.tlsPort))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot change port settings on spice graphics")); goto cleanup; } if (STRNEQ_NULLABLE(olddev->data.spice.keymap, dev->data.spice.keymap)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot change keymap setting on spice graphics")); goto cleanup; } -- 1.7.12.4

Signed-off-by: Wang Rui <moon.wangrui@huawei.com> --- src/qemu/qemu_hotplug.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index d1767bb..ec0122b 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2297,10 +2297,9 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, return ret; } - - -static virDomainGraphicsDefPtr qemuDomainFindGraphics(virDomainObjPtr vm, - virDomainGraphicsDefPtr dev) +static virDomainGraphicsDefPtr +qemuDomainFindGraphics(virDomainObjPtr vm, + virDomainGraphicsDefPtr dev) { size_t i; @@ -2312,7 +2311,6 @@ static virDomainGraphicsDefPtr qemuDomainFindGraphics(virDomainObjPtr vm, return NULL; } - int qemuDomainChangeGraphics(virQEMUDriverPtr driver, virDomainObjPtr vm, -- 1.7.12.4

We can change vnc password by using virDomainUpdateDeviceFlags API with live flag. But it can't be changed with config flag. Error is reported as below. error: Operation not supported: persistent update of device 'graphics' is not supported This patch supports the graphics arguments changed with config flag. Signed-off-by: Wang Rui <moon.wangrui@huawei.com> --- src/conf/domain_conf.c | 2 +- src/qemu/qemu_driver.c | 18 +++++++++++++++++- src/qemu/qemu_hotplug.c | 14 ++++++++++++++ src/qemu/qemu_hotplug.h | 2 ++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2d81c37..468260c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21066,7 +21066,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, { virDomainDeviceDefPtr ret = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; - int flags = VIR_DOMAIN_XML_INACTIVE; + int flags = VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE; char *xmlStr = NULL; int rc = -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9152cf5..fa03cbe 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7460,6 +7460,7 @@ qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps, virDomainDeviceDefPtr dev) { virDomainDiskDefPtr orig, disk; + virDomainGraphicsDefPtr newGraphics; virDomainNetDefPtr net; int pos; @@ -7498,6 +7499,22 @@ qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps, orig->startupPolicy = disk->startupPolicy; break; + case VIR_DOMAIN_DEVICE_GRAPHICS: + newGraphics = dev->data.graphics; + pos = qemuDomainFindGraphicsIndex(vmdef, newGraphics); + if (pos < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("cannot find existing graphics type '%s' device to modify"), + virDomainGraphicsTypeToString(newGraphics->type)); + return -1; + } + + virDomainGraphicsDefFree(vmdef->graphics[pos]); + + vmdef->graphics[pos] = newGraphics; + dev->data.graphics = NULL; + break; + case VIR_DOMAIN_DEVICE_NET: net = dev->data.net; if ((pos = virDomainNetFindIdx(vmdef, net)) < 0) @@ -7517,7 +7534,6 @@ qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps, case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_VIDEO: case VIR_DOMAIN_DEVICE_WATCHDOG: - case VIR_DOMAIN_DEVICE_GRAPHICS: case VIR_DOMAIN_DEVICE_HUB: case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_MEMBALLOON: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ec0122b..d7437db 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2312,6 +2312,20 @@ qemuDomainFindGraphics(virDomainObjPtr vm, } int +qemuDomainFindGraphicsIndex(virDomainDefPtr def, + virDomainGraphicsDefPtr dev) +{ + size_t i; + + for (i = 0; i < def->ngraphics; i++) { + if (def->graphics[i]->type == dev->type) + return i; + } + + return -1; +} + +int qemuDomainChangeGraphics(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainGraphicsDefPtr dev) diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 1c9ca8f..d13c532 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -55,6 +55,8 @@ int qemuDomainAttachHostDevice(virConnectPtr conn, virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainHostdevDefPtr hostdev); +int qemuDomainFindGraphicsIndex(virDomainDefPtr def, + virDomainGraphicsDefPtr dev); int qemuDomainChangeGraphics(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainGraphicsDefPtr dev); -- 1.7.12.4

On 08.12.2014 14:48, Wang Rui wrote:
We can change vnc password by using virDomainUpdateDeviceFlags API with live flag. But it can't be changed with config flag.
v1: https://www.redhat.com/archives/libvir-list/2014-November/msg00627.html
diff to v1:
according to Jan's suggestion, 1. (patch 1/3) change error number to VIR_ERR_OPERATION_UNSUPPORTED 2. (patch 3/3) add 'VIR_DOMAIN_XML_SECURE' to flags in initialization. 3. (patch 3/3) Introduce a new function qemuDomainFindGraphicsIndex. Free the old graphics def and replace it with the new one as what we did for DEVICE_NET.
Wang Rui (3): qemu: report properer error number when change graphics failed qemu: fix alignment of qemuDomainFindGraphics qemu: make persistent update of graphics device supported
src/conf/domain_conf.c | 2 +- src/qemu/qemu_driver.c | 18 +++++++++++++++++- src/qemu/qemu_hotplug.c | 36 ++++++++++++++++++++++++------------ src/qemu/qemu_hotplug.h | 2 ++ 4 files changed, 44 insertions(+), 14 deletions(-)
ACKed and pushed. Michal
participants (2)
-
Michal Privoznik
-
Wang Rui