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

[libvirt] [PATCH] repeat lookup by name in LookupByID



There was error every time when I undefine stoped container
"no domain with matching id".
Bug arrise due to stoped container has ID = -1.

In such case container will be searched by name.

other:
use VIR_ERR_NO_DOMAIN when domain is not found
Index: src/openvz_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_driver.c,v
retrieving revision 1.28
diff -u -p -r1.28 openvz_driver.c
--- src/openvz_driver.c	11 Jul 2008 11:09:44 -0000	1.28
+++ src/openvz_driver.c	16 Jul 2008 07:51:19 -0000
@@ -128,11 +128,22 @@ static void cmdExecFree(char *cmdExec[])
 static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
                                    int id) {
     struct openvz_driver *driver = (struct openvz_driver *)conn->privateData;
-    struct openvz_vm *vm = openvzFindVMByID(driver, id);
+    struct openvz_vm *vm;
     virDomainPtr dom;
 
+    vm = openvzFindVMByID(driver, id);
+
+    if (!vm) { /*try to find by name*/
+        char name[OPENVZ_NAME_MAX];
+        if (snprintf(name, OPENVZ_NAME_MAX, "%d",id) >= OPENVZ_NAME_MAX) {
+            openvzError(conn, VIR_ERR_INTERNAL_ERROR, _("Too long domain name"));
+            return NULL;
+        }
+        vm = openvzFindVMByName(driver, name);
+    }
+
     if (!vm) {
-        openvzError(conn, VIR_ERR_INTERNAL_ERROR, _("no domain with matching id"));
+        openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
         return NULL;
     }
 
@@ -160,7 +171,7 @@ static virDomainPtr openvzDomainLookupBy
     virDomainPtr dom;
 
     if (!vm) {
-        openvzError(conn, VIR_ERR_INVALID_DOMAIN, _("no domain with matching uuid"));
+        openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
         return NULL;
     }
 
@@ -181,7 +192,7 @@ static virDomainPtr openvzDomainLookupBy
     virDomainPtr dom;
 
     if (!vm) {
-        openvzError(conn, VIR_ERR_INTERNAL_ERROR, _("no domain with matching name"));
+        openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
         return NULL;
     }
 

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