From nobody Wed May 14 19:20:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522237232461185.85886846079984; Wed, 28 Mar 2018 04:40:32 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id DDF823DD47; Wed, 28 Mar 2018 11:40: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 9CB0F600CC; Wed, 28 Mar 2018 11:40:30 +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 F0C6B4CA99; Wed, 28 Mar 2018 11:40:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2SBeSPn021926 for ; Wed, 28 Mar 2018 07:40:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id F25199C073; Wed, 28 Mar 2018 11:40:27 +0000 (UTC) Received: from thyrus.usersys.redhat.com (unknown [10.34.245.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BA92946A2 for ; Wed, 28 Mar 2018 11:40:27 +0000 (UTC) From: Pino Toscano To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 13:40:18 +0200 Message-Id: <20180328114021.15169-2-ptoscano@redhat.com> In-Reply-To: <20180328114021.15169-1-ptoscano@redhat.com> References: <20180328114021.15169-1-ptoscano@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] vmx: check for present/enabled devices earlier 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 28 Mar 2018 11:40:31 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When parsing filesystems, network interfaces, serial ports, and parallel ports, check earlier whether they are present/enabled, delaying the allocation of the objects. This is mostly a small optimization, with no behaviour change. Signed-off-by: Pino Toscano --- src/vmx/vmx.c | 92 +++++++++++++++++++------------------------------------= ---- 1 file changed, 30 insertions(+), 62 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 3b0c16d5a..ba47a87b7 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2439,11 +2439,6 @@ int virVMXParseFileSystem(virConfPtr conf, int numbe= r, virDomainFSDefPtr *def) return -1; } =20 - if (!(*def =3D virDomainFSDefNew())) - return -1; - - (*def)->type =3D VIR_DOMAIN_FS_TYPE_MOUNT; - snprintf(prefix, sizeof(prefix), "sharedFolder%d", number); =20 VMX_BUILD_NAME(present); @@ -2454,14 +2449,19 @@ int virVMXParseFileSystem(virConfPtr conf, int numb= er, virDomainFSDefPtr *def) =20 /* vmx:present */ if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) = < 0) - goto cleanup; + return -1; =20 /* vmx:enabled */ if (virVMXGetConfigBoolean(conf, enabled_name, &enabled, false, true) = < 0) - goto cleanup; + return -1; =20 if (!(present && enabled)) - goto ignore; + return 0; + + if (!(*def =3D virDomainFSDefNew())) + return -1; + + (*def)->type =3D VIR_DOMAIN_FS_TYPE_MOUNT; =20 /* vmx:hostPath */ if (virVMXGetConfigString(conf, hostPath_name, &hostPath, false) < 0) @@ -2497,14 +2497,6 @@ int virVMXParseFileSystem(virConfPtr conf, int numbe= r, virDomainFSDefPtr *def) VIR_FREE(guestName); =20 return result; - - ignore: - virDomainFSDefFree(*def); - *def =3D NULL; - - result =3D 0; - - goto cleanup; } =20 =20 @@ -2557,9 +2549,6 @@ virVMXParseEthernet(virConfPtr conf, int controller, = virDomainNetDefPtr *def) return -1; } =20 - if (VIR_ALLOC(*def) < 0) - return -1; - snprintf(prefix, sizeof(prefix), "ethernet%d", controller); =20 VMX_BUILD_NAME(present); @@ -2575,17 +2564,20 @@ virVMXParseEthernet(virConfPtr conf, int controller= , virDomainNetDefPtr *def) =20 /* vmx:present */ if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) = < 0) - goto cleanup; + return -1; =20 /* vmx:startConnected */ if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected, true, true) < 0) { - goto cleanup; + return -1; } =20 /* FIXME: Need to distiguish between active and inactive domains here = */ if (! present/* && ! startConnected*/) - goto ignore; + return 0; + + if (VIR_ALLOC(*def) < 0) + return -1; =20 /* vmx:connectionType -> def:type */ if (virVMXGetConfigString(conf, connectionType_name, &connectionType, @@ -2726,14 +2718,6 @@ virVMXParseEthernet(virConfPtr conf, int controller,= virDomainNetDefPtr *def) VIR_FREE(vnet); =20 return result; - - ignore: - virDomainNetDefFree(*def); - *def =3D NULL; - - result =3D 0; - - goto cleanup; } =20 =20 @@ -2773,11 +2757,6 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr con= f, int port, return -1; } =20 - if (!(*def =3D virDomainChrDefNew(NULL))) - return -1; - - (*def)->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; - snprintf(prefix, sizeof(prefix), "serial%d", port); =20 VMX_BUILD_NAME(present); @@ -2788,17 +2767,22 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr co= nf, int port, =20 /* vmx:present */ if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) = < 0) - goto cleanup; + return -1; =20 /* vmx:startConnected */ if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected, true, true) < 0) { - goto cleanup; + return -1; } =20 /* FIXME: Need to distiguish between active and inactive domains here = */ if (! present/* && ! startConnected*/) - goto ignore; + return 0; + + if (!(*def =3D virDomainChrDefNew(NULL))) + return -1; + + (*def)->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; =20 /* vmx:fileType -> def:type */ if (virVMXGetConfigString(conf, fileType_name, &fileType, true) < 0) @@ -2919,14 +2903,6 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr con= f, int port, virURIFree(parsedUri); =20 return result; - - ignore: - virDomainChrDefFree(*def); - *def =3D NULL; - - result =3D 0; - - goto cleanup; } =20 =20 @@ -2961,11 +2937,6 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr c= onf, int port, return -1; } =20 - if (!(*def =3D virDomainChrDefNew(NULL))) - return -1; - - (*def)->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; - snprintf(prefix, sizeof(prefix), "parallel%d", port); =20 VMX_BUILD_NAME(present); @@ -2975,17 +2946,22 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr = conf, int port, =20 /* vmx:present */ if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) = < 0) - goto cleanup; + return -1; =20 /* vmx:startConnected */ if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected, true, true) < 0) { - goto cleanup; + return -1; } =20 /* FIXME: Need to distiguish between active and inactive domains here = */ if (! present/* && ! startConnected*/) - goto ignore; + return 0; + + if (!(*def =3D virDomainChrDefNew(NULL))) + return -1; + + (*def)->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; =20 /* vmx:fileType -> def:type */ if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0) @@ -3029,14 +3005,6 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr c= onf, int port, VIR_FREE(fileName); =20 return result; - - ignore: - virDomainChrDefFree(*def); - *def =3D NULL; - - result =3D 0; - - goto cleanup; } =20 =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list