]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Allow overwrite of existing guest config
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 22 May 2007 00:39:59 +0000 (00:39 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 22 May 2007 00:39:59 +0000 (00:39 +0000)
ChangeLog
src/xm_internal.c

index c1d42a9d4807c1a5eb1c32234f7aa5b8b436ba7f..07a78a0214053c6f9c00e2fd0ea3fc73efd69018 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon May 21 20:38:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
+
+       * src/xm_internal.c: Allow xenXMDomainDefineXML to overwrite
+       an existing guest config to match semantics of XenD and QEMU
+       drivers. Patch from Hugh Brock.
+
 Fri May 18 14:36:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
 
        * qemud/conf.c, qemud/internal.h, qemud/qemud.c: Save VM output
index 066a09a91e0616408ae06394b56732b65a995066..2ca25cd562d5a07a62e1d9b8c8787a49e19c6b12 100644 (file)
@@ -2072,7 +2072,9 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
  */
 virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
     virDomainPtr ret;
+    virDomainPtr olddomain;
     char filename[PATH_MAX];
+    const char * oldfilename;
     unsigned char uuid[VIR_UUID_BUFLEN];
     virConfPtr conf = NULL;
     xenXMConfCachePtr entry = NULL;
@@ -2103,8 +2105,39 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
     }
 
     if (virHashLookup(nameConfigMap, value->str)) {
-        xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "domain with name already exists");
-        goto error;
+        /* domain exists, we will overwrite it */
+
+        if (!(oldfilename = (char *)virHashLookup(nameConfigMap, value->str))) {
+            xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "can't retrieve config filename for domain to overwrite");
+            goto error;
+        }
+
+        if (!(entry = virHashLookup(configCache, oldfilename))) {
+            xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "can't retrieve config entry for domain to overwrite");
+            goto error;
+        }
+
+        if (xenXMConfigGetUUID(entry->conf, "uuid", uuid) < 0) {
+            xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "uuid config parameter is missing");
+            goto error;
+        }
+        
+        if (!(olddomain = virGetDomain(conn, value->str, uuid)))
+            goto error;
+
+        /* Remove the name -> filename mapping */
+        if (virHashRemoveEntry(nameConfigMap, value->str, NULL) < 0) {
+            xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "failed to remove old domain from config map");
+            goto error;
+        }
+
+        /* Remove the config record itself */
+        if (virHashRemoveEntry(configCache, oldfilename, xenXMConfigFree) < 0) {
+            xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "failed to remove old domain from config map");
+            goto error;
+        }
+
+        entry = NULL;
     }
 
     if ((strlen(configDir) + 1 + strlen(value->str) + 1) > PATH_MAX) {