migration: Fixes and cleanups aroung migrate-set-parameters
v2 cover migration: Fixes and cleanups aroung migrate-set-parameters
v2:
* Rebased
* PATCH 1 dropped. Fixes a crash bug. Daniel asked me to modify the fix. Unfortunately, I don't understand this anymore, and don't have the time & energy to start over.
* PATCH 4 dropped. Plugs a hole in input validation. David pointed asked me to additionally fix an error message, but I don't quite understand what he wants.
We can discuss what to do about the dropped patches, but I don't want to hold the remainder of the series any longer just for that.
Markus Armbruster (4):
migration: Fix migrate-set-parameters argument validation
migration: Clean up signed vs. unsigned XBZRLE cache-size
migration: Fix cache_init()'s "Failed to allocate" error messages
migration: Fix a few absurdly defective error messages
qapi/migration.json | 32 ++++++++++++++++---------------- migration/migration.h | 2 +- migration/page_cache.h | 2 +- migration/ram.h | 2 +- migration/migration.c | 27 +++++++++++++-------------- migration/page_cache.c | 8 +++----- migration/ram.c | 2 +- monitor/hmp-cmds.c | 24 ++++++++++++------------ 8 files changed, 48 insertions(+), 51 deletions(-)
Signature · 1 line
2.26.2
PATCH v2 1/4 migration: Fix migrate-set-parameters argument validation
Commit 741d4086c8 "migration: Use proper types in json" (v2.12.0) switched MigrationParameters to narrower integer types, and removed the simplified qmp_migrate_set_parameters()'s argument checking accordingly.
Good idea, except qmp_migrate_set_parameters() takes MigrateSetParameters, not MigrationParameters. Its job is updating migrate_get_current()->parameters (which *is* of type MigrationParameters) according to its argument. The integers now get truncated silently. Reproducer:
---> {'execute': 'query-migrate-parameters'}
<--- {"return": {[...] "compress-threads": 8, [...]}}
---> {"execute": "migrate-set-parameters", "arguments": {"compress-threads": 257}}
<--- {"return": {}}
---> {'execute': 'query-migrate-parameters'}
<--- {"return": {[...] "compress-threads": 1, [...]}}Fix by resynchronizing MigrateSetParameters with MigrationParameters.
--- qapi/migration.json | 28 ++++++++++++++-------------- monitor/hmp-cmds.c | 24 ++++++++++++------------ 2 files changed, 26 insertions(+), 26 deletions(-)
qapi/migration.json +14 -14
@@ -885,28 +885,28 @@ '*announce-max': 'size', '*announce-rounds': 'size', '*announce-step': 'size', - '*compress-level': 'int', - '*compress-threads': 'int', + '*compress-level': 'uint8', + '*compress-threads': 'uint8', '*compress-wait-thread': 'bool', - '*decompress-threads': 'int', - '*throttle-trigger-threshold': 'int', - '*cpu-throttle-initial': 'int', - '*cpu-throttle-increment': 'int', + '*decompress-threads': 'uint8', + '*throttle-trigger-threshold': 'uint8', + '*cpu-throttle-initial': 'uint8', + '*cpu-throttle-increment': 'uint8', '*cpu-throttle-tailslow': 'bool', '*tls-creds': 'StrOrNull', '*tls-hostname': 'StrOrNull', '*tls-authz': 'StrOrNull', - '*max-bandwidth': 'int', - '*downtime-limit': 'int', - '*x-checkpoint-delay': 'int', + '*max-bandwidth': 'size', + '*downtime-limit': 'uint64', + '*x-checkpoint-delay': 'uint32', '*block-incremental': 'bool', - '*multifd-channels': 'int', + '*multifd-channels': 'uint8', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle': 'int', + '*max-cpu-throttle': 'uint8', '*multifd-compression': 'MultiFDCompression', - '*multifd-zlib-level': 'int', - '*multifd-zstd-level': 'int', + '*multifd-zlib-level': 'uint8', + '*multifd-zstd-level': 'uint8', '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } ##
@@ -1093,7 +1093,7 @@ '*max-bandwidth': 'size', '*downtime-limit': 'uint64', '*x-checkpoint-delay': 'uint32', - '*block-incremental': 'bool' , + '*block-incremental': 'bool', '*multifd-channels': 'uint8', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size',
monitor/hmp-cmds.c +12 -12
@@ -1294,11 +1294,11 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)switch (val) {case MIGRATION_PARAMETER_COMPRESS_LEVEL : p->has_compress_level = true; -visit_type_int (v, param, &p->compress_level, &err); +visit_type_uint8 (v, param, &p->compress_level, &err);break ;case MIGRATION_PARAMETER_COMPRESS_THREADS : p->has_compress_threads = true; -visit_type_int (v, param, &p->compress_threads, &err); +visit_type_uint8 (v, param, &p->compress_threads, &err);break ;case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD : p->has_compress_wait_thread = true;
@@ -1306,19 +1306,19 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)break ;case MIGRATION_PARAMETER_DECOMPRESS_THREADS : p->has_decompress_threads = true; -visit_type_int (v, param, &p->decompress_threads, &err); +visit_type_uint8 (v, param, &p->decompress_threads, &err);break ;case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD : p->has_throttle_trigger_threshold = true; -visit_type_int (v, param, &p->throttle_trigger_threshold, &err); +visit_type_uint8 (v, param, &p->throttle_trigger_threshold, &err);break ;case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL : p->has_cpu_throttle_initial = true; -visit_type_int (v, param, &p->cpu_throttle_initial, &err); +visit_type_uint8 (v, param, &p->cpu_throttle_initial, &err);break ;case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT : p->has_cpu_throttle_increment = true; -visit_type_int (v, param, &p->cpu_throttle_increment, &err); +visit_type_uint8 (v, param, &p->cpu_throttle_increment, &err);break ;case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW : p->has_cpu_throttle_tailslow = true;
@@ -1326,7 +1326,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)break ;case MIGRATION_PARAMETER_MAX_CPU_THROTTLE : p->has_max_cpu_throttle = true; -visit_type_int (v, param, &p->max_cpu_throttle, &err); +visit_type_uint8 (v, param, &p->max_cpu_throttle, &err);break ;case MIGRATION_PARAMETER_TLS_CREDS : p->has_tls_creds = true;
@@ -1362,11 +1362,11 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)break ;case MIGRATION_PARAMETER_DOWNTIME_LIMIT : p->has_downtime_limit = true; -visit_type_int (v, param, &p->downtime_limit, &err); +visit_type_size (v, param, &p->downtime_limit, &err);break ;case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY : p->has_x_checkpoint_delay = true; -visit_type_int (v, param, &p->x_checkpoint_delay, &err); +visit_type_uint32 (v, param, &p->x_checkpoint_delay, &err);break ;case MIGRATION_PARAMETER_BLOCK_INCREMENTAL : p->has_block_incremental = true;
@@ -1374,7 +1374,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)break ;case MIGRATION_PARAMETER_MULTIFD_CHANNELS : p->has_multifd_channels = true; -visit_type_int (v, param, &p->multifd_channels, &err); +visit_type_uint8 (v, param, &p->multifd_channels, &err);break ;case MIGRATION_PARAMETER_MULTIFD_COMPRESSION : p->has_multifd_compression = true;
@@ -1383,11 +1383,11 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)break ;case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL : p->has_multifd_zlib_level = true; -visit_type_int (v, param, &p->multifd_zlib_level, &err); +visit_type_uint8 (v, param, &p->multifd_zlib_level, &err);break ;case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL : p->has_multifd_zstd_level = true; -visit_type_int (v, param, &p->multifd_zstd_level, &err); +visit_type_uint8 (v, param, &p->multifd_zstd_level, &err);break ;case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE : p->has_xbzrle_cache_size = true;
Signature · 1 line
2.26.2
PATCH v2 2/4 migration: Clean up signed vs. unsigned XBZRLE cache-size
In reply to Markus Armbruster73af8dd8d7 "migration: Make xbzrle_cache_size a migration parameter" (v2.11.0) made the new parameter unsigned (QAPI type 'size', uint64_t in C). It neglected to update existing code, which continues to use int64_t.
migrate_xbzrle_cache_size() returns the new parameter. Adjust its return type.
QMP query-migrate-cache-size returns migrate_xbzrle_cache_size(). Adjust its return type.
migrate-set-parameters passes the new parameter to xbzrle_cache_resize(). Adjust its parameter type.
xbzrle_cache_resize() passes it on to cache_init(). Adjust its parameter type.
--- qapi/migration.json | 4 ++-- migration/migration.h | 2 +- migration/page_cache.h | 2 +- migration/ram.h | 2 +- migration/migration.c | 4 ++-- migration/page_cache.c | 2 +- migration/ram.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-)
qapi/migration.json +2 -2
@@ -78,7 +78,7 @@ # Since: 1.2 ## { 'struct': 'XBZRLECacheStats', - 'data': {'cache-size': 'int', 'bytes': 'int', 'pages': 'int', + 'data': {'cache-size': 'size', 'bytes': 'int', 'pages': 'int', 'cache-miss': 'int', 'cache-miss-rate': 'number', 'encoding-rate': 'number', 'overflow': 'int' } }
@@ -1465,7 +1465,7 @@ # <- { "return": 67108864 } # ## -{ 'command': 'query-migrate-cache-size', 'returns': 'int', +{ 'command': 'query-migrate-cache-size', 'returns': 'size', 'features': [ 'deprecated' ] } ##
migration/migration.h +1 -1
@@ -324,7 +324,7 @@ int migrate_multifd_zlib_level(void);int migrate_multifd_zstd_level (void );int migrate_use_xbzrle (void ); -int64_t migrate_xbzrle_cache_size (void ); +uint64_t migrate_xbzrle_cache_size (void );bool migrate_colo_enabled (void );bool migrate_use_block (void );
migration/page_cache.h +1 -1
@@ -28,7 +28,7 @@ typedef struct PageCache PageCache;* @page_size: cache page size * @errp: set *errp if the check failed, with reason */ -PageCache *cache_init (int64_t cache_size,size_t page_size,Error **errp); +PageCache *cache_init (uint64_t cache_size,size_t page_size,Error **errp);/** * cache_fini: free all cache resources * @cache pointer to the PageCache struct
migration/ram.h +1 -1
@@ -47,7 +47,7 @@ bool ramblock_is_ignored(RAMBlock *block);INTERNAL_RAMBLOCK_FOREACH (block) \ if (!qemu_ram_is_migratable(block)) {} else -int xbzrle_cache_resize(int64_t new_size, Error **errp); +int xbzrle_cache_resize(uint64_t new_size, Error **errp);uint64_t ram_bytes_remaining (void );uint64_t ram_bytes_total (void );
migration/migration.c +2 -2
@@ -2216,7 +2216,7 @@ void qmp_migrate_set_cache_size(int64_t value, Error **errp)qmp_migrate_set_parameters (&p, errp); } -int64_t qmp_query_migrate_cache_size (Error **errp) +uint64_t qmp_query_migrate_cache_size (Error **errp) {return migrate_xbzrle_cache_size (); }
@@ -2446,7 +2446,7 @@ int migrate_use_xbzrle(void)return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE ]; } -int64_t migrate_xbzrle_cache_size (void ) +uint64_t migrate_xbzrle_cache_size (void ) {MigrationState *s;
migration/page_cache.c +1 -1
@@ -38,7 +38,7 @@ struct PageCache {size_t num_items; }; -PageCache *cache_init (int64_t new_size,size_t page_size,Error **errp) +PageCache *cache_init (uint64_t new_size,size_t page_size,Error **errp) {int64_t i;size_t num_pages = new_size / page_size;
migration/ram.c +1 -1
@@ -126,7 +126,7 @@ static void XBZRLE_cache_unlock(void)* @new_size: new cache size * @errp: set *errp if the check failed, with reason */ -int xbzrle_cache_resize (int64_t new_size,Error **errp) +int xbzrle_cache_resize (uint64_t new_size,Error **errp) {PageCache *new_cache;int64_t ret =0 ;
Signature · 1 line
2.26.2
PATCH v2 3/4 migration: Fix cache_init()'s "Failed to allocate" error messages
In reply to Markus Armbrustercache_init() attempts to handle allocation failure.. The two error messages are garbage, as untested error messages commonly are:
Parameter 'cache size' expects Failed to allocate cache Parameter 'cache size' expects Failed to allocate page cache
Fix them to just
Failed to allocate cache
Failed to allocate page cache
--- migration/page_cache.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
migration/page_cache.c +2 -4
@@ -60,8 +60,7 @@ PageCache *cache_init(uint64_t new_size, size_t page_size, Error **errp)/* We prefer not to abort if there is no memory */ cache =g_try_malloc (sizeof (*cache));if (!cache) { -error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"cache size" , -"Failed to allocate cache" ); +error_setg (errp,"Failed to allocate cache" );return NULL ; } cache->page_size = page_size;
@@ -74,8 +73,7 @@ PageCache *cache_init(uint64_t new_size, size_t page_size, Error **errp) cache->page_cache =g_try_malloc ((cache->max_num_items) *sizeof (*cache->page_cache));if (!cache->page_cache) { -error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"cache size" , -"Failed to allocate page cache" ); +error_setg (errp,"Failed to allocate page cache" );g_free (cache);return NULL ; }
Signature · 1 line
2.26.2
Re: [PATCH v2 3/4] migration: Fix cache_init()'s "Failed to allocate" error messages
Quoted 1 line · Markus Armbruster
cache_init()attempts to handle allocation failure.. The two error
The double . looks odd.
Quoted 16 lines
messages are garbage, as untested error messages commonly are:
Parameter 'cache size' expects Failed to allocate cache Parameter 'cache size' expects Failed to allocate page cache
Fix them to just
Failed to allocate cache
Failed to allocate page cacheSigned-off-by Markus Armbruster <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- migration/page_cache.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v2 3/4] migration: Fix cache_init()'s "Failed to allocate" error messages
Quoted 4 lines · Eric Blake
Quoted 1 line · Markus Armbruster
cache_init()attempts to handle allocation failure.. The two errorThe double . looks odd.
Typo. Perhaps the maintainer can take care of it.
Quoted 16 lines
Quoted 16 lines
messages are garbage, as untested error messages commonly are:
Parameter 'cache size' expects Failed to allocate cache Parameter 'cache size' expects Failed to allocate page cache
Fix them to just
Failed to allocate cache
Failed to allocate page cacheSigned-off-by Markus Armbruster <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- migration/page_cache.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Re: [PATCH v2 3/4] migration: Fix cache_init()'s "Failed to allocate" error messages
Quoted 8 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 4 lines · Eric Blake
Quoted 1 line · Markus Armbruster
cache_init()attempts to handle allocation failure.. The two errorThe double . looks odd.
Typo. Perhaps the maintainer can take care of it.
Yeh I can try and remember to take it out on the merge.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
messages are garbage, as untested error messages commonly are:
Parameter 'cache size' expects Failed to allocate cache Parameter 'cache size' expects Failed to allocate page cache
Fix them to just
Failed to allocate cache
Failed to allocate page cacheSigned-off-by Markus Armbruster <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- migration/page_cache.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH v2 4/4 migration: Fix a few absurdly defective error messages
In reply to Markus Armbrustermigrate_params_check() has a number of error messages of the form
Parameter 'NAME' expects is invalid, it should be ...
Fix them to something like
Parameter 'NAME' expects a ...
--- migration/migration.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
migration/migration.c +11 -12
@@ -1226,21 +1226,21 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp)if (params->has_compress_level && (params->compress_level >9 )) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"compress_level" , -"is invalid, it should be in the range of 0 to 9" ); +"a value between 0 and 9" );return false; }if (params->has_compress_threads && (params->compress_threads <1 )) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"compress_threads" , -"is invalid, it should be in the range of 1 to 255" ); +"a value between 1 and 255" );return false; }if (params->has_decompress_threads && (params->decompress_threads <1 )) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"decompress_threads" , -"is invalid, it should be in the range of 1 to 255" ); +"a value between 1 and 255" );return false; }
@@ -1293,21 +1293,21 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp)if (params->has_multifd_channels && (params->multifd_channels <1 )) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"multifd_channels" , -"is invalid, it should be in the range of 1 to 255" ); +"a value between 1 and 255" );return false; }if (params->has_multifd_zlib_level && (params->multifd_zlib_level >9 )) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"multifd_zlib_level" , -"is invalid, it should be in the range of 0 to 9" ); +"a value between 0 and 9" );return false; }if (params->has_multifd_zstd_level && (params->multifd_zstd_level >20 )) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"multifd_zstd_level" , -"is invalid, it should be in the range of 0 to 20" ); +"a value between 0 and 20" );return false; }
@@ -1316,8 +1316,7 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp) !is_power_of_2(params->xbzrle_cache_size))) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"xbzrle_cache_size" , -"is invalid, it should be bigger than target page size" -" and a power of 2" ); +"a power of two no less than the target page size" );return false; }
@@ -1334,21 +1333,21 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp) params->announce_initial > 100000) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"announce_initial" , -"is invalid, it must be less than 100000 ms" ); +"a value between 0 and 100000" );return false; }if (params->has_announce_max && params->announce_max >100000 ) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"announce_max" , -"is invalid, it must be less than 100000 ms" ); +"a value between 0 and 100000" );return false; }if (params->has_announce_rounds && params->announce_rounds >1000 ) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"announce_rounds" , -"is invalid, it must be in the range of 0 to 1000" ); +"a value between 0 and 1000" );return false; } if (params->has_announce_step &&
@@ -1356,7 +1355,7 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp) params->announce_step > 10000)) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"announce_step" , -"is invalid, it must be in the range of 1 to 10000 ms" ); +"a value between 0 and 10000" );return false; }
Signature · 1 line
2.26.2
Quoted 11 lines · * Markus Armbruster ([email protected]) wrote:
v2:
* Rebased
* PATCH 1 dropped. Fixes a crash bug. Daniel asked me to modify the fix. Unfortunately, I don't understand this anymore, and don't have the time & energy to start over.
* PATCH 4 dropped. Plugs a hole in input validation. David pointed asked me to additionally fix an error message, but I don't quite understand what he wants.We can discuss what to do about the dropped patches, but I don't want to hold the remainder of the series any longer just for that.
Queued (with double . removed)
Quoted 21 lines
Markus Armbruster (4):
migration: Fix migrate-set-parameters argument validation
migration: Clean up signed vs. unsigned XBZRLE cache-size
migration: Fix cache_init()'s "Failed to allocate" error messages
migration: Fix a few absurdly defective error messagesqapi/migration.json | 32 ++++++++++++++++---------------- migration/migration.h | 2 +- migration/page_cache.h | 2 +- migration/ram.h | 2 +- migration/migration.c | 27 +++++++++++++-------------- migration/page_cache.c | 8 +++----- migration/ram.c | 2 +- monitor/hmp-cmds.c | 24 ++++++++++++------------ 8 files changed, 48 insertions(+), 51 deletions(-)Signature · 1 line
2.26.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK