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

[Xen-changelog] [xen-unstable] libxl: specify HVM vs PV in create_info using libxl_domain_type enum



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1310997150 -3600
# Node ID 4e872ffccc19a22bf8755c8c63ee2bccd5e20d5a
# Parent  30ab13a761c11dac58a4f8fb2ebf3d6f40b9c362
libxl: specify HVM vs PV in create_info using libxl_domain_type enum

Since libxl_init_build_info now needs an error return and a ctx (to
log to) switch all libxl_init_*_info to have an int return and a ctx.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
---


diff -r 30ab13a761c1 -r 4e872ffccc19 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl.h       Mon Jul 18 14:52:30 2011 +0100
@@ -250,9 +250,14 @@
 int libxl_ctx_postfork(libxl_ctx *ctx);
 
 /* domain related functions */
-void libxl_init_create_info(libxl_domain_create_info *c_info);
-void libxl_init_build_info(libxl_domain_build_info *b_info, 
libxl_domain_create_info *c_info);
-void libxl_init_dm_info(libxl_device_model_info *dm_info, 
libxl_domain_create_info *c_info, libxl_domain_build_info *b_info);
+int libxl_init_create_info(libxl_ctx *ctx, 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);
+int libxl_init_dm_info(libxl_ctx *ctx,
+                       libxl_device_model_info *dm_info,
+                       libxl_domain_create_info *c_info,
+                       libxl_domain_build_info *b_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 30ab13a761c1 -r 4e872ffccc19 tools/libxl/libxl.idl
--- a/tools/libxl/libxl.idl     Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl.idl     Mon Jul 18 14:52:30 2011 +0100
@@ -136,7 +136,7 @@
     ])
                                              
 libxl_domain_create_info = Struct("domain_create_info",[
-    ("hvm",          bool),
+    ("type",         libxl_domain_type),
     ("hap",          bool),
     ("oos",          bool),
     ("ssidref",      uint32),
diff -r 30ab13a761c1 -r 4e872ffccc19 tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c        Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl_create.c        Mon Jul 18 14:52:30 2011 +0100
@@ -60,19 +60,22 @@
     libxl_device_model_info_destroy(&d_config->dm_info);
 }
 
-void libxl_init_create_info(libxl_domain_create_info *c_info)
+int libxl_init_create_info(libxl_ctx *ctx, libxl_domain_create_info *c_info)
 {
     memset(c_info, '\0', sizeof(*c_info));
     c_info->xsdata = NULL;
     c_info->platformdata = NULL;
     c_info->hap = 1;
-    c_info->hvm = 1;
+    c_info->type = LIBXL_DOMAIN_TYPE_HVM;
     c_info->oos = 1;
     c_info->ssidref = 0;
     c_info->poolid = 0;
+    return 0;
 }
 
-void libxl_init_build_info(libxl_domain_build_info *b_info, 
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)
 {
     memset(b_info, '\0', sizeof(*b_info));
     b_info->max_vcpus = 1;
@@ -82,9 +85,10 @@
     b_info->disable_migrate = 0;
     b_info->cpuid = NULL;
     b_info->shadow_memkb = 0;
-    if (c_info->hvm) {
+    b_info->type = c_info->type;
+    switch (b_info->type) {
+    case LIBXL_DOMAIN_TYPE_HVM:
         b_info->video_memkb = 8 * 1024;
-        b_info->type = LIBXL_DOMAIN_TYPE_HVM;
         b_info->u.hvm.firmware = NULL;
         b_info->u.hvm.pae = 1;
         b_info->u.hvm.apic = 1;
@@ -95,14 +99,23 @@
         b_info->u.hvm.vpt_align = 1;
         b_info->u.hvm.timer_mode = 1;
         b_info->u.hvm.nested_hvm = 0;
-    } else {
-        b_info->type = LIBXL_DOMAIN_TYPE_PV;
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
         b_info->u.pv.slack_memkb = 8 * 1024;
+        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;
     }
+    return 0;
 }
 
-void libxl_init_dm_info(libxl_device_model_info *dm_info,
-        libxl_domain_create_info *c_info, libxl_domain_build_info *b_info)
+int libxl_init_dm_info(libxl_ctx *ctx,
+                       libxl_device_model_info *dm_info,
+                       libxl_domain_create_info *c_info,
+                       libxl_domain_build_info *b_info)
 {
     memset(dm_info, '\0', sizeof(*dm_info));
 
@@ -132,6 +145,7 @@
     dm_info->usb = 0;
     dm_info->usbdevice = NULL;
     dm_info->xen_platform_pci = 1;
+    return 0;
 }
 
 static int init_console_info(libxl_device_console *console, int dev_num)
@@ -316,9 +330,12 @@
         goto out;
     }
 
-    flags = info->hvm ? XEN_DOMCTL_CDF_hvm_guest : 0;
-    flags |= info->hap ? XEN_DOMCTL_CDF_hap : 0;
-    flags |= info->oos ? 0 : XEN_DOMCTL_CDF_oos_off;
+    flags = 0;
+    if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
+        flags |= XEN_DOMCTL_CDF_hvm_guest;
+        flags |= info->hap ? XEN_DOMCTL_CDF_hap : 0;
+        flags |= info->oos ? 0 : XEN_DOMCTL_CDF_oos_off;
+    }
     *domid = -1;
 
     /* Ultimately, handle is an array of 16 uint8_t, same as uuid */
