);
+virCPUDefPtr virCPUDefNew(void)
+{
+ virCPUDefPtr cpu = g_new0(virCPUDef, 1);
+ cpu->refs = 1;
+ return cpu;
+}
+
void
virCPUDefFreeFeatures(virCPUDefPtr def)
{
virCPUDefFreeFeatures(def);
}
+void
+virCPUDefRef(virCPUDefPtr def)
+{
+ g_atomic_int_inc(&def->refs);
+}
+
void
virCPUDefFree(virCPUDefPtr def)
{
if (!def)
return;
- virCPUDefFreeModel(def);
- VIR_FREE(def->cache);
- VIR_FREE(def->tsc);
- VIR_FREE(def);
+ if (g_atomic_int_dec_and_test(&def->refs)) {
+ virCPUDefFreeModel(def);
+ VIR_FREE(def->cache);
+ VIR_FREE(def->tsc);
+ VIR_FREE(def);
+ }
}
{
virCPUDefPtr copy;
- if (!cpu || VIR_ALLOC(copy) < 0)
+ if (!cpu)
return NULL;
+ copy = virCPUDefNew();
copy->type = cpu->type;
copy->mode = cpu->mode;
copy->match = cpu->match;
goto cleanup;
}
- if (VIR_ALLOC(def) < 0)
- goto cleanup;
+ def = virCPUDefNew();
if (type == VIR_CPU_TYPE_AUTO) {
if (virXPathBoolean("boolean(./arch)", ctxt)) {
typedef struct _virCPUDef virCPUDef;
typedef virCPUDef *virCPUDefPtr;
struct _virCPUDef {
+ int refs;
int type; /* enum virCPUType */
int mode; /* enum virCPUMode */
int match; /* enum virCPUMatch */
virHostCPUTscInfoPtr tsc;
};
+virCPUDefPtr virCPUDefNew(void);
void ATTRIBUTE_NONNULL(1)
virCPUDefFreeFeatures(virCPUDefPtr def);
void ATTRIBUTE_NONNULL(1)
virCPUDefFreeModel(virCPUDefPtr def);
+void
+virCPUDefRef(virCPUDefPtr def);
void
virCPUDefFree(virCPUDefPtr def);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUDef, virCPUDefFree);
if (!(driver = cpuGetSubDriver(arch)))
return NULL;
- if (VIR_ALLOC(cpu) < 0)
- return NULL;
+ cpu = virCPUDefNew();
switch (type) {
case VIR_CPU_TYPE_HOST:
{
virCPUDefPtr cpu = NULL;
- if (VIR_ALLOC(cpu) < 0) {
- virCPUDefFree(cpu);
- return NULL;
- }
+ cpu = virCPUDefNew();
cpu->model = g_strdup(cpus[0]->model);
}
}
- if (VIR_ALLOC(cpu) < 0)
- goto error;
+ cpu = virCPUDefNew();
cpu->model = g_strdup(model->name);
virCPUx86Data modelData = VIR_CPU_X86_DATA_INIT;
virCPUx86VendorPtr vendor;
- if (VIR_ALLOC(cpu) < 0)
- goto error;
+ cpu = virCPUDefNew();
cpu->model = g_strdup(model->name);
if (!(base_model = x86ModelFromCPU(cpus[0], map, -1)))
goto error;
- if (VIR_ALLOC(cpu) < 0)
- goto error;
+ cpu = virCPUDefNew();
cpu->type = VIR_CPU_TYPE_GUEST;
cpu->match = VIR_CPU_MATCH_EXACT;
virCPUDefIsEqual;
virCPUDefListFree;
virCPUDefListParse;
+virCPUDefNew;
virCPUDefParseXML;
virCPUDefParseXMLString;
+virCPUDefRef;
virCPUDefStealModel;
virCPUDefUpdateFeature;
virCPUModeTypeToString;
if (!phy_info->hw_cap[0])
return 0;
- if (VIR_ALLOC(cpu) < 0)
- goto error;
+ cpu = virCPUDefNew();
host_pae = phy_info->hw_cap[0] & LIBXL_X86_FEATURE_PAE_MASK;
if (host_pae &&
}
if (!def->cpu) {
- virCPUDefPtr cpu;
- if (VIR_ALLOC(cpu) < 0)
- return -1;
-
+ virCPUDefPtr cpu = virCPUDefNew();
cpu->mode = VIR_CPU_MODE_HOST_PASSTHROUGH;
cpu->type = VIR_CPU_TYPE_GUEST;
cpu->nfeatures = 0;
return 0;
if (!def->cpu) {
- if (VIR_ALLOC(def->cpu) < 0)
- goto cleanup;
+ def->cpu = virCPUDefNew();
def->cpu->mode = VIR_CPU_MODE_HOST_PASSTHROUGH;
def->cpu->type = VIR_CPU_TYPE_GUEST;
def->cpu->nfeatures = 0;
if (!virDomainNumaSetNodeCount(numa, nr_nodes))
goto cleanup;
- if (VIR_ALLOC(cpu) < 0)
- goto cleanup;
+ cpu = virCPUDefNew();
list = list->list;
while (list) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
return 0;
- if (VIR_ALLOC(cpu) < 0)
- goto cleanup;
+ cpu = virCPUDefNew();
cpu->model = g_strdup(model);
static virCPUDefPtr
virQEMUCapsNewHostCPUModel(void)
{
- virCPUDefPtr cpu;
-
- if (VIR_ALLOC(cpu) < 0)
- return NULL;
+ virCPUDefPtr cpu = virCPUDefNew();
cpu->type = VIR_CPU_TYPE_GUEST;
cpu->mode = VIR_CPU_MODE_CUSTOM;
}
if (!def->cpu)
- def->cpu = g_new0(virCPUDef, 1);
+ def->cpu = virCPUDefNew();
def->cpu->type = VIR_CPU_TYPE_GUEST;
goto cleanup;
if (coresPerSocket > 1) {
- if (VIR_ALLOC(cpu) < 0)
- goto cleanup;
+ cpu = virCPUDefNew();
cpu->type = VIR_CPU_TYPE_GUEST;
cpu->mode = VIR_CPU_MODE_CUSTOM;
if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
goto error;
- if (VIR_ALLOC(cpu) < 0)
- goto cleanup;
+ cpu = virCPUDefNew();
cpu->model = g_strdup("host");
!(hostData = virCPUDataParse(host)))
goto cleanup;
- if (VIR_ALLOC(cpu) < 0)
- goto cleanup;
-
+ cpu = virCPUDefNew();
cpu->arch = hostData->arch;
if (guest) {
cpu->type = VIR_CPU_TYPE_GUEST;
if (!(qemuCaps = cpuTestMakeQEMUCaps(data)))
goto cleanup;
- if (VIR_ALLOC(cpu) < 0)
- goto cleanup;
-
+ cpu = virCPUDefNew();
cpu->arch = data->arch;
cpu->type = VIR_CPU_TYPE_GUEST;
cpu->match = VIR_CPU_MATCH_EXACT;