Blame SOURCES/netcf-call-aug_load-at-most-once-per-second.patch

f586e2
From 513224ceee718af980b6bc01a3e5f3f0e6452307 Mon Sep 17 00:00:00 2001
f586e2
From: Laine Stump <laine@laine.org>
f586e2
Date: Mon, 28 Sep 2015 17:11:11 -0400
f586e2
Subject: [PATCH 1/2] call aug_load() at most once per second
f586e2
f586e2
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1268382
f586e2
f586e2
Previously, netcf would call aug_load() at the start of each public
f586e2
API call, and rely on augeas quickly determining if the files needed
f586e2
to be reread based on checking the mtime of all files. With a large
f586e2
number of files (i.e. several hundred ifcfg files) just checking the
f586e2
mtime of all files ends up taking quite a long time; enough to turn a
f586e2
simple "virsh iface-list" of 300 bridges + 300 vlans into a 22 second
f586e2
ordeal.
f586e2
f586e2
With this patch applied, netcf will only call aug_load() at most once
f586e2
every second, resulting in runtime for virsh iface-list going down to
f586e2
< 1 second.
f586e2
f586e2
The trade-off is that the results of a netcf API call could be up to 1
f586e2
second out of date (but only due to changes in the config external to
f586e2
netcf). Since ifcfg files change very infrequently, this is likely
f586e2
acceptable.
f586e2
f586e2
(cherry picked from commit 9b5f4eb57af28a604cd7ac8b2c1be9e49f0b517d)
f586e2
---
f586e2
 src/dutil_linux.c | 8 +++++++-
f586e2
 src/dutil_linux.h | 1 +
f586e2
 2 files changed, 8 insertions(+), 1 deletion(-)
f586e2
f586e2
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
f586e2
index 0850593..24f4d95 100644
f586e2
--- a/src/dutil_linux.c
f586e2
+++ b/src/dutil_linux.c
f586e2
@@ -32,6 +32,7 @@
f586e2
 #include <unistd.h>
f586e2
 #include <ctype.h>
f586e2
 #include <errno.h>
f586e2
+#include <time.h>
f586e2
 
f586e2
 #include <dirent.h>
f586e2
 #include <sys/wait.h>
f586e2
@@ -151,6 +152,7 @@ int remove_augeas_xfm_table(struct netcf *ncf,
f586e2
  */
f586e2
 augeas *get_augeas(struct netcf *ncf) {
f586e2
     int r;
f586e2
+    time_t current_time;
f586e2
 
f586e2
     if (ncf->driver->augeas == NULL) {
f586e2
         augeas *aug;
f586e2
@@ -186,9 +188,12 @@ augeas *get_augeas(struct netcf *ncf) {
f586e2
         }
f586e2
         ncf->driver->copy_augeas_xfm = 0;
f586e2
         ncf->driver->load_augeas = 1;
f586e2
+        ncf->driver->load_augeas_time = 0;
f586e2
     }
f586e2
 
f586e2
-    if (ncf->driver->load_augeas) {
f586e2
+    current_time = time(NULL);
f586e2
+    if (ncf->driver->load_augeas &&
f586e2
+        ncf->driver->load_augeas_time != current_time) {
f586e2
         augeas *aug = ncf->driver->augeas;
f586e2
 
f586e2
         r = aug_load(aug);
f586e2
@@ -207,6 +212,7 @@ augeas *get_augeas(struct netcf *ncf) {
f586e2
         }
f586e2
         ERR_THROW(r > 0, ncf, EOTHER, "errors in loading some config files");
f586e2
         ncf->driver->load_augeas = 0;
f586e2
+        ncf->driver->load_augeas_time = current_time;
f586e2
     }
f586e2
     return ncf->driver->augeas;
f586e2
  error:
f586e2
diff --git a/src/dutil_linux.h b/src/dutil_linux.h
f586e2
index a06a15c..75ac631 100644
f586e2
--- a/src/dutil_linux.h
f586e2
+++ b/src/dutil_linux.h
f586e2
@@ -41,6 +41,7 @@ struct driver {
f586e2
     struct nl_sock     *nl_sock;
f586e2
     struct nl_cache   *link_cache;
f586e2
     struct nl_cache   *addr_cache;
f586e2
+    time_t             load_augeas_time;
f586e2
     unsigned int       load_augeas : 1;
f586e2
     unsigned int       copy_augeas_xfm : 1;
f586e2
     unsigned int       augeas_xfm_num_tables;
f586e2
-- 
f586e2
1.8.3.1
f586e2