diff mbox

qmp: return err msg when powerdown a vm when it isn't in running state

Message ID 1450710967-24399-1-git-send-email-qhjin_dev@163.com
State New
Headers show

Commit Message

qhjindev Dec. 21, 2015, 3:16 p.m. UTC
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.

Signed-off-by: Qinghua Jin <qhjin_dev@163.com>
---
 qmp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Prasad Pandit Dec. 21, 2015, 5:55 p.m. UTC | #1
+-- On Mon, 21 Dec 2015, Qinghua Jin wrote --+
| -void qmp_system_powerdown(Error **erp)
| +void qmp_system_powerdown(Error **errp)
|  {
| +    if (!runstate_is_running()) {
| +        error_setg(errp, "Can't powerdown the Virtual Machine when it isn't running");
| +        return;
| +    }
|      qemu_system_powerdown_request();
|  }

 - Maybe direct call to 'if (!runstate_check(RUN_STATE_RUNNING))' is better?  
   runstate_is_running too invokes the same. Not sure why are there two
   functions 'runstate_is_running' & 'runstate_check'.
 - Can't -> Can not
 - "...the Virtual Machine.." -> "...virtual machine.." (not capitalised)
 - "...when it isn't.." -> "as it is not..."
 - OR maybe just say -> "Virtual machine is not running"

--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F
qhjindev Dec. 21, 2015, 11:10 p.m. UTC | #2
Thanks for your help, i'll resubmit the patch right away.


At 2015-12-22 01:55:35, "P J P" <ppandit@redhat.com> wrote:
>+-- On Mon, 21 Dec 2015, Qinghua Jin wrote --+
>| -void qmp_system_powerdown(Error **erp)
>| +void qmp_system_powerdown(Error **errp)
>|  {
>| +    if (!runstate_is_running()) {
>| +        error_setg(errp, "Can't powerdown the Virtual Machine when it isn't running");
>| +        return;
>| +    }
>|      qemu_system_powerdown_request();
>|  }
>
> - Maybe direct call to 'if (!runstate_check(RUN_STATE_RUNNING))' is better?  
>   runstate_is_running too invokes the same. Not sure why are there two
>   functions 'runstate_is_running' & 'runstate_check'.
> - Can't -> Can not
> - "...the Virtual Machine.." -> "...virtual machine.." (not capitalised)
> - "...when it isn't.." -> "as it is not..."
> - OR maybe just say -> "Virtual machine is not running"
>
>--
>Prasad J Pandit / Red Hat Product Security Team
>47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F
diff mbox

Patch

diff --git a/qmp.c b/qmp.c
index 0a1fa19..8e43435 100644
--- a/qmp.c
+++ b/qmp.c
@@ -114,8 +114,12 @@  void qmp_system_reset(Error **errp)
     qemu_system_reset_request();
 }
 
-void qmp_system_powerdown(Error **erp)
+void qmp_system_powerdown(Error **errp)
 {
+    if (!runstate_is_running()) {
+        error_setg(errp, "Can't powerdown the Virtual Machine when it isn't running");
+        return;
+    }
     qemu_system_powerdown_request();
 }