diff options
author | Markus Armbruster <armbru@redhat.com> | 2011-01-28 11:21:43 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2011-01-31 11:16:22 +0100 |
commit | 88d791e202127598cfd3221c819b504697656a52 (patch) | |
tree | 7d0076f503c4b26bc396518364b3b8e1394e10b7 /blockdev.c | |
parent | 4cfe1f3124e9d6d7458e6d581cf65de42736ec1b (diff) | |
download | qemu-88d791e202127598cfd3221c819b504697656a52.tar.gz qemu-88d791e202127598cfd3221c819b504697656a52.tar.bz2 qemu-88d791e202127598cfd3221c819b504697656a52.zip |
blockdev: Factor drive_index_to_{bus,unit}_id out of drive_init()
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r-- | blockdev.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/blockdev.c b/blockdev.c index 6d828f202d..a42c5e4a62 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, |