mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
xml: print uuids in the warning
In the XML warning, we print a virsh command line that can be used to edit that XML. This patch prints UUIDs if the entity name contains special characters (like shell metacharacters, or "--" that would break parsing of the XML comment). If the entity doesn't have a UUID, just print the virsh command that can be used to edit it.
This commit is contained in:
parent
23f5e74ed3
commit
0b121614a2
@ -14288,6 +14288,7 @@ int virDomainSaveXML(const char *configDir,
|
|||||||
virDomainDefPtr def,
|
virDomainDefPtr def,
|
||||||
const char *xml)
|
const char *xml)
|
||||||
{
|
{
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
char *configFile = NULL;
|
char *configFile = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -14301,7 +14302,10 @@ int virDomainSaveXML(const char *configDir,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virXMLSaveFile(configFile, def->name, "edit", xml);
|
virUUIDFormat(def->uuid, uuidstr);
|
||||||
|
ret = virXMLSaveFile(configFile,
|
||||||
|
virXMLPickShellSafeComment(def->name, uuidstr), "edit",
|
||||||
|
xml);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(configFile);
|
VIR_FREE(configFile);
|
||||||
|
@ -1978,6 +1978,7 @@ int virNetworkSaveXML(const char *configDir,
|
|||||||
virNetworkDefPtr def,
|
virNetworkDefPtr def,
|
||||||
const char *xml)
|
const char *xml)
|
||||||
{
|
{
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
char *configFile = NULL;
|
char *configFile = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -1991,7 +1992,10 @@ int virNetworkSaveXML(const char *configDir,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virXMLSaveFile(configFile, def->name, "net-edit", xml);
|
virUUIDFormat(def->uuid, uuidstr);
|
||||||
|
ret = virXMLSaveFile(configFile,
|
||||||
|
virXMLPickShellSafeComment(def->name, uuidstr),
|
||||||
|
"net-edit", xml);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(configFile);
|
VIR_FREE(configFile);
|
||||||
|
@ -2717,6 +2717,7 @@ int virNWFilterSaveXML(const char *configDir,
|
|||||||
virNWFilterDefPtr def,
|
virNWFilterDefPtr def,
|
||||||
const char *xml)
|
const char *xml)
|
||||||
{
|
{
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
char *configFile = NULL;
|
char *configFile = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -2730,7 +2731,10 @@ int virNWFilterSaveXML(const char *configDir,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virXMLSaveFile(configFile, def->name, "nwfilter-edit", xml);
|
virUUIDFormat(def->uuid, uuidstr);
|
||||||
|
ret = virXMLSaveFile(configFile,
|
||||||
|
virXMLPickShellSafeComment(def->name, uuidstr),
|
||||||
|
"nwfilter-edit", xml);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(configFile);
|
VIR_FREE(configFile);
|
||||||
@ -3151,6 +3155,7 @@ virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
|
|||||||
virNWFilterObjPtr nwfilter,
|
virNWFilterObjPtr nwfilter,
|
||||||
virNWFilterDefPtr def)
|
virNWFilterDefPtr def)
|
||||||
{
|
{
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
char *xml;
|
char *xml;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -3174,7 +3179,10 @@ virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virXMLSaveFile(nwfilter->configFile, def->name, "nwfilter-edit", xml);
|
virUUIDFormat(def->uuid, uuidstr);
|
||||||
|
ret = virXMLSaveFile(nwfilter->configFile,
|
||||||
|
virXMLPickShellSafeComment(def->name, uuidstr),
|
||||||
|
"nwfilter-edit", xml);
|
||||||
VIR_FREE(xml);
|
VIR_FREE(xml);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1637,6 +1637,7 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
|
|||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
virStoragePoolDefPtr def)
|
virStoragePoolDefPtr def)
|
||||||
{
|
{
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
char *xml;
|
char *xml;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -1666,7 +1667,10 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virXMLSaveFile(pool->configFile, def->name, "pool-edit", xml);
|
virUUIDFormat(def->uuid, uuidstr);
|
||||||
|
ret = virXMLSaveFile(pool->configFile,
|
||||||
|
virXMLPickShellSafeComment(def->name, uuidstr),
|
||||||
|
"pool-edit", xml);
|
||||||
VIR_FREE(xml);
|
VIR_FREE(xml);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1819,6 +1819,7 @@ virURIParse;
|
|||||||
# xml.h
|
# xml.h
|
||||||
virXMLChildElementCount;
|
virXMLChildElementCount;
|
||||||
virXMLParseHelper;
|
virXMLParseHelper;
|
||||||
|
virXMLPickShellSafeComment;
|
||||||
virXMLPropString;
|
virXMLPropString;
|
||||||
virXMLSaveFile;
|
virXMLSaveFile;
|
||||||
virXPathBoolean;
|
virXPathBoolean;
|
||||||
|
@ -973,8 +973,7 @@ parallelsStorageVolumeDefine(virStoragePoolObjPtr pool,
|
|||||||
if (!xml_path)
|
if (!xml_path)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virXMLSaveFile(xml_path, privvol->name,
|
if (virXMLSaveFile(xml_path, NULL, "volume-create", xmldesc)) {
|
||||||
"volume-create", xmldesc)) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
_("Can't create file with volume description"));
|
_("Can't create file with volume description"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -1599,7 +1599,6 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
|
|||||||
char *snapDir = NULL;
|
char *snapDir = NULL;
|
||||||
char *snapFile = NULL;
|
char *snapFile = NULL;
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
virUUIDFormat(vm->def->uuid, uuidstr);
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
||||||
newxml = virDomainSnapshotDefFormat(uuidstr, snapshot->def,
|
newxml = virDomainSnapshotDefFormat(uuidstr, snapshot->def,
|
||||||
@ -1622,13 +1621,7 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virAsprintf(&tmp, "snapshot-edit %s", vm->def->name) < 0) {
|
ret = virXMLSaveFile(snapFile, NULL, "snapshot-edit", newxml);
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = virXMLSaveFile(snapFile, snapshot->def->name, tmp, newxml);
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(snapFile);
|
VIR_FREE(snapFile);
|
||||||
|
@ -780,6 +780,16 @@ error:
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *virXMLPickShellSafeComment(const char *str1, const char *str2)
|
||||||
|
{
|
||||||
|
if(str1 && !strpbrk(str1, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~") &&
|
||||||
|
!strstr(str1, "--"))
|
||||||
|
return str1;
|
||||||
|
if(str2 && !strpbrk(str2, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~") &&
|
||||||
|
!strstr(str2, "--"))
|
||||||
|
return str2;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int virXMLEmitWarning(int fd,
|
static int virXMLEmitWarning(int fd,
|
||||||
const char *name,
|
const char *name,
|
||||||
@ -794,7 +804,7 @@ OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:\n\
|
|||||||
or other application using the libvirt API.\n\
|
or other application using the libvirt API.\n\
|
||||||
-->\n\n";
|
-->\n\n";
|
||||||
|
|
||||||
if (fd < 0 || !name || !cmd) {
|
if (fd < 0 || !cmd) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -807,9 +817,7 @@ or other application using the libvirt API.\n\
|
|||||||
if (safewrite(fd, cmd, len) != len)
|
if (safewrite(fd, cmd, len) != len)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Omit the domain name if it contains a double hyphen
|
if (name) {
|
||||||
* because they aren't allowed in XML comments */
|
|
||||||
if (!strstr(name, "--")) {
|
|
||||||
if (safewrite(fd, " ", 1) != 1)
|
if (safewrite(fd, " ", 1) != 1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -837,7 +845,7 @@ virXMLRewriteFile(int fd, void *opaque)
|
|||||||
{
|
{
|
||||||
struct virXMLRewriteFileData *data = opaque;
|
struct virXMLRewriteFileData *data = opaque;
|
||||||
|
|
||||||
if (data->warnName && data->warnCommand) {
|
if (data->warnCommand) {
|
||||||
if (virXMLEmitWarning(fd, data->warnName, data->warnCommand) < 0)
|
if (virXMLEmitWarning(fd, data->warnName, data->warnCommand) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ xmlDocPtr virXMLParseHelper(int domcode,
|
|||||||
const char *url,
|
const char *url,
|
||||||
xmlXPathContextPtr *pctxt);
|
xmlXPathContextPtr *pctxt);
|
||||||
|
|
||||||
|
const char *virXMLPickShellSafeComment(const char *str1, const char *str2);
|
||||||
/**
|
/**
|
||||||
* virXMLParse:
|
* virXMLParse:
|
||||||
* @filename: file to parse, or NULL for string parsing
|
* @filename: file to parse, or NULL for string parsing
|
||||||
|
Loading…
Reference in New Issue
Block a user