qmp: return err msg when powerdown a vm when it isn't in running state
PATCH v3 1/1 qmp: return err msg when powerdown a vm when it isn't in running state
When send system_powerdown to QMP when the vm isn't in RUN_STATE_RUNNING, it will be ignored by system. So reply a err msg with the situation.
---
This is an update of the patch as per Fam Zheng's suggestion:
http://lists.gnu.org/archive/html/qemu-devel/2015-12/msg03949.html
qmp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
qmp.c +6 -1
@@ -114,8 +114,13 @@ void qmp_system_reset(Error **errp)qemu_system_reset_request (); } -void qmp_system_powerdown (Error **erp) +void qmp_system_powerdown (Error **errp) { +if (!runstate_check (RUN_STATE_RUNNING )) { +error_setg (errp, +"Can not powerdown virtual machine as it is not running" ); +return ; + }qemu_system_powerdown_request (); }
Signature · 1 line
2.5.0
+-- On Tue, 22 Dec 2015, Qinghua Jin wrote --+
| -void qmp_system_powerdown(Error **erp)
| +void qmp_system_powerdown(Error **errp)
| {
| + if (!runstate_check(RUN_STATE_RUNNING)) {
| + error_setg(errp,
| + "Can not powerdown virtual machine as it is not running");
| + return;
| + }
| qemu_system_powerdown_request();
| }Looks okay.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F
Quoted 20 lines · Qinghua Jin
When send
system_powerdownto QMP when the vm isn't inRUN_STATE_RUNNING, it will be ignored by system. So reply a err msg with the situation.Signed-off-by Qinghua Jin <[email protected]>---
This is an update of the patch as per Fam Zheng's suggestion:
http://lists.gnu.org/archive/html/qemu-devel/2015-12/msg03949.htmlqmp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)qmp.c +0
-0@@ -114,8 +114,13 @@ void qmp_system_reset(Error **errp)qemu_system_reset_request (); }
qmp.c void qmp_system_reset(Error **errp) · line 125
Quoted 10 lines
qmp.c +6
-1-void qmp_system_powerdown (Error **erp) +void qmp_system_powerdown (Error **errp) { +if (!runstate_check (RUN_STATE_RUNNING )) { +error_setg (errp, +"Can not powerdown virtual machine as it is not running" ); +return ; + }qemu_system_powerdown_request (); }
This is the handler for QMP command system_powerdown. The patch makes the QMP command fail in run states other than RUN_STATE_RUNNING.
There are other callers: the HMP command handler hmp_system_powerdown(), GTK's gd_menu_powerdown(), Cocoa's powerDownQEMU(). They all ignore the error. Why is that appropriate?
qemu_system_powerdown_request() sets powerdown_requested = 1. This makes the next qemu_powerdown_requested() return 1. Gets called only by main_loop_should_exit(). I can't quite see how "it will be ignored by system" when we're in RUN_STATE_RUNNING. Can you explain?