Skip to contentSkip to conversation

support of cpupools in xl: commands and library changes

PATCH In review Juergen Gross 3 participants 4 messages Oct 1, 2010 – Oct 6, 2010 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 support of cpupools in xl: commands and library changes

Hi,

attached patch adds support of cpu pools in xl/libxl.

Juergen

Signature · 5 lines
Juergen Gross                 Principal Developer Operating Systems
TSP ES&S SWE OS6                       Telephone: +49 (0) 89 3222 2967
Fujitsu Technology Solutions              e-mail: [email protected]
Domagkstr. 28                           Internet: ts.fujitsu.com
D-80807 Muenchen                 Company details: ts.fujitsu.com/imprint.html
Signed-off-by [email protected]

Support of cpu pools in xl:
library functions
xl pool-create
xl pool-list
xl pool-destroy
xl pool-cpu-add
xl pool-cpu-remove
xl pool-migrate
Renamed all cpu pool related names to *cpupool*

tools/libxl/libxl.c +191 -9
diff -r f501dd7581e2 tools/libxl/libxl.c
@@ -607,10 +607,10 @@ int libxl_domain_info(libxl_ctx *ctx, li
     return 0;
 }
 
-libxl_poolinfo * libxl_list_pool(libxl_ctx *ctx, int *nb_pool)
+libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx *ctx, int *nb_pool)
 {
-    libxl_poolinfo *ptr;
-    int i;
+    libxl_cpupoolinfo *ptr;
+    int i, m;
     xc_cpupoolinfo_t *info;
     uint32_t poolid;
     libxl_physinfo physinfo;
@@ -627,12 +627,19 @@ libxl_poolinfo * libxl_list_pool(libxl_c
         info = xc_cpupool_getinfo(ctx->xch, poolid);
         if (info == NULL)
             break;
-        ptr = realloc(ptr, (i + 1) * sizeof(libxl_poolinfo));
+        ptr = realloc(ptr, (i + 1) * sizeof(libxl_cpupoolinfo));
         if (!ptr) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpupool info");
             return NULL;
         }
         ptr[i].poolid = info->cpupool_id;
+        ptr[i].sched_id = info->sched_id;
+        ptr[i].n_dom = info->n_dom;
+        if (libxl_cpumap_alloc(&ptr[i].cpumap, physinfo.max_cpu_id + 1))
+            break;
+        for (m = 0; m < ptr[i].cpumap.size / sizeof(*ptr[i].cpumap.map); m++)
+            ptr[i].cpumap.map[m] = (info->cpumap_size > (m * sizeof(*ptr[i].cpumap.map))) ?
+                info->cpumap[m] : 0;
         poolid = info->cpupool_id + 1;
         free(info);
     }
@@ -3228,7 +3235,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
     xc_domaininfo_t domaininfo;
     xc_vcpuinfo_t vcpuinfo;
     xc_physinfo_t physinfo = { 0 };
-    unsigned num_cpuwords;
 
     if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting infolist");
@@ -3244,10 +3250,9 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
         return NULL;
     }
 
-    num_cpuwords = ((physinfo.max_cpu_id + 64) / 64);
     for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) {
-        ptr->cpumap = malloc(num_cpuwords * sizeof(*ptr->cpumap));
-        if (!ptr->cpumap) {
+        if (libxl_cpumap_alloc(&ptr->cpumap, *nrcpus)) {
+            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpumap");
             return NULL;
         }
         if (xc_vcpu_getinfo(ctx->xch, domid, *nb_vcpu, &vcpuinfo) == -1) {
@@ -3255,7 +3260,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
             return NULL;
         }
         if (xc_vcpu_getaffinity(ctx->xch, domid, *nb_vcpu,
-            ptr->cpumap, ((*nrcpus) + 7) / 8) == -1) {
+            ptr->cpumap.map, ((*nrcpus) + 7) / 8) == -1) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting vcpu affinity");
             return NULL;
         }
@@ -3659,3 +3664,180 @@ void libxl_file_reference_destroy(libxl_
     libxl__file_reference_unmap(f);
     free(f->path);
 }
+
+int libxl_get_freecpus(libxl_ctx *ctx, libxl_cpumap *cpumap)
+{
+    libxl_physinfo info;
+    int ret;
+
+    if (libxl_get_physinfo(ctx, &info) != 0)
+        return ERROR_FAIL;
+
+    ret = libxl_cpumap_alloc(cpumap, info.max_cpu_id + 1);
+    if (ret)
+        return ret;
+
+    if (xc_cpupool_freeinfo(ctx->xch, cpumap->map, cpumap->size)) {
+        free(cpumap->map);
+        cpumap->map = NULL;
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
+int libxl_create_cpupool(libxl_ctx *ctx, char *name, int schedid,
+                         libxl_cpumap cpumap, libxl_uuid *uuid,
+                         uint32_t *poolid)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc;
+    int i;
+    xs_transaction_t t;
+    char *uuid_string;
+
+    uuid_string = libxl__uuid2string(&gc, *uuid);
+    if (!uuid_string)
+        return ERROR_NOMEM;
+
+    rc = xc_cpupool_create(ctx->xch, poolid, schedid);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+           "Could not create cpupool");
+        return ERROR_FAIL;
+    }
+
+    for (i = 0; i < cpumap.size * 8; i++)
+        if (cpumap.map[i / 64] & (1L << (i % 64))) {
+            rc = xc_cpupool_addcpu(ctx->xch, *poolid, i);
+            if (rc) {
+                LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+                    "Error moving cpu to cpupool");
+                return ERROR_FAIL;
+            }
+        }
+
+    for (;;) {
+        t = xs_transaction_start(ctx->xsh);
+
+        xs_mkdir(ctx->xsh, t, libxl__sprintf(&gc, "/local/pool/%d", *poolid));
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "/local/pool/%d/uuid", *poolid),
+                 uuid_string);
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "/local/pool/%d/name", *poolid),
+                 name);
+
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))
+            return 0;
+    }
+}
+
+int libxl_destroy_cpupool(libxl_ctx *ctx, uint32_t poolid)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc, i;
+    xc_cpupoolinfo_t *info;
+    xs_transaction_t t;
+
+    info = xc_cpupool_getinfo(ctx->xch, poolid);
+    if (info == NULL)
+        return ERROR_NOMEM;
+
+    rc = ERROR_INVAL;
+    if ((info->cpupool_id != poolid) || (info->n_dom))
+        goto out;
+
+    for (i = 0; i < info->cpumap_size; i++)
+        if (info->cpumap[i / 64] & (1L << (i % 64))) {
+            rc = xc_cpupool_removecpu(ctx->xch, poolid, i);
+            if (rc) {
+                LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+                    "Error removing cpu from cpupool");
+                rc = ERROR_FAIL;
+                goto out;
+            }
+        }
+
+    rc = xc_cpupool_destroy(ctx->xch, poolid);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "Could not destroy cpupool");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    for (;;) {
+        t = xs_transaction_start(ctx->xsh);
+
+        xs_rm(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "/local/pool/%d", poolid));
+
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))
+            break;
+    }
+
+    rc = 0;
+
+out:
+    free(info);
+
+    return rc;
+}
+
+int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu)
+{
+    int rc;
+
+    rc = xc_cpupool_addcpu(ctx->xch, poolid, cpu);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+            "Error moving cpu to cpupool");
+        return ERROR_FAIL;
+    }
+    return 0;
+}
+
+int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu)
+{
+    int rc;
+
+    rc = xc_cpupool_removecpu(ctx->xch, poolid, cpu);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+            "Error removing cpu from cpupool");
+        return ERROR_FAIL;
+    }
+    return 0;
+}
+
+int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc;
+    char *dom_path;
+    char *vm_path;
+    char *poolname;
+    xs_transaction_t t;
+
+    dom_path = libxl__xs_get_dompath(&gc, domid);
+    if (!dom_path) {
+        return ERROR_FAIL;
+    }
+
+    rc = xc_cpupool_movedomain(ctx->xch, poolid, domid);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+            "Error moving domain to cpupool");
+        return ERROR_FAIL;
+    }
+
+    poolname = libxl__cpupoolid_to_name(&gc, poolid);
+    vm_path = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/vm", dom_path));
+    for (; vm_path;) {
+        t = xs_transaction_start(ctx->xsh);
+
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "%s/pool_name", vm_path), poolname);
+
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))
+            break;
+    }
+
+    return 0;
+}
tools/libxl/libxl.h +10 -3
diff -r f501dd7581e2 tools/libxl/libxl.h
@@ -140,8 +140,6 @@ void libxl_string_list_destroy(libxl_str
 
 typedef char **libxl_key_value_list;
 void libxl_key_value_list_destroy(libxl_key_value_list *kvl);
-
-typedef uint64_t *libxl_cpumap;
 
 typedef uint32_t libxl_hwcap[8];
 
@@ -358,7 +356,7 @@ int libxl_domain_info(libxl_ctx*, libxl_
 int libxl_domain_info(libxl_ctx*, libxl_dominfo *info_r,
                       uint32_t domid);
 libxl_dominfo * libxl_list_domain(libxl_ctx*, int *nb_domain);
-libxl_poolinfo * libxl_list_pool(libxl_ctx*, int *nb_pool);
+libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool);
 libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm);
 
 typedef struct libxl__device_model_starting libxl_device_model_starting;
