[libvirt] [PATCH] Add generic parameter=value support for virsh's schedinfo command

This patch maintains the two Xen-specific --weight and --cap options, but adds support for setting arbitrary parameters by specifying them in param=value syntax. Changes to the virsh manual are included. diff -r 51fd150edd42 -r aae58f42bd4a docs/virsh.pod --- a/docs/virsh.pod Tue Oct 07 11:45:52 2008 -0700 +++ b/docs/virsh.pod Tue Oct 07 13:53:49 2008 -0700 @@ -318,12 +318,14 @@ with all the same limitations. Open network connections may be severed upon restore, as TCP timeouts may have expired. +=item B<schedinfo> optional I<--set> B<parameter=value> I<domain-id> + =item B<schedinfo> optional I<--weight> B<number> optional I<--cap> B<number> I<domain-id> -Allows to show (and set) the domain scheduler parameters. This is currently -only defined for XEN_CREDIT scheduler, and the optional weight and cap -arguments allows to set the associated parameters in that scheduler if -provided. +Allows to show (and set) the domain scheduler parameters. + +B<Note>: The weight and cap parameters are defined only for the +XEN_CREDIT scheduler and are now I<DEPRECATED>. =item B<setmem> I<domain-id> B<kilobytes> diff -r 51fd150edd42 -r aae58f42bd4a src/virsh.c --- a/src/virsh.c Tue Oct 07 11:45:52 2008 -0700 +++ b/src/virsh.c Tue Oct 07 13:53:49 2008 -0700 @@ -1112,6 +1112,7 @@ static const vshCmdOptDef opts_schedinfo[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")}, + {"set", VSH_OT_STRING, VSH_OFLAG_NONE, gettext_noop("parameter=value")}, {"weight", VSH_OT_INT, VSH_OFLAG_NONE, gettext_noop("weight for XEN_CREDIT")}, {"cap", VSH_OT_INT, VSH_OFLAG_NONE, gettext_noop("cap for XEN_CREDIT")}, {NULL, 0, 0, NULL} @@ -1121,6 +1122,9 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) { char *schedulertype; + char *set; + char *param_name = NULL; + long long int param_value = 0; virDomainPtr dom; virSchedParameterPtr params = NULL; int i, ret; @@ -1128,6 +1132,7 @@ int nr_inputparams = 0; int inputparams = 0; int weightfound = 0; + int setfound = 0; int weight = 0; int capfound = 0; int cap = 0; @@ -1141,7 +1146,7 @@ if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL))) return FALSE; - /* Currently supports Xen Credit only */ + /* Deprecated Xen-only options */ if(vshCommandOptBool(cmd, "weight")) { weight = vshCommandOptInt(cmd, "weight", &weightfound); if (!weightfound) { @@ -1160,6 +1165,21 @@ } else { nr_inputparams++; } + } + + if(vshCommandOptBool(cmd, "set")) { + set = vshCommandOptString(cmd, "set", &setfound); + if (!setfound) { + vshError(ctl, FALSE, "%s", _("Error getting param")); + goto cleanup; + } + + if (sscanf(set, "%a[^=]=%i", ¶m_name, ¶m_value) != 2) { + vshError(ctl, FALSE, "%s", _("Invalid value of param")); + goto cleanup; + } + + nr_inputparams++; } params = vshMalloc(ctl, sizeof (virSchedParameter) * nr_inputparams); @@ -1180,7 +1200,14 @@ params[inputparams].value.ui = cap; inputparams++; } - /* End Currently supports Xen Credit only */ + /* End Deprecated Xen-only options */ + + if (setfound) { + strncpy(params[inputparams].field,param_name,sizeof(params[0].field)); + params[inputparams].type = VIR_DOMAIN_SCHED_FIELD_LLONG; + params[inputparams].value.l = param_value; + inputparams++; + } assert (inputparams == nr_inputparams); @@ -1247,6 +1274,7 @@ } cleanup: free(params); + free(param_name); virDomainFree(dom); return ret_val; }

On Tue, Oct 07, 2008 at 01:55:28PM -0700, Dan Smith wrote:
This patch maintains the two Xen-specific --weight and --cap options, but adds support for setting arbitrary parameters by specifying them in param=value syntax.
Changes to the virsh manual are included.
Sounds good, but ...
+ if (sscanf(set, "%a[^=]=%i", ¶m_name, ¶m_value) != 2) {
a is not part of C89, that's an extension to the standard if i believe the linux man page. I would rather avoid a portability problem here Otherwise looks fine to me, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

DV> a is not part of C89, that's an extension to the standard if i believe DV> the linux man page. I would rather avoid a portability problem here Oh, right, I always forget about that. I'll send a replacement. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com
participants (2)
-
Dan Smith
-
Daniel Veillard