From patchwork Mon Feb 8 14:14:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 8249981 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 592B0BEEE5 for ; Mon, 8 Feb 2016 14:14:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BA6FB201E4 for ; Mon, 8 Feb 2016 14:14:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 18E64201D3 for ; Mon, 8 Feb 2016 14:14:43 +0000 (UTC) Received: from localhost ([::1]:45141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSmaQ-0006U9-8F for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Feb 2016 09:14:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSmaF-0006Tq-FA for qemu-devel@nongnu.org; Mon, 08 Feb 2016 09:14:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSmaA-0004U9-CJ for qemu-devel@nongnu.org; Mon, 08 Feb 2016 09:14:31 -0500 Received: from smtp3.mundo-r.com ([212.51.32.191]:14858 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSmaA-0004TY-5c; Mon, 08 Feb 2016 09:14:26 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CMAwA/orhW/5tjdVtdGQEBAQEPAQEBAYMKgT+IW509BQEBAQEBAQUBgQ8BkBqCEwENgWYShXuBLDgUAQEBAQEBAYEKhG9ST040iB8BvQ+FSoI9h0CDbgWWdY1QjnOOPh4BAUKBNgFMGYFKaIhTAQEB X-IPAS-Result: A2CMAwA/orhW/5tjdVtdGQEBAQEPAQEBAYMKgT+IW509BQEBAQEBAQUBgQ8BkBqCEwENgWYShXuBLDgUAQEBAQEBAYEKhG9ST040iB8BvQ+FSoI9h0CDbgWWdY1QjnOOPh4BAUKBNgFMGYFKaIhTAQEB X-IronPort-AV: E=Sophos;i="5.22,416,1449529200"; d="scan'208";a="14096450" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 08 Feb 2016 15:14:21 +0100 Received: from dsl-hkibrasgw4-50df50-201.dhcp.inet.fi ([80.223.80.201] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim) id 1aSma5-0003Db-Ez; Mon, 08 Feb 2016 15:14:21 +0100 Received: from berto by perseus.local with local (Exim 4.86) (envelope-from ) id 1aSmZr-00064i-Rg; Mon, 08 Feb 2016 16:14:07 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 8 Feb 2016 16:14:03 +0200 Message-Id: <7bfce913f68d95284746e7cf3693703f5361b26f.1454940776.git.berto@igalia.com> X-Mailer: git-send-email 2.7.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.51.32.191 Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Subject: [Qemu-devel] [PATCH 1/3] block: Allow x-blockdev-del on a BB with a monitor-owned BDS 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When x-blockdev-del is performed on a BlockBackend that has inserted media it will only succeed if the BDS doesn't have any additional references. The only problem with this is that if the BDS was created separately using blockdev-add then the backend won't be able to be destroyed unless the BDS is ejected first. This is an unnecessary restriction. Now that we have a list of monitor-owned BDSs we can allow x-blockdev-del to work in this scenario if the BDS has exactly one extra reference and that reference is from the monitor. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake --- blockdev.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index e1b6b0f..847058d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3966,9 +3966,16 @@ void qmp_x_blockdev_del(bool has_id, const char *id, } if (bs->refcnt > 1) { - error_setg(errp, "Block device %s is in use", - bdrv_get_device_or_node_name(bs)); - goto out; + /* We allow deleting a BlockBackend that has a BDS with an + * extra reference if that extra reference is from the + * monitor. */ + bool bs_has_only_monitor_ref = + blk && bs->monitor_list.tqe_prev && bs->refcnt == 2; + if (!bs_has_only_monitor_ref) { + error_setg(errp, "Block device %s is in use", + bdrv_get_device_or_node_name(bs)); + goto out; + } } }