This patch also changes functionality a bit.
First if unlinking of old config file is failed we rollback and return error
previously and now we return success. I don't think this makes much difference.
I guess in both cases on libvirtd restart we have to deal with both new and old
config existing on disk with different names but same uuid.
Second if unlinking of old autolink is failed we rollback previously which
was not right as at this point we already unlink old config file. So this
is fixed now.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/qemu/qemu_domain.c | 29 +++++++++++++++++++++++++++++
src/qemu/qemu_domain.h | 5 +++++
src/qemu/qemu_driver.c | 39 ++++++++-------------------------------
3 files changed, 42 insertions(+), 31 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index d7dbca4..7b2c165 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11094,3 +11094,32 @@ qemuDomainInterfaceSetDefaultQDisc(virQEMUDriverPtr driver,
return 0;
}
+
+
+int
+qemuDomainNamePathsCleanup(virQEMUDriverConfigPtr cfg,
+ const char *name,
+ bool bestEffort)
+{
+ g_autofree char *cfg_file = NULL;
+ g_autofree char *autostart_link = NULL;
+
+ cfg_file = virDomainConfigFile(cfg->configDir, name);
+ autostart_link = virDomainConfigFile(cfg->autostartDir, name);
+
+ if (virFileExists(cfg_file) &&
+ unlink(cfg_file) < 0) {
+ virReportSystemError(errno, _("Failed to unlink '%s'"),
cfg_file);
+ if (!bestEffort)
+ return -1;
+ }
+
+ if (virFileIsLink(autostart_link) == 1 &&
+ unlink(autostart_link) < 0) {
+ virReportSystemError(errno, _("Failed to unlink '%s'"),
autostart_link);
+ if (!bestEffort)
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index fc69678..a2dfe86 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1050,3 +1050,8 @@ qemuDomainFileWrapperFDClose(virDomainObjPtr vm,
int
qemuDomainInterfaceSetDefaultQDisc(virQEMUDriverPtr driver,
virDomainNetDefPtr net);
+
+int
+qemuDomainNamePathsCleanup(virQEMUDriverConfigPtr cfg,
+ const char *name,
+ bool bestEffort);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 621facc..52c42cf 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19112,6 +19112,7 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
virObjectEventPtr event_new = NULL;
virObjectEventPtr event_old = NULL;
int ret = -1;
+ virErrorPtr err = NULL;
g_autofree char *new_dom_name = NULL;
g_autofree char *old_dom_name = NULL;
g_autofree char *new_dom_cfg_file = NULL;
@@ -19158,25 +19159,7 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
new_dom_name = NULL;
if (virDomainDefSave(vm->def, driver->xmlopt, cfg->configDir) < 0)
- goto rollback;
-
- if (virFileExists(old_dom_cfg_file) &&
- unlink(old_dom_cfg_file) < 0) {
- virReportSystemError(errno,
- _("cannot remove old domain config file %s"),
- old_dom_cfg_file);
- 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;
- }
- }
+ goto cleanup;
event_old = virDomainEventLifecycleNew(vm->def->id, old_dom_name,
vm->def->uuid,
VIR_DOMAIN_EVENT_UNDEFINED,
@@ -19189,23 +19172,17 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
ret = 0;
cleanup:
- return ret;
-
- rollback:
- if (old_dom_name) {
+ if (old_dom_name && ret < 0) {
new_dom_name = vm->def->name;
vm->def->name = old_dom_name;
old_dom_name = NULL;
}
- 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;
+ if (ret < 0)
+ virErrorPreserveLast(&err);
+ qemuDomainNamePathsCleanup(cfg, ret < 0 ? new_dom_name : old_dom_name, true);
+ virErrorRestore(&err);
+ return ret;
}
static int qemuDomainRename(virDomainPtr dom,
--
1.8.3.1