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