From e457e68ac42c85ee7e34951d5ff8d022f51fa82f Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 9 Apr 2009 15:20:06 -0700 Subject: [PATCH] vswitch: Add unixctl command to reload configuration file synchronously. The Xen interface-reconfigure script wants to tell vswitchd to reload its configuration and wait until it is complete. Until now there has been no way to do this: sending SIGHUP causes a reload, but there is no way to tell when it is complete. Now "vlogconf -t -e vswitchd/reload" does the job. --- vswitchd/etc/init.d/vswitch | 4 +++- vswitchd/vswitchd.c | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/vswitchd/etc/init.d/vswitch b/vswitchd/etc/init.d/vswitch index 3f0b2ece..c6614721 100755 --- a/vswitchd/etc/init.d/vswitch +++ b/vswitchd/etc/init.d/vswitch @@ -143,7 +143,9 @@ case "$1" in ;; reload) if [ -f "$VSWITCHD_PIDFILE" ]; then - kill -HUP $(cat "$VSWITCHD_PIDFILE") + "$VSWITCH_BASE"/bin/vlogconf \ + --target=vswitchd.$(cat "$VSWITCHD_PIDFILE").ctl \ + --execute=vswitchd/reload fi ;; strace) diff --git a/vswitchd/vswitchd.c b/vswitchd/vswitchd.c index e5cedcb9..f3049b02 100644 --- a/vswitchd/vswitchd.c +++ b/vswitchd/vswitchd.c @@ -59,15 +59,17 @@ static void parse_options(int argc, char *argv[]); static void usage(void) NO_RETURN; +static void reload(struct unixctl_conn *, const char *args); -char *config_file; +static bool need_reconfigure; +static struct unixctl_conn **conns; +static size_t n_conns; int main(int argc, char *argv[]) { struct unixctl_server *unixctl; struct signal *sighup; - bool need_reconfigure; int retval; set_program_name(argv[0]); @@ -86,6 +88,7 @@ main(int argc, char *argv[]) if (retval) { ofp_fatal(retval, "could not listen for control connections"); } + unixctl_command_register("vswitchd/reload", reload); cfg_read(); mgmt_init(); @@ -116,13 +119,30 @@ main(int argc, char *argv[]) return 0; } +static void +reload(struct unixctl_conn *conn, const char *args UNUSED) +{ + need_reconfigure = true; + conns = xrealloc(conns, sizeof *conns * (n_conns + 1)); + conns[n_conns++] = conn; +} + void reconfigure(void) { + size_t i; + cfg_read(); bridge_reconfigure(); mgmt_reconfigure(); port_reconfigure(); + + for (i = 0; i < n_conns; i++) { + unixctl_command_reply(conns[i], 202, NULL); + } + free(conns); + conns = NULL; + n_conns = 0; } static void @@ -146,6 +166,7 @@ parse_options(int argc, char *argv[]) {0, 0, 0, 0}, }; char *short_options = long_options_to_short_options(long_options); + const char *config_file; int error; for (;;) { -- 2.30.2