From patchwork Mon Sep 29 16:47:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 394508 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AC6FC1400AB for ; Tue, 30 Sep 2014 02:48:42 +1000 (EST) Received: from localhost ([::1]:37818 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYe7r-0005Fa-7F for incoming@patchwork.ozlabs.org; Mon, 29 Sep 2014 12:48:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYe7C-0004G9-TV for qemu-devel@nongnu.org; Mon, 29 Sep 2014 12:48:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XYe75-00069J-R2 for qemu-devel@nongnu.org; Mon, 29 Sep 2014 12:47:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13117) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYe75-00066C-K5 for qemu-devel@nongnu.org; Mon, 29 Sep 2014 12:47:51 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8TGlj7Y006604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 29 Sep 2014 12:47:45 -0400 Received: from dhcp-17-12.bos.redhat.com ([10.18.17.209]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8TGlhu1014993; Mon, 29 Sep 2014 12:47:44 -0400 From: John Snow To: qemu-devel@nongnu.org Date: Mon, 29 Sep 2014 12:47:13 -0400 Message-Id: <1412009238-13530-2-git-send-email-jsnow@redhat.com> In-Reply-To: <1412009238-13530-1-git-send-email-jsnow@redhat.com> References: <1412009238-13530-1-git-send-email-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, John Snow , armbru@redhat.com, stefanha@redhat.com, mst@redhat.com Subject: [Qemu-devel] [PATCH v2 1/6] blockdev: Orphaned drive search X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When users use command line options like -hda, -cdrom, or even -drive if=ide, it is up to the board initialization routines to pick up these drives and create backing devices for them. Some boards, like Q35, have not been doing this. However, there is no warning explaining why certain drive specifications are just silently ignored, so this function adds a check to print some warnings to assist users in debugging these sorts of issues in the future. This patch will not warn about drives added with if_none, for which it is not possible to tell in advance if the omission of a backing device is an issue. A warning in these cases is considered appropriate. Signed-off-by: John Snow --- blockdev.c | 21 +++++++++++++++++++++ include/sysemu/blockdev.h | 2 ++ vl.c | 10 +++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index b361fbb..81398e7 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 23a5d10..80f768d 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 dbdca59..6500472 100644 --- a/vl.c +++ b/vl.c @@ -1168,6 +1168,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; @@ -1177,9 +1178,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) @@ -4458,6 +4463,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();