@@ -432,7 +449,7 @@
         goto error_out;
     }
 
-    if ( !d_config->c_info.hvm && cb ) {
+    if ( d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV && cb ) {
         if ( (*cb)(ctx, domid, priv) )
             goto error_out;
     }
@@ -486,7 +503,9 @@
             goto error_out;
         }
     }
-    if (d_config->c_info.hvm) {
+    switch (d_config->c_info.type) {
+    case LIBXL_DOMAIN_TYPE_HVM:
+    {
         libxl_device_console console;
 
         ret = init_console_info(&console, 0);
@@ -505,7 +524,10 @@
                        "failed to create device model: %d", ret);
             goto error_out;
         }
-    } else {
+        break;
+    }
+    case LIBXL_DOMAIN_TYPE_PV:
+    {
         int need_qemu = 0;
         libxl_device_console console;
 
@@ -530,6 +552,11 @@
 
         if (need_qemu)
             libxl__create_xenpv_qemu(gc, domid, d_config->vfbs, &dm_starting);
+        break;
+    }
+    default:
+        ret = ERROR_INVAL;
+        goto error_out;
     }
 
     if (dm_starting) {
@@ -552,7 +579,8 @@
         goto error_out;
     }
 
-    if (!d_config->c_info.hvm && d_config->b_info.u.pv.e820_host) {
+    if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV &&
+        d_config->b_info.u.pv.e820_host) {
         int rc;
         rc = libxl__e820_alloc(ctx, domid, d_config);
         if (rc)
@@ -560,7 +588,9 @@
                       "Failed while collecting E820 with: %d (errno:%d)\n",
                       rc, errno);
     }
-    if ( cb && (d_config->c_info.hvm || d_config->b_info.u.pv.bootloader )) {
+    if ( cb && (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM ||
+                (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV &&
+                 d_config->b_info.u.pv.bootloader ))) {
         if ( (*cb)(ctx, domid, priv) )
             goto error_out;
     }
diff -r 30ab13a761c1 -r 4e872ffccc19 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c    Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl_dm.c    Mon Jul 18 14:52:30 2011 +0100
@@ -629,7 +629,7 @@
     }
 
     memset(&c_info, 0x00, sizeof(libxl_domain_create_info));
-    c_info.hvm = 0;
+    c_info.type = LIBXL_DOMAIN_TYPE_PV;
     c_info.name = libxl__sprintf(gc, "%s-dm", libxl__domid_to_name(gc, 
info->domid));
 
     libxl_uuid_copy(&c_info.uuid, &info->uuid);
