From patchwork Tue Jul 26 06:38:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 106783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4B394B70B1 for ; Tue, 26 Jul 2011 16:38:33 +1000 (EST) Received: from localhost ([::1]:57707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlbHi-0001To-Ev for incoming@patchwork.ozlabs.org; Tue, 26 Jul 2011 02:38:30 -0400 Received: from eggs.gnu.org ([140.186.70.92]:56598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlbHd-0001Te-Lk for qemu-devel@nongnu.org; Tue, 26 Jul 2011 02:38:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QlbHc-0000Wz-Ew for qemu-devel@nongnu.org; Tue, 26 Jul 2011 02:38:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36905) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlbHc-0000Wv-16 for qemu-devel@nongnu.org; Tue, 26 Jul 2011 02:38:24 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6Q6cKB3017992 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Jul 2011 02:38:21 -0400 Received: from blackfin.pond.sub.org (ovpn-113-29.phx2.redhat.com [10.3.113.29]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6Q6cJjd030859; Tue, 26 Jul 2011 02:38:20 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 1BE8C265; Tue, 26 Jul 2011 08:38:18 +0200 (CEST) From: Markus Armbruster To: Hannes Reinecke References: <1311346277-32329-1-git-send-email-hare@suse.de> <1311346277-32329-6-git-send-email-hare@suse.de> <4E2E5CD2.3090102@suse.de> Date: Tue, 26 Jul 2011 08:38:17 +0200 In-Reply-To: <4E2E5CD2.3090102@suse.de> (Hannes Reinecke's message of "Tue, 26 Jul 2011 08:21:06 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Kevin Wolf , qemu-devel@nongnu.org, kvm@vger.kernel.org, Alexander Graf Subject: Re: [Qemu-devel] [PATCH 5/6] scsi-disk: Remove 'drive_kind' 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 Hannes Reinecke writes: > On 07/25/2011 05:59 PM, Markus Armbruster wrote: >> Hannes Reinecke writes: >> >>> Instead of using its own definitions scsi-disk should >>> be using the device type of the parent device. >>> >>> Signed-off-by: Hannes Reinecke >>> --- >>> hw/scsi-defs.h | 6 +++++- >>> hw/scsi-disk.c | 48 ++++++++++++++++++++++++------------------------ >>> 2 files changed, 29 insertions(+), 25 deletions(-) >>> > [ .. ] >>> @@ -1217,44 +1214,47 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind) >>> return -1; >>> } >>> >>> - if (kind == SCSI_CD) { >>> + if (scsi_type == TYPE_ROM) { >>> s->qdev.blocksize = 2048; >>> - } else { >>> + } else if (scsi_type == TYPE_DISK) { >>> s->qdev.blocksize = s->qdev.conf.logical_block_size; >>> + } else { >>> + error_report("scsi-disk: Unhandled SCSI type %02x", scsi_type); >>> + return -1; >>> } >>> s->cluster_size = s->qdev.blocksize / 512; >>> s->bs->buffer_alignment = s->qdev.blocksize; >>> >>> - s->qdev.type = TYPE_DISK; >>> + s->qdev.type = scsi_type; >> >> Is this a bug fix? >> > No, proper initialisation. > s->qdev.type is the SCSI type we're told to emulate. So we have to set > it to the correct value otherwise the emulation will return wrong > values. Well, it changes .type from TYPE_DISK to TYPE_ROM for scsi-cd. I understand how that is required for your patch to work. I wonder whether it has an impact beyond that, given that the old value is plainly wrong. >>> qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s); >>> - bdrv_set_removable(s->bs, kind == SCSI_CD); >>> + bdrv_set_removable(s->bs, scsi_type == TYPE_ROM); >>> add_boot_device_path(s->qdev.conf.bootindex,&dev->qdev, ",0"); >>> return 0; >>> } >>> >>> static int scsi_hd_initfn(SCSIDevice *dev) >>> { >>> - return scsi_initfn(dev, SCSI_HD); >>> + return scsi_initfn(dev, TYPE_DISK); >>> } >>> >>> static int scsi_cd_initfn(SCSIDevice *dev) >>> { >>> - return scsi_initfn(dev, SCSI_CD); >>> + return scsi_initfn(dev, TYPE_ROM); >>> } >>> >>> static int scsi_disk_initfn(SCSIDevice *dev) >>> { >>> - SCSIDriveKind kind; >>> DriveInfo *dinfo; >>> + uint8_t scsi_type = TYPE_DISK; >>> >>> - if (!dev->conf.bs) { >>> - kind = SCSI_HD; /* will die in scsi_initfn() */ >> >> The comment explains why we don't explicitly fail when !dev->conf.bs, >> like all the other block device models. I'd rather keep it. >> > Ah. The magic of block devices. By all means, keep it. Like this? By the way, I'm afraid you forgot to remove typedef SCSIDriveKind. Care to respin this one? diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index f42a5d1..0925944 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1251,17 +1251,17 @@ static int scsi_cd_initfn(SCSIDevice *dev) static int scsi_disk_initfn(SCSIDevice *dev) { - SCSIDriveKind kind; + uint8_t scsi_type; DriveInfo *dinfo; if (!dev->conf.bs) { - kind = SCSI_HD; /* will die in scsi_initfn() */ + scsi_type = TYPE_DISK; /* will die in scsi_initfn() */ } else { dinfo = drive_get_by_blockdev(dev->conf.bs); - kind = dinfo->media_cd ? SCSI_CD : SCSI_HD; + scsi_type = dinfo->media_cd ? TYPE_ROM : TYPE_DISK; } - return scsi_initfn(dev, kind); + return scsi_initfn(dev, scsi_type); } #define DEFINE_SCSI_DISK_PROPERTIES() \