}
+/**
+ * virDomainDefGetVcpuPinInfoHelper:
+ * @def: domain definition
+ * @maplen: length of one cpumap passed from caller (@cpumaps)
+ * @ncpumaps: count of cpumaps of @maplen length in @cpumaps
+ * @cpumaps: array of pinning information bitmaps to be filled
+ * @hostcpus: number of cpus in the host
+ * @autoCpuset: Cpu pinning bitmap used in case of automatic cpu pinning
+ *
+ * Fills the @cpumaps array as documented by the virDomainGetVcpuPinInfo API.
+ * In case when automatic cpu pinning is supported, the bitmap should be passed
+ * as @autoCpuset. If @hostcpus is < 0 no error is reported (to pass through
+ * error message).
+ *
+ * Returns number of filled entries or -1 on error.
+ */
+int
+virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
+ int maplen,
+ int ncpumaps,
+ unsigned char *cpumaps,
+ int hostcpus,
+ virBitmapPtr autoCpuset)
+{
+ virBitmapPtr allcpumap = NULL;
+ size_t i;
+
+ if (hostcpus < 0)
+ return -1;
+
+ if (!(allcpumap = virBitmapNew(hostcpus)))
+ return -1;
+
+ virBitmapSetAll(allcpumap);
+
+ /* Clamp to actual number of vcpus */
+ if (ncpumaps > virDomainDefGetVcpus(def))
+ ncpumaps = virDomainDefGetVcpus(def);
+
+ for (i = 0; i < ncpumaps; i++) {
+ virDomainVcpuInfoPtr vcpu = virDomainDefGetVcpu(def, i);
+ virBitmapPtr bitmap = NULL;
+
+ if (!vcpu->online)
+ continue;
+
+ if (vcpu->cpumask)
+ bitmap = vcpu->cpumask;
+ else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO &&
+ autoCpuset)
+ bitmap = autoCpuset;
+ else if (def->cpumask)
+ bitmap = def->cpumask;
+ else
+ bitmap = allcpumap;
+
+ virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen);
+ }
+
+ virBitmapFree(allcpumap);
+ return ncpumaps;
+}
+
+
virDomainDiskDefPtr
virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
{
int virDomainDefCheckDuplicateDiskInfo(virDomainDefPtr def)
ATTRIBUTE_NONNULL(1);
+int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
+ int maplen,
+ int ncpumaps,
+ unsigned char *cpumaps,
+ int hostcpus,
+ virBitmapPtr autoCpuset)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
+
#endif /* __DOMAIN_CONF_H */
virDomainDefGetOnlineVcpumap;
virDomainDefGetSecurityLabelDef;
virDomainDefGetVcpu;
+virDomainDefGetVcpuPinInfoHelper;
virDomainDefGetVcpus;
virDomainDefGetVcpusMax;
virDomainDefHasDeviceAddress;
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainObjPtr vm = NULL;
virDomainDefPtr targetDef = NULL;
- int hostcpus, vcpu, ret = -1;
- virBitmapPtr allcpumap = NULL;
+ int ret = -1;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
/* Make sure coverity knows targetDef is valid at this point. */
sa_assert(targetDef);
- /* Clamp to actual number of vcpus */
- if (ncpumaps > virDomainDefGetVcpus(targetDef))
- ncpumaps = virDomainDefGetVcpus(targetDef);
-
- if ((hostcpus = libxl_get_max_cpus(cfg->ctx)) < 0)
- goto cleanup;
-
- if (!(allcpumap = virBitmapNew(hostcpus)))
- goto cleanup;
-
- virBitmapSetAll(allcpumap);
-
- memset(cpumaps, 0x00, maplen * ncpumaps);
-
- for (vcpu = 0; vcpu < ncpumaps; vcpu++) {
- virDomainVcpuInfoPtr vcpuinfo = virDomainDefGetVcpu(targetDef, vcpu);
- virBitmapPtr bitmap = NULL;
-
- if (!vcpuinfo->online)
- continue;
-
- if (vcpuinfo->cpumask)
- bitmap = vcpuinfo->cpumask;
- else if (targetDef->cpumask)
- bitmap = targetDef->cpumask;
- else
- bitmap = allcpumap;
-
- virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, vcpu), maplen);
- }
-
- ret = ncpumaps;
+ ret = virDomainDefGetVcpuPinInfoHelper(targetDef, maplen, ncpumaps, cpumaps,
+ libxl_get_max_cpus(cfg->ctx), NULL);
cleanup:
- virBitmapFree(allcpumap);
if (vm)
virObjectUnlock(vm);
virObjectUnref(cfg);
virDomainObjPtr vm = NULL;
virDomainDefPtr def;
int ret = -1;
- int hostcpus;
- size_t i;
- virBitmapPtr allcpumap = NULL;
qemuDomainObjPrivatePtr priv = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
if (!(def = virDomainObjGetOneDef(vm, flags)))
goto cleanup;
- if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
- goto cleanup;
-
- if (!(allcpumap = virBitmapNew(hostcpus)))
- goto cleanup;
-
- virBitmapSetAll(allcpumap);
priv = vm->privateData;
- /* Clamp to actual number of vcpus */
- if (ncpumaps > virDomainDefGetVcpus(def))
- ncpumaps = virDomainDefGetVcpus(def);
-
- if (ncpumaps < 1)
- goto cleanup;
-
- for (i = 0; i < ncpumaps; i++) {
- virDomainVcpuInfoPtr vcpu = virDomainDefGetVcpu(def, i);
- virBitmapPtr bitmap = NULL;
-
- if (!vcpu->online)
- continue;
-
- if (vcpu->cpumask)
- bitmap = vcpu->cpumask;
- else if (vm->def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO &&
- priv->autoCpuset)
- bitmap = priv->autoCpuset;
- else if (def->cpumask)
- bitmap = def->cpumask;
- else
- bitmap = allcpumap;
-
- virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen);
- }
-
- ret = ncpumaps;
-
+ ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
+ nodeGetCPUCount(NULL),
+ priv->autoCpuset);
cleanup:
- virBitmapFree(allcpumap);
virDomainObjEndAPI(&vm);
return ret;
}
int maplen,
unsigned int flags)
{
- testDriverPtr privconn = dom->conn->privateData;
+ testDriverPtr driver = dom->conn->privateData;
virDomainObjPtr privdom;
virDomainDefPtr def;
- int ret = -1, hostcpus, vcpu;
- virBitmapPtr allcpumap = NULL;
+ int ret = -1;
if (!(privdom = testDomObjFromDomain(dom)))
return -1;
if (!(def = virDomainObjGetOneDef(privdom, flags)))
goto cleanup;
- hostcpus = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo);
-
- if (!(allcpumap = virBitmapNew(hostcpus)))
- goto cleanup;
-
- virBitmapSetAll(allcpumap);
-
- /* Clamp to actual number of vcpus */
- if (ncpumaps > virDomainDefGetVcpus(def))
- ncpumaps = virDomainDefGetVcpus(def);
-
- for (vcpu = 0; vcpu < ncpumaps; vcpu++) {
- virDomainVcpuInfoPtr vcpuinfo = virDomainDefGetVcpu(def, vcpu);
- virBitmapPtr bitmap = NULL;
-
- if (!vcpuinfo->online)
- continue;
-
- if (vcpuinfo->cpumask)
- bitmap = vcpuinfo->cpumask;
- else if (def->cpumask)
- bitmap = def->cpumask;
- else
- bitmap = allcpumap;
-
- virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, vcpu), maplen);
- }
-
- ret = ncpumaps;
+ ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
+ VIR_NODEINFO_MAXCPUS(driver->nodeInfo),
+ NULL);
cleanup:
- virBitmapFree(allcpumap);
virDomainObjEndAPI(&privdom);
return ret;
}