diff -r 30ab13a761c1 -r 4e872ffccc19 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c   Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl_pci.c   Mon Jul 18 14:52:30 2011 +0100
@@ -1275,7 +1275,7 @@
     struct e820entry map[E820MAX];
     libxl_domain_build_info *b_info;
 
-    if (d_config == NULL || d_config->c_info.hvm)
+    if (d_config == NULL || d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM)
         return ERROR_INVAL;
 
     b_info = &d_config->b_info;
diff -r 30ab13a761c1 -r 4e872ffccc19 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Mon Jul 18 14:52:30 2011 +0100
@@ -300,7 +300,7 @@
 
     printf("(domain\n\t(domid %d)\n", domid);
     printf("\t(create_info)\n");
-    printf("\t(hvm %d)\n", c_info->hvm);
+    printf("\t(hvm %d)\n", c_info->type == LIBXL_DOMAIN_TYPE_HVM);
     printf("\t(hap %d)\n", c_info->hap);
     printf("\t(oos %d)\n", c_info->oos);
     printf("\t(ssidref %d)\n", c_info->ssidref);
@@ -333,14 +333,15 @@
     printf("\t(target_memkb %d)\n", b_info->target_memkb);
     printf("\t(nomigrate %d)\n", b_info->disable_migrate);
 
-    if (!c_info->hvm && b_info->u.pv.bootloader) {
+    if (c_info->type == LIBXL_DOMAIN_TYPE_PV && b_info->u.pv.bootloader) {
         printf("\t(bootloader %s)\n", b_info->u.pv.bootloader);
         if (b_info->u.pv.bootloader_args)
             printf("\t(bootloader_args %s)\n", b_info->u.pv.bootloader_args);
     }
 
     printf("\t(image\n");
-    if (c_info->hvm) {
+    switch (c_info->type) {
+    case LIBXL_DOMAIN_TYPE_HVM:
         printf("\t\t(hvm\n");
         printf("\t\t\t(firmware %s)\n", b_info->u.hvm.firmware);
         printf("\t\t\t(video_memkb %d)\n", b_info->video_memkb);
@@ -380,13 +381,18 @@
                     dm_info->spicedisable_ticketing);
         printf("\t\t\t(spiceagent_mouse %d)\n", dm_info->spiceagent_mouse);
         printf("\t\t)\n");
-    } else {
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
         printf("\t\t(linux %d)\n", 0);
         printf("\t\t\t(kernel %s)\n", b_info->u.pv.kernel.path);
         printf("\t\t\t(cmdline %s)\n", b_info->u.pv.cmdline);
         printf("\t\t\t(ramdisk %s)\n", b_info->u.pv.ramdisk.path);
         printf("\t\t\t(e820_host %d)\n", b_info->u.pv.e820_host);
         printf("\t\t)\n");
+        break;
+    default:
+        fprintf(stderr, "Unknown domain type %d\n", c_info->type);
+        exit(1);
     }
     printf("\t)\n");
 
@@ -453,7 +459,7 @@
         printf("\t\t)\n");
         printf("\t)\n");
     }
-       printf(")\n");
+    printf(")\n");
 }
 
 static int parse_action_on_shutdown(const char *buf, libxl_action_on_shutdown 
*a)
@@ -538,7 +544,8 @@
         exit(1);
     }
 
-    libxl_init_create_info(c_info);
+    if (libxl_init_create_info(ctx, c_info))
+        exit(1);
 
     if (!xlu_cfg_get_string (config, "seclabel", &buf)) {
         e = libxl_flask_context_to_sid(ctx, (char *)buf, strlen(buf),
@@ -553,10 +560,10 @@
         }
     }
 
-    c_info->hvm = 0;
+    c_info->type = LIBXL_DOMAIN_TYPE_PV;
     if (!xlu_cfg_get_string (config, "builder", &buf) &&
         !strncmp(buf, "hvm", strlen(buf)))
