[ovs-dev,1/2] stp: Change the api for next patch.

Submitted by nickcooper-zhangtonghao on March 18, 2017, 8:13 a.m.

Details

Message ID 1489824836-32780-1-git-send-email-nic@opencloud.tech
State Accepted
Headers show

Commit Message

nickcooper-zhangtonghao March 18, 2017, 8:13 a.m.
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>
Acked-by: Ben Pfaff <blp@ovn.org>
---
 lib/stp.c              | 29 +++++++++++++----------------
 lib/stp.h              |  4 ++--
 ofproto/ofproto-dpif.c |  4 +---
 3 files changed, 16 insertions(+), 21 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/stp.c b/lib/stp.c
index 2ffe5c2..b7ddc39 100644
--- a/lib/stp.c
+++ b/lib/stp.c
@@ -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)
diff --git a/lib/stp.h b/lib/stp.h
index 9f945ad..c64089a 100644
--- a/lib/stp.h
+++ b/lib/stp.h
@@ -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);
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 6611c23..523adad 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -2541,10 +2541,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;
 }