提交 7b2f20b1 编写于 作者: M Matthias Bolte

Clarify semantic of nparams argument of virDomainGetSchedulerType

Some drivers assumed it can be NULL (e.g. qemu and lxc) and check it
before assigning to it, other drivers assumed it must be non-NULL
(e.g. test and esx) and just assigned to it.

Unify this to nparams being optional and document it.
上级 ed97be61
...@@ -3513,7 +3513,9 @@ esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams) ...@@ -3513,7 +3513,9 @@ esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams)
return NULL; return NULL;
} }
*nparams = 3; /* reservation, limit, shares */ if (nparams != NULL) {
*nparams = 3; /* reservation, limit, shares */
}
return type; return type;
} }
......
...@@ -4973,9 +4973,10 @@ error: ...@@ -4973,9 +4973,10 @@ error:
/** /**
* virDomainGetSchedulerType: * virDomainGetSchedulerType:
* @domain: pointer to domain object * @domain: pointer to domain object
* @nparams: number of scheduler parameters(return value) * @nparams: pointer to number of scheduler parameters, can be NULL
* (return value)
* *
* Get the scheduler type. * Get the scheduler type and the number of scheduler parameters.
* *
* Returns NULL in case of error. The caller must free the returned string. * Returns NULL in case of error. The caller must free the returned string.
*/ */
......
...@@ -2396,14 +2396,16 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams) ...@@ -2396,14 +2396,16 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
goto cleanup; goto cleanup;
} }
*nparams = 0; if (nparams)
*nparams = 0;
switch(sched_id) { switch(sched_id) {
case XEN_SCHEDULER_SEDF: case XEN_SCHEDULER_SEDF:
ret = strdup("sedf"); ret = strdup("sedf");
break; break;
case XEN_SCHEDULER_CREDIT: case XEN_SCHEDULER_CREDIT:
ret = strdup("credit"); ret = strdup("credit");
*nparams = XEN_SCHED_CREDIT_NPARAM; if (nparams)
*nparams = XEN_SCHED_CREDIT_NPARAM;
break; break;
case XEN_SCHEDULER_CREDIT2: case XEN_SCHEDULER_CREDIT2:
ret = strdup("credit2"); ret = strdup("credit2");
......
...@@ -2624,7 +2624,9 @@ static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, ...@@ -2624,7 +2624,9 @@ static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED,
{ {
char *type = NULL; char *type = NULL;
*nparams = 1; if (nparams)
*nparams = 1;
type = strdup("fair"); type = strdup("fair");
if (!type) if (!type)
virReportOOMError(); virReportOOMError();
......
...@@ -3531,8 +3531,7 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams) ...@@ -3531,8 +3531,7 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams)
const char *ret = NULL; const char *ret = NULL;
char *schedulertype = NULL; char *schedulertype = NULL;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) if (domain->conn == NULL || domain->name == NULL) {
|| (nparams == NULL)) {
virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__);
return NULL; return NULL;
} }
...@@ -3562,14 +3561,16 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams) ...@@ -3562,14 +3561,16 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams)
virReportOOMError(); virReportOOMError();
goto error; goto error;
} }
*nparams = XEN_SCHED_CRED_NPARAM; if (nparams)
*nparams = XEN_SCHED_CRED_NPARAM;
} else if (STREQ (ret, "sedf")) { } else if (STREQ (ret, "sedf")) {
schedulertype = strdup("sedf"); schedulertype = strdup("sedf");
if (schedulertype == NULL){ if (schedulertype == NULL){
virReportOOMError(); virReportOOMError();
goto error; goto error;
} }
*nparams = XEN_SCHED_SEDF_NPARAM; if (nparams)
*nparams = XEN_SCHED_SEDF_NPARAM;
} else { } else {
virXendError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unknown scheduler")); virXendError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unknown scheduler"));
goto error; goto error;
......
...@@ -1767,7 +1767,9 @@ static char * ...@@ -1767,7 +1767,9 @@ static char *
xenapiDomainGetSchedulerType (virDomainPtr dom ATTRIBUTE_UNUSED, int *nparams) xenapiDomainGetSchedulerType (virDomainPtr dom ATTRIBUTE_UNUSED, int *nparams)
{ {
char *result = NULL; char *result = NULL;
*nparams = 0;
if (nparams)
*nparams = 0;
if (!(result = strdup("credit"))) if (!(result = strdup("credit")))
virReportOOMError(); virReportOOMError();
return result; return result;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册