[PATCH 4/4] nwfilter: Save config to disk if we generated a UUID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



libvirt-daemon-config-nwfilter will put a bunch of xml configs
into /etc/libvirt/nwfilter. These configs don't hardcode a UUID
and depends on libvirt to generate one. However the generated UUID
is never saved to disk, unless the user manually calls Define.

This makes daemon reload quite noisy with many errors like:

error : virNWFilterObjAssignDef:3101 : operation failed: filter 'allow-incoming-ipv4' already exists with uuid 50def3b5-48d6-46a3-b005-cc22df4e5c5c

Because a new UUID is generated every time the config is read from
disk, so libvirt constantly thinks it's finding a new nwfilter.

Detect if we generated a UUID when the config file is loaded; if so,
resave the new contents to disk to ensure the UUID is persisteny.

This is similar to what was done in commit a47ae7c0 with virtual
networks and generated MAC addresses
---
 src/conf/nwfilter_conf.c | 6 ++++++
 src/conf/nwfilter_conf.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index d8e83f0..f9cb8ea 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2658,6 +2658,7 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
     }
 
     uuid = virXPathString("string(./uuid)", ctxt);
+    ret->uuid_specified = (uuid != NULL);
     if (uuid == NULL) {
         if (virUUIDGenerate(ret->uuid) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3178,6 +3179,11 @@ virNWFilterLoadConfig(virNWFilterObjListPtr nwfilters,
         goto error;
     }
 
+    /* We generated a UUID, make it permanent by saving the config to disk */
+    if (!def->uuid_specified &&
+        virNWFilterSaveConfig(configDir, def) < 0)
+        goto error;
+
     if (!(nwfilter = virNWFilterObjAssignDef(nwfilters, def))) {
         goto error;
     }
diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h
index 823cfa4..ea3cd5c 100644
--- a/src/conf/nwfilter_conf.h
+++ b/src/conf/nwfilter_conf.h
@@ -536,6 +536,7 @@ typedef virNWFilterDef *virNWFilterDefPtr;
 struct _virNWFilterDef {
     char *name;
     unsigned char uuid[VIR_UUID_BUFLEN];
+    bool uuid_specified;
 
     char *chainsuffix;
     virNWFilterChainPriority chainPriority;
-- 
2.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]