From patchwork Wed Sep 13 18:18:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 9951843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E6538602C9 for ; Wed, 13 Sep 2017 18:21:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFC3828836 for ; Wed, 13 Sep 2017 18:21:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D464C28968; Wed, 13 Sep 2017 18:21:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 6B55A28836 for ; Wed, 13 Sep 2017 18:21:28 +0000 (UTC) Received: from localhost ([::1]:43982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsCHY-0007eH-Kz for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Sep 2017 14:21:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36390) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsCG3-0007ah-P7 for qemu-devel@nongnu.org; Wed, 13 Sep 2017 14:19:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsCG2-0004bc-Ky for qemu-devel@nongnu.org; Wed, 13 Sep 2017 14:19:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50038) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsCG0-0004a2-BN; Wed, 13 Sep 2017 14:19:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78A5E81DE4; Wed, 13 Sep 2017 18:19:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 78A5E81DE4 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com Received: from localhost (ovpn-204-23.brq.redhat.com [10.40.204.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FD0C5D724; Wed, 13 Sep 2017 18:19:21 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 13 Sep 2017 20:18:53 +0200 Message-Id: <20170913181910.29688-2-mreitz@redhat.com> In-Reply-To: <20170913181910.29688-1-mreitz@redhat.com> References: <20170913181910.29688-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 13 Sep 2017 18:19:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/18] block: Add BdrvDeletedStatus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Max Reitz , Stefan Hajnoczi , John Snow Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Sometimes an operation may delete a BDS. It may then not be trivial to determine this because the BDS object itself cannot be accessed afterwards. With this patch, one can attach a BdrvDeletedStatus object to a BDS which can be used to safely query whether the BDS still exists even after it has been deleted. Signed-off-by: Max Reitz --- include/block/block_int.h | 12 ++++++++++++ block.c | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/include/block/block_int.h b/include/block/block_int.h index ba4c383393..eaeaad9428 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -498,6 +498,13 @@ typedef struct BdrvAioNotifier { QLIST_ENTRY(BdrvAioNotifier) list; } BdrvAioNotifier; +typedef struct BdrvDeletedStatus { + /* Set to true by bdrv_delete() */ + bool deleted; + + QLIST_ENTRY(BdrvDeletedStatus) next; +} BdrvDeletedStatus; + struct BdrvChildRole { /* If true, bdrv_replace_node() doesn't change the node this BdrvChild * points to. */ @@ -706,6 +713,11 @@ struct BlockDriverState { /* Only read/written by whoever has set active_flush_req to true. */ unsigned int flushed_gen; /* Flushed write generation */ + + /* When bdrv_delete() is invoked, it will walk through this list + * and set every entry's @deleted field to true. The entries will + * not be freed automatically. */ + QLIST_HEAD(, BdrvDeletedStatus) deleted_status; }; struct BlockBackendRootState { diff --git a/block.c b/block.c index 6dd47e414e..0b55c5a41c 100644 --- a/block.c +++ b/block.c @@ -3246,10 +3246,16 @@ out: static void bdrv_delete(BlockDriverState *bs) { + BdrvDeletedStatus *del_stat; + assert(!bs->job); assert(bdrv_op_blocker_is_empty(bs)); assert(!bs->refcnt); + QLIST_FOREACH(del_stat, &bs->deleted_status, next) { + del_stat->deleted = true; + } + bdrv_close(bs); /* remove from list, if necessary */