Skip to contentSkip to conversation

: QMP queue

GIT PULL Luiz Capitulino 2 participants 8 messages May 8, 2012 – May 9, 2012

lore
Share & tools
lore
#0 lore raw

This pull request contains the new 'suspended' RunState series, a related fix from Gerd and HMP fixes.

The HMP fixes are not directly related to QMP, but are included in this pull request for my convenience (besides, HMP is becoming QMP front-end anyway). I can do a separate pull if needed, though.

The changes (since 4f08129eeb42422655cc946a0a0c3accc2b8e3db) are available in the following repository:

git://repo.or.cz/qemu/qmp-unstable.git queue/qmp

Gerd Hoffmann (1):
wakeup on migration

Luiz Capitulino (5):
qapi-schema.json: fix RunState enums alphabetical order
runstate: introduce suspended state
vl: drop is_suspended variable
hmp: expr_unary(): check for overflow in strtoul()/strtoull()
hmp: fix bad value conversion for M type

 input.c          |    4 ++--
 migration.c      |    1 +
 monitor.c        |   12 ++++++++++--
 qapi-schema.json |    8 +++++---
 qmp.c            |    2 ++
 vl.c             |   14 +++++++++-----
 6 files changed, 29 insertions(+), 12 deletions(-)
#1 lore raw

[Qemu-devel] [PULL 1/6] wakeup on migration

From: Gerd Hoffmann <[email protected]>

Wakeup the guest when the live part of the migation is finished. This avoids being in suspended state on migration, so we don't have to save the is_suspended bit.

---
 migration.c |    1 +
 1 file changed, 1 insertion(+)
migration.c +1 -0
index 94f7839..f9e968e 100644
@@ -252,6 +252,7 @@ static void migrate_fd_put_ready(void *opaque)
         int old_vm_running = runstate_is_running();
 
         DPRINTF("done iterating\n");
+        qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
         vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
 
         if (qemu_savevm_state_complete(s->file) < 0) {
Signature · 1 line
1.7.9.2.384.g4a92a
#2 lore raw

[Qemu-devel] [PULL 2/6] qapi-schema.json: fix RunState enums alphabetical order

In reply to Luiz Capitulino
---
 qapi-schema.json |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
qapi-schema.json +2 -2
index 4279259..33f2f92 100644
@@ -92,6 +92,8 @@
 #
 # @debug: QEMU is running on a debugger
 #
+# @finish-migrate: guest is paused to finish the migration process
+#
 # @inmigrate: guest is paused waiting for an incoming migration
 #
 # @internal-error: An internal error that prevents further guest execution
@@ -106,8 +108,6 @@
 #
 # @prelaunch: QEMU was started with -S and guest has not started
 #
-# @finish-migrate: guest is paused to finish the migration process
-#
 # @restore-vm: guest is paused to restore VM state
 #
 # @running: guest is actively running
Signature · 1 line
1.7.9.2.384.g4a92a
#3 lore raw

[Qemu-devel] [PULL 3/6] runstate: introduce suspended state

In reply to Luiz Capitulino

QEMU enters in this state when the guest suspends to ram (S3).

This is important so that HMP users and QMP clients can know that the guest is suspended. QMP also has an event for this, but events are not reliable and are limited (ie. a client can connect to QEMU after the event has been emitted).

Having a different state for S3 brings a new issue, though. Every device that doesn't run when the VM is stopped but wants to run when the VM is suspended has to check for RUN_STATE_SUSPENDED explicitly. This is the case for the keyboard and mouse devices, for example.

---
 input.c          |    4 ++--
 qapi-schema.json |    4 +++-
 qmp.c            |    2 ++
 vl.c             |    7 +++++++
 4 files changed, 14 insertions(+), 3 deletions(-)
input.c +2 -2
index 6b5c2c3..6968b31 100644
@@ -130,7 +130,7 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
 
 void kbd_put_keycode(int keycode)
 {
-    if (!runstate_is_running()) {
+    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
         return;
     }
     if (qemu_put_kbd_event) {
@@ -154,7 +154,7 @@ void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
     void *mouse_event_opaque;
     int width, height;
 
-    if (!runstate_is_running()) {
+    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
         return;
     }
     if (QTAILQ_EMPTY(&mouse_handlers)) {
qapi-schema.json +3 -1
index 33f2f92..2ca7195 100644
@@ -116,12 +116,14 @@
 #
 # @shutdown: guest is shut down (and -no-shutdown is in use)
 #
+# @suspended: guest is suspended (ACPI S3)
+#
 # @watchdog: the watchdog action is configured to pause and has been triggered
 ##
 { 'enum': 'RunState',
   'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused',
             'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm',
-            'running', 'save-vm', 'shutdown', 'watchdog' ] }
+            'running', 'save-vm', 'shutdown', 'suspended', 'watchdog' ] }
 
 ##
 # @StatusInfo:
qmp.c +2 -0
index a182b51..fee9fb2 100644
@@ -151,6 +151,8 @@ void qmp_cont(Error **errp)
                runstate_check(RUN_STATE_SHUTDOWN)) {
         error_set(errp, QERR_RESET_REQUIRED);
         return;
+    } else if (runstate_check(RUN_STATE_SUSPENDED)) {
+        return;
     }
 
     bdrv_iterate(iostatus_bdrv_it, NULL);
