[PATCH 3/3] util: bitmap: Don't alloc overly large binary bitmaps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]