From nobody Sat Apr 27 18:45:18 2024 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=1635260340; cv=none; d=zohomail.com; s=zohoarc; b=bb7oASm8hqBNq6DQCWXA9UyusudM2jqQ3f+ojyXXLkdStVT49mzs0TZMDMZTMgWBTFPjdiiER+z2/Pehlg3F05YSIKQ99vaNIdqpqZAmIbul8dVpj0lZ3EkmUERxdGJPjgn8fLct5FMuFRSSfOUFCRWUDgxaC+bi4cbGjzmAMbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635260340; 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=IKBeuQ2sRb+y4GT0ps+M2/lDp46H51m2s0qLInbkjv4=; b=F/nznSso/aH4ZaDp4UAaSweaq+iBndnp3ONCL6sS5uZqQ8F5JrvQc4p0eDRBXW+xEpLmr83R3RCTAPhN4yD1dtmRVY7XOQ9on6zYDZXP7nsFwPbQ+NJp0w2GiHDODgKhRE/uMC+KKdN0goC/cFrsl4usbBc0OJrm+vUBkEsde5Y= 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 1635260340393501.7300908179641; Tue, 26 Oct 2021 07:59:00 -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-455-n0eABWISNQGPb9WRKEw-bw-1; Tue, 26 Oct 2021 10:58:54 -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 1E5C280A5D6; Tue, 26 Oct 2021 14:58:39 +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 73A7D5C1A3; Tue, 26 Oct 2021 14:58:38 +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 B06EB180BAD2; Tue, 26 Oct 2021 14:58:36 +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 19QEwZn6000454 for ; Tue, 26 Oct 2021 10:58:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id CC0A14D734; Tue, 26 Oct 2021 14:58:35 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5245D794D8 for ; Tue, 26 Oct 2021 14:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635260339; 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=IKBeuQ2sRb+y4GT0ps+M2/lDp46H51m2s0qLInbkjv4=; b=X1HpnoKx55+17XR16tnqjkuuIlWSeH1drTnpHwdfS/g1OygGfLuwwKb0V/OMdLGQI2CqR7 G4uYn6yXchbZ2yT7Ow7RXEih7BCiLOQb8gTKm4fki7Wd4ROe/2R1gcWFMvIHekdWiA+tSB c4IzmDOFjA5/i+Qw3DOfd+Cw6vhqxaU= X-MC-Unique: n0eABWISNQGPb9WRKEw-bw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH] qemu_block: Refactor qemuBlockExportAddNBD() Date: Tue, 26 Oct 2021 16:58:22 +0200 Message-Id: <071650947c7bab45933f5928f6fb0eb23847ab12.1635260087.git.khanicov@redhat.com> 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: 1635260342635100001 Content-Type: text/plain; charset="utf-8" I think this patch improves readability of the function by removing unnecessary 'else' branches after 'return' and reworking the code a bit. Signed-off-by: Kristina Hanicova --- src/qemu/qemu_block.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 34fdec2c4b..4e532d29c0 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3592,28 +3592,21 @@ qemuBlockExportAddNBD(virDomainObj *vm, const char *bitmap) { qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virJSONValue) nbdprops =3D NULL; + const char *bitmaps[2] =3D { bitmap, NULL }; =20 - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) { - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCK_EXPORT_ADD)) { - g_autoptr(virJSONValue) nbdprops =3D NULL; - const char *bitmaps[2] =3D { bitmap, NULL }; + /* older qemu versions didn't support configuring the exportname and + * took the 'drivealias' as the export name */ + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) + return qemuMonitorNBDServerAdd(priv->mon, drivealias, NULL, writab= le, NULL); =20 - if (!(nbdprops =3D qemuBlockExportGetNBDProps(src->nodeformat, - exportname, - writable, - bitmaps))) - return -1; + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCK_EXPORT_ADD)) + return qemuMonitorNBDServerAdd(priv->mon, src->nodeformat, + exportname, writable, bitmap); =20 - return qemuMonitorBlockExportAdd(priv->mon, &nbdprops); - } else { - return qemuMonitorNBDServerAdd(priv->mon, src->nodeformat, - exportname, writable, bitmap); - } - } else { - /* older qemu versions didn't support configuring the exportname a= nd - * took the 'drivealias' as the export name */ - return qemuMonitorNBDServerAdd(priv->mon, drivealias, NULL, writab= le, NULL); - } + if ((nbdprops =3D qemuBlockExportGetNBDProps(src->nodeformat, exportna= me, + writable, bitmaps))) + return qemuMonitorBlockExportAdd(priv->mon, &nbdprops); =20 - return 0; + return -1; } --=20 2.31.1