[PATCH 02/11] hyperv: implement domainUndefine and domainUndefineFlags
Daniel P. Berrangé
berrange at redhat.com
Thu Nov 26 14:26:38 UTC 2020
On Tue, Nov 24, 2020 at 02:48:31PM -0500, Matt Coleman wrote:
> Co-authored-by: Sri Ramanujam <sramanujam at datto.com>
> Signed-off-by: Matt Coleman <matt at datto.com>
> ---
> src/hyperv/hyperv_driver.c | 60 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 60 insertions(+)
>
> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
> index 6d81deb4d9..8e16ff529f 100644
> --- a/src/hyperv/hyperv_driver.c
> +++ b/src/hyperv/hyperv_driver.c
> @@ -1874,6 +1874,64 @@ hypervDomainCreate(virDomainPtr domain)
> }
>
>
> +static int
> +hypervDomainUndefineFlags(virDomainPtr domain, unsigned int flags)
> +{
> + int result = -1;
> + char uuid_string[VIR_UUID_STRING_BUFLEN];
> + hypervPrivate *priv = domain->conn->privateData;
> + Msvm_ComputerSystem *computerSystem = NULL;
> + g_autoptr(hypervInvokeParamsList) params = NULL;
> + g_auto(virBuffer) eprQuery = VIR_BUFFER_INITIALIZER;
> +
> + virCheckFlags(0, -1);
> +
> + virUUIDFormat(domain->uuid, uuid_string);
> +
> + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0)
> + goto cleanup;
> +
> + /* try to shut down the VM if it's not disabled, just to be safe */
> + if (computerSystem->data->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_DISABLED &&
> + hypervDomainShutdown(domain) < 0) {
> + goto cleanup;
> + }
Many, but not all, drivers in libvirt allow undefining the cofig for a running
VM. ie we can delete the config on disk, without affecting the running VM.
This results in a so called "transient" VM - basically a VM which only exists
as long as it is running - virDomainCreateXML creates such a beast, while
virDomainDefineXML+virDomainCreate creates a "persistent" VM and starts it.
If hyperv doesn't allow that, then shutting down the VM is likely to be
surprising.
I'd suggest we report an error indicating undefine is not permitted for a
running VM in such a case.
> +
> + /* prepare params */
> + params = hypervCreateInvokeParamsList("DestroySystem",
> + MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR,
> + Msvm_VirtualSystemManagementService_WmiInfo);
> +
> + if (!params)
> + goto cleanup;
> +
> + virBufferEscapeSQL(&eprQuery,
> + MSVM_COMPUTERSYSTEM_WQL_SELECT "WHERE Name = '%s'",
> + uuid_string);
> +
> + if (hypervAddEprParam(params, "AffectedSystem", &eprQuery, Msvm_ComputerSystem_WmiInfo) < 0)
> + goto cleanup;
> +
> + /* actually destroy the VM */
> + if (hypervInvokeMethod(priv, ¶ms, NULL) < 0)
> + goto cleanup;
> +
> + result = 0;
> +
> + cleanup:
> + hypervFreeObject(priv, (hypervObject *)computerSystem);
> +
> + return result;
> +}
> +
> +
> +static int
> +hypervDomainUndefine(virDomainPtr domain)
> +{
> + return hypervDomainUndefineFlags(domain, 0);
> +}
> +
> +
> static int
> hypervDomainGetAutostart(virDomainPtr domain, int *autostart)
> {
> @@ -2485,6 +2543,8 @@ static virHypervisorDriver hypervHypervisorDriver = {
> .connectNumOfDefinedDomains = hypervConnectNumOfDefinedDomains, /* 0.9.5 */
> .domainCreate = hypervDomainCreate, /* 0.9.5 */
> .domainCreateWithFlags = hypervDomainCreateWithFlags, /* 0.9.5 */
> + .domainUndefine = hypervDomainUndefine, /* 6.10.0 */
> + .domainUndefineFlags = hypervDomainUndefineFlags, /* 6.10.0 */
> .domainGetAutostart = hypervDomainGetAutostart, /* 6.9.0 */
> .domainSetAutostart = hypervDomainSetAutostart, /* 6.9.0 */
> .domainGetSchedulerType = hypervDomainGetSchedulerType, /* 6.10.0 */
> --
> 2.27.0
>
>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
More information about the libvir-list
mailing list