From nobody Fri Apr 26 15:23:21 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=1659538110; cv=none; d=zohomail.com; s=zohoarc; b=lJTq6/G+q9+QX+t2f3Jj98NRCjDFZu9vg+B6INcANDxOilJ/qn/QpVdsCau+t3jL0764ngIrU1HcGrrUHmQ/TzTTC2HTH/wvLVxlN9NF6mw+o5nVtBiDBZyl1hg8a8zZNJIDnPIUCT60noAWRDX1I371LoO+mzz8yZVSj4No+jk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659538110; 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=Eny/8qwO5TWNRA3nuSkwUS7Ux5CDlm/1H03qJd+sMsE=; b=I9Cv3oe1uedXyVvq0KX9X0LGGr6o1eMbVk207g6BblsJ96ezVdJMZMnEK062vWHzeyLRXyTyghN/ES8EmVEpmH6bLJ/WILskjAmlqaXc+69M9Nn562+Vm9B9TxBnxvCSf27hRvL7HmHNAuHaRHysfQpgucFO9IeEP9xUFphyupM= 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 1659538110266871.7001624785674; Wed, 3 Aug 2022 07:48:30 -0700 (PDT) Received: from localhost ([::1]:37482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJFfh-0000Jt-0T for importer@patchew.org; Wed, 03 Aug 2022 10:48:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFcE-0006Qs-RM for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:44:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34967) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFcB-0002eQ-E1 for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:44:53 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-308-sAopS1HxNbSqeh6fqBeQVg-1; Wed, 03 Aug 2022 10:44:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 51C8B3815D21; Wed, 3 Aug 2022 14:44:49 +0000 (UTC) Received: from localhost (unknown [10.39.193.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A6FD2026D4C; Wed, 3 Aug 2022 14:44:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659537890; 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=Eny/8qwO5TWNRA3nuSkwUS7Ux5CDlm/1H03qJd+sMsE=; b=DMCDLmEMdOx8qFFkyJLFW7wBERGYwhw9GhiUCAppkckMZHsTe+QfSY/nkvs1XwNU53v/9p VtRz/NkYdvkondnnUbOwOqs993LlCMs2S04PqEhXJukQTPhI6zk0pIGuH1a3bPx2Hbhggo xcqcf5WPIh9UoT2iIk1EU5Ft5iRPcGc= X-MC-Unique: sAopS1HxNbSqeh6fqBeQVg-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Stefan Hajnoczi Subject: [PATCH 1/3] block/qcow2: Keep auto_backing_file if possible Date: Wed, 3 Aug 2022 16:44:44 +0200 Message-Id: <20220803144446.20723-2-hreitz@redhat.com> In-Reply-To: <20220803144446.20723-1-hreitz@redhat.com> References: <20220803144446.20723-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659538110772100002 Content-Type: text/plain; charset="utf-8" qcow2_do_open() is used by qcow2_co_invalidate_cache(), i.e. may be run on an image that has been opened before. When reading the backing file string from the image header, compare it against the existing bs->backing_file, and update bs->auto_backing_file only if they differ. auto_backing_file should ideally contain the filename the backing BDS will actually have after opening, i.e. a post-bdrv_refresh_filename() version of what is in the image header. So for example, if the image header reports the following backing file string: json:{"driver": "qcow2", "file": { "driver": "file", "filename": "/tmp/backing.qcow2" }} Then auto_backing_file should contain simply "/tmp/backing.qcow2". Because bdrv_refresh_filename() only works on existing BDSs, though, the way how we get this auto_backing_file value is to have the format driver set it to whatever is in the image header, and when the backing BDS is opened based on that, we update it with the filename the backing BDS actually got. However, qcow2's qcow2_co_invalidate_cache() implementation breaks this because it just resets auto_backing_file to whatever is in the image file without opening a BDS based on it, so we never get auto_backing_file back to the "refreshed" version, and in the example above, it would stay "json:{...}". Then, bs->backing->bs->filename will differ from bs->auto_backing_file, making bdrv_backing_overridden(bs) return true, which will lead bdrv_refresh_filename(bs) to generate a json:{} filename for bs, even though that may not have been necessary. This is reported in the issue linked below. Therefore, skip updating auto_backing_file if nothing has changed in the image header since we last read it. Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1117 Signed-off-by: Hanna Reitz --- block/qcow2.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index c6c6692fb7..a43fee2067 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1696,16 +1696,27 @@ static int coroutine_fn qcow2_do_open(BlockDriverSt= ate *bs, QDict *options, ret =3D -EINVAL; goto fail; } + + s->image_backing_file =3D g_malloc(len + 1); ret =3D bdrv_pread(bs->file, header.backing_file_offset, len, - bs->auto_backing_file, 0); + s->image_backing_file, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read backing file name= "); goto fail; } - bs->auto_backing_file[len] =3D '\0'; - pstrcpy(bs->backing_file, sizeof(bs->backing_file), - bs->auto_backing_file); - s->image_backing_file =3D g_strdup(bs->auto_backing_file); + s->image_backing_file[len] =3D '\0'; + + /* + * Update only when something has changed. This function is calle= d by + * qcow2_co_invalidate_cache(), and we do not want to reset + * auto_backing_file unless necessary. + */ + if (!g_str_equal(s->image_backing_file, bs->backing_file)) { + pstrcpy(bs->backing_file, sizeof(bs->backing_file), + s->image_backing_file); + pstrcpy(bs->auto_backing_file, sizeof(bs->auto_backing_file), + s->image_backing_file); + } } =20 /* --=20 2.36.1 From nobody Fri Apr 26 15:23:21 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=1659538265; cv=none; d=zohomail.com; s=zohoarc; b=ETivppKCsga6ICS1Ikay/Ar384W8MSUkrJZRNmk0oBgrGTpKJDHMYE5ejWpTCE+Eq/onFM35sd7wRzS4rdUh9+kai4tRiPSyd8xO2pEDAKADZcnZey3tw4FAUtu1Q0+tYXXH7/aK1rhZWiEYOiHv4h1iOx6L1UBznQh9jq/NWi4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659538265; 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=K5HfCWfjPKKmO8BGrMcvph/of4e4KrAMKFDU4lZgHjM=; b=Y3idh8NN2wCEfsuKMy14QqUkWrqb3IJjGT8AISlv+2DfV2iIgQGcOiFhKxk2XcwwUB/eI59xgy5T8W82x8nZefJTCDYdyRER7ipF0s1v674t0AwRszDw2l68iq/o36CBRoaFl19jOD53KxOSKLu3CbLNCO+3iK+u+hKR6hCcp+o= 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 16595382655876.788955723612617; Wed, 3 Aug 2022 07:51:05 -0700 (PDT) Received: from localhost ([::1]:44078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJFiB-0004rA-Ch for importer@patchew.org; Wed, 03 Aug 2022 10:51:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFcG-0006Sm-LP for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:44:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:58135) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFcF-0002fq-5t for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:44:56 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-497-tHV5xX7zPEmNrvHCbAiFXA-1; Wed, 03 Aug 2022 10:44:51 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ECF77801585; Wed, 3 Aug 2022 14:44:50 +0000 (UTC) Received: from localhost (unknown [10.39.193.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B48340CFD0A; Wed, 3 Aug 2022 14:44:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659537894; 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=K5HfCWfjPKKmO8BGrMcvph/of4e4KrAMKFDU4lZgHjM=; b=MTkOeHjP70tYzg4bzxr2D2/QBAsKJdLVuF6mVJuQN7sEQDkl/zsCSMM9undH3wPcJ0Pmnz T4KwF67J4c6xJ7y10td0A/08X8ZcUwe5EKeX6fDpIic1LlJJTrfhNC4OTk9Ds3LNpisDmw M4782p6K0KgTfwUcKH2Sz5KVYiLf9/Y= X-MC-Unique: tHV5xX7zPEmNrvHCbAiFXA-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Stefan Hajnoczi Subject: [PATCH 2/3] block/qed: Keep auto_backing_file if possible Date: Wed, 3 Aug 2022 16:44:45 +0200 Message-Id: <20220803144446.20723-3-hreitz@redhat.com> In-Reply-To: <20220803144446.20723-1-hreitz@redhat.com> References: <20220803144446.20723-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659538268385100001 Content-Type: text/plain; charset="utf-8" Just like qcow2, qed invokes its open function in its .bdrv_co_invalidate_cache() implementation. Therefore, just like done for qcow2 in HEAD^, update auto_backing_file only if the backing file string in the image header differs from the one we have read before. Signed-off-by: Hanna Reitz --- block/qed.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/block/qed.c b/block/qed.c index 40943e679b..324ca0e95a 100644 --- a/block/qed.c +++ b/block/qed.c @@ -445,6 +445,8 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverSta= te *bs, QDict *options, } =20 if ((s->header.features & QED_F_BACKING_FILE)) { + g_autofree char *backing_file_str =3D NULL; + if ((uint64_t)s->header.backing_filename_offset + s->header.backing_filename_size > s->header.cluster_size * s->header.header_size) { @@ -452,16 +454,21 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverS= tate *bs, QDict *options, return -EINVAL; } =20 + backing_file_str =3D g_malloc(sizeof(bs->backing_file)); ret =3D qed_read_string(bs->file, s->header.backing_filename_offse= t, s->header.backing_filename_size, - bs->auto_backing_file, - sizeof(bs->auto_backing_file)); + backing_file_str, sizeof(bs->backing_file)); if (ret < 0) { error_setg(errp, "Failed to read backing filename"); return ret; } - pstrcpy(bs->backing_file, sizeof(bs->backing_file), - bs->auto_backing_file); + + if (!g_str_equal(backing_file_str, bs->backing_file)) { + pstrcpy(bs->backing_file, sizeof(bs->backing_file), + backing_file_str); + pstrcpy(bs->auto_backing_file, sizeof(bs->auto_backing_file), + backing_file_str); + } =20 if (s->header.features & QED_F_BACKING_FORMAT_NO_PROBE) { pstrcpy(bs->backing_format, sizeof(bs->backing_format), "raw"); --=20 2.36.1 From nobody Fri Apr 26 15:23:21 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=1659538144; cv=none; d=zohomail.com; s=zohoarc; b=EChfgxp6g3HRA+1H4nm9PGyezdNmmSZLWN17CkrRdb7M7viRJ/JI6UGYuBspiChDymAG3uwHhXpnmeVj3uzsNzmTfam64wIYXoukAvxOpeez6fTXFWjSvjabTIDIMf5dvQJ9uGiJ/LrxA9Dz8cQVKBORrdqruwNKEWFuT4ljrts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659538144; 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=gPTpJKQmJ5CjbixxfOK6/Br8MhSadxcQXbhjhetEHPo=; b=BAyoWHCMUQ4KcL/CD1y3zlbVWoOSHIiWGs6Q2Qghqae35d48UvAr7s1Yd8KVCGXmdWyhTzzVzg+Wxq3/T9z34PEhdeqqZfAOmOoJOAMJIp+fvAdL/qk70mQqqHsBTZv+/fGKFiguUH1gqr0ofDHMylNSdVcfAVvUZudAg+Mu3Hk= 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 16595381439952.1399580768357964; Wed, 3 Aug 2022 07:49:03 -0700 (PDT) Received: from localhost ([::1]:38168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJFgC-0000m9-Vs for importer@patchew.org; Wed, 03 Aug 2022 10:49:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFcG-0006St-Sf for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:44:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:29112) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFcE-0002es-R8 for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:44:56 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-423-r0Myhr5DOnaQ1I_LidPrQA-1; Wed, 03 Aug 2022 10:44:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ABD19280400C; Wed, 3 Aug 2022 14:44:52 +0000 (UTC) Received: from localhost (unknown [10.39.193.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B2BF1121314; Wed, 3 Aug 2022 14:44:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659537894; 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=gPTpJKQmJ5CjbixxfOK6/Br8MhSadxcQXbhjhetEHPo=; b=adBuMmicnvLAM9Q8EAt7ta6cPVmrT2q309z8qEH9KUrBlR1aXEoOJZaRiipY3VHupvlc0H 4Viig1A8SCkgFkqre2MNI40ezG4bszlcmaOIHqJF0aeqlZwAe2lKF5l+R3csYb7adp7nMA Es4XGMcmEU9NtQPphsKJK7JJdMtocLU= X-MC-Unique: r0Myhr5DOnaQ1I_LidPrQA-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Stefan Hajnoczi Subject: [PATCH 3/3] iotests/backing-file-invalidation: Add new test Date: Wed, 3 Aug 2022 16:44:46 +0200 Message-Id: <20220803144446.20723-4-hreitz@redhat.com> In-Reply-To: <20220803144446.20723-1-hreitz@redhat.com> References: <20220803144446.20723-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659538145047100003 Content-Type: text/plain; charset="utf-8" Add a new test to see what happens when you migrate a VM with a backing chain that has json:{} backing file strings, which, when opened, will be resolved to plain filenames. Signed-off-by: Hanna Reitz --- .../tests/backing-file-invalidation | 152 ++++++++++++++++++ .../tests/backing-file-invalidation.out | 5 + 2 files changed, 157 insertions(+) create mode 100755 tests/qemu-iotests/tests/backing-file-invalidation create mode 100644 tests/qemu-iotests/tests/backing-file-invalidation.out diff --git a/tests/qemu-iotests/tests/backing-file-invalidation b/tests/qem= u-iotests/tests/backing-file-invalidation new file mode 100755 index 0000000000..4eccc80153 --- /dev/null +++ b/tests/qemu-iotests/tests/backing-file-invalidation @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +# group: rw migration +# +# Migrate a VM with a BDS with backing nodes, which runs +# bdrv_invalidate_cache(), which for qcow2 and qed triggers reading the +# backing file string from the image header. Check whether this +# interferes with bdrv_backing_overridden(). +# +# Copyright (C) 2022 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import json +import os +from typing import Optional + +import iotests +from iotests import qemu_img_create, qemu_img_info + + +image_size =3D 1 * 1024 * 1024 +imgs =3D [os.path.join(iotests.test_dir, f'{i}.img') for i in range(0, 4)] + +mig_sock =3D os.path.join(iotests.sock_dir, 'mig.sock') + + +class TestPostMigrateFilename(iotests.QMPTestCase): + vm_s: Optional[iotests.VM] =3D None + vm_d: Optional[iotests.VM] =3D None + + def setUp(self) -> None: + # Create backing chain of three images, where the backing file str= ings + # are json:{} filenames + qemu_img_create('-f', iotests.imgfmt, imgs[0], str(image_size)) + for i in range(1, 3): + backing =3D { + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': imgs[i - 1] + } + } + qemu_img_create('-f', iotests.imgfmt, '-F', iotests.imgfmt, + '-b', 'json:' + json.dumps(backing), + imgs[i], str(image_size)) + + def tearDown(self) -> None: + if self.vm_s is not None: + self.vm_s.shutdown() + if self.vm_d is not None: + self.vm_d.shutdown() + + for img in imgs: + try: + os.remove(img) + except OSError: + pass + try: + os.remove(mig_sock) + except OSError: + pass + + def test_migration(self) -> None: + """ + Migrate a VM with the backing chain created in setUp() attached. = At + the end of the migration process, the destination will run + bdrv_invalidate_cache(), which for some image formats (qcow2 and q= ed) + means the backing file string is re-read from the image header. If + this overwrites bs->auto_backing_file, doing so may cause + bdrv_backing_overridden() to become true: The image header reports= a + json:{} filename, but when opening it, bdrv_refresh_filename() will + simplify it to a plain simple filename; and when bs->auto_backing_= file + and bs->backing->bs->filename differ, bdrv_backing_overridden() be= comes + true. + If bdrv_backing_overridden() is true, the BDS will be forced to ge= t a + json:{} filename, which in general is not the end of the world, bu= t not + great. Check whether that happens, i.e. whether migration changes= the + node's filename. + """ + + blockdev =3D { + 'node-name': 'node0', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': imgs[2] + } + } + + self.vm_s =3D iotests.VM(path_suffix=3D'a') \ + .add_blockdev(json.dumps(blockdev)) + self.vm_d =3D iotests.VM(path_suffix=3D'b') \ + .add_blockdev(json.dumps(blockdev)) \ + .add_incoming(f'unix:{mig_sock}') + + assert self.vm_s is not None + assert self.vm_d is not None + + self.vm_s.launch() + self.vm_d.launch() + + pre_mig_filename =3D self.vm_s.node_info('node0')['file'] + + self.vm_s.qmp('migrate', uri=3Df'unix:{mig_sock}') + + # Wait for migration to be done + self.vm_s.event_wait('STOP') + self.vm_d.event_wait('RESUME') + + post_mig_filename =3D self.vm_d.node_info('node0')['file'] + + # Verify that the filename hasn't changed from before the migration + self.assertEqual(pre_mig_filename, post_mig_filename) + + self.vm_s.shutdown() + self.vm_s =3D None + + # For good measure, try creating an overlay and check its backing + # chain below. This is how the issue was originally found. + result =3D self.vm_d.qmp('blockdev-snapshot-sync', + format=3Diotests.imgfmt, + snapshot_file=3Dimgs[3], + node_name=3D'node0', + snapshot_node_name=3D'node0-overlay') + self.assert_qmp(result, 'return', {}) + + self.vm_d.shutdown() + self.vm_d =3D None + + # Check the newly created overlay's backing chain + chain =3D qemu_img_info('--backing-chain', imgs[3]) + for index, image in enumerate(chain): + self.assertEqual(image['filename'], imgs[3 - index]) + + +if __name__ =3D=3D '__main__': + # These are the image formats that run their open() function from their + # .bdrv_co_invaliate_cache() implementations, so test them + iotests.main(supported_fmts=3D['qcow2', 'qed'], + supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/tests/backing-file-invalidation.out b/tests= /qemu-iotests/tests/backing-file-invalidation.out new file mode 100644 index 0000000000..ae1213e6f8 --- /dev/null +++ b/tests/qemu-iotests/tests/backing-file-invalidation.out @@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK --=20 2.36.1