[libvirt] [PATCH 1/3] vz: implement connectGetType and connectGetMaxVcpus API calls

From: Maxim Nestratov <mnestratov@virtuozzo.com> As a connection type we report 'vz'. And 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 | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 15dc70f..3cd6096 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1337,12 +1337,31 @@ 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")) + return 1028; + + virReportError(VIR_ERR_INVALID_ARG, + _("unknown type '%s'"), type); + return -1; +} + +static const char *vzConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED) { + return "vz"; +} + 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 */ + .connectGetType = vzConnectGetType, /* 1.2.21 */ + .connectGetMaxVcpus = vzConnectGetMaxVcpus, /* 1.2.21 */ .nodeGetInfo = vzNodeGetInfo, /* 0.10.0 */ .connectGetCapabilities = vzConnectGetCapabilities, /* 0.10.0 */ .connectBaselineCPU = vzConnectBaselineCPU, /* 1.2.6 */ -- 1.7.1

From: Maxim Nestratov <mnestratov@virtuozzo.com> 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 files changed, 42 insertions(+), 0 deletions(-) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 3cd6096..8a311ed 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1354,6 +1354,44 @@ static const char *vzConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED) { return "vz"; } +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 */ @@ -1363,6 +1401,10 @@ static virHypervisorDriver vzDriver = { .connectGetType = vzConnectGetType, /* 1.2.21 */ .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 */ -- 1.7.1

On 10/14/2015 12:50 PM, Maxim Nestratov wrote:
From: Maxim Nestratov <mnestratov@virtuozzo.com>
The following functions were implemented:
vzNodeGetCPUStats, vzNodeGetMemoryStats, vzNodeGetCellsFreeMemory and vzNodeGetFreeMemory.
Looks good to me, ACK.
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com> --- src/vz/vz_driver.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 3cd6096..8a311ed 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1354,6 +1354,44 @@ static const char *vzConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED) { return "vz"; }
+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 */ @@ -1363,6 +1401,10 @@ static virHypervisorDriver vzDriver = { .connectGetType = vzConnectGetType, /* 1.2.21 */ .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 */

From: Maxim Nestratov <mnestratov@virtuozzo.com> The following functions are implemented: vzDomainIsUpdated, vzDomainGetVcpusFlags and vzDomainGetMaxVcpus. Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com> --- src/vz/vz_driver.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 8a311ed..6557816 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) { @@ -1437,6 +1487,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 */ -- 1.7.1

On 10/14/2015 12:50 PM, Maxim Nestratov wrote:
From: Maxim Nestratov <mnestratov@virtuozzo.com>
The following functions are implemented:
vzDomainIsUpdated, vzDomainGetVcpusFlags and vzDomainGetMaxVcpus.
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
ACK
--- src/vz/vz_driver.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 8a311ed..6557816 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) { @@ -1437,6 +1487,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 */

On 10/14/2015 12:50 PM, Maxim Nestratov wrote:
From: Maxim Nestratov <mnestratov@virtuozzo.com>
As a connection type we report 'vz'. And 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 | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 15dc70f..3cd6096 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1337,12 +1337,31 @@ 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 */ What about VMs? + if (type == NULL || STRCASEEQ(type, "vz")) What about parallels virt type?
+ return 1028; + Why not 1024?
+ virReportError(VIR_ERR_INVALID_ARG, + _("unknown type '%s'"), type); + return -1; +} + +static const char *vzConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED) { + return "vz"; +} +
Is this function really needed? virConnectGetType returns driver name if it's not implemented in the driver, exactly what are you doing. const char * virConnectGetType(virConnectPtr conn) { const char *ret; VIR_DEBUG("conn=%p", conn); virResetLastError(); virCheckConnectReturn(conn, NULL); if (conn->driver->connectGetType) { ret = conn->driver->connectGetType(conn); if (ret) return ret; } return conn->driver->name; }
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 */ + .connectGetType = vzConnectGetType, /* 1.2.21 */ + .connectGetMaxVcpus = vzConnectGetMaxVcpus, /* 1.2.21 */ .nodeGetInfo = vzNodeGetInfo, /* 0.10.0 */ .connectGetCapabilities = vzConnectGetCapabilities, /* 0.10.0 */ .connectBaselineCPU = vzConnectBaselineCPU, /* 1.2.6 */

14.10.2015 18:28, Dmitry Guryanov пишет:
On 10/14/2015 12:50 PM, Maxim Nestratov wrote:
From: Maxim Nestratov <mnestratov@virtuozzo.com>
As a connection type we report 'vz'. And 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 | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 15dc70f..3cd6096 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1337,12 +1337,31 @@ 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 */ What about VMs? + if (type == NULL || STRCASEEQ(type, "vz")) What about parallels virt type?
+ return 1028; + Why not 1024?
The only reason is that this number is used in openVZ driver. I failed to find out why it was chosen back then. I guess it was NR_CPUS configured for openVZ kernel.
+ virReportError(VIR_ERR_INVALID_ARG, + _("unknown type '%s'"), type); + return -1; +} + +static const char *vzConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED) { + return "vz"; +} +
Is this function really needed? virConnectGetType returns driver name if it's not implemented in the driver, exactly what are you doing.
const char * virConnectGetType(virConnectPtr conn) { const char *ret; VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckConnectReturn(conn, NULL);
if (conn->driver->connectGetType) { ret = conn->driver->connectGetType(conn); if (ret) return ret; } return conn->driver->name; }
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 */ + .connectGetType = vzConnectGetType, /* 1.2.21 */ + .connectGetMaxVcpus = vzConnectGetMaxVcpus, /* 1.2.21 */ .nodeGetInfo = vzNodeGetInfo, /* 0.10.0 */ .connectGetCapabilities = vzConnectGetCapabilities, /* 0.10.0 */ .connectBaselineCPU = vzConnectBaselineCPU, /* 1.2.6 */
participants (3)
-
Dmitry Guryanov
-
Maxim Nestratov
-
Maxim Nestratov