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

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