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

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