Skip to content

Commit 90d9dac

Browse files
committed
ch: Enable CPU hotplug support
Enable the use setvcpus for the cloud-hypervisor domain. Specifically supporting 'virsh setvcpus --live'.
1 parent 8475531 commit 90d9dac

File tree

2 files changed

+88
-7
lines changed

2 files changed

+88
-7
lines changed

src/ch/ch_driver.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "ch_conf.h"
2424
#include "ch_domain.h"
2525
#include "ch_driver.h"
26+
#include "ch_hotplug.h"
2627
#include "ch_monitor.h"
2728
#include "ch_process.h"
2829
#include "ch_cgroup.h"
@@ -1770,6 +1771,92 @@ chDomainSetNumaParameters(virDomainPtr dom,
17701771
return ret;
17711772
}
17721773

1774+
static int
1775+
virCHDomainSetVcpusMax(virCHDriverPtr driver,
1776+
virDomainDefPtr def,
1777+
virDomainDefPtr persistentDef,
1778+
unsigned int nvcpus)
1779+
{
1780+
g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver);
1781+
unsigned int topologycpus;
1782+
1783+
if (def) {
1784+
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
1785+
_("maximum vcpu count of a live domain can't be modified"));
1786+
return -1;
1787+
}
1788+
1789+
if (virDomainNumaGetCPUCountTotal(persistentDef->numa) > nvcpus) {
1790+
virReportError(VIR_ERR_INVALID_ARG, "%s",
1791+
_("Number of CPUs in <numa> exceeds the desired "
1792+
"maximum vcpu count"));
1793+
return -1;
1794+
}
1795+
1796+
if (virDomainDefGetVcpusTopology(persistentDef, &topologycpus) == 0 &&
1797+
nvcpus != topologycpus) {
1798+
/* allow setting a valid vcpu count for the topology so an invalid
1799+
* setting may be corrected via this API */
1800+
virReportError(VIR_ERR_INVALID_ARG, "%s",
1801+
_("CPU topology doesn't match the desired vcpu count"));
1802+
return -1;
1803+
}
1804+
1805+
/* ordering information may become invalid, thus clear it */
1806+
virDomainDefVcpuOrderClear(persistentDef);
1807+
1808+
if (virDomainDefSetVcpusMax(persistentDef, nvcpus, driver->xmlopt) < 0)
1809+
return -1;
1810+
1811+
if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->stateDir) < 0)
1812+
return -1;
1813+
1814+
return 0;
1815+
}
1816+
1817+
static int
1818+
chDomainSetVcpusFlags(virDomainPtr dom,
1819+
unsigned int nvcpus,
1820+
unsigned int flags)
1821+
{
1822+
virCHDriverPtr driver = dom->conn->privateData;
1823+
virDomainObjPtr vm = NULL;
1824+
virDomainDefPtr def;
1825+
virDomainDefPtr persistentDef;
1826+
int ret = -1;
1827+
1828+
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
1829+
VIR_DOMAIN_AFFECT_CONFIG |
1830+
VIR_DOMAIN_VCPU_MAXIMUM |
1831+
VIR_DOMAIN_VCPU_GUEST |
1832+
VIR_DOMAIN_VCPU_HOTPLUGGABLE, -1);
1833+
1834+
if (!(vm = virCHDomainObjFromDomain(dom)))
1835+
goto cleanup;
1836+
1837+
if (virDomainSetVcpusFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
1838+
goto cleanup;
1839+
1840+
1841+
if (virCHDomainObjBeginJob(vm, CH_JOB_MODIFY) < 0)
1842+
goto cleanup;
1843+
1844+
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
1845+
goto endjob;
1846+
1847+
if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
1848+
ret = virCHDomainSetVcpusMax(driver, def, persistentDef, nvcpus);
1849+
else
1850+
ret = virCHDomainSetVcpusInternal(vm, def, nvcpus);
1851+
1852+
endjob:
1853+
virCHDomainObjEndJob(vm);
1854+
1855+
cleanup:
1856+
virDomainObjEndAPI(&vm);
1857+
return ret;
1858+
}
1859+
17731860
/* Function Tables */
17741861
static virHypervisorDriver chHypervisorDriver = {
17751862
.name = "CH",
@@ -1818,6 +1905,7 @@ static virHypervisorDriver chHypervisorDriver = {
18181905
.nodeGetCPUMap = chNodeGetCPUMap, /* 6.7.0 */
18191906
.domainSetNumaParameters = chDomainSetNumaParameters, /* 6.7.0 */
18201907
.domainGetNumaParameters = chDomainGetNumaParameters, /* 6.7.0 */
1908+
.domainSetVcpusFlags = chDomainSetVcpusFlags, /* 6.7.0 */
18211909
};
18221910

18231911
static virConnectDriver chConnectDriver = {

src/ch/ch_process.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ virCHProcessSetupVcpu(virDomainObjPtr vm,
421421
static int
422422
virCHProcessSetupVcpuPids(virDomainObjPtr vm)
423423
{
424-
size_t maxvcpus = virDomainDefGetVcpusMax(vm->def);
425424
virCHMonitorThreadInfoPtr info = NULL;
426425
size_t nthreads, ncpus = 0;
427426
size_t i;
@@ -436,19 +435,13 @@ virCHProcessSetupVcpuPids(virDomainObjPtr vm)
436435
if (info[i].type != virCHThreadTypeVcpu)
437436
continue;
438437

439-
// TODO: hotplug support
440438
vcpuInfo = &info[i].vcpuInfo;
441439
vcpu = virDomainDefGetVcpu(vm->def, vcpuInfo->cpuid);
442440
vcpupriv = CH_DOMAIN_VCPU_PRIVATE(vcpu);
443441
vcpupriv->tid = info[i].tid;
444442
ncpus++;
445443
}
446444

447-
// TODO: Remove the warning when hotplug is implemented.
448-
if (ncpus != maxvcpus)
449-
VIR_WARN("Mismatch in the number of cpus, expected: %ld, actual: %ld",
450-
maxvcpus, ncpus);
451-
452445
return 0;
453446
}
454447

0 commit comments

Comments
 (0)