From patchwork Mon Jan 31 15:29:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 81165 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 8F974B70EA for ; Tue, 1 Feb 2011 03:04:30 +1100 (EST) Received: from localhost ([127.0.0.1]:42095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PjwEs-0004GV-IN for incoming@patchwork.ozlabs.org; Mon, 31 Jan 2011 11:04:26 -0500 Received: from [140.186.70.92] (port=43127 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pjvfr-0002jN-Fp for qemu-devel@nongnu.org; Mon, 31 Jan 2011 10:28:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pjvfh-0003Vh-En for qemu-devel@nongnu.org; Mon, 31 Jan 2011 10:28:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1030) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pjvfh-0003VP-7S for qemu-devel@nongnu.org; Mon, 31 Jan 2011 10:28:05 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0VFS3Jl000959 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 31 Jan 2011 10:28:03 -0500 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p0VFRZ2M012144; Mon, 31 Jan 2011 10:28:02 -0500 From: Kevin Wolf To: anthony@codemonkey.ws Date: Mon, 31 Jan 2011 16:29:12 +0100 Message-Id: <1296487756-12553-25-git-send-email-kwolf@redhat.com> In-Reply-To: <1296487756-12553-1-git-send-email-kwolf@redhat.com> References: <1296487756-12553-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 24/28] blockdev: Factor drive_index_to_{bus, unit}_id out of drive_init() 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 Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- blockdev.c | 22 ++++++++++++++-------- 1 files changed, 14 insertions(+), 8 deletions(-) diff --git a/blockdev.c b/blockdev.c index 6d828f2..a42c5e4 100644 --- a/blockdev.c +++ b/blockdev.c @@ -75,6 +75,18 @@ void blockdev_auto_del(BlockDriverState *bs) } } +static int drive_index_to_bus_id(BlockInterfaceType type, int index) +{ + int max_devs = if_max_devs[type]; + return max_devs ? index / max_devs : 0; +} + +static int drive_index_to_unit_id(BlockInterfaceType type, int index) +{ + int max_devs = if_max_devs[type]; + return max_devs ? index % max_devs : index; +} + QemuOpts *drive_def(const char *optstr) { return qemu_opts_parse(qemu_find_opts("drive"), optstr, 0); @@ -382,14 +394,8 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) error_report("index cannot be used with bus and unit"); return NULL; } - if (max_devs == 0) - { - unit_id = index; - bus_id = 0; - } else { - unit_id = index % max_devs; - bus_id = index / max_devs; - } + bus_id = drive_index_to_bus_id(type, index); + unit_id = drive_index_to_unit_id(type, index); } /* if user doesn't specify a unit_id,