@@ -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);
}
@@ -122,5 +122,4 @@ void bond_rebalance(struct bond *);
*/
void bond_update_post_recirc_rules(struct bond *, uint32_t *recirc_id,
uint32_t *hash_basis);
-bool bond_may_recirc(const struct bond *);
#endif /* bond.h */
@@ -1987,15 +1987,9 @@ output_normal(struct xlate_ctx *ctx, const struct xbundle *out_xbundle,
struct flow_wildcards *wc = ctx->wc;
struct ofport_dpif *ofport;
- if (ctx->xbridge->support.odp.recirc
- && bond_may_recirc(out_xbundle->bond)) {
- /* To avoid unnecessary locking, bond_may_recirc() is first
- * called outside of the 'rwlock'. After acquiring the lock,
- * bond_update_post_recirc_rules() will check again to make
- * sure bond configuration has not been changed.
- *
- * In case recirculation is not actually in use, 'xr.recirc_id'
- * will be set to '0', Since a valid 'recirc_id' can
+ if (ctx->xbridge->support.odp.recirc) {
+ /* In case recirculation is not actually in use, 'xr.recirc_id'
+ * will be set to '0', since a valid 'recirc_id' can
* not be zero. */
bond_update_post_recirc_rules(out_xbundle->bond,
&xr.recirc_id,
Minor refactoring to make the bond code easier to read. Signed-off-by: Andy Zhou <azhou@ovn.org> --- ofproto/bond.c | 26 ++++++++++++++++++-------- ofproto/bond.h | 1 - ofproto/ofproto-dpif-xlate.c | 12 +++--------- 3 files changed, 21 insertions(+), 18 deletions(-)