virDomainControllerDefPtr cont;
size_t nbitmaps = 0;
int ret = -1;
- bool b;
size_t i;
memset(max_idx, -1, sizeof(max_idx));
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),
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));
}
virBitmapPtr map = NULL;
size_t i;
int ndisks;
- bool inuse;
if (!def->dom) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
goto cleanup;
}
- if (virBitmapGetBit(map, idx, &inuse) < 0 || inuse) {
+ if (virBitmapIsBitSet(map, idx)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk '%s' specified twice"),
disk->name);
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)
if (options->featureToString && def->features) {
size_t i;
- bool b;
bool empty = virBitmapIsAllClear(def->features);
if (empty) {
}
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));
}
virBitmapGetBit;
virBitmapIsAllClear;
virBitmapIsAllSet;
+virBitmapIsBitSet;
virBitmapLastSetBit;
virBitmapNew;
virBitmapNewCopy;
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);
}
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);
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);
}
}
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();
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);
}
virBitmapPtr features)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
- bool b;
size_t i;
if (backingType)
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")) {
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
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
*/
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",
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);
}
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)) {
}
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;
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 */
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);
}
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);
}
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++;
}
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);