cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
218e99
From b853920b298d19a1905d106c7d965bda29b7a26c Mon Sep 17 00:00:00 2001
218e99
From: Gerd Hoffmann <kraxel@redhat.com>
218e99
Date: Mon, 2 Sep 2013 13:26:15 +0200
218e99
Subject: [PATCH 09/29] usb: add serial bus property
218e99
218e99
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
218e99
Message-id: <1378128376-25930-2-git-send-email-kraxel@redhat.com>
218e99
Patchwork-id: 53989
218e99
O-Subject: [RHEL-7 qemu-kvm PATCH 1/2] usb: add serial bus property
218e99
Bugzilla: 953304
218e99
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
218e99
RH-Acked-by: Hans de Goede <hdegoede@redhat.com>
218e99
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
218e99
This patch adds a serial property for all usb devices, which can be
218e99
used to set the serial number of a usb device (as listed by lsusb -v)
218e99
to a specific value.  Applies to emulated devices only.
218e99
218e99
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
218e99
(cherry picked from commit 71938a09d2b9fd4007515fec6c395916cb08f868)
218e99
---
218e99
 hw/usb/bus.c         |  1 +
218e99
 hw/usb/desc.c        |  6 ++++++
218e99
 hw/usb/dev-hid.c     |  3 +++
218e99
 hw/usb/dev-storage.c | 13 +++----------
218e99
 include/hw/usb.h     |  1 +
218e99
 5 files changed, 14 insertions(+), 10 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 hw/usb/bus.c         |    1 +
218e99
 hw/usb/desc.c        |    6 ++++++
218e99
 hw/usb/dev-hid.c     |    3 +++
218e99
 hw/usb/dev-storage.c |   13 +++----------
218e99
 include/hw/usb.h     |    1 +
218e99
 5 files changed, 14 insertions(+), 10 deletions(-)
218e99
218e99
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
218e99
index d1827be..f83d1de 100644
218e99
--- a/hw/usb/bus.c
218e99
+++ b/hw/usb/bus.c
218e99
@@ -13,6 +13,7 @@ static int usb_qdev_exit(DeviceState *qdev);
218e99
 
218e99
 static Property usb_props[] = {
218e99
     DEFINE_PROP_STRING("port", USBDevice, port_path),
218e99
+    DEFINE_PROP_STRING("serial", USBDevice, serial),
218e99
     DEFINE_PROP_BIT("full-path", USBDevice, flags,
218e99
                     USB_DEV_FLAG_FULL_PATH, true),
218e99
     DEFINE_PROP_END_OF_LIST()
218e99
diff --git a/hw/usb/desc.c b/hw/usb/desc.c
218e99
index fce303e..bf6c522 100644
218e99
--- a/hw/usb/desc.c
218e99
+++ b/hw/usb/desc.c
218e99
@@ -566,6 +566,12 @@ void usb_desc_create_serial(USBDevice *dev)
218e99
     char *path;
218e99
     int dst;
218e99
 
218e99
+    if (dev->serial) {
218e99
+        /* 'serial' usb bus property has priority if present */
218e99
+        usb_desc_set_string(dev, index, dev->serial);
218e99
+        return;
218e99
+    }
218e99
+
218e99
     assert(index != 0 && desc->str[index] != NULL);
218e99
     dst = snprintf(serial, sizeof(serial), "%s", desc->str[index]);
218e99
     path = qdev_get_dev_path(hcd);
218e99
diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
218e99
index b48899d..31f3cde 100644
218e99
--- a/hw/usb/dev-hid.c
218e99
+++ b/hw/usb/dev-hid.c
218e99
@@ -560,6 +560,9 @@ static int usb_hid_initfn(USBDevice *dev, int kind)
218e99
 {
218e99
     USBHIDState *us = DO_UPCAST(USBHIDState, dev, dev);
218e99
 
218e99
+    if (dev->serial) {
218e99
+        usb_desc_set_string(dev, STR_SERIALNUMBER, dev->serial);
218e99
+    }
218e99
     usb_desc_init(dev);
218e99
     us->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
218e99
     hid_init(&us->hid, kind, usb_hid_changed);
218e99
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
218e99
index 1073901..fe914ab 100644
218e99
--- a/hw/usb/dev-storage.c
218e99
+++ b/hw/usb/dev-storage.c
218e99
@@ -58,7 +58,6 @@ typedef struct {
218e99
     USBPacket *packet;
218e99
     /* usb-storage only */
218e99
     BlockConf conf;
218e99
-    char *serial;
218e99
     uint32_t removable;
218e99
 } MSDState;
218e99
 
218e99
@@ -602,7 +601,7 @@ static int usb_msd_initfn_storage(USBDevice *dev)
218e99
         return -1;
218e99
     }
218e99
 
218e99
-    blkconf_serial(&s->conf, &s->serial);
218e99
+    blkconf_serial(&s->conf, &dev->serial);
218e99
 
218e99
     /*
218e99
      * Hack alert: this pretends to be a block device, but it's really
218e99
@@ -616,16 +615,11 @@ static int usb_msd_initfn_storage(USBDevice *dev)
218e99
     bdrv_detach_dev(bs, &s->dev.qdev);
218e99
     s->conf.bs = NULL;
218e99
 
218e99
-    if (s->serial) {
218e99
-        usb_desc_set_string(dev, STR_SERIALNUMBER, s->serial);
218e99
-    } else {
218e99
-        usb_desc_create_serial(dev);
218e99
-    }
218e99
-
218e99
+    usb_desc_create_serial(dev);
218e99
     usb_desc_init(dev);
218e99
     scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info_storage, NULL);
218e99
     scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable,
218e99
-                                            s->conf.bootindex, s->serial);
218e99
+                                            s->conf.bootindex, dev->serial);
218e99
     if (!scsi_dev) {
218e99
         return -1;
218e99
     }
218e99
@@ -734,7 +728,6 @@ static const VMStateDescription vmstate_usb_msd = {
218e99
 
218e99
 static Property msd_properties[] = {
218e99
     DEFINE_BLOCK_PROPERTIES(MSDState, conf),
218e99
-    DEFINE_PROP_STRING("serial", MSDState, serial),
218e99
     DEFINE_PROP_BIT("removable", MSDState, removable, 0, false),
218e99
     DEFINE_PROP_END_OF_LIST(),
218e99
 };
218e99
diff --git a/include/hw/usb.h b/include/hw/usb.h
218e99
index 4d9d05e..901b0da 100644
218e99
--- a/include/hw/usb.h
218e99
+++ b/include/hw/usb.h
218e99
@@ -205,6 +205,7 @@ struct USBDevice {
218e99
     DeviceState qdev;
218e99
     USBPort *port;
218e99
     char *port_path;
218e99
+    char *serial;
218e99
     void *opaque;
218e99
     uint32_t flags;
218e99
 
218e99
-- 
218e99
1.7.1
218e99