From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738257245; cv=none; d=zohomail.com; s=zohoarc; b=M7qF5VXXqP6orUfbkQBIx9zIffCvzSzMQx6yUYX7vushq0ixw8FmUJwMSsY/jnUat3BAk0Fwl+FUu7qHxTI3q3JFxuB067IZ/r6BSROZHFE2XVYEO5TZvXeyG2pxsmX2iRLzGv2+oBh//TxNxgJUaxbGQ0VLrQ5uI+EG3HeJHiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738257245; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AkkF2cn/t641hJWFZPt980OvaWaQev/HN6FTjpix9O0=; b=aJY4S300orAFCAqzbmojQOGIp/uAeeZuC+oujI1YyHp8jfgfA85l3SwmRSRlNqnHG0tOUvoTLmiGvGLMfRxsuSxrm0bjq45oF+Ex3WGx2rfnZA6ogDxD+qs6Nt6Ou4wBI1bfFKLf7jVZ8NXE08joJn1UnuqkRa+LXjFf1fn5mdA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738257245543339.71178318006343; Thu, 30 Jan 2025 09:14:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdY69-0000X1-4Q; Thu, 30 Jan 2025 12:13:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY66-0000WP-PC for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:12:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY64-00039I-Nc for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:12:58 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-260-mUdhSWqwODezgaFl6aavlw-1; Thu, 30 Jan 2025 12:12:54 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0324F1956052; Thu, 30 Jan 2025 17:12:52 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.13]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AB1CA30001BE; Thu, 30 Jan 2025 17:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738257175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AkkF2cn/t641hJWFZPt980OvaWaQev/HN6FTjpix9O0=; b=PvnQFhIeP4PcRbuNu7zDYqs5uyZuU/yxJ43PZPKFDdkUFhT2fwGPtz9fH54p6rX0UV2tET eJdvoTkY2OEssoJAv5TWlq7H6Jtk2+wR2CUhTpLbKWoRIbpkeCggnvv0UefOGBllHTfW0S DgT4/JBHtldAeQP1/mgtMfKaOWbKRT0= X-MC-Unique: mUdhSWqwODezgaFl6aavlw-1 X-Mimecast-MFC-AGG-ID: mUdhSWqwODezgaFl6aavlw From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 01/15] block: Add 'active' field to BlockDeviceInfo Date: Thu, 30 Jan 2025 18:12:32 +0100 Message-ID: <20250130171240.286878-2-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738257253830019000 Content-Type: text/plain; charset="utf-8" This allows querying from QMP (and also HMP) whether an image is currently active or inactive (in the sense of BDRV_O_INACTIVE). Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- qapi/block-core.json | 6 +++++- block/monitor/block-hmp-cmds.c | 5 +++-- block/qapi.c | 1 + tests/qemu-iotests/184.out | 2 ++ tests/qemu-iotests/191.out | 16 ++++++++++++++++ tests/qemu-iotests/273.out | 5 +++++ 6 files changed, 32 insertions(+), 3 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index fd3bcc1c17..1296ca8ae2 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -486,6 +486,10 @@ # @backing_file_depth: number of files in the backing file chain # (since: 1.2) # +# @active: true if the backend is active; typical cases for inactive backe= nds +# are on the migration source instance after migration completes and o= n the +# destination before it completes. (since: 10.0) +# # @encrypted: true if the backing device is encrypted # # @detect_zeroes: detect and optimize zero writes (Since 2.1) @@ -556,7 +560,7 @@ { 'struct': 'BlockDeviceInfo', 'data': { 'file': 'str', '*node-name': 'str', 'ro': 'bool', 'drv': 'str', '*backing_file': 'str', 'backing_file_depth': 'int', - 'encrypted': 'bool', + 'active': 'bool', 'encrypted': 'bool', 'detect_zeroes': 'BlockdevDetectZeroesOptions', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 1d312513fc..e84ff6ab16 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -630,11 +630,12 @@ static void print_block_info(Monitor *mon, BlockInfo = *info, } =20 if (inserted) { - monitor_printf(mon, ": %s (%s%s%s)\n", + monitor_printf(mon, ": %s (%s%s%s%s)\n", inserted->file, inserted->drv, inserted->ro ? ", read-only" : "", - inserted->encrypted ? ", encrypted" : ""); + inserted->encrypted ? ", encrypted" : "", + inserted->active ? "" : ", inactive"); } else { monitor_printf(mon, ": [not inserted]\n"); } diff --git a/block/qapi.c b/block/qapi.c index 902ecb08e0..63604dc6d3 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -63,6 +63,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, info->file =3D g_strdup(bs->filename); info->ro =3D bdrv_is_read_only(bs); info->drv =3D g_strdup(bs->drv->format_name); + info->active =3D !bdrv_is_inactive(bs); info->encrypted =3D bs->encrypted; =20 info->cache =3D g_new(BlockdevCacheInfo, 1); diff --git a/tests/qemu-iotests/184.out b/tests/qemu-iotests/184.out index e8f631f853..52692b6b3b 100644 --- a/tests/qemu-iotests/184.out +++ b/tests/qemu-iotests/184.out @@ -26,6 +26,7 @@ Testing: { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "backing-image": { "virtual-size": 1073741824, @@ -59,6 +60,7 @@ Testing: { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 1073741824, "filename": "null-co://", diff --git a/tests/qemu-iotests/191.out b/tests/qemu-iotests/191.out index c3309e4bc6..2a72ca7106 100644 --- a/tests/qemu-iotests/191.out +++ b/tests/qemu-iotests/191.out @@ -114,6 +114,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "backing-image": { "virtual-size": 67108864, @@ -155,6 +156,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 197120, "filename": "TEST_DIR/t.IMGFMT.ovl2", @@ -183,6 +185,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "backing-image": { "virtual-size": 67108864, @@ -224,6 +227,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 197120, "filename": "TEST_DIR/t.IMGFMT", @@ -252,6 +256,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "backing-image": { "virtual-size": 67108864, @@ -293,6 +298,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 393216, "filename": "TEST_DIR/t.IMGFMT.mid", @@ -321,6 +327,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 67108864, "filename": "TEST_DIR/t.IMGFMT.base", @@ -350,6 +357,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 393216, "filename": "TEST_DIR/t.IMGFMT.base", @@ -521,6 +529,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "backing-image": { "virtual-size": 67108864, @@ -562,6 +571,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 197120, "filename": "TEST_DIR/t.IMGFMT.ovl2", @@ -590,6 +600,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "backing-image": { "backing-image": { @@ -642,6 +653,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 197120, "filename": "TEST_DIR/t.IMGFMT.ovl3", @@ -670,6 +682,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 67108864, "filename": "TEST_DIR/t.IMGFMT.base", @@ -699,6 +712,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 393216, "filename": "TEST_DIR/t.IMGFMT.base", @@ -727,6 +741,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "backing-image": { "virtual-size": 67108864, @@ -768,6 +783,7 @@ wrote 65536/65536 bytes at offset 1048576 { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 197120, "filename": "TEST_DIR/t.IMGFMT", diff --git a/tests/qemu-iotests/273.out b/tests/qemu-iotests/273.out index 71843f02de..c19753c685 100644 --- a/tests/qemu-iotests/273.out +++ b/tests/qemu-iotests/273.out @@ -23,6 +23,7 @@ Testing: -blockdev file,node-name=3Dbase,filename=3DTEST_= DIR/t.IMGFMT.base -blockdev { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "backing-image": { "backing-image": { @@ -74,6 +75,7 @@ Testing: -blockdev file,node-name=3Dbase,filename=3DTEST_= DIR/t.IMGFMT.base -blockdev { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 197120, "filename": "TEST_DIR/t.IMGFMT", @@ -102,6 +104,7 @@ Testing: -blockdev file,node-name=3Dbase,filename=3DTES= T_DIR/t.IMGFMT.base -blockdev { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "backing-image": { "virtual-size": 197120, @@ -142,6 +145,7 @@ Testing: -blockdev file,node-name=3Dbase,filename=3DTES= T_DIR/t.IMGFMT.base -blockdev { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 197120, "filename": "TEST_DIR/t.IMGFMT.mid", @@ -170,6 +174,7 @@ Testing: -blockdev file,node-name=3Dbase,filename=3DTES= T_DIR/t.IMGFMT.base -blockdev { "iops_rd": 0, "detect_zeroes": "off", + "active": true, "image": { "virtual-size": 197120, "filename": "TEST_DIR/t.IMGFMT.base", --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738257213; cv=none; d=zohomail.com; s=zohoarc; b=bfAaloFb9mhx0nT4RVAAx09DopqRTammfLSn8c+rpcd3EkwDHg10kxrthKqiinJDot2op4o90kp1Qrjcrz9EfFxMNGVTAvoy9km/GG84Xj/0pLPNrRLp0gI/qK02XVv8P3qgxCQZBdDtIN2xDM4hC74AsM1/gXAxPrJPI4y2YNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738257213; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O9R1bvCZlCby3nJpaX4lx6Gi7/oQpcND1WUKEvZhskk=; b=BlkosoZXnD7kAJBM0Xu5LomwZw6K2Ruj7Gn0I2eYrJPmScGeKqZTpXNO5BdusPtKd2U8axH24H/UTEPsUD9JW+O1PtW0uyX9NLjpXQu6JMLg6VxdBmgevltqMOFQrTHgUmteTZtD5gmMp+ve8JNG7KqSBZ79WvoH7R2bER0/ano= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738257213419118.33607578854605; Thu, 30 Jan 2025 09:13:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdY6B-0000YQ-8i; Thu, 30 Jan 2025 12:13:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY68-0000Wf-7V for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY66-00039j-6E for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:12:59 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-481-0UBNsMEPNjG7tnJvPJ-h4g-1; Thu, 30 Jan 2025 12:12:56 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D0E6919560B0; Thu, 30 Jan 2025 17:12:54 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.13]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6DD643003FD2; Thu, 30 Jan 2025 17:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738257177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O9R1bvCZlCby3nJpaX4lx6Gi7/oQpcND1WUKEvZhskk=; b=WEOJ48rgKP5Vu07Hnrnist9gQTJA/c62jff4p+6hPHrtAeLl/yyP1ASwbCb1yNyoZtPFH9 nRlcspyl9Hc6Qcx28nBfrvaEjF2Tbzv9oIvHaRn0T24HJc567+wSUuw9XDhDmVPrrfRLW+ fJxTjQZKT1KJiLCJ/kaTEmQiP3S3KxQ= X-MC-Unique: 0UBNsMEPNjG7tnJvPJ-h4g-1 X-Mimecast-MFC-AGG-ID: 0UBNsMEPNjG7tnJvPJ-h4g From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 02/15] block: Inactivate external snapshot overlays when necessary Date: Thu, 30 Jan 2025 18:12:33 +0100 Message-ID: <20250130171240.286878-3-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738257216070019000 Content-Type: text/plain; charset="utf-8" Putting an active block node on top of an inactive one is strictly speaking an invalid configuration and the next patch will turn it into a hard error. However, taking a snapshot while disk images are inactive after completing migration has an important use case: After migrating to a file, taking an external snapshot is what is needed to take a full VM snapshot. In order for this to keep working after the later patches, change creating a snapshot such that it automatically inactivates an overlay that is added on top of an already inactive node. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- blockdev.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/blockdev.c b/blockdev.c index 218024497b..eb2517f1dd 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1497,6 +1497,22 @@ static void external_snapshot_action(TransactionActi= on *action, return; } =20 + /* + * Older QEMU versions have allowed adding an active parent node to an + * inactive child node. This is unsafe in the general case, but there = is an + * important use case, which is taking a VM snapshot with migration to= file + * and then adding an external snapshot while the VM is still stopped = and + * images are inactive. Requiring the user to explicitly create the ov= erlay + * as inactive would break compatibility, so just do it automatically = here + * to keep this working. + */ + if (bdrv_is_inactive(state->old_bs) && !bdrv_is_inactive(state->new_bs= )) { + ret =3D bdrv_inactivate(state->new_bs, errp); + if (ret < 0) { + return; + } + } + ret =3D bdrv_append(state->new_bs, state->old_bs, errp); if (ret < 0) { return; --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738257213; cv=none; d=zohomail.com; s=zohoarc; b=OTzktccPqajgzGc1zr8omofnp3J9X+ijcmxAYaP3McjQkgvLRrrlmTOGu/oS4seBa9Jk6aQUrV1XRBzlud2WqgsADYJoCnWsOzlYljKXqmLZwpPT4MH2S9gnJhxhcmwQRG9qB/j0F2v5SnCQBhwYeySZuPNWb7DxLCPhJIeqNzE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738257213; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ESM96NOFMTrfjmv5qDklK8Zu/7Pwmxh9z7Ci8tSUiJQ=; b=bXINepsTViYwaPdCTW5cLCerZ9NccqoOyhz2o1eaz7Qs6vHfsBH5eLVvc6a8tnCKSQMOK8wqAw07TkQ2pSZjpxLdUXY6BVL105zmXsWbbN2EyhZVVobywoaBqwwUuAO2/FblNfDEtAxlFSn2p+rqGVbg0sbAI53VQRRZAx1VjlU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738257213405580.8751785791308; Thu, 30 Jan 2025 09:13:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdY6F-0000bU-UM; Thu, 30 Jan 2025 12:13:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6D-0000a1-9A for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6B-0003B8-Ii for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:04 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-sxmmHn9XN0KhoBlQsTOTlQ-1; Thu, 30 Jan 2025 12:12:58 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D9A44195608D; Thu, 30 Jan 2025 17:12:57 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.13]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7490B30001BE; Thu, 30 Jan 2025 17:12:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738257182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ESM96NOFMTrfjmv5qDklK8Zu/7Pwmxh9z7Ci8tSUiJQ=; b=EueG9n2/tGo9gMsmih/vi5LgB/yk3wpfdMbosRxkXTAG6vyYjeRSDyEH3zgkacBRttcO+/ Bwks8bf9Bm00f7oSPmlAcpSEdsYyeKbNtqZmvKUTTZ0phiVfyYubw0jfhlyFAPNOCh0Sdr 7r190SE7AU61nqLXMQ7TuHRyZj9l/Lk= X-MC-Unique: sxmmHn9XN0KhoBlQsTOTlQ-1 X-Mimecast-MFC-AGG-ID: sxmmHn9XN0KhoBlQsTOTlQ From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 03/15] migration/block-active: Remove global active flag Date: Thu, 30 Jan 2025 18:12:34 +0100 Message-ID: <20250130171240.286878-4-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738257216103019000 Content-Type: text/plain; charset="utf-8" Block devices have an individual active state, a single global flag can't cover this correctly. This becomes more important as we allow users to manually manage which nodes are active or inactive. Now that it's allowed to call bdrv_inactivate_all() even when some nodes are already inactive, we can remove the flag and just unconditionally call bdrv_inactivate_all() and, more importantly, bdrv_activate_all() before we make use of the nodes. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- migration/migration.h | 3 --- migration/block-active.c | 46 ---------------------------------------- migration/migration.c | 8 ------- 3 files changed, 57 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 0df2a187af..9540e8f04e 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -553,7 +553,4 @@ void migration_bitmap_sync_precopy(bool last_stage); /* migration/block-dirty-bitmap.c */ void dirty_bitmap_mig_init(void); =20 -/* migration/block-active.c */ -void migration_block_active_setup(bool active); - #endif diff --git a/migration/block-active.c b/migration/block-active.c index d477cf8182..40e986aade 100644 --- a/migration/block-active.c +++ b/migration/block-active.c @@ -12,51 +12,12 @@ #include "qemu/error-report.h" #include "trace.h" =20 -/* - * Migration-only cache to remember the block layer activation status. - * Protected by BQL. - * - * We need this because.. - * - * - Migration can fail after block devices are invalidated (during - * switchover phase). When that happens, we need to be able to recover - * the block drive status by re-activating them. - * - * - Currently bdrv_inactivate_all() is not safe to be invoked on top of - * invalidated drives (even if bdrv_activate_all() is actually safe to be - * called any time!). It means remembering this could help migration to - * make sure it won't invalidate twice in a row, crashing QEMU. It can - * happen when we migrate a PAUSED VM from host1 to host2, then migrate - * again to host3 without starting it. TODO: a cleaner solution is to - * allow safe invoke of bdrv_inactivate_all() at anytime, like - * bdrv_activate_all(). - * - * For freshly started QEMU, the flag is initialized to TRUE reflecting the - * scenario where QEMU owns block device ownerships. - * - * For incoming QEMU taking a migration stream, the flag is initialized to - * FALSE reflecting that the incoming side doesn't own the block devices, - * not until switchover happens. - */ -static bool migration_block_active; - -/* Setup the disk activation status */ -void migration_block_active_setup(bool active) -{ - migration_block_active =3D active; -} - bool migration_block_activate(Error **errp) { ERRP_GUARD(); =20 assert(bql_locked()); =20 - if (migration_block_active) { - trace_migration_block_activation("active-skipped"); - return true; - } - trace_migration_block_activation("active"); =20 bdrv_activate_all(errp); @@ -65,7 +26,6 @@ bool migration_block_activate(Error **errp) return false; } =20 - migration_block_active =3D true; return true; } =20 @@ -75,11 +35,6 @@ bool migration_block_inactivate(void) =20 assert(bql_locked()); =20 - if (!migration_block_active) { - trace_migration_block_activation("inactive-skipped"); - return true; - } - trace_migration_block_activation("inactive"); =20 ret =3D bdrv_inactivate_all(); @@ -89,6 +44,5 @@ bool migration_block_inactivate(void) return false; } =20 - migration_block_active =3D false; return true; } diff --git a/migration/migration.c b/migration/migration.c index 2d1da917c7..ae252f24e6 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1838,12 +1838,6 @@ void qmp_migrate_incoming(const char *uri, bool has_= channels, return; } =20 - /* - * Newly setup incoming QEMU. Mark the block active state to reflect - * that the src currently owns the disks. - */ - migration_block_active_setup(false); - once =3D false; } =20 @@ -3808,8 +3802,6 @@ static void migration_instance_init(Object *obj) ms->state =3D MIGRATION_STATUS_NONE; ms->mbps =3D -1; ms->pages_per_second =3D -1; - /* Freshly started QEMU owns all the block devices */ - migration_block_active_setup(true); qemu_sem_init(&ms->pause_sem, 0); qemu_mutex_init(&ms->error_mutex); =20 --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738257378; cv=none; d=zohomail.com; s=zohoarc; b=S0RrGmr/jJBIV/WgQunapkMmHblKiihQoYy0kQ4Z1nCxih9mh9uqXAWJUfltROVNaDugEbMIci6XunFP8K5seanjb6PGVWLU4roGSd86L3TM9OZ3BEyxGPvhigeWsWNLnCngTpT/oAM9+o6h5HksoPL1hr6aeXGCWi1cYfQPigM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738257378; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ujcWsxYgiSfNM90SILjF47R2m0lOXbwEHvICzvLQvvs=; b=NhiHDuDwbAK0+kFDMT4WeAMc97F+ZkcrD2jPFyC27At4p0iOGWq9u9Qe4o9p4F+uPPqEE2ug/YQqNRB9oWjqLpTYz5NPtrDhjeY8inzYMQqGop7BH58IZpCkX3NJpklOGVHku4ikNng7ygCZ2s1B2+gRKUbwyz033n9HiHskhBI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738257378485524.4761520277882; Thu, 30 Jan 2025 09:16:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdY6G-0000c0-OJ; Thu, 30 Jan 2025 12:13:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6E-0000aL-9z for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6B-0003BE-QV for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:06 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-t1_wAA2xON62_zUTHDaP0g-1; Thu, 30 Jan 2025 12:13:01 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9429E195608D; Thu, 30 Jan 2025 17:13:00 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.13]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4542830001BE; Thu, 30 Jan 2025 17:12:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738257183; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ujcWsxYgiSfNM90SILjF47R2m0lOXbwEHvICzvLQvvs=; b=cHbac+yH55aq14ymUALFQyTScwIZupiBL6vJd8Obn+LTVgKwckrJMIyGCqq6FBLjS+jUrr SYUAoEKjDXpXkASHiCOSFdtfwuNriWsaSp4U5bjhISkzahE2UzUplSkhLH6SPI/3RU+vhP B86v/vbKLTZpzQ3rP+wIrjz9dG5qndE= X-MC-Unique: t1_wAA2xON62_zUTHDaP0g-1 X-Mimecast-MFC-AGG-ID: t1_wAA2xON62_zUTHDaP0g From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 04/15] block: Don't attach inactive child to active node Date: Thu, 30 Jan 2025 18:12:35 +0100 Message-ID: <20250130171240.286878-5-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738257378973019000 Content-Type: text/plain; charset="utf-8" An active node makes unrestricted use of its children and would possibly run into assertion failures when it operates on an inactive child node. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block.c b/block.c index f60606f242..94368a200e 100644 --- a/block.c +++ b/block.c @@ -3183,6 +3183,11 @@ bdrv_attach_child_noperm(BlockDriverState *parent_bs, child_bs->node_name, child_name, parent_bs->node_name); return NULL; } + if (bdrv_is_inactive(child_bs) && !bdrv_is_inactive(parent_bs)) { + error_setg(errp, "Inactive '%s' can't be a %s child of active '%s'= ", + child_bs->node_name, child_name, parent_bs->node_name); + return NULL; + } =20 bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL, --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738257253; cv=none; d=zohomail.com; s=zohoarc; b=C9xPcfNBX2XwmTIQ/iXBg+cdncjFck/ba0ywK4whEeAoJOSutezfgkJ/LlNfavkDfIDTNOQmqnifyYZZ/Lj5qfz05K8/51UPku5a7kQdSmo1R8rCFuijsaOlYAaivZ6kKc0Rrsk01LY1S16M4qVj/bW8QR7/HB+CN7h7urU/zfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738257253; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bybbmbp4o3dm/8LvP5Lj7D6zru5NTPZT+ktuCm9LAKE=; b=ibgdCR94qkUwGgasSud+pNN90g462TEh4P/XBFs8YeWTmdvevis7TCBvjvq0MWyK982TlSyeo/UXsNE3AV2hc0hKlIvqQRQ5oA8mPpy3iy+I91qDkzpo7bQOwkSqiDan4LDtL5KT50nKGuetQHR9fJ6BqrYLoQ92fjb9GfFWRxM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738257253979902.4305941983976; Thu, 30 Jan 2025 09:14:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdY6N-0000en-2P; Thu, 30 Jan 2025 12:13:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6J-0000do-Ra for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6I-0003C7-63 for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:11 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-Ljjwrv_tOZqs4wdk1OkJwA-1; Thu, 30 Jan 2025 12:13:04 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B1BDC1955F67; Thu, 30 Jan 2025 17:13:03 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.13]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0C1BC30001BE; Thu, 30 Jan 2025 17:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738257188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bybbmbp4o3dm/8LvP5Lj7D6zru5NTPZT+ktuCm9LAKE=; b=ZPu9WA+rllL+3kYFWkJ0xwiqqUEQoJkezWYWj5wtCpViVUyLS/ysq3abPQVeCqUxalT6CK Luag/QwCW/kdvRCE+8Ixbbnay3I1hWpZhcl7fImCD/PJCrhymOo1CRFDfk8MnHL3dyIxT+ hXxAqGr8iOJXNfehsNOk8KGKlHOAnxQ= X-MC-Unique: Ljjwrv_tOZqs4wdk1OkJwA-1 X-Mimecast-MFC-AGG-ID: Ljjwrv_tOZqs4wdk1OkJwA From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 05/15] block: Allow inactivating already inactive nodes Date: Thu, 30 Jan 2025 18:12:36 +0100 Message-ID: <20250130171240.286878-6-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738257256028019000 Content-Type: text/plain; charset="utf-8" What we wanted to catch with the assertion is cases where the recursion finds that a child was inactive before its parent. This should never happen. But if the user tries to inactivate an image that is already inactive, that's harmless and we don't want to fail the assertion. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 94368a200e..be6b71c314 100644 --- a/block.c +++ b/block.c @@ -6960,7 +6960,8 @@ bdrv_has_bds_parent(BlockDriverState *bs, bool only_a= ctive) return false; } =20 -static int GRAPH_RDLOCK bdrv_inactivate_recurse(BlockDriverState *bs) +static int GRAPH_RDLOCK +bdrv_inactivate_recurse(BlockDriverState *bs, bool top_level) { BdrvChild *child, *parent; int ret; @@ -6978,7 +6979,14 @@ static int GRAPH_RDLOCK bdrv_inactivate_recurse(Bloc= kDriverState *bs) return 0; } =20 - assert(!(bs->open_flags & BDRV_O_INACTIVE)); + /* + * Inactivating an already inactive node on user request is harmless, = but if + * a child is already inactive before its parent, that's bad. + */ + if (bs->open_flags & BDRV_O_INACTIVE) { + assert(top_level); + return 0; + } =20 /* Inactivate this node */ if (bs->drv->bdrv_inactivate) { @@ -7015,7 +7023,7 @@ static int GRAPH_RDLOCK bdrv_inactivate_recurse(Block= DriverState *bs) =20 /* Recursively inactivate children */ QLIST_FOREACH(child, &bs->children, next) { - ret =3D bdrv_inactivate_recurse(child->bs); + ret =3D bdrv_inactivate_recurse(child->bs, false); if (ret < 0) { return ret; } @@ -7040,7 +7048,7 @@ int bdrv_inactivate_all(void) if (bdrv_has_bds_parent(bs, false)) { continue; } - ret =3D bdrv_inactivate_recurse(bs); + ret =3D bdrv_inactivate_recurse(bs, true); if (ret < 0) { bdrv_next_cleanup(&it); break; --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738257325; cv=none; d=zohomail.com; s=zohoarc; b=Yfi5AZncGEMxaNK0tfTFJ4+ZeqjU9SXU/+UeZGt6y04jdvT4t/KbHgNbcabZ9EyTja84h+VfF52LiASK0gi1bRjkgNSWON4mfXaUD2VY426tLF9snUZbglnkeMqFDrwk4JqM6Av9hMk3BvGany4BGWamLe3kw5WbtIoXT7mAoGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738257325; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=x2wBYH1nF1e4Gs/jyRNfxVZkd6GU5b6C98eFGtW8FFw=; b=Jo++E606OXkW/autCECgHIXOFsz/Dm2ctviNuylGsClbOARIZHZo2cekpStYns0M4DiUriSb5rxsP2kE7R1EJMkawKAMrk1Nc/bsTabwATUzy26XEJqid2W7AtPjdI38SdSinyNPTvH/L67ulkRRq6oxCqQoOmY5wV60giAdWog= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738257325230548.7855162528915; Thu, 30 Jan 2025 09:15:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdY6M-0000el-KE; Thu, 30 Jan 2025 12:13:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6J-0000dp-Ro for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6I-0003CG-4W for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:11 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-bT7oymGEMuCOyrxl3Ru3jg-1; Thu, 30 Jan 2025 12:13:07 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EB2271801F1C; Thu, 30 Jan 2025 17:13:06 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.13]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2705730001BE; Thu, 30 Jan 2025 17:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738257189; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x2wBYH1nF1e4Gs/jyRNfxVZkd6GU5b6C98eFGtW8FFw=; b=ex9JzPEnkiO4VbfnKs8Oe0Wq3VQGcE1mGE4WjzOAzGA1fSDFC+z9WKMBVQRO7BP6Smc88F mqIx4gsLImFbG9jv5umzWEV8Wxv7MeAc849qV4h0EtDPOWplkyzX6cjKVosTFBlk99FhA/ dDt5BtwXGC9Y1N636j7fB8Xi9Pf/Pyg= X-MC-Unique: bT7oymGEMuCOyrxl3Ru3jg-1 X-Mimecast-MFC-AGG-ID: bT7oymGEMuCOyrxl3Ru3jg From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 06/15] block: Fix crash on block_resize on inactive node Date: Thu, 30 Jan 2025 18:12:37 +0100 Message-ID: <20250130171240.286878-7-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738257326549019000 Content-Type: text/plain; charset="utf-8" In order for block_resize to fail gracefully on an inactive node instead of crashing with an assertion failure in bdrv_co_write_req_prepare() (called from bdrv_co_truncate()), we need to check for inactive nodes also when they are attached as a root node and make sure that BLK_PERM_RESIZE isn't among the permissions allowed for inactive nodes. To this effect, don't enumerate the permissions that are incompatible with inactive nodes any more, but allow only BLK_PERM_CONSISTENT_READ for them. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block.c | 7 +++++++ block/block-backend.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index be6b71c314..fa6198bca3 100644 --- a/block.c +++ b/block.c @@ -3077,6 +3077,13 @@ bdrv_attach_child_common(BlockDriverState *child_bs, assert(child_class->get_parent_desc); GLOBAL_STATE_CODE(); =20 + if (bdrv_is_inactive(child_bs) && (perm & ~BLK_PERM_CONSISTENT_READ)) { + g_autofree char *perm_names =3D bdrv_perm_names(perm); + error_setg(errp, "Permission '%s' unavailable on inactive node", + perm_names); + return NULL; + } + new_child =3D g_new(BdrvChild, 1); *new_child =3D (BdrvChild) { .bs =3D NULL, diff --git a/block/block-backend.c b/block/block-backend.c index d093f01f89..cc6f58ae78 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -253,7 +253,7 @@ static bool blk_can_inactivate(BlockBackend *blk) * guest. For block job BBs that satisfy this, we can just allow * it. This is the case for mirror job source, which is required * by libvirt non-shared block migration. */ - if (!(blk->perm & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED))) { + if (!(blk->perm & ~BLK_PERM_CONSISTENT_READ)) { return true; } =20 --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738257281; cv=none; d=zohomail.com; s=zohoarc; b=jAN7xY71IGeeSj/Op1Z3f7SB6M1+rZMjUQSHqT9o2i5eRhsiSRmyH2wblIpeCYorXqVquZq6CnI4MnrBgf7eny7rQNTYWSBgU8dcnTsAAYpAi1QWMNnpOui6Vm7kyS+HEV146vBlgcU47ewGeIHN6Jsvc5Tm6hBRr61BA9ncHjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738257281; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MGyGwm7yKnpQ/lYdW8A4CneUsm3hKjEqfRfyc+9vUhY=; b=exay82hfG4rtTTWfnnZgwnZK3EFtFWkPq88cz4PL1PwEZcnPrmvmCXoLm/I6hQZ7NPmWyPjfO9swToKk/TGYDy+BTMIAcDzLlumGcuH+DMc1LgVHzXWhKi5Q0P0GIikrzfm6hfhRFrs87oB78Y7SJmN1qGE0X3CTV3waTCGTwfY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738257281401974.2899846834094; Thu, 30 Jan 2025 09:14:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdY6R-0000gJ-TE; Thu, 30 Jan 2025 12:13:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6O-0000ff-Qo for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6N-0003DX-6W for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:16 -0500 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-2HPXZCM_OzWDZc4_t8jOYw-1; Thu, 30 Jan 2025 12:13:11 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1104D19560A3; Thu, 30 Jan 2025 17:13:10 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.13]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 62CEF30001BE; Thu, 30 Jan 2025 17:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738257194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MGyGwm7yKnpQ/lYdW8A4CneUsm3hKjEqfRfyc+9vUhY=; b=Nrz7DcG2PLL7IW/yDvgklGV07+2r9HDmVo3E84rKdPOwEGNhZr8n6ju70LRvTJy5MgHx3g 5hh3XJuvV0bXElJz0RdWzGz8ERzXcuOJzgCLqz6FgFlqjnPxzJQRVoFpEnsuLelb+Du+G0 3qalilYxKNGdwhuhzdRKgDg2rbbufVM= X-MC-Unique: 2HPXZCM_OzWDZc4_t8jOYw-1 X-Mimecast-MFC-AGG-ID: 2HPXZCM_OzWDZc4_t8jOYw From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 07/15] block: Add option to create inactive nodes Date: Thu, 30 Jan 2025 18:12:38 +0100 Message-ID: <20250130171240.286878-8-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738257282302019000 Content-Type: text/plain; charset="utf-8" In QEMU, nodes are automatically created inactive while expecting an incoming migration (i.e. RUN_STATE_INMIGRATE). In qemu-storage-daemon, the notion of runstates doesn't exist. It also wouldn't necessarily make sense to introduce it because a single daemon can serve multiple VMs that can be in different states. Therefore, allow the user to explicitly open images as inactive with a new option. The default is as before: Nodes are usually active, except when created during RUN_STATE_INMIGRATE. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- qapi/block-core.json | 6 ++++++ include/block/block-common.h | 1 + block.c | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index 1296ca8ae2..6029e54889 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4683,6 +4683,11 @@ # # @cache: cache-related options # +# @active: whether the block node should be activated (default: true). +# Having inactive block nodes is useful primarily for migration becaus= e it +# allows opening an image on the destination while the source is still +# holding locks for it. (Since 10.0) +# # @read-only: whether the block device should be read-only (default: # false). Note that some block drivers support only read-only # access, either generally or in certain configurations. In this @@ -4709,6 +4714,7 @@ '*node-name': 'str', '*discard': 'BlockdevDiscardOptions', '*cache': 'BlockdevCacheOptions', + '*active': 'bool', '*read-only': 'bool', '*auto-read-only': 'bool', '*force-share': 'bool', diff --git a/include/block/block-common.h b/include/block/block-common.h index 338fe5ff7a..7030669f04 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -257,6 +257,7 @@ typedef enum { #define BDRV_OPT_AUTO_READ_ONLY "auto-read-only" #define BDRV_OPT_DISCARD "discard" #define BDRV_OPT_FORCE_SHARE "force-share" +#define BDRV_OPT_ACTIVE "active" =20 =20 #define BDRV_SECTOR_BITS 9 diff --git a/block.c b/block.c index fa6198bca3..95bde42dda 100644 --- a/block.c +++ b/block.c @@ -1573,6 +1573,10 @@ static void update_flags_from_options(int *flags, Qe= muOpts *opts) if (qemu_opt_get_bool_del(opts, BDRV_OPT_AUTO_READ_ONLY, false)) { *flags |=3D BDRV_O_AUTO_RDONLY; } + + if (!qemu_opt_get_bool_del(opts, BDRV_OPT_ACTIVE, true)) { + *flags |=3D BDRV_O_INACTIVE; + } } =20 static void update_options_from_flags(QDict *options, int flags) @@ -1799,6 +1803,11 @@ QemuOptsList bdrv_runtime_opts =3D { .type =3D QEMU_OPT_BOOL, .help =3D "Ignore flush requests", }, + { + .name =3D BDRV_OPT_ACTIVE, + .type =3D QEMU_OPT_BOOL, + .help =3D "Node is activated", + }, { .name =3D BDRV_OPT_READ_ONLY, .type =3D QEMU_OPT_BOOL, --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738257373; cv=none; d=zohomail.com; s=zohoarc; b=GyijamWEQP1ILnvb+wYKtgn31IgNfJmXiCYrgYiaGKdyBx9n5hsv8xBcC999JEE/762simks0RNoUlXJ+lL8hYNgazg1Xf3AGht6vZ0uv8ui6rkqgkeLHvVzFJlZWX5QI+JNwNVC7hQc8awgfRbTIp+zIJPV0FA+wBxQaKhU3gs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738257373; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XQhdlUIorhc+WfYLeEcO868bG+6tcHgkeJ1XmARqtxw=; b=XIlLT92evDOZ2TdbuF4VkWnO+XaKUfAjc3FeM6MeVMJgJfu42LIWxlcnhFlv/R5at0fWL6T7k7N76gyaJS0u165gR1EMUae2dLhWI9smcEc21eWoM0HqvrZUmwxmq+OXLVgegv27wUi+uJSsd+uw1tIrRDZmFxHF7UPX3JvMwY0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738257373906281.95260949548526; Thu, 30 Jan 2025 09:16:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdY6b-0000kC-Op; Thu, 30 Jan 2025 12:13:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6Q-0000fw-CR for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6O-0003Dd-2P for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:18 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-qNgbe4o7MOqzLwAtCeboVw-1; Thu, 30 Jan 2025 12:13:13 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F331E180035F; Thu, 30 Jan 2025 17:13:12 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.13]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7B81A30001BE; Thu, 30 Jan 2025 17:13:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738257195; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XQhdlUIorhc+WfYLeEcO868bG+6tcHgkeJ1XmARqtxw=; b=C2Lt9eRWC0wyiQ3fsFxHhAprXit6cT3zcGsT1hw6DBMvWyR2ak2YqJYl/UGira4mvmkL0A iJX+xOf5HSGmpzU7aFmI5rQkCLfCIaZPp/tdwiMhe8GXmxEShn7ekzjLWk00hVWKM5csc+ o7ON0cnn+mhHQZ5+6jgxdvo3E16EUmU= X-MC-Unique: qNgbe4o7MOqzLwAtCeboVw-1 X-Mimecast-MFC-AGG-ID: qNgbe4o7MOqzLwAtCeboVw From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 08/15] block: Add blockdev-set-active QMP command Date: Thu, 30 Jan 2025 18:12:39 +0100 Message-ID: <20250130171240.286878-9-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738257375088019000 Content-Type: text/plain; charset="utf-8" The system emulator tries to automatically activate and inactivate block nodes at the right point during migration. However, there are still cases where it's necessary that the user can do this manually. Images are only activated on the destination VM of a migration when the VM is actually resumed. If the VM was paused, this doesn't happen automatically. The user may want to perform some operation on a block device (e.g. taking a snapshot or starting a block job) without also resuming the VM yet. This is an example where a manual command is necessary. Another example is VM migration when the image files are opened by an external qemu-storage-daemon instance on each side. In this case, the process that needs to hand over the images isn't even part of the migration and can't know when the migration completes. Management tools need a way to explicitly inactivate images on the source and activate them on the destination. This adds a new blockdev-set-active QMP command that lets the user change the status of individual nodes (this is necessary in qemu-storage-daemon because it could be serving multiple VMs and only one of them migrates at a time). For convenience, operating on all devices (like QEMU does automatically during migration) is offered as an option, too, and can be used in the context of single VM. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- qapi/block-core.json | 32 ++++++++++++++++++++++++++++++ include/block/block-global-state.h | 3 +++ block.c | 21 ++++++++++++++++++++ blockdev.c | 32 ++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index 6029e54889..2ffb2efbc7 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4945,6 +4945,38 @@ { 'command': 'blockdev-del', 'data': { 'node-name': 'str' }, 'allow-preconfig': true } =20 +## +# @blockdev-set-active: +# +# Activate or inactive a block device. Use this to manage the handover of = block +# devices on migration with qemu-storage-daemon. +# +# Activating a node automatically activates all of its child nodes first. +# Inactivating a node automatically inactivates any of its child nodes tha= t are +# not in use by a still active node. +# +# @node-name: Name of the graph node to activate or inactivate. By default= , all +# nodes are affected by the operation. +# +# @active: true if the nodes should be active when the command returns suc= cess, +# false if they should be inactive. +# +# Since: 10.0 +# +# .. qmp-example:: +# +# -> { "execute": "blockdev-set-active", +# "arguments": { +# "node-name": "node0", +# "active": false +# } +# } +# <- { "return": {} } +## +{ 'command': 'blockdev-set-active', + 'data': { '*node-name': 'str', 'active': 'bool' }, + 'allow-preconfig': true } + ## # @BlockdevCreateOptionsFile: # diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index bd7cecd1cf..22ec21117d 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -181,6 +181,9 @@ bdrv_activate(BlockDriverState *bs, Error **errp); int coroutine_fn no_co_wrapper_bdrv_rdlock bdrv_co_activate(BlockDriverState *bs, Error **errp); =20 +int no_coroutine_fn +bdrv_inactivate(BlockDriverState *bs, Error **errp); + void bdrv_activate_all(Error **errp); int bdrv_inactivate_all(void); =20 diff --git a/block.c b/block.c index 95bde42dda..61e131e71f 100644 --- a/block.c +++ b/block.c @@ -7048,6 +7048,27 @@ bdrv_inactivate_recurse(BlockDriverState *bs, bool t= op_level) return 0; } =20 +int bdrv_inactivate(BlockDriverState *bs, Error **errp) +{ + int ret; + + GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD_MAINLOOP(); + + if (bdrv_has_bds_parent(bs, true)) { + error_setg(errp, "Node has active parent node"); + return -EPERM; + } + + ret =3D bdrv_inactivate_recurse(bs, true); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to inactivate node"); + return ret; + } + + return 0; +} + int bdrv_inactivate_all(void) { BlockDriverState *bs =3D NULL; diff --git a/blockdev.c b/blockdev.c index eb2517f1dd..7e0d433712 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3471,6 +3471,38 @@ void qmp_blockdev_del(const char *node_name, Error *= *errp) bdrv_unref(bs); } =20 +void qmp_blockdev_set_active(const char *node_name, bool active, Error **e= rrp) +{ + int ret; + + GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD_MAINLOOP(); + + if (!node_name) { + if (active) { + bdrv_activate_all(errp); + } else { + ret =3D bdrv_inactivate_all(); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to inactivate all nod= es"); + } + } + } else { + BlockDriverState *bs =3D bdrv_find_node(node_name); + if (!bs) { + error_setg(errp, "Failed to find node with node-name=3D'%s'", + node_name); + return; + } + + if (active) { + bdrv_activate(bs, errp); + } else { + bdrv_inactivate(bs, errp); + } + } +} + static BdrvChild * GRAPH_RDLOCK bdrv_find_child(BlockDriverState *parent_bs, const char *child_name) { --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738257392; cv=none; d=zohomail.com; s=zohoarc; b=GRncL1pQjEky8vOxGkYgxxUNQFxhcNWy5W683hMKCcEMAiPIK2Q5JroyfmDtjgvtlLkW/ykm8AumybOnx0NBpnP4uwqOK6CiFVEHXqEIdtivqgfPSXyKtESeQC+a2aX3Pr4sZKETTPzxyrDZ8lbIcC3IbQ6rrYhoKOexGZzswns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738257392; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dk2VJkbp/ESsuXG+uATmLQktP5CdnzP9cX78wLplU4E=; b=THHZuAcrpuoJ5sqXsV7f3jhIC3/GO1Tf7gvS4TSt5bJFDG9Yw5oTeSVUIDFvZ0acCNJh/nmb4ddImtc58R6LRHRLU49q7LtHZQck0am2qqs0iGmIDOehtRZXVuopz2CpPO54rnDm16lR5QQQYfiUYi0cCgeerODcf3C4ygAYVrU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738257392785991.927065679382; Thu, 30 Jan 2025 09:16:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdY6d-0000lu-FQ; Thu, 30 Jan 2025 12:13:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6Y-0000jG-AC for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdY6V-0003G2-3Z for qemu-devel@nongnu.org; Thu, 30 Jan 2025 12:13:26 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-68-vd9MIpHANNSgWtEdsRYP_g-1; Thu, 30 Jan 2025 12:13:17 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D61A918009F5; Thu, 30 Jan 2025 17:13:15 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.13]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 691293003FD1; Thu, 30 Jan 2025 17:13:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738257200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dk2VJkbp/ESsuXG+uATmLQktP5CdnzP9cX78wLplU4E=; b=YV4OqDgMhY+sRrWDJoVKBp31KU8wsMjs4sugax0pl/md0WvaLqhglRdjUquuvW35NUW3ue XTahcxaSUnDYGLUkFCFiNZeCNg1QvdcvFNdg9/4p6YdGf1r6oHDnJyHfESpH7B7CvSr4+/ lDCFOnI87oJSnVjLc1YBjEkZff0EMWg= X-MC-Unique: vd9MIpHANNSgWtEdsRYP_g-1 X-Mimecast-MFC-AGG-ID: vd9MIpHANNSgWtEdsRYP_g From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 09/15] block: Support inactive nodes in blk_insert_bs() Date: Thu, 30 Jan 2025 18:12:40 +0100 Message-ID: <20250130171240.286878-10-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738257393034019000 Content-Type: text/plain; charset="utf-8" Device models have a relatively complex way to set up their block backends, in which blk_attach_dev() sets blk->disable_perm =3D true. We want to support inactive images in exports, too, so that qemu-storage-daemon can be used with migration. Because they don't use blk_attach_dev(), they need another way to set this flag. The most convenient is to do this automatically when an inactive node is attached to a BlockBackend that can be inactivated. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/block-backend.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index cc6f58ae78..9288f7e1c6 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -900,14 +900,24 @@ void blk_remove_bs(BlockBackend *blk) int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) { ThrottleGroupMember *tgm =3D &blk->public.throttle_group_member; + uint64_t perm, shared_perm; =20 GLOBAL_STATE_CODE(); bdrv_ref(bs); bdrv_graph_wrlock(); + + if ((bs->open_flags & BDRV_O_INACTIVE) && blk_can_inactivate(blk)) { + blk->disable_perm =3D true; + perm =3D 0; + shared_perm =3D BLK_PERM_ALL; + } else { + perm =3D blk->perm; + shared_perm =3D blk->shared_perm; + } + blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, BDRV_CHILD_FILTERED | BDRV_CHILD_PR= IMARY, - blk->perm, blk->shared_perm, - blk, errp); + perm, shared_perm, blk, errp); bdrv_graph_wrunlock(); if (blk->root =3D=3D NULL) { return -EPERM; --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738317125; cv=none; d=zohomail.com; s=zohoarc; b=El2XtA5GkqVUc9CyHZX4cH/4MHVAIF+cJgfElYGPSccf2j0es16uNJi4izgSCwJzohTySg6EHLf6eOEPVcCSd2bYgzcVq/3PggBTXNKyvP/YRfaxWJ3GrsVlEwxSFp5Qv8ZqBC7esscpsj8kp3lejloYyrMtmTPwL+4ERFZVIX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738317125; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=h3AzVFjotzbJcbZ0UqufvYfRxr80TJWhnXEy1OHyymQ=; b=G+/ODdJ7yHH9Hq+WNKmzbXrMIvzDmrCr7c+N9UdHf8p+20pphZeDzhZSRRI8Wmaiyi0JPBdaJtoE2G9jNx7iYbMK8BzQpI8VZbCdM9xtOb0Xh/8BIPz9J1RWsRsBulUIndqM+5cO8B0I9GtUiycwCG9suegR4PH2qwl/3QlX8y8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738317125860981.8486004377129; Fri, 31 Jan 2025 01:52:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdngF-0003tT-Fh; Fri, 31 Jan 2025 04:51:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngE-0003se-AG for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngC-0002me-T1 for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:18 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-269-MQUDXGphMbOEJUBtkmj-aA-1; Fri, 31 Jan 2025 04:51:12 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7BA0E1801F1A; Fri, 31 Jan 2025 09:51:11 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.6]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7C0BD1800984; Fri, 31 Jan 2025 09:51:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738317075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h3AzVFjotzbJcbZ0UqufvYfRxr80TJWhnXEy1OHyymQ=; b=TpcVTH+Y9u6MLG7uDmKEJvqQ6G570gfBnar/snONtL8kNX4hOOsdVjvoGiR6AR4G0DOqde MNoMZrOYMwVw5LZ52LpA3jcAdhuT7Y16EJUvm49YWzihr81dccIDiZcgLx7hUpCWCqHWF9 ev+ocsGDZqFAppUvYAOciHnGveTVWYo= X-MC-Unique: MQUDXGphMbOEJUBtkmj-aA-1 X-Mimecast-MFC-AGG-ID: MQUDXGphMbOEJUBtkmj-aA From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 10/15] block/export: Don't ignore image activation error in blk_exp_add() Date: Fri, 31 Jan 2025 10:50:46 +0100 Message-ID: <20250131095051.49708-1-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738317127731019000 Content-Type: text/plain; charset="utf-8" Currently, block jobs can't handle inactive images correctly. Incoming write requests would run into assertion failures. Make sure that we return an error when creating an export can't activate the image. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/export/export.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/export/export.c b/block/export/export.c index 79c71ee245..bac42b8608 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -145,7 +145,11 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) * ctx was acquired in the caller. */ bdrv_graph_rdlock_main_loop(); - bdrv_activate(bs, NULL); + ret =3D bdrv_activate(bs, errp); + if (ret < 0) { + bdrv_graph_rdunlock_main_loop(); + goto fail; + } bdrv_graph_rdunlock_main_loop(); =20 perm =3D BLK_PERM_CONSISTENT_READ; --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738317137; cv=none; d=zohomail.com; s=zohoarc; b=eczxoS1EcD2hHOjOd5BXszpOyf5kH6p3ULAIkp57HsGbDPA6ZNgJwCIcnAygZnVSGzv0gIz6GTkxkWnfUnS3NIWE8oPCmbZA7S06Uc8NOXt9Xiex9OA/RRqrrOksl3LK3STkPi67w1MZbxrP3Iq4klr3FkiM9Ng2oPfdGL0KbKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738317137; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cP1kplkz6TyaABI+9aCePeeE4QsDrwjvH+C2S/FBxCA=; b=A+M3ry+b0n+w0t/Nq9vqkurvB26dU2fqK98XzQeFmbncPI5LWzqP5nri0NhgbdU1DwWxR2qMdqgYbhz02VucsEEErzl4OEgGNB9oKgK+ejrYcyYWUPH/Nf/wEV/ZyVbOkT24HlQmCL3yq2PLfbwOf0PfbtFjviDBqQOSA0xsDF4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173831713756857.95254850374886; Fri, 31 Jan 2025 01:52:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdngN-00045x-SA; Fri, 31 Jan 2025 04:51:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngL-000401-RU for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngJ-0002nG-Uk for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:25 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-392-3qgcPhubMliFCxvlslLaQg-1; Fri, 31 Jan 2025 04:51:20 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 74AA719560AF; Fri, 31 Jan 2025 09:51:19 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.6]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E27E61800975; Fri, 31 Jan 2025 09:51:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738317082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cP1kplkz6TyaABI+9aCePeeE4QsDrwjvH+C2S/FBxCA=; b=Xqd1Qwkb3hrdb575qMf7wep551v+xrd9pZXcoCNts1pc5iA2b11JxwXChHcALVO6xMfIqW Ez5i+fltCzuDZm3/2i97AqjXeEMhY73Q9OYl0fwmxBlhRGqI1kqm7st+oR5zXrv2r2STw+ SzahPOThOmfzf6XGzszuWTky4W7zha8= X-MC-Unique: 3qgcPhubMliFCxvlslLaQg-1 X-Mimecast-MFC-AGG-ID: 3qgcPhubMliFCxvlslLaQg From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 11/15] block/export: Add option to allow export of inactive nodes Date: Fri, 31 Jan 2025 10:50:47 +0100 Message-ID: <20250131095051.49708-2-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738317139849019000 Content-Type: text/plain; charset="utf-8" Add an option in BlockExportOptions to allow creating an export on an inactive node without activating the node. This mode needs to be explicitly supported by the export type (so that it doesn't perform any operations that are forbidden for inactive nodes), so this patch alone doesn't allow this option to be successfully used yet. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- qapi/block-export.json | 10 +++++++++- include/block/block-global-state.h | 3 +++ include/block/export.h | 3 +++ block.c | 4 ++++ block/export/export.c | 31 ++++++++++++++++++++---------- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index ce33fe378d..117b05d13c 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -372,6 +372,13 @@ # cannot be moved to the iothread. The default is false. # (since: 5.2) # +# @allow-inactive: If true, the export allows the exported node to be inac= tive. +# If it is created for an inactive block node, the node remains inacti= ve. If +# the export type doesn't support running on an inactive node, an erro= r is +# returned. If false, inactive block nodes are automatically activated= before +# creating the export and trying to inactivate them later fails. +# (since: 10.0; default: false) +# # Since: 4.2 ## { 'union': 'BlockExportOptions', @@ -381,7 +388,8 @@ '*iothread': 'str', 'node-name': 'str', '*writable': 'bool', - '*writethrough': 'bool' }, + '*writethrough': 'bool', + '*allow-inactive': 'bool' }, 'discriminator': 'type', 'data': { 'nbd': 'BlockExportOptionsNbd', diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 22ec21117d..9be34b3c99 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -175,6 +175,9 @@ BlockDriverState * GRAPH_RDLOCK check_to_replace_node(BlockDriverState *parent_bs, const char *node_name, Error **errp); =20 + +bool GRAPH_RDLOCK bdrv_is_inactive(BlockDriverState *bs); + int no_coroutine_fn GRAPH_RDLOCK bdrv_activate(BlockDriverState *bs, Error **errp); =20 diff --git a/include/block/export.h b/include/block/export.h index f2fe0f8078..4bd9531d4d 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -29,6 +29,9 @@ typedef struct BlockExportDriver { */ size_t instance_size; =20 + /* True if the export type supports running on an inactive node */ + bool supports_inactive; + /* Creates and starts a new block export */ int (*create)(BlockExport *, BlockExportOptions *, Error **); =20 diff --git a/block.c b/block.c index 61e131e71f..7eeb8d076e 100644 --- a/block.c +++ b/block.c @@ -6845,6 +6845,10 @@ void bdrv_init_with_whitelist(void) bdrv_init(); } =20 +bool bdrv_is_inactive(BlockDriverState *bs) { + return bs->open_flags & BDRV_O_INACTIVE; +} + int bdrv_activate(BlockDriverState *bs, Error **errp) { BdrvChild *child, *parent; diff --git a/block/export/export.c b/block/export/export.c index bac42b8608..f3bbf11070 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -75,6 +75,7 @@ static const BlockExportDriver *blk_exp_find_driver(Block= ExportType type) BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { bool fixed_iothread =3D export->has_fixed_iothread && export->fixed_io= thread; + bool allow_inactive =3D export->has_allow_inactive && export->allow_in= active; const BlockExportDriver *drv; BlockExport *exp =3D NULL; BlockDriverState *bs; @@ -138,17 +139,24 @@ BlockExport *blk_exp_add(BlockExportOptions *export, = Error **errp) } } =20 - /* - * Block exports are used for non-shared storage migration. Make sure - * that BDRV_O_INACTIVE is cleared and the image is ready for write - * access since the export could be available before migration handove= r. - * ctx was acquired in the caller. - */ bdrv_graph_rdlock_main_loop(); - ret =3D bdrv_activate(bs, errp); - if (ret < 0) { - bdrv_graph_rdunlock_main_loop(); - goto fail; + if (allow_inactive) { + if (!drv->supports_inactive) { + error_setg(errp, "Export type does not support inactive export= s"); + bdrv_graph_rdunlock_main_loop(); + goto fail; + } + } else { + /* + * Block exports are used for non-shared storage migration. Make s= ure + * that BDRV_O_INACTIVE is cleared and the image is ready for write + * access since the export could be available before migration han= dover. + */ + ret =3D bdrv_activate(bs, errp); + if (ret < 0) { + bdrv_graph_rdunlock_main_loop(); + goto fail; + } } bdrv_graph_rdunlock_main_loop(); =20 @@ -162,6 +170,9 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) if (!fixed_iothread) { blk_set_allow_aio_context_change(blk, true); } + if (allow_inactive) { + blk_set_force_allow_inactivate(blk); + } =20 ret =3D blk_insert_bs(blk, bs, errp); if (ret < 0) { --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738317125; cv=none; d=zohomail.com; s=zohoarc; b=Fs2qxR4CKTDgLsf0VIiAaOXUEr8BTOgwgE0ZVvdcmi8jCcIokiw6uucCyI49jS6v252WgEcpvJhahBW8LOjIl8PKCMzrHGMVK7Me8Zg30S4oRkbGvAQRDTH8WuJE0XP2ZG0hTx58jX26qtn7le1iMHd9okzTwvaOFHvvJHOlpug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738317125; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Gy0Ro0AiLBW+IDrNU0PGthGke20CO9S9gyVmcl9+x2Q=; b=D+mkmtgceoHpS1St00Zo9so0vybZXRpu9njrnDWltr7N1tcw7ccwQfU0xZ+xi3pfLmoao+RhlLLpmUNCt51ySd3ofngM7gsXqjCOEyfahuBixod10NbbBPoI4z+Te1qm3r+D2PnT04QC/2Ded4M06CHvqoNNRdYFKHF9SB3+Hd8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738317125207665.0995641561693; Fri, 31 Jan 2025 01:52:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdngQ-0004Et-5u; Fri, 31 Jan 2025 04:51:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngO-00048c-If for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngN-0002oC-9K for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:28 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-318-Y7UIwp2ePN6knLhQ6mzAZQ-1; Fri, 31 Jan 2025 04:51:23 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 356BC1801F0E; Fri, 31 Jan 2025 09:51:22 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.6]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E0F221800975; Fri, 31 Jan 2025 09:51:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738317086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gy0Ro0AiLBW+IDrNU0PGthGke20CO9S9gyVmcl9+x2Q=; b=Va9HZl7MY2nBvGZDlTeOYsk6qlQIZQoL4bi/ruqNzFp3gpzFVaH3hJCLELMRUgUp5SEuU2 BR73JEJ0OJRhm6BHR6WF3xxqEpf8x2suGIlhYcbW8dc5gczIAdtR8rosZq5LPytoWPNE1U yMqSBx2e0HnKR2CPfNhuPkr9gAoJjLE= X-MC-Unique: Y7UIwp2ePN6knLhQ6mzAZQ-1 X-Mimecast-MFC-AGG-ID: Y7UIwp2ePN6knLhQ6mzAZQ From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 12/15] nbd/server: Support inactive nodes Date: Fri, 31 Jan 2025 10:50:48 +0100 Message-ID: <20250131095051.49708-3-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738317128725019000 Content-Type: text/plain; charset="utf-8" In order to support running an NBD export on inactive nodes, we must make sure to return errors for any operations that aren't allowed on inactive nodes. Reads are the only operation we know we need for inactive images, so to err on the side of caution, return errors for everything else, even if some operations could possibly be okay. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake --- nbd/server.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/nbd/server.c b/nbd/server.c index f64e47270c..2076fb2666 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2026,6 +2026,7 @@ static void nbd_export_delete(BlockExport *blk_exp) const BlockExportDriver blk_exp_nbd =3D { .type =3D BLOCK_EXPORT_TYPE_NBD, .instance_size =3D sizeof(NBDExport), + .supports_inactive =3D true, .create =3D nbd_export_create, .delete =3D nbd_export_delete, .request_shutdown =3D nbd_export_request_shutdown, @@ -2920,6 +2921,22 @@ static coroutine_fn int nbd_handle_request(NBDClient= *client, NBDExport *exp =3D client->exp; char *msg; size_t i; + bool inactive; + + WITH_GRAPH_RDLOCK_GUARD() { + inactive =3D bdrv_is_inactive(blk_bs(exp->common.blk)); + if (inactive) { + switch (request->type) { + case NBD_CMD_READ: + /* These commands are allowed on inactive nodes */ + break; + default: + /* Return an error for the rest */ + return nbd_send_generic_reply(client, request, -EPERM, + "export is inactive", errp); + } + } + } =20 switch (request->type) { case NBD_CMD_CACHE: --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738317133; cv=none; d=zohomail.com; s=zohoarc; b=nJ5ZeG+hN8FmCwd0X51MvkiV8mOfkpLRFa6tPiEbtOKKz/JJtEIbxNwGta4V1KoA197GQf0q8Mf23WIu6WbIIdH6lsSX7+UQRCDqlrW3Uw/sBDctaT8xR//yj+9h0Pbhkgb5vH+Vr4t1woSxnFf9EvmY0K/4L7gC4FY/HnFX6+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738317133; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DkCHPTSgu46sKfQlR+iwsxq9+VZrqAq4gn91UtuoshE=; b=UJRiruXac/RQdmEg06w1dp/YlO6cCID2vyF6ybDqqb8cLH6ifAfaa4ym7OljqcpZgva793FyiyEnBC+HnIgfa2O7hzpQ+7iyw780t/G5VDaYbzcnMGrSg7lu856nt9XGsyjpDYx9IHPiX32qLxTqfaJpTbePZyiEdpv8Z6M5Ldc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173831713393525.56450338126774; Fri, 31 Jan 2025 01:52:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdngV-0004Po-9k; Fri, 31 Jan 2025 04:51:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngT-0004Nl-7d for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngR-0002oi-M5 for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:32 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-279-KySP6KshOSiOOXJ9yIg8Qw-1; Fri, 31 Jan 2025 04:51:26 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 006D11801F10; Fri, 31 Jan 2025 09:51:26 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.6]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A1C81180098C; Fri, 31 Jan 2025 09:51:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738317090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DkCHPTSgu46sKfQlR+iwsxq9+VZrqAq4gn91UtuoshE=; b=Gjttsxf218U1Q6l57aIy7Q4EO8DvE3kEXlTkjNrO5QGxDqr/FBThnN7ZEP6UtppZPiozXR 1aQa1jzZ1YpOoIDhGhk3/aTD4hfNSfbvsVv69Jr+9zfKYmVp1dTgkVym1SnkYTGunPay8d d1BPeg8YncvBL7mf3OyAvDfpKHoWSgA= X-MC-Unique: KySP6KshOSiOOXJ9yIg8Qw-1 X-Mimecast-MFC-AGG-ID: KySP6KshOSiOOXJ9yIg8Qw From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 13/15] iotests: Add filter_qtest() Date: Fri, 31 Jan 2025 10:50:49 +0100 Message-ID: <20250131095051.49708-4-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738317136018019000 Content-Type: text/plain; charset="utf-8" The open-coded form of this filter has been copied into enough tests that it's better to move it into iotests.py. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake --- tests/qemu-iotests/iotests.py | 4 ++++ tests/qemu-iotests/041 | 4 +--- tests/qemu-iotests/165 | 4 +--- tests/qemu-iotests/tests/copy-before-write | 3 +-- tests/qemu-iotests/tests/migrate-bitmaps-test | 7 +++---- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 19817c7353..9c9c908983 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -701,6 +701,10 @@ def _filter(_key, value): def filter_nbd_exports(output: str) -> str: return re.sub(r'((min|opt|max) block): [0-9]+', r'\1: XXX', output) =20 +def filter_qtest(output: str) -> str: + output =3D re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', output) + output =3D re.sub(r'\n?\[I \+\d+\.\d+\] CLOSED\n?$', '', output) + return output =20 Msg =3D TypeVar('Msg', Dict[str, Any], List[Any], str) =20 diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 98d17b1388..8452845f44 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1100,10 +1100,8 @@ class TestRepairQuorum(iotests.QMPTestCase): =20 # Check the full error message now self.vm.shutdown() - log =3D self.vm.get_log() - log =3D re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) + log =3D iotests.filter_qtest(self.vm.get_log()) log =3D re.sub(r'^Formatting.*\n', '', log) - log =3D re.sub(r'\n\[I \+\d+\.\d+\] CLOSED\n?$', '', log) log =3D re.sub(r'^%s: ' % os.path.basename(iotests.qemu_prog), '',= log) =20 self.assertEqual(log, diff --git a/tests/qemu-iotests/165 b/tests/qemu-iotests/165 index b24907a62f..b3b1709d71 100755 --- a/tests/qemu-iotests/165 +++ b/tests/qemu-iotests/165 @@ -82,9 +82,7 @@ class TestPersistentDirtyBitmap(iotests.QMPTestCase): self.vm.shutdown() =20 #catch 'Persistent bitmaps are lost' possible error - log =3D self.vm.get_log() - log =3D re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) - log =3D re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + log =3D iotests.filter_qtest(self.vm.get_log()) if log: print(log) =20 diff --git a/tests/qemu-iotests/tests/copy-before-write b/tests/qemu-iotest= s/tests/copy-before-write index d33bea577d..498c558008 100755 --- a/tests/qemu-iotests/tests/copy-before-write +++ b/tests/qemu-iotests/tests/copy-before-write @@ -95,8 +95,7 @@ class TestCbwError(iotests.QMPTestCase): =20 self.vm.shutdown() log =3D self.vm.get_log() - log =3D re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) - log =3D re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + log =3D iotests.filter_qtest(log) log =3D iotests.filter_qemu_io(log) return log =20 diff --git a/tests/qemu-iotests/tests/migrate-bitmaps-test b/tests/qemu-iot= ests/tests/migrate-bitmaps-test index f98e721e97..8fb4099201 100755 --- a/tests/qemu-iotests/tests/migrate-bitmaps-test +++ b/tests/qemu-iotests/tests/migrate-bitmaps-test @@ -122,11 +122,10 @@ class TestDirtyBitmapMigration(iotests.QMPTestCase): =20 # catch 'Could not reopen qcow2 layer: Bitmap already exists' # possible error - log =3D self.vm_a.get_log() - log =3D re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) - log =3D re.sub(r'^(wrote .* bytes at offset .*\n.*KiB.*ops.*sec.*\= n){3}', + log =3D iotests.filter_qtest(self.vm_a.get_log()) + log =3D re.sub(r'^(wrote .* bytes at offset .*\n' + r'.*KiB.*ops.*sec.*\n?){3}', '', log) - log =3D re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) self.assertEqual(log, '') =20 # test that bitmap is still persistent --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738317126; cv=none; d=zohomail.com; s=zohoarc; b=VX5D62aQdzLE+ZEYINGL+jtTXSzC/lizokaZM6lvb3KK3/JprpDquI67HQlLyObEh3aBo0t7GzaN12KuByCOBNlzVf/kel22biryyWpS6v8g1xaZgtV/CkuIPDms9TXvzAFZ5p5EtFTFxsJr0jbfjDZKzfJipXrCZR+91gDQwu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738317126; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cOcagsDq+WLooY855coOQtIiVBuj3mR4zwpM01LptH0=; b=Q9XJVOxZSunwYTEBky9Hgn5YsaicDUvlZ+QEQ2YINRfLafZAIeohnQ6GIsyhjxBFeh7unSAoXL0LUBjaaxpAyKbxFMDo98zgo7QdnzoyjLpabFwVWuF1xjihx/NMvtxFDCz10WbiEnasj4Cvylsh0ltQtGMiAYokDxBiPzreJeg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738317126063194.0615269823577; Fri, 31 Jan 2025 01:52:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdngY-0004Wu-Uz; Fri, 31 Jan 2025 04:51:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngX-0004SO-21 for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngV-0002pD-2w for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:36 -0500 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-thutYYJpNhi7DqVBEKAJRg-1; Fri, 31 Jan 2025 04:51:30 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 399451955F2D; Fri, 31 Jan 2025 09:51:29 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.6]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6B77818009A8; Fri, 31 Jan 2025 09:51:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738317093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cOcagsDq+WLooY855coOQtIiVBuj3mR4zwpM01LptH0=; b=dUSSfJhzLUPxjoDpyoQDese7flszw9Egs8dHvnP83sqKHP24ZaMrS0Ef3lipPvLug1zr6i b1x2Zvlhaube7gK1wKMoSb+3PkqnJtAH8UFLquA9lSki1ne0YVGBktXIphe/FI0aUKtBT0 ueyJY7eSSyx+sajGhUyrX7/oALuqIkw= X-MC-Unique: thutYYJpNhi7DqVBEKAJRg-1 X-Mimecast-MFC-AGG-ID: thutYYJpNhi7DqVBEKAJRg From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 14/15] iotests: Add qsd-migrate case Date: Fri, 31 Jan 2025 10:50:50 +0100 Message-ID: <20250131095051.49708-5-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738317127896019000 Content-Type: text/plain; charset="utf-8" Test that it's possible to migrate a VM that uses an image on shared storage through qemu-storage-daemon. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas Reviewed-by: Eric Blake --- tests/qemu-iotests/tests/qsd-migrate | 132 +++++++++++++++++++++++ tests/qemu-iotests/tests/qsd-migrate.out | 51 +++++++++ 2 files changed, 183 insertions(+) create mode 100755 tests/qemu-iotests/tests/qsd-migrate create mode 100644 tests/qemu-iotests/tests/qsd-migrate.out diff --git a/tests/qemu-iotests/tests/qsd-migrate b/tests/qemu-iotests/test= s/qsd-migrate new file mode 100755 index 0000000000..687bda6f93 --- /dev/null +++ b/tests/qemu-iotests/tests/qsd-migrate @@ -0,0 +1,132 @@ +#!/usr/bin/env python3 +# group: rw quick +# +# Copyright (C) Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Creator/Owner: Kevin Wolf + +import iotests + +from iotests import filter_qemu_io, filter_qtest + +iotests.script_initialize(supported_fmts=3D['generic'], + supported_protocols=3D['file'], + supported_platforms=3D['linux']) + +with iotests.FilePath('disk.img') as path, \ + iotests.FilePath('nbd-src.sock', base_dir=3Diotests.sock_dir) as nbd_= src, \ + iotests.FilePath('nbd-dst.sock', base_dir=3Diotests.sock_dir) as nbd_= dst, \ + iotests.FilePath('migrate.sock', base_dir=3Diotests.sock_dir) as mig_= sock, \ + iotests.VM(path_suffix=3D"-src") as vm_src, \ + iotests.VM(path_suffix=3D"-dst") as vm_dst: + + img_size =3D '10M' + + iotests.log('Preparing disk...') + iotests.qemu_img_create('-f', iotests.imgfmt, path, img_size) + + iotests.log('Launching source QSD...') + qsd_src =3D iotests.QemuStorageDaemon( + '--blockdev', f'file,node-name=3Ddisk-file,filename=3D{path}', + '--blockdev', f'{iotests.imgfmt},file=3Ddisk-file,node-name=3Ddisk= -fmt', + '--nbd-server', f'addr.type=3Dunix,addr.path=3D{nbd_src}', + '--export', 'nbd,id=3Dexp0,node-name=3Ddisk-fmt,writable=3Dtrue,' + 'allow-inactive=3Dtrue', + qmp=3DTrue, + ) + + iotests.log('Launching source VM...') + vm_src.add_args('-blockdev', f'nbd,node-name=3Ddisk,server.type=3Dunix= ,' + f'server.path=3D{nbd_src},export=3Ddisk-f= mt') + vm_src.add_args('-device', 'virtio-blk,drive=3Ddisk,id=3Dvirtio0') + vm_src.launch() + + iotests.log('Launching destination QSD...') + qsd_dst =3D iotests.QemuStorageDaemon( + '--blockdev', f'file,node-name=3Ddisk-file,filename=3D{path},activ= e=3Doff', + '--blockdev', f'{iotests.imgfmt},file=3Ddisk-file,node-name=3Ddisk= -fmt,' + f'active=3Doff', + '--nbd-server', f'addr.type=3Dunix,addr.path=3D{nbd_dst}', + '--export', 'nbd,id=3Dexp0,node-name=3Ddisk-fmt,writable=3Dtrue,' + 'allow-inactive=3Dtrue', + qmp=3DTrue, + instance_id=3D'b', + ) + + iotests.log('Launching destination VM...') + vm_dst.add_args('-blockdev', f'nbd,node-name=3Ddisk,server.type=3Dunix= ,' + f'server.path=3D{nbd_dst},export=3Ddisk-f= mt') + vm_dst.add_args('-device', 'virtio-blk,drive=3Ddisk,id=3Dvirtio0') + vm_dst.add_args('-incoming', f'unix:{mig_sock}') + vm_dst.launch() + + iotests.log('\nTest I/O on the source') + vm_src.hmp_qemu_io('virtio0/virtio-backend', 'write -P 0x11 0 4k', + use_log=3DTrue, qdev=3DTrue) + vm_src.hmp_qemu_io('virtio0/virtio-backend', 'read -P 0x11 0 4k', + use_log=3DTrue, qdev=3DTrue) + + iotests.log('\nStarting migration...') + + mig_caps =3D [ + {'capability': 'events', 'state': True}, + {'capability': 'pause-before-switchover', 'state': True}, + ] + vm_src.qmp_log('migrate-set-capabilities', capabilities=3Dmig_caps) + vm_dst.qmp_log('migrate-set-capabilities', capabilities=3Dmig_caps) + vm_src.qmp_log('migrate', uri=3Df'unix:{mig_sock}', + filters=3D[iotests.filter_qmp_testfiles]) + + vm_src.event_wait('MIGRATION', + match=3D{'data': {'status': 'pre-switchover'}}) + + iotests.log('\nPre-switchover: Reconfigure QSD instances') + + iotests.log(qsd_src.qmp('blockdev-set-active', {'active': False})) + iotests.log(qsd_dst.qmp('blockdev-set-active', {'active': True})) + + iotests.log('\nCompleting migration...') + + vm_src.qmp_log('migrate-continue', state=3D'pre-switchover') + vm_dst.event_wait('MIGRATION', match=3D{'data': {'status': 'completed'= }}) + + iotests.log('\nTest I/O on the destination') + + # Now the destination must see what the source wrote + vm_dst.hmp_qemu_io('virtio0/virtio-backend', 'read -P 0x11 0 4k', + use_log=3DTrue, qdev=3DTrue) + + # And be able to overwrite it + vm_dst.hmp_qemu_io('virtio0/virtio-backend', 'write -P 0x22 0 4k', + use_log=3DTrue, qdev=3DTrue) + vm_dst.hmp_qemu_io('virtio0/virtio-backend', 'read -P 0x22 0 4k', + use_log=3DTrue, qdev=3DTrue) + + iotests.log('\nDone') + + vm_src.shutdown() + iotests.log('\n--- vm_src log ---') + log =3D vm_src.get_log() + if log: + iotests.log(log, [filter_qtest, filter_qemu_io]) + qsd_src.stop() + + vm_dst.shutdown() + iotests.log('\n--- vm_dst log ---') + log =3D vm_dst.get_log() + if log: + iotests.log(log, [filter_qtest, filter_qemu_io]) + qsd_dst.stop() diff --git a/tests/qemu-iotests/tests/qsd-migrate.out b/tests/qemu-iotests/= tests/qsd-migrate.out new file mode 100644 index 0000000000..e69c19190d --- /dev/null +++ b/tests/qemu-iotests/tests/qsd-migrate.out @@ -0,0 +1,51 @@ +Preparing disk... +Launching source QSD... +Launching source VM... +Launching destination QSD... +Launching destination VM... + +Test I/O on the source +{"execute": "human-monitor-command", "arguments": {"command-line": "qemu-i= o -d virtio0/virtio-backend \"write -P 0x11 0 4k\""}} +{"return": ""} +{"execute": "human-monitor-command", "arguments": {"command-line": "qemu-i= o -d virtio0/virtio-backend \"read -P 0x11 0 4k\""}} +{"return": ""} + +Starting migration... +{"execute": "migrate-set-capabilities", "arguments": {"capabilities": [{"c= apability": "events", "state": true}, {"capability": "pause-before-switchov= er", "state": true}]}} +{"return": {}} +{"execute": "migrate-set-capabilities", "arguments": {"capabilities": [{"c= apability": "events", "state": true}, {"capability": "pause-before-switchov= er", "state": true}]}} +{"return": {}} +{"execute": "migrate", "arguments": {"uri": "unix:SOCK_DIR/PID-migrate.soc= k"}} +{"return": {}} + +Pre-switchover: Reconfigure QSD instances +{"return": {}} +{"return": {}} + +Completing migration... +{"execute": "migrate-continue", "arguments": {"state": "pre-switchover"}} +{"return": {}} + +Test I/O on the destination +{"execute": "human-monitor-command", "arguments": {"command-line": "qemu-i= o -d virtio0/virtio-backend \"read -P 0x11 0 4k\""}} +{"return": ""} +{"execute": "human-monitor-command", "arguments": {"command-line": "qemu-i= o -d virtio0/virtio-backend \"write -P 0x22 0 4k\""}} +{"return": ""} +{"execute": "human-monitor-command", "arguments": {"command-line": "qemu-i= o -d virtio0/virtio-backend \"read -P 0x22 0 4k\""}} +{"return": ""} + +Done + +--- vm_src log --- +wrote 4096/4096 bytes at offset 0 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 0 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- vm_dst log --- +read 4096/4096 bytes at offset 0 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 0 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 0 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) --=20 2.48.1 From nobody Sat Apr 5 07:15:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1738317151; cv=none; d=zohomail.com; s=zohoarc; b=iW6/A782SOjnUT4sC1blIc5leCxsIdcXrAmCxEFxpdN/fbZrhsBbtx7O/luyIVI/9ZM2+U5MlPEibpRRoivMbU6jHr09oQ/Yv+8M3FhwuJG4gfl7hifhBs5IvfpLI0TITgCErTXH8mTVCwwdxk2UM2Vh/zVYo1LFQAnFvdZEsDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738317151; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4BvpgBRGAlHZfsV7fB7YJ2Rsr2+Ztfrnn2l12bnaxrU=; b=AmzboJwOHKwtxaGMVhGC7O/mqq0EVDZuR8VkQHAeMgRAPEIxehlM4qdGkqtznhhyjGlAjxT6YTGv4Mui2UDKTZmncqDbYa7dzprGWzqGW2XgRdp3/sabAsEhcKJ7stecPBSwgME4xQIgZ+CNmTHFEIj6CtEc71dCej5mekY6rqA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1738317151638696.4735403433043; Fri, 31 Jan 2025 01:52:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdnga-0004Yn-JA; Fri, 31 Jan 2025 04:51:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngZ-0004Xj-CX for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tdngW-0002pO-5H for qemu-devel@nongnu.org; Fri, 31 Jan 2025 04:51:39 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-452-WmDDIW2jN9KpReEtgoKhCg-1; Fri, 31 Jan 2025 04:51:33 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9AED81800374; Fri, 31 Jan 2025 09:51:32 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.6]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A65821800975; Fri, 31 Jan 2025 09:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738317095; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4BvpgBRGAlHZfsV7fB7YJ2Rsr2+Ztfrnn2l12bnaxrU=; b=aiGeEik2K5hkKtTffrFjn+hzNGApISc4/BOZUs12b+6huX4qH2/480vQM0MfRCaNn3PgWv 1eA58grOkl5UjtrpdIaDPbx0sn7jd9bosU9E+Vkv/Adf3ssnlRP8O7zs+NemzRPxc2ea5L rIyOfV3AxQMKY6oY2fzaaRBjKL+ERRI= X-MC-Unique: WmDDIW2jN9KpReEtgoKhCg-1 X-Mimecast-MFC-AGG-ID: WmDDIW2jN9KpReEtgoKhCg From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, pkrempa@redhat.com, peterx@redhat.com, farosas@suse.de, qemu-devel@nongnu.org Subject: [PATCH v2 15/15] iotests: Add (NBD-based) tests for inactive nodes Date: Fri, 31 Jan 2025 10:50:51 +0100 Message-ID: <20250131095051.49708-6-kwolf@redhat.com> In-Reply-To: <20250130171240.286878-1-kwolf@redhat.com> References: <20250130171240.286878-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1738317153979019000 Content-Type: text/plain; charset="utf-8" This tests different types of operations on inactive block nodes (including graph changes, block jobs and NBD exports) to make sure that users manually activating and inactivating nodes doesn't break things. Support for inactive nodes in other export types will have to come with separate test cases because they have different dependencies like blkio or root permissions and we don't want to disable this basic test when they are not fulfilled. Signed-off-by: Kevin Wolf Acked-by: Fabiano Rosas --- tests/qemu-iotests/iotests.py | 4 + tests/qemu-iotests/tests/inactive-node-nbd | 303 ++++++++++++++++++ .../qemu-iotests/tests/inactive-node-nbd.out | 239 ++++++++++++++ 3 files changed, 546 insertions(+) create mode 100755 tests/qemu-iotests/tests/inactive-node-nbd create mode 100644 tests/qemu-iotests/tests/inactive-node-nbd.out diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 9c9c908983..7292c8b342 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -913,6 +913,10 @@ def add_incoming(self, addr): self._args.append(addr) return self =20 + def add_paused(self): + self._args.append('-S') + return self + def hmp(self, command_line: str, use_log: bool =3D False) -> QMPMessag= e: cmd =3D 'human-monitor-command' kwargs: Dict[str, Any] =3D {'command-line': command_line} diff --git a/tests/qemu-iotests/tests/inactive-node-nbd b/tests/qemu-iotest= s/tests/inactive-node-nbd new file mode 100755 index 0000000000..2279f7c1e1 --- /dev/null +++ b/tests/qemu-iotests/tests/inactive-node-nbd @@ -0,0 +1,303 @@ +#!/usr/bin/env python3 +# group: rw quick +# +# Copyright (C) Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Creator/Owner: Kevin Wolf + +import iotests + +from iotests import QemuIoInteractive +from iotests import filter_qemu_io, filter_qtest, filter_qmp_testfiles + +iotests.script_initialize(supported_fmts=3D['generic'], + supported_protocols=3D['file'], + supported_platforms=3D['linux']) + +def get_export(node_name=3D'disk-fmt', allow_inactive=3DNone): + exp =3D { + 'id': 'exp0', + 'type': 'nbd', + 'node-name': node_name, + 'writable': True, + } + + if allow_inactive is not None: + exp['allow-inactive'] =3D allow_inactive + + return exp + +def node_is_active(_vm, node_name): + nodes =3D _vm.cmd('query-named-block-nodes', flat=3DTrue) + node =3D next(n for n in nodes if n['node-name'] =3D=3D node_name) + return node['active'] + +with iotests.FilePath('disk.img') as path, \ + iotests.FilePath('snap.qcow2') as snap_path, \ + iotests.FilePath('snap2.qcow2') as snap2_path, \ + iotests.FilePath('target.img') as target_path, \ + iotests.FilePath('nbd.sock', base_dir=3Diotests.sock_dir) as nbd_sock= , \ + iotests.VM() as vm: + + img_size =3D '10M' + + iotests.log('Preparing disk...') + iotests.qemu_img_create('-f', iotests.imgfmt, path, img_size) + iotests.qemu_img_create('-f', iotests.imgfmt, target_path, img_size) + + iotests.qemu_img_create('-f', 'qcow2', '-b', path, '-F', iotests.imgfm= t, + snap_path) + iotests.qemu_img_create('-f', 'qcow2', '-b', snap_path, '-F', 'qcow2', + snap2_path) + + iotests.log('Launching VM...') + vm.add_blockdev(f'file,node-name=3Ddisk-file,filename=3D{path}') + vm.add_blockdev(f'{iotests.imgfmt},file=3Ddisk-file,node-name=3Ddisk-f= mt,' + 'active=3Doff') + vm.add_blockdev(f'file,node-name=3Dtarget-file,filename=3D{target_path= }') + vm.add_blockdev(f'{iotests.imgfmt},file=3Dtarget-file,node-name=3Dtarg= et-fmt') + vm.add_blockdev(f'file,node-name=3Dsnap-file,filename=3D{snap_path}') + vm.add_blockdev(f'file,node-name=3Dsnap2-file,filename=3D{snap2_path}') + + # Actually running the VM activates all images + vm.add_paused() + + vm.launch() + vm.qmp_log('nbd-server-start', + addr=3D{'type': 'unix', 'data':{'path': nbd_sock}}, + filters=3D[filter_qmp_testfiles]) + + iotests.log('\n=3D=3D=3D Creating export of inactive node =3D=3D=3D') + + iotests.log('\nExports activate nodes without allow-inactive') + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + vm.qmp_log('block-export-add', **get_export()) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + vm.qmp_log('query-block-exports') + vm.qmp_log('block-export-del', id=3D'exp0') + vm.event_wait('BLOCK_EXPORT_DELETED') + vm.qmp_log('query-block-exports') + + iotests.log('\nExports activate nodes with allow-inactive=3Dfalse') + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DFal= se) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + vm.qmp_log('block-export-add', **get_export(allow_inactive=3DFalse)) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + vm.qmp_log('query-block-exports') + vm.qmp_log('block-export-del', id=3D'exp0') + vm.event_wait('BLOCK_EXPORT_DELETED') + vm.qmp_log('query-block-exports') + + iotests.log('\nExport leaves nodes inactive with allow-inactive=3Dtrue= ') + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DFal= se) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + vm.qmp_log('block-export-add', **get_export(allow_inactive=3DTrue)) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + vm.qmp_log('query-block-exports') + vm.qmp_log('block-export-del', id=3D'exp0') + vm.event_wait('BLOCK_EXPORT_DELETED') + vm.qmp_log('query-block-exports') + + iotests.log('\n=3D=3D=3D Inactivating node with existing export =3D=3D= =3D') + + iotests.log('\nInactivating nodes with an export fails without ' + 'allow-inactive') + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DTru= e) + vm.qmp_log('block-export-add', **get_export(node_name=3D'disk-fmt')) + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DFal= se) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + vm.qmp_log('query-block-exports') + vm.qmp_log('block-export-del', id=3D'exp0') + vm.event_wait('BLOCK_EXPORT_DELETED') + vm.qmp_log('query-block-exports') + + iotests.log('\nInactivating nodes with an export fails with ' + 'allow-inactive=3Dfalse') + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DTru= e) + vm.qmp_log('block-export-add', + **get_export(node_name=3D'disk-fmt', allow_inactive=3DFalse= )) + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DFal= se) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + vm.qmp_log('query-block-exports') + vm.qmp_log('block-export-del', id=3D'exp0') + vm.event_wait('BLOCK_EXPORT_DELETED') + vm.qmp_log('query-block-exports') + + iotests.log('\nInactivating nodes with an export works with ' + 'allow-inactive=3Dtrue') + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DTru= e) + vm.qmp_log('block-export-add', + **get_export(node_name=3D'disk-fmt', allow_inactive=3DTrue)) + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DFal= se) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + vm.qmp_log('query-block-exports') + vm.qmp_log('block-export-del', id=3D'exp0') + vm.event_wait('BLOCK_EXPORT_DELETED') + vm.qmp_log('query-block-exports') + + iotests.log('\n=3D=3D=3D Inactive nodes with parent =3D=3D=3D') + + iotests.log('\nInactivating nodes with an active parent fails') + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DTru= e) + vm.qmp_log('blockdev-set-active', node_name=3D'disk-file', active=3DFa= lse) + iotests.log('disk-file active: %s' % node_is_active(vm, 'disk-file')) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + + iotests.log('\nInactivating nodes with an inactive parent works') + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DFal= se) + vm.qmp_log('blockdev-set-active', node_name=3D'disk-file', active=3DFa= lse) + iotests.log('disk-file active: %s' % node_is_active(vm, 'disk-file')) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + + iotests.log('\nCreating active parent node with an inactive child fail= s') + vm.qmp_log('blockdev-add', driver=3D'raw', file=3D'disk-fmt', + node_name=3D'disk-filter') + vm.qmp_log('blockdev-add', driver=3D'raw', file=3D'disk-fmt', + node_name=3D'disk-filter', active=3DTrue) + + iotests.log('\nCreating inactive parent node with an inactive child wo= rks') + vm.qmp_log('blockdev-add', driver=3D'raw', file=3D'disk-fmt', + node_name=3D'disk-filter', active=3DFalse) + vm.qmp_log('blockdev-del', node_name=3D'disk-filter') + + iotests.log('\n=3D=3D=3D Resizing an inactive node =3D=3D=3D') + vm.qmp_log('block_resize', node_name=3D'disk-fmt', size=3D16*1024*1024) + + iotests.log('\n=3D=3D=3D Taking a snapshot of an inactive node =3D=3D= =3D') + + iotests.log('\nActive overlay over inactive backing file automatically= ' + 'makes both inactive for compatibility') + vm.qmp_log('blockdev-add', driver=3D'qcow2', node_name=3D'snap-fmt', + file=3D'snap-file', backing=3DNone) + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + iotests.log('snap-fmt active: %s' % node_is_active(vm, 'snap-fmt')) + vm.qmp_log('blockdev-snapshot', node=3D'disk-fmt', overlay=3D'snap-fmt= ') + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + iotests.log('snap-fmt active: %s' % node_is_active(vm, 'snap-fmt')) + vm.qmp_log('blockdev-del', node_name=3D'snap-fmt') + + iotests.log('\nInactive overlay over inactive backing file just works') + vm.qmp_log('blockdev-add', driver=3D'qcow2', node_name=3D'snap-fmt', + file=3D'snap-file', backing=3DNone, active=3DFalse) + vm.qmp_log('blockdev-snapshot', node=3D'disk-fmt', overlay=3D'snap-fmt= ') + + iotests.log('\n=3D=3D=3D Block jobs with inactive nodes =3D=3D=3D') + + iotests.log('\nStreaming into an inactive node') + vm.qmp_log('block-stream', device=3D'snap-fmt', + filters=3D[iotests.filter_qmp_generated_node_ids]) + + iotests.log('\nCommitting an inactive root node (active commit)') + vm.qmp_log('block-commit', job_id=3D'job0', device=3D'snap-fmt', + filters=3D[iotests.filter_qmp_generated_node_ids]) + + iotests.log('\nCommitting an inactive intermediate node to inactive ba= se') + vm.qmp_log('blockdev-add', driver=3D'qcow2', node_name=3D'snap2-fmt', + file=3D'snap2-file', backing=3D'snap-fmt', active=3DFalse) + + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + iotests.log('snap-fmt active: %s' % node_is_active(vm, 'snap-fmt')) + iotests.log('snap2-fmt active: %s' % node_is_active(vm, 'snap2-fmt')) + + vm.qmp_log('block-commit', job_id=3D'job0', device=3D'snap2-fmt', + top_node=3D'snap-fmt', + filters=3D[iotests.filter_qmp_generated_node_ids]) + + iotests.log('\nCommitting an inactive intermediate node to active base= ') + vm.qmp_log('blockdev-set-active', node_name=3D'disk-fmt', active=3DTru= e) + vm.qmp_log('block-commit', job_id=3D'job0', device=3D'snap2-fmt', + top_node=3D'snap-fmt', + filters=3D[iotests.filter_qmp_generated_node_ids]) + + iotests.log('\nMirror from inactive source to active target') + vm.qmp_log('blockdev-mirror', job_id=3D'job0', device=3D'snap2-fmt', + target=3D'target-fmt', sync=3D'full', + filters=3D[iotests.filter_qmp_generated_node_ids]) + + iotests.log('\nMirror from active source to inactive target') + + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + iotests.log('snap-fmt active: %s' % node_is_active(vm, 'snap-fmt')) + iotests.log('snap2-fmt active: %s' % node_is_active(vm, 'snap2-fmt')) + iotests.log('target-fmt active: %s' % node_is_active(vm, 'target-fmt')) + + # Activating snap2-fmt recursively activates the whole backing chain + vm.qmp_log('blockdev-set-active', node_name=3D'snap2-fmt', active=3DTr= ue) + vm.qmp_log('blockdev-set-active', node_name=3D'target-fmt', active=3DF= alse) + + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + iotests.log('snap-fmt active: %s' % node_is_active(vm, 'snap-fmt')) + iotests.log('snap2-fmt active: %s' % node_is_active(vm, 'snap2-fmt')) + iotests.log('target-fmt active: %s' % node_is_active(vm, 'target-fmt')) + + vm.qmp_log('blockdev-mirror', job_id=3D'job0', device=3D'snap2-fmt', + target=3D'target-fmt', sync=3D'full', + filters=3D[iotests.filter_qmp_generated_node_ids]) + + iotests.log('\nBackup from active source to inactive target') + + vm.qmp_log('blockdev-backup', job_id=3D'job0', device=3D'snap2-fmt', + target=3D'target-fmt', sync=3D'full', + filters=3D[iotests.filter_qmp_generated_node_ids]) + + iotests.log('\nBackup from inactive source to active target') + + # Activating snap2-fmt recursively inactivates the whole backing chain + vm.qmp_log('blockdev-set-active', node_name=3D'snap2-fmt', active=3DFa= lse) + vm.qmp_log('blockdev-set-active', node_name=3D'target-fmt', active=3DT= rue) + + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + iotests.log('snap-fmt active: %s' % node_is_active(vm, 'snap-fmt')) + iotests.log('snap2-fmt active: %s' % node_is_active(vm, 'snap2-fmt')) + iotests.log('target-fmt active: %s' % node_is_active(vm, 'target-fmt')) + + vm.qmp_log('blockdev-backup', job_id=3D'job0', device=3D'snap2-fmt', + target=3D'target-fmt', sync=3D'full', + filters=3D[iotests.filter_qmp_generated_node_ids]) + + iotests.log('\n=3D=3D=3D Accessing export on inactive node =3D=3D=3D') + + # Use the target node because it has the right image format and isn't = the + # (read-only) backing file of a qcow2 node + vm.qmp_log('blockdev-set-active', node_name=3D'target-fmt', active=3DF= alse) + vm.qmp_log('block-export-add', + **get_export(node_name=3D'target-fmt', allow_inactive=3DTru= e)) + + # The read should succeed, everything else should fail gracefully + qemu_io =3D QemuIoInteractive('-f', 'raw', + f'nbd+unix:///target-fmt?socket=3D{nbd_soc= k}') + iotests.log(qemu_io.cmd('read 0 64k'), filters=3D[filter_qemu_io]) + iotests.log(qemu_io.cmd('write 0 64k'), filters=3D[filter_qemu_io]) + iotests.log(qemu_io.cmd('write -z 0 64k'), filters=3D[filter_qemu_io]) + iotests.log(qemu_io.cmd('write -zu 0 64k'), filters=3D[filter_qemu_io]) + iotests.log(qemu_io.cmd('discard 0 64k'), filters=3D[filter_qemu_io]) + iotests.log(qemu_io.cmd('flush'), filters=3D[filter_qemu_io]) + iotests.log(qemu_io.cmd('map'), filters=3D[filter_qemu_io]) + qemu_io.close() + + iotests.log('\n=3D=3D=3D Resuming VM activates all images =3D=3D=3D') + vm.qmp_log('cont') + + iotests.log('disk-fmt active: %s' % node_is_active(vm, 'disk-fmt')) + iotests.log('snap-fmt active: %s' % node_is_active(vm, 'snap-fmt')) + iotests.log('snap2-fmt active: %s' % node_is_active(vm, 'snap2-fmt')) + iotests.log('target-fmt active: %s' % node_is_active(vm, 'target-fmt')) + + iotests.log('\nShutting down...') + vm.shutdown() + log =3D vm.get_log() + if log: + iotests.log(log, [filter_qtest, filter_qemu_io]) diff --git a/tests/qemu-iotests/tests/inactive-node-nbd.out b/tests/qemu-io= tests/tests/inactive-node-nbd.out new file mode 100644 index 0000000000..a458b4fc05 --- /dev/null +++ b/tests/qemu-iotests/tests/inactive-node-nbd.out @@ -0,0 +1,239 @@ +Preparing disk... +Launching VM... +{"execute": "nbd-server-start", "arguments": {"addr": {"data": {"path": "S= OCK_DIR/PID-nbd.sock"}, "type": "unix"}}} +{"return": {}} + +=3D=3D=3D Creating export of inactive node =3D=3D=3D + +Exports activate nodes without allow-inactive +disk-fmt active: False +{"execute": "block-export-add", "arguments": {"id": "exp0", "node-name": "= disk-fmt", "type": "nbd", "writable": true}} +{"return": {}} +disk-fmt active: True +{"execute": "query-block-exports", "arguments": {}} +{"return": [{"id": "exp0", "node-name": "disk-fmt", "shutting-down": false= , "type": "nbd"}]} +{"execute": "block-export-del", "arguments": {"id": "exp0"}} +{"return": {}} +{"execute": "query-block-exports", "arguments": {}} +{"return": []} + +Exports activate nodes with allow-inactive=3Dfalse +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "disk-fmt"}} +{"return": {}} +disk-fmt active: False +{"execute": "block-export-add", "arguments": {"allow-inactive": false, "id= ": "exp0", "node-name": "disk-fmt", "type": "nbd", "writable": true}} +{"return": {}} +disk-fmt active: True +{"execute": "query-block-exports", "arguments": {}} +{"return": [{"id": "exp0", "node-name": "disk-fmt", "shutting-down": false= , "type": "nbd"}]} +{"execute": "block-export-del", "arguments": {"id": "exp0"}} +{"return": {}} +{"execute": "query-block-exports", "arguments": {}} +{"return": []} + +Export leaves nodes inactive with allow-inactive=3Dtrue +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "disk-fmt"}} +{"return": {}} +disk-fmt active: False +{"execute": "block-export-add", "arguments": {"allow-inactive": true, "id"= : "exp0", "node-name": "disk-fmt", "type": "nbd", "writable": true}} +{"return": {}} +disk-fmt active: False +{"execute": "query-block-exports", "arguments": {}} +{"return": [{"id": "exp0", "node-name": "disk-fmt", "shutting-down": false= , "type": "nbd"}]} +{"execute": "block-export-del", "arguments": {"id": "exp0"}} +{"return": {}} +{"execute": "query-block-exports", "arguments": {}} +{"return": []} + +=3D=3D=3D Inactivating node with existing export =3D=3D=3D + +Inactivating nodes with an export fails without allow-inactive +{"execute": "blockdev-set-active", "arguments": {"active": true, "node-nam= e": "disk-fmt"}} +{"return": {}} +{"execute": "block-export-add", "arguments": {"id": "exp0", "node-name": "= disk-fmt", "type": "nbd", "writable": true}} +{"return": {}} +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "disk-fmt"}} +{"error": {"class": "GenericError", "desc": "Failed to inactivate node: Op= eration not permitted"}} +disk-fmt active: True +{"execute": "query-block-exports", "arguments": {}} +{"return": [{"id": "exp0", "node-name": "disk-fmt", "shutting-down": false= , "type": "nbd"}]} +{"execute": "block-export-del", "arguments": {"id": "exp0"}} +{"return": {}} +{"execute": "query-block-exports", "arguments": {}} +{"return": []} + +Inactivating nodes with an export fails with allow-inactive=3Dfalse +{"execute": "blockdev-set-active", "arguments": {"active": true, "node-nam= e": "disk-fmt"}} +{"return": {}} +{"execute": "block-export-add", "arguments": {"allow-inactive": false, "id= ": "exp0", "node-name": "disk-fmt", "type": "nbd", "writable": true}} +{"return": {}} +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "disk-fmt"}} +{"error": {"class": "GenericError", "desc": "Failed to inactivate node: Op= eration not permitted"}} +disk-fmt active: True +{"execute": "query-block-exports", "arguments": {}} +{"return": [{"id": "exp0", "node-name": "disk-fmt", "shutting-down": false= , "type": "nbd"}]} +{"execute": "block-export-del", "arguments": {"id": "exp0"}} +{"return": {}} +{"execute": "query-block-exports", "arguments": {}} +{"return": []} + +Inactivating nodes with an export works with allow-inactive=3Dtrue +{"execute": "blockdev-set-active", "arguments": {"active": true, "node-nam= e": "disk-fmt"}} +{"return": {}} +{"execute": "block-export-add", "arguments": {"allow-inactive": true, "id"= : "exp0", "node-name": "disk-fmt", "type": "nbd", "writable": true}} +{"return": {}} +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "disk-fmt"}} +{"return": {}} +disk-fmt active: False +{"execute": "query-block-exports", "arguments": {}} +{"return": [{"id": "exp0", "node-name": "disk-fmt", "shutting-down": false= , "type": "nbd"}]} +{"execute": "block-export-del", "arguments": {"id": "exp0"}} +{"return": {}} +{"execute": "query-block-exports", "arguments": {}} +{"return": []} + +=3D=3D=3D Inactive nodes with parent =3D=3D=3D + +Inactivating nodes with an active parent fails +{"execute": "blockdev-set-active", "arguments": {"active": true, "node-nam= e": "disk-fmt"}} +{"return": {}} +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "disk-file"}} +{"error": {"class": "GenericError", "desc": "Node has active parent node"}} +disk-file active: True +disk-fmt active: True + +Inactivating nodes with an inactive parent works +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "disk-fmt"}} +{"return": {}} +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "disk-file"}} +{"return": {}} +disk-file active: False +disk-fmt active: False + +Creating active parent node with an inactive child fails +{"execute": "blockdev-add", "arguments": {"driver": "raw", "file": "disk-f= mt", "node-name": "disk-filter"}} +{"error": {"class": "GenericError", "desc": "Inactive 'disk-fmt' can't be = a file child of active 'disk-filter'"}} +{"execute": "blockdev-add", "arguments": {"active": true, "driver": "raw",= "file": "disk-fmt", "node-name": "disk-filter"}} +{"error": {"class": "GenericError", "desc": "Inactive 'disk-fmt' can't be = a file child of active 'disk-filter'"}} + +Creating inactive parent node with an inactive child works +{"execute": "blockdev-add", "arguments": {"active": false, "driver": "raw"= , "file": "disk-fmt", "node-name": "disk-filter"}} +{"return": {}} +{"execute": "blockdev-del", "arguments": {"node-name": "disk-filter"}} +{"return": {}} + +=3D=3D=3D Resizing an inactive node =3D=3D=3D +{"execute": "block_resize", "arguments": {"node-name": "disk-fmt", "size":= 16777216}} +{"error": {"class": "GenericError", "desc": "Permission 'resize' unavailab= le on inactive node"}} + +=3D=3D=3D Taking a snapshot of an inactive node =3D=3D=3D + +Active overlay over inactive backing file automatically makes both inactiv= e for compatibility +{"execute": "blockdev-add", "arguments": {"backing": null, "driver": "qcow= 2", "file": "snap-file", "node-name": "snap-fmt"}} +{"return": {}} +disk-fmt active: False +snap-fmt active: True +{"execute": "blockdev-snapshot", "arguments": {"node": "disk-fmt", "overla= y": "snap-fmt"}} +{"return": {}} +disk-fmt active: False +snap-fmt active: False +{"execute": "blockdev-del", "arguments": {"node-name": "snap-fmt"}} +{"return": {}} + +Inactive overlay over inactive backing file just works +{"execute": "blockdev-add", "arguments": {"active": false, "backing": null= , "driver": "qcow2", "file": "snap-file", "node-name": "snap-fmt"}} +{"return": {}} +{"execute": "blockdev-snapshot", "arguments": {"node": "disk-fmt", "overla= y": "snap-fmt"}} +{"return": {}} + +=3D=3D=3D Block jobs with inactive nodes =3D=3D=3D + +Streaming into an inactive node +{"execute": "block-stream", "arguments": {"device": "snap-fmt"}} +{"error": {"class": "GenericError", "desc": "Could not create node: Inacti= ve 'snap-fmt' can't be a file child of active 'NODE_NAME'"}} + +Committing an inactive root node (active commit) +{"execute": "block-commit", "arguments": {"device": "snap-fmt", "job-id": = "job0"}} +{"error": {"class": "GenericError", "desc": "Inactive 'snap-fmt' can't be = a backing child of active 'NODE_NAME'"}} + +Committing an inactive intermediate node to inactive base +{"execute": "blockdev-add", "arguments": {"active": false, "backing": "sna= p-fmt", "driver": "qcow2", "file": "snap2-file", "node-name": "snap2-fmt"}} +{"return": {}} +disk-fmt active: False +snap-fmt active: False +snap2-fmt active: False +{"execute": "block-commit", "arguments": {"device": "snap2-fmt", "job-id":= "job0", "top-node": "snap-fmt"}} +{"error": {"class": "GenericError", "desc": "Inactive 'snap-fmt' can't be = a backing child of active 'NODE_NAME'"}} + +Committing an inactive intermediate node to active base +{"execute": "blockdev-set-active", "arguments": {"active": true, "node-nam= e": "disk-fmt"}} +{"return": {}} +{"execute": "block-commit", "arguments": {"device": "snap2-fmt", "job-id":= "job0", "top-node": "snap-fmt"}} +{"error": {"class": "GenericError", "desc": "Inactive 'snap-fmt' can't be = a backing child of active 'NODE_NAME'"}} + +Mirror from inactive source to active target +{"execute": "blockdev-mirror", "arguments": {"device": "snap2-fmt", "job-i= d": "job0", "sync": "full", "target": "target-fmt"}} +{"error": {"class": "GenericError", "desc": "Inactive 'snap2-fmt' can't be= a backing child of active 'NODE_NAME'"}} + +Mirror from active source to inactive target +disk-fmt active: True +snap-fmt active: False +snap2-fmt active: False +target-fmt active: True +{"execute": "blockdev-set-active", "arguments": {"active": true, "node-nam= e": "snap2-fmt"}} +{"return": {}} +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "target-fmt"}} +{"return": {}} +disk-fmt active: True +snap-fmt active: True +snap2-fmt active: True +target-fmt active: False +{"execute": "blockdev-mirror", "arguments": {"device": "snap2-fmt", "job-i= d": "job0", "sync": "full", "target": "target-fmt"}} +{"error": {"class": "GenericError", "desc": "Permission 'write' unavailabl= e on inactive node"}} + +Backup from active source to inactive target +{"execute": "blockdev-backup", "arguments": {"device": "snap2-fmt", "job-i= d": "job0", "sync": "full", "target": "target-fmt"}} +{"error": {"class": "GenericError", "desc": "Could not create node: Inacti= ve 'target-fmt' can't be a target child of active 'NODE_NAME'"}} + +Backup from inactive source to active target +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "snap2-fmt"}} +{"return": {}} +{"execute": "blockdev-set-active", "arguments": {"active": true, "node-nam= e": "target-fmt"}} +{"return": {}} +disk-fmt active: False +snap-fmt active: False +snap2-fmt active: False +target-fmt active: True +{"execute": "blockdev-backup", "arguments": {"device": "snap2-fmt", "job-i= d": "job0", "sync": "full", "target": "target-fmt"}} +{"error": {"class": "GenericError", "desc": "Could not create node: Inacti= ve 'snap2-fmt' can't be a file child of active 'NODE_NAME'"}} + +=3D=3D=3D Accessing export on inactive node =3D=3D=3D +{"execute": "blockdev-set-active", "arguments": {"active": false, "node-na= me": "target-fmt"}} +{"return": {}} +{"execute": "block-export-add", "arguments": {"allow-inactive": true, "id"= : "exp0", "node-name": "target-fmt", "type": "nbd", "writable": true}} +{"return": {}} +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +write failed: Operation not permitted + +write failed: Operation not permitted + +write failed: Operation not permitted + +discard failed: Operation not permitted + + +qemu-io: Failed to get allocation status: Operation not permitted + + +=3D=3D=3D Resuming VM activates all images =3D=3D=3D +{"execute": "cont", "arguments": {}} +{"return": {}} +disk-fmt active: True +snap-fmt active: True +snap2-fmt active: True +target-fmt active: True + +Shutting down... + --=20 2.48.1