From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005950; cv=none; d=zohomail.com; s=zohoarc; b=QtqzjSMEt/rTniTJDJY8205YE+IS+RIKqQWsTK+6BB4/UiifItINmO2zz+VGAh+hVG/7vixluEVKAh68aQDUaLa5uAVomfYHscW6BOSswz5xeZquTIyauPAQMBhTgz4dbRk6kTXWl2b0//DZzwAXTECu6j9RQStAaFZoo25hrEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005950; h=Content-Type:Content-Transfer-Encoding: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=YI4+bmLyo5XI0oOGwRj21muBiyiSuYqzMWErxCyiOgA=; b=nm7kLrVn8At/i7QFI0eUtEmbuZbYMxLEB/j1vSH+8BNuQNaDVFFGiXK/KTwnP50A8a0/PQanp3O5jhjBETrJPEkU1rVQ2BrRGf0jX7+C9McnwhYEZ58ktbQVgOQbQG4M90qGehzFPyDjkneSvQY9TABENTlOQBZXqfudqrCfGMI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005950616674.1384803798891; Mon, 14 Aug 2023 02:39:10 -0700 (PDT) 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-131-dnqHCgGLN6qY1Q_0h1euzw-1; Mon, 14 Aug 2023 05:36:46 -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 CC9E6823DFF; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7024D40C2073; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 271D81946587; Mon, 14 Aug 2023 09:36:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 712571946587 for ; Mon, 14 Aug 2023 09:36:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1080440C206F; Mon, 14 Aug 2023 09:36:19 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id A709E40C2063 for ; Mon, 14 Aug 2023 09:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005949; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YI4+bmLyo5XI0oOGwRj21muBiyiSuYqzMWErxCyiOgA=; b=H7zIKZbWRXg1slh6j534yEzWjphQz6YN4AIKWkoio0j7uXOgvpP3nZug2zbjKcVbXjFlX/ bDecC6gJiaX9BmdlOCwEFWz8A0nU2hvWMMjq5lenqlN1X6y7bTkur1v66ND8J86jmXsH47 NzSxclpEz4UBBg37iFcgj/xlNWGj4HI= X-MC-Unique: dnqHCgGLN6qY1Q_0h1euzw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 01/25] libvirt_private: list virDomainMomentDefPostParse Date: Mon, 14 Aug 2023 11:35:53 +0200 Message-ID: <6967cf9d7c5ffbc318bcfbf896b3da1d906c16d4.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005951901100001 Content-Type: text/plain; charset="utf-8"; x-default="true" We will need to call this function from qemu_snapshot when introducing external snapshot revert support. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index da60c965dd..aeb54d8952 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -807,6 +807,10 @@ virInterfaceDefParseString; virInterfaceDefParseXML; =20 =20 +# conf/moment_conf.h +virDomainMomentDefPostParse; + + # conf/netdev_bandwidth_conf.h virDomainClearNetBandwidth; virNetDevBandwidthFormat; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005822; cv=none; d=zohomail.com; s=zohoarc; b=UJIUsVmLiWcLarsFxckP+LAuifiOEux0scH5f9Q10wMwm5+LwWYibCozlqsh1imRkNLNsfjzzTuxvrjZs6uDHW7dBippQOfhxOwx3qntXp4kBd1z0Y6MzoHpwlHjUNZ+fFDVoujiIiVpqyDFYQlM/cXXltDABS89zr2emFIgx3A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005822; h=Content-Type:Content-Transfer-Encoding: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=VG92HCVg+GQIlqIEgzY3RK3XWkPirr/TU7t3dLTfVTc=; b=O4XDj05gF2w+Cvfxk8TKbRi0SgRztaTUOJuA2KQI+sIWNqJOz9AAoDkv7ddf3jkb9FTl64FvSxkTgLcbjVejwLVlbKYPDfkHgj8h08+ELQtvRRWhezHt+qpsy3aSBitsvQLqUw4cECEouP5hRT+D2HaAdMdebMyM/yzvtnrQjFY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005822012782.2447619667139; Mon, 14 Aug 2023 02:37:02 -0700 (PDT) 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-152-el5aTuMwPem4uILUXestHA-1; Mon, 14 Aug 2023 05:36:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EADD48057A4; Mon, 14 Aug 2023 09:36:53 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D67B263F79; Mon, 14 Aug 2023 09:36:53 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AE6601946A5E; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 70E871946586 for ; Mon, 14 Aug 2023 09:36:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A6F7840C2070; Mon, 14 Aug 2023 09:36:19 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A29440C2063 for ; Mon, 14 Aug 2023 09:36:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005820; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VG92HCVg+GQIlqIEgzY3RK3XWkPirr/TU7t3dLTfVTc=; b=L287tJI90yvZJhato4HLm8CJzCNYAQMq2/wZ32ux2BnvfvoeFojEajFzfytjBz3Ccl7qW9 JnFB0GTRNt9EECAxz38E6/PUeweNaReBvPERo9lekGiS/pNlZ5+oWZNcM5IYlOl+F5kXFE +nMFBvhv0j8N+As7KbPYdsK2wxI687Q= X-MC-Unique: el5aTuMwPem4uILUXestHA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 02/25] snapshot_conf: export virDomainSnapshotDiskDefClear Date: Mon, 14 Aug 2023 11:35:54 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005822955100001 Content-Type: text/plain; charset="utf-8"; x-default="true" We will need to call this function from qemu_snapshot when introducing external snapshot revert support. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/conf/snapshot_conf.c | 2 +- src/conf/snapshot_conf.h | 3 +++ src/libvirt_private.syms | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 0acba95d7f..cc59bddbc8 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -74,7 +74,7 @@ VIR_ENUM_IMPL(virDomainSnapshotState, ); =20 /* Snapshot Def functions */ -static void +void virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDef *disk) { VIR_FREE(disk->name); diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 96c77ef42b..ad49990a1e 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -59,6 +59,9 @@ struct _virDomainSnapshotDiskDef { virStorageSource *src; }; =20 +void +virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDef *disk); + void virDomainSnapshotDiskDefFree(virDomainSnapshotDiskDef *disk); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index aeb54d8952..a75156f097 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1037,6 +1037,7 @@ virDomainSnapshotDefFormat; virDomainSnapshotDefIsExternal; virDomainSnapshotDefNew; virDomainSnapshotDefParseString; +virDomainSnapshotDiskDefClear; virDomainSnapshotDiskDefFree; virDomainSnapshotDiskDefParseXML; virDomainSnapshotFormatConvertXMLFlags; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005821; cv=none; d=zohomail.com; s=zohoarc; b=KAqZVXdsuuixByoDEcDL34+x70Uwk9D+SYmONOAx1N0WWeO3NIaqGo5P8/ZshdUtWfGyDRc0NOPI+ehTnBhjroCqRxrTIKfNHqj6gJJEZwdAUv8Z4pcLR8W8h/SBdXkxpUViYHWvHyx2m1Lc0ap3JlFc2/8GHEL/NkdmevcAzvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005821; h=Content-Type:Content-Transfer-Encoding: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=qam5xeFztWJUQbV2Ep9yhW3YXlrPa2qmzvVIUxMwFwo=; b=ChzYbR7LSJ6TzHoJ7bwVjEytNNYt6/zHQukZAxINKrhL++K9V8gx19XMuM0oYoq6e3FesPd3f9HQNovK9MxKSNiLm6btAOTaQgVcHhc6bJeNNzHNynjuDluwbYDPyjY+fav0kyZ9E7T9zpPDwsslWUgHFiHb6D0dUy16jdQc20o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692005821853193.44201631700855; Mon, 14 Aug 2023 02:37:01 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [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-45-OoVYs3ZsMA6WQINh8o39hg-1; Mon, 14 Aug 2023 05:36:55 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D000A3814948; Mon, 14 Aug 2023 09:36:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5B2A140E919; Mon, 14 Aug 2023 09:36:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6EF6A19465B7; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 75FCB194658D for ; Mon, 14 Aug 2023 09:36:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 49F8040C2071; Mon, 14 Aug 2023 09:36:20 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E061040C2063 for ; Mon, 14 Aug 2023 09:36:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005820; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qam5xeFztWJUQbV2Ep9yhW3YXlrPa2qmzvVIUxMwFwo=; b=JwJtAyBeac0O7LvQGVaY//e3NZktIRNRUh0P0CefjNIh4vpruK0ZoGEwoE3ICAc48JFtxe IuD+lU62DcVhYDknKG6fl50sKgsNmO0cZIbbl+1NzzqOqIiwe23hGpxbv7GQwHGvJtzqfu k+8OgNetoMAXRk573G973IRckdDra2M= X-MC-Unique: OoVYs3ZsMA6WQINh8o39hg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 03/25] snapshot_conf: use alternate domain definition in virDomainSnapshotDefAssignExternalNames Date: Mon, 14 Aug 2023 11:35:55 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005823039100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Commit introduced new argument for virDomainSnapshotAlignDisks() that allows passing alternate domain definition in case the snapshot parent.dom is NULL. In case of redefining snapshot it will not hit the part of code that unconditionally uses parent.dom as there will not be need to generate default external file names. It should be still fixed to make it safe. Future external snapshot revert code will use this to generate default file names and in this case it would crash. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/conf/snapshot_conf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index cc59bddbc8..ac5aba1753 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -486,12 +486,14 @@ virDomainSnapshotRedefineValidate(virDomainSnapshotDe= f *def, /** * virDomainSnapshotDefAssignExternalNames: * @def: snapshot def object + * @domdef: domain def object * * Generate default external file names for snapshot targets. Returns 0 on * success, -1 on error. */ static int -virDomainSnapshotDefAssignExternalNames(virDomainSnapshotDef *def) +virDomainSnapshotDefAssignExternalNames(virDomainSnapshotDef *def, + virDomainDef *domdef) { const char *origpath; char *tmppath; @@ -514,7 +516,7 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnapsh= otDef *def) return -1; } =20 - if (!(origpath =3D virDomainDiskGetSource(def->parent.dom->disks[i= ]))) { + if (!(origpath =3D virDomainDiskGetSource(domdef->disks[i]))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("cannot generate external snapshot name for d= isk '%1$s' without source"), disk->name); @@ -702,7 +704,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapd= ef, } =20 /* Generate default external file names for external snapshot location= s */ - if (virDomainSnapshotDefAssignExternalNames(snapdef) < 0) + if (virDomainSnapshotDefAssignExternalNames(snapdef, domdef) < 0) return -1; =20 return 0; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005833; cv=none; d=zohomail.com; s=zohoarc; b=X4gGwEW1JzNgFWQiSRxZ9nBuxNnxnyWGavNQYTeIOShIyVqRyCVRc8VbLQNKwtWmfm+ywV+WLm/xT+NZxaPsrtT/mCQffUy217/2FqUyTppF/AWnvyhcEm+Ilbu8orRlW6f1KJH5HubgCYD1FsxHSVM3fbehNZt6RF9uq3BVgNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005833; h=Content-Type:Content-Transfer-Encoding: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=lcbeSGhSE2vdCUG+LoWIDYSTgXUW6afwqbpaXrhi7M8=; b=MEFyZei2O76mn/t+mgiyj3XGwflOro3Wp1kCuYWWowN/Iq+nGwjNBqP7xYEDhGdL6YUzfPwsqa06SPIPJeVCjEdI0IPZhnRxVqkKLk0CTlB0wR5XDOZFi4wf7kgjIed3LT0+riM61T7CyVVJJ/L4ZJzF533dLTZ+McVneFTyE/E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005833416496.511714384857; Mon, 14 Aug 2023 02:37:13 -0700 (PDT) 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-621-OqxzEFy6NXSOUKphnih7pw-1; Mon, 14 Aug 2023 05:36:47 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CB8A8830D2B; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E31EE140E919; Mon, 14 Aug 2023 09:36:42 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 315DE1946A63; Mon, 14 Aug 2023 09:36:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 73E84194658C for ; Mon, 14 Aug 2023 09:36:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E26A040C2063; Mon, 14 Aug 2023 09:36:20 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 853C640C2073 for ; Mon, 14 Aug 2023 09:36:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005832; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=lcbeSGhSE2vdCUG+LoWIDYSTgXUW6afwqbpaXrhi7M8=; b=EdZIHForr7HGf6EizeCF1mhanpsvOs9mVO+cuvwHMfX25YimpdXNKRF6jx7j84hD5qHb4o B5zrQMbqiyx5oEClNvMfJYBBFgKzMuG5ama3B4+6ovqALCM8STz70Ce3byDcVcloSmu/ei RtMbuW+i6+cHijfQb05X4YqbjLUbTbk= X-MC-Unique: OqxzEFy6NXSOUKphnih7pw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 04/25] snapshot_conf: introduce metadata element Date: Mon, 14 Aug 2023 11:35:56 +0200 Message-ID: <494fdeefa4496aa40115e1f9cab463ba5289d825.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005834961100005 Content-Type: text/plain; charset="utf-8"; x-default="true" This new element will hold the new disk overlay created when reverting to non-leaf snapshot in order to remember the files libvirt created. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/conf/schemas/domainsnapshot.rng | 7 +++++++ src/conf/snapshot_conf.c | 30 +++++++++++++++++++++++++++++ src/conf/snapshot_conf.h | 5 +++++ 3 files changed, 42 insertions(+) diff --git a/src/conf/schemas/domainsnapshot.rng b/src/conf/schemas/domains= napshot.rng index 45f01b96cd..2549c47b22 100644 --- a/src/conf/schemas/domainsnapshot.rng +++ b/src/conf/schemas/domainsnapshot.rng @@ -60,6 +60,13 @@ + + + + + + + diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index ac5aba1753..8ecf311a17 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -112,6 +112,9 @@ virDomainSnapshotDefDispose(void *obj) for (i =3D 0; i < def->ndisks; i++) virDomainSnapshotDiskDefClear(&def->disks[i]); g_free(def->disks); + for (i =3D 0; i < def->nrevertdisks; i++) + virDomainSnapshotDiskDefClear(&def->revertdisks[i]); + g_free(def->revertdisks); virObjectUnref(def->cookie); } =20 @@ -376,6 +379,22 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, return NULL; } =20 + if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) { + g_autofree xmlNodePtr *revertDiskNodes =3D NULL; + + if ((n =3D virXPathNodeSet("./revertDisks/*", ctxt, &revertDiskNod= es)) < 0) + return NULL; + if (n) + def->revertdisks =3D g_new0(virDomainSnapshotDiskDef, n); + def->nrevertdisks =3D n; + for (i =3D 0; i < def->nrevertdisks; i++) { + if (virDomainSnapshotDiskDefParseXML(revertDiskNodes[i], ctxt, + &def->revertdisks[i], + flags, xmlopt) < 0) + return NULL; + } + } + if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL) { int active; =20 @@ -834,6 +853,17 @@ virDomainSnapshotDefFormatInternal(virBuffer *buf, virBufferAddLit(buf, "\n"); } =20 + if (def->nrevertdisks > 0) { + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + + for (i =3D 0; i < def->nrevertdisks; i++) { + if (virDomainSnapshotDiskDefFormat(&childBuf, &def->revertdisk= s[i], xmlopt) < 0) + return -1; + } + + virXMLFormatElement(buf, "revertDisks", NULL, &childBuf); + } + if (def->parent.dom) { if (virDomainDefFormatInternal(def->parent.dom, xmlopt, buf, domainflags) < 0) diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index ad49990a1e..ab76af604a 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -80,6 +80,11 @@ struct _virDomainSnapshotDef { size_t ndisks; /* should not exceed dom->ndisks */ virDomainSnapshotDiskDef *disks; =20 + /* When we revert to non-leaf snapshot we need to + * store the new overlay disks. */ + size_t nrevertdisks; + virDomainSnapshotDiskDef *revertdisks; + virObject *cookie; }; =20 --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005812; cv=none; d=zohomail.com; s=zohoarc; b=gyt3ZF73ZUgFOi6+vAPWLFzAhFWEXKS5c1KjqvINSTra/HetQsr4A7jNV12CyBFpBjzyShJE5n3BPh7hRuHokCGQKVLKfuqS1eWJSvfpl57b77oh2SuNVBqG2y/aErJBhv2QWxTIqx2DZH+QdGpp8DGv/AOgRdfbmX+P0N0Kvh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005812; h=Content-Type:Content-Transfer-Encoding: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=sPy6biOB3CUTfiGkUREcvnd+78DqvHP8GGhslXWmot8=; b=UvDUU/Nv55799Mk3aWVp2oxZjEB2HqrX2md6jbbE05MNooCLRhzLyGkEVEpnnErAiQ8w07E7ZfOmMa11Bm4+9hpgZ6Nl9F0r0FfSEScl5PdMN7AXS9Br2MQA8xjg97C+G4hvhnUnF+z0ZL/tO2WakQcK9uDsgMc6UvG1nSZ7BT4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692005812453300.02149329886674; Mon, 14 Aug 2023 02:36:52 -0700 (PDT) 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-161-P3UjIfFOM9i8aRQVkqARCQ-1; Mon, 14 Aug 2023 05:36:47 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F41CB823D75; Mon, 14 Aug 2023 09:36:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E288F401E6A; Mon, 14 Aug 2023 09:36:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D8A7519465B3; Mon, 14 Aug 2023 09:36:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 915231946597 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8549140C2074; Mon, 14 Aug 2023 09:36:21 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2805440C2073 for ; Mon, 14 Aug 2023 09:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005811; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=sPy6biOB3CUTfiGkUREcvnd+78DqvHP8GGhslXWmot8=; b=ezIREmxNc+2oSBTbD0DuhMkc/37SvafeW27GptaUNGOXcy3xvdCgcyQ3x67bSt4nb71ndG XK6XiIcZ42S1RnJsYzIPPO0Hc0iu5PGJ/WatbZD3J1OGgnINne+TdESfc4t+pbx37nyPB2 eIybH2TceprEq2MO7YGhRJ1jLGspxyA= X-MC-Unique: P3UjIfFOM9i8aRQVkqARCQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 05/25] virDomainSnapshotAlignDisks: Allow overriding user-configured snapshot default Date: Mon, 14 Aug 2023 11:35:57 +0200 Message-ID: <5598d91b29bd944a369a6f43eda52812a6626415.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005814516100005 Content-Type: text/plain; charset="utf-8"; x-default="true" This new option will be used by external snapshot revert code. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/conf/snapshot_conf.c | 15 ++++++++++++--- src/conf/snapshot_conf.h | 3 ++- src/qemu/qemu_snapshot.c | 2 +- src/test/test_driver.c | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 8ecf311a17..67cec34920 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -581,6 +581,8 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnapsh= otDef *def, * @default_snapshot: snapshot location to assign to disks which don't hav= e any * @uniform_internal_snapshot: Require that for an internal snapshot all d= isks * take part in the internal snapshot + * @force_default_location: Always use @default_snapshot even if domain def + * has different default value * * Align snapdef->disks to domain definition, filling in any missing disks= or * snapshot state defaults given by the domain, with a fallback to @@ -598,6 +600,10 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnaps= hotDef *def, * in the internal snapshot. This is for hypervisors where granularity of = an * internal snapshot can't be controlled. * + * When @force_default_location is true we will always use @default_snapsh= ot + * even if domain definition has different default set. This is required to + * create new snapshot definition when reverting external snapshots. + * * Convert paths to disk targets for uniformity. * * On error -1 is returned and a libvirt error is reported. @@ -606,7 +612,8 @@ int virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapdef, virDomainDef *existingDomainDef, virDomainSnapshotLocation default_snapshot, - bool uniform_internal_snapshot) + bool uniform_internal_snapshot, + bool force_default_location) { virDomainDef *domdef =3D snapdef->parent.dom; g_autoptr(GHashTable) map =3D virHashNew(NULL); @@ -714,7 +721,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapd= ef, /* Don't snapshot empty drives */ if (virStorageSourceIsEmpty(domdef->disks[i]->src)) snapdisk->snapshot =3D VIR_DOMAIN_SNAPSHOT_LOCATION_NO; - else + else if (!force_default_location) snapdisk->snapshot =3D domdef->disks[i]->snapshot; =20 snapdisk->src->type =3D VIR_STORAGE_TYPE_FILE; @@ -970,8 +977,10 @@ virDomainSnapshotRedefinePrep(virDomainObj *vm, virDomainSnapshotDefIsExternal(snapdef)) align_location =3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL; =20 - if (virDomainSnapshotAlignDisks(snapdef, otherDomDef, align_location, = true) < 0) + if (virDomainSnapshotAlignDisks(snapdef, otherDomDef, align_location, + true, false) < 0) { return -1; + } =20 return 0; } diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index ab76af604a..14254d1c86 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -126,7 +126,8 @@ char *virDomainSnapshotDefFormat(const char *uuidstr, int virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapshot, virDomainDef *existingDomainDef, virDomainSnapshotLocation default_snapshot, - bool uniform_internal_snapshot); + bool uniform_internal_snapshot, + bool force_default_location); =20 bool virDomainSnapshotDefIsExternal(virDomainSnapshotDef *def); bool virDomainSnapshotIsExternal(virDomainMomentObj *snap); diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 91de8b0c31..844b02d427 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1585,7 +1585,7 @@ qemuSnapshotCreateAlignDisks(virDomainObj *vm, else def->memory =3D VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL; } - if (virDomainSnapshotAlignDisks(def, NULL, align_location, true) < 0) + if (virDomainSnapshotAlignDisks(def, NULL, align_location, true, false= ) < 0) return -1; =20 return 0; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 4b8e02c684..905be3853b 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -8724,7 +8724,7 @@ testDomainSnapshotAlignDisks(virDomainObj *vm, VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL; } =20 - return virDomainSnapshotAlignDisks(def, NULL, align_location, true); + return virDomainSnapshotAlignDisks(def, NULL, align_location, true, fa= lse); } =20 =20 --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005891; cv=none; d=zohomail.com; s=zohoarc; b=TDUhDFkuNHJC8me9ucTqlzVNbwdFzKJUzMd510MMoZviBjHC47oeLOczVPx35vJ44+uXJHsJEbCtc9wmLVve+zpYROXep/NY04WdmqWvPM6LWm048lshCEwU5xXP1IPZ/PMlz8uW0xuTguFET79e1DorYqEfeiPN3WJuOIvWsBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005891; h=Content-Type:Content-Transfer-Encoding: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=xyv7w5pFBOuTwmP/dkcpLwPBcqaR/kuT6E1NlX/d9a4=; b=aVSCE4CtJFidMI2LACnyF/+YGAoRTjTE2/iB6NHtDFAQgEc3GNxFIDmBGfVudrzuawIKhM5OC9wMB+RTGqXnGBPIn44OTCprfoEsnkRmiOsV4xMjp1irCG5EIWu69IXJgE9+5+EncpZEiIwACJ83VgUoXe368/XpJCizIbo9o1M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005891286595.571135699207; Mon, 14 Aug 2023 02:38:11 -0700 (PDT) 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-108-r3kSumiLOvmsXkCttm2mUQ-1; Mon, 14 Aug 2023 05:37:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8095985D06F; Mon, 14 Aug 2023 09:36:55 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B99C40D2839; Mon, 14 Aug 2023 09:36:55 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3B23919459EC; Mon, 14 Aug 2023 09:36:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 914871946595 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2769740C2076; Mon, 14 Aug 2023 09:36:22 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF00940C2073 for ; Mon, 14 Aug 2023 09:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005890; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xyv7w5pFBOuTwmP/dkcpLwPBcqaR/kuT6E1NlX/d9a4=; b=Eo3V0OhDAdpg1U1RbZVdKtV+yU+rbX819UECybALUGtaYJC9W4danvAfIY9gTqV8gH1TQU wPTV2Fmd1pnXkAOeZ/P7EFpd8CAwFYw3Hiu5xSghIiZmsSVDfXAnl7m4kPU0rAaRgIPsvY nTBZJ9TuGGaX+6tNU6k/iIAYhxZpsSg= X-MC-Unique: r3kSumiLOvmsXkCttm2mUQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 06/25] qemu_snapshot: introduce qemuSnapshotDomainDefUpdateDisk Date: Mon, 14 Aug 2023 11:35:58 +0200 Message-ID: <2467d67634184af54f7c636786ff678a15eacf50.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005893172100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Extract the code that updates disks in domain definition while creating external snapshots. We will use it later in the external snapshot revert code. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 63 ++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 844b02d427..72a0f71d4f 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -142,6 +142,42 @@ qemuSnapshotFSThaw(virDomainObj *vm, } =20 =20 +static int +qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef, + virDomainSnapshotDef *snapdef, + bool reuse) +{ + size_t i; + + for (i =3D 0; i < snapdef->ndisks; i++) { + g_autoptr(virStorageSource) newsrc =3D NULL; + virDomainSnapshotDiskDef *snapdisk =3D &(snapdef->disks[i]); + virDomainDiskDef *defdisk =3D domdef->disks[i]; + + if (snapdisk->snapshot !=3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) + continue; + + if (!(newsrc =3D virStorageSourceCopy(snapdisk->src, false))) + return -1; + + if (virStorageSourceInitChainElement(newsrc, defdisk->src, false) = < 0) + return -1; + + if (!reuse && + virStorageSourceHasBacking(defdisk->src)) { + defdisk->src->readonly =3D true; + newsrc->backingStore =3D g_steal_pointer(&defdisk->src); + } else { + virObjectUnref(defdisk->src); + } + + defdisk->src =3D g_steal_pointer(&newsrc); + } + + return 0; +} + + /* The domain is expected to be locked and inactive. */ static int qemuSnapshotCreateInactiveInternal(virQEMUDriver *driver, @@ -216,31 +252,8 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *driv= er, } =20 /* update disk definitions */ - for (i =3D 0; i < snapdef->ndisks; i++) { - g_autoptr(virStorageSource) newsrc =3D NULL; - - snapdisk =3D &(snapdef->disks[i]); - defdisk =3D vm->def->disks[i]; - - if (snapdisk->snapshot !=3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) - continue; - - if (!(newsrc =3D virStorageSourceCopy(snapdisk->src, false))) - goto cleanup; - - if (virStorageSourceInitChainElement(newsrc, defdisk->src, false) = < 0) - goto cleanup; - - if (!reuse && - virStorageSourceHasBacking(defdisk->src)) { - defdisk->src->readonly =3D true; - newsrc->backingStore =3D g_steal_pointer(&defdisk->src); - } else { - virObjectUnref(defdisk->src); - } - - defdisk->src =3D g_steal_pointer(&newsrc); - } + if (qemuSnapshotDomainDefUpdateDisk(vm->def, snapdef, reuse) < 0) + goto cleanup; =20 if (virDomainDefSave(vm->def, driver->xmlopt, cfg->configDir) < 0) goto cleanup; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005812; cv=none; d=zohomail.com; s=zohoarc; b=oEm9iKHSBtVhz0LNNjKe0uEDmYYwtQHzp4Li5kxVreVSgmI56XoqSMW2zT6F1+4+UTzu4kkcAL70hwLVXZR8ufx+V+ase1L3x1v4P0qIkME9GB+VPZ0J9yWi+gFRXgNDrta3eqa5mjtTugCUuZzmBAMcUiZgrlSb+g1nHGIiQ5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005812; h=Content-Type:Content-Transfer-Encoding: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=KEH6nhUmhscP/MylJEv+o4MZaO8JpyVv5X7Y8bE6Zdw=; b=WH+JUw3sF6nP+X5FufkbOelvrGdd7mpBDBdEKg5oSUuVIQGwSSLMoamHTEAAhZyliyB6syiQXH1a6OTNC/icJbBVR97Jyq8bnnW9Sadwyz9y6sTVh/kDBGU546l9Wmnwn+KwGqhpo/Hzasqf/yUA6cqMz8UL7Pio0qBQzbzHBZw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005812862592.8189142679499; Mon, 14 Aug 2023 02:36:52 -0700 (PDT) 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-450-b_Y_F5iIMVe3Z_d7Hd4IRg-1; Mon, 14 Aug 2023 05:36:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CAD4280CC49; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77DA840D2840; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6B7A11946A71; Mon, 14 Aug 2023 09:36:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 910371946586 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DFCA840C2078; Mon, 14 Aug 2023 09:36:22 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6225740C2073 for ; Mon, 14 Aug 2023 09:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005811; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=KEH6nhUmhscP/MylJEv+o4MZaO8JpyVv5X7Y8bE6Zdw=; b=VALhPEEl7ehGyKbru69vIcVxmSzmjc9xPKR93R7EkwboIW6L9KKb49ApV7c8MC0d2QDd1U Um1pqsDHAaTkichWbFrGh0eE7A3q1//Zd43UhTonMQbokQD9CtB3Nk7qaU8JbSkIr2VMeU ylhTz+xuUdSbO92pXZ5Eqgf1XejmRm8= X-MC-Unique: b_Y_F5iIMVe3Z_d7Hd4IRg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 07/25] qemu_snapshot: use virDomainDiskByName while updating domain def Date: Mon, 14 Aug 2023 11:35:59 +0200 Message-ID: <631fb8d087bb0522e11bf65daff0a0ff313d5330.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005815104100007 Content-Type: text/plain; charset="utf-8"; x-default="true" When creating external snapshot this function is called only when the VM is not running so there is only one definition to care about. However, it will be used by external snapshot revert code for active and inactive definition and they may be different if a disk was (un)plugged only for the active or inactive definition. The current code would crash so use virDomainDiskByName() to get the correct disk from the domain definition based on the disk name and make sure it exists. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 72a0f71d4f..8e1eb21b5d 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -152,11 +152,14 @@ qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef, for (i =3D 0; i < snapdef->ndisks; i++) { g_autoptr(virStorageSource) newsrc =3D NULL; virDomainSnapshotDiskDef *snapdisk =3D &(snapdef->disks[i]); - virDomainDiskDef *defdisk =3D domdef->disks[i]; + virDomainDiskDef *defdisk =3D virDomainDiskByName(domdef, snapdisk= ->name, false); =20 if (snapdisk->snapshot !=3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) continue; =20 + if (!defdisk) + continue; + if (!(newsrc =3D virStorageSourceCopy(snapdisk->src, false))) return -1; =20 --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005892; cv=none; d=zohomail.com; s=zohoarc; b=SHs4x9eHQ+TXhv7XJH4SuWnmMTMgB2ZxHeiOHlVIcStTFaNDPxFuoHQYtCPyydfcHPNmZI6HZ8Os2M/Fvp20iHvNFo/3aNLda3MjZ2yo28Q1RTJFGKIKrKu+FK4wYPgOQM4cC0I8exoY8ybXwv2sRt+bCcxAH5qtW9e8/33NQnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005892; h=Content-Type:Content-Transfer-Encoding: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=U+fjfDWnzro7sv0zE1NaFG44jXlElbE+p4N+TtUjyWQ=; b=mPQDDIxpCRCXwvAQNJ6/hwnBXhEMobowJ6O36xpubEfYRjZYVl1StkzpraXBTSSm6/3+3vSPSHPNxBEeD5FP+JyzToYgth89YXkEr5hQUNCpEyLTVsDQa5drG/TMAhH7uGPL65ET0GvrzCGmpcb0U5HhY50P1im6viivTUCcJZ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692005892611806.4074062715498; Mon, 14 Aug 2023 02:38:12 -0700 (PDT) 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-302-iPD89PACMSKi5ofCE_D0Kg-1; Mon, 14 Aug 2023 05:36:58 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C8E685D07C; Mon, 14 Aug 2023 09:36:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28256C15BAD; Mon, 14 Aug 2023 09:36:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 81EFF194658D; Mon, 14 Aug 2023 09:36:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 910D41946587 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 82A0D40C2075; Mon, 14 Aug 2023 09:36:23 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 259F640C2073 for ; Mon, 14 Aug 2023 09:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005891; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=U+fjfDWnzro7sv0zE1NaFG44jXlElbE+p4N+TtUjyWQ=; b=DCs8U+Ugkq2HopBvqiWAvPdhYo1F5Y7A4r10FhDuEPD6pClC61ec+WZvMBwSV/wowErnWd B9qPtdWtJrsnU5r+stS/joSghuoOWGTxSdZSACMPxKjdDPwmB7DVxbazz0WfUIkmiO+/dP N8dgFJjJZdyXyoG/a7J/aE3APp093p0= X-MC-Unique: iPD89PACMSKi5ofCE_D0Kg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 08/25] qemu_snapshot: introduce qemuSnapshotCreateQcow2Files Date: Mon, 14 Aug 2023 11:36:00 +0200 Message-ID: <9b68e3d5ae80973d867a4fd366ad2ed5b4b061d2.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005893184100002 Content-Type: text/plain; charset="utf-8"; x-default="true" Extract creation of qcow2 files for external snapshots to separate function as we will need it for external snapshot revert code. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 85 ++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 8e1eb21b5d..f43548e29f 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -181,43 +181,37 @@ qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef, } =20 =20 -/* The domain is expected to be locked and inactive. */ +/** + * qemuSnapshotCreateQcow2Files: + * @vm: domain object + * @snapdef: snapshot definition + * @created: bitmap to store which disks were created + * + * Create new qcow2 images based on snapshot definition @snapdef and use + * domain object @vm as source for backing images. + * + * Returns 0 on success, -1 on error. + */ static int -qemuSnapshotCreateInactiveInternal(virQEMUDriver *driver, - virDomainObj *vm, - virDomainMomentObj *snap) -{ - return qemuDomainSnapshotForEachQcow2(driver, vm->def, snap, "-c", fal= se); -} - - -/* The domain is expected to be locked and inactive. */ -static int -qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver, - virDomainObj *vm, - virDomainMomentObj *snap, - bool reuse) +qemuSnapshotCreateQcow2Files(virDomainObj *vm, + virDomainSnapshotDef *snapdef, + virBitmap *created) { size_t i; - virDomainSnapshotDiskDef *snapdisk; - virDomainDiskDef *defdisk; const char *qemuImgPath; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - int ret =3D -1; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - virDomainSnapshotDef *snapdef =3D virDomainSnapshotObjGetDef(snap); - g_autoptr(virBitmap) created =3D virBitmapNew(snapdef->ndisks); + virQEMUDriver *driver =3D ((qemuDomainObjPrivate *) vm->privateData)->= driver; + virDomainSnapshotDiskDef *snapdisk =3D NULL; + virDomainDiskDef *defdisk =3D NULL; =20 if (!(qemuImgPath =3D qemuFindQemuImgBinary(driver))) - goto cleanup; + return -1; =20 - /* If reuse is true, then qemuSnapshotPrepare already - * ensured that the new files exist, and it was up to the user to - * create them correctly. */ - for (i =3D 0; i < snapdef->ndisks && !reuse; i++) { + for (i =3D 0; i < snapdef->ndisks; i++) { g_autoptr(virCommand) cmd =3D NULL; snapdisk =3D &(snapdef->disks[i]); defdisk =3D vm->def->disks[i]; + if (snapdisk->snapshot !=3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) continue; =20 @@ -225,7 +219,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *drive= r, snapdisk->src->format =3D VIR_STORAGE_FILE_QCOW2; =20 if (qemuDomainStorageSourceValidateDepth(defdisk->src, 1, defdisk-= >dst) < 0) - goto cleanup; + return -1; =20 /* creates cmd line args: qemu-img create -f qcow2 -o */ if (!(cmd =3D virCommandNewArgList(qemuImgPath, @@ -234,7 +228,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *drive= r, virStorageFileFormatTypeToString(= snapdisk->src->format), "-o", NULL))) - goto cleanup; + return -1; =20 /* adds cmd line arg: backing_fmt=3Dformat,backing_file=3D/path/to= /backing/file */ virBufferAsprintf(&buf, "backing_fmt=3D%s,backing_file=3D", @@ -251,9 +245,42 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *driv= er, ignore_value(virBitmapSetBit(created, i)); =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; } =20 + return 0; +} + + +/* The domain is expected to be locked and inactive. */ +static int +qemuSnapshotCreateInactiveInternal(virQEMUDriver *driver, + virDomainObj *vm, + virDomainMomentObj *snap) +{ + return qemuDomainSnapshotForEachQcow2(driver, vm->def, snap, "-c", fal= se); +} + + +/* The domain is expected to be locked and inactive. */ +static int +qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver, + virDomainObj *vm, + virDomainMomentObj *snap, + bool reuse) +{ + virDomainSnapshotDiskDef *snapdisk; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + int ret =3D -1; + virDomainSnapshotDef *snapdef =3D virDomainSnapshotObjGetDef(snap); + g_autoptr(virBitmap) created =3D virBitmapNew(snapdef->ndisks); + + /* If reuse is true, then qemuSnapshotPrepare already + * ensured that the new files exist, and it was up to the user to + * create them correctly. */ + if (!reuse && qemuSnapshotCreateQcow2Files(vm, snapdef, created) < 0) + goto cleanup; + /* update disk definitions */ if (qemuSnapshotDomainDefUpdateDisk(vm->def, snapdef, reuse) < 0) goto cleanup; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005887; cv=none; d=zohomail.com; s=zohoarc; b=bBhpKEDVI09SYXdTCoES0gPyaL/H7/6Qd3v1OHtXoaXeoGijTUPEL/bpVbCEhsAnzy2lxsRngHbGT1zEnqqHv9ULbeRhnK4iF268YOmT6tTBEdMKEKlVwVPHTLNIuG+YH7LTdnHoZcWP1FNWCKcvcej8OkFXWrkok4BH5MJezq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005887; h=Content-Type:Content-Transfer-Encoding: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=B3GdlhvAEymI1CyDQ79JkyNtk1xuBDwoogm/lpk8qpw=; b=GJ7prUQhpLzE3dPHjjRrAWR40e6OaZozylXCSy9le1HZdnIl/O37z4DDo7G+V49i/x3T94MlBKxQMfdNohbol8EqHdXAMO6kIDqPPVSRqXVwEiV1YkkvdByxLlwbf0q3AyAcJnzSnWtifg4Z/u8Xmwfv2EMNR4ZTQ6hC+nf1opg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692005887867295.00099885431086; Mon, 14 Aug 2023 02:38:07 -0700 (PDT) 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-404--FSpwAS-OxW1d9femQj7YA-1; Mon, 14 Aug 2023 05:36:59 -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 8EABD80CD90; Mon, 14 Aug 2023 09:36:57 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 774222026D4B; Mon, 14 Aug 2023 09:36:57 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F05761946A48; Mon, 14 Aug 2023 09:36:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 93C7519465A2 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 245F340C2077; Mon, 14 Aug 2023 09:36:24 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB1C640C2073 for ; Mon, 14 Aug 2023 09:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005886; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=B3GdlhvAEymI1CyDQ79JkyNtk1xuBDwoogm/lpk8qpw=; b=RiLFWx3lkJBMnPOJgDE7CMLRsYnvhR8yS8d2wbaH7NjCb5tJbxfhGznimLBDA57DP4aoeD u18crZY3pG2nb1VYDSgaDPiuJtSoiTbaEp3dIgPlCQvPGC/BoxGmR2Iimp/L5gltOs8xJ4 3TlmTg6nkNgKsb/ts7XNEbNsZ8a3Oxs= X-MC-Unique: -FSpwAS-OxW1d9femQj7YA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 09/25] qemuSnapshotCreateQcow2Files: use domain definition directly Date: Mon, 14 Aug 2023 11:36:01 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005889409100011 Content-Type: text/plain; charset="utf-8"; x-default="true" To create new overlay files when external snapshot revert support is introduced we will be using different domain definition than what is currently used by the domain. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index f43548e29f..50f871baf3 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -183,24 +183,25 @@ qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef, =20 /** * qemuSnapshotCreateQcow2Files: - * @vm: domain object + * @driver: QEMU driver + * @def: domain definition * @snapdef: snapshot definition * @created: bitmap to store which disks were created * * Create new qcow2 images based on snapshot definition @snapdef and use - * domain object @vm as source for backing images. + * domain definition @def as source for backing images. * * Returns 0 on success, -1 on error. */ static int -qemuSnapshotCreateQcow2Files(virDomainObj *vm, +qemuSnapshotCreateQcow2Files(virQEMUDriver *driver, + virDomainDef *def, virDomainSnapshotDef *snapdef, virBitmap *created) { size_t i; const char *qemuImgPath; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - virQEMUDriver *driver =3D ((qemuDomainObjPrivate *) vm->privateData)->= driver; virDomainSnapshotDiskDef *snapdisk =3D NULL; virDomainDiskDef *defdisk =3D NULL; =20 @@ -210,7 +211,7 @@ qemuSnapshotCreateQcow2Files(virDomainObj *vm, for (i =3D 0; i < snapdef->ndisks; i++) { g_autoptr(virCommand) cmd =3D NULL; snapdisk =3D &(snapdef->disks[i]); - defdisk =3D vm->def->disks[i]; + defdisk =3D def->disks[i]; =20 if (snapdisk->snapshot !=3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) continue; @@ -278,7 +279,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *drive= r, /* If reuse is true, then qemuSnapshotPrepare already * ensured that the new files exist, and it was up to the user to * create them correctly. */ - if (!reuse && qemuSnapshotCreateQcow2Files(vm, snapdef, created) < 0) + if (!reuse && qemuSnapshotCreateQcow2Files(driver, vm->def, snapdef, c= reated) < 0) goto cleanup; =20 /* update disk definitions */ --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005831; cv=none; d=zohomail.com; s=zohoarc; b=hzyEhP0GZkoVoYK5UW0XcA2psycR1qfX/mvXr05kBIFM6g8g8Y2U7HPLcIsXWc+6Bnev7FX6iIXf58qjNJJOhUdfIWCx4qOJfeOZ1D0ect1LpPVNtC8aidQIhOSewnt55ZWJAS1CyDVtPRfzLyqj271aCJyq3uRh9e2vQPQu2Hs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005831; h=Content-Type:Content-Transfer-Encoding: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=wlL9dE7BweqnjmebGMsynguM6GoOxQN6VZclk42eS0M=; b=kGCRe1mYedvlGuM/xe87NIz8ru9BpupTOTLWezhjq5UxzEWOPMDC1J2ob4LOvMJbGrp+eeYnJ0blbeklPjv9QyovnEwooZEPUR+Ac3TUB1efCIjdJlXy7jol+i5N0Zpzua0GOKceZJAI1XvIAGEh5MQhX4X1vRSVerIifSJJJUM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005831400406.9201333207616; Mon, 14 Aug 2023 02:37:11 -0700 (PDT) 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-349-O6qpmlngOfiIbnZYCwbAtg-1; Mon, 14 Aug 2023 05:36:59 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DFAF785571B; Mon, 14 Aug 2023 09:36:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA5E4C15BBA; Mon, 14 Aug 2023 09:36:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BA7CC19465B9; Mon, 14 Aug 2023 09:36:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 93C4A19465A0 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BB96340C2079; Mon, 14 Aug 2023 09:36:24 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E81140C2073 for ; Mon, 14 Aug 2023 09:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005830; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wlL9dE7BweqnjmebGMsynguM6GoOxQN6VZclk42eS0M=; b=YIYbrMQViroOA4H9M4uskMGoXqYG08h6XaFfjvazgF6g0vZ+BPCz4Vd8b/JMhJkNYq1mFp bjgEDuGPamtxgTuK5DeZ0HY9KVaACLb7VCViNZClCvkggtKhi1VRxgnqdBkOlTYSFlnBTt 70BtKRBzp0Zgra/FwuBTW2SbT9eSY8M= X-MC-Unique: O6qpmlngOfiIbnZYCwbAtg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 10/25] qemu_snapshot: move external disk prepare to single function Date: Mon, 14 Aug 2023 11:36:02 +0200 Message-ID: <501a3b8e4a561e668d2e4eef26b9a0115ef80f9d.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005833106100001 Content-Type: text/plain; charset="utf-8"; x-default="true" We will need to reuse the functionality when reverting external snapshots. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 50f871baf3..a090ca13d4 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -527,6 +527,25 @@ qemuSnapshotPrepareDiskExternal(virDomainDiskDef *disk, bool active, bool reuse) { + if (!snapdisk->src->format) { + snapdisk->src->format =3D VIR_STORAGE_FILE_QCOW2; + } else if (snapdisk->src->format !=3D VIR_STORAGE_FILE_QCOW2 && + snapdisk->src->format !=3D VIR_STORAGE_FILE_QED) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("external snapshot format for disk %1$s is unsupp= orted: %2$s"), + snapdisk->name, + virStorageFileFormatTypeToString(snapdisk->src->for= mat)); + return -1; + } + + if (snapdisk->src->metadataCacheMaxSize > 0) { + if (snapdisk->src->format !=3D VIR_STORAGE_FILE_QCOW2) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("metadata cache max size control is supported= only with qcow2 images")); + return -1; + } + } + if (qemuTranslateSnapshotDiskSourcePool(snapdisk) < 0) return -1; =20 @@ -707,25 +726,6 @@ qemuSnapshotPrepare(virDomainObj *vm, break; =20 case VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL: - if (!disk->src->format) { - disk->src->format =3D VIR_STORAGE_FILE_QCOW2; - } else if (disk->src->format !=3D VIR_STORAGE_FILE_QCOW2 && - disk->src->format !=3D VIR_STORAGE_FILE_QED) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("external snapshot format for disk %1$s i= s unsupported: %2$s"), - disk->name, - virStorageFileFormatTypeToString(disk->src-= >format)); - return -1; - } - - if (disk->src->metadataCacheMaxSize > 0) { - if (disk->src->format !=3D VIR_STORAGE_FILE_QCOW2) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("metadata cache max size control is s= upported only with qcow2 images")); - return -1; - } - } - if (qemuSnapshotPrepareDiskExternal(dom_disk, disk, active, re= use) < 0) return -1; =20 --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005912; cv=none; d=zohomail.com; s=zohoarc; b=CfXvSH5CSBZ9L+bd93ARod/wtWH6WdzDkQE/+wsYfv2t8ItwYLRviZdWx3r8FtDaSK5ZR2YdqqD3zy/rzcGBximGg8tqXTHs3kkxTkXJjA4pyz2CLER10lZF3X0CAB3fGrssvQCU0CstCVxruEjCuk1EocUopr1TfvoQwoJhVZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005912; h=Content-Type:Content-Transfer-Encoding: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=Na4KLEg2jYnuY1sSoACsvfvbTSPEytmHBY6zFBKKta4=; b=Iu880kh7brHXdu0lFmZOeDI+nHjUFNDPsIztMO5z9c9rfcQpvxtCGuxxxtpIdPqWFIsZRmgPZif8fSY6FKoSJoArwhfU48Ln3fl25IHQKwijfuhSLu/qTfUYibtjE9JsqR6IITRYWAecSjfeiLeu0SN4qbCXR3bPiD0aCB1/11I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 169200591234227.07885947025204; Mon, 14 Aug 2023 02:38:32 -0700 (PDT) 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-45-tAzs7AUJOoG0vZCW8Z9zGw-1; Mon, 14 Aug 2023 05:36:55 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C9AFA8DC660; Mon, 14 Aug 2023 09:36:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B574DC15BAD; Mon, 14 Aug 2023 09:36:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 718E319465BA; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8FA8C1946594 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5D36940C207A; Mon, 14 Aug 2023 09:36:25 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0019D40C2073 for ; Mon, 14 Aug 2023 09:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005911; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Na4KLEg2jYnuY1sSoACsvfvbTSPEytmHBY6zFBKKta4=; b=RHXA05yD11TPT4cAy9RRd5FkchlWIv+IrZz4XEiPElU3q0vPdQc6p63/TdBGYALwCQLJAR S0meSM3KBSN0rOHnGp3csgAWrK1GrgZh0l6K+Nig8Gx+6YgFo8xUFLq3bBJ6qZrVJj5vPM /hZqRmrcmeXiwk1fmPaBwjZLLLNtRXI= X-MC-Unique: tAzs7AUJOoG0vZCW8Z9zGw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 11/25] qemu_snapshot: use VIR_ASYNC_JOB_SNAPSHOT when reverting snapshot Date: Mon, 14 Aug 2023 11:36:03 +0200 Message-ID: <866ae1e4b63489ff34a9b0d308746748a99e2971.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005913436100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Both creating and deleting snapshot are using VIR_ASYNC_JOB_SNAPSHOT but reverting is using VIR_ASYNC_JOB_START. Let's unify it to make it consistent for all snapshot operations. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index a090ca13d4..82fbb79ab0 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2008,7 +2008,7 @@ qemuSnapshotRevertActive(virDomainObj *vm, /* Transitions 5, 6, 8, 9 */ qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT, - VIR_ASYNC_JOB_START, 0); + VIR_ASYNC_JOB_SNAPSHOT, 0); virDomainAuditStop(vm, "from-snapshot"); detail =3D VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT; event =3D virDomainEventLifecycleNewFromObj(vm, @@ -2033,7 +2033,7 @@ qemuSnapshotRevertActive(virDomainObj *vm, =20 rc =3D qemuProcessStart(snapshot->domain->conn, driver, vm, cookie ? cookie->cpu : NULL, - VIR_ASYNC_JOB_START, NULL, -1, NULL, snap, + VIR_ASYNC_JOB_SNAPSHOT, NULL, -1, NULL, snap, VIR_NETDEV_VPORT_PROFILE_OP_CREATE, start_flags); virDomainAuditStart(vm, "from-snapshot", rc >=3D 0); @@ -2066,7 +2066,7 @@ qemuSnapshotRevertActive(virDomainObj *vm, } rc =3D qemuProcessStartCPUs(driver, vm, VIR_DOMAIN_RUNNING_FROM_SNAPSHOT, - VIR_ASYNC_JOB_START); + VIR_ASYNC_JOB_SNAPSHOT); if (rc < 0) return -1; } @@ -2129,7 +2129,7 @@ qemuSnapshotRevertInactive(virDomainObj *vm, if (virDomainObjIsActive(vm)) { /* Transitions 4, 7 */ qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT, - VIR_ASYNC_JOB_START, 0); + VIR_ASYNC_JOB_SNAPSHOT, 0); virDomainAuditStop(vm, "from-snapshot"); detail =3D VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT; event =3D virDomainEventLifecycleNewFromObj(vm, @@ -2156,7 +2156,7 @@ qemuSnapshotRevertInactive(virDomainObj *vm, start_flags |=3D paused ? VIR_QEMU_PROCESS_START_PAUSED : 0; =20 rc =3D qemuProcessStart(snapshot->domain->conn, driver, vm, NULL, - VIR_ASYNC_JOB_START, NULL, -1, NULL, NULL, + VIR_ASYNC_JOB_SNAPSHOT, NULL, -1, NULL, NULL, VIR_NETDEV_VPORT_PROFILE_OP_CREATE, start_flags); virDomainAuditStart(vm, "from-snapshot", rc >=3D 0); @@ -2223,10 +2223,11 @@ qemuSnapshotRevert(virDomainObj *vm, return -1; } =20 - if (qemuProcessBeginJob(vm, - VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT, - flags) < 0) + if (virDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_SNAPSHOT, + VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT, + flags) < 0) { return -1; + } =20 if (!(snap =3D qemuSnapObjFromSnapshot(vm, snapshot))) goto endjob; @@ -2276,7 +2277,7 @@ qemuSnapshotRevert(virDomainObj *vm, } =20 endjob: - qemuProcessEndJob(vm); + virDomainObjEndAsyncJob(vm); =20 return ret; } --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005836; cv=none; d=zohomail.com; s=zohoarc; b=HEPOp2fNhsptySmo2glf+Z2jWnBqjYO3Ig9/zFXhA1tChBi8tHuhysufQUGl7DM0xCFtLqTeszAiNJh/3u0kp7atvoRVoepXBenyKDzphkFIjMj0X1DdP628q0r8Sx4dmtz2voUkriUPKo3Wh9hjKBNym54iKloRpts8WvgOM3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005836; h=Content-Type:Content-Transfer-Encoding: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=973AmwVShniIr87hBqayoN6GAFp8q8TpMvtgGUoig5o=; b=HXMY/+RJSqlt+GZj2fIjefS/ibQtEhmXPo6olROuuYNgqrWgsuPnE/KdsRFKVf8TL6eZUIqjWemCA8W8qzxdspeHu7dW3Dtiy2PKkMzG6OgHRWUumqC0nkZt2bodDlJZ/speyIKPxGwMjj2V9P+/+RIzYX8XV0zMp+bS8noeUgg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692005836458339.3371922700653; Mon, 14 Aug 2023 02:37:16 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [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-231-FQcjKOj1PsqTWrxOI245Qg-1; Mon, 14 Aug 2023 05:37:06 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5969E3814950; Mon, 14 Aug 2023 09:37:04 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40891403166; Mon, 14 Aug 2023 09:37:04 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A2A9619459EC; Mon, 14 Aug 2023 09:36:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A5017194658C for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F39B140C207B; Mon, 14 Aug 2023 09:36:25 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 959A240C2073 for ; Mon, 14 Aug 2023 09:36:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005835; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=973AmwVShniIr87hBqayoN6GAFp8q8TpMvtgGUoig5o=; b=KSf2tDc9rlSSi8w+PEqqRd9Z+NKuYVGfFfMZvoSaoLClpLt2b1E2+mflb/ILQ7XJfReDT3 TXqkRWqTw/qPN9JydsiVA0RhcU4G7uEenQLVL2VT5iDbWl+tmPlzFzGYzUh2/0ZJ7jdoJ0 T6z5O3FPGOHQLHKapPPyHhLY52xYAdU= X-MC-Unique: FQcjKOj1PsqTWrxOI245Qg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 12/25] qemu_snapshot: introduce external snapshot revert support Date: Mon, 14 Aug 2023 11:36:04 +0200 Message-ID: <5fb760599eff3728797165aec65a29178349993e.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005838154100009 Content-Type: text/plain; charset="utf-8"; x-default="true" When reverting to external snapshot we need to create new overlay qcow2 files from the disk files the VM had when the snapshot was taken. There are some specifics and limitations when reverting to a snapshot: 1) When reverting to last snapshot we need to first create new overlay files before we can safely delete the old overlay files in case the creation fails so we have still recovery option when we error out. These new files will not have the suffix as when the snapshot was created as renaming the original files in order to use the same file names as when the snapshot was created would add unnecessary complexity to the code. 2) When reverting to any snapshot we will always create overlay files for every disk the VM had when the snapshot was done. Otherwise we would have to figure out if there is any other qcow2 image already using any of the VM disks as backing store and that itself might be extremely complex and in some cases impossible. 3) When reverting from any state the current overlay files will be always removed as that VM state is not meant to be saved. It's the same as with internal snapshots. If user want's to keep the current state before reverting they need to create a new snapshot. For now this will only work if the current snapshot is the last. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 278 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 274 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 82fbb79ab0..0534989e37 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -18,6 +18,8 @@ =20 #include =20 +#include + #include "qemu_snapshot.h" =20 #include "qemu_monitor.h" @@ -1982,6 +1984,229 @@ qemuSnapshotRevertWriteMetadata(virDomainObj *vm, } =20 =20 +/** + * qemuSnapshotRevertExternalPrepare: + * @vm: domain object + * @tmpsnapdef: temporary snapshot definition + * @snap: snapshot object we are reverting to + * @config: live domain definition + * @inactiveConfig: offline domain definition + * memsnapFD: pointer to store memory state file FD or NULL + * memsnapPath: pointer to store memory state file path or NULL + * + * Prepare new temporary snapshot definition @tmpsnapdef that will + * be used while creating new overlay files after reverting to snapshot + * @snap. In case we are reverting to snapshot with memory state it will + * open it and pass FD via @memsnapFD and path to the file via + * @memsnapPath, caller is responsible for freeing both @memsnapFD and + * memsnapPath. + * + * Returns 0 in success, -1 on error. + */ +static int +qemuSnapshotRevertExternalPrepare(virDomainObj *vm, + virDomainSnapshotDef *tmpsnapdef, + virDomainMomentObj *snap, + virDomainDef *config, + virDomainDef *inactiveConfig, + int *memsnapFD, + char **memsnapPath) +{ + size_t i; + bool active =3D virDomainObjIsActive(vm); + virDomainDef *domdef =3D NULL; + virDomainSnapshotDef *snapdef =3D virDomainSnapshotObjGetDef(snap); + + if (config) { + domdef =3D config; + } else { + domdef =3D inactiveConfig; + } + + /* We need this to generate creation timestamp that is used as default + * snapshot name. */ + if (virDomainMomentDefPostParse(&tmpsnapdef->parent) < 0) + return -1; + + if (virDomainSnapshotAlignDisks(tmpsnapdef, domdef, + VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL, + false, true) < 0) { + return -1; + } + + for (i =3D 0; i < tmpsnapdef->ndisks; i++) { + virDomainSnapshotDiskDef *snapdisk =3D &tmpsnapdef->disks[i]; + virDomainDiskDef *domdisk =3D domdef->disks[i]; + + if (qemuSnapshotPrepareDiskExternal(domdisk, snapdisk, active, fal= se) < 0) + return -1; + } + + if (memsnapFD && memsnapPath && snapdef->memorysnapshotfile) { + virQEMUDriver *driver =3D ((qemuDomainObjPrivate *) vm->privateDat= a)->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driv= er); + + *memsnapPath =3D snapdef->memorysnapshotfile; + *memsnapFD =3D qemuDomainOpenFile(cfg, NULL, *memsnapPath, O_RDONL= Y, NULL); + } + + return 0; +} + + +/** + * qemuSnapshotRevertExternalActive: + * @vm: domain object + * @tmpsnapdef: temporary snapshot definition + * + * Creates a new disk overlays using the temporary snapshot + * definition @tmpsnapdef for running VM by calling QMP APIs. + * + * Returns 0 on success, -1 on error. + */ +static int +qemuSnapshotRevertExternalActive(virDomainObj *vm, + virDomainSnapshotDef *tmpsnapdef) +{ + size_t i; + g_autoptr(GHashTable) blockNamedNodeData =3D NULL; + g_autoptr(qemuSnapshotDiskContext) snapctxt =3D NULL; + + snapctxt =3D qemuSnapshotDiskContextNew(tmpsnapdef->ndisks, vm, VIR_AS= YNC_JOB_SNAPSHOT); + + if (!(blockNamedNodeData =3D qemuBlockGetNamedNodeData(vm, VIR_ASYNC_J= OB_SNAPSHOT))) + return -1; + + for (i =3D 0; i < tmpsnapdef->ndisks; i++) { + if (qemuSnapshotDiskPrepareOne(snapctxt, + vm->def->disks[i], + tmpsnapdef->disks + i, + blockNamedNodeData, + false, + true) < 0) + return -1; + } + + if (qemuSnapshotDiskCreate(snapctxt) < 0) + return -1; + + return 0; +} + + +/** + * qemuSnapshotRevertExternalInactive: + * @vm: domain object + * @tmpsnapdef: temporary snapshot definition + * @domdef: offline domain definition + * + * Creates a new disk overlays using the temporary snapshot + * definition @tmpsnapdef for offline VM by calling qemu-img. + * + * Returns 0 on success, -1 on error. + */ +static int +qemuSnapshotRevertExternalInactive(virDomainObj *vm, + virDomainSnapshotDef *tmpsnapdef, + virDomainDef *domdef) +{ + virQEMUDriver *driver =3D QEMU_DOMAIN_PRIVATE(vm)->driver; + g_autoptr(virBitmap) created =3D NULL; + + created =3D virBitmapNew(tmpsnapdef->ndisks); + + if (qemuSnapshotDomainDefUpdateDisk(domdef, tmpsnapdef, false) < 0) + return -1; + + if (qemuSnapshotCreateQcow2Files(driver, domdef, tmpsnapdef, created) = < 0) { + ssize_t bit =3D -1; + virErrorPtr err =3D NULL; + + virErrorPreserveLast(&err); + + while ((bit =3D virBitmapNextSetBit(created, bit)) >=3D 0) { + virDomainSnapshotDiskDef *snapdisk =3D &(tmpsnapdef->disks[bit= ]); + + if (virStorageSourceInit(snapdisk->src) < 0 || + virStorageSourceUnlink(snapdisk->src) < 0) { + VIR_WARN("Failed to remove snapshot image '%s'", + snapdisk->src->path); + } + } + + virErrorRestore(&err); + + return -1; + } + + return 0; +} + + +/** + * qemuSnapshotRevertExternalFinish: + * @vm: domain object + * @tmpsnapdef: temporary snapshot definition + * @snap: snapshot object we are reverting to + * + * Finishes disk overlay creation by removing existing overlays that + * will no longer be used if there are any and updating snapshot @snap + * metadata and current snapshot metadata so it can be saved once the + * revert is completed. + */ +static void +qemuSnapshotRevertExternalFinish(virDomainObj *vm, + virDomainSnapshotDef *tmpsnapdef, + virDomainMomentObj *snap) +{ + size_t i; + virDomainMomentObj *curSnap =3D virDomainSnapshotGetCurrent(vm->snapsh= ots); + virDomainSnapshotDef *curdef =3D virDomainSnapshotObjGetDef(curSnap); + virDomainSnapshotDef *snapdef =3D virDomainSnapshotObjGetDef(snap); + + if (curdef->revertdisks) { + for (i =3D 0; i < curdef->nrevertdisks; i++) { + virDomainSnapshotDiskDef *snapdisk =3D &(curdef->revertdisks[i= ]); + + if (virStorageSourceInit(snapdisk->src) < 0 || + virStorageSourceUnlink(snapdisk->src) < 0) { + VIR_WARN("Failed to remove snapshot image '%s'", + snapdisk->src->path); + } + + virDomainSnapshotDiskDefClear(snapdisk); + } + + g_clear_pointer(&curdef->revertdisks, g_free); + curdef->nrevertdisks =3D 0; + } else { + for (i =3D 0; i < curdef->ndisks; i++) { + virDomainSnapshotDiskDef *snapdisk =3D &(curdef->disks[i]); + + if (virStorageSourceInit(snapdisk->src) < 0 || + virStorageSourceUnlink(snapdisk->src) < 0) { + VIR_WARN("Failed to remove snapshot image '%s'", + snapdisk->src->path); + } + } + } + + if (snap->nchildren !=3D 0) { + snapdef->revertdisks =3D g_steal_pointer(&tmpsnapdef->disks); + snapdef->nrevertdisks =3D tmpsnapdef->ndisks; + tmpsnapdef->ndisks =3D 0; + } else { + for (i =3D 0; i < snapdef->ndisks; i++) { + virDomainSnapshotDiskDefClear(&snapdef->disks[i]); + } + g_free(snapdef->disks); + snapdef->disks =3D g_steal_pointer(&tmpsnapdef->disks); + snapdef->ndisks =3D tmpsnapdef->ndisks; + tmpsnapdef->ndisks =3D 0; + } +} + + static int qemuSnapshotRevertActive(virDomainObj *vm, virDomainSnapshotPtr snapshot, @@ -1996,10 +2221,14 @@ qemuSnapshotRevertActive(virDomainObj *vm, { virObjectEvent *event =3D NULL; virObjectEvent *event2 =3D NULL; + virDomainMomentObj *loadSnap =3D NULL; + VIR_AUTOCLOSE memsnapFD =3D -1; + char *memsnapPath =3D NULL; int detail; bool defined =3D false; qemuDomainSaveCookie *cookie =3D (qemuDomainSaveCookie *) snapdef->coo= kie; int rc; + g_autoptr(virDomainSnapshotDef) tmpsnapdef =3D NULL; =20 start_flags |=3D VIR_QEMU_PROCESS_START_PAUSED; =20 @@ -2017,6 +2246,19 @@ qemuSnapshotRevertActive(virDomainObj *vm, virObjectEventStateQueue(driver->domainEventState, event); } =20 + if (virDomainSnapshotIsExternal(snap)) { + if (!(tmpsnapdef =3D virDomainSnapshotDefNew())) + return -1; + + if (qemuSnapshotRevertExternalPrepare(vm, tmpsnapdef, snap, + *config, *inactiveConfig, + &memsnapFD, &memsnapPath) < = 0) { + return -1; + } + } else { + loadSnap =3D snap; + } + if (*inactiveConfig) { virDomainObjAssignDef(vm, inactiveConfig, false, NULL); defined =3D true; @@ -2033,7 +2275,8 @@ qemuSnapshotRevertActive(virDomainObj *vm, =20 rc =3D qemuProcessStart(snapshot->domain->conn, driver, vm, cookie ? cookie->cpu : NULL, - VIR_ASYNC_JOB_SNAPSHOT, NULL, -1, NULL, snap, + VIR_ASYNC_JOB_SNAPSHOT, NULL, memsnapFD, + memsnapPath, loadSnap, VIR_NETDEV_VPORT_PROFILE_OP_CREATE, start_flags); virDomainAuditStart(vm, "from-snapshot", rc >=3D 0); @@ -2045,6 +2288,14 @@ qemuSnapshotRevertActive(virDomainObj *vm, if (rc < 0) return -1; =20 + + if (virDomainSnapshotIsExternal(snap)) { + if (qemuSnapshotRevertExternalActive(vm, tmpsnapdef) < 0) + return -1; + + qemuSnapshotRevertExternalFinish(vm, tmpsnapdef, snap); + } + /* Touch up domain state. */ if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING) && (snapdef->state =3D=3D VIR_DOMAIN_SNAPSHOT_PAUSED || @@ -2119,6 +2370,7 @@ qemuSnapshotRevertInactive(virDomainObj *vm, int detail; bool defined =3D false; int rc; + g_autoptr(virDomainSnapshotDef) tmpsnapdef =3D NULL; =20 /* Transitions 1, 4, 7 */ /* Newer qemu -loadvm refuses to revert to the state of a snapshot @@ -2138,9 +2390,27 @@ qemuSnapshotRevertInactive(virDomainObj *vm, virObjectEventStateQueue(driver->domainEventState, event); } =20 - if (qemuSnapshotInternalRevertInactive(driver, vm, snap) < 0) { - qemuDomainRemoveInactive(driver, vm, 0, false); - return -1; + if (virDomainSnapshotIsExternal(snap)) { + if (!(tmpsnapdef =3D virDomainSnapshotDefNew())) + return -1; + + if (qemuSnapshotRevertExternalPrepare(vm, tmpsnapdef, snap, + NULL, *inactiveConfig, + NULL, NULL) < 0) { + return -1; + } + + if (qemuSnapshotRevertExternalInactive(vm, tmpsnapdef, + *inactiveConfig) < 0) { + return -1; + } + + qemuSnapshotRevertExternalFinish(vm, tmpsnapdef, snap); + } else { + if (qemuSnapshotInternalRevertInactive(driver, vm, snap) < 0) { + qemuDomainRemoveInactive(driver, vm, 0, false); + return -1; + } } =20 if (*inactiveConfig) { --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005951; cv=none; d=zohomail.com; s=zohoarc; b=eJMt84S9yEw9qZHf2IZ50Eq8jE1L4Kj/DQZArj8cj4VVPKwQdT/w09ViJtF5HkO/j4vxmAU8/onbLlCMq9+QOtnhs2e2qcn2vl42ApKA2dGoI8QxfpzvPtLSgsTiCBJx+OuTgGCLFapCFVAsUIcXHBTKvZ/g3nE28sqhN6ekO+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005951; h=Content-Type:Content-Transfer-Encoding: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=jFKhypxwsfWCyWZ7z/m99DLGArJhwexPimNk4cDYX8g=; b=jvXE0cEq1jrJ+F4b2DvtREIANj8bR7cn5EyaeZL1He7Pl3YEMQoi48n+5iExYq6Yugy0kePjKAgfkG1V9d99gt6uciIl4hAy7L6bvPO+lJNIFc06323p6h3kIw23b1bk2wfOjQy382PDfrgRtmpXTO9W7zfkHlhlXzs4t1AewGI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692005951095842.5959055330842; Mon, 14 Aug 2023 02:39:11 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [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-656-0dObeyy3NM-ZtK28XwRmpQ-1; Mon, 14 Aug 2023 05:37:11 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BEBAA2999B3F; Mon, 14 Aug 2023 09:37:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C9EC403169; Mon, 14 Aug 2023 09:37:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 24D6919451E8; Mon, 14 Aug 2023 09:36:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A370D19465B5 for ; Mon, 14 Aug 2023 09:36:42 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9422040C207E; Mon, 14 Aug 2023 09:36:26 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37A6C40C2073 for ; Mon, 14 Aug 2023 09:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005949; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=jFKhypxwsfWCyWZ7z/m99DLGArJhwexPimNk4cDYX8g=; b=jGLTImrHM2JTDkcEG813w5PRlMWvPKG96Z5oAmJ4qCQhVJH7ZUPwUhME8b4QzeTy/uoX5w CqiFhKg0OMmkfuF2Iv9T6Pzy2jXZX4+zrajWJIYBizAkv48tUoXcfIT+1i4prXCrMHJs1x W8IY1cb5q4dftjkvK48w7QJt9TBmap8= X-MC-Unique: 0dObeyy3NM-ZtK28XwRmpQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 13/25] qemu_snapshot: rename qemuSnapshotDeleteExternalPrepare Date: Mon, 14 Aug 2023 11:36:05 +0200 Message-ID: <7e79f2e75a36b567c81e6ea6a443988c073886a8.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005952575100003 Content-Type: text/plain; charset="utf-8"; x-default="true" The new name reflects that we prepare data for external snapshot deletion and the old name will be used later for different part of code. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 0534989e37..dd88e478b8 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2623,9 +2623,9 @@ qemuSnapshotFindParentSnapForDisk(virDomainMomentObj = *snap, =20 =20 static int -qemuSnapshotDeleteExternalPrepare(virDomainObj *vm, - virDomainMomentObj *snap, - GSList **externalData) +qemuSnapshotDeleteExternalPrepareData(virDomainObj *vm, + virDomainMomentObj *snap, + GSList **externalData) { ssize_t i; virDomainSnapshotDef *snapdef =3D virDomainSnapshotObjGetDef(snap); @@ -3482,7 +3482,7 @@ qemuSnapshotDelete(virDomainObj *vm, g_autoslist(qemuSnapshotDeleteExternalData) tmpData =3D NULL; =20 /* this also serves as validation whether the snapshot can be = deleted */ - if (qemuSnapshotDeleteExternalPrepare(vm, snap, &tmpData) < 0) + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, &tmpData) = < 0) goto endjob; =20 if (!virDomainObjIsActive(vm)) { @@ -3497,7 +3497,7 @@ qemuSnapshotDelete(virDomainObj *vm, =20 /* Call the prepare again as some data require that the VM= is * running to get everything we need. */ - if (qemuSnapshotDeleteExternalPrepare(vm, snap, &externalD= ata) < 0) + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, &exter= nalData) < 0) goto endjob; } else { qemuDomainJobPrivate *jobPriv =3D vm->job->privateData; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005811; cv=none; d=zohomail.com; s=zohoarc; b=cybJjxfJOD+1QMalZSSvAjrFWqcsyB1/0/R6+67h1R7al13NrtE7NzsIzsi7sOr6WuogmtpoPhr0uaVoMYgeQAGUNbpcz+rvhMfFS8fMyA+NTwt0wGzXcox0Q1qB05UrrlwYVz82qJEMretUb59M0/gFk8+JRAmSazZXsUVDySU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005811; h=Content-Type:Content-Transfer-Encoding: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=uPmo3WC0qoniibDb5bNxqEc8ECj2lnR0nOqdqEbt0LE=; b=PaI5BkD5UKu8yJHPVIQZLxDoRK/5hDnZfdrCD4oXeXKR5qYEdgDH5iL9nI/gIfldKZJ5EHd7zzXlXWQ3eTjo6MqwMSWaVIZTFHo0B4ekt7E57t/Mut+WnfIjn5StjIBQVHnZswhbcKWgW6mpf3Nf7Mi2BZEIPuuMSVF2qVheIT4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692005811939543.4112842876503; Mon, 14 Aug 2023 02:36:51 -0700 (PDT) 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-99-K8zdw8_3P8KUTSMOOUANuQ-1; Mon, 14 Aug 2023 05:36:45 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC33985D082; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9576F4021B9; Mon, 14 Aug 2023 09:36:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B31F81946595; Mon, 14 Aug 2023 09:36:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A5BF3194658D for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 36B5240C207C; Mon, 14 Aug 2023 09:36:27 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD61A40C2073 for ; Mon, 14 Aug 2023 09:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005810; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=uPmo3WC0qoniibDb5bNxqEc8ECj2lnR0nOqdqEbt0LE=; b=HK09Ix/kGn88kjdHOptbMJKi8BdWca0Ji0bydtMVI2ZLyRdoKO7YpQkyZxrkPCPCzkJEag PiPMvdWx0VIHM3yQyg6k7s9rlnGBQTh0w0TxNx/Mn1Tr+y+W6dr+WR4D4MXMnFiXItwMZu P98WanBZg4mnyIJwDHJJj5+eHU7TUvE= X-MC-Unique: K8zdw8_3P8KUTSMOOUANuQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 14/25] qemu_snapshot: extract external snapshot delete prepare to function Date: Mon, 14 Aug 2023 11:36:06 +0200 Message-ID: <1e380eb9c863ef7d2e61173ff49bc0fa6a1e7888.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005812885100003 Content-Type: text/plain; charset="utf-8"; x-default="true" This part of code is about to grow to make deletion work when user reverts to non-leaf snapshot. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 104 ++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 34 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index dd88e478b8..c3d17b4cee 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2706,6 +2706,73 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj *= vm, } =20 =20 +/** + * qemuSnapshotDeleteExternalPrepare: + * @vm: domain object + * @snap: snapshot object we are deleting + * @flags: flags passed to virDomainSnapshotDelete + * @externalData: pointer to GSList of qemuSnapshotDeleteExternalData + * @stop_qemu: pointer to boolean indicating QEMU process was started + * + * Validates and prepares data for snapshot @snap we are deleting and + * store it in @externalData. For offline VMs we need to start QEMU + * process in order to delete external snapshots and caller will need + * to stop that process, @stop_qemu will be set to True. + * + * Return 0 on success, -1 on error. + */ +static int +qemuSnapshotDeleteExternalPrepare(virDomainObj *vm, + virDomainMomentObj *snap, + unsigned int flags, + GSList **externalData, + bool *stop_qemu) +{ + virQEMUDriver *driver =3D ((qemuDomainObjPrivate *) vm->privateData)->= driver; + g_autoslist(qemuSnapshotDeleteExternalData) tmpData =3D NULL; + + if (!virDomainSnapshotIsExternal(snap)) + return 0; + + if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | + VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { + return 0; + } + + /* this also serves as validation whether the snapshot can be deleted = */ + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, &tmpData) < 0) + return -1; + + if (!virDomainObjIsActive(vm)) { + if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB_SNAPSHO= T, + NULL, -1, NULL, NULL, + VIR_NETDEV_VPORT_PROFILE_OP_CREATE, + VIR_QEMU_PROCESS_START_PAUSED) < 0) { + return -1; + } + + *stop_qemu =3D true; + + /* Call the prepare again as some data require that the VM is + * running to get everything we need. */ + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, externalData) = < 0) + return -1; + } else { + qemuDomainJobPrivate *jobPriv =3D vm->job->privateData; + + *externalData =3D g_steal_pointer(&tmpData); + + /* If the VM is running we need to indicate that the async snapshot + * job is snapshot delete job. */ + jobPriv->snapshotDelete =3D true; + + qemuDomainSaveStatus(vm); + } + + return 0; +} + + typedef struct _virQEMUMomentReparent virQEMUMomentReparent; struct _virQEMUMomentReparent { const char *dir; @@ -3476,40 +3543,9 @@ qemuSnapshotDelete(virDomainObj *vm, if (qemuSnapshotDeleteValidate(vm, snap, flags) < 0) goto endjob; =20 - if (virDomainSnapshotIsExternal(snap) && - !(flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | - VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY))) { - g_autoslist(qemuSnapshotDeleteExternalData) tmpData =3D NULL; - - /* this also serves as validation whether the snapshot can be = deleted */ - if (qemuSnapshotDeleteExternalPrepareData(vm, snap, &tmpData) = < 0) - goto endjob; - - if (!virDomainObjIsActive(vm)) { - if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB= _SNAPSHOT, - NULL, -1, NULL, NULL, - VIR_NETDEV_VPORT_PROFILE_OP_CREATE, - VIR_QEMU_PROCESS_START_PAUSED) < 0) { - goto endjob; - } - - stop_qemu =3D true; - - /* Call the prepare again as some data require that the VM= is - * running to get everything we need. */ - if (qemuSnapshotDeleteExternalPrepareData(vm, snap, &exter= nalData) < 0) - goto endjob; - } else { - qemuDomainJobPrivate *jobPriv =3D vm->job->privateData; - - externalData =3D g_steal_pointer(&tmpData); - - /* If the VM is running we need to indicate that the async= snapshot - * job is snapshot delete job. */ - jobPriv->snapshotDelete =3D true; - - qemuDomainSaveStatus(vm); - } + if (qemuSnapshotDeleteExternalPrepare(vm, snap, flags, + &externalData, &stop_qemu) <= 0) { + goto endjob; } } =20 --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005885; cv=none; d=zohomail.com; s=zohoarc; b=gnOW5bT5R+0iXXVdasuT3ORU9CMjxHM8BCeWa9vehEVzchgKDKeLMsr0sorV5pIlIOKipas56QvcftADc4b35IzrdcsnLcM26fQpIejHx3h1YftPRXSi16ac43xRNIDHx3bkWM8Gt30Tgr+97I79AefqCuFjFVGJlcTE5ol3Mds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005885; h=Content-Type:Content-Transfer-Encoding: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=4vYM7ubAgPfJMOpCXt3DOj7H5fYnf/YWyzdLMJCx8Po=; b=Kq9wchuvAUpISw4GL6rzGSbMIjhbaP1F3dT4aIU+v2FZmnYPAVMx+fCk5OQM3jxFLTVOq5L9bdzaBQINdZT9mvxRha8EN8xgSo1MZBWg54FkrInP75hnn3meaYX/B0WDsm5aZDRU33pJHSnK6W527sdIq/JvVfvIz1qpygWbp8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005885729404.07121862287306; Mon, 14 Aug 2023 02:38:05 -0700 (PDT) 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-639-6PS3p5v0Pf2v5jTfVWAxyQ-1; Mon, 14 Aug 2023 05:36:47 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2701C80D0BB; Mon, 14 Aug 2023 09:36:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5748403169; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A34701946A7E; Mon, 14 Aug 2023 09:36:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9821E19465A3 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CC9E140C2073; Mon, 14 Aug 2023 09:36:27 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EFE640C207F for ; Mon, 14 Aug 2023 09:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005884; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4vYM7ubAgPfJMOpCXt3DOj7H5fYnf/YWyzdLMJCx8Po=; b=S5jFNieZe11OIWhikdKX+uABDhP4RQ7kwuTFEEg9ZfM6d/Xe+9vF2zKxPsoO/eKg29UXws 0wxdAy3RQpTvnKVO8EUIoIJhY46ovtq7giV9uI3wIs+gkCBXIBcXVrpL5hJ/k5FHiUbXgl 3nDCOLJbxQkoAXSOGhnufjMyETYsMi4= X-MC-Unique: 6PS3p5v0Pf2v5jTfVWAxyQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 15/25] qemu_snapshot: add merge to external snapshot delete prepare data Date: Mon, 14 Aug 2023 11:36:07 +0200 Message-ID: <3b37dacf66a01a39a27624dfc331002df0402c03.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005887170100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Before external snapshot revert every delete operation did block commit in order to delete a snapshot. But now when user reverts to non-leaf snapshot deleting leaf snapshot will not have any overlay files so we can just simply delete the snapshot images. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 84 +++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index c3d17b4cee..d47dc72709 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2622,9 +2622,26 @@ qemuSnapshotFindParentSnapForDisk(virDomainMomentObj= *snap, } =20 =20 +/** + * qemuSnapshotDeleteExternalPrepareData: + * @vm: domain object + * @snap: snapshot object + * @merge: whether we are just deleting image or not + * @externalData: prepared data to delete external snapshot + * + * Validate if we can delete selected snapshot @snap and prepare all neces= sary + * data that will be used when deleting snapshot as @externalData. + * + * If @merge is set to true we will merge the deleted snapshot into parent= one + * instead of just deleting it. This is necessary when operating on snapsh= ot + * that has existing overlay files. + * + * Returns -1 on error, 0 on success. + */ static int qemuSnapshotDeleteExternalPrepareData(virDomainObj *vm, virDomainMomentObj *snap, + bool merge, GSList **externalData) { ssize_t i; @@ -2648,10 +2665,6 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj *= vm, data =3D g_new0(qemuSnapshotDeleteExternalData, 1); data->snapDisk =3D snapDisk; =20 - data->domDisk =3D qemuDomainDiskByName(vm->def, snapDisk->name); - if (!data->domDisk) - return -1; - data->parentDomDisk =3D virDomainDiskByTarget(snapdef->parent.dom, data->snapDisk->name); if (!data->parentDomDisk) { @@ -2661,39 +2674,46 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj = *vm, return -1; } =20 - if (virDomainObjIsActive(vm)) { - data->diskSrc =3D virStorageSourceChainLookupBySource(data->do= mDisk->src, - data->snap= Disk->src, - &data->pre= vDiskSrc); - if (!data->diskSrc) + if (merge) { + data->domDisk =3D qemuDomainDiskByName(vm->def, snapDisk->name= ); + if (!data->domDisk) return -1; =20 - if (!virStorageSourceIsSameLocation(data->diskSrc, data->snapD= isk->src)) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("VM disk source and snapshot disk source = are not the same")); - return -1; - } + if (virDomainObjIsActive(vm)) { + data->diskSrc =3D virStorageSourceChainLookupBySource(data= ->domDisk->src, + data->= snapDisk->src, + &data-= >prevDiskSrc); + if (!data->diskSrc) + return -1; =20 - data->parentDiskSrc =3D data->diskSrc->backingStore; - if (!virStorageSourceIsBacking(data->parentDiskSrc)) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("failed to find parent disk source in bac= king chain")); - return -1; - } + if (!virStorageSourceIsSameLocation(data->diskSrc, data->s= napDisk->src)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("VM disk source and snapshot disk sou= rce are not the same")); + return -1; + } =20 - if (!virStorageSourceIsSameLocation(data->parentDiskSrc, data-= >parentDomDisk->src)) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("snapshot VM disk source and parent disk = source are not the same")); - return -1; + data->parentDiskSrc =3D data->diskSrc->backingStore; + if (!virStorageSourceIsBacking(data->parentDiskSrc)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to find parent disk source in= backing chain")); + return -1; + } + + if (!virStorageSourceIsSameLocation(data->parentDiskSrc, + data->parentDomDisk->s= rc)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("snapshot VM disk source and parent d= isk source are not the same")); + return -1; + } } - } =20 - data->parentSnap =3D qemuSnapshotFindParentSnapForDisk(snap, data-= >snapDisk); + data->parentSnap =3D qemuSnapshotFindParentSnapForDisk(snap, d= ata->snapDisk); =20 - if (data->parentSnap && !virDomainSnapshotIsExternal(data->parentS= nap)) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("deleting external snapshot that has internal= snapshot as parent not supported")); - return -1; + if (data->parentSnap && !virDomainSnapshotIsExternal(data->par= entSnap)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("deleting external snapshot that has inte= rnal snapshot as parent not supported")); + return -1; + } } =20 ret =3D g_slist_prepend(ret, g_steal_pointer(&data)); @@ -2740,7 +2760,7 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm, } =20 /* this also serves as validation whether the snapshot can be deleted = */ - if (qemuSnapshotDeleteExternalPrepareData(vm, snap, &tmpData) < 0) + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, true, &tmpData) < = 0) return -1; =20 if (!virDomainObjIsActive(vm)) { @@ -2755,7 +2775,7 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm, =20 /* Call the prepare again as some data require that the VM is * running to get everything we need. */ - if (qemuSnapshotDeleteExternalPrepareData(vm, snap, externalData) = < 0) + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, true, external= Data) < 0) return -1; } else { qemuDomainJobPrivate *jobPriv =3D vm->job->privateData; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005884; cv=none; d=zohomail.com; s=zohoarc; b=NTuIHTMun4J67/pt21C26BmiWpAoq9wKiEUnpeBTBLgEriOcAaENtUJIru7bUM0iBKlrKE9TWn39qIZU5FFNUho4YtRgbi7tf4hKJWhppgDfhbIsC1ZlqTLBg+GSBPL4wWphIpwJJY+8aOInTAVPpDRkgLn4bujqx+ZbQaBX4E0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005884; h=Content-Type:Content-Transfer-Encoding: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=R+z8ew8Ra5EqoVoSPD30/NmGVTN6yGdo/gff49BAd68=; b=OL02fjtbg7TjXBgX5uhvAFtbGpU/Scr6sXYyqwvAUkIMIaHXb73n9UvH9GtuN0v6uIAbrTLkJF/9aMTDDx9mLn5dcR77DX4WcCOFl5gnAz+Hqe4KLfzZDacmF+abHhOMX0wK99IhAhWY6oW5rASed2TtsGsCAJquisIL4xHoouk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692005884161923.8140004108868; Mon, 14 Aug 2023 02:38:04 -0700 (PDT) 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-673-AtZ4e16YOu-MejoLWP9J-g-1; Mon, 14 Aug 2023 05:36:54 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 551D38DC664; Mon, 14 Aug 2023 09:36:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4276F492C14; Mon, 14 Aug 2023 09:36:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1C2AF19452D2; Mon, 14 Aug 2023 09:36:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 98B4719465A4 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6EE3E40C207F; Mon, 14 Aug 2023 09:36:28 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12D2140C207D for ; Mon, 14 Aug 2023 09:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005883; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=R+z8ew8Ra5EqoVoSPD30/NmGVTN6yGdo/gff49BAd68=; b=Mm4YiJApH5OlwC3D6tbxGJ3UW9wh6yoqxNi7AjiXfLJ0ECHYmNnJne3LGxMkRhhmAbxZkl Jgn9NrOseW7t7Pl2UkeEau7kCjMSz407hOXF0+3Xiw8DdYAoF5LxT36BcEpTUxEiXj3CFI E57daGLhDNc1tM/QlfOXZphaSSe7fzw= X-MC-Unique: AtZ4e16YOu-MejoLWP9J-g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 16/25] qemu_snapshot: prepare data for non-active leaf external snapshot deletion Date: Mon, 14 Aug 2023 11:36:08 +0200 Message-ID: <10c3cfcbd1f0440e689d253ab285b82e57336f8a.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005885361100001 Content-Type: text/plain; charset="utf-8"; x-default="true" In this case there is no need to run block commit and using qemu process at all. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 55 +++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index d47dc72709..8b005cae8f 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2759,34 +2759,43 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm, return 0; } =20 - /* this also serves as validation whether the snapshot can be deleted = */ - if (qemuSnapshotDeleteExternalPrepareData(vm, snap, true, &tmpData) < = 0) - return -1; - - if (!virDomainObjIsActive(vm)) { - if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB_SNAPSHO= T, - NULL, -1, NULL, NULL, - VIR_NETDEV_VPORT_PROFILE_OP_CREATE, - VIR_QEMU_PROCESS_START_PAUSED) < 0) { - return -1; - } - - *stop_qemu =3D true; - - /* Call the prepare again as some data require that the VM is - * running to get everything we need. */ - if (qemuSnapshotDeleteExternalPrepareData(vm, snap, true, external= Data) < 0) + /* Leaf non-active snapshot doesn't have overlay files for the disk im= ages + * so there is no need to do any merge and we can just delete the files + * directly. */ + if (snap !=3D virDomainSnapshotGetCurrent(vm->snapshots) && + snap->nchildren =3D=3D 0) { + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, false, externa= lData) < 0) return -1; } else { - qemuDomainJobPrivate *jobPriv =3D vm->job->privateData; + /* this also serves as validation whether the snapshot can be dele= ted */ + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, true, &tmpData= ) < 0) + return -1; =20 - *externalData =3D g_steal_pointer(&tmpData); + if (!virDomainObjIsActive(vm)) { + if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB_SNA= PSHOT, + NULL, -1, NULL, NULL, + VIR_NETDEV_VPORT_PROFILE_OP_CREATE, + VIR_QEMU_PROCESS_START_PAUSED) < 0) { + return -1; + } =20 - /* If the VM is running we need to indicate that the async snapshot - * job is snapshot delete job. */ - jobPriv->snapshotDelete =3D true; + *stop_qemu =3D true; =20 - qemuDomainSaveStatus(vm); + /* Call the prepare again as some data require that the VM is + * running to get everything we need. */ + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, true, exte= rnalData) < 0) + return -1; + } else { + qemuDomainJobPrivate *jobPriv =3D vm->job->privateData; + + *externalData =3D g_steal_pointer(&tmpData); + + /* If the VM is running we need to indicate that the async sna= pshot + * job is snapshot delete job. */ + jobPriv->snapshotDelete =3D true; + + qemuDomainSaveStatus(vm); + } } =20 return 0; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005834; cv=none; d=zohomail.com; s=zohoarc; b=lOSvbvCeu8hsFG9Kb+KoyFVe8GdZIMQVdMmluhubJ8B87ckDhretWxvdLXaNCb0tozhKfKE9QuQRHbYZLRhlilCSBGiPPxRrR/rLNg5pCIvsk96GbiOQ+zhsh5LPp1AQa3XhJEe2DEY81lH+nVSFzE9iPrwJe1El4tRFMJBEqPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005834; h=Content-Type:Content-Transfer-Encoding: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=8HJx1X9RjvQHpOsM7LMWRq6WeYM0UXVYHa0R8NlJMNY=; b=RPT0YN2kHB4zHW3erGlpZr3jcrxLzbwWdVVCbtG4v62k7ylVQGlu/Rgw6LsiFFWbiKicqocI695ilmidfDgG7ktScaQCo8M+8ky5LPY7agQXYxUbK0mTWFRvM4bXX32y9l6/p398giBaapZgJ0OU7veX7AbfKW+ZziXC5ARYEso= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005834842327.9682248132773; Mon, 14 Aug 2023 02:37:14 -0700 (PDT) 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-638-i7iVmRY7NwWmqrXWX5ySnw-1; Mon, 14 Aug 2023 05:37:08 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B6E96830D35; Mon, 14 Aug 2023 09:37:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97467403174; Mon, 14 Aug 2023 09:37:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AA7A119451DA; Mon, 14 Aug 2023 09:36:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 98D7C19465A8 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 105F540B4CCC; Mon, 14 Aug 2023 09:36:29 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id A865C40C207D for ; Mon, 14 Aug 2023 09:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005833; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=8HJx1X9RjvQHpOsM7LMWRq6WeYM0UXVYHa0R8NlJMNY=; b=QM+epQ00fUIYzUAEzVcxfhRNkVS0hnI3eI07XBeIUPMSm/o/QN1LjHLaKlgM6BuTeqeOVF h3bU+RthnWSJrTzub2HX4jvLlIp+Bg7Nuz76pSri1547aaIPeq8CH+uurboJBV7JXZENbe ImA+JLZV3CheEK0/3Nd1WcRddZza9R8= X-MC-Unique: i7iVmRY7NwWmqrXWX5ySnw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 17/25] qemu_snapshot: add support to delete external snapshot without block commit Date: Mon, 14 Aug 2023 11:36:09 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005836622100007 Content-Type: text/plain; charset="utf-8"; x-default="true" When block commit is not needed we can just simply unlink the disk files. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 56 ++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 8b005cae8f..a67be1ae49 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2563,6 +2563,7 @@ typedef struct _qemuSnapshotDeleteExternalData { virStorageSource *prevDiskSrc; /* source of disk for which @diskSrc is backing disk */ qemuBlockJobData *job; + bool merge; } qemuSnapshotDeleteExternalData; =20 =20 @@ -2664,6 +2665,7 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj *v= m, =20 data =3D g_new0(qemuSnapshotDeleteExternalData, 1); data->snapDisk =3D snapDisk; + data->merge =3D merge; =20 data->parentDomDisk =3D virDomainDiskByTarget(snapdef->parent.dom, data->snapDisk->name); @@ -2674,7 +2676,7 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj *v= m, return -1; } =20 - if (merge) { + if (data->merge) { data->domDisk =3D qemuDomainDiskByName(vm->def, snapDisk->name= ); if (!data->domDisk) return -1; @@ -3114,31 +3116,42 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, virTristateBool autofinalize =3D VIR_TRISTATE_BOOL_NO; unsigned int commitFlags =3D VIR_DOMAIN_BLOCK_COMMIT_DELETE; =20 - if (data->domDisk->src =3D=3D data->diskSrc) { - commitFlags |=3D VIR_DOMAIN_BLOCK_COMMIT_ACTIVE; - autofinalize =3D VIR_TRISTATE_BOOL_YES; + if (data->merge) { + if (data->domDisk->src =3D=3D data->diskSrc) { + commitFlags |=3D VIR_DOMAIN_BLOCK_COMMIT_ACTIVE; + autofinalize =3D VIR_TRISTATE_BOOL_YES; + } + + if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDis= k, true) < 0) + goto error; + + data->job =3D qemuBlockCommit(vm, + data->domDisk, + data->parentDiskSrc, + data->diskSrc, + data->prevDiskSrc, + 0, + VIR_ASYNC_JOB_SNAPSHOT, + autofinalize, + commitFlags); + + if (!data->job) + goto error; + } else { + if (virStorageSourceInit(data->parentDomDisk->src) < 0 || + virStorageSourceUnlink(data->parentDomDisk->src) < 0) { + VIR_WARN("Failed to remove snapshot image '%s'", + data->snapDisk->name); + } } - - if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, t= rue) < 0) - goto error; - - data->job =3D qemuBlockCommit(vm, - data->domDisk, - data->parentDiskSrc, - data->diskSrc, - data->prevDiskSrc, - 0, - VIR_ASYNC_JOB_SNAPSHOT, - autofinalize, - commitFlags); - - if (!data->job) - goto error; } =20 for (cur =3D externalData; cur; cur =3D g_slist_next(cur)) { qemuSnapshotDeleteExternalData *data =3D cur->data; =20 + if (!data->merge) + continue; + if (qemuSnapshotDeleteBlockJobRunning(vm, data->job) < 0) goto error; =20 @@ -3153,6 +3166,9 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, for (cur =3D externalData; cur; cur =3D g_slist_next(cur)) { qemuSnapshotDeleteExternalData *data =3D cur->data; =20 + if (!data->merge) + continue; + if (data->job->state =3D=3D QEMU_BLOCKJOB_STATE_READY) { if (qemuBlockPivot(vm, data->job, VIR_ASYNC_JOB_SNAPSHOT, NULL= ) < 0) goto error; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005811; cv=none; d=zohomail.com; s=zohoarc; b=Pm20MZBFIWQ5+Kp1sT4xbFPij59+GIox28UMrWsdgVV05TrEn9L3IMyMvvyv8tHaSvyrXyVyLxmqHPqM0Evy0tBDWIMRKyfyAZgCSepi4psi3yNgozFIC0woqg2RvQUnk6NQlC0dyGV81NPD6eMcL3uXGzmJzn07s2AYr9OejD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005811; h=Content-Type:Content-Transfer-Encoding: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=wajkSIqgMCinT51pVrY2Vq6iLQSLpSrcYRYnOsbtDQw=; b=UEqzLNt3lSR9VpVZ3uMLujsJ0V4hqV5G06KFNYc2Z6c6zCez97ofwjGw7tr2L5UerDvAolX/TdcDS7XyOeqS2gHSl6FzlVIA+0PLBv4BOS3ccPwuu1MWv5b2Uq/MgZgOY0/qVf8/Y396h4HP6Pg6yEsZIYtK4oicenJHPuP8ZDg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692005811151226.73857422500373; Mon, 14 Aug 2023 02:36:51 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [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-621-i4quy3xNPLGfZG8vxcoXJg-1; Mon, 14 Aug 2023 05:36:47 -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 0D2961C07263; Mon, 14 Aug 2023 09:36:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3AEF40C206F; Mon, 14 Aug 2023 09:36:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7B3B61946594; Mon, 14 Aug 2023 09:36:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9A3F919465B1 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A4F5A40B4CCB; Mon, 14 Aug 2023 09:36:29 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4929140C207D for ; Mon, 14 Aug 2023 09:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005810; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wajkSIqgMCinT51pVrY2Vq6iLQSLpSrcYRYnOsbtDQw=; b=atIzHF08m/Uy9mNR1GXyDUAoZsvT97K/gfU6aNWp+7RuOpzU0zONigfLa0dhOXwO91EPbF cK2VO0gCDq/pCXP0ISSic4Hu0GfMFwhmDbyjrpUmdTzoNYWzOcr2E2sEG3gEdddRc8t/Mm TL2LfHDJ2EHMkrOam8AWM08Aah7nQaM= X-MC-Unique: i4quy3xNPLGfZG8vxcoXJg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 18/25] qemu_snapshot: delete: properly update parent snapshot with revert data Date: Mon, 14 Aug 2023 11:36:10 +0200 Message-ID: <603c2a7a39cebc8ccc6c136490b3c06471c70694.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005811703100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When deleting external snapshot and parent snapshot is the currently active snapshot as user reverted to it we need to properly update the parent snapshot metadata. After the delete is done the new overlay files will be the currently used files created when snapshot revert was done, replacing the original overlay files. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index a67be1ae49..6dd420a53b 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -3229,6 +3229,41 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, } =20 =20 +static int +qemuSnapshotDeleteUpdateParent(virDomainObj *vm, + virDomainMomentObj *parent) +{ + size_t i; + virQEMUDriver *driver =3D QEMU_DOMAIN_PRIVATE(vm)->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + virDomainSnapshotDef *parentDef =3D virDomainSnapshotObjGetDef(parent); + + if (!parentDef) + return 0; + + if (!parentDef->revertdisks) + return 0; + + for (i =3D 0; i < parentDef->ndisks; i++) { + virDomainSnapshotDiskDefClear(&parentDef->disks[i]); + } + g_free(parentDef->disks); + + parentDef->disks =3D g_steal_pointer(&parentDef->revertdisks); + parentDef->ndisks =3D parentDef->nrevertdisks; + parentDef->nrevertdisks =3D 0; + + if (qemuDomainSnapshotWriteMetadata(vm, + parent, + driver->xmlopt, + cfg->snapshotDir) < 0) { + return -1; + } + + return 0; +} + + static int qemuSnapshotDiscardMetadata(virDomainObj *vm, virDomainMomentObj *snap, @@ -3268,6 +3303,11 @@ qemuSnapshotDiscardMetadata(virDomainObj *vm, virDomainMomentMoveChildren(snap, snap->parent); } =20 + if (update_parent && snap->parent) { + if (qemuSnapshotDeleteUpdateParent(vm, snap->parent) < 0) + ret =3D -1; + } + snapFile =3D g_strdup_printf("%s/%s/%s.xml", cfg->snapshotDir, vm->def= ->name, snap->def->name); =20 --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005826; cv=none; d=zohomail.com; s=zohoarc; b=QVL4QLodytZ5s8AvgBC6t/c2I+1J7Mb2iXOoHNBFBrY42KD4AxBbWYpGScYxH6OXkpYlWtMREstXWzNUfxo31T7kzcqjFUMcYRr+2s6EvpICOI9ICqe0SJL6CInlDnq0ymHeZUQFF/SVQ06eL5A7ZodkzmQbOECX+OdwJ2v5DbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005826; h=Content-Type:Content-Transfer-Encoding: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=3p5JLfu5Nc5VRHsqx0H5CUQIsKbdkiRWWFFb1WEDO7M=; b=nTjIfWKvwcrhMn8aDpxsELl9LOvUSWFVHMw/8i18062cr6hkR/NNqvTEW04wMRUn79HHnJ1m9rQ8cygmNA4OahtSaR6h0Pn5m+twNR2n2XiLyk74yJnzFQQpLTYjxxHlWZdTFFMP96alHsK8Ky0ZqBw7OOkEtH6SNtF5QXPKkbE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692005826362594.2477078846172; Mon, 14 Aug 2023 02:37:06 -0700 (PDT) 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-475-Qw4uUedAO46z2tJAo9sCOw-1; Mon, 14 Aug 2023 05:37:00 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B1FA104458B; Mon, 14 Aug 2023 09:36:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 264F9492C13; Mon, 14 Aug 2023 09:36:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 371F01946A54; Mon, 14 Aug 2023 09:36:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9B1D619465B2 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4721440B4CCD; Mon, 14 Aug 2023 09:36:30 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE0C240C207D for ; Mon, 14 Aug 2023 09:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005825; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3p5JLfu5Nc5VRHsqx0H5CUQIsKbdkiRWWFFb1WEDO7M=; b=NNUK9ueK0p9N5+72Y+i+TMiIT8c4Ct3Y8sWEndag9zHY0NEmGzuHrKrGY2gXvHmJAjEf2K lXIa1qtwO/Ul0Vq8NGIFF4CqKDp7O5mpCb+l5R6o49MvRe8viYzoOyytic1rLJmxtEqVLx ic2gXSnExat56dqTOTn37uwqM8xJ5Rw= X-MC-Unique: Qw4uUedAO46z2tJAo9sCOw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 19/25] qemu_snapshot: remove revertdisks when creating new snapshot Date: Mon, 14 Aug 2023 11:36:11 +0200 Message-ID: <7d235f26a53c314a68209c245336f81b6dde045c.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005826943100003 Content-Type: text/plain; charset="utf-8"; x-default="true" When user creates a new snapshot after reverting to non-leaf snapshot we no longer need to store the temporary overlays as they will be part of the VM XMLs stored in the newly created snapshot. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 6dd420a53b..0238ab2249 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1659,6 +1659,28 @@ qemuSnapshotCreateWriteMetadata(virDomainObj *vm, } =20 =20 +static void +qemuSnapshotClearRevertdisks(virDomainMomentObj *current) +{ + virDomainSnapshotDef *curdef =3D NULL; + + if (!current) + return; + + curdef =3D virDomainSnapshotObjGetDef(current); + + if (curdef->revertdisks) { + size_t i; + + for (i =3D 0; i < curdef->nrevertdisks; i++) + virDomainSnapshotDiskDefClear(&curdef->revertdisks[i]); + + g_clear_pointer(&curdef->revertdisks, g_free); + curdef->nrevertdisks =3D 0; + } +} + + static virDomainSnapshotPtr qemuSnapshotRedefine(virDomainObj *vm, virDomainPtr domain, @@ -1668,6 +1690,7 @@ qemuSnapshotRedefine(virDomainObj *vm, unsigned int flags) { virDomainMomentObj *snap =3D NULL; + virDomainMomentObj *current =3D virDomainSnapshotGetCurrent(vm->snapsh= ots); virDomainSnapshotPtr ret =3D NULL; g_autoptr(virDomainSnapshotDef) snapdef =3D virObjectRef(snapdeftmp); =20 @@ -1685,8 +1708,10 @@ qemuSnapshotRedefine(virDomainObj *vm, * makes sense, such as checking that qemu-img recognizes the * snapshot name in at least one of the domain's disks? */ =20 - if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT) + if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT) { + qemuSnapshotClearRevertdisks(current); qemuSnapshotSetCurrent(vm, snap); + } =20 if (qemuSnapshotCreateWriteMetadata(vm, snap, driver, cfg) < 0) goto error; @@ -1765,6 +1790,7 @@ qemuSnapshotCreate(virDomainObj *vm, } =20 if (!tmpsnap) { + qemuSnapshotClearRevertdisks(current); qemuSnapshotSetCurrent(vm, snap); =20 if (qemuSnapshotCreateWriteMetadata(vm, snap, driver, cfg) < 0) --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005826; cv=none; d=zohomail.com; s=zohoarc; b=llcsM+3tTrvtOClPaqfPf+KYBeGgxo2EKWhZSglSmSOmv8zwj6AEZXA4Qf01kMXjqmmZm1IwiwvxOS6uSkxXFodtr7ohnijiWDLU44F50jPvO6IhwnKckNbv+jK/McFf2n/AHyF4IfOSIxbBdrGyOQ/0A7po+70z8+KRvPncrZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005826; h=Content-Type:Content-Transfer-Encoding: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=Job1OVcr2/oQkzOzg2E43MJPj7HobhSo/pqS4ukwIZQ=; b=KQUfx3eLFEsJ611Wiu50ifFkjZZqD+YsEl53US0bRf/NarUsQX3pY0i6uM15nJRzQKwVC8a0O3DDCCarJXsckWABEiFzFkT5qLynRy/tDTt49PR+rV1AYag0Fb+FKkrvAuwwbPN0O8DLAXQbEjXpfJWhtSUyjCc42EBrU6pNuUQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005826367133.11867516357472; Mon, 14 Aug 2023 02:37:06 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [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-246-HjUheO7qNPCKSBimQTauqg-1; Mon, 14 Aug 2023 05:37:01 -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 EA1221C0755A; Mon, 14 Aug 2023 09:36:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4E682026D68; Mon, 14 Aug 2023 09:36:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6CB931946A73; Mon, 14 Aug 2023 09:36:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9CCAC19465B5 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DC2A240B4CCE; Mon, 14 Aug 2023 09:36:30 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8009A40C207D for ; Mon, 14 Aug 2023 09:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005825; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Job1OVcr2/oQkzOzg2E43MJPj7HobhSo/pqS4ukwIZQ=; b=d5yRHO8zrFUUVa2bh9f5DZtpROIGNpC0S1rm2yr6TJo8ZAzWpTrPI6OuM6HjgCd2CXg+mP 4VWQRGWSpWPS1Ws37mXJWfUW+AZS21/Vq6BlHL+x49gbf17en9E6QwRKwIc5igPShRenFZ rnIwM6fD+bTTsDB35GgPdJq9ExGsbeI= X-MC-Unique: HjUheO7qNPCKSBimQTauqg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 20/25] virdomainmomentobjlist: introduce virDomainMomentIsAncestor Date: Mon, 14 Aug 2023 11:36:12 +0200 Message-ID: <82fa479d1beb2dd1f9ddf9863752fca68ac2179b.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005826574100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This new helper will allow us to check if we are able to delete external snapshot after user did revert to non-leaf snapshot. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/conf/virdomainmomentobjlist.c | 17 +++++++++++++++++ src/conf/virdomainmomentobjlist.h | 4 ++++ src/libvirt_private.syms | 1 + 3 files changed, 22 insertions(+) diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentob= jlist.c index e5cdd9a141..ea9850df8c 100644 --- a/src/conf/virdomainmomentobjlist.c +++ b/src/conf/virdomainmomentobjlist.c @@ -582,3 +582,20 @@ virDomainMomentFindLeaf(virDomainMomentObjList *list) return moment; return NULL; } + + +/* Check if @moment is descendant of @ancestor. */ +bool +virDomainMomentIsAncestor(virDomainMomentObj *moment, + virDomainMomentObj *ancestor) +{ + if (moment =3D=3D ancestor) + return false; + + for (moment =3D moment->parent; moment; moment =3D moment->parent) { + if (moment =3D=3D ancestor) + return true; + } + + return false; +} diff --git a/src/conf/virdomainmomentobjlist.h b/src/conf/virdomainmomentob= jlist.h index d2ab3b46b1..2ea6b181c0 100644 --- a/src/conf/virdomainmomentobjlist.h +++ b/src/conf/virdomainmomentobjlist.h @@ -157,3 +157,7 @@ virDomainMomentCheckCycles(virDomainMomentObjList *list, =20 virDomainMomentObj * virDomainMomentFindLeaf(virDomainMomentObjList *list); + +bool +virDomainMomentIsAncestor(virDomainMomentObj *moment, + virDomainMomentObj *ancestor); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a75156f097..1cf40ba863 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1221,6 +1221,7 @@ virDomainMomentDropChildren; virDomainMomentDropParent; virDomainMomentForEachChild; virDomainMomentForEachDescendant; +virDomainMomentIsAncestor; virDomainMomentMoveChildren; virDomainMomentObjFree; virDomainMomentObjNew; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005887; cv=none; d=zohomail.com; s=zohoarc; b=cp6qTXoXrzG7VhrBoA3kDEBm0BYHojBHQ92FPF0Q+etl6TI1tDsN7F7c1ZN69uuy8tbVPD02Fm8lCTokP1TRbFwm9KYFkqznHypSmLAdwFh1ho/BbCTS+hsp6DtX82rCOokS51mv+kgL8HCpLAGOf1bNcwqVMWjtMcueohrHwCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005887; h=Content-Type:Content-Transfer-Encoding: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=vZdC5e+7DXFp4TIPVN0BG12ULQhfxY9sJ40yrGzDM0k=; b=kSL9+jte83YHlIIScqFY9YdXKLDcx3uERbhDfuuFkkXa7Y87D9UMUxH7oEoK8uUVCLQIIEd7A8rHJEZE+AAQOw5SepYajlHbobT2x8y7ssmrUmbl0Dp8dkvBz9CG/J3O2WxuntueSPRhZMtD0j4OXr4XSnhz5ZzInHO1KP9/Y6I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 169200588779146.16681904310212; Mon, 14 Aug 2023 02:38:07 -0700 (PDT) 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-660-FqnkPVvnOymNrg87FpTexQ-1; Mon, 14 Aug 2023 05:37:08 -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 35FBB8087B9; Mon, 14 Aug 2023 09:37:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05EE62026FFE; Mon, 14 Aug 2023 09:37:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E17A319451DF; Mon, 14 Aug 2023 09:36:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B92731946594 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7D69240B4CCF; Mon, 14 Aug 2023 09:36:31 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21A2840C207D for ; Mon, 14 Aug 2023 09:36:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005886; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=vZdC5e+7DXFp4TIPVN0BG12ULQhfxY9sJ40yrGzDM0k=; b=ioAhF3ecWicPHNm8zbADK6TL+l+TRoohlGs3Qh3gR0xlnpdeOWsW6AQXRNUQw9g/Z5kWMf wqY9Iep2hNw+Rv0AigD8NPLkW35Orbqx8TGoSp/fFaiw8sGbXKCHGGM/GZJJpHDpJ15v7M Umsa6iqyi2/PNF7O8ZTmwa19XbkLVWc= X-MC-Unique: FqnkPVvnOymNrg87FpTexQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 21/25] qemuDomainGetImageIds: pass domain definition directly Date: Mon, 14 Aug 2023 11:36:13 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005889174100007 Content-Type: text/plain; charset="utf-8"; x-default="true" We only need the domain definition from domain object. This will allow us to use it from snapshot code where we need to pass different domain definition. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_backup.c | 2 +- src/qemu/qemu_blockjob.c | 2 +- src/qemu/qemu_domain.c | 8 ++++---- src/qemu/qemu_domain.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c index 3be33193f4..a94869522d 100644 --- a/src/qemu/qemu_backup.c +++ b/src/qemu/qemu_backup.c @@ -586,7 +586,7 @@ qemuBackupJobTerminate(virDomainObj *vm, if (!cfg) cfg =3D virQEMUDriverGetConfig(priv->driver); =20 - qemuDomainGetImageIds(cfg, vm, backupdisk->store, NULL, &uid, = &gid); + qemuDomainGetImageIds(cfg, vm->def, backupdisk->store, NULL, &= uid, &gid); =20 if (virFileRemove(backupdisk->store->path, uid, gid) < 0) VIR_WARN("failed to remove scratch file '%s'", diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index 1cac17c5c0..f1d22df59f 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -932,7 +932,7 @@ qemuBlockJobDeleteImages(virQEMUDriver *driver, for (; p !=3D NULL; p =3D p->backingStore) { if (virStorageSourceGetActualType(p) =3D=3D VIR_STORAGE_TYPE_FILE)= { =20 - qemuDomainGetImageIds(cfg, vm, p, disk->src, &uid, &gid); + qemuDomainGetImageIds(cfg, vm->def, p, disk->src, &uid, &gid); =20 if (virFileRemove(p->path, uid, gid) < 0) { VIR_WARN("Unable to remove snapshot image file '%s' (%s)", diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 029238a9d7..0bb1fafdec 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7719,7 +7719,7 @@ qemuDomainCleanupRun(virQEMUDriver *driver, =20 void qemuDomainGetImageIds(virQEMUDriverConfig *cfg, - virDomainObj *vm, + virDomainDef *def, virStorageSource *src, virStorageSource *parentSrc, uid_t *uid, gid_t *gid) @@ -7740,7 +7740,7 @@ qemuDomainGetImageIds(virQEMUDriverConfig *cfg, *gid =3D cfg->group; } =20 - if (vm && (vmlabel =3D virDomainDefGetSecurityLabelDef(vm->def, "dac")= ) && + if ((vmlabel =3D virDomainDefGetSecurityLabelDef(def, "dac")) && vmlabel->label) virParseOwnershipIds(vmlabel->label, uid, gid); =20 @@ -7765,7 +7765,7 @@ qemuDomainStorageFileInit(virQEMUDriver *driver, uid_t uid; gid_t gid; =20 - qemuDomainGetImageIds(cfg, vm, src, parent, &uid, &gid); + qemuDomainGetImageIds(cfg, vm->def, src, parent, &uid, &gid); =20 if (virStorageSourceInitAs(src, uid, gid) < 0) return -1; @@ -7958,7 +7958,7 @@ qemuDomainDetermineDiskChain(virQEMUDriver *driver, return 0; } =20 - qemuDomainGetImageIds(cfg, vm, src, disksrc, &uid, &gid); + qemuDomainGetImageIds(cfg, vm->def, src, disksrc, &uid, &gid); =20 if (virStorageSourceGetMetadata(src, uid, gid, QEMU_DOMAIN_STORAGE_SOURCE_CHAIN_MAX_D= EPTH, diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 999190e381..7ac1cdd6be 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -738,7 +738,7 @@ bool qemuDomainDiskChangeSupported(virDomainDiskDef *di= sk, virDomainDiskDef *orig_disk); =20 void qemuDomainGetImageIds(virQEMUDriverConfig *cfg, - virDomainObj *vm, + virDomainDef *def, virStorageSource *src, virStorageSource *parentSrc, uid_t *uid, --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005887; cv=none; d=zohomail.com; s=zohoarc; b=F2TfLjTYw2P9+DDnah1t/kSydTpW8+bbt02uMo1qcajCWbYNFc+jlEj5yy+IZIsN7llv59r4f3GygY3o7RW+9tGECjsEYQ69ESfntVqPUIpKPsycAnO6F0vgTUssx1psqlTjjf8H/LBIGf7JkoGpl+T+SwKM3mVlmHLXvIN4YCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005887; h=Content-Type:Content-Transfer-Encoding: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=SBR/+ynU4jQC1TukIvSz7ICRDxKYPvAUg1Ag53HoOqI=; b=B9Fun4Tw7kHG1BmPX9767J+betaccANpu3UcKkhWOB3qd58KSHcij5/RTAoP20hdnrTi7iW8hCZbb1Jkh4LGTwhj51z4C1SE1cmbZ/+nBrXO8kKonmDA2wqkeI49HHgEqVLTzWRpyIFcDW/1aJEYG5JkVGi9TJf03CD8f/0SUiw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005887562356.50533936396164; Mon, 14 Aug 2023 02:38:07 -0700 (PDT) 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-642-Zx7-AW6oM-mPagPqpFpqOg-1; Mon, 14 Aug 2023 05:37:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 46F36805586; Mon, 14 Aug 2023 09:37:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EE2540D2839; Mon, 14 Aug 2023 09:37:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 38A2B19451C7; Mon, 14 Aug 2023 09:36:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9B89A19465B3 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2119640C207D; Mon, 14 Aug 2023 09:36:32 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6E6F40B4CD0 for ; Mon, 14 Aug 2023 09:36:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005886; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=SBR/+ynU4jQC1TukIvSz7ICRDxKYPvAUg1Ag53HoOqI=; b=hqTOEOA6GKH8pk04EfAUWrETH/RZ/O9Wqew+g/jrR8f1zns5tH8JKr99nqiAsuCSLO0GlB J3wMaMhd3vJUtLwFvf16x1wHD/ERuEYk47o4PaRDf0h8uKZMYDKVi7nuQLDBRuAM80z0xi ydf3+TRQaIV0Sv9kg9AXkDiFmSlbqmk= X-MC-Unique: Zx7-AW6oM-mPagPqpFpqOg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 22/25] qemu_snapshot: update backing store after deleting external snapshot Date: Mon, 14 Aug 2023 11:36:14 +0200 Message-ID: <398d88dc84373b1173b435266c9dc6677c352578.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005889204100008 Content-Type: text/plain; charset="utf-8"; x-default="true" With introduction of external snapshot revert we will have to update backing store of qcow images not actively used be QEMU manually. The need for this patch comes from the fact that we stop and start QEMU process therefore after revert not all existing snapshots will be known to that QEMU process due to reverting to non-leaf snapshot or having multiple branches. We need to loop over all existing snapshots and check all disks to see if they happen to have the image we are deleting as backing store and update them to point to the new image except for images currently used by the running QEMU process doing the merge operation. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 122 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 0238ab2249..8d0581d33b 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2588,6 +2588,8 @@ typedef struct _qemuSnapshotDeleteExternalData { virStorageSource *parentDiskSrc; /* backing disk source of the @diskSr= c */ virStorageSource *prevDiskSrc; /* source of disk for which @diskSrc is backing disk */ + GSList *disksWithBacking; /* list of storage source data for which the + deleted storage source is backing store */ qemuBlockJobData *job; bool merge; } qemuSnapshotDeleteExternalData; @@ -2600,6 +2602,7 @@ qemuSnapshotDeleteExternalDataFree(qemuSnapshotDelete= ExternalData *data) return; =20 virObjectUnref(data->job); + g_slist_free_full(data->disksWithBacking, g_free); =20 g_free(data); } @@ -2649,6 +2652,84 @@ qemuSnapshotFindParentSnapForDisk(virDomainMomentObj= *snap, } =20 =20 +struct _qemuSnapshotDisksWithBackingStoreData { + virStorageSource *diskSrc; + uid_t uid; + gid_t gid; +}; + + +struct _qemuSnapshotDisksWithBackingStoreIterData { + virDomainMomentObj *current; + virStorageSource *diskSrc; + GSList **disksWithBacking; + virQEMUDriverConfig *cfg; +}; + + +static int +qemuSnapshotDiskHasBackingDisk(void *payload, + const char *name G_GNUC_UNUSED, + void *opaque) +{ + virDomainMomentObj *snap =3D payload; + virDomainSnapshotDef *snapdef =3D virDomainSnapshotObjGetDef(snap); + struct _qemuSnapshotDisksWithBackingStoreIterData *iterdata =3D opaque; + ssize_t i; + + /* skip snapshots that are within the active snapshot tree as it will = be handled + * by qemu */ + if (virDomainMomentIsAncestor(iterdata->current, snap) || iterdata->cu= rrent =3D=3D snap) + return 0; + + for (i =3D 0; i < snapdef->parent.dom->ndisks; i++) { + virDomainDiskDef *disk =3D snapdef->parent.dom->disks[i]; + uid_t uid; + gid_t gid; + + if (!virStorageSourceIsLocalStorage(disk->src)) + continue; + + qemuDomainGetImageIds(iterdata->cfg, snapdef->parent.dom, disk->sr= c, + NULL, &uid, &gid); + + if (!disk->src->backingStore) + ignore_value(virStorageSourceGetMetadata(disk->src, uid, gid, = 1, false)); + + if (virStorageSourceIsSameLocation(disk->src->backingStore, iterda= ta->diskSrc)) { + struct _qemuSnapshotDisksWithBackingStoreData *data =3D + g_new0(struct _qemuSnapshotDisksWithBackingStoreData, 1); + + data->diskSrc =3D disk->src; + data->uid =3D uid; + data->gid =3D gid; + + *iterdata->disksWithBacking =3D g_slist_prepend(*iterdata->dis= ksWithBacking, data); + } + } + + return 0; +} + + +static void +qemuSnapshotGetDisksWithBackingStore(virDomainObj *vm, + virDomainMomentObj *snap, + qemuSnapshotDeleteExternalData *data) +{ + struct _qemuSnapshotDisksWithBackingStoreIterData iterData; + virQEMUDriver *driver =3D QEMU_DOMAIN_PRIVATE(vm)->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + + iterData.current =3D virDomainSnapshotGetCurrent(vm->snapshots); + iterData.diskSrc =3D data->diskSrc; + iterData.disksWithBacking =3D &data->disksWithBacking; + iterData.cfg =3D cfg; + + virDomainMomentForEachDescendant(snap, qemuSnapshotDiskHasBackingDisk,= &iterData); +} + + /** * qemuSnapshotDeleteExternalPrepareData: * @vm: domain object @@ -2733,6 +2814,8 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj *v= m, _("snapshot VM disk source and parent d= isk source are not the same")); return -1; } + + qemuSnapshotGetDisksWithBackingStore(vm, snap, data); } =20 data->parentSnap =3D qemuSnapshotFindParentSnapForDisk(snap, d= ata->snapDisk); @@ -3129,6 +3212,43 @@ qemuSnapshotSetInvalid(virDomainObj *vm, } =20 =20 +static void +qemuSnapshotUpdateBackingStore(virDomainObj *vm, + qemuSnapshotDeleteExternalData *data) +{ + GSList *cur =3D NULL; + const char *qemuImgPath; + virQEMUDriver *driver =3D QEMU_DOMAIN_PRIVATE(vm)->driver; + + if (!(qemuImgPath =3D qemuFindQemuImgBinary(driver))) + return; + + for (cur =3D data->disksWithBacking; cur; cur =3D g_slist_next(cur)) { + struct _qemuSnapshotDisksWithBackingStoreData *backingData =3D cur= ->data; + g_autoptr(virCommand) cmd =3D NULL; + + /* creates cmd line args: qemu-img create -f qcow2 -o */ + if (!(cmd =3D virCommandNewArgList(qemuImgPath, + "rebase", + "-u", + "-F", + virStorageFileFormatTypeToString(= data->parentDiskSrc->format), + "-f", + virStorageFileFormatTypeToString(= backingData->diskSrc->format), + "-b", + data->parentDiskSrc->path, + backingData->diskSrc->path, + NULL))) + continue; + + virCommandSetUID(cmd, backingData->uid); + virCommandSetGID(cmd, backingData->gid); + + ignore_value(virCommandRun(cmd, NULL)); + } +} + + static int qemuSnapshotDiscardExternal(virDomainObj *vm, virDomainMomentObj *snap, @@ -3215,6 +3335,8 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, =20 qemuBlockJobSyncEnd(vm, data->job, VIR_ASYNC_JOB_SNAPSHOT); =20 + qemuSnapshotUpdateBackingStore(vm, data); + if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, f= alse) < 0) goto error; } --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005833; cv=none; d=zohomail.com; s=zohoarc; b=NpTYZ1eFiAGdNQxM8WgFqZdthw+s3ToRAV+iOpO1fQM1ITVvd8t5WGFDV4vROOS2xqdQdaE12ipEg4+B6xRCQJFif8UHLKiPJ4PuKxmsYQyVp8gV7baWLbr3v94x3Ulxb66jhsCWlIyuZ/kCGQ67MKWRlOimmhvNo6a+XGiV4DM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005833; h=Content-Type:Content-Transfer-Encoding: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=g9GK7uhZQj58KdiTXtsHVE8pbLm7TSXGFXtb2gIIfM4=; b=f6J6vRWGoRFMGpwm84k+3e2p1xe4nTcDYtYqACS9TU0T7aru1mn2iSzHzzU+swhzMB4zXHHxuhwBWYw/LnRNCWpbY1dSMxQ80sxjMoNtIzV3E8QR+fPv4ZbbUEpDcvT7ULpUa+gSwGzZoWA5rxwwWAVtIV8STM/yBWPXJSxh6DU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 169200583324690.02809063474797; Mon, 14 Aug 2023 02:37:13 -0700 (PDT) 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-176-pAOKMudTPp6NWjl38qE9Mw-1; Mon, 14 Aug 2023 05:37:08 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D495B8057AA; Mon, 14 Aug 2023 09:37:04 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1042C16023; Mon, 14 Aug 2023 09:37:04 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D902219452D0; Mon, 14 Aug 2023 09:36:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B8C94194658F for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B668840B4CD1; Mon, 14 Aug 2023 09:36:32 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A0C440B4CD0 for ; Mon, 14 Aug 2023 09:36:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005832; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=g9GK7uhZQj58KdiTXtsHVE8pbLm7TSXGFXtb2gIIfM4=; b=SuugIkEFX5dDD09oDy257lJdgE3JP9wTRawhxxDNne0dhVRqhf6UKShz9ucquSprdlHjYG AIY2k8TnhiTGuJVWWRg9uTnVFm/mubSdLNxZJ0QLQ+zHVi9gRprOmyZusNY49tAnTXcfzM zQzahBvoz56wRYxTfAdeoJSqeS95sP4= X-MC-Unique: pAOKMudTPp6NWjl38qE9Mw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 23/25] qemu_snapshot: check only once if snapshot is external Date: Mon, 14 Aug 2023 11:36:15 +0200 Message-ID: <8e908a497b9e35e9778da3a4557276c6c48ab48f.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005834605100003 Content-Type: text/plain; charset="utf-8"; x-default="true" There will be more external snapshot checks introduced by following patch so group them together. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 8d0581d33b..dca95b415b 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -3728,18 +3728,18 @@ qemuSnapshotDeleteValidate(virDomainObj *vm, } } =20 - if (virDomainSnapshotIsExternal(snap) && - qemuDomainHasBlockjob(vm, false)) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("cannot delete external snapshots when there is a= nother active block job")); - return -1; - } + if (virDomainSnapshotIsExternal(snap)) { + if (qemuDomainHasBlockjob(vm, false)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot delete external snapshots when there = is another active block job")); + return -1; + } =20 - if (virDomainSnapshotIsExternal(snap) && - (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("deletion of external disk snapshots with childre= n not supported")); - return -1; + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("deletion of external disk snapshots with chi= ldren not supported")); + return -1; + } } =20 return 0; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005915; cv=none; d=zohomail.com; s=zohoarc; b=ZbgIS6h9ODt/Hg13SQAwRSi1HdA8urHew/s9YYl81uIO1wXudiBbpwFvKpxH4E9YwMwAoYjj6yz6oAZko72tsgwOamUKRLtJwrtknRfIKJffsG3yc27SFEh76fOf24ERAvYdM0AWJ3l04xF2nW4F1aErBdSi/a8XefxDtg4u2SQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005915; h=Content-Type:Content-Transfer-Encoding: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=dgmm9SHpu+XCkGvUDiqGnrZzdoO6ahrJXkn6dk9ZwAc=; b=UVpnNI2xR3sS1hFmdKK3+ZeZbT4IaYDAcIiGu23nYKefOEE0hxjBCHX69Wv4ssYGnMnTV4wCNxeSwD1jt33+Ugklc8J0aVjcv45IPtBYAzPlRaJBKPl53DFXDOVoqqJF+79w1ragOQBxioXwPAtVmVZ6Otex8I6kfCZl+eQ7FyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005915111905.7731364109213; Mon, 14 Aug 2023 02:38:35 -0700 (PDT) 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-624-9yb7ef2DPnKdABFqrCDQ0A-1; Mon, 14 Aug 2023 05:36:46 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CA732187585F; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 452E8C15BAD; Mon, 14 Aug 2023 09:36:42 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EED151946A4C; Mon, 14 Aug 2023 09:36:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BB8FB19465B7 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 58DB540B4CD2; Mon, 14 Aug 2023 09:36:33 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF82C40B4CD0 for ; Mon, 14 Aug 2023 09:36:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005914; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dgmm9SHpu+XCkGvUDiqGnrZzdoO6ahrJXkn6dk9ZwAc=; b=IwTFmEooD1zVniIlrSgDsOaWJgESplqhfi2FVESvJAl1Xsemy/PquGLfAanKHsxmo2F/KZ E/LSgQt1gNaWYX11sBa+LfrH2Ck00VG1T0mDEFmgybrTzpPQieijl5Z++AK3QiM55nMq0q fPzgitsKV8V2+v+3qpiEfp93ZJ44mUw= X-MC-Unique: 9yb7ef2DPnKdABFqrCDQ0A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 24/25] qemu_snapshot: add checks for external snapshot deletion Date: Mon, 14 Aug 2023 11:36:16 +0200 Message-ID: <618d0131a78df4a224983915028762897870113d.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005916441100001 Content-Type: text/plain; charset="utf-8"; x-default="true" With the introduction of external snapshot revert support we need to error out in some cases when trying to delete some snapshots. If users reverts to non-leaf snapshots and would try to delete it after the revert is done it would not work currently as this operation would require using block-stream which is not implemented for now as in this case the snapshot has two children so the disk files have multiple overlays. Similarly if user reverts to non-leaf snapshot and would try to delete snapshot that is non-leaf but not in currently active snapshot chain we would still need to use block-commit operation. The issue here is that in order to do that we would have to start new qemu process with different domain definition than what is currently used by the domain. If the current domain would be running it would complicate things even more so this operation is not yet supported. If user creates new snapshot after reverting to non-leaf snapshot it creates a new branch. Deleting snapshot with multiple children will require block-stream which is not implemented for now. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index dca95b415b..692d88e24d 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -3729,6 +3729,8 @@ qemuSnapshotDeleteValidate(virDomainObj *vm, } =20 if (virDomainSnapshotIsExternal(snap)) { + virDomainMomentObj *current =3D virDomainSnapshotGetCurrent(vm->sn= apshots); + if (qemuDomainHasBlockjob(vm, false)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot delete external snapshots when there = is another active block job")); @@ -3740,6 +3742,25 @@ qemuSnapshotDeleteValidate(virDomainObj *vm, _("deletion of external disk snapshots with chi= ldren not supported")); return -1; } + + if (snap =3D=3D current && snap->nchildren !=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("deletion of active external snapshot that is= not a leaf snapshot is not supported")); + return -1; + } + + if (snap !=3D current && snap->nchildren !=3D 0 && + virDomainMomentIsAncestor(snap, current)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("deletion of non-leaf external snapshot that = is not in active chain is not supported")); + return -1; + } + + if (snap->nchildren > 1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("deletion of external disk snapshot with mult= iple children snapshots not supported")); + return -1; + } } =20 return 0; --=20 2.41.0 From nobody Sat May 18 01:57:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692005886; cv=none; d=zohomail.com; s=zohoarc; b=RGD/qCN5fmJOLd6P7TFcTb1EdEUX/HDK4UQD3KbWiuzVbEdU431pGpJ/ABz/LJYbubgaqJczPQCIitX6jaxjKzbBnvZQwgzRBtY7hXnT8CFdt+uhGqnuVyZacWx+nncx2xpZtIKUMZDlKa1FVBJF3hcOzRY1p2h/2LxjGtRznew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005886; h=Content-Type:Content-Transfer-Encoding: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=Z4pb2bE4f5E9ySWMjXkWTx6z2l9YnP7NzDtrfc9olNk=; b=gqCWdVN5UYghdtBYQb40ksbY8i1SRoeFRIezMEegLC6GfbMEwrZ9feco7zkPoYGFm6Jz3QODT0EbqF4bH+Tr88/O74i4GeBYT7//vRwC7Jtrh865CjtctwWqhGrGsJ5AQb9vtj+sJrRlMRrWKzmcfbwM/ZOF6HrbbL5yukj/G3w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005886878390.7136563510554; Mon, 14 Aug 2023 02:38:06 -0700 (PDT) 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-515-PBX2LL3FP42lFptTi0AGKw-1; Mon, 14 Aug 2023 05:37:09 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 84F1380CC35; Mon, 14 Aug 2023 09:37:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CE94C16029; Mon, 14 Aug 2023 09:37:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6F99E19451D1; Mon, 14 Aug 2023 09:36:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A1B5F19465B6 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EF4E440B4CD3; Mon, 14 Aug 2023 09:36:33 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91C8C40B4CD0 for ; Mon, 14 Aug 2023 09:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005885; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Z4pb2bE4f5E9ySWMjXkWTx6z2l9YnP7NzDtrfc9olNk=; b=YryW6sKersYu8vmMbayvMcYAFYrJvSoaghZ/j5J2Cz2NjAjI2eGRKC1kkKTWbn1205qRbN HhT9HDhQ0XavtSpqaPa0iSvRs8R+sIEbvvrp4PUe0xqlEiOqZj+wQokpqRmyXURougYnYT H+zvB6PyXusgbE4knFf8Sb1Mlti712M= X-MC-Unique: PBX2LL3FP42lFptTi0AGKw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 25/25] qemu_snapshot: allow snapshot revert for external snapshots Date: Mon, 14 Aug 2023 11:36:17 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005888295100005 Content-Type: text/plain; charset="utf-8"; x-default="true" Now that the support to revert external snapshots is implemented we can drop this check. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 692d88e24d..d943281e35 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1892,12 +1892,6 @@ qemuSnapshotRevertValidate(virDomainObj *vm, return -1; } =20 - if (virDomainSnapshotIsExternal(snap)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("revert to external snapshot not supported yet")); - return -1; - } - if (!snap->def->dom) { virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, _("snapshot '%1$s' lacks domain '%2$s' rollback inf= o"), --=20 2.41.0