From nobody Mon Feb 9 17:21:43 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=1632496790; cv=none; d=zohomail.com; s=zohoarc; b=WvRg9gmzV6Wt+WYnm6kaLAn7jVeDKZvzj9SjKtFmHEu1ZgPag90jYIGXZIo5QSRTGU//fkkftiPvJS/LZESWNyWyhAC9BNyG6CJE6xrHqvxqv+VNkuepYA7RUB3z9nbFjyMV2ca82S/HXq7G6ahaCGlWrSy5l2Z42tv4KHl6EoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632496790; 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=PWbTPeUrpZEROOfhe4b0Wt+rgthx5MAFpYIh5nqdRI8=; b=UTsoJv+mCUakKV6sHBggZOujC4FrpMkQU0I7lu0JqSxbSa0PY29q0L+KftPlmfIrq2VGQk5z+HXEUIxUh6v/qiw3NS/s2oMlZiPmaONtkghimOC3ksFz5UZ3Ojd6d77L2HEtvZgClPg2ju9VDrfwaJI5fJhRV3eDZ71LBSOUL6Y= 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 1632496790271450.3809756500043; Fri, 24 Sep 2021 08:19:50 -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-43-CgDP_QDZOIypGKHOGDlHtA-1; Fri, 24 Sep 2021 11:19:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8529610144E9; Fri, 24 Sep 2021 15:19:42 +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 658F760BF1; Fri, 24 Sep 2021 15:19:42 +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 1755A4EA2A; Fri, 24 Sep 2021 15:19:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18OFI3bM026567 for ; Fri, 24 Sep 2021 11:18:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id DDBA91803B; Fri, 24 Sep 2021 15:18:02 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DFAC177C0 for ; Fri, 24 Sep 2021 15:18:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632496789; 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=PWbTPeUrpZEROOfhe4b0Wt+rgthx5MAFpYIh5nqdRI8=; b=Z8lwTSRoGZxqQ1mVNK+Wws5Wz37o5dGIS8EJI7wdEXjdQDAhwb7JuFoQHJD4ri/5JUz8oz BTcHsoiXJS0mvSe6ObViK7LWySUmG/b/sBXohB8Rg4qmcPSdMf9Lt11ytiNq2njInPCvJN xEgPzhvJhLsMY1wTNmNNB/5rc+Cf9SM= X-MC-Unique: CgDP_QDZOIypGKHOGDlHtA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 1/7] virsh: domain: use early return in virshDomainDefine() Date: Fri, 24 Sep 2021 17:17:44 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.12 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: 1632496791819100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index bee3346eb0..edee548d8a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -245,18 +245,18 @@ static virDomainPtr virshDomainDefine(virConnectPtr conn, const char *xml, unsigned int flags) { virDomainPtr dom; - if (flags) { - dom =3D virDomainDefineXMLFlags(conn, xml, flags); - /* If validate is the only flag, just drop it and - * try again. - */ - if (!dom) { - if ((virGetLastErrorCode() =3D=3D VIR_ERR_NO_SUPPORT) && - (flags =3D=3D VIR_DOMAIN_DEFINE_VALIDATE)) - dom =3D virDomainDefineXML(conn, xml); - } - } else { - dom =3D virDomainDefineXML(conn, xml); + + if (!flags) + return virDomainDefineXML(conn, xml); + + dom =3D virDomainDefineXMLFlags(conn, xml, flags); + /* If validate is the only flag, just drop it and + * try again. + */ + if (!dom) { + if ((virGetLastErrorCode() =3D=3D VIR_ERR_NO_SUPPORT) && + (flags =3D=3D VIR_DOMAIN_DEFINE_VALIDATE)) + dom =3D virDomainDefineXML(conn, xml); } return dom; } --=20 2.31.1 From nobody Mon Feb 9 17:21:43 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=1632496799; cv=none; d=zohomail.com; s=zohoarc; b=MGkyePqgNDKtaljtSbaj8nwWJ+uGIdxx3XI9q+ZX/z4thiFfkguHr3UltWs4YCEMt93XjCr3ERVYAwzS/pjXvt0ToH9bUEBTjUc3Zjam0CNOcDrCPuaT+snfQLu1CM7pQ9J+9u902KxYaoH6Lw1T5jWknooUeR/LRsRTraK9Nns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632496799; 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=OXUIZcyZFK8XCvnpg0tSbcXMztPncHpFr+DTksw8NP8=; b=P72u/o4GrrBnN+j0NK7M1Ux1NW5YDFwSgB8nEkQB1y2NxeWleoIi/iQQa4Qg4+DuUSLIGulm3plSUMVALj1M5vHywHFYrbPmF0SWCwM3frN9KB1q3OZCu2u3T75nUTUo1sAMCbFoE2vsYmHaE71hnUNMJfgAdUArCc5ZuXO7YMU= 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 1632496799934172.39051681833735; Fri, 24 Sep 2021 08:19:59 -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-282-jz_s_KekNC-YqhWRESvQNg-1; Fri, 24 Sep 2021 11:19:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AAF4310846A0; Fri, 24 Sep 2021 15:19:47 +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 2D36E8547B; Fri, 24 Sep 2021 15:19:47 +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 DE58A4EA37; Fri, 24 Sep 2021 15:19:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18OFI4J8026574 for ; Fri, 24 Sep 2021 11:18:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id CA05D1B467; Fri, 24 Sep 2021 15:18:03 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 320BC177F1 for ; Fri, 24 Sep 2021 15:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632496799; 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=OXUIZcyZFK8XCvnpg0tSbcXMztPncHpFr+DTksw8NP8=; b=YeDoYXS1UPq+RhzLXmT+21/tlcNTL1UrG5YnkD++hPMU2kh7dq0jDNbC3v93kE5gfwki2l LCPnxBOF/c18nKY3it/Zu3ss1wCwiPI5zWNfydpS/RWRQ0wJg31CnQk7xLcFs8p3BuzxAR 7R4v8k8uyS9+JRnUsSBZqjrGdcDkwA4= X-MC-Unique: jz_s_KekNC-YqhWRESvQNg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 2/7] virsh: domain: remove nested 'if' in cmdAttachDisk() Date: Fri, 24 Sep 2021 17:17:45 +0200 Message-Id: <128d0626035366edaca66c2cc1736cd7d822ba61.1632495763.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.13 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: 1632496801941100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index edee548d8a..0d482f9e15 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -659,12 +659,9 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) return false; } =20 - if (mode) { - if (STRNEQ(mode, "readonly") && STRNEQ(mode, "shareable")) { - vshError(ctl, _("No support for %s in command 'attach-disk'"), - mode); - return false; - } + if (mode && STRNEQ(mode, "readonly") && STRNEQ(mode, "shareable")) { + vshError(ctl, _("No support for %s in command 'attach-disk'"), mod= e); + return false; } =20 if (wwn && !virValidateWWN(wwn)) --=20 2.31.1 From nobody Mon Feb 9 17:21:43 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=1632496887; cv=none; d=zohomail.com; s=zohoarc; b=m66VXRp3PSJtFpLfX3vjrRD2ly7tEfsEGp9t/aWfl5hQpasSJdTuyB5uJ3b2aC+GP3JM55d7j4nRQ+PCni3GTFaUOnL44oFEl+9EjpH8KXHSkFZZIlQEUBft4EwYl9InY731RmUxK7zvV8pQSMuHhJRDOU9KrXDmd2SNJqCTYS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632496887; 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=Z7SfBFGgU3/qox0M1qsFPx1VWeneNh8U9kUB+LRiC1M=; b=HyF6bnswvxVpcSlztpsR6EziZ0/lCuEky056tvE3EudK84t/YAeptUVdggAEb7IMXVaZKPr2rRWNeA0CxN035YY0Y5CIFcRqI/4eB/8YCJcpH/NevqmTX4r2d6eBTXWWM4t7vaTnnBe6HvcqT7FCdjJKXgCtBi8NF0Z7QBnyUKY= 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 16324968878341018.7537523883486; Fri, 24 Sep 2021 08:21:27 -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-16-Hv3WEgK5Ov2z4wJWve7bKw-1; Fri, 24 Sep 2021 11:21:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E05B104ECFC; Fri, 24 Sep 2021 15:21:20 +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 E2F205D9DD; Fri, 24 Sep 2021 15:21:19 +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 148941803B30; Fri, 24 Sep 2021 15:21:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18OFIDTO026594 for ; Fri, 24 Sep 2021 11:18:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3A8231800D; Fri, 24 Sep 2021 15:18:12 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 215FF177C0 for ; Fri, 24 Sep 2021 15:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632496886; 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=Z7SfBFGgU3/qox0M1qsFPx1VWeneNh8U9kUB+LRiC1M=; b=Dl72znGMDnc98ZuZ6+9VdUs5o+RkPd4/Eqqysr8Xso1xXJ/pgjXbmGgNRsn3T/kFzbAMGS tlnnaTai0eu0ANYGy3bGY8o9l2VdFZ2ujQBpXAwrLHLiwTzpAetftWo9VN2+mBmcvapFLJ JAuIu8lTxFggh+VBF6I+mvkqoUlHyWA= X-MC-Unique: Hv3WEgK5Ov2z4wJWve7bKw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 3/7] virsh: domain: remove 'ret' variable and use direct return when possible Date: Fri, 24 Sep 2021 17:17:46 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.14 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: 1632496888848100004 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 62 ++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0d482f9e15..1da9b183bf 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2702,7 +2702,6 @@ virshBlockJobAbort(virDomainPtr dom, static bool cmdBlockjob(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D false; bool raw =3D vshCommandOptBool(cmd, "raw"); bool bytes =3D vshCommandOptBool(cmd, "bytes"); bool abortMode =3D vshCommandOptBool(cmd, "abort"); @@ -2735,13 +2734,10 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd) return false; =20 if (bandwidth) - ret =3D virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes); - else if (abortMode || pivot || async) - ret =3D virshBlockJobAbort(dom, path, pivot, async); - else - ret =3D virshBlockJobInfo(ctl, dom, path, raw, bytes); - - return ret; + return virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes); + if (abortMode || pivot || async) + return virshBlockJobAbort(dom, path, pivot, async); + return virshBlockJobInfo(ctl, dom, path, raw, bytes); } =20 /* @@ -5063,7 +5059,6 @@ cmdSchedInfoUpdateOne(vshControl *ctl, const char *field, const char *value) { virTypedParameterPtr param; - int ret =3D -1; size_t i; =20 for (i =3D 0; i < nsrc_params; i++) { @@ -5078,14 +5073,11 @@ cmdSchedInfoUpdateOne(vshControl *ctl, vshSaveLibvirtError(); return -1; } - ret =3D 0; - break; + return 0; } =20 - if (ret < 0) - vshError(ctl, _("invalid scheduler option: %s"), field); - - return ret; + vshError(ctl, _("invalid scheduler option: %s"), field); + return -1; } =20 static int @@ -5529,7 +5521,6 @@ virshGenFileName(vshControl *ctl, virDomainPtr dom, c= onst char *mime) g_autoptr(GDateTime) now =3D g_date_time_new_now_local(); g_autofree char *nowstr =3D NULL; const char *ext =3D NULL; - char *ret =3D NULL; =20 if (!dom) { vshError(ctl, "%s", _("Invalid domain supplied")); @@ -5544,10 +5535,8 @@ virshGenFileName(vshControl *ctl, virDomainPtr dom, = const char *mime) =20 nowstr =3D g_date_time_format(now, "%Y-%m-%d-%H:%M:%S"); =20 - ret =3D g_strdup_printf("%s-%s%s", virDomainGetName(dom), - nowstr, NULLSTR_EMPTY(ext)); - - return ret; + return g_strdup_printf("%s-%s%s", virDomainGetName(dom), + nowstr, NULLSTR_EMPTY(ext)); } =20 static bool @@ -5686,7 +5675,6 @@ static bool cmdSetLifecycleAction(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); bool current =3D vshCommandOptBool(cmd, "current"); @@ -5727,10 +5715,9 @@ cmdSetLifecycleAction(vshControl *ctl, const vshCmd = *cmd) =20 if (virDomainSetLifecycleAction(dom, type, action, flags) < 0) { vshError(ctl, "%s", _("Unable to change lifecycle action.")); - ret =3D false; + return false; } - - return ret; + return true; } =20 /* @@ -6469,15 +6456,14 @@ static bool cmdDomjobabort(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 if (virDomainAbortJob(dom) < 0) - ret =3D false; + return false; =20 - return ret; + return true; } =20 /* @@ -11926,12 +11912,12 @@ virshDomainDetachInterface(char *doc, xmlNodePtr cur =3D NULL, matchNode =3D NULL; g_autofree char *detach_xml =3D NULL; char buf[64]; - int diff_mac, ret =3D -1; + int diff_mac =3D -1; size_t i; =20 if (!(xml =3D virXMLParseStringCtxt(doc, _("(domain_definition)"), &ct= xt))) { vshError(ctl, "%s", _("Failed to get interface information")); - goto cleanup; + return false; } =20 g_snprintf(buf, sizeof(buf), "/domain/devices/interface[@type=3D'%s']"= , type); @@ -11939,13 +11925,13 @@ virshDomainDetachInterface(char *doc, if (obj =3D=3D NULL || obj->type !=3D XPATH_NODESET || obj->nodesetval =3D=3D NULL || obj->nodesetval->nodeNr =3D=3D 0) { vshError(ctl, _("No interface found whose type is %s"), type); - goto cleanup; + return false; } =20 if (!mac && obj->nodesetval->nodeNr > 1) { vshError(ctl, _("Domain has %d interfaces. Please specify which on= e " "to detach using --mac"), obj->nodesetval->nodeNr); - goto cleanup; + return false; } =20 if (!mac) { @@ -11968,7 +11954,7 @@ virshDomainDetachInterface(char *doc, "MAC address %s. You must use deta= ch-device and " "specify the device pci address to= remove it."), mac); - goto cleanup; + return false; } matchNode =3D obj->nodesetval->nodeTab[i]; } @@ -11978,22 +11964,18 @@ virshDomainDetachInterface(char *doc, } if (!matchNode) { vshError(ctl, _("No interface with MAC address %s was found"), mac= ); - goto cleanup; + return false; } =20 hit: if (!(detach_xml =3D virXMLNodeToString(xml, matchNode))) { vshSaveLibvirtError(); - goto cleanup; + return false; } =20 if (flags !=3D 0 || current) - ret =3D virDomainDetachDeviceFlags(dom, detach_xml, flags); - else - ret =3D virDomainDetachDevice(dom, detach_xml); - - cleanup: - return ret =3D=3D 0; + return virDomainDetachDeviceFlags(dom, detach_xml, flags) =3D=3D 0; + return virDomainDetachDevice(dom, detach_xml) =3D=3D 0; } =20 =20 --=20 2.31.1 From nobody Mon Feb 9 17:21:43 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=1632496808; cv=none; d=zohomail.com; s=zohoarc; b=dWhcIrgvHezZ+djDVcexGo0DD2a5ZpFFPv0iUxj1j5dQl8kJlxm5cSYr4OjUCyzM14V6c7y+8EebdZcFOXfKCC4ySX1b3VHCTNpsQYns1BHdqG/nD0EH8t9rMilREjjdv+YYvkZ7YCYrdqJwjEiDJLVgjsODnK10nY8QiEs3smA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632496808; 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=t5n8lz043rTGQYRB5TfmsW+mXz2jDbkl4VkroO8NowI=; b=IsdRG/cewN5EVT8LDsYORZF9LYi11MhkBsDPXXj2340GJWX30mGm892RAY/qUMprs2hdlGaKXeDZZqv2PWqIK4Zxie4hONGDgODm7Yljwbu3UgVJgRNjv6KYBCmr6zIfWL9ig41fxmC15Qt0w9GMx5F/YBzhnXBunH52Js5uMTs= 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 1632496808584266.90001350958016; Fri, 24 Sep 2021 08:20:08 -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-510-ZaxyqN8HMleppkui2GPzxw-1; Fri, 24 Sep 2021 11:20:04 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D549D100C682; Fri, 24 Sep 2021 15:19:53 +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 F031B5BAFA; Fri, 24 Sep 2021 15:19:50 +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 B48A64EA38; Fri, 24 Sep 2021 15:19:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18OFIKPo026607 for ; Fri, 24 Sep 2021 11:18:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C2A61803B; Fri, 24 Sep 2021 15:18:20 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA82476608 for ; Fri, 24 Sep 2021 15:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632496807; 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=t5n8lz043rTGQYRB5TfmsW+mXz2jDbkl4VkroO8NowI=; b=gU6mmbdyDd6BBYLRMGZEd3QWG4yeAGClXgnl8jU75Dme/ksAzCa9lkE6KP6w729KPXdv+S yxiyrZKuLlALQj8h/W1JEH8tBZ0/nLKsC8lsIwVNf6kyV13tTGOI90UL7m8mFLFibXs+PV nBgpRkHMaZ4GlM8zdMAsP0szvTBdswA= X-MC-Unique: ZaxyqN8HMleppkui2GPzxw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 4/7] virsh: domain: remove 'ret' variable, use early return when possible Date: Fri, 24 Sep 2021 17:17:47 +0200 Message-Id: <8c46918e147d0b7a6f40ccf22a808b9bb954e317.1632495763.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.13 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: 1632496809015100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 84 +++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 51 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 1da9b183bf..1692197d1a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2923,7 +2923,6 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) const char *path =3D NULL; unsigned long long size =3D 0; unsigned int flags =3D 0; - bool ret =3D false; =20 if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < = 0) return false; @@ -2942,12 +2941,11 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) =20 if (virDomainBlockResize(dom, path, size, flags) < 0) { vshError(ctl, _("Failed to resize block device '%s'"), path); - } else { - vshPrintExtra(ctl, _("Block device '%s' is resized"), path); - ret =3D true; + return false; } =20 - return ret; + vshPrintExtra(ctl, _("Block device '%s' is resized"), path); + return true; } =20 #ifndef WIN32 @@ -3421,19 +3419,17 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; const char *name; - bool ret =3D true; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) return false; =20 - if (virDomainSuspend(dom) =3D=3D 0) { - vshPrintExtra(ctl, _("Domain '%s' suspended\n"), name); - } else { + if (virDomainSuspend(dom) !=3D 0) { vshError(ctl, _("Failed to suspend domain '%s'"), name); - ret =3D false; + return false; } =20 - return ret; + vshPrintExtra(ctl, _("Domain '%s' suspended\n"), name); + return true; } =20 /* @@ -5802,20 +5798,18 @@ static bool cmdResume(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; const char *name; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) return false; =20 - if (virDomainResume(dom) =3D=3D 0) { - vshPrintExtra(ctl, _("Domain '%s' resumed\n"), name); - } else { + if (virDomainResume(dom) !=3D 0) { vshError(ctl, _("Failed to resume domain '%s'"), name); - ret =3D false; + return false; } =20 - return ret; + vshPrintExtra(ctl, _("Domain '%s' resumed\n"), name); + return true; } =20 /* @@ -5997,20 +5991,18 @@ static bool cmdReset(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; const char *name; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) return false; =20 - if (virDomainReset(dom, 0) =3D=3D 0) { - vshPrintExtra(ctl, _("Domain '%s' was reset\n"), name); - } else { + if (virDomainReset(dom, 0) !=3D 0) { vshError(ctl, _("Failed to reset domain '%s'"), name); - ret =3D false; + return false; } =20 - return ret; + vshPrintExtra(ctl, _("Domain '%s' was reset\n"), name); + return true; } =20 /* @@ -8183,7 +8175,6 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; const char *from =3D NULL; - bool ret =3D true; char *buffer; unsigned int flags =3D 0; virshControl *priv =3D ctl->privData; @@ -8203,14 +8194,14 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) dom =3D virDomainDefineXML(priv->conn, buffer); VIR_FREE(buffer); =20 - if (dom !=3D NULL) { - vshPrintExtra(ctl, _("Domain '%s' defined from %s\n"), - virDomainGetName(dom), from); - } else { + if (!dom) { vshError(ctl, _("Failed to define domain from %s"), from); - ret =3D false; + return false; } - return ret; + + vshPrintExtra(ctl, _("Domain '%s' defined from %s\n"), + virDomainGetName(dom), from); + return true; } =20 /* @@ -8239,7 +8230,6 @@ static bool cmdDestroy(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; const char *name; unsigned int flags =3D 0; int result; @@ -8255,14 +8245,13 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd) else result =3D virDomainDestroy(dom); =20 - if (result =3D=3D 0) { - vshPrintExtra(ctl, _("Domain '%s' destroyed\n"), name); - } else { + if (result < 0) { vshError(ctl, _("Failed to destroy domain '%s'"), name); - ret =3D false; + return false; } =20 - return ret; + vshPrintExtra(ctl, _("Domain '%s' destroyed\n"), name); + return true; } =20 /* @@ -9955,7 +9944,6 @@ static bool cmdDumpXML(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; g_autofree char *dump =3D NULL; unsigned int flags =3D 0; bool inactive =3D vshCommandOptBool(cmd, "inactive"); @@ -9975,14 +9963,11 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 - dump =3D virDomainGetXMLDesc(dom, flags); - if (dump !=3D NULL) { - vshPrint(ctl, "%s", dump); - } else { - ret =3D false; - } + if (!(dump =3D virDomainGetXMLDesc(dom, flags))) + return false; =20 - return ret; + vshPrint(ctl, "%s", dump); + return true; } =20 /* @@ -10016,7 +10001,6 @@ static const vshCmdOptDef opts_domxmlfromnative[] = =3D { static bool cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D true; const char *format =3D NULL; const char *configFile =3D NULL; g_autofree char *configData =3D NULL; @@ -10032,13 +10016,11 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd= *cmd) return false; =20 xmlData =3D virConnectDomainXMLFromNative(priv->conn, format, configDa= ta, flags); - if (xmlData !=3D NULL) { - vshPrint(ctl, "%s", xmlData); - } else { - ret =3D false; - } + if (!xmlData) + return false; =20 - return ret; + vshPrint(ctl, "%s", xmlData); + return true; } =20 /* --=20 2.31.1 From nobody Mon Feb 9 17:21:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1632496809; cv=none; d=zohomail.com; s=zohoarc; b=RCp3sUmjpYQVWPgQdXq45M4g3ray1GiC7AzZ+wYn2KbgQbneVeqbw43o+C5bSeeQHTcRc9YxIDr3YfHxnr6LVasqj+Y3XKDwcLL6drEJSpeEiwW9nITQYjgFGp+9hAqgIGUD+YejZPiMpw5sj4tkGWqKWDWOJZTuDRl1dDHnp8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632496809; 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=CD75jTV2TM0pQoLdY02A9wWl3qVYPieU0OFF+EvaqZ4=; b=m+TNUmfxADne6yImcI4bn3bwnVXYNCBSxtchwJ78TD/60liRUdpdL4yyv81CDZucDSK4aktNjVaA12oD45G2A+JS0tDaKUuj33f6A38kFOsd/sbxLVx2eE9atwgCnbFXawTVuByeBwcHnQlXDHo88Hg+LHKKybA97AnZuwaQ6Us= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1632496809250193.2940189166477; Fri, 24 Sep 2021 08:20:09 -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-289-hGuTEOFUMp6fwihCqgKY5w-1; Fri, 24 Sep 2021 11:20:06 -0400 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 DA8EE84A5EB; Fri, 24 Sep 2021 15:19:54 +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 C5189104B4C6; Fri, 24 Sep 2021 15:19:53 +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 5CCFF4EA39; Fri, 24 Sep 2021 15:19:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18OFIMN0026628 for ; Fri, 24 Sep 2021 11:18:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id C44061B467; Fri, 24 Sep 2021 15:18:22 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3680F79446 for ; Fri, 24 Sep 2021 15:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632496808; 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=CD75jTV2TM0pQoLdY02A9wWl3qVYPieU0OFF+EvaqZ4=; b=SB29ZxzoKyzWZxMqaCnT1bhVPGOmoPLXdtO8tOongBdaxswox8CW8SuCZZOX6oDmovPqL1 Lz8pkZXr9D/bRY6adZwVtxWZY545N/fGrRWSS2QfG1k7wHWeyrr/5XcPL+oosqFTvfamY2 k2tQ9BqyDRoR0vwrZhZrMMWjZgqPo5Q= X-MC-Unique: hGuTEOFUMp6fwihCqgKY5w-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 5/7] virsh: domain: use early return when possible Date: Fri, 24 Sep 2021 17:17:48 +0200 Message-Id: <9379937c2bc17ea4c00c2ae5c5945af9eec711b6.1632495763.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: 1632496811065100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 1692197d1a..3c496d845a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5883,13 +5883,13 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) rv =3D virDomainShutdownFlags(dom, flags); else rv =3D virDomainShutdown(dom); - if (rv =3D=3D 0) { - vshPrintExtra(ctl, _("Domain '%s' is being shutdown\n"), name); - } else { + + if (rv !=3D 0) { vshError(ctl, _("Failed to shutdown domain '%s'"), name); return false; } =20 + vshPrintExtra(ctl, _("Domain '%s' is being shutdown\n"), name); return true; } =20 @@ -5959,13 +5959,12 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) return false; =20 - if (virDomainReboot(dom, flags) =3D=3D 0) { - vshPrintExtra(ctl, _("Domain '%s' is being rebooted\n"), name); - } else { + if (virDomainReboot(dom, flags) !=3D 0) { vshError(ctl, _("Failed to reboot domain '%s'"), name); return false; } =20 + vshPrintExtra(ctl, _("Domain '%s' is being rebooted\n"), name); return true; } =20 --=20 2.31.1 From nobody Mon Feb 9 17:21:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1632496895; cv=none; d=zohomail.com; s=zohoarc; b=BUoRvhaNAV2n8s+npoIkTnCp+jLDVWICcq6WARcAjTQJfOKrb18ligSoQ2Fu4w39G6NsSRk750cM8oofWCak9KeKU9H5ryGWvi4FvZXhkhTH2uZYXST81UYXm6PJ/EFMqXxSRyTNL+jn8cdpy6rVU7GQn9/hLgXe6JTyLO5wrng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632496895; 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=mu+mvOf2tdvYKTknijX3SW/CrArsgaoHnQ4GiPBeuCA=; b=Z62arzrY4Xgpu1ydqf8J0roLDzWnx+lj5UnjBfRiGivNwA8G6n5jGCrXMQ0ktwwHdmi+2AoHCplXkbKVLYp45EWA4jElMJZA2wVsLiaMMbZz1PddYN+9XSzo7s2UO8ApRSrZG2YN8sKNa2tA1wl9wCRTBTHobwP3Lhg+SVpjv/M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 163249689582362.92658276271254; Fri, 24 Sep 2021 08:21:35 -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-159-YPz3fAUoNLuQ2K2GmJN7IA-1; Fri, 24 Sep 2021 11:21:33 -0400 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 D186A18D6A32; Fri, 24 Sep 2021 15:21:27 +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 A9C711803B; Fri, 24 Sep 2021 15:21:27 +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 7934D1806D02; Fri, 24 Sep 2021 15:21:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18OFIN1o026637 for ; Fri, 24 Sep 2021 11:18:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id D67B41803B; Fri, 24 Sep 2021 15:18:23 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 152C51800D for ; Fri, 24 Sep 2021 15:18:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632496894; 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=mu+mvOf2tdvYKTknijX3SW/CrArsgaoHnQ4GiPBeuCA=; b=JwFJJpVmdlPN2hAGZR4YLIQ2Ffa6rQ+fOV8NuRyRmGOhgPTKCWnoxQT2egKTefJCQqQTy0 rFvJSp3SiP4YKQa8KFDggsnBl73GA5I/3++hiucdPbUNaD92tTHIoyZK13Hi3T5NIJ4kde VFriSQHuKy0kmKyISv3ppweTCJ4YY20= X-MC-Unique: YPz3fAUoNLuQ2K2GmJN7IA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 6/7] virsh: domain: remove 'ret' variable and use 'count' instead Date: Fri, 24 Sep 2021 17:17:49 +0200 Message-Id: <71748b6e562bbc67099042299429de5282556782.1632495763.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: 1632496898090100001 Content-Type: text/plain; charset="utf-8" This patch also includes use of an early return in case of an error. I think the changes make the functions more readable. Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 3c496d845a..94ed786751 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13608,10 +13608,10 @@ static bool cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - int ret =3D -1; const vshCmdOpt *opt =3D NULL; g_autofree const char **mountpoints =3D NULL; size_t nmountpoints =3D 0; + int count =3D 0; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -13621,16 +13621,13 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd) mountpoints[nmountpoints-1] =3D opt->data; } =20 - ret =3D virDomainFSFreeze(dom, mountpoints, nmountpoints, 0); - if (ret < 0) { + if ((count =3D virDomainFSFreeze(dom, mountpoints, nmountpoints, 0)) <= 0) { vshError(ctl, _("Unable to freeze filesystems")); - goto cleanup; + return false; } =20 - vshPrintExtra(ctl, _("Froze %d filesystem(s)\n"), ret); - - cleanup: - return ret >=3D 0; + vshPrintExtra(ctl, _("Froze %d filesystem(s)\n"), count); + return true; } =20 static const vshCmdInfo info_domfsthaw[] =3D { @@ -13656,10 +13653,10 @@ static bool cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - int ret =3D -1; const vshCmdOpt *opt =3D NULL; g_autofree const char **mountpoints =3D NULL; size_t nmountpoints =3D 0; + int count =3D 0; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -13669,16 +13666,13 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd) mountpoints[nmountpoints-1] =3D opt->data; } =20 - ret =3D virDomainFSThaw(dom, mountpoints, nmountpoints, 0); - if (ret < 0) { + if ((count =3D virDomainFSThaw(dom, mountpoints, nmountpoints, 0)) < 0= ) { vshError(ctl, _("Unable to thaw filesystems")); - goto cleanup; + return false; } =20 - vshPrintExtra(ctl, _("Thawed %d filesystem(s)\n"), ret); - - cleanup: - return ret >=3D 0; + vshPrintExtra(ctl, _("Thawed %d filesystem(s)\n"), count); + return true; } =20 static const vshCmdInfo info_domfsinfo[] =3D { --=20 2.31.1 From nobody Mon Feb 9 17:21:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1632496887; cv=none; d=zohomail.com; s=zohoarc; b=Nh4aR+dRb1uVtHnRWlBTghklW70JnZl85/X48Hv7K5rRrX/NIOOjZ8oC6HSs3XhFvnoi8pi2JcWXbV6CVofLfK/Ucm9uffolcWQSdAs4sRTund4ekQqHuj+q+jloxbDtVDH07bJe3VH74exgs9TZaoaqpoPL/M4skHt6BHK7pgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632496887; 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=QR+/S/D0IiAGATHPeqZdlwLT2+FYjELqjjakkJS5XCY=; b=TLcG1Zh8ekqXcfzVX2lqa9GDQPnx3C5yvWvMWfzSC72OQ2kRkm4M/RRzQOyV/qT6UY8Fq0QIr702TiSX+Et2ohPB3blryAeMk4GO69Same0Cok9oR3dtjiR9qouUwp6fH/d/VARYlACpuC+fT32wtVGk2BwHKjKuu7/e277tzmY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1632496887660909.6962865014765; Fri, 24 Sep 2021 08:21:27 -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-585-lRSFApaLMlqbO4Ej1Ytr3A-1; Fri, 24 Sep 2021 11:21:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30CB78145EE; Fri, 24 Sep 2021 15:21:20 +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 E33885D9DE; Fri, 24 Sep 2021 15:21:19 +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 7C6044EA2F; Fri, 24 Sep 2021 15:21:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18OFIPJu026668 for ; Fri, 24 Sep 2021 11:18:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 25051177C0; Fri, 24 Sep 2021 15:18:25 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F2F45172D for ; Fri, 24 Sep 2021 15:18:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632496886; 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=QR+/S/D0IiAGATHPeqZdlwLT2+FYjELqjjakkJS5XCY=; b=dzNhzV0DffBA2TvkFh05ARHPZWr5zNRPkAR/wFlIhASCMpn/5BuzqLNygT3SZaktQCqMMY CEieTGLAd68ICaGtNvlz/GY3ToCAWYYiRgU+Pwj2hdttm+zHXl58L8BlqM54OvKXm65cus EcRrSSwWV0sbRv1ClJQ/tJu5U+J0w2M= X-MC-Unique: lRSFApaLMlqbO4Ej1Ytr3A-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 7/7] virsh: domain: remove else branch Date: Fri, 24 Sep 2021 17:17:50 +0200 Message-Id: <77aee018132c1753d5c0e3edf2a4ca397b7993a7.1632495763.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.14 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: 1632496888813100003 Content-Type: text/plain; charset="utf-8" I removed else branches after return/break as they are not necessary and the code looks cleaner without them. Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 94ed786751..ca8f08d949 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11046,12 +11046,12 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd= *cmd) return false; =20 rc =3D vshCommandOptULongLong(ctl, cmd, "size", &size); - if (rc < 0) { + if (rc < 0) + return false; + + if (rc !=3D 0 && + (virDomainMigrateSetCompressionCache(dom, size, 0) < 0)) return false; - } else if (rc !=3D 0) { - if (virDomainMigrateSetCompressionCache(dom, size, 0) < 0) - return false; - } =20 if (virDomainMigrateGetCompressionCache(dom, &size, 0) < 0) return false; @@ -11432,11 +11432,9 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) =20 /* We got what we came for so return successfully */ ret =3D true; - if (!all) { + if (!all) break; - } else { - vshPrint(ctl, "\n"); - } + vshPrint(ctl, "\n"); } =20 if (!ret) { --=20 2.31.1