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:
Michal Privoznik 2011-04-29 11:28:28 +02:00
parent d37c6a3ae0
commit 5d09c31495
8 changed files with 53 additions and 1 deletions

View File

@ -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>

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -901,6 +901,7 @@ virArgvToString;
virAsprintf;
virBuildPathInternal;
virDirCreate;
virEmitXMLWarning;
virEnumFromString;
virEnumToString;
virEventAddHandle;

View File

@ -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;
}

View File

@ -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__ */