From nobody Fri Dec 19 17:04:49 2025 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=1678722250; cv=none; d=zohomail.com; s=zohoarc; b=Rs03As7yCvYjHOhFMrROXMEciDgjslAobSuAny7Heq8Y4XXK8tNbQBa7R3JVlJtqUgexQHVHt5fnZ5SVv8/Zaxoq4/LpZWH9lZhnEFMCX1tsxhYxreXp6pNOjK6KrxsUfFHoyCPAvKjrDfTMFqYXuTdVaTTEcY2ryqNLzAjLyso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678722250; 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=/eXxx6G9qCc+cTrukkhYokwhRpbRDfW648MRm6+idY8=; b=XX7qUyN4y/Kp/FVyOIiraaizKAb0TSux21Hwnetw3fIByWxOKRZDc8KDWK/sxvGcsit3S/v2vwvIqw81oDehvpR3NX10V1/Aqpst3m0n5LpOi5n5oTBbkpWoVAC4zbZRQSfaNrCZSqD3FRyctIxtNxBM7i3YKqAFf1NoxIcoJNA= 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 1678722250365622.6534534315706; Mon, 13 Mar 2023 08:44:10 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-382-o2h1IDDxOBiuhJKWvPwroQ-1; Mon, 13 Mar 2023 11:42:57 -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 983D01C09075; Mon, 13 Mar 2023 15:42:33 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8584B1410F1B; Mon, 13 Mar 2023 15:42:33 +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 753AD1946594; Mon, 13 Mar 2023 15:42:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F11631946A4D for ; Mon, 13 Mar 2023 15:42:31 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E44B42166B26; Mon, 13 Mar 2023 15:42:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.45.226.242]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86FF52166B2C for ; Mon, 13 Mar 2023 15:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678722248; 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=/eXxx6G9qCc+cTrukkhYokwhRpbRDfW648MRm6+idY8=; b=Bd+j/p7N4NwsPG8FZzhaLUcxlZP28g7EBdlaci2Vo/Yqmi3UocLk3lHCXRiLR66J478tWF anX+RjKnGNO4n9JG++2cZzy15H28YNd1qTIZ7HT8xH1jsT3E+whPrO/4vwMKTxgbQ9dYh1 b3E7tpQxmrhMZCulTYBv6G7ob3ooWu0= X-MC-Unique: o2h1IDDxOBiuhJKWvPwroQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 07/20] qemu_snapshot: introduce qemuSnapshotCreateQcow2Files Date: Mon, 13 Mar 2023 16:42:08 +0100 Message-Id: <4bd61088ecf8d8b0e7f2bfa6c23fc7a719c1d055.1678718987.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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: 1678722251508100001 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 --- src/qemu/qemu_snapshot.c | 67 +++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index bbef753db6..06ed20c815 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -181,35 +181,21 @@ qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef, } =20 =20 -/* 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) +qemuSnapshotCreateQcow2Files(virDomainObj *vm, + virDomainSnapshotDef *snapdef, + virBitmap *created, + bool reuse) { 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 @@ -218,6 +204,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *drive= r, 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 +212,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 +221,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 +238,39 @@ 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 (qemuSnapshotCreateQcow2Files(vm, snapdef, created, reuse) < 0) + goto cleanup; + /* update disk definitions */ if (qemuSnapshotDomainDefUpdateDisk(vm->def, snapdef, reuse) < 0) goto cleanup; --=20 2.39.2