From nobody Mon Feb 9 06:05:29 2026 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=1638452263; cv=none; d=zohomail.com; s=zohoarc; b=VNRPozr+6gBeTXPCPoIrIE0Cggio9ycDo+rvo2cufCu7wUtKk9xr8bP5TPlPpR4wE8fio2IzNmFZgoPVSBeAhi4XbCPFnLklALqhVhkKjZsBMZ9PKXGqk50fEawgbhpLckcmjgVlS6AIR8UaluWZD1SU3gypo1tqwVWRBorkr9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638452263; 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=aZSwn0+30Ev+CAIYh+NsHwiS8CtpdYSC8imv/Xw1/UE=; b=HPGB83E4pdCnE/PtYki2z+8DocSy6vEbqU79soqCP7oe97A4fgeG+tGPFS8GYzaFIkgsrkI/kb0Yev/qwXRpBdQKNyNHAsrSy8Ip9GezB1vNoxeSr2fIvwpODONeBoaGEzdQBjfCbuLclzfdkZxneoyLOj+eZVodUvkR8Dz66w4= 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 163845226345774.82198237919488; Thu, 2 Dec 2021 05:37:43 -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-375-gGbxmJ50OsW2BxD7YDYYtg-1; Thu, 02 Dec 2021 08:37:40 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AC9201023F53; Thu, 2 Dec 2021 13:37:35 +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 8EE611000051; Thu, 2 Dec 2021 13:37:35 +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 5D7011809C89; Thu, 2 Dec 2021 13:37:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2DXSqS021031 for ; Thu, 2 Dec 2021 08:33:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5DB145D9CA; Thu, 2 Dec 2021 13:33:28 +0000 (UTC) Received: from antique-work.lan (unknown [10.40.192.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id D032818371 for ; Thu, 2 Dec 2021 13:33:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638452262; 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=aZSwn0+30Ev+CAIYh+NsHwiS8CtpdYSC8imv/Xw1/UE=; b=bL0qn1DZyg13HQ60aG67+PTAT3V4yAXCEli8dlnPgy+1ZJzYhHbzemaDu9NvwjohN04gPE xxiwBZf0Bw8epoU4fO/i7vhDcJBVmHrkny3eEMbIQwCCj7kOl/j7Ye25FzSDV7ozlaNuoy rOYNZALGeVoaJK/kbnkBgtssV4iUKhY= X-MC-Unique: gGbxmJ50OsW2BxD7YDYYtg-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 06/14] qemu_snapshot: revert: move validation to separate function Date: Thu, 2 Dec 2021 14:33:13 +0100 Message-Id: <1782615665359a8c2698e5a2856deccc0c37ac18.1638451855.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.84 on 10.5.11.22 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: 1638452265003100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 78 ++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index beeb012431..cc219f8b64 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1897,6 +1897,49 @@ qemuSnapshotCreateXML(virDomainPtr domain, } =20 =20 +static int +qemuSnapshotRevertValidate(virDomainObj *vm, + virDomainMomentObj *snap, + virDomainSnapshotDef *snapdef, + unsigned int flags) +{ + if (!vm->persistent && + snapdef->state !=3D VIR_DOMAIN_SNAPSHOT_RUNNING && + snapdef->state !=3D VIR_DOMAIN_SNAPSHOT_PAUSED && + (flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | + VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) =3D=3D 0) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("transient domain needs to request run or pause t= o revert to inactive snapshot")); + return -1; + } + + 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 '%s' lacks domain '%s' rollback info"), + snap->def->name, vm->def->name); + return -1; + } + + if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) { + if (vm->hasManagedSave && + !(snapdef->state =3D=3D VIR_DOMAIN_SNAPSHOT_RUNNING || + snapdef->state =3D=3D VIR_DOMAIN_SNAPSHOT_PAUSED)) { + virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s", + _("snapshot without memory state, removal of ex= isting managed saved state strongly recommended to avoid corruption")); + return -1; + } + } + + return 0; +} + + /* The domain is expected to be locked and inactive. */ static int qemuSnapshotRevertInactive(virQEMUDriver *driver, @@ -1979,41 +2022,8 @@ qemuSnapshotRevert(virDomainObj *vm, goto endjob; snapdef =3D virDomainSnapshotObjGetDef(snap); =20 - if (!vm->persistent && - snapdef->state !=3D VIR_DOMAIN_SNAPSHOT_RUNNING && - snapdef->state !=3D VIR_DOMAIN_SNAPSHOT_PAUSED && - (flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | - VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) =3D=3D 0) { - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("transient domain needs to request run or pause " - "to revert to inactive snapshot")); + if (qemuSnapshotRevertValidate(vm, snap, snapdef, flags) < 0) goto endjob; - } - - if (virDomainSnapshotIsExternal(snap)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("revert to external snapshot not supported yet")); - goto endjob; - } - - if (!snap->def->dom) { - virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, - _("snapshot '%s' lacks domain '%s' rollback info"), - snap->def->name, vm->def->name); - goto endjob; - } - - if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) { - if (vm->hasManagedSave && - !(snapdef->state =3D=3D VIR_DOMAIN_SNAPSHOT_RUNNING || - snapdef->state =3D=3D VIR_DOMAIN_SNAPSHOT_PAUSED)) { - virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s", - _("snapshot without memory state, removal of " - "existing managed saved state strongly " - "recommended to avoid corruption")); - goto endjob; - } - } =20 config =3D virDomainDefCopy(snap->def->dom, driver->xmlopt, priv->qemuCaps, true); --=20 2.31.1