]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
bonding: Prevent duplicate userspace notification
authorVlad Yasevich <vyasevich@gmail.com>
Sat, 27 May 2017 14:14:35 +0000 (10:14 -0400)
committerDavid S. Miller <davem@davemloft.net>
Sat, 27 May 2017 22:51:41 +0000 (18:51 -0400)
Whenever a user changes bonding options, a NETDEV_CHANGEINFODATA
notificatin is generated which results in a rtnelink message to
be sent.  While runnig 'ip monitor', we can actually see 2 messages,
one a result of the event, and the other a result of state change
that is generated bo netdev_state_change().  However, this is not
always the case. If bonding changes were done via sysfs or ifenslave
(old ioctl interface), then only 1 message is seen.

This patch removes duplicate messages in the case of using netlink
to configure bonding.  It introduceds a separte function that
triggers a netdev event and uses that function in the syfs and ioctl
cases.

This was discovered while auditing all the different envents and
continues the effort of cleaning up duplicated netlink messages.

CC: David Ahern <dsa@cumulusnetworks.com>
CC: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com>
Acked-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_main.c
drivers/net/bonding/bond_options.c
include/net/bond_options.h

index 2359478b977f0e008335e51dc8f63adc2dc35087..d4484d1a81644826bb30a98681f32e3b81f69485 100644 (file)
@@ -3488,7 +3488,8 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
        case BOND_CHANGE_ACTIVE_OLD:
        case SIOCBONDCHANGEACTIVE:
                bond_opt_initstr(&newval, slave_dev->name);
-               res = __bond_opt_set(bond, BOND_OPT_ACTIVE_SLAVE, &newval);
+               res = __bond_opt_set_notify(bond, BOND_OPT_ACTIVE_SLAVE,
+                                           &newval);
                break;
        default:
                res = -EOPNOTSUPP;
index 1bcbb8913e1715872c463fa8717365d5eeae284e..8ca683396fccebd072133f0ae69b8e2db27a6484 100644 (file)
@@ -673,7 +673,30 @@ int __bond_opt_set(struct bonding *bond,
 out:
        if (ret)
                bond_opt_error_interpret(bond, opt, ret, val);
-       else if (bond->dev->reg_state == NETREG_REGISTERED)
+
+       return ret;
+}
+/**
+ * __bond_opt_set_notify - set a bonding option
+ * @bond: target bond device
+ * @option: option to set
+ * @val: value to set it to
+ *
+ * This function is used to change the bond's option value and trigger
+ * a notification to user sapce. 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_notify(struct bonding *bond,
+                         unsigned int option, struct bond_opt_value *val)
+{
+       int ret = -ENOENT;
+
+       ASSERT_RTNL();
+
+       ret = __bond_opt_set(bond, option, val);
+
+       if (!ret && (bond->dev->reg_state == NETREG_REGISTERED))
                call_netdevice_notifiers(NETDEV_CHANGEINFODATA, bond->dev);
 
        return ret;
@@ -696,7 +719,7 @@ int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf)
        if (!rtnl_trylock())
                return restart_syscall();
        bond_opt_initstr(&optval, buf);
-       ret = __bond_opt_set(bond, option, &optval);
+       ret = __bond_opt_set_notify(bond, option, &optval);
        rtnl_unlock();
 
        return ret;
index 1797235cd590c361eb216d33558b95e441087d3e..d79d28f5318c239731317739a5933a356c21930e 100644 (file)
@@ -104,6 +104,8 @@ struct bond_option {
 
 int __bond_opt_set(struct bonding *bond, unsigned int option,
                   struct bond_opt_value *val);
+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);
 
 const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,