bitmap: new member variable and function renaming

Add a new member variable map_len to store map len of bitmap.
and rename size to max_bit accordingly.

rename virBitmapAlloc to virBitmapNew.
This commit is contained in:
Hu Tao 2012-09-14 15:46:56 +08:00 committed by Laine Stump
parent 60b0284f24
commit 0831a5bade
9 changed files with 21 additions and 25 deletions

View File

@ -9110,7 +9110,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;
}

View File

@ -357,7 +357,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
goto cleanup;
}
if (!(map = virBitmapAlloc(def->dom->ndisks))) {
if (!(map = virBitmapNew(def->dom->ndisks))) {
virReportOOMError();
goto cleanup;
}

View File

@ -6,11 +6,11 @@
#
# bitmap.h
virBitmapAlloc;
virBitmapClearBit;
virBitmapCopy;
virBitmapFree;
virBitmapGetBit;
virBitmapNew;
virBitmapSetBit;
virBitmapString;

View File

@ -869,7 +869,7 @@ libxlStartup(int privileged) {
/* Allocate bitmap for vnc port reservation */
if ((libxl_driver->reservedVNCPorts =
virBitmapAlloc(LIBXL_VNC_PORT_MAX - LIBXL_VNC_PORT_MIN)) == NULL)
virBitmapNew(LIBXL_VNC_PORT_MAX - LIBXL_VNC_PORT_MIN)) == NULL)
goto out_of_memory;
if (virDomainObjListInit(&libxl_driver->domains) < 0)

View File

@ -1718,7 +1718,7 @@ qemuCapsNew(void)
if (!(caps = virObjectNew(qemuCapsClass)))
return NULL;
if (!(caps->flags = virBitmapAlloc(QEMU_CAPS_LAST)))
if (!(caps->flags = virBitmapNew(QEMU_CAPS_LAST)))
goto no_memory;
return caps;

View File

@ -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

View File

@ -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",

View File

@ -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

View File

@ -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;
}