All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: [PATCH 3 of 6] libxl: specify HVM vs PV in build_info using libxl_domain_type enum
Date: Mon, 18 Jul 2011 10:06:30 +0100	[thread overview]
Message-ID: <bd0ccd8f7e1370e78025.1310979990@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1310979987@localhost.localdomain>

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1310978325 -3600
# Node ID bd0ccd8f7e1370e78025084ea9ca3e4f04d7c6e0
# Parent  8c7190363635ebae729f5cf7f4ca254a0972326e
libxl: specify HVM vs PV in build_info using libxl_domain_type enum

Also caught one place (in libxl__domain_restore_common) which used
info->u.hvm.pae even if !hvm. (fortunately the value was unused in
xc_domain_restore).

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

diff -r 8c7190363635 -r bd0ccd8f7e13 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Mon Jul 18 09:38:45 2011 +0100
+++ b/tools/libxl/libxl.c	Mon Jul 18 09:38:45 2011 +0100
@@ -2036,17 +2036,27 @@ int libxl_domain_need_memory(libxl_ctx *
         libxl_device_model_info *dm_info, uint32_t *need_memkb)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc = ERROR_INVAL;
     *need_memkb = b_info->target_memkb;
-    if (b_info->hvm) {
+    switch (b_info->type) {
+    case LIBXL_DOMAIN_TYPE_HVM:
         *need_memkb += b_info->shadow_memkb + LIBXL_HVM_EXTRA_MEMORY;
         if (dm_info->device_model_stubdomain)
             *need_memkb += 32 * 1024;
-    } else
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
         *need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY;
+        break;
+    default:
+        goto out;
+    }
     if (*need_memkb % (2 * 1024))
         *need_memkb += (2 * 1024) - (*need_memkb % (2 * 1024));
+    rc = 0;
+out:
     libxl__free_all(&gc);
-    return 0;
+    return rc;
+
 }
 
 int libxl_get_free_memory(libxl_ctx *ctx, uint32_t *memkb)
