Re: [libvirt] [PATCH 09/12] vcpu: add virsh support

2010-10-12 Thread Eric Blake

On 09/29/2010 06:02 PM, Eric Blake wrote:

* tools/virsh.c (cmdSetvcpus): Add new flags.  Let invalid
commands through to driver, to ease testing of hypervisor argument
validation.
(cmdVcpucount): New command.
(commands): Add new command.
* tools/virsh.pod (setvcpus, vcpucount): Document new behavior.
---


In testing this, I found it useful to add one more command.

Previously, virsh had no way to get at 
virConnectGetMaxVcpus/virDomainGetMaxVcpus (it is used it inside 
setvcpus, but not exposed to the user).  And now that 
virDomainGetVcpusFlags is smarter about reading the maximum limit 
associated with the XML of a domain, it is harder to tell whether the 
maximum associated with a domain is due to the domain's xml or due to 
the XML omitting the vcpus element and inheriting the hypervisor's 
maximum.  That is, with more flexibility in vcpu management, it is also 
more important to know, for example, that the max vcpus permitted by xen 
is 32, and the max vcpus permitted by qemu is dependent on the number of 
cores in the host, whether or not a given domain is using that many vcpus.


I debated between two interfaces:

1. Make vcpucount smarter:
vcpucount = virConnectGetMaxVcpus, plus table of all vcpu stats on all 
domains

vcpucount domain = table of all vcpu stats on domain
vcpucount {--live|--config} {--curent|--maximum} domain = single stat
vcpucount domain... = table of all vcpu stats on listed domains

2. Add second command, leaving vcpucount unchanged from v1:
maxvcpus [--type=string] = virConnectGetMaxVcpus

then decided to go with option 2 in my v2 posting of the vcpu series, 
unless anyone has a reason why overloading a single command makes more 
sense than keeping the separate API calls under separate commands.


--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 09/12] vcpu: add virsh support

2010-10-01 Thread Daniel Veillard
On Wed, Sep 29, 2010 at 06:02:13PM -0600, Eric Blake wrote:
 * tools/virsh.c (cmdSetvcpus): Add new flags.  Let invalid
 commands through to driver, to ease testing of hypervisor argument
 validation.
 (cmdVcpucount): New command.
 (commands): Add new command.
 * tools/virsh.pod (setvcpus, vcpucount): Document new behavior.
 ---
 
 I know - the typical API addition sequence adds driver support
 first and then virsh support.  I can rearrange the patch order
 if desired.

  Nahh, fine, actually the entry points are there, so really there
is no problem !

[...]
  /*
 + * vcpucount command
 + */
 +static const vshCmdInfo info_vcpucount[] = {
 +{help, N_(domain vcpu counts)},
 +{desc, N_(Returns the number of domain virtual CPUs.)},

  Ouch Returns the number of virtual CPUs used by the domain.  would
be clearer I think

[...]
 +if (maximum + current + persistent + active == 1) {
 +vshError(ctl,
 + _(when using --%s, either --%s or --%s must be specified),
 + maximum ? maximum : current ? current
 + : persistent ? persistent : active,
 + maximum + current ? persistent : maximum,
 + maximum + current ? active : current);

  Ouch, headache :-) but but looks right


Okay, code ended up being a bit more complex than I expected but that's
due to the various options and the fallback to old APIs, fine,

ACK,

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
dan...@veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 09/12] vcpu: add virsh support

2010-09-29 Thread Eric Blake
* tools/virsh.c (cmdSetvcpus): Add new flags.  Let invalid
commands through to driver, to ease testing of hypervisor argument
validation.
(cmdVcpucount): New command.
(commands): Add new command.
* tools/virsh.pod (setvcpus, vcpucount): Document new behavior.
---

