]> xenbits.xensource.com Git - libvirt.git/commitdiff
Misc fixes uncovered by OOM testing
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 1 Apr 2009 10:31:01 +0000 (10:31 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 1 Apr 2009 10:31:01 +0000 (10:31 +0000)
ChangeLog
src/datatypes.c
src/domain_conf.c
src/nodeinfo.c
src/xend_internal.c
tests/sexpr2xmltest.c
tests/testutils.c
tests/xml2sexprtest.c

index 9f939b64f4d171310ca9a65d00d44cc9dd27cb71..2f674b383e63b42d3fb0576a175313e18df9ccc0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Wed Apr  1 11:27:22 BST 2009 Daniel P. Berrange <berrange@redhat.com>
+
+       Misc fixes uncovered from OOM testing
+       * src/datatypes.c: Switch to virReportErrorHelper for error
+       reporting, so source line/file/function info is correct
+       * src/domain_conf.c: Check for failure in virXPathNodeSet()
+       * src/noeinfo.c: Translate error strings
+       * src/xend_internal.c: Check for OOM failure after generating
+       SEXPR buffer
+       * tests/sexpr2xmltest.c: Don't unref a NULL connection object.
+       Reset error object between tests. Free capabilities on exit
+       * tests/testutils.c: Fix crash in OOM testing for non-SMP
+       usage
+       * tests/xml2sexprtest.c: Reset error object between tests
+
 Wed Apr  1 11:22:22 BST 2009 Daniel P. Berrange <berrange@redhat.com>
 
        Sanitise symlink resolving
index 3b2c958a01696ee451dbccd0a3564123dfa29e50..b1013f201a69fdd2be33dca1c96e6a8f9a6f7aa5 100644 (file)
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
+#define virLibConnError(conn, code, fmt...)                       \
+    virReportErrorHelper(conn, VIR_FROM_THIS, code, __FILE__,     \
+                         __FUNCTION__, __LINE__, fmt)
+
 /************************************************************************
  *                                                                     *
  *                     Domain and Connections allocations              *
  *                                                                     *
  ************************************************************************/
-/**
- * virLibConnError:
- * @conn: the connection if available
- * @error: the error number
- * @info: extra information string
- *
- * Handle an error at the connection level
- */
-static void
-virLibConnError(virConnectPtr conn, virErrorNumber error, const char *info)
-{
-    const char *errmsg;
-
-    if (error == VIR_ERR_OK)
-        return;
-
-    errmsg = virErrorMsg(error, info);
-    virRaiseError(conn, NULL, NULL, VIR_FROM_NONE, error, VIR_ERR_ERROR,
-                  errmsg, info, NULL, 0, 0, errmsg, info);
-}
 
 /**
  * virDomainFreeName:
index 269644983f6fd2fd75eb4f4ea41d78ffdec058c4..3d734148d4fecba573db975213910b802f5b99d8 100644 (file)
@@ -2068,7 +2068,10 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
         VIR_FREE(tmp);
     }
 
-    if ((n = virXPathNodeSet(conn, "./features/*", ctxt, &nodes)) > 0) {
+    n = virXPathNodeSet(conn, "./features/*", ctxt, &nodes);
+    if (n < 0)
+        goto error;
+    if (n) {
         for (i = 0 ; i < n ; i++) {
             int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name);
             if (val < 0) {
@@ -2079,8 +2082,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
             }
             def->features |= (1 << val);
         }
+        VIR_FREE(nodes);
     }
-    VIR_FREE(nodes);
 
     if (virDomainLifecycleParseXML(conn, ctxt, "string(./on_reboot[1])",
                                    &def->onReboot, VIR_DOMAIN_LIFECYCLE_RESTART) < 0)
index bab719770365a5fda36c4c24998620e408ef6af1..9894cd119e3ea74799f8cef0ec6d54e2ff0a9551 100644 (file)
@@ -74,8 +74,8 @@ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr n
                 buf++;
             if (*buf != ':') {
                 virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
-                                VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
-                                "parsing cpuinfo processor");
+                              VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
+                              "%s", _("parsing cpuinfo processor"));
                 return -1;
             }
             nodeinfo->cpus++;
@@ -87,8 +87,8 @@ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr n
                 buf++;
             if (*buf != ':' || !buf[1]) {
                 virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
-                                VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
-                                "parsing cpuinfo cpu MHz");
+                              VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
+                              "%s", _("parsing cpuinfo cpu MHz"));
                 return -1;
             }
             if (virStrToLong_ui(buf+1, &p, 10, &ui) == 0
@@ -103,8 +103,8 @@ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr n
                 buf++;
             if (*buf != ':' || !buf[1]) {
                 virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
-                                VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
-                                "parsing cpuinfo cpu cores %c", *buf);
+                              VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
+                              "parsing cpuinfo cpu cores %c", *buf);
                 return -1;
             }
             if (virStrToLong_ui(buf+1, &p, 10, &id) == 0
@@ -116,8 +116,8 @@ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr n
 
     if (!nodeinfo->cpus) {
         virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
-                        VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
-                        "no cpus found");
+                      VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
+                      "%s", _("no cpus found"));
         return -1;
     }
 
index 35918fda10afb2b369b50a747a6e7119f93eb8ca..c00559bffc1f4a5a7375e7ff514bbfa3351cae8f 100644 (file)
@@ -5538,6 +5538,11 @@ xenDaemonFormatSxpr(virConnectPtr conn,
 
     virBufferAddLit(&buf, ")"); /* closes (vm */
 
+    if (virBufferError(&buf)) {
+        virReportOOMError(conn);
+        return NULL;
+    }
+
     return virBufferContentAndReset(&buf);
 
 error:
index 09cf45a5d4263dc5c6f9bc178bcd00aa957ca74d..42de88094ccb6ac4f8a7dbdf310e675836944abb 100644 (file)
@@ -64,7 +64,8 @@ static int testCompareFiles(const char *xml, const char *sexpr,
  fail:
   free(gotxml);
   virDomainDefFree(def);
-  virUnrefConnect(conn);
+  if (conn)
+    virUnrefConnect(conn);
 
   return ret;
 }
@@ -115,6 +116,7 @@ mymain(int argc, char **argv)
 #define DO_TEST(in, out, version)                                      \
     do {                                                               \
         struct testInfo info = { in, out, version };                   \
+        virResetLastError();                                           \
         if (virtTestRun("Xen SEXPR-2-XML " in " -> " out,              \
                         1, testCompareHelper, &info) < 0)              \
             ret = -1;                                                  \
@@ -163,6 +165,8 @@ mymain(int argc, char **argv)
     DO_TEST("fv-sound", "fv-sound", 1);
     DO_TEST("fv-sound-all", "fv-sound-all", 1);
 
+    virCapabilitiesFree(caps);
+
     return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
 }
 
index 8d8f82d119f2088da62a5d9eded7208bcece8b22..c90d4a9e1fdbddabbc4374a6f51fcd1be09212a4 100644 (file)
@@ -409,7 +409,8 @@ int virtTestMain(int argc,
         /* Run once for each alloc, failing a different one
            and validating that the test case failed */
         for (n = 0; n < approxAlloc && (!mp || worker) ; n++) {
-            if ((n % mp) != (worker - 1))
+            if (mp &&
+                (n % mp) != (worker - 1))
                 continue;
             if (!testDebug) {
                 if (mp)
index 20528fe9e389655f85b3d0c677a8c9b945ad7c76..e6b0c4c8a00750530a3ce61a6cadaa9aca3061af 100644 (file)
@@ -95,6 +95,7 @@ mymain(int argc, char **argv)
 #define DO_TEST(in, out, name, version)                                \
     do {                                                               \
         struct testInfo info = { in, out, name, version };             \
+        virResetLastError();                                           \
         if (virtTestRun("Xen XML-2-SEXPR " in " -> " out,              \
                         1, testCompareHelper, &info) < 0)     \
             ret = -1;                                                  \