mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemu_agent: Move updater function for VCPU hotplug into qemu_agent.c
To allow testing of the cpu updater function, this function needs to be available separately. Export it from qemu_agent.c where it should belong.
This commit is contained in:
parent
2e38753fb0
commit
18a629167c
@ -1597,3 +1597,66 @@ cleanup:
|
|||||||
virJSONValueFree(cpus);
|
virJSONValueFree(cpus);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* modify the cpu info structure to set the correct amount of cpus */
|
||||||
|
int
|
||||||
|
qemuAgentUpdateCPUInfo(unsigned int nvcpus,
|
||||||
|
qemuAgentCPUInfoPtr cpuinfo,
|
||||||
|
int ncpuinfo)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int nonline = 0;
|
||||||
|
int nofflinable = 0;
|
||||||
|
|
||||||
|
/* count the active and offlinable cpus */
|
||||||
|
for (i = 0; i < ncpuinfo; i++) {
|
||||||
|
if (cpuinfo[i].online)
|
||||||
|
nonline++;
|
||||||
|
|
||||||
|
if (cpuinfo[i].offlinable && cpuinfo[i].online)
|
||||||
|
nofflinable++;
|
||||||
|
|
||||||
|
/* This shouldn't happen, but we can't trust the guest agent */
|
||||||
|
if (!cpuinfo[i].online && !cpuinfo[i].offlinable) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("Invalid data provided by guest agent"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* the guest agent reported less cpus than requested */
|
||||||
|
if (nvcpus > ncpuinfo) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("guest agent reports less cpu than requested"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* not enough offlinable CPUs to support the request */
|
||||||
|
if (nvcpus < nonline - nofflinable) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
|
_("Cannot offline enough CPUs"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < ncpuinfo; i++) {
|
||||||
|
if (nvcpus < nonline) {
|
||||||
|
/* unplug */
|
||||||
|
if (cpuinfo[i].offlinable && cpuinfo[i].online) {
|
||||||
|
cpuinfo[i].online = false;
|
||||||
|
nonline--;
|
||||||
|
}
|
||||||
|
} else if (nvcpus > nonline) {
|
||||||
|
/* plug */
|
||||||
|
if (!cpuinfo[i].online) {
|
||||||
|
cpuinfo[i].online = true;
|
||||||
|
nonline++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* done */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -94,4 +94,7 @@ struct _qemuAgentCPUInfo {
|
|||||||
|
|
||||||
int qemuAgentGetVCPUs(qemuAgentPtr mon, qemuAgentCPUInfoPtr *info);
|
int qemuAgentGetVCPUs(qemuAgentPtr mon, qemuAgentCPUInfoPtr *info);
|
||||||
int qemuAgentSetVCPUs(qemuAgentPtr mon, qemuAgentCPUInfoPtr cpus, size_t ncpus);
|
int qemuAgentSetVCPUs(qemuAgentPtr mon, qemuAgentCPUInfoPtr cpus, size_t ncpus);
|
||||||
|
int qemuAgentUpdateCPUInfo(unsigned int nvcpus,
|
||||||
|
qemuAgentCPUInfoPtr cpuinfo,
|
||||||
|
int ncpuinfo);
|
||||||
#endif /* __QEMU_AGENT_H__ */
|
#endif /* __QEMU_AGENT_H__ */
|
||||||
|
@ -4089,68 +4089,6 @@ unsupported:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
qemuDomainPrepareAgentVCPUs(unsigned int nvcpus,
|
|
||||||
qemuAgentCPUInfoPtr cpuinfo,
|
|
||||||
int ncpuinfo)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
int nonline = 0;
|
|
||||||
int nofflinable = 0;
|
|
||||||
|
|
||||||
/* count the active and offlinable cpus */
|
|
||||||
for (i = 0; i < ncpuinfo; i++) {
|
|
||||||
if (cpuinfo[i].online)
|
|
||||||
nonline++;
|
|
||||||
|
|
||||||
if (cpuinfo[i].offlinable && cpuinfo[i].online)
|
|
||||||
nofflinable++;
|
|
||||||
|
|
||||||
/* This shouldn't happen, but we can't trust the guest agent */
|
|
||||||
if (!cpuinfo[i].online && !cpuinfo[i].offlinable) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Invalid data provided by guest agent"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* the guest agent reported less cpus than requested */
|
|
||||||
if (nvcpus > ncpuinfo) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("guest agent reports less cpu than requested"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* not enough offlinable CPUs to support the request */
|
|
||||||
if (nvcpus < nonline - nofflinable) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
||||||
_("Cannot offline enough CPUs"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < ncpuinfo; i++) {
|
|
||||||
if (nvcpus < nonline) {
|
|
||||||
/* unplug */
|
|
||||||
if (cpuinfo[i].offlinable && cpuinfo[i].online) {
|
|
||||||
cpuinfo[i].online = false;
|
|
||||||
nonline--;
|
|
||||||
}
|
|
||||||
} else if (nvcpus > nonline) {
|
|
||||||
/* plug */
|
|
||||||
if (!cpuinfo[i].online) {
|
|
||||||
cpuinfo[i].online = true;
|
|
||||||
nonline++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* done */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
@ -4243,7 +4181,7 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
if (ncpuinfo < 0)
|
if (ncpuinfo < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (qemuDomainPrepareAgentVCPUs(nvcpus, cpuinfo, ncpuinfo) < 0)
|
if (qemuAgentUpdateCPUInfo(nvcpus, cpuinfo, ncpuinfo) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
qemuDomainObjEnterAgent(vm);
|
qemuDomainObjEnterAgent(vm);
|
||||||
|
Loading…
Reference in New Issue
Block a user