From e6cc053abab1f84b8ab3d5ac361df0d520f321a0 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Wed, 25 Mar 2009 06:00:59 -0700 Subject: [PATCH] Return error when multiple writers are modifying vswitchd.conf. We now have multiple writers of vswitchd.conf. The bridge compatibility module's attempts to write can now fail due to the file being locked. This change notifies the caller of that. --- vswitchd/brcompat.c | 34 +++++++++++++++++++++++++--------- vswitchd/brcompat.h | 2 +- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/vswitchd/brcompat.c b/vswitchd/brcompat.c index c187858d..5a1be8b7 100644 --- a/vswitchd/brcompat.c +++ b/vswitchd/brcompat.c @@ -146,19 +146,19 @@ static const struct nl_policy brc_dp_policy[] = { /* Modify the existing configuration according to 'act'. The configuration * file will be modified to reflect these changes. The caller is - * responsible for causing vswitchd to actually re-read its configuration. */ -void + * responsible for causing vswitchd to actually re-read its configuration. + * Returns 0 on success, otherwise a postive errno. */ +int brc_modify_config(const char *dp_name, const char *port_name, enum bmc_action act) { if (!brc_enabled) { - return; + return 0; } if (cfg_lock(NULL)) { /* Couldn't lock config file. */ - /* xxx Handle this better */ - return; + return EAGAIN; } switch (act) { @@ -182,16 +182,23 @@ brc_modify_config(const char *dp_name, const char *port_name, cfg_write(); cfg_unlock(); + + return 0; } static int brc_add_dp(const char *dp_name) { + int retval; + if (bridge_exists(dp_name)) { return EEXIST; } - brc_modify_config(dp_name, NULL, BMC_ADD_DP); + retval = brc_modify_config(dp_name, NULL, BMC_ADD_DP); + if (retval) { + return retval; + } reconfigure(); @@ -205,11 +212,16 @@ brc_add_dp(const char *dp_name) static int brc_del_dp(const char *dp_name) { + int retval; + if (!bridge_exists(dp_name)) { return ENXIO; } - brc_modify_config(dp_name, NULL, BMC_DEL_DP); + retval = brc_modify_config(dp_name, NULL, BMC_DEL_DP); + if (retval) { + return retval; + } reconfigure(); @@ -266,6 +278,7 @@ brc_handle_port_cmd(struct ofpbuf *buffer, bool add) { struct nlattr *attrs[ARRAY_SIZE(brc_port_policy)]; const char *dp_name, *port_name; + int retval; if (!nl_policy_parse(buffer, NLMSG_HDRLEN + GENL_HDRLEN, brc_port_policy, attrs, ARRAY_SIZE(brc_port_policy))) { @@ -280,9 +293,12 @@ brc_handle_port_cmd(struct ofpbuf *buffer, bool add) } if (add) { - brc_modify_config(dp_name, port_name, BMC_ADD_PORT); + retval = brc_modify_config(dp_name, port_name, BMC_ADD_PORT); } else { - brc_modify_config(dp_name, port_name, BMC_DEL_PORT); + retval = brc_modify_config(dp_name, port_name, BMC_DEL_PORT); + } + if (retval) { + return retval; } /* Force vswitchd to reconfigure itself. */ diff --git a/vswitchd/brcompat.h b/vswitchd/brcompat.h index e503e609..2827207c 100644 --- a/vswitchd/brcompat.h +++ b/vswitchd/brcompat.h @@ -39,7 +39,7 @@ enum bmc_action { void brc_init(void); void brc_wait(void); void brc_run(void); -void brc_modify_config(const char *dp_name, const char *port_name, +int brc_modify_config(const char *dp_name, const char *port_name, enum bmc_action act); #endif /* brcompat.h */ -- 2.30.2