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

[Xen-devel] [PATCH 07 of 26 V3] libxl: provide _init and _setdefault for libxl_domain_build_info



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1330000276 0
# Node ID bd8a0016da72365006cc283276f6dd9fb16f68e9
# Parent  8052126f50e2dae878ad227a3f0e45cec193c19f
libxl: provide _init and _setdefault for libxl_domain_build_info.

Some fields require further scaffolding before they can use the
_init/_setdefault scheme and are handled in later patches.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 8052126f50e2 -r bd8a0016da72 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/libxl.c       Thu Feb 23 12:31:16 2012 +0000
@@ -2625,7 +2625,11 @@ int libxl_domain_need_memory(libxl_ctx *
                              uint32_t *need_memkb)
 {
     GC_INIT(ctx);
-    int rc = ERROR_INVAL;
+    int rc;
+
+    rc = libxl__domain_build_info_setdefault(gc, b_info);
+    if (rc) goto out;
+
     *need_memkb = b_info->target_memkb;
     switch (b_info->type) {
     case LIBXL_DOMAIN_TYPE_HVM:
@@ -2637,6 +2641,7 @@ int libxl_domain_need_memory(libxl_ctx *
         *need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY;
         break;
     default:
+        rc = ERROR_INVAL;
         goto out;
     }
     if (*need_memkb % (2 * 1024))
diff -r 8052126f50e2 -r bd8a0016da72 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/libxl.h       Thu Feb 23 12:31:16 2012 +0000
@@ -357,9 +357,8 @@ int libxl_ctx_postfork(libxl_ctx *ctx);
 
 /* domain related functions */
 void libxl_domain_create_info_init(libxl_domain_create_info *c_info);
-int libxl_init_build_info(libxl_ctx *ctx,
-                          libxl_domain_build_info *b_info,
-                          libxl_domain_create_info *c_info);
+void libxl_domain_build_info_init(libxl_domain_build_info *b_info,
+                          const libxl_domain_create_info *c_info);
 typedef int (*libxl_console_ready)(libxl_ctx *ctx, uint32_t domid, void *priv);
 int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, 
libxl_console_ready cb, void *priv, uint32_t *domid);
 int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, 
libxl_console_ready cb, void *priv, uint32_t *domid, int restore_fd);
diff -r 8052126f50e2 -r bd8a0016da72 tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c    Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/libxl_bootloader.c    Thu Feb 23 12:31:16 2012 +0000
@@ -346,6 +346,9 @@ int libxl_run_bootloader(libxl_ctx *ctx,
 
     struct stat st_buf;
 
+    rc = libxl__domain_build_info_setdefault(gc, info);
+    if (rc) goto out;
+
     if (info->type != LIBXL_DOMAIN_TYPE_PV || !info->u.pv.bootloader)
         goto out;
 
diff -r 8052126f50e2 -r bd8a0016da72 tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c        Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/libxl_create.c        Thu Feb 23 12:31:16 2012 +0000
@@ -66,16 +66,10 @@ int libxl__domain_create_info_setdefault
     return 0;
 }
 
