qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 11/14] ide: Turn drive serial into a qdev property ide-drive.serial
Date: Fri, 28 May 2010 15:38:52 +0200	[thread overview]
Message-ID: <1275053935-10627-12-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1275053935-10627-1-git-send-email-armbru@redhat.com>

It needs to be a qdev property, because it belongs to the drive's
guest part.

Bonus: info qtree now shows the serial number.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/core.c     |   11 ++++++-----
 hw/ide/internal.h |    4 +++-
 hw/ide/qdev.c     |   16 +++++++++++++++-
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index d6381aa..70af1b6 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2596,7 +2596,8 @@ void ide_bus_reset(IDEBus *bus)
     ide_clear_hob(bus);
 }
 
-void ide_init_drive(IDEState *s, DriveInfo *dinfo, const char *version)
+void ide_init_drive(IDEState *s, DriveInfo *dinfo,
+                    const char *version, const char *serial)
 {
     int cylinders, heads, secs;
     uint64_t nb_sectors;
@@ -2618,9 +2619,9 @@ void ide_init_drive(IDEState *s, DriveInfo *dinfo, const char *version)
         s->is_cdrom = 1;
         bdrv_set_change_cb(s->bs, cdrom_change_cb, s);
     }
-    strncpy(s->drive_serial_str, drive_get_serial(s->bs),
-            sizeof(s->drive_serial_str));
-    if (*s->drive_serial_str) {
+    if (serial && *serial) {
+        strncpy(s->drive_serial_str, serial, sizeof(s->drive_serial_str));
+    } else {
         snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
                  "QM%05d", s->drive_serial);
     }
@@ -2669,7 +2670,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
         dinfo = i == 0 ? hd0 : hd1;
         ide_init1(bus, i);
         if (dinfo) {
-            ide_init_drive(&bus->ifs[i], dinfo, NULL);
+            ide_init_drive(&bus->ifs[i], dinfo, NULL, dinfo->serial);
         } else {
             ide_reset(&bus->ifs[i]);
         }
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 6b0024d..eef1ee1 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -457,6 +457,7 @@ struct IDEDevice {
     uint32_t unit;
     BlockConf conf;
     char *version;
+    char *serial;
 };
 
 typedef int (*ide_qdev_initfn)(IDEDevice *dev);
@@ -554,7 +555,8 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);
 void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
-void ide_init_drive(IDEState *s, DriveInfo *dinfo, const char *version);
+void ide_init_drive(IDEState *s, DriveInfo *dinfo,
+                    const char *version, const char *serial);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
                                     DriveInfo *hd1, qemu_irq irq);
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 9ebb906..5f301bc 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -99,7 +99,20 @@ typedef struct IDEDrive {
 static int ide_drive_initfn(IDEDevice *dev)
 {
     IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
-    ide_init_drive(bus->ifs + dev->unit, dev->conf.dinfo, dev->version);
+    IDEState *s = bus->ifs + dev->unit;
+    const char *serial;
+
+    serial = dev->serial;
+    if (!serial) {
+        /* try to fall back to value set with legacy -drive serial=... */
+        serial = drive_get_serial(s->bs);
+    }
+
+    ide_init_drive(s, dev->conf.dinfo, dev->version, serial);
+
+    if (!dev->serial) {
+        dev->serial = qemu_strdup(s->drive_serial_str);
+    }
     return 0;
 }
 
@@ -111,6 +124,7 @@ static IDEDeviceInfo ide_drive_info = {
         DEFINE_PROP_UINT32("unit", IDEDrive, dev.unit, -1),
         DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf),
         DEFINE_PROP_STRING("ver",  IDEDrive, dev.version),
+        DEFINE_PROP_STRING("serial",  IDEDrive, dev.serial),
         DEFINE_PROP_END_OF_LIST(),
     }
 };
-- 
1.6.6.1

  parent reply	other threads:[~2010-05-28 13:39 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-28 13:38 [Qemu-devel] [PATCH 00/14] Block-related fixes and cleanups Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 01/14] blockdev: Belatedly remove MAX_DRIVES Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 02/14] blockdev: Belatedly remove driveopts Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 03/14] usb: Remove unused usb_device_add() parameter is_hotplug Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 04/14] ide: Remove useless IDEDeviceInfo members unit, drive Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 05/14] ide: Remove redundant IDEState member conf Markus Armbruster
2010-05-31 14:56   ` [Qemu-devel] " Kevin Wolf
2010-05-31 15:47     ` Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 06/14] ide: Split ide_init1() off ide_init2() Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 07/14] ide: Change ide_init_drive() to require valid dinfo argument Markus Armbruster
2010-06-01 14:57   ` [Qemu-devel] " Kevin Wolf
2010-06-01 18:29     ` Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 08/14] ide: Split non-qdev code off ide_init2() Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 09/14] qdev: New qdev_prop_set_string() Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 10/14] qdev: Don't leak string property value on hot unplug Markus Armbruster
2010-05-28 13:38 ` Markus Armbruster [this message]
2010-05-28 13:38 ` [Qemu-devel] [PATCH 12/14] ide: Fix info qtree for ide-drive.ver Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 13/14] scsi: Turn drive serial into a qdev property scsi-disk.serial Markus Armbruster
2010-05-28 13:38 ` [Qemu-devel] [PATCH 14/14] scsi: Fix info qtree for scsi-disk.ver Markus Armbruster
2010-05-31  9:19 ` [Qemu-devel] Re: [PATCH 00/14] Block-related fixes and cleanups Gerd Hoffmann
2010-06-01  6:33   ` Jes Sorensen
  -- strict thread matches above, loose matches on Subject: below --
2010-06-01 18:32 [Qemu-devel] " Markus Armbruster
2010-06-01 18:32 ` [Qemu-devel] [PATCH 11/14] ide: Turn drive serial into a qdev property ide-drive.serial Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1275053935-10627-12-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).