Permalink
Browse files

allow change handlers to return error and propagate it

Signed-off-by: Jiri Pirko <jpirko@redhat.com>
  • Loading branch information...
1 parent 53efbcb commit e5dc39436dc7d43326997f9a6c31e793e88c3095 Jiri Pirko committed Mar 12, 2012
Showing with 49 additions and 34 deletions.
  1. +3 −3 include/team.h
  2. +20 −9 lib/libteam.c
  3. +1 −2 lib/options.c
  4. +1 −2 lib/ports.c
  5. +2 −2 lib/team_private.h
  6. +6 −4 src/team_monitor.c
  7. +3 −2 teamd/teamd.c
  8. +1 −1 teamd/teamd.h
  9. +6 −5 teamd/teamd_link_watch.c
  10. +3 −2 teamd/teamd_per_port.c
  11. +3 −2 teamd/teamd_runner_activebackup.c
View
@@ -50,8 +50,8 @@ void team_set_log_priority(struct team_handle *th, int priority);
void *team_get_user_priv(struct team_handle *th);
void team_set_user_priv(struct team_handle *th, void *priv);
int team_get_event_fd(struct team_handle *th);
-void team_process_event(struct team_handle *th);
-void team_check_events(struct team_handle *th);
+int team_process_event(struct team_handle *th);
+int team_check_events(struct team_handle *th);
int team_get_mode_name(struct team_handle *th, char **mode_name);
int team_set_mode_name(struct team_handle *th, const char *mode_name);
int team_get_active_port(struct team_handle *th, uint32_t *ifindex);
@@ -128,7 +128,7 @@ enum {
typedef unsigned int team_change_type_mask_t;
struct team_change_handler {
- void (*func)(struct team_handle *th,
+ int (*func)(struct team_handle *th,
void *func_priv,
team_change_type_mask_t type_mask);
/* type_mask passed to function
View
@@ -183,9 +183,10 @@ void set_call_change_handlers(struct team_handle *th,
th->change_handler.pending_type_mask |= set_type_mask;
}
-void check_call_change_handlers(struct team_handle *th,
- team_change_type_mask_t call_type_mask)
+int check_call_change_handlers(struct team_handle *th,
+ team_change_type_mask_t call_type_mask)
{
+ int err = 0;
struct change_handler_item *handler_item;
team_change_type_mask_t to_call_type_mask =
th->change_handler.pending_type_mask & call_type_mask;
@@ -196,10 +197,14 @@ void check_call_change_handlers(struct team_handle *th,
handler->type_mask & to_call_type_mask;
if (item_type_mask) {
- handler->func(th, handler->func_priv, item_type_mask);
+ err = handler->func(th, handler->func_priv,
+ item_type_mask);
+ if (err)
+ break;
}
}
th->change_handler.pending_type_mask &= ~call_type_mask;
+ return err;
}
static struct change_handler_item *
@@ -637,12 +642,13 @@ int team_get_event_fd(struct team_handle *th)
* nl_recvmsgs_default() which blocks so be sure to call this only
* if there are some data to read on event socket file descriptor.
*
+ * Returns: zero on success or negative number in case of an error.
**/
TEAM_EXPORT
-void team_process_event(struct team_handle *th)
+int team_process_event(struct team_handle *th)
{
nl_recvmsgs_default(th->nl_sock_event);
- check_call_change_handlers(th, TEAM_ANY_CHANGE);
+ return check_call_change_handlers(th, TEAM_ANY_CHANGE);
}
/**
@@ -653,9 +659,10 @@ void team_process_event(struct team_handle *th)
* them one by one. This is safe to be called even if no data present
* on event socket file descriptor.
*
+ * Returns: zero on success or negative number in case of an error.
**/
TEAM_EXPORT
-void team_check_events(struct team_handle *th)
+int team_check_events(struct team_handle *th)
{
int err;
fd_set rfds;
@@ -670,11 +677,15 @@ void team_check_events(struct team_handle *th)
err = select(fdmax, &rfds, NULL, NULL, &tv);
if (err == -1 && errno == EINTR)
continue;
- if (err != -1 && FD_ISSET(tfd, &rfds))
- team_process_event(th);
- else
+ if (err != -1 && FD_ISSET(tfd, &rfds)) {
+ err = team_process_event(th);
+ if (err)
+ return err;
+ } else {
break;
+ }
}
+ return 0;
}
/**
View
@@ -258,8 +258,7 @@ static int get_options(struct team_handle *th)
if (err)
return err;
- check_call_change_handlers(th, TEAM_OPTION_CHANGE);
- return 0;
+ return check_call_change_handlers(th, TEAM_OPTION_CHANGE);
nla_put_failure:
nlmsg_free(msg);
View
@@ -153,8 +153,7 @@ static int get_port_list(struct team_handle *th)
if (err)
return err;
- check_call_change_handlers(th, TEAM_PORT_CHANGE);
- return 0;
+ return check_call_change_handlers(th, TEAM_PORT_CHANGE);
nla_put_failure:
nlmsg_free(msg);
View
@@ -109,7 +109,7 @@ int send_and_recv(struct team_handle *th, struct nl_msg *msg,
void *valid_data);
void set_call_change_handlers(struct team_handle *th,
team_change_type_mask_t set_type_mask);
-void check_call_change_handlers(struct team_handle *th,
- team_change_type_mask_t call_type_mask);
+int check_call_change_handlers(struct team_handle *th,
+ team_change_type_mask_t call_type_mask);
#endif /* _TEAM_PRIVATE_H_ */
View
@@ -71,8 +71,8 @@ static void do_main_loop(struct team_handle *th)
}
-static void port_change_handler_func(struct team_handle *th, void *arg,
- team_change_type_mask_t type_mask)
+static int port_change_handler_func(struct team_handle *th, void *arg,
+ team_change_type_mask_t type_mask)
{
struct team_port *port;
@@ -88,15 +88,16 @@ static void port_change_handler_func(struct team_handle *th, void *arg,
team_get_port_speed(port),
team_get_port_duplex(port));
}
+ return 0;
}
static struct team_change_handler port_change_handler = {
.func = port_change_handler_func,
.type_mask = TEAM_PORT_CHANGE,
};
-static void option_change_handler_func(struct team_handle *th, void *arg,
- team_change_type_mask_t type_mask)
+static int option_change_handler_func(struct team_handle *th, void *arg,
+ team_change_type_mask_t type_mask)
{
struct team_option *option;
@@ -106,6 +107,7 @@ static void option_change_handler_func(struct team_handle *th, void *arg,
team_get_option_name(option),
team_is_option_changed(option));
}
+ return 0;
}
static struct team_change_handler option_change_handler = {
View
@@ -872,15 +872,16 @@ static void debug_log_option_list(struct teamd_context *ctx)
teamd_log_dbg("</option_list>");
}
-static void debug_change_handler_func(struct team_handle *th, void *arg,
- team_change_type_mask_t type_mask)
+static int debug_change_handler_func(struct team_handle *th, void *arg,
+ team_change_type_mask_t type_mask)
{
struct teamd_context *ctx = team_get_user_priv(th);
if (type_mask & TEAM_PORT_CHANGE)
debug_log_port_list(ctx);
if (type_mask & TEAM_OPTION_CHANGE)
debug_log_option_list(ctx);
+ return 0;
}
static struct team_change_handler debug_change_handler = {
View
@@ -47,7 +47,7 @@ struct teamd_runner;
struct teamd_link_watch;
struct teamd_context;
-typedef void (*teamd_link_watch_handler_t)(struct teamd_context *ctx);
+typedef int (*teamd_link_watch_handler_t)(struct teamd_context *ctx);
struct teamd_context {
enum teamd_command cmd;
View
@@ -44,18 +44,19 @@ static const struct teamd_link_watch *teamd_find_link_watch(const char *link_wat
}
-static void call_link_watch_handler(struct teamd_context *ctx)
+static int call_link_watch_handler(struct teamd_context *ctx)
{
if (ctx->link_watch_handler)
- ctx->link_watch_handler(ctx);
+ return ctx->link_watch_handler(ctx);
+ return 0;
}
-static void port_change_handler_func(struct team_handle *th, void *arg,
- team_change_type_mask_t type_mask)
+static int port_change_handler_func(struct team_handle *th, void *arg,
+ team_change_type_mask_t type_mask)
{
struct teamd_context *ctx = team_get_user_priv(th);
- call_link_watch_handler(ctx);
+ return call_link_watch_handler(ctx);
}
static struct team_change_handler port_change_handler = {
View
@@ -192,7 +192,7 @@ static void teamd_free_port_privs(struct teamd_context *ctx)
check_ppitems_to_be_removed(ctx, true);
}
-static void port_priv_change_handler_func(struct team_handle *th, void *arg,
+static int port_priv_change_handler_func(struct team_handle *th, void *arg,
team_change_type_mask_t type_mask)
{
struct teamd_context *ctx = team_get_user_priv(th);
@@ -210,12 +210,13 @@ static void port_priv_change_handler_func(struct team_handle *th, void *arg,
err = create_ppitem(ctx, &ppitem, ifindex);
if (err) {
teamd_run_loop_quit(ctx, err);
- return;
+ return err;
}
}
if (team_is_port_removed(port))
ppitem->to_be_removed = true;
}
+ return 0;
}
static struct team_change_handler port_priv_change_handler = {
@@ -106,7 +106,7 @@ static void change_active_port(struct teamd_context *ctx,
strerror(-err));
}
-static void link_watch_handler(struct teamd_context *ctx)
+static int link_watch_handler(struct teamd_context *ctx)
{
struct team_port *port;
uint32_t active_ifindex;
@@ -122,7 +122,7 @@ static void link_watch_handler(struct teamd_context *ctx)
err = team_get_active_port(ctx->th, &active_ifindex);
if (err) {
teamd_log_err("Failed to get active port.");
- return;
+ return err;
}
active_ifname = dev_name_dup(ctx, active_ifindex);
@@ -169,6 +169,7 @@ static void link_watch_handler(struct teamd_context *ctx)
nochange:
free(active_ifname);
+ return 0;
}
static int abl_init(struct teamd_context *ctx)

0 comments on commit e5dc394

Please sign in to comment.