From nobody Wed May 8 22:34:57 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=1631716426; cv=none; d=zohomail.com; s=zohoarc; b=WmP/vvhfwjzCtM6PiQZCl7523Xvmc1IaB/Cj7e1Y6rAeB7eWblqN941mJbDqkS4qDLIZLasfUalWbKFtfREIqQTJVjaKBRMv9zoMrkMJu72QjL8ocQpB0YCfBru8DAeIX5gQARIhpGRUiME3IoKJtCOA5LiHxxGbYsbunxxsAJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631716426; 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=ePI5VR+snpQT7r3Tamg48v4TiO5fm2gttKntQZCGWoY=; b=OVCldm+tVEFycyFFXSzlV7ALKqH+Jcxgt73GCEm+kr/TNPWVPdMZxjK+C8IcZQW7iF+twK/shioYWzBeGlOX8jV44OJ6BzOu/xmhKZpsckhyT2fpyGZJHSGr54v6JuEWpJKQxPbOkKIGI/1wf/kJXHf54izcZS2/EqoQibJlV5A= 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 1631716426352241.75634144373282; Wed, 15 Sep 2021 07:33:46 -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-294-xaKsyGfkOHy6t1Ty_FiuEQ-1; Wed, 15 Sep 2021 10:33:42 -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 ED818100CCC5; Wed, 15 Sep 2021 14:33:36 +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 DA43F10023AE; Wed, 15 Sep 2021 14:33:33 +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 B67794EA2A; Wed, 15 Sep 2021 14:33:30 +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 18FEReR9022306 for ; Wed, 15 Sep 2021 10:27:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0F3535D9D3; Wed, 15 Sep 2021 14:27:40 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D5A65D9CA for ; Wed, 15 Sep 2021 14:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631716425; 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=ePI5VR+snpQT7r3Tamg48v4TiO5fm2gttKntQZCGWoY=; b=MjR2esXsLwWCjB3tUn8kYgaEdK34Syze30g/HNBM7LQPOkXatqKzndzrsEUW/G4uy2xdlg gf5tA+Nl/eIS6/Rzt8D8X2BNyho+Lai5qm5+1HibYngjdSg54GGJL/QtO631gWZOZKopit MKwh+RPo9vI6pJPOBo2gaandgbzJKMM= X-MC-Unique: xaKsyGfkOHy6t1Ty_FiuEQ-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH] tools/virsh-pool: refactor smaller functions Date: Wed, 15 Sep 2021 16:27:15 +0200 Message-Id: <500bda686590866c15f3178dd85eae8127a8093b.1631715926.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.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: 1631716427493100001 Content-Type: text/plain; charset="utf-8" I think these functions look much more readable with just simple if conditions. Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-pool.c | 68 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 38 deletions(-) diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 1a2ab8cc53..c65e8163a6 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -269,7 +269,6 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) { virStoragePoolPtr pool; const char *from =3D NULL; - bool ret =3D true; g_autofree char *buffer =3D NULL; bool build; bool overwrite; @@ -297,17 +296,15 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; =20 - pool =3D virStoragePoolCreateXML(priv->conn, buffer, flags); - - if (pool !=3D NULL) { - vshPrintExtra(ctl, _("Pool %s created from %s\n"), - virStoragePoolGetName(pool), from); - virStoragePoolFree(pool); - } else { + if (!(pool =3D virStoragePoolCreateXML(priv->conn, buffer, flags))) { vshError(ctl, _("Failed to create pool from %s"), from); - ret =3D false; + return false; } - return ret; + + vshPrintExtra(ctl, _("Pool %s created from %s\n"), + virStoragePoolGetName(pool), from); + virStoragePoolFree(pool); + return true; } =20 static const vshCmdOptDef opts_pool_define_as[] =3D { @@ -490,17 +487,16 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd) =20 if (printXML) { vshPrint(ctl, "%s", xml); - } else { - pool =3D virStoragePoolCreateXML(priv->conn, xml, flags); + return true; + } =20 - if (pool !=3D NULL) { - vshPrintExtra(ctl, _("Pool %s created\n"), name); - virStoragePoolFree(pool); - } else { - vshError(ctl, _("Failed to create pool %s"), name); - return false; - } + if (!(pool =3D virStoragePoolCreateXML(priv->conn, xml, flags))) { + vshError(ctl, _("Failed to create pool %s"), name); + return false; } + + vshPrintExtra(ctl, _("Pool %s created\n"), name); + virStoragePoolFree(pool); return true; } =20 @@ -532,7 +528,6 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd) { virStoragePoolPtr pool; const char *from =3D NULL; - bool ret =3D true; g_autofree char *buffer =3D NULL; unsigned int flags =3D 0; virshControl *priv =3D ctl->privData; @@ -546,17 +541,15 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; =20 - pool =3D virStoragePoolDefineXML(priv->conn, buffer, flags); - - if (pool !=3D NULL) { - vshPrintExtra(ctl, _("Pool %s defined from %s\n"), - virStoragePoolGetName(pool), from); - virStoragePoolFree(pool); - } else { + if (!(pool =3D virStoragePoolDefineXML(priv->conn, buffer, flags))) { vshError(ctl, _("Failed to define pool from %s"), from); - ret =3D false; + return false; } - return ret; + + vshPrintExtra(ctl, _("Pool %s defined from %s\n"), + virStoragePoolGetName(pool), from); + virStoragePoolFree(pool); + return true; } =20 /* @@ -586,17 +579,16 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd) =20 if (printXML) { vshPrint(ctl, "%s", xml); - } else { - pool =3D virStoragePoolDefineXML(priv->conn, xml, 0); + return true; + } =20 - if (pool !=3D NULL) { - vshPrintExtra(ctl, _("Pool %s defined\n"), name); - virStoragePoolFree(pool); - } else { - vshError(ctl, _("Failed to define pool %s"), name); - return false; - } + if (!(pool =3D virStoragePoolDefineXML(priv->conn, xml, 0))) { + vshError(ctl, _("Failed to define pool %s"), name); + return false; } + + vshPrintExtra(ctl, _("Pool %s defined\n"), name); + virStoragePoolFree(pool); return true; } =20 --=20 2.31.1