From 4bfa30106bfa18ce963b671a0c4ef5cf91d3f4ec Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Fri, 3 Apr 2009 14:56:32 -0700 Subject: [PATCH] Use new vswitchd management settings when they change. When changes were made to the "mgmt" section of vswitchd.conf, we weren't noticing changes if the major sections were not modified. Thanks to Dan for reporting this. --- lib/cfg.c | 24 ++++++++++++++++++++++++ lib/cfg.h | 2 ++ vswitchd/mgmt.c | 12 ++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/cfg.c b/lib/cfg.c index 4fbaa9ca..916cb932 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -540,6 +540,30 @@ cfg_del_section(const char *section_, ...) dirty = true; } + +/* Fills 'svec' with all of the key-value pairs that have sections that + * begin with 'section'. The caller must first initialize 'svec'. */ +void +cfg_get_section(struct svec *svec, const char *section_, ...) +{ + struct ds section; + va_list args; + char **p; + + ds_init(§ion); + va_start(args, section_); + ds_put_format_valist(§ion, section_, args); + ds_put_char(§ion, '.'); + va_end(args); + + for (p = cfg.names; *p; p++) { /* XXX this is inefficient */ + if (!strncmp(section.string, *p, section.length)) { + svec_add(svec, *p); + } + } + ds_destroy(§ion); +} + /* Returns the value numbered 'idx' of 'key'. Returns a null pointer if 'idx' * is greater than or equal to cfg_count(key). The caller must not modify or * free the returned string or retain its value beyond the next call to diff --git a/lib/cfg.h b/lib/cfg.h index c2f7d17f..8ecace94 100644 --- a/lib/cfg.h +++ b/lib/cfg.h @@ -70,6 +70,8 @@ void cfg_register(const char *key_spec, enum cfg_flags); void cfg_add_entry(const char *key, ...) PRINTF_FORMAT(1, 2); void cfg_del_entry(const char *key, ...) PRINTF_FORMAT(1, 2); void cfg_del_section(const char *key, ...) PRINTF_FORMAT(1, 2); +void cfg_get_section(struct svec *svec, const char *key, ...) + PRINTF_FORMAT(2, 3); bool cfg_has(const char *key, ...) PRINTF_FORMAT(1, 2); bool cfg_is_valid(enum cfg_flags, const char *key, ...) PRINTF_FORMAT(2, 3); diff --git a/vswitchd/mgmt.c b/vswitchd/mgmt.c index 02313bda..ab1b36a9 100644 --- a/vswitchd/mgmt.c +++ b/vswitchd/mgmt.c @@ -156,7 +156,7 @@ mgmt_reconfigure(void) } svec_init(&new_cfg); - cfg_get_subsections(&new_cfg, "mgmt"); + cfg_get_section(&new_cfg, "mgmt"); if (svec_equal(&mgmt_cfg, &new_cfg)) { /* Reconnecting to the controller causes the config file to be * resent automatically. If we're not reconnecting and the @@ -165,12 +165,14 @@ mgmt_reconfigure(void) if (cfg_updated && mgmt_rconn) { send_config_update(0, false); } + svec_destroy(&new_cfg); return; } controller_name = cfg_get_string(0, "mgmt.controller"); if (!controller_name) { VLOG_ERR("no controller specified for managment"); + svec_destroy(&new_cfg); return; } @@ -210,11 +212,9 @@ mgmt_reconfigure(void) mgmt_rconn = NULL; } mgmt_rconn = rconn_create(inactivity_probe, max_backoff); - if (controller_name) { - retval = rconn_connect(mgmt_rconn, controller_name); - if (retval == EAFNOSUPPORT) { - VLOG_ERR("no support for %s vconn", controller_name); - } + retval = rconn_connect(mgmt_rconn, controller_name); + if (retval == EAFNOSUPPORT) { + VLOG_ERR("no support for %s vconn", controller_name); } } -- 2.30.2