vl.c +7 -0
index ae91a8a..a7afc79 100644
@@ -366,6 +366,11 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
     { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
 
+    { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
+    { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
+    { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
+    { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
+
     { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
     { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
 
@@ -1420,6 +1425,7 @@ static void qemu_system_suspend(void)
 {
     pause_all_vcpus();
     notifier_list_notify(&suspend_notifiers, NULL);
+    runstate_set(RUN_STATE_SUSPENDED);
     monitor_protocol_event(QEVENT_SUSPEND, NULL);
     is_suspended = true;
 }
@@ -1447,6 +1453,7 @@ void qemu_system_wakeup_request(WakeupReason reason)
     if (!(wakeup_reason_mask & (1 << reason))) {
         return;
     }
+    runstate_set(RUN_STATE_RUNNING);
     monitor_protocol_event(QEVENT_WAKEUP, NULL);
     notifier_list_notify(&wakeup_notifiers, &reason);
     reset_requested = 1;
Signature · 1 line
1.7.9.2.384.g4a92a
#4 lore raw

[Qemu-devel] [PULL 4/6] vl: drop is_suspended variable

In reply to Luiz Capitulino

Check for the RUN_STATE_SUSPENDED state instead.

---
 vl.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
vl.c +2 -5
index a7afc79..5e0080b 100644
@@ -1293,7 +1293,6 @@ static pid_t shutdown_pid;
 static int powerdown_requested;
 static int debug_requested;
 static int suspend_requested;
-static bool is_suspended;
 static NotifierList suspend_notifiers =
     NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
 static NotifierList wakeup_notifiers =
@@ -1427,12 +1426,11 @@ static void qemu_system_suspend(void)
     notifier_list_notify(&suspend_notifiers, NULL);
     runstate_set(RUN_STATE_SUSPENDED);
     monitor_protocol_event(QEVENT_SUSPEND, NULL);
-    is_suspended = true;
 }
 
 void qemu_system_suspend_request(void)
 {
-    if (is_suspended) {
+    if (runstate_check(RUN_STATE_SUSPENDED)) {
         return;
     }
     suspend_requested = 1;
@@ -1447,7 +1445,7 @@ void qemu_register_suspend_notifier(Notifier *notifier)
 
 void qemu_system_wakeup_request(WakeupReason reason)
 {
-    if (!is_suspended) {
+    if (!runstate_check(RUN_STATE_SUSPENDED)) {
         return;
     }
     if (!(wakeup_reason_mask & (1 << reason))) {
@@ -1458,7 +1456,6 @@ void qemu_system_wakeup_request(WakeupReason reason)
     notifier_list_notify(&wakeup_notifiers, &reason);
     reset_requested = 1;
     qemu_notify_event();
-    is_suspended = false;
 }
 
 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
Signature · 1 line
1.7.9.2.384.g4a92a
#5 lore raw

[Qemu-devel] [PULL 5/6] hmp: expr_unary(): check for overflow in strtoul()/strtoull()

In reply to Luiz Capitulino

It's not checked currently, so something like:

(qemu) balloon -100000000000001111114334234
(qemu)

Will just "work" (in this case the balloon command will get a random value).

Fix it by checking if strtoul()/strtoull() overflowed.

---
 monitor.c |    4 ++++
 1 file changed, 4 insertions(+)
monitor.c +4 -0
index 8946a10..bf60984 100644
@@ -3120,11 +3120,15 @@ static int64_t expr_unary(Monitor *mon)
         n = 0;
         break;
     default:
+        errno = 0;
 #if TARGET_PHYS_ADDR_BITS > 32
         n = strtoull(pch, &p, 0);
 #else
         n = strtoul(pch, &p, 0);
 #endif
+        if (errno == ERANGE) {
+            expr_error(mon, "number too large");
+        }
         if (pch == p) {
             expr_error(mon, "invalid char in expression");
         }
Signature · 1 line
1.7.9.2.384.g4a92a
#6 lore raw

[Qemu-devel] [PULL 6/6] hmp: fix bad value conversion for M type

In reply to Luiz Capitulino

The M type converts from megabytes to bytes. However, the value can be negative before the conversion, which will lead to a flawed conversion.

For example, this:

(qemu) balloon -1000000000000011
(qemu)

Just "works", but the value passed by the balloon command will be something else.

This patch fixes this problem by requering a positive value before converting. There's really no reason to accept a negative value for the M type.

---
 monitor.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
monitor.c +6 -2
index bf60984..12a6fe2 100644
@@ -89,8 +89,8 @@
  *              TODO lift the restriction
  * 'i'          32 bit integer
  * 'l'          target long (32 or 64 bit)
- * 'M'          just like 'l', except in user mode the value is
- *              multiplied by 2^20 (think Mebibyte)
+ * 'M'          Non-negative target long (32 or 64 bit), in user mode the
+ *              value is multiplied by 2^20 (think Mebibyte)
  * 'o'          octets (aka bytes)
  *              user mode accepts an optional T, t, G, g, M, m, K, k
  *              suffix, which multiplies the value by 2^40 for
@@ -3622,6 +3622,10 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
                     monitor_printf(mon, "integer is for 32-bit values\n");
                     goto fail;
                 } else if (c == 'M') {
+                    if (val < 0) {
+                        monitor_printf(mon, "enter a positive value\n");
+                        goto fail;
+                    }
                     val <<= 20;
                 }
                 qdict_put(qdict, key, qint_from_int(val));
Signature · 1 line
1.7.9.2.384.g4a92a
#7 lore raw
In reply to Luiz Capitulino
Quoted 11 lines · Luiz Capitulino

This pull request contains the new 'suspended' RunState series, a related fix from Gerd and HMP fixes.

The HMP fixes are not directly related to QMP, but are included in this pull request for my convenience (besides, HMP is becoming QMP front-end anyway). I can do a separate pull if needed, though.

The changes (since 4f08129eeb42422655cc946a0a0c3accc2b8e3db) are available in the following repository:

git://repo.or.cz/qemu/qmp-unstable.git queue/qmp

Pulled. Thanks.

Regards,

Anthony Liguori

Quoted 21 lines

Gerd Hoffmann (1):
wakeup on migration

Luiz Capitulino (5):
qapi-schema.json: fix RunState enums alphabetical order
runstate: introduce suspended state
vl: drop is_suspended variable
hmp: expr_unary(): check for overflow in strtoul()/strtoull()
hmp: fix bad value conversion for M type

  input.c          |    4 ++--
  migration.c      |    1 +
  monitor.c        |   12 ++++++++++--
  qapi-schema.json |    8 +++++---
  qmp.c            |    2 ++
  vl.c             |   14 +++++++++-----
  6 files changed, 29 insertions(+), 12 deletions(-)