libxl: provide _init and _setdefault for libxl_domain_build_info.
authorIan Campbell <ian.campbell@citrix.com>
Thu, 1 Mar 2012 12:26:13 +0000 (12:26 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 1 Mar 2012 12:26:13 +0000 (12:26 +0000)
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@citrix.com>
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/libxl_bootloader.c
tools/libxl/libxl_create.c
tools/libxl/libxl_dm.c
tools/libxl/libxl_internal.h
tools/libxl/xl_cmdimpl.c

index 53037885a4b67f808baafaf867c75ccd27dd4ce4..e6870879b0b5998857d7567ca1ced6a47b84c3ca 100644 (file)
@@ -2625,7 +2625,11 @@ int libxl_domain_need_memory(libxl_ctx *ctx, libxl_domain_build_info *b_info,
                              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 *ctx, libxl_domain_build_info *b_info,
         *need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY;
         break;
     default:
+        rc = ERROR_INVAL;
         goto out;
     }
     if (*need_memkb % (2 * 1024))
index 99f53c4872102db041e287d0e7c6528e9d0aeaf1..f14300945add8a04a5afca18ace7bc96084b45e7 100644 (file)
@@ -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);
index 907c871f65acea2538df2d6476b5202e552c508b..4afe1fb6ec9271f62db23c89b6038d95eba2393f 100644 (file)
@@ -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;
 
index 1c0bfb49130e14e8f0526d1ed6fd98ecf37e8862..9601df3a657bd6e2474d185baf439b475eca3036 100644 (file)
@@ -66,16 +66,10 @@ int libxl__domain_create_info_setdefault(libxl__gc *gc,
     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;
 
@@ -108,15 +100,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;
@@ -125,7 +111,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;
@@ -488,6 +514,8 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
             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]);
index 47a34d8061de1d4b416f885065f356a1354379a1..66894cb60a9ab2eedc92743efddd8cd9e25368ce 100644 (file)
@@ -713,13 +713,12 @@ static int libxl__create_stubdom(libxl__gc *gc,
 
     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);
@@ -742,6 +741,8 @@ static int libxl__create_stubdom(libxl__gc *gc,
 
     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;
index 5f927b62ed9b7780d03a477ccbcd8c33f8ef6664..81e309c3a3aa33936c785701d000bdb81215f5c6 100644 (file)
@@ -189,6 +189,8 @@ libxl__ev_xswatch *libxl__watch_slot_contents(libxl__gc *gc, int slotnum);
  */
 _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;
index 94f899d3dfc7e29020bc031a72d0c2c2b224a4d2..094bbe89b951bf2cd73c24ea80a4f85a372398f1 100644 (file)
@@ -584,8 +584,7 @@ static void parse_config_data(const char *configfile_filename_report,
         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)) {
@@ -599,6 +598,11 @@ static void parse_config_data(const char *configfile_filename_report,
     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);
@@ -613,6 +617,11 @@ static void parse_config_data(const char *configfile_filename_report,
     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);