mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
virBitmapFormat: Don't check return value
'virBitmapFormat' always returns a string; remove pointless checks. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
a44a48b681
commit
3518f46cba
@ -2083,8 +2083,7 @@ chDomainSetNumaParamsLive(virDomainObj *vm,
|
||||
return -1;
|
||||
|
||||
/* Ensure the cpuset string is formatted before passing to cgroup */
|
||||
if (!(nodeset_str = virBitmapFormat(nodeset)))
|
||||
return -1;
|
||||
nodeset_str = virBitmapFormat(nodeset);
|
||||
|
||||
if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0,
|
||||
false, &cgroup_temp) < 0 ||
|
||||
|
@ -816,8 +816,7 @@ virCapsHostNUMACellCPUFormat(virBuffer *buf,
|
||||
if (cpus[j].siblings) {
|
||||
g_autofree char *siblings = NULL;
|
||||
|
||||
if (!(siblings = virBitmapFormat(cpus[j].siblings)))
|
||||
return -1;
|
||||
siblings = virBitmapFormat(cpus[j].siblings);
|
||||
|
||||
virBufferAsprintf(&childBuf,
|
||||
" socket_id='%d' die_id='%d' cluster_id='%d' core_id='%d' siblings='%s'",
|
||||
@ -954,9 +953,6 @@ virCapabilitiesFormatCaches(virBuffer *buf,
|
||||
const char *unit = NULL;
|
||||
unsigned long long short_size = virFormatIntPretty(bank->size, &unit);
|
||||
|
||||
if (!cpus_str)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* Let's just *hope* the size is aligned to KiBs so that it does not
|
||||
* bite is back in the future
|
||||
@ -1038,9 +1034,6 @@ virCapabilitiesFormatMemoryBandwidth(virBuffer *buf,
|
||||
virResctrlInfoMemBWPerNode *control = &node->control;
|
||||
g_autofree char *cpus_str = virBitmapFormat(node->cpus);
|
||||
|
||||
if (!cpus_str)
|
||||
return -1;
|
||||
|
||||
virBufferAsprintf(&attrBuf,
|
||||
" id='%u' cpus='%s'",
|
||||
node->id, cpus_str);
|
||||
|
@ -18223,8 +18223,6 @@ virDomainResctrlNew(xmlNodePtr node,
|
||||
/* We need to format it back because we need to be consistent in the naming
|
||||
* even when users specify some "sub-optimal" string there. */
|
||||
vcpus_str = virBitmapFormat(vcpus);
|
||||
if (!vcpus_str)
|
||||
return NULL;
|
||||
|
||||
if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
|
||||
alloc_id = virXMLPropString(node, "id");
|
||||
@ -25881,8 +25879,7 @@ virDomainMemorySourceDefFormat(virBuffer *buf,
|
||||
switch (def->model) {
|
||||
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
|
||||
if (def->source.dimm.nodes) {
|
||||
if (!(bitmap = virBitmapFormat(def->source.dimm.nodes)))
|
||||
return -1;
|
||||
bitmap = virBitmapFormat(def->source.dimm.nodes);
|
||||
|
||||
virBufferAsprintf(&childBuf, "<nodemask>%s</nodemask>\n", bitmap);
|
||||
}
|
||||
@ -25893,8 +25890,7 @@ virDomainMemorySourceDefFormat(virBuffer *buf,
|
||||
break;
|
||||
case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
|
||||
if (def->source.virtio_mem.nodes) {
|
||||
if (!(bitmap = virBitmapFormat(def->source.virtio_mem.nodes)))
|
||||
return -1;
|
||||
bitmap = virBitmapFormat(def->source.virtio_mem.nodes);
|
||||
|
||||
virBufferAsprintf(&childBuf, "<nodemask>%s</nodemask>\n", bitmap);
|
||||
}
|
||||
@ -25921,8 +25917,7 @@ virDomainMemorySourceDefFormat(virBuffer *buf,
|
||||
|
||||
case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
|
||||
if (def->source.sgx_epc.nodes) {
|
||||
if (!(bitmap = virBitmapFormat(def->source.sgx_epc.nodes)))
|
||||
return -1;
|
||||
bitmap = virBitmapFormat(def->source.sgx_epc.nodes);
|
||||
|
||||
virBufferAsprintf(&childBuf, "<nodemask>%s</nodemask>\n", bitmap);
|
||||
}
|
||||
@ -26992,9 +26987,8 @@ virDomainHugepagesFormatBuf(virBuffer *buf,
|
||||
hugepage->size);
|
||||
|
||||
if (hugepage->nodemask) {
|
||||
g_autofree char *nodeset = NULL;
|
||||
if (!(nodeset = virBitmapFormat(hugepage->nodemask)))
|
||||
return -1;
|
||||
g_autofree char *nodeset = virBitmapFormat(hugepage->nodemask);
|
||||
|
||||
virBufferAsprintf(buf, " nodeset='%s'", nodeset);
|
||||
}
|
||||
|
||||
@ -27321,8 +27315,6 @@ virDomainResctrlMonDefFormatHelper(virDomainResctrlMonDef *domresmon,
|
||||
}
|
||||
|
||||
vcpus = virBitmapFormat(domresmon->vcpus);
|
||||
if (!vcpus)
|
||||
return -1;
|
||||
|
||||
virBufferAsprintf(buf, "vcpus='%s'/>\n", vcpus);
|
||||
|
||||
@ -27356,8 +27348,6 @@ virDomainCachetuneDefFormat(virBuffer *buf,
|
||||
return 0;
|
||||
|
||||
vcpus = virBitmapFormat(resctrl->vcpus);
|
||||
if (!vcpus)
|
||||
return -1;
|
||||
|
||||
virBufferAsprintf(&attrBuf, " vcpus='%s'", vcpus);
|
||||
|
||||
@ -27415,8 +27405,6 @@ virDomainMemorytuneDefFormat(virBuffer *buf,
|
||||
return 0;
|
||||
|
||||
vcpus = virBitmapFormat(resctrl->vcpus);
|
||||
if (!vcpus)
|
||||
return -1;
|
||||
|
||||
virBufferAsprintf(&attrBuf, " vcpus='%s'", vcpus);
|
||||
|
||||
@ -27545,15 +27533,14 @@ virDomainCpuDefFormat(virBuffer *buf,
|
||||
{
|
||||
virDomainVcpuDef *vcpu;
|
||||
size_t i;
|
||||
g_autofree char *cpumask = NULL;
|
||||
|
||||
virBufferAddLit(buf, "<vcpu");
|
||||
virBufferAsprintf(buf, " placement='%s'",
|
||||
virDomainCpuPlacementModeTypeToString(def->placement_mode));
|
||||
|
||||
if (def->cpumask && !virBitmapIsAllSet(def->cpumask)) {
|
||||
if ((cpumask = virBitmapFormat(def->cpumask)) == NULL)
|
||||
return -1;
|
||||
g_autofree char *cpumask = virBitmapFormat(def->cpumask);
|
||||
|
||||
virBufferAsprintf(buf, " cpuset='%s'", cpumask);
|
||||
}
|
||||
if (virDomainDefHasVcpusOffline(def))
|
||||
|
@ -273,7 +273,6 @@ virDomainNumatuneFormatXML(virBuffer *buf,
|
||||
virDomainNuma *numatune)
|
||||
{
|
||||
const char *tmp = NULL;
|
||||
char *nodeset = NULL;
|
||||
bool nodesetSpecified = false;
|
||||
size_t i = 0;
|
||||
|
||||
@ -298,10 +297,9 @@ virDomainNumatuneFormatXML(virBuffer *buf,
|
||||
virBufferAsprintf(buf, "<memory mode='%s' ", tmp);
|
||||
|
||||
if (numatune->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC) {
|
||||
if (!(nodeset = virBitmapFormat(numatune->memory.nodeset)))
|
||||
return -1;
|
||||
g_autofree char *nodeset = virBitmapFormat(numatune->memory.nodeset);
|
||||
|
||||
virBufferAsprintf(buf, "nodeset='%s'/>\n", nodeset);
|
||||
VIR_FREE(nodeset);
|
||||
} else if (numatune->memory.placement) {
|
||||
tmp = virDomainNumatunePlacementTypeToString(numatune->memory.placement);
|
||||
virBufferAsprintf(buf, "placement='%s'/>\n", tmp);
|
||||
@ -310,19 +308,18 @@ virDomainNumatuneFormatXML(virBuffer *buf,
|
||||
|
||||
for (i = 0; i < numatune->nmem_nodes; i++) {
|
||||
virDomainNumaNode *mem_node = &numatune->mem_nodes[i];
|
||||
g_autofree char *nodeset = NULL;
|
||||
|
||||
if (!mem_node->nodeset)
|
||||
continue;
|
||||
|
||||
if (!(nodeset = virBitmapFormat(mem_node->nodeset)))
|
||||
return -1;
|
||||
nodeset = virBitmapFormat(mem_node->nodeset);
|
||||
|
||||
virBufferAsprintf(buf,
|
||||
"<memnode cellid='%zu' mode='%s' nodeset='%s'/>\n",
|
||||
i,
|
||||
virDomainNumatuneMemModeTypeToString(mem_node->mode),
|
||||
nodeset);
|
||||
VIR_FREE(nodeset);
|
||||
}
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
@ -461,9 +458,8 @@ virDomainNumatuneMaybeFormatNodeset(virDomainNuma *numatune,
|
||||
cellid) < 0)
|
||||
return -1;
|
||||
|
||||
if (nodeset &&
|
||||
!(*mask = virBitmapFormat(nodeset)))
|
||||
return -1;
|
||||
if (nodeset)
|
||||
*mask = virBitmapFormat(nodeset);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1010,8 +1006,6 @@ virDomainNumaDefFormatXML(virBuffer *buf,
|
||||
if (cpumask) {
|
||||
g_autofree char *cpustr = virBitmapFormat(cpumask);
|
||||
|
||||
if (!cpustr)
|
||||
return -1;
|
||||
virBufferAsprintf(&attrBuf, " cpus='%s'", cpustr);
|
||||
}
|
||||
virBufferAsprintf(&attrBuf, " memory='%llu'",
|
||||
|
@ -799,9 +799,6 @@ virNetworkObjFormat(virNetworkObj *obj,
|
||||
char *classIdStr = virBitmapFormat(obj->classIdMap);
|
||||
size_t i;
|
||||
|
||||
if (!classIdStr)
|
||||
return NULL;
|
||||
|
||||
virBufferAddLit(&buf, "<networkstatus>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
virBufferAsprintf(&buf, "<class_id bitmap='%s'/>\n", classIdStr);
|
||||
|
@ -410,8 +410,7 @@ virDomainCgroupRestoreCgroupState(virDomainObj *vm,
|
||||
if (!(all_nodes = virNumaGetHostMemoryNodeset()))
|
||||
goto error;
|
||||
|
||||
if (!(mem_mask = virBitmapFormat(all_nodes)))
|
||||
goto error;
|
||||
mem_mask = virBitmapFormat(all_nodes);
|
||||
|
||||
if (virCgroupHasEmptyTasks(cgroup, VIR_CGROUP_CONTROLLER_CPUSET) <= 0)
|
||||
goto error;
|
||||
@ -648,8 +647,7 @@ virDomainCgroupEmulatorAllNodesAllow(virCgroup *cgroup,
|
||||
if (!(all_nodes = virNumaGetHostMemoryNodeset()))
|
||||
goto cleanup;
|
||||
|
||||
if (!(all_nodes_str = virBitmapFormat(all_nodes)))
|
||||
goto cleanup;
|
||||
all_nodes_str = virBitmapFormat(all_nodes);
|
||||
|
||||
data = g_new0(virCgroupEmulatorAllNodesData, 1);
|
||||
|
||||
|
@ -5051,8 +5051,7 @@ libxlDomainGetNumaParameters(virDomainPtr dom,
|
||||
}
|
||||
}
|
||||
|
||||
if (!(nodeset = virBitmapFormat(nodes)))
|
||||
goto cleanup;
|
||||
nodeset = virBitmapFormat(nodes);
|
||||
|
||||
if (virTypedParameterAssign(param, VIR_DOMAIN_NUMA_NODESET,
|
||||
VIR_TYPED_PARAM_STRING, nodeset) < 0)
|
||||
|
@ -2030,10 +2030,8 @@ xenFormatCPUAllocation(virConf *conf, virDomainDef *def)
|
||||
if (xenConfigSetInt(conf, "vcpus", virDomainDefGetVcpus(def)) < 0)
|
||||
return -1;
|
||||
|
||||
if ((def->cpumask != NULL) &&
|
||||
((cpus = virBitmapFormat(def->cpumask)) == NULL)) {
|
||||
return -1;
|
||||
}
|
||||
if (def->cpumask != NULL)
|
||||
cpus = virBitmapFormat(def->cpumask);
|
||||
|
||||
if (cpus &&
|
||||
xenConfigSetString(conf, "cpus", cpus) < 0)
|
||||
|
@ -7498,8 +7498,7 @@ qemuBuildNumaCPUs(virBuffer *buf,
|
||||
if (!cpu)
|
||||
return 0;
|
||||
|
||||
if (!(cpumask = virBitmapFormat(cpu)))
|
||||
return -1;
|
||||
cpumask = virBitmapFormat(cpu);
|
||||
|
||||
for (tmpmask = cpumask; tmpmask; tmpmask = next) {
|
||||
if ((next = strchr(tmpmask, ',')))
|
||||
|
@ -2306,13 +2306,11 @@ qemuDomainObjPrivateXMLFormatAutomaticPlacement(virBuffer *buf,
|
||||
if (!priv->autoNodeset && !priv->autoCpuset)
|
||||
return 0;
|
||||
|
||||
if (priv->autoNodeset &&
|
||||
!((nodeset = virBitmapFormat(priv->autoNodeset))))
|
||||
return -1;
|
||||
if (priv->autoNodeset)
|
||||
nodeset = virBitmapFormat(priv->autoNodeset);
|
||||
|
||||
if (priv->autoCpuset &&
|
||||
!((cpuset = virBitmapFormat(priv->autoCpuset))))
|
||||
return -1;
|
||||
if (priv->autoCpuset)
|
||||
cpuset = virBitmapFormat(priv->autoCpuset);
|
||||
|
||||
virBufferAddLit(buf, "<numad");
|
||||
virBufferEscapeString(buf, " nodeset='%s'", nodeset);
|
||||
|
@ -4300,9 +4300,7 @@ qemuDomainPinVcpuLive(virDomainObj *vm,
|
||||
}
|
||||
|
||||
tmpmap = virBitmapNewCopy(cpumap);
|
||||
|
||||
if (!(str = virBitmapFormat(cpumap)))
|
||||
goto cleanup;
|
||||
str = virBitmapFormat(cpumap);
|
||||
|
||||
if (vcpuinfo->online) {
|
||||
/* Configure the corresponding cpuset cgroup before set affinity. */
|
||||
@ -8233,9 +8231,7 @@ qemuDomainSetNumaParamsLive(virDomainObj *vm,
|
||||
if (!virNumaNodesetIsAvailable(nodeset))
|
||||
return -1;
|
||||
|
||||
/* Ensure the cpuset string is formatted before passing to cgroup */
|
||||
if (!(nodeset_str = virBitmapFormat(nodeset)))
|
||||
return -1;
|
||||
nodeset_str = virBitmapFormat(nodeset);
|
||||
|
||||
if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0,
|
||||
false, &cgroup_thread) < 0 ||
|
||||
@ -16682,9 +16678,7 @@ qemuDomainGetResctrlMonData(virQEMUDriver *driver,
|
||||
* res.vcpus is assigned with an memory space holding it,
|
||||
* let this newly allocated memory buffer to be freed along with
|
||||
* the free of 'res' */
|
||||
if (!(res->vcpus = virBitmapFormat(domresmon->vcpus)))
|
||||
goto error;
|
||||
|
||||
res->vcpus = virBitmapFormat(domresmon->vcpus);
|
||||
res->name = g_strdup(virResctrlMonitorGetID(monitor));
|
||||
|
||||
if (virResctrlMonitorGetStats(monitor, (const char **)features,
|
||||
@ -18451,9 +18445,7 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params,
|
||||
|
||||
#define ADD_BITMAP(name) \
|
||||
do { \
|
||||
g_autofree char *tmp = NULL; \
|
||||
if (!(tmp = virBitmapFormat(name))) \
|
||||
goto cleanup; \
|
||||
g_autofree char *tmp = virBitmapFormat(name); \
|
||||
if (virTypedParamsAddString(&par, &npar, &maxpar, #name, tmp) < 0) \
|
||||
goto cleanup; \
|
||||
} while (0)
|
||||
@ -18583,10 +18575,9 @@ qemuDomainSetGuestVcpus(virDomainPtr dom,
|
||||
}
|
||||
|
||||
if (!virBitmapIsAllClear(map)) {
|
||||
char *tmp = virBitmapFormat(map);
|
||||
g_autofree char *tmp = virBitmapFormat(map);
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("guest is missing vCPUs '%1$s'"), NULLSTR(tmp));
|
||||
VIR_FREE(tmp);
|
||||
_("guest is missing vCPUs '%1$s'"), tmp);
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
|
@ -3946,10 +3946,7 @@ virCgroupSetupBlkioDeviceWriteBps(virCgroup *cgroup, const char *path,
|
||||
int
|
||||
virCgroupSetupCpusetCpus(virCgroup *cgroup, virBitmap *cpumask)
|
||||
{
|
||||
g_autofree char *new_cpus = NULL;
|
||||
|
||||
if (!(new_cpus = virBitmapFormat(cpumask)))
|
||||
return -1;
|
||||
g_autofree char *new_cpus = virBitmapFormat(cpumask);
|
||||
|
||||
if (virCgroupSetCpusetCpus(cgroup, new_cpus) < 0)
|
||||
return -1;
|
||||
|
@ -3903,8 +3903,7 @@ prlsdkDoApplyConfig(struct _vzDriver *driver,
|
||||
pret = PrlVmCfg_SetCpuCount(sdkdom, virDomainDefGetVcpus(def));
|
||||
prlsdkCheckRetGoto(pret, error);
|
||||
|
||||
if (!(mask = virBitmapFormat(def->cpumask)))
|
||||
goto error;
|
||||
mask = virBitmapFormat(def->cpumask);
|
||||
|
||||
pret = PrlVmCfg_SetCpuMask(sdkdom, mask);
|
||||
prlsdkCheckRetGoto(pret, error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user