[libvirt] [PATCH 0/3] bitmap: Fix regression when getting iothread info

Peter Krempa (3): vz: Remove dead code from vzDomainGetVcpus vz: Use virBitmapToDataBuf instead of virBitmapToData in vzDomainGetVcpus util: bitmap: Don't alloc overly large binary bitmaps src/util/virbitmap.c | 7 +++++-- src/vz/vz_driver.c | 24 ++++-------------------- 2 files changed, 9 insertions(+), 22 deletions(-) -- 2.4.5

'maxcpu' and 'vcpus' are set but not used after that --- src/vz/vz_driver.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 47c5023..a489767 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -823,7 +823,7 @@ vzDomainGetVcpus(virDomainPtr domain, { virDomainObjPtr privdom = NULL; size_t i; - int v, maxcpu, hostcpus; + int v; int ret = -1; if (!(privdom = vzDomObjFromDomainRef(domain))) @@ -836,13 +836,6 @@ vzDomainGetVcpus(virDomainPtr domain, goto cleanup; } - if ((hostcpus = nodeGetCPUCount()) < 0) - goto cleanup; - - maxcpu = maplen * 8; - if (maxcpu > hostcpus) - maxcpu = hostcpus; - if (maxinfo >= 1) { if (info != NULL) { memset(info, 0, sizeof(*info) * maxinfo); -- 2.4.5

--- src/vz/vz_driver.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index a489767..8d90191 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -823,7 +823,6 @@ vzDomainGetVcpus(virDomainPtr domain, { virDomainObjPtr privdom = NULL; size_t i; - int v; int ret = -1; if (!(privdom = vzDomObjFromDomainRef(domain))) @@ -847,19 +846,11 @@ vzDomainGetVcpus(virDomainPtr domain, } } if (cpumaps != NULL) { - unsigned char *tmpmap = NULL; - int tmpmapLen = 0; - memset(cpumaps, 0, maplen * maxinfo); - virBitmapToData(privdom->def->cpumask, &tmpmap, &tmpmapLen); - if (tmpmapLen > maplen) - tmpmapLen = maplen; - - for (v = 0; v < maxinfo; v++) { - unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v); - memcpy(cpumap, tmpmap, tmpmapLen); - } - VIR_FREE(tmpmap); + for (i = 0; i < maxinfo; i++) + virBitmapToDataBuf(privdom->def->cpumask, + VIR_GET_CPUMAP(cpumaps, maplen, i), + maplen); } } ret = maxinfo; -- 2.4.5

Optimize the virBitmap to array-of-char bitmap conversion by skipping trailing zero bytes. This also fixes a regression when requesting iothread information from a live VM since after commit 825df8c3158cfaf5f398418471f10f4ff3c3515a the bitmap returned from virProcessGetAffinity is too big to be formatted properly via RPC. A user would get the following error: error: Unable to get domain IOThreads information error: Unable to encode message payload Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1238589 --- src/util/virbitmap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 9abc807..4d270a9 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -498,9 +498,12 @@ virBitmapPtr virBitmapNewData(void *data, int len) */ int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen) { - int len; + ssize_t len; - len = (bitmap->max_bit + CHAR_BIT - 1) / CHAR_BIT; + if ((len = virBitmapLastSetBit(bitmap)) < 0) + len = 1; + else + len = (len + CHAR_BIT) / CHAR_BIT; if (VIR_ALLOC_N(*data, len) < 0) return -1; -- 2.4.5

On 02.07.2015 16:55, Peter Krempa wrote:
Peter Krempa (3): vz: Remove dead code from vzDomainGetVcpus vz: Use virBitmapToDataBuf instead of virBitmapToData in vzDomainGetVcpus util: bitmap: Don't alloc overly large binary bitmaps
src/util/virbitmap.c | 7 +++++-- src/vz/vz_driver.c | 24 ++++-------------------- 2 files changed, 9 insertions(+), 22 deletions(-)
ACK series Michal

On Wed, Jul 08, 2015 at 10:22:33 +0200, Michal Privoznik wrote:
On 02.07.2015 16:55, Peter Krempa wrote:
Peter Krempa (3): vz: Remove dead code from vzDomainGetVcpus vz: Use virBitmapToDataBuf instead of virBitmapToData in vzDomainGetVcpus util: bitmap: Don't alloc overly large binary bitmaps
src/util/virbitmap.c | 7 +++++-- src/vz/vz_driver.c | 24 ++++-------------------- 2 files changed, 9 insertions(+), 22 deletions(-)
ACK series
Pushed; Thanks. Peter
participants (2)
-
Michal Privoznik
-
Peter Krempa