Add a new member variable map_len to store map len of bitmap. and rename size to max_bit accordingly. rename virBitmapAlloc to virBitmapNew. --- src/conf/domain_conf.c | 2 +- src/conf/snapshot_conf.c | 2 +- src/libvirt_private.syms | 2 +- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/util/bitmap.c | 30 +++++++++++++----------------- src/util/bitmap.h | 2 +- tools/virsh-domain.c | 2 +- 8 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 292cc9a..3a44432 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8871,7 +8871,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (STREQ(def->os.type, "hvm")) { if (virDomainDefParseBootXML(ctxt, def, &bootMapSize) < 0) goto error; - if (bootMapSize && !(bootMap = virBitmapAlloc(bootMapSize))) + if (bootMapSize && !(bootMap = virBitmapNew(bootMapSize))) goto no_memory; } diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index e13cdd6..ba5b188 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -357,7 +357,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, goto cleanup; } - if (!(map = virBitmapAlloc(def->dom->ndisks))) { + if (!(map = virBitmapNew(def->dom->ndisks))) { virReportOOMError(); goto cleanup; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8dfb4ce..557fa0e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -6,11 +6,11 @@ # # bitmap.h -virBitmapAlloc; virBitmapClearBit; virBitmapCopy; virBitmapFree; virBitmapGetBit; +virBitmapNew; virBitmapSetBit; virBitmapString; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ed85b6f..cf9de69 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1649,7 +1649,7 @@ qemuCapsNew(void) { virBitmapPtr caps; - if (!(caps = virBitmapAlloc(QEMU_CAPS_LAST))) + if (!(caps = virBitmapNew(QEMU_CAPS_LAST))) virReportOOMError(); return caps; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a410521..7a8b475 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -696,7 +696,7 @@ qemudStartup(int privileged) { * do this before the config is loaded properly, since the port * numbers are configurable now */ if ((qemu_driver->reservedRemotePorts = - virBitmapAlloc(qemu_driver->remotePortMax - qemu_driver->remotePortMin)) == NULL) + virBitmapNew(qemu_driver->remotePortMax - qemu_driver->remotePortMin)) == NULL) goto out_of_memory; /* We should always at least have the 'nop' manager, so diff --git a/src/util/bitmap.c b/src/util/bitmap.c index cd52802..dc9c28a 100644 --- a/src/util/bitmap.c +++ b/src/util/bitmap.c @@ -36,7 +36,8 @@ struct _virBitmap { - size_t size; + size_t max_bit; + size_t map_len; unsigned long *map; }; @@ -48,7 +49,7 @@ struct _virBitmap { /** - * virBitmapAlloc: + * virBitmapNew: * @size: number of bits * * Allocate a bitmap capable of containing @size bits. @@ -56,7 +57,7 @@ struct _virBitmap { * Returns a pointer to the allocated bitmap or NULL if * memory cannot be allocated. */ -virBitmapPtr virBitmapAlloc(size_t size) +virBitmapPtr virBitmapNew(size_t size) { virBitmapPtr bitmap; size_t sz; @@ -75,7 +76,8 @@ virBitmapPtr virBitmapAlloc(size_t size) return NULL; } - bitmap->size = size; + bitmap->max_bit = size; + bitmap->map_len = sz; return bitmap; } @@ -83,7 +85,7 @@ virBitmapPtr virBitmapAlloc(size_t size) * virBitmapFree: * @bitmap: previously allocated bitmap * - * Free @bitmap previously allocated by virBitmapAlloc. + * Free @bitmap previously allocated by virBitmapNew. */ void virBitmapFree(virBitmapPtr bitmap) { @@ -96,17 +98,12 @@ void virBitmapFree(virBitmapPtr bitmap) int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src) { - size_t sz; - - if (dst->size != src->size) { + if (dst->max_bit != src->max_bit) { errno = EINVAL; return -1; } - sz = (src->size + VIR_BITMAP_BITS_PER_UNIT - 1) / - VIR_BITMAP_BITS_PER_UNIT; - - memcpy(dst->map, src->map, sz * sizeof(src->map[0])); + memcpy(dst->map, src->map, src->map_len * sizeof(src->map[0])); return 0; } @@ -123,7 +120,7 @@ int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src) */ int virBitmapSetBit(virBitmapPtr bitmap, size_t b) { - if (bitmap->size <= b) + if (bitmap->max_bit <= b) return -1; bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] |= VIR_BITMAP_BIT(b); @@ -141,7 +138,7 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b) */ int virBitmapClearBit(virBitmapPtr bitmap, size_t b) { - if (bitmap->size <= b) + if (bitmap->max_bit <= b) return -1; bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] &= ~VIR_BITMAP_BIT(b); @@ -161,7 +158,7 @@ int virBitmapClearBit(virBitmapPtr bitmap, size_t b) */ int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result) { - if (bitmap->size <= b) + if (bitmap->max_bit <= b) return -1; *result = !!(bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] & VIR_BITMAP_BIT(b)); @@ -183,8 +180,7 @@ char *virBitmapString(virBitmapPtr bitmap) virBufferAddLit(&buf, "0x"); - sz = (bitmap->size + VIR_BITMAP_BITS_PER_UNIT - 1) / - VIR_BITMAP_BITS_PER_UNIT; + sz = bitmap->map_len; while (sz--) { virBufferAsprintf(&buf, "%0*lx", diff --git a/src/util/bitmap.h b/src/util/bitmap.h index 1d8750e..2609509 100644 --- a/src/util/bitmap.h +++ b/src/util/bitmap.h @@ -34,7 +34,7 @@ typedef virBitmap *virBitmapPtr; /* * Allocate a bitmap capable of containing @size bits. */ -virBitmapPtr virBitmapAlloc(size_t size) ATTRIBUTE_RETURN_CHECK; +virBitmapPtr virBitmapNew(size_t size) ATTRIBUTE_RETURN_CHECK; /* * Free previously allocated bitmap diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c6695b3..a7d6c37 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -7178,7 +7178,7 @@ vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2) if (n1_child_size == 0 && n2_child_size == 0) return true; - if (!(bitmap = virBitmapAlloc(n1_child_size))) { + if (!(bitmap = virBitmapNew(n1_child_size))) { virReportOOMError(); return false; } -- 1.7.10.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list