[libvirt] [PATCH 1/2] test_driver: implement virDomainPMSuspendForDuration
Daniel Henrique Barboza
danielhb413 at gmail.com
Tue Sep 3 17:00:01 UTC 2019
On 8/13/19 1:19 PM, Ilias Stamatis wrote:
> Signed-off-by: Ilias Stamatis <stamatis.iliass at gmail.com>
> ---
> src/test/test_driver.c | 79 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 79 insertions(+)
>
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index 5f5c512571..d21a69c7ed 100755
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -4090,6 +4090,84 @@ static int testDomainSetMetadata(virDomainPtr dom,
> return ret;
> }
>
> +
> +static int
> +testDomainPMSuspendForDuration(virDomainPtr dom,
> + unsigned int target,
> + unsigned long long duration,
> + unsigned int flags)
> +{
> + virDomainObjPtr vm;
> + testDriverPtr privconn = dom->conn->privateData;
> + virObjectEventPtr event_suspend = NULL;
> + virObjectEventPtr event_shutdown = NULL;
> + int ret = -1;
> +
> + virCheckFlags(0, -1);
> +
> + if (duration) {
> + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
> + _("Duration not supported. Use 0 for now"));
> + return -1;
> + }
> +
> + if (target >= VIR_NODE_SUSPEND_TARGET_LAST) {
> + virReportError(VIR_ERR_INVALID_ARG,
> + _("Unknown suspend target: %u"),
> + target);
> + return -1;
> + }
> +
> + if (!(vm = testDomObjFromDomain(dom)))
> + return -1;
> +
> + if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) {
> + virReportError(VIR_ERR_OPERATION_INVALID, "%s",
> + _("domain is not running"));
> + goto cleanup;
> + }
> +
> + if (vm->def->pm.s3 || vm->def->pm.s4) {
> + if (vm->def->pm.s3 == VIR_TRISTATE_BOOL_NO &&
> + (target == VIR_NODE_SUSPEND_TARGET_MEM ||
> + target == VIR_NODE_SUSPEND_TARGET_HYBRID)) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("S3 state is disabled for this domain"));
> + goto cleanup;
> + }
> +
> + if (vm->def->pm.s4 == VIR_TRISTATE_BOOL_NO &&
> + target == VIR_NODE_SUSPEND_TARGET_DISK) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("S4 state is disabled for this domain"));
> + goto cleanup;
> + }
> + }
> +
> + virDomainObjSetState(vm, VIR_DOMAIN_PMSUSPENDED,
> + VIR_DOMAIN_PMSUSPENDED_UNKNOWN);
> + event_suspend = virDomainEventLifecycleNewFromObj(vm,
> + VIR_DOMAIN_EVENT_PMSUSPENDED,
> + VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
> + virObjectEventStateQueue(privconn->eventState, event_suspend);
> +
> + if (target == VIR_NODE_SUSPEND_TARGET_DISK) {
> + testDomainShutdownState(dom, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
> + event_shutdown = virDomainEventLifecycleNewFromObj(vm,
> + VIR_DOMAIN_EVENT_STOPPED,
> + VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
> + if (!vm->persistent)
> + virDomainObjListRemove(privconn->domains, vm);
> + }
> +
> + ret = 0;
> + cleanup:
> + virDomainObjEndAPI(&vm);
> + virObjectEventStateQueue(privconn->eventState, event_shutdown);
Unless you're OK with passing a NULL here, you need to check if
'event_shutdown' is NULL at this point, since there's no guarantee that
you set the var with something else in the 'if
target==VIR_NODE_SUSPEND_TARGET_DISK'
conditional.
I'll take a guess here and say that this is unintended, thus it's best
to move this
'virObjectEventStateQueue()' call that uses 'event_shutdown' inside the "if"
right before the cleanup label.
Thanks,
DHB
> + return ret;
> +}
> +
> +
> #define TEST_TOTAL_CPUTIME 48772617035LL
>
> static int
> @@ -9415,6 +9493,7 @@ static virHypervisorDriver testHypervisorDriver = {
> .domainSendKey = testDomainSendKey, /* 5.5.0 */
> .domainGetMetadata = testDomainGetMetadata, /* 1.1.3 */
> .domainSetMetadata = testDomainSetMetadata, /* 1.1.3 */
> + .domainPMSuspendForDuration = testDomainPMSuspendForDuration, /* 5.7.0 */
> .domainGetCPUStats = testDomainGetCPUStats, /* 5.6.0 */
> .domainSendProcessSignal = testDomainSendProcessSignal, /* 5.5.0 */
> .connectGetCPUModelNames = testConnectGetCPUModelNames, /* 1.1.3 */
> --
> 2.22.0
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
More information about the libvir-list
mailing list