[libvirt] [PATCH] virsh: move command cpu-baseline from domain group to host group.
cpu-baseline command can compute baseline CPU for a set of given CPUs, I think it should not belong to domain group, but now it belongs to host group, so I moved the related source from virsh-domain.c to virsh-host.c Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com> --- tools/virsh-domain.c | 116 ------------------------------------------------- tools/virsh-host.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 116 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 42c9920..8fc6c59 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6107,116 +6107,6 @@ cleanup: } /* - * "cpu-baseline" command - */ -static const vshCmdInfo info_cpu_baseline[] = { - {.name = "help", - .data = N_("compute baseline CPU") - }, - {.name = "desc", - .data = N_("Compute baseline CPU for a set of given CPUs.") - }, - {.name = NULL} -}; - -static const vshCmdOptDef opts_cpu_baseline[] = { - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("file containing XML CPU descriptions") - }, - {.name = "features", - .type = VSH_OT_BOOL, - .help = N_("Show features that are part of the CPU model type") - }, - {.name = NULL} -}; - -static bool -cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) -{ - const char *from = NULL; - bool ret = false; - char *buffer; - char *result = NULL; - char **list = NULL; - unsigned int flags = 0; - int count = 0; - - xmlDocPtr xml = NULL; - xmlNodePtr *node_list = NULL; - xmlXPathContextPtr ctxt = NULL; - virBuffer buf = VIR_BUFFER_INITIALIZER; - size_t i; - - if (vshCommandOptBool(cmd, "features")) - flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES; - - if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - return false; - - if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) - return false; - - /* add a separate container around the xml */ - virBufferStrcat(&buf, "<container>", buffer, "</container>", NULL); - if (virBufferError(&buf)) - goto no_memory; - - VIR_FREE(buffer); - buffer = virBufferContentAndReset(&buf); - - - if (!(xml = virXMLParseStringCtxt(buffer, from, &ctxt))) - goto cleanup; - - if ((count = virXPathNodeSet("//cpu[not(ancestor::cpus)]", - ctxt, &node_list)) == -1) - goto cleanup; - - if (count == 0) { - vshError(ctl, _("No host CPU specified in '%s'"), from); - goto cleanup; - } - - list = vshCalloc(ctl, count, sizeof(const char *)); - - for (i = 0; i < count; i++) { - if (!(list[i] = virXMLNodeToString(xml, node_list[i]))) { - vshSaveLibvirtError(); - goto cleanup; - } - } - - result = virConnectBaselineCPU(ctl->conn, - (const char **)list, count, flags); - - if (result) { - vshPrint(ctl, "%s", result); - ret = true; - } - -cleanup: - xmlXPathFreeContext(ctxt); - xmlFreeDoc(xml); - VIR_FREE(result); - if (list != NULL && count > 0) { - for (i = 0; i < count; i++) - VIR_FREE(list[i]); - } - VIR_FREE(list); - VIR_FREE(buffer); - VIR_FREE(node_list); - - return ret; - -no_memory: - vshError(ctl, "%s", _("Out of memory")); - ret = false; - goto cleanup; -} - -/* * "cpu-stats" command */ static const vshCmdInfo info_cpu_stats[] = { @@ -10517,12 +10407,6 @@ const vshCmdDef domManagementCmds[] = { .flags = 0 }, #endif - {.name = "cpu-baseline", - .handler = cmdCPUBaseline, - .opts = opts_cpu_baseline, - .info = info_cpu_baseline, - .flags = 0 - }, {.name = "cpu-compare", .handler = cmdCPUCompare, .opts = opts_cpu_compare, diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 1d1bb97..b69de7c 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -35,6 +35,7 @@ #include "virbuffer.h" #include "viralloc.h" #include "virsh-domain.h" +#include "virfile.h" #include "virxml.h" #include "virtypedparam.h" #include "virstring.h" @@ -193,6 +194,116 @@ cleanup: } /* + * "cpu-baseline" command + */ +static const vshCmdInfo info_cpu_baseline[] = { + {.name = "help", + .data = N_("compute baseline CPU") + }, + {.name = "desc", + .data = N_("Compute baseline CPU for a set of given CPUs.") + }, + {.name = NULL} +}; + +static const vshCmdOptDef opts_cpu_baseline[] = { + {.name = "file", + .type = VSH_OT_DATA, + .flags = VSH_OFLAG_REQ, + .help = N_("file containing XML CPU descriptions") + }, + {.name = "features", + .type = VSH_OT_BOOL, + .help = N_("Show features that are part of the CPU model type") + }, + {.name = NULL} +}; + +static bool +cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) +{ + const char *from = NULL; + bool ret = false; + char *buffer; + char *result = NULL; + char **list = NULL; + unsigned int flags = 0; + int count = 0; + + xmlDocPtr xml = NULL; + xmlNodePtr *node_list = NULL; + xmlXPathContextPtr ctxt = NULL; + virBuffer buf = VIR_BUFFER_INITIALIZER; + size_t i; + + if (vshCommandOptBool(cmd, "features")) + flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES; + + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) + return false; + + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) + return false; + + /* add a separate container around the xml */ + virBufferStrcat(&buf, "<container>", buffer, "</container>", NULL); + if (virBufferError(&buf)) + goto no_memory; + + VIR_FREE(buffer); + buffer = virBufferContentAndReset(&buf); + + + if (!(xml = virXMLParseStringCtxt(buffer, from, &ctxt))) + goto cleanup; + + if ((count = virXPathNodeSet("//cpu[not(ancestor::cpus)]", + ctxt, &node_list)) == -1) + goto cleanup; + + if (count == 0) { + vshError(ctl, _("No host CPU specified in '%s'"), from); + goto cleanup; + } + + list = vshCalloc(ctl, count, sizeof(const char *)); + + for (i = 0; i < count; i++) { + if (!(list[i] = virXMLNodeToString(xml, node_list[i]))) { + vshSaveLibvirtError(); + goto cleanup; + } + } + + result = virConnectBaselineCPU(ctl->conn, + (const char **)list, count, flags); + + if (result) { + vshPrint(ctl, "%s", result); + ret = true; + } + +cleanup: + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + VIR_FREE(result); + if (list != NULL && count > 0) { + for (i = 0; i < count; i++) + VIR_FREE(list[i]); + } + VIR_FREE(list); + VIR_FREE(buffer); + VIR_FREE(node_list); + + return ret; + +no_memory: + vshError(ctl, "%s", _("Out of memory")); + ret = false; + goto cleanup; +} + +/* * "maxvcpus" command */ static const vshCmdInfo info_maxvcpus[] = { @@ -955,6 +1066,12 @@ const vshCmdDef hostAndHypervisorCmds[] = { .info = info_hostname, .flags = 0 }, + {.name = "cpu-baseline", + .handler = cmdCPUBaseline, + .opts = opts_cpu_baseline, + .info = info_cpu_baseline, + .flags = 0 + }, {.name = "maxvcpus", .handler = cmdMaxvcpus, .opts = opts_maxvcpus, -- 1.7.1 -- Regards, -------------------------------------------------- Li Yang TEL:+86+25-86630566-8529 EMail:liyang.fnst@cn.fujitsu.com --------------------------------------------------
On 10/15/13 08:02, liyang wrote:
cpu-baseline command can compute baseline CPU for a set of given CPUs, I think it should not belong to domain group, but now it belongs to host group, so I moved the related source from virsh-domain.c to virsh-host.c
Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com> --- tools/virsh-domain.c | 116 ------------------------------------------------- tools/virsh-host.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 116 deletions(-)
Your mailing client mangled whitespace in this patch, thus it can't be applied. Please use git send-email or other option that doesn't mangle patches for sending submissions. Peter
Thanks for reminding me, I will use send-email to send this patch soon. On 2013-10-15 17:10, Peter Krempa wrote:
On 10/15/13 08:02, liyang wrote:
cpu-baseline command can compute baseline CPU for a set of given CPUs, I think it should not belong to domain group, but now it belongs to host group, so I moved the related source from virsh-domain.c to virsh-host.c
Signed-off-by: Li Yang<liyang.fnst@cn.fujitsu.com> --- tools/virsh-domain.c | 116 ------------------------------------------------- tools/virsh-host.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 116 deletions(-)
Your mailing client mangled whitespace in this patch, thus it can't be applied. Please use git send-email or other option that doesn't mangle patches for sending submissions.
Peter
-- Regards, -------------------------------------------------- Li Yang TEL:+86+25-86630566-8529 EMail:liyang.fnst@cn.fujitsu.com --------------------------------------------------
On Tue, Oct 15, 2013 at 02:02:42PM +0800, liyang wrote:
cpu-baseline command can compute baseline CPU for a set of given CPUs, I think it should not belong to domain group, but now it belongs to host group, so I moved the related source from virsh-domain.c to virsh-host.c
NACK, it is correct to be against the host - it has many use cases where there is no domain involved at all. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
On 10/15/13 11:44, Daniel P. Berrange wrote:
On Tue, Oct 15, 2013 at 02:02:42PM +0800, liyang wrote:
cpu-baseline command can compute baseline CPU for a set of given CPUs, I think it should not belong to domain group, but now it belongs to host group, so I moved the related source from virsh-domain.c to virsh-host.c
NACK, it is correct to be against the host - it has many use cases where there is no domain involved at all.
Well in that case it should probably be in virsh-host.c as the patch is moving it actually. The commit message isn't clear though.
Daniel
Peter
On Tue, Oct 15, 2013 at 11:52:09AM +0200, Peter Krempa wrote:
On 10/15/13 11:44, Daniel P. Berrange wrote:
On Tue, Oct 15, 2013 at 02:02:42PM +0800, liyang wrote:
cpu-baseline command can compute baseline CPU for a set of given CPUs, I think it should not belong to domain group, but now it belongs to host group, so I moved the related source from virsh-domain.c to virsh-host.c
NACK, it is correct to be against the host - it has many use cases where there is no domain involved at all.
Well in that case it should probably be in virsh-host.c as the patch is moving it actually. The commit message isn't clear though.
Oh, whoops, I mis-read the commit message. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
On 2013-10-15 17:54, Daniel P. Berrange wrote:
On Tue, Oct 15, 2013 at 11:52:09AM +0200, Peter Krempa wrote:
On 10/15/13 11:44, Daniel P. Berrange wrote:
On Tue, Oct 15, 2013 at 02:02:42PM +0800, liyang wrote:
cpu-baseline command can compute baseline CPU for a set of given CPUs, I think it should not belong to domain group, but now it belongs to host group, so I moved the related source from virsh-domain.c to virsh-host.c NACK, it is correct to be against the host - it has many use cases where there is no domain involved at all. Well in that case it should probably be in virsh-host.c as the patch is moving it actually. The commit message isn't clear though. Oh, whoops, I mis-read the commit message.
Daniel Yes, I just found I gave you a bad commit message, will fix it.
-- Regards, -------------------------------------------------- Li Yang TEL:+86+25-86630566-8529 EMail:liyang.fnst@cn.fujitsu.com --------------------------------------------------
participants (3)
-
Daniel P. Berrange -
liyang -
Peter Krempa