]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Fix broken autostart symlink after renaming domain
authorJulio Faracco <jcfaracco@gmail.com>
Thu, 19 Jul 2018 04:21:48 +0000 (01:21 -0300)
committerErik Skultety <eskultet@redhat.com>
Thu, 19 Jul 2018 09:22:28 +0000 (11:22 +0200)
If a domain is configured to start on boot, it has a symlink to the
domain definition inside the autostart directory. If you rename this
domain, the definition is renamed too. The symlink need to be pointed to
this renamed file. This commit recreates the symlink after renaming the
XML file.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1594985

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
src/qemu/qemu_driver.c

index 25170f6f26aefea38ca0e22ea801aafb709226f0..b5e6fe8132eb36e6ac1eb7524760f6bb5e8a7544 100644 (file)
@@ -20917,6 +20917,8 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
     char *old_dom_name = NULL;
     char *new_dom_cfg_file = NULL;
     char *old_dom_cfg_file = NULL;
+    char *new_dom_autostart_link = NULL;
+    char *old_dom_autostart_link = NULL;
 
     virCheckFlags(0, ret);
 
@@ -20937,6 +20939,21 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
                                                  vm->def->name)))
         goto cleanup;
 
+    if (vm->autostart) {
+        if (!(new_dom_autostart_link = virDomainConfigFile(cfg->autostartDir,
+                                                          new_dom_name)) ||
+            !(old_dom_autostart_link = virDomainConfigFile(cfg->autostartDir,
+                                                          vm->def->name)))
+            goto cleanup;
+
+        if (symlink(new_dom_cfg_file, new_dom_autostart_link) < 0) {
+            virReportSystemError(errno,
+                                 _("Failed to create symlink '%s to '%s'"),
+                                 new_dom_autostart_link, new_dom_cfg_file);
+            goto cleanup;
+        }
+    }
+
     event_old = virDomainEventLifecycleNewFromObj(vm,
                                             VIR_DOMAIN_EVENT_UNDEFINED,
                                             VIR_DOMAIN_EVENT_UNDEFINED_RENAMED);
@@ -20957,12 +20974,24 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
         goto rollback;
     }
 
+    if (vm->autostart) {
+        if (virFileIsLink(old_dom_autostart_link) &&
+            unlink(old_dom_autostart_link) < 0) {
+            virReportSystemError(errno,
+                                 _("Failed to delete symlink '%s'"),
+                                 old_dom_autostart_link);
+            goto rollback;
+        }
+    }
+
     event_new = virDomainEventLifecycleNewFromObj(vm,
                                               VIR_DOMAIN_EVENT_DEFINED,
                                               VIR_DOMAIN_EVENT_DEFINED_RENAMED);
     ret = 0;
 
  cleanup:
+    VIR_FREE(old_dom_autostart_link);
+    VIR_FREE(new_dom_autostart_link);
     VIR_FREE(old_dom_cfg_file);
     VIR_FREE(new_dom_cfg_file);
     VIR_FREE(old_dom_name);
@@ -20982,6 +21011,10 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
     if (virFileExists(new_dom_cfg_file))
         unlink(new_dom_cfg_file);
 
+    if (vm->autostart &&
+        virFileExists(new_dom_autostart_link))
+        unlink(new_dom_autostart_link);
+
     goto cleanup;
 }