@@ -857,18 +857,6 @@ stp_port_no(const struct stp_port *p)
return index;
}
-/* Returns the port ID for 'p'. */
-int
-stp_port_get_id(const struct stp_port *p)
-{
- int port_id;
-
- ovs_mutex_lock(&mutex);
- port_id = p->port_id;
- ovs_mutex_unlock(&mutex);
- return port_id;
-}
-
/* Returns the state of port 'p'. */
enum stp_state
stp_port_get_state(const struct stp_port *p)
@@ -882,13 +870,12 @@ stp_port_get_state(const struct stp_port *p)
}
/* Returns the role of port 'p'. */
-enum stp_role
-stp_port_get_role(const struct stp_port *p)
+static enum stp_role
+stp_port_get_role(const struct stp_port *p) OVS_REQUIRES(mutex)
{
struct stp_port *root_port;
enum stp_role role;
- ovs_mutex_lock(&mutex);
root_port = p->stp->root_port;
if (root_port && root_port->port_id == p->port_id) {
role = STP_ROLE_ROOT;
@@ -899,7 +886,6 @@ stp_port_get_role(const struct stp_port *p)
} else {
role = STP_ROLE_ALTERNATE;
}
- ovs_mutex_unlock(&mutex);
return role;
}
@@ -915,6 +901,17 @@ stp_port_get_counts(const struct stp_port *p,
ovs_mutex_unlock(&mutex);
}
+void
+stp_port_get_status(const struct stp_port *p,
+ int *port_id, enum stp_state *state, enum stp_role *role)
+{
+ ovs_mutex_lock(&mutex);
+ *port_id = p->port_id;
+ *state = p->state;
+ *role = stp_port_get_role(p);
+ ovs_mutex_unlock(&mutex);
+}
+
/* Disables STP on port 'p'. */
void
stp_port_disable(struct stp_port *p)
@@ -145,11 +145,11 @@ void stp_port_set_name(struct stp_port *, const char *);
void stp_port_set_aux(struct stp_port *, void *);
void *stp_port_get_aux(struct stp_port *);
int stp_port_no(const struct stp_port *);
-int stp_port_get_id(const struct stp_port *);
enum stp_state stp_port_get_state(const struct stp_port *);
-enum stp_role stp_port_get_role(const struct stp_port *);
void stp_port_get_counts(const struct stp_port *,
int *tx_count, int *rx_count, int *error_count);
+void stp_port_get_status(const struct stp_port *p,
+ int *port_id, enum stp_state *state, enum stp_role *role);
void stp_port_enable(struct stp_port *);
void stp_port_disable(struct stp_port *);
void stp_port_set_priority(struct stp_port *, uint8_t new_priority);
@@ -2442,10 +2442,8 @@ get_stp_port_status(struct ofport *ofport_,
}
s->enabled = true;
- s->port_id = stp_port_get_id(sp);
- s->state = stp_port_get_state(sp);
+ stp_port_get_status(sp, &s->port_id, &s->state, &s->role);
s->sec_in_state = (time_msec() - ofport->stp_state_entered) / 1000;
- s->role = stp_port_get_role(sp);
return 0;
}
This patch changes the stp_port_get_role and removes the stp_port_get_id, because stp/show has locked the mutex before calling the stp_port_get_role, and stp_port_get_id will not be used. Signed-off-by: nickcooper-zhangtonghao <nic@opencloud.tech> --- lib/stp.c | 29 +++++++++++++---------------- lib/stp.h | 4 ++-- ofproto/ofproto-dpif.c | 4 +--- 3 files changed, 16 insertions(+), 21 deletions(-)