[PATCH 1/3] migration/migration: improve error reporting for migrate parameters

Mao Zhongyi posted 3 patches 5 years, 10 months ago
Maintainers: "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Juan Quintela <quintela@redhat.com>
There is a newer version of this series
[PATCH 1/3] migration/migration: improve error reporting for migrate parameters
Posted by Mao Zhongyi 5 years, 10 months ago
use QERR_INVALID_PARAMETER_VALUE instead of
"Parameter '%s' expects" for consistency.

Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
---
 migration/migration.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index 2b7b5bccfa..e0223f3b15 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1202,16 +1202,17 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp)
     }
 
     if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) {
-        error_setg(errp, "Parameter 'max_bandwidth' expects an integer in the"
-                         " range of 0 to %zu bytes/second", SIZE_MAX);
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                   "max_bandwidth",
+                   "an integer in the range of 0 to '2^64 - 1' bytes/second");
         return false;
     }
 
     if (params->has_downtime_limit &&
         (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
-        error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
-                         "the range of 0 to %d milliseconds",
-                         MAX_MIGRATE_DOWNTIME);
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                   "downtime_limit",
+                   "an integer in the range of 0 to 2000000 milliseconds");
         return false;
     }
 
@@ -2108,9 +2109,9 @@ void qmp_migrate_set_speed(int64_t value, Error **errp)
 void qmp_migrate_set_downtime(double value, Error **errp)
 {
     if (value < 0 || value > MAX_MIGRATE_DOWNTIME_SECONDS) {
-        error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
-                         "the range of 0 to %d seconds",
-                         MAX_MIGRATE_DOWNTIME_SECONDS);
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                   "downtime_limit",
+                   "an integer in the range of 0 to 2000 seconds");
         return;
     }
 
-- 
2.17.1




Re: [PATCH 1/3] migration/migration: improve error reporting for migrate parameters
Posted by Juan Quintela 5 years, 10 months ago
Mao Zhongyi <maozhongyi@cmss.chinamobile.com> wrote:
> use QERR_INVALID_PARAMETER_VALUE instead of
> "Parameter '%s' expects" for consistency.

I agree with the idea.

> Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
> ---
>  migration/migration.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/migration/migration.c b/migration/migration.c
> index 2b7b5bccfa..e0223f3b15 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -1202,16 +1202,17 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp)
>      }
>  
>      if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) {
> -        error_setg(errp, "Parameter 'max_bandwidth' expects an integer in the"
> -                         " range of 0 to %zu bytes/second", SIZE_MAX);
> +        error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
> +                   "max_bandwidth",
> +                   "an integer in the range of 0 to '2^64 - 1' bytes/second");
>          return false;
>      }

You are inlining the constants.  What about:

error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
           "max_bandwidth",
           "an integer in the range of 0 to '" stringify(SIZE_MAX)
           "'bytes/second");

Same for the others.

Thanks, Juan.