mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 05:45:46 +00:00
Allow multiple parameters for schedinfo
virsh schedinfo was able to set only one parameter at a time (not counting the deprecated options), but it is useful to set more at once, so this patch adds the possibility to do stuff like this: virsh schedinfo <domain> cpu_shares=0 vcpu_period=0 vcpu_quota=0 \ emulator_period=0 emulator_quota=0 Invalid scheduler options are reported as well. These were previously reported only if the command hadn't updated any values (when cmdSchedInfoUpdate returned 0). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=810078 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=919372 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=919375
This commit is contained in:
parent
43b6f304bc
commit
e7cd2844ca
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Ensure that virsh schedinfo --set invalid=val fails
|
# Ensure that virsh schedinfo --set invalid=val fails
|
||||||
|
|
||||||
# Copyright (C) 2010-2011 Red Hat, Inc.
|
# Copyright (C) 2010-2011, 2013 Red Hat, Inc.
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -37,7 +37,7 @@ fi
|
|||||||
. "$srcdir/test-lib.sh"
|
. "$srcdir/test-lib.sh"
|
||||||
|
|
||||||
printf 'Scheduler : fair\n\n' > exp-out || framework_failure
|
printf 'Scheduler : fair\n\n' > exp-out || framework_failure
|
||||||
printf 'error: invalid scheduler option: j=k\n' > exp-err || framework_failure
|
printf 'error: invalid scheduler option: j\n' > exp-err || framework_failure
|
||||||
|
|
||||||
fail=0
|
fail=0
|
||||||
|
|
||||||
|
@ -3904,16 +3904,14 @@ static const vshCmdOptDef opts_schedinfo[] = {
|
|||||||
.flags = VSH_OFLAG_REQ,
|
.flags = VSH_OFLAG_REQ,
|
||||||
.help = N_("domain name, id or uuid")
|
.help = N_("domain name, id or uuid")
|
||||||
},
|
},
|
||||||
{.name = "set",
|
|
||||||
.type = VSH_OT_STRING,
|
|
||||||
.help = N_("parameter=value")
|
|
||||||
},
|
|
||||||
{.name = "weight",
|
{.name = "weight",
|
||||||
.type = VSH_OT_INT,
|
.type = VSH_OT_INT,
|
||||||
|
.flags = VSH_OFLAG_REQ_OPT,
|
||||||
.help = N_("weight for XEN_CREDIT")
|
.help = N_("weight for XEN_CREDIT")
|
||||||
},
|
},
|
||||||
{.name = "cap",
|
{.name = "cap",
|
||||||
.type = VSH_OT_INT,
|
.type = VSH_OT_INT,
|
||||||
|
.flags = VSH_OFLAG_REQ_OPT,
|
||||||
.help = N_("cap for XEN_CREDIT")
|
.help = N_("cap for XEN_CREDIT")
|
||||||
},
|
},
|
||||||
{.name = "current",
|
{.name = "current",
|
||||||
@ -3928,72 +3926,100 @@ static const vshCmdOptDef opts_schedinfo[] = {
|
|||||||
.type = VSH_OT_BOOL,
|
.type = VSH_OT_BOOL,
|
||||||
.help = N_("get/set value from running domain")
|
.help = N_("get/set value from running domain")
|
||||||
},
|
},
|
||||||
|
{.name = "set",
|
||||||
|
.type = VSH_OT_ARGV,
|
||||||
|
.flags = VSH_OFLAG_NONE,
|
||||||
|
.help = N_("parameter=value")
|
||||||
|
},
|
||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
cmdSchedInfoUpdateOne(vshControl *ctl,
|
||||||
|
virTypedParameterPtr src_params, int nsrc_params,
|
||||||
|
virTypedParameterPtr *params,
|
||||||
|
int *nparams, int *maxparams,
|
||||||
|
const char *field, const char *value)
|
||||||
|
{
|
||||||
|
virTypedParameterPtr param;
|
||||||
|
int ret = -1;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < nsrc_params; i++) {
|
||||||
|
param = &(src_params[i]);
|
||||||
|
|
||||||
|
if (STRNEQ(field, param->field))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (virTypedParamsAddFromString(params, nparams, maxparams,
|
||||||
|
field, param->type,
|
||||||
|
value) < 0) {
|
||||||
|
vshSaveLibvirtError();
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
vshError(ctl, _("invalid scheduler option: %s"), field);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
|
cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
|
||||||
virTypedParameterPtr src_params, int nsrc_params,
|
virTypedParameterPtr src_params, int nsrc_params,
|
||||||
virTypedParameterPtr *update_params)
|
virTypedParameterPtr *update_params)
|
||||||
{
|
{
|
||||||
const char *set_arg;
|
|
||||||
char *set_field = NULL;
|
char *set_field = NULL;
|
||||||
char *set_val = NULL;
|
char *set_val = NULL;
|
||||||
virTypedParameterPtr param;
|
const char *val = NULL;
|
||||||
|
const vshCmdOpt *opt = NULL;
|
||||||
virTypedParameterPtr params = NULL;
|
virTypedParameterPtr params = NULL;
|
||||||
int nparams = 0;
|
int nparams = 0;
|
||||||
int maxparams = 0;
|
int maxparams = 0;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rv;
|
int rv;
|
||||||
int val;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (vshCommandOptString(cmd, "set", &set_arg) > 0) {
|
while ((opt = vshCommandOptArgv(cmd, opt))) {
|
||||||
set_field = vshStrdup(ctl, set_arg);
|
set_field = vshStrdup(ctl, opt->data);
|
||||||
if (!(set_val = strchr(set_field, '='))) {
|
if (!(set_val = strchr(set_field, '='))) {
|
||||||
vshError(ctl, "%s", _("Invalid syntax for --set, expecting name=value"));
|
vshError(ctl, "%s", _("Invalid syntax for --set, "
|
||||||
|
"expecting name=value"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
*set_val = '\0';
|
*set_val = '\0';
|
||||||
set_val++;
|
set_val++;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < nsrc_params; i++) {
|
if (cmdSchedInfoUpdateOne(ctl, src_params, nsrc_params,
|
||||||
param = &(src_params[i]);
|
¶ms, &nparams, &maxparams,
|
||||||
|
set_field, set_val) < 0)
|
||||||
/* Legacy 'weight' and 'cap' parameter */
|
|
||||||
if (param->type == VIR_TYPED_PARAM_UINT &&
|
|
||||||
(STREQ(param->field, "weight") || STREQ(param->field, "cap")) &&
|
|
||||||
(rv = vshCommandOptInt(cmd, param->field, &val)) != 0) {
|
|
||||||
if (rv < 0) {
|
|
||||||
vshError(ctl, _("Invalid value of %s"), param->field);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
VIR_FREE(set_field);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams,
|
rv = vshCommandOptStringReq(ctl, cmd, "cap", &val);
|
||||||
param->field, val) < 0) {
|
if (rv < 0 ||
|
||||||
vshSaveLibvirtError();
|
(val &&
|
||||||
|
cmdSchedInfoUpdateOne(ctl, src_params, nsrc_params,
|
||||||
|
¶ms, &nparams, &maxparams,
|
||||||
|
"cap", val) < 0))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
rv = vshCommandOptStringReq(ctl, cmd, "weight", &val);
|
||||||
}
|
if (rv < 0 ||
|
||||||
|
(val &&
|
||||||
if (set_field && STREQ(set_field, param->field)) {
|
cmdSchedInfoUpdateOne(ctl, src_params, nsrc_params,
|
||||||
if (virTypedParamsAddFromString(¶ms, &nparams, &maxparams,
|
¶ms, &nparams, &maxparams,
|
||||||
set_field, param->type,
|
"weight", val) < 0))
|
||||||
set_val) < 0) {
|
|
||||||
vshSaveLibvirtError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*update_params = params;
|
|
||||||
ret = nparams;
|
ret = nparams;
|
||||||
|
*update_params = params;
|
||||||
params = NULL;
|
params = NULL;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -4083,15 +4109,6 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
/* See if we've tried to --set var=val. If so, the fact that
|
|
||||||
we reach this point (with update == 0) means that "var" did
|
|
||||||
not match any of the settable parameters. Report the error. */
|
|
||||||
const char *var_value_pair = NULL;
|
|
||||||
if (vshCommandOptString(cmd, "set", &var_value_pair) > 0) {
|
|
||||||
vshError(ctl, _("invalid scheduler option: %s"),
|
|
||||||
var_value_pair);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
/* When not doing --set, --live and --config do not mix. */
|
/* When not doing --set, --live and --config do not mix. */
|
||||||
if (live && config) {
|
if (live && config) {
|
||||||
vshError(ctl, "%s",
|
vshError(ctl, "%s",
|
||||||
|
@ -1307,8 +1307,8 @@ except that it does some error checking.
|
|||||||
The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment
|
The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment
|
||||||
variables, and defaults to C<vi>.
|
variables, and defaults to C<vi>.
|
||||||
|
|
||||||
=item B<schedinfo> [I<--set> B<parameter=value>] I<domain> [[I<--config>]
|
=item B<schedinfo> I<domain> [[I<--config>] [I<--live>] | [I<--current>]]
|
||||||
[I<--live>] | [I<--current>]]
|
[[I<--set>] B<parameter=value>]...
|
||||||
|
|
||||||
=item B<schedinfo> [I<--weight> B<number>] [I<--cap> B<number>]
|
=item B<schedinfo> [I<--weight> B<number>] [I<--cap> B<number>]
|
||||||
I<domain>
|
I<domain>
|
||||||
|
Loading…
Reference in New Issue
Block a user