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

[Xen-devel] [PATCH v3 2/7] libxl: Add to libxl__domain_type a new return value (LIBXL_DOMAIN_TYPE_NOTFOUND)



So that the callers can distinguish between an error and
an domain not found. The exposed API calls that are effected
by this are: libxl_domain_[remus_start,suspend,unpause,cdrom_insert,
set_vcpuonline]

We add an helper function to deal with the two types of errors:
libxl_domain_type2err. However for libxl_[pci,dom].c we just add
the extra check for LIBXL_DOMAIN_TYPE_NOTFOUND for simplicity
reasons.

Suggested-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
---
 tools/libxl/libxl.c         | 53 ++++++++++++++++++++++++++-------------------
 tools/libxl/libxl.h         |  5 +++++
 tools/libxl/libxl_dom.c     |  5 ++++-
 tools/libxl/libxl_pci.c     |  6 +++++
 tools/libxl/libxl_types.idl |  2 ++
 5 files changed, 48 insertions(+), 23 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 0b57bae..4152ee4 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -354,6 +354,16 @@ const char *libxl_defbool_to_string(libxl_defbool b)
         return LIBXL__DEFBOOL_STR_DEFAULT;
 }
 
+static int libxl_domain_type2error(libxl_domain_type type)
+{
+    switch (type) {
+    case LIBXL_DOMAIN_TYPE_INVALID: return ERROR_FAIL;
+    case LIBXL_DOMAIN_TYPE_NOTFOUND: return ERROR_DOMAIN_NOTFOUND;
+    default: break;
+    }
+    return 0;
+}
+
 
/******************************************************************************/
 
 
@@ -512,7 +522,7 @@ int libxl_domain_rename(libxl_ctx *ctx, uint32_t domid,
 
 int libxl__domain_resume(libxl__gc *gc, uint32_t domid, int suspend_cancel)
 {
-    int rc = 0;
+    int rc;
 
     if (xc_domain_resume(CTX->xch, domid, suspend_cancel)) {
         LOGE(ERROR, "xc_domain_resume failed for domain %u", domid);
@@ -521,10 +531,9 @@ int libxl__domain_resume(libxl__gc *gc, uint32_t domid, 
int suspend_cancel)
     }
 
     libxl_domain_type type = libxl__domain_type(gc, domid);
-    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
-        rc = ERROR_FAIL;
+    rc = libxl_domain_type2error(type);
+    if (rc)
         goto out;
-    }
 
     if (type == LIBXL_DOMAIN_TYPE_HVM) {
         rc = libxl__domain_resume_device_model(gc, domid);
@@ -842,10 +851,9 @@ int libxl_domain_remus_start(libxl_ctx *ctx, 
libxl_domain_remus_info *info,
     int rc;
 
     libxl_domain_type type = libxl__domain_type(gc, domid);
-    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
-        rc = ERROR_FAIL;
+    rc = libxl_domain_type2error(type);
+    if (rc)
         goto out;
-    }
 
     libxl_defbool_setdefault(&info->allow_unsafe, false);
     libxl_defbool_setdefault(&info->blackhole, false);
@@ -961,10 +969,9 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, 
int fd, int flags,
     int rc;
 
     libxl_domain_type type = libxl__domain_type(gc, domid);
-    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
-        rc = ERROR_FAIL;
+    rc = libxl_domain_type2error(type);
+    if (rc)
         goto out_err;
-    }
 
     libxl__domain_suspend_state *dss;
     GCNEW(dss);
@@ -1024,13 +1031,12 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
     GC_INIT(ctx);
     char *path;
     char *state;
-    int ret, rc = 0;
+    int ret, rc;
 
     libxl_domain_type type = libxl__domain_type(gc, domid);
-    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
-        rc = ERROR_FAIL;
+    rc = libxl_domain_type2error(type);
+    if (rc)
         goto out;
-    }
 
     if (type == LIBXL_DOMAIN_TYPE_HVM) {
         path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", 
domid);
@@ -1059,8 +1065,9 @@ int libxl__domain_pvcontrol_available(libxl__gc *gc, 
uint32_t domid)
     int ret;
 
     libxl_domain_type domtype = libxl__domain_type(gc, domid);
-    if (domtype == LIBXL_DOMAIN_TYPE_INVALID)
-        return ERROR_FAIL;
+    ret = libxl_domain_type2error(domtype);
+    if (ret)
+        return ret;
 
     if (domtype == LIBXL_DOMAIN_TYPE_PV)
         return 1;
