Quite straigthforward as vz sdk memory setting function makes just what we want to that is set "amount of physical memory allocated to a domain". 'useflags' is introduced for non flag function implementation. We can't just use combination of flags like "live | config" or we fail for inactive domains. Other combinations have drawbacks too. Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx> --- src/vz/vz_driver.c | 36 ++++++++++++++++++++++++++++++++++++ src/vz/vz_sdk.c | 24 ++++++++++++++++++++++++ src/vz/vz_sdk.h | 2 ++ 3 files changed, 62 insertions(+) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 08447d9..85f17f7 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1479,6 +1479,40 @@ vzConnectUnregisterCloseCallback(virConnectPtr conn, virConnectCloseFunc cb) return ret; } +static int vzDomainSetMemoryFlagsImpl(virDomainPtr domain, unsigned long memory, + unsigned int flags, bool useflags) +{ + virDomainObjPtr dom = NULL; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (!(dom = vzDomObjFromDomain(domain))) + return -1; + + if (useflags && vzCheckConfigUpdateFlags(dom, &flags) < 0) + goto cleanup; + + ret = prlsdkSetMemsize(dom, memory >> 10); + + cleanup: + + virObjectUnlock(dom); + return ret; +} + +static int vzDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory, + unsigned int flags) +{ + return vzDomainSetMemoryFlagsImpl(domain, memory, flags, true); +} + +static int vzDomainSetMemory(virDomainPtr domain, unsigned long memory) +{ + return vzDomainSetMemoryFlagsImpl(domain, memory, 0, false); +} + static virHypervisorDriver vzDriver = { .name = "vz", .connectOpen = vzConnectOpen, /* 0.10.0 */ @@ -1543,6 +1577,8 @@ static virHypervisorDriver vzDriver = { .domainMemoryStats = vzDomainMemoryStats, /* 1.2.17 */ .connectRegisterCloseCallback = vzConnectRegisterCloseCallback, /* 1.3.2 */ .connectUnregisterCloseCallback = vzConnectUnregisterCloseCallback, /* 1.3.2 */ + .domainSetMemoryFlags = vzDomainSetMemoryFlags, /* 1.3.3 */ + .domainSetMemory = vzDomainSetMemory, /* 1.3.3 */ }; static virConnectDriver vzConnectDriver = { diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index c006517..85ea0d7 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -4302,3 +4302,27 @@ prlsdkGetMemoryStats(virDomainObjPtr dom, return ret; } + +/* memsize is in MiB */ +int prlsdkSetMemsize(virDomainObjPtr dom, unsigned int memsize) +{ + vzDomObjPtr privdom = dom->privateData; + PRL_HANDLE job; + PRL_RESULT pret; + + job = PrlVm_BeginEdit(privdom->sdkdom); + if (PRL_FAILED(waitJob(job))) + goto error; + + pret = PrlVmCfg_SetRamSize(privdom->sdkdom, memsize); + prlsdkCheckRetGoto(pret, error); + + job = PrlVm_CommitEx(privdom->sdkdom, 0); + if (PRL_FAILED(waitJob(job))) + goto error; + + return 0; + + error: + return -1; +} diff --git a/src/vz/vz_sdk.h b/src/vz/vz_sdk.h index 2f11d4f..4621868 100644 --- a/src/vz/vz_sdk.h +++ b/src/vz/vz_sdk.h @@ -80,3 +80,5 @@ int prlsdkGetMemoryStats(virDomainObjPtr dom, virDomainMemoryStatPtr stats, unsigned int nr_stats); void prlsdkDomObjFreePrivate(void *p); +/* memsize is in MiB */ +int prlsdkSetMemsize(virDomainObjPtr dom, unsigned int memsize); -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list