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