Skip to content

Commit

Permalink
rstp: Add internal functions without locks.
Browse files Browse the repository at this point in the history
This patch adds some internal functions which
does not use the locks. This patch is used for
next patch.

Signed-off-by: nickcooper-zhangtonghao <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
xpu22 authored and blp committed Jun 8, 2017
1 parent 8d2f837 commit 066f0ab
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
61 changes: 48 additions & 13 deletions lib/rstp.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ static void rstp_port_set_mcheck__(struct rstp_port *, bool mcheck)
OVS_REQUIRES(rstp_mutex);
static void reinitialize_port__(struct rstp_port *p)
OVS_REQUIRES(rstp_mutex);
static bool rstp_is_root_bridge__(const struct rstp *rstp)
OVS_REQUIRES(rstp_mutex);
static uint32_t rstp_get_root_path_cost__(const struct rstp *rstp)
OVS_REQUIRES(rstp_mutex);
static struct rstp_port *rstp_get_root_port__(const struct rstp *rstp)
OVS_REQUIRES(rstp_mutex);
static rstp_identifier rstp_get_root_id__(const struct rstp *rstp)
OVS_REQUIRES(rstp_mutex);
static void rstp_unixctl_tcn(struct unixctl_conn *, int argc,
const char *argv[], void *aux);

const char *
rstp_state_name(enum rstp_state state)
Expand Down Expand Up @@ -208,9 +218,6 @@ rstp_port_get_number(const struct rstp_port *p)
return number;
}

static void rstp_unixctl_tcn(struct unixctl_conn *, int argc,
const char *argv[], void *aux);

/* Decrements the State Machines' timers. */
void
rstp_tick_timers(struct rstp *rstp)
Expand Down Expand Up @@ -796,14 +803,21 @@ rstp_port_set_path_cost__(struct rstp_port *port, uint32_t path_cost)
}

/* Gets the root path cost. */
static uint32_t
rstp_get_root_path_cost__(const struct rstp *rstp)
OVS_REQUIRES(rstp_mutex)
{
return rstp->root_priority.root_path_cost;
}

uint32_t
rstp_get_root_path_cost(const struct rstp *rstp)
OVS_EXCLUDED(rstp_mutex)
{
uint32_t cost;

ovs_mutex_lock(&rstp_mutex);
cost = rstp->root_priority.root_path_cost;
cost = rstp_get_root_path_cost__(rstp);
ovs_mutex_unlock(&rstp_mutex);
return cost;
}
Expand Down Expand Up @@ -1313,14 +1327,21 @@ rstp_get_designated_id(const struct rstp *rstp)
}

/* Returns the root bridge id. */
static rstp_identifier
rstp_get_root_id__(const struct rstp *rstp)
OVS_REQUIRES(rstp_mutex)
{
return rstp->root_priority.root_bridge_id;
}

rstp_identifier
rstp_get_root_id(const struct rstp *rstp)
OVS_EXCLUDED(rstp_mutex)
{
rstp_identifier root_id;

ovs_mutex_lock(&rstp_mutex);
root_id = rstp->root_priority.root_bridge_id;
root_id = rstp_get_root_id__(rstp);
ovs_mutex_unlock(&rstp_mutex);

return root_id;
Expand Down Expand Up @@ -1357,15 +1378,22 @@ rstp_get_bridge_port_id(const struct rstp *rstp)
/* Returns true if the bridge believes to the be root of the spanning tree,
* false otherwise.
*/
static bool
rstp_is_root_bridge__(const struct rstp *rstp)
OVS_REQUIRES(rstp_mutex)
{
return rstp->bridge_identifier ==
rstp->root_priority.designated_bridge_id;
}

bool
rstp_is_root_bridge(const struct rstp *rstp)
OVS_EXCLUDED(rstp_mutex)
{
bool is_root;

ovs_mutex_lock(&rstp_mutex);
is_root = rstp->bridge_identifier ==
rstp->root_priority.designated_bridge_id;
is_root = rstp_is_root_bridge__(rstp);
ovs_mutex_unlock(&rstp_mutex);

return is_root;
Expand All @@ -1388,23 +1416,30 @@ rstp_get_designated_root(const struct rstp *rstp)
/* Returns the port connecting 'rstp' to the root bridge, or a null pointer if
* there is no such port.
*/
struct rstp_port *
rstp_get_root_port(struct rstp *rstp)
OVS_EXCLUDED(rstp_mutex)
static struct rstp_port *
rstp_get_root_port__(const struct rstp *rstp)
OVS_REQUIRES(rstp_mutex)
{
struct rstp_port *p;

ovs_mutex_lock(&rstp_mutex);
HMAP_FOR_EACH (p, node, &rstp->ports) {
if (p->port_id == rstp->root_port_id) {
ovs_mutex_unlock(&rstp_mutex);
return p;
}
}
ovs_mutex_unlock(&rstp_mutex);
return NULL;
}

struct rstp_port *
rstp_get_root_port(const struct rstp *rstp)
OVS_EXCLUDED(rstp_mutex)
{
ovs_mutex_lock(&rstp_mutex);
struct rstp_port *p = rstp_get_root_port__(rstp);
ovs_mutex_unlock(&rstp_mutex);
return p;
}

/* Returns the state of port 'p'. */
enum rstp_state
rstp_port_get_state(const struct rstp_port *p)
Expand Down
2 changes: 1 addition & 1 deletion lib/rstp.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ uint16_t rstp_get_designated_port_id(const struct rstp *)
OVS_EXCLUDED(rstp_mutex);
uint16_t rstp_get_bridge_port_id(const struct rstp *)
OVS_EXCLUDED(rstp_mutex);
struct rstp_port * rstp_get_root_port(struct rstp *)
struct rstp_port * rstp_get_root_port(const struct rstp *)
OVS_EXCLUDED(rstp_mutex);
rstp_identifier rstp_get_designated_root(const struct rstp *)
OVS_EXCLUDED(rstp_mutex);
Expand Down

0 comments on commit 066f0ab

Please sign in to comment.