Received: from eggs.gnu.org ([140.186.70.92]:59746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QXUnC-0001qC-4c for qemu-devel@nongnu.org; Fri, 17 Jun 2011 04:52:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QXUnA-0006Hi-Lb for qemu-devel@nongnu.org; Fri, 17 Jun 2011 04:52:41 -0400 Received: from oxygen.pond.sub.org ([78.46.104.156]:38920) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QXUnA-0006HJ-3T for qemu-devel@nongnu.org; Fri, 17 Jun 2011 04:52:40 -0400 Received: from oxygen-old.pond.sub.org (unknown [IPv6:2a01:4f8:130:9021::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "oxygen.pond.sub.org", Issuer "CAcert Class 3 Root" (verified OK)) by oxygen.pond.sub.org (Postfix) with ESMTPS id 32186A210B for ; Fri, 17 Jun 2011 10:52:37 +0200 (CEST) Received: from blackfin.pond.sub.org (p5B32C66C.dip.t-dialin.net [91.50.198.108]) by oxygen-old.pond.sub.org (Postfix) with ESMTPA id DE236277175 for ; Fri, 17 Jun 2011 10:52:36 +0200 (CEST) From: Markus Armbruster Date: Fri, 17 Jun 2011 10:52:36 +0200 Message-Id: <1308300756-29327-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH] usb-storage: Turn drive serial into a qdev property usb-storage.serial List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kraxel@redhat.com It needs to be a qdev property, because it belongs to the drive's guest part. Precedence: commit a0fef654 and 6ced55a5. Bonus: info qtree now shows the serial number. Signed-off-by: Markus Armbruster --- hw/usb-msd.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hw/usb-msd.c b/hw/usb-msd.c index c59797b..9033843 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -51,6 +51,7 @@ typedef struct { SCSIRequest *req; SCSIBus bus; BlockConf conf; + char *serial; SCSIDevice *scsi_dev; uint32_t removable; int result; @@ -531,9 +532,15 @@ static int usb_msd_initfn(USBDevice *dev) bdrv_detach(bs, &s->dev.qdev); s->conf.bs = NULL; - dinfo = drive_get_by_blockdev(bs); - if (dinfo && dinfo->serial) { - usb_desc_set_string(dev, STR_SERIALNUMBER, dinfo->serial); + if (!s->serial) { + /* try to fall back to value set with legacy -drive serial=... */ + dinfo = drive_get_by_blockdev(bs); + if (*dinfo->serial) { + s->serial = strdup(dinfo->serial); + } + } + if (s->serial) { + usb_desc_set_string(dev, STR_SERIALNUMBER, s->serial); } usb_desc_init(dev); @@ -632,6 +639,7 @@ static struct USBDeviceInfo msd_info = { .usbdevice_init = usb_msd_init, .qdev.props = (Property[]) { DEFINE_BLOCK_PROPERTIES(MSDState, conf), + DEFINE_PROP_STRING("serial", MSDState, serial), DEFINE_PROP_BIT("removable", MSDState, removable, 0, false), DEFINE_PROP_END_OF_LIST(), }, -- 1.7.2.3