mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-22 14:09:22 +00:00
virsh: Allow using complete <capabilities> elements with cpu-baseline
This patch cleans the cpu baseline function using new libvirt helper functions and fixes XPath expression that selects <cpu> elements from the source file, that can contain concatenated <capabilities> XMLs, domain XMLs and bare <cpu> elements. The fixed XPath expression ensures not to select NUMA <cpu id=... elements. This patch also removes vshRealloc function, that remained unused after cleaning up cpu-baseline. https://bugzilla.redhat.com/show_bug.cgi?id=731645
This commit is contained in:
parent
882e768ef0
commit
b0889eae6a
106
tools/virsh.c
106
tools/virsh.c
@ -384,9 +384,6 @@ static void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int li
|
|||||||
static void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz, const char *filename, int line);
|
static void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz, const char *filename, int line);
|
||||||
#define vshCalloc(_ctl, _nmemb, _sz) _vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__)
|
#define vshCalloc(_ctl, _nmemb, _sz) _vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__)
|
||||||
|
|
||||||
static void *_vshRealloc(vshControl *ctl, void *ptr, size_t sz, const char *filename, int line);
|
|
||||||
#define vshRealloc(_ctl, _ptr, _sz) _vshRealloc(_ctl, _ptr, _sz, __FILE__, __LINE__)
|
|
||||||
|
|
||||||
static char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, int line);
|
static char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, int line);
|
||||||
#define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__)
|
#define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__)
|
||||||
|
|
||||||
@ -414,19 +411,6 @@ _vshCalloc(vshControl *ctl, size_t nmemb, size_t size, const char *filename, int
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
|
||||||
_vshRealloc(vshControl *ctl, void *ptr, size_t size, const char *filename, int line)
|
|
||||||
{
|
|
||||||
void *x;
|
|
||||||
|
|
||||||
if ((x = realloc(ptr, size)))
|
|
||||||
return x;
|
|
||||||
VIR_FREE(ptr);
|
|
||||||
vshError(ctl, _("%s: %d: failed to allocate %d bytes"),
|
|
||||||
filename, line, (int) size);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
_vshStrdup(vshControl *ctl, const char *s, const char *filename, int line)
|
_vshStrdup(vshControl *ctl, const char *s, const char *filename, int line)
|
||||||
{
|
{
|
||||||
@ -12003,18 +11987,18 @@ static bool
|
|||||||
cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
|
cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
|
||||||
{
|
{
|
||||||
const char *from = NULL;
|
const char *from = NULL;
|
||||||
bool ret = true;
|
bool ret = false;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
const char **list = NULL;
|
const char **list = NULL;
|
||||||
unsigned int count = 0;
|
int count = 0;
|
||||||
xmlDocPtr doc = NULL;
|
|
||||||
xmlNodePtr node_list;
|
xmlDocPtr xml = NULL;
|
||||||
|
xmlNodePtr *node_list = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
xmlSaveCtxtPtr sctxt = NULL;
|
xmlBufferPtr xml_buf = NULL;
|
||||||
xmlBufferPtr buf = NULL;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
xmlXPathObjectPtr obj = NULL;
|
int i;
|
||||||
int res, i;
|
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
return false;
|
return false;
|
||||||
@ -12025,69 +12009,57 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
|
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
doc = xmlNewDoc(NULL);
|
/* add an separate container around the xml */
|
||||||
if (doc == NULL)
|
virBufferStrcat(&buf, "<container>", buffer, "</container>", NULL);
|
||||||
|
if (virBufferError(&buf))
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
res = xmlParseBalancedChunkMemory(doc, NULL, NULL, 0,
|
VIR_FREE(buffer);
|
||||||
(const xmlChar *)buffer, &node_list);
|
buffer = virBufferContentAndReset(&buf);
|
||||||
if (res != 0) {
|
|
||||||
vshError(ctl, _("Failed to parse XML fragment %s"), from);
|
|
||||||
ret = false;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
xmlAddChildList((xmlNodePtr) doc, node_list);
|
|
||||||
|
|
||||||
ctxt = xmlXPathNewContext(doc);
|
if (!(xml = virXMLParseStringCtxt(buffer, from, &ctxt)))
|
||||||
if (!ctxt)
|
|
||||||
goto no_memory;
|
|
||||||
|
|
||||||
obj = xmlXPathEval(BAD_CAST "//cpu[not(ancestor::cpu)]", ctxt);
|
|
||||||
if ((obj == NULL) || (obj->nodesetval == NULL) ||
|
|
||||||
(obj->nodesetval->nodeTab == NULL))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0;i < obj->nodesetval->nodeNr;i++) {
|
if ((count = virXPathNodeSet("//cpu[not(ancestor::cpus)]",
|
||||||
buf = xmlBufferCreate();
|
ctxt, &node_list)) == -1)
|
||||||
if (buf == NULL)
|
goto cleanup;
|
||||||
goto no_memory;
|
|
||||||
sctxt = xmlSaveToBuffer(buf, NULL, 0);
|
|
||||||
if (sctxt == NULL) {
|
|
||||||
xmlBufferFree(buf);
|
|
||||||
goto no_memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
xmlSaveTree(sctxt, obj->nodesetval->nodeTab[i]);
|
|
||||||
xmlSaveClose(sctxt);
|
|
||||||
|
|
||||||
list = vshRealloc(ctl, list, sizeof(char *) * (count + 1));
|
|
||||||
list[count++] = (char *) buf->content;
|
|
||||||
buf->content = NULL;
|
|
||||||
xmlBufferFree(buf);
|
|
||||||
buf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
vshError(ctl, _("No host CPU specified in '%s'"), from);
|
vshError(ctl, _("No host CPU specified in '%s'"), from);
|
||||||
ret = false;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list = vshCalloc(ctl, count, sizeof(const char *));
|
||||||
|
|
||||||
|
if (!(xml_buf = xmlBufferCreate()))
|
||||||
|
goto no_memory;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
xmlBufferEmpty(xml_buf);
|
||||||
|
|
||||||
|
if (xmlNodeDump(xml_buf, xml, node_list[i], 0, 0) < 0) {
|
||||||
|
vshError(ctl, _("Failed to extract <cpu> element"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
list[i] = vshStrdup(ctl, (const char *)xmlBufferContent(xml_buf));
|
||||||
|
}
|
||||||
|
|
||||||
result = virConnectBaselineCPU(ctl->conn, list, count, 0);
|
result = virConnectBaselineCPU(ctl->conn, list, count, 0);
|
||||||
|
|
||||||
if (result)
|
if (result) {
|
||||||
vshPrint(ctl, "%s", result);
|
vshPrint(ctl, "%s", result);
|
||||||
else
|
ret = true;
|
||||||
ret = false;
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
xmlXPathFreeObject(obj);
|
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(xml);
|
||||||
|
xmlBufferFree(xml_buf);
|
||||||
VIR_FREE(result);
|
VIR_FREE(result);
|
||||||
if ((list != NULL) && (count > 0)) {
|
if ((list != NULL) && (count > 0)) {
|
||||||
for (i = 0;i < count;i++)
|
for (i = 0; i < count; i++)
|
||||||
VIR_FREE(list[i]);
|
VIR_FREE(list[i]);
|
||||||
}
|
}
|
||||||
VIR_FREE(list);
|
VIR_FREE(list);
|
||||||
|
Loading…
Reference in New Issue
Block a user