[libvirt] [PATCH v2 0/3] vz: implement some API calls

v1-v2 change: - removed vzConnectGetType - addressed comments on vzConnectGetMaxVcpus Maxim Nestratov (3): vz: implement connectGetMaxVcpus API calls vz: implement API calls of nodeGetxxx family vz: implement some domain API calls src/vz/vz_driver.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) -- 2.4.3

Because we have no limitation for maximal number of vcpus in containers we report as maximum 1028 just for the sake of common sence. Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com> --- src/vz/vz_driver.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 15dc70f..987824f 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1337,12 +1337,26 @@ vzDomainMemoryStats(virDomainPtr domain, return ret; } +static int vzConnectGetMaxVcpus(virConnectPtr conn ATTRIBUTE_UNUSED, + const char *type) +{ + /* As far as we have no limitation for containers + * we report maximum */ + if (type == NULL || STRCASEEQ(type, "vz") || STRCASEEQ(type, "parallels")) + return 1028; + + virReportError(VIR_ERR_INVALID_ARG, + _("unknown type '%s'"), type); + return -1; +} + static virHypervisorDriver vzDriver = { .name = "vz", .connectOpen = vzConnectOpen, /* 0.10.0 */ .connectClose = vzConnectClose, /* 0.10.0 */ .connectGetVersion = vzConnectGetVersion, /* 0.10.0 */ .connectGetHostname = vzConnectGetHostname, /* 0.10.0 */ + .connectGetMaxVcpus = vzConnectGetMaxVcpus, /* 1.2.21 */ .nodeGetInfo = vzNodeGetInfo, /* 0.10.0 */ .connectGetCapabilities = vzConnectGetCapabilities, /* 0.10.0 */ .connectBaselineCPU = vzConnectBaselineCPU, /* 1.2.6 */ -- 2.4.3

The following functions were implemented: vzNodeGetCPUStats, vzNodeGetMemoryStats, vzNodeGetCellsFreeMemory and vzNodeGetFreeMemory. Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com> --- src/vz/vz_driver.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 987824f..80c5e8c 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1350,6 +1350,44 @@ static int vzConnectGetMaxVcpus(virConnectPtr conn ATTRIBUTE_UNUSED, return -1; } +static int +vzNodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED, + int cpuNum, + virNodeCPUStatsPtr params, + int *nparams, + unsigned int flags) +{ + return nodeGetCPUStats(cpuNum, params, nparams, flags); +} + +static int +vzNodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED, + int cellNum, + virNodeMemoryStatsPtr params, + int *nparams, + unsigned int flags) +{ + return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); +} + +static int +vzNodeGetCellsFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED, + unsigned long long *freeMems, + int startCell, + int maxCells) +{ + return nodeGetCellsFreeMemory(freeMems, startCell, maxCells); +} + +static unsigned long long +vzNodeGetFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + unsigned long long freeMem; + if (nodeGetMemory(NULL, &freeMem) < 0) + return 0; + return freeMem; +} + static virHypervisorDriver vzDriver = { .name = "vz", .connectOpen = vzConnectOpen, /* 0.10.0 */ @@ -1358,6 +1396,10 @@ static virHypervisorDriver vzDriver = { .connectGetHostname = vzConnectGetHostname, /* 0.10.0 */ .connectGetMaxVcpus = vzConnectGetMaxVcpus, /* 1.2.21 */ .nodeGetInfo = vzNodeGetInfo, /* 0.10.0 */ + .nodeGetCPUStats = vzNodeGetCPUStats, /* 1.2.21 */ + .nodeGetMemoryStats = vzNodeGetMemoryStats, /* 1.2.21 */ + .nodeGetCellsFreeMemory = vzNodeGetCellsFreeMemory, /* 1.2.21 */ + .nodeGetFreeMemory = vzNodeGetFreeMemory, /* 1.2.21 */ .connectGetCapabilities = vzConnectGetCapabilities, /* 0.10.0 */ .connectBaselineCPU = vzConnectBaselineCPU, /* 1.2.6 */ .connectListDomains = vzConnectListDomains, /* 0.10.0 */ -- 2.4.3

The following functions are implemented: vzDomainIsUpdated, vzDomainGetVcpusFlags and vzDomainGetMaxVcpus. Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com> --- src/vz/vz_driver.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 80c5e8c..f6bb696 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1337,6 +1337,56 @@ vzDomainMemoryStats(virDomainPtr domain, return ret; } +static int +vzDomainGetVcpusFlags(virDomainPtr dom, + unsigned int flags) +{ + virDomainObjPtr privdom = NULL; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG | + VIR_DOMAIN_VCPU_MAXIMUM, -1); + + if (!(privdom = vzDomObjFromDomain(dom))) + goto cleanup; + + if (flags & VIR_DOMAIN_VCPU_MAXIMUM) + ret = privdom->def->maxvcpus; + else + ret = privdom->def->vcpus; + + cleanup: + if (privdom) + virObjectUnlock(privdom); + + return ret; +} + +static int vzDomainGetMaxVcpus(virDomainPtr dom) +{ + return vzDomainGetVcpusFlags(dom, (VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_VCPU_MAXIMUM)); +} + +static int vzDomainIsUpdated(virDomainPtr dom) +{ + virDomainObjPtr privdom; + int ret = -1; + + /* As far as VZ domains are always updated (e.g. current==persistent), + * we just check for domain existence */ + if (!(privdom = vzDomObjFromDomain(dom))) + goto cleanup; + + ret = 0; + + cleanup: + if (privdom) + virObjectUnlock(privdom); + return ret; +} + static int vzConnectGetMaxVcpus(virConnectPtr conn ATTRIBUTE_UNUSED, const char *type) { @@ -1432,6 +1482,9 @@ static virHypervisorDriver vzDriver = { .domainDetachDevice = vzDomainDetachDevice, /* 1.2.15 */ .domainDetachDeviceFlags = vzDomainDetachDeviceFlags, /* 1.2.15 */ .domainIsActive = vzDomainIsActive, /* 1.2.10 */ + .domainIsUpdated = vzDomainIsUpdated, /* 1.2.21 */ + .domainGetVcpusFlags = vzDomainGetVcpusFlags, /* 1.2.21 */ + .domainGetMaxVcpus = vzDomainGetMaxVcpus, /* 1.2.21 */ .connectDomainEventRegisterAny = vzConnectDomainEventRegisterAny, /* 1.2.10 */ .connectDomainEventDeregisterAny = vzConnectDomainEventDeregisterAny, /* 1.2.10 */ .nodeGetCPUMap = vzNodeGetCPUMap, /* 1.2.8 */ -- 2.4.3

On 10/19/2015 10:02 PM, Maxim Nestratov wrote:
v1-v2 change: - removed vzConnectGetType - addressed comments on vzConnectGetMaxVcpus
Maxim Nestratov (3): vz: implement connectGetMaxVcpus API calls vz: implement API calls of nodeGetxxx family vz: implement some domain API calls
src/vz/vz_driver.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+)
ACKed and pushed this series, thanks!
participants (2)
-
Dmitry Guryanov
-
Maxim Nestratov