mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
util: use new virTypedParameter helpers
Reusing common code makes things smaller; it also buys us some additional safety, such as now rejecting duplicate parameters during a set operation. * src/qemu/qemu_driver.c (qemuDomainSetBlkioParameters) (qemuDomainSetMemoryParameters, qemuDomainSetNumaParameters) (qemuSetSchedulerParametersFlags) (qemuDomainSetInterfaceParameters, qemuDomainSetBlockIoTune) (qemuDomainGetBlkioParameters, qemuDomainGetMemoryParameters) (qemuDomainGetNumaParameters, qemuGetSchedulerParametersFlags) (qemuDomainBlockStatsFlags, qemuDomainGetInterfaceParameters) (qemuDomainGetBlockIoTune): Use new helpers. * src/esx/esx_driver.c (esxDomainSetSchedulerParametersFlags) (esxDomainSetMemoryParameters) (esxDomainGetSchedulerParametersFlags) (esxDomainGetMemoryParameters): Likewise. * src/libxl/libxl_driver.c (libxlDomainSetSchedulerParametersFlags) (libxlDomainGetSchedulerParametersFlags): Likewise. * src/lxc/lxc_driver.c (lxcDomainSetMemoryParameters) (lxcSetSchedulerParametersFlags, lxcDomainSetBlkioParameters) (lxcDomainGetMemoryParameters, lxcGetSchedulerParametersFlags) (lxcDomainGetBlkioParameters): Likewise. * src/test/test_driver.c (testDomainSetSchedulerParamsFlags) (testDomainGetSchedulerParamsFlags): Likewise. * src/xen/xen_hypervisor.c (xenHypervisorSetSchedulerParameters) (xenHypervisorGetSchedulerParameters): Likewise.
This commit is contained in:
parent
61ca98b054
commit
9e48c22534
@ -32,6 +32,7 @@
|
||||
#include "logging.h"
|
||||
#include "uuid.h"
|
||||
#include "vmx.h"
|
||||
#include "virtypedparam.h"
|
||||
#include "esx_driver.h"
|
||||
#include "esx_interface_driver.h"
|
||||
#include "esx_network_driver.h"
|
||||
@ -3660,43 +3661,38 @@ esxDomainGetSchedulerParametersFlags(virDomainPtr domain,
|
||||
dynamicProperty = dynamicProperty->_next) {
|
||||
if (STREQ(dynamicProperty->name, "config.cpuAllocation.reservation") &&
|
||||
! (mask & (1 << 0))) {
|
||||
snprintf (params[i].field, VIR_TYPED_PARAM_FIELD_LENGTH, "%s",
|
||||
VIR_DOMAIN_SCHEDULER_RESERVATION);
|
||||
|
||||
params[i].type = VIR_TYPED_PARAM_LLONG;
|
||||
|
||||
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
||||
esxVI_Type_Long) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
params[i].value.l = dynamicProperty->val->int64;
|
||||
if (virTypedParameterAssign(¶ms[i],
|
||||
VIR_DOMAIN_SCHEDULER_RESERVATION,
|
||||
VIR_TYPED_PARAM_LLONG,
|
||||
dynamicProperty->val->int64) < 0)
|
||||
goto cleanup;
|
||||
mask |= 1 << 0;
|
||||
++i;
|
||||
} else if (STREQ(dynamicProperty->name,
|
||||
"config.cpuAllocation.limit") &&
|
||||
! (mask & (1 << 1))) {
|
||||
snprintf (params[i].field, VIR_TYPED_PARAM_FIELD_LENGTH, "%s",
|
||||
VIR_DOMAIN_SCHEDULER_LIMIT);
|
||||
|
||||
params[i].type = VIR_TYPED_PARAM_LLONG;
|
||||
|
||||
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
||||
esxVI_Type_Long) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
params[i].value.l = dynamicProperty->val->int64;
|
||||
if (virTypedParameterAssign(¶ms[i],
|
||||
VIR_DOMAIN_SCHEDULER_LIMIT,
|
||||
VIR_TYPED_PARAM_LLONG,
|
||||
dynamicProperty->val->int64) < 0)
|
||||
goto cleanup;
|
||||
mask |= 1 << 1;
|
||||
++i;
|
||||
} else if (STREQ(dynamicProperty->name,
|
||||
"config.cpuAllocation.shares") &&
|
||||
! (mask & (1 << 2))) {
|
||||
snprintf (params[i].field, VIR_TYPED_PARAM_FIELD_LENGTH, "%s",
|
||||
VIR_DOMAIN_SCHEDULER_SHARES);
|
||||
|
||||
params[i].type = VIR_TYPED_PARAM_INT;
|
||||
|
||||
if (virTypedParameterAssign(¶ms[i],
|
||||
VIR_DOMAIN_SCHEDULER_SHARES,
|
||||
VIR_TYPED_PARAM_INT, 0) < 0)
|
||||
goto cleanup;
|
||||
if (esxVI_SharesInfo_CastFromAnyType(dynamicProperty->val,
|
||||
&sharesInfo) < 0) {
|
||||
goto cleanup;
|
||||
@ -3769,6 +3765,15 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain,
|
||||
int i;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
if (virTypedParameterArrayValidate(params, nparams,
|
||||
VIR_DOMAIN_SCHEDULER_RESERVATION,
|
||||
VIR_TYPED_PARAM_LLONG,
|
||||
VIR_DOMAIN_SCHEDULER_LIMIT,
|
||||
VIR_TYPED_PARAM_LLONG,
|
||||
VIR_DOMAIN_SCHEDULER_SHARES,
|
||||
VIR_TYPED_PARAM_INT,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
if (esxVI_EnsureSession(priv->primary) < 0) {
|
||||
return -1;
|
||||
@ -3783,8 +3788,7 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain,
|
||||
}
|
||||
|
||||
for (i = 0; i < nparams; ++i) {
|
||||
if (STREQ (params[i].field, VIR_DOMAIN_SCHEDULER_RESERVATION) &&
|
||||
params[i].type == VIR_TYPED_PARAM_LLONG) {
|
||||
if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_RESERVATION)) {
|
||||
if (esxVI_Long_Alloc(&spec->cpuAllocation->reservation) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -3797,8 +3801,7 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain,
|
||||
}
|
||||
|
||||
spec->cpuAllocation->reservation->value = params[i].value.l;
|
||||
} else if (STREQ (params[i].field, VIR_DOMAIN_SCHEDULER_LIMIT) &&
|
||||
params[i].type == VIR_TYPED_PARAM_LLONG) {
|
||||
} else if(STREQ (params[i].field, VIR_DOMAIN_SCHEDULER_LIMIT)) {
|
||||
if (esxVI_Long_Alloc(&spec->cpuAllocation->limit) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -3812,8 +3815,7 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain,
|
||||
}
|
||||
|
||||
spec->cpuAllocation->limit->value = params[i].value.l;
|
||||
} else if (STREQ (params[i].field, VIR_DOMAIN_SCHEDULER_SHARES) &&
|
||||
params[i].type == VIR_TYPED_PARAM_INT) {
|
||||
} else if(STREQ (params[i].field, VIR_DOMAIN_SCHEDULER_SHARES)) {
|
||||
if (esxVI_SharesInfo_Alloc(&sharesInfo) < 0 ||
|
||||
esxVI_Int_Alloc(&sharesInfo->shares) < 0) {
|
||||
goto cleanup;
|
||||
@ -3851,10 +3853,6 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain,
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ESX_ERROR(VIR_ERR_INVALID_ARG, _("Unknown field '%s'"),
|
||||
params[i].field);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4828,6 +4826,11 @@ esxDomainSetMemoryParameters(virDomainPtr domain, virTypedParameterPtr params,
|
||||
int i;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
if (virTypedParameterArrayValidate(params, nparams,
|
||||
VIR_DOMAIN_MEMORY_MIN_GUARANTEE,
|
||||
VIR_TYPED_PARAM_ULLONG,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
if (esxVI_EnsureSession(priv->primary) < 0) {
|
||||
return -1;
|
||||
@ -4842,18 +4845,13 @@ esxDomainSetMemoryParameters(virDomainPtr domain, virTypedParameterPtr params,
|
||||
}
|
||||
|
||||
for (i = 0; i < nparams; ++i) {
|
||||
if (STREQ (params[i].field, VIR_DOMAIN_MEMORY_MIN_GUARANTEE) &&
|
||||
params[i].type == VIR_TYPED_PARAM_ULLONG) {
|
||||
if (STREQ(params[i].field, VIR_DOMAIN_MEMORY_MIN_GUARANTEE)) {
|
||||
if (esxVI_Long_Alloc(&spec->memoryAllocation->reservation) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
spec->memoryAllocation->reservation->value =
|
||||
VIR_DIV_UP(params[i].value.ul, 1024); /* Scale from kilobytes to megabytes */
|
||||
} else {
|
||||
ESX_ERROR(VIR_ERR_INVALID_ARG, _("Unknown field '%s'"),
|
||||
params[i].field);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4917,16 +4915,11 @@ esxDomainGetMemoryParameters(virDomainPtr domain, virTypedParameterPtr params,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virStrcpyStatic(params[0].field,
|
||||
VIR_DOMAIN_MEMORY_MIN_GUARANTEE) == NULL) {
|
||||
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Field %s too big for destination"),
|
||||
VIR_DOMAIN_MEMORY_MIN_GUARANTEE);
|
||||
/* Scale from megabytes to kilobytes */
|
||||
if (virTypedParameterAssign(params, VIR_DOMAIN_MEMORY_MIN_GUARANTEE,
|
||||
VIR_TYPED_PARAM_ULLONG,
|
||||
reservation->value * 1024) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
params[0].type = VIR_TYPED_PARAM_ULLONG;
|
||||
params[0].value.ul = reservation->value * 1024; /* Scale from megabytes to kilobytes */
|
||||
|
||||
*nparams = 1;
|
||||
result = 0;
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include "libxl_driver.h"
|
||||
#include "libxl_conf.h"
|
||||
#include "xen_xm.h"
|
||||
|
||||
#include "virtypedparam.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
||||
|
||||
@ -3610,26 +3610,14 @@ libxlDomainGetSchedulerParametersFlags(virDomainPtr dom,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
params[0].value.ui = sc_info.weight;
|
||||
params[0].type = VIR_TYPED_PARAM_UINT;
|
||||
if (virStrcpyStatic(params[0].field,
|
||||
VIR_DOMAIN_SCHEDULER_WEIGHT) == NULL) {
|
||||
libxlError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Field name '%s' too long"),
|
||||
VIR_DOMAIN_SCHEDULER_WEIGHT);
|
||||
if (virTypedParameterAssign(¶ms[0], VIR_DOMAIN_SCHEDULER_WEIGHT,
|
||||
VIR_TYPED_PARAM_UINT, sc_info.weight) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (*nparams > 1) {
|
||||
params[1].value.ui = sc_info.cap;
|
||||
params[1].type = VIR_TYPED_PARAM_UINT;
|
||||
if (virStrcpyStatic(params[1].field,
|
||||
VIR_DOMAIN_SCHEDULER_CAP) == NULL) {
|
||||
libxlError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Field name '%s' too long"),
|
||||
VIR_DOMAIN_SCHEDULER_CAP);
|
||||
if (virTypedParameterAssign(¶ms[0], VIR_DOMAIN_SCHEDULER_CAP,
|
||||
VIR_TYPED_PARAM_UINT, sc_info.cap) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if (*nparams > XEN_SCHED_CREDIT_NPARAM)
|
||||
@ -3664,6 +3652,13 @@ libxlDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
||||
int ret = -1;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
if (virTypedParameterArrayValidate(params, nparams,
|
||||
VIR_DOMAIN_SCHEDULER_WEIGHT,
|
||||
VIR_TYPED_PARAM_UINT,
|
||||
VIR_DOMAIN_SCHEDULER_CAP,
|
||||
VIR_TYPED_PARAM_UINT,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
libxlDriverLock(driver);
|
||||
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||
@ -3705,24 +3700,9 @@ libxlDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
||||
virTypedParameterPtr param = ¶ms[i];
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_WEIGHT)) {
|
||||
if (param->type != VIR_TYPED_PARAM_UINT) {
|
||||
libxlError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("invalid type for weight tunable, expected a 'uint'"));
|
||||
goto cleanup;
|
||||
}
|
||||
sc_info.weight = params[i].value.ui;
|
||||
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CAP)) {
|
||||
if (param->type != VIR_TYPED_PARAM_UINT) {
|
||||
libxlError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("invalid type for cap tunable, expected a 'uint'"));
|
||||
goto cleanup;
|
||||
}
|
||||
sc_info.cap = params[i].value.ui;
|
||||
} else {
|
||||
libxlError(VIR_ERR_INVALID_ARG,
|
||||
_("Invalid parameter '%s'"), param->field);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "virnetdev.h"
|
||||
#include "virnodesuspend.h"
|
||||
#include "virtime.h"
|
||||
#include "virtypedparam.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||
|
||||
@ -778,18 +779,29 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int lxcDomainSetMemoryParameters(virDomainPtr dom,
|
||||
virTypedParameterPtr params,
|
||||
int nparams,
|
||||
unsigned int flags)
|
||||
static int
|
||||
lxcDomainSetMemoryParameters(virDomainPtr dom,
|
||||
virTypedParameterPtr params,
|
||||
int nparams,
|
||||
unsigned int flags)
|
||||
{
|
||||
lxc_driver_t *driver = dom->conn->privateData;
|
||||
int i;
|
||||
virCgroupPtr cgroup = NULL;
|
||||
virDomainObjPtr vm = NULL;
|
||||
int ret = -1;
|
||||
int rc;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
if (virTypedParameterArrayValidate(params, nparams,
|
||||
VIR_DOMAIN_MEMORY_HARD_LIMIT,
|
||||
VIR_TYPED_PARAM_ULLONG,
|
||||
VIR_DOMAIN_MEMORY_SOFT_LIMIT,
|
||||
VIR_TYPED_PARAM_ULLONG,
|
||||
VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT,
|
||||
VIR_TYPED_PARAM_ULLONG,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
lxcDriverLock(driver);
|
||||
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||
@ -813,14 +825,6 @@ static int lxcDomainSetMemoryParameters(virDomainPtr dom,
|
||||
virTypedParameterPtr param = ¶ms[i];
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT)) {
|
||||
int rc;
|
||||
if (param->type != VIR_TYPED_PARAM_ULLONG) {
|
||||
lxcError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("invalid type for memory hard_limit tunable, expected a 'ullong'"));
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = virCgroupSetMemoryHardLimit(cgroup, params[i].value.ul);
|
||||
if (rc != 0) {
|
||||
virReportSystemError(-rc, "%s",
|
||||
@ -828,14 +832,6 @@ static int lxcDomainSetMemoryParameters(virDomainPtr dom,
|
||||
ret = -1;
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT)) {
|
||||
int rc;
|
||||
if (param->type != VIR_TYPED_PARAM_ULLONG) {
|
||||
lxcError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("invalid type for memory soft_limit tunable, expected a 'ullong'"));
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = virCgroupSetMemorySoftLimit(cgroup, params[i].value.ul);
|
||||
if (rc != 0) {
|
||||
virReportSystemError(-rc, "%s",
|
||||
@ -843,28 +839,12 @@ static int lxcDomainSetMemoryParameters(virDomainPtr dom,
|
||||
ret = -1;
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT)) {
|
||||
int rc;
|
||||
if (param->type != VIR_TYPED_PARAM_ULLONG) {
|
||||
lxcError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("invalid type for swap_hard_limit tunable, expected a 'ullong'"));
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = virCgroupSetMemSwapHardLimit(cgroup, params[i].value.ul);
|
||||
if (rc != 0) {
|
||||
virReportSystemError(-rc, "%s",
|
||||
_("unable to set swap_hard_limit tunable"));
|
||||
ret = -1;
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_MIN_GUARANTEE)) {
|
||||
lxcError(VIR_ERR_INVALID_ARG,
|
||||
_("Memory tunable `%s' not implemented"), param->field);
|
||||
ret = -1;
|
||||
} else {
|
||||
lxcError(VIR_ERR_INVALID_ARG,
|
||||
_("Parameter `%s' not supported"), param->field);
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -877,10 +857,11 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int lxcDomainGetMemoryParameters(virDomainPtr dom,
|
||||
virTypedParameterPtr params,
|
||||
int *nparams,
|
||||
unsigned int flags)
|
||||
static int
|
||||
lxcDomainGetMemoryParameters(virDomainPtr dom,
|
||||
virTypedParameterPtr params,
|
||||
int *nparams,
|
||||
unsigned int flags)
|
||||
{
|
||||
lxc_driver_t *driver = dom->conn->privateData;
|
||||
int i;
|
||||
@ -919,8 +900,6 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
|
||||
for (i = 0; i < LXC_NB_MEM_PARAM && i < *nparams; i++) {
|
||||
virTypedParameterPtr param = ¶ms[i];
|
||||
val = 0;
|
||||
param->value.ul = 0;
|
||||
param->type = VIR_TYPED_PARAM_ULLONG;
|
||||
|
||||
switch(i) {
|
||||
case 0: /* fill memory hard limit here */
|
||||
@ -930,14 +909,10 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
|
||||
_("unable to get memory hard limit"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT) == NULL) {
|
||||
lxcError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("Field memory hard limit too long for destination"));
|
||||
if (virTypedParameterAssign(param, VIR_DOMAIN_MEMORY_HARD_LIMIT,
|
||||
VIR_TYPED_PARAM_ULLONG, val) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
param->value.ul = val;
|
||||
break;
|
||||
|
||||
case 1: /* fill memory soft limit here */
|
||||
rc = virCgroupGetMemorySoftLimit(cgroup, &val);
|
||||
if (rc != 0) {
|
||||
@ -945,14 +920,10 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
|
||||
_("unable to get memory soft limit"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT) == NULL) {
|
||||
lxcError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("Field memory soft limit too long for destination"));
|
||||
if (virTypedParameterAssign(param, VIR_DOMAIN_MEMORY_SOFT_LIMIT,
|
||||
VIR_TYPED_PARAM_ULLONG, val) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
param->value.ul = val;
|
||||
break;
|
||||
|
||||
case 2: /* fill swap hard limit here */
|
||||
rc = virCgroupGetMemSwapHardLimit(cgroup, &val);
|
||||
if (rc != 0) {
|
||||
@ -960,12 +931,10 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
|
||||
_("unable to get swap hard limit"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT) == NULL) {
|
||||
lxcError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("Field swap hard limit too long for destination"));
|
||||
if (virTypedParameterAssign(param,
|
||||
VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT,
|
||||
VIR_TYPED_PARAM_ULLONG, val) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
param->value.ul = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -2753,6 +2722,15 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||
if (virTypedParameterArrayValidate(params, nparams,
|
||||
VIR_DOMAIN_SCHEDULER_CPU_SHARES,
|
||||
VIR_TYPED_PARAM_ULLONG,
|
||||
VIR_DOMAIN_SCHEDULER_VCPU_PERIOD,
|
||||
VIR_TYPED_PARAM_ULLONG,
|
||||
VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
|
||||
VIR_TYPED_PARAM_LLONG,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
lxcDriverLock(driver);
|
||||
|
||||
@ -2793,12 +2771,6 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
|
||||
virTypedParameterPtr param = ¶ms[i];
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
|
||||
if (param->type != VIR_TYPED_PARAM_ULLONG) {
|
||||
lxcError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("invalid type for cpu_shares tunable, expected a 'ullong'"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||
rc = virCgroupSetCpuShares(group, params[i].value.ul);
|
||||
if (rc != 0) {
|
||||
@ -2814,13 +2786,6 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
|
||||
vmdef->cputune.shares = params[i].value.ul;
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) {
|
||||
if (param->type != VIR_TYPED_PARAM_ULLONG) {
|
||||
lxcError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("invalid type for vcpu_period tunable,"
|
||||
" expected a 'ullong'"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||
rc = lxcSetVcpuBWLive(group, params[i].value.ul, 0);
|
||||
if (rc != 0)
|
||||
@ -2834,13 +2799,6 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
|
||||
vmdef->cputune.period = params[i].value.ul;
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) {
|
||||
if (param->type != VIR_TYPED_PARAM_LLONG) {
|
||||
lxcError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("invalid type for vcpu_quota tunable,"
|
||||
" expected a 'llong'"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||
rc = lxcSetVcpuBWLive(group, 0, params[i].value.l);
|
||||
if (rc != 0)
|
||||
@ -2853,10 +2811,6 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
|
||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||
vmdef->cputune.quota = params[i].value.l;
|
||||
}
|
||||
} else {
|
||||
lxcError(VIR_ERR_INVALID_ARG,
|
||||
_("Invalid parameter `%s'"), param->field);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2968,42 +2922,25 @@ lxcGetSchedulerParametersFlags(virDomainPtr dom,
|
||||
goto cleanup;
|
||||
}
|
||||
out:
|
||||
params[0].value.ul = shares;
|
||||
params[0].type = VIR_TYPED_PARAM_ULLONG;
|
||||
if (virStrcpyStatic(params[0].field,
|
||||
VIR_DOMAIN_SCHEDULER_CPU_SHARES) == NULL) {
|
||||
lxcError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Field name '%s' too long"),
|
||||
VIR_DOMAIN_SCHEDULER_CPU_SHARES);
|
||||
if (virTypedParameterAssign(¶ms[0], VIR_DOMAIN_SCHEDULER_CPU_SHARES,
|
||||
VIR_TYPED_PARAM_ULLONG, shares) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
saved_nparams++;
|
||||
|
||||
if (cpu_bw_status) {
|
||||
if (*nparams > saved_nparams) {
|
||||
params[1].value.ul = period;
|
||||
params[1].type = VIR_TYPED_PARAM_ULLONG;
|
||||
if (virStrcpyStatic(params[1].field,
|
||||
VIR_DOMAIN_SCHEDULER_VCPU_PERIOD) == NULL) {
|
||||
lxcError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Field name '%s' too long"),
|
||||
VIR_DOMAIN_SCHEDULER_VCPU_PERIOD);
|
||||
if (virTypedParameterAssign(¶ms[1],
|
||||
VIR_DOMAIN_SCHEDULER_VCPU_PERIOD,
|
||||
VIR_TYPED_PARAM_ULLONG, period) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
saved_nparams++;
|
||||
}
|
||||
|
||||
if (*nparams > saved_nparams) {
|
||||
params[2].value.ul = quota;
|
||||
params[2].type = VIR_TYPED_PARAM_LLONG;
|
||||
if (virStrcpyStatic(params[2].field,
|
||||
VIR_DOMAIN_SCHEDULER_VCPU_QUOTA) == NULL) {
|
||||
lxcError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Field name '%s' too long"),
|
||||
VIR_DOMAIN_SCHEDULER_VCPU_QUOTA);
|
||||
if (virTypedParameterAssign(¶ms[2],
|
||||
VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
|
||||
VIR_TYPED_PARAM_LLONG, quota) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
saved_nparams++;
|
||||
}
|
||||
}
|
||||
@ -3029,10 +2966,11 @@ lxcGetSchedulerParameters(virDomainPtr domain,
|
||||
}
|
||||
|
||||
|
||||
static int lxcDomainSetBlkioParameters(virDomainPtr dom,
|
||||
virTypedParameterPtr params,
|
||||
int nparams,
|
||||
unsigned int flags)
|
||||
static int
|
||||
lxcDomainSetBlkioParameters(virDomainPtr dom,
|
||||
virTypedParameterPtr params,
|
||||
int nparams,
|
||||
unsigned int flags)
|
||||
{
|
||||
lxc_driver_t *driver = dom->conn->privateData;
|
||||
int i;
|
||||
@ -3043,6 +2981,12 @@ static int lxcDomainSetBlkioParameters(virDomainPtr dom,
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||
if (virTypedParameterArrayValidate(params, nparams,
|
||||
VIR_DOMAIN_BLKIO_WEIGHT,
|
||||
VIR_TYPED_PARAM_UINT,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
lxcDriverLock(driver);
|
||||
|
||||
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||
@ -3074,11 +3018,6 @@ static int lxcDomainSetBlkioParameters(virDomainPtr dom,
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) {
|
||||
int rc;
|
||||
if (param->type != VIR_TYPED_PARAM_UINT) {
|
||||
lxcError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("invalid type for blkio weight tunable, expected a 'unsigned int'"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (params[i].value.ui > 1000 || params[i].value.ui < 100) {
|
||||
lxcError(VIR_ERR_INVALID_ARG, "%s",
|
||||
@ -3092,10 +3031,6 @@ static int lxcDomainSetBlkioParameters(virDomainPtr dom,
|
||||
_("unable to set blkio weight tunable"));
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
lxcError(VIR_ERR_INVALID_ARG,
|
||||
_("Parameter `%s' not supported"), param->field);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3107,12 +3042,6 @@ static int lxcDomainSetBlkioParameters(virDomainPtr dom,
|
||||
virTypedParameterPtr param = ¶ms[i];
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) {
|
||||
if (param->type != VIR_TYPED_PARAM_UINT) {
|
||||
lxcError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("invalid type for blkio weight tunable, expected a 'unsigned int'"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (params[i].value.ui > 1000 || params[i].value.ui < 100) {
|
||||
lxcError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("out of blkio weight range."));
|
||||
@ -3120,10 +3049,6 @@ static int lxcDomainSetBlkioParameters(virDomainPtr dom,
|
||||
}
|
||||
|
||||
persistentDef->blkio.weight = params[i].value.ui;
|
||||
} else {
|
||||
lxcError(VIR_ERR_INVALID_ARG,
|
||||
_("Parameter `%s' not supported"), param->field);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3142,10 +3067,11 @@ cleanup:
|
||||
|
||||
|
||||
#define LXC_NB_BLKIO_PARAM 1
|
||||
static int lxcDomainGetBlkioParameters(virDomainPtr dom,
|
||||
virTypedParameterPtr params,
|
||||
int *nparams,
|
||||
unsigned int flags)
|
||||
static int
|
||||
lxcDomainGetBlkioParameters(virDomainPtr dom,
|
||||
virTypedParameterPtr params,
|
||||
int *nparams,
|
||||
unsigned int flags)
|
||||
{
|
||||
lxc_driver_t *driver = dom->conn->privateData;
|
||||
int i;
|
||||
@ -3194,8 +3120,6 @@ static int lxcDomainGetBlkioParameters(virDomainPtr dom,
|
||||
for (i = 0; i < *nparams && i < LXC_NB_BLKIO_PARAM; i++) {
|
||||
virTypedParameterPtr param = ¶ms[i];
|
||||
val = 0;
|
||||
param->value.ui = 0;
|
||||
param->type = VIR_TYPED_PARAM_UINT;
|
||||
|
||||
switch (i) {
|
||||
case 0: /* fill blkio weight here */
|
||||
@ -3205,13 +3129,9 @@ static int lxcDomainGetBlkioParameters(virDomainPtr dom,
|
||||
_("unable to get blkio weight"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) {
|
||||
lxcError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Field name '%s' too long"),
|
||||
VIR_DOMAIN_BLKIO_WEIGHT);
|
||||
if (virTypedParameterAssign(param, VIR_DOMAIN_BLKIO_WEIGHT,
|
||||
VIR_TYPED_PARAM_UINT, val) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
param->value.ui = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -3222,19 +3142,13 @@ static int lxcDomainGetBlkioParameters(virDomainPtr dom,
|
||||
} else if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||
for (i = 0; i < *nparams && i < LXC_NB_BLKIO_PARAM; i++) {
|
||||
virTypedParameterPtr param = ¶ms[i];
|
||||
val = 0;
|
||||
param->value.ui = 0;
|
||||
param->type = VIR_TYPED_PARAM_UINT;
|
||||
|
||||
switch (i) {
|
||||
case 0: /* fill blkio weight here */
|
||||
if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) {
|
||||
lxcError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Field name '%s' too long"),
|
||||
VIR_DOMAIN_BLKIO_WEIGHT);
|
||||
if (virTypedParameterAssign(param, VIR_DOMAIN_BLKIO_WEIGHT,
|
||||
VIR_TYPED_PARAM_UINT,
|
||||
persistentDef->blkio.weight) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
param->value.ui = persistentDef->blkio.weight;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -50,6 +50,7 @@
|
||||
#include "threads.h"
|
||||
#include "logging.h"
|
||||
#include "virfile.h"
|
||||
#include "virtypedparam.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_TEST
|
||||
|
||||
@ -2691,16 +2692,11 @@ testDomainGetSchedulerParamsFlags(virDomainPtr domain,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virStrcpyStatic(params[0].field,
|
||||
VIR_DOMAIN_SCHEDULER_WEIGHT) == NULL) {
|
||||
testError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
|
||||
VIR_DOMAIN_SCHEDULER_WEIGHT);
|
||||
if (virTypedParameterAssign(params, VIR_DOMAIN_SCHEDULER_WEIGHT,
|
||||
VIR_TYPED_PARAM_UINT, 50) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
params[0].type = VIR_TYPED_PARAM_UINT;
|
||||
/* XXX */
|
||||
/*params[0].value.ui = privdom->weight;*/
|
||||
params[0].value.ui = 50;
|
||||
|
||||
*nparams = 1;
|
||||
ret = 0;
|
||||
@ -2730,6 +2726,11 @@ testDomainSetSchedulerParamsFlags(virDomainPtr domain,
|
||||
int ret = -1, i;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
if (virTypedParameterArrayValidate(params, nparams,
|
||||
VIR_DOMAIN_SCHEDULER_WEIGHT,
|
||||
VIR_TYPED_PARAM_UINT,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
testDriverLock(privconn);
|
||||
privdom = virDomainFindByName(&privconn->domains,
|
||||
@ -2742,16 +2743,10 @@ testDomainSetSchedulerParamsFlags(virDomainPtr domain,
|
||||
}
|
||||
|
||||
for (i = 0; i < nparams; i++) {
|
||||
if (STRNEQ(params[i].field, VIR_DOMAIN_SCHEDULER_WEIGHT)) {
|
||||
testError(VIR_ERR_INVALID_ARG, "field");
|
||||
goto cleanup;
|
||||
if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_WEIGHT)) {
|
||||
/* XXX */
|
||||
/*privdom->weight = params[i].value.ui;*/
|
||||
}
|
||||
if (params[i].type != VIR_TYPED_PARAM_UINT) {
|
||||
testError(VIR_ERR_INVALID_ARG, "type");
|
||||
goto cleanup;
|
||||
}
|
||||
/* XXX */
|
||||
/*privdom->weight = params[i].value.ui;*/
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* xen_internal.c: direct access to Xen hypervisor level
|
||||
*
|
||||
* Copyright (C) 2005-2011 Red Hat, Inc.
|
||||
* Copyright (C) 2005-2012 Red Hat, Inc.
|
||||
*
|
||||
* See COPYING.LIB for the License of this software
|
||||
*
|
||||
@ -67,6 +67,7 @@
|
||||
#include "memory.h"
|
||||
#include "virfile.h"
|
||||
#include "virnodesuspend.h"
|
||||
#include "virtypedparam.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_XEN
|
||||
|
||||
@ -1335,27 +1336,18 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain,
|
||||
if (ret < 0)
|
||||
return(-1);
|
||||
|
||||
if (virStrcpyStatic(params[0].field,
|
||||
VIR_DOMAIN_SCHEDULER_WEIGHT) == NULL) {
|
||||
virXenError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Weight %s too big for destination",
|
||||
VIR_DOMAIN_SCHEDULER_WEIGHT);
|
||||
if (virTypedParameterAssign(¶ms[0],
|
||||
VIR_DOMAIN_SCHEDULER_WEIGHT,
|
||||
VIR_TYPED_PARAM_UINT,
|
||||
op_dom.u.getschedinfo.u.credit.weight) < 0)
|
||||
return -1;
|
||||
}
|
||||
params[0].type = VIR_TYPED_PARAM_UINT;
|
||||
params[0].value.ui = op_dom.u.getschedinfo.u.credit.weight;
|
||||
|
||||
if (*nparams > 1) {
|
||||
if (virStrcpyStatic(params[1].field,
|
||||
VIR_DOMAIN_SCHEDULER_CAP) == NULL) {
|
||||
virXenError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Cap %s too big for destination",
|
||||
VIR_DOMAIN_SCHEDULER_CAP);
|
||||
if (*nparams > 1 &&
|
||||
virTypedParameterAssign(¶ms[1],
|
||||
VIR_DOMAIN_SCHEDULER_CAP,
|
||||
VIR_TYPED_PARAM_UINT,
|
||||
op_dom.u.getschedinfo.u.credit.cap) < 0)
|
||||
return -1;
|
||||
}
|
||||
params[1].type = VIR_TYPED_PARAM_UINT;
|
||||
params[1].value.ui = op_dom.u.getschedinfo.u.credit.cap;
|
||||
}
|
||||
|
||||
if (*nparams > XEN_SCHED_CRED_NPARAM)
|
||||
*nparams = XEN_SCHED_CRED_NPARAM;
|
||||
@ -1399,6 +1391,14 @@ xenHypervisorSetSchedulerParameters(virDomainPtr domain,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (virTypedParameterArrayValidate(params, nparams,
|
||||
VIR_DOMAIN_SCHEDULER_WEIGHT,
|
||||
VIR_TYPED_PARAM_UINT,
|
||||
VIR_DOMAIN_SCHEDULER_CAP,
|
||||
VIR_TYPED_PARAM_UINT,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
|
||||
if (priv->handle < 0) {
|
||||
virXenErrorFunc(VIR_ERR_INTERNAL_ERROR, __FUNCTION__,
|
||||
@ -1453,8 +1453,7 @@ xenHypervisorSetSchedulerParameters(virDomainPtr domain,
|
||||
|
||||
for (i = 0; i < nparams; i++) {
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
if (STREQ (params[i].field, VIR_DOMAIN_SCHEDULER_WEIGHT) &&
|
||||
params[i].type == VIR_TYPED_PARAM_UINT) {
|
||||
if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_WEIGHT)) {
|
||||
val = params[i].value.ui;
|
||||
if ((val < 1) || (val > USHRT_MAX)) {
|
||||
snprintf(buf, sizeof(buf), _("Credit scheduler weight parameter (%d) is out of range (1-65535)"), val);
|
||||
@ -1462,8 +1461,7 @@ xenHypervisorSetSchedulerParameters(virDomainPtr domain,
|
||||
return(-1);
|
||||
}
|
||||
op_dom.u.getschedinfo.u.credit.weight = val;
|
||||
} else if (STREQ (params[i].field, VIR_DOMAIN_SCHEDULER_CAP) &&
|
||||
params[i].type == VIR_TYPED_PARAM_UINT) {
|
||||
} else if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_CAP)) {
|
||||
val = params[i].value.ui;
|
||||
if (val >= USHRT_MAX) {
|
||||
snprintf(buf, sizeof(buf), _("Credit scheduler cap parameter (%d) is out of range (0-65534)"), val);
|
||||
@ -1471,11 +1469,6 @@ xenHypervisorSetSchedulerParameters(virDomainPtr domain,
|
||||
return(-1);
|
||||
}
|
||||
op_dom.u.getschedinfo.u.credit.cap = val;
|
||||
} else {
|
||||
virXenErrorFunc(VIR_ERR_INVALID_ARG, __FUNCTION__,
|
||||
"Credit scheduler accepts 'cap' and 'weight' integer parameters",
|
||||
0);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user