-int libxl_init_build_info(libxl_ctx *ctx,
-                          libxl_domain_build_info *b_info,
-                          libxl_domain_create_info *c_info)
+void libxl_domain_build_info_init(libxl_domain_build_info *b_info,
+                                  const libxl_domain_create_info *c_info)
 {
     memset(b_info, '\0', sizeof(*b_info));
-    b_info->max_vcpus = 1;
-    b_info->cur_vcpus = 1;
-    if (libxl_cpumap_alloc(ctx, &b_info->cpumap))
-        return ERROR_NOMEM;
-    libxl_cpumap_set_any(&b_info->cpumap);
     b_info->max_memkb = 32 * 1024;
     b_info->target_memkb = b_info->max_memkb;
     b_info->disable_migrate = 0;
@@ -83,8 +77,6 @@ int libxl_init_build_info(libxl_ctx *ctx
     b_info->shadow_memkb = 0;
     b_info->type = c_info->type;
 
-    b_info->device_model_version =
-        LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
     b_info->device_model_stubdomain = false;
     b_info->device_model = NULL;
 
@@ -107,15 +99,9 @@ int libxl_init_build_info(libxl_ctx *ctx
 
         b_info->u.hvm.stdvga = 0;
         b_info->u.hvm.vnc.enable = 1;
-        b_info->u.hvm.vnc.listen = strdup("127.0.0.1");
         b_info->u.hvm.vnc.display = 0;
         b_info->u.hvm.vnc.findunused = 1;
-        b_info->u.hvm.keymap = NULL;
-        b_info->u.hvm.sdl.enable = 0;
-        b_info->u.hvm.sdl.opengl = 0;
-        b_info->u.hvm.nographic = 0;
         b_info->u.hvm.serial = NULL;
-        b_info->u.hvm.boot = strdup("cda");
         b_info->u.hvm.usb = 0;
         b_info->u.hvm.usbdevice = NULL;
         b_info->u.hvm.xen_platform_pci = 1;
@@ -124,7 +110,47 @@ int libxl_init_build_info(libxl_ctx *ctx
         b_info->u.pv.slack_memkb = 8 * 1024;
         break;
     default:
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+        abort();
+    }
+}
+
+int libxl__domain_build_info_setdefault(libxl__gc *gc,
+                                        libxl_domain_build_info *b_info)
+{
+    if (!b_info->device_model_version)
+        b_info->device_model_version =
+            LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
+
+    if (!b_info->max_vcpus)
+        b_info->max_vcpus = 1;
+    if (!b_info->cur_vcpus)
+        b_info->cur_vcpus = 1;
+
+    if (!b_info->cpumap.size) {
+        if (libxl_cpumap_alloc(CTX, &b_info->cpumap))
+            return ERROR_NOMEM;
+        libxl_cpumap_set_any(&b_info->cpumap);
+    }
+
+    switch (b_info->type) {
+    case LIBXL_DOMAIN_TYPE_HVM:
+        if (!b_info->u.hvm.boot) {
+            b_info->u.hvm.boot = strdup("cda");
+            if (!b_info->u.hvm.boot) return ERROR_NOMEM;
+        }
+
+        if (b_info->u.hvm.vnc.enable) {
+            if (!b_info->u.hvm.vnc.listen) {
+                b_info->u.hvm.vnc.listen = strdup("127.0.0.1");
+                if (!b_info->u.hvm.vnc.listen) return ERROR_NOMEM;
+            }
+        }
+
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
+        break;
+    default:
+        LIBXL__LOG(CTX, LIBXL__LOG_ERROR,
                    "invalid domain type %s in create info",
                    libxl_domain_type_to_string(b_info->type));
         return ERROR_INVAL;
@@ -487,6 +513,8 @@ static int do_domain_create(libxl__gc *g
             goto error_out;
     }
 
+    ret = libxl__domain_build_info_setdefault(gc, &d_config->b_info);
+    if (ret) goto error_out;
 
     for (i = 0; i < d_config->num_disks; i++) {
         ret = libxl__device_disk_set_backend(gc, &d_config->disks[i]);
diff -r 8052126f50e2 -r bd8a0016da72 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c    Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/libxl_dm.c    Thu Feb 23 12:31:16 2012 +0000
@@ -711,13 +711,12 @@ static int libxl__create_stubdom(libxl__
 
     libxl_uuid_generate(&dm_config.c_info.uuid);
 
-    memset(&dm_config.b_info, 0x00, sizeof(libxl_domain_build_info));
-    dm_config.b_info.type = dm_config.c_info.type;
+    libxl_domain_build_info_init(&dm_config.b_info, &dm_config.c_info);
+
     dm_config.b_info.max_vcpus = 1;
     dm_config.b_info.max_memkb = 32 * 1024;
     dm_config.b_info.target_memkb = dm_config.b_info.max_memkb;
 
-    dm_config.b_info.type = LIBXL_DOMAIN_TYPE_PV;
     dm_config.b_info.u.pv.kernel.path = libxl__abs_path(gc, "ioemu-stubdom.gz",
                                               libxl_xenfirmwaredir_path());
     dm_config.b_info.u.pv.cmdline = libxl__sprintf(gc, " -d %d", guest_domid);
@@ -740,6 +739,8 @@ static int libxl__create_stubdom(libxl__
 
     ret = libxl__domain_create_info_setdefault(gc, &dm_config.c_info);
     if (ret) goto out;
+    ret = libxl__domain_build_info_setdefault(gc, &dm_config.b_info);
+    if (ret) goto out;
 
     libxl__vfb_and_vkb_from_hvm_guest_config(gc, guest_config, &vfb, &vkb);
     dm_config.vfbs = &vfb;
diff -r 8052126f50e2 -r bd8a0016da72 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/libxl_internal.h      Thu Feb 23 12:31:16 2012 +0000
@@ -189,6 +189,8 @@ libxl__ev_xswatch *libxl__watch_slot_con
  */
 _hidden int libxl__domain_create_info_setdefault(libxl__gc *gc,
                                         libxl_domain_create_info *c_info);
+_hidden int libxl__domain_build_info_setdefault(libxl__gc *gc,
+                                        libxl_domain_build_info *b_info);
 
 struct libxl__evgen_domain_death {
     uint32_t domid;
diff -r 8052126f50e2 -r bd8a0016da72 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c  Thu Feb 23 12:31:16 2012 +0000
@@ -585,8 +585,7 @@ static void parse_config_data(const char
         exit(1);
     }
 
-    if (libxl_init_build_info(ctx, b_info, c_info))
-        exit(1);
+    libxl_domain_build_info_init(b_info, c_info);
 
     /* the following is the actual config parsing with overriding values in 
the structures */
     if (!xlu_cfg_get_long (config, "vcpus", &l, 0)) {
@@ -600,6 +599,11 @@ static void parse_config_data(const char
     if (!xlu_cfg_get_list (config, "cpus", &cpus, 0, 1)) {
         int i, n_cpus = 0;
 
+        if (libxl_cpumap_alloc(ctx, &b_info->cpumap)) {
+            fprintf(stderr, "Unable to allocate cpumap\n");
+            exit(1);
+        }
+
         libxl_cpumap_set_none(&b_info->cpumap);
         while ((buf = xlu_cfg_get_listitem(cpus, n_cpus)) != NULL) {
             i = atoi(buf);
@@ -614,6 +618,11 @@ static void parse_config_data(const char
     else if (!xlu_cfg_get_string (config, "cpus", &buf, 0)) {
         char *buf2 = strdup(buf);
 
+        if (libxl_cpumap_alloc(ctx, &b_info->cpumap)) {
+            fprintf(stderr, "Unable to allocate cpumap\n");
+            exit(1);
+        }
+
         libxl_cpumap_set_none(&b_info->cpumap);
         if (vcpupin_parse(buf2, &b_info->cpumap))
             exit(1);

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