From nobody Tue Oct 22 22:20:44 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 --- 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