Ensure domains are killed off if hotplug fails. Fix deletion of inactive domains

This commit is contained in:
Daniel P. Berrange 2007-02-22 19:09:29 +00:00
parent 0f5e637a26
commit 6d6261f4e8
3 changed files with 37 additions and 30 deletions

View File

@ -1,3 +1,10 @@
Thu Feb 22 14:06:24 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/xm_internal.c, src/xend_internal.c: Re-arrange VM creation
commands to ensure we destroy stillborn domains if device hotplug
fails to complete. Fix deletion of inactive VMs from internal
cache of domain configs.
Thu Feb 22 11:45:24 EST 2007 Daniel P. Berrange <berrange@redhat.com> Thu Feb 22 11:45:24 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/xs_internal.c: Refuse to do shutdown / reboot on * src/xs_internal.c: Refuse to do shutdown / reboot on

View File

@ -2816,7 +2816,7 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
int ret; int ret;
char *sexpr; char *sexpr;
char *name = NULL; char *name = NULL;
virDomainPtr dom; virDomainPtr dom = NULL;
if (!VIR_IS_CONNECT(conn)) { if (!VIR_IS_CONNECT(conn)) {
virXendError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__); virXendError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
@ -2841,32 +2841,30 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
ret = xenDaemonDomainCreateLinux(conn, sexpr); ret = xenDaemonDomainCreateLinux(conn, sexpr);
free(sexpr); free(sexpr);
if (ret != 0) { if (ret != 0) {
fprintf(stderr, _("Failed to create domain %s\n"), name);
goto error; goto error;
} }
ret = xend_wait_for_devices(conn, name); /* This comes before wait_for_devices, to ensure that latter
if (ret != 0) { cleanup will destroy the domain upon failure */
fprintf(stderr, _("Failed to get devices for domain %s\n"), name); if (!(dom = virDomainLookupByName(conn, name)))
goto error; goto error;
}
dom = virDomainLookupByName(conn, name); if ((ret = xend_wait_for_devices(conn, name)) < 0)
if (dom == NULL) {
goto error; goto error;
}
ret = xenDaemonDomainResume(dom); if ((ret = xenDaemonDomainResume(dom)) < 0)
if (ret != 0) {
fprintf(stderr, _("Failed to resume new domain %s\n"), name);
xenDaemonDomainDestroy(dom);
goto error; goto error;
}
free(name); free(name);
return (dom); return (dom);
error: error:
/* Make sure we don't leave a still-born domain around */
if (dom != NULL) {
xenDaemonDomainDestroy(dom);
virFreeDomain(dom->conn, dom);
}
if (name != NULL) if (name != NULL)
free(name); free(name);
return (NULL); return (NULL);

View File

@ -50,7 +50,9 @@ typedef struct xenXMConfCache {
} xenXMConfCache; } xenXMConfCache;
static char configDir[PATH_MAX]; static char configDir[PATH_MAX];
/* Config file name to config object */
static virHashTablePtr configCache = NULL; static virHashTablePtr configCache = NULL;
/* Name to config file name */
static virHashTablePtr nameConfigMap = NULL; static virHashTablePtr nameConfigMap = NULL;
static int nconnections = 0; static int nconnections = 0;
static time_t lastRefresh = 0; static time_t lastRefresh = 0;
@ -1295,13 +1297,6 @@ int xenXMDomainCreate(virDomainPtr domain) {
ret = xenDaemonDomainCreateLinux(domain->conn, sexpr); ret = xenDaemonDomainCreateLinux(domain->conn, sexpr);
free(sexpr); free(sexpr);
if (ret != 0) { if (ret != 0) {
fprintf(stderr, "Failed to create domain %s\n", domain->name);
return (-1);
}
ret = xend_wait_for_devices(domain->conn, domain->name);
if (ret != 0) {
fprintf(stderr, "Failed to get devices for domain %s\n", domain->name);
return (-1); return (-1);
} }
@ -1310,15 +1305,20 @@ int xenXMDomainCreate(virDomainPtr domain) {
} }
domain->id = ret; domain->id = ret;
ret = xenDaemonDomainResume(domain); if ((ret = xend_wait_for_devices(domain->conn, domain->name)) < 0)
if (ret != 0) { goto cleanup;
fprintf(stderr, "Failed to resume new domain %s\n", domain->name);
xenDaemonDomainDestroy(domain); if ((ret = xenDaemonDomainResume(domain)) < 0)
domain->id = -1; goto cleanup;
return (-1);
}
return (0); return (0);
cleanup:
if (domain->id != -1) {
xenDaemonDomainDestroy(domain);
domain->id = -1;
}
return (-1);
} }
@ -2165,10 +2165,12 @@ int xenXMDomainUndefine(virDomainPtr domain) {
if (unlink(entry->filename) < 0) if (unlink(entry->filename) < 0)
return (-1); return (-1);
if (virHashRemoveEntry(nameConfigMap, entry->filename, NULL) < 0) /* Remove the name -> filename mapping */
if (virHashRemoveEntry(nameConfigMap, domain->name, NULL) < 0)
return(-1); return(-1);
if (virHashRemoveEntry(configCache, domain->name, xenXMConfigFree) < 0) /* Remove the config record itself */
if (virHashRemoveEntry(configCache, entry->filename, xenXMConfigFree) < 0)
return (-1); return (-1);
return (0); return (0);