[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/4] SCSI-hotdel: Factor out IF argument parsing
From: |
Wolfgang Mauerer |
Subject: |
[Qemu-devel] [PATCH 2/4] SCSI-hotdel: Factor out IF argument parsing |
Date: |
Fri, 18 Sep 2009 17:26:32 +0200 |
This avoids some small code duplication later on.
Signed-off-by: Wolfgang Mauerer <address@hidden>
Signed-off-by: Jan Kiszka <address@hidden>
---
sysemu.h | 1 +
vl.c | 69 +++++++++++++++++++++++++++++++++++---------------------------
2 files changed, 40 insertions(+), 30 deletions(-)
diff --git a/sysemu.h b/sysemu.h
index e79e4ac..4fabb2a 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -194,6 +194,7 @@ extern int drive_get_max_bus(BlockInterfaceType type);
extern void drive_uninit(BlockDriverState *bdrv);
extern const char *drive_get_serial(BlockDriverState *bdrv);
extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
+BlockInterfaceType qemu_opt_get_if(const char* buf);
BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
diff --git a/vl.c b/vl.c
index 88bd3eb..bd0c2be 100644
--- a/vl.c
+++ b/vl.c
@@ -1903,6 +1903,31 @@ void drive_uninit(BlockDriverState *bdrv)
}
}
+BlockInterfaceType qemu_opt_get_if(const char* buf) {
+ BlockInterfaceType type;
+
+ type = IF_COUNT;
+ if (!strcmp(buf, "ide")) {
+ type = IF_IDE;
+ } else if (!strcmp(buf, "scsi")) {
+ type = IF_SCSI;
+ } else if (!strcmp(buf, "floppy")) {
+ type = IF_FLOPPY;
+ } else if (!strcmp(buf, "pflash")) {
+ type = IF_PFLASH;
+ } else if (!strcmp(buf, "mtd")) {
+ type = IF_MTD;
+ } else if (!strcmp(buf, "sd")) {
+ type = IF_SD;
+ } else if (!strcmp(buf, "virtio")) {
+ type = IF_VIRTIO;
+ } else if (!strcmp(buf, "xen")) {
+ type = IF_XEN;
+ }
+
+ return type;
+}
+
DriveInfo *drive_init(QemuOpts *opts, void *opaque,
int *fatal_error)
{
@@ -1959,39 +1984,23 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
if ((buf = qemu_opt_get(opts, "if")) != NULL) {
pstrcpy(devname, sizeof(devname), buf);
- if (!strcmp(buf, "ide")) {
- type = IF_IDE;
- max_devs = MAX_IDE_DEVS;
- } else if (!strcmp(buf, "scsi")) {
- type = IF_SCSI;
- max_devs = MAX_SCSI_DEVS;
- } else if (!strcmp(buf, "floppy")) {
- type = IF_FLOPPY;
- max_devs = 0;
- } else if (!strcmp(buf, "pflash")) {
- type = IF_PFLASH;
- max_devs = 0;
- } else if (!strcmp(buf, "mtd")) {
- type = IF_MTD;
- max_devs = 0;
- } else if (!strcmp(buf, "sd")) {
- type = IF_SD;
- max_devs = 0;
- } else if (!strcmp(buf, "virtio")) {
- type = IF_VIRTIO;
- max_devs = 0;
- } else if (!strcmp(buf, "xen")) {
- type = IF_XEN;
- max_devs = 0;
- } else if (!strcmp(buf, "none")) {
- type = IF_NONE;
+ type = qemu_opt_get_if(buf);
+ switch (type) {
+ case IF_IDE:
+ max_devs = MAX_IDE_DEVS;
+ break;
+ case IF_SCSI:
+ max_devs = MAX_SCSI_DEVS;
+ break;
+ case IF_COUNT:
max_devs = 0;
- } else {
- fprintf(stderr, "qemu: unsupported bus type '%s'\n", buf);
- return NULL;
+ fprintf(stderr, "qemu: unsupported bus type '%s'\n", buf);
+ return NULL;
+ default:
+ max_devs = 0;
}
}
-
+
if (cyls || heads || secs) {
if (cyls < 1 || cyls > 16383) {
fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", buf);
--
1.6.4
- [Qemu-devel] [PATCH 0/4] SCSI-hotdel: Implement removal of SCSI hard disks, Wolfgang Mauerer, 2009/09/19
- [Qemu-devel] [PATCH 1/4] SCSI-hotdel: Add detach method to LSI SCSI driver, Wolfgang Mauerer, 2009/09/19
- [Qemu-devel] [PATCH 2/4] SCSI-hotdel: Factor out IF argument parsing,
Wolfgang Mauerer <=
- [Qemu-devel] [PATCH 3/4] SCSI-Hotdel: Implement drive_hot_del, Wolfgang Mauerer, 2009/09/19
- [Qemu-devel] [PATCH 4/4] Small cleanup for drive_hot_add, Wolfgang Mauerer, 2009/09/19
- Re: [Qemu-devel] [PATCH 3/4] SCSI-Hotdel: Implement drive_hot_del, Gerd Hoffmann, 2009/09/21
- Re: [Qemu-devel] [PATCH 3/4] SCSI-Hotdel: Implement drive_hot_del, Wolfgang Mauerer, 2009/09/30
- Re: [Qemu-devel] [PATCH 3/4] SCSI-Hotdel: Implement drive_hot_del, Gerd Hoffmann, 2009/09/30
Re: [Qemu-devel] [PATCH 1/4] SCSI-hotdel: Add detach method to LSI SCSI driver, Gerd Hoffmann, 2009/09/21