@@ -2390,10 +2397,9 @@ static void device_disk_add(libxl__egc *egc, uint32_t 
domid,
     libxl_device_disk_copy(ctx, &disk_saved, disk);
 
     libxl_domain_type type = libxl__domain_type(gc, domid);
-    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
-        rc = ERROR_FAIL;
+    rc = libxl_domain_type2error(type);
+    if (rc)
         goto out;
-    }
 
     /*
      * get_vdev != NULL -> local attach
@@ -2840,10 +2846,10 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, 
libxl_device_disk *disk,
     libxl__device_disk_setdefault(gc, &disk_empty);
 
     libxl_domain_type type = libxl__domain_type(gc, domid);
-    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
-        rc = ERROR_FAIL;
+    rc = libxl_domain_type2error(type);
+    if (rc)
         goto out;
-    }
+
     if (type != LIBXL_DOMAIN_TYPE_HVM) {
         LOG(ERROR, "cdrom-insert requires an HVM domain");
         rc = ERROR_INVAL;
@@ -5526,6 +5532,9 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, 
libxl_bitmap *cpumap)
     case LIBXL_DOMAIN_TYPE_PV:
         rc = libxl__set_vcpuonline_xenstore(gc, domid, cpumap);
         break;
+    case LIBXL_DOMAIN_TYPE_NOTFOUND:
+        rc = ERROR_DOMAIN_NOTFOUND;
+        break;
     default:
         rc = ERROR_INVAL;
     }
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 1cf5699..f03fa3b 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -181,6 +181,11 @@
 /*
  * libxl_domain_info returns ERROR_DOMAIN_NOTFOUND if the domain
  * is not present, instead of ERROR_INVAL.
+ *
+ * libxl_set_vcpuonline, libxl_domain_remus_start, libx_domain_suspend,
+ * libxl_domain_unpause, and libxl_cdrom_insert can return
+ * LIBLX_DOMAIN_TYPE_NOTFOUND if the domain is not present, instead of
+ * LIBXL_DOMAIN_TYPE_INVALID.
  */
 #define LIBXL_HAVE_ERROR_DOMAIN_NOTFOUND 1
 /*
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index ace8a66..1d11729 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -32,10 +32,13 @@ libxl_domain_type libxl__domain_type(libxl__gc *gc, 
uint32_t domid)
     int ret;
 
     ret = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
-    if (ret != 1 || info.domain != domid) {
+    if (ret != 1) {
         LOG(ERROR, "unable to get domain type for domid=%"PRIu32, domid);
         return LIBXL_DOMAIN_TYPE_INVALID;
     }
+    if (info.domain != domid)
+        return LIBXL_DOMAIN_TYPE_NOTFOUND;
+
     if (info.flags & XEN_DOMINF_hvm_guest)
         return LIBXL_DOMAIN_TYPE_HVM;
     else
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index f3ae132..958c1a3 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -143,6 +143,9 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, 
uint32_t domid, libxl_d
     if (domtype == LIBXL_DOMAIN_TYPE_INVALID)
         return ERROR_FAIL;
 
+    if (domtype == LIBXL_DOMAIN_TYPE_NOTFOUND)
+        return ERROR_DOMAIN_NOTFOUND;
+
     if (!starting && domtype == LIBXL_DOMAIN_TYPE_PV) {
         if (libxl__wait_for_backend(gc, be_path, "4") < 0)
             return ERROR_FAIL;
@@ -212,6 +215,9 @@ static int libxl__device_pci_remove_xenstore(libxl__gc *gc, 
uint32_t domid, libx
     if (domtype == LIBXL_DOMAIN_TYPE_INVALID)
         return ERROR_FAIL;
 
+    if (domtype == LIBXL_DOMAIN_TYPE_NOTFOUND)
+        return ERROR_DOMAIN_NOTFOUND;
+
     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);
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 117b61d..d81e0c2 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -69,6 +69,7 @@ libxl_error = Enumeration("error", [
 
 libxl_domain_type = Enumeration("domain_type", [
     (-1, "INVALID"),
+    (-2, "NOTFOUND"),
     (1, "HVM"),
     (2, "PV"),
     ], init_val = "LIBXL_DOMAIN_TYPE_INVALID")
@@ -469,6 +470,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
                                       ("e820_host", libxl_defbool),
                                       ])),
                  ("invalid", None),
+                 ("notfound", None),
                  ], keyvar_init_val = "LIBXL_DOMAIN_TYPE_INVALID")),
     ], dir=DIR_IN
 )
-- 
2.1.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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