From patchwork Fri Sep 12 15:57:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 388722 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 1824F1401AF for ; Sat, 13 Sep 2014 02:08:19 +1000 (EST) Received: from localhost ([::1]:46001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSTOT-0002zF-2q for incoming@patchwork.ozlabs.org; Fri, 12 Sep 2014 12:08:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSTEA-0000dg-K6 for qemu-devel@nongnu.org; Fri, 12 Sep 2014 11:57:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XSTE4-0000n1-Fq for qemu-devel@nongnu.org; Fri, 12 Sep 2014 11:57:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22969) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSTE4-0000mu-7Q for qemu-devel@nongnu.org; Fri, 12 Sep 2014 11:57:32 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8CFvVCx021870 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 12 Sep 2014 11:57:31 -0400 Received: from noname.redhat.com (ovpn-116-108.ams2.redhat.com [10.36.116.108]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8CFv87x022313; Fri, 12 Sep 2014 11:57:30 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 12 Sep 2014 17:57:00 +0200 Message-Id: <1410537426-9917-17-git-send-email-kwolf@redhat.com> In-Reply-To: <1410537426-9917-1-git-send-email-kwolf@redhat.com> References: <1410537426-9917-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PULL 16/22] blockdev: Refuse to drive_del something added with blockdev-add 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 From: Markus Armbruster For some device models, the guest can prevent unplug. Some users need a way to forcibly revoke device model access to the block backend then, so the underlying images can be safely used for something else. drive_del lets you do that. Unfortunately, it conflates revoking access with destroying the backend. Commit 9063f81 made drive_del immediately destroy the root BDS. Nice: the device name becomes available for reuse immediately. Not so nice: the device model's pointer to the root BDS dangles, and we're prone to crash when the memory gets reused. Commit d22b2f4 fixed that by hiding the root BDS instead of destroying it. Destruction only happens on unplug. "Hiding" means removing it from bdrv_states and graph_bdrv_states; see bdrv_make_anon(). This "destroy on revoke" is a misfeature we don't want to carry forward to blockdev-add, just like "destroy on unplug" (commit 2d246f0). So make drive_del fail on anything added with blockdev-add. We'll add separate QMP commands to revoke device model access and to destroy backends. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- blockdev.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index e919566..b361fbb 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1739,6 +1739,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *id = qdict_get_str(qdict, "id"); BlockDriverState *bs; + DriveInfo *dinfo; AioContext *aio_context; Error *local_err = NULL; @@ -1748,6 +1749,13 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) return -1; } + dinfo = drive_get_by_blockdev(bs); + if (dinfo && !dinfo->enable_auto_del) { + error_report("Deleting device added with blockdev-add" + " is not supported"); + return -1; + } + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); @@ -1775,7 +1783,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT); } else { - drive_del(drive_get_by_blockdev(bs)); + drive_del(dinfo); } aio_context_release(aio_context);