From nobody Sun May 19 06:50:48 2024 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=1625069349; cv=none; d=zohomail.com; s=zohoarc; b=TUx7OAJeOHYkI3WKpVZjxghT1e/R8wYoU0/USkhyrakj24fTTTX8whKmBIt4mJwC+Mmfdzq1v2zzmXx6ZZKY4sK4ryicBDr1+MdHDYKpAjn2CjdPSIAqIEZKotVZI385yoo4US8sBWABG/lX7WT7jDL+wcIR4sA2dQ811l/kOaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069349; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7q479c3HKYtUzJNO/3mFsW54OcH4FXotX0///SAOshE=; b=nOgd7A9niSYjY1nYAHc/l5RfFmPtCnx4hWFYKCu2LzQuvKrY+GVo/8CpPUQTa95V3awrSsB23mi1K3QiiQ6G3Rz+Sf+S+NCC3ItOxIDrRRhwPwvN+QTSKsGroYQklh4NST7I+ppmXXvjTCQ+Y/8QchcBVZsAIqAL4ksVC2Hyk/I= 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 1625069349155315.18371935556604; Wed, 30 Jun 2021 09:09:09 -0700 (PDT) Received: from localhost ([::1]:53782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyclw-0005ER-6i for importer@patchew.org; Wed, 30 Jun 2021 12:09:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfK-0002OQ-S2 for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50414) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfI-0006uG-DN for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-342-2CqqzIIyPyqDK6W1aXFrAg-1; Wed, 30 Jun 2021 12:02:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B1A12A40C2; Wed, 30 Jun 2021 16:02:12 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFB1B18AAB; Wed, 30 Jun 2021 16:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7q479c3HKYtUzJNO/3mFsW54OcH4FXotX0///SAOshE=; b=NqMxbf5wjHlMgm/4afBtOtdjgoVLIf+XLLNEDeF0anBT3wWXRV6L6nyvsqAXusxIWq3Dif 5HOc+HE0OV+jy41qnCYaacHs8E2pIpH/lgZFA0yREI6WyHeCobKu5sFyfdjUt0viQxwGwD hAowAILKAQIAZuMsDj8Ed497zF5UkNU= X-MC-Unique: 2CqqzIIyPyqDK6W1aXFrAg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 01/24] Prevent compiler warning on block.c Date: Wed, 30 Jun 2021 18:01:43 +0200 Message-Id: <20210630160206.276439-2-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Miroslav Rezanina Commit 3108a15cf (block: introduce bdrv_drop_filter()) introduced uninitialized variable to_cow_parent in bdrv_replace_node_common function that is used only when detach_subchain is true. It is used in two places. First if block properly initialize the variable and second block use it. However, compiler may treat these two blocks as two independent cases so it thinks first block can fail test and second one pass (although both use same condition). This cause warning that variable can be uninitialized in second block. The warning was observed with GCC 8.4.1 and 11.0.1. To prevent this warning, initialize the variable with NULL. Signed-off-by: Miroslav Rezanina Message-Id: <1162368493.17178530.1620201543649.JavaMail.zimbra@redhat.com> Signed-off-by: Kevin Wolf --- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block.c b/block.c index 1d37f133a8..3e277855e7 100644 --- a/block.c +++ b/block.c @@ -4866,7 +4866,7 @@ static int bdrv_replace_node_common(BlockDriverState = *from, Transaction *tran =3D tran_new(); g_autoptr(GHashTable) found =3D NULL; g_autoptr(GSList) refresh_list =3D NULL; - BlockDriverState *to_cow_parent; + BlockDriverState *to_cow_parent =3D NULL; int ret; =20 if (detach_subchain) { --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069430; cv=none; d=zohomail.com; s=zohoarc; b=MHSvdK4hIWpQDu57SNsRwihoF8i+ax2HYusGYnWYUdcctyFzxFZp72dcqvEnneBHKGjdaOFv7kiSEajJkVJMjhqRpEhdxdJZ4rBkrEFxTLg2QIks5jRlBGgB3EEvmdArBtQ8QnJlAyvuZ/7UQMFWRsIqkIh3Z9fsqB/RYpmRzYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069430; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z8X3FKADVp/gBsZl3Z9T0lIT3DesjSNTXgZSYcBtxaE=; b=K5BgtAUwuniVVA1KTkF/jlqXxAfT/PejA6SME0/a/9hF6PR79cFyNJyQch4j0ddemTN/zP/KDQHojMVIEj4WVnpDj9pvAKDDi77iTHjSlGUyopFmfTtUb4RELzR1q0B2eUia1mvtXiQBIlyd9f/84TnrWLgrvol5vjGFkYdv0Zw= 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 1625069430483854.7353612727884; Wed, 30 Jun 2021 09:10:30 -0700 (PDT) Received: from localhost ([::1]:59384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycnF-0000V6-Nm for importer@patchew.org; Wed, 30 Jun 2021 12:10:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfO-0002aL-I0 for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55438) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfJ-0006uZ-KW for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-qm4CmJYsNn6bTvlvIde1EA-1; Wed, 30 Jun 2021 12:02:14 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ED08DA40C5; Wed, 30 Jun 2021 16:02:13 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0571B604CD; Wed, 30 Jun 2021 16:02:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068936; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z8X3FKADVp/gBsZl3Z9T0lIT3DesjSNTXgZSYcBtxaE=; b=REh/O3A3ZTQjprvA7VsZmMGVQoe85+S97cu7ZTzfu+fe46oz8LI0CQhV20XFzVNuZ1aIPo UZNO13czHbAUwCzgcrFslMe9g7lz3+jOg12HEjfMv9V+zvsg/VQOrc/Qz0pxtmzWqNakio uA6fGoSnTxcw9P5ooZzcERUoNwmQkoY= X-MC-Unique: qm4CmJYsNn6bTvlvIde1EA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 02/24] block: Move read-only check during truncation earlier Date: Wed, 30 Jun 2021 18:01:44 +0200 Message-Id: <20210630160206.276439-3-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Eric Blake No need to start a tracked request that will always fail. The choice to check read-only after bdrv_inc_in_flight() predates 1bc5f09f2e (block: Use tracked request for truncate), but waiting for serializing requests can make the effect more noticeable. Signed-off-by: Eric Blake Message-Id: <20210609163034.997943-1-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- block/io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/io.c b/block/io.c index dd93364258..cf177a9d2d 100644 --- a/block/io.c +++ b/block/io.c @@ -3392,6 +3392,11 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, = int64_t offset, bool exact, return old_size; } =20 + if (bdrv_is_read_only(bs)) { + error_setg(errp, "Image is read-only"); + return -EACCES; + } + if (offset > old_size) { new_bytes =3D offset - old_size; } else { @@ -3408,11 +3413,6 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, = int64_t offset, bool exact, if (new_bytes) { bdrv_make_request_serialising(&req, 1); } - if (bdrv_is_read_only(bs)) { - error_setg(errp, "Image is read-only"); - ret =3D -EACCES; - goto out; - } ret =3D bdrv_co_write_req_prepare(child, offset - new_bytes, new_bytes= , &req, 0); if (ret < 0) { --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069298; cv=none; d=zohomail.com; s=zohoarc; b=maPW/cfKRRfO78ySgCHiIRJhuFpV55XL0n/rs/SsyQ8tve/DqHtOk55jZ7xXEMJXBkYZQ0l0SQzrHJuwuWrnEHJCqwueDNsMkHepzNdgzJ+0rk6IpN/I4cQUlVeP/gSFjg2xVEFk9K0boteXapxARjvWQiqZfWuyMpyf6Rf2x70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069298; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MBILtnV+Iorzg0Zv7PpW1VkAYlsKaI1ABjB/gmvTi/g=; b=FjERig/Deud9NmvAXHm+Yu0iMKR9m9Va+GfN4B6FDJS4/TLEOfnDw7iNbLdvMS5MGi7zs8gwGjLT/lAD9wXrTxzLt7CiJ/bHwM0xNHLGVtefu9/H7eSP6I4yObfO94EeqnlSpz26VjvUByWjL7x+dd+t/dLEcLKJw4/H5bxhbVI= 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 1625069298629261.56362481590804; Wed, 30 Jun 2021 09:08:18 -0700 (PDT) Received: from localhost ([::1]:50804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycl7-0003Ep-NN for importer@patchew.org; Wed, 30 Jun 2021 12:08:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfN-0002W8-8z for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfL-0006vq-8R for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-454--QfmdSGsO32_9yGFqngiNQ-1; Wed, 30 Jun 2021 12:02:16 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35971A40C8; Wed, 30 Jun 2021 16:02:15 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4042E179E6; Wed, 30 Jun 2021 16:02:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MBILtnV+Iorzg0Zv7PpW1VkAYlsKaI1ABjB/gmvTi/g=; b=b1cUdNClEoniplGhXII6JPXl9sEptPpU4/a8qUnpgpIcew/PI4EcYdoyU37Q36LHV/n8kO vGJiKjJeeYwWFEr2f9j3yGQ9ZV0K/oUb3mXDfque+esqZxkIG4cM1vbNeF3fSqoN/FC7YT ASe05u1Zt3nwZrzDzLKWzUqGePAc6Hc= X-MC-Unique: -QfmdSGsO32_9yGFqngiNQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 03/24] block: BDRV_O_NO_IO for backing file on creation Date: Wed, 30 Jun 2021 18:01:45 +0200 Message-Id: <20210630160206.276439-4-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Max Reitz When creating an image file with a backing file, we generally try to open the backing file (unless -u was specified), mostly to verify that it is there, but also to get the file size if none was specified for the new image. For neither of these things do we need data I/O, and so we can pass BDRV_O_NO_IO when opening the backing file. This allows us to open even encrypted backing images without requiring the user to provide a secret. This makes the -u switch in iotests 189 and 198 unnecessary (and the $size parameter), so drop it, because this way we get regression tests for this patch here. Fixes: https://gitlab.com/qemu-project/qemu/-/issues/441 Signed-off-by: Max Reitz Message-Id: <20210622140030.212487-1-mreitz@redhat.com> Signed-off-by: Kevin Wolf --- block.c | 6 +++++- tests/qemu-iotests/189 | 2 +- tests/qemu-iotests/198 | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 3e277855e7..a2a4a0dd80 100644 --- a/block.c +++ b/block.c @@ -6553,9 +6553,13 @@ void bdrv_img_create(const char *filename, const cha= r *fmt, } assert(full_backing); =20 - /* backing files always opened read-only */ + /* + * No need to do I/O here, which allows us to open encrypted + * backing images without needing the secret + */ back_flags =3D flags; back_flags &=3D ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKIN= G); + back_flags |=3D BDRV_O_NO_IO; =20 backing_options =3D qdict_new(); if (backing_fmt) { diff --git a/tests/qemu-iotests/189 b/tests/qemu-iotests/189 index 4e463385b2..801494c6b9 100755 --- a/tests/qemu-iotests/189 +++ b/tests/qemu-iotests/189 @@ -67,7 +67,7 @@ echo "=3D=3D verify pattern =3D=3D" $QEMU_IO --object $SECRET0 -c "read -P 0xa 0 $size" --image-opts $IMGSPECB= ASE | _filter_qemu_io | _filter_testdir =20 echo "=3D=3D create overlay =3D=3D" -_make_test_img --object $SECRET1 -o "encrypt.format=3Dluks,encrypt.key-sec= ret=3Dsec1,encrypt.iter-time=3D10" -u -b "$TEST_IMG_BASE" -F $IMGFMT $size +_make_test_img --object $SECRET1 -o "encrypt.format=3Dluks,encrypt.key-sec= ret=3Dsec1,encrypt.iter-time=3D10" -b "$TEST_IMG_BASE" -F $IMGFMT =20 echo echo "=3D=3D writing part of a cluster =3D=3D" diff --git a/tests/qemu-iotests/198 b/tests/qemu-iotests/198 index b333a8f281..1c93dea1f7 100755 --- a/tests/qemu-iotests/198 +++ b/tests/qemu-iotests/198 @@ -64,7 +64,7 @@ echo "=3D=3D writing whole image base =3D=3D" $QEMU_IO --object $SECRET0 -c "write -P 0xa 0 $size" --image-opts $IMGSPEC= BASE | _filter_qemu_io | _filter_testdir =20 echo "=3D=3D create overlay =3D=3D" -_make_test_img --object $SECRET1 -o "encrypt.format=3Dluks,encrypt.key-sec= ret=3Dsec1,encrypt.iter-time=3D10" -u -b "$TEST_IMG_BASE" -F $IMGFMT $size +_make_test_img --object $SECRET1 -o "encrypt.format=3Dluks,encrypt.key-sec= ret=3Dsec1,encrypt.iter-time=3D10" -b "$TEST_IMG_BASE" -F $IMGFMT =20 echo echo "=3D=3D writing whole image layer =3D=3D" --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069976; cv=none; d=zohomail.com; s=zohoarc; b=jLwPsDigDw4ui+4+IllZFZPidXxV1+CmPY6V1P8L82Y9jeKRzsNbkkZ7cseF951Ibgq4BZGtIv2WF2yDgT0Pu75Z3Tbz4Vl7y9V6GKBxnBu1SXw8Oc3X+3ZKNXH9rfsDBXkkMDIpNJW/jevLWKotDmCzJkIMSv97TYyZBNdL790= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069976; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0P6yq/5asofQLDn40wPsgOLIVdHH5Zff0LBsNzY9hWM=; b=UebkJqSgWuvgH5E6Df1cQVz1lKFiAfbccbU+ChcdSUoWpnXcoLFMjNgaLhzPYBOFHtj9/peKRKHp4+c6Gu2ZTUeFgWyLlzaUK4j+vv0SpuiFebUXGFd/4ycRs8l82MHUyFwa5e8PSvSdP9kHdHFVKVqijIS+4fXkKNxeKsusUJk= 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 1625069976506851.5421296618338; Wed, 30 Jun 2021 09:19:36 -0700 (PDT) Received: from localhost ([::1]:52542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycw3-0006nz-7U for importer@patchew.org; Wed, 30 Jun 2021 12:19:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfp-0002xR-MT for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49332) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfX-00073z-3U for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-294-6VjRpcAKMBqO4zzmXTxtKg-1; Wed, 30 Jun 2021 12:02:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 791EDA40C5; Wed, 30 Jun 2021 16:02:16 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C4A8604CD; Wed, 30 Jun 2021 16:02:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068949; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0P6yq/5asofQLDn40wPsgOLIVdHH5Zff0LBsNzY9hWM=; b=aGJbDrtbbHHxpZtYbVz8tsOmSkLuIMp9Cm2dTOgzIa7mzvqgd3IazeOBpMcMddXVWJh/w5 48o/CEwTJ3dZWe0T6EZfMqiFFjF7Gk1Tc8sySoA+YPiHUKkGoCpv0iQeXZJNP5zcWupNeC ne7to/FxmetrGAtLOyXrEj93I4oMc1c= X-MC-Unique: 6VjRpcAKMBqO4zzmXTxtKg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 04/24] block: rename bdrv_replace_child to bdrv_replace_child_tran Date: Wed, 30 Jun 2021 18:01:46 +0200 Message-Id: <20210630160206.276439-5-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We have bdrv_replace_child() wrapper on bdrv_replace_child_noperm(). But bdrv_replace_child() doesn't update permissions. It's rather strange, as normally it's expected that foo() should call foo_noperm() and update permissions. Let's rename and add comment. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Message-Id: <20210610112618.127378-2-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- block.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index a2a4a0dd80..e49ff8c078 100644 --- a/block.c +++ b/block.c @@ -2249,12 +2249,14 @@ static TransactionActionDrv bdrv_replace_child_drv = =3D { }; =20 /* - * bdrv_replace_child + * bdrv_replace_child_tran * * Note: real unref of old_bs is done only on commit. + * + * The function doesn't update permissions, caller is responsible for this. */ -static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs, - Transaction *tran) +static void bdrv_replace_child_tran(BdrvChild *child, BlockDriverState *ne= w_bs, + Transaction *tran) { BdrvReplaceChildState *s =3D g_new(BdrvReplaceChildState, 1); *s =3D (BdrvReplaceChildState) { @@ -4766,7 +4768,7 @@ static void bdrv_remove_filter_or_cow_child_abort(voi= d *opaque) } =20 /* - * We don't have to restore child->bs here to undo bdrv_replace_child() + * We don't have to restore child->bs here to undo bdrv_replace_child_= tran() * because that function is transactionable and it registered own comp= letion * entries in @tran, so .abort() for bdrv_replace_child_safe() will be * called automatically. @@ -4802,7 +4804,7 @@ static void bdrv_remove_filter_or_cow_child(BlockDriv= erState *bs, } =20 if (child->bs) { - bdrv_replace_child(child, NULL, tran); + bdrv_replace_child_tran(child, NULL, tran); } =20 s =3D g_new(BdrvRemoveFilterOrCowChild, 1); @@ -4842,7 +4844,7 @@ static int bdrv_replace_node_noperm(BlockDriverState = *from, c->name, from->node_name); return -EPERM; } - bdrv_replace_child(c, to, tran); + bdrv_replace_child_tran(c, to, tran); } =20 return 0; --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069373; cv=none; d=zohomail.com; s=zohoarc; b=f/aeZR+KoS8/4vTtb6u3wxiGqopKeF42pcq4ZIO/yxhdpW8ZIHoVpztrbNB/WtvbS7SC21DP1J1JcGf1bCginavOm8EtFVaFrldtIH7vsezHvIuI1rLNR/ZUIB9kIrG8gD7lJbWrQQ56sUXx0Q1JxDiIhGqOKqGLCCKEv92OiII= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069373; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dFLfy8QTG/Oo/Bksf8jc34H2gBsyB0yMczmjA5TkneA=; b=Glpb5bI5X367Jn18t/U6LnqRxIQAfeEUX9/dItCODkM7U4wwl6Plp1i0+Pt76O3oFKIYky7mrzvGChcb3yoWenl8g6MMA0C4MHFrStfuqKopHL0OpS3LzicVjEOrxzK3k7jKjBOV5yOAb/vO/X5JTQNoJ4C7eY6MCd/kEi0HfQI= 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 162506937356741.29254759408889; Wed, 30 Jun 2021 09:09:33 -0700 (PDT) Received: from localhost ([::1]:55948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycmK-0006em-S9 for importer@patchew.org; Wed, 30 Jun 2021 12:09:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycg8-00035s-Jl for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53852) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfj-00078f-Ih for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:08 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-8IFs9LX4NWClZ98D6xNgdQ-1; Wed, 30 Jun 2021 12:02:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB12C804140; Wed, 30 Jun 2021 16:02:17 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id B714A5B826; Wed, 30 Jun 2021 16:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dFLfy8QTG/Oo/Bksf8jc34H2gBsyB0yMczmjA5TkneA=; b=TF+KiAYrYiSdzP1VhCTHPWk9qp9CAGQqr4n5fcMw8j7hs1dE5KQPKMJyNfNvz3HTbIK5WQ rFuODuTzOLYJJ23MxLEJSiUOgahelp9GuB6wOpkFLpUSJkyW3vBoQfX+fBJ2P0m0sonw6T DG7vjg4DfItIDSJRuu1ZujKtguG81Nc= X-MC-Unique: 8IFs9LX4NWClZ98D6xNgdQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 05/24] block: comment graph-modifying function not updating permissions Date: Wed, 30 Jun 2021 18:01:47 +0200 Message-Id: <20210630160206.276439-6-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Message-Id: <20210610112618.127378-3-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- block.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block.c b/block.c index e49ff8c078..9518f0e087 100644 --- a/block.c +++ b/block.c @@ -2770,6 +2770,8 @@ static TransactionActionDrv bdrv_attach_child_common_= drv =3D { * @child is saved to a new entry of @tran, so that *@child could be rever= ted to * NULL on abort(). So referenced variable must live at least until transa= ction * end. + * + * Function doesn't update permissions, caller is responsible for this. */ static int bdrv_attach_child_common(BlockDriverState *child_bs, const char *child_name, @@ -2848,6 +2850,8 @@ static int bdrv_attach_child_common(BlockDriverState = *child_bs, /* * Variable referenced by @child must live at least until transaction end. * (see bdrv_attach_child_common() doc for details) + * + * Function doesn't update permissions, caller is responsible for this. */ static int bdrv_attach_child_noperm(BlockDriverState *parent_bs, BlockDriverState *child_bs, @@ -3115,6 +3119,8 @@ static BdrvChildRole bdrv_backing_role(BlockDriverSta= te *bs) /* * Sets the bs->backing link of a BDS. A new reference is created; callers * which don't need their own reference any more must call bdrv_unref(). + * + * Function doesn't update permissions, caller is responsible for this. */ static int bdrv_set_backing_noperm(BlockDriverState *bs, BlockDriverState *backing_hd, @@ -4792,6 +4798,8 @@ static TransactionActionDrv bdrv_remove_filter_or_cow= _child_drv =3D { * A function to remove backing-chain child of @bs if exists: cow child for * format nodes (always .backing) and filter child for filters (may be .fi= le or * .backing) + * + * Function doesn't update permissions, caller is responsible for this. */ static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, Transaction *tran) --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069499; cv=none; d=zohomail.com; s=zohoarc; b=XR/ZkPA18zK8vEmlZgR7t1v3AU62gYfL1hkrvwLs+TvVcVsrHJuHtu+yzaNbxQ69SV+RfBZx1EmVbLDHbx0hSGKQt6vYa4x7vjIapw3AjkfXPYhObWz+XCjkl0gEs791EQGZBd5klTb2JGJHJRVjyTiNNSkHUyMawjRR5pMylw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069499; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4c5/u9scxRPXvTvAEM+hG0QOBGUVzKNr3U3susJdclU=; b=eBjY0STEIn4eriHS+fg8M88+HJmzAuxyepxMnbk3JBa2MWhhCUbLqZ+7pDz2B7N+D9QRnh3QeO65oj05jk+zkFkoDBnLpxc/ST7lQMwrzl4EwOOsgASddAPdMCQWVqC0b9DnXtLPOws3H2UOhWE5K+scop/OFj8UpHtAD+RgqQg= 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 1625069499008940.9123818486515; Wed, 30 Jun 2021 09:11:39 -0700 (PDT) Received: from localhost ([::1]:34516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycoL-0002rG-Ly for importer@patchew.org; Wed, 30 Jun 2021 12:11:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfQ-0002dp-6V for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfO-0006yW-EY for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-iXPCSrI9OBKb1xyUB6ZCRQ-1; Wed, 30 Jun 2021 12:02:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5C6F10C1ADC; Wed, 30 Jun 2021 16:02:18 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id F246F604CD; Wed, 30 Jun 2021 16:02:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4c5/u9scxRPXvTvAEM+hG0QOBGUVzKNr3U3susJdclU=; b=SjSBvvYkH17lj0ied5ThuEz13F7qlFddFw2LQSJYUZWjg4B6HHuSJjFhZNJxmUn4sN7B1t 8rAzvmeL1IdHTpTOEsKdJTa5VEMV8UDyMJ708G1CIFyM7ZAuTbpdrOXhL9E8ypPoBWUQff BFh2z+4XLOL6t9+3yeyY0tL1w0t9c50= X-MC-Unique: iXPCSrI9OBKb1xyUB6ZCRQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 06/24] block: introduce bdrv_remove_file_or_backing_child() Date: Wed, 30 Jun 2021 18:01:48 +0200 Message-Id: <20210630160206.276439-7-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy To be used for reopen in future commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210610120537.196183-2-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- block.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 9518f0e087..7eceef0afa 100644 --- a/block.c +++ b/block.c @@ -4795,17 +4795,16 @@ static TransactionActionDrv bdrv_remove_filter_or_c= ow_child_drv =3D { }; =20 /* - * A function to remove backing-chain child of @bs if exists: cow child for - * format nodes (always .backing) and filter child for filters (may be .fi= le or - * .backing) - * + * A function to remove backing or file child of @bs. * Function doesn't update permissions, caller is responsible for this. */ -static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, - Transaction *tran) +static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, + BdrvChild *child, + Transaction *tran) { BdrvRemoveFilterOrCowChild *s; - BdrvChild *child =3D bdrv_filter_or_cow_child(bs); + + assert(child =3D=3D bs->backing || child =3D=3D bs->file); =20 if (!child) { return; @@ -4830,6 +4829,17 @@ static void bdrv_remove_filter_or_cow_child(BlockDri= verState *bs, } } =20 +/* + * A function to remove backing-chain child of @bs if exists: cow child for + * format nodes (always .backing) and filter child for filters (may be .fi= le or + * .backing) + */ +static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, + Transaction *tran) +{ + bdrv_remove_file_or_backing_child(bs, bdrv_filter_or_cow_child(bs), tr= an); +} + static int bdrv_replace_node_noperm(BlockDriverState *from, BlockDriverState *to, bool auto_skip, Transaction *tran, --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069185; cv=none; d=zohomail.com; s=zohoarc; b=gsyod/rVKoyZxA5sjm5FCtM5GnfN9w43WTsmYKlXBoqGM2B/K6syN+6vRQ2WJlOCsNYPNY6LvTD2me6rvOuaPoN7o8lZDGUzqZK0i1kq1kLAMC+Ssub52BFg3i9gcLoyIp0MicHyeySS8PCHMW+K0hPcq/rCyunVUE5qBaTgOrI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069185; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Gzkz4iQ1z7SgIx+HREwKK8edPLbz9y/BM8Rp8M8y6Tg=; b=g03h/eVN3cjmyHUk9ebZpI4LsOWlqCZq7XxxzmERh2ns2+99P9PdeXhnegHDYobtRBSJ+bcO6Aq5SdM2EtnxjE09hqoQB+mlnFsggjpIPrKaKYJ3U0kx8vnqeoApTxnyeslD1Ig2sYhiAtHO4JPXbs+rNNu5jXplKWB+lJRVql0= 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 1625069185793934.9480425682189; Wed, 30 Jun 2021 09:06:25 -0700 (PDT) Received: from localhost ([::1]:44264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycjI-0007DA-07 for importer@patchew.org; Wed, 30 Jun 2021 12:06:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfV-0002rO-Pw for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54544) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfR-00070c-Qz for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-oSqTpHrMO9aqnBWm3CyIaA-1; Wed, 30 Jun 2021 12:02:21 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B4AF801596; Wed, 30 Jun 2021 16:02:20 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3977A189C7; Wed, 30 Jun 2021 16:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gzkz4iQ1z7SgIx+HREwKK8edPLbz9y/BM8Rp8M8y6Tg=; b=hLlkYxzhybQnfPHS12ZtVjtGulM3/VOTqtzBa3QYZTWXtoCu92N6RD9Ew4AECNyMPqWv/h la7NF+0tEfYF0uNIXYlxzVYSLNG9BDyc/hbxpD05PXXonkg/OdDtbrnM6Ir8KCIr8AdlLn 9JfGxZKBbayIokXShXyNyPksRQhlGkU= X-MC-Unique: oSqTpHrMO9aqnBWm3CyIaA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 07/24] block: introduce bdrv_set_file_or_backing_noperm() Date: Wed, 30 Jun 2021 18:01:49 +0200 Message-Id: <20210630160206.276439-8-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy To be used for reopen in future commit. Notes: - It seems OK to update inherits_from if new bs is recursively inherits from parent bs. Let's just not check for backing_chain_contains, to support file child of non-filters. - Simply check child->frozen instead of bdrv_is_backing_chain_frozen(), as we really interested only in this one child. - Role determination of new child is a bit more complex: it remains the same for backing child, it's obvious for filter driver. But for non-filter file child let's for now restrict to only replacing existing child (and keeping its role). Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210610120537.196183-3-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- block.c | 83 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 20 deletions(-) diff --git a/block.c b/block.c index 7eceef0afa..14711ce7ab 100644 --- a/block.c +++ b/block.c @@ -84,6 +84,9 @@ static BlockDriverState *bdrv_open_inherit(const char *fi= lename, =20 static void bdrv_replace_child_noperm(BdrvChild *child, BlockDriverState *new_bs); +static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, + BdrvChild *child, + Transaction *tran); static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, Transaction *tran); =20 @@ -3117,56 +3120,96 @@ static BdrvChildRole bdrv_backing_role(BlockDriverS= tate *bs) } =20 /* - * Sets the bs->backing link of a BDS. A new reference is created; callers - * which don't need their own reference any more must call bdrv_unref(). + * Sets the bs->backing or bs->file link of a BDS. A new reference is crea= ted; + * callers which don't need their own reference any more must call bdrv_un= ref(). * * Function doesn't update permissions, caller is responsible for this. */ -static int bdrv_set_backing_noperm(BlockDriverState *bs, - BlockDriverState *backing_hd, - Transaction *tran, Error **errp) +static int bdrv_set_file_or_backing_noperm(BlockDriverState *parent_bs, + BlockDriverState *child_bs, + bool is_backing, + Transaction *tran, Error **errp) { int ret =3D 0; - bool update_inherits_from =3D bdrv_chain_contains(bs, backing_hd) && - bdrv_inherits_from_recursive(backing_hd, bs); + bool update_inherits_from =3D + bdrv_inherits_from_recursive(child_bs, parent_bs); + BdrvChild *child =3D is_backing ? parent_bs->backing : parent_bs->file; + BdrvChildRole role; =20 - if (bdrv_is_backing_chain_frozen(bs, child_bs(bs->backing), errp)) { + if (!parent_bs->drv) { + /* + * Node without drv is an object without a class :/. TODO: finally= fix + * qcow2 driver to never clear bs->drv and implement format corrup= tion + * handling in other way. + */ + error_setg(errp, "Node corrupted"); + return -EINVAL; + } + + if (child && child->frozen) { + error_setg(errp, "Cannot change frozen '%s' link from '%s' to '%s'= ", + child->name, parent_bs->node_name, child->bs->node_name= ); return -EPERM; } =20 - if (bs->backing) { - /* Cannot be frozen, we checked that above */ - bdrv_unset_inherits_from(bs, bs->backing, tran); - bdrv_remove_filter_or_cow_child(bs, tran); + if (parent_bs->drv->is_filter) { + role =3D BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY; + } else if (is_backing) { + role =3D BDRV_CHILD_COW; + } else { + /* + * We only can use same role as it is in existing child. We don't = have + * infrastructure to determine role of file child in generic way + */ + if (!child) { + error_setg(errp, "Cannot set file child to format node without= " + "file child"); + return -EINVAL; + } + role =3D child->role; } =20 - if (!backing_hd) { + if (child) { + bdrv_unset_inherits_from(parent_bs, child, tran); + bdrv_remove_file_or_backing_child(parent_bs, child, tran); + } + + if (!child_bs) { goto out; } =20 - ret =3D bdrv_attach_child_noperm(bs, backing_hd, "backing", - &child_of_bds, bdrv_backing_role(bs), - &bs->backing, tran, errp); + ret =3D bdrv_attach_child_noperm(parent_bs, child_bs, + is_backing ? "backing" : "file", + &child_of_bds, role, + is_backing ? &parent_bs->backing : + &parent_bs->file, + tran, errp); if (ret < 0) { return ret; } =20 =20 /* - * If backing_hd was already part of bs's backing chain, and - * inherits_from pointed recursively to bs then let's update it to + * If inherits_from pointed recursively to bs then let's update it to * point directly to bs (else it will become NULL). */ if (update_inherits_from) { - bdrv_set_inherits_from(backing_hd, bs, tran); + bdrv_set_inherits_from(child_bs, parent_bs, tran); } =20 out: - bdrv_refresh_limits(bs, tran, NULL); + bdrv_refresh_limits(parent_bs, tran, NULL); =20 return 0; } =20 +static int bdrv_set_backing_noperm(BlockDriverState *bs, + BlockDriverState *backing_hd, + Transaction *tran, Error **errp) +{ + return bdrv_set_file_or_backing_noperm(bs, backing_hd, true, tran, err= p); +} + int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, Error **errp) { --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069648; cv=none; d=zohomail.com; s=zohoarc; b=Mtm/VMFcmK/E1+inuCi5RR0ggYNWmzMbhINu2TmxdEgZXdy+PPMhkiMHPY9EDGlSQ/uH4LuNoeoLCo9HkTmAYzSYyQiSsOlydcs9OnHtOZZlUPl0ZIDM4YlVSSG+yC3kZ1w19hlYSZUjJigsZLXM9ujDwRt4jSf/rslCPZbLJ3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069648; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PfadbdrKuNm1bxZma0g4JjkhulrWWXUAUO0RTqrHdrA=; b=CIETozyTk4/sOYejP/TdieilhRjMLtAb+UMtAE0NCkyE6ZeFC+S8iNZOqYZmNZPcEYBLoE1UW5TTJDT3IfQdFWpeNx+DztegF10PStMmZt4u4AfE64UblJNEJOSu0p7ePPYZWW6T1r8YxX6UXHRpU/PKH1CmFGfj0Qjk191sgig= 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 1625069648198183.4352385611876; Wed, 30 Jun 2021 09:14:08 -0700 (PDT) Received: from localhost ([::1]:40926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycql-0007Cz-Ba for importer@patchew.org; Wed, 30 Jun 2021 12:14:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfT-0002nQ-PF for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39421) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfR-00070v-Um for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:27 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-125-iKeXfzxgORmHFBFwfnIS_Q-1; Wed, 30 Jun 2021 12:02:23 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67D29100C660; Wed, 30 Jun 2021 16:02:21 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72F11604CD; Wed, 30 Jun 2021 16:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PfadbdrKuNm1bxZma0g4JjkhulrWWXUAUO0RTqrHdrA=; b=S04DsJ3985EXvpC1nzTMbxv4eaqry8EryfT49HOfFjFLHMMCOYYL6bk7c+c0eaB/Pk8ckb M9SF2UyxZFkDrYBZdTz1svoF8LF7WbgptcWb91AvdBxc8GLNRIgF+5iQMacb/bWJ/S2xJT EDrTxotabcVE9dkmMwEaAo07XePi0XA= X-MC-Unique: iKeXfzxgORmHFBFwfnIS_Q-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 08/24] block: bdrv_reopen_parse_backing(): don't check aio context Date: Wed, 30 Jun 2021 18:01:50 +0200 Message-Id: <20210630160206.276439-9-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We don't need this check: bdrv_set_backing_noperm() will do it anyway (actually in bdrv_attach_child_common()). Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210610120537.196183-4-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- block.c | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/block.c b/block.c index 14711ce7ab..69dc9d188d 100644 --- a/block.c +++ b/block.c @@ -4215,29 +4215,6 @@ int bdrv_reopen_set_read_only(BlockDriverState *bs, = bool read_only, return ret; } =20 -static bool bdrv_reopen_can_attach(BlockDriverState *parent, - BdrvChild *child, - BlockDriverState *new_child, - Error **errp) -{ - AioContext *parent_ctx =3D bdrv_get_aio_context(parent); - AioContext *child_ctx =3D bdrv_get_aio_context(new_child); - GSList *ignore; - bool ret; - - ignore =3D g_slist_prepend(NULL, child); - ret =3D bdrv_can_set_aio_context(new_child, parent_ctx, &ignore, NULL); - g_slist_free(ignore); - if (ret) { - return ret; - } - - ignore =3D g_slist_prepend(NULL, child); - ret =3D bdrv_can_set_aio_context(parent, child_ctx, &ignore, errp); - g_slist_free(ignore); - return ret; -} - /* * Take a BDRVReopenState and check if the value of 'backing' in the * reopen_state->options QDict is valid or not. @@ -4289,16 +4266,6 @@ static int bdrv_reopen_parse_backing(BDRVReopenState= *reopen_state, g_assert_not_reached(); } =20 - /* - * Check AioContext compatibility so that the bdrv_set_backing_hd() ca= ll in - * bdrv_reopen_commit() won't fail. - */ - if (new_backing_bs) { - if (!bdrv_reopen_can_attach(bs, bs->backing, new_backing_bs, errp)= ) { - return -EINVAL; - } - } - /* * Ensure that @bs can really handle backing files, because we are * about to give it one (or swap the existing one) --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069626; cv=none; d=zohomail.com; s=zohoarc; b=SFbJw0hZu1lULT4sA7YOpINu6HLp9WQtUbFN3fLCKBc5GzrSPISBxlnPNf3kQSYMV623p6HCMGn8BHoAPqKwe4hrjR/Rj7+fNK/sJOBSQlfHzisL//BuohgmMb/dg1cAvf+Cpzib7nFIenoq98GPkAvyn8eeLz5iEsxhd85TZE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069626; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PBl2DzOdzlR78uhIEDr+i4e/y0olLuP4GBtsWtC9/0Y=; b=jDSwsCvlV04KdgdsE0t3EGSXbD931d9PUd6dyd4Ion9zN/049DKx6sD73ufeYZvoDydIfbfF/12DV50+L7+xMpc3gYeLz5EJzB9XrRGkSNIb5qvKNfr1A3U8Uz8hXMw5dMBJI1ohDxr3amZYSxLzykuvvhEdTZhBOi0a4DxQYgM= 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 1625069626511204.75189930481986; Wed, 30 Jun 2021 09:13:46 -0700 (PDT) Received: from localhost ([::1]:39420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycqP-0006BR-PM for importer@patchew.org; Wed, 30 Jun 2021 12:13:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfj-0002vS-PN for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23478) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfT-00071q-7l for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:40 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-455-L-dMBxQnOQ2BuNWc7AeOHw-1; Wed, 30 Jun 2021 12:02:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1D78804141; Wed, 30 Jun 2021 16:02:22 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF0F6189C7; Wed, 30 Jun 2021 16:02:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PBl2DzOdzlR78uhIEDr+i4e/y0olLuP4GBtsWtC9/0Y=; b=R82x5D1C1Bi2QcjqcIL8zCrkTeLEYaNmCUpVFxeL5mA5vCPXLT1F6ujGunmMieYbcH87md Rcx1fcF9bwygnFW+11mF4jmZHyrobLLZmB95w8+CQsLTGPiZweztG0R8UM9FLlzx5w9KoG MhZcfxpfiYCU97R/2ELDJ0LaJXJJhT0= X-MC-Unique: L-dMBxQnOQ2BuNWc7AeOHw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 09/24] block: bdrv_reopen_parse_backing(): don't check frozen child Date: Wed, 30 Jun 2021 18:01:51 +0200 Message-Id: <20210630160206.276439-10-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy bdrv_set_backing_noperm() takes care of it (actual check is in bdrv_set_file_or_backing_noperm()), so we don't need to check it here. While being here, improve error message a bit. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210610120537.196183-5-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- block.c | 14 +------------- tests/qemu-iotests/245 | 8 ++++---- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/block.c b/block.c index 69dc9d188d..6472866283 100644 --- a/block.c +++ b/block.c @@ -4308,19 +4308,7 @@ static int bdrv_reopen_parse_backing(BDRVReopenState= *reopen_state, "an implicit backing file", bs->node_name); return -EPERM; } - /* - * Check if the backing link that we want to replace is frozen. - * Note that - * bdrv_filter_or_cow_child(overlay_bs) =3D=3D overlay_bs->backing, - * because we know that overlay_bs =3D=3D bs, and that @bs - * either is a filter that uses ->backing or a COW format BDS - * with bs->drv->supports_backing =3D=3D true. - */ - if (bdrv_is_backing_chain_frozen(overlay_bs, - child_bs(overlay_bs->backing), er= rp)) - { - return -EPERM; - } + reopen_state->replace_backing_bs =3D true; reopen_state->old_backing_bs =3D bs->backing ? bs->backing->bs : N= ULL; ret =3D bdrv_set_backing_noperm(bs, new_backing_bs, set_backings_t= ran, diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 index fc5297e268..c7d671366a 100755 --- a/tests/qemu-iotests/245 +++ b/tests/qemu-iotests/245 @@ -878,7 +878,7 @@ class TestBlockdevReopen(iotests.QMPTestCase): =20 # We can't remove hd1 while the stream job is ongoing opts['backing'] =3D None - self.reopen(opts, {}, "Cannot change 'backing' link from 'hd0' to = 'hd1'") + self.reopen(opts, {}, "Cannot change frozen 'backing' link from 'h= d0' to 'hd1'") =20 self.vm.run_job('stream0', auto_finalize =3D False, auto_dismiss = =3D True) =20 @@ -910,7 +910,7 @@ class TestBlockdevReopen(iotests.QMPTestCase): # We can't remove hd2 while the stream job is ongoing opts['backing']['backing'] =3D None self.reopen(opts['backing'], {'read-only': False}, - "Cannot change 'backing' link from 'hd1' to 'hd2'") + "Cannot change frozen 'backing' link from 'hd1' to 'hd= 2'") =20 # We can detach hd1 from hd0 because it doesn't affect the stream = job opts['backing'] =3D None @@ -933,11 +933,11 @@ class TestBlockdevReopen(iotests.QMPTestCase): =20 # We can't remove hd2 while the commit job is ongoing opts['backing']['backing'] =3D None - self.reopen(opts, {}, "Cannot change 'backing' link from 'hd1' to = 'hd2'") + self.reopen(opts, {}, "Cannot change frozen 'backing' link from 'h= d1' to 'hd2'") =20 # We can't remove hd1 while the commit job is ongoing opts['backing'] =3D None - self.reopen(opts, {}, "Cannot change 'backing' link from 'hd0' to = 'hd1'") + self.reopen(opts, {}, "Cannot change frozen 'backing' link from 'h= d0' to 'hd1'") =20 event =3D self.vm.event_wait(name=3D'BLOCK_JOB_READY') self.assert_qmp(event, 'data/device', 'commit0') --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069770; cv=none; d=zohomail.com; s=zohoarc; b=fahlqHk3wlcZKct0o0fajvQoMwErMdEC7N6xTJFOlA2OM7Kv+THVEnSSuTNjXUGNRxTrQoPPOGIyeSc8QP8cJm/YyM7rqVWu0cdWxbC9EovqTWFaBWgLBa171LshjcW/eGwXmjjUbRNvqGov3IOZf6jvzS5XR+pmufkxVLT/C0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069770; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EJQnL7sDNEh3cUuLLgYudcyp4Qjd7GjnLgEdQDqKhKg=; b=KS6hk+k946p1RZL/QuGr0MCy+CyI/WL3PEthe+aNLgQHVIAtCbMLOBfs0l8Dh45zd6/BiNriQw1XHD0A1Dds1wALgliQFOY0wVrGHlV9nDlImlsfG8v5CPCaNtt0YUJ8OjajzUgBC0mncCm+micwdxBJRaVSBGRwiNgf1xRSKOo= 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 1625069770301900.6442906808547; Wed, 30 Jun 2021 09:16:10 -0700 (PDT) Received: from localhost ([::1]:45876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycsj-00023w-3Q for importer@patchew.org; Wed, 30 Jun 2021 12:16:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfl-0002w1-KZ for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55310) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfV-00073d-F4 for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-249-a_aUIjWTPeivHc1AsqaBxQ-1; Wed, 30 Jun 2021 12:02:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC26F100C665; Wed, 30 Jun 2021 16:02:23 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8A36604CD; Wed, 30 Jun 2021 16:02:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EJQnL7sDNEh3cUuLLgYudcyp4Qjd7GjnLgEdQDqKhKg=; b=Er0tpvlRLCqoSjcvmE9jIM6mySKDip5vD3O9agjW6Xp9emO03dqn/5FDo8fioCoeS0+z0G u77AZeqlN6pX8E6ZO4pyZ/2D9Xu08H8goGwtxDYRn1Fx0wMY0Y5dux/caDwYusqBxqSM9M aUFoVCKzw201LE7IfefSJEwpzt/bYHA= X-MC-Unique: a_aUIjWTPeivHc1AsqaBxQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 10/24] block: bdrv_reopen_parse_backing(): simplify handling implicit filters Date: Wed, 30 Jun 2021 18:01:52 +0200 Message-Id: <20210630160206.276439-11-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy The logic around finding overlay here is not obvious. Actually it does two simple things: 1. If new bs is already in backing chain, split from parent bs by several implicit filters we are done, do nothing. 2. Otherwise, don't try to replace implicit filter. Let's rewrite this in more obvious way. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210610120537.196183-6-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- block.c | 53 ++++++++++++++++------------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/block.c b/block.c index 6472866283..d047cae43c 100644 --- a/block.c +++ b/block.c @@ -4237,7 +4237,7 @@ static int bdrv_reopen_parse_backing(BDRVReopenState = *reopen_state, Error **errp) { BlockDriverState *bs =3D reopen_state->bs; - BlockDriverState *overlay_bs, *below_bs, *new_backing_bs; + BlockDriverState *new_backing_bs; QObject *value; const char *str; =20 @@ -4266,6 +4266,18 @@ static int bdrv_reopen_parse_backing(BDRVReopenState= *reopen_state, g_assert_not_reached(); } =20 + if (bs->backing) { + if (bdrv_skip_implicit_filters(bs->backing->bs) =3D=3D new_backing= _bs) { + return 0; + } + + if (bs->backing->bs->implicit) { + error_setg(errp, "Cannot change backing link if '%s' has " + "an implicit backing file", bs->node_name); + return -EPERM; + } + } + /* * Ensure that @bs can really handle backing files, because we are * about to give it one (or swap the existing one) @@ -4283,42 +4295,9 @@ static int bdrv_reopen_parse_backing(BDRVReopenState= *reopen_state, return -EINVAL; } =20 - /* - * Find the "actual" backing file by skipping all links that point - * to an implicit node, if any (e.g. a commit filter node). - * We cannot use any of the bdrv_skip_*() functions here because - * those return the first explicit node, while we are looking for - * its overlay here. - */ - overlay_bs =3D bs; - for (below_bs =3D bdrv_filter_or_cow_bs(overlay_bs); - below_bs && below_bs->implicit; - below_bs =3D bdrv_filter_or_cow_bs(overlay_bs)) - { - overlay_bs =3D below_bs; - } - - /* If we want to replace the backing file we need some extra checks */ - if (new_backing_bs !=3D bdrv_filter_or_cow_bs(overlay_bs)) { - int ret; - - /* Check for implicit nodes between bs and its backing file */ - if (bs !=3D overlay_bs) { - error_setg(errp, "Cannot change backing link if '%s' has " - "an implicit backing file", bs->node_name); - return -EPERM; - } - - reopen_state->replace_backing_bs =3D true; - reopen_state->old_backing_bs =3D bs->backing ? bs->backing->bs : N= ULL; - ret =3D bdrv_set_backing_noperm(bs, new_backing_bs, set_backings_t= ran, - errp); - if (ret < 0) { - return ret; - } - } - - return 0; + reopen_state->replace_backing_bs =3D true; + reopen_state->old_backing_bs =3D bs->backing ? bs->backing->bs : NULL; + return bdrv_set_backing_noperm(bs, new_backing_bs, set_backings_tran, = errp); } =20 /* --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069809; cv=none; d=zohomail.com; s=zohoarc; b=ZCshYjFZUJD0NxR3kRIbYpWXYmwNUjQjGVEjjqQSewitpeoqfkg9RJ3n4sCs7NP7sYKEYrVs2p0zL/NKKoYUHcbrsPaW7zxjXgJWd4KaVgAtSP7lJDDi7vY42nRBG5UrUOXnRTqaeUy5hKMavyGCIK0aSTngguB2ve9pCr46yTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069809; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MsrqUz9pWC7EX6rdkWNpOOzj3UDDlO0RZ2Ve9nuG+KM=; b=c2O56qkSS4qPCWZFpnyrEnCj8bZ9Y7cj8K/jfRaYkSIDQHj4E/NqTOOdFdg7wvp76sxEY9a7CAWI5UUiQpqS4LXgpE2YhqnY2KxPLrzb9OeXfp/mNMka47w+YFR97Ruc6oDp70Z4RHmOR7tX8Lx3t1WyJy5UV7edePwMHF6X/tE= 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 1625069809681938.8330643708599; Wed, 30 Jun 2021 09:16:49 -0700 (PDT) Received: from localhost ([::1]:47396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyctL-0003Ap-KX for importer@patchew.org; Wed, 30 Jun 2021 12:16:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfj-0002vT-R7 for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfV-00073E-AJ for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:43 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-371-7pWkFsIjMR2_Q_liranYtg-1; Wed, 30 Jun 2021 12:02:26 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3531AA40CB; Wed, 30 Jun 2021 16:02:25 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30468189C7; Wed, 30 Jun 2021 16:02:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MsrqUz9pWC7EX6rdkWNpOOzj3UDDlO0RZ2Ve9nuG+KM=; b=EdUV4H/EeG1eyXt9kvUC2n4mgJwvzN3PcEdLj/tTNFZcLPRO0uiK0BRZm7ffNuzecuumO9 W2nKhJDBtFID01ecIHdT2Vc5CEE47VYqy2rFOHt6Emgue3xJpQidPshoCrNbk9Iawz166X M5lstAblViv5ZK+KcfYcZwwnXyt5BJI= X-MC-Unique: 7pWkFsIjMR2_Q_liranYtg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 11/24] block: move supports_backing check to bdrv_set_file_or_backing_noperm() Date: Wed, 30 Jun 2021 18:01:53 +0200 Message-Id: <20210630160206.276439-12-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Move supports_backing check of bdrv_reopen_parse_backing to called (through bdrv_set_backing_noperm()) bdrv_set_file_or_backing_noperm() function. The check applies to general case, so it's appropriate for bdrv_set_file_or_backing_noperm(). We have to declare backing support for two test drivers, otherwise new check fails. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210610120537.196183-7-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- block.c | 29 +++++++++++++++-------------- tests/unit/test-bdrv-drain.c | 1 + tests/unit/test-bdrv-graph-mod.c | 1 + 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index d047cae43c..0a73335380 100644 --- a/block.c +++ b/block.c @@ -3152,6 +3152,14 @@ static int bdrv_set_file_or_backing_noperm(BlockDriv= erState *parent_bs, return -EPERM; } =20 + if (is_backing && !parent_bs->drv->is_filter && + !parent_bs->drv->supports_backing) + { + error_setg(errp, "Driver '%s' of node '%s' does not support backin= g " + "files", parent_bs->drv->format_name, parent_bs->node_n= ame); + return -EINVAL; + } + if (parent_bs->drv->is_filter) { role =3D BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY; } else if (is_backing) { @@ -4278,20 +4286,13 @@ static int bdrv_reopen_parse_backing(BDRVReopenStat= e *reopen_state, } } =20 - /* - * Ensure that @bs can really handle backing files, because we are - * about to give it one (or swap the existing one) - */ - if (bs->drv->is_filter) { - /* Filters always have a file or a backing child */ - if (!bs->backing) { - error_setg(errp, "'%s' is a %s filter node that does not suppo= rt a " - "backing child", bs->node_name, bs->drv->format_nam= e); - return -EINVAL; - } - } else if (!bs->drv->supports_backing) { - error_setg(errp, "Driver '%s' of node '%s' does not support backin= g " - "files", bs->drv->format_name, bs->node_name); + if (bs->drv->is_filter && !bs->backing) { + /* + * Filters always have a file or a backing child, so we are trying= to + * change wrong child + */ + error_setg(errp, "'%s' is a %s filter node that does not support a= " + "backing child", bs->node_name, bs->drv->format_name); return -EINVAL; } =20 diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 892f7f47d8..ce071b5fc5 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -95,6 +95,7 @@ static int bdrv_test_change_backing_file(BlockDriverState= *bs, static BlockDriver bdrv_test =3D { .format_name =3D "test", .instance_size =3D sizeof(BDRVTestState), + .supports_backing =3D true, =20 .bdrv_close =3D bdrv_test_close, .bdrv_co_preadv =3D bdrv_test_co_preadv, diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-= mod.c index 88f25c0cdb..a6e3bb79be 100644 --- a/tests/unit/test-bdrv-graph-mod.c +++ b/tests/unit/test-bdrv-graph-mod.c @@ -41,6 +41,7 @@ static void no_perm_default_perms(BlockDriverState *bs, B= drvChild *c, =20 static BlockDriver bdrv_no_perm =3D { .format_name =3D "no-perm", + .supports_backing =3D true, .bdrv_child_perm =3D no_perm_default_perms, }; =20 --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069765; cv=none; d=zohomail.com; s=zohoarc; b=O4MBLoBo++FVUY10E1AL2wmYiPzek4RLk6VD31QfCeipR8XsnVILE8OvOhPCCyM1fld6mXswkXKsF8XNHmSSSbIG/FWHjSbZnA5t7T9hdPSAM0WBZQOiaT6RSC1Fzd/B2dwqzCdVO5tfC/U50DqccvSjITlWoENSX8s2S1lqn6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069765; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fu1fJvLMjQVman1pVaxRT/tGA4ZJ0E7xnvhdnOGg5nM=; b=TO4044sYJO6nZu/usCErqTjhMbZT5b8f8483GMq618w3DHjTnkDi6HvDtn+0CXtBYR6ZTICwQPCr/ybI2i/TRsHhG6VXJi9ZWmRUZSaVsFDYJhSAeg1SE+4IpaRk0grRFberQW+xeV+f016k3qdcstGcjLYhyr39Dldf+3VTrNk= 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 1625069765233637.2951909131667; Wed, 30 Jun 2021 09:16:05 -0700 (PDT) Received: from localhost ([::1]:45570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycse-0001rA-EL for importer@patchew.org; Wed, 30 Jun 2021 12:16:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfo-0002wE-9f for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfX-000746-3a for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-182-YfJMixDfMO24UwQATGkm3A-1; Wed, 30 Jun 2021 12:02:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79BE6100C661; Wed, 30 Jun 2021 16:02:26 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AA62604CD; Wed, 30 Jun 2021 16:02:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068949; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fu1fJvLMjQVman1pVaxRT/tGA4ZJ0E7xnvhdnOGg5nM=; b=OvxTeh92PQMQzaz63+67MWfKlnCHewum037iJEs2MasroUpJRZ5mLJvcn2uMFVL0iRsYTE nb/K5QeKNS4ngeUWRnKRzNMN8HEG0ivB4g9NPc8ffjwUfl4vKg8ZZlYMmIBYhZdXhFHfjB fzCbSTAywjH7I9z4qjEeonoZAGTZ6qs= X-MC-Unique: YfJMixDfMO24UwQATGkm3A-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 12/24] block: BDRVReopenState: drop replace_backing_bs field Date: Wed, 30 Jun 2021 18:01:54 +0200 Message-Id: <20210630160206.276439-13-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy It's used only in bdrv_reopen_commit(). "backing" is covered by the loop through all children except for case when we removed backing child during reopen. Make it more obvious and drop extra boolean field: qdict_del will not fail if there is no such entry. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210610120537.196183-8-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- include/block/block.h | 1 - block.c | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 8e707a83b7..d28022e761 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -208,7 +208,6 @@ typedef struct BDRVReopenState { int flags; BlockdevDetectZeroesOptions detect_zeroes; bool backing_missing; - bool replace_backing_bs; /* new_backing_bs is ignored if this is fals= e */ BlockDriverState *old_backing_bs; /* keep pointer for permissions upda= te */ QDict *options; QDict *explicit_options; diff --git a/block.c b/block.c index 0a73335380..ca11078cd2 100644 --- a/block.c +++ b/block.c @@ -4296,7 +4296,6 @@ static int bdrv_reopen_parse_backing(BDRVReopenState = *reopen_state, return -EINVAL; } =20 - reopen_state->replace_backing_bs =3D true; reopen_state->old_backing_bs =3D bs->backing ? bs->backing->bs : NULL; return bdrv_set_backing_noperm(bs, new_backing_bs, set_backings_tran, = errp); } @@ -4550,17 +4549,16 @@ static void bdrv_reopen_commit(BDRVReopenState *reo= pen_state) bs->open_flags =3D reopen_state->flags; bs->detect_zeroes =3D reopen_state->detect_zeroes; =20 - if (reopen_state->replace_backing_bs) { - qdict_del(bs->explicit_options, "backing"); - qdict_del(bs->options, "backing"); - } - /* Remove child references from bs->options and bs->explicit_options. * Child options were already removed in bdrv_reopen_queue_child() */ QLIST_FOREACH(child, &bs->children, next) { qdict_del(bs->explicit_options, child->name); qdict_del(bs->options, child->name); } + /* backing is probably removed, so it's not handled by previous loop */ + qdict_del(bs->explicit_options, "backing"); + qdict_del(bs->options, "backing"); + bdrv_refresh_limits(bs, NULL, NULL); } =20 --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625069986; cv=none; d=zohomail.com; s=zohoarc; b=iY/pQTF27lesI1e1wohDpOKPgzim0Qi+bVXqyGSf/ID2tmxCxCmHUOXx/FpdrRigfRlRYKwys0x1h/YiFICazQHpxDV7K1AzmywldIwpgnr0jK/2g7WXkxYNydzCVV2J7TvGM90RLZppOi8I4o2DLKhxSciNwy1i72le/WsjTkc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625069986; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wyMTrpENnrhLwjLQlRcHMny1rIjUqH3gRWS7kOwrfjg=; b=oLrk9GpfO4jsE9HOcCYwMOSXJP5glyqIOPtfQDxSqfd87GBz35UnqeUX7c8eQFQ1tJTrPMkw4SekT7oYCiBSvCYJPUkc8w8gM9EMw6jBc04zqiqG/VzppRmP1Z4zpUt9y+BMps9PwpyJnY4guMXyQHL3EX2yaF9D24N5Sudrblc= 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 1625069986980847.778904533059; Wed, 30 Jun 2021 09:19:46 -0700 (PDT) Received: from localhost ([::1]:53416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycwE-0007Of-7n for importer@patchew.org; Wed, 30 Jun 2021 12:19:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfs-0002yn-6O for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24419) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfa-00075T-5U for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-176-zaJswWdtPQ67Z7yyWDvLAA-1; Wed, 30 Jun 2021 12:02:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 99A5D1835AC4; Wed, 30 Jun 2021 16:02:27 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6C726E0B9; Wed, 30 Jun 2021 16:02:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wyMTrpENnrhLwjLQlRcHMny1rIjUqH3gRWS7kOwrfjg=; b=NApg4JF31KRD5bXGvS+EsM/IJ2GAYavLpF2HKiEgdWSKteXULZ/vdFNxlnVrokCPKTHbUv K28iqSSlcbhMLENXHHMC4tGf119RDNlFwDed/mjGg6B5VGOL7cnRwSvAdp66/10CSxcxQn TYnHRUHbjVaU/EDgvyCM1oscqcD4wy8= X-MC-Unique: zaJswWdtPQ67Z7yyWDvLAA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 13/24] block: Allow changing bs->file on reopen Date: Wed, 30 Jun 2021 18:01:55 +0200 Message-Id: <20210630160206.276439-14-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Alberto Garcia When the x-blockdev-reopen was added it allowed reconfiguring the graph by replacing backing files, but changing the 'file' option was forbidden. Because of this restriction some operations are not possible, notably inserting and removing block filters. This patch adds support for replacing the 'file' option. This is similar to replacing the backing file and the user is likewise responsible for the correctness of the resulting graph, otherwise this can lead to data corruption. Signed-off-by: Alberto Garcia [vsementsov: bdrv_reopen_parse_file_or_backing() is modified a lot] Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210610120537.196183-9-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- include/block/block.h | 1 + block.c | 78 +++++++++++++++++++++++++++++------------- tests/qemu-iotests/245 | 23 +++++++------ 3 files changed, 67 insertions(+), 35 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index d28022e761..7ec77ecb1a 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -209,6 +209,7 @@ typedef struct BDRVReopenState { BlockdevDetectZeroesOptions detect_zeroes; bool backing_missing; BlockDriverState *old_backing_bs; /* keep pointer for permissions upda= te */ + BlockDriverState *old_file_bs; /* keep pointer for permissions update = */ QDict *options; QDict *explicit_options; void *opaque; diff --git a/block.c b/block.c index ca11078cd2..acd35cb0cb 100644 --- a/block.c +++ b/block.c @@ -92,7 +92,7 @@ static void bdrv_remove_filter_or_cow_child(BlockDriverSt= ate *bs, =20 static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, - Transaction *set_backings_tran, Error **err= p); + Transaction *change_child_tran, Error **err= p); static void bdrv_reopen_commit(BDRVReopenState *reopen_state); static void bdrv_reopen_abort(BDRVReopenState *reopen_state); =20 @@ -4148,6 +4148,10 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue,= Error **errp) refresh_list =3D bdrv_topological_dfs(refresh_list, found, state->old_backing_bs); } + if (state->old_file_bs) { + refresh_list =3D bdrv_topological_dfs(refresh_list, found, + state->old_file_bs); + } } =20 /* @@ -4240,64 +4244,81 @@ int bdrv_reopen_set_read_only(BlockDriverState *bs,= bool read_only, * * Return 0 on success, otherwise return < 0 and set @errp. */ -static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state, - Transaction *set_backings_tran, - Error **errp) +static int bdrv_reopen_parse_file_or_backing(BDRVReopenState *reopen_state, + bool is_backing, Transaction = *tran, + Error **errp) { BlockDriverState *bs =3D reopen_state->bs; - BlockDriverState *new_backing_bs; + BlockDriverState *new_child_bs; + BlockDriverState *old_child_bs =3D is_backing ? child_bs(bs->backing) : + child_bs(bs->file); + const char *child_name =3D is_backing ? "backing" : "file"; QObject *value; const char *str; =20 - value =3D qdict_get(reopen_state->options, "backing"); + value =3D qdict_get(reopen_state->options, child_name); if (value =3D=3D NULL) { return 0; } =20 switch (qobject_type(value)) { case QTYPE_QNULL: - new_backing_bs =3D NULL; + assert(is_backing); /* The 'file' option does not allow a null val= ue */ + new_child_bs =3D NULL; break; case QTYPE_QSTRING: str =3D qstring_get_str(qobject_to(QString, value)); - new_backing_bs =3D bdrv_lookup_bs(NULL, str, errp); - if (new_backing_bs =3D=3D NULL) { + new_child_bs =3D bdrv_lookup_bs(NULL, str, errp); + if (new_child_bs =3D=3D NULL) { return -EINVAL; - } else if (bdrv_recurse_has_child(new_backing_bs, bs)) { - error_setg(errp, "Making '%s' a backing file of '%s' " - "would create a cycle", str, bs->node_name); + } else if (bdrv_recurse_has_child(new_child_bs, bs)) { + error_setg(errp, "Making '%s' a %s child of '%s' would create = a " + "cycle", str, child_name, bs->node_name); return -EINVAL; } break; default: - /* 'backing' does not allow any other data type */ + /* + * The options QDict has been flattened, so 'backing' and 'file' + * do not allow any other data type here. + */ g_assert_not_reached(); } =20 - if (bs->backing) { - if (bdrv_skip_implicit_filters(bs->backing->bs) =3D=3D new_backing= _bs) { + if (old_child_bs =3D=3D new_child_bs) { + return 0; + } + + if (old_child_bs) { + if (bdrv_skip_implicit_filters(old_child_bs) =3D=3D new_child_bs) { return 0; } =20 - if (bs->backing->bs->implicit) { - error_setg(errp, "Cannot change backing link if '%s' has " - "an implicit backing file", bs->node_name); + if (old_child_bs->implicit) { + error_setg(errp, "Cannot replace implicit %s child of %s", + child_name, bs->node_name); return -EPERM; } } =20 - if (bs->drv->is_filter && !bs->backing) { + if (bs->drv->is_filter && !old_child_bs) { /* * Filters always have a file or a backing child, so we are trying= to * change wrong child */ error_setg(errp, "'%s' is a %s filter node that does not support a= " - "backing child", bs->node_name, bs->drv->format_name); + "%s child", bs->node_name, bs->drv->format_name, child_= name); return -EINVAL; } =20 - reopen_state->old_backing_bs =3D bs->backing ? bs->backing->bs : NULL; - return bdrv_set_backing_noperm(bs, new_backing_bs, set_backings_tran, = errp); + if (is_backing) { + reopen_state->old_backing_bs =3D old_child_bs; + } else { + reopen_state->old_file_bs =3D old_child_bs; + } + + return bdrv_set_file_or_backing_noperm(bs, new_child_bs, is_backing, + tran, errp); } =20 /* @@ -4319,7 +4340,7 @@ static int bdrv_reopen_parse_backing(BDRVReopenState = *reopen_state, */ static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, - Transaction *set_backings_tran, Error **err= p) + Transaction *change_child_tran, Error **err= p) { int ret =3D -1; int old_flags; @@ -4439,12 +4460,21 @@ static int bdrv_reopen_prepare(BDRVReopenState *reo= pen_state, * either a reference to an existing node (using its node name) * or NULL to simply detach the current backing file. */ - ret =3D bdrv_reopen_parse_backing(reopen_state, set_backings_tran, err= p); + ret =3D bdrv_reopen_parse_file_or_backing(reopen_state, true, + change_child_tran, errp); if (ret < 0) { goto error; } qdict_del(reopen_state->options, "backing"); =20 + /* Allow changing the 'file' option. In this case NULL is not allowed = */ + ret =3D bdrv_reopen_parse_file_or_backing(reopen_state, false, + change_child_tran, errp); + if (ret < 0) { + goto error; + } + qdict_del(reopen_state->options, "file"); + /* Options that are not handled are only okay if they are unchanged * compared to the old state. It is expected that some options are only * used for the initial open, but not reopen (e.g. filename) */ diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 index c7d671366a..d955e0dfd3 100755 --- a/tests/qemu-iotests/245 +++ b/tests/qemu-iotests/245 @@ -146,8 +146,8 @@ class TestBlockdevReopen(iotests.QMPTestCase): self.reopen(opts, {'driver': 'raw'}, "Cannot change the option 'dr= iver'") self.reopen(opts, {'driver': ''}, "Invalid parameter ''") self.reopen(opts, {'driver': None}, "Invalid parameter type for 'd= river', expected: string") - self.reopen(opts, {'file': 'not-found'}, "Cannot change the option= 'file'") - self.reopen(opts, {'file': ''}, "Cannot change the option 'file'") + self.reopen(opts, {'file': 'not-found'}, "Cannot find device=3D'' = nor node-name=3D'not-found'") + self.reopen(opts, {'file': ''}, "Cannot find device=3D'' nor node-= name=3D''") self.reopen(opts, {'file': None}, "Invalid parameter type for 'fil= e', expected: BlockdevRef") self.reopen(opts, {'file.node-name': 'newname'}, "Cannot change th= e option 'node-name'") self.reopen(opts, {'file.driver': 'host_device'}, "Cannot change t= he option 'driver'") @@ -443,7 +443,7 @@ class TestBlockdevReopen(iotests.QMPTestCase): =20 # Illegal operation: hd2 is a child of hd1 self.reopen(opts[2], {'backing': 'hd1'}, - "Making 'hd1' a backing file of 'hd2' would create a c= ycle") + "Making 'hd1' a backing child of 'hd2' would create a = cycle") =20 # hd2 <- hd0, hd2 <- hd1 self.reopen(opts[0], {'backing': 'hd2'}) @@ -454,8 +454,9 @@ class TestBlockdevReopen(iotests.QMPTestCase): =20 # More illegal operations self.reopen(opts[2], {'backing': 'hd1'}, - "Making 'hd1' a backing file of 'hd2' would create a c= ycle") - self.reopen(opts[2], {'file': 'hd0-file'}, "Cannot change the opti= on 'file'") + "Making 'hd1' a backing child of 'hd2' would create a = cycle") + self.reopen(opts[2], {'file': 'hd0-file'}, + "Permission conflict on node 'hd0-file': permissions '= write, resize' are both required by node 'hd0' (uses node 'hd0-file' as 'fi= le' child) and unshared by node 'hd2' (uses node 'hd0-file' as 'file' child= ).") =20 result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd2') self.assert_qmp(result, 'error/class', 'GenericError') @@ -497,18 +498,18 @@ class TestBlockdevReopen(iotests.QMPTestCase): =20 # Illegal: hd2 is backed by hd1 self.reopen(opts[1], {'backing': 'hd2'}, - "Making 'hd2' a backing file of 'hd1' would create a c= ycle") + "Making 'hd2' a backing child of 'hd1' would create a = cycle") =20 # hd1 <- hd0 <- hd2 self.reopen(opts[2], {'backing': 'hd0'}) =20 # Illegal: hd2 is backed by hd0, which is backed by hd1 self.reopen(opts[1], {'backing': 'hd2'}, - "Making 'hd2' a backing file of 'hd1' would create a c= ycle") + "Making 'hd2' a backing child of 'hd1' would create a = cycle") =20 # Illegal: hd1 cannot point to itself self.reopen(opts[1], {'backing': 'hd1'}, - "Making 'hd1' a backing file of 'hd1' would create a c= ycle") + "Making 'hd1' a backing child of 'hd1' would create a = cycle") =20 # Remove all backing files self.reopen(opts[0]) @@ -530,7 +531,7 @@ class TestBlockdevReopen(iotests.QMPTestCase): =20 # Illegal: hd0 is a child of the blkverify node self.reopen(opts[0], {'backing': 'bv'}, - "Making 'bv' a backing file of 'hd0' would create a cy= cle") + "Making 'bv' a backing child of 'hd0' would create a c= ycle") =20 # Delete the blkverify node result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'bv') @@ -563,7 +564,7 @@ class TestBlockdevReopen(iotests.QMPTestCase): # You can't make quorum0 a backing file of hd0: # hd0 is already a child of quorum0. self.reopen(hd_opts(0), {'backing': 'quorum0'}, - "Making 'quorum0' a backing file of 'hd0' would create= a cycle") + "Making 'quorum0' a backing child of 'hd0' would creat= e a cycle") =20 # Delete quorum0 result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'quorum0') @@ -969,7 +970,7 @@ class TestBlockdevReopen(iotests.QMPTestCase): =20 # We can't remove hd1 while the commit job is ongoing opts['backing'] =3D None - self.reopen(opts, {}, "Cannot change backing link if 'hd0' has an = implicit backing file") + self.reopen(opts, {}, "Cannot replace implicit backing child of hd= 0") =20 # hd2 <- hd0 self.vm.run_job('commit0', auto_finalize =3D False, auto_dismiss = =3D True) --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070137; cv=none; d=zohomail.com; s=zohoarc; b=GdUA/rnbTTZ1TrbV5jdIBLCMut8uoDCfTgAgZZr3irrO9+DXooykwRdVTmUwTnfn47bgcQD2jEQojoQRIkVBct3iPViPY4NVDxguWYek9NtPWn6LmfssBdT2aITDVEUdIpVJY/30XbwFEdIkHJBuhYVyz/lT/FqskBRLYvzlX9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070137; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CJKTkTZ4uMQcizttwS9+dN21D02u2uEK+7NsYrSQPVg=; b=QgdmbnZwjPEORcWxkNWbQGgTUmGnnWSxxALIoCbynSieJ6p2iYf98ATTfG7VQoKfcCjuHsq5W001bE5C6mHxbx5j7QoOfEZV/gm9Nwr6suPZK9d5wvEiNkEjyC2qxqj8UA9jtZIEl/vah27HhdPxk4Le+Qi9aqBlVneDw8xpPRg= 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 1625070137634587.0441423236841; Wed, 30 Jun 2021 09:22:17 -0700 (PDT) Received: from localhost ([::1]:60034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycye-0003UQ-IF for importer@patchew.org; Wed, 30 Jun 2021 12:22:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycft-0002zA-Ov for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60936) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfa-00076D-5n for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:53 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-523-BaHIyJ2HPJWg7rLBdtdqPw-1; Wed, 30 Jun 2021 12:02:30 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D54D0800D55; Wed, 30 Jun 2021 16:02:28 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id E21D8604CD; Wed, 30 Jun 2021 16:02:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CJKTkTZ4uMQcizttwS9+dN21D02u2uEK+7NsYrSQPVg=; b=DD0J37VfephsLiC2O0X/s1YFpBMTWYI5alyN8hr/YSfTK5bhEMUa4QmiYBy7P/p8zC3AJN FduF7RZkoXOHAZ0suExXeX84N8GQfsEbvhxuQL1WK6XdX11nkCCDotI5ONtOsCVF9SDBQ4 uPkaq5A7ROFdOSGhbl2wYwLDy9gKtm4= X-MC-Unique: BaHIyJ2HPJWg7rLBdtdqPw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 14/24] iotests: Test replacing files with x-blockdev-reopen Date: Wed, 30 Jun 2021 18:01:56 +0200 Message-Id: <20210630160206.276439-15-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Alberto Garcia This patch adds new tests in which we use x-blockdev-reopen to change bs->file Signed-off-by: Alberto Garcia Message-Id: <20210610120537.196183-10-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- tests/qemu-iotests/245 | 109 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/245.out | 11 +++- 2 files changed, 117 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 index d955e0dfd3..0295129cbb 100755 --- a/tests/qemu-iotests/245 +++ b/tests/qemu-iotests/245 @@ -79,7 +79,7 @@ class TestBlockdevReopen(iotests.QMPTestCase): for line in log.split("\n"): if line.startswith("Pattern verification failed"): raise Exception("%s (command #%d)" % (line, found)) - if re.match("read .*/.* bytes at offset", line): + if re.match("(read|wrote) .*/.* bytes at offset", line): found +=3D 1 self.assertEqual(found, self.total_io_cmds, "Expected output of %d qemu-io commands, found %d= " % @@ -537,6 +537,113 @@ class TestBlockdevReopen(iotests.QMPTestCase): result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'bv') self.assert_qmp(result, 'return', {}) =20 + # Replace the protocol layer ('file' parameter) of a disk image + def test_replace_file(self): + # Create two small raw images and add them to a running VM + qemu_img('create', '-f', 'raw', hd_path[0], '10k') + qemu_img('create', '-f', 'raw', hd_path[1], '10k') + + hd0_opts =3D {'driver': 'file', 'node-name': 'hd0-file', 'filename= ': hd_path[0] } + hd1_opts =3D {'driver': 'file', 'node-name': 'hd1-file', 'filename= ': hd_path[1] } + + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **hd0_= opts) + self.assert_qmp(result, 'return', {}) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **hd1_= opts) + self.assert_qmp(result, 'return', {}) + + # Add a raw format layer that uses hd0-file as its protocol layer + opts =3D {'driver': 'raw', 'node-name': 'hd', 'file': 'hd0-file'} + + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # Fill the image with data + self.run_qemu_io("hd", "read -P 0 0 10k") + self.run_qemu_io("hd", "write -P 0xa0 0 10k") + + # Replace hd0-file with hd1-file and fill it with (different) data + self.reopen(opts, {'file': 'hd1-file'}) + self.run_qemu_io("hd", "read -P 0 0 10k") + self.run_qemu_io("hd", "write -P 0xa1 0 10k") + + # Use hd0-file again and check that it contains the expected data + self.reopen(opts, {'file': 'hd0-file'}) + self.run_qemu_io("hd", "read -P 0xa0 0 10k") + + # And finally do the same with hd1-file + self.reopen(opts, {'file': 'hd1-file'}) + self.run_qemu_io("hd", "read -P 0xa1 0 10k") + + # Insert (and remove) a throttle filter + def test_insert_throttle_filter(self): + # Add an image to the VM + hd0_opts =3D hd_opts(0) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **hd0_= opts) + self.assert_qmp(result, 'return', {}) + + # Create a throttle-group object + opts =3D { 'qom-type': 'throttle-group', 'id': 'group0', + 'limits': { 'iops-total': 1000 } } + result =3D self.vm.qmp('object-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # Add a throttle filter with the group that we just created. + # The filter is not used by anyone yet + opts =3D { 'driver': 'throttle', 'node-name': 'throttle0', + 'throttle-group': 'group0', 'file': 'hd0-file' } + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # Insert the throttle filter between hd0 and hd0-file + self.reopen(hd0_opts, {'file': 'throttle0'}) + + # Remove the throttle filter from hd0 + self.reopen(hd0_opts, {'file': 'hd0-file'}) + + # Insert (and remove) a compress filter + def test_insert_compress_filter(self): + # Add an image to the VM: hd (raw) -> hd0 (qcow2) -> hd0-file (fil= e) + opts =3D {'driver': 'raw', 'node-name': 'hd', 'file': hd_opts(0)} + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # Add a 'compress' filter + filter_opts =3D {'driver': 'compress', + 'node-name': 'compress0', + 'file': 'hd0'} + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **filt= er_opts) + self.assert_qmp(result, 'return', {}) + + # Unmap the beginning of the image (we cannot write compressed + # data to an allocated cluster) + self.run_qemu_io("hd", "write -z -u 0 128k") + + # Write data to the first cluster + self.run_qemu_io("hd", "write -P 0xa0 0 64k") + + # Insert the filter then write to the second cluster + # hd -> compress0 -> hd0 -> hd0-file + self.reopen(opts, {'file': 'compress0'}) + self.run_qemu_io("hd", "write -P 0xa1 64k 64k") + + # Remove the filter then write to the third cluster + # hd -> hd0 -> hd0-file + self.reopen(opts, {'file': 'hd0'}) + self.run_qemu_io("hd", "write -P 0xa2 128k 64k") + + # Verify the data that we just wrote + self.run_qemu_io("hd", "read -P 0xa0 0 64k") + self.run_qemu_io("hd", "read -P 0xa1 64k 64k") + self.run_qemu_io("hd", "read -P 0xa2 128k 64k") + + self.vm.shutdown() + + # Check the first byte of the first three L2 entries and verify th= at + # the second one is compressed (0x40) while the others are not (0x= 80) + iotests.qemu_io_log('-f', 'raw', '-c', 'read -P 0x80 0x40000 1', + '-c', 'read -P 0x40 0x40008 1', + '-c', 'read -P 0x80 0x40010 1', h= d_path[0]) + # Misc reopen tests with different block drivers @iotests.skip_if_unsupported(['quorum', 'throttle']) def test_misc_drivers(self): diff --git a/tests/qemu-iotests/245.out b/tests/qemu-iotests/245.out index 99c12f4f98..daf1e51922 100644 --- a/tests/qemu-iotests/245.out +++ b/tests/qemu-iotests/245.out @@ -10,8 +10,15 @@ {"return": {}} {"data": {"id": "stream0", "type": "stream"}, "event": "BLOCK_JOB_PENDING"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"device": "stream0", "len": 3145728, "offset": 3145728, "speed":= 0, "type": "stream"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"micro= seconds": "USECS", "seconds": "SECS"}} -............... +....read 1/1 bytes at offset 262144 +1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 1/1 bytes at offset 262152 +1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 1/1 bytes at offset 262160 +1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +.............. ---------------------------------------------------------------------- -Ran 21 tests +Ran 24 tests =20 OK --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070215; cv=none; d=zohomail.com; s=zohoarc; b=KMhu2CSbbzT1lpYpUvN5BzrpjdqsKEFifDOlo+VhhebWTHA8U4x0NzTFdH39I9BPITAK22CneG/TFYAw7WetkF3DdHEzuIa3v0J+ia1oE6zuK2poDkHmsTkhdurf5X+q+VxW5xBxxOOmROn6phkV6BEy96Z0tYWZE0ngzWQWfMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070215; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s5t17Z+QuCnaYytft9xZU/rY0g8YyrHZdTZNQW0vfhA=; b=CEYnEW8C4wyz9uvSmDE9PDEd4+c/V93aVj2wDNsiuydGVt3Fuhva0n8pXEKTOzNFKlgJfxr2LvM+Kn1KEpsOLsSkDMXhwPMU08QnOuUXozE7AYCBa99tQUqLnBBRNHle6d/Ehh+Z4k14lIvbp+Pb9ntdxATs34CbReRs+qvB0QY= 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 1625070215650228.85135939671625; Wed, 30 Jun 2021 09:23:35 -0700 (PDT) Received: from localhost ([::1]:37964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyczu-0007e9-GK for importer@patchew.org; Wed, 30 Jun 2021 12:23:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycg1-00031d-9K for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21593) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfa-00076d-Dn for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-128-WAT4gDeeP6WsbzyZmBpLbA-1; Wed, 30 Jun 2021 12:02:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D812100C663; Wed, 30 Jun 2021 16:02:30 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 288EC604CD; Wed, 30 Jun 2021 16:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s5t17Z+QuCnaYytft9xZU/rY0g8YyrHZdTZNQW0vfhA=; b=KmchKM4kyAa3eWl00Q0STT/JMwG0wrxcI3zrc+d5IRmeUxNnJfS9dn4sw6w2KQODpohBzl Q0PfG/pCifpeYhUzZdJ1QlAZ0vUH6fnPFc/urGyFP3tO+C5AEvmb0Jg9oJD7RLbhwvgzTU hzS9l27/ThYfZUyZKa+yvbDafnQ3Ka0= X-MC-Unique: WAT4gDeeP6WsbzyZmBpLbA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 15/24] introduce QEMU_AUTO_VFREE Date: Wed, 30 Jun 2021 18:01:57 +0200 Message-Id: <20210630160206.276439-16-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Introduce a convenient macro, that works for qemu_memalign() like g_autofree works with g_malloc. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210628121133.193984-2-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- include/qemu/osdep.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index c3656b755a..c91a78b5e6 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -386,6 +386,21 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *align= , bool shared, void qemu_vfree(void *ptr); void qemu_anon_ram_free(void *ptr, size_t size); =20 +/* + * It's an analog of GLIB's g_autoptr_cleanup_generic_gfree(), used to def= ine + * g_autofree macro. + */ +static inline void qemu_cleanup_generic_vfree(void *p) +{ + void **pp =3D (void **)p; + qemu_vfree(*pp); +} + +/* + * Analog of g_autofree, but qemu_vfree is called on cleanup instead of g_= free. + */ +#define QEMU_AUTO_VFREE __attribute__((cleanup(qemu_cleanup_generic_vfree)= )) + /* * Abstraction of PROT_ and MAP_ flags as passed to mmap(), for example, * consumed by qemu_ram_mmap(). --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070170; cv=none; d=zohomail.com; s=zohoarc; b=a22eC6fawotNifxpHMPM329bOBtJ9OOYZ9FA5caRQKI/LHUsdux4YA7cyiSE22z06yYhj/TlQ52igptybFCYUGHsZL4GzV8Sj8UQ/hNcKtveWkOMTy3/ouLjRUHNYe06fYAkA3ltB2PSNAIS8EBZmLIddI1Odwd1rPgrPy07IJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070170; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=606/egHMQGfZltz+YwAPSGw6QT56p57Q3k1YWew8UHM=; b=fG40b425UTzieJCt954ABEaOZcpke5rOvSxqF1WI6LnCUpuDMo5QUrTn8HIXl1wBfUfX4UzAYmmuPG2yAEfMW3v5II0pW2JjO1H35lzXVYHo3r3r14POIJbTiqwc+jECUbIFEW75Ml5mfMb5S9irO2Ja5+rQoc3Z5FVy1snDzNI= 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 1625070170901611.4559044582892; Wed, 30 Jun 2021 09:22:50 -0700 (PDT) Received: from localhost ([::1]:34438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyczB-0005IT-Q4 for importer@patchew.org; Wed, 30 Jun 2021 12:22:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycg5-00033u-0u for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfi-00077G-71 for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:04 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-41-UUDeeU91MXqEodBgRcqu1w-1; Wed, 30 Jun 2021 12:02:33 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5708A804140; Wed, 30 Jun 2021 16:02:31 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63F8F179E6; Wed, 30 Jun 2021 16:02:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068957; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=606/egHMQGfZltz+YwAPSGw6QT56p57Q3k1YWew8UHM=; b=bPD6F84sDz6xEX6KeCI2/EPxe27/8DrRoD3IKjT1j4p6kGMt7HWx+Z0skyjLjoLX5e7Q1O 6VWm4SSgrnPBqJicXbwdsoTwCc7TKu4Fkr5LdhHqILD/wGH1K6+ilCVBUL5IdF/uvrOtCx 4Ycg9M1YvfuRQSD3VbR36i/0Utf/1eU= X-MC-Unique: UUDeeU91MXqEodBgRcqu1w-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 16/24] block/commit: use QEMU_AUTO_VFREE Date: Wed, 30 Jun 2021 18:01:58 +0200 Message-Id: <20210630160206.276439-17-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210628121133.193984-3-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- block/commit.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/block/commit.c b/block/commit.c index b7f0c7c061..42792b4556 100644 --- a/block/commit.c +++ b/block/commit.c @@ -119,24 +119,24 @@ static int coroutine_fn commit_run(Job *job, Error **= errp) uint64_t delay_ns =3D 0; int ret =3D 0; int64_t n =3D 0; /* bytes */ - void *buf =3D NULL; + QEMU_AUTO_VFREE void *buf =3D NULL; int64_t len, base_len; =20 - ret =3D len =3D blk_getlength(s->top); + len =3D blk_getlength(s->top); if (len < 0) { - goto out; + return len; } job_progress_set_remaining(&s->common.job, len); =20 - ret =3D base_len =3D blk_getlength(s->base); + base_len =3D blk_getlength(s->base); if (base_len < 0) { - goto out; + return base_len; } =20 if (base_len < len) { ret =3D blk_truncate(s->base, len, false, PREALLOC_MODE_OFF, 0, NU= LL); if (ret) { - goto out; + return ret; } } =20 @@ -174,7 +174,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) block_job_error_action(&s->common, s->on_error, error_in_source, -ret); if (action =3D=3D BLOCK_ERROR_ACTION_REPORT) { - goto out; + return ret; } else { n =3D 0; continue; @@ -190,12 +190,7 @@ static int coroutine_fn commit_run(Job *job, Error **e= rrp) } } =20 - ret =3D 0; - -out: - qemu_vfree(buf); - - return ret; + return 0; } =20 static const BlockJobDriver commit_job_driver =3D { @@ -435,7 +430,7 @@ int bdrv_commit(BlockDriverState *bs) int ro; int64_t n; int ret =3D 0; - uint8_t *buf =3D NULL; + QEMU_AUTO_VFREE uint8_t *buf =3D NULL; Error *local_err =3D NULL; =20 if (!drv) @@ -556,8 +551,6 @@ int bdrv_commit(BlockDriverState *bs) =20 ret =3D 0; ro_cleanup: - qemu_vfree(buf); - blk_unref(backing); if (bdrv_cow_bs(bs) !=3D backing_file_bs) { bdrv_set_backing_hd(bs, backing_file_bs, &error_abort); --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070116; cv=none; d=zohomail.com; s=zohoarc; b=dUSdneBSVkl/ZeaWDrk8NJkaZ1dJK1mwLiOujlTHofhEpH/SLwaN2Y5yT/7xr9khUs1nQoi42kyBCbgGVQJGLPCAe3+wOPe+p4QzQdeSKZ5MUJIWM31u7Gx3opExkmJdnq2ioSTE84vKHAJ5fKVPNiARSAyBw5jzbVRTzY4EJu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070116; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iNmFTPHPNIJ7H8cJwRoq/vyHCo4guwpPKbvKDoTQLTk=; b=eukuuhXBolIzOEcl0JsRSdJfjAZC/+OI/xXtRl976C3C5iaW9nT2AcKAjaPWAl0NImZDIUHAUAwRX4FfgAGSv356XlFuFCnDCTu1I68HejtDSWrIt52TF3P/eF55YJxkghmfOs6O5BeYSUacumzUOt9dkY00LtHH2XbJLNw3Eig= 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 1625070116211583.8327034207871; Wed, 30 Jun 2021 09:21:56 -0700 (PDT) Received: from localhost ([::1]:59066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycyI-0002o2-TI for importer@patchew.org; Wed, 30 Jun 2021 12:21:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfw-0002zP-Un for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48514) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfc-00076y-Ce for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:02:56 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-9HKHpFT2OvSsZAkjIHSB8Q-1; Wed, 30 Jun 2021 12:02:33 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94BFAA40C0; Wed, 30 Jun 2021 16:02:32 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F372604CD; Wed, 30 Jun 2021 16:02:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iNmFTPHPNIJ7H8cJwRoq/vyHCo4guwpPKbvKDoTQLTk=; b=NfBc8q6ZVefIA7fCb1iWDc+gBanmD++1fnV5FbUBhIB24SXivPHrhUDQVn/OfYecAdR3y+ ipfbv3nj14VlIRobXV4vOEKLILTmwSA0G2g8uSGhMDxK7Y76NxEFenCOXuhOs6pIwVC3nz GyZUe0Jhcbw5M0i5tKliwdL3dL9ao00= X-MC-Unique: 9HKHpFT2OvSsZAkjIHSB8Q-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 17/24] block/ssh: add support for sha256 host key fingerprints Date: Wed, 30 Jun 2021 18:01:59 +0200 Message-Id: <20210630160206.276439-18-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 Currently the SSH block driver supports MD5 and SHA1 for host key fingerprints. This is a cryptographically sensitive operation and so these hash algorithms are inadequate by modern standards. This adds support for SHA256 which has been supported in libssh since the 0.8.1 release. Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210622115156.138458-1-berrange@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Richard W.M. Jones Signed-off-by: Kevin Wolf --- qapi/block-core.json | 3 ++- block/ssh.c | 3 +++ tests/qemu-iotests/207 | 54 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/207.out | 25 ++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index a54f37dbef..3114ba69bb 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3190,11 +3190,12 @@ # # @md5: The given hash is an md5 hash # @sha1: The given hash is an sha1 hash +# @sha256: The given hash is an sha256 hash # # Since: 2.12 ## { 'enum': 'SshHostKeyCheckHashType', - 'data': [ 'md5', 'sha1' ] } + 'data': [ 'md5', 'sha1', 'sha256' ] } =20 ## # @SshHostKeyHash: diff --git a/block/ssh.c b/block/ssh.c index b51a031620..d008caf059 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -442,6 +442,9 @@ static int check_host_key(BDRVSSHState *s, SshHostKeyCh= eck *hkc, Error **errp) } else if (hkc->u.hash.type =3D=3D SSH_HOST_KEY_CHECK_HASH_TYPE_SH= A1) { return check_host_key_hash(s, hkc->u.hash.hash, SSH_PUBLICKEY_HASH_SHA1, errp); + } else if (hkc->u.hash.type =3D=3D SSH_HOST_KEY_CHECK_HASH_TYPE_SH= A256) { + return check_host_key_hash(s, hkc->u.hash.hash, + SSH_PUBLICKEY_HASH_SHA256, errp); } g_assert_not_reached(); break; diff --git a/tests/qemu-iotests/207 b/tests/qemu-iotests/207 index f9f3fd7131..0f5c4bc8a0 100755 --- a/tests/qemu-iotests/207 +++ b/tests/qemu-iotests/207 @@ -73,6 +73,9 @@ with iotests.FilePath('t.img') as disk_path, \ iotests.log("=3D=3D=3D Test host-key-check options =3D=3D=3D") iotests.log("") =20 + iotests.log("--- no host key checking --") + iotests.log("") + vm.launch() blockdev_create(vm, { 'driver': 'ssh', 'location': { @@ -90,6 +93,9 @@ with iotests.FilePath('t.img') as disk_path, \ =20 iotests.img_info_log(remote_path) =20 + iotests.log("--- known_hosts key checking --") + iotests.log("") + vm.launch() blockdev_create(vm, { 'driver': 'ssh', 'location': { @@ -115,6 +121,7 @@ with iotests.FilePath('t.img') as disk_path, \ # Mappings of base64 representations to digests md5_keys =3D {} sha1_keys =3D {} + sha256_keys =3D {} =20 for key in keys: md5_keys[key] =3D subprocess.check_output( @@ -125,6 +132,10 @@ with iotests.FilePath('t.img') as disk_path, \ 'echo %s | base64 -d | sha1sum -b | cut -d" " -f1' % key, shell=3DTrue).rstrip().decode('ascii') =20 + sha256_keys[key] =3D subprocess.check_output( + 'echo %s | base64 -d | sha256sum -b | cut -d" " -f1' % key, + shell=3DTrue).rstrip().decode('ascii') + vm.launch() =20 # Find correct key first @@ -150,6 +161,9 @@ with iotests.FilePath('t.img') as disk_path, \ vm.shutdown() iotests.notrun('Did not find a key that fits 127.0.0.1') =20 + iotests.log("--- explicit md5 key checking --") + iotests.log("") + blockdev_create(vm, { 'driver': 'ssh', 'location': { 'path': disk_path, @@ -164,6 +178,7 @@ with iotests.FilePath('t.img') as disk_path, \ } }, 'size': 2097152 }) + blockdev_create(vm, { 'driver': 'ssh', 'location': { 'path': disk_path, @@ -182,6 +197,9 @@ with iotests.FilePath('t.img') as disk_path, \ =20 iotests.img_info_log(remote_path) =20 + iotests.log("--- explicit sha1 key checking --") + iotests.log("") + vm.launch() blockdev_create(vm, { 'driver': 'ssh', 'location': { @@ -215,6 +233,42 @@ with iotests.FilePath('t.img') as disk_path, \ =20 iotests.img_info_log(remote_path) =20 + iotests.log("--- explicit sha256 key checking --") + iotests.log("") + + vm.launch() + blockdev_create(vm, { 'driver': 'ssh', + 'location': { + 'path': disk_path, + 'server': { + 'host': '127.0.0.1', + 'port': '22' + }, + 'host-key-check': { + 'mode': 'hash', + 'type': 'sha256', + 'hash': 'wrong', + } + }, + 'size': 2097152 }) + blockdev_create(vm, { 'driver': 'ssh', + 'location': { + 'path': disk_path, + 'server': { + 'host': '127.0.0.1', + 'port': '22' + }, + 'host-key-check': { + 'mode': 'hash', + 'type': 'sha256', + 'hash': sha256_keys[matching_key], + } + }, + 'size': 4194304 }) + vm.shutdown() + + iotests.img_info_log(remote_path) + # # Invalid path and user # diff --git a/tests/qemu-iotests/207.out b/tests/qemu-iotests/207.out index 1239d9d648..aeb8569d77 100644 --- a/tests/qemu-iotests/207.out +++ b/tests/qemu-iotests/207.out @@ -16,6 +16,8 @@ virtual size: 4 MiB (4194304 bytes) =20 =3D=3D=3D Test host-key-check options =3D=3D=3D =20 +--- no host key checking -- + {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": = {"driver": "ssh", "location": {"host-key-check": {"mode": "none"}, "path": = "TEST_DIR/PID-t.img", "server": {"host": "127.0.0.1", "port": "22"}}, "size= ": 8388608}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} @@ -25,6 +27,8 @@ image: TEST_IMG file format: IMGFMT virtual size: 8 MiB (8388608 bytes) =20 +--- known_hosts key checking -- + {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": = {"driver": "ssh", "location": {"host-key-check": {"mode": "known_hosts"}, "= path": "TEST_DIR/PID-t.img", "server": {"host": "127.0.0.1", "port": "22"}}= , "size": 4194304}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} @@ -34,6 +38,8 @@ image: TEST_IMG file format: IMGFMT virtual size: 4 MiB (4194304 bytes) =20 +--- explicit md5 key checking -- + {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": = {"driver": "ssh", "location": {"host-key-check": {"hash": "wrong", "mode": = "hash", "type": "md5"}, "path": "TEST_DIR/PID-t.img", "server": {"host": "1= 27.0.0.1", "port": "22"}}, "size": 2097152}}} {"return": {}} Job failed: remote host key does not match host_key_check 'wrong' @@ -49,6 +55,8 @@ image: TEST_IMG file format: IMGFMT virtual size: 8 MiB (8388608 bytes) =20 +--- explicit sha1 key checking -- + {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": = {"driver": "ssh", "location": {"host-key-check": {"hash": "wrong", "mode": = "hash", "type": "sha1"}, "path": "TEST_DIR/PID-t.img", "server": {"host": "= 127.0.0.1", "port": "22"}}, "size": 2097152}}} {"return": {}} Job failed: remote host key does not match host_key_check 'wrong' @@ -64,6 +72,23 @@ image: TEST_IMG file format: IMGFMT virtual size: 4 MiB (4194304 bytes) =20 +--- explicit sha256 key checking -- + +{"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": = {"driver": "ssh", "location": {"host-key-check": {"hash": "wrong", "mode": = "hash", "type": "sha256"}, "path": "TEST_DIR/PID-t.img", "server": {"host":= "127.0.0.1", "port": "22"}}, "size": 2097152}}} +{"return": {}} +Job failed: remote host key does not match host_key_check 'wrong' +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +{"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": = {"driver": "ssh", "location": {"host-key-check": {"hash": "HASH", "mode": "= hash", "type": "sha256"}, "path": "TEST_DIR/PID-t.img", "server": {"host": = "127.0.0.1", "port": "22"}}, "size": 4194304}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 4 MiB (4194304 bytes) + =3D=3D=3D Invalid path and user =3D=3D=3D =20 {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": = {"driver": "ssh", "location": {"host-key-check": {"mode": "none"}, "path": = "/this/is/not/an/existing/path", "server": {"host": "127.0.0.1", "port": "2= 2"}}, "size": 4194304}}} --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070319; cv=none; d=zohomail.com; s=zohoarc; b=hMK/fh8v7UuY+2WXDowJ9PqlU7fovGsEklJFgjaq31S5CKwi4/d30J3L/JouGukwKUEDEmTKPPbhEUr6Cr56dbsCCu4okC+RsKZ73pgpyfweSCNW9vnIlgpASugVudOjrhoTBAUw9YCzGNjAwk2vC1PY5dGNxmFmZnH6v+5/OUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070319; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FWXZAsL3I0faxZD3HzjAdjp/nhX2pR+C3kho4LsKvr4=; b=f+61GoW+KkUbCHQbcAC9PWXhOSGZIhUKwHTl77Mbrmd/7sf/pNnanALZMJnDEH4d3cd6lzxTayE0XbfM5uYY7Jm2SnYxx5o8ZF2qeJRlu1KbJBxA6+A7Fxf6IIMUxyyrTGwRGOiQZIkdxUuSIavosyux699DWDJC2uL7oEYaXpE= 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 1625070319686104.33745053008613; Wed, 30 Jun 2021 09:25:19 -0700 (PDT) Received: from localhost ([::1]:43192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyd1a-0002qL-JH for importer@patchew.org; Wed, 30 Jun 2021 12:25:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycg3-00032l-5z for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54377) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfd-000775-8z for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:02 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-341-4Nd79IoIPI-FeiptHnJPww-1; Wed, 30 Jun 2021 12:02:35 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF4181023F41; Wed, 30 Jun 2021 16:02:33 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC507604CD; Wed, 30 Jun 2021 16:02:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FWXZAsL3I0faxZD3HzjAdjp/nhX2pR+C3kho4LsKvr4=; b=Z1ewgM3ts13kZPoqzQYsoEIhjMoNdCoOF0Pk9ECcBE4vY73RUtElOZ96pJK078+fezK7NM V4UeAQAbYKZPdX9gGxUEBAl3Vas+c3RV9XrDrFLN6DfgWMJ2Dqy8RRuYAjnPaF98sqQZRh L18Ouf7qyJx6iWvqHlT6YhdWFyrC8yk= X-MC-Unique: 4Nd79IoIPI-FeiptHnJPww-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 18/24] vhost: Add Error parameter to vhost_dev_init() Date: Wed, 30 Jun 2021 18:02:00 +0200 Message-Id: <20210630160206.276439-19-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This allows callers to return better error messages instead of making one up while the real error ends up on stderr. Most callers can immediately make use of this because they already have an Error parameter themselves. The others just keep printing the error with error_report_err(). Signed-off-by: Kevin Wolf Message-Id: <20210609154658.350308-2-kwolf@redhat.com> Reviewed-by: Stefano Garzarella Reviewed-by: Raphael Norwitz Signed-off-by: Kevin Wolf --- include/hw/virtio/vhost.h | 2 +- backends/cryptodev-vhost.c | 5 ++++- backends/vhost-user.c | 4 ++-- hw/block/vhost-user-blk.c | 4 ++-- hw/net/vhost_net.c | 6 +++++- hw/scsi/vhost-scsi.c | 4 +--- hw/scsi/vhost-user-scsi.c | 4 +--- hw/virtio/vhost-user-fs.c | 3 +-- hw/virtio/vhost-user-vsock.c | 3 +-- hw/virtio/vhost-vsock.c | 3 +-- hw/virtio/vhost.c | 16 ++++++++++------ 11 files changed, 29 insertions(+), 25 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 21a9a52088..2d7aaad67b 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -104,7 +104,7 @@ struct vhost_net { =20 int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, - uint32_t busyloop_timeout); + uint32_t busyloop_timeout, Error **errp); void vhost_dev_cleanup(struct vhost_dev *hdev); int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 8231e7f1bc..bc13e466b4 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -52,6 +52,7 @@ cryptodev_vhost_init( { int r; CryptoDevBackendVhost *crypto; + Error *local_err =3D NULL; =20 crypto =3D g_new(CryptoDevBackendVhost, 1); crypto->dev.max_queues =3D 1; @@ -66,8 +67,10 @@ cryptodev_vhost_init( /* vhost-user needs vq_index to initiate a specific queue pair */ crypto->dev.vq_index =3D crypto->cc->queue_index * crypto->dev.nvqs; =20 - r =3D vhost_dev_init(&crypto->dev, options->opaque, options->backend_t= ype, 0); + r =3D vhost_dev_init(&crypto->dev, options->opaque, options->backend_t= ype, 0, + &local_err); if (r < 0) { + error_report_err(local_err); goto fail; } =20 diff --git a/backends/vhost-user.c b/backends/vhost-user.c index b366610e16..10b39992d2 100644 --- a/backends/vhost-user.c +++ b/backends/vhost-user.c @@ -48,9 +48,9 @@ vhost_user_backend_dev_init(VhostUserBackend *b, VirtIODe= vice *vdev, b->dev.nvqs =3D nvqs; b->dev.vqs =3D g_new0(struct vhost_virtqueue, nvqs); =20 - ret =3D vhost_dev_init(&b->dev, &b->vhost_user, VHOST_BACKEND_TYPE_USE= R, 0); + ret =3D vhost_dev_init(&b->dev, &b->vhost_user, VHOST_BACKEND_TYPE_USE= R, 0, + errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost initialization failed"); return -1; } =20 diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index c6210fad0c..0cb56baefb 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -332,9 +332,9 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) =20 vhost_dev_set_config_notifier(&s->dev, &blk_ops); =20 - ret =3D vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USE= R, 0); + ret =3D vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USE= R, 0, + errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost initialization failed"); return ret; } =20 diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 44c1ed92dc..447b119f85 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -22,6 +22,7 @@ #include "standard-headers/linux/vhost_types.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" +#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" =20 @@ -157,6 +158,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) bool backend_kernel =3D options->backend_type =3D=3D VHOST_BACKEND_TYP= E_KERNEL; struct vhost_net *net =3D g_new0(struct vhost_net, 1); uint64_t features =3D 0; + Error *local_err =3D NULL; =20 if (!options->net_backend) { fprintf(stderr, "vhost-net requires net backend to be setup\n"); @@ -187,8 +189,10 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opti= ons) } =20 r =3D vhost_dev_init(&net->dev, options->opaque, - options->backend_type, options->busyloop_timeout); + options->backend_type, options->busyloop_timeout, + &local_err); if (r < 0) { + error_report_err(local_err); goto fail; } if (backend_kernel) { diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 4d70fa036b..8c611bfd2d 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -219,10 +219,8 @@ static void vhost_scsi_realize(DeviceState *dev, Error= **errp) vsc->dev.backend_features =3D 0; =20 ret =3D vhost_dev_init(&vsc->dev, (void *)(uintptr_t)vhostfd, - VHOST_BACKEND_TYPE_KERNEL, 0); + VHOST_BACKEND_TYPE_KERNEL, 0, errp); if (ret < 0) { - error_setg(errp, "vhost-scsi: vhost initialization failed: %s", - strerror(-ret)); goto free_vqs; } =20 diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index 4666019442..1b2f7eed98 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -122,10 +122,8 @@ static void vhost_user_scsi_realize(DeviceState *dev, = Error **errp) vqs =3D vsc->dev.vqs; =20 ret =3D vhost_dev_init(&vsc->dev, &s->vhost_user, - VHOST_BACKEND_TYPE_USER, 0); + VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { - error_setg(errp, "vhost-user-scsi: vhost initialization failed: %s= ", - strerror(-ret)); goto free_vhost; } =20 diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 6f7f91533d..c595957983 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -235,9 +235,8 @@ static void vuf_device_realize(DeviceState *dev, Error = **errp) fs->vhost_dev.nvqs =3D 1 + fs->conf.num_request_queues; fs->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, fs->vhost_dev.nvq= s); ret =3D vhost_dev_init(&fs->vhost_dev, &fs->vhost_user, - VHOST_BACKEND_TYPE_USER, 0); + VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost_dev_init failed"); goto err_virtio; } =20 diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c index a6f08c26b9..b6a4a25ea1 100644 --- a/hw/virtio/vhost-user-vsock.c +++ b/hw/virtio/vhost-user-vsock.c @@ -108,9 +108,8 @@ static void vuv_device_realize(DeviceState *dev, Error = **errp) vhost_dev_set_config_notifier(&vvc->vhost_dev, &vsock_ops); =20 ret =3D vhost_dev_init(&vvc->vhost_dev, &vsock->vhost_user, - VHOST_BACKEND_TYPE_USER, 0); + VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost_dev_init failed"); goto err_virtio; } =20 diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index 8ddfb9abfe..777cafe70d 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -170,9 +170,8 @@ static void vhost_vsock_device_realize(DeviceState *dev= , Error **errp) vhost_vsock_common_realize(vdev, "vhost-vsock"); =20 ret =3D vhost_dev_init(&vvc->vhost_dev, (void *)(uintptr_t)vhostfd, - VHOST_BACKEND_TYPE_KERNEL, 0); + VHOST_BACKEND_TYPE_KERNEL, 0, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost-vsock: vhost_dev_init failed"); goto err_virtio; } =20 diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 7b7bde7657..991c67ddcd 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1286,7 +1286,8 @@ static void vhost_virtqueue_cleanup(struct vhost_virt= queue *vq) } =20 int vhost_dev_init(struct vhost_dev *hdev, void *opaque, - VhostBackendType backend_type, uint32_t busyloop_timeou= t) + VhostBackendType backend_type, uint32_t busyloop_timeou= t, + Error **errp) { uint64_t features; int i, r, n_initialized_vqs =3D 0; @@ -1300,24 +1301,26 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, =20 r =3D hdev->vhost_ops->vhost_backend_init(hdev, opaque); if (r < 0) { + error_setg(errp, "vhost_backend_init failed"); goto fail; } =20 r =3D hdev->vhost_ops->vhost_set_owner(hdev); if (r < 0) { - VHOST_OPS_DEBUG("vhost_set_owner failed"); + error_setg(errp, "vhost_set_owner failed"); goto fail; } =20 r =3D hdev->vhost_ops->vhost_get_features(hdev, &features); if (r < 0) { - VHOST_OPS_DEBUG("vhost_get_features failed"); + error_setg(errp, "vhost_get_features failed"); goto fail; } =20 for (i =3D 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { r =3D vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i= ); if (r < 0) { + error_setg_errno(errp, -r, "Failed to initialize virtqueue %d"= , i); goto fail; } } @@ -1327,6 +1330,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, r =3D vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_inde= x + i, busyloop_timeout); if (r < 0) { + error_setg(errp, "Failed to set busyloop timeout"); goto fail_busyloop; } } @@ -1367,7 +1371,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, if (hdev->migration_blocker !=3D NULL) { r =3D migrate_add_blocker(hdev->migration_blocker, &local_err); if (local_err) { - error_report_err(local_err); + error_propagate(errp, local_err); error_free(hdev->migration_blocker); goto fail_busyloop; } @@ -1384,8 +1388,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); =20 if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev= )) { - error_report("vhost backend memory slots limit is less" - " than current number of present memory slots"); + error_setg(errp, "vhost backend memory slots limit is less" + " than current number of present memory slots"); r =3D -1; goto fail_busyloop; } --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070700; cv=none; d=zohomail.com; s=zohoarc; b=HJDXl4tgOPtI71Xim8cPJOPuayBHTo5bPZwQVfNwB4jSC1vE+qrbkaf4xikHyoY26ZDy2NsjGnkBhS3TXfzkYp9WYE1GocKEePcxvduTD23i5yH2uvdpwy/IdLNVURzxE04YeeCn4qQUNwsMIjMKJ3y30oybCP8cOid9prP9Irk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070700; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=65+GjJ0FQtyKVNQXYllqAIwUk+B/Qk6vbtFF5fBMIOw=; b=SmBdAs0MNUhrUgwSuw1R/BUlCmbY3iP6zgBQCI4crpk53d8PPphXdr83V36qWfmc4vzZE8Cjy+7TsSrx/TKh0bFblZzWjRnuF01xlC+Zu4eUu1PCvEcF9XkCVbbrIGhI9OwSMfbIZ8+ERUK12I/i5HdRyb6R62PdZZoAHMxeWrM= 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 162507070066489.60576117535084; Wed, 30 Jun 2021 09:31:40 -0700 (PDT) Received: from localhost ([::1]:56340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyd7j-0003h6-De for importer@patchew.org; Wed, 30 Jun 2021 12:31:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycgT-0003gS-GV for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37703) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycg1-0007Gn-Ke for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-443-nMEeGMvyOqiyS-INpJuNcQ-1; Wed, 30 Jun 2021 12:02:36 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 368BD804140; Wed, 30 Jun 2021 16:02:35 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22653179E6; Wed, 30 Jun 2021 16:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=65+GjJ0FQtyKVNQXYllqAIwUk+B/Qk6vbtFF5fBMIOw=; b=bQehLIPcQBwP37ZSPKp43ipCfWlUymzmAa/oo4GnXnJvgtM+pjCJEwA4MbXGHzjow4B8za yDHpeUMHzqRuBPnSQxZzlLqB6jN9aEsmj5xz7v4TPVg8t0Pw+N0xRJ4a5QtvbY9FWLP3iN 3x+YaZIQIZPXTBalH/SSpQQ+2zMOSqw= X-MC-Unique: nMEeGMvyOqiyS-INpJuNcQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 19/24] vhost: Distinguish errors in vhost_backend_init() Date: Wed, 30 Jun 2021 18:02:01 +0200 Message-Id: <20210630160206.276439-20-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Instead of just returning 0/-1 and letting the caller make up a meaningless error message, add an Error parameter to allow reporting the real error and switch to 0/-errno so that different kind of errors can be distinguished in the caller. Specifically, in vhost-user, EPROTO is used for all errors that relate to the connection itself, whereas other error codes are used for errors relating to the content of the connection. This will allow us later to automatically reconnect when the connection goes away, without ending up in an endless loop if it's a permanent error in the configuration. Signed-off-by: Kevin Wolf Message-Id: <20210609154658.350308-3-kwolf@redhat.com> Reviewed-by: Stefano Garzarella Reviewed-by: Raphael Norwitz Signed-off-by: Kevin Wolf --- include/hw/virtio/vhost-backend.h | 3 ++- hw/virtio/vhost-backend.c | 2 +- hw/virtio/vhost-user.c | 41 ++++++++++++++++--------------- hw/virtio/vhost-vdpa.c | 2 +- hw/virtio/vhost.c | 13 +++++----- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 8a6f8e2a7a..728ebb0ed9 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -37,7 +37,8 @@ struct vhost_scsi_target; struct vhost_iotlb_msg; struct vhost_virtqueue; =20 -typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque); +typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque, + Error **errp); typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev); =20 diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 31b33bde37..f4f71cf58a 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -30,7 +30,7 @@ static int vhost_kernel_call(struct vhost_dev *dev, unsig= ned long int request, return ioctl(fd, request, arg); } =20 -static int vhost_kernel_init(struct vhost_dev *dev, void *opaque) +static int vhost_kernel_init(struct vhost_dev *dev, void *opaque, Error **= errp) { assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_KERNEL); =20 diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index ee57abe045..024cb201bb 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1856,7 +1856,8 @@ static int vhost_user_postcopy_notifier(NotifierWithR= eturn *notifier, return 0; } =20 -static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque) +static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque, + Error **errp) { uint64_t features, protocol_features, ram_slots; struct vhost_user *u; @@ -1871,7 +1872,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque) =20 err =3D vhost_user_get_features(dev, &features); if (err < 0) { - return err; + return -EPROTO; } =20 if (virtio_has_feature(features, VHOST_USER_F_PROTOCOL_FEATURES)) { @@ -1880,7 +1881,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque) err =3D vhost_user_get_u64(dev, VHOST_USER_GET_PROTOCOL_FEATURES, &protocol_features); if (err < 0) { - return err; + return -EPROTO; } =20 dev->protocol_features =3D @@ -1891,14 +1892,14 @@ static int vhost_user_backend_init(struct vhost_dev= *dev, void *opaque) dev->protocol_features &=3D ~(1ULL << VHOST_USER_PROTOCOL_F_CO= NFIG); } else if (!(protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_CONFIG))) { - error_report("Device expects VHOST_USER_PROTOCOL_F_CONFIG " - "but backend does not support it."); - return -1; + error_setg(errp, "Device expects VHOST_USER_PROTOCOL_F_CONFIG " + "but backend does not support it."); + return -EINVAL; } =20 err =3D vhost_user_set_protocol_features(dev, dev->protocol_featur= es); if (err < 0) { - return err; + return -EPROTO; } =20 /* query the max queues we support if backend supports Multiple Qu= eue */ @@ -1906,12 +1907,12 @@ static int vhost_user_backend_init(struct vhost_dev= *dev, void *opaque) err =3D vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, &dev->max_queues); if (err < 0) { - return err; + return -EPROTO; } } if (dev->num_queues && dev->max_queues < dev->num_queues) { - error_report("The maximum number of queues supported by the " - "backend is %" PRIu64, dev->max_queues); + error_setg(errp, "The maximum number of queues supported by th= e " + "backend is %" PRIu64, dev->max_queues); return -EINVAL; } =20 @@ -1920,9 +1921,9 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque) VHOST_USER_PROTOCOL_F_SLAVE_REQ) && virtio_has_feature(dev->protocol_features, VHOST_USER_PROTOCOL_F_REPLY_ACK))) { - error_report("IOMMU support requires reply-ack and " - "slave-req protocol features."); - return -1; + error_setg(errp, "IOMMU support requires reply-ack and " + "slave-req protocol features."); + return -EINVAL; } =20 /* get max memory regions if backend supports configurable RAM slo= ts */ @@ -1932,15 +1933,15 @@ static int vhost_user_backend_init(struct vhost_dev= *dev, void *opaque) } else { err =3D vhost_user_get_max_memslots(dev, &ram_slots); if (err < 0) { - return err; + return -EPROTO; } =20 if (ram_slots < u->user->memory_slots) { - error_report("The backend specified a max ram slots limit " - "of %" PRIu64", when the prior validated limi= t was %d. " - "This limit should never decrease.", ram_slot= s, - u->user->memory_slots); - return -1; + error_setg(errp, "The backend specified a max ram slots li= mit " + "of %" PRIu64", when the prior validated limit = was " + "%d. This limit should never decrease.", ram_sl= ots, + u->user->memory_slots); + return -EINVAL; } =20 u->user->memory_slots =3D MIN(ram_slots, VHOST_USER_MAX_RAM_SL= OTS); @@ -1958,7 +1959,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque) if (dev->vq_index =3D=3D 0) { err =3D vhost_setup_slave_channel(dev); if (err < 0) { - return err; + return -EPROTO; } } =20 diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 61ba313331..80827ee040 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -265,7 +265,7 @@ static void vhost_vdpa_add_status(struct vhost_dev *dev= , uint8_t status) vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s); } =20 -static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque) +static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **er= rp) { struct vhost_vdpa *v; assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 991c67ddcd..fd13135706 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1289,9 +1289,9 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, VhostBackendType backend_type, uint32_t busyloop_timeou= t, Error **errp) { + ERRP_GUARD(); uint64_t features; int i, r, n_initialized_vqs =3D 0; - Error *local_err =3D NULL; =20 hdev->vdev =3D NULL; hdev->migration_blocker =3D NULL; @@ -1299,9 +1299,11 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opa= que, r =3D vhost_set_backend_type(hdev, backend_type); assert(r >=3D 0); =20 - r =3D hdev->vhost_ops->vhost_backend_init(hdev, opaque); + r =3D hdev->vhost_ops->vhost_backend_init(hdev, opaque, errp); if (r < 0) { - error_setg(errp, "vhost_backend_init failed"); + if (!*errp) { + error_setg_errno(errp, -r, "vhost_backend_init failed"); + } goto fail; } =20 @@ -1369,9 +1371,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, } =20 if (hdev->migration_blocker !=3D NULL) { - r =3D migrate_add_blocker(hdev->migration_blocker, &local_err); - if (local_err) { - error_propagate(errp, local_err); + r =3D migrate_add_blocker(hdev->migration_blocker, errp); + if (*errp) { error_free(hdev->migration_blocker); goto fail_busyloop; } --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070285; cv=none; d=zohomail.com; s=zohoarc; b=aZTR9z/o1y6Zg2X34wkrcqHoZryYxZuB4RxesfxszFkFQGr1gF5Hf/zO0wkGrj/MfuDNRMvpWNWVIbsAdb1Xqu5PaOUkw9qmZyahEdao7yhNqHQd26OKtG41Zu3cBurAbSwl2D1UpDTonu5YxLNEdARVIn6KE1/LnYI/VatpZw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070285; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lY+CR9DyqRcBSb40dZwh7LYxoBtVR7xXUAS+jL4NECA=; b=WFxWMUlRvmO8dAmEuzCKsgi+Q0dYVnUbCLoGoqHILb3UFZJGSqiaX94Sc9FoMrPCitwjPIAOMlG0fcaOo537OojOyPZTFvh0u8RNyVjnRkkRO5RE8dTY7jYkfFX98F/dSa7CbMycDtVgbtBDlTyINhzr/Zao7Xc/CjOJZpZTRCA= 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 1625070285597250.7607948271526; Wed, 30 Jun 2021 09:24:45 -0700 (PDT) Received: from localhost ([::1]:41582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyd12-0001hn-BN for importer@patchew.org; Wed, 30 Jun 2021 12:24:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44314) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycg3-00033N-Fc for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59478) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfj-000787-IR for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:03 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-57-dIwABHB4McWUHZgDcQ1rug-1; Wed, 30 Jun 2021 12:02:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 52AC110C1ADC; Wed, 30 Jun 2021 16:02:36 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5ED52604CD; Wed, 30 Jun 2021 16:02:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lY+CR9DyqRcBSb40dZwh7LYxoBtVR7xXUAS+jL4NECA=; b=Qw/Gl1U9l34zfH0z3cT9DZwcEsjgfEgDGM9nYeuFIBWUkt1VrB6dtfcFqYg/AQXFyG3o5d uUYdM6wZlIR5oESEmGtk5+7PlPdvonagdsFduiV2lfzjypIjdAQLNQohRThPLqa9BXjgAA HudrW8o98ZmDJJQbD8PqdfxBin4c+dE= X-MC-Unique: dIwABHB4McWUHZgDcQ1rug-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 20/24] vhost: Return 0/-errno in vhost_dev_init() Date: Wed, 30 Jun 2021 18:02:02 +0200 Message-Id: <20210630160206.276439-21-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Instead of just returning 0/-1 and letting the caller make up a meaningless error message, switch to 0/-errno so that different kinds of errors can be distinguished in the caller. This involves changing a few more callbacks in VhostOps to return 0/-errno: .vhost_set_owner(), .vhost_get_features() and .vhost_virtqueue_set_busyloop_timeout(). The implementations of these functions are trivial as they generally just send a message to the backend. Signed-off-by: Kevin Wolf Message-Id: <20210609154658.350308-4-kwolf@redhat.com> Reviewed-by: Stefano Garzarella Reviewed-by: Raphael Norwitz Signed-off-by: Kevin Wolf --- hw/virtio/vhost-backend.c | 4 +++- hw/virtio/vhost-user.c | 10 +++++++--- hw/virtio/vhost-vdpa.c | 4 +++- hw/virtio/vhost.c | 8 ++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index f4f71cf58a..594d770b75 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -24,10 +24,12 @@ static int vhost_kernel_call(struct vhost_dev *dev, uns= igned long int request, void *arg) { int fd =3D (uintptr_t) dev->opaque; + int ret; =20 assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_KERNEL); =20 - return ioctl(fd, request, arg); + ret =3D ioctl(fd, request, arg); + return ret < 0 ? -errno : ret; } =20 static int vhost_kernel_init(struct vhost_dev *dev, void *opaque, Error **= errp) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 024cb201bb..889559d86a 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1353,7 +1353,11 @@ static int vhost_user_get_u64(struct vhost_dev *dev,= int request, uint64_t *u64) =20 static int vhost_user_get_features(struct vhost_dev *dev, uint64_t *featur= es) { - return vhost_user_get_u64(dev, VHOST_USER_GET_FEATURES, features); + if (vhost_user_get_u64(dev, VHOST_USER_GET_FEATURES, features) < 0) { + return -EPROTO; + } + + return 0; } =20 static int vhost_user_set_owner(struct vhost_dev *dev) @@ -1364,7 +1368,7 @@ static int vhost_user_set_owner(struct vhost_dev *dev) }; =20 if (vhost_user_write(dev, &msg, NULL, 0) < 0) { - return -1; + return -EPROTO; } =20 return 0; @@ -1872,7 +1876,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, =20 err =3D vhost_user_get_features(dev, &features); if (err < 0) { - return -EPROTO; + return err; } =20 if (virtio_has_feature(features, VHOST_USER_F_PROTOCOL_FEATURES)) { diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 80827ee040..0f469f1823 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -245,10 +245,12 @@ static int vhost_vdpa_call(struct vhost_dev *dev, uns= igned long int request, { struct vhost_vdpa *v =3D dev->opaque; int fd =3D v->device_fd; + int ret; =20 assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); =20 - return ioctl(fd, request, arg); + ret =3D ioctl(fd, request, arg); + return ret < 0 ? -errno : ret; } =20 static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index fd13135706..c7f9d8bb06 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1309,13 +1309,13 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, =20 r =3D hdev->vhost_ops->vhost_set_owner(hdev); if (r < 0) { - error_setg(errp, "vhost_set_owner failed"); + error_setg_errno(errp, -r, "vhost_set_owner failed"); goto fail; } =20 r =3D hdev->vhost_ops->vhost_get_features(hdev, &features); if (r < 0) { - error_setg(errp, "vhost_get_features failed"); + error_setg_errno(errp, -r, "vhost_get_features failed"); goto fail; } =20 @@ -1332,7 +1332,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, r =3D vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_inde= x + i, busyloop_timeout); if (r < 0) { - error_setg(errp, "Failed to set busyloop timeout"); + error_setg_errno(errp, -r, "Failed to set busyloop timeout= "); goto fail_busyloop; } } @@ -1391,7 +1391,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev= )) { error_setg(errp, "vhost backend memory slots limit is less" " than current number of present memory slots"); - r =3D -1; + r =3D -EINVAL; goto fail_busyloop; } =20 --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070035; cv=none; d=zohomail.com; s=zohoarc; b=ijkNvqII2tbgC3AiNJMOWvyqbQQId4mJUudtGho7szIec45B9FKEtwq25CdA5mQ1O1rV+Uc1r7qSfhLHrb/MSGK2eMR/LFqR8Td/d5SxuOdsXuOj6IWbfEunq8BwwAbKhlw8tml0Bmzq5PjH+y3/Vt9fRyFzEFmKtJpV22Xr6/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070035; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qj+XI9Pr/X81rgEpbanaesV3sXzfn3UF1DQnyJbWIBg=; b=LAD3TrXUOykLPfTRMW/kRfK4J1A9Crr+VYJG1Yo3zHbO5Bo5D2vGS6d97psfajUW1JJCvljNMM4PaN7QK/pfJ55pAGNtP5W0FzC9GeJFaCyMuRi2lH8EvP5GSYM0pNmlJfZl639WqnIURuGDXPxlZT/F44UBRiO37Cn/JtVkBYk= 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 1625070035093163.19862158947706; Wed, 30 Jun 2021 09:20:35 -0700 (PDT) Received: from localhost ([::1]:55724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lycx0-0000XM-AF for importer@patchew.org; Wed, 30 Jun 2021 12:20:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycg5-00033v-1b for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49349) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfj-00078j-Ix for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:04 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-179-hMXH58I5NUygHNk-F9haEA-1; Wed, 30 Jun 2021 12:02:38 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8CCB2A40C1; Wed, 30 Jun 2021 16:02:37 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A2C7604CD; Wed, 30 Jun 2021 16:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qj+XI9Pr/X81rgEpbanaesV3sXzfn3UF1DQnyJbWIBg=; b=dI6udiX/P9vl30bYc3F0BR4boK3p17kZDTtVnuZWIND4mhpMMW1m/61IKJzUCNUhCsHMSO LZlJNBicmbZp2igwZukhNwRJ45o1qFu3q2xLUc4m0Uw7iu04rNXG8kD1lXdjbK5Z+Ry1WB o2mm5tPYWQ3yVdm6p1bv47IIltcE3iA= X-MC-Unique: hMXH58I5NUygHNk-F9haEA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 21/24] vhost-user-blk: Add Error parameter to vhost_user_blk_start() Date: Wed, 30 Jun 2021 18:02:03 +0200 Message-Id: <20210630160206.276439-22-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Instead of letting the caller make up a meaningless error message, add an Error parameter to allow reporting the real error. Signed-off-by: Kevin Wolf Message-Id: <20210609154658.350308-5-kwolf@redhat.com> Reviewed-by: Stefano Garzarella Reviewed-by: Raphael Norwitz Signed-off-by: Kevin Wolf --- hw/block/vhost-user-blk.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 0cb56baefb..e9382e152a 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -113,7 +113,7 @@ const VhostDevConfigOps blk_ops =3D { .vhost_dev_config_notifier =3D vhost_user_blk_handle_config_change, }; =20 -static int vhost_user_blk_start(VirtIODevice *vdev) +static int vhost_user_blk_start(VirtIODevice *vdev, Error **errp) { VHostUserBlk *s =3D VHOST_USER_BLK(vdev); BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); @@ -121,19 +121,19 @@ static int vhost_user_blk_start(VirtIODevice *vdev) int i, ret; =20 if (!k->set_guest_notifiers) { - error_report("binding does not support guest notifiers"); + error_setg(errp, "binding does not support guest notifiers"); return -ENOSYS; } =20 ret =3D vhost_dev_enable_notifiers(&s->dev, vdev); if (ret < 0) { - error_report("Error enabling host notifiers: %d", -ret); + error_setg_errno(errp, -ret, "Error enabling host notifiers"); return ret; } =20 ret =3D k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true); if (ret < 0) { - error_report("Error binding guest notifier: %d", -ret); + error_setg_errno(errp, -ret, "Error binding guest notifier"); goto err_host_notifiers; } =20 @@ -141,27 +141,27 @@ static int vhost_user_blk_start(VirtIODevice *vdev) =20 ret =3D vhost_dev_prepare_inflight(&s->dev, vdev); if (ret < 0) { - error_report("Error set inflight format: %d", -ret); + error_setg_errno(errp, -ret, "Error setting inflight format"); goto err_guest_notifiers; } =20 if (!s->inflight->addr) { ret =3D vhost_dev_get_inflight(&s->dev, s->queue_size, s->inflight= ); if (ret < 0) { - error_report("Error get inflight: %d", -ret); + error_setg_errno(errp, -ret, "Error getting inflight"); goto err_guest_notifiers; } } =20 ret =3D vhost_dev_set_inflight(&s->dev, s->inflight); if (ret < 0) { - error_report("Error set inflight: %d", -ret); + error_setg_errno(errp, -ret, "Error setting inflight"); goto err_guest_notifiers; } =20 ret =3D vhost_dev_start(&s->dev, vdev); if (ret < 0) { - error_report("Error starting vhost: %d", -ret); + error_setg_errno(errp, -ret, "Error starting vhost"); goto err_guest_notifiers; } s->started_vu =3D true; @@ -214,6 +214,7 @@ static void vhost_user_blk_set_status(VirtIODevice *vde= v, uint8_t status) { VHostUserBlk *s =3D VHOST_USER_BLK(vdev); bool should_start =3D virtio_device_started(vdev, status); + Error *local_err =3D NULL; int ret; =20 if (!vdev->vm_running) { @@ -229,10 +230,9 @@ static void vhost_user_blk_set_status(VirtIODevice *vd= ev, uint8_t status) } =20 if (should_start) { - ret =3D vhost_user_blk_start(vdev); + ret =3D vhost_user_blk_start(vdev, &local_err); if (ret < 0) { - error_report("vhost-user-blk: vhost start failed: %s", - strerror(-ret)); + error_reportf_err(local_err, "vhost-user-blk: vhost start fail= ed: "); qemu_chr_fe_disconnect(&s->chardev); } } else { @@ -270,6 +270,7 @@ static uint64_t vhost_user_blk_get_features(VirtIODevic= e *vdev, static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) { VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + Error *local_err =3D NULL; int i, ret; =20 if (!vdev->start_on_kick) { @@ -287,10 +288,9 @@ static void vhost_user_blk_handle_output(VirtIODevice = *vdev, VirtQueue *vq) /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start * vhost here instead of waiting for .set_status(). */ - ret =3D vhost_user_blk_start(vdev); + ret =3D vhost_user_blk_start(vdev, &local_err); if (ret < 0) { - error_report("vhost-user-blk: vhost start failed: %s", - strerror(-ret)); + error_reportf_err(local_err, "vhost-user-blk: vhost start failed: = "); qemu_chr_fe_disconnect(&s->chardev); return; } @@ -340,9 +340,8 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) =20 /* restore vhost state */ if (virtio_device_started(vdev, vdev->status)) { - ret =3D vhost_user_blk_start(vdev); + ret =3D vhost_user_blk_start(vdev, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost start failed"); return ret; } } --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070379; cv=none; d=zohomail.com; s=zohoarc; b=LrmhoxHeUoFqW37e5y06sWCB0WMllyb5SVJxK7JzWcDLFDtL4suTQJgvQVAC1NNIZZl5Vu7WGMEiRO9tDNwq1+KBLMtpVc2Jelk/0feqWsJKOsSx39V+P0tz9/alq0XD6axjwNGBWIZofZzbMOJpOPc8q1byNSM771CjAUQ2I7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070379; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FvGmCYj7ykVpCCWeIiMBmiblyJ4fnn6QIsHl9PyEB5w=; b=mhowKg//FUAEytzD7dg87P1meogWkMpFJf6Z+kUM0bxPEjGHILxjgQdDaatRV2Cd9FxtvVpY2mK2XbTgAV3ccnd2rimluHz9WJPX3YozSfJPd2nm0D3RXpiBbiSISlOAsHpnNgJRl6btQt2ys+0d7sJgSAypGke9Ls2fjQtCg6A= 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 1625070379654637.7876320117282; Wed, 30 Jun 2021 09:26:19 -0700 (PDT) Received: from localhost ([::1]:45990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyd2X-0004rJ-Mp for importer@patchew.org; Wed, 30 Jun 2021 12:26:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycg8-000365-Pw for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36277) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfj-00078y-Iv for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:08 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-361-Nu7390f_PpybcAjqiB_8HA-1; Wed, 30 Jun 2021 12:02:39 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C72131835AC4; Wed, 30 Jun 2021 16:02:38 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5278179E6; Wed, 30 Jun 2021 16:02:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FvGmCYj7ykVpCCWeIiMBmiblyJ4fnn6QIsHl9PyEB5w=; b=cU1u1iRcE+91PaBFU+UffZyuNzlOWV9L2KVkbJa035l4bBKBmqkl7UGNuDMuDRNX3GMn3V g2QvnxkMqlri/LWlURIsVuuyWcveRlEuNP0cUup3kHnVRvZ+vqjEC3fQtMsV3TC0ffXDy7 ea4jJsQ6vWC9BBCsyxQ+5zrbyH4F52U= X-MC-Unique: Nu7390f_PpybcAjqiB_8HA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 22/24] vhost: Distinguish errors in vhost_dev_get_config() Date: Wed, 30 Jun 2021 18:02:04 +0200 Message-Id: <20210630160206.276439-23-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Instead of just returning 0/-1 and letting the caller make up a meaningless error message, add an Error parameter to allow reporting the real error and switch to 0/-errno so that different kind of errors can be distinguished in the caller. config_len in vhost_user_get_config() is defined by the device, so if it's larger than VHOST_USER_MAX_CONFIG_SIZE, this is a programming error. Turn the corresponding check into an assertion. Signed-off-by: Kevin Wolf Message-Id: <20210609154658.350308-6-kwolf@redhat.com> Reviewed-by: Stefano Garzarella Reviewed-by: Raphael Norwitz Signed-off-by: Kevin Wolf --- include/hw/virtio/vhost-backend.h | 2 +- include/hw/virtio/vhost.h | 4 ++-- hw/block/vhost-user-blk.c | 9 +++++---- hw/display/vhost-user-gpu.c | 6 ++++-- hw/input/vhost-user-input.c | 6 ++++-- hw/net/vhost_net.c | 2 +- hw/virtio/vhost-user-vsock.c | 9 +++++---- hw/virtio/vhost-user.c | 24 ++++++++++++------------ hw/virtio/vhost-vdpa.c | 2 +- hw/virtio/vhost.c | 14 +++++++++++--- 10 files changed, 46 insertions(+), 32 deletions(-) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 728ebb0ed9..8475c5a29d 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -98,7 +98,7 @@ typedef int (*vhost_set_config_op)(struct vhost_dev *dev,= const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags); typedef int (*vhost_get_config_op)(struct vhost_dev *dev, uint8_t *config, - uint32_t config_len); + uint32_t config_len, Error **errp); =20 typedef int (*vhost_crypto_create_session_op)(struct vhost_dev *dev, void *session_info, diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 2d7aaad67b..045d0fd9f2 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -130,8 +130,8 @@ int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file); =20 int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int writ= e); -int vhost_dev_get_config(struct vhost_dev *dev, uint8_t *config, - uint32_t config_len); +int vhost_dev_get_config(struct vhost_dev *hdev, uint8_t *config, + uint32_t config_len, Error **errp); int vhost_dev_set_config(struct vhost_dev *dev, const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags); /* notifier callback in case vhost device config space changed diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index e9382e152a..3770f715da 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -91,11 +91,13 @@ static int vhost_user_blk_handle_config_change(struct v= host_dev *dev) int ret; struct virtio_blk_config blkcfg; VHostUserBlk *s =3D VHOST_USER_BLK(dev->vdev); + Error *local_err =3D NULL; =20 ret =3D vhost_dev_get_config(dev, (uint8_t *)&blkcfg, - sizeof(struct virtio_blk_config)); + sizeof(struct virtio_blk_config), + &local_err); if (ret < 0) { - error_report("get config space failed"); + error_report_err(local_err); return -1; } =20 @@ -478,9 +480,8 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) assert(s->connected); =20 ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, - sizeof(struct virtio_blk_config)); + sizeof(struct virtio_blk_config), errp); if (ret < 0) { - error_setg(errp, "vhost-user-blk: get block config failed"); goto vhost_err; } =20 diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 6cdaa1c73b..389199e6ca 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -415,14 +415,16 @@ vhost_user_gpu_get_config(VirtIODevice *vdev, uint8_t= *config_data) VirtIOGPUBase *b =3D VIRTIO_GPU_BASE(vdev); struct virtio_gpu_config *vgconfig =3D (struct virtio_gpu_config *)config_data; + Error *local_err =3D NULL; int ret; =20 memset(config_data, 0, sizeof(struct virtio_gpu_config)); =20 ret =3D vhost_dev_get_config(&g->vhost->dev, - config_data, sizeof(struct virtio_gpu_confi= g)); + config_data, sizeof(struct virtio_gpu_confi= g), + &local_err); if (ret) { - error_report("vhost-user-gpu: get device config space failed"); + error_report_err(local_err); return; } =20 diff --git a/hw/input/vhost-user-input.c b/hw/input/vhost-user-input.c index 63984a8ba7..273e96a7b1 100644 --- a/hw/input/vhost-user-input.c +++ b/hw/input/vhost-user-input.c @@ -49,13 +49,15 @@ static void vhost_input_get_config(VirtIODevice *vdev, = uint8_t *config_data) { VirtIOInput *vinput =3D VIRTIO_INPUT(vdev); VHostUserInput *vhi =3D VHOST_USER_INPUT(vdev); + Error *local_err =3D NULL; int ret; =20 memset(config_data, 0, vinput->cfg_size); =20 - ret =3D vhost_dev_get_config(&vhi->vhost->dev, config_data, vinput->cf= g_size); + ret =3D vhost_dev_get_config(&vhi->vhost->dev, config_data, vinput->cf= g_size, + &local_err); if (ret) { - error_report("vhost-user-input: get device config space failed"); + error_report_err(local_err); return; } } diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 447b119f85..10a7780a13 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -117,7 +117,7 @@ uint64_t vhost_net_get_features(struct vhost_net *net, = uint64_t features) int vhost_net_get_config(struct vhost_net *net, uint8_t *config, uint32_t config_len) { - return vhost_dev_get_config(&net->dev, config, config_len); + return vhost_dev_get_config(&net->dev, config, config_len, NULL); } int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags) diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c index b6a4a25ea1..6095ed7349 100644 --- a/hw/virtio/vhost-user-vsock.c +++ b/hw/virtio/vhost-user-vsock.c @@ -34,10 +34,12 @@ static void vuv_get_config(VirtIODevice *vdev, uint8_t = *config) static int vuv_handle_config_change(struct vhost_dev *dev) { VHostUserVSock *vsock =3D VHOST_USER_VSOCK(dev->vdev); + Error *local_err =3D NULL; int ret =3D vhost_dev_get_config(dev, (uint8_t *)&vsock->vsockcfg, - sizeof(struct virtio_vsock_config)); + sizeof(struct virtio_vsock_config), + &local_err); if (ret < 0) { - error_report("get config space failed"); + error_report_err(local_err); return -1; } =20 @@ -114,9 +116,8 @@ static void vuv_device_realize(DeviceState *dev, Error = **errp) } =20 ret =3D vhost_dev_get_config(&vvc->vhost_dev, (uint8_t *)&vsock->vsock= cfg, - sizeof(struct virtio_vsock_config)); + sizeof(struct virtio_vsock_config), errp); if (ret < 0) { - error_setg_errno(errp, -ret, "get config space failed"); goto err_vhost_dev; } =20 diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 889559d86a..1ac4a2ebec 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -2117,7 +2117,7 @@ static void vhost_user_set_iotlb_callback(struct vhos= t_dev *dev, int enabled) } =20 static int vhost_user_get_config(struct vhost_dev *dev, uint8_t *config, - uint32_t config_len) + uint32_t config_len, Error **errp) { VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_GET_CONFIG, @@ -2127,32 +2127,32 @@ static int vhost_user_get_config(struct vhost_dev *= dev, uint8_t *config, =20 if (!virtio_has_feature(dev->protocol_features, VHOST_USER_PROTOCOL_F_CONFIG)) { - return -1; + error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported"); + return -EINVAL; } =20 - if (config_len > VHOST_USER_MAX_CONFIG_SIZE) { - return -1; - } + assert(config_len <=3D VHOST_USER_MAX_CONFIG_SIZE); =20 msg.payload.config.offset =3D 0; msg.payload.config.size =3D config_len; if (vhost_user_write(dev, &msg, NULL, 0) < 0) { - return -1; + return -EPROTO; } =20 if (vhost_user_read(dev, &msg) < 0) { - return -1; + return -EPROTO; } =20 if (msg.hdr.request !=3D VHOST_USER_GET_CONFIG) { - error_report("Received unexpected msg type. Expected %d received %= d", - VHOST_USER_GET_CONFIG, msg.hdr.request); - return -1; + error_setg(errp, + "Received unexpected msg type. Expected %d received %d", + VHOST_USER_GET_CONFIG, msg.hdr.request); + return -EINVAL; } =20 if (msg.hdr.size !=3D VHOST_USER_CONFIG_HDR_SIZE + config_len) { - error_report("Received bad msg size."); - return -1; + error_setg(errp, "Received bad msg size."); + return -EINVAL; } =20 memcpy(config, msg.payload.config.region, config_len); diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 0f469f1823..4fa414feea 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -523,7 +523,7 @@ static int vhost_vdpa_set_config(struct vhost_dev *dev,= const uint8_t *data, } =20 static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, - uint32_t config_len) + uint32_t config_len, Error **errp) { struct vhost_vdpa_config *v_config; unsigned long config_size =3D offsetof(struct vhost_vdpa_config, buf); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index c7f9d8bb06..e8f85a5d2d 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1562,15 +1562,23 @@ void vhost_ack_features(struct vhost_dev *hdev, con= st int *feature_bits, } =20 int vhost_dev_get_config(struct vhost_dev *hdev, uint8_t *config, - uint32_t config_len) + uint32_t config_len, Error **errp) { + ERRP_GUARD(); + int ret; + assert(hdev->vhost_ops); =20 if (hdev->vhost_ops->vhost_get_config) { - return hdev->vhost_ops->vhost_get_config(hdev, config, config_len); + ret =3D hdev->vhost_ops->vhost_get_config(hdev, config, config_len= , errp); + if (ret < 0 && !*errp) { + error_setg_errno(errp, -ret, "vhost_get_config failed"); + } + return ret; } =20 - return -1; + error_setg(errp, "vhost_get_config not implemented"); + return -ENOTSUP; } =20 int vhost_dev_set_config(struct vhost_dev *hdev, const uint8_t *data, --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070409; cv=none; d=zohomail.com; s=zohoarc; b=OjVhYasHWUC8RyElwhIRvtJJBcGNIFCIn+wj626Im9zHCSDHQ8g+90IUgmO2HbDrQBShdLw3+TNb3CFsCMDNQU07QwTDT0BUf6NgTP/rAYImD620833BHkwk2xqDBorcsgNVK8d7sLcE9lehVacwie9c3F89i3X34rWAoQAmW6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070409; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Etn6oUUzO4ANe9n/wA5G/QI1PGrS5csr8Jhf/5aX0G0=; b=FMPbSBPCZuW7DoVX4W2gB6O3xsnREwl2/riMVi6iplaAqp2UsV+k9uKc6d3wEcN66sCfulLBCjCCtnFwNXngYvplRemImp4mFdARRm3y6duM//dyJr5blmSbkHpJAfu/bQCh7fDGrIsc8LmCg2tLSDKcoVwdMfg4BtWa5F80ym0= 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 1625070409217193.37712327218821; Wed, 30 Jun 2021 09:26:49 -0700 (PDT) Received: from localhost ([::1]:47582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyd32-0005xM-4o for importer@patchew.org; Wed, 30 Jun 2021 12:26:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycg9-000382-Kl for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40216) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfk-00079M-Cu for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:09 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-83-Kk66EDYWMkSGL_tXQ0hrSA-1; Wed, 30 Jun 2021 12:02:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 11098800D55; Wed, 30 Jun 2021 16:02:40 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AA22604CD; Wed, 30 Jun 2021 16:02:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068963; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Etn6oUUzO4ANe9n/wA5G/QI1PGrS5csr8Jhf/5aX0G0=; b=BsIT3lo2bp56C+Ul0hFPMjDSDkIQuuCIqiW4FtpiWDXJJq8/LBpq7MtNDH9T0b/VxWmJDJ rrYYeWPD4ugAOn+8bjL3VbxdrBz0rT8rHDhlaxJQ7kN32FqOzAVf0zxmQbrgAescl7FW4a HEI7+L5PH9o7aNNpPzhzRtzP8u89CHU= X-MC-Unique: Kk66EDYWMkSGL_tXQ0hrSA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 23/24] vhost-user-blk: Factor out vhost_user_blk_realize_connect() Date: Wed, 30 Jun 2021 18:02:05 +0200 Message-Id: <20210630160206.276439-24-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This function is the part that we will want to retry if the connection is lost during initialisation, so factor it out to keep the following patch simpler. The error path for vhost_dev_get_config() forgot disconnecting the chardev, add this while touching the code. Signed-off-by: Kevin Wolf Message-Id: <20210609154658.350308-7-kwolf@redhat.com> Reviewed-by: Stefano Garzarella Reviewed-by: Raphael Norwitz Signed-off-by: Kevin Wolf --- hw/block/vhost-user-blk.c | 48 ++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 3770f715da..e49d2e4c83 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -423,6 +423,36 @@ static void vhost_user_blk_event(void *opaque, QEMUChr= Event event) } } =20 +static int vhost_user_blk_realize_connect(VHostUserBlk *s, Error **errp) +{ + DeviceState *dev =3D &s->parent_obj.parent_obj; + int ret; + + s->connected =3D false; + + ret =3D qemu_chr_fe_wait_connected(&s->chardev, errp); + if (ret < 0) { + return ret; + } + + ret =3D vhost_user_blk_connect(dev, errp); + if (ret < 0) { + qemu_chr_fe_disconnect(&s->chardev); + return ret; + } + assert(s->connected); + + ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, + sizeof(struct virtio_blk_config), errp); + if (ret < 0) { + qemu_chr_fe_disconnect(&s->chardev); + vhost_dev_cleanup(&s->dev); + return ret; + } + + return 0; +} + static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -467,22 +497,10 @@ static void vhost_user_blk_device_realize(DeviceState= *dev, Error **errp) =20 s->inflight =3D g_new0(struct vhost_inflight, 1); s->vhost_vqs =3D g_new0(struct vhost_virtqueue, s->num_queues); - s->connected =3D false; - - if (qemu_chr_fe_wait_connected(&s->chardev, errp) < 0) { - goto virtio_err; - } =20 - if (vhost_user_blk_connect(dev, errp) < 0) { - qemu_chr_fe_disconnect(&s->chardev); - goto virtio_err; - } - assert(s->connected); - - ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, - sizeof(struct virtio_blk_config), errp); + ret =3D vhost_user_blk_realize_connect(s, errp); if (ret < 0) { - goto vhost_err; + goto virtio_err; } =20 /* we're fully initialized, now we can operate, so add the handler */ @@ -491,8 +509,6 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) NULL, true); return; =20 -vhost_err: - vhost_dev_cleanup(&s->dev); virtio_err: g_free(s->vhost_vqs); s->vhost_vqs =3D NULL; --=20 2.31.1 From nobody Sun May 19 06:50:48 2024 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=1625070558; cv=none; d=zohomail.com; s=zohoarc; b=T5RowprupCfhtfIkTyxczzx8BzSMl0gCF6ZbzcRtzyYa9evpPJulcBt4RPFsTWbKq9iahlCqUIE5aC/Pntmz7nehVEtpWXan3m8j0G1qikVHtoCgwAjV8HISAhR2w7FVInchGNIeBL3XeCRQ+Z4qCqdaE6D6MbAIvj3Vw747PWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625070558; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WgIVAzybn4sBLVdmGsnWr0e6+AwqrdPF9mwTWyWpiVU=; b=m55etngsEo44qhpKVMAAygdrO0ldsGe3r4lgr9Sv9HyaIXAyKLRcF5f+5fI5WrRiFINwXEKSoP2sfUgftZ5MDJjHkBalGXIbRkPPPtSds6zcKT0OxvOxkJYOLcDz9eWgPu4PqM+wWeuhEHKdnAeQtYR3PepKXoOIRxpIkZm7l8M= 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 1625070558358288.9176880694072; Wed, 30 Jun 2021 09:29:18 -0700 (PDT) Received: from localhost ([::1]:52754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyd5Q-0001C1-VE for importer@patchew.org; Wed, 30 Jun 2021 12:29:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycgH-0003J2-JH for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49315) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lycfu-0007DO-Tr for qemu-devel@nongnu.org; Wed, 30 Jun 2021 12:03:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-123-AWCQ4mqKPACx8Z9_1xzZiQ-1; Wed, 30 Jun 2021 12:02:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B7DB10C1ADC; Wed, 30 Jun 2021 16:02:41 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59C7518AAB; Wed, 30 Jun 2021 16:02:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625068973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WgIVAzybn4sBLVdmGsnWr0e6+AwqrdPF9mwTWyWpiVU=; b=d8oqhk61XSIC14e8pXwfogCGGA/hPRMzzlwm431kJF2xEQV+QeAxQDh2Z+W48Vl7N+Ml+x oxYBLxGFQC26EjzCXY/vHIf9/QbXGL0CBzMwThtOPBTmpURqVojucq3XkgnP8syYr3tgF4 /NJay5X0JvDvquyDmxnrBu8WheoybdY= X-MC-Unique: AWCQ4mqKPACx8Z9_1xzZiQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 24/24] vhost-user-blk: Implement reconnection during realize Date: Wed, 30 Jun 2021 18:02:06 +0200 Message-Id: <20210630160206.276439-25-kwolf@redhat.com> In-Reply-To: <20210630160206.276439-1-kwolf@redhat.com> References: <20210630160206.276439-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.435, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Commit dabefdd6 removed code that was supposed to try reconnecting during .realize(), but actually just crashed and had several design problems. This adds the feature back without the crash in simple cases while also fixing some design problems: Reconnection is now only tried if there was a problem with the connection and not an error related to the content (which would fail again the same way in the next attempt). Reconnection is limited to three attempts (four with the initial attempt) so that we won't end up in an infinite loop if a problem is permanent. If the backend restarts three times in the very short time window of device initialisation, we have bigger problems and erroring out is the right course of action. In the case that a connection error occurs and we reconnect, the error message is printed using error_report_err(), but otherwise ignored. Signed-off-by: Kevin Wolf Message-Id: <20210609154658.350308-8-kwolf@redhat.com> Reviewed-by: Raphael Norwitz Signed-off-by: Kevin Wolf --- hw/block/vhost-user-blk.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index e49d2e4c83..ba13cb87e5 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -31,6 +31,8 @@ #include "sysemu/sysemu.h" #include "sysemu/runstate.h" =20 +#define REALIZE_CONNECTION_RETRIES 3 + static const int user_feature_bits[] =3D { VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_SEG_MAX, @@ -455,8 +457,10 @@ static int vhost_user_blk_realize_connect(VHostUserBlk= *s, Error **errp) =20 static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) { + ERRP_GUARD(); VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + int retries; int i, ret; =20 if (!s->chardev.chr) { @@ -498,7 +502,17 @@ static void vhost_user_blk_device_realize(DeviceState = *dev, Error **errp) s->inflight =3D g_new0(struct vhost_inflight, 1); s->vhost_vqs =3D g_new0(struct vhost_virtqueue, s->num_queues); =20 - ret =3D vhost_user_blk_realize_connect(s, errp); + retries =3D REALIZE_CONNECTION_RETRIES; + assert(!*errp); + do { + if (*errp) { + error_prepend(errp, "Reconnecting after error: "); + error_report_err(*errp); + *errp =3D NULL; + } + ret =3D vhost_user_blk_realize_connect(s, errp); + } while (ret =3D=3D -EPROTO && retries--); + if (ret < 0) { goto virtio_err; } --=20 2.31.1