Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a4b32ce7 authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by David S. Miller
Browse files

bonding: convert xmit_hash_policy to use the new option API



This patch adds the necessary changes so xmit_hash_policy would use the
new bonding option API. Also fix some trivial/style errors.

Signed-off-by: default avatarNikolay Aleksandrov <nikolay@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent aa59d851
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
@@ -214,15 +214,6 @@ const struct bond_parm_tbl bond_lacp_tbl[] = {
{	NULL,		-1},
};

const struct bond_parm_tbl xmit_hashtype_tbl[] = {
{	"layer2",		BOND_XMIT_POLICY_LAYER2},
{	"layer3+4",		BOND_XMIT_POLICY_LAYER34},
{	"layer2+3",		BOND_XMIT_POLICY_LAYER23},
{	"encap2+3",		BOND_XMIT_POLICY_ENCAP23},
{	"encap3+4",		BOND_XMIT_POLICY_ENCAP34},
{	NULL,			-1},
};

const struct bond_parm_tbl arp_all_targets_tbl[] = {
{	"any",			BOND_ARP_TARGETS_ANY},
{	"all",			BOND_ARP_TARGETS_ALL},
@@ -4039,14 +4030,15 @@ static int bond_check_params(struct bond_params *params)
			pr_info("xmit_hash_policy param is irrelevant in mode %s\n",
			       bond_mode_name(bond_mode));
		} else {
			xmit_hashtype = bond_parse_parm(xmit_hash_policy,
							xmit_hashtype_tbl);
			if (xmit_hashtype == -1) {
			bond_opt_initstr(&newval, xmit_hash_policy);
			valptr = bond_opt_parse(bond_opt_get(BOND_OPT_XMIT_HASH),
						&newval);
			if (!valptr) {
				pr_err("Error: Invalid xmit_hash_policy \"%s\"\n",
				       xmit_hash_policy == NULL ? "NULL" :
				       xmit_hash_policy);
				return -EINVAL;
			}
			xmit_hashtype = valptr->value;
		}
	}

+2 −1
Original line number Diff line number Diff line
@@ -238,7 +238,8 @@ static int bond_changelink(struct net_device *bond_dev,
		int xmit_hash_policy =
			nla_get_u8(data[IFLA_BOND_XMIT_HASH_POLICY]);

		err = bond_option_xmit_hash_policy_set(bond, xmit_hash_policy);
		bond_opt_initval(&newval, xmit_hash_policy);
		err = __bond_opt_set(bond, BOND_OPT_XMIT_HASH, &newval);
		if (err)
			return err;
	}
+21 −11
Original line number Diff line number Diff line
@@ -36,6 +36,15 @@ static struct bond_opt_value bond_pps_tbl[] = {
	{ NULL,      -1,        0},
};

static struct bond_opt_value bond_xmit_hashtype_tbl[] = {
	{ "layer2",   BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT},
	{ "layer3+4", BOND_XMIT_POLICY_LAYER34, 0},
	{ "layer2+3", BOND_XMIT_POLICY_LAYER23, 0},
	{ "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0},
	{ "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0},
	{ NULL,       -1,                       0},
};

static struct bond_option bond_opts[] = {
	[BOND_OPT_MODE] = {
		.id = BOND_OPT_MODE,
@@ -53,6 +62,13 @@ static struct bond_option bond_opts[] = {
		.values = bond_pps_tbl,
		.set = bond_option_pps_set
	},
	[BOND_OPT_XMIT_HASH] = {
		.id = BOND_OPT_XMIT_HASH,
		.name = "xmit_hash_policy",
		.desc = "balance-xor and 802.3ad hashing method",
		.values = bond_xmit_hashtype_tbl,
		.set = bond_option_xmit_hash_policy_set
	},
	{ }
};

@@ -860,18 +876,12 @@ int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac)
	return 0;
}

int bond_option_xmit_hash_policy_set(struct bonding *bond, int xmit_hash_policy)
int bond_option_xmit_hash_policy_set(struct bonding *bond,
				     struct bond_opt_value *newval)
{
	if (bond_parm_tbl_lookup(xmit_hash_policy, xmit_hashtype_tbl) < 0) {
		pr_err("%s: Ignoring invalid xmit_hash_policy value %d.\n",
		       bond->dev->name, xmit_hash_policy);
		return -EINVAL;
	}

	bond->params.xmit_policy = xmit_hash_policy;
	pr_info("%s: setting xmit hash policy to %s (%d).\n",
		bond->dev->name,
		xmit_hashtype_tbl[xmit_hash_policy].modename, xmit_hash_policy);
	pr_info("%s: setting xmit hash policy to %s (%llu).\n",
		bond->dev->name, newval->string, newval->value);
	bond->params.xmit_policy = newval->value;

	return 0;
}
+3 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ enum {
enum {
	BOND_OPT_MODE,
	BOND_OPT_PACKETS_PER_SLAVE,
	BOND_OPT_XMIT_HASH,
	BOND_OPT_LAST
};

@@ -102,4 +103,6 @@ static inline void __bond_opt_init(struct bond_opt_value *optval,

int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval);
int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval);
int bond_option_xmit_hash_policy_set(struct bonding *bond,
				     struct bond_opt_value *newval);
#endif /* _BOND_OPTIONS_H */
+4 −2
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ static void bond_info_seq_stop(struct seq_file *seq, void *v)
static void bond_info_show_master(struct seq_file *seq)
{
	struct bonding *bond = seq->private;
	struct bond_opt_value *optval;
	struct slave *curr;
	int i;

@@ -84,9 +85,10 @@ static void bond_info_show_master(struct seq_file *seq)

	if (bond->params.mode == BOND_MODE_XOR ||
		bond->params.mode == BOND_MODE_8023AD) {
		seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
			xmit_hashtype_tbl[bond->params.xmit_policy].modename,
		optval = bond_opt_get_val(BOND_OPT_XMIT_HASH,
					  bond->params.xmit_policy);
		seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
			   optval->string, bond->params.xmit_policy);
	}

	if (USES_PRIMARY(bond->params.mode)) {
Loading