plugins/api-system: Handle migrate_add_blocker() failure
PATCH 1/1 plugins/api-system: Handle migrate_add_blocker() failure
migrate_add_blocker() can fail (e.g. if migration is already in progress), in which case it returns a negative value and populates its errp argument with the reason.
The previous code ignored the return value, leaving state inconsistent on failure. Fix this by:
- Passing a local Error ** so failure details can be reported.
- Checking the return value; on failure, report the error, free the migration_blocker Error object, and return NULL to the caller.
Resolves: CID 1645470
--- plugins/api-system.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
plugins/api-system.c +7 -1
@@ -105,10 +105,16 @@ static Error *migration_blocker;const void *qemu_plugin_request_time_control (void ) {if (!has_control) { +Error *local_err =NULL ; has_control = true;error_setg (&migration_blocker,"TCG plugin time control does not support migration" ); -migrate_add_blocker (&migration_blocker,NULL ); +if (migrate_add_blocker (&migration_blocker, &local_err) <0 ) { +error_report_err (local_err); +error_free (migration_blocker); + migration_blocker =NULL ; +return NULL ; + }return &has_control; }return NULL ;
Signature · 1 line
2.43.0
Quoted 10 lines · Trieu Huynh
migrate_add_blocker()can fail (e.g. if migration is already in progress), in which case it returns a negative value and populates its errp argument with the reason.The previous code ignored the return value, leaving state inconsistent on failure. Fix this by:
- Passing a local Error ** so failure details can be reported.
- Checking the return value; on failure, report the error, free themigration_blockerError object, and return NULL to the caller.
Quoted 7 lines
Resolves: CID 1645470
Signed-off-by Trieu Huynh <[email protected]>--- plugins/api-system.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
While the description makes sense, how would it happen in real world?
Plugins usually will request time control on startup (so no migration is happening). In all cases, plugin who want to control time will have no other choice than abort. Maybe we could simply assert that migrate_add_blocker succeeded in this context.
Regards,
Pierrick
Quoted 20 lines · Pierrick Bouvier
Quoted 10 lines · Trieu Huynh
migrate_add_blocker()can fail (e.g. if migration is already in progress), in which case it returns a negative value and populates its errp argument with the reason.The previous code ignored the return value, leaving state inconsistent on failure. Fix this by:
- Passing a local Error ** so failure details can be reported.
- Checking the return value; on failure, report the error, free themigration_blockerError object, and return NULL to the caller.Quoted 7 lines
Resolves: CID 1645470
Signed-off-by Trieu Huynh <[email protected]>--- plugins/api-system.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 7 lines
While the description makes sense, how would it happen in real world?
Plugins usually will request time control on startup (so no migration is happening). In all cases, plugin who want to control time will have no other choice than abort.
Maybe we could simply assert thatmigrate_add_blockersucceeded in this context.
If the user starts QEMU with the --only-migratable option then all attempts to install migration-blockers will fail. In this case we need to report to the user that the thing they tried to do (use a time-control plugin and also migrate) isn't possible, i.e. exit cleanly with an error rather than falling over.
thanks
-- PMM
Quoted 30 lines · Peter Maydell
Quoted 20 lines · Pierrick Bouvier
Quoted 10 lines · Trieu Huynh
migrate_add_blocker()can fail (e.g. if migration is already in progress), in which case it returns a negative value and populates its errp argument with the reason.The previous code ignored the return value, leaving state inconsistent on failure. Fix this by:
- Passing a local Error ** so failure details can be reported.
- Checking the return value; on failure, report the error, free themigration_blockerError object, and return NULL to the caller.Quoted 7 lines
Resolves: CID 1645470
Signed-off-by Trieu Huynh <[email protected]>--- plugins/api-system.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)Quoted 7 lines
While the description makes sense, how would it happen in real world?
Plugins usually will request time control on startup (so no migration is happening). In all cases, plugin who want to control time will have no other choice than abort.
Maybe we could simply assert thatmigrate_add_blockersucceeded in this context.
Quoted 6 lines
If the user starts QEMU with the --only-migratable option then all attempts to install migration-blockers will fail. In this case we need to report to the user that the thing they tried to do (use a time-control plugin and also migrate) isn't possible, i.e. exit cleanly with an error rather than falling over.
Reporting errors is useful when there is a possibility to recover from it, but in this case it seems like we can only stop when user try to request time control, so I'm not sure we should return anything from this function at all instead of crashing.
Quoted 2 lines
thanks
-- PMM
Quoted 39 lines · Pierrick Bouvier
Quoted 30 lines · Peter Maydell
Quoted 20 lines · Pierrick Bouvier
Quoted 10 lines · Trieu Huynh
migrate_add_blocker()can fail (e.g. if migration is already in progress), in which case it returns a negative value and populates its errp argument with the reason.The previous code ignored the return value, leaving state inconsistent on failure. Fix this by:
- Passing a local Error ** so failure details can be reported.
- Checking the return value; on failure, report the error, free themigration_blockerError object, and return NULL to the caller.Quoted 7 lines
Resolves: CID 1645470
Signed-off-by Trieu Huynh <[email protected]>--- plugins/api-system.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)Quoted 7 lines
While the description makes sense, how would it happen in real world?
Plugins usually will request time control on startup (so no migration is happening). In all cases, plugin who want to control time will have no other choice than abort.
Maybe we could simply assert thatmigrate_add_blockersucceeded in this context.Quoted 6 lines
If the user starts QEMU with the --only-migratable option then all attempts to install migration-blockers will fail. In this case we need to report to the user that the thing they tried to do (use a time-control plugin and also migrate) isn't possible, i.e. exit cleanly with an error rather than falling over.
Quoted 4 lines
Reporting errors is useful when there is a possibility to recover from it, but in this case it seems like we can only stop when user try to request time control, so I'm not sure we should return anything from this function at all instead of crashing.
When the user does something that is misguided QEMU should (as an ideal) never crash -- a crash indicates a bug in QEMU. User mistakes should cause QEMU to produce (hopefully helpful) error messages.
If we want to say "there is no sensible way for the plugin to recover from this failure, we should just print the error message and exit QEMU" then that is what error_fatal is for.
thanks
-- PMM
Quoted 46 lines · Peter Maydell
Quoted 39 lines · Pierrick Bouvier
Quoted 30 lines · Peter Maydell
Quoted 20 lines · Pierrick Bouvier
Quoted 10 lines · Trieu Huynh
migrate_add_blocker()can fail (e.g. if migration is already in progress), in which case it returns a negative value and populates its errp argument with the reason.The previous code ignored the return value, leaving state inconsistent on failure. Fix this by:
- Passing a local Error ** so failure details can be reported.
- Checking the return value; on failure, report the error, free themigration_blockerError object, and return NULL to the caller.Quoted 7 lines
Resolves: CID 1645470
Signed-off-by Trieu Huynh <[email protected]>--- plugins/api-system.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)Quoted 7 lines
While the description makes sense, how would it happen in real world?
Plugins usually will request time control on startup (so no migration is happening). In all cases, plugin who want to control time will have no other choice than abort.
Maybe we could simply assert thatmigrate_add_blockersucceeded in this context.Quoted 6 lines
If the user starts QEMU with the --only-migratable option then all attempts to install migration-blockers will fail. In this case we need to report to the user that the thing they tried to do (use a time-control plugin and also migrate) isn't possible, i.e. exit cleanly with an error rather than falling over.
Quoted 4 lines
Reporting errors is useful when there is a possibility to recover from it, but in this case it seems like we can only stop when user try to request time control, so I'm not sure we should return anything from this function at all instead of crashing.
Quoted 8 lines
When the user does something that is misguided QEMU should (as an ideal) never crash -- a crash indicates a bug in QEMU. User mistakes should cause QEMU to produce (hopefully helpful) error messages.
If we want to say "there is no sensible way for the plugin to recover from this failure, we should just print the error message and exit QEMU" then that is what
error_fatalis for.
So yes, error_fatal is that we would like here.
My point was not how to stop execution (error_fatal, assert, or any other means) but to avoid returning a NULL handle on this case.
Quoted 2 lines
thanks
-- PMM
Regards,
Pierrick
Quoted 25 lines · Trieu Huynh
migrate_add_blocker()can fail (e.g. if migration is already in progress), in which case it returns a negative value and populates its errp argument with the reason.The previous code ignored the return value, leaving state inconsistent on failure. Fix this by:
- Passing a local Error ** so failure details can be reported.
- Checking the return value; on failure, report the error, free themigration_blockerError object, and return NULL to the caller.Resolves: CID 1645470
Signed-off-by Trieu Huynh <[email protected]>--- plugins/api-system.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)plugins/api-system.c +0
-0@@ -105,10 +105,16 @@ static Error *migration_blocker;const void *qemu_plugin_request_time_control (void ) {
plugins/api-system.c static Error *migration_blocker; · line 115
Quoted 10 lines
plugins/api-system.c +5
-1if (!has_control) { +Error *local_err =NULL ; has_control = true;error_setg (&migration_blocker,"TCG plugin time control does not support migration" ); -migrate_add_blocker (&migration_blocker,NULL ); +if (migrate_add_blocker (&migration_blocker, &local_err) <0 ) { +error_report_err (local_err); +error_free (migration_blocker); + migration_blocker =NULL ;
You don't need to free the migration_blocker Error if migrate_add_blocker() fails -- the function documents that it will do that for you and set the pointer to NULL.
plugins/api-system.c static Error *migration_blocker; · line 118
Quoted 4 lines
plugins/api-system.c +3
-0+ migration_blocker =NULL ; +return NULL ; + }return &has_control;
thanks
-- PMM
PATCH v2 1/1 plugins/api-system: Handle migrate_add_blocker() failure
In reply to Trieu Huynhmigrate_add_blocker() can fail (e.g. if migration is already in progress), in which case it returns a negative value and populates its errp argument with the reason.
The previous code ignored the return value. Pass &error_fatal so that on failure QEMU exits cleanly with an informative error message rather than continuing in an inconsistent state.
Resolves: CID 1645470
---
v2:
- Pass &error_fatal instead of returning NULL: the plugin has no recovery path, QEMU should exit cleanly with an error message. (Peter Maydell, Pierrick Bouvier)
- Remove manual error_free(migration_blocker) + migration_blocker = NULL:
migrate_add_blocker() already does this on failure. (Peter Maydell)
--- plugins/api-system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
plugins/api-system.c +1 -1
@@ -108,7 +108,7 @@ const void *qemu_plugin_request_time_control(void) has_control = true;error_setg (&migration_blocker,"TCG plugin time control does not support migration" ); -migrate_add_blocker (&migration_blocker,NULL ); +migrate_add_blocker (&migration_blocker, &error_fatal);return &has_control; }return NULL ;
Signature · 1 line
2.43.0
Quoted 26 lines · Trieu Huynh
migrate_add_blocker()can fail (e.g. if migration is already in progress), in which case it returns a negative value and populates its errp argument with the reason.The previous code ignored the return value. Pass
&error_fatalso that on failure QEMU exits cleanly with an informative error message rather than continuing in an inconsistent state.Resolves: CID 1645470
Signed-off-by Trieu Huynh <[email protected]>---
v2:
- Pass&error_fatalinstead of returning NULL: the plugin has no recovery path, QEMU should exit cleanly with an error message. (Peter Maydell, Pierrick Bouvier)
- Remove manualerror_free(migration_blocker)+migration_blocker= NULL:
migrate_add_blocker()already does this on failure. (Peter Maydell)--- plugins/api-system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)plugins/api-system.c +0
-0
plugins/api-system.c const void *qemu_plugin_request_time_control(void) · line 114
Quoted 8 lines
plugins/api-system.c +1
-1@@ -108,7 +108,7 @@ const void *qemu_plugin_request_time_control(void) has_control = true;error_setg (&migration_blocker,"TCG plugin time control does not support migration" ); -migrate_add_blocker (&migration_blocker,NULL ); +migrate_add_blocker (&migration_blocker, &error_fatal);return &has_control; }return NULL ;
This looks better.
Just a small process nit, new versions should be posted as a new thread, and not as a reply to your previous version. No need to repost though.
On error, correctly prints:
qemu-system-aarch64: disallowing migration blocker (--only-migratable) for: TCG plugin time control does not support migration
Regards,
Pierrick
Quoted 26 lines · Trieu Huynh
migrate_add_blocker()can fail (e.g. if migration is already in progress), in which case it returns a negative value and populates its errp argument with the reason.The previous code ignored the return value. Pass
&error_fatalso that on failure QEMU exits cleanly with an informative error message rather than continuing in an inconsistent state.Resolves: CID 1645470
Signed-off-by Trieu Huynh <[email protected]>---
v2:
- Pass&error_fatalinstead of returning NULL: the plugin has no recovery path, QEMU should exit cleanly with an error message. (Peter Maydell, Pierrick Bouvier)
- Remove manualerror_free(migration_blocker)+migration_blocker= NULL:
migrate_add_blocker()already does this on failure. (Peter Maydell)--- plugins/api-system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)plugins/api-system.c +0
-0
plugins/api-system.c const void *qemu_plugin_request_time_control(void) · line 114
Quoted 8 lines
plugins/api-system.c +1
-1@@ -108,7 +108,7 @@ const void *qemu_plugin_request_time_control(void) has_control = true;error_setg (&migration_blocker,"TCG plugin time control does not support migration" ); -migrate_add_blocker (&migration_blocker,NULL ); +migrate_add_blocker (&migration_blocker, &error_fatal);return &has_control; }return NULL ;
This was merged into master (aed38fe5206d848a8366181bfab96835fcd5643b). Thank you for your contribution!
Regards,
Pierrick