Commit 2bff369b authored by Jonathan Toppins's avatar Jonathan Toppins Committed by Jakub Kicinski

bonding: netlink error message support for options

Add support for reporting errors via extack in both bond_newlink
and bond_changelink.

Instead of having to look in the kernel log for why an option was not
correct just report the error to the user via the extack variable.

What is currently reported today:
  ip link add bond0 type bond
  ip link set bond0 up
  ip link set bond0 type bond mode 4
 RTNETLINK answers: Device or resource busy

After this change:
  ip link add bond0 type bond
  ip link set bond0 up
  ip link set bond0 type bond mode 4
 Error: unable to set option because the bond is up.
Signed-off-by: default avatarJonathan Toppins <jtoppins@redhat.com>
Acked-by: default avatarJay Vosburgh <jay.vosburgh@canonical.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent ce1d8e74
This diff is collapsed.
......@@ -632,27 +632,35 @@ static int bond_opt_check_deps(struct bonding *bond,
}
static void bond_opt_dep_print(struct bonding *bond,
const struct bond_option *opt)
const struct bond_option *opt,
struct nlattr *bad_attr,
struct netlink_ext_ack *extack)
{
const struct bond_opt_value *modeval;
struct bond_params *params;
params = &bond->params;
modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
if (test_bit(params->mode, &opt->unsuppmodes))
if (test_bit(params->mode, &opt->unsuppmodes)) {
netdev_err(bond->dev, "option %s: mode dependency failed, not supported in mode %s(%llu)\n",
opt->name, modeval->string, modeval->value);
NL_SET_ERR_MSG_ATTR(extack, bad_attr,
"option not supported in mode");
}
}
static void bond_opt_error_interpret(struct bonding *bond,
const struct bond_option *opt,
int error, const struct bond_opt_value *val)
int error, const struct bond_opt_value *val,
struct nlattr *bad_attr,
struct netlink_ext_ack *extack)
{
const struct bond_opt_value *minval, *maxval;
char *p;
switch (error) {
case -EINVAL:
NL_SET_ERR_MSG_ATTR(extack, bad_attr, "invalid option value");
if (val) {
if (val->string) {
/* sometimes RAWVAL opts may have new lines */
......@@ -674,13 +682,17 @@ static void bond_opt_error_interpret(struct bonding *bond,
opt->name, minval ? minval->value : 0, maxval->value);
break;
case -EACCES:
bond_opt_dep_print(bond, opt);
bond_opt_dep_print(bond, opt, bad_attr, extack);
break;
case -ENOTEMPTY:
NL_SET_ERR_MSG_ATTR(extack, bad_attr,
"unable to set option because the bond device has slaves");
netdev_err(bond->dev, "option %s: unable to set because the bond device has slaves\n",
opt->name);
break;
case -EBUSY:
NL_SET_ERR_MSG_ATTR(extack, bad_attr,
"unable to set option because the bond is up");
netdev_err(bond->dev, "option %s: unable to set because the bond device is up\n",
opt->name);
break;
......@@ -691,6 +703,8 @@ static void bond_opt_error_interpret(struct bonding *bond,
*p = '\0';
netdev_err(bond->dev, "option %s: interface %s does not exist!\n",
opt->name, val->string);
NL_SET_ERR_MSG_ATTR(extack, bad_attr,
"interface does not exist");
}
break;
default:
......@@ -703,13 +717,17 @@ static void bond_opt_error_interpret(struct bonding *bond,
* @bond: target bond device
* @option: option to set
* @val: value to set it to
* @bad_attr: netlink attribue that caused the error
* @extack: extended netlink error structure, used when an error message
* needs to be returned to the caller via netlink
*
* This function is used to change the bond's option value, it can be
* used for both enabling/changing an option and for disabling it. RTNL lock
* must be obtained before calling this function.
*/
int __bond_opt_set(struct bonding *bond,
unsigned int option, struct bond_opt_value *val)
unsigned int option, struct bond_opt_value *val,
struct nlattr *bad_attr, struct netlink_ext_ack *extack)
{
const struct bond_opt_value *retval = NULL;
const struct bond_option *opt;
......@@ -731,7 +749,7 @@ int __bond_opt_set(struct bonding *bond,
ret = opt->set(bond, retval);
out:
if (ret)
bond_opt_error_interpret(bond, opt, ret, val);
bond_opt_error_interpret(bond, opt, ret, val, bad_attr, extack);
return ret;
}
......@@ -753,7 +771,7 @@ int __bond_opt_set_notify(struct bonding *bond,
ASSERT_RTNL();
ret = __bond_opt_set(bond, option, val);
ret = __bond_opt_set(bond, option, val, NULL, NULL);
if (!ret && (bond->dev->reg_state == NETREG_REGISTERED))
call_netdevice_notifiers(NETDEV_CHANGEINFODATA, bond->dev);
......
......@@ -107,7 +107,8 @@ struct bond_option {
};
int __bond_opt_set(struct bonding *bond, unsigned int option,
struct bond_opt_value *val);
struct bond_opt_value *val,
struct nlattr *bad_attr, struct netlink_ext_ack *extack);
int __bond_opt_set_notify(struct bonding *bond, unsigned int option,
struct bond_opt_value *val);
int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment