virsh: Preserve startupPolicy in change-media command

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

Even after my rework of startupPolicy handling, one command
slipped my attention. The change-media command has a very unique
approach to constructing disk XML. However, it will not preserve
startupPolicy attribute.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2015-09-24 18:00:06 +02:00
parent 1b5685dada
commit d72a8f7465

View File

@ -11534,6 +11534,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node,
xmlNodePtr source = NULL; xmlNodePtr source = NULL;
char *device_type = NULL; char *device_type = NULL;
char *ret = NULL; char *ret = NULL;
char *startupPolicy = NULL;
if (!disk_node) if (!disk_node)
return NULL; return NULL;
@ -11567,13 +11568,15 @@ virshUpdateDiskXML(xmlNodePtr disk_node,
goto cleanup; goto cleanup;
} }
if (type == VIRSH_UPDATE_DISK_XML_INSERT && source) {
vshError(NULL, _("The disk device '%s' already has media"), target);
goto cleanup;
}
/* remove current source */
if (source) { if (source) {
if (type == VIRSH_UPDATE_DISK_XML_INSERT) {
vshError(NULL, _("The disk device '%s' already has media"), target);
goto cleanup;
}
startupPolicy = virXMLPropString(source, "startupPolicy");
/* remove current source */
xmlUnlinkNode(source); xmlUnlinkNode(source);
xmlFreeNode(source); xmlFreeNode(source);
source = NULL; source = NULL;
@ -11597,6 +11600,8 @@ virshUpdateDiskXML(xmlNodePtr disk_node,
else else
xmlNewProp(source, BAD_CAST "file", BAD_CAST new_source); xmlNewProp(source, BAD_CAST "file", BAD_CAST new_source);
if (startupPolicy)
xmlNewProp(source, BAD_CAST "startupPolicy", BAD_CAST startupPolicy);
xmlAddChild(disk_node, source); xmlAddChild(disk_node, source);
} }
@ -11607,6 +11612,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node,
cleanup: cleanup:
VIR_FREE(device_type); VIR_FREE(device_type);
VIR_FREE(startupPolicy);
return ret; return ret;
} }