Article View: linux.kernel.netdev
Article #16030[PATCH net-next 4/6] bonding: factor out slave publication
From: Hangbin Liu
Date: Fri, 13 Nov 2026 14:04
Date: Fri, 13 Nov 2026 14:04
84 lines
11279 bytes
11279 bytes
From: Hangbin Liu <liuhangbin@kylinos.cn>
Factor the publication step of bond_enslave() into bond_publish_slave()
so the infallible "commit point" of the function is explicit and cannot
be interleaved with new fallible code by accident.
No functional change.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
drivers/net/bonding/bond_main.c | 49 ++++++++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 20 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index f696a0d15034..bb3752683456 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1884,6 +1884,34 @@ void bond_xdp_set_features(struct net_device *bond_dev)
xdp_set_features_flag(bond_dev, val);
}
+/* Make the fully prepared slave visible to the rest of the bonding
+ * code. All fallible steps of bond_enslave() must have completed
+ * before this runs: error paths never undo the publication.
+ */
+static void bond_publish_slave(struct bonding *bond, struct slave *slave)
+{
+ /* Must called before bond_update_slave_arr() or bond_select_active_slave() */
+ WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
+ netdev_compute_master_upper_features(bond->dev, true);
+ bond_set_carrier(bond);
+
+ /* Needs to be called before bond_select_active_slave(), which will
+ * remove the maddrs if the slave is selected as active slave.
+ */
+ bond_slave_ns_maddrs_add(bond, slave);
+
+ if (bond_uses_primary(bond)) {
+ block_netpoll_tx();
+ bond_select_active_slave(bond);
+ unblock_netpoll_tx();
+ }
+
+ /* broadcast mode uses the all_slaves to loop through slaves. */
+ if (bond_mode_can_use_xmit_hash(bond) ||
+ BOND_MODE(bond) == BOND_MODE_BROADCAST)
+ bond_update_slave_arr(bond, NULL);
+}
+
/* enslave device <slave> to bond device <master> */
int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
struct netlink_ext_ack *extack)
@@ -2341,26 +2369,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
bond_xdp_set_features(bond_dev);
- /* Must called before bond_update_slave_arr() or bond_select_active_slave() */
- WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
- netdev_compute_master_upper_features(bond->dev, true);
- bond_set_carrier(bond);
-
- /* Needs to be called before bond_select_active_slave(), which will
- * remove the maddrs if the slave is selected as active slave.
- */
- bond_slave_ns_maddrs_add(bond, new_slave);
-
- if (bond_uses_primary(bond)) {
- block_netpoll_tx();
- bond_select_active_slave(bond);
- unblock_netpoll_tx();
- }
-
- /* broadcast mode uses the all_slaves to loop through slaves. */
- if (bond_mode_can_use_xmit_hash(bond) ||
- BOND_MODE(bond) == BOND_MODE_BROADCAST)
- bond_update_slave_arr(bond, NULL);
+ bond_publish_slave(bond, new_slave);
slave_info(bond_dev, slave_dev, "Enslaving as %s interface with %s link\n",
bond_is_active_slave(new_slave) ? "an active" : "a backup",
--
2.56.0
Technical Details
Message-ID:
<20261113-bond_enslave_restruct-v1-4-364c549e78db@kylinos.cn>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362692-linux-kernel-netdev=dewy.ruReferences:
<20261113-bond_enslave_restruct-v1-0-364c549e78db@kylinos.cn>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362692-linux-kernel-netdev=dewy.ru From: hangbin.liu@linux.dev (Hangbin Liu) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next 4/6] bonding: factor out slave publication Date: Fri, 13 Nov 2026 22:04:19 +0800 Organization: Usenet Network Message-ID: <20261113-bond_enslave_restruct-v1-4-364c549e78db@kylinos.cn> References: <20261113-bond_enslave_restruct-v1-0-364c549e78db@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1455698"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:+a4dkSxU5HQc1v64NKlxZvsZ+50= sha256:O017vfCIf4lFlCe2pcy7dv3RdOwfZgA14EimIukDskc= sha1:543FfmNlYkY9Kdnv2+Qsfa8hhV0= sha256:tb6BYC7vncAxFDnXOahECqD85GdL+MRCXa9mQNnDwpk= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 693CC1146A5; Sat, 14 Nov 2026 01:35:55 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FW--N0wc_41g; Sat, 14 Nov 2026 01:35:52 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-362692-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 8AB3D114679; Sat, 14 Nov 2026 01:35:40 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id CDE4C2E0BB7; Fri, 13 Nov 2026 14:06:21 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794578767; b=pSo2reaTO8/4OPZeoqG2mFpinF72oTPU6VZ/zcZ98/TbC2f3Dd7+rGrtYfMvhdH3j7cJ UQGl7XQEPCodHQE101MdNrMtWVKeWz/ZDbcIl69OovLCIkgODXVJiRvCt54h9b3Tly07c TzlLtsMcS36TY+SccTC7frOE9wfrNo7hAIjY/8Xdu7F3TZi+IHd/yvr/dWphCAiywp3yI ytgto/+S4lif0VAnsVnefMt2+8YooMrqoZMrxFzVfoQ8opoOx1TMLVPyx+Xk8Jfqfrfio bI2asPI/jwRQIoQvFXYF7wo5epejTHw7YYVLxb8uFZyK5gGv4BuNeLwFYgH8KZRJQjw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794578767; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:Date: Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer; bh=C0kDAcJ25HEa7l+lmxjvOALQB9PoPJwZxNqhGvdBIOo=; b=pM/wC64eDEsx1IlBcIfn7uxXdh15vLc7vB0Sz5EDdx0xfx2ALBW1+NLziKXw9qDwyAPd ojakTKdplHGroVl/q+MTObtn3b4kBKfqipGbQEawfRW+9kv6GmLt/zp241BbwoAYIhKAH HwxleYjHpqNOKHrXzOuo5Ae7G8VyEezM/XjBK1QaIMTQaerzoF9An9kkT5yzqKGWaw/jM Kbkd+qVQavu3SYz88rzIQw42L7d9haiwGcR1a333r/MKFbSbfDFgfDwxHgsT0dXQ0WBu8 xQJskrhagU15du0zHity8uep/koC5p337NIaFzqxiLPUkieoI6HQUD0dvGdrpJYHeFg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Nr6uAWFN; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27307606A89B; Fri, 13 Nov 2026 14:06:07 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Nr6uAWFN X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.242 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794578766; b=ICdOiCAoJ11ameW4gFrplw13LRxFdPmOLUNq+t9TTDEhuktyuopU+oOGpZFNzLd5jM4A Ol2WPRjbLjqUgCwoCCw0M3yykxJBrB+m7sf7+TMjFRFS6jo6FkDrwaI9n9M75BlEUA3/o q8UQ74j2Ra/6a1bIbRf0kP1GS6/AjdQNhyyeZNOMcIsDUXYVDigl81jytbmgke5wLo1+F ApC+GGyucMxtNxRNBINbpAKVPEz4ocwMEhbW6LIUumURCID1G1Spihk9A9M6wxzfIk6+G lP2fi/LslJb9I6ZddW29UdDVcLgPZ1nwI9IFC/tsdJoBn6sQrn2q1dzmbrbKVHPxukQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794578766; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=C0kDAcJ25HEa7l+lmxjvOALQB9PoPJwZxNqhGvdBIOo=; b=NxzrnefEROoLQXsBt7iHLhxRAlZegoqCYAg0l1HR2Wv9BUTZ8EeRq1OAuei3HaOD/2p5 kNMG20p8Umk/5RZSJfzW1Qbobk3TzD66AfKU3UZeEmY+T59ufm/8z+0IBuuXBQQ8SU7+1 JQmP4ePpaxLeGLHKaxjr2F8EboHyOIciW46yehJj1+x12kyXDLZehn+KadenOo7H9Ijp+ 9Cu2eUpDsXSYAmG5EY+UyxDRTe+FKFMxUhVALlGQli1Qp6nUYiIOap/Vf6k8i5XpyBbeN M0GMn3EbLv/ttGWW5/IApt6ekNsbF4SqIob/qhC6/5Te+kc2VEXDvpJr81dMLpDNqBg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Nr6uAWFN; arc=none smtp.remote-ip=91.218.175.242 X-Received: from mta0.migadu.com (out-242.mta0.migadu.com [91.218.175.242]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD6E2606A333 for <netdev@vger.kernel.org>; Fri, 13 Nov 2026 14:06:05 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AD6E2606A333 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=S2jAsuhfj6x/gYRYbnNnnd58G4n/8un6QgXDeo7I9G4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794578763; v=1; x=1795183563; b=Nr6uAWFNQwj1pBY2WEsP80Ieo4Wu9Rj9OjFOObaEZrUW2oWIpu+xZochN8cb7cKNxDbybJFg 5G6XoZ3DjgtZJ6V5Wr3wld1uJS5TaYVF72t674RaieMlvT9WPNRSuzUfH7ws829atSegVUKqju5 0y3v6Sa1RWUJpw3IVNgXVE7A= X-Envelope-To: netdev@vger.kernel.org X-Received: by mta10.migadu.com with ESMTPS id 19a0522a90f91ab5; Fri, 13 Nov 2026 14:05:59 +0000 X-Mizu-Trace-ID: 19a0522a90f91ab5 X-Migadu-Flow: FLOW_OUT X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261113-bond_enslave_restruct-v1-0-364c549e78db@kylinos.cn> X-Cc: Hangbin Liu <hangbin.liu@linux.dev>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Hangbin Liu <hangbin.liu@linux.dev> X-Mailer: b4 0.16.0