From nobody Fri May 16 08:52:37 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 1501283296527827.862655946331; Fri, 28 Jul 2017 16:08:16 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id CA43D3389D7; Fri, 28 Jul 2017 23:08:12 +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 985FF5C8A3; Fri, 28 Jul 2017 23:08:11 +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 AE68C1805977; Fri, 28 Jul 2017 23:08:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6SN870T007068 for ; Fri, 28 Jul 2017 19:08:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6242E173D3; Fri, 28 Jul 2017 23:08:07 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B1335D6A6 for ; Fri, 28 Jul 2017 23:08:04 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7ECBD41A17 for ; Fri, 28 Jul 2017 23:08:02 +0000 (UTC) Received: from linux-tbji.Home (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Fri, 28 Jul 2017 17:07:57 -0600 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CA43D3389D7 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CA43D3389D7 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7ECBD41A17 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jfehlig@suse.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7ECBD41A17 From: Jim Fehlig To: libvir-list@redhat.com Date: Fri, 28 Jul 2017 17:07:33 -0600 Message-Id: <20170728230734.11001-2-jfehlig@suse.com> In-Reply-To: <20170728230734.11001-1-jfehlig@suse.com> References: <20170728230734.11001-1-jfehlig@suse.com> X-Greylist: Delayed for 25:43:20 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 28 Jul 2017 23:08:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 28 Jul 2017 23:08:04 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: joao.m.martins@oracle.com Subject: [libvirt] [PATCH V2 1/2] libxl: make emulator checks mockable 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 28 Jul 2017 23:08:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Export the libxl emulator checks with ATTRIBUTE_NOINLINE so they can be mocked in the test suite. While add it, change the function names to conform to naming standards. Signed-off-by: Jim Fehlig --- src/libxl/libxl_capabilities.c | 30 +++++++++++++++++++++++++++++- src/libxl/libxl_capabilities.h | 5 ++++- src/libxl/libxl_conf.c | 17 +++-------------- src/libxl/libxl_domain.c | 2 +- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index e0959202b..501ebf477 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -743,7 +743,7 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps, #define LIBXL_QEMU_DM_STR "Options specific to the Xen version:" =20 int -libxlDomainGetEmulatorType(const virDomainDef *def) +libxlCapsGetEmulatorType(const virDomainDef *def) { int ret =3D LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN; virCommandPtr cmd =3D NULL; @@ -772,3 +772,31 @@ libxlDomainGetEmulatorType(const virDomainDef *def) virCommandFree(cmd); return ret; } + + +/* + * Returns 0 if an is defined, exists, and is executable. + * Returns -1 otherwise. + */ +int +libxlCapsCheckEmulator(const virDomainDef *def) +{ + if (def->emulator =3D=3D NULL) + return 0; + + if (!virFileExists(def->emulator)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("emulator '%s' not found"), + def->emulator); + return -1; + } + + if (!virFileIsExecutable(def->emulator)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("emulator '%s' is not executable"), + def->emulator); + return -1; + } + + return 0; +} diff --git a/src/libxl/libxl_capabilities.h b/src/libxl/libxl_capabilities.h index 992b78077..28a58d36b 100644 --- a/src/libxl/libxl_capabilities.h +++ b/src/libxl/libxl_capabilities.h @@ -52,6 +52,9 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps, size_t nfirmwares); =20 int -libxlDomainGetEmulatorType(const virDomainDef *def); +libxlCapsGetEmulatorType(const virDomainDef *def) ATTRIBUTE_NOINLINE; + +int +libxlCapsCheckEmulator(const virDomainDef *def) ATTRIBUTE_NOINLINE; =20 #endif /* LIBXL_CAPABILITIES_H */ diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 4416a09dd..f8ebd88e0 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -472,25 +472,14 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, b_info->u.hvm.bios =3D LIBXL_BIOS_TYPE_OVMF; =20 if (def->emulator) { - if (!virFileExists(def->emulator)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("emulator '%s' not found"), - def->emulator); + if (libxlCapsCheckEmulator(def) < 0) return -1; - } - - if (!virFileIsExecutable(def->emulator)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("emulator '%s' is not executable"), - def->emulator); - return -1; - } =20 VIR_FREE(b_info->device_model); if (VIR_STRDUP(b_info->device_model, def->emulator) < 0) return -1; =20 - b_info->device_model_version =3D libxlDomainGetEmulatorType(de= f); + b_info->device_model_version =3D libxlCapsGetEmulatorType(def); } =20 if (def->nserials) { @@ -2082,7 +2071,7 @@ libxlMakeVideo(virDomainDefPtr def, libxl_domain_conf= ig *d_config) =20 { libxl_domain_build_info *b_info =3D &d_config->b_info; - int dm_type =3D libxlDomainGetEmulatorType(def); + int dm_type =3D libxlCapsGetEmulatorType(def); =20 if (d_config->c_info.type !=3D LIBXL_DOMAIN_TYPE_HVM) return 0; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 7caa67474..1bc9045bf 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -335,7 +335,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, } =20 if (dev->type =3D=3D VIR_DOMAIN_DEVICE_VIDEO && def->os.type =3D=3D VI= R_DOMAIN_OSTYPE_HVM) { - int dm_type =3D libxlDomainGetEmulatorType(def); + int dm_type =3D libxlCapsGetEmulatorType(def); =20 switch (dev->data.video->type) { case VIR_DOMAIN_VIDEO_TYPE_VGA: --=20 2.13.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list