From nobody Sun Feb 8 11:22:09 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=1628617626; cv=none; d=zohomail.com; s=zohoarc; b=WERj9U5MEscb7yR73Wjl8lClsGzRPNG0mkTJWKrdrbkZOB3KhRF4ymCtxzySs1jkz4KjfnPaOBS1FfRy8d6FaFhXp5xXH6N23ERq9bEqg7jqWn8eZhtpno6MGGtQwSXYO6WZT0pFeDto4JS70Z3h/Z1r2N2vVcpkRSGs+QZ7l24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628617626; 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=eW2nz8dsc7/jlse07mZfAvDXyzPLvYJuiQxDrvVcRVY=; b=SHrEZaJF2S+yMyoJK8qwnHy8pMJ+D2IbFTchBtkZQv+6A87crEy9peO07H/AtPfocBiTBrypyB7KHBZqNtm22+OPmm4CXoUWu0pruib1Wj79HrPKtYwmOU2mxXaSjfUj7wijZoXE92kBN4V350Uq78rOsRr6xiwzULKdy/Yydok= 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 1628617626899359.31023362788187; Tue, 10 Aug 2021 10:47:06 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-142-9I8U-naFN1y6-ZHj8P-pKw-1; Tue, 10 Aug 2021 13:45:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CAEB802937; Tue, 10 Aug 2021 17:45:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB65A5D6A8; Tue, 10 Aug 2021 17:45:36 +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 B710A4A70F; Tue, 10 Aug 2021 17:45:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17AHjQT2025785 for ; Tue, 10 Aug 2021 13:45:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8546620DE; Tue, 10 Aug 2021 17:45:26 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 516646E0B7 for ; Tue, 10 Aug 2021 17:45:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628617625; 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=eW2nz8dsc7/jlse07mZfAvDXyzPLvYJuiQxDrvVcRVY=; b=bXM1dCA7orGAqyW/vEFJfGJz/qiTTdOCE3ql1KfUlyiBg79fpJJV1DCGLvw+1c3lznMK4c FE6+vh5Y45ljIzdQzixMsMKOnOTZg9Z+ukag49xpY4+oCS8yN5UxO3HRjCRMuFoK9BIh7o qxVLyL9yBbUit+6sCOdXkjiMVoeOiWs= X-MC-Unique: 9I8U-naFN1y6-ZHj8P-pKw-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 10/10] virsh: snapshot: remove pointless cleanup labels Date: Tue, 10 Aug 2021 19:45:09 +0200 Message-Id: <5d8beecb3ea8411f78e271db21c03b276366525c.1628617414.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.15 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628617628406100003 Signed-off-by: J=C3=A1n Tomko --- tools/virsh-snapshot.c | 130 +++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 84 deletions(-) diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 889959640d..ee99d0e061 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -41,7 +41,6 @@ static bool virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, unsigned int flags, const char *from) { - bool ret =3D false; g_autoptr(virshDomainSnapshot) snapshot =3D NULL; bool halt =3D false; const char *name =3D NULL; @@ -64,12 +63,12 @@ virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, = const char *buffer, persistent =3D virDomainIsPersistent(dom); if (persistent < 0) { vshReportError(ctl); - goto cleanup; + return false; } if (!persistent) { vshError(ctl, "%s", _("cannot halt after snapshot of transient domain")); - goto cleanup; + return false; } if (virDomainIsActive(dom) =3D=3D 1) halt =3D true; @@ -78,17 +77,17 @@ virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, = const char *buffer, } =20 if (snapshot =3D=3D NULL) - goto cleanup; + return false; =20 if (halt && virDomainDestroy(dom) < 0) { vshReportError(ctl); - goto cleanup; + return false; } =20 name =3D virDomainSnapshotGetName(snapshot); if (!name) { vshError(ctl, "%s", _("Could not get snapshot name")); - goto cleanup; + return false; } =20 if (from) @@ -96,10 +95,7 @@ virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, c= onst char *buffer, else vshPrintExtra(ctl, _("Domain snapshot %s created"), name); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -162,7 +158,6 @@ static bool cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; const char *from =3D NULL; g_autofree char *buffer =3D NULL; unsigned int flags =3D 0; @@ -189,23 +184,20 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_SNAPSHOT_CREATE_VALIDATE; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; =20 if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0) - goto cleanup; + return false; if (!from) { buffer =3D g_strdup(""); } else { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshSaveLibvirtError(); - goto cleanup; + return false; } } =20 - ret =3D virshSnapshotCreate(ctl, dom, buffer, flags, from); - - cleanup: - return ret; + return virshSnapshotCreate(ctl, dom, buffer, flags, from); } =20 /* @@ -386,7 +378,6 @@ static bool cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; g_autofree char *buffer =3D NULL; const char *name =3D NULL; const char *desc =3D NULL; @@ -417,7 +408,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) =20 if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0 || vshCommandOptStringReq(ctl, cmd, "description", &desc) < 0) - goto cleanup; + return false; =20 virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); @@ -425,17 +416,17 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cm= d) virBufferEscapeString(&buf, "%s\n", desc); =20 if (vshCommandOptStringReq(ctl, cmd, "memspec", &memspec) < 0) - goto cleanup; + return false; =20 if (memspec && virshParseSnapshotMemspec(ctl, &buf, memspec) < 0) - goto cleanup; + return false; =20 if (vshCommandOptBool(cmd, "diskspec")) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { if (virshParseSnapshotDiskspec(ctl, &buf, opt->data) < 0) - goto cleanup; + return false; } virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); @@ -447,14 +438,10 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cm= d) =20 if (vshCommandOptBool(cmd, "print-xml")) { vshPrint(ctl, "%s\n", buffer); - ret =3D true; - goto cleanup; + return true; } =20 - ret =3D virshSnapshotCreate(ctl, dom, buffer, flags, NULL); - - cleanup: - return ret; + return virshSnapshotCreate(ctl, dom, buffer, flags, NULL); } =20 /* Helper for resolving {--current | --ARG name} into a snapshot @@ -789,11 +776,11 @@ virshSnapshotFilter(vshControl *ctl, virDomainSnapsho= tPtr snapshot, =20 xml =3D virDomainSnapshotGetXMLDesc(snapshot, 0); if (!xml) - goto cleanup; + return -1; =20 xmldoc =3D virXMLParseStringCtxt(xml, _("(domain_snapshot)"), &ctxt); if (!xmldoc) - goto cleanup; + return -1; =20 /* Libvirt 1.0.1 and newer never call this function, because the * filtering is already supported by the listing functions. Older @@ -803,7 +790,7 @@ virshSnapshotFilter(vshControl *ctl, virDomainSnapshotP= tr snapshot, state =3D virXPathString("string(/domainsnapshot/state)", ctxt); if (!state) { vshError(ctl, "%s", _("unable to perform snapshot filtering")); - goto cleanup; + return -1; } if (STREQ(state, "disk-snapshot")) { ret =3D ((flags & (VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY | @@ -819,7 +806,6 @@ virshSnapshotFilter(vshControl *ctl, virDomainSnapshotP= tr snapshot, ret =3D !!(flags & VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE); } =20 - cleanup: return ret; } =20 @@ -859,7 +845,6 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) g_autofree char *state =3D NULL; int external; g_autofree char *parent =3D NULL; - bool ret =3D false; int count; unsigned int flags; int current; @@ -872,7 +857,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) =20 if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom, &snapshot, &name) < 0) - goto cleanup; + return false; =20 vshPrint(ctl, "%-15s %s\n", _("Name:"), name); vshPrint(ctl, "%-15s %s\n", _("Domain:"), virDomainGetName(dom)); @@ -897,17 +882,17 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) * state of the machine at the time of the snapshot. */ doc =3D virDomainSnapshotGetXMLDesc(snapshot, 0); if (!doc) - goto cleanup; + return false; =20 xmldoc =3D virXMLParseStringCtxt(doc, _("(domain_snapshot)"), &ctxt); if (!xmldoc) - goto cleanup; + return false; =20 state =3D virXPathString("string(/domainsnapshot/state)", ctxt); if (!state) { vshError(ctl, "%s", _("unexpected problem reading snapshot xml")); - goto cleanup; + return false; } vshPrint(ctl, "%-15s %s\n", _("State:"), state); =20 @@ -933,7 +918,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) if (external < 0) { vshError(ctl, "%s", _("unexpected problem reading snapshot xml")); - goto cleanup; + return false; } vshPrint(ctl, "%-15s %s\n", _("Location:"), external ? _("external") : _("internal")); @@ -946,24 +931,22 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) /* Children, Descendants. After this point, the fallback to * compute children is too expensive, so we gracefully quit if the * APIs don't exist. */ - if (priv->useSnapshotOld) { - ret =3D true; - goto cleanup; - } + if (priv->useSnapshotOld) + return true; flags =3D 0; count =3D virDomainSnapshotNumChildren(snapshot, flags); if (count < 0) { if (last_error->code =3D=3D VIR_ERR_NO_SUPPORT) { vshResetLibvirtError(); - ret =3D true; + return true; } - goto cleanup; + return false; } vshPrint(ctl, "%-15s %d\n", _("Children:"), count); flags =3D VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS; count =3D virDomainSnapshotNumChildren(snapshot, flags); if (count < 0) - goto cleanup; + return false; vshPrint(ctl, "%-15s %d\n", _("Descendants:"), count); =20 /* Metadata; the fallback here relies on the fact that metadata @@ -978,10 +961,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%-15s %s\n", _("Metadata:"), metadata ? _("yes") : _("no")); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* Helpers for collecting a list of snapshots. */ @@ -1644,7 +1624,6 @@ static bool cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; const char *name =3D NULL; g_autoptr(virshDomainSnapshot) snapshot =3D NULL; g_autofree char *xml =3D NULL; @@ -1660,16 +1639,13 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *c= md) return false; =20 if (!(snapshot =3D virDomainSnapshotLookupByName(dom, name, 0))) - goto cleanup; + return false; =20 if (!(xml =3D virDomainSnapshotGetXMLDesc(snapshot, flags))) - goto cleanup; + return false; =20 vshPrint(ctl, "%s", xml); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -1700,32 +1676,28 @@ static bool cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; const char *name =3D NULL; g_autoptr(virshDomainSnapshot) snapshot =3D NULL; g_autofree char *parent =3D NULL; =20 dom =3D virshCommandOptDomain(ctl, cmd, NULL); if (dom =3D=3D NULL) - goto cleanup; + return false; =20 if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom, &snapshot, &name) < 0) - goto cleanup; + return false; =20 if (virshGetSnapshotParent(ctl, snapshot, &parent) < 0) - goto cleanup; + return false; if (!parent) { vshError(ctl, _("snapshot '%s' has no parent"), name); - goto cleanup; + return false; } =20 vshPrint(ctl, "%s", parent); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -1768,7 +1740,6 @@ static bool cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; const char *name =3D NULL; g_autoptr(virshDomainSnapshot) snapshot =3D NULL; unsigned int flags =3D 0; @@ -1788,11 +1759,11 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshC= md *cmd) =20 dom =3D virshCommandOptDomain(ctl, cmd, NULL); if (dom =3D=3D NULL) - goto cleanup; + return false; =20 if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom, &snapshot, &name) < 0) - goto cleanup; + return false; =20 result =3D virDomainRevertToSnapshot(snapshot, flags); if (result < 0 && force && @@ -1802,13 +1773,9 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCm= d *cmd) result =3D virDomainRevertToSnapshot(snapshot, flags); } if (result < 0) - goto cleanup; + return false; =20 - ret =3D true; - - cleanup: - - return ret; + return true; } =20 /* @@ -1851,18 +1818,17 @@ static bool cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; const char *name =3D NULL; g_autoptr(virshDomainSnapshot) snapshot =3D NULL; unsigned int flags =3D 0; =20 dom =3D virshCommandOptDomain(ctl, cmd, NULL); if (dom =3D=3D NULL) - goto cleanup; + return false; =20 if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom, &snapshot, &name) < 0) - goto cleanup; + return false; =20 if (vshCommandOptBool(cmd, "children")) flags |=3D VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN; @@ -1881,14 +1847,10 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cm= d) vshPrintExtra(ctl, _("Domain snapshot %s deleted\n"), name); } else { vshError(ctl, _("Failed to delete snapshot %s"), name); - goto cleanup; + return false; } =20 - ret =3D true; - - cleanup: - - return ret; + return true; } =20 const vshCmdDef snapshotCmds[] =3D { --=20 2.31.1