From nobody Sat May 11 06:02:48 2024 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=1631885018; cv=none; d=zohomail.com; s=zohoarc; b=ms1ZT5WJIU7LTvL8G2gcHmcAaVFac0ASdGoxjZGr7cIe+yFxR1pV1M81TgSajtKtM4a+CEF3TqLNlZC+yWwXc/3xWdjTif3oItoXpv1LqeIK+oUIWH+CD+mM2WMIjCKyTneQKg7PFa9KiguqcsNEVox/P+l2VpyhIZimIjPvRSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631885018; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=WSBvkh0pLzNRwYTj2JEXiVBTn9NIdgSh/Z+x6yIB8gw=; b=NCQTJcg3BUs59hTfAYvxxnltiIhlvjxLLKuIvzvpyDnZzaQIRRRx2TFT3CEloVLG6/IUMrGxwYPjkbUxL2Kx+Y59gQZ8vXP/NwZzNwevniOF6dP+thCUddO3awFsAVrupVCzRRQ3oktyWC0B8cUe13QX519Q9lGttjJtNGGjHAk= 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 1631885018288721.2313432875162; Fri, 17 Sep 2021 06:23:38 -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-482-DxfS19pEP3Sqr4r4SEpYEA-1; Fri, 17 Sep 2021 09:23:35 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 49CEA84A5E0; Fri, 17 Sep 2021 13:23:30 +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 9F07018B5E; Fri, 17 Sep 2021 13:23:29 +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 913A04EA2A; Fri, 17 Sep 2021 13:23:27 +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 18HDNQ5X013205 for ; Fri, 17 Sep 2021 09:23:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C32E5D9FC; Fri, 17 Sep 2021 13:23:26 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA6E85D9C6 for ; Fri, 17 Sep 2021 13:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631885017; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=WSBvkh0pLzNRwYTj2JEXiVBTn9NIdgSh/Z+x6yIB8gw=; b=iaxRPl1L2HZuwVCUfbs2+nC3SFQmXbvDlxLDxz0pNNLjv700TsCKCCpLjJfX0R0obMkZfE K8UwxpV9dZAPofc1blynpeekEEePboAehwU4oso8YQB5q2XnngygqrUsu92VI1uWD5y6px pIk5LtZu2bV0j0tMgP8uf3+p/l/znlw= X-MC-Unique: DxfS19pEP3Sqr4r4SEpYEA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH] tools: virsh-snapshot: refactor small functions Date: Fri, 17 Sep 2021 15:23:17 +0200 Message-Id: <4967fc94b438a43062af0f3357e1cbd6f1220f94.1631884795.git.khanicov@redhat.com> 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.79 on 10.5.11.11 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: 1631885018736100001 Content-Type: text/plain; charset="utf-8" This patch includes: * removal of dead code * simplifying nested if conditions * removal of unnecessary variables * usage of "direct" boolean return Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-snapshot.c | 43 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 2659b4340d..3bdad03df0 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -771,7 +771,6 @@ virshSnapshotFilter(vshControl *ctl, virDomainSnapshotP= tr snapshot, g_autofree char *xml =3D NULL; g_autoptr(xmlDoc) xmldoc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; - int ret =3D -1; g_autofree char *state =3D NULL; =20 if (!snapshot) @@ -796,20 +795,17 @@ virshSnapshotFilter(vshControl *ctl, virDomainSnapsho= tPtr snapshot, return -1; } if (STREQ(state, "disk-snapshot")) { - ret =3D ((flags & (VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY | - VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL)) =3D=3D - (VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY | - VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL)); - } else { - if (!(flags & VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL)) - ret =3D 0; - else if (STREQ(state, "shutoff")) - ret =3D !!(flags & VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE); - else - ret =3D !!(flags & VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE); + return ((flags & (VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY | + VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL)) =3D=3D + (VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY | + VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL)); } =20 - return ret; + if (!(flags & VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL)) + return 0; + if (STREQ(state, "shutoff")) + return !!(flags & VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE); + return !!(flags & VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE); } =20 /* @@ -869,14 +865,8 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) * attempt a fallback. */ current =3D virDomainSnapshotIsCurrent(snapshot, 0); if (current < 0) { - g_autoptr(virshDomainSnapshot) other =3D NULL; - vshResetLibvirtError(); current =3D 0; - if (other) { - if (STREQ(name, virDomainSnapshotGetName(other))) - current =3D 1; - } } vshPrint(ctl, "%-15s %s\n", _("Current:"), current > 0 ? _("yes") : _("no")); @@ -1776,10 +1766,8 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCm= d *cmd) vshResetLibvirtError(); result =3D virDomainRevertToSnapshot(snapshot, flags); } - if (result < 0) - return false; =20 - return true; + return result >=3D 0; } =20 /* @@ -1844,16 +1832,15 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cm= d) /* XXX If we wanted, we could emulate DELETE_CHILDREN_ONLY even on * older servers that reject the flag, by manually computing the * list of descendants. But that's a lot of code to maintain. */ - if (virDomainSnapshotDelete(snapshot, flags) =3D=3D 0) { - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) - vshPrintExtra(ctl, _("Domain snapshot %s children deleted\n"),= name); - else - vshPrintExtra(ctl, _("Domain snapshot %s deleted\n"), name); - } else { + if (virDomainSnapshotDelete(snapshot, flags) < 0) { vshError(ctl, _("Failed to delete snapshot %s"), name); return false; } =20 + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) + vshPrintExtra(ctl, _("Domain snapshot %s children deleted\n"), nam= e); + else + vshPrintExtra(ctl, _("Domain snapshot %s deleted\n"), name); return true; } =20 --=20 2.31.1