diff -r 8c7190363635 -r bd0ccd8f7e13 tools/libxl/libxl.idl
--- a/tools/libxl/libxl.idl	Mon Jul 18 09:38:45 2011 +0100
+++ b/tools/libxl/libxl.idl	Mon Jul 18 09:38:45 2011 +0100
@@ -159,9 +159,9 @@ libxl_domain_build_info = Struct("domain
     ("shadow_memkb",    uint32),
     ("disable_migrate", bool),
     ("cpuid",           libxl_cpuid_policy_list),
-    ("hvm",             bool),
-    ("u", KeyedUnion(None, "hvm",
-                [("hvm", "%s", Struct(None,
+    ("type",            libxl_domain_type),
+    ("u", KeyedUnion(None, "type",
+                [("hvm", "%s == LIBXL_DOMAIN_TYPE_HVM", Struct(None,
                                        [("firmware", string),
                                         ("pae", bool),
                                         ("apic", bool),
@@ -174,7 +174,7 @@ libxl_domain_build_info = Struct("domain
                                         ("timer_mode", integer),
                                         ("nested_hvm", bool),
                                         ])),
-                 ("pv", "!%s", Struct(None,
+                 ("pv", "%s == LIBXL_DOMAIN_TYPE_PV", Struct(None,
                                        [("kernel", libxl_file_reference),
                                         ("slack_memkb", uint32),
                                         ("bootloader", string),
diff -r 8c7190363635 -r bd0ccd8f7e13 tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c	Mon Jul 18 09:38:45 2011 +0100
+++ b/tools/libxl/libxl_bootloader.c	Mon Jul 18 09:38:45 2011 +0100
@@ -323,7 +323,7 @@ int libxl_run_bootloader(libxl_ctx *ctx,
 
     struct stat st_buf;
 
-    if (info->hvm || !info->u.pv.bootloader)
+    if (info->type != LIBXL_DOMAIN_TYPE_PV || !info->u.pv.bootloader)
         goto out;
 
     rc = ERROR_INVAL;
diff -r 8c7190363635 -r bd0ccd8f7e13 tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c	Mon Jul 18 09:38:45 2011 +0100
+++ b/tools/libxl/libxl_create.c	Mon Jul 18 09:38:45 2011 +0100
@@ -84,7 +84,7 @@ void libxl_init_build_info(libxl_domain_
     b_info->shadow_memkb = 0;
     if (c_info->hvm) {
         b_info->video_memkb = 8 * 1024;
-        b_info->hvm = 1;
+        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;
@@ -96,6 +96,7 @@ void libxl_init_build_info(libxl_domain_
         b_info->u.hvm.timer_mode = 1;
         b_info->u.hvm.nested_hvm = 0;
     } else {
+        b_info->type = LIBXL_DOMAIN_TYPE_PV;
         b_info->u.pv.slack_memkb = 8 * 1024;
     }
 }
@@ -160,7 +161,8 @@ int libxl__domain_build(libxl__gc *gc,
 
     gettimeofday(&start_time, NULL);
 
-    if (info->hvm) {
+    switch (info->type) {
+    case LIBXL_DOMAIN_TYPE_HVM:
         ret = libxl__build_hvm(gc, domid, info, dm_info, state);
         if (ret)
             goto out;
@@ -172,7 +174,8 @@ int libxl__domain_build(libxl__gc *gc,
         vments[3] = "hvm";
         vments[4] = "start_time";
         vments[5] = libxl__sprintf(gc, "%lu.%02d", start_time.tv_sec,(int)start_time.tv_usec/10000);
-    } else {
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
         ret = libxl__build_pv(gc, domid, info, state);
         if (ret)
             goto out;
@@ -193,6 +196,10 @@ int libxl__domain_build(libxl__gc *gc,
             vments[i++] = "image/cmdline";
             vments[i++] = (char*) info->u.pv.cmdline;
         }
+        break;
+    default:
+        ret = ERROR_INVAL;
+        goto out;
     }
     ret = libxl__build_post(gc, domid, info, state, vments, localents);
 out:
@@ -219,7 +226,8 @@ static int domain_restore(libxl__gc *gc,
 
     gettimeofday(&start_time, NULL);
 
-    if (info->hvm) {
+    switch (info->type) {
+    case LIBXL_DOMAIN_TYPE_HVM:
         vments = libxl__calloc(gc, 7, sizeof(char *));
         vments[0] = "rtc/timeoffset";
         vments[1] = (info->u.hvm.timeoffset) ? info->u.hvm.timeoffset : "";
@@ -227,7 +235,8 @@ static int domain_restore(libxl__gc *gc,
         vments[3] = "hvm";
         vments[4] = "start_time";
         vments[5] = libxl__sprintf(gc, "%lu.%02d", start_time.tv_sec,(int)start_time.tv_usec/10000);
-    } else {
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
         vments = libxl__calloc(gc, 11, sizeof(char *));
         i = 0;
         vments[i++] = "image/ostype";
@@ -244,20 +253,24 @@ static int domain_restore(libxl__gc *gc,
             vments[i++] = "image/cmdline";
             vments[i++] = (char*) info->u.pv.cmdline;
         }
+        break;
+    default:
+        ret = ERROR_INVAL;
+        goto out;
     }
     ret = libxl__build_post(gc, domid, info, state, vments, localents);
     if (ret)
         goto out;
 
     dm_info->saved_state = NULL;
-    if (info->hvm) {
+    if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
         ret = asprintf(&dm_info->saved_state,
                        XC_DEVICE_MODEL_RESTORE_FILE".%d", domid);
         ret = (ret < 0) ? ERROR_FAIL : 0;
     }
 
 out:
-    if (!info->hvm) {
+    if (info->type == LIBXL_DOMAIN_TYPE_PV) {
         libxl__file_reference_unmap(&info->u.pv.kernel);
         libxl__file_reference_unmap(&info->u.pv.ramdisk);
     }
diff -r 8c7190363635 -r bd0ccd8f7e13 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c	Mon Jul 18 09:38:45 2011 +0100
+++ b/tools/libxl/libxl_dm.c	Mon Jul 18 09:38:45 2011 +0100
@@ -642,12 +642,13 @@ static int libxl__create_stubdom(libxl__
     b_info.max_vcpus = 1;
     b_info.max_memkb = 32 * 1024;
     b_info.target_memkb = b_info.max_memkb;
+
+    b_info.type = LIBXL_DOMAIN_TYPE_PV;
     b_info.u.pv.kernel.path = libxl__abs_path(gc, "ioemu-stubdom.gz",
                                               libxl_xenfirmwaredir_path());
     b_info.u.pv.cmdline = libxl__sprintf(gc, " -d %d", info->domid);
     b_info.u.pv.ramdisk.path = "";
     b_info.u.pv.features = "";
-    b_info.hvm = 0;
 
     /* fixme: this function can leak the stubdom if it fails */
 
diff -r 8c7190363635 -r bd0ccd8f7e13 tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c	Mon Jul 18 09:38:45 2011 +0100
+++ b/tools/libxl/libxl_dom.c	Mon Jul 18 09:38:45 2011 +0100
@@ -75,14 +75,14 @@ int libxl__build_pre(libxl__gc *gc, uint
     libxl_ctx *ctx = libxl__gc_owner(gc);
     xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
     xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + LIBXL_MAXMEM_CONSTANT);
-    if (!info->hvm)
+    if (info->type == LIBXL_DOMAIN_TYPE_PV)
         xc_domain_set_memmap_limit(ctx->xch, domid,
                 (info->max_memkb + info->u.pv.slack_memkb));
     xc_domain_set_tsc_info(ctx->xch, domid, info->tsc_mode, 0, 0, 0);
     if ( info->disable_migrate )
         xc_domain_disable_migrate(ctx->xch, domid);
 
-    if (info->hvm) {
+    if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
         unsigned long shadow;
         shadow = (info->shadow_memkb + 1023) / 1024;
         xc_shadow_control(ctx->xch, domid, XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, NULL, 0, &shadow, 0, NULL);
@@ -340,10 +340,25 @@ int libxl__domain_restore_common(libxl__
     libxl_ctx *ctx = libxl__gc_owner(gc);
     /* read signature */
     int rc;
+    int hvm, pae, superpages;
+    switch (info->type) {
+    case LIBXL_DOMAIN_TYPE_HVM:
+        hvm = 1;
+        superpages = 1;
+        pae = info->u.hvm.pae;
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
+        hvm = 0;
+        superpages = 0;
+        pae = 1;
+        break;
+    default:
+        return ERROR_INVAL;
+    }
     rc = xc_domain_restore(ctx->xch, fd, domid,
-                             state->store_port, &state->store_mfn,
-                             state->console_port, &state->console_mfn,
-                             info->hvm, info->u.hvm.pae, !!info->hvm);
+                           state->store_port, &state->store_mfn,
+                           state->console_port, &state->console_mfn,
+                           hvm, pae, superpages);
     if ( rc ) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "restoring domain");
         return ERROR_FAIL;
diff -r 8c7190363635 -r bd0ccd8f7e13 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Mon Jul 18 09:38:45 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Mon Jul 18 09:38:45 2011 +0100
@@ -381,7 +381,7 @@ static void printf_info(int domid,
         printf("\t\t\t(spiceagent_mouse %d)\n", dm_info->spiceagent_mouse);
         printf("\t\t)\n");
     } else {
-        printf("\t\t(linux %d)\n", b_info->hvm);
+        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);

  parent reply	other threads:[~2011-07-18  9:06 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-12 18:37 [RFC 0/3] libxl event handling Ian Jackson
2011-07-12 18:37 ` [PATCH 1/3] RFC: libxl: API changes re domain type (and keyed union semantics) Ian Jackson
2011-07-12 18:37   ` [PATCH 2/3] RFC: libxl: API changes re event handling Ian Jackson
2011-07-12 18:37     ` [PATCH 3/3] RFC: libxl: internal API for " Ian Jackson
2011-07-13 10:22       ` Ian Campbell
2011-07-13 10:21     ` [PATCH 2/3] RFC: libxl: API changes re " Ian Campbell
2011-07-13 14:03       ` Ian Jackson
2011-07-13 16:08         ` Ian Campbell
2011-07-13 16:17           ` Ian Jackson
2011-07-13 16:33             ` Ian Campbell
2011-07-13 17:04               ` Ian Jackson
2011-07-13  9:19   ` [PATCH 1/3] RFC: libxl: API changes re domain type (and keyed union semantics) Ian Campbell
2011-07-15 12:45   ` Ian Campbell
2011-07-15 13:13     ` Ian Jackson
2011-07-18  9:06       ` [PATCH 0 of 6] libxl: IDL improvements Ian Campbell
2011-07-18  9:06         ` [PATCH 1 of 6] libxl: Give the HVM domain type the name "HVM" Ian Campbell
2011-07-18  9:06         ` [PATCH 2 of 6] libxl: replace libxl__domain_is_hvm with libxl__domain_type Ian Campbell
2011-07-18  9:06         ` Ian Campbell [this message]
2011-07-18  9:06         ` [PATCH 4 of 6] libxl: specify HVM vs PV in create_info using libxl_domain_type enum Ian Campbell
2011-07-18  9:06         ` [PATCH 5 of 6] libxl: use libxl_domain_type enum with libxl__domain_suspend_common Ian Campbell
2011-07-18  9:06         ` [PATCH 6 of 6] libxl: Keyed unions key off an enum instead of an arbitrary expression Ian Campbell
2011-07-18 13:57       ` [PATCH 0 of 6 V2] libxl: IDL improvements Ian Campbell
2011-07-18 13:57         ` [PATCH 1 of 6 V2] libxl: Give the HVM domain type the name "HVM" Ian Campbell
2011-07-18 14:56           ` Wei LIU
2011-07-18 15:20             ` Ian Jackson
2011-07-18 13:57         ` [PATCH 2 of 6 V2] libxl: replace libxl__domain_is_hvm with libxl__domain_type Ian Campbell
2011-07-18 13:57         ` [PATCH 3 of 6 V2] libxl: specify HVM vs PV in build_info using libxl_domain_type enum Ian Campbell
2011-07-18 13:57         ` [PATCH 4 of 6 V2] libxl: specify HVM vs PV in create_info " Ian Campbell
2011-07-18 13:57         ` [PATCH 5 of 6 V2] libxl: use libxl_domain_type enum with libxl__domain_suspend_common Ian Campbell
2011-07-18 13:57         ` [PATCH 6 of 6 V2] libxl: Keyed unions key off an enum instead of an arbitrary expression Ian Campbell
2011-07-18 16:11         ` [PATCH 0 of 6 V2] libxl: IDL improvements Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bd0ccd8f7e1370e78025.1310979990@localhost.localdomain \
    --to=ian.campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.