From nobody Sun Feb 8 17:33:11 2026 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=1637839082; cv=none; d=zohomail.com; s=zohoarc; b=j5t/1FFELFag+069X7j+tEc5U0+sLN2vf9KO/BHremyPUKOjm6WslsR9ShxSrJOvUO2e9aP++dfuBWln+LWSxJN3AeggbNYRik/Gv1kr4FJ+P2jZ7HjXhCWpVQNKPT4a7pBLfloCvwWtOBK+U8NlivoD3ReVD4pQCZ9KeVjTei4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637839082; 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=cJSYr/8g0OAJoHjmC/Dqk+2uoJIPPwC2oevyuox0vh8=; b=cFc7VyEldeIP2v+2xV+DccRci/cM5gTOa28SMVLZxgVbr6Lg1y8qZgx1mQERKIvT6AH+Nh6bcN8DAZOiw3d9UeeuBdWHz2kpxTibzE7TE2VvGfSTtKtHiYfGcL1tVMvXS7qSWfPIiLRxPnoEFMn0tXROG3QVB4AnZmBcGoxaQas= 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 1637839082885607.39553327623; Thu, 25 Nov 2021 03:18:02 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-282-jeTXGP54P8CjJddY3FpJ7Q-1; Thu, 25 Nov 2021 06:16:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A225D83DB64; Thu, 25 Nov 2021 11:16:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8347A7945B; Thu, 25 Nov 2021 11:16:44 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 54AA81806D2C; Thu, 25 Nov 2021 11:16:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1APBGhB7022919 for ; Thu, 25 Nov 2021 06:16:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id B9B6B1042A90; Thu, 25 Nov 2021 11:16:43 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36A44104B4DE for ; Thu, 25 Nov 2021 11:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637839081; 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=cJSYr/8g0OAJoHjmC/Dqk+2uoJIPPwC2oevyuox0vh8=; b=VmD+ey2FZ6F8QWN2zU8TyBrvbKY5JMmBxmygZMIteBjv+9hvwgzlHciGVuU5e3UnpHG58n pQGHk62ZgSRZYwwpJ4MSRapHyNB3+pRyFIsfa8MEyrTJOzSM0z85cn0B3+Exsk0YTtSaqa vYsQIN5TWZ7F1SycK0IHyqyzL4PR/tg= X-MC-Unique: jeTXGP54P8CjJddY3FpJ7Q-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 10/11] qemu_snapshot: create: move snapshot create to separate function Date: Thu, 25 Nov 2021 12:16:16 +0100 Message-Id: <6a833135fd2b5514d14dbf2ddbd18d8e703015cf.1637838934.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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: 1637839084557100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 149 ++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 73 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index d22f0522ed..c5f0a5afe8 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1757,6 +1757,81 @@ qemuSnapshotRedefine(virDomainObj *vm, } =20 =20 +static virDomainSnapshotPtr +qemuSnapshotCreate(virDomainObj *vm, + virDomainPtr domain, + virDomainSnapshotDef *def, + virQEMUDriver *driver, + virQEMUDriverConfig *cfg, + unsigned int flags) +{ + + virDomainMomentObj *snap =3D NULL; + virDomainMomentObj *current =3D NULL; + virDomainSnapshotPtr ret =3D NULL; + + if (qemuSnapshotAlignDisks(vm, def, driver, flags) < 0) + return NULL; + + if (qemuSnapshotPrepare(vm, def, &flags) < 0) + return NULL; + + if (!(snap =3D virDomainSnapshotAssignDef(vm->snapshots, def))) + return NULL; + + virObjectRef(def); + + current =3D virDomainSnapshotGetCurrent(vm->snapshots); + if (current) { + snap->def->parent_name =3D g_strdup(current->def->name); + } + + /* actually do the snapshot */ + if (virDomainObjIsActive(vm)) { + if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY || + virDomainSnapshotObjGetDef(snap)->memory =3D=3D VIR_DOMAIN_SNA= PSHOT_LOCATION_EXTERNAL) { + /* external full system or disk snapshot */ + if (qemuSnapshotCreateActiveExternal(driver, vm, snap, cfg, fl= ags) < 0) + goto error; + } else { + /* internal full system */ + if (qemuSnapshotCreateActiveInternal(driver, vm, snap, flags) = < 0) + goto error; + } + } else { + /* inactive; qemuSnapshotPrepare guaranteed that we + * aren't mixing internal and external, and altered flags to + * contain DISK_ONLY if there is an external disk. */ + if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) { + bool reuse =3D !!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT= ); + + if (qemuSnapshotCreateInactiveExternal(driver, vm, snap, reuse= ) < 0) + goto error; + } else { + if (qemuSnapshotCreateInactiveInternal(driver, vm, snap) < 0) + goto error; + } + } + + if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)) { + qemuSnapshotSetCurrent(vm, snap); + + if (qemuSnapshotCreateWriteMetadata(vm, snap, driver, cfg) < 0) + goto error; + } + + ret =3D virGetDomainSnapshot(domain, snap->def->name); + if (!ret) + goto error; + + return ret; + + error: + virDomainSnapshotObjListRemove(vm->snapshots, snap); + return NULL; +} + + virDomainSnapshotPtr qemuSnapshotCreateXML(virDomainPtr domain, virDomainObj *vm, @@ -1764,7 +1839,6 @@ qemuSnapshotCreateXML(virDomainPtr domain, unsigned int flags) { virQEMUDriver *driver =3D domain->conn->privateData; - virDomainMomentObj *snap =3D NULL; virDomainSnapshotPtr snapshot =3D NULL; bool redefine =3D flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); @@ -1815,81 +1889,10 @@ qemuSnapshotCreateXML(virDomainPtr domain, =20 if (redefine) { snapshot =3D qemuSnapshotRedefine(vm, domain, def, driver, cfg, fl= ags); - goto endjob; } else { - virDomainMomentObj *current =3D NULL; - - if (qemuSnapshotAlignDisks(vm, def, driver, flags) < 0) - goto endjob; - - if (qemuSnapshotPrepare(vm, def, &flags) < 0) - goto endjob; - - if (!(snap =3D virDomainSnapshotAssignDef(vm->snapshots, def))) - goto endjob; - - def =3D NULL; - - current =3D virDomainSnapshotGetCurrent(vm->snapshots); - if (current) { - snap->def->parent_name =3D g_strdup(current->def->name); - } + snapshot =3D qemuSnapshotCreate(vm, domain, def, driver, cfg, flag= s); } =20 - /* actually do the snapshot */ - if (virDomainObjIsActive(vm)) { - if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY || - virDomainSnapshotObjGetDef(snap)->memory =3D=3D VIR_DOMAIN_SNA= PSHOT_LOCATION_EXTERNAL) { - /* external full system or disk snapshot */ - if (qemuSnapshotCreateActiveExternal(driver, vm, snap, cfg, fl= ags) < 0) - goto endjob; - } else { - /* internal full system */ - if (qemuSnapshotCreateActiveInternal(driver, vm, snap, flags) = < 0) - goto endjob; - } - } else { - /* inactive; qemuSnapshotPrepare guaranteed that we - * aren't mixing internal and external, and altered flags to - * contain DISK_ONLY if there is an external disk. */ - if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) { - bool reuse =3D !!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT= ); - - if (qemuSnapshotCreateInactiveExternal(driver, vm, snap, reuse= ) < 0) - goto endjob; - } else { - if (qemuSnapshotCreateInactiveInternal(driver, vm, snap) < 0) - goto endjob; - } - } - - /* If we fail after this point, there's not a whole lot we can - * do; we've successfully taken the snapshot, and we are now running - * on it, so we have to go forward the best we can - */ - if (!(snapshot =3D virGetDomainSnapshot(domain, snap->def->name))) - goto endjob; - - if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)) { - if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)) - qemuSnapshotSetCurrent(vm, snap); - - if (qemuSnapshotCreateWriteMetadata(vm, snap, driver, cfg) < 0) { - /* if writing of metadata fails, error out rather than trying - * to silently carry on without completing the snapshot */ - virObjectUnref(snapshot); - snapshot =3D NULL; - goto endjob; - } - - snap =3D NULL; - } - - endjob: - - if (snap) - virDomainSnapshotObjListRemove(vm->snapshots, snap); - qemuDomainObjEndAsyncJob(driver, vm); =20 return snapshot; --=20 2.31.1