[PATCH] #1: Add error handling and do quick wins (qemu, test)

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

 



This patch:

(1) Adds the VIR_ERR_NO_DOMAIN and VIR_ERR_NO_NETWORK errors (the latter
will be used later to make the same change to virNetworkLookup* functions).

(2) Changes the documentation of virDomainLookup* functions to match the
new behaviour.

(3) Changes qemu & test drivers to have the new behaviour.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903

? qemud/libvirtd.init
Index: include/libvirt/virterror.h
===================================================================
RCS file: /data/cvs/libvirt/include/libvirt/virterror.h,v
retrieving revision 1.25
diff -u -p -r1.25 virterror.h
--- include/libvirt/virterror.h	20 Jun 2007 17:25:39 -0000	1.25
+++ include/libvirt/virterror.h	3 Jul 2007 14:17:19 -0000
@@ -125,6 +125,8 @@ typedef enum {
     VIR_ERR_RPC, /* some sort of RPC error */
     VIR_ERR_GNUTLS_ERROR, /* error from a GNUTLS call */
     VIR_WAR_NO_NETWORK, /* failed to start network */
+    VIR_ERR_NO_DOMAIN, /* domain not found or unexpectedly disappeared */
+    VIR_ERR_NO_NETWORK, /* network not found */
 } virErrorNumber;
 
 /**
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.84
diff -u -p -r1.84 libvirt.c
--- src/libvirt.c	29 Jun 2007 13:23:13 -0000	1.84
+++ src/libvirt.c	3 Jul 2007 14:17:20 -0000
@@ -744,7 +744,8 @@ virDomainCreateLinux(virConnectPtr conn,
  *
  * Try to find a domain based on the hypervisor ID number
  *
- * Returns a new domain object or NULL in case of failure
+ * Returns a new domain object or NULL in case of failure.  If the
+ * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
  */
 virDomainPtr
 virDomainLookupByID(virConnectPtr conn, int id)
@@ -772,7 +773,8 @@ virDomainLookupByID(virConnectPtr conn, 
  *
  * Try to lookup a domain on the given hypervisor based on its UUID.
  *
- * Returns a new domain object or NULL in case of failure
+ * Returns a new domain object or NULL in case of failure.  If the
+ * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
  */
 virDomainPtr
 virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
@@ -800,7 +802,8 @@ virDomainLookupByUUID(virConnectPtr conn
  *
  * Try to lookup a domain on the given hypervisor based on its UUID.
  *
- * Returns a new domain object or NULL in case of failure
+ * Returns a new domain object or NULL in case of failure.  If the
+ * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
  */
 virDomainPtr
 virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
@@ -849,7 +852,8 @@ virDomainLookupByUUIDString(virConnectPt
  *
  * Try to lookup a domain on the given hypervisor based on its name.
  *
- * Returns a new domain object or NULL in case of failure
+ * Returns a new domain object or NULL in case of failure.  If the
+ * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
  */
 virDomainPtr
 virDomainLookupByName(virConnectPtr conn, const char *name)
Index: src/qemu_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_driver.c,v
retrieving revision 1.2
diff -u -p -r1.2 qemu_driver.c
--- src/qemu_driver.c	29 Jun 2007 13:23:13 -0000	1.2
+++ src/qemu_driver.c	3 Jul 2007 14:17:22 -0000
@@ -1748,7 +1748,7 @@ static virDomainPtr qemudDomainLookupByI
     virDomainPtr dom;
 
     if (!vm) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "no domain with matching id");
+        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
         return NULL;
     }
 
@@ -1768,7 +1768,7 @@ static virDomainPtr qemudDomainLookupByU
     virDomainPtr dom;
 
     if (!vm) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "no domain with matching uuid");
+        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
         return NULL;
     }
 
@@ -1788,7 +1788,7 @@ static virDomainPtr qemudDomainLookupByN
     virDomainPtr dom;
 
     if (!vm) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "no domain with matching name");
+        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
         return NULL;
     }
 
