[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 28/28] blockdev: Fix drive_add for drives without me
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 28/28] blockdev: Fix drive_add for drives without media |
Date: |
Mon, 31 Jan 2011 16:29:16 +0100 |
From: Markus Armbruster <address@hidden>
Watch this:
(qemu) drive_add 0 if=none
(qemu) info block
none0: type=hd removable=0 [not inserted]
(qemu) drive_del none0
Segmentation fault (core dumped)
add_init_drive() is confused about drive_init()'s failure modes, and
cleans up when it shouldn't. This leaves the DriveInfo with member
opts dangling. drive_del attempts to free it, and dies.
drive_init() behaves as follows:
* If it created a drive with media, it returns its DriveInfo.
* If it created a drive without media, it clears *fatal_error and
returns NULL.
* If it couldn't create a drive, it sets *fatal_error and returns
NULL.
Of its three callers:
* drive_init_func() is correct.
* usb_msd_init() assumes drive_init() failed when it returns NULL.
This is correct only because it always passes option "file", and
"drive without media" can't happen then.
* add_init_drive() assumes drive_init() failed when it returns NULL.
This is incorrect.
Clean up drive_init() to return NULL on failure and only on failure.
Drop its parameter fatal_error.
Signed-off-by: Markus Armbruster <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
blockdev.c | 8 ++------
blockdev.h | 2 +-
hw/device-hotplug.c | 3 +--
hw/usb-msd.c | 3 +--
vl.c | 9 ++-------
5 files changed, 7 insertions(+), 18 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 4b2145c..1c56da0 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -203,7 +203,7 @@ static int parse_block_error_action(const char *buf, int
is_read)
}
}
-DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
+DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
{
const char *buf;
const char *file = NULL;
@@ -225,8 +225,6 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi,
int *fatal_error)
int snapshot = 0;
int ret;
- *fatal_error = 1;
-
translation = BIOS_ATA_TRANSLATION_AUTO;
if (default_to_scsi) {
@@ -499,8 +497,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi,
int *fatal_error)
abort();
}
if (!file || !*file) {
- *fatal_error = 0;
- return NULL;
+ return dinfo;
}
if (snapshot) {
/* always use cache=unsafe with snapshot */
@@ -529,7 +526,6 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi,
int *fatal_error)
if (bdrv_key_required(dinfo->bdrv))
autostart = 0;
- *fatal_error = 0;
return dinfo;
}
diff --git a/blockdev.h b/blockdev.h
index e5d8c56..84e462a 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -48,7 +48,7 @@ DriveInfo *drive_get_by_blockdev(BlockDriverState *bs);
QemuOpts *drive_def(const char *optstr);
QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
const char *optstr);
-DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi, int *fatal_error);
+DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi);
/* device-hotplug */
diff --git a/hw/device-hotplug.c b/hw/device-hotplug.c
index 95a6372..8b2ed7a 100644
--- a/hw/device-hotplug.c
+++ b/hw/device-hotplug.c
@@ -29,7 +29,6 @@
DriveInfo *add_init_drive(const char *optstr)
{
- int fatal_error;
DriveInfo *dinfo;
QemuOpts *opts;
@@ -37,7 +36,7 @@ DriveInfo *add_init_drive(const char *optstr)
if (!opts)
return NULL;
- dinfo = drive_init(opts, current_machine->use_scsi, &fatal_error);
+ dinfo = drive_init(opts, current_machine->use_scsi);
if (!dinfo) {
qemu_opts_del(opts);
return NULL;
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 11722c7..97d1e4a 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -542,7 +542,6 @@ static USBDevice *usb_msd_init(const char *filename)
QemuOpts *opts;
DriveInfo *dinfo;
USBDevice *dev;
- int fatal_error;
const char *p1;
char fmt[32];
@@ -572,7 +571,7 @@ static USBDevice *usb_msd_init(const char *filename)
qemu_opt_set(opts, "if", "none");
/* create host drive */
- dinfo = drive_init(opts, 0, &fatal_error);
+ dinfo = drive_init(opts, 0);
if (!dinfo) {
qemu_opts_del(opts);
return NULL;
diff --git a/vl.c b/vl.c
index f86724f..ce5708b 100644
--- a/vl.c
+++ b/vl.c
@@ -631,13 +631,8 @@ static int bt_parse(const char *opt)
static int drive_init_func(QemuOpts *opts, void *opaque)
{
int *use_scsi = opaque;
- int fatal_error = 0;
- if (drive_init(opts, *use_scsi, &fatal_error) == NULL) {
- if (fatal_error)
- return 1;
- }
- return 0;
+ return drive_init(opts, *use_scsi) == NULL;
}
static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
@@ -666,7 +661,7 @@ static void default_drive(int enable, int snapshot, int
use_scsi,
if (snapshot) {
drive_enable_snapshot(opts, NULL);
}
- if (drive_init_func(opts, &use_scsi)) {
+ if (!drive_init(opts, use_scsi)) {
exit(1);
}
}
--
1.7.2.3
- [Qemu-devel] [PATCH 10/28] ahci: Fix cpu_physical_memory_unmap() argument ordering, (continued)
- [Qemu-devel] [PATCH 10/28] ahci: Fix cpu_physical_memory_unmap() argument ordering, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 18/28] qcow2-refcount: remove write-only variables, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 15/28] qed: Images with backing file do not require QED_F_NEED_CHECK, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 11/28] Reorganize struct Qcow2Cache for better struct packing, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 14/28] qcow2: Add bdrv_discard support, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 17/28] scsi hotplug: Set DriveInfo member bus correctly, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 16/28] raw-win32: Fix bdrv_flush return value, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 24/28] blockdev: Factor drive_index_to_{bus, unit}_id out of drive_init(), Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 27/28] blockdev: Replace drive_add()'s fmt, ... by optstr parameter, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 25/28] blockdev: New drive_get_by_index(), Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 28/28] blockdev: Fix drive_add for drives without media,
Kevin Wolf <=
- [Qemu-devel] [PATCH 19/28] blockdev: New drive_get_next(), replacing qdev_init_bdrv(), Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 06/28] block: tell drivers about an image resize, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 21/28] blockdev: Put BlockInterfaceType names and max_devs in tables, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 13/28] qemu-io: Fix discard command, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 23/28] blockdev: Make drive_add() take explicit type, index parameters, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 20/28] blockdev: Move BlockInterfaceType from qemu-common.h to blockdev.h, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 09/28] Add documentation for STRTOSZ_DEFSUFFIX_ macros, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 26/28] blockdev: Reject multiple definitions for the same drive, Kevin Wolf, 2011/01/31
- [Qemu-devel] [PATCH 22/28] blockdev: Fix regression in -drive if=scsi, index=N, Kevin Wolf, 2011/01/31
- [Qemu-devel] Re: [PULL 00/28] Block patches, Anthony Liguori, 2011/01/31