mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
Add warning message to XML definition files stored on disk
Users often edit XML file stored in configuration directory thinking of modifying a domain/network/pool/etc. Thus it is wise to let them know they are using the wrong way and give them hint.
This commit is contained in:
parent
d37c6a3ae0
commit
5d09c31495
2
AUTHORS
2
AUTHORS
@ -27,6 +27,7 @@ The primary maintainers and people with commit access rights:
|
||||
Justin Clift <jclift@redhat.com>
|
||||
Osier Yang <jyang@redhat.com>
|
||||
Wen Congyang <wency@cn.fujitsu.com>
|
||||
Michal Prívozník <mprivozn@redhat.com>
|
||||
|
||||
Previous maintainers:
|
||||
Karel Zak <kzak@redhat.com>
|
||||
@ -146,7 +147,6 @@ Patches have also been contributed by:
|
||||
Paweł Krześniak <pawel.krzesniak@gmail.com>
|
||||
Kay Schubert <kayegypt@web.de>
|
||||
Marc-André Lureau <marcandre.lureau@redhat.com>
|
||||
Michal Prívozník <mprivozn@redhat.com>
|
||||
Juerg Haefliger <juerg.haefliger@hp.com>
|
||||
Matthias Dahl <mdvirt@designassembly.de>
|
||||
Niels de Vos <ndevos@redhat.com>
|
||||
|
@ -8561,6 +8561,8 @@ int virDomainSaveXML(const char *configDir,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virEmitXMLWarning(fd, def->name, "edit");
|
||||
|
||||
towrite = strlen(xml);
|
||||
if (safewrite(fd, xml, towrite) < 0) {
|
||||
virReportSystemError(errno,
|
||||
|
@ -925,6 +925,8 @@ int virNetworkSaveXML(const char *configDir,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virEmitXMLWarning(fd, def->name, "net-edit");
|
||||
|
||||
towrite = strlen(xml);
|
||||
if (safewrite(fd, xml, towrite) < 0) {
|
||||
virReportSystemError(errno,
|
||||
|
@ -2249,6 +2249,8 @@ int virNWFilterSaveXML(const char *configDir,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virEmitXMLWarning(fd, def->name, "nwfilter-edit");
|
||||
|
||||
towrite = strlen(xml);
|
||||
if (safewrite(fd, xml, towrite) < 0) {
|
||||
virReportSystemError(errno,
|
||||
@ -2645,6 +2647,8 @@ virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virEmitXMLWarning(fd, def->name, "nwfilter-edit");
|
||||
|
||||
towrite = strlen(xml);
|
||||
if (safewrite(fd, xml, towrite) != towrite) {
|
||||
virReportSystemError(errno,
|
||||
|
@ -1551,6 +1551,8 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virEmitXMLWarning(fd, def->name, "pool-edit");
|
||||
|
||||
towrite = strlen(xml);
|
||||
if (safewrite(fd, xml, towrite) != towrite) {
|
||||
virReportSystemError(errno,
|
||||
|
@ -901,6 +901,7 @@ virArgvToString;
|
||||
virAsprintf;
|
||||
virBuildPathInternal;
|
||||
virDirCreate;
|
||||
virEmitXMLWarning;
|
||||
virEnumFromString;
|
||||
virEnumToString;
|
||||
virEventAddHandle;
|
||||
|
@ -3207,3 +3207,40 @@ bool virIsDevMapperDevice(const char *devname ATTRIBUTE_UNUSED)
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
int virEmitXMLWarning(int fd,
|
||||
const char *name,
|
||||
const char *cmd) {
|
||||
size_t len;
|
||||
const char *prologue = "<!--\n\
|
||||
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE \n\
|
||||
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:\n\
|
||||
virsh ";
|
||||
const char *epilogue = "\n\
|
||||
or other application using the libvirt API.\n\
|
||||
-->\n\n";
|
||||
|
||||
if (fd < 0 || !name || !cmd)
|
||||
return -1;
|
||||
|
||||
len = strlen(prologue);
|
||||
if (safewrite(fd, prologue, len) != len)
|
||||
return -1;
|
||||
|
||||
len = strlen(cmd);
|
||||
if (safewrite(fd, cmd, len) != len)
|
||||
return -1;
|
||||
|
||||
if (safewrite(fd, " ", 1) != 1)
|
||||
return -1;
|
||||
|
||||
len = strlen(name);
|
||||
if (safewrite(fd, name, len) != len)
|
||||
return -1;
|
||||
|
||||
len = strlen(epilogue);
|
||||
if (safewrite(fd, epilogue, len) != len)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -299,4 +299,8 @@ int virBuildPathInternal(char **path, ...) ATTRIBUTE_SENTINEL;
|
||||
char *virTimestamp(void);
|
||||
|
||||
bool virIsDevMapperDevice(const char *devname) ATTRIBUTE_NONNULL(1);
|
||||
|
||||
int virEmitXMLWarning(int fd,
|
||||
const char *name,
|
||||
const char *cmd) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
||||
#endif /* __VIR_UTIL_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user