Index: src/test.c
===================================================================
RCS file: /data/cvs/libvirt/src/test.c,v
retrieving revision 1.38
diff -u -p -r1.38 test.c
--- src/test.c	26 Jun 2007 22:57:41 -0000	1.38
+++ src/test.c	3 Jul 2007 14:17:23 -0000
@@ -983,6 +983,7 @@ virDomainPtr testLookupDomainByID(virCon
     }
 
     if (idx < 0) {
+        testError (conn, NULL, VIR_ERR_NO_DOMAIN, NULL);
         return(NULL);
     }
 
@@ -1000,8 +1001,9 @@ virDomainPtr testLookupDomainByUUID(virC
 {
     testPrivatePtr priv = (testPrivatePtr) conn->privateData;
     testCon *con = &node->connections[priv->handle];
-    virDomainPtr dom = NULL;
+    virDomainPtr dom;
     int i, idx = -1;
+
     for (i = 0 ; i < MAX_DOMAINS ; i++) {
         if (con->domains[i].active &&
             memcmp(uuid, con->domains[i].uuid, VIR_UUID_BUFLEN) == 0) {
@@ -1009,15 +1011,20 @@ virDomainPtr testLookupDomainByUUID(virC
             break;
         }
     }
-    if (idx >= 0) {
-        dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid);
-        if (dom == NULL) {
-            testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain"));
-            return(NULL);
-        }
-        dom->id = con->domains[idx].id;
+
+    if (idx < 0) {
+        testError (conn, NULL, VIR_ERR_NO_DOMAIN, NULL);
+        return NULL;
     }
-    return (dom);
+
+    dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid);
+    if (dom == NULL) {
+        testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain"));
+        return NULL;
+    }
+    dom->id = con->domains[idx].id;
+
+    return dom;
 }
 
 virDomainPtr testLookupDomainByName(virConnectPtr conn,
@@ -1025,8 +1032,9 @@ virDomainPtr testLookupDomainByName(virC
 {
     testPrivatePtr priv = (testPrivatePtr) conn->privateData;
     testCon *con = &node->connections[priv->handle];
-    virDomainPtr dom = NULL;
+    virDomainPtr dom;
     int i, idx = -1;
+
     for (i = 0 ; i < MAX_DOMAINS ; i++) {
         if (con->domains[i].active &&
             strcmp(name, con->domains[i].name) == 0) {
@@ -1034,15 +1042,20 @@ virDomainPtr testLookupDomainByName(virC
             break;
         }
     }
-    if (idx >= 0) {
-        dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid);
-        if (dom == NULL) {
-            testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain"));
-            return(NULL);
-        }
-        dom->id = con->domains[idx].id;
+
+    if (idx < 0) {
+        testError (conn, NULL, VIR_ERR_NO_DOMAIN, NULL);
+        return NULL;
     }
-    return (dom);
+
+    dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid);
+    if (dom == NULL) {
+        testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain"));
+        return NULL;
+    }
+    dom->id = con->domains[idx].id;
+
+    return dom;
 }
 
 int testListDomains (virConnectPtr conn,
Index: src/virterror.c
===================================================================
RCS file: /data/cvs/libvirt/src/virterror.c,v
retrieving revision 1.27
diff -u -p -r1.27 virterror.c
--- src/virterror.c	20 Jun 2007 17:25:39 -0000	1.27
+++ src/virterror.c	3 Jul 2007 14:17:23 -0000
@@ -634,6 +634,18 @@ __virErrorMsg(virErrorNumber error, cons
 	    else
 		errmsg = _("Failed to find the network: %s");
 	    break;
+	case VIR_ERR_NO_DOMAIN:
+	    if (info == NULL)
+		errmsg = _("Domain not found");
+	    else
+		errmsg = _("Domain not found: %s");
+	    break;
+	case VIR_ERR_NO_NETWORK:
+	    if (info == NULL)
+		errmsg = _("Network not found");
+	    else
+		errmsg = _("Network not found: %s");
+	    break;
     }
     return (errmsg);
 }

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]