mirror of https://github.com/xemu-project/xemu.git
migration: introduce migrate_params_check()
Helper to check the parameters. Abstracted from qmp_migrate_set_parameters(). Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <1500349150-13240-5-git-send-email-peterx@redhat.com> Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
parent
2081475841
commit
16d063bc2a
|
@ -644,64 +644,86 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
|
/*
|
||||||
|
* Check whether the parameters are valid. Error will be put into errp
|
||||||
|
* (if provided). Return true if valid, otherwise false.
|
||||||
|
*/
|
||||||
|
static bool migrate_params_check(MigrationParameters *params, Error **errp)
|
||||||
{
|
{
|
||||||
MigrationState *s = migrate_get_current();
|
|
||||||
|
|
||||||
if (params->has_compress_level &&
|
if (params->has_compress_level &&
|
||||||
(params->compress_level < 0 || params->compress_level > 9)) {
|
(params->compress_level < 0 || params->compress_level > 9)) {
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level",
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level",
|
||||||
"is invalid, it should be in the range of 0 to 9");
|
"is invalid, it should be in the range of 0 to 9");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->has_compress_threads &&
|
if (params->has_compress_threads &&
|
||||||
(params->compress_threads < 1 || params->compress_threads > 255)) {
|
(params->compress_threads < 1 || params->compress_threads > 255)) {
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
||||||
"compress_threads",
|
"compress_threads",
|
||||||
"is invalid, it should be in the range of 1 to 255");
|
"is invalid, it should be in the range of 1 to 255");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->has_decompress_threads &&
|
if (params->has_decompress_threads &&
|
||||||
(params->decompress_threads < 1 || params->decompress_threads > 255)) {
|
(params->decompress_threads < 1 || params->decompress_threads > 255)) {
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
||||||
"decompress_threads",
|
"decompress_threads",
|
||||||
"is invalid, it should be in the range of 1 to 255");
|
"is invalid, it should be in the range of 1 to 255");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->has_cpu_throttle_initial &&
|
if (params->has_cpu_throttle_initial &&
|
||||||
(params->cpu_throttle_initial < 1 ||
|
(params->cpu_throttle_initial < 1 ||
|
||||||
params->cpu_throttle_initial > 99)) {
|
params->cpu_throttle_initial > 99)) {
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
||||||
"cpu_throttle_initial",
|
"cpu_throttle_initial",
|
||||||
"an integer in the range of 1 to 99");
|
"an integer in the range of 1 to 99");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->has_cpu_throttle_increment &&
|
if (params->has_cpu_throttle_increment &&
|
||||||
(params->cpu_throttle_increment < 1 ||
|
(params->cpu_throttle_increment < 1 ||
|
||||||
params->cpu_throttle_increment > 99)) {
|
params->cpu_throttle_increment > 99)) {
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
||||||
"cpu_throttle_increment",
|
"cpu_throttle_increment",
|
||||||
"an integer in the range of 1 to 99");
|
"an integer in the range of 1 to 99");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->has_max_bandwidth &&
|
if (params->has_max_bandwidth &&
|
||||||
(params->max_bandwidth < 0 || params->max_bandwidth > SIZE_MAX)) {
|
(params->max_bandwidth < 0 || params->max_bandwidth > SIZE_MAX)) {
|
||||||
error_setg(errp, "Parameter 'max_bandwidth' expects an integer in the"
|
error_setg(errp, "Parameter 'max_bandwidth' expects an integer in the"
|
||||||
" range of 0 to %zu bytes/second", SIZE_MAX);
|
" range of 0 to %zu bytes/second", SIZE_MAX);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->has_downtime_limit &&
|
if (params->has_downtime_limit &&
|
||||||
(params->downtime_limit < 0 ||
|
(params->downtime_limit < 0 ||
|
||||||
params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
|
params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
|
||||||
error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
|
error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
|
||||||
"the range of 0 to %d milliseconds",
|
"the range of 0 to %d milliseconds",
|
||||||
MAX_MIGRATE_DOWNTIME);
|
MAX_MIGRATE_DOWNTIME);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->has_x_checkpoint_delay && (params->x_checkpoint_delay < 0)) {
|
if (params->has_x_checkpoint_delay && (params->x_checkpoint_delay < 0)) {
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
||||||
"x_checkpoint_delay",
|
"x_checkpoint_delay",
|
||||||
"is invalid, it should be positive");
|
"is invalid, it should be positive");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
|
||||||
|
{
|
||||||
|
MigrationState *s = migrate_get_current();
|
||||||
|
|
||||||
|
if (!migrate_params_check(params, errp)) {
|
||||||
|
/* Invalid parameter */
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->has_compress_level) {
|
if (params->has_compress_level) {
|
||||||
|
|
Loading…
Reference in New Issue