提交 e430c0d0 编写于 作者: M Matthias Bolte

Clarify the semantic of virDomainGetSchedulerParameters arguments

params and nparams are essential and cannot be NULL. Check this in
libvirt.c and remove redundant checks from the drivers (e.g. xend).

Instead of enforcing that nparams must point to exact same value as
returned by virDomainGetSchedulerType relax this to a lower bound
check. This is what some drivers (e.g. xen hypervisor and esx)
already did. Other drivers (e.g. xend) didn't check nparams at all
and assumed that there is enough space in params.

Unify the behavior in all drivers to a lower bound check and update
nparams to the number of valid values in params on success.
上级 7b2f20b1
...@@ -5015,14 +5015,15 @@ error: ...@@ -5015,14 +5015,15 @@ error:
/** /**
* virDomainGetSchedulerParameters: * virDomainGetSchedulerParameters:
* @domain: pointer to domain object * @domain: pointer to domain object
* @params: pointer to scheduler parameter object * @params: pointer to scheduler parameter objects
* (return value) * (return value)
* @nparams: pointer to number of scheduler parameter * @nparams: pointer to number of scheduler parameter objects
* (this value should be same than the returned value * (this value must be at least as large as the returned value
* nparams of virDomainGetSchedulerType) * nparams of virDomainGetSchedulerType)
* *
* Get the scheduler parameters, the @params array will be filled with the * Get all scheduler parameters, the @params array will be filled with the
* values. * values and @nparams will be updated to the number of valid elements in
* @params.
* *
* Returns -1 in case of error, 0 in case of success. * Returns -1 in case of error, 0 in case of success.
*/ */
...@@ -5041,6 +5042,12 @@ virDomainGetSchedulerParameters(virDomainPtr domain, ...@@ -5041,6 +5042,12 @@ virDomainGetSchedulerParameters(virDomainPtr domain,
virDispatchError(NULL); virDispatchError(NULL);
return -1; return -1;
} }
if (params == NULL || nparams == NULL || *nparams <= 0) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
conn = domain->conn; conn = domain->conn;
if (conn->driver->domainGetSchedulerParameters) { if (conn->driver->domainGetSchedulerParameters) {
......
...@@ -2466,7 +2466,7 @@ libxlDomainGetSchedulerParameters(virDomainPtr dom, virSchedParameterPtr params, ...@@ -2466,7 +2466,7 @@ libxlDomainGetSchedulerParameters(virDomainPtr dom, virSchedParameterPtr params,
goto cleanup; goto cleanup;
} }
if (*nparams != XEN_SCHED_CREDIT_NPARAM) { if (*nparams < XEN_SCHED_CREDIT_NPARAM) {
libxlError(VIR_ERR_INVALID_ARG, "%s", _("Invalid parameter count")); libxlError(VIR_ERR_INVALID_ARG, "%s", _("Invalid parameter count"));
goto cleanup; goto cleanup;
} }
...@@ -2494,6 +2494,7 @@ libxlDomainGetSchedulerParameters(virDomainPtr dom, virSchedParameterPtr params, ...@@ -2494,6 +2494,7 @@ libxlDomainGetSchedulerParameters(virDomainPtr dom, virSchedParameterPtr params,
goto cleanup; goto cleanup;
} }
*nparams = XEN_SCHED_CREDIT_NPARAM;
ret = 0; ret = 0;
cleanup: cleanup:
......
...@@ -2234,7 +2234,7 @@ static int lxcGetSchedulerParameters(virDomainPtr domain, ...@@ -2234,7 +2234,7 @@ static int lxcGetSchedulerParameters(virDomainPtr domain,
if (driver->cgroup == NULL) if (driver->cgroup == NULL)
return -1; return -1;
if ((*nparams) != 1) { if (*nparams < 1) {
lxcError(VIR_ERR_INVALID_ARG, lxcError(VIR_ERR_INVALID_ARG,
"%s", _("Invalid parameter count")); "%s", _("Invalid parameter count"));
return -1; return -1;
...@@ -2264,6 +2264,7 @@ static int lxcGetSchedulerParameters(virDomainPtr domain, ...@@ -2264,6 +2264,7 @@ static int lxcGetSchedulerParameters(virDomainPtr domain,
} }
params[0].type = VIR_DOMAIN_SCHED_FIELD_ULLONG; params[0].type = VIR_DOMAIN_SCHED_FIELD_ULLONG;
*nparams = 1;
ret = 0; ret = 0;
cleanup: cleanup:
......
...@@ -5181,7 +5181,7 @@ static int qemuGetSchedulerParameters(virDomainPtr dom, ...@@ -5181,7 +5181,7 @@ static int qemuGetSchedulerParameters(virDomainPtr dom,
goto cleanup; goto cleanup;
} }
if ((*nparams) != 1) { if (*nparams < 1) {
qemuReportError(VIR_ERR_INVALID_ARG, qemuReportError(VIR_ERR_INVALID_ARG,
"%s", _("Invalid parameter count")); "%s", _("Invalid parameter count"));
goto cleanup; goto cleanup;
...@@ -5221,6 +5221,7 @@ out: ...@@ -5221,6 +5221,7 @@ out:
goto cleanup; goto cleanup;
} }
*nparams = 1;
ret = 0; ret = 0;
cleanup: cleanup:
......
...@@ -2652,8 +2652,8 @@ static int testDomainGetSchedulerParams(virDomainPtr domain, ...@@ -2652,8 +2652,8 @@ static int testDomainGetSchedulerParams(virDomainPtr domain,
goto cleanup; goto cleanup;
} }
if (*nparams != 1) { if (*nparams < 1) {
testError(VIR_ERR_INVALID_ARG, "nparams"); testError(VIR_ERR_INVALID_ARG, "%s", _("Invalid parameter count"));
goto cleanup; goto cleanup;
} }
strcpy(params[0].field, "weight"); strcpy(params[0].field, "weight");
...@@ -2661,6 +2661,8 @@ static int testDomainGetSchedulerParams(virDomainPtr domain, ...@@ -2661,6 +2661,8 @@ static int testDomainGetSchedulerParams(virDomainPtr domain,
/* XXX */ /* XXX */
/*params[0].value.ui = privdom->weight;*/ /*params[0].value.ui = privdom->weight;*/
params[0].value.ui = 50; params[0].value.ui = 50;
*nparams = 1;
ret = 0; ret = 0;
cleanup: cleanup:
......
...@@ -60,6 +60,9 @@ extern int xenRegister (void); ...@@ -60,6 +60,9 @@ extern int xenRegister (void);
# define XEND_DOMAINS_DIR "/var/lib/xend/domains" # define XEND_DOMAINS_DIR "/var/lib/xend/domains"
# define XEN_SCHED_SEDF_NPARAM 6
# define XEN_SCHED_CRED_NPARAM 2
/* _xenUnifiedDriver: /* _xenUnifiedDriver:
* *
* Entry points into the underlying Xen drivers. This structure * Entry points into the underlying Xen drivers. This structure
......
...@@ -1207,14 +1207,14 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams) ...@@ -1207,14 +1207,14 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams)
if (schedulertype == NULL) if (schedulertype == NULL)
virReportOOMError(); virReportOOMError();
if (nparams) if (nparams)
*nparams = 6; *nparams = XEN_SCHED_SEDF_NPARAM;
break; break;
case XEN_SCHEDULER_CREDIT: case XEN_SCHEDULER_CREDIT:
schedulertype = strdup("credit"); schedulertype = strdup("credit");
if (schedulertype == NULL) if (schedulertype == NULL)
virReportOOMError(); virReportOOMError();
if (nparams) if (nparams)
*nparams = 2; *nparams = XEN_SCHED_CRED_NPARAM;
break; break;
default: default:
break; break;
...@@ -1232,8 +1232,8 @@ static const char *str_cap = "cap"; ...@@ -1232,8 +1232,8 @@ static const char *str_cap = "cap";
* @domain: pointer to the Xen Hypervisor block * @domain: pointer to the Xen Hypervisor block
* @params: pointer to scheduler parameters. * @params: pointer to scheduler parameters.
* This memory area should be allocated before calling. * This memory area should be allocated before calling.
* @nparams:this parameter should be same as * @nparams: this parameter must be at least as large as
* a given number of scheduler parameters. * the given number of scheduler parameters.
* from xenHypervisorGetSchedulerType(). * from xenHypervisorGetSchedulerType().
* *
* Do a low level hypercall to get scheduler parameters * Do a low level hypercall to get scheduler parameters
...@@ -1288,12 +1288,21 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain, ...@@ -1288,12 +1288,21 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain,
switch (op_sys.u.getschedulerid.sched_id){ switch (op_sys.u.getschedulerid.sched_id){
case XEN_SCHEDULER_SEDF: case XEN_SCHEDULER_SEDF:
if (*nparams < XEN_SCHED_SEDF_NPARAM) {
virXenError(VIR_ERR_INVALID_ARG,
"%s", _("Invalid parameter count"));
return -1;
}
/* TODO: Implement for Xen/SEDF */ /* TODO: Implement for Xen/SEDF */
TODO TODO
return(-1); return(-1);
case XEN_SCHEDULER_CREDIT: case XEN_SCHEDULER_CREDIT:
if (*nparams < 2) if (*nparams < XEN_SCHED_CRED_NPARAM) {
return(-1); virXenError(VIR_ERR_INVALID_ARG,
"%s", _("Invalid parameter count"));
return -1;
}
memset(&op_dom, 0, sizeof(op_dom)); memset(&op_dom, 0, sizeof(op_dom));
op_dom.cmd = XEN_V2_OP_SCHEDULER; op_dom.cmd = XEN_V2_OP_SCHEDULER;
op_dom.domain = (domid_t) domain->id; op_dom.domain = (domid_t) domain->id;
...@@ -1319,7 +1328,7 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain, ...@@ -1319,7 +1328,7 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain,
params[1].type = VIR_DOMAIN_SCHED_FIELD_UINT; params[1].type = VIR_DOMAIN_SCHED_FIELD_UINT;
params[1].value.ui = op_dom.u.getschedinfo.u.credit.cap; params[1].value.ui = op_dom.u.getschedinfo.u.credit.cap;
*nparams = 2; *nparams = XEN_SCHED_CRED_NPARAM;
break; break;
default: default:
virXenErrorFunc(VIR_ERR_INVALID_ARG, __FUNCTION__, virXenErrorFunc(VIR_ERR_INVALID_ARG, __FUNCTION__,
......
...@@ -55,8 +55,6 @@ ...@@ -55,8 +55,6 @@
/* /*
* The number of Xen scheduler parameters * The number of Xen scheduler parameters
*/ */
#define XEN_SCHED_SEDF_NPARAM 6
#define XEN_SCHED_CRED_NPARAM 2
#define XEND_RCV_BUF_MAX_LEN 65536 #define XEND_RCV_BUF_MAX_LEN 65536
...@@ -3607,8 +3605,7 @@ xenDaemonGetSchedulerParameters(virDomainPtr domain, ...@@ -3607,8 +3605,7 @@ xenDaemonGetSchedulerParameters(virDomainPtr domain,
int sched_nparam = 0; int sched_nparam = 0;
int ret = -1; int ret = -1;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
|| (params == NULL) || (nparams == NULL)) {
virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__);
return (-1); return (-1);
} }
...@@ -3636,10 +3633,22 @@ xenDaemonGetSchedulerParameters(virDomainPtr domain, ...@@ -3636,10 +3633,22 @@ xenDaemonGetSchedulerParameters(virDomainPtr domain,
switch (sched_nparam){ switch (sched_nparam){
case XEN_SCHED_SEDF_NPARAM: case XEN_SCHED_SEDF_NPARAM:
if (*nparams < XEN_SCHED_SEDF_NPARAM) {
virXendError(VIR_ERR_INVALID_ARG,
"%s", _("Invalid parameter count"));
goto error;
}
/* TODO: Implement for Xen/SEDF */ /* TODO: Implement for Xen/SEDF */
TODO TODO
goto error; goto error;
case XEN_SCHED_CRED_NPARAM: case XEN_SCHED_CRED_NPARAM:
if (*nparams < XEN_SCHED_CRED_NPARAM) {
virXendError(VIR_ERR_INVALID_ARG,
"%s", _("Invalid parameter count"));
goto error;
}
/* get cpu_weight/cpu_cap from xend/domain */ /* get cpu_weight/cpu_cap from xend/domain */
if (sexpr_node(root, "domain/cpu_weight") == NULL) { if (sexpr_node(root, "domain/cpu_weight") == NULL) {
virXendError(VIR_ERR_INTERNAL_ERROR, virXendError(VIR_ERR_INTERNAL_ERROR,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册