util: bitmap: Tolerate NULL bitmaps in virBitmapEqual

After virBitmapEqual is able to compare NULL bitmaps few bits of code
can be cleaned up.
This commit is contained in:
Peter Krempa 2015-01-20 19:41:08 +01:00
parent 9bbbb91216
commit 20448c2a72
4 changed files with 17 additions and 35 deletions

View File

@ -15637,18 +15637,10 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
goto error;
}
if (src_huge->nodemask && dst_huge->nodemask) {
if (!virBitmapEqual(src_huge->nodemask, dst_huge->nodemask)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Target huge page nodemask does not match source"));
goto error;
}
} else {
if (src_huge->nodemask || dst_huge->nodemask) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Target huge page nodemask does not match source"));
goto error;
}
if (!virBitmapEqual(src_huge->nodemask, dst_huge->nodemask)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Target huge page nodemask does not match source"));
goto error;
}
}
@ -19138,20 +19130,12 @@ virDomainIsAllVcpupinInherited(virDomainDefPtr def)
{
size_t i;
if (!def->cpumask) {
if (def->cputune.nvcpupin)
for (i = 0; i < def->cputune.nvcpupin; i++) {
if (!virBitmapEqual(def->cputune.vcpupin[i]->cpumask, def->cpumask))
return false;
else
return true;
} else {
for (i = 0; i < def->cputune.nvcpupin; i++) {
if (!virBitmapEqual(def->cputune.vcpupin[i]->cpumask,
def->cpumask))
return false;
}
}
return true;
}
return true;
}
@ -19489,9 +19473,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
for (i = 0; i < def->cputune.nvcpupin; i++) {
char *cpumask;
/* Ignore the vcpupin which inherit from "cpuset of "<vcpu>." */
if (def->cpumask &&
virBitmapEqual(def->cpumask,
def->cputune.vcpupin[i]->cpumask))
if (virBitmapEqual(def->cpumask, def->cputune.vcpupin[i]->cpumask))
continue;
virBufferAsprintf(buf, "<vcpupin vcpu='%u' ",
@ -19518,9 +19500,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
for (i = 0; i < def->cputune.niothreadspin; i++) {
char *cpumask;
/* Ignore the iothreadpin which inherit from "cpuset of "<vcpu>." */
if (def->cpumask &&
virBitmapEqual(def->cpumask,
def->cputune.iothreadspin[i]->cpumask))
if (virBitmapEqual(def->cpumask, def->cputune.iothreadspin[i]->cpumask))
continue;
virBufferAsprintf(buf, "<iothreadpin iothread='%u' ",

View File

@ -542,9 +542,6 @@ virDomainNumatuneNodesEqual(virDomainNumatunePtr n1,
if (!nd1->nodeset && !nd2->nodeset)
continue;
if (!nd1->nodeset || !nd2->nodeset)
return false;
if (nd1->mode != nd2->mode)
return false;

View File

@ -504,6 +504,12 @@ bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2)
virBitmapPtr tmp;
size_t i;
if (!b1 && !b2)
return true;
if (!b1 || !b2)
return false;
if (b1->max_bit > b2->max_bit) {
tmp = b1;
b1 = b2;

View File

@ -84,8 +84,7 @@ virBitmapPtr virBitmapNewData(void *data, int len) ATTRIBUTE_NONNULL(1);
int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2);
size_t virBitmapSize(virBitmapPtr bitmap)
ATTRIBUTE_NONNULL(1);