From d678379df1967d18b050fedc1ab674391b3629f5 Mon Sep 17 00:00:00 2001 From: Konstantin Neumoin Date: Fri, 14 Apr 2017 17:53:52 +0300 Subject: [PATCH] vz: support virDomainSetVcpus Acked-by: Nikolay Shirokovskiy Signed-off-by: Konstantin Neumoin --- src/vz/vz_driver.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/vz/vz_sdk.c | 23 +++++++++++++++++++++++ src/vz/vz_sdk.h | 1 + 3 files changed, 67 insertions(+) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index da83a8ff5c..ed7132f213 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -3905,6 +3905,47 @@ vzDomainReset(virDomainPtr domain, unsigned int flags) return ret; } +static int vzDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus, + unsigned int flags) +{ + virDomainObjPtr dom = NULL; + int ret = -1; + bool job = false; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (!(dom = vzDomObjFromDomainRef(domain))) + goto cleanup; + + if (vzCheckConfigUpdateFlags(dom, &flags) < 0) + goto cleanup; + + if (virDomainSetVcpusFlagsEnsureACL(domain->conn, dom->def, flags) < 0) + goto cleanup; + + if (vzDomainObjBeginJob(dom) < 0) + goto cleanup; + job = true; + + if (vzEnsureDomainExists(dom) < 0) + goto cleanup; + + ret = prlsdkSetCpuCount(dom, nvcpus); + + cleanup: + if (job) + vzDomainObjEndJob(dom); + virDomainObjEndAPI(&dom); + return ret; +} + +static int vzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) +{ + return vzDomainSetVcpusFlags(dom, nvcpus, + VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG); +} + static virHypervisorDriver vzHypervisorDriver = { .name = "vz", .connectOpen = vzConnectOpen, /* 0.10.0 */ @@ -3954,6 +3995,8 @@ static virHypervisorDriver vzHypervisorDriver = { .domainDetachDeviceFlags = vzDomainDetachDeviceFlags, /* 1.2.15 */ .domainIsActive = vzDomainIsActive, /* 1.2.10 */ .domainIsUpdated = vzDomainIsUpdated, /* 1.2.21 */ + .domainSetVcpus = vzDomainSetVcpus, /* 3.3.0 */ + .domainSetVcpusFlags = vzDomainSetVcpusFlags, /* 3.3.0 */ .domainGetVcpusFlags = vzDomainGetVcpusFlags, /* 1.2.21 */ .domainGetMaxVcpus = vzDomainGetMaxVcpus, /* 1.2.21 */ .domainSetUserPassword = vzDomainSetUserPassword, /* 2.0.0 */ diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index c1a50fdc68..2daa44a900 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -4902,3 +4902,26 @@ int prlsdkMigrate(virDomainObjPtr dom, virURIPtr uri, cleanup: return ret; } + +int prlsdkSetCpuCount(virDomainObjPtr dom, unsigned int count) +{ + vzDomObjPtr privdom = dom->privateData; + PRL_HANDLE job; + PRL_RESULT pret; + + job = PrlVm_BeginEdit(privdom->sdkdom); + if (PRL_FAILED(waitDomainJob(job, dom))) + goto error; + + pret = PrlVmCfg_SetCpuCount(privdom->sdkdom, count); + prlsdkCheckRetGoto(pret, error); + + job = PrlVm_CommitEx(privdom->sdkdom, 0); + if (PRL_FAILED(waitDomainJob(job, dom))) + goto error; + + return 0; + + error: + return -1; +} diff --git a/src/vz/vz_sdk.h b/src/vz/vz_sdk.h index f8da2ad3ad..100a5e315b 100644 --- a/src/vz/vz_sdk.h +++ b/src/vz/vz_sdk.h @@ -71,6 +71,7 @@ int prlsdkGetMemoryStats(PRL_HANDLE sdkstas, virDomainMemoryStatPtr stats, unsigned int nr_stats); /* memsize is in MiB */ int prlsdkSetMemsize(virDomainObjPtr dom, unsigned int memsize); +int prlsdkSetCpuCount(virDomainObjPtr dom, unsigned int count); int prlsdkDomainSetUserPassword(virDomainObjPtr dom, const char *user, -- GitLab