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

[Xen-devel] [PATCH v9 7/9] xl: move the vcpu affinity parsing in a function



so that the same code can be shared for the parsing of the
soft affinity, being introduced in the next patch.

This is pure code motion, so no functional change intended,
and it is being done as a separate patch for the sake of
separating code motion from actual changes, i.e., for
facilitating reviews.

Signed-off-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx>
---
 tools/libxl/xl_cmdimpl.c |   81 ++++++++++++++++++++++++----------------------
 1 file changed, 43 insertions(+), 38 deletions(-)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index d9e235e..d08a149 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -692,6 +692,47 @@ static void parse_top_level_sdl_options(XLU_Config *config,
     xlu_cfg_replace_string (config, "xauthority", &sdl->xauthority, 0);
 }
 
+static void parse_vcpu_affinity(XLU_Config *config, XLU_ConfigList *cpus,
+                                const char *buf, libxl_domain_build_info *info)
+{
+    info->num_vcpu_hard_affinity = info->max_vcpus;
+    const char *buf2;
+    int i;
+
+    info->vcpu_hard_affinity =
+        xmalloc(info->num_vcpu_hard_affinity * sizeof(libxl_bitmap));
+
+    for (i = 0; i < info->num_vcpu_hard_affinity; i++) {
+        libxl_bitmap_init(&info->vcpu_hard_affinity[i]);
+        if (libxl_cpu_bitmap_alloc(ctx, &info->vcpu_hard_affinity[i], 0)) {
+            fprintf(stderr, "Unable to allocate cpumap for vcpu %d\n", i);
+            exit(1);
+        }
+        libxl_bitmap_set_none(&info->vcpu_hard_affinity[i]);
+    }
+
+    /*
+     * When buf is !NULL, we've been passed a string, and what we do
+     * is parse it and put the result in all the entries of the vcpu
+     * affinity array. If it's NULL, what we have is a list, and what
+     * we put in each entry of the vcpu affinity array is the result of
+     * the parsing of each element of the list (if there are more
+     * vcpus than elements, the missing ones have their affinity masks
+     * completely full).
+     */
+    for (i = 0; i < info->num_vcpu_hard_affinity; i++) {
+        if (buf || ((buf2 = xlu_cfg_get_listitem(cpus, i)) != NULL)) {
+            if (vcpupin_parse(buf ? buf : buf2,
+                              &info->vcpu_hard_affinity[i]))
+                exit(1);
+        } else
+            libxl_bitmap_set_any(&info->vcpu_hard_affinity[i]);
+    }
+
+    /* We have a list of cpumaps, disable automatic placement */
+    libxl_defbool_set(&info->numa_placement, false);
+}
+
 static void parse_config_data(const char *config_source,
                               const char *config_data,
                               int config_len,
@@ -825,44 +866,8 @@ static void parse_config_data(const char *config_source,
 
     buf = NULL;
     if (!xlu_cfg_get_list (config, "cpus", &cpus, 0, 1) ||
-        !xlu_cfg_get_string (config, "cpus", &buf, 0)) {
-        b_info->num_vcpu_hard_affinity = b_info->max_vcpus;
-        const char *buf2;
-
-        b_info->vcpu_hard_affinity =
-            xmalloc(b_info->num_vcpu_hard_affinity * sizeof(libxl_bitmap));
-
-        for (i = 0; i < b_info->num_vcpu_hard_affinity; i++) {
-            libxl_bitmap_init(&b_info->vcpu_hard_affinity[i]);
-            if (libxl_cpu_bitmap_alloc(ctx,
-                                       &b_info->vcpu_hard_affinity[i], 0)) {
-                fprintf(stderr, "Unable to allocate cpumap for vcpu %d\n", i);
-                exit(1);
-            }
-            libxl_bitmap_set_none(&b_info->vcpu_hard_affinity[i]);
-        }
-
-        /*
-         * When buf is !NULL, we've been passed a string, and what we do
-         * is parse it and put the result in all the entries of the vcpu
-         * affinity array. If it's NULL, what we have is a list, and what
-         * we put in each entry of the vcpu affinity array is the result of
-         * the parsing of each element of the list (if there are more
-         * vcpus than elements, the missing ones have their affinity masks
-         * completely full).
-         */
-        for (i = 0; i < b_info->num_vcpu_hard_affinity; i++) {
-            if (buf || ((buf2 = xlu_cfg_get_listitem(cpus, i)) != NULL)) {
-                if (vcpupin_parse(buf ? buf : buf2,
-                                  &b_info->vcpu_hard_affinity[i]))
-                    exit(1);
-            } else
-                libxl_bitmap_set_any(&b_info->vcpu_hard_affinity[i]);
-        }
-
-        /* We have a list of cpumaps, disable automatic placement */
-        libxl_defbool_set(&b_info->numa_placement, false);
-    }
+        !xlu_cfg_get_string (config, "cpus", &buf, 0))
+        parse_vcpu_affinity(config, cpus, buf, b_info);
 
     if (!xlu_cfg_get_long (config, "memory", &l, 0)) {
         b_info->max_memkb = l * 1024;


_______________________________________________
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®.