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. --- diff to v2: - remove redundant flag VIR_XML_EMIT_WARNING - remove enum, pass const string instead - don't translate warning message diff to v1: - instead of pointing users to web, write down the actual virsh command - write to passed FD instead of buffer src/conf/domain_conf.c | 2 ++ src/conf/network_conf.c | 2 ++ src/conf/nwfilter_conf.c | 4 ++++ src/conf/storage_conf.c | 2 ++ src/libvirt_private.syms | 1 + src/util/util.c | 37 +++++++++++++++++++++++++++++++++++++ src/util/util.h | 4 ++++ 7 files changed, 52 insertions(+), 0 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index eae178b..e98af0f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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, diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 08f7b77..4eb46fa 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -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, diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 5ba2972..eb75bad 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -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, diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index aeb1596..9be4cae 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -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, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ea4bf74..e2e706d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -901,6 +901,7 @@ virArgvToString; virAsprintf; virBuildPathInternal; virDirCreate; +virEmitXMLWarning; virEnumFromString; virEnumToString; virEventAddHandle; diff --git a/src/util/util.c b/src/util/util.c index 9041ab6..3b151f4 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -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; +} diff --git a/src/util/util.h b/src/util/util.h index d320c40..9d8df06 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -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__ */ -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list