[Libvirt-cim] [PATCH] Make infostore compare the UUID of the domain to the one stored in the

Dan Smith danms at us.ibm.com
Mon Aug 4 17:36:29 UTC 2008


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1217871367 25200
# Node ID 91cffef5e2cbb19f956e2969aacfd3fdab0d30b7
# Parent  3386917656ad569e226a846eea28793ecd852d0b
Make infostore compare the UUID of the domain to the one stored in the
store file, and if different, ignore all the information therein.

This should make sure that if a domain is undefined and redefined with
the same name, using other libvirt tools, the settings previously persisted
by the providers will not be used for the new domain.

Signed-off-by: Dan Smith <danms at us.ibm.com>

diff -r 3386917656ad -r 91cffef5e2cb libxkutil/infostore.c
--- a/libxkutil/infostore.c	Mon Aug 04 10:28:30 2008 -0700
+++ b/libxkutil/infostore.c	Mon Aug 04 10:36:07 2008 -0700
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include <sys/file.h>
+#include <string.h>
 
 #include <libvirt/libvirt.h>
 #include <libxml/parser.h>
@@ -164,7 +165,7 @@
         return size >= 0;
 }
 
-struct infostore_ctx *infostore_open(virDomainPtr dom)
+static struct infostore_ctx *_infostore_open(virDomainPtr dom)
 {
         struct infostore_ctx *isc;
         struct stat s;
@@ -228,6 +229,58 @@
         free(filename);
 
         return NULL;
+}
+
+static struct infostore_ctx *delete_and_open(virDomainPtr dom)
+{
+        char *filename = NULL;
+
+        filename = make_filename(dom);
+        if (filename == NULL) {
+                CU_DEBUG("Failed to make filename for domain");
+                return NULL;
+        }
+
+        if (unlink(filename) != 0) {
+                CU_DEBUG("Unable to delete %s: %m", filename);
+        } else {
+                CU_DEBUG("Deleted %s", filename);
+        }
+
+        free(filename);
+
+        return _infostore_open(dom);
+}
+
+struct infostore_ctx *infostore_open(virDomainPtr dom)
+{
+        struct infostore_ctx *isc;
+        char uuid[VIR_UUID_STRING_BUFLEN];
+        char *_uuid = NULL;
+
+        isc = _infostore_open(dom);
+        if (isc == NULL)
+                return NULL;
+
+        if (virDomainGetUUIDString(dom, uuid) != 0) {
+                CU_DEBUG("Failed to get UUID string for comparison");
+                infostore_close(isc);
+                isc = delete_and_open(dom);
+                return isc;
+        }
+
+        _uuid = infostore_get_str(isc, "uuid");
+        if (_uuid == NULL)
+                goto out;
+
+        if (!STREQ(uuid, _uuid)) {
+                infostore_close(isc);
+                isc = delete_and_open(dom);
+        }
+ out:
+        free(_uuid);
+        infostore_set_str(isc, "uuid", uuid);
+        return isc;
 }
 
 void infostore_close(struct infostore_ctx *ctx)




More information about the Libvirt-cim mailing list