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. Changes: - Replace use of 'a' conversion modifier with pre-alloc Index: libvirt-0.4.6/docs/virsh.pod =================================================================== --- libvirt-0.4.6.orig/docs/virsh.pod +++ libvirt-0.4.6/docs/virsh.pod @@ -322,12 +322,14 @@ This is roughly equivalent to doing a hi with all the same limitations. Open network connections may be severed upon restore, as TCP timeouts may have expired. +=item B optional I<--set> B I + =item B optional I<--weight> B optional I<--cap> B I -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: The weight and cap parameters are defined only for the +XEN_CREDIT scheduler and are now I. =item B I B Index: libvirt-0.4.6/src/virsh.c =================================================================== --- libvirt-0.4.6.orig/src/virsh.c +++ libvirt-0.4.6/src/virsh.c @@ -1295,6 +1295,7 @@ static const vshCmdInfo info_schedinfo[] 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} @@ -1304,6 +1305,9 @@ static int 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; @@ -1311,6 +1315,7 @@ cmdSchedinfo(vshControl *ctl, const vshC int nr_inputparams = 0; int inputparams = 0; int weightfound = 0; + int setfound = 0; int weight = 0; int capfound = 0; int cap = 0; @@ -1324,7 +1329,7 @@ cmdSchedinfo(vshControl *ctl, const vshC 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) { @@ -1345,6 +1350,25 @@ cmdSchedinfo(vshControl *ctl, const vshC } } + if(vshCommandOptBool(cmd, "set")) { + set = vshCommandOptString(cmd, "set", &setfound); + if (!setfound) { + vshError(ctl, FALSE, "%s", _("Error getting param")); + goto cleanup; + } + + param_name = vshMalloc(ctl, strlen(set) + 1); + if (param_name == NULL) + goto cleanup; + + if (sscanf(set, "%[^=]=%i", param_name, ¶m_value) != 2) { + vshError(ctl, FALSE, "%s", _("Invalid value of param")); + goto cleanup; + } + + nr_inputparams++; + } + params = vshMalloc(ctl, sizeof (virSchedParameter) * nr_inputparams); if (params == NULL) { goto cleanup; @@ -1363,7 +1387,14 @@ cmdSchedinfo(vshControl *ctl, const vshC 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); @@ -1430,6 +1461,7 @@ cmdSchedinfo(vshControl *ctl, const vshC } cleanup: free(params); + free(param_name); virDomainFree(dom); return ret_val; }