From patchwork Sat Sep 13 15:00:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 388922 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 577A314011B for ; Sun, 14 Sep 2014 01:14:42 +1000 (EST) Received: from localhost ([::1]:50164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSp28-00087a-Ej for incoming@patchwork.ozlabs.org; Sat, 13 Sep 2014 11:14:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSoop-0002Q1-1R for qemu-devel@nongnu.org; Sat, 13 Sep 2014 11:01:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XSoog-00028h-Mt for qemu-devel@nongnu.org; Sat, 13 Sep 2014 11:00:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15239) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSoog-00028S-GV for qemu-devel@nongnu.org; Sat, 13 Sep 2014 11:00:46 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8DF0iYr017607 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 13 Sep 2014 11:00:44 -0400 Received: from blackfin.pond.sub.org (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8DF0aMd009397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 13 Sep 2014 11:00:42 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3AEB83042B60; Sat, 13 Sep 2014 17:00:29 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Sat, 13 Sep 2014 17:00:22 +0200 Message-Id: <1410620427-20089-19-git-send-email-armbru@redhat.com> In-Reply-To: <1410620427-20089-1-git-send-email-armbru@redhat.com> References: <1410620427-20089-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, benoit.canet@nodalink.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v2 18/23] blockdev: Fix blockdev-add not to create IDE drive (0, 0) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org blockdev_init() always creates a DriveInfo, but only drive_new() fills it in. qmp_blockdev_add() leaves it blank. This results in a drive with type = IF_IDE, bus = 0, unit = 0. Screwed up in commit ee13ed1c. Board initialization code looking for IDE drive (0,0) can pick up one of these bogus drives. Not sure whether getting the QMP command executed early enough is likely in practice, though. Fix by creating DriveInfo in drive_new(). Block backends created by blockdev-add don't get one. A few places assume a block backend always has a DriveInfo. Fix them up. Signed-off-by: Markus Armbruster --- block/block-backend.c | 4 +--- blockdev.c | 10 ++-------- hw/block/block.c | 16 ++++++++++------ hw/ide/qdev.c | 2 +- hw/scsi/scsi-disk.c | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 9b146c8..ac3d774 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -100,9 +100,7 @@ static void drive_info_del(DriveInfo *dinfo) if (!dinfo) { return; } - if (dinfo->opts) { - qemu_opts_del(dinfo->opts); - } + qemu_opts_del(dinfo->opts); g_free(dinfo->serial); g_free(dinfo); } diff --git a/blockdev.c b/blockdev.c index 2def256..0d99be0 100644 --- a/blockdev.c +++ b/blockdev.c @@ -285,7 +285,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, int on_read_error, on_write_error; BlockBackend *blk; BlockDriverState *bs; - DriveInfo *dinfo; ThrottleConfig cfg; int snapshot = 0; bool copy_on_read; @@ -457,9 +456,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, bdrv_set_io_limits(bs, &cfg); } - dinfo = g_malloc0(sizeof(*dinfo)); - blk_set_legacy_dinfo(blk, dinfo); - if (!file || !*file) { if (has_driver_specific_opts) { file = NULL; @@ -903,21 +899,19 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) } /* Set legacy DriveInfo fields */ - dinfo = blk_legacy_dinfo(blk); + dinfo = g_malloc0(sizeof(*dinfo)); dinfo->enable_auto_del = true; dinfo->opts = all_opts; - dinfo->cyls = cyls; dinfo->heads = heads; dinfo->secs = secs; dinfo->trans = translation; - dinfo->type = type; dinfo->bus = bus_id; dinfo->unit = unit_id; dinfo->devaddr = devaddr; - dinfo->serial = g_strdup(serial); + blk_set_legacy_dinfo(blk, dinfo); switch(type) { case IF_IDE: diff --git a/hw/block/block.c b/hw/block/block.c index 0666dd3..a625773 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -19,7 +19,9 @@ void blkconf_serial(BlockConf *conf, char **serial) if (!*serial) { /* try to fall back to value set with legacy -drive serial=... */ dinfo = blk_legacy_dinfo(conf->blk); - *serial = g_strdup(dinfo->serial); + if (dinfo) { + *serial = g_strdup(dinfo->serial); + } } } @@ -32,11 +34,13 @@ void blkconf_geometry(BlockConf *conf, int *ptrans, if (!conf->cyls && !conf->heads && !conf->secs) { /* try to fall back to value set with legacy -drive cyls=... */ dinfo = blk_legacy_dinfo(conf->blk); - conf->cyls = dinfo->cyls; - conf->heads = dinfo->heads; - conf->secs = dinfo->secs; - if (ptrans) { - *ptrans = dinfo->trans; + if (dinfo) { + conf->cyls = dinfo->cyls; + conf->heads = dinfo->heads; + conf->secs = dinfo->secs; + if (ptrans) { + *ptrans = dinfo->trans; + } } } if (!conf->cyls && !conf->heads && !conf->secs) { diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 4818334..a74c81e 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -206,7 +206,7 @@ static int ide_drive_initfn(IDEDevice *dev) { DriveInfo *dinfo = blk_legacy_dinfo(dev->conf.blk); - return ide_dev_initfn(dev, dinfo->media_cd ? IDE_CD : IDE_HD); + return ide_dev_initfn(dev, dinfo && dinfo->media_cd ? IDE_CD : IDE_HD); } #define DEFINE_IDE_DEV_PROPERTIES() \ diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 768c1ad..e0c5ed3 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2331,7 +2331,7 @@ static void scsi_disk_realize(SCSIDevice *dev, Error **errp) } dinfo = blk_legacy_dinfo(dev->conf.blk); - if (dinfo->media_cd) { + if (dinfo && dinfo->media_cd) { scsi_cd_realize(dev, errp); } else { scsi_hd_realize(dev, errp);