virCPUDefPtr virCPUDefCopy(const virCPUDefPtr cpu) { virCPUDefPtr copy; unsigned int i; if (!cpu) return NULL; if (VIR_ALLOC(copy) < 0) goto no_memory; copy->type = cpu->type; copy->mode = cpu->mode; copy->match = cpu->match; copy->fallback = cpu->fallback; copy->sockets = cpu->sockets; copy->cores = cpu->cores; copy->threads = cpu->threads; if (cpu->arch && !(copy->arch = strdup(cpu->arch))) goto no_memory; if (virCPUDefCopyModel(copy, cpu, false) < 0) goto error; if (cpu->ncells) { if (VIR_ALLOC_N(copy->cells, cpu->ncells) < 0) goto no_memory; copy->ncells_max = copy->ncells = cpu->ncells; for (i = 0; i < cpu->ncells; i++) { copy->cells[i].cellid = cpu->cells[i].cellid; copy->cells[i].mem = cpu->cells[i].mem; if (VIR_ALLOC_N(copy->cells[i].cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) goto no_memory; memcpy(copy->cells[i].cpumask, cpu->cells[i].cpumask, VIR_DOMAIN_CPUMASK_LEN); if (!(copy->cells[i].cpustr = strdup(cpu->cells[i].cpustr))) goto no_memory; } copy->cells_cpus = cpu->cells_cpus; } return copy; no_memory: virReportOOMError(); error: virCPUDefFree(copy); return NULL; }
virCPUDefPtr virCPUDefCopy(const virCPUDef *cpu) { virCPUDefPtr copy; size_t i; if (!cpu || VIR_ALLOC(copy) < 0) return NULL; copy->type = cpu->type; copy->mode = cpu->mode; copy->match = cpu->match; copy->fallback = cpu->fallback; copy->sockets = cpu->sockets; copy->cores = cpu->cores; copy->threads = cpu->threads; copy->arch = cpu->arch; if (virCPUDefCopyModel(copy, cpu, false) < 0) goto error; if (cpu->ncells) { if (VIR_ALLOC_N(copy->cells, cpu->ncells) < 0) goto error; copy->ncells_max = copy->ncells = cpu->ncells; for (i = 0; i < cpu->ncells; i++) { copy->cells[i].cellid = cpu->cells[i].cellid; copy->cells[i].mem = cpu->cells[i].mem; copy->cells[i].cpumask = virBitmapNewCopy(cpu->cells[i].cpumask); if (!copy->cells[i].cpumask) goto error; if (VIR_STRDUP(copy->cells[i].cpustr, cpu->cells[i].cpustr) < 0) goto error; } copy->cells_cpus = cpu->cells_cpus; } return copy; error: virCPUDefFree(copy); return NULL; }
virCPUDefPtr virCPUDefCopy(const virCPUDef *cpu) { virCPUDefPtr copy; if (!(copy = virCPUDefCopyWithoutModel(cpu))) return NULL; if (virCPUDefCopyModel(copy, cpu, false) < 0) goto error; return copy; error: virCPUDefFree(copy); return NULL; }