WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] libxl: properly check errors from libxl__get_ishvm (

Make is_hvm log on errors; make callers check its error returns; and
rename the function according to the libxl__ name scheme for internal
functions.

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Cc: Jun Zhu <Jun.Zhu@xxxxxxxxxx>
Cc: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>

---
 tools/libxl/libxl.c          |   31 +++++++++++++++++++++----------
 tools/libxl/libxl_dom.c      |   19 +++++++++++++------
 tools/libxl/libxl_internal.h |    2 +-
 tools/libxl/libxl_pci.c      |   16 +++++++++-------
 4 files changed, 44 insertions(+), 24 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 099d82e..0343f7e 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -427,9 +427,10 @@ out:
 int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid)
 {
     libxl_gc gc = LIBXL_INIT_GC(ctx);
-    int rc = 0;
+    int hvm, rc = 0;
 
-    if (is_hvm(ctx, domid)) {
+    rc = libxl__get_ishvm(ctx, domid, &hvm);  if (rc) goto out;
+    if (hvm) {
         XL_LOG(ctx, XL_LOG_DEBUG, "Called domain_resume on "
                 "non-cooperative hvm domain %u", domid);
         rc = ERROR_NI;
@@ -645,11 +646,13 @@ libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm)
 int libxl_domain_suspend(libxl_ctx *ctx, libxl_domain_suspend_info *info,
                          uint32_t domid, int fd)
 {
-    int hvm = is_hvm(ctx, domid);
+    int hvm;
     int live = info != NULL && info->flags & XL_SUSPEND_LIVE;
     int debug = info != NULL && info->flags & XL_SUSPEND_DEBUG;
     int rc = 0;
 
+    rc = libxl__get_ishvm(ctx, domid, &hvm);  if (rc) return rc;
+
     core_suspend(ctx, domid, fd, hvm, live, debug);
     if (hvm)
         rc = save_device_model(ctx, domid, fd);
@@ -685,9 +688,10 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
     libxl_gc gc = LIBXL_INIT_GC(ctx);
     char *path;
     char *state;
-    int ret, rc = 0;
+    int hvm, ret, rc = 0;
 
-    if (is_hvm(ctx, domid)) {
+    rc = libxl__get_ishvm(ctx, domid, &hvm);  if (rc) return rc;
+    if (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")) {
@@ -717,6 +721,7 @@ int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid, 
int req)
     libxl_gc gc = LIBXL_INIT_GC(ctx);
     char *shutdown_path;
     char *dom_path;
+    int hvm, rc = 0;
 
     if (req > ARRAY_SIZE(req_table)) {
         libxl_free_all(&gc);
@@ -732,7 +737,8 @@ int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid, 
int req)
     shutdown_path = libxl_sprintf(&gc, "%s/control/shutdown", dom_path);
 
     xs_write(ctx->xsh, XBT_NULL, shutdown_path, req_table[req], 
strlen(req_table[req]));
-    if (is_hvm(ctx,domid)) {
+    rc = libxl__get_ishvm(ctx, domid, &hvm);  if (rc) goto out;
+    if (hvm) {
         unsigned long acpi_s_state = 0;
         unsigned long pvdriver = 0;
         int ret;
@@ -754,8 +760,9 @@ int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid, 
int req)
             }
        }
     }
+ out:
     libxl_free_all(&gc);
-    return 0;
+    return rc;
 }
 
 int libxl_get_wait_fd(libxl_ctx *ctx, int *fd)
@@ -920,9 +927,10 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, 
int force)
     libxl_gc gc = LIBXL_INIT_GC(ctx);
     char *dom_path;
     char *vm_path;
-    int rc, dm_present;
+    int rc, hvm, dm_present;
 
