diff mbox

[PATCHv3] ps2: migrate ledstate

Message ID 1318607068-17700-1-git-send-email-cfergeau@redhat.com
State New
Headers show

Commit Message

Christophe Fergeau Oct. 14, 2011, 3:44 p.m. UTC
Make the ps2 device track its ledstate so that we can migrate it.
Otherwise it gets lost across migration, and spice-server gets
confused about the actual keyboard state and sends bogus
caps/scroll/num key events. This fixes RH bug #729294

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>

---
v3: use VMSTATE_UINT32_V to indicate the ledstate field was added
    in version_id == 4
---
 hw/ps2.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

Comments

Gerd Hoffmann Oct. 17, 2011, 9:25 a.m. UTC | #1
>
>   static const VMStateDescription vmstate_ps2_common = {
>       .name = "PS2 Common State",
> -    .version_id = 3,
> +    .version_id = 4,
>       .minimum_version_id = 2,
>       .minimum_version_id_old = 2,
>       .fields      = (VMStateField []) {

> @@ -577,6 +585,7 @@ static const VMStateDescription vmstate_ps2_keyboard = {
>           VMSTATE_INT32(scan_enabled, PS2KbdState),
>           VMSTATE_INT32(translate, PS2KbdState),
>           VMSTATE_INT32_V(scancode_set, PS2KbdState,3),
> +        VMSTATE_INT32_V(ledstate, PS2KbdState, 4),
>           VMSTATE_END_OF_LIST()
>       }

version_id in vmstate_ps2_keyboard must be updated too.

The version update in vmstate_ps2_common might not be needed, IIRC the 
versions for stuff referenced via VMSTATE_STRUCT() isn't used anyway, Juan?

cheers,
   Gerd
Christophe Fergeau Oct. 17, 2011, 10:10 a.m. UTC | #2
On Mon, Oct 17, 2011 at 11:25:42AM +0200, Gerd Hoffmann wrote:
> >
> >  static const VMStateDescription vmstate_ps2_common = {
> >      .name = "PS2 Common State",
> >-    .version_id = 3,
> >+    .version_id = 4,
> >      .minimum_version_id = 2,
> >      .minimum_version_id_old = 2,
> >      .fields      = (VMStateField []) {
> 
> version_id in vmstate_ps2_keyboard must be updated too.

Yeah, I somehow updated the field in the wrong struct, /me blushes and
hides. I don't think this struct version needs to be updated.

> The version update in vmstate_ps2_common might not be needed, IIRC
> the versions for stuff referenced via VMSTATE_STRUCT() isn't used
> anyway, Juan?

Ah, ok, I hoped it would help to handle migration between versions with and
without this field, I guess I was too optimistic :)

Thanks,

Christophe
diff mbox

Patch

diff --git a/hw/ps2.c b/hw/ps2.c
index 24228c1..f37112b 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -92,6 +92,7 @@  typedef struct {
        not the keyboard controller.  */
     int translate;
     int scancode_set; /* 1=XT, 2=AT, 3=PS/2 */
+    int ledstate;
 } PS2KbdState;
 
 typedef struct {
@@ -195,11 +196,17 @@  uint32_t ps2_read_data(void *opaque)
     return val;
 }
 
+static void ps2_set_ledstate(PS2KbdState *s, int ledstate)
+{
+    s->ledstate = ledstate;
+    kbd_put_ledstate(ledstate);
+}
+
 static void ps2_reset_keyboard(PS2KbdState *s)
 {
     s->scan_enabled = 1;
     s->scancode_set = 2;
-    kbd_put_ledstate(0);
+    ps2_set_ledstate(s, 0);
 }
 
 void ps2_write_keyboard(void *opaque, int val)
@@ -274,7 +281,7 @@  void ps2_write_keyboard(void *opaque, int val)
         s->common.write_cmd = -1;
         break;
     case KBD_CMD_SET_LEDS:
-        kbd_put_ledstate(val);
+        ps2_set_ledstate(s, val);
         ps2_queue(&s->common, KBD_REPLY_ACK);
         s->common.write_cmd = -1;
         break;
@@ -544,7 +551,7 @@  static void ps2_mouse_reset(void *opaque)
 
 static const VMStateDescription vmstate_ps2_common = {
     .name = "PS2 Common State",
-    .version_id = 3,
+    .version_id = 4,
     .minimum_version_id = 2,
     .minimum_version_id_old = 2,
     .fields      = (VMStateField []) {
@@ -563,6 +570,7 @@  static int ps2_kbd_post_load(void* opaque, int version_id)
 
     if (version_id == 2)
         s->scancode_set=2;
+    kbd_put_ledstate(s->ledstate);
     return 0;
 }
 
@@ -577,6 +585,7 @@  static const VMStateDescription vmstate_ps2_keyboard = {
         VMSTATE_INT32(scan_enabled, PS2KbdState),
         VMSTATE_INT32(translate, PS2KbdState),
         VMSTATE_INT32_V(scancode_set, PS2KbdState,3),
+        VMSTATE_INT32_V(ledstate, PS2KbdState, 4),
         VMSTATE_END_OF_LIST()
     }
 };