From: Ben Pfaff Date: Fri, 8 May 2009 17:39:17 +0000 (-0700) Subject: cfg: Log changes to config, not whole config, in cfg_read(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d99a750bc2da47e92b7140d6e51cab972749012;p=openvswitch cfg: Log changes to config, not whole config, in cfg_read(). The configuration file is re-read on a regular basis by brcompatd and vswitchd in practice. When debug-level logging is enabled on the cfg module, it was logging the entire config file each time. Not only is this a waste of log-file space, it's difficult for humans to see what actually changed, if anything. So this commit changes cfg_read() to log a diff instead of the whole config file. --- diff --git a/lib/cfg.c b/lib/cfg.c index 83e9a439..53a71cda 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -166,10 +166,11 @@ update_cookie(void) /* Reads all of the configuration files or directories that have been added * with cfg_add_file(), merges their content. Any previous configuration is - * replaced. */ -void + * replaced. Returns 0 if successful, otherwise a positive errno value. */ +int cfg_read(void) { + struct svec old_cfg; struct ds ds; FILE *file; char *section; @@ -177,11 +178,12 @@ cfg_read(void) if (!cfg_name) { - return; + return ENODEV; } - /* Clear old configuration data. */ - svec_clear(&cfg); + /* Save old configuration data and clear the active configuration. */ + svec_init(&old_cfg); + svec_swap(&old_cfg, &cfg); /* Read new configuration. */ VLOG_DBG("reading configuration from %s", cfg_name); @@ -189,7 +191,7 @@ cfg_read(void) file = fopen(cfg_name, "r"); if (!file) { VLOG_ERR("failed to open \"%s\": %s", cfg_name, strerror(errno)); - return; + return errno; } ds_init(&ds); @@ -232,13 +234,27 @@ cfg_read(void) fclose(file); if (VLOG_IS_DBG_ENABLED()) { + struct svec removed, added; size_t i; - VLOG_DBG("new configuration:"); - for (i = 0; i < cfg.n; i++) { - VLOG_DBG("%s", cfg.names[i]); + svec_diff(&old_cfg, &cfg, &removed, NULL, &added); + if (removed.n || added.n) { + VLOG_DBG("configuration changes:"); + for (i = 0; i < removed.n; i++) { + VLOG_DBG("-%s", removed.names[i]); + } + for (i = 0; i < added.n; i++) { + VLOG_DBG("+%s", added.names[i]); + } + } else { + VLOG_DBG("configuration unchanged"); } + svec_destroy(&added); + svec_destroy(&removed); } + svec_destroy(&old_cfg); + + return 0; } int diff --git a/lib/cfg.h b/lib/cfg.h index 8b21922e..2b79f439 100644 --- a/lib/cfg.h +++ b/lib/cfg.h @@ -38,7 +38,7 @@ struct svec; struct ofpbuf; int cfg_set_file(const char *file_name); -void cfg_read(void); +int cfg_read(void); int cfg_lock(uint8_t *cookie, int timeout); void cfg_unlock(void); int cfg_write(void);