aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blockdev.c21
-rw-r--r--include/sysemu/blockdev.h2
-rw-r--r--vl.c10
3 files changed, 32 insertions, 1 deletions
diff --git a/blockdev.c b/blockdev.c
index dc94ad319a..48da1a7e0f 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -166,6 +166,27 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)
return NULL;
}
+bool drive_check_orphaned(void)
+{
+ DriveInfo *dinfo;
+ bool rs = false;
+
+ QTAILQ_FOREACH(dinfo, &drives, next) {
+ /* If dinfo->bdrv->dev is NULL, it has no device attached. */
+ /* Unless this is a default drive, this may be an oversight. */
+ if (!dinfo->bdrv->dev && !dinfo->is_default &&
+ dinfo->type != IF_NONE) {
+ fprintf(stderr, "Warning: Orphaned drive without device: "
+ "id=%s,file=%s,if=%s,bus=%d,unit=%d\n",
+ dinfo->id, dinfo->bdrv->filename, if_name[dinfo->type],
+ dinfo->bus, dinfo->unit);
+ rs = true;
+ }
+ }
+
+ return rs;
+}
+
DriveInfo *drive_get_by_index(BlockInterfaceType type, int index)
{
return drive_get(type,
diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h
index abec381049..30402867b9 100644
--- a/include/sysemu/blockdev.h
+++ b/include/sysemu/blockdev.h
@@ -38,6 +38,7 @@ struct DriveInfo {
int unit;
int auto_del; /* see blockdev_mark_auto_del() */
bool enable_auto_del; /* Only for legacy drive_new() */
+ bool is_default; /* Added by default_drive() ? */
int media_cd;
int cyls, heads, secs, trans;
QemuOpts *opts;
@@ -46,6 +47,7 @@ struct DriveInfo {
};
DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
+bool drive_check_orphaned(void);
DriveInfo *drive_get_by_index(BlockInterfaceType type, int index);
int drive_get_max_bus(BlockInterfaceType type);
DriveInfo *drive_get_next(BlockInterfaceType type);
diff --git a/vl.c b/vl.c
index 9d2aaaf1dc..4bc8f97c25 100644
--- a/vl.c
+++ b/vl.c
@@ -1169,6 +1169,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,
int index, const char *optstr)
{
QemuOpts *opts;
+ DriveInfo *dinfo;
if (!enable || drive_get_by_index(type, index)) {
return;
@@ -1178,9 +1179,13 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,
if (snapshot) {
drive_enable_snapshot(opts, NULL);
}
- if (!drive_new(opts, type)) {
+
+ dinfo = drive_new(opts, type);
+ if (!dinfo) {
exit(1);
}
+ dinfo->is_default = true;
+
}
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
@@ -4457,6 +4462,9 @@ int main(int argc, char **argv, char **envp)
if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
exit(1);
+ /* Did we create any drives that we failed to create a device for? */
+ drive_check_orphaned();
+
net_check_clients();
ds = init_displaystate();