mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
qemu: Implement virDomainPMWakeup API
using 'system-wakeup' monitor command. It is supported only in JSON, as we are enabling it if possible. Moreover, this command is available in qemu-1.1+ which definitely has JSON.
This commit is contained in:
parent
a04d10f739
commit
9bf1bcc59d
@ -12165,6 +12165,61 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
qemuDomainPMWakeup(virDomainPtr dom,
|
||||
unsigned int flags)
|
||||
{
|
||||
struct qemud_driver *driver = dom->conn->privateData;
|
||||
virDomainObjPtr vm;
|
||||
int ret = -1;
|
||||
qemuDomainObjPrivatePtr priv;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
qemuDriverLock(driver);
|
||||
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||
qemuDriverUnlock(driver);
|
||||
|
||||
if (!vm) {
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
virUUIDFormat(dom->uuid, uuidstr);
|
||||
qemuReportError(VIR_ERR_NO_DOMAIN,
|
||||
_("no domain with matching uuid '%s'"), uuidstr);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!virDomainObjIsActive(vm)) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||
"%s", _("domain is not running"));
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
priv = vm->privateData;
|
||||
|
||||
if (!qemuCapsGet(priv->qemuCaps, QEMU_CAPS_WAKEUP)) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||
_("Unable to wake up domain due to "
|
||||
"missing system_wakeup monitor command"));
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
ret = qemuMonitorSystemWakeup(priv->mon);
|
||||
qemuDomainObjExitMonitor(driver, vm);
|
||||
|
||||
endjob:
|
||||
if (qemuDomainObjEndJob(driver, vm) == 0)
|
||||
vm = NULL;
|
||||
|
||||
cleanup:
|
||||
if (vm)
|
||||
virDomainObjUnlock(vm);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static virDriver qemuDriver = {
|
||||
.no = VIR_DRV_QEMU,
|
||||
.name = "QEMU",
|
||||
@ -12323,6 +12378,7 @@ static virDriver qemuDriver = {
|
||||
.domainSetMetadata = qemuDomainSetMetadata, /* 0.9.10 */
|
||||
.domainGetMetadata = qemuDomainGetMetadata, /* 0.9.10 */
|
||||
.domainPMSuspendForDuration = qemuDomainPMSuspendForDuration, /* 0.9.11 */
|
||||
.domainPMWakeup = qemuDomainPMWakeup, /* 0.9.11 */
|
||||
};
|
||||
|
||||
|
||||
|
@ -2784,3 +2784,22 @@ int qemuMonitorOpenGraphics(qemuMonitorPtr mon,
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorSystemWakeup(qemuMonitorPtr mon)
|
||||
{
|
||||
VIR_DEBUG("mon=%p", mon);
|
||||
|
||||
if (!mon) {
|
||||
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("monitor must not be NULL"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!mon->json) {
|
||||
qemuReportError(VIR_ERR_NO_SUPPORT, "%s",
|
||||
_("JSON monitor is required"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return qemuMonitorJSONSystemWakeup(mon);
|
||||
}
|
||||
|
@ -536,6 +536,8 @@ int qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon,
|
||||
const char *device,
|
||||
virDomainBlockIoTuneInfoPtr reply);
|
||||
|
||||
int qemuMonitorSystemWakeup(qemuMonitorPtr mon);
|
||||
|
||||
/**
|
||||
* When running two dd process and using <> redirection, we need a
|
||||
* shell that will not truncate files. These two strings serve that
|
||||
|
@ -3492,3 +3492,24 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon,
|
||||
virJSONValueFree(result);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorJSONSystemWakeup(qemuMonitorPtr mon)
|
||||
{
|
||||
int ret = -1;
|
||||
virJSONValuePtr cmd = NULL;
|
||||
virJSONValuePtr reply = NULL;
|
||||
|
||||
cmd = qemuMonitorJSONMakeCommand("system_wakeup", NULL);
|
||||
if (!cmd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = qemuMonitorJSONCommand(mon, cmd, &reply);
|
||||
|
||||
if (ret == 0)
|
||||
ret = qemuMonitorJSONCheckError(cmd, reply);
|
||||
|
||||
virJSONValueFree(cmd);
|
||||
virJSONValueFree(reply);
|
||||
return ret;
|
||||
}
|
||||
|
@ -267,4 +267,6 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon,
|
||||
const char *device,
|
||||
virDomainBlockIoTuneInfoPtr reply);
|
||||
|
||||
int qemuMonitorJSONSystemWakeup(qemuMonitorPtr mon);
|
||||
|
||||
#endif /* QEMU_MONITOR_JSON_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user