From patchwork Fri Jun 4 16:33:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 54648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7A9C9B7D2E for ; Sat, 5 Jun 2010 03:18:04 +1000 (EST) Received: from localhost ([127.0.0.1]:55903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKaWv-0004xd-Q6 for incoming@patchwork.ozlabs.org; Fri, 04 Jun 2010 13:18:01 -0400 Received: from [140.186.70.92] (port=44968 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKZtS-0007ri-Du for qemu-devel@nongnu.org; Fri, 04 Jun 2010 12:37:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKZtQ-0002gv-6Y for qemu-devel@nongnu.org; Fri, 04 Jun 2010 12:37:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23598) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKZtP-0002ge-UX for qemu-devel@nongnu.org; Fri, 04 Jun 2010 12:37:12 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o54Gb97P002442 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Jun 2010 12:37:10 -0400 Received: from localhost.localdomain (vpn2-9-144.ams2.redhat.com [10.36.9.144]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o54GXWSx032074; Fri, 4 Jun 2010 12:36:57 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 4 Jun 2010 18:33:04 +0200 Message-Id: <1275669195-28312-17-git-send-email-kwolf@redhat.com> In-Reply-To: <1275669195-28312-1-git-send-email-kwolf@redhat.com> References: <1275669195-28312-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 16/27] ide: Turn drive serial into a qdev property ide-drive.serial X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Markus Armbruster 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 Signed-off-by: Kevin Wolf --- 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 d3328cd..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..5e549d9 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 = dev->conf.dinfo->serial; + } + + 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(), } };