mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-20 11:48:28 -06:00
qemu: Change return type of qemuMonitorGetGuestCPU()
To allow returning more granular errors, change the error type to an integer.
This commit is contained in:
parent
48072521b6
commit
a6a6f84af9
@ -3933,28 +3933,33 @@ qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd)
|
|||||||
* qemuMonitorJSONGetGuestCPU:
|
* qemuMonitorJSONGetGuestCPU:
|
||||||
* @mon: Pointer to the monitor
|
* @mon: Pointer to the monitor
|
||||||
* @arch: arch of the guest
|
* @arch: arch of the guest
|
||||||
|
* @data: returns the cpu data
|
||||||
*
|
*
|
||||||
* Retrieve the definition of the guest CPU from a running qemu instance.
|
* Retrieve the definition of the guest CPU from a running qemu instance.
|
||||||
*
|
*
|
||||||
* Returns the cpu definition object. On error returns NULL.
|
* Returns 0 on success, -2 if the operation is not supported by the guest,
|
||||||
|
* -1 on other errors.
|
||||||
*/
|
*/
|
||||||
virCPUDataPtr
|
int
|
||||||
qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
|
qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
|
||||||
virArch arch)
|
virArch arch,
|
||||||
|
virCPUDataPtr *data)
|
||||||
{
|
{
|
||||||
VIR_DEBUG("mon=%p, arch='%s'", mon, virArchToString(arch));
|
VIR_DEBUG("mon=%p, arch='%s' data='%p'", mon, virArchToString(arch), data);
|
||||||
|
|
||||||
if (!mon) {
|
if (!mon) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
_("monitor must not be NULL"));
|
_("monitor must not be NULL"));
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mon->json) {
|
if (!mon->json) {
|
||||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||||
_("JSON monitor is required"));
|
_("JSON monitor is required"));
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return qemuMonitorJSONGetGuestCPU(mon, arch);
|
*data = NULL;
|
||||||
|
|
||||||
|
return qemuMonitorJSONGetGuestCPU(mon, arch, data);
|
||||||
}
|
}
|
||||||
|
@ -764,8 +764,9 @@ int qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
int qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd);
|
int qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd);
|
||||||
|
|
||||||
virCPUDataPtr qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
|
int qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
|
||||||
virArch arch);
|
virArch arch,
|
||||||
|
virCPUDataPtr *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When running two dd process and using <> redirection, we need a
|
* When running two dd process and using <> redirection, we need a
|
||||||
|
@ -5503,9 +5503,10 @@ qemuMonitorJSONParseCPUx86FeatureWord(virJSONValuePtr data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virCPUDataPtr
|
static int
|
||||||
qemuMonitorJSONGetCPUx86Data(qemuMonitorPtr mon,
|
qemuMonitorJSONGetCPUx86Data(qemuMonitorPtr mon,
|
||||||
const char *property)
|
const char *property,
|
||||||
|
virCPUDataPtr *cpudata)
|
||||||
{
|
{
|
||||||
virJSONValuePtr cmd;
|
virJSONValuePtr cmd;
|
||||||
virJSONValuePtr reply = NULL;
|
virJSONValuePtr reply = NULL;
|
||||||
@ -5513,14 +5514,14 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitorPtr mon,
|
|||||||
virCPUx86Data *x86Data = NULL;
|
virCPUx86Data *x86Data = NULL;
|
||||||
virCPUx86CPUID cpuid;
|
virCPUx86CPUID cpuid;
|
||||||
size_t i;
|
size_t i;
|
||||||
virCPUDataPtr ret = NULL;
|
|
||||||
int n;
|
int n;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
if (!(cmd = qemuMonitorJSONMakeCommand("qom-get",
|
if (!(cmd = qemuMonitorJSONMakeCommand("qom-get",
|
||||||
"s:path", QOM_CPU_PATH,
|
"s:path", QOM_CPU_PATH,
|
||||||
"s:property", property,
|
"s:property", property,
|
||||||
NULL)))
|
NULL)))
|
||||||
return NULL;
|
return -1;
|
||||||
|
|
||||||
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -5551,9 +5552,11 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitorPtr mon,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ret = virCPUx86MakeData(VIR_ARCH_X86_64, &x86Data)))
|
if (!(*cpudata = virCPUx86MakeData(VIR_ARCH_X86_64, &x86Data)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virJSONValueFree(cmd);
|
virJSONValueFree(cmd);
|
||||||
virJSONValueFree(reply);
|
virJSONValueFree(reply);
|
||||||
@ -5566,24 +5569,27 @@ cleanup:
|
|||||||
* qemuMonitorJSONGetGuestCPU:
|
* qemuMonitorJSONGetGuestCPU:
|
||||||
* @mon: Pointer to the monitor
|
* @mon: Pointer to the monitor
|
||||||
* @arch: arch of the guest
|
* @arch: arch of the guest
|
||||||
|
* @data: returns the cpu data of the guest
|
||||||
*
|
*
|
||||||
* Retrieve the definition of the guest CPU from a running qemu instance.
|
* Retrieve the definition of the guest CPU from a running qemu instance.
|
||||||
*
|
*
|
||||||
* Returns the cpu definition object. On error returns NULL.
|
* Returns 0 on success, -2 if guest doesn't support this feature,
|
||||||
|
* -1 on other errors.
|
||||||
*/
|
*/
|
||||||
virCPUDataPtr
|
int
|
||||||
qemuMonitorJSONGetGuestCPU(qemuMonitorPtr mon,
|
qemuMonitorJSONGetGuestCPU(qemuMonitorPtr mon,
|
||||||
virArch arch)
|
virArch arch,
|
||||||
|
virCPUDataPtr *data)
|
||||||
{
|
{
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case VIR_ARCH_X86_64:
|
case VIR_ARCH_X86_64:
|
||||||
case VIR_ARCH_I686:
|
case VIR_ARCH_I686:
|
||||||
return qemuMonitorJSONGetCPUx86Data(mon, "feature-words");
|
return qemuMonitorJSONGetCPUx86Data(mon, "feature-words", data);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("CPU definition retrieval isn't supported for '%s'"),
|
_("CPU definition retrieval isn't supported for '%s'"),
|
||||||
virArchToString(arch));
|
virArchToString(arch));
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -427,5 +427,7 @@ int qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
|
|||||||
int qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon,
|
int qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon,
|
||||||
char ***aliases);
|
char ***aliases);
|
||||||
|
|
||||||
virCPUDataPtr qemuMonitorJSONGetGuestCPU(qemuMonitorPtr mon, virArch arch);
|
int qemuMonitorJSONGetGuestCPU(qemuMonitorPtr mon,
|
||||||
|
virArch arch,
|
||||||
|
virCPUDataPtr *data);
|
||||||
#endif /* QEMU_MONITOR_JSON_H */
|
#endif /* QEMU_MONITOR_JSON_H */
|
||||||
|
@ -3472,17 +3472,22 @@ qemuProcessVerifyGuestCPU(virQEMUDriverPtr driver, virDomainObjPtr vm)
|
|||||||
virArch arch = def->os.arch;
|
virArch arch = def->os.arch;
|
||||||
virCPUDataPtr guestcpu = NULL;
|
virCPUDataPtr guestcpu = NULL;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
|
int rc;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case VIR_ARCH_I686:
|
case VIR_ARCH_I686:
|
||||||
case VIR_ARCH_X86_64:
|
case VIR_ARCH_X86_64:
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
guestcpu = qemuMonitorGetGuestCPU(priv->mon, arch);
|
rc = qemuMonitorGetGuestCPU(priv->mon, arch, &guestcpu);
|
||||||
qemuDomainObjExitMonitor(driver, vm);
|
qemuDomainObjExitMonitor(driver, vm);
|
||||||
|
|
||||||
if (!(guestcpu))
|
if (rc < 0) {
|
||||||
|
if (rc == -2)
|
||||||
|
break;
|
||||||
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (def->features[VIR_DOMAIN_FEATURE_PVSPINLOCK] == VIR_DOMAIN_FEATURE_STATE_ON) {
|
if (def->features[VIR_DOMAIN_FEATURE_PVSPINLOCK] == VIR_DOMAIN_FEATURE_STATE_ON) {
|
||||||
if (!cpuHasFeature(guestcpu, VIR_CPU_x86_KVM_PV_UNHALT)) {
|
if (!cpuHasFeature(guestcpu, VIR_CPU_x86_KVM_PV_UNHALT)) {
|
||||||
|
@ -1997,8 +1997,9 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
|
|||||||
if (qemuMonitorTestAddItem(test, "qom-get", jsonStr) < 0)
|
if (qemuMonitorTestAddItem(test, "qom-get", jsonStr) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(cpuData = qemuMonitorJSONGetGuestCPU(qemuMonitorTestGetMonitor(test),
|
if (qemuMonitorJSONGetGuestCPU(qemuMonitorTestGetMonitor(test),
|
||||||
VIR_ARCH_X86_64)))
|
VIR_ARCH_X86_64,
|
||||||
|
&cpuData) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(actual = cpuDataFormat(cpuData)))
|
if (!(actual = cpuDataFormat(cpuData)))
|
||||||
|
Loading…
Reference in New Issue
Block a user