summaryrefslogtreecommitdiff
path: root/ofproto/bond.c
diff options
context:
space:
mode:
authorAndy Zhou <azhou@ovn.org>2017-03-09 16:52:27 -0800
committerAndy Zhou <azhou@ovn.org>2017-04-17 13:59:01 -0700
commita80aba3a7996759e4950187dcfbe89ab7cfe7d93 (patch)
tree83016fb3ff45776bab007de97675ce12259e5f49 /ofproto/bond.c
parent2c0e107efbd2d442b17bff992ee41e1ce910eba1 (diff)
downloadopenvswitch-a80aba3a7996759e4950187dcfbe89ab7cfe7d93.tar.gz
ofproto/bond: Make bond_may_recirc() private within bond.c
Minor refactoring to make the bond code easier to read. Signed-off-by: Andy Zhou <azhou@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'ofproto/bond.c')
-rw-r--r--ofproto/bond.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/ofproto/bond.c b/ofproto/bond.c
index 17bd3b816..441ca44fa 100644
--- a/ofproto/bond.c
+++ b/ofproto/bond.c
@@ -926,7 +926,7 @@ bond_recirculation_account(struct bond *bond)
}
}
-bool
+static bool
bond_may_recirc(const struct bond *bond)
{
return bond->balance == BM_TCP && bond->recirc_id;
@@ -960,15 +960,25 @@ void
bond_update_post_recirc_rules(struct bond *bond, uint32_t *recirc_id,
uint32_t *hash_basis)
{
- ovs_rwlock_wrlock(&rwlock);
- if (bond_may_recirc(bond)) {
- *recirc_id = bond->recirc_id;
- *hash_basis = bond->basis;
- bond_update_post_recirc_rules__(bond, false);
- } else {
+ bool may_recirc = bond_may_recirc(bond);
+
+ if (may_recirc) {
+ /* To avoid unnecessary locking, bond_may_recirc() is first
+ * called outside of the 'rwlock'. After acquiring the lock,
+ * check again to make sure bond configuration has not been changed. */
+ ovs_rwlock_wrlock(&rwlock);
+ may_recirc = bond_may_recirc(bond);
+ if (may_recirc) {
+ *recirc_id = bond->recirc_id;
+ *hash_basis = bond->basis;
+ bond_update_post_recirc_rules__(bond, false);
+ }
+ ovs_rwlock_unlock(&rwlock);
+ }
+
+ if (!may_recirc) {
*recirc_id = *hash_basis = 0;
}
- ovs_rwlock_unlock(&rwlock);
}