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; copy->cells[i].cpumask = virBitmapNewCopy(cpu->cells[i].cpumask); if (!copy->cells[i].cpumask) goto no_memory; 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; }
int virDomainNumatuneSet(virDomainNumaPtr numa, bool placement_static, int placement, int mode, virBitmapPtr nodeset) { int ret = -1; /* No need to do anything in this case */ if (mode == -1 && placement == -1 && !nodeset) return 0; if (!numa->memory.specified) { if (mode == -1) mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT; if (placement == -1) placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT; } /* Range checks */ if (mode != -1 && (mode < 0 || mode >= VIR_DOMAIN_NUMATUNE_MEM_LAST)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported numatune mode '%d'"), mode); goto cleanup; } if (placement != -1 && (placement < 0 || placement >= VIR_DOMAIN_NUMATUNE_PLACEMENT_LAST)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported numatune placement '%d'"), mode); goto cleanup; } if (mode != -1) numa->memory.mode = mode; if (nodeset) { virBitmapFree(numa->memory.nodeset); if (!(numa->memory.nodeset = virBitmapNewCopy(nodeset))) goto cleanup; if (placement == -1) placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC; } if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT) { if (numa->memory.nodeset || placement_static) placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC; else placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO; } if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC && !numa->memory.nodeset) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("nodeset for NUMA memory tuning must be set " "if 'placement' is 'static'")); goto cleanup; } /* setting nodeset when placement auto is invalid */ if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO && numa->memory.nodeset) { virBitmapFree(numa->memory.nodeset); numa->memory.nodeset = NULL; } if (placement != -1) numa->memory.placement = placement; numa->memory.specified = true; ret = 0; cleanup: return ret; }
int virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr, bool placement_static, int placement, int mode, virBitmapPtr nodeset) { bool create = !*numatunePtr; /* Whether we are creating new struct */ int ret = -1; virDomainNumatunePtr numatune = NULL; /* No need to do anything in this case */ if (mode == -1 && placement == -1 && !nodeset) return 0; /* Range checks */ if (mode != -1 && (mode < 0 || mode >= VIR_DOMAIN_NUMATUNE_MEM_LAST)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported numatune mode '%d'"), mode); goto cleanup; } if (placement != -1 && (placement < 0 || placement >= VIR_DOMAIN_NUMATUNE_PLACEMENT_LAST)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported numatune placement '%d'"), mode); goto cleanup; } if (create && VIR_ALLOC(*numatunePtr) < 0) goto cleanup; numatune = *numatunePtr; if (create) { /* Defaults for new struct */ if (mode == -1) mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT; if (placement == -1) placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT; } if (mode != -1) numatune->memory.mode = mode; if (nodeset) { virBitmapFree(numatune->memory.nodeset); numatune->memory.nodeset = virBitmapNewCopy(nodeset); if (!numatune->memory.nodeset) goto cleanup; if (placement == -1) placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC; } if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT) { if (numatune->memory.nodeset || placement_static) placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC; else placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO; } if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC && !numatune->memory.nodeset) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("nodeset for NUMA memory tuning must be set " "if 'placement' is 'static'")); goto cleanup; } if (placement != -1) numatune->memory.placement = placement; numatune->memory.specified = true; ret = 0; cleanup: return ret; }