I know - the typical API addition sequence adds driver support
first and then virsh support.  I can rearrange the patch order
if desired.

 tools/virsh.c   |  211 +--
 tools/virsh.pod |   28 +++-
 2 files changed, 217 insertions(+), 22 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 85014f2..0fcfdb7 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2220,10 +2220,181 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
 }

 /*
+ * vcpucount command
+ */
+static const vshCmdInfo info_vcpucount[] = {
+{help, N_(domain vcpu counts)},
+{desc, N_(Returns the number of domain virtual CPUs.)},
+{NULL, NULL}
+};
+
+static const vshCmdOptDef opts_vcpucount[] = {
+{domain, VSH_OT_DATA, VSH_OFLAG_REQ, N_(domain name, id or uuid)},
+{maximum, VSH_OT_BOOL, 0, N_(get maximum cap on vcpus)},
+{current, VSH_OT_BOOL, 0, N_(get current vcpu usage)},
+{persistent, VSH_OT_BOOL, 0, N_(get value to be used on next boot)},
+{active, VSH_OT_BOOL, 0, N_(get value from running domain)},
+{NULL, 0, 0, NULL}
+};
+
+static int
+cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
+{
+virDomainPtr dom;
+int ret = TRUE;
+int maximum = vshCommandOptBool(cmd, maximum);
+int current = vshCommandOptBool(cmd, current);
+int persistent = vshCommandOptBool(cmd, persistent);
+int active = vshCommandOptBool(cmd, active);
+bool all = maximum + current + persistent + active == 0;
+int count;
+
+if (maximum  current) {
+vshError(ctl, %s,
+ _(--maximum and --current cannot both be specified));
+return FALSE;
+}
+if (persistent  active) {
+vshError(ctl, %s,
+ _(--persistent and --active cannot both be specified));
+return FALSE;
+}
+if (maximum + current + persistent + active == 1) {
+vshError(ctl,
+ _(when using --%s, either --%s or --%s must be specified),
+ maximum ? maximum : current ? current
+ : persistent ? persistent : active,
+ maximum + current ? persistent : maximum,
+ maximum + current ? active : current);
+return FALSE;
+}
+
+if (!vshConnectionUsability(ctl, ctl-conn))
+return FALSE;
+
+if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+return FALSE;
+
+/* In all cases, try the new API first; if it fails because we are
+ * talking to an older client, try a fallback API before giving
+ * up.  */
+if (all || (maximum  persistent)) {
+count = virDomainGetVcpusFlags(dom, (VIR_DOMAIN_VCPU_MAXIMUM |
+ VIR_DOMAIN_VCPU_PERSISTENT));
+if (count  0  (last_error-code == VIR_ERR_NO_SUPPORT
+  || last_error-code == VIR_ERR_INVALID_ARG)) {
+char *tmp;
+char *xml = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE);
+if (xml  (tmp = strstr(xml, vcpu))) {
+tmp = strchr(tmp, '');
+if (!tmp || virStrToLong_i(tmp + 1, tmp, 10, count)  0)
+count = -1;
+}
+VIR_FREE(xml);
+}
+
+if (count  0) {
+virshReportError(ctl);
+ret = FALSE;
+} else if (all) {
+vshPrint(ctl, %-12s %-12s %3d\n, _(maximum), _(persistent),
+ count);
+} else {
+vshPrint(ctl, %d\n, count);
+}
+virFreeError(last_error);
+last_error = NULL;
+}
+
+if (all || (maximum  active)) {
+count = virDomainGetVcpusFlags(dom, (VIR_DOMAIN_VCPU_MAXIMUM |
+ VIR_DOMAIN_VCPU_ACTIVE));
+if (count  0  (last_error-code == VIR_ERR_NO_SUPPORT
+  || last_error-code == VIR_ERR_INVALID_ARG)) {
+count = virDomainGetMaxVcpus(dom);
+}
+
+if (count  0) {
+virshReportError(ctl);
+ret = FALSE;
+} else if (all) {
+vshPrint(ctl, %-12s %-12s %3d\n, _(maximum), _(active),
+ count);
+} else {
+vshPrint(ctl, %d\n, count);
+}
+virFreeError(last_error);
+last_error = NULL;
+}
+
+if (all || (current  persistent)) {
+count = virDomainGetVcpusFlags(dom, VIR_DOMAIN_VCPU_PERSISTENT);
+if (count  0  (last_error-code == VIR_ERR_NO_SUPPORT
+  || last_error-code == VIR_ERR_INVALID_ARG)) {
+char *tmp, *end;
+char *xml = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE);
+if (xml  (tmp = strstr(xml, vcpu))) {
+