|
23 | 23 | #include "ch_conf.h" |
24 | 24 | #include "ch_domain.h" |
25 | 25 | #include "ch_driver.h" |
| 26 | +#include "ch_hotplug.h" |
26 | 27 | #include "ch_monitor.h" |
27 | 28 | #include "ch_process.h" |
28 | 29 | #include "ch_cgroup.h" |
@@ -1770,6 +1771,92 @@ chDomainSetNumaParameters(virDomainPtr dom, |
1770 | 1771 | return ret; |
1771 | 1772 | } |
1772 | 1773 |
|
| 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 | + |
1773 | 1860 | /* Function Tables */ |
1774 | 1861 | static virHypervisorDriver chHypervisorDriver = { |
1775 | 1862 | .name = "CH", |
@@ -1818,6 +1905,7 @@ static virHypervisorDriver chHypervisorDriver = { |
1818 | 1905 | .nodeGetCPUMap = chNodeGetCPUMap, /* 6.7.0 */ |
1819 | 1906 | .domainSetNumaParameters = chDomainSetNumaParameters, /* 6.7.0 */ |
1820 | 1907 | .domainGetNumaParameters = chDomainGetNumaParameters, /* 6.7.0 */ |
| 1908 | + .domainSetVcpusFlags = chDomainSetVcpusFlags, /* 6.7.0 */ |
1821 | 1909 | }; |
1822 | 1910 |
|
1823 | 1911 | static virConnectDriver chConnectDriver = { |
|
0 commit comments