@@ -498,6 +496,15 @@ int libxl_device_net2_del(libxl_ctx *ctx
 int libxl_device_net2_del(libxl_ctx *ctx, libxl_device_net2 *net2,
                           int wait);
 
+int libxl_get_freecpus(libxl_ctx *ctx, libxl_cpumap *cpumap);
+int libxl_create_cpupool(libxl_ctx *ctx, char *name, int schedid,
+                         libxl_cpumap cpumap, libxl_uuid *uuid,
+                         uint32_t *poolid);
+int libxl_destroy_cpupool(libxl_ctx *ctx, uint32_t poolid);
+int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu);
+int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu);
+int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid);
+
 /* common paths */
 const char *libxl_sbindir_path(void);
 const char *libxl_bindir_path(void);
tools/libxl/libxl.idl +11 -5
diff -r f501dd7581e2 tools/libxl/libxl.idl
@@ -16,8 +16,6 @@ libxl_string_list = Builtin("string_list
 libxl_string_list = Builtin("string_list", destructor_fn="libxl_string_list_destroy", passby=PASS_BY_REFERENCE)
 libxl_key_value_list = Builtin("key_value_list", destructor_fn="libxl_key_value_list_destroy", passby=PASS_BY_REFERENCE)
 libxl_file_reference = Builtin("file_reference", destructor_fn="libxl_file_reference_destroy", passby=PASS_BY_REFERENCE)
-
-libxl_cpumap = Builtin("cpumap", destructor_fn="free")
 
 libxl_hwcap = Builtin("hwcap")
 
@@ -45,9 +43,17 @@ SHUTDOWN_* constant."""),
     ("vcpu_online", uint32),
     ], destructor_fn=None)
 
-libxl_poolinfo = Struct("poolinfo", [
-    ("poolid", uint32)
-    ], destructor_fn=None)
+libxl_cpumap = Struct("cpumap", [
+    ("size", uint32, False, "number of bytes in map"),
+    ("map",  Reference(uint64)),
+    ])
+                      
+libxl_cpupoolinfo = Struct("cpupoolinfo", [
+    ("poolid",      uint32),
+    ("sched_id",    uint32),
+    ("n_dom",       uint32),
+    ("cpumap",      libxl_cpumap)
+    ], destructor_fn="libxl_cpupoolinfo_destroy")
 
 libxl_vminfo = Struct("vminfo", [
     ("uuid", libxl_uuid),
tools/libxl/libxl_internal.h +1 -1
diff -r f501dd7581e2 tools/libxl/libxl_internal.h
@@ -237,7 +237,7 @@ _hidden char *libxl__abs_path(libxl__gc 
 #define LIBXL__LOG_ERROR   XTL_ERROR
 
 _hidden char *libxl__domid_to_name(libxl__gc *gc, uint32_t domid);
-_hidden char *libxl__poolid_to_name(libxl__gc *gc, uint32_t poolid);
+_hidden char *libxl__cpupoolid_to_name(libxl__gc *gc, uint32_t poolid);
 
   /* holds the CPUID response for a single CPUID leaf
    * input contains the value of the EAX and ECX register,
tools/libxl/libxl_utils.c +80 -14

136 lines not on this page · raw message

tools/libxl/libxl_utils.h +8 -2
diff -r f501dd7581e2 tools/libxl/libxl_utils.h
@@ -21,8 +21,10 @@ unsigned long libxl_get_required_shadow_
 unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus);
 int libxl_name_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid);
 char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid);
-int libxl_name_to_poolid(libxl_ctx *ctx, const char *name, uint32_t *poolid);
-char *libxl_poolid_to_name(libxl_ctx *ctx, uint32_t poolid);
+int libxl_name_to_cpupoolid(libxl_ctx *ctx, const char *name, uint32_t *poolid);
+char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid);
+int libxl_name_to_schedid(libxl_ctx *ctx, const char *name);
+char *libxl_schedid_to_name(libxl_ctx *ctx, int schedid);
 int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid);
 int libxl_is_stubdom(libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid);
 int libxl_create_logfile(libxl_ctx *ctx, char *name, char **full_name);
@@ -74,5 +76,9 @@ int libxl_devid_to_device_net2(libxl_ctx
  * return -1 if there are an error */
 int libxl_check_device_model_version(libxl_ctx *ctx, char *path);
 
+int libxl_cpumap_alloc(libxl_cpumap *cpumap, int max_cpus);
+int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu);
+void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
+void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
 #endif
 
tools/libxl/libxltypes.py +4 -1
diff -r f501dd7581e2 tools/libxl/libxltypes.py
@@ -131,7 +131,10 @@ class Reference(Type):
         kwargs.setdefault('passby', PASS_BY_VALUE)
         
         kwargs.setdefault('namespace', ty.namespace)
-        typename = ty.typename[len(kwargs['namespace']):]
+
+        typename = ty.typename
+        if ty.namespace:
+            typename = typename[len(kwargs['namespace']):]
         Type.__init__(self, typename + " *", **kwargs)
 
 #
tools/libxl/libxlu_cfg_l.c +8 -22
diff -r f501dd7581e2 tools/libxl/libxlu_cfg_l.c
@@ -54,6 +54,7 @@ typedef unsigned char flex_uint8_t;
 typedef unsigned char flex_uint8_t; 
 typedef unsigned short int flex_uint16_t;
 typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
 
 /* Limits of integral types. */
 #ifndef INT8_MIN
@@ -83,8 +84,6 @@ typedef unsigned int flex_uint32_t;
 #ifndef UINT32_MAX
 #define UINT32_MAX             (4294967295U)
 #endif
-
-#endif /* ! C99 */
 
 #endif /* ! FLEXINT_H */
 
@@ -159,15 +158,7 @@ typedef void* yyscan_t;
 
 /* Size of default input buffer. */
 #ifndef YY_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k.
- * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
- * Ditto for the __ia64__ case accordingly.
- */
-#define YY_BUF_SIZE 32768
-#else
 #define YY_BUF_SIZE 16384
-#endif /* __ia64__ */
 #endif
 
 /* The state buf must be large enough to hold one state per character in the main buffer.
@@ -496,7 +487,7 @@ void xlu__cfg_yyset_column(int  column_n
 void xlu__cfg_yyset_column(int  column_no, yyscan_t yyscanner);
 
 
-#line 500 "libxlu_cfg_l.c"
+#line 491 "libxlu_cfg_l.c"
 
 #define INITIAL 0
 #define lexerr 1
@@ -632,12 +623,7 @@ static int input (yyscan_t yyscanner );
 
 /* Amount of stuff to slurp up with each read. */
 #ifndef YY_READ_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k */
-#define YY_READ_BUF_SIZE 16384
-#else
 #define YY_READ_BUF_SIZE 8192
-#endif /* __ia64__ */
 #endif
 
 /* Copy whatever the last rule matched to the standard output. */
@@ -645,7 +631,7 @@ static int input (yyscan_t yyscanner );
 /* This used to be an fputs(), but since the string might contain NUL's,
  * we now use fwrite().
  */
-#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#define ECHO fwrite( yytext, yyleng, 1, yyout )
 #endif
 
 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
@@ -656,7 +642,7 @@ static int input (yyscan_t yyscanner );
 	if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
 		{ \
 		int c = '*'; \
-		size_t n; \
+		int n; \
 		for ( n = 0; n < max_size && \
 			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
 			buf[n] = (char) c; \
@@ -744,7 +730,7 @@ YY_DECL
 #line 37 "libxlu_cfg_l.l"
 
 
-#line 748 "libxlu_cfg_l.c"
+#line 734 "libxlu_cfg_l.c"
 
     yylval = yylval_param;
 
@@ -944,7 +930,7 @@ YY_RULE_SETUP
 #line 82 "libxlu_cfg_l.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
 	YY_BREAK
-#line 948 "libxlu_cfg_l.c"
+#line 934 "libxlu_cfg_l.c"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(lexerr):
 	yyterminate();
@@ -1687,8 +1673,8 @@ YY_BUFFER_STATE xlu__cfg_yy_scan_string 
 
 /** Setup the input buffer state to scan the given bytes. The next call to xlu__cfg_yylex() will
  * scan from a @e copy of @a bytes.
- * @param yybytes the byte buffer to scan
- * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ * @param bytes the byte buffer to scan
+ * @param len the number of bytes in the buffer pointed to by @a bytes.
  * @param yyscanner The scanner object.
  * @return the newly allocated buffer state object.
  */
tools/libxl/libxlu_cfg_l.h +2 -16
diff -r f501dd7581e2 tools/libxl/libxlu_cfg_l.h
@@ -58,6 +58,7 @@ typedef unsigned char flex_uint8_t;
 typedef unsigned char flex_uint8_t; 
 typedef unsigned short int flex_uint16_t;
 typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
 
 /* Limits of integral types. */
 #ifndef INT8_MIN
@@ -87,8 +88,6 @@ typedef unsigned int flex_uint32_t;
 #ifndef UINT32_MAX
 #define UINT32_MAX             (4294967295U)
 #endif
-
-#endif /* ! C99 */
 
 #endif /* ! FLEXINT_H */
 
@@ -132,15 +131,7 @@ typedef void* yyscan_t;
 
 /* Size of default input buffer. */
 #ifndef YY_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k.
- * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
- * Ditto for the __ia64__ case accordingly.
- */
-#define YY_BUF_SIZE 32768
-#else
 #define YY_BUF_SIZE 16384
-#endif /* __ia64__ */
 #endif
 
 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
@@ -310,12 +301,7 @@ static int yy_flex_strlen (yyconst char 
 
 /* Amount of stuff to slurp up with each read. */
 #ifndef YY_READ_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k */
-#define YY_READ_BUF_SIZE 16384
-#else
 #define YY_READ_BUF_SIZE 8192
-#endif /* __ia64__ */
 #endif
 
 /* Number of entries by which start-condition stack grows. */
@@ -352,6 +338,6 @@ extern int xlu__cfg_yylex \
 
 #line 82 "libxlu_cfg_l.l"
 
-#line 356 "libxlu_cfg_l.h"
+#line 342 "libxlu_cfg_l.h"
 #undef xlu__cfg_yyIN_HEADER
 #endif /* xlu__cfg_yyHEADER_H */
tools/libxl/xl.h +6 -0
diff -r f501dd7581e2 tools/libxl/xl.h
@@ -79,6 +79,12 @@ int main_network2attach(int argc, char *
 int main_network2attach(int argc, char **argv);
 int main_network2list(int argc, char **argv);
 int main_network2detach(int argc, char **argv);
+int main_poolcreate(int argc, char **argv);
+int main_poollist(int argc, char **argv);
+int main_pooldestroy(int argc, char **argv);
+int main_poolcpuadd(int argc, char **argv);
+int main_poolcpuremove(int argc, char **argv);
+int main_poolmigrate(int argc, char **argv);
 
 void help(char *command);
 
tools/libxl/xl_cmdimpl.c +459 -12

528 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +35 -0
diff -r f501dd7581e2 tools/libxl/xl_cmdtable.c
@@ -338,6 +338,41 @@ struct cmd_spec cmd_table[] = {
       "destroy a domain's version 2 virtual network device",
       "<Domain> <DevId>",
     },
+    { "pool-create",
+      &main_poolcreate,
+      "Create a CPU pool based an ConfigFile",
+      "[options] <ConfigFile> [vars]",
+      "-h, --help                   Print this help.\n"
+      "-f=FILE, --defconfig=FILE    Use the given configuration file.\n"
+      "-n, --dryrun                 Dry run - prints the resulting configuration."
+    },
+    { "pool-list",
+      &main_poollist,
+      "List CPU pools on host",
+      "[-l|--long] [-c|--cpus] [<CPU Pool>]",
+      "-l, --long                     Output all CPU pool details.\n"
+      "-c, --cpus                     Output list of CPUs used by a pool"
+    },
+    { "pool-destroy",
+      &main_pooldestroy,
+      "Deactivates a CPU pool",
+      "<CPU Pool>",
+    },
+    { "pool-cpu-add",
+      &main_poolcpuadd,
+      "Adds a CPU to a CPU pool",
+      "<CPU Pool> <CPU nr>",
+    },
+    { "pool-cpu-remove",
+      &main_poolcpuremove,
+      "Removes a CPU from a CPU pool",
+      "<CPU Pool> <CPU nr>",
+    },
+    { "pool-migrate",
+      &main_poolmigrate,
+      "Moves a domain into a CPU pool",
+      "<Domain> <CPU Pool>",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
tools/python/xen/lowlevel/xl/xl.c +10 -0
diff -r f501dd7581e2 tools/python/xen/lowlevel/xl/xl.c
@@ -208,6 +208,11 @@ int attrib__libxl_cpuid_policy_list_set(
     return -1;
 }
 
+int attrib__uint64_t_ptr_set(PyObject *v, uint64_t * *pptr)
+{
+    return -1;
+}
+
 int attrib__libxl_cpumap_set(PyObject *v, libxl_cpumap *pptr)
 {
     return -1;
@@ -254,6 +259,11 @@ int attrib__struct_in_addr_set(PyObject 
 }
 
 PyObject *attrib__libxl_cpuid_policy_list_get(libxl_cpuid_policy_list *pptr)
+{
+    return NULL;
+}
+
+PyObject *attrib__uint64_t_ptr_get(uint64_t * *pptr)
 {
     return NULL;
 }

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Not a new issue with this series but is there documentation for the pool configuration file format or an example somewhere? If not could you maybe add an example at some point (e.g. under tools/examples)?

Quoted 1 line · Juergen Gross
Signed-off-by [email protected]

Should go after the comment...

Quoted 9 lines

Support of cpu pools in xl:
library functions
xl pool-create
xl pool-list
xl pool-destroy
xl pool-cpu-add
xl pool-cpu-remove
xl pool-migrate
Renamed all cpu pool related names to *cpupool*

But not the actual xl command names -- I presume this is for xm compatibility, which is shame but unavoidable I suppose.

Quoted 22 lines

diff -r f501dd7581e2 tools/libxl/libxl.c

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +3 -4
@@ -607,10 +607,10 @@ int libxl_domain_info(libxl_ctx *ctx, li
     return 0;
 }
 
-libxl_poolinfo * libxl_list_pool(libxl_ctx *ctx, int *nb_pool)
+libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx *ctx, int *nb_pool)
 {
-    libxl_poolinfo *ptr;
-    int i;
+    libxl_cpupoolinfo *ptr;
+    int i, m;
     xc_cpupoolinfo_t *info;
     uint32_t poolid;
     libxl_physinfo physinfo;
@@ -627,12 +627,19 @@ libxl_poolinfo * libxl_list_pool(libxl_c
         info = xc_cpupool_getinfo(ctx->xch, poolid);
         if (info == NULL)
             break;
-        ptr = realloc(ptr, (i + 1) * sizeof(libxl_poolinfo));

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 libxl_poolinfo * libxl_list_pool(libxl_c · line 639

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +5 -0
+        ptr = realloc(ptr, (i + 1) * sizeof(libxl_cpupoolinfo));
         if (!ptr) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpupool info");
             return NULL;
         }
         ptr[i].poolid = info->cpupool_id;
+        ptr[i].sched_id = info->sched_id;
+        ptr[i].n_dom = info->n_dom;
+        if (libxl_cpumap_alloc(&ptr[i].cpumap, physinfo.max_cpu_id + 1))
+            break;

Ah, here's the user of physinfo I couldn't find in the previous patch!

Why isn't this just using "info->cpumap_size * sizeof(*info->cpumap)" though? (I have a feeling I asked this before but I can't find the question or answer in the thread anywhere so maybe I just thought about it).

I have a feeling that most users of these interfaces are more interested in the number of CPUs represented by the cpumap rather than the number of bytes which happen to be needed to represent them. Perhaps this is something you could look at while changing the map to uint8_t?

Quoted 9 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +5 -0
@@ -3659,3 +3664,180 @@ void libxl_file_reference_destroy(libxl_
     libxl__file_reference_unmap(f);
     free(f->path);
 }
+
+int libxl_get_freecpus(libxl_ctx *ctx, libxl_cpumap *cpumap)
+{
+    libxl_physinfo info;
+    int ret;

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3681

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+
+    if (libxl_get_physinfo(ctx, &info) != 0)
+        return ERROR_FAIL;
+
+    ret = libxl_cpumap_alloc(cpumap, info.max_cpu_id + 1);
+    if (ret)
+        return ret;
+
+    if (xc_cpupool_freeinfo(ctx->xch, cpumap->map, cpumap->size)) {
+        free(cpumap->map);

This should be libxl_cpumap_destroy(&cpumap).

Quoted 20 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +20 -0
+        cpumap->map = NULL;
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
+int libxl_create_cpupool(libxl_ctx *ctx, char *name, int schedid,
+                         libxl_cpumap cpumap, libxl_uuid *uuid,
+                         uint32_t *poolid)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc;
+    int i;
+    xs_transaction_t t;
+    char *uuid_string;
+
+    uuid_string = libxl__uuid2string(&gc, *uuid);
+    if (!uuid_string)
+        return ERROR_NOMEM;

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3711

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+
+    rc = xc_cpupool_create(ctx->xch, poolid, schedid);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+           "Could not create cpupool");
+        return ERROR_FAIL;
+    }
+
+    for (i = 0; i < cpumap.size * 8; i++)
+        if (cpumap.map[i / 64] & (1L << (i % 64))) {

I see a lot of this sort of thing in various places, perhaps it is worth (later, not now) having an iterator in the style of the Linux foreach_* macros? e.g.

	xl_cpumap_foreach_present(cpumap, i) {
		rc = xc_cpupool_addcpu(ctx->xch, *poolid, i);
		...
	}

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3716

Quoted 5 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +5 -0
+            rc = xc_cpupool_addcpu(ctx->xch, *poolid, i);
+            if (rc) {
+                LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+                    "Error moving cpu to cpupool");
+                return ERROR_FAIL;

I guess it's a toss up whether this should destroy the partially created pool or not.

Quoted 4 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +4 -0
+            }
+        }
+
+    for (;;) {

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3730

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+        t = xs_transaction_start(ctx->xsh);
+
+        xs_mkdir(ctx->xsh, t, libxl__sprintf(&gc, "/local/pool/%d", *poolid));
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "/local/pool/%d/uuid", *poolid),
+                 uuid_string);
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "/local/pool/%d/name", *poolid),
+                 name);
+
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))
+            return 0;

Does this return success on failure with errno != EAGAIN?

Quoted 11 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +11 -0
+    }
+}
+
+int libxl_destroy_cpupool(libxl_ctx *ctx, uint32_t poolid)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc, i;
+    xc_cpupoolinfo_t *info;
+    xs_transaction_t t;
+
+    info = xc_cpupool_getinfo(ctx->xch, poolid);

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3751

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+    if (info == NULL)
+        return ERROR_NOMEM;
+
+    rc = ERROR_INVAL;
+    if ((info->cpupool_id != poolid) || (info->n_dom))
+        goto out;
+
+    for (i = 0; i < info->cpumap_size; i++)
+        if (info->cpumap[i / 64] & (1L << (i % 64))) {
+            rc = xc_cpupool_removecpu(ctx->xch, poolid, i);

I take it this is necessary and that destroying a pool doesn't implicitly remove all CPUs from the pool?

Quoted 12 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +12 -0
+            if (rc) {
+                LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+                    "Error removing cpu from cpupool");
+                rc = ERROR_FAIL;
+                goto out;
+            }
+        }
+
+    rc = xc_cpupool_destroy(ctx->xch, poolid);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "Could not destroy cpupool");
+        rc = ERROR_FAIL;

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3773

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+        goto out;
+    }
+
+    for (;;) {
+        t = xs_transaction_start(ctx->xsh);
+
+        xs_rm(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "/local/pool/%d", poolid));
+
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))
+            break;

Same comment wrt failure with errno != EAGAIN.

Quoted 19 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +19 -0
+int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc;
+    char *dom_path;
+    char *vm_path;
+    char *poolname;
+    xs_transaction_t t;
+
+    dom_path = libxl__xs_get_dompath(&gc, domid);
+    if (!dom_path) {
+        return ERROR_FAIL;
+    }
+
+    rc = xc_cpupool_movedomain(ctx->xch, poolid, domid);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+            "Error moving domain to cpupool");
+        return ERROR_FAIL;

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3802

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+    }
+
+    poolname = libxl__cpupoolid_to_name(&gc, poolid);
+    vm_path = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/vm", dom_path));
+    for (; vm_path;) {
+        t = xs_transaction_start(ctx->xsh);
+
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "%s/pool_name", vm_path), poolname);
+
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))

errno != EGAIN handling again.

Have you thought about possible races here? Is it possible that the reads of vm_path and poolname need to be under the transaction to avoid races with other operations renaming the pool or migrating the guest etc?

Quoted 59 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +55 -0
@@ -5168,3 +5174,444 @@ int main_tmem_freeable(int argc, char **
     printf("%d\n", mb);
     return 0;
 }
+
+int main_poolcreate(int argc, char **argv)
+{
+    char *filename = NULL;
+    char *p, extra_config[1024];
+    int dryrun = 0;
+    int opt;
+    int option_index = 0;
+    static struct option long_options[] = {
+        {"help", 0, 0, 'h'},
+        {"defconfig", 1, 0, 'f'},
+        {"dryrun", 0, 0, 'n'},
+        {0, 0, 0, 0}
+    };
+    int ret;
+    void *config_data = 0;
+    int config_len = 0;
+    XLU_Config *config;
+    const char *buf;
+    char *name, *sched;
+    uint32_t poolid;
+    int schedid = -1;
+    XLU_ConfigList *cpus;
+    int n_cpus, i, n;
+    libxl_cpumap freemap;
+    libxl_cpumap cpumap;
+    libxl_uuid uuid;
+
+    while (1) {
+        opt = getopt_long(argc, argv, "hnf:", long_options, &option_index);
+        if (opt == -1)
+            break;
+
+        switch (opt) {
+        case 'f':
+            filename = optarg;
+            break;
+        case 'h':
+            help("pool-create");
+            return 0;
+        case 'n':
+            dryrun = 1;
+            break;
+        default:
+            fprintf(stderr, "option not supported\n");
+            break;
+        }
+    }
+
+    memset(extra_config, 0, sizeof(extra_config));
+    while (optind < argc) {
+        if ((p = strchr(argv[optind], '='))) {
+            if (strlen(extra_config) + 1 < sizeof(extra_config)) {
+                if (strlen(extra_config))
+                    strcat(extra_config, "\n");

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 int main_tmem_freeable(int argc, char ** · line 5241

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+                strcat(extra_config, argv[optind]);
+            }
+        } else if (!filename) {
+            filename = argv[optind];
+        } else {
+            help("pool-create");
+            return -ERROR_FAIL;
+        }
+        optind++;
+    }

Move this loop until after libxl_read_file_contents so you can add the items directly to the end of the data along with the reallocs and therefore avoid the 1024 character limitation?

Quoted 9 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +9 -0
+
+    if (!filename) {
+        help("pool-create");
+        return -ERROR_FAIL;
+    }
+
+    if (libxl_read_file_contents(&ctx, filename, &config_data, &config_len)) {
+        fprintf(stderr, "Failed to read config file: %s: %s\n",
+                filename, strerror(errno));

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 int main_tmem_freeable(int argc, char ** · line 5260

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+        return -ERROR_FAIL;
+    }
+    if (strlen(extra_config)) {
+        if (config_len > INT_MAX - (strlen(extra_config) + 2)) {
+            fprintf(stderr, "Failed to attach extra configration\n");
+            return -ERROR_FAIL;
+        }
+        config_data = realloc(config_data,
+                              config_len + strlen(extra_config) + 2);
+        if (!config_data) {

Leaks previous config_data on failure, need to use a temporary variable.

Quoted 59 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +59 -0
+int main_poollist(int argc, char **argv)
+{
+    int opt;
+    int option_index = 0;
+    static struct option long_options[] = {
+        {"help", 0, 0, 'h'},
+        {"long", 0, 0, 'l'},
+        {"cpus", 0, 0, 'c'},
+        {0, 0, 0, 0}
+    };
+    int opt_long = 0;
+    int opt_cpus = 0;
+    char *pool = NULL;
+    libxl_cpupoolinfo *poolinfo;
+    int n_pools, p, c, n;
+    uint32_t poolid;
+    char *name;
+    int ret = 0;
+
+    while (1) {
+        opt = getopt_long(argc, argv, "hlc", long_options, &option_index);
+        if (opt == -1)
+            break;
+
+        switch (opt) {
+        case 'h':
+            help("pool-list");
+            return 0;
+        case 'l':
+            opt_long = 1;
+            break;
+        case 'c':
+            opt_cpus = 1;
+            break;
+        default:
+            fprintf(stderr, "option not supported\n");
+            break;
+        }
+    }
+
+    if ((optind + 1) < argc) {
+        help("pool-list");
+        return -ERROR_FAIL;
+    }
+    if (optind < argc) {
+        pool = argv[optind];
+        if (libxl_name_to_cpupoolid(&ctx, pool, &poolid)) {
+            fprintf(stderr, "Pool \'%s\' does not exist\n", pool);
+            return -ERROR_FAIL;
+        }
+    }
+
+    poolinfo = libxl_list_cpupool(&ctx, &n_pools);
+    if (!poolinfo) {
+        fprintf(stderr, "error getting cpupool info\n");
+        return -ERROR_NOMEM;
+    }
+
+    if (!opt_long) {

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 int main_tmem_freeable(int argc, char ** · line 5329

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+        printf("%-19s", "Name");
+        if (opt_cpus)
+            printf("CPU list\n");
+        else
+            printf("CPUs   Sched     Active   Domain count\n");
+    }
+
+    for (p = 0; p < n_pools; p++) {
+        if (!ret && (!pool || (poolinfo[p].poolid != poolid))) {
+            name = libxl_cpupoolid_to_name(&ctx, poolinfo[p].poolid);

Need to free name somewhere.

Quoted 45 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +45 -0
+            if (!name) {
+                fprintf(stderr, "error getting cpupool info\n");
+                ret = -ERROR_NOMEM;
+            }
+            else if (opt_long) {
+                ret = -ERROR_NI;
+            } else {
+                printf("%-19s", name);
+                n = 0;
+                for (c = 0; c < poolinfo[p].cpumap.size * 8; c++)
+                    if (poolinfo[p].cpumap.map[c / 64] & (1L << (c % 64))) {
+                        if (n && opt_cpus) printf(",");
+                        if (opt_cpus) printf("%d", c);
+                        n++;
+                    }
+                if (!opt_cpus) {
+                    printf("%3d %9s       y       %4d", n,
+                           libxl_schedid_to_name(&ctx, poolinfo[p].sched_id),
+                           poolinfo[p].n_dom);
+                }
+                printf("\n");
+            }
+        }
+        libxl_cpupoolinfo_destroy(poolinfo + p);
+    }
+
+    return ret;
+}
+
+int main_pooldestroy(int argc, char **argv)
+{
+    int opt;
+    char *pool;
+    uint32_t poolid;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("pool-destroy");
+            return 0;
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 int main_tmem_freeable(int argc, char ** · line 5384

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+
+    pool = argv[optind];
+    if (!pool) {
+        fprintf(stderr, "no cpupool specified\n");
+        help("pool-destroy");
+        return -ERROR_FAIL;
+    }
+
+    if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) ||
+        !libxl_cpupoolid_to_name(&ctx, poolid)) {

Given that cpupool_qualifier_to_cpupoolid basically == libxl_name_to_cpupoolid is there really any need to check the inverse before attempting to destroy the pool?

Ian.

#2 lore raw
Quoted 19 lines · Ian Campbell

Not a new issue with this series but is there documentation for the pool configuration file format or an example somewhere? If not could you maybe add an example at some point (e.g. under tools/examples)?

Quoted 1 line · Juergen Gross
Signed-off-by [email protected]

Should go after the comment...

Quoted 9 lines

Support of cpu pools in xl:
library functions
xl pool-create
xl pool-list
xl pool-destroy
xl pool-cpu-add
xl pool-cpu-remove
xl pool-migrate
Renamed all cpu pool related names to *cpupool*

Quoted 2 lines

But not the actual xl command names -- I presume this is for xm compatibility, which is shame but unavoidable I suppose.

Hmm. What about adding aliases for xm (xm cpupool-*) and using only the cpupool-* commands for xl?

Quoted 36 lines
Quoted 23 lines

diff -r f501dd7581e2 tools/libxl/libxl.c

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +3 -4
@@ -607,10 +607,10 @@ int libxl_domain_info(libxl_ctx *ctx, li
      return 0;
  }
 
-libxl_poolinfo * libxl_list_pool(libxl_ctx *ctx, int *nb_pool)
+libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx *ctx, int *nb_pool)
  {
-    libxl_poolinfo *ptr;
-    int i;
+    libxl_cpupoolinfo *ptr;
+    int i, m;
      xc_cpupoolinfo_t *info;
      uint32_t poolid;
      libxl_physinfo physinfo;
@@ -627,12 +627,19 @@ libxl_poolinfo * libxl_list_pool(libxl_c
          info = xc_cpupool_getinfo(ctx->xch, poolid);
          if (info == NULL)
              break;
-        ptr = realloc(ptr, (i + 1) * sizeof(libxl_poolinfo));

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 libxl_poolinfo * libxl_list_pool(libxl_c · line 639

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +5 -0
+        ptr = realloc(ptr, (i + 1) * sizeof(libxl_cpupoolinfo));
          if (!ptr) {
              LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpupool info");
              return NULL;
          }
          ptr[i].poolid = info->cpupool_id;
+        ptr[i].sched_id = info->sched_id;
+        ptr[i].n_dom = info->n_dom;
+        if (libxl_cpumap_alloc(&ptr[i].cpumap, physinfo.max_cpu_id + 1))
+            break;

Ah, here's the user of physinfo I couldn't find in the previous patch!

Quoted 4 lines

Why isn't this just using "info->cpumap_size * sizeof(*info->cpumap)" though? (I have a feeling I asked this before but I can't find the question or answer in the thread anywhere so maybe I just thought about it).

Changing to xc_get_max_cpus().

Quoted 5 lines

I have a feeling that most users of these interfaces are more interested in the number of CPUs represented by the cpumap rather than the number of bytes which happen to be needed to represent them. Perhaps this is something you could look at while changing the map to uint8_t?

I think this would make sense.

Quoted 14 lines
Quoted 14 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +9 -0
@@ -3659,3 +3664,180 @@ void libxl_file_reference_destroy(libxl_
      libxl__file_reference_unmap(f);
      free(f->path);
  }
+
+int libxl_get_freecpus(libxl_ctx *ctx, libxl_cpumap *cpumap)
+{
+    libxl_physinfo info;
+    int ret;
+
+    if (libxl_get_physinfo(ctx,&info) != 0)
+        return ERROR_FAIL;
+
Quoted 8 lines

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3681

Quoted 6 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +6 -0
+    ret = libxl_cpumap_alloc(cpumap, info.max_cpu_id + 1);
+    if (ret)
+        return ret;
+
+    if (xc_cpupool_freeinfo(ctx->xch, cpumap->map, cpumap->size)) {
+        free(cpumap->map);

This should be libxl_cpumap_destroy(&cpumap).

With the change of xc_cpupool_freeinfo() no need for free() any more.

Quoted 35 lines
Quoted 21 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +20 -0
+        cpumap->map = NULL;
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
+int libxl_create_cpupool(libxl_ctx *ctx, char *name, int schedid,
+                         libxl_cpumap cpumap, libxl_uuid *uuid,
+                         uint32_t *poolid)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc;
+    int i;
+    xs_transaction_t t;
+    char *uuid_string;
+
+    uuid_string = libxl__uuid2string(&gc, *uuid);
+    if (!uuid_string)
+        return ERROR_NOMEM;

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3711

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+
+    rc = xc_cpupool_create(ctx->xch, poolid, schedid);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+           "Could not create cpupool");
+        return ERROR_FAIL;
+    }
+
+    for (i = 0; i<  cpumap.size * 8; i++)
+        if (cpumap.map[i / 64]&  (1L<<  (i % 64))) {

I see a lot of this sort of thing in various places, perhaps it is worth (later, not now) having an iterator in the style of the Linux foreach_* macros? e.g.

Quoted 5 lines
	xl_cpumap_foreach_present(cpumap, i) {
		rc = xc_cpupool_addcpu(ctx->xch, *poolid, i);
		...
	}

I'll look into this when I change the cpumap type.

Quoted 8 lines

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3716

Quoted 5 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +5 -0
+            rc = xc_cpupool_addcpu(ctx->xch, *poolid, i);
+            if (rc) {
+                LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+                    "Error moving cpu to cpupool");
+                return ERROR_FAIL;

I guess it's a toss up whether this should destroy the partially created pool or not.

A call of libxl_destroy_cpupool() should do the job.

Quoted 17 lines
Quoted 5 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +4 -0
+            }
+        }
+
+    for (;;) {

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3730

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+        t = xs_transaction_start(ctx->xsh);
+
+        xs_mkdir(ctx->xsh, t, libxl__sprintf(&gc, "/local/pool/%d", *poolid));
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "/local/pool/%d/uuid", *poolid),
+                 uuid_string);
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "/local/pool/%d/name", *poolid),
+                 name);
+
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))
+            return 0;

Does this return success on failure with errno != EAGAIN?

Like lots of other libxl functions...
Missing xenstore entries seem not to be regarded as failures.

Quoted 17 lines
Quoted 17 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +16 -0
+    }
+}
+
+int libxl_destroy_cpupool(libxl_ctx *ctx, uint32_t poolid)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc, i;
+    xc_cpupoolinfo_t *info;
+    xs_transaction_t t;
+
+    info = xc_cpupool_getinfo(ctx->xch, poolid);
+    if (info == NULL)
+        return ERROR_NOMEM;
+
+    rc = ERROR_INVAL;
+    if ((info->cpupool_id != poolid) || (info->n_dom))
Quoted 8 lines

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3751

Quoted 5 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +5 -0
+        goto out;
+
+    for (i = 0; i<  info->cpumap_size; i++)
+        if (info->cpumap[i / 64]&  (1L<<  (i % 64))) {
+            rc = xc_cpupool_removecpu(ctx->xch, poolid, i);

I take it this is necessary and that destroying a pool doesn't implicitly remove all CPUs from the pool?

Not in the hypervisor. This is subject to the tools.

Quoted 17 lines
Quoted 17 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +16 -0
+            if (rc) {
+                LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+                    "Error removing cpu from cpupool");
+                rc = ERROR_FAIL;
+                goto out;
+            }
+        }
+
+    rc = xc_cpupool_destroy(ctx->xch, poolid);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "Could not destroy cpupool");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    for (;;) {
Quoted 8 lines

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3773

Quoted 6 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +6 -0
+        t = xs_transaction_start(ctx->xsh);
+
+        xs_rm(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "/local/pool/%d", poolid));
+
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))
+            break;

Same comment wrt failure with errno != EAGAIN.

Same answer as above :-)

Quoted 33 lines
Quoted 20 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +19 -0
+int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc;
+    char *dom_path;
+    char *vm_path;
+    char *poolname;
+    xs_transaction_t t;
+
+    dom_path = libxl__xs_get_dompath(&gc, domid);
+    if (!dom_path) {
+        return ERROR_FAIL;
+    }
+
+    rc = xc_cpupool_movedomain(ctx->xch, poolid, domid);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+            "Error moving domain to cpupool");
+        return ERROR_FAIL;

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 void libxl_file_reference_destroy(libxl_ · line 3802

Quoted 10 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +10 -0
+    }
+
+    poolname = libxl__cpupoolid_to_name(&gc, poolid);
+    vm_path = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/vm", dom_path));
+    for (; vm_path;) {
+        t = xs_transaction_start(ctx->xsh);
+
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "%s/pool_name", vm_path), poolname);
+
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))

errno != EGAIN handling again.

Quoted 4 lines

Have you thought about possible races here? Is it possible that the reads of vm_path and poolname need to be under the transaction to avoid races with other operations renaming the pool or migrating the guest etc?

Theoretically possible, yes.

Quoted 66 lines
Quoted 66 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +61 -0
@@ -5168,3 +5174,444 @@ int main_tmem_freeable(int argc, char **
      printf("%d\n", mb);
      return 0;
  }
+
+int main_poolcreate(int argc, char **argv)
+{
+    char *filename = NULL;
+    char *p, extra_config[1024];
+    int dryrun = 0;
+    int opt;
+    int option_index = 0;
+    static struct option long_options[] = {
+        {"help", 0, 0, 'h'},
+        {"defconfig", 1, 0, 'f'},
+        {"dryrun", 0, 0, 'n'},
+        {0, 0, 0, 0}
+    };
+    int ret;
+    void *config_data = 0;
+    int config_len = 0;
+    XLU_Config *config;
+    const char *buf;
+    char *name, *sched;
+    uint32_t poolid;
+    int schedid = -1;
+    XLU_ConfigList *cpus;
+    int n_cpus, i, n;
+    libxl_cpumap freemap;
+    libxl_cpumap cpumap;
+    libxl_uuid uuid;
+
+    while (1) {
+        opt = getopt_long(argc, argv, "hnf:", long_options,&option_index);
+        if (opt == -1)
+            break;
+
+        switch (opt) {
+        case 'f':
+            filename = optarg;
+            break;
+        case 'h':
+            help("pool-create");
+            return 0;
+        case 'n':
+            dryrun = 1;
+            break;
+        default:
+            fprintf(stderr, "option not supported\n");
+            break;
+        }
+    }
+
+    memset(extra_config, 0, sizeof(extra_config));
+    while (optind<  argc) {
+        if ((p = strchr(argv[optind], '='))) {
+            if (strlen(extra_config) + 1<  sizeof(extra_config)) {
+                if (strlen(extra_config))
+                    strcat(extra_config, "\n");
+                strcat(extra_config, argv[optind]);
+            }
+        } else if (!filename) {
+            filename = argv[optind];
+        } else {
+            help("pool-create");
Quoted 8 lines

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 int main_tmem_freeable(int argc, char ** · line 5241

Quoted 4 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +4 -0
+            return -ERROR_FAIL;
+        }
+        optind++;
+    }

Move this loop until after libxl_read_file_contents so you can add the items directly to the end of the data along with the reallocs and therefore avoid the 1024 character limitation?

The filename may be a result of this loop...

Quoted 14 lines
Quoted 14 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +13 -0
+
+    if (!filename) {
+        help("pool-create");
+        return -ERROR_FAIL;
+    }
+
+    if (libxl_read_file_contents(&ctx, filename,&config_data,&config_len)) {
+        fprintf(stderr, "Failed to read config file: %s: %s\n",
+                filename, strerror(errno));
+        return -ERROR_FAIL;
+    }
+    if (strlen(extra_config)) {
+        if (config_len>  INT_MAX - (strlen(extra_config) + 2)) {
Quoted 8 lines

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 int main_tmem_freeable(int argc, char ** · line 5260

Quoted 6 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +6 -0
+            fprintf(stderr, "Failed to attach extra configration\n");
+            return -ERROR_FAIL;
+        }
+        config_data = realloc(config_data,
+                              config_len + strlen(extra_config) + 2);
+        if (!config_data) {

Leaks previous config_data on failure, need to use a temporary variable.

Hmm. I had the impression xl isn't always free-ing all it's allocated memory...
Switching to xrealloc.

Quoted 64 lines
Quoted 64 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +63 -0
+int main_poollist(int argc, char **argv)
+{
+    int opt;
+    int option_index = 0;
+    static struct option long_options[] = {
+        {"help", 0, 0, 'h'},
+        {"long", 0, 0, 'l'},
+        {"cpus", 0, 0, 'c'},
+        {0, 0, 0, 0}
+    };
+    int opt_long = 0;
+    int opt_cpus = 0;
+    char *pool = NULL;
+    libxl_cpupoolinfo *poolinfo;
+    int n_pools, p, c, n;
+    uint32_t poolid;
+    char *name;
+    int ret = 0;
+
+    while (1) {
+        opt = getopt_long(argc, argv, "hlc", long_options,&option_index);
+        if (opt == -1)
+            break;
+
+        switch (opt) {
+        case 'h':
+            help("pool-list");
+            return 0;
+        case 'l':
+            opt_long = 1;
+            break;
+        case 'c':
+            opt_cpus = 1;
+            break;
+        default:
+            fprintf(stderr, "option not supported\n");
+            break;
+        }
+    }
+
+    if ((optind + 1)<  argc) {
+        help("pool-list");
+        return -ERROR_FAIL;
+    }
+    if (optind<  argc) {
+        pool = argv[optind];
+        if (libxl_name_to_cpupoolid(&ctx, pool,&poolid)) {
+            fprintf(stderr, "Pool \'%s\' does not exist\n", pool);
+            return -ERROR_FAIL;
+        }
+    }
+
+    poolinfo = libxl_list_cpupool(&ctx,&n_pools);
+    if (!poolinfo) {
+        fprintf(stderr, "error getting cpupool info\n");
+        return -ERROR_NOMEM;
+    }
+
+    if (!opt_long) {
+        printf("%-19s", "Name");
+        if (opt_cpus)
+            printf("CPU list\n");
+        else
Quoted 8 lines

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 int main_tmem_freeable(int argc, char ** · line 5329

Quoted 6 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +6 -0
+            printf("CPUs   Sched     Active   Domain count\n");
+    }
+
+    for (p = 0; p<  n_pools; p++) {
+        if (!ret&&  (!pool || (poolinfo[p].poolid != poolid))) {
+            name = libxl_cpupoolid_to_name(&ctx, poolinfo[p].poolid);

Need to free name somewhere.

I can do it, but I think there is much more work ahead for freeing all allocated memory in xl!

Quoted 52 lines
Quoted 52 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +51 -0
+            if (!name) {
+                fprintf(stderr, "error getting cpupool info\n");
+                ret = -ERROR_NOMEM;
+            }
+            else if (opt_long) {
+                ret = -ERROR_NI;
+            } else {
+                printf("%-19s", name);
+                n = 0;
+                for (c = 0; c<  poolinfo[p].cpumap.size * 8; c++)
+                    if (poolinfo[p].cpumap.map[c / 64]&  (1L<<  (c % 64))) {
+                        if (n&&  opt_cpus) printf(",");
+                        if (opt_cpus) printf("%d", c);
+                        n++;
+                    }
+                if (!opt_cpus) {
+                    printf("%3d %9s       y       %4d", n,
+                           libxl_schedid_to_name(&ctx, poolinfo[p].sched_id),
+                           poolinfo[p].n_dom);
+                }
+                printf("\n");
+            }
+        }
+        libxl_cpupoolinfo_destroy(poolinfo + p);
+    }
+
+    return ret;
+}
+
+int main_pooldestroy(int argc, char **argv)
+{
+    int opt;
+    char *pool;
+    uint32_t poolid;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("pool-destroy");
+            return 0;
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    pool = argv[optind];
+    if (!pool) {
+        fprintf(stderr, "no cpupool specified\n");
+        help("pool-destroy");
+        return -ERROR_FAIL;
Quoted 8 lines

tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 int main_tmem_freeable(int argc, char ** · line 5384

Quoted 4 lines
tools/libxl/libxl.c Fri Oct 01 09:12:27 2010 +0200 renamed from tools/libxl/libxl.c Fri Oct 01 09:03:51 2010 +0200 +4 -0
+    }
+
+    if (cpupool_qualifier_to_cpupoolid(pool,&poolid, NULL) ||
+        !libxl_cpupoolid_to_name(&ctx, poolid)) {

Given that cpupool_qualifier_to_cpupoolid basically == libxl_name_to_cpupoolid is there really any need to check the inverse before attempting to destroy the pool?

Yes.
cpupool_qualifier_to_cpupoolid() will always return 0 for any positive integer given to it (like domain_qualifier_to_domid()). This may be still no valid cpupoolid.

Juergen

Signature · 5 lines
Juergen Gross                 Principal Developer Operating Systems
TSP ES&S SWE OS6                       Telephone: +49 (0) 89 3222 2967
Fujitsu Technology Solutions              e-mail: [email protected]
Domagkstr. 28                           Internet: ts.fujitsu.com
D-80807 Muenchen                 Company details: ts.fujitsu.com/imprint.html
#3 lore raw
Quoted 7 lines · Juergen Gross
Quoted 4 lines
Quoted 1 line

Renamed all cpu pool related names to *cpupool*

But not the actual xl command names -- I presume this is for xm compatibility, which is shame but unavoidable I suppose.

Hmm. What about adding aliases for xm (xm cpupool-*) and using only the cpupool-* commands for xl?

I'm not sure, what do others on the list think of this?

Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
tools/libxl/libxl.c +4 -0
+            }
+        }
+
+    for (;;) {

tools/libxl/libxl.c void libxl_file_reference_destroy(libxl_ · line 3730

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+        t = xs_transaction_start(ctx->xsh);
+
+        xs_mkdir(ctx->xsh, t, libxl__sprintf(&gc, "/local/pool/%d", *poolid));
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "/local/pool/%d/uuid", *poolid),
+                 uuid_string);
+        libxl__xs_write(&gc, t, libxl__sprintf(&gc, "/local/pool/%d/name", *poolid),
+                 name);
+
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))
+            return 0;

Does this return success on failure with errno != EAGAIN?

Quoted 2 lines

Like lots of other libxl functions...
Missing xenstore entries seem not to be regarded as failures.

OK, I'm not sure what is considered correct here but if its the norm then fine.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
tools/libxl/xl_cmdimpl.c +3 -0
+
+int main_poolcreate(int argc, char **argv)
+{

[...]

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ while (1) {

[...]

Quoted 4 lines
    }
Quoted 3 lines
Quoted 3 lines
tools/libxl/xl_cmdimpl.c +3 -0
+
+    memset(extra_config, 0, sizeof(extra_config));
+    while (optind<  argc) {

[...]

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

+ }

Move this loop until after libxl_read_file_contents so you can add the items directly to the end of the data along with the reallocs and therefore avoid the 1024 character limitation?

The filename may be a result of this loop...

OK, it's consistent with xl create too so I guess even though it looks weird to me it must be ok ;-)

Quoted 4 lines
Quoted 1 line

Need to free name somewhere.

I can do it, but I think there is much more work ahead for freeing all allocated memory in xl!

Some of us have been actively working towards making xl free its memory correctly since it is a useful to have xl leak free in order to validate libxl which may be used by longer running toolstacks and hence better not leak!

I'd certainly like to avoid taking backward steps where possible.

Quoted 11 lines
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if (cpupool_qualifier_to_cpupoolid(pool,&poolid, NULL) ||
+        !libxl_cpupoolid_to_name(&ctx, poolid)) {

Given that cpupool_qualifier_to_cpupoolid basically == libxl_name_to_cpupoolid is there really any need to check the inverse before attempting to destroy the pool?

Yes.
cpupool_qualifier_to_cpupoolid() will always return 0 for any positive integer given to it (like domain_qualifier_to_domid()). This may be still no valid cpupoolid.

I see, cpupool_qualifier_to_cpupoolid is just a more clever strtoul-like function not an actual cpupoolid lookup function. No problem then.

Thanks,
Ian.