the domain. If this is omitted, it defaults to the OS provided defaults. NB,
There is no unit for the value, it's a relative measure based on the setting
of other VM, e.g. A VM configured with value 2048 will get twice as much CPU
- time as a VM configured with value 1024. :since:`Since 0.9.0`
+ time as a VM configured with value 1024. The value should be in range
+ [2, 262144]. :since:`Since 0.9.0`
``period``
The optional ``period`` element specifies the enforcement interval (unit:
microseconds). Within ``period``, each vCPU of the domain will not be allowed
If *--current* is specified, it is equivalent to either *--live* or
*--config*, depending on the current state of the guest.
-``Note``: The cpu_shares parameter has a valid value range of 0-262144; Negative
-values are wrapped to positive, and larger values are capped at the maximum.
-Therefore, -1 is a useful shorthand for 262144. On the Linux kernel, the
-values 0 and 1 are automatically converted to a minimal value of 2.
+``Note``: The cpu_shares parameter has a valid value range of 2-262144.
``Note``: The weight and cap parameters are defined only for the
XEN_CREDIT scheduler.
static int
virDomainDefCputuneValidate(const virDomainDef *def)
{
+ if (def->cputune.shares > 0 &&
+ (def->cputune.shares < VIR_CGROUP_CPU_SHARES_MIN ||
+ def->cputune.shares > VIR_CGROUP_CPU_SHARES_MAX)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Value of cputune 'shares' must be in range [%llu, %llu]"),
+ VIR_CGROUP_CPU_SHARES_MIN,
+ VIR_CGROUP_CPU_SHARES_MAX);
+ return -1;
+ }
+
CPUTUNE_VALIDATE_PERIOD(period);
CPUTUNE_VALIDATE_PERIOD(global_period);
CPUTUNE_VALIDATE_PERIOD(emulator_period);
int virCgroupSetupCpuShares(virCgroupPtr cgroup, unsigned long long shares,
unsigned long long *realValue);
+#define VIR_CGROUP_CPU_SHARES_MIN 2LL
+#define VIR_CGROUP_CPU_SHARES_MAX 262144LL
#define VIR_CGROUP_CPU_PERIOD_MIN 1000LL
#define VIR_CGROUP_CPU_PERIOD_MAX 1000000LL
#define VIR_CGROUP_CPU_QUOTA_MIN 1000LL
virCgroupV1SetCpuShares(virCgroupPtr group,
unsigned long long shares)
{
+ if (shares < VIR_CGROUP_CPU_SHARES_MIN ||
+ shares > VIR_CGROUP_CPU_SHARES_MAX) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("shares '%llu' must be in range [%llu, %llu]"),
+ shares,
+ VIR_CGROUP_CPU_SHARES_MIN,
+ VIR_CGROUP_CPU_SHARES_MAX);
+ return -1;
+ }
+
if (group->unitName) {
GVariant *value = g_variant_new("t", shares);
virCgroupV2SetCpuShares(virCgroupPtr group,
unsigned long long shares)
{
+ if (shares < VIR_CGROUP_CPU_SHARES_MIN ||
+ shares > VIR_CGROUP_CPU_SHARES_MAX) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("shares '%llu' must be in range [%llu, %llu]"),
+ shares,
+ VIR_CGROUP_CPU_SHARES_MIN,
+ VIR_CGROUP_CPU_SHARES_MAX);
+ return -1;
+ }
+
if (group->unitName) {
GVariant *value = g_variant_new("t", shares);