Commit c27334ae authored by Paolo Abeni's avatar Paolo Abeni
Browse files

Merge branch 'bonding-support-aggregator-selection-based-on-port-priority'

Hangbin Liu says:

====================
bonding: support aggregator selection based on port priority

This patchset introduces a new per-port bonding option: `ad_actor_port_prio`.

It allows users to configure the actor's port priority, which can then be used
by the bonding driver for aggregator selection based on port priority.

This provides finer control over LACP aggregator choice, especially in setups
with multiple eligible aggregators over 2 switches.
====================

Link: https://patch.msgid.link/20250902064501.360822-1-liuhangbin@gmail.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 389cca2b c2377f17
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -193,6 +193,15 @@ ad_actor_sys_prio
	This parameter has effect only in 802.3ad mode and is available through
	SysFs interface.

actor_port_prio

	In an AD system, this specifies the port priority. The allowed range
	is 1 - 65535. If the value is not specified, it takes 255 as the
	default value.

	This parameter has effect only in 802.3ad mode and is available through
	netlink interface.

ad_actor_system

	In an AD system, this specifies the mac-address for the actor in
@@ -241,10 +250,18 @@ ad_select
		ports (slaves).  Reselection occurs as described under the
		"bandwidth" setting, above.

	The bandwidth and count selection policies permit failover of
	802.3ad aggregations when partial failure of the active aggregator
	occurs.  This keeps the aggregator with the highest availability
	(either in bandwidth or in number of ports) active at all times.
	actor_port_prio or 3

		The active aggregator is chosen by the highest total sum of
		actor port priorities across its active ports. Note this
		priority is actor_port_prio, not per port prio, which is
		used for primary reselect.

	The bandwidth, count and actor_port_prio selection policies permit
	failover of 802.3ad aggregations when partial failure of the active
	aggregator occurs. This keeps the aggregator with the highest
	availability (either in bandwidth, number of ports, or total value
	of port priorities) active at all times.

	This option was added in bonding version 3.4.0.

+31 −0
Original line number Diff line number Diff line
@@ -436,6 +436,7 @@ static void __ad_actor_update_port(struct port *port)

	port->actor_system = BOND_AD_INFO(bond).system.sys_mac_addr;
	port->actor_system_priority = BOND_AD_INFO(bond).system.sys_priority;
	port->actor_port_priority = SLAVE_AD_INFO(port->slave)->port_priority;
}

/* Conversions */
@@ -746,6 +747,18 @@ static int __agg_active_ports(struct aggregator *agg)
	return active;
}

static unsigned int __agg_ports_priority(const struct aggregator *agg)
{
	struct port *port = agg->lag_ports;
	unsigned int prio = 0;

	for (; port; port = port->next_port_in_aggregator)
		if (port->is_enabled)
			prio += port->actor_port_priority;

	return prio;
}

/**
 * __get_agg_bandwidth - get the total bandwidth of an aggregator
 * @aggregator: the aggregator we're looking at
@@ -1707,6 +1720,9 @@ static struct aggregator *ad_agg_selection_test(struct aggregator *best,
	 * 4.  Therefore, current and best both have partner replies or
	 *     both do not, so perform selection policy:
	 *
	 * BOND_AD_PRIO: Select by total priority of ports. If priority
	 *     is equal, select by count.
	 *
	 * BOND_AD_COUNT: Select by count of ports.  If count is equal,
	 *     select by bandwidth.
	 *
@@ -1728,6 +1744,14 @@ static struct aggregator *ad_agg_selection_test(struct aggregator *best,
		return best;

	switch (__get_agg_selection_mode(curr->lag_ports)) {
	case BOND_AD_PRIO:
		if (__agg_ports_priority(curr) > __agg_ports_priority(best))
			return curr;

		if (__agg_ports_priority(curr) < __agg_ports_priority(best))
			return best;

		fallthrough;
	case BOND_AD_COUNT:
		if (__agg_active_ports(curr) > __agg_active_ports(best))
			return curr;
@@ -1793,6 +1817,10 @@ static int agg_device_up(const struct aggregator *agg)
 * (slaves), and reselect whenever a link state change takes place or the
 * set of slaves in the bond changes.
 *
 * BOND_AD_PRIO: select the aggregator with highest total priority of ports
 * (slaves), and reselect whenever a link state change takes place or the
 * set of slaves in the bond changes.
 *
 * FIXME: this function MUST be called with the first agg in the bond, or
 * __get_active_agg() won't work correctly. This function should be better
 * called with the bond itself, and retrieve the first agg from it.
@@ -2209,6 +2237,9 @@ void bond_3ad_bind_slave(struct slave *slave)

		ad_initialize_port(port, &bond->params);

		/* Port priority is initialized. Update it to slave's ad info */
		SLAVE_AD_INFO(slave)->port_priority = port->actor_port_priority;

		port->slave = slave;
		port->actor_port_number = SLAVE_AD_INFO(slave)->id;
		/* key is determined according to the link speed, duplex and
+16 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ static size_t bond_get_slave_size(const struct net_device *bond_dev,
		nla_total_size(sizeof(u8)) +	/* IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE */
		nla_total_size(sizeof(u16)) +	/* IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE */
		nla_total_size(sizeof(s32)) +	/* IFLA_BOND_SLAVE_PRIO */
		nla_total_size(sizeof(u16)) +	/* IFLA_BOND_SLAVE_ACTOR_PORT_PRIO */
		0;
}

