From patchwork Mon Nov 11 16:01:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237281 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01B44159A for ; Mon, 11 Nov 2019 16:05:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC1002190F for ; Mon, 11 Nov 2019 16:05:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XDBjLTSt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC1002190F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCBa-0001dK-G4 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:05:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38865) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC95-0007Wx-MI for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC94-0002bv-Ad for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:27 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:53346 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC94-0002bn-6V for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488145; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JhPkULzpAKB6qvX8JHd2YYQL6Gxr+IDduoxSVeSIPns=; b=XDBjLTStd4oLn29iLQawYhFfHSff1m/tfIVAcLNdCu1TlNV+derus7qHv3Nzx8uKq78e/6 imj1mSWukEsWQmKQIxUVGvL8ZOWEo4csJfZdbrfG7aUyVjw0nnHrO9qybejsc5m4pp66QJ GJHRGQUWu2U6PHkSNFqUWSegNpqDpsM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-257-88TrCnz0N0G_8jV1Bn_KMg-1; Mon, 11 Nov 2019 11:02:23 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D21E5805D81; Mon, 11 Nov 2019 16:02:22 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 532FF600CC; Mon, 11 Nov 2019 16:02:20 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 01/23] blockdev: Allow external snapshots everywhere Date: Mon, 11 Nov 2019 17:01:54 +0100 Message-Id: <20191111160216.197086-2-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 88TrCnz0N0G_8jV1Bn_KMg-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" There is no good reason why we would allow external snapshots only on the first non-filter node in a chain. Parent BDSs should not care whether their child is replaced by a snapshot. (If they do care, they should announce that via freezing the chain, which is checked in bdrv_append() through bdrv_set_backing_hd().) Before we had bdrv_is_first_non_filter() here (since 212a5a8f095), there was a special function bdrv_check_ext_snapshot() that allowed snapshots by default, but block drivers could override this. Only blkverify did so, however. It is not clear to me why blkverify would do so; maybe just so that the testee block driver would not be replaced. The introducing commit f6186f49e2c does not explain why. Maybe because 08b24cfe376 would have been the correct solution? (Which adds a .supports_backing check.) Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- blockdev.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/blockdev.c b/blockdev.c index 8e029e9c01..ab78230d23 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1595,11 +1595,6 @@ static void external_snapshot_prepare(BlkActionState *common, } } - if (!bdrv_is_first_non_filter(state->old_bs)) { - error_setg(errp, QERR_FEATURE_DISABLED, "snapshot"); - goto out; - } - if (action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC) { BlockdevSnapshotSync *s = action->u.blockdev_snapshot_sync.data; const char *format = s->has_format ? s->format : "qcow2"; From patchwork Mon Nov 11 16:01:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237289 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E98815AB for ; Mon, 11 Nov 2019 16:08:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D93FB21E6F for ; Mon, 11 Nov 2019 16:08:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="C4wvlncZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D93FB21E6F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54577 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCEb-0006AJ-HD for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:08:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38896) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9B-0007cx-Hb for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9A-0002eD-3n for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:33 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:29496 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9A-0002e5-0f for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oYWxyAmuO3FgSq/YJGZHxk4ZXvR/0OK0pMpLY2h3gm4=; b=C4wvlncZUCA9vCFR8LHSeyshJe0w0CsrEzwLsOe9LFzs0oP71K2vgijTNnvYtAU+tKi3Uo w1U+Z1GLLpeZfHxVvS4NyJqOMzQWy2YEfEXQF0QSx152IZP0VLZ9IZ3oVzOQTSX6he2WtO VGm400hLcAqO3rGj1J7pK74sW6NGNuk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-102-pNgn-R6eN7OgKlM3jpjfjw-1; Mon, 11 Nov 2019 11:02:28 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E57B18A3097; Mon, 11 Nov 2019 16:02:26 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50D1367154; Mon, 11 Nov 2019 16:02:25 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 02/23] blockdev: Allow resizing everywhere Date: Mon, 11 Nov 2019 17:01:55 +0100 Message-Id: <20191111160216.197086-3-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: pNgn-R6eN7OgKlM3jpjfjw-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Block nodes that do not allow resizing should not share BLK_PERM_RESIZE. It does not matter whether they are the first non-filter in their chain or not. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- blockdev.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/blockdev.c b/blockdev.c index ab78230d23..9dc2238bf3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3177,11 +3177,6 @@ void qmp_block_resize(bool has_device, const char *device, aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); - if (!bdrv_is_first_non_filter(bs)) { - error_setg(errp, QERR_FEATURE_DISABLED, "resize"); - goto out; - } - if (size < 0) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size"); goto out; From patchwork Mon Nov 11 16:01:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237287 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B123159A for ; Mon, 11 Nov 2019 16:07:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 106D02190F for ; Mon, 11 Nov 2019 16:07:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LQRgXddf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 106D02190F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCEC-0005T3-SR for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:07:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38917) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9E-0007gP-6d for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9C-0002hT-Vn for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:36 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:26572 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9C-0002hH-SA for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ci3tBGhBQMbp9g6rpjNCLTiGWuLZL0KUEDcu2z4zqdk=; b=LQRgXddfS5l3HpDhZw4Ft1G4c6AGPrRLyQ4F4PB6BDRRwjLydTb8L98V7oU3MjxMMGVP8+ NBxoOWSOOuiuc2EWSryOtCJiIkZtMhPEuWXspemOyN8oio2Jk+QROmPxCTIjdqFlPGlVq+ uCiwHO7kRkR8vSbEZFsZjdQe4E5tqLk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-260-qj3YBVAHMLqHfZVSPVcVEg-1; Mon, 11 Nov 2019 11:02:30 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F196D100550E; Mon, 11 Nov 2019 16:02:28 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 948806106C; Mon, 11 Nov 2019 16:02:28 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 03/23] block: Drop bdrv_is_first_non_filter() Date: Mon, 11 Nov 2019 17:01:56 +0100 Message-Id: <20191111160216.197086-4-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: qj3YBVAHMLqHfZVSPVcVEg-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" It is unused now. (And it was ugly because it needed to explore all BDS chains from the top.) Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 26 -------------------------- include/block/block.h | 1 - 2 files changed, 27 deletions(-) diff --git a/block.c b/block.c index ae279ff21f..9b1049786a 100644 --- a/block.c +++ b/block.c @@ -6205,32 +6205,6 @@ bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs, return false; } -/* This function checks if the candidate is the first non filter bs down it's - * bs chain. Since we don't have pointers to parents it explore all bs chains - * from the top. Some filters can choose not to pass down the recursion. - */ -bool bdrv_is_first_non_filter(BlockDriverState *candidate) -{ - BlockDriverState *bs; - BdrvNextIterator it; - - /* walk down the bs forest recursively */ - for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { - bool perm; - - /* try to recurse in this top level bs */ - perm = bdrv_recurse_is_first_non_filter(bs, candidate); - - /* candidate is the first non filter */ - if (perm) { - bdrv_next_cleanup(&it); - return true; - } - } - - return false; -} - BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, const char *node_name, Error **errp) { diff --git a/include/block/block.h b/include/block/block.h index e9dcfef7fa..8f6a0cad9c 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -404,7 +404,6 @@ int bdrv_amend_options(BlockDriverState *bs_new, QemuOpts *opts, /* external snapshots */ bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs, BlockDriverState *candidate); -bool bdrv_is_first_non_filter(BlockDriverState *candidate); /* check if a named node can be replaced when doing drive-mirror */ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, From patchwork Mon Nov 11 16:01:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237291 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F8FE159A for ; Mon, 11 Nov 2019 16:08:16 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0654B21E6F for ; Mon, 11 Nov 2019 16:08:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ccoNezzC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0654B21E6F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCEg-0006Id-KK for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:08:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38942) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9G-0007k8-Uw for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9F-0002ic-L7 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:38 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:32132 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9F-0002iR-GO for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488157; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6JuuBg3yIfbXvKOIwpye2mO65C0TEQ6XQ2POeXscqTY=; b=ccoNezzCLV4SaJgy7VAafNMj6qb+snARgNZoXAKeFdp6/8hcjwwSNAN6Snu3T0bGPWVCa9 2zXR4OCRxaCNL0rKdLyVt2Yk6rtpuEy0GpoaO5+5dXYI60AKJY1XnqTvA+2Dqn5IsiVJrh +/foaroSoW4XSnIOyo48A8dAp87xSdI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-bqG8W5D-M4SgmCJoz4t_SQ-1; Mon, 11 Nov 2019 11:02:32 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A57F7805D84; Mon, 11 Nov 2019 16:02:31 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20EA54521; Mon, 11 Nov 2019 16:02:30 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 04/23] iotests: Let 041 use -blockdev for quorum children Date: Mon, 11 Nov 2019 17:01:57 +0100 Message-Id: <20191111160216.197086-5-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: bqG8W5D-M4SgmCJoz4t_SQ-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Using -drive with default options means that a virtio-blk drive will be created that has write access to the to-be quorum children. Quorum should have exclusive write access to them, so we should use -blockdev instead. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/041 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index d7be30b62b..3c60c07b01 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -884,7 +884,10 @@ class TestRepairQuorum(iotests.QMPTestCase): # Assign a node name to each quorum image in order to manipulate # them opts = "node-name=img%i" % self.IMAGES.index(i) - self.vm = self.vm.add_drive(i, opts) + opts += ',driver=%s' % iotests.imgfmt + opts += ',file.driver=file' + opts += ',file.filename=%s' % i + self.vm = self.vm.add_blockdev(opts) self.vm.launch() From patchwork Mon Nov 11 16:01:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237299 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A93FB159A for ; Mon, 11 Nov 2019 16:11:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7F9CC21E6F for ; Mon, 11 Nov 2019 16:11:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XVRjeb4a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F9CC21E6F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCHU-0001ge-79 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:11:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38958) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9I-0007lk-6V for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9H-0002j3-0Y for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:40 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:52032 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9G-0002iq-SY for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488158; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3JbotJTxHKKKYfV5r8+bH/XRYV/UHb25zxWl0uaJ7H8=; b=XVRjeb4ahLZnplYrDUdMG1cwAzg6TCFAjQpouoh1QFzBWPZ1S8HY0C8ldVyDBHcd9i2bbu kDk+fGqZRGlS38B/66pZJL10AnamsCTWdywMKkKeUeYRE/QWiXLuXB/x7q+f6TTzCNdBJV tBP+/gfmm+a5aLzWlZ34S9IwOrvdjic= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-lwbNUFThMwK9Y2yJ9yRdJQ-1; Mon, 11 Nov 2019 11:02:35 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5194B18B5F81; Mon, 11 Nov 2019 16:02:34 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C176A5D9C9; Mon, 11 Nov 2019 16:02:33 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 05/23] quorum: Fix child permissions Date: Mon, 11 Nov 2019 17:01:58 +0100 Message-Id: <20191111160216.197086-6-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: lwbNUFThMwK9Y2yJ9yRdJQ-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Quorum cannot share WRITE or RESIZE on its children. Presumably, it only does so because as a filter, it seemed intuitively correct to point its .bdrv_child_perm to bdrv_filter_default_perm(). However, it is not really a filter, and bdrv_filter_default_perm() does not work for it, so we have to provide a custom .bdrv_child_perm implementation. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/quorum.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/block/quorum.c b/block/quorum.c index df68adcfaa..17b439056f 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1114,6 +1114,23 @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp) return NULL; } +static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + *nperm = perm & DEFAULT_PERM_PASSTHROUGH; + + /* + * We cannot share RESIZE or WRITE, as this would make the + * children differ from each other. + */ + *nshared = (shared & (BLK_PERM_CONSISTENT_READ | + BLK_PERM_WRITE_UNCHANGED)) + | DEFAULT_PERM_UNCHANGED; +} + static const char *const quorum_strong_runtime_opts[] = { QUORUM_OPT_VOTE_THRESHOLD, QUORUM_OPT_BLKVERIFY, @@ -1143,7 +1160,7 @@ static BlockDriver bdrv_quorum = { .bdrv_add_child = quorum_add_child, .bdrv_del_child = quorum_del_child, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = quorum_child_perm, .is_filter = true, .bdrv_recurse_is_first_non_filter = quorum_recurse_is_first_non_filter, From patchwork Mon Nov 11 16:01:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237305 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13BB31709 for ; Mon, 11 Nov 2019 16:14:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE6E920856 for ; Mon, 11 Nov 2019 16:13:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bjfiyDGn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE6E920856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCKE-0005AI-FU for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:13:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38992) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9L-0007pb-Il for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9K-0002kI-9f for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:43 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:26391 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9K-0002kA-51 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q1v7i5SHUOGNmsZ/v/MshgeRxWVOaV5oHiAq5a4o24E=; b=bjfiyDGnhdL8rS+IvrI6sCfKsXKNA76B0zGYPrXm9dDQNDuD8nIIuWJ9IqwUb0R3K3M9Zo lh23DQ7PxxM+7CUTlCcahCCcejQXt21MRDYIkQEyaH0KTHWleQkf1ZeZBeJSquGCrIqgLe BE/lgRu93mXAKI0h6k1AUQC7bkH97eQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-168-aGxf9YByOraTu5KyR0fMJw-1; Mon, 11 Nov 2019 11:02:38 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 66A0C800C72; Mon, 11 Nov 2019 16:02:37 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D05AF608FB; Mon, 11 Nov 2019 16:02:36 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 06/23] block: Add bdrv_recurse_can_replace() Date: Mon, 11 Nov 2019 17:01:59 +0100 Message-Id: <20191111160216.197086-7-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: aGxf9YByOraTu5KyR0fMJw-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" After a couple of follow-up patches, this function will replace bdrv_recurse_is_first_non_filter() in check_to_replace_node(). bdrv_recurse_is_first_non_filter() is both not sufficiently specific for check_to_replace_node() (it allows cases that should not be allowed, like replacing child nodes of quorum with dissenting data that have more parents than just quorum), and it is too restrictive (it is perfectly fine to replace filters). Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 38 ++++++++++++++++++++++++++++++++++++++ include/block/block_int.h | 10 ++++++++++ 2 files changed, 48 insertions(+) diff --git a/block.c b/block.c index 9b1049786a..de53addeb0 100644 --- a/block.c +++ b/block.c @@ -6205,6 +6205,44 @@ bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs, return false; } +/* + * This function checks whether the given @to_replace is allowed to be + * replaced by a node that always shows the same data as @bs. This is + * used for example to verify whether the mirror job can replace + * @to_replace by the target mirrored from @bs. + * To be replaceable, @bs and @to_replace may either be guaranteed to + * always show the same data (because they are only connected through + * filters), or some driver may allow replacing one of its children + * because it can guarantee that this child's data is not visible at + * all (for example, for dissenting quorum children that have no other + * parents). + */ +bool bdrv_recurse_can_replace(BlockDriverState *bs, + BlockDriverState *to_replace) +{ + if (!bs || !bs->drv) { + return false; + } + + if (bs == to_replace) { + return true; + } + + /* See what the driver can do */ + if (bs->drv->bdrv_recurse_can_replace) { + return bs->drv->bdrv_recurse_can_replace(bs, to_replace); + } + + /* For filters without an own implementation, we can recurse on our own */ + if (bs->drv->is_filter) { + BdrvChild *child = bs->file ?: bs->backing; + return bdrv_recurse_can_replace(child->bs, to_replace); + } + + /* Safe default */ + return false; +} + BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, const char *node_name, Error **errp) { diff --git a/include/block/block_int.h b/include/block/block_int.h index dd033d0b37..75f03dcc38 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -102,6 +102,13 @@ struct BlockDriver { */ bool (*bdrv_recurse_is_first_non_filter)(BlockDriverState *bs, BlockDriverState *candidate); + /* + * Return true if @to_replace can be replaced by a BDS with the + * same data as @bs without it affecting @bs's behavior (that is, + * without it being visible to @bs's parents). + */ + bool (*bdrv_recurse_can_replace)(BlockDriverState *bs, + BlockDriverState *to_replace); int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename); int (*bdrv_probe_device)(const char *filename); @@ -1264,6 +1271,9 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared); +bool bdrv_recurse_can_replace(BlockDriverState *bs, + BlockDriverState *to_replace); + /* * Default implementation for drivers to pass bdrv_co_block_status() to * their file. From patchwork Mon Nov 11 16:02:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237295 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B440159A for ; Mon, 11 Nov 2019 16:11:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D564D21E6F for ; Mon, 11 Nov 2019 16:11:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IoWLjt5m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D564D21E6F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCHO-0001Xo-Ms for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:11:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39014) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9O-0007tr-5k for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9M-0002l8-Vp for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:45 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:45960 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9M-0002kq-Pv for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YBxYyLElSLzboh8cesGsJMPgXDGU3wNgSyzMbJz9L+E=; b=IoWLjt5mrSodjPqzR57cgGzTt0joOdUT1c6znlxSoJSUeXJErGOtbTtv3zi7X/mOOi7cLz +/+UgrABdvZJFQrkj4oSKxtpbFwzE6oFW0V/thUUvpGUq8eLGRLn2gjh3SzBGcjP9o5wNf l/pAm7j883hRDkoxVL2QGCtqJHuJ+I4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-307-kadYVi_PNMiRCla8N5kaKw-1; Mon, 11 Nov 2019 11:02:41 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7267B911E8; Mon, 11 Nov 2019 16:02:40 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E24DA608FB; Mon, 11 Nov 2019 16:02:39 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 07/23] blkverify: Implement .bdrv_recurse_can_replace() Date: Mon, 11 Nov 2019 17:02:00 +0100 Message-Id: <20191111160216.197086-8-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: kadYVi_PNMiRCla8N5kaKw-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/blkverify.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/block/blkverify.c b/block/blkverify.c index 304b0a1368..0add3ab483 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -282,6 +282,20 @@ static bool blkverify_recurse_is_first_non_filter(BlockDriverState *bs, return bdrv_recurse_is_first_non_filter(s->test_file->bs, candidate); } +static bool blkverify_recurse_can_replace(BlockDriverState *bs, + BlockDriverState *to_replace) +{ + BDRVBlkverifyState *s = bs->opaque; + + /* + * blkverify quits the whole qemu process if there is a mismatch + * between bs->file->bs and s->test_file->bs. Therefore, we know + * know that both must match bs and we can recurse down to either. + */ + return bdrv_recurse_can_replace(bs->file->bs, to_replace) || + bdrv_recurse_can_replace(s->test_file->bs, to_replace); +} + static void blkverify_refresh_filename(BlockDriverState *bs) { BDRVBlkverifyState *s = bs->opaque; @@ -328,6 +342,7 @@ static BlockDriver bdrv_blkverify = { .is_filter = true, .bdrv_recurse_is_first_non_filter = blkverify_recurse_is_first_non_filter, + .bdrv_recurse_can_replace = blkverify_recurse_can_replace, }; static void bdrv_blkverify_init(void) From patchwork Mon Nov 11 16:02:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237297 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDCB5159A for ; Mon, 11 Nov 2019 16:11:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C427B21E6F for ; Mon, 11 Nov 2019 16:11:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PBuf8nGf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C427B21E6F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCHS-0001di-FE for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:11:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39048) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9S-0007yb-Kz for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9Q-0002mA-Mj for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:50 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:27588 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9Q-0002m2-Hc for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cXa4wTze/T+4Gu/yeb0QaCnonZ0OhfMJIpz3c3Ils4k=; b=PBuf8nGfHUywH3emgSP58xKeFgFTTRjIBWUSJ18iozKY4NYC23jg4Rd/3UVCBGaQF7gjgc i3hMqc+zRmlT/BC3+Rk01ZcG2wV/sGCLy3YSUHk6iPZIfCVPR1nnEAccL7Ukd3dvfmJsIZ DEkfkpy1gyBeT5NmmjgwoFTjTUTOv4Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-383-bLwSvupOMXWixPQYH9Et-Q-1; Mon, 11 Nov 2019 11:02:44 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D89D3801E69; Mon, 11 Nov 2019 16:02:43 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02F60608FB; Mon, 11 Nov 2019 16:02:42 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 08/23] quorum: Store children in own structure Date: Mon, 11 Nov 2019 17:02:01 +0100 Message-Id: <20191111160216.197086-9-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: bLwSvupOMXWixPQYH9Et-Q-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This will be useful when we want to store additional attributes for each child. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/quorum.c | 64 ++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/block/quorum.c b/block/quorum.c index 17b439056f..59cd524502 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -65,9 +65,13 @@ typedef struct QuorumVotes { bool (*compare)(QuorumVoteValue *a, QuorumVoteValue *b); } QuorumVotes; +typedef struct QuorumChild { + BdrvChild *child; +} QuorumChild; + /* the following structure holds the state of one quorum instance */ typedef struct BDRVQuorumState { - BdrvChild **children; /* children BlockDriverStates */ + QuorumChild *children; int num_children; /* children count */ unsigned next_child_index; /* the index of the next child that should * be added @@ -264,7 +268,7 @@ static void quorum_report_bad_versions(BDRVQuorumState *s, } QLIST_FOREACH(item, &version->items, next) { quorum_report_bad(QUORUM_OP_TYPE_READ, acb->offset, acb->bytes, - s->children[item->index]->bs->node_name, 0); + s->children[item->index].child->bs->node_name, 0); } } } @@ -279,7 +283,7 @@ static void quorum_rewrite_entry(void *opaque) * corrupted data. * Mask out BDRV_REQ_WRITE_UNCHANGED because this overwrites the * area with different data from the other children. */ - bdrv_co_pwritev(s->children[co->idx], acb->offset, acb->bytes, + bdrv_co_pwritev(s->children[co->idx].child, acb->offset, acb->bytes, acb->qiov, acb->flags & ~BDRV_REQ_WRITE_UNCHANGED); /* Wake up the caller after the last rewrite */ @@ -578,8 +582,8 @@ static void read_quorum_children_entry(void *opaque) int i = co->idx; QuorumChildRequest *sacb = &acb->qcrs[i]; - sacb->bs = s->children[i]->bs; - sacb->ret = bdrv_co_preadv(s->children[i], acb->offset, acb->bytes, + sacb->bs = s->children[i].child->bs; + sacb->ret = bdrv_co_preadv(s->children[i].child, acb->offset, acb->bytes, &acb->qcrs[i].qiov, 0); if (sacb->ret == 0) { @@ -605,7 +609,8 @@ static int read_quorum_children(QuorumAIOCB *acb) acb->children_read = s->num_children; for (i = 0; i < s->num_children; i++) { - acb->qcrs[i].buf = qemu_blockalign(s->children[i]->bs, acb->qiov->size); + acb->qcrs[i].buf = qemu_blockalign(s->children[i].child->bs, + acb->qiov->size); qemu_iovec_init(&acb->qcrs[i].qiov, acb->qiov->niov); qemu_iovec_clone(&acb->qcrs[i].qiov, acb->qiov, acb->qcrs[i].buf); } @@ -647,8 +652,8 @@ static int read_fifo_child(QuorumAIOCB *acb) /* We try to read the next child in FIFO order if we failed to read */ do { n = acb->children_read++; - acb->qcrs[n].bs = s->children[n]->bs; - ret = bdrv_co_preadv(s->children[n], acb->offset, acb->bytes, + acb->qcrs[n].bs = s->children[n].child->bs; + ret = bdrv_co_preadv(s->children[n].child, acb->offset, acb->bytes, acb->qiov, 0); if (ret < 0) { quorum_report_bad_acb(&acb->qcrs[n], ret); @@ -688,8 +693,8 @@ static void write_quorum_entry(void *opaque) int i = co->idx; QuorumChildRequest *sacb = &acb->qcrs[i]; - sacb->bs = s->children[i]->bs; - sacb->ret = bdrv_co_pwritev(s->children[i], acb->offset, acb->bytes, + sacb->bs = s->children[i].child->bs; + sacb->ret = bdrv_co_pwritev(s->children[i].child, acb->offset, acb->bytes, acb->qiov, acb->flags); if (sacb->ret == 0) { acb->success_count++; @@ -743,12 +748,12 @@ static int64_t quorum_getlength(BlockDriverState *bs) int i; /* check that all file have the same length */ - result = bdrv_getlength(s->children[0]->bs); + result = bdrv_getlength(s->children[0].child->bs); if (result < 0) { return result; } for (i = 1; i < s->num_children; i++) { - int64_t value = bdrv_getlength(s->children[i]->bs); + int64_t value = bdrv_getlength(s->children[i].child->bs); if (value < 0) { return value; } @@ -774,10 +779,10 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs) error_votes.compare = quorum_64bits_compare; for (i = 0; i < s->num_children; i++) { - result = bdrv_co_flush(s->children[i]->bs); + result = bdrv_co_flush(s->children[i].child->bs); if (result) { quorum_report_bad(QUORUM_OP_TYPE_FLUSH, 0, 0, - s->children[i]->bs->node_name, result); + s->children[i].child->bs->node_name, result); result_value.l = result; quorum_count_vote(&error_votes, &result_value, i); } else { @@ -803,7 +808,7 @@ static bool quorum_recurse_is_first_non_filter(BlockDriverState *bs, int i; for (i = 0; i < s->num_children; i++) { - bool perm = bdrv_recurse_is_first_non_filter(s->children[i]->bs, + bool perm = bdrv_recurse_is_first_non_filter(s->children[i].child->bs, candidate); if (perm) { return true; @@ -932,7 +937,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, } /* allocate the children array */ - s->children = g_new0(BdrvChild *, s->num_children); + s->children = g_new0(QuorumChild, s->num_children); opened = g_new0(bool, s->num_children); for (i = 0; i < s->num_children; i++) { @@ -940,8 +945,9 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, ret = snprintf(indexstr, 32, "children.%d", i); assert(ret < 32); - s->children[i] = bdrv_open_child(NULL, options, indexstr, bs, - &child_format, false, &local_err); + s->children[i].child = bdrv_open_child(NULL, options, indexstr, bs, + &child_format, false, + &local_err); if (local_err) { ret = -EINVAL; goto close_exit; @@ -962,7 +968,7 @@ close_exit: if (!opened[i]) { continue; } - bdrv_unref_child(bs, s->children[i]); + bdrv_unref_child(bs, s->children[i].child); } g_free(s->children); g_free(opened); @@ -979,7 +985,7 @@ static void quorum_close(BlockDriverState *bs) int i; for (i = 0; i < s->num_children; i++) { - bdrv_unref_child(bs, s->children[i]); + bdrv_unref_child(bs, s->children[i].child); } g_free(s->children); @@ -998,8 +1004,8 @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs, return; } - assert(s->num_children <= INT_MAX / sizeof(BdrvChild *)); - if (s->num_children == INT_MAX / sizeof(BdrvChild *) || + assert(s->num_children <= INT_MAX / sizeof(QuorumChild)); + if (s->num_children == INT_MAX / sizeof(QuorumChild) || s->next_child_index == UINT_MAX) { error_setg(errp, "Too many children"); return; @@ -1022,8 +1028,10 @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs, s->next_child_index--; goto out; } - s->children = g_renew(BdrvChild *, s->children, s->num_children + 1); - s->children[s->num_children++] = child; + s->children = g_renew(QuorumChild, s->children, s->num_children + 1); + s->children[s->num_children++] = (QuorumChild){ + .child = child, + }; out: bdrv_drained_end(bs); @@ -1036,7 +1044,7 @@ static void quorum_del_child(BlockDriverState *bs, BdrvChild *child, int i; for (i = 0; i < s->num_children; i++) { - if (s->children[i] == child) { + if (s->children[i].child == child) { break; } } @@ -1058,8 +1066,8 @@ static void quorum_del_child(BlockDriverState *bs, BdrvChild *child, /* We can safely remove this child now */ memmove(&s->children[i], &s->children[i + 1], - (s->num_children - i - 1) * sizeof(BdrvChild *)); - s->children = g_renew(BdrvChild *, s->children, --s->num_children); + (s->num_children - i - 1) * sizeof(QuorumChild)); + s->children = g_renew(QuorumChild, s->children, --s->num_children); bdrv_unref_child(bs, child); bdrv_drained_end(bs); @@ -1100,7 +1108,7 @@ static void quorum_gather_child_options(BlockDriverState *bs, QDict *target, for (i = 0; i < s->num_children; i++) { qlist_append(children_list, - qobject_ref(s->children[i]->bs->full_open_options)); + qobject_ref(s->children[i].child->bs->full_open_options)); } } From patchwork Mon Nov 11 16:02:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237303 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9130A15AB for ; Mon, 11 Nov 2019 16:13:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6721A20856 for ; Mon, 11 Nov 2019 16:13:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bqGMIHGM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6721A20856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCKE-00059L-75 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:13:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39071) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9U-00080r-Ms for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9T-0002n2-CL for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:52 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:25073 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9T-0002mp-7Y for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NEbi0Ur8DfgE4/ZOeodz1rU6ezfOkugTot9Q4UHBw8Y=; b=bqGMIHGMtsUUU8ItE+xLxu4oUhMnPe1fNxp+f3TgYRSwErJaFzbkSvj5WJZNJVfF1+u8DZ R0KtYXQshpftP3axJ/S+vlWyH0CQZAU5f0i2KjvBRmdTJD5qY7wPlyuC3ISvFeSvp5jMdy dhn8yYisIJvJ7Pnel3upVe6yDDIVeNc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-215-Die4-GB9Pl6yRNJr3PN7nw-1; Mon, 11 Nov 2019 11:02:48 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 02D90107ACC6; Mon, 11 Nov 2019 16:02:47 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89C374521; Mon, 11 Nov 2019 16:02:46 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 09/23] quorum: Add QuorumChild.to_be_replaced Date: Mon, 11 Nov 2019 17:02:02 +0100 Message-Id: <20191111160216.197086-10-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: Die4-GB9Pl6yRNJr3PN7nw-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We will need this to verify that Quorum can let one of its children be replaced without breaking anything else. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/quorum.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/block/quorum.c b/block/quorum.c index 59cd524502..3a824e77e3 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -67,6 +67,13 @@ typedef struct QuorumVotes { typedef struct QuorumChild { BdrvChild *child; + + /* + * If set, check whether this node can be replaced without any + * other parent noticing: Unshare CONSISTENT_READ, and take the + * WRITE permission. + */ + bool to_be_replaced; } QuorumChild; /* the following structure holds the state of one quorum instance */ @@ -1128,6 +1135,16 @@ static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { + BDRVQuorumState *s = bs->opaque; + int i; + + for (i = 0; i < s->num_children; i++) { + if (s->children[i].child == c) { + break; + } + } + assert(!c || i < s->num_children); + *nperm = perm & DEFAULT_PERM_PASSTHROUGH; /* @@ -1137,6 +1154,12 @@ static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, *nshared = (shared & (BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED)) | DEFAULT_PERM_UNCHANGED; + + if (c && s->children[i].to_be_replaced) { + /* Prepare for sudden data changes */ + *nperm |= BLK_PERM_WRITE; + *nshared &= ~BLK_PERM_CONSISTENT_READ; + } } static const char *const quorum_strong_runtime_opts[] = { From patchwork Mon Nov 11 16:02:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237285 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77C62159A for ; Mon, 11 Nov 2019 16:05:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E38C2196E for ; Mon, 11 Nov 2019 16:05:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HTN3aHiV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E38C2196E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCCD-0002UH-6k for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:05:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39103) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9a-00084x-Q1 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9U-0002nd-Qb for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:58 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:40782 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9U-0002nN-MW for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IWX2ctN6XoWefEe2vb6nKkxe1T5DYNE3IqEfaYYWvXw=; b=HTN3aHiVwWLxFUnU54ZRXGXO/nzVz4uqrbDQYqI2/wT6SFhVMsRtOSiXV2/aO5eCoDispr Mk9BKqF01RY9HeiwzkBHUvMAuRfEwLzXuPyR9pJad2S6pLfqss1WhNAdWYJ9Q4iohnS0K9 T6CmypE+V+/ycnwIwxkBXdHxhRM5L7g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-245-P4zVO02qNYSj50LgzzNASQ-1; Mon, 11 Nov 2019 11:02:50 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B47B5800C72; Mon, 11 Nov 2019 16:02:49 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30B42608FB; Mon, 11 Nov 2019 16:02:48 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 10/23] quorum: Implement .bdrv_recurse_can_replace() Date: Mon, 11 Nov 2019 17:02:03 +0100 Message-Id: <20191111160216.197086-11-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: P4zVO02qNYSj50LgzzNASQ-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/quorum.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/block/quorum.c b/block/quorum.c index 3a824e77e3..8ee03e9baf 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -825,6 +825,67 @@ static bool quorum_recurse_is_first_non_filter(BlockDriverState *bs, return false; } +static bool quorum_recurse_can_replace(BlockDriverState *bs, + BlockDriverState *to_replace) +{ + BDRVQuorumState *s = bs->opaque; + int i; + + for (i = 0; i < s->num_children; i++) { + /* + * We have no idea whether our children show the same data as + * this node (@bs). It is actually highly likely that + * @to_replace does not, because replacing a broken child is + * one of the main use cases here. + * + * We do know that the new BDS will match @bs, so replacing + * any of our children by it will be safe. It cannot change + * the data this quorum node presents to its parents. + * + * However, replacing @to_replace by @bs in any of our + * children's chains may change visible data somewhere in + * there. We therefore cannot recurse down those chains with + * bdrv_recurse_can_replace(). + * (More formally, bdrv_recurse_can_replace() requires that + * @to_replace will be replaced by something matching the @bs + * passed to it. We cannot guarantee that.) + * + * Thus, we can only check whether any of our immediate + * children matches @to_replace. + * + * (In the future, we might add a function to recurse down a + * chain that checks that nothing there cares about a change + * in data from the respective child in question. For + * example, most filters do not care when their child's data + * suddenly changes, as long as their parents do not care.) + */ + if (s->children[i].child->bs == to_replace) { + Error *local_err = NULL; + + /* + * We now have to ensure that there is no other parent + * that cares about replacing this child by a node with + * potentially different data. + */ + s->children[i].to_be_replaced = true; + bdrv_child_refresh_perms(bs, s->children[i].child, &local_err); + + /* Revert permissions */ + s->children[i].to_be_replaced = false; + bdrv_child_refresh_perms(bs, s->children[i].child, &error_abort); + + if (local_err) { + error_free(local_err); + return false; + } + + return true; + } + } + + return false; +} + static int quorum_valid_threshold(int threshold, int num_children, Error **errp) { @@ -1195,6 +1256,7 @@ static BlockDriver bdrv_quorum = { .is_filter = true, .bdrv_recurse_is_first_non_filter = quorum_recurse_is_first_non_filter, + .bdrv_recurse_can_replace = quorum_recurse_can_replace, .strong_runtime_opts = quorum_strong_runtime_opts, }; From patchwork Mon Nov 11 16:02:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237293 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC2CE159A for ; Mon, 11 Nov 2019 16:08:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9358F222C1 for ; Mon, 11 Nov 2019 16:08:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZQOdIj49" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9358F222C1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCEi-0006MC-Dz for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:08:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39138) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9g-00086u-MN for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9a-0002rA-P4 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:04 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:29639 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9Z-0002qi-8k for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:02:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488176; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=twVsBJ1nTiS7APsE0cYdUcRoL6m6H4xxbgEn76Lc0nM=; b=ZQOdIj49q/b45UxXnq6uJCs/MimEj7hgCLaszx7SOHjZSFV9rAknpErs6E60D0aHbTou1v WvpfZ30glPMZxIS8Rc1/JsvT+UqRxPZFTWT0xFsEV1eKbz+TiPmQaIK47jhd0XkZsprO4Y xmExIGSCza8EBMs85u+YQcFms86Uu7g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-323-NG-rArKoNnmFOz6kQclKpg-1; Mon, 11 Nov 2019 11:02:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BC9581005500; Mon, 11 Nov 2019 16:02:52 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 40A3B28D18; Mon, 11 Nov 2019 16:02:51 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 11/23] block: Use bdrv_recurse_can_replace() Date: Mon, 11 Nov 2019 17:02:04 +0100 Message-Id: <20191111160216.197086-12-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: NG-rArKoNnmFOz6kQclKpg-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Let check_to_replace_node() use the more specialized bdrv_recurse_can_replace() instead of bdrv_recurse_is_first_non_filter(), which is too restrictive. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index de53addeb0..7608f21570 100644 --- a/block.c +++ b/block.c @@ -6243,6 +6243,17 @@ bool bdrv_recurse_can_replace(BlockDriverState *bs, return false; } +/* + * Check whether the given @node_name can be replaced by a node that + * has the same data as @parent_bs. If so, return @node_name's BDS; + * NULL otherwise. + * + * @node_name must be a (recursive) *child of @parent_bs (or this + * function will return NULL). + * + * The result (whether the node can be replaced or not) is only valid + * for as long as no graph changes occur. + */ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, const char *node_name, Error **errp) { @@ -6267,8 +6278,11 @@ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, * Another benefit is that this tests exclude backing files which are * blocked by the backing blockers. */ - if (!bdrv_recurse_is_first_non_filter(parent_bs, to_replace_bs)) { - error_setg(errp, "Only top most non filter can be replaced"); + if (!bdrv_recurse_can_replace(parent_bs, to_replace_bs)) { + error_setg(errp, "Cannot replace '%s' by a node mirrored from '%s', " + "because it cannot be guaranteed that doing so would not " + "lead to an abrupt change of visible data", + node_name, parent_bs->node_name); to_replace_bs = NULL; goto out; } From patchwork Mon Nov 11 16:02:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237307 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F57D159A for ; Mon, 11 Nov 2019 16:14:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3645F21783 for ; Mon, 11 Nov 2019 16:14:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eU4wGZGj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3645F21783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCKJ-0005F8-AM for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:14:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39134) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9g-00086s-M9 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9c-0002rt-U6 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:02 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:48999 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9c-0002rZ-PS for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488180; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0M30rCDkeefWzVT2kMcruZnUpjgy4BYgcCbtRYC3qlg=; b=eU4wGZGjPdxGSAY1ynG3RLB9cxGosVEHBr6SqtKob++8FfhMhtxmUL1qcC9PYrzMrrnsBa 15E3gHfG72W8n3w8a7i1nom5Kp4LcI5DCYJ4D0aI5x1x5NZeVOLj43mL4cOk09cxJZl6ze G7x/itAJEGUfa7np1R56/mrMHpKHxk0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-128-4RJylzfzNe6FPk1SYAWntA-1; Mon, 11 Nov 2019 11:02:57 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF2D1477; Mon, 11 Nov 2019 16:02:55 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 13D825EE1A; Mon, 11 Nov 2019 16:02:54 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 12/23] block: Remove bdrv_recurse_is_first_non_filter() Date: Mon, 11 Nov 2019 17:02:05 +0100 Message-Id: <20191111160216.197086-13-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: 4RJylzfzNe6FPk1SYAWntA-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" It no longer has any users. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 33 --------------------------------- block/blkverify.c | 15 --------------- block/copy-on-read.c | 9 --------- block/quorum.c | 18 ------------------ block/replication.c | 7 ------- block/throttle.c | 8 -------- include/block/block.h | 4 ---- include/block/block_int.h | 8 -------- 8 files changed, 102 deletions(-) diff --git a/block.c b/block.c index 7608f21570..0159f8e510 100644 --- a/block.c +++ b/block.c @@ -6172,39 +6172,6 @@ int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts, return bs->drv->bdrv_amend_options(bs, opts, status_cb, cb_opaque, errp); } -/* This function will be called by the bdrv_recurse_is_first_non_filter method - * of block filter and by bdrv_is_first_non_filter. - * It is used to test if the given bs is the candidate or recurse more in the - * node graph. - */ -bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs, - BlockDriverState *candidate) -{ - /* return false if basic checks fails */ - if (!bs || !bs->drv) { - return false; - } - - /* the code reached a non block filter driver -> check if the bs is - * the same as the candidate. It's the recursion termination condition. - */ - if (!bs->drv->is_filter) { - return bs == candidate; - } - /* Down this path the driver is a block filter driver */ - - /* If the block filter recursion method is defined use it to recurse down - * the node graph. - */ - if (bs->drv->bdrv_recurse_is_first_non_filter) { - return bs->drv->bdrv_recurse_is_first_non_filter(bs, candidate); - } - - /* the driver is a block filter but don't allow to recurse -> return false - */ - return false; -} - /* * This function checks whether the given @to_replace is allowed to be * replaced by a node that always shows the same data as @bs. This is diff --git a/block/blkverify.c b/block/blkverify.c index 0add3ab483..ba6b1853ae 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -268,20 +268,6 @@ static int blkverify_co_flush(BlockDriverState *bs) return bdrv_co_flush(s->test_file->bs); } -static bool blkverify_recurse_is_first_non_filter(BlockDriverState *bs, - BlockDriverState *candidate) -{ - BDRVBlkverifyState *s = bs->opaque; - - bool perm = bdrv_recurse_is_first_non_filter(bs->file->bs, candidate); - - if (perm) { - return true; - } - - return bdrv_recurse_is_first_non_filter(s->test_file->bs, candidate); -} - static bool blkverify_recurse_can_replace(BlockDriverState *bs, BlockDriverState *to_replace) { @@ -341,7 +327,6 @@ static BlockDriver bdrv_blkverify = { .bdrv_co_flush = blkverify_co_flush, .is_filter = true, - .bdrv_recurse_is_first_non_filter = blkverify_recurse_is_first_non_filter, .bdrv_recurse_can_replace = blkverify_recurse_can_replace, }; diff --git a/block/copy-on-read.c b/block/copy-on-read.c index e95223d3cb..242d3ff055 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -118,13 +118,6 @@ static void cor_lock_medium(BlockDriverState *bs, bool locked) } -static bool cor_recurse_is_first_non_filter(BlockDriverState *bs, - BlockDriverState *candidate) -{ - return bdrv_recurse_is_first_non_filter(bs->file->bs, candidate); -} - - static BlockDriver bdrv_copy_on_read = { .format_name = "copy-on-read", @@ -143,8 +136,6 @@ static BlockDriver bdrv_copy_on_read = { .bdrv_co_block_status = bdrv_co_block_status_from_file, - .bdrv_recurse_is_first_non_filter = cor_recurse_is_first_non_filter, - .has_variable_length = true, .is_filter = true, }; diff --git a/block/quorum.c b/block/quorum.c index 8ee03e9baf..1974e2ffa8 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -808,23 +808,6 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs) return result; } -static bool quorum_recurse_is_first_non_filter(BlockDriverState *bs, - BlockDriverState *candidate) -{ - BDRVQuorumState *s = bs->opaque; - int i; - - for (i = 0; i < s->num_children; i++) { - bool perm = bdrv_recurse_is_first_non_filter(s->children[i].child->bs, - candidate); - if (perm) { - return true; - } - } - - return false; -} - static bool quorum_recurse_can_replace(BlockDriverState *bs, BlockDriverState *to_replace) { @@ -1255,7 +1238,6 @@ static BlockDriver bdrv_quorum = { .bdrv_child_perm = quorum_child_perm, .is_filter = true, - .bdrv_recurse_is_first_non_filter = quorum_recurse_is_first_non_filter, .bdrv_recurse_can_replace = quorum_recurse_can_replace, .strong_runtime_opts = quorum_strong_runtime_opts, diff --git a/block/replication.c b/block/replication.c index 99532ce521..d6681b6c84 100644 --- a/block/replication.c +++ b/block/replication.c @@ -306,12 +306,6 @@ out: return ret; } -static bool replication_recurse_is_first_non_filter(BlockDriverState *bs, - BlockDriverState *candidate) -{ - return bdrv_recurse_is_first_non_filter(bs->file->bs, candidate); -} - static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) { Error *local_err = NULL; @@ -699,7 +693,6 @@ static BlockDriver bdrv_replication = { .bdrv_co_writev = replication_co_writev, .is_filter = true, - .bdrv_recurse_is_first_non_filter = replication_recurse_is_first_non_filter, .has_variable_length = true, .strong_runtime_opts = replication_strong_runtime_opts, diff --git a/block/throttle.c b/block/throttle.c index 0349f42257..71f4bb0ad1 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -207,12 +207,6 @@ static void throttle_reopen_abort(BDRVReopenState *reopen_state) reopen_state->opaque = NULL; } -static bool throttle_recurse_is_first_non_filter(BlockDriverState *bs, - BlockDriverState *candidate) -{ - return bdrv_recurse_is_first_non_filter(bs->file->bs, candidate); -} - static void coroutine_fn throttle_co_drain_begin(BlockDriverState *bs) { ThrottleGroupMember *tgm = bs->opaque; @@ -252,8 +246,6 @@ static BlockDriver bdrv_throttle = { .bdrv_co_pwrite_zeroes = throttle_co_pwrite_zeroes, .bdrv_co_pdiscard = throttle_co_pdiscard, - .bdrv_recurse_is_first_non_filter = throttle_recurse_is_first_non_filter, - .bdrv_attach_aio_context = throttle_attach_aio_context, .bdrv_detach_aio_context = throttle_detach_aio_context, diff --git a/include/block/block.h b/include/block/block.h index 8f6a0cad9c..764a217de6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -401,10 +401,6 @@ int bdrv_amend_options(BlockDriverState *bs_new, QemuOpts *opts, BlockDriverAmendStatusCB *status_cb, void *cb_opaque, Error **errp); -/* external snapshots */ -bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs, - BlockDriverState *candidate); - /* check if a named node can be replaced when doing drive-mirror */ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, const char *node_name, Error **errp); diff --git a/include/block/block_int.h b/include/block/block_int.h index 75f03dcc38..589a797fab 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -94,14 +94,6 @@ struct BlockDriver { * must implement them and return -ENOTSUP. */ bool is_filter; - /* for snapshots block filter like Quorum can implement the - * following recursive callback. - * It's purpose is to recurse on the filter children while calling - * bdrv_recurse_is_first_non_filter on them. - * For a sample implementation look in the future Quorum block filter. - */ - bool (*bdrv_recurse_is_first_non_filter)(BlockDriverState *bs, - BlockDriverState *candidate); /* * Return true if @to_replace can be replaced by a BDS with the * same data as @bs without it affecting @bs's behavior (that is, From patchwork Mon Nov 11 16:02:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237311 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 163F615AB for ; Mon, 11 Nov 2019 16:17:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D55BB21783 for ; Mon, 11 Nov 2019 16:17:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VD85oIqr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D55BB21783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCNb-0000ie-0d for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:17:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39165) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9h-0008Ai-P1 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9g-0002si-KT for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:05 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:38671 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9e-0002rz-EQ for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488181; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9vLRvKZ0AqOa77gWXnx/Um95rM/5mkSjRqxXXTMITcs=; b=VD85oIqrcyxA76keAWRZHmSvQ0d/ba/auoz9+Pq8NngUBebXZgcuS/mWjlxxQZcqBnqpyO 0Ls5g0ayFk/UR+BTKhsLrtRstBLO0invWHN7d59OSXO5lkddHXoWtPYPRB4sOFOdbA1QAL tOJSHTc6xZ7R5oyAW169rWPQx3l8UnA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-235-gEuF1lAONZGSKdPwyTZuHA-1; Mon, 11 Nov 2019 11:03:00 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1AAB71800D63; Mon, 11 Nov 2019 16:02:59 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 88BE1600CC; Mon, 11 Nov 2019 16:02:58 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 13/23] mirror: Double-check immediately before replacing Date: Mon, 11 Nov 2019 17:02:06 +0100 Message-Id: <20191111160216.197086-14-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: gEuF1lAONZGSKdPwyTZuHA-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" There is no guarantee that we can still replace the node we want to replace at the end of the mirror job. Double-check by calling bdrv_recurse_can_replace(). Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/mirror.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index f0f2d9dff1..68a4404666 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -695,7 +695,19 @@ static int mirror_exit_common(Job *job) * drain potential other users of the BDS before changing the graph. */ assert(s->in_drain); bdrv_drained_begin(target_bs); - bdrv_replace_node(to_replace, target_bs, &local_err); + /* + * Cannot use check_to_replace_node() here, because that would + * check for an op blocker on @to_replace, and we have our own + * there. + */ + if (bdrv_recurse_can_replace(src, to_replace)) { + bdrv_replace_node(to_replace, target_bs, &local_err); + } else { + error_setg(&local_err, "Can no longer replace '%s' by '%s', " + "because it can no longer be guaranteed that doing so " + "would not lead to an abrupt change of visible data", + to_replace->node_name, target_bs->node_name); + } bdrv_drained_end(target_bs); if (local_err) { error_report_err(local_err); From patchwork Mon Nov 11 16:02:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237315 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0071A16B1 for ; Mon, 11 Nov 2019 16:18:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CBB9D21925 for ; Mon, 11 Nov 2019 16:18:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="etRQ10uh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBB9D21925 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCOE-0001Rr-7t for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:18:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39211) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9m-0008Kc-Ad for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9l-0002vN-0t for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:10 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:58454 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9k-0002v3-T2 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qakAL0ITihVz+AFdnaqR0YnYpEIqJv3zX+oL+M5cVLU=; b=etRQ10uhV6/aTFYvGDwVKrjA7hHt61f0t9M/BL3u/tXICwzULp3nBPys8YQ4N0RIFdVx8z 1xu9XkCInmxu49WPsc/cCcrCMgbKGVKOzH7uxYOZ2xdAEKLQYgsZsZhcgfYe3sZVchurFV 6AvcPVrdLhPwWP3bb1T+2TEbzAfjOks= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-391-clmjbh3NOMG4HYONIoknPw-1; Mon, 11 Nov 2019 11:03:04 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E6422107ACC4; Mon, 11 Nov 2019 16:03:02 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B359B60904; Mon, 11 Nov 2019 16:03:01 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 14/23] quorum: Stop marking it as a filter Date: Mon, 11 Nov 2019 17:02:07 +0100 Message-Id: <20191111160216.197086-15-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: clmjbh3NOMG4HYONIoknPw-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Quorum is not a filter, for example because it cannot guarantee which of its children will serve the next request. Thus, any of its children may differ from the data visible to quorum's parents. We have other filters with multiple children, but they differ in this aspect: - blkverify quits the whole qemu process if its children differ. As such, we can always skip it when we want to skip it (as a filter node) by going to any of its children. Both have the same data. - replication generally serves requests from bs->file, so this is its only actually filtered child. - Block job filters currently only have one child, but they will probably get more children in the future. Still, they will always have only one actually filtered child. Having "filters" as a dedicated node category only makes sense if you can skip them by going to a one fixed child that always shows the same data as the filter node. Quorum cannot fulfill this, so it is not a filter. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/quorum.c | 1 - 1 file changed, 1 deletion(-) diff --git a/block/quorum.c b/block/quorum.c index 1974e2ffa8..8cd13a7b91 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1237,7 +1237,6 @@ static BlockDriver bdrv_quorum = { .bdrv_child_perm = quorum_child_perm, - .is_filter = true, .bdrv_recurse_can_replace = quorum_recurse_can_replace, .strong_runtime_opts = quorum_strong_runtime_opts, From patchwork Mon Nov 11 16:02:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237321 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A3C514E5 for ; Mon, 11 Nov 2019 16:21:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B53421783 for ; Mon, 11 Nov 2019 16:21:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hQCdsjFh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B53421783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCRK-00051J-S7 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:21:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39261) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9t-0008TS-U9 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9o-0002ym-Gq for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:17 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:27474 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9o-0002yS-Cw for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RdKb/hYNSlDaukRFq6ANuOdiA03sLkb2ULTE0afREU8=; b=hQCdsjFhfrEiDK5qGoPQPTcHv5zVgxrnGT9KdqYMrxFxbXCxVLpKnTruP9ZaQKwG8IVJO9 xSAfYNk2UcKEMY4wzrALY0K6j2QFDLazqJHMQP0bAN23lcwm8WvpA3zlIR4TUn9Uv9eRl/ +H6ELPNgzeK8o+p1xx+hdB0IOBoX+KM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-34-_UQop2qqOQ-EKVZmjdrKvQ-1; Mon, 11 Nov 2019 11:03:07 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B0E0800C72; Mon, 11 Nov 2019 16:03:06 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7214F600CC; Mon, 11 Nov 2019 16:03:05 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 15/23] mirror: Prevent loops Date: Mon, 11 Nov 2019 17:02:08 +0100 Message-Id: <20191111160216.197086-16-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: _UQop2qqOQ-EKVZmjdrKvQ-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" While bdrv_replace_node() will not follow through with it, a specific @replaces asks the mirror job to create a loop. For example, say both the source and the target share a child where the source is a filter; by letting @replaces point to the common child, you ask for a loop. Or if you use @replaces in drive-mirror with sync=none and mode=absolute-paths, you generally ask for a loop (@replaces must point to a child of the source, and sync=none makes the source the backing file of the target after the job). bdrv_replace_node() will not create those loops, but by doing so, it ignores the user-requested configuration, which is not ideally either. (In the first example above, the target's child will remain what it was, which may still be reasonable. But in the second example, the target will just not become a child of the source, which is precisely what was requested with @replaces.) So prevent such configurations, both before the job, and before it actually completes. Signed-off-by: Max Reitz --- block.c | 30 ++++++++++++++++++++++++ block/mirror.c | 19 +++++++++++++++- blockdev.c | 48 ++++++++++++++++++++++++++++++++++++++- include/block/block_int.h | 3 +++ 4 files changed, 98 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 0159f8e510..e3922a0474 100644 --- a/block.c +++ b/block.c @@ -6259,6 +6259,36 @@ out: return to_replace_bs; } +/* + * Return true iff @child is a (recursive) child of @parent, with at + * least @min_level edges between them. + * + * (If @min_level == 0, return true if @child == @parent. For + * @min_level == 1, @child needs to be at least a real child; for + * @min_level == 2, it needs to be at least a grand-child; and so on.) + */ +bool bdrv_is_child_of(BlockDriverState *child, BlockDriverState *parent, + int min_level) +{ + BdrvChild *c; + + if (child == parent && min_level <= 0) { + return true; + } + + if (!parent) { + return false; + } + + QLIST_FOREACH(c, &parent->children, next) { + if (bdrv_is_child_of(child, c->bs, min_level - 1)) { + return true; + } + } + + return false; +} + /** * Iterates through the list of runtime option keys that are said to * be "strong" for a BDS. An option is called "strong" if it changes diff --git a/block/mirror.c b/block/mirror.c index 68a4404666..b258c7e98b 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -701,7 +701,24 @@ static int mirror_exit_common(Job *job) * there. */ if (bdrv_recurse_can_replace(src, to_replace)) { - bdrv_replace_node(to_replace, target_bs, &local_err); + /* + * It is OK for @to_replace to be an immediate child of + * @target_bs, because that is what happens with + * drive-mirror sync=none mode=absolute-paths: target_bs's + * backing file will be the source node, which is also + * to_replace (by default). + * bdrv_replace_node() handles this case by not letting + * target_bs->backing point to itself, but to the source + * still. + */ + if (!bdrv_is_child_of(to_replace, target_bs, 2)) { + bdrv_replace_node(to_replace, target_bs, &local_err); + } else { + error_setg(&local_err, "Can no longer replace '%s' by '%s', " + "because the former is now a child of the latter, " + "and doing so would thus create a loop", + to_replace->node_name, target_bs->node_name); + } } else { error_setg(&local_err, "Can no longer replace '%s' by '%s', " "because it can no longer be guaranteed that doing so " diff --git a/blockdev.c b/blockdev.c index 9dc2238bf3..d29f147f72 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3824,7 +3824,7 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs, } if (has_replaces) { - BlockDriverState *to_replace_bs; + BlockDriverState *to_replace_bs, *target_backing_bs; AioContext *replace_aio_context; int64_t bs_size, replace_size; @@ -3839,6 +3839,52 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs, return; } + if (bdrv_is_child_of(to_replace_bs, target, 1)) { + error_setg(errp, "Replacing %s by %s would result in a loop, " + "because the former is a child of the latter", + to_replace_bs->node_name, target->node_name); + return; + } + + if (backing_mode == MIRROR_SOURCE_BACKING_CHAIN || + backing_mode == MIRROR_OPEN_BACKING_CHAIN) + { + /* + * While we do not quite know what OPEN_BACKING_CHAIN + * (used for mode=existing) will yield, it is probably + * best to restrict it exactly like SOURCE_BACKING_CHAIN, + * because that is our best guess. + */ + switch (sync) { + case MIRROR_SYNC_MODE_FULL: + target_backing_bs = NULL; + break; + + case MIRROR_SYNC_MODE_TOP: + target_backing_bs = backing_bs(bs); + break; + + case MIRROR_SYNC_MODE_NONE: + target_backing_bs = bs; + break; + + default: + abort(); + } + } else { + assert(backing_mode == MIRROR_LEAVE_BACKING_CHAIN); + target_backing_bs = backing_bs(target); + } + + if (bdrv_is_child_of(to_replace_bs, target_backing_bs, 0)) { + error_setg(errp, "Replacing '%s' by '%s' with this sync mode would " + "result in a loop, because the former would be a child " + "of the latter's backing file ('%s') after the mirror " + "job", to_replace_bs->node_name, target->node_name, + target_backing_bs->node_name); + return; + } + replace_aio_context = bdrv_get_aio_context(to_replace_bs); aio_context_acquire(replace_aio_context); replace_size = bdrv_getlength(to_replace_bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index 589a797fab..7064a1a4fa 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1266,6 +1266,9 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, bool bdrv_recurse_can_replace(BlockDriverState *bs, BlockDriverState *to_replace); +bool bdrv_is_child_of(BlockDriverState *child, BlockDriverState *parent, + int min_level); + /* * Default implementation for drivers to pass bdrv_co_block_status() to * their file. From patchwork Mon Nov 11 16:02:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237325 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 379CF1709 for ; Mon, 11 Nov 2019 16:21:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0B9512196E for ; Mon, 11 Nov 2019 16:21:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="azRDV1ax" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B9512196E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCRa-0005Oq-Gy for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:21:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39252) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9r-0008SD-Ge for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9q-0002zO-Fh for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:15 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59241 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9q-0002zE-CZ for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0x6FV2Rgv9rlxoxQjtMI8X+Lb/rJSquGcr1RaAZH9qI=; b=azRDV1axok/d0VXJSgRV4WmLw2Fy3mWCCLzyHzFbPn4v5hJDHKP1EoJfLGqqEmloGRo4LA lhd3MuNOgyH7M0n3mkXMCC+TME65wNjIR2wZnk3Lt6ipmt5HRq7SEOAO19AxfzGkguLjVz lDrzPg/zVx6QwRrWNsz+WhsP56LrM50= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-69-xrm1mkQJNoaDfcNx6rK19A-1; Mon, 11 Nov 2019 11:03:10 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4129C805D9A; Mon, 11 Nov 2019 16:03:09 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AA77D10027B3; Mon, 11 Nov 2019 16:03:08 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 16/23] iotests: Use complete_and_wait() in 155 Date: Mon, 11 Nov 2019 17:02:09 +0100 Message-Id: <20191111160216.197086-17-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: xrm1mkQJNoaDfcNx6rK19A-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This way, we get to see errors during the completion phase. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/155 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/qemu-iotests/155 b/tests/qemu-iotests/155 index e19485911c..d7ef2579d3 100755 --- a/tests/qemu-iotests/155 +++ b/tests/qemu-iotests/155 @@ -163,12 +163,7 @@ class MirrorBaseClass(BaseClass): self.assert_qmp(result, 'return', {}) - self.vm.event_wait('BLOCK_JOB_READY') - - result = self.vm.qmp('block-job-complete', device='mirror-job') - self.assert_qmp(result, 'return', {}) - - self.vm.event_wait('BLOCK_JOB_COMPLETED') + self.complete_and_wait('mirror-job') def testFull(self): self.runMirror('full') From patchwork Mon Nov 11 16:02:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237329 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D06A14E5 for ; Mon, 11 Nov 2019 16:25:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D856921783 for ; Mon, 11 Nov 2019 16:25:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DT/finZN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D856921783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCUt-0001cK-Js for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:24:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39292) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUC9v-00009c-Od for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9u-00031u-Fc for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:19 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:60540 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9s-000302-QP for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488196; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cl4SYAw3Ga27eigSjmrt5Kp5SAtVG9rNF6zj/H4oMMo=; b=DT/finZNUFSfg4rsNlHoGUfHScp+4njtyT6zqhM0Vmx8lXThrTRGB9cUC0H/PwodCW2VkG vVol9x0lIyNOYIRcZpoYRMUhySZVSKpTxWY0afTSNMB9OyxfFM9Ke9jRJqg7BJYIq9aH6n O/bbjN9PpFPJKYHJjZEKGC2P3dFAJ30= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-346-TY9MFZjTMkuavyJqBKb5hA-1; Mon, 11 Nov 2019 11:03:13 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4ECAC10753F3; Mon, 11 Nov 2019 16:03:12 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BED485DDAA; Mon, 11 Nov 2019 16:03:11 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 17/23] iotests: Use skip_if_unsupported decorator in 041 Date: Mon, 11 Nov 2019 17:02:10 +0100 Message-Id: <20191111160216.197086-18-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: TY9MFZjTMkuavyJqBKb5hA-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We can use this decorator above TestRepairQuorum.setUp() to skip all quorum tests with a single line. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/041 | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 3c60c07b01..2ab59e9c53 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -871,6 +871,7 @@ class TestRepairQuorum(iotests.QMPTestCase): image_len = 1 * 1024 * 1024 # MB IMAGES = [ quorum_img1, quorum_img2, quorum_img3 ] + @iotests.skip_if_unsupported(['quorum']) def setUp(self): self.vm = iotests.VM() @@ -894,9 +895,8 @@ class TestRepairQuorum(iotests.QMPTestCase): #assemble the quorum block device from the individual files args = { "driver": "quorum", "node-name": "quorum0", "vote-threshold": 2, "children": [ "img0", "img1", "img2" ] } - if iotests.supports_quorum(): - result = self.vm.qmp("blockdev-add", **args) - self.assert_qmp(result, 'return', {}) + result = self.vm.qmp("blockdev-add", **args) + self.assert_qmp(result, 'return', {}) def tearDown(self): @@ -909,9 +909,6 @@ class TestRepairQuorum(iotests.QMPTestCase): pass def test_complete(self): - if not iotests.supports_quorum(): - return - self.assert_no_active_block_jobs() result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0', @@ -928,9 +925,6 @@ class TestRepairQuorum(iotests.QMPTestCase): 'target image does not match source after mirroring') def test_cancel(self): - if not iotests.supports_quorum(): - return - self.assert_no_active_block_jobs() result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0', @@ -945,9 +939,6 @@ class TestRepairQuorum(iotests.QMPTestCase): self.vm.shutdown() def test_cancel_after_ready(self): - if not iotests.supports_quorum(): - return - self.assert_no_active_block_jobs() result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0', @@ -964,9 +955,6 @@ class TestRepairQuorum(iotests.QMPTestCase): 'target image does not match source after mirroring') def test_pause(self): - if not iotests.supports_quorum(): - return - self.assert_no_active_block_jobs() result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0', @@ -992,9 +980,6 @@ class TestRepairQuorum(iotests.QMPTestCase): 'target image does not match source after mirroring') def test_medium_not_found(self): - if not iotests.supports_quorum(): - return - if iotests.qemu_default_machine != 'pc': return @@ -1006,9 +991,6 @@ class TestRepairQuorum(iotests.QMPTestCase): self.assert_qmp(result, 'error/class', 'GenericError') def test_image_not_found(self): - if not iotests.supports_quorum(): - return - result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0', sync='full', node_name='repair0', replaces='img1', mode='existing', target=quorum_repair_img, @@ -1016,9 +998,6 @@ class TestRepairQuorum(iotests.QMPTestCase): self.assert_qmp(result, 'error/class', 'GenericError') def test_device_not_found(self): - if not iotests.supports_quorum(): - return - result = self.vm.qmp('drive-mirror', job_id='job0', device='nonexistent', sync='full', node_name='repair0', @@ -1027,9 +1006,6 @@ class TestRepairQuorum(iotests.QMPTestCase): self.assert_qmp(result, 'error/class', 'GenericError') def test_wrong_sync_mode(self): - if not iotests.supports_quorum(): - return - result = self.vm.qmp('drive-mirror', device='quorum0', job_id='job0', node_name='repair0', replaces='img1', @@ -1037,27 +1013,18 @@ class TestRepairQuorum(iotests.QMPTestCase): self.assert_qmp(result, 'error/class', 'GenericError') def test_no_node_name(self): - if not iotests.supports_quorum(): - return - result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0', sync='full', replaces='img1', target=quorum_repair_img, format=iotests.imgfmt) self.assert_qmp(result, 'error/class', 'GenericError') def test_nonexistent_replaces(self): - if not iotests.supports_quorum(): - return - result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0', sync='full', node_name='repair0', replaces='img77', target=quorum_repair_img, format=iotests.imgfmt) self.assert_qmp(result, 'error/class', 'GenericError') def test_after_a_quorum_snapshot(self): - if not iotests.supports_quorum(): - return - result = self.vm.qmp('blockdev-snapshot-sync', node_name='img1', snapshot_file=quorum_snapshot_file, snapshot_node_name="snap1"); From patchwork Mon Nov 11 16:02:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237301 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 804F1159A for ; Mon, 11 Nov 2019 16:12:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 56181206BA for ; Mon, 11 Nov 2019 16:12:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UHvaVF/d" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 56181206BA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCIN-0002Xt-3w for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:12:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39332) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCA0-0000Hl-DP for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9u-00032l-Sh for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:23 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:40166 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9u-00031l-O1 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4NCOW8nlY+fuC+DwQmCp78uCKYSfszoYLuO4iepSv0g=; b=UHvaVF/dnMUNekb8owAecOm5b10yvDWUdskrFXQp950JaQKlLetEEXfAs5aIXdUel8l1J2 ysrPHr4mRMiwzJiLGIKI50Jj5k07QHVafynb8Vq+mawHNtC6o7/uh7W8lPZDD/H3l5N4aO xFLaIQ1Cq1aXgvJcKfLHT0GOHwz4B8E= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-54-aVsf2vmaPq6YKdgjdjTRkA-1; Mon, 11 Nov 2019 11:03:16 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6256292CA62; Mon, 11 Nov 2019 16:03:15 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD9EE5D6D4; Mon, 11 Nov 2019 16:03:14 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 18/23] iotests: Add VM.assert_block_path() Date: Mon, 11 Nov 2019 17:02:11 +0100 Message-Id: <20191111160216.197086-19-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: aVsf2vmaPq6YKdgjdjTRkA-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz --- tests/qemu-iotests/iotests.py | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index d34305ce69..3e03320ce3 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -681,6 +681,65 @@ class VM(qtest.QEMUQtestMachine): return fields.items() <= ret.items() + """ + Check whether the node under the given path in the block graph is + @expected_node. + + @root is the node name of the node where the @path is rooted. + + @path is a string that consists of child names separated by + slashes. It must begin with a slash. + + Examples for @root + @path: + - root="qcow2-node", path="/backing/file" + - root="quorum-node", path="/children.2/file" + + Hypothetically, @path could be empty, in which case it would point + to @root. However, in practice this case is not useful and hence + not allowed. + + @expected_node may be None. + + @graph may be None or the result of an x-debug-query-block-graph + call that has already been performed. + """ + def assert_block_path(self, root, path, expected_node, graph=None): + if graph is None: + graph = self.qmp('x-debug-query-block-graph')['return'] + + iter_path = iter(path.split('/')) + + # Must start with a / + assert next(iter_path) == '' + + node = next((node for node in graph['nodes'] if node['name'] == root), + None) + + for path_node in iter_path: + assert node is not None, 'Cannot follow path %s' % path + + try: + node_id = next(edge['child'] for edge in graph['edges'] \ + if edge['parent'] == node['id'] and + edge['name'] == path_node) + + node = next(node for node in graph['nodes'] \ + if node['id'] == node_id) + except StopIteration: + node = None + + assert node is not None or expected_node is None, \ + 'No node found under %s (but expected %s)' % \ + (path, expected_node) + + assert expected_node is not None or node is None, \ + 'Found node %s under %s (but expected none)' % \ + (node['name'], path) + + if node is not None and expected_node is not None: + assert node['name'] == expected_node, \ + 'Found node %s under %s (but expected %s)' % \ + (node['name'], path, expected_node) index_re = re.compile(r'([^\[]+)\[([^\]]+)\]') From patchwork Mon Nov 11 16:02:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237335 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 268C314E5 for ; Mon, 11 Nov 2019 16:29:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F119C20656 for ; Mon, 11 Nov 2019 16:29:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ItW71+v4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F119C20656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCZF-0005Zt-U3 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:29:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39334) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCA0-0000Hy-6N for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUC9y-00036s-TN for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:23 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:29558 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUC9y-00035f-Ou for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vmeBo3JNakPin2YEux2IhikmCE6WDGLfwJ+Y7vlA4eU=; b=ItW71+v4frPU1ARaD9mGS38etWBVc57kl0DBpVG7ThzVFKpVrsWwsl6MyajmetoGKWTclZ 5C8hWI2jVnFBJc9O2gaIPMnwXYI1318m2xt0nY1Cnd8w0MWS+lXLHtmt3AKCIfav+R1oXs anXiExn2S6Scg9pWr0by4JFAvS/v4H0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-qOoY9_l9PMuY3GXE_myZFA-1; Mon, 11 Nov 2019 11:03:19 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id D764A1852E23; Mon, 11 Nov 2019 16:03:17 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 728175D9C9; Mon, 11 Nov 2019 16:03:17 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 19/23] iotests: Resolve TODOs in 041 Date: Mon, 11 Nov 2019 17:02:12 +0100 Message-Id: <20191111160216.197086-20-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: qOoY9_l9PMuY3GXE_myZFA-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/041 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 2ab59e9c53..d636cb7f1d 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -918,8 +918,7 @@ class TestRepairQuorum(iotests.QMPTestCase): self.complete_and_wait(drive="job0") self.assert_has_block_node("repair0", quorum_repair_img) - # TODO: a better test requiring some QEMU infrastructure will be added - # to check that this file is really driven by quorum + self.vm.assert_block_path('quorum0', '/children.1', 'repair0') self.vm.shutdown() self.assertTrue(iotests.compare_images(quorum_img2, quorum_repair_img), 'target image does not match source after mirroring') @@ -1041,9 +1040,7 @@ class TestRepairQuorum(iotests.QMPTestCase): self.complete_and_wait('job0') self.assert_has_block_node("repair0", quorum_repair_img) - # TODO: a better test requiring some QEMU infrastructure will be added - # to check that this file is really driven by quorum - self.vm.shutdown() + self.vm.assert_block_path('quorum0', '/children.1', 'repair0') # Test mirroring with a source that does not have any parents (not even a # BlockBackend) From patchwork Mon Nov 11 16:02:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237317 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BD9615AB for ; Mon, 11 Nov 2019 16:18:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 430E721783 for ; Mon, 11 Nov 2019 16:18:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GTA/Y3dP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 430E721783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCOQ-0001fY-JM for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:18:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39386) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCA9-0000NN-Rg for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUCA7-00039I-Hw for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:33 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:52825 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUCA5-00038N-0g for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kIme/mNdsrkmmm0aGxqarwdyfyoRKfnPiYA6KQ8nt1k=; b=GTA/Y3dP3xUr3ccttDKVnm9RBcoBLlFF1eZVQpy4MOBVetb+HMtX9QGWXgr0z1P31SHyJb HjrR3kBeZ/u3jIEsKOHwwxCn81GPJfoIpQ4W7rovGP0MKB8LnDoGhDlIfx7Bowz6SSdRLt UGzQJrKmVcaD/qrxz6hWUbu6fOJwIUA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-224-SUcwdxAGPYensn6jeUpPpA-1; Mon, 11 Nov 2019 11:03:22 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E0330107ACE4; Mon, 11 Nov 2019 16:03:20 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C8413DBB; Mon, 11 Nov 2019 16:03:20 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 20/23] iotests: Use self.image_len in TestRepairQuorum Date: Mon, 11 Nov 2019 17:02:13 +0100 Message-Id: <20191111160216.197086-21-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: SUcwdxAGPYensn6jeUpPpA-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 041's TestRepairQuorum has its own image_len, no need to refer to TestSingleDrive. (This patch allows commenting out TestSingleDrive to speed up 041 during test testing.) Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/041 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index d636cb7f1d..0c1af45639 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -881,7 +881,7 @@ class TestRepairQuorum(iotests.QMPTestCase): # Add each individual quorum images for i in self.IMAGES: qemu_img('create', '-f', iotests.imgfmt, i, - str(TestSingleDrive.image_len)) + str(self.image_len)) # Assign a node name to each quorum image in order to manipulate # them opts = "node-name=img%i" % self.IMAGES.index(i) From patchwork Mon Nov 11 16:02:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237337 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6CB9C159A for ; Mon, 11 Nov 2019 16:33:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 42E5520656 for ; Mon, 11 Nov 2019 16:33:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZG8+q6VN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42E5520656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCdY-0001me-0G for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:33:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39384) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCA9-0000NL-Rk for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUCA7-000399-9n for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:33 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:41838 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUCA5-00038R-FC for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KjOmMb8SbuE3Eau+JWgFrpKa9d+ujZ1o70YXIj/vuCw=; b=ZG8+q6VNNFhX+EY4QQOVWcPv5JQAfkOvonxPKfhdW44tUb/asfO/KDWNqN4o35N1txC7P1 OZG5bEJcMp3velKF7zoYEXkpxUzr53d7clH1pmCxjIwiwXOgFZmJp+yFtZAW7i7LkNB8Jn XF6M5zhKwk9Onclw7VuMSJSP7HBcGgU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-370-EClod1VRMXayYki6wpUtwg-1; Mon, 11 Nov 2019 11:03:25 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 04B5792CA60; Mon, 11 Nov 2019 16:03:24 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6FEDD3DBB; Mon, 11 Nov 2019 16:03:23 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 21/23] iotests: Add tests for invalid Quorum @replaces Date: Mon, 11 Nov 2019 17:02:14 +0100 Message-Id: <20191111160216.197086-22-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: EClod1VRMXayYki6wpUtwg-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Add two tests to see that you cannot replace a Quorum child with the mirror job while the child is in use by a different parent. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/041 | 70 +++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/041.out | 4 +-- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 0c1af45639..ab0cb5b42f 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -20,6 +20,7 @@ import time import os +import re import iotests from iotests import qemu_img, qemu_io @@ -34,6 +35,8 @@ quorum_img3 = os.path.join(iotests.test_dir, 'quorum3.img') quorum_repair_img = os.path.join(iotests.test_dir, 'quorum_repair.img') quorum_snapshot_file = os.path.join(iotests.test_dir, 'quorum_snapshot.img') +nbd_sock_path = os.path.join(iotests.test_dir, 'nbd.sock') + class TestSingleDrive(iotests.QMPTestCase): image_len = 1 * 1024 * 1024 # MB qmp_cmd = 'drive-mirror' @@ -901,7 +904,8 @@ class TestRepairQuorum(iotests.QMPTestCase): def tearDown(self): self.vm.shutdown() - for i in self.IMAGES + [ quorum_repair_img, quorum_snapshot_file ]: + for i in self.IMAGES + [ quorum_repair_img, quorum_snapshot_file, + nbd_sock_path ]: # Do a try/except because the test may have deleted some images try: os.remove(i) @@ -1042,6 +1046,70 @@ class TestRepairQuorum(iotests.QMPTestCase): self.assert_has_block_node("repair0", quorum_repair_img) self.vm.assert_block_path('quorum0', '/children.1', 'repair0') + """ + Check that we cannot replace a Quorum child when it has other + parents. + """ + def test_with_other_parent(self): + result = self.vm.qmp('nbd-server-start', + addr={ + 'type': 'unix', + 'data': {'path': nbd_sock_path} + }) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('nbd-server-add', device='img1') + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('drive-mirror', job_id='mirror', device='quorum0', + sync='full', node_name='repair0', replaces='img1', + target=quorum_repair_img, format=iotests.imgfmt) + self.assert_qmp(result, 'error/desc', + "Cannot replace 'img1' by a node mirrored from " + "'quorum0', because it cannot be guaranteed that doing " + "so would not lead to an abrupt change of visible data") + + """ + The same as test_with_other_parent(), but add the NBD server only + when the mirror job is already running. + """ + def test_with_other_parents_after_mirror_start(self): + result = self.vm.qmp('nbd-server-start', + addr={ + 'type': 'unix', + 'data': {'path': nbd_sock_path} + }) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('drive-mirror', job_id='mirror', device='quorum0', + sync='full', node_name='repair0', replaces='img1', + target=quorum_repair_img, format=iotests.imgfmt) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('nbd-server-add', device='img1') + self.assert_qmp(result, 'return', {}) + + # The full error message goes to stderr, we will check it later + self.complete_and_wait('mirror', + completion_error='Operation not permitted') + + # Should not have been replaced + self.vm.assert_block_path('quorum0', '/children.1', 'img1') + + # Check the full error message now + self.vm.shutdown() + log = self.vm.get_log() + log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) + log = re.sub(r'^Formatting.*\n', '', log) + log = re.sub(r'\n\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + log = re.sub(r'^qemu-system-[^:]*: ', '', log) + + self.assertEqual(log, + "Can no longer replace 'img1' by 'repair0', because " + + "it can no longer be guaranteed that doing so would " + + "not lead to an abrupt change of visible data") + + # Test mirroring with a source that does not have any parents (not even a # BlockBackend) class TestOrphanedSource(iotests.QMPTestCase): diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index f496be9197..ffc779b4d1 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -........................................................................................... +............................................................................................. ---------------------------------------------------------------------- -Ran 91 tests +Ran 93 tests OK From patchwork Mon Nov 11 16:02:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237309 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DD3015AB for ; Mon, 11 Nov 2019 16:14:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 141BF20856 for ; Mon, 11 Nov 2019 16:14:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="i0y+EXoB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 141BF20856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCL3-000678-T6 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:14:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39418) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCAB-0000Np-8J for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUCAA-0003AH-6M for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:35 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:50550 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUCAA-00039l-30 for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OwInKIeB2qHqz5J6Rh6jtjb8BLoBMDSnI+3OT0jmMbs=; b=i0y+EXoBDuO2GJmUAYVF4EHiO4UWoFybOGDEUvW+U5Qe6zMOhjNBYH1tBHR/5ZQ9FnERo/ wfJfJ9+Ir+1ka1Y6qvCBs1acC6dlPV4/SJaiXXXGUSbsUv1YeUxb/M6j/NvshZLyL9lMl6 Pi2i/HIUZbAv4iSclqHeLOTFSz7bOzI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-136-DX4p-F7uOKW3Albyr_5N-g-1; Mon, 11 Nov 2019 11:03:28 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34FC81005500; Mon, 11 Nov 2019 16:03:27 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A1A7C5D9C9; Mon, 11 Nov 2019 16:03:26 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 22/23] iotests: Check that @replaces can replace filters Date: Mon, 11 Nov 2019 17:02:15 +0100 Message-Id: <20191111160216.197086-23-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: DX4p-F7uOKW3Albyr_5N-g-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/041 | 46 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index ab0cb5b42f..9a00cf6f7b 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1200,6 +1200,52 @@ class TestOrphanedSource(iotests.QMPTestCase): self.assertFalse('mirror-filter' in nodes, 'Mirror filter node did not disappear') +# Test cases for @replaces that do not necessarily involve Quorum +class TestReplaces(iotests.QMPTestCase): + # Each of these test cases needs their own block graph, so do not + # create any nodes here + def setUp(self): + self.vm = iotests.VM() + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + for img in (test_img, target_img): + try: + os.remove(img) + except OSError: + pass + + """ + Check that we can replace filter nodes. + """ + @iotests.skip_if_unsupported(['copy-on-read']) + def test_replace_filter(self): + result = self.vm.qmp('blockdev-add', **{ + 'driver': 'copy-on-read', + 'node-name': 'filter0', + 'file': { + 'driver': 'copy-on-read', + 'node-name': 'filter1', + 'file': { + 'driver': 'null-co' + } + } + }) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-add', + node_name='target', driver='null-co') + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-mirror', job_id='mirror', device='filter0', + target='target', sync='full', replaces='filter1') + self.assert_qmp(result, 'return', {}) + + self.complete_and_wait('mirror') + + self.vm.assert_block_path('filter0', '/file', 'target') + if __name__ == '__main__': iotests.main(supported_fmts=['qcow2', 'qed'], supported_protocols=['file']) diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index ffc779b4d1..877b76fd31 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -............................................................................................. +.............................................................................................. ---------------------------------------------------------------------- -Ran 93 tests +Ran 94 tests OK From patchwork Mon Nov 11 16:02:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11237339 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 860BB14ED for ; Mon, 11 Nov 2019 16:36:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4B1FC20656 for ; Mon, 11 Nov 2019 16:36:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jOwiC8h9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4B1FC20656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:55022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCfe-0005J8-2q for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Nov 2019 11:36:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39440) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCAF-0000RU-Ge for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUCA9-0003AB-TX for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:39 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:54854 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUCA9-00039c-PB for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:03:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573488212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=whUrYdJLhBASdpWCpuLFMfQuo3veDYHSDj2xi+Fnx2w=; b=jOwiC8h90pZhHFg1K21fLWxbjWtYzVJnp9H1uIO/oT3hMqDKRR3zNRVb6ayzM85kFLtsDx J6N99oNRfRjx8P7n6jrCEJtmAgcPJHYB3g4E9eXgEcRcXAUR9jvXtuALijsGCbKxzJqhmp rMnTeUVmRr4cveLxmbIbFYN3yVDiC5c= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-344-JvaqgvzvP0S0b2aKMOMFRg-1; Mon, 11 Nov 2019 11:03:31 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D1A9107ACC5; Mon, 11 Nov 2019 16:03:30 +0000 (UTC) Received: from localhost (ovpn-117-116.ams2.redhat.com [10.36.117.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3BBA608FF; Mon, 11 Nov 2019 16:03:29 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v2 23/23] iotests: Mirror must not attempt to create loops Date: Mon, 11 Nov 2019 17:02:16 +0100 Message-Id: <20191111160216.197086-24-mreitz@redhat.com> In-Reply-To: <20191111160216.197086-1-mreitz@redhat.com> References: <20191111160216.197086-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: JvaqgvzvP0S0b2aKMOMFRg-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/041 | 235 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 +- 2 files changed, 237 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 9a00cf6f7b..0e43bb699d 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1246,6 +1246,241 @@ class TestReplaces(iotests.QMPTestCase): self.vm.assert_block_path('filter0', '/file', 'target') + """ + See what happens when the @sync/@replaces configuration dictates + creating a loop. + """ + @iotests.skip_if_unsupported(['throttle']) + def test_loop(self): + qemu_img('create', '-f', iotests.imgfmt, test_img, str(1 * 1024 * 1024)) + + # Dummy group so we can create a NOP filter + result = self.vm.qmp('object-add', qom_type='throttle-group', id='tg0') + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-add', **{ + 'driver': 'throttle', + 'node-name': 'source', + 'throttle-group': 'tg0', + 'file': { + 'driver': iotests.imgfmt, + 'node-name': 'filtered', + 'file': { + 'driver': 'file', + 'filename': test_img + } + } + }) + self.assert_qmp(result, 'return', {}) + + # Block graph is now: + # source[throttle] --file--> filtered[imgfmt] --file--> ... + + result = self.vm.qmp('drive-mirror', job_id='mirror', device='source', + target=target_img, format=iotests.imgfmt, + node_name='target', sync='none', + replaces='filtered') + + """ + Block graph before mirror exits would be (ignoring mirror_top): + source[throttle] --file--> filtered[imgfmt] --file--> ... + target[imgfmt] --file--> ... + + Then, because of sync=none and drive-mirror in absolute-paths mode, + the source is attached to the target: + source[throttle] --file--> filtered[imgfmt] --file--> ... + ^ + backing + | + target[imgfmt] --file--> ... + + Replacing filtered by target would yield: + source[throttle] --file--> target[imgfmt] --file--> ... + ^ | + +------- backing --------+ + + I.e., a loop. bdrv_replace_node() detects this and simply + does not let source's file link point to target. However, + that means that target cannot really replace source. + + drive-mirror should detect this and not allow this case. + """ + + self.assert_qmp(result, 'error/desc', + "Replacing 'filtered' by 'target' with this sync " + \ + "mode would result in a loop, because the former " + \ + "would be a child of the latter's backing file " + \ + "('source') after the mirror job") + + """ + Test what happens when there would be no loop with the pre-mirror + configuration, but something changes during the mirror job that asks + for a loop to be created during completion. + """ + @iotests.skip_if_unsupported(['copy-on-read', 'quorum']) + def test_loop_during_mirror(self): + qemu_img('create', '-f', iotests.imgfmt, test_img, str(1 * 1024 * 1024)) + + """ + In this test, we are going to mirror from a node that is a + filter above some file "common-base". The target is a quorum + node (with just an unrelated null-co child). + + We will ask the mirror job to replace common-base by the + target upon completion. That is a completely valid + configuration so far. + + However, while the job is running, we add common-base as an + (indirect[1]) child to the target quorum node. This way, + completing the job as requested would yield a loop, because + the target would be supposed to replace common-base -- which + is its own (indirect) child. + + [1] It needs to be an indirect child, because if it were a + direct child, the mirror job would simply end by effectively + injecting the target above common-base. This is the same + effect as when using sync=none: The target ends up above the + source. + + So only loops that have a length of more than one node are + forbidden, which means common-base must be an indirect child + of the target. + + (Furthermore, we are going to use x-blockdev-change to add + common-base as a child to the target. This command only + allows doing so for nodes that have no parent yet. + common-base will have a parent already, though, namely the + source node. Therefore, this is another reason why we need at + least one node above common-base, so this parent can become + target's child during the mirror.) + """ + + result = self.vm.qmp('blockdev-add', **{ + 'driver': 'null-co', + 'node-name': 'common-base', + 'read-zeroes': True, + 'size': 1 * 1024 * 1024 + }) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-add', **{ + 'driver': 'copy-on-read', + 'node-name': 'source', + 'file': 'common-base' + }) + self.assert_qmp(result, 'return', {}) + + """ + As explained above, we have to create a parent above + common-base. + + We cannot use any parent that would forward the RESIZE + permission, because the job takes it on the target, but + unshares it on the source: After the x-blockdev-change + operation during the mirror job, this parent will be a child + of the target, so common-base will be an (indirect) child of + both the mirror's source and target. Thus, the job would + conflict with itself. + + Therefore, we make common-base a backing child of a $imgfmt + node. Unfortunately, we cannot let the mirror job replace a + node that acts as a backing child somewhere (because of an op + blocker), so we put another raw node between the $imgfmt node + and common-base. + """ + result = self.vm.qmp('blockdev-add', **{ + 'driver': iotests.imgfmt, + 'node-name': 'base-parent', + 'file': { + 'driver': 'file', + 'filename': test_img + }, + 'backing': { + 'driver': 'raw', + 'file': 'common-base' + } + }) + + """ + Add a quorum node with a single child, we will add base-parent + to prepare a loop later. + (We do not care about this single child at all, but it is + impossible to create a quorum node without any children. We + will ignore this child from now on.) + """ + result = self.vm.qmp('blockdev-add', **{ + 'driver': 'quorum', + 'node-name': 'target', + 'vote-threshold': 1, + 'children': [ + { + 'driver': 'null-co', + 'read-zeroes': True, + 'size': 1 * 1024 * 1024 + } + ] + }) + self.assert_qmp(result, 'return', {}) + + """ + Current block graph: + + base-parent[$imgfmt] --backing--> [raw] + | + file + v + source[COR] --file--> common-base[null-co] + + target[quorum] + + + The following blockdev-mirror asks for this graph post-mirror: + + base-parent[$imgfmt] --backing--> [raw] + | + file + v + source[COR] --file--> target[quorum] + + That would be a valid configuration without any loops. + """ + + result = self.vm.qmp('blockdev-mirror', job_id='mirror', + device='source', target='target', sync='full', + replaces='common-base') + self.assert_qmp(result, 'return', {}) + + """ + However, now we will make base-parent a child of target. + Before the mirror job completes, that is still completely + valid: + + source + | + v + target -> base-parent -> [raw] -> common-base + """ + + result = self.vm.qmp('x-blockdev-change', + parent='target', node='base-parent') + self.assert_qmp(result, 'return', {}) + + """ + However, post-mirror, we thus ask for a loop: + + source -> target (replaced common-base) -> base-parent + ^ | + | v + +----------------- [raw] + + bdrv_replace_node() would not allow such a configuration, but + we should not pretend we can create it, so the mirror job + should fail during completion. + """ + + self.complete_and_wait('mirror', + completion_error='Operation not permitted') + if __name__ == '__main__': iotests.main(supported_fmts=['qcow2', 'qed'], supported_protocols=['file']) diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index 877b76fd31..20a8158b99 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -.............................................................................................. +................................................................................................ ---------------------------------------------------------------------- -Ran 94 tests +Ran 96 tests OK