From patchwork Fri Jun 12 13:26:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 49825 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A468C20C81 for ; Fri, 12 Jun 2015 13:26:19 +0000 (UTC) Received: by laboh3 with SMTP id oh3sf10749079lab.0 for ; Fri, 12 Jun 2015 06:26:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=n9TLqCb7atu+PwYLcVe0W/RR93E2Cfekvxa4OBxR3lQ=; b=Brx46be5OxhIEb0BuiimJTYgjcd3S/4l0HSGja8TNRC7s4DQ3REskxjKLs3nagJHYu EMkURdmGyXTtQoZWhDgEtzmmSoHumM312FqE2q+k0692i6raLGeW6NFXMtCjHaal4Nou wwvAM2uuMDCGHJmP4iAguTJdEp4jjpC1npbOdcGpWFaEPndDSLMgy+FIFoxvV9DlLrPe GEYrbD5qJ8Bwwvz7GHZ+5Sezh4UBnzk+iqCntn23A8/moT6qVPK+I9CxZ8uNjtbJ/VgG sw8UEIeODs23lgBQ8ZTCp4+kxnjcGSV1mkjSUMTJBgFVfbve8K8Kx4vueqgY5SJKMwsN TiZA== X-Gm-Message-State: ALoCoQl/pHsnfP+m1s4t4IiOTDxsKXWTQaEJd+JrfP8g2+yBycqNmWzelw0qF+Ej6N1Cq/2iK/A3 X-Received: by 10.180.37.198 with SMTP id a6mr4135211wik.7.1434115578586; Fri, 12 Jun 2015 06:26:18 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.129 with SMTP id s1ls346721las.89.gmail; Fri, 12 Jun 2015 06:26:18 -0700 (PDT) X-Received: by 10.152.29.34 with SMTP id g2mr15128173lah.73.1434115578425; Fri, 12 Jun 2015 06:26:18 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id ky4si3394084lab.70.2015.06.12.06.26.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 06:26:18 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbcmx3 with SMTP id mx3so20064400lbc.1 for ; Fri, 12 Jun 2015 06:26:18 -0700 (PDT) X-Received: by 10.112.234.200 with SMTP id ug8mr14978660lbc.117.1434115578230; Fri, 12 Jun 2015 06:26:18 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp565554lbb; Fri, 12 Jun 2015 06:26:17 -0700 (PDT) X-Received: by 10.181.27.131 with SMTP id jg3mr6785765wid.89.1434115577388; Fri, 12 Jun 2015 06:26:17 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id kw8si7130360wjb.181.2015.06.12.06.26.17 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 12 Jun 2015 06:26:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Z3OyO-0001st-0x; Fri, 12 Jun 2015 14:26:16 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Markus Armbruster , Kevin Wolf , qemu-block@nongnu.org Subject: [PATCH 1/4] block: Warn if an if= drive was also connected manually Date: Fri, 12 Jun 2015 14:26:12 +0100 Message-Id: <1434115575-7214-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1434115575-7214-1-git-send-email-peter.maydell@linaro.org> References: <1434115575-7214-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Improve the diagnosis of command line errors where the user requested an automatic connection of a drive (via if=, or by not setting if= and using the board-default-if). We already fail this case if the board actually handles if=, but if the board did not auto-connect the drive we should at least warn about the problem, since the most likely reason is a forgotten if=none, and this command line might become an error if the board starts handling this if= type in future. To do this we need to identify when a drive is automatically connected by the board; we do this by assuming that all calls to blk_by_legacy_dinfo() imply that we're about to assign the drive to a device. This is a slightly ugly place to make the test, but simpler than trying to locate and change every place in the code that does automatic drive handling, and the worst case is that we might print out a spurious warning. Signed-off-by: Peter Maydell --- block/block-backend.c | 4 ++++ blockdev.c | 39 +++++++++++++++++++++++++++++++++++++++ include/sysemu/blockdev.h | 2 ++ 3 files changed, 45 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 93e46f3..a45c207 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -260,6 +260,9 @@ DriveInfo *blk_set_legacy_dinfo(BlockBackend *blk, DriveInfo *dinfo) /* * Return the BlockBackend with DriveInfo @dinfo. * It must exist. + * For the purposes of providing helpful error messages, we assume + * that any call to this function implies that the drive is going + * to be automatically claimed by the board model. */ BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo) { @@ -267,6 +270,7 @@ BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo) QTAILQ_FOREACH(blk, &blk_backends, link) { if (blk->legacy_dinfo == dinfo) { + dinfo->auto_claimed = true; return blk; } } diff --git a/blockdev.c b/blockdev.c index de94a8b..97a56b9 100644 --- a/blockdev.c +++ b/blockdev.c @@ -230,6 +230,32 @@ bool drive_check_orphaned(void) dinfo->bus, dinfo->unit); rs = true; } + if (blk_get_attached_dev(blk) && dinfo->type != IF_NONE && + !dinfo->auto_claimed) { + /* This drive is attached to something, but it was specified + * with if= and it's not attached because it was + * automatically claimed by the board code because of the if= + * specification. The user probably forgot an if=none. + */ + fprintf(stderr, + "Warning: automatic connection of this drive requested "); + if (dinfo->type_is_board_default) { + fprintf(stderr, "(because if= was not specified and this " + "machine defaults to if=%s) ", + if_name[dinfo->type]); + } else { + fprintf(stderr, "(because if=%s was specified) ", + if_name[dinfo->type]); + } + fprintf(stderr, + "but it was also connected manually to a device: " + "id=%s,file=%s,if=%s,bus=%d,unit=%d\n" + "(If you don't want this drive auto-connected, " + "use if=none.)\n", + blk_name(blk), blk_bs(blk)->filename, if_name[dinfo->type], + dinfo->bus, dinfo->unit); + rs = true; + } } return rs; @@ -683,6 +709,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) const char *werror, *rerror; bool read_only = false; bool copy_on_read; + bool type_is_board_default = false; const char *serial; const char *filename; Error *local_err = NULL; @@ -808,6 +835,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) } } else { type = block_default_type; + type_is_board_default = true; } /* Geometry */ @@ -994,6 +1022,17 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) dinfo->devaddr = devaddr; dinfo->serial = g_strdup(serial); + if (type == IF_VIRTIO) { + /* We created the automatic device earlier. For other types this + * will be set to true at the point where the drive is claimed + * by the IDE/SCSI/etc bus, when that code calls blk_by_legacy_dinfo() + * to find the block backend from the drive. + */ + dinfo->auto_claimed = true; + } + + dinfo->type_is_board_default = type_is_board_default; + blk_set_legacy_dinfo(blk, dinfo); switch(type) { diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index 3104150..f9c44e2 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -36,6 +36,8 @@ struct DriveInfo { int unit; int auto_del; /* see blockdev_mark_auto_del() */ bool is_default; /* Added by default_drive() ? */ + bool auto_claimed; /* Automatically claimed by board model? */ + bool type_is_board_default; /* type is from board default, not user 'if=' */ int media_cd; int cyls, heads, secs, trans; QemuOpts *opts;