diff mbox

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

Message ID 1488892290-106534-1-git-send-email-nic@opencloud.tech
State Deferred
Headers show

Commit Message

nickcooper-zhangtonghao March 7, 2017, 1:11 p.m. UTC
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(-)

Comments

nickcooper-zhangtonghao March 14, 2017, 1:20 a.m. UTC | #1
Is there someone can help me to review stp patches?

http://patchwork.ozlabs.org/patch/736157/ <http://patchwork.ozlabs.org/patch/736157/>
http://patchwork.ozlabs.org/patch/736158/ <http://patchwork.ozlabs.org/patch/736158/>
http://patchwork.ozlabs.org/patch/736159/ <http://patchwork.ozlabs.org/patch/736159/>
http://patchwork.ozlabs.org/patch/736229/ <http://patchwork.ozlabs.org/patch/736229/>
http://patchwork.ozlabs.org/patch/736548/ <http://patchwork.ozlabs.org/patch/736548/>



Thanks.
Nick

> On Mar 7, 2017, at 9:11 PM, nickcooper-zhangtonghao <nic@opencloud.tech> wrote:
> 
> 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 <mailto:nic@opencloud.tech>>
Ben Pfaff March 17, 2017, 6:36 p.m. UTC | #2
On Tue, Mar 07, 2017 at 05:11:27AM -0800, nickcooper-zhangtonghao wrote:
> 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>
diff mbox

Patch

diff --git a/lib/stp.c b/lib/stp.c
index ecef012..1444dd7 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 1e1b107..526ef27 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -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;
 }