From patchwork Mon Oct 31 13:30:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 122854 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 8E592B6F81 for ; Tue, 1 Nov 2011 02:08:51 +1100 (EST) Received: from localhost ([::1]:44636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKtTh-0000ew-51 for incoming@patchwork.ozlabs.org; Mon, 31 Oct 2011 11:08:45 -0400 Received: from eggs.gnu.org ([140.186.70.92]:40859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKruG-0004xu-Ni for qemu-devel@nongnu.org; Mon, 31 Oct 2011 09:28:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RKruF-0004I0-Kl for qemu-devel@nongnu.org; Mon, 31 Oct 2011 09:28:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52858) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKruF-0004Hr-B4 for qemu-devel@nongnu.org; Mon, 31 Oct 2011 09:28:03 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9VDS15o004512 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 31 Oct 2011 09:28:01 -0400 Received: from dhcp-5-188.str.redhat.com (vpn1-7-216.ams2.redhat.com [10.36.7.216]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p9VDRMoW023034; Mon, 31 Oct 2011 09:28:00 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Mon, 31 Oct 2011 14:30:01 +0100 Message-Id: <1320067830-12093-27-git-send-email-kwolf@redhat.com> In-Reply-To: <1320067830-12093-1-git-send-email-kwolf@redhat.com> References: <1320067830-12093-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 26/55] scsi-disk: store valid mode pages in a table 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 From: Paolo Bonzini A small refactoring of the MODE SENSE implementation in scsi-disk. Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- hw/scsi-disk.c | 25 +++++++++++++------------ 1 files changed, 13 insertions(+), 12 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index bdb98ef..8f3ada6 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -607,10 +607,23 @@ static int scsi_emulate_mechanism_status(SCSIDiskState *s, uint8_t *outbuf) static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, int page_control) { + static const int mode_sense_valid[0x3f] = { + [MODE_PAGE_HD_GEOMETRY] = (1 << TYPE_DISK), + [MODE_PAGE_FLEXIBLE_DISK_GEOMETRY] = (1 << TYPE_DISK), + [MODE_PAGE_CACHING] = (1 << TYPE_DISK) | (1 << TYPE_ROM), + [MODE_PAGE_CAPABILITIES] = (1 << TYPE_ROM), + }; + BlockDriverState *bdrv = s->bs; int cylinders, heads, secs; uint8_t *p = *p_outbuf; + if ((mode_sense_valid[page] & (1 << s->qdev.type)) == 0) { + return -1; + } + + p[0] = page; + /* * If Changeable Values are requested, a mask denoting those mode parameters * that are changeable shall be returned. As we currently don't support @@ -619,10 +632,6 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, */ switch (page) { case MODE_PAGE_HD_GEOMETRY: - if (s->qdev.type == TYPE_ROM) { - return -1; - } - p[0] = 4; p[1] = 0x16; if (page_control == 1) { /* Changeable Values */ break; @@ -654,10 +663,6 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, break; case MODE_PAGE_FLEXIBLE_DISK_GEOMETRY: - if (s->qdev.type == TYPE_ROM) { - return -1; - } - p[0] = 5; p[1] = 0x1e; if (page_control == 1) { /* Changeable Values */ break; @@ -707,10 +712,6 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, break; case MODE_PAGE_CAPABILITIES: - if (s->qdev.type != TYPE_ROM) { - return -1; - } - p[0] = 0x2a; p[1] = 0x14; if (page_control == 1) { /* Changeable Values */ break;