From patchwork Mon Sep 2 11:51:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 271899 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9EA1A2C009A for ; Mon, 2 Sep 2013 21:55:31 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757968Ab3IBLzX (ORCPT ); Mon, 2 Sep 2013 07:55:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57494 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754338Ab3IBLzW (ORCPT ); Mon, 2 Sep 2013 07:55:22 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r82BtIsB019177 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 2 Sep 2013 07:55:19 -0400 Received: from boza.brq.redhat.com (dhcp-1-132.brq.redhat.com [10.34.1.132]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r82BtFkG025314; Mon, 2 Sep 2013 07:55:17 -0400 From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: andy@greyhouse.net, fubar@us.ibm.com, davem@davemloft.net Subject: [PATCH net-next 1/5] bonding: simplify and fix peer notification Date: Mon, 2 Sep 2013 13:51:38 +0200 Message-Id: <1378122702-28943-2-git-send-email-nikolay@redhat.com> In-Reply-To: <1378122702-28943-1-git-send-email-nikolay@redhat.com> References: <1378122702-28943-1-git-send-email-nikolay@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch aims to remove a use of the bond->lock for mutual exclusion which will later allow easier migration to RCU of the users of this functionality. We use RTNL as a synchronizing mechanism since it's always held when send_peer_notif is set, and when it is decremented from the notifier function. We can also drop some locking, and fix the leakage of the send_peer_notif counter. Signed-off-by: Nikolay Aleksandrov --- drivers/net/bonding/bond_main.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index c50679f..05e638b 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -828,7 +828,6 @@ static bool bond_should_notify_peers(struct bonding *bond) test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state)) return false; - bond->send_peer_notif--; return true; } @@ -2259,12 +2258,8 @@ re_arm: read_unlock(&bond->lock); if (should_notify_peers) { - if (!rtnl_trylock()) { - read_lock(&bond->lock); - bond->send_peer_notif++; - read_unlock(&bond->lock); + if (!rtnl_trylock()) return; - } call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev); rtnl_unlock(); } @@ -2876,12 +2871,8 @@ re_arm: read_unlock(&bond->lock); if (should_notify_peers) { - if (!rtnl_trylock()) { - read_lock(&bond->lock); - bond->send_peer_notif++; - read_unlock(&bond->lock); + if (!rtnl_trylock()) return; - } call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev); rtnl_unlock(); } @@ -2916,6 +2907,10 @@ static int bond_master_netdev_event(unsigned long event, case NETDEV_REGISTER: bond_create_proc_entry(event_bond); break; + case NETDEV_NOTIFY_PEERS: + if (event_bond->send_peer_notif) + event_bond->send_peer_notif--; + break; default: break; } @@ -3213,11 +3208,8 @@ static int bond_close(struct net_device *bond_dev) { struct bonding *bond = netdev_priv(bond_dev); - write_lock_bh(&bond->lock); - bond->send_peer_notif = 0; - write_unlock_bh(&bond->lock); - bond_work_cancel_all(bond); + bond->send_peer_notif = 0; if (bond_is_lb(bond)) { /* Must be called only after all * slaves have been released