Hi

This patch adds checking the UUID in __virGetDomain().

Now, the UUID of domain is wrong in the following operations.

1. Start virsh in interactive mode.
2. Execute domuuid to the domain
3. Execute undefine to the domain which executed domuuid in 2.
4. Create the domain whose name is same as the domain that executed undefine.
5. Execute domuuid for the new domain

This patch can fix it.


Signed-off-by: Masayuki Sunou <[EMAIL PROTECTED]>

Thanks,
Masayuki Sunou.

--------------------------------------------------------------------------------
Index: src/hash.c
===================================================================
RCS file: /data/cvs/libvirt/src/hash.c,v
retrieving revision 1.22
diff -u -p -r1.22 hash.c
--- src/hash.c  8 May 2007 10:53:27 -0000       1.22
+++ src/hash.c  7 Jun 2007 02:08:41 -0000
@@ -758,8 +758,14 @@ __virGetDomain(virConnectPtr conn, const
 
     ret = (virDomainPtr) virHashLookup(conn->domains, name);
     if (ret != NULL) {
-        /* TODO check the UUID */
-       goto done;
+        if (memcmp(ret->uuid, uuid, 16)) {
+            if (virFreeDomain(conn, ret, 0) < 0) {
+                xmlMutexUnlock(conn->hashes_mux);
+                return(NULL);
+            }
+        } else {
+            goto done;
+        }
     }
 
     /*
@@ -813,7 +819,7 @@ error:
  * Returns the reference count or -1 in case of failure.
  */
 int
-virFreeDomain(virConnectPtr conn, virDomainPtr domain) {
+virFreeDomain(virConnectPtr conn, virDomainPtr domain, int lock) {
     int ret = 0;
 
     if ((!VIR_IS_CONNECT(conn)) || (!VIR_IS_CONNECTED_DOMAIN(domain)) ||
@@ -821,7 +827,8 @@ virFreeDomain(virConnectPtr conn, virDom
         virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
         return(-1);
     }
-    xmlMutexLock(conn->hashes_mux);
+    if (lock)
+        xmlMutexLock(conn->hashes_mux);
 
     /*
      * decrement the count for the domain
@@ -853,13 +860,14 @@ virFreeDomain(virConnectPtr conn, virDom
     
     if (conn->domains != NULL)
         virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
-    if (conn->hashes_mux != NULL)
+    if (conn->hashes_mux != NULL && lock)
         xmlFreeMutex(conn->hashes_mux);
     free(conn);
     return(0);
 
 done:
-    xmlMutexUnlock(conn->hashes_mux);
+    if (lock)
+        xmlMutexUnlock(conn->hashes_mux);
     return(ret);
 }
 
Index: src/internal.h
===================================================================
RCS file: /data/cvs/libvirt/src/internal.h,v
retrieving revision 1.41
diff -u -p -r1.41 internal.h
--- src/internal.h      8 May 2007 10:53:27 -0000       1.41
+++ src/internal.h      7 Jun 2007 02:08:41 -0000
@@ -202,7 +202,7 @@ virDomainPtr        __virGetDomain  (virConnectP
                                 const char *name,
                                 const unsigned char *uuid);
 int            virFreeDomain   (virConnectPtr conn,
-                                virDomainPtr domain);
+                                virDomainPtr domain, int lock);
 virDomainPtr   virGetDomainByID(virConnectPtr conn,
                                 int id);
 virNetworkPtr  __virGetNetwork (virConnectPtr conn,
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.73
diff -u -p -r1.73 libvirt.c
--- src/libvirt.c       5 Jun 2007 12:06:08 -0000       1.73
+++ src/libvirt.c       7 Jun 2007 02:08:41 -0000
@@ -730,7 +730,7 @@ virDomainFree(virDomainPtr domain)
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
         return (-1);
     }
-    if (virFreeDomain(domain->conn, domain) < 0)
+    if (virFreeDomain(domain->conn, domain, 1) < 0)
         return (-1);
     return(0);
 }
Index: src/qemu_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_internal.c,v
retrieving revision 1.25
diff -u -p -r1.25 qemu_internal.c
--- src/qemu_internal.c 5 Jun 2007 12:06:08 -0000       1.25
+++ src/qemu_internal.c 7 Jun 2007 02:08:42 -0000
@@ -906,7 +906,7 @@ static int qemuUndefine(virDomainPtr dom
     }
 
  cleanup:
-    if (virFreeDomain(dom->conn, dom) < 0)
+    if (virFreeDomain(dom->conn, dom, 1) < 0)
         ret = -1;
 
     return ret;
Index: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.116
diff -u -p -r1.116 xend_internal.c
--- src/xend_internal.c 5 Jun 2007 12:06:09 -0000       1.116
+++ src/xend_internal.c 7 Jun 2007 02:08:42 -0000
@@ -1900,7 +1900,7 @@ error:
     virXendError(conn, VIR_ERR_INTERNAL_ERROR,
                  _("failed to parse Xend domain information"));
     if (ret != NULL)
-        virFreeDomain(conn, ret);
+        virFreeDomain(conn, ret, 1);
     return(NULL);
 }
 #endif /* !PROXY */
@@ -3055,7 +3055,7 @@ xenDaemonCreateLinux(virConnectPtr conn,
     /* Make sure we don't leave a still-born domain around */
     if (dom != NULL) {
         xenDaemonDomainDestroy(dom);
-        virFreeDomain(dom->conn, dom);
+        virFreeDomain(dom->conn, dom, 1);
     }
     if (name != NULL)
         free(name);

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

Reply via email to