[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v3 2/5] libxl: factor out libxl__get_device_modlel_version



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@xxxxxxxxxx>
---
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>

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

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)
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.