xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Subject: [PATCH 20/21] libxl: further fixups re LIBXL_DOMAIN_TYPE
Date: Tue, 26 Jun 2012 18:55:17 +0100	[thread overview]
Message-ID: <1340733318-21099-21-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1340733318-21099-1-git-send-email-ian.jackson@eu.citrix.com>

* Abolish the macro LIBXL__DOMAIN_IS_TYPE which had incorrect error
  handling.  At every call site, replace it with an open-coded call to
  libxl_domain_type and check against LIBXL_DOMAIN_TYPE_INVALID.

* This involves adding an `out:' to libxl_domain_unpause.

* In libxl_domain_destroy and do_pci_add, do not `default: abort();'
  if the domain type cannot be found.  Instead switch on
  LIBXL_DOMAIN_TYPE_INVALID specifically and do some actual error
  handling.

* In libxl__primary_console_find, remove a spurious default clause
  from the domain type switch.

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

Changes in v5:
 * Add `default: abort()' to libxl__domain_type switch.

Changes in v4 of series:
 * Hunk
     In libxl_domain_suspend (as reorganised) error check, check for
     LIBXL_DOMAIN_TYPE_INVALID and remove a pointless extra log message.
   merged into the earlier patch where the slightly-wrong code was
   introduced.
---
 tools/libxl/libxl.c          |   28 +++++++++++++++++++++++-----
 tools/libxl/libxl_internal.h |    5 +++--
 tools/libxl/libxl_pci.c      |   18 +++++++++++++-----
 3 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 1a7404a..1b84398 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -390,7 +390,13 @@ int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid, int suspend_cancel)
         goto out;
     }
 
-    if (LIBXL__DOMAIN_IS_TYPE(gc,  domid, HVM)) {
+    libxl_domain_type type = libxl__domain_type(gc, domid);
+    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    if (type == LIBXL_DOMAIN_TYPE_HVM) {
         rc = libxl__domain_resume_device_model(gc, domid);
         if (rc) {
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
@@ -788,7 +794,13 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
     char *state;
     int ret, rc = 0;
 
-    if (LIBXL__DOMAIN_IS_TYPE(gc,  domid, HVM)) {
+    libxl_domain_type type = libxl__domain_type(gc, domid);
+    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    if (type == LIBXL_DOMAIN_TYPE_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")) {
@@ -802,6 +814,7 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unpausing domain %d", domid);
         rc = ERROR_FAIL;
     }
+ out:
     GC_FREE;
     return rc;
 }
@@ -813,7 +826,11 @@ int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid)
     unsigned long pvdriver = 0;
     int ret;
 
-    if (LIBXL__DOMAIN_IS_TYPE(gc, domid, PV))
+    libxl_domain_type domtype = libxl__domain_type(gc, domid);
+    if (domtype == LIBXL_DOMAIN_TYPE_INVALID)
+        return ERROR_FAIL;
+
+    if (domtype == LIBXL_DOMAIN_TYPE_PV)
         return 1;
 
     ret = xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_CALLBACK_IRQ, &pvdriver);
@@ -1213,6 +1230,9 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid)
         pid = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "/local/domain/%d/image/device-model-pid", domid));
         dm_present = (pid != NULL);
         break;
+    case LIBXL_DOMAIN_TYPE_INVALID:
+        rc = ERROR_FAIL;
+        goto out;
     default:
         abort();
     }
@@ -1362,8 +1382,6 @@ static int libxl__primary_console_find(libxl_ctx *ctx, uint32_t domid_vm,
         case LIBXL_DOMAIN_TYPE_INVALID:
             rc = ERROR_INVAL;
             goto out;
-        default:
-            abort();
         }
     }
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 9df0db5..36c75ed 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -797,8 +797,7 @@ _hidden int libxl__domain_cpupool(libxl__gc *gc, uint32_t domid);
 _hidden libxl_scheduler libxl__domain_scheduler(libxl__gc *gc, uint32_t domid);
 _hidden int libxl__sched_set_params(libxl__gc *gc, uint32_t domid,
                                     libxl_domain_sched_params *scparams);
-#define LIBXL__DOMAIN_IS_TYPE(gc, domid, type) \
-    libxl__domain_type((gc), (domid)) == LIBXL_DOMAIN_TYPE_##type
+
 typedef struct {
     uint32_t store_port;
     uint32_t store_domid;
@@ -841,7 +840,9 @@ _hidden int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid);
 
 _hidden void libxl__userdata_destroyall(libxl__gc *gc, uint32_t domid);
 
+/* returns 0 or 1, or a libxl error code */
 _hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid);
+
 _hidden char * libxl__domain_pvcontrol_read(libxl__gc *gc,
                                             xs_transaction_t t, uint32_t domid);
 _hidden int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t,
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index de1b79f..81438be 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -128,7 +128,11 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_d
     if (!num_devs)
         return libxl__create_pci_backend(gc, domid, pcidev, 1);
 
-    if (!starting && LIBXL__DOMAIN_IS_TYPE(gc, domid, PV)) {
+    libxl_domain_type domtype = libxl__domain_type(gc, domid);
+    if (domtype == LIBXL_DOMAIN_TYPE_INVALID)
+        return ERROR_FAIL;
+
+    if (!starting && domtype == LIBXL_DOMAIN_TYPE_PV) {
         if (libxl__wait_for_backend(gc, be_path, "4") < 0)
             return ERROR_FAIL;
     }
@@ -171,7 +175,11 @@ static int libxl__device_pci_remove_xenstore(libxl__gc *gc, uint32_t domid, libx
         return ERROR_INVAL;
     num = atoi(num_devs);
 
-    if (LIBXL__DOMAIN_IS_TYPE(gc, domid, PV)) {
+    libxl_domain_type domtype = libxl__domain_type(gc, domid);
+    if (domtype == LIBXL_DOMAIN_TYPE_INVALID)
+        return ERROR_FAIL;
+
+    if (domtype == LIBXL_DOMAIN_TYPE_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;
@@ -199,7 +207,7 @@ retry_transaction:
         if (errno == EAGAIN)
             goto retry_transaction;
 
-    if (LIBXL__DOMAIN_IS_TYPE(gc, domid, PV)) {
+    if (domtype == LIBXL_DOMAIN_TYPE_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;
@@ -939,8 +947,8 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i
         }
         break;
     }
-    default:
-        abort();
+    case LIBXL_DOMAIN_TYPE_INVALID:
+        return ERROR_FAIL;
     }
 out:
     if (!libxl_is_stubdom(ctx, domid, NULL)) {
-- 
1.7.2.5

  parent reply	other threads:[~2012-06-26 17:55 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-26 17:54 [PATCH v5 00/21] libxl: domain save/restore: run in a separate process Ian Jackson
2012-06-26 17:54 ` [PATCH 01/21] libxc: xc_domain_restore, make toolstack_restore const-correct Ian Jackson
2012-06-26 17:54 ` [PATCH 02/21] libxc: Do not segfault if (e.g.) switch_qemu_logdirty fails Ian Jackson
2012-06-26 17:55 ` [PATCH 03/21] libxl: domain save: rename variables etc Ian Jackson
2012-06-26 17:55 ` [PATCH 04/21] libxl: domain restore: reshuffle, preparing for ao Ian Jackson
2012-06-26 17:55 ` [PATCH 05/21] libxl: domain save: API changes for asynchrony Ian Jackson
2012-06-26 17:55 ` [PATCH 06/21] libxl: domain save/restore: run in a separate process Ian Jackson
2012-06-26 17:55 ` [PATCH 07/21] libxl: rename libxl_dom:save_helper to physmap_path Ian Jackson
2012-06-26 17:55 ` [PATCH 08/21] libxl: provide libxl__xs_*_checked and libxl__xs_transaction_* Ian Jackson
2012-06-26 17:55 ` [PATCH 09/21] libxl: wait for qemu to acknowledge logdirty command Ian Jackson
2012-06-26 17:55 ` [PATCH 10/21] libxl: datacopier: provide "prefix data" facility Ian Jackson
2012-06-26 17:55 ` [PATCH 11/21] libxl: prepare for asynchronous writing of qemu save file Ian Jackson
2012-06-26 17:55 ` [PATCH 12/21] libxl: Make libxl__domain_save_device_model asynchronous Ian Jackson
2012-06-26 17:55 ` [PATCH 13/21] libxl: Add a gc to libxl_get_cpu_topology Ian Jackson
2012-06-26 17:55 ` [PATCH 14/21] libxl: Do not pass NULL as gc_opt; introduce NOGC Ian Jackson
2012-06-26 17:55 ` [PATCH 15/21] libxl: Get compiler to warn about gc_opt==NULL Ian Jackson
2012-06-28 17:56   ` Ian Jackson
2012-06-26 17:55 ` [PATCH 16/21] xl: Handle return value from libxl_domain_suspend correctly Ian Jackson
2012-06-26 17:55 ` [PATCH 17/21] libxl: do not leak dms->saved_state Ian Jackson
2012-06-26 17:55 ` [PATCH 18/21] libxl: do not leak spawned middle children Ian Jackson
2012-06-26 17:55 ` [PATCH 19/21] libxl: do not leak an event struct on ignored ao progress Ian Jackson
2012-06-26 17:55 ` Ian Jackson [this message]
2012-06-26 17:55 ` [PATCH 21/21] libxl: DO NOT APPLY enforce prohibition on internal Ian Jackson
2012-06-26 18:00 ` [PATCH v5 00/21] libxl: domain save/restore: run in a separate process Ian Jackson
2012-06-26 18:44   ` Shriram Rajagopalan
2012-06-27  1:25     ` Shriram Rajagopalan
2012-06-27 13:46       ` Ian Jackson
2012-06-27 15:59         ` Ian Jackson
2012-06-27 16:09           ` Shriram Rajagopalan
2012-06-27 16:42             ` Shriram Rajagopalan
2012-06-28 11:24               ` Ian Jackson
2012-06-27 16:06         ` Shriram Rajagopalan
2012-06-27 13:17     ` Ian Jackson
2012-06-27 13:28       ` Shriram Rajagopalan
2012-06-28 13:38 ` [PATCH v6 " Ian Jackson
2012-06-28 13:50   ` Ian Campbell
2012-06-28 14:24     ` Ian Jackson
2012-06-28 14:44       ` Ian Campbell
2012-06-28 15:17       ` Shriram Rajagopalan
2012-06-28 17:45   ` Ian Jackson
  -- strict thread matches above, loose matches on Subject: below --
2012-06-15 11:53 [PATCH v3 00/18] " Ian Jackson
2012-06-15 11:54 ` [PATCH 20/21] libxl: further fixups re LIBXL_DOMAIN_TYPE Ian Jackson
2012-06-22 11:42   ` Ian Campbell

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=1340733318-21099-21-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).