Blame SOURCES/libvirt-networkGetDHCPLeases-Don-t-always-report-error-if-unable-to-read-leases-file.patch

edecca
From dfd454d377c90f5a039c6a8487703dd604bffabc Mon Sep 17 00:00:00 2001
edecca
Message-Id: <dfd454d377c90f5a039c6a8487703dd604bffabc@dist-git>
edecca
From: Michal Privoznik <mprivozn@redhat.com>
edecca
Date: Thu, 26 Jul 2018 11:41:09 +0200
edecca
Subject: [PATCH] networkGetDHCPLeases: Don't always report error if unable to
edecca
 read leases file
edecca
edecca
https://bugzilla.redhat.com/show_bug.cgi?id=1600468
edecca
edecca
If we are unable to read leases file (no matter what the reason
edecca
is), we return 0 - just like if there were no leases. However,
edecca
because we use virFileReadAll() an error is printed into the log.
edecca
Note that not all networks have leases file - only those for
edecca
which we start dnsmasq.
edecca
edecca
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
edecca
Reviewed-by: Erik Skultety <eskultet@redhat.com>
edecca
(cherry picked from commit 142c4b10fd8f55b7d2e86f5a184608da70f2edd3)
edecca
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
edecca
Reviewed-by: Erik Skultety <eskultet@redhat.com>
edecca
---
edecca
 src/network/bridge_driver.c | 21 ++++++++++++++-------
edecca
 1 file changed, 14 insertions(+), 7 deletions(-)
edecca
edecca
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
edecca
index ac849581ec..1ad95d524c 100644
edecca
--- a/src/network/bridge_driver.c
edecca
+++ b/src/network/bridge_driver.c
edecca
@@ -4157,13 +4157,20 @@ networkGetDHCPLeases(virNetworkPtr net,
edecca
     custom_lease_file = networkDnsmasqLeaseFileNameCustom(driver, def->bridge);
edecca
 
edecca
     /* Read entire contents */
edecca
-    if ((custom_lease_file_len = virFileReadAll(custom_lease_file,
edecca
-                                                VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX,
edecca
-                                                &lease_entries)) < 0) {
edecca
-        /* Even though src/network/leaseshelper.c guarantees the existence of
edecca
-         * leases file (even if no leases are present), and the control reaches
edecca
-         * here, instead of reporting error, return 0 leases */
edecca
-        rv = 0;
edecca
+    if ((custom_lease_file_len = virFileReadAllQuiet(custom_lease_file,
edecca
+                                                     VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX,
edecca
+                                                     &lease_entries)) < 0) {
edecca
+        /* Not all networks are guaranteed to have leases file.
edecca
+         * Only those which run dnsmasq. Therefore, if we failed
edecca
+         * to read the leases file, don't report error. Return 0
edecca
+         * leases instead. */
edecca
+        if (errno == ENOENT) {
edecca
+            rv = 0;
edecca
+        } else {
edecca
+            virReportSystemError(errno,
edecca
+                                 _("Unable to read leases file: %s"),
edecca
+                                 custom_lease_file);
edecca
+        }
edecca
         goto error;
edecca
     }
edecca
 
edecca
-- 
edecca
2.18.0
edecca