This is pure code movement to dig out the function internals into a separate functions as the code is to be reused later. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_driver.c | 86 +++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d6cb404..7065999 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1868,6 +1868,59 @@ static int qemuDomainSuspend(virDomainPtr dom) } +/** + * qemuDomainSetTimeImpl: + * + * Domain must have a job set as the monitor is entered here. + * + * Returns 0 on success, -1 otherwise. + */ +static int +qemuDomainSetTimeImpl(virQEMUDriverPtr driver, + virDomainObjPtr vm, + long long seconds, + unsigned int nseconds, + bool rtcSync) +{ + int rv, ret = -1; + qemuDomainObjPrivatePtr priv = vm->privateData; + + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_RTC_RESET_REINJECTION)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot set time: qemu doesn't support " + "rtc-reset-reinjection command")); + goto cleanup; + } + + if (!qemuDomainAgentAvailable(priv, true)) + goto cleanup; + + qemuDomainObjEnterAgent(vm); + rv = qemuAgentSetTime(priv->agent, seconds, nseconds, rtcSync); + qemuDomainObjExitAgent(vm); + + if (rv < 0) + goto cleanup; + + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); + goto cleanup; + } + + qemuDomainObjEnterMonitor(driver, vm); + rv = qemuMonitorRTCResetReinjection(priv->mon); + qemuDomainObjExitMonitor(driver, vm); + + if (rv < 0) + goto cleanup; + + ret = 0; + cleanup: + return ret; +} + + static int qemuDomainResumeFlags(virDomainPtr dom, unsigned int flags) @@ -17712,11 +17765,9 @@ qemuDomainSetTime(virDomainPtr dom, unsigned int flags) { virQEMUDriverPtr driver = dom->conn->privateData; - qemuDomainObjPrivatePtr priv; virDomainObjPtr vm; bool rtcSync = flags & VIR_DOMAIN_TIME_SYNC; int ret = -1; - int rv; virCheckFlags(VIR_DOMAIN_TIME_SYNC, ret); @@ -17726,8 +17777,6 @@ qemuDomainSetTime(virDomainPtr dom, if (virDomainSetTimeEnsureACL(dom->conn, vm->def) < 0) goto cleanup; - priv = vm->privateData; - if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; @@ -17737,34 +17786,7 @@ qemuDomainSetTime(virDomainPtr dom, goto endjob; } - if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_RTC_RESET_REINJECTION)) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("cannot set time: qemu doesn't support " - "rtc-reset-reinjection command")); - goto endjob; - } - - if (!qemuDomainAgentAvailable(priv, true)) - goto endjob; - - qemuDomainObjEnterAgent(vm); - rv = qemuAgentSetTime(priv->agent, seconds, nseconds, rtcSync); - qemuDomainObjExitAgent(vm); - - if (rv < 0) - goto endjob; - - if (!virDomainObjIsActive(vm)) { - virReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("domain is not running")); - goto endjob; - } - - qemuDomainObjEnterMonitor(driver, vm); - rv = qemuMonitorRTCResetReinjection(priv->mon); - qemuDomainObjExitMonitor(driver, vm); - - if (rv < 0) + if (qemuDomainSetTimeImpl(driver, vm, seconds, nseconds, rtcSync) < 0) goto endjob; ret = 0; -- 2.0.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list