@@ -77,6 +78,10 @@ static int bond_fill_slave_info(struct sk_buff *skb,
					ad_port->partner_oper.port_state))
				goto nla_put_failure;
		}

		if (nla_put_u16(skb, IFLA_BOND_SLAVE_ACTOR_PORT_PRIO,
				SLAVE_AD_INFO(slave)->port_priority))
			goto nla_put_failure;
	}

	return 0;
@@ -130,6 +135,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
static const struct nla_policy bond_slave_policy[IFLA_BOND_SLAVE_MAX + 1] = {
	[IFLA_BOND_SLAVE_QUEUE_ID]	= { .type = NLA_U16 },
	[IFLA_BOND_SLAVE_PRIO]		= { .type = NLA_S32 },
	[IFLA_BOND_SLAVE_ACTOR_PORT_PRIO]	= { .type = NLA_U16 },
};

static int bond_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -180,6 +186,16 @@ static int bond_slave_changelink(struct net_device *bond_dev,
			return err;
	}

	if (data[IFLA_BOND_SLAVE_ACTOR_PORT_PRIO]) {
		u16 ad_prio = nla_get_u16(data[IFLA_BOND_SLAVE_ACTOR_PORT_PRIO]);

		bond_opt_slave_initval(&newval, &slave_dev, ad_prio);
		err = __bond_opt_set(bond, BOND_OPT_ACTOR_PORT_PRIO, &newval,
				     data[IFLA_BOND_SLAVE_ACTOR_PORT_PRIO], extack);
		if (err)
			return err;
	}

	return 0;
}

+41 −4
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
				  const struct bond_opt_value *newval);
static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
					     const struct bond_opt_value *newval);
static int bond_option_actor_port_prio_set(struct bonding *bond,
					   const struct bond_opt_value *newval);
static int bond_option_ad_actor_system_set(struct bonding *bond,
					   const struct bond_opt_value *newval);
static int bond_option_ad_user_port_key_set(struct bonding *bond,
@@ -163,6 +165,7 @@ static const struct bond_opt_value bond_ad_select_tbl[] = {
	{ "stable",          BOND_AD_STABLE,    BOND_VALFLAG_DEFAULT},
	{ "bandwidth",       BOND_AD_BANDWIDTH, 0},
	{ "count",           BOND_AD_COUNT,     0},
	{ "actor_port_prio", BOND_AD_PRIO,      0},
	{ NULL,              -1,                0},
};

@@ -222,6 +225,13 @@ static const struct bond_opt_value bond_ad_actor_sys_prio_tbl[] = {
	{ NULL,      -1,    0},
};

static const struct bond_opt_value bond_actor_port_prio_tbl[] = {
	{ "minval",  0,     BOND_VALFLAG_MIN},
	{ "maxval",  65535, BOND_VALFLAG_MAX},
	{ "default", 255,   BOND_VALFLAG_DEFAULT},
	{ NULL,      -1,    0},
};

static const struct bond_opt_value bond_ad_user_port_key_tbl[] = {
	{ "minval",  0,     BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT},
	{ "maxval",  1023,  BOND_VALFLAG_MAX},
@@ -483,6 +493,13 @@ static const struct bond_option bond_opts[BOND_OPT_LAST] = {
		.values = bond_ad_actor_sys_prio_tbl,
		.set = bond_option_ad_actor_sys_prio_set,
	},
	[BOND_OPT_ACTOR_PORT_PRIO] = {
		.id = BOND_OPT_ACTOR_PORT_PRIO,
		.name = "actor_port_prio",
		.unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
		.values = bond_actor_port_prio_tbl,
		.set = bond_option_actor_port_prio_set,
	},
	[BOND_OPT_AD_ACTOR_SYSTEM] = {
		.id = BOND_OPT_AD_ACTOR_SYSTEM,
		.name = "ad_actor_system",
@@ -1812,6 +1829,26 @@ static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
	return 0;
}

static int bond_option_actor_port_prio_set(struct bonding *bond,
					   const struct bond_opt_value *newval)
{
	struct slave *slave;

	slave = bond_slave_get_rtnl(newval->slave_dev);
	if (!slave) {
		netdev_dbg(bond->dev, "%s called on NULL slave\n", __func__);
		return -ENODEV;
	}

	netdev_dbg(newval->slave_dev, "Setting actor_port_prio to %llu\n",
		   newval->value);

	SLAVE_AD_INFO(slave)->port_priority = newval->value;
	bond_3ad_update_ad_actor_settings(bond);

	return 0;
}

static int bond_option_ad_actor_system_set(struct bonding *bond,
					   const struct bond_opt_value *newval)
{
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ enum {
	BOND_AD_STABLE = 0,
	BOND_AD_BANDWIDTH = 1,
	BOND_AD_COUNT = 2,
	BOND_AD_PRIO = 3,
};

/* rx machine states(43.4.11 in the 802.3ad standard) */
@@ -274,6 +275,7 @@ struct ad_slave_info {
	struct port port;		/* 802.3ad port structure */
	struct bond_3ad_stats stats;
	u16 id;
	u16 port_priority;
};

static inline const char *bond_3ad_churn_desc(churn_state_t state)
Loading