libvirt/SOURCES/libvirt-networkGetDHCPLease...

60 lines
2.6 KiB
Diff

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