[libvirt] [PATCH v2 01/45] cpuGetModels: Switch to virArch

Jiri Denemark jdenemar at redhat.com
Mon Sep 19 13:30:10 UTC 2016


Our internal APIs mostly use virArch rather than strings. Switching
cpuGetModels to virArch will save us from unnecessary conversions in the
future.

Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
---

Notes:
    Version 2:
    - no change

 src/cpu/cpu.c           | 17 ++++-------------
 src/cpu/cpu.h           |  3 +--
 src/driver-hypervisor.h |  2 +-
 src/qemu/qemu_driver.c  | 11 ++++++++++-
 src/test/test_driver.c  | 12 +++++++++++-
 5 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 11a68f0..19afeab 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -747,7 +747,7 @@ cpuModelIsAllowed(const char *model,
 /**
  * cpuGetModels:
  *
- * @archName: CPU architecture string
+ * @arch: CPU architecture
  * @models: where to store the NULL-terminated list of supported models
  *
  * Fetches all CPU models supported by libvirt on @archName.
@@ -755,26 +755,17 @@ cpuModelIsAllowed(const char *model,
  * Returns number of supported CPU models or -1 on error.
  */
 int
-cpuGetModels(const char *archName, char ***models)
+cpuGetModels(virArch arch, char ***models)
 {
     struct cpuArchDriver *driver;
-    virArch arch;
 
-    VIR_DEBUG("arch=%s", archName);
-
-    arch = virArchFromString(archName);
-    if (arch == VIR_ARCH_NONE) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("cannot find architecture %s"),
-                       archName);
-        return -1;
-    }
+    VIR_DEBUG("arch=%s", virArchToString(arch));
 
     driver = cpuGetSubDriver(arch);
     if (driver == NULL) {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("cannot find a driver for the architecture %s"),
-                       archName);
+                       virArchToString(arch));
         return -1;
     }
 
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index f1d5276..422818e 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -199,8 +199,7 @@ cpuModelIsAllowed(const char *model,
     ATTRIBUTE_NONNULL(1);
 
 int
-cpuGetModels(const char *arch, char ***models)
-    ATTRIBUTE_NONNULL(1);
+cpuGetModels(virArch arch, char ***models);
 
 /* cpuDataFormat and cpuDataParse are implemented for unit tests only and
  * have no real-life usage
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 5cd1fdf..51af732 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -678,7 +678,7 @@ typedef char *
 
 typedef int
 (*virDrvConnectGetCPUModelNames)(virConnectPtr conn,
-                                 const char *args,
+                                 const char *archName,
                                  char ***models,
                                  unsigned int flags);
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e29180d..c1c522a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18363,14 +18363,23 @@ qemuNodeSuspendForDuration(virConnectPtr conn,
 
 static int
 qemuConnectGetCPUModelNames(virConnectPtr conn,
-                            const char *arch,
+                            const char *archName,
                             char ***models,
                             unsigned int flags)
 {
+    virArch arch;
+
     virCheckFlags(0, -1);
     if (virConnectGetCPUModelNamesEnsureACL(conn) < 0)
         return -1;
 
+    if (!(arch = virArchFromString(archName))) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("cannot find architecture %s"),
+                       archName);
+        return -1;
+    }
+
     return cpuGetModels(arch, models);
 }
 
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 87799e1..7ef3d2f 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5893,11 +5893,21 @@ testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED,
 
 static int
 testConnectGetCPUModelNames(virConnectPtr conn ATTRIBUTE_UNUSED,
-                            const char *arch,
+                            const char *archName,
                             char ***models,
                             unsigned int flags)
 {
+    virArch arch;
+
     virCheckFlags(0, -1);
+
+    if (!(arch = virArchFromString(archName))) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("cannot find architecture %s"),
+                       archName);
+        return -1;
+    }
+
     return cpuGetModels(arch, models);
 }
 
-- 
2.10.0




More information about the libvir-list mailing list