From d12504dea45897ffa90d2d494b393d700acdea63 Mon Sep 17 00:00:00 2001
Message-Id: <d12504dea45897ffa90d2d494b393d700acdea63.1346940159.git.minovotn@redhat.com>
In-Reply-To: <c629acdc74c5b775c5cf7a7a3cb20ac833bcd0cc.1346940159.git.minovotn@redhat.com>
References: <c629acdc74c5b775c5cf7a7a3cb20ac833bcd0cc.1346940159.git.minovotn@redhat.com>
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Thu, 16 Aug 2012 11:39:18 +0200
Subject: [PATCH 16/18] usb: restore USBDevice->attached on vmload

RH-Author: Gerd Hoffmann <kraxel@redhat.com>
Message-id: <1345117160-21046-17-git-send-email-kraxel@redhat.com>
Patchwork-id: 40931
O-Subject: [RHEL-6.4 qemu-kvm PATCH 16/18] usb: restore USBDevice->attached on vmload
Bugzilla: 805172
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Hans de Goede <hdegoede@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 495d544798151206bafca65ec588c0388637eb40)
---
 hw/usb-bus.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 hw/usb-bus.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 9c5bc16..832dd63 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -26,10 +26,23 @@ static struct BusInfo usb_bus_info = {
 static int next_usb_bus = 0;
 static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses);
 
+static int usb_device_post_load(void *opaque, int version_id)
+{
+    USBDevice *dev = opaque;
+
+    if (dev->state == USB_STATE_NOTATTACHED) {
+        dev->attached = 0;
+    } else {
+        dev->attached = 1;
+    }
+    return 0;
+}
+
 const VMStateDescription vmstate_usb_device = {
     .name = "USBDevice",
     .version_id = 1,
     .minimum_version_id = 1,
+    .post_load = usb_device_post_load,
     .fields = (VMStateField []) {
         VMSTATE_UINT8(addr, USBDevice),
         VMSTATE_INT32(state, USBDevice),
-- 
1.7.11.4

