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

[libvirt] [PATCH 02/23] Fix handling of OOM when getting Xen dom ID



From: "Daniel P. Berrange" <berrange redhat com>

The methods for obtaining the Xen dom ID cannot distinguish
between returning -1 due to an error and returning -1 due to
the domain being shutoff. Change them to return the dom ID
via an output parameter.

Signed-off-by: Daniel P. Berrange <berrange redhat com>
---
 src/xen/xen_driver.c    |  3 ++-
 src/xen/xend_internal.c | 10 ++++++----
 src/xenxs/xen_sxpr.c    | 17 ++++++++++-------
 src/xenxs/xen_sxpr.h    |  4 ++--
 tests/sexpr2xmltest.c   |  3 ++-
 5 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 6cb4f4f..40b98ee 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1604,7 +1604,8 @@ xenUnifiedConnectDomainXMLFromNative(virConnectPtr conn,
 
         def = xenParseXM(conf, priv->xendConfigVersion, priv->caps);
     } else if (STREQ(format, XEN_CONFIG_FORMAT_SEXPR)) {
-        id = xenGetDomIdFromSxprString(config, priv->xendConfigVersion);
+        if (xenGetDomIdFromSxprString(config, priv->xendConfigVersion, &id) < 0)
+            goto cleanup;
         xenUnifiedLock(priv);
         tty = xenStoreDomainGetConsolePath(conn, id);
         vncport = xenStoreDomainGetVNCPort(conn, id);
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index f698c8d..dc57350 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -1561,7 +1561,7 @@ xenDaemonDomainFetch(virConnectPtr conn, int domid, const char *name,
 {
     struct sexpr *root;
     xenUnifiedPrivatePtr priv = conn->privateData;
-    virDomainDefPtr def;
+    virDomainDefPtr def = NULL;
     int id;
     char * tty;
     int vncport;
@@ -1573,7 +1573,8 @@ xenDaemonDomainFetch(virConnectPtr conn, int domid, const char *name,
     if (root == NULL)
         return NULL;
 
-    id = xenGetDomIdFromSxpr(root, priv->xendConfigVersion);
+    if (xenGetDomIdFromSxpr(root, priv->xendConfigVersion, &id) < 0)
+        goto cleanup;
     xenUnifiedLock(priv);
     if (sexpr_lookup(root, "domain/image/hvm"))
         tty = xenStoreDomainGetSerialConsolePath(conn, id);
@@ -3224,7 +3225,7 @@ xenDaemonDomainBlockPeek(virConnectPtr conn,
     xenUnifiedPrivatePtr priv = conn->privateData;
     struct sexpr *root = NULL;
     int fd = -1, ret = -1;
-    virDomainDefPtr def;
+    virDomainDefPtr def = NULL;
     int id;
     char * tty;
     int vncport;
@@ -3249,7 +3250,8 @@ xenDaemonDomainBlockPeek(virConnectPtr conn,
         return -1;
     }
 
-    id = xenGetDomIdFromSxpr(root, priv->xendConfigVersion);
+    if (xenGetDomIdFromSxpr(root, priv->xendConfigVersion, &id) < 0)
+        goto cleanup;
     xenUnifiedLock(priv);
     tty = xenStoreDomainGetConsolePath(conn, id);
     vncport = xenStoreDomainGetVNCPort(conn, id);
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index 462eac6..bb8a335 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -40,30 +40,33 @@
 #include "virstring.h"
 
 /* Get a domain id from a S-expression string */
-int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion)
+int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion, int *id)
 {
     struct sexpr *root = string2sexpr(sexpr);
+    int ret;
+
+    *id = -1;
 
     if (!root)
         return -1;
 
-    int id = xenGetDomIdFromSxpr(root, xendConfigVersion);
+    ret = xenGetDomIdFromSxpr(root, xendConfigVersion, id);
     sexpr_free(root);
-    return id;
+    return ret;
 }
 
 /* Get a domain id from a S-expression */
-int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion)
+int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion, int *id)
 {
-    int id = -1;
     const char * tmp = sexpr_node(root, "domain/domid");
     if (tmp == NULL && xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { /* domid was mandatory */
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("domain information incomplete, missing id"));
+        return -1;
     } else {
-      id = tmp ? sexpr_int(root, "domain/domid") : -1;
+        *id = tmp ? sexpr_int(root, "domain/domid") : -1;
+        return 0;
     }
-    return id;
 }
 
 /*****************************************************************
diff --git a/src/xenxs/xen_sxpr.h b/src/xenxs/xen_sxpr.h
index d7ce46a..f354a50 100644
--- a/src/xenxs/xen_sxpr.h
+++ b/src/xenxs/xen_sxpr.h
@@ -40,8 +40,8 @@ typedef enum {
 } xenConfigVersionEnum;
 
 /* helper functions to get the dom id from a sexpr */
-int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion);
-int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion);
+int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion, int *id);
+int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion, int *id);
 
 virDomainDefPtr xenParseSxprString(const char *sexpr, int xendConfigVersion,
                                    char *tty, int vncport);
diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
index eafefda..b939319 100644
--- a/tests/sexpr2xmltest.c
+++ b/tests/sexpr2xmltest.c
@@ -50,7 +50,8 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
   if (virMutexInit(&priv.lock) < 0)
       goto fail;
 
-  id = xenGetDomIdFromSxprString(sexprData, xendConfigVersion);
+  if (xenGetDomIdFromSxprString(sexprData, xendConfigVersion, &id) < 0)
+      goto fail;
   xenUnifiedLock(&priv);
   tty = xenStoreDomainGetConsolePath(conn, id);
   vncport = xenStoreDomainGetVNCPort(conn, id);
-- 
1.8.3.1


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