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

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

 



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;
     }
 
--
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]