diff mbox

[v3,2/5] libxl: factor out libxl__get_device_modlel_version

Message ID 1465983102-19308-3-git-send-email-wei.liu2@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Liu June 15, 2016, 9:31 a.m. UTC
Factor out the logic to determine device model version to a function. It
will be used later. Note that code now also checks if the stbudom field
is actually set before trying to extract a value from it.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Anthony PERARD <anthony.perard@citrix.com>

v3: new patch
---
 tools/libxl/libxl_create.c   | 35 ++++++++++++++++++++++++-----------
 tools/libxl/libxl_internal.h |  5 +++++
 2 files changed, 29 insertions(+), 11 deletions(-)

Comments

Dario Faggioli June 15, 2016, 1:27 p.m. UTC | #1
On Wed, 2016-06-15 at 10:31 +0100, Wei Liu wrote:
> Factor out the logic to determine device model version to a function.
> It
> will be used later. Note that code now also checks if the stbudom
> field
> is actually set before trying to extract a value from it.
> 
> No functional change.
> 
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> ---
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Anthony PERARD <anthony.perard@citrix.com>
>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>

Regards,
Dario
Anthony PERARD June 15, 2016, 5:04 p.m. UTC | #2
On Wed, Jun 15, 2016 at 10:31:39AM +0100, Wei Liu wrote:
> Factor out the logic to determine device model version to a function. It
> will be used later. Note that code now also checks if the stbudom field
> is actually set before trying to extract a value from it.
> 
> No functional change.
> 
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>

Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Ian Jackson July 8, 2016, 5:37 p.m. UTC | #3
Wei Liu writes ("[PATCH v3 2/5] libxl: factor out libxl__get_device_modlel_version"):

Typo in subject line.

> Factor out the logic to determine device model version to a function. It
> will be used later. Note that code now also checks if the stbudom field
> is actually set before trying to extract a value from it.

With the typo fixed,

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
diff mbox

Patch

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 1b99472..45fd7bc 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -62,6 +62,28 @@  void libxl__rdm_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info)
                             LIBXL_RDM_MEM_BOUNDARY_MEMKB_DEFAULT;
 }
 
+libxl_device_model_version
+libxl__get_device_model_version(libxl__gc *gc,
+                                const libxl_domain_build_info *b_info)
+{
+    libxl_device_model_version version = LIBXL_DEVICE_MODEL_VERSION_UNKNOWN;
+
+    if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) {
+        if (!libxl_defbool_is_default(b_info->device_model_stubdomain) &&
+            libxl_defbool_val(b_info->device_model_stubdomain)) {
+            version = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
+        } else {
+            version = libxl__default_device_model(gc);
+        }
+    } else {
+        version = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
+    }
+
+    assert(version != LIBXL_DEVICE_MODEL_VERSION_UNKNOWN);
+
+    return version;
+}
+
 int libxl__domain_build_info_setdefault(libxl__gc *gc,
                                         libxl_domain_build_info *b_info)
 {
@@ -80,17 +102,8 @@  int libxl__domain_build_info_setdefault(libxl__gc *gc,
         b_info->device_model_ssidref = SECINITSID_DOMDM;
 
     if (!b_info->device_model_version) {
-        if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) {
-            if (libxl_defbool_val(b_info->device_model_stubdomain)) {
-                b_info->device_model_version =
-                    LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
-            } else {
-                b_info->device_model_version = libxl__default_device_model(gc);
-            }
-        } else {
-            b_info->device_model_version =
-                LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
-        }
+        b_info->device_model_version =
+            libxl__get_device_model_version(gc, b_info);
         if (b_info->device_model_version
                 == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
             const char *dm;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index e7ab85d..3958313 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1999,6 +1999,11 @@  _hidden int libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);
   /* Return the system-wide default device model */
 _hidden libxl_device_model_version libxl__default_device_model(libxl__gc *gc);
 
+/* Derive device model version from build info */
+_hidden libxl_device_model_version
+libxl__get_device_model_version(libxl__gc *gc,
+                                const libxl_domain_build_info *b_info);
+
 #define DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, fmt, _a...)              \
     libxl__sprintf(gc, "/local/domain/%u/device-model/%u" fmt, dm_domid,   \
                    domid, ##_a)