From 3b930db8159788759f8a5ce0d4e84d33153fa4cc Mon Sep 17 00:00:00 2001
Message-Id: <3b930db8159788759f8a5ce0d4e84d33153fa4cc.1369221838.git.minovotn@redhat.com>
In-Reply-To: <44d9306ede26ea2881e6c1f104b901be647022a8.1369221838.git.minovotn@redhat.com>
References: <44d9306ede26ea2881e6c1f104b901be647022a8.1369221838.git.minovotn@redhat.com>
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Tue, 14 May 2013 11:11:12 +0200
Subject: [PATCH 5/8] usb-storage: Forward serial number to scsi-disk

RH-Author: Gerd Hoffmann <kraxel@redhat.com>
Message-id: <1368529872-8973-4-git-send-email-kraxel@redhat.com>
Patchwork-id: 51349
O-Subject: [RHEL-6.5 qemu-kvm PATCH 3/3] usb-storage: Forward serial number to scsi-disk
Bugzilla: 947416
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>

From: Kevin Wolf <kwolf@redhat.com>

usb-storage takes care to fetch the USB serial number from -drive
options, but it neglected to pass its own 'serial' property to the
scsi-disk it creates. With this patch, the 'serial' qdev property and
the 'serial' option in -drive behave the same and correctly apply the
serial number on both USB and SCSI level.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 76534da749ceb3b4c13ec09b173bcf6d6c2e36d4)

Conflicts:

	hw/pci-hotplug.c
	hw/usb-msd.c
---
 hw/pci-hotplug.c |    2 +-
 hw/scsi-bus.c    |    8 ++++++--
 hw/scsi.h        |    3 ++-
 hw/usb-msd.c     |    2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 hw/pci-hotplug.c | 2 +-
 hw/scsi-bus.c    | 8 ++++++--
 hw/scsi.h        | 3 ++-
 hw/usb-msd.c     | 2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index cdb0267..b659cd0 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -91,7 +91,7 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
      */
     dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1);
     scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit,
-                                        false, -1);
+                                        false, -1, NULL);
     dinfo->unit = scsidev->id;
 
     if (printinfo)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 936d994..8c2c74f 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -186,7 +186,8 @@ void scsi_qdev_register(SCSIDeviceInfo *info)
 
 /* handle legacy '-drive if=scsi,...' cmd line args */
 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
-                                      int unit, bool removable, int bootindex)
+                                      int unit, bool removable, int bootindex,
+                                      const char *serial)
 {
     const char *driver;
     DeviceState *dev;
@@ -200,6 +201,9 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
     if (qdev_prop_exists(dev, "removable")) {
         qdev_prop_set_bit(dev, "removable", removable);
     }
+    if (serial) {
+        qdev_prop_set_string(dev, "serial", serial);
+    }
     if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
         qdev_free(dev);
         return NULL;
@@ -222,7 +226,7 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
             continue;
         }
         qemu_opts_loc_restore(dinfo->opts);
-        if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1)) {
+        if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL)) {
             res = -1;
             break;
         }
diff --git a/hw/scsi.h b/hw/scsi.h
index 6fee286..371141b 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -152,7 +152,8 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
 }
 
 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
-                                      int unit, bool removable, int bootindex);
+                                      int unit, bool removable, int bootindex,
+                                      const char *serial);
 int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
 
 /*
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 8c074a5..50cbf7a 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -586,7 +586,7 @@ static int usb_msd_initfn(USBDevice *dev)
     usb_desc_init(dev);
     scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info);
     s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable,
-                                            s->conf.bootindex);
+                                            s->conf.bootindex, s->serial);
     if (!s->scsi_dev) {
         return -1;
     }
-- 
1.7.11.7

