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