-    if (is_hvm(ctx, domid)) {
+    rc = libxl__get_ishvm(ctx, domid, &hvm);  if (rc) goto out;
+    if (hvm) {
         dm_present = 1;
     } else {
         char *pid;
@@ -1004,11 +1012,14 @@ out:
 
 int libxl_primary_console_exec(libxl_ctx *ctx, uint32_t domid_vm)
 {
+    int rc, hvm;
     uint32_t stubdomid = libxl_get_stubdom_id(ctx, domid_vm);
+
     if (stubdomid)
         return libxl_console_exec(ctx, stubdomid, 1, LIBXL_CONSTYPE_PV);
     else {
-        if (is_hvm(ctx, domid_vm))
+        rc = libxl__get_ishvm(ctx, domid_vm, &hvm);  if (rc) return rc;
+        if (hvm)
             return libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSTYPE_SERIAL);
         else
             return libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSTYPE_PV);
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 1691858..c45b694 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -31,17 +31,24 @@
 #include "libxl.h"
 #include "libxl_internal.h"
 
-int is_hvm(libxl_ctx *ctx, uint32_t domid)
+int libxl__get_ishvm(libxl_ctx *ctx, uint32_t domid, int *is_hvm_r)
 {
     xc_domaininfo_t info;
     int ret;
 
     ret = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
-    if (ret != 1)
-        return -1;
-    if (info.domain != domid)
-        return -1;
-    return !!(info.flags & XEN_DOMINF_hvm_guest);
+    if (ret != 1) {
+        XL_LOG_ERRNO(ctx,XL_LOG_ERROR, "is_hvm: xc_domain_getinfolist failed");
+        return ERROR_FAIL;
+    }
+    if (info.domain != domid) {
+        XL_LOG(ctx, XL_LOG_ERROR, "is_hvm: xc_domain_getinfolist gave info "
+               "for %"PRIu32"d when we asked for %"PRIu32"d",
+               info.domain, domid);
+        return ERROR_FAIL;
+    }
+    *is_hvm_r = !!(info.flags & XEN_DOMINF_hvm_guest);
+    return 0;
 }
 
 int get_shutdown_reason(libxl_ctx *ctx, uint32_t domid)
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index face021..3f822d4 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -140,7 +140,7 @@ _hidden char *libxl_xs_read(libxl_gc *gc, xs_transaction_t 
t, char *path);
 _hidden char **libxl_xs_directory(libxl_gc *gc, xs_transaction_t t, char 
*path, unsigned int *nb);
 
 /* from xl_dom */
-_hidden int is_hvm(libxl_ctx *ctx, uint32_t domid);
+_hidden int libxl__get_ishvm(libxl_ctx *ctx, uint32_t domid, int *is_hvm_r);
 _hidden int get_shutdown_reason(libxl_ctx *ctx, uint32_t domid);
 #define dominfo_get_shutdown_reason(info) (((info)->flags >> 
XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask)
 
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index f32db3b..cf7380c 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -266,7 +266,7 @@ static int libxl_device_pci_add_xenstore(libxl_gc *gc, 
uint32_t domid, libxl_dev
     libxl_ctx *ctx = libxl_gc_owner(gc);
     flexarray_t *back;
     char *num_devs, *be_path;
-    int num = 0;
+    int rc, hvm, num = 0;
     unsigned int boffset = 0;
     xs_transaction_t t;
 
@@ -275,7 +275,8 @@ static int libxl_device_pci_add_xenstore(libxl_gc *gc, 
uint32_t domid, libxl_dev
     if (!num_devs)
         return libxl_create_pci_backend(gc, domid, pcidev, 1);
 
-    if (!is_hvm(ctx, domid)) {
+    rc = libxl__get_ishvm(ctx, domid, &hvm);  if (rc) return rc;
+    if (!hvm) {
         if (libxl_wait_for_backend(ctx, be_path, "4") < 0)
             return ERROR_FAIL;
     }
@@ -319,7 +320,7 @@ static int libxl_device_pci_remove_xenstore(libxl_gc *gc, 
uint32_t domid, libxl_
 {
     libxl_ctx *ctx = libxl_gc_owner(gc);
     char *be_path, *num_devs_path, *num_devs, *xsdev, *tmp, *tmppath;
-    int num, i, j;
+    int num, i, j, rc, hvm;
     xs_transaction_t t;
     unsigned int domain = 0, bus = 0, dev = 0, func = 0;
 
@@ -330,7 +331,8 @@ static int libxl_device_pci_remove_xenstore(libxl_gc *gc, 
uint32_t domid, libxl_
         return ERROR_INVAL;
     num = atoi(num_devs);
 
-    if (!is_hvm(ctx, domid)) {
+    rc = libxl__get_ishvm(ctx, domid, &hvm);  if (rc) return rc;
+    if (!hvm) {
         if (libxl_wait_for_backend(ctx, be_path, "4") < 0) {
             XL_LOG(ctx, XL_LOG_DEBUG, "pci backend at %s is not ready", 
be_path);
             return ERROR_FAIL;
@@ -358,7 +360,7 @@ retry_transaction:
         if (errno == EAGAIN)
             goto retry_transaction;
 
-    if (!is_hvm(ctx, domid)) {
+    if (!hvm) {
         if (libxl_wait_for_backend(ctx, be_path, "4") < 0) {
             XL_LOG(ctx, XL_LOG_DEBUG, "pci backend at %s is not ready", 
be_path);
             return ERROR_FAIL;
@@ -610,7 +612,7 @@ static int do_pci_add(libxl_gc *gc, uint32_t domid, 
libxl_device_pci *pcidev)
     char *state, *vdevfn;
     int rc, hvm;
 
-    hvm = is_hvm(ctx, domid);
+    rc = libxl__get_ishvm(ctx, domid, &hvm);  if (rc) return rc;
     if (hvm) {
         if (libxl_wait_for_device_model(ctx, domid, "running", NULL, NULL) < 
0) {
             return ERROR_FAIL;
@@ -834,7 +836,7 @@ static int do_pci_remove(libxl_gc *gc, uint32_t domid, 
libxl_device_pci *pcidev)
 
     libxl_device_pci_remove_xenstore(gc, domid, pcidev);
 
-    hvm = is_hvm(ctx, domid);
+    rc = libxl__get_ishvm(ctx, domid, &hvm);  if (rc) return rc;
     if (hvm) {
         if (libxl_wait_for_device_model(ctx, domid, "running", NULL, NULL) < 
0) {
             return ERROR_FAIL;
-- 
1.5.6.5


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