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

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