From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=58132 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PilSh-0008EQ-RI for qemu-devel@nongnu.org; Fri, 28 Jan 2011 05:21:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PilSg-0002ST-Aq for qemu-devel@nongnu.org; Fri, 28 Jan 2011 05:21:51 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:53397) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PilSg-0002S3-5o for qemu-devel@nongnu.org; Fri, 28 Jan 2011 05:21:50 -0500 From: Markus Armbruster Date: Fri, 28 Jan 2011 11:21:43 +0100 Message-Id: <1296210106-11145-9-git-send-email-armbru@redhat.com> In-Reply-To: <1296210106-11145-1-git-send-email-armbru@redhat.com> References: <1296210106-11145-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH v2 08/11] blockdev: Factor drive_index_to_{bus, unit}_id out of drive_init() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@gmail.com, hare@suse.de Signed-off-by: Markus Armbruster --- blockdev.c | 22 ++++++++++++++-------- 1 files changed, 14 insertions(+), 8 deletions(-) diff --git a/blockdev.c b/blockdev.c index a5e56ee..f0bed2e 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); @@ -376,14 +388,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, -- 1.7.2.3