Allow overwrite of existing guest config

This commit is contained in:
Daniel P. Berrange 2007-05-22 00:39:59 +00:00
parent f58ac222be
commit 3b0acf5616
2 changed files with 41 additions and 2 deletions

View File

@ -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> 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 * qemud/conf.c, qemud/internal.h, qemud/qemud.c: Save VM output

View File

@ -2072,7 +2072,9 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
*/ */
virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) { virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
virDomainPtr ret; virDomainPtr ret;
virDomainPtr olddomain;
char filename[PATH_MAX]; char filename[PATH_MAX];
const char * oldfilename;
unsigned char uuid[VIR_UUID_BUFLEN]; unsigned char uuid[VIR_UUID_BUFLEN];
virConfPtr conf = NULL; virConfPtr conf = NULL;
xenXMConfCachePtr entry = NULL; xenXMConfCachePtr entry = NULL;
@ -2103,10 +2105,41 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
} }
if (virHashLookup(nameConfigMap, value->str)) { if (virHashLookup(nameConfigMap, value->str)) {
xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "domain with name already exists"); /* 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; 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) { if ((strlen(configDir) + 1 + strlen(value->str) + 1) > PATH_MAX) {
xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "config file name is too long"); xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "config file name is too long");
goto error; goto error;