-        c_info->hvm = 1;
+        c_info->type = LIBXL_DOMAIN_TYPE_HVM;
 
     if (!xlu_cfg_get_long (config, "hap", &l))
         c_info->hap = l;
@@ -586,7 +593,8 @@
         exit(1);
     }
 
-    libxl_init_build_info(b_info, c_info);
+    if (libxl_init_build_info(ctx, b_info, c_info))
+        exit(1);
 
     /* the following is the actual config parsing with overriding values in 
the structures */
     if (!xlu_cfg_get_long (config, "vcpus", &l)) {
@@ -654,7 +662,8 @@
     if (!xlu_cfg_get_long (config, "gfx_passthru", &l))
         dm_info->gfx_passthru = l;
 
-    if (c_info->hvm == 1) {
+    switch(c_info->type) {
+    case LIBXL_DOMAIN_TYPE_HVM:
         if (!xlu_cfg_get_string (config, "kernel", &buf))
             fprintf(stderr, "WARNING: ignoring \"kernel\" directive for HVM 
guest. "
                     "Use \"firmware_override\" instead if you really want a 
non-default firmware\n");
@@ -679,7 +688,9 @@
             b_info->u.hvm.timer_mode = l;
         if (!xlu_cfg_get_long (config, "nestedhvm", &l))
             b_info->u.hvm.nested_hvm = l;
-    } else {
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
+    {
         char *cmdline = NULL;
         const char *root = NULL, *extra = "";
 
@@ -712,6 +723,10 @@
 
         b_info->u.pv.cmdline = cmdline;
         xlu_cfg_replace_string (config, "ramdisk", &b_info->u.pv.ramdisk.path);
+        break;
+    }
+    default:
+        abort();
     }
 
     if (!xlu_cfg_get_list (config, "disk", &vbds, 0, 0)) {
@@ -888,11 +903,16 @@
     /* To be reworked (automatically enabled) once the auto ballooning
      * after guest starts is done (with PCI devices passed in). */
     if (!xlu_cfg_get_long (config, "e820_host", &l)) {
-        if (c_info->hvm)
-          fprintf(stderr, "Can't do e820_host in HVM mode!");
-        else {
-          if (l)
-            b_info->u.pv.e820_host = true;
+        switch (c_info->type) {
+        case LIBXL_DOMAIN_TYPE_HVM:
+            fprintf(stderr, "Can't do e820_host in HVM mode!");
+            break;
+        case LIBXL_DOMAIN_TYPE_PV:
+            if (l)
+                b_info->u.pv.e820_host = true;
+            break;
+        default:
+            abort();
         }
     }
     if (!xlu_cfg_get_list (config, "pci", &pcis, 0, 0)) {
@@ -911,7 +931,7 @@
             if (!libxl_device_pci_parse_bdf(ctx, pcidev, buf))
                 d_config->num_pcidevs++;
         }
-        if (d_config->num_pcidevs && !c_info->hvm)
+        if (d_config->num_pcidevs && c_info->type == LIBXL_DOMAIN_TYPE_PV)
             b_info->u.pv.e820_host = true;
     }
 
@@ -994,12 +1014,13 @@
         break;
     }
 
-    if (c_info->hvm == 1) {
+    if (c_info->type == LIBXL_DOMAIN_TYPE_HVM) {
         XLU_ConfigList *dmargs;
         int nr_dmargs = 0;
 
         /* init dm from c and b */
-        libxl_init_dm_info(dm_info, c_info, b_info);
+        if (libxl_init_dm_info(ctx, dm_info, c_info, b_info))
+            exit(1);
 
         /* then process config related to dm */
         if (!xlu_cfg_get_string (config, "device_model", &buf)) {
@@ -1082,9 +1103,7 @@
         }
     }
 
-    dm_info->type = c_info->hvm ?
-        LIBXL_DOMAIN_TYPE_HVM :
-        LIBXL_DOMAIN_TYPE_PV;
+    dm_info->type = c_info->type;
 
     xlu_cfg_destroy(config);
 }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.