On Thu, Feb 11, 2010 at 04:43:51PM +0100, Jiri Denemark wrote: > Baseline CPU is the best CPU which can be used for a guest on any of the > hosts. > [...] > +char * > +cpuBaselineXML(const char **xmlCPUs, > + unsigned int ncpus, > + const char **models, > + unsigned int nmodels) > +{ > + xmlDocPtr doc = NULL; > + xmlXPathContextPtr ctxt = NULL; > + virCPUDefPtr *cpus = NULL; > + virCPUDefPtr cpu = NULL; > + char *cpustr; > + unsigned int i; > + > + if (xmlCPUs == NULL && ncpus != 0) { > + virCPUReportError(VIR_ERR_INTERNAL_ERROR, > + "%s", _("nonzero ncpus doesn't match with NULL xmlCPUs")); > + return NULL; > + } > + > + if (ncpus < 1) { > + virCPUReportError(VIR_ERR_INVALID_ARG, "%s", _("No CPUs given")); > + return NULL; > + } > + > + if (VIR_ALLOC_N(cpus, ncpus)) > + goto no_memory; > + > + for (i = 0; i < ncpus; i++) { > + doc = xmlParseMemory(xmlCPUs[i], strlen(xmlCPUs[i])); > + if (doc == NULL || (ctxt = xmlXPathNewContext(doc)) == NULL) > + goto no_memory; Hum, no, doc == NULL might come from parsing error, raising an OOMError in that case sounds weird, unless you're 100% sure this is well formed XML... > + ctxt->node = xmlDocGetRootElement(doc); > + > + cpus[i] = virCPUDefParseXML(ctxt->node, ctxt, VIR_CPU_TYPE_HOST); > + if (cpus[i] == NULL) > + goto error; > + > + xmlXPathFreeContext(ctxt); > + xmlFreeDoc(doc); > + ctxt = NULL; > + doc = NULL; > + } > + > + if (!(cpu = cpuBaseline(cpus, ncpus, models, nmodels))) > + goto error; > + > + cpustr = virCPUDefFormat(cpu, "", 0); > + > +cleanup: > + if (cpus) { > + for (i = 0; i < ncpus; i++) > + virCPUDefFree(cpus[i]); > + VIR_FREE(cpus); > + } > + virCPUDefFree(cpu); > + xmlXPathFreeContext(ctxt); > + xmlFreeDoc(doc); > + > + return cpustr; > + > +no_memory: > + virReportOOMError(); > +error: > + cpustr = NULL; > + goto cleanup; > +} Otherwise looks fine, ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@xxxxxxxxxxxx | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list