On Tue, Oct 13, 2015 at 12:10:05PM +0200, Michal Privoznik wrote:
On 22.09.2015 14:15, Martin Kletzander wrote:
> In order for the user to be able to fix broken domains function
> qemuDomainGetXMLDesc() needs to be able to lookup invalid domain
> definitions and handle them properly. When redefined, function
> qemuDomainDefineXMLFlags() must clear the 'invalid XML' reason. As a
> nice addition, qemuDomainGetState() can lookup such domains without any
> other change and that allows virsh not only to get their status, but
> also to list them.
>
> Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
> ---
> src/qemu/qemu_driver.c | 21 ++++++++++++++-------
> 1 file changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 0a671500134f..881c5c4c1984 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -2706,7 +2706,7 @@ qemuDomainGetState(virDomainPtr dom,
>
> virCheckFlags(0, -1);
>
> - if (!(vm = qemuDomObjFromDomain(dom)))
> + if (!(vm = qemuDomObjFromDomainInvalid(dom)))
> goto cleanup;
>
> if (virDomainGetStateEnsureACL(dom->conn, vm->def) < 0)
> @@ -7082,19 +7082,23 @@ qemuDomainGetXMLDesc(virDomainPtr dom,
>
> /* Flags checked by virDomainDefFormat */
>
> - if (!(vm = qemuDomObjFromDomain(dom)))
> + if (!(vm = qemuDomObjFromDomainInvalid(dom)))
> goto cleanup;
>
> if (virDomainGetXMLDescEnsureACL(dom->conn, vm->def, flags) < 0)
> goto cleanup;
>
> - if (qemuDomainUpdateCurrentMemorySize(driver, vm) < 0)
> - goto cleanup;
> + if (vm->def->parseError) {
> + ignore_value(VIR_STRDUP(ret, vm->def->xmlStr));
> + } else {
> + if (qemuDomainUpdateCurrentMemorySize(driver, vm) < 0)
> + goto cleanup;
>
> - if ((flags & VIR_DOMAIN_XML_MIGRATABLE))
> - flags |= QEMU_DOMAIN_FORMAT_LIVE_FLAGS;
> + if ((flags & VIR_DOMAIN_XML_MIGRATABLE))
> + flags |= QEMU_DOMAIN_FORMAT_LIVE_FLAGS;
>
> - ret = qemuDomainFormatXML(driver, vm, flags);
> + ret = qemuDomainFormatXML(driver, vm, flags);
> + }
>
> cleanup:
> virDomainObjEndAPI(&vm);
> @@ -7557,6 +7561,9 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
> goto cleanup;
> }
>
> + if (oldDef && oldDef->parseError)
> + virDomainObjSetState(vm, virDomainObjGetState(vm, NULL), 0);
> +
I don't understand this bit. Why is this needed?
This resets the domain state reason to "unknown" (while keeping the
state) which is the same one as the properly-loaded domains have.
Otherwise it would keep the INVALID_XML reason -- virshdomstate
--reason would output shutoff (invalid xml).
> event = virDomainEventLifecycleNewFromObj(vm,
> VIR_DOMAIN_EVENT_DEFINED,
> !oldDef ?
>
Otherwise looking good.
Michal