@@ -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;
@@ -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)
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(-)