@@ -7229,12 +7229,12 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
LOG(ERROR, "fail to get memory target for domain %d", domid);
goto out;
}
- /* Target memory in xenstore is different from what user has
- * asked for. The difference is video_memkb. See
- * libxl_set_memory_target.
+
+ /* libxl__get_targetmem_fudge() calculates the difference from
+ * what is in xenstore to what we have in the domain build info.
*/
d_config->b_info.target_memkb = target_memkb +
- d_config->b_info.video_memkb;
+ libxl__get_targetmem_fudge(gc, &d_config->b_info);
d_config->b_info.max_memkb = max_memkb;
}
@@ -490,7 +490,6 @@ int libxl__build_post(libxl__gc *gc, uint32_t domid,
xs_transaction_t t;
char **ents;
int i, rc;
- int64_t mem_target_fudge;
if (info->num_vnuma_nodes && !info->num_vcpu_soft_affinity) {
rc = set_vnuma_affinity(gc, domid, info);
@@ -523,17 +522,12 @@ int libxl__build_post(libxl__gc *gc, uint32_t domid,
}
}
- mem_target_fudge =
- (info->type == LIBXL_DOMAIN_TYPE_HVM &&
- info->max_memkb > info->target_memkb)
- ? LIBXL_MAXMEM_CONSTANT : 0;
-
ents = libxl__calloc(gc, 12 + (info->max_vcpus * 2) + 2, sizeof(char *));
ents[0] = "memory/static-max";
ents[1] = GCSPRINTF("%"PRId64, info->max_memkb);
ents[2] = "memory/target";
- ents[3] = GCSPRINTF("%"PRId64, info->target_memkb - info->video_memkb
- - mem_target_fudge);
+ ents[3] = GCSPRINTF("%"PRId64, info->target_memkb -
+ libxl__get_targetmem_fudge(gc, info));
ents[4] = "memory/videoram";
ents[5] = GCSPRINTF("%"PRId64, info->video_memkb);
ents[6] = "domid";
@@ -4107,6 +4107,21 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc,
libxl_uuid_copy(CTX, &dst->uuid, &src->uuid);
}
+/* Target memory in xenstore is different from what user has
+ * asked for. The difference is video_memkb + (possible) fudge.
+ * See libxl_set_memory_target.
+ */
+static inline
+uint64_t libxl__get_targetmem_fudge(libxl__gc *gc,
+ const libxl_domain_build_info *info)
+{
+ int64_t mem_target_fudge = (info->type == LIBXL_DOMAIN_TYPE_HVM &&
+ info->max_memkb > info->target_memkb)
+ ? LIBXL_MAXMEM_CONSTANT : 0;
+
+ return info->video_memkb + mem_target_fudge;
+}
+
/* Macros used to compare device identifier. Returns true if the two
* devices have same identifier. */
#define COMPARE_DEVID(a, b) ((a)->devid == (b)->devid)