render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 401cbf50f18234b0631b4b0e01b9e403137fee95 Mon Sep 17 00:00:00 2001
Message-Id: <401cbf50f18234b0631b4b0e01b9e403137fee95@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Tue, 11 Apr 2017 20:45:07 +0200
Subject: [PATCH] cpu: Introduce virCPUGetHostIsSupported

Sometimes we want to call virCPUGetHost only when it is implemented for
a given architecture to avoid logging expected and possibly misleading
errors. The new virCPUGetHostIsSupported API may be used to guard such
calls to virCPUGetHost.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit bf1a881715c905c67f7d38dcd5bd6c2afbff1f9b)

https://bugzilla.redhat.com/show_bug.cgi?id=1444421

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/cpu/cpu.c            | 20 ++++++++++++++++++++
 src/cpu/cpu.h            |  3 +++
 src/libvirt_private.syms |  1 +
 3 files changed, 24 insertions(+)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 8a407ac18..702b14dbb 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -358,6 +358,26 @@ virCPUDataFree(virCPUDataPtr data)
 
 
 /**
+ * virCPUGetHostIsSupported:
+ *
+ * @arch: CPU architecture
+ *
+ * Check whether virCPUGetHost is supported for @arch.
+ *
+ * Returns true if virCPUGetHost is supported, false otherwise.
+ */
+bool
+virCPUGetHostIsSupported(virArch arch)
+{
+    struct cpuArchDriver *driver;
+
+    VIR_DEBUG("arch=%s", virArchToString(arch));
+
+    return (driver = cpuGetSubDriver(arch)) && driver->getHost;
+}
+
+
+/**
  * virCPUGetHost:
  *
  * @arch: CPU architecture
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index 352445c40..c6ca111e9 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -183,6 +183,9 @@ virCPUDataNew(virArch arch);
 void
 virCPUDataFree(virCPUDataPtr data);
 
+bool
+virCPUGetHostIsSupported(virArch arch);
+
 virCPUDefPtr
 virCPUGetHost(virArch arch,
               virCPUType type,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index cc78c5975..d802e7598 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1026,6 +1026,7 @@ virCPUDataNew;
 virCPUDataParse;
 virCPUExpandFeatures;
 virCPUGetHost;
+virCPUGetHostIsSupported;
 virCPUGetModels;
 virCPUProbeHost;
 virCPUTranslate;
-- 
2.12.2