mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
Introduce virBitmapIsBitSet
A helper that never returns an error and treats bits out of bitmap range as false. Use it everywhere we use ignore_value on virBitmapGetBit, or loop over the bitmap size.
This commit is contained in:
parent
76a2a5ce8b
commit
22fd3ac38f
@ -3107,7 +3107,6 @@ virDomainDefRejectDuplicateControllers(virDomainDefPtr def)
|
||||
virDomainControllerDefPtr cont;
|
||||
size_t nbitmaps = 0;
|
||||
int ret = -1;
|
||||
bool b;
|
||||
size_t i;
|
||||
|
||||
memset(max_idx, -1, sizeof(max_idx));
|
||||
@ -3133,8 +3132,7 @@ virDomainDefRejectDuplicateControllers(virDomainDefPtr def)
|
||||
if (max_idx[cont->type] == -1)
|
||||
continue;
|
||||
|
||||
ignore_value(virBitmapGetBit(bitmaps[cont->type], cont->idx, &b));
|
||||
if (b) {
|
||||
if (virBitmapIsBitSet(bitmaps[cont->type], cont->idx)) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Multiple '%s' controllers with index '%d'"),
|
||||
virDomainControllerTypeToString(cont->type),
|
||||
|
@ -439,9 +439,7 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def)
|
||||
virInterfaceLinkFormat(&buf, &data->net.lnk);
|
||||
if (data->net.features) {
|
||||
for (i = 0; i < VIR_NET_DEV_FEAT_LAST; i++) {
|
||||
bool b;
|
||||
ignore_value(virBitmapGetBit(data->net.features, i, &b));
|
||||
if (b) {
|
||||
if (virBitmapIsBitSet(data->net.features, i)) {
|
||||
virBufferAsprintf(&buf, "<feature name='%s'/>\n",
|
||||
virNetDevFeatureTypeToString(i));
|
||||
}
|
||||
|
@ -465,7 +465,6 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
|
||||
virBitmapPtr map = NULL;
|
||||
size_t i;
|
||||
int ndisks;
|
||||
bool inuse;
|
||||
|
||||
if (!def->dom) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
@ -500,7 +499,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virBitmapGetBit(map, idx, &inuse) < 0 || inuse) {
|
||||
if (virBitmapIsBitSet(map, idx)) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("disk '%s' specified twice"),
|
||||
disk->name);
|
||||
@ -553,8 +552,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
|
||||
for (i = 0; i < def->dom->ndisks; i++) {
|
||||
virDomainSnapshotDiskDefPtr disk;
|
||||
|
||||
ignore_value(virBitmapGetBit(map, i, &inuse));
|
||||
if (inuse)
|
||||
if (virBitmapIsBitSet(map, i))
|
||||
continue;
|
||||
disk = &def->disks[ndisks++];
|
||||
if (VIR_ALLOC(disk->src) < 0)
|
||||
|
@ -1567,7 +1567,6 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
|
||||
|
||||
if (options->featureToString && def->features) {
|
||||
size_t i;
|
||||
bool b;
|
||||
bool empty = virBitmapIsAllClear(def->features);
|
||||
|
||||
if (empty) {
|
||||
@ -1578,8 +1577,7 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
|
||||
}
|
||||
|
||||
for (i = 0; i < VIR_STORAGE_FILE_FEATURE_LAST; i++) {
|
||||
ignore_value(virBitmapGetBit(def->features, i, &b));
|
||||
if (b)
|
||||
if (virBitmapIsBitSet(def->features, i))
|
||||
virBufferAsprintf(buf, "<%s/>\n",
|
||||
options->featureToString(i));
|
||||
}
|
||||
|
@ -1070,6 +1070,7 @@ virBitmapFree;
|
||||
virBitmapGetBit;
|
||||
virBitmapIsAllClear;
|
||||
virBitmapIsAllSet;
|
||||
virBitmapIsBitSet;
|
||||
virBitmapLastSetBit;
|
||||
virBitmapNew;
|
||||
virBitmapNewCopy;
|
||||
|
@ -1093,9 +1093,7 @@ libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm)
|
||||
cpumask = def->cputune.vcpupin[vcpu]->cpumask;
|
||||
|
||||
for (i = 0; i < virBitmapSize(cpumask); ++i) {
|
||||
bool bit;
|
||||
ignore_value(virBitmapGetBit(cpumask, i, &bit));
|
||||
if (bit)
|
||||
if (virBitmapIsBitSet(cpumask, i))
|
||||
VIR_USE_CPU(cpumap, i);
|
||||
}
|
||||
|
||||
|
@ -2051,7 +2051,6 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,
|
||||
virBitmapPtr cpumask = NULL;
|
||||
int maxcpu, hostcpus, vcpu, pcpu, n, ret = -1;
|
||||
unsigned char *cpumap;
|
||||
bool pinned;
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||
@ -2100,9 +2099,7 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,
|
||||
cpumask = vcpupin_list[n]->cpumask;
|
||||
cpumap = VIR_GET_CPUMAP(cpumaps, maplen, vcpu);
|
||||
for (pcpu = 0; pcpu < maxcpu; pcpu++) {
|
||||
if (virBitmapGetBit(cpumask, pcpu, &pinned) < 0)
|
||||
goto cleanup;
|
||||
if (!pinned)
|
||||
if (!virBitmapIsBitSet(cpumask, pcpu))
|
||||
VIR_UNUSE_CPU(cpumap, pcpu);
|
||||
}
|
||||
}
|
||||
|
@ -1911,11 +1911,7 @@ nodeCapsInitNUMA(virCapsPtr caps)
|
||||
cpu = 0;
|
||||
|
||||
for (i = 0; i < virBitmapSize(cpumap); i++) {
|
||||
bool cpustate;
|
||||
if (virBitmapGetBit(cpumap, i, &cpustate) < 0)
|
||||
continue;
|
||||
|
||||
if (cpustate) {
|
||||
if (virBitmapIsBitSet(cpumap, i)) {
|
||||
if (virNodeCapsFillCPUInfo(i, cpus + cpu++) < 0) {
|
||||
topology_failed = true;
|
||||
virResetLastError();
|
||||
|
@ -2048,12 +2048,7 @@ bool
|
||||
virQEMUCapsGet(virQEMUCapsPtr qemuCaps,
|
||||
virQEMUCapsFlags flag)
|
||||
{
|
||||
bool b;
|
||||
|
||||
if (!qemuCaps || virBitmapGetBit(qemuCaps->flags, flag, &b) < 0)
|
||||
return false;
|
||||
else
|
||||
return b;
|
||||
return qemuCaps && virBitmapIsBitSet(qemuCaps->flags, flag);
|
||||
}
|
||||
|
||||
|
||||
|
@ -807,7 +807,6 @@ virStorageBackendCreateQemuImgOpts(char **opts,
|
||||
virBitmapPtr features)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
bool b;
|
||||
size_t i;
|
||||
|
||||
if (backingType)
|
||||
@ -823,8 +822,7 @@ virStorageBackendCreateQemuImgOpts(char **opts,
|
||||
virBufferAsprintf(&buf, "compat=%s,", compat);
|
||||
if (features && format == VIR_STORAGE_FILE_QCOW2) {
|
||||
for (i = 0; i < VIR_STORAGE_FILE_FEATURE_LAST; i++) {
|
||||
ignore_value(virBitmapGetBit(features, i, &b));
|
||||
if (b) {
|
||||
if (virBitmapIsBitSet(features, i)) {
|
||||
switch ((virStorageFileFeature) i) {
|
||||
case VIR_STORAGE_FILE_FEATURE_LAZY_REFCOUNTS:
|
||||
if (STREQ_NULLABLE(compat, "0.10")) {
|
||||
|
@ -178,6 +178,24 @@ static bool virBitmapIsSet(virBitmapPtr bitmap, size_t b)
|
||||
return !!(bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] & VIR_BITMAP_BIT(b));
|
||||
}
|
||||
|
||||
/**
|
||||
* virBitmapIsBitSet:
|
||||
* @bitmap: Pointer to bitmap
|
||||
* @b: bit position to get
|
||||
*
|
||||
* Get setting of bit position @b in @bitmap.
|
||||
*
|
||||
* If @b is in the range of @bitmap, returns the value of the bit.
|
||||
* Otherwise false is returned.
|
||||
*/
|
||||
bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b)
|
||||
{
|
||||
if (bitmap->max_bit <= b)
|
||||
return false;
|
||||
|
||||
return virBitmapIsSet(bitmap, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* virBitmapGetBit:
|
||||
* @bitmap: Pointer to bitmap
|
||||
|
@ -61,6 +61,11 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b)
|
||||
int virBitmapClearBit(virBitmapPtr bitmap, size_t b)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
||||
|
||||
/*
|
||||
* Get bit @b in @bitmap. Returns false if b is out of range.
|
||||
*/
|
||||
bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
||||
/*
|
||||
* Get setting of bit position @b in @bitmap and store in @result
|
||||
*/
|
||||
|
@ -3085,9 +3085,7 @@ virCgroupGetPercpuStats(virCgroupPtr group,
|
||||
need_cpus = MIN(total_cpus, start_cpu + ncpus);
|
||||
|
||||
for (i = 0; i < need_cpus; i++) {
|
||||
bool present;
|
||||
ignore_value(virBitmapGetBit(cpumap, i, &present));
|
||||
if (!present) {
|
||||
if (!virBitmapIsBitSet(cpumap, i)) {
|
||||
cpu_time = 0;
|
||||
} else if (virStrToLong_ull(pos, &pos, 10, &cpu_time) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
|
@ -874,10 +874,6 @@ dnsmasqCapsGetVersion(dnsmasqCapsPtr caps)
|
||||
bool
|
||||
dnsmasqCapsGet(dnsmasqCapsPtr caps, dnsmasqCapsFlags flag)
|
||||
{
|
||||
bool b;
|
||||
|
||||
if (!caps || virBitmapGetBit(caps->flags, flag, &b) < 0)
|
||||
return false;
|
||||
else
|
||||
return b;
|
||||
return caps && virBitmapIsBitSet(caps->flags, flag);
|
||||
}
|
||||
|
@ -184,14 +184,7 @@ int virPortAllocatorAcquire(virPortAllocatorPtr pa,
|
||||
for (i = pa->start; i <= pa->end && !*port; i++) {
|
||||
bool used = false, v6used = false;
|
||||
|
||||
if (virBitmapGetBit(pa->bitmap,
|
||||
i - pa->start, &used) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to query port %zu"), i);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (used)
|
||||
if (virBitmapIsBitSet(pa->bitmap, i - pa->start))
|
||||
continue;
|
||||
|
||||
if (!(pa->flags & VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)) {
|
||||
@ -269,12 +262,8 @@ int virPortAllocatorSetUsed(virPortAllocatorPtr pa,
|
||||
}
|
||||
|
||||
if (value) {
|
||||
bool used = false;
|
||||
if (virBitmapGetBit(pa->bitmap, port - pa->start, &used) < 0)
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to query port %d"), port);
|
||||
|
||||
if (used || virBitmapSetBit(pa->bitmap, port - pa->start) < 0) {
|
||||
if (virBitmapIsBitSet(pa->bitmap, port - pa->start) ||
|
||||
virBitmapSetBit(pa->bitmap, port - pa->start) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to reserve port %d"), port);
|
||||
goto cleanup;
|
||||
|
@ -407,7 +407,6 @@ virProcessKillPainfully(pid_t pid, bool force)
|
||||
int virProcessSetAffinity(pid_t pid, virBitmapPtr map)
|
||||
{
|
||||
size_t i;
|
||||
bool set = false;
|
||||
VIR_DEBUG("Set process affinity on %lld\n", (long long)pid);
|
||||
# ifdef CPU_ALLOC
|
||||
/* New method dynamically allocates cpu mask, allowing unlimted cpus */
|
||||
@ -433,9 +432,7 @@ int virProcessSetAffinity(pid_t pid, virBitmapPtr map)
|
||||
|
||||
CPU_ZERO_S(masklen, mask);
|
||||
for (i = 0; i < virBitmapSize(map); i++) {
|
||||
if (virBitmapGetBit(map, i, &set) < 0)
|
||||
return -1;
|
||||
if (set)
|
||||
if (virBitmapIsBitSet(map, i))
|
||||
CPU_SET_S(i, masklen, mask);
|
||||
}
|
||||
|
||||
@ -457,9 +454,7 @@ int virProcessSetAffinity(pid_t pid, virBitmapPtr map)
|
||||
|
||||
CPU_ZERO(&mask);
|
||||
for (i = 0; i < virBitmapSize(map); i++) {
|
||||
if (virBitmapGetBit(map, i, &set) < 0)
|
||||
return -1;
|
||||
if (set)
|
||||
if (virBitmapIsBitSet(map, i))
|
||||
CPU_SET(i, &mask);
|
||||
}
|
||||
|
||||
|
@ -232,9 +232,7 @@ xenDomainUsedCpus(virDomainPtr dom, virDomainDefPtr def)
|
||||
cpumap, cpumaplen)) >= 0) {
|
||||
for (n = 0; n < ncpus; n++) {
|
||||
for (m = 0; m < priv->nbNodeCpus; m++) {
|
||||
bool used;
|
||||
ignore_value(virBitmapGetBit(cpulist, m, &used));
|
||||
if ((!used) &&
|
||||
if (!virBitmapIsBitSet(cpulist, m) &&
|
||||
(VIR_CPU_USABLE(cpumap, cpumaplen, n, m))) {
|
||||
ignore_value(virBitmapSetBit(cpulist, m));
|
||||
nb++;
|
||||
|
@ -1089,10 +1089,7 @@ sexpr_to_xend_topology(const struct sexpr *root, virCapsPtr caps)
|
||||
}
|
||||
|
||||
for (n = 0, cpu = 0; cpu < numCpus; cpu++) {
|
||||
bool used;
|
||||
|
||||
ignore_value(virBitmapGetBit(cpuset, cpu, &used));
|
||||
if (used)
|
||||
if (virBitmapIsBitSet(cpuset, cpu))
|
||||
cpuInfo[n++].id = cpu;
|
||||
}
|
||||
virBitmapFree(cpuset);
|
||||
|
Loading…
Reference in New Issue
Block a user