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 2 of 6] libxl: replace libxl__domain_is_hvm with libxl__domain_type
Date: Mon, 18 Jul 2011 10:06:29 +0100	[thread overview]
Message-ID: <8c7190363635ebae729f.1310979989@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 8c7190363635ebae729f5cf7f4ca254a0972326e
# Parent  3237f9de6c5053543fa13a7303a8c48733c58afd
libxl: replace libxl__domain_is_hvm with libxl__domain_type

New function returns a libxl_domain_type enum.

Add LIBXL__DOMAIN_IS_TYPE helper macro.

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

diff -r 3237f9de6c50 -r 8c7190363635 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
@@ -240,7 +240,7 @@ int libxl_domain_resume(libxl_ctx *ctx, 
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     int rc = 0;
 
-    if (libxl__domain_is_hvm(&gc, domid)) {
+    if (LIBXL__DOMAIN_IS_TYPE(&gc,  domid, HVM)) {
         LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Called domain_resume on "
                 "non-cooperative hvm domain %u", domid);
         rc = ERROR_NI;
@@ -474,7 +474,7 @@ int libxl_domain_suspend(libxl_ctx *ctx,
                          uint32_t domid, int fd)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
-    int hvm = libxl__domain_is_hvm(&gc, domid);
+    int hvm = LIBXL__DOMAIN_IS_TYPE(&gc,  domid, HVM);
     int live = info != NULL && info->flags & XL_SUSPEND_LIVE;
     int debug = info != NULL && info->flags & XL_SUSPEND_DEBUG;
     int rc = 0;
@@ -517,7 +517,7 @@ int libxl_domain_unpause(libxl_ctx *ctx,
     char *state;
     int ret, rc = 0;
 
-    if (libxl__domain_is_hvm(&gc, domid)) {
+    if (LIBXL__DOMAIN_IS_TYPE(&gc,  domid, HVM)) {
         path = libxl__sprintf(&gc, "/local/domain/0/device-model/%d/state", domid);
         state = libxl__xs_read(&gc, XBT_NULL, path);
         if (state != NULL && !strcmp(state, "paused")) {
@@ -560,7 +560,7 @@ int libxl_domain_shutdown(libxl_ctx *ctx
         return ERROR_FAIL;
     }
 
-    if (libxl__domain_is_hvm(&gc, domid)) {
+    if (LIBXL__DOMAIN_IS_TYPE(&gc,  domid, HVM)) {
         unsigned long pvdriver = 0;
         int ret;
         ret = xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_CALLBACK_IRQ, &pvdriver);
@@ -722,6 +722,7 @@ int libxl_domain_destroy(libxl_ctx *ctx,
     libxl_dominfo dominfo;
     char *dom_path;
     char *vm_path;
+    char *pid;
     int rc, dm_present;
 
     rc = libxl_domain_info(ctx, &dominfo, domid);
@@ -734,12 +735,16 @@ int libxl_domain_destroy(libxl_ctx *ctx,
         return rc;
     }
 
-    if (libxl__domain_is_hvm(&gc, domid)) {
+    switch (libxl__domain_type(&gc, domid)) {
+    case LIBXL_DOMAIN_TYPE_HVM:
         dm_present = 1;
-    } else {
-        char *pid;
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
         pid = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "/local/domain/%d/image/device-model-pid", domid));
         dm_present = (pid != NULL);
+        break;
+    default:
+        abort();
     }
 
     dom_path = libxl__xs_get_dompath(&gc, domid);
@@ -818,10 +823,16 @@ int libxl_primary_console_exec(libxl_ctx
         rc = libxl_console_exec(ctx, stubdomid,
                                 STUBDOM_CONSOLE_SERIAL, LIBXL_CONSOLE_TYPE_PV);
     else {
-        if (libxl__domain_is_hvm(&gc, domid_vm))
+        switch (libxl__domain_type(&gc, domid_vm)) {
+        case LIBXL_DOMAIN_TYPE_HVM:
             rc = libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSOLE_TYPE_SERIAL);
-        else
+            break;
+        case LIBXL_DOMAIN_TYPE_PV:
             rc = libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSOLE_TYPE_PV);
+            break;
+        default:
+            abort();
+        }
     }
     libxl__free_all(&gc);
     return rc;
diff -r 3237f9de6c50 -r 8c7190363635 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
@@ -35,7 +35,7 @@
 #include "libxl.h"
 #include "libxl_internal.h"
 
-int libxl__domain_is_hvm(libxl__gc *gc, uint32_t domid)
+libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     xc_domaininfo_t info;
@@ -46,7 +46,10 @@ int libxl__domain_is_hvm(libxl__gc *gc, 
         return -1;
     if (info.domain != domid)
         return -1;
-    return !!(info.flags & XEN_DOMINF_hvm_guest);
+    if (info.flags & XEN_DOMINF_hvm_guest)
+        return LIBXL_DOMAIN_TYPE_HVM;
+    else
+        return LIBXL_DOMAIN_TYPE_PV;
 }
 
 int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t domid)
diff -r 3237f9de6c50 -r 8c7190363635 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h	Mon Jul 18 09:38:45 2011 +0100
+++ b/tools/libxl/libxl_internal.h	Mon Jul 18 09:38:45 2011 +0100
@@ -167,9 +167,10 @@ _hidden char **libxl__xs_directory(libxl
    /* On error: returns NULL, sets errno (no logging) */
 
 /* from xl_dom */
-_hidden int libxl__domain_is_hvm(libxl__gc *gc, uint32_t domid);
+_hidden libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid);
 _hidden int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t domid);
-
+#define LIBXL__DOMAIN_IS_TYPE(gc, domid, type) \
+    libxl__domain_type((gc), (domid)) == LIBXL_DOMAIN_TYPE_##type
 typedef struct {
     uint32_t store_port;
     unsigned long store_mfn;
diff -r 3237f9de6c50 -r 8c7190363635 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c	Mon Jul 18 09:38:45 2011 +0100
+++ b/tools/libxl/libxl_pci.c	Mon Jul 18 09:38:45 2011 +0100
@@ -286,7 +286,7 @@ static int libxl__device_pci_add_xenstor
     if (!num_devs)
         return libxl__create_pci_backend(gc, domid, pcidev, 1);
 
-    if (!starting && !libxl__domain_is_hvm(gc, domid)) {
+    if (!starting && LIBXL__DOMAIN_IS_TYPE(gc, domid, PV)) {
         if (libxl__wait_for_backend(gc, be_path, "4") < 0)
             return ERROR_FAIL;
     }
@@ -329,7 +329,7 @@ static int libxl__device_pci_remove_xens
         return ERROR_INVAL;
     num = atoi(num_devs);
 
-    if (!libxl__domain_is_hvm(gc, domid)) {
+    if (LIBXL__DOMAIN_IS_TYPE(gc, domid, PV)) {
         if (libxl__wait_for_backend(gc, be_path, "4") < 0) {
             LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "pci backend at %s is not ready", be_path);
             return ERROR_FAIL;
@@ -357,7 +357,7 @@ retry_transaction:
         if (errno == EAGAIN)
             goto retry_transaction;
 
-    if (!libxl__domain_is_hvm(gc, domid)) {
+    if (LIBXL__DOMAIN_IS_TYPE(gc, domid, PV)) {
         if (libxl__wait_for_backend(gc, be_path, "4") < 0) {
             LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "pci backend at %s is not ready", be_path);
             return ERROR_FAIL;
@@ -604,10 +604,11 @@ static int do_pci_add(libxl__gc *gc, uin
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *path;
     char *state, *vdevfn;
-    int rc, hvm;
+    int rc, hvm = 0;
 
-    hvm = libxl__domain_is_hvm(gc, domid);
-    if (hvm) {
+    switch (libxl__domain_type(gc, domid)) {
+    case LIBXL_DOMAIN_TYPE_HVM:
+        hvm = 1;
         if (libxl__wait_for_device_model(gc, domid, "running",
                                          NULL, NULL, NULL) < 0) {
             return ERROR_FAIL;
@@ -635,7 +636,9 @@ static int do_pci_add(libxl__gc *gc, uin
         xs_write(ctx->xsh, XBT_NULL, path, state, strlen(state));
         if ( rc )
             return ERROR_FAIL;
-    } else {
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
+    {
         char *sysfs_path = libxl__sprintf(gc, SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->domain,
                                          pcidev->bus, pcidev->dev, pcidev->func);
         FILE *f = fopen(sysfs_path, "r");
@@ -694,6 +697,9 @@ static int do_pci_add(libxl__gc *gc, uin
         }
         fclose(f);
     }
+    default:
+        abort();
+    }
 out:
     if (!libxl_is_stubdom(ctx, domid, NULL)) {
         rc = xc_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev));
@@ -831,7 +837,7 @@ static int do_pci_remove(libxl__gc *gc, 
     libxl_device_pci *assigned;
     char *path;
     char *state;
-    int hvm, rc, num;
+    int hvm = 0, rc, num;
     int stubdomid = 0;
 
     if ( !libxl_device_pci_list_assigned(ctx, &assigned, domid, &num) ) {
@@ -842,8 +848,9 @@ static int do_pci_remove(libxl__gc *gc, 
         }
     }
 
-    hvm = libxl__domain_is_hvm(gc, domid);
-    if (hvm) {
+    switch (libxl__domain_type(gc, domid)) {
+    case LIBXL_DOMAIN_TYPE_HVM:
+        hvm = 1;
         if (libxl__wait_for_device_model(gc, domid, "running",
                                          NULL, NULL, NULL) < 0) {
             return ERROR_FAIL;
@@ -871,7 +878,9 @@ static int do_pci_remove(libxl__gc *gc, 
         }
         path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
         xs_write(ctx->xsh, XBT_NULL, path, state, strlen(state));
-    } else {
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
+    {
         char *sysfs_path = libxl__sprintf(gc, SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->domain,
                                          pcidev->bus, pcidev->dev, pcidev->func);
         FILE *f = fopen(sysfs_path, "r");
@@ -921,6 +930,9 @@ skip1:
         }
         fclose(f);
     }
+    default:
+        abort();
+    }
 out:
     /* don't do multiple resets while some functions are still passed through */
     if ( (pcidev->vdevfn & 0x7) == 0 ) {

  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         ` Ian Campbell [this message]
2011-07-18  9:06         ` [PATCH 3 of 6] libxl: specify HVM vs PV in build_info using libxl_domain_type enum Ian Campbell
2011-07-18  9:06         ` [PATCH 4 of 6] libxl: specify HVM vs PV in create_info " 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=8c7190363635ebae729f.1310979989@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.