Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[sfrench/cifs-2.6.git] / drivers / net / bonding / bond_sysfs.c
index 855dc10ffa1b8aea624816bd299e0689b314309d..11b76b352415f6dedad302133b97e952728032dd 100644 (file)
@@ -74,7 +74,7 @@ struct rw_semaphore bonding_rwsem;
  * "show" function for the bond_masters attribute.
  * The class parameter is ignored.
  */
-static ssize_t bonding_show_bonds(struct class *cls, char *buffer)
+static ssize_t bonding_show_bonds(struct class *cls, char *buf)
 {
        int res = 0;
        struct bonding *bond;
@@ -86,14 +86,13 @@ static ssize_t bonding_show_bonds(struct class *cls, char *buffer)
                        /* not enough space for another interface name */
                        if ((PAGE_SIZE - res) > 10)
                                res = PAGE_SIZE - 10;
-                       res += sprintf(buffer + res, "++more++");
+                       res += sprintf(buf + res, "++more++ ");
                        break;
                }
-               res += sprintf(buffer + res, "%s ",
-                              bond->dev->name);
+               res += sprintf(buf + res, "%s ", bond->dev->name);
        }
-       res += sprintf(buffer + res, "\n");
-       res++;
+       if (res)
+               buf[res-1] = '\n'; /* eat the leftover space */
        up_read(&(bonding_rwsem));
        return res;
 }
@@ -229,20 +228,20 @@ static ssize_t bonding_show_slaves(struct device *d,
        int i, res = 0;
        struct bonding *bond = to_bond(d);
 
-       read_lock_bh(&bond->lock);
+       read_lock(&bond->lock);
        bond_for_each_slave(bond, slave, i) {
                if (res > (PAGE_SIZE - IFNAMSIZ)) {
                        /* not enough space for another interface name */
                        if ((PAGE_SIZE - res) > 10)
                                res = PAGE_SIZE - 10;
-                       res += sprintf(buf + res, "++more++");
+                       res += sprintf(buf + res, "++more++ ");
                        break;
                }
                res += sprintf(buf + res, "%s ", slave->dev->name);
        }
-       read_unlock_bh(&bond->lock);
-       res += sprintf(buf + res, "\n");
-       res++;
+       read_unlock(&bond->lock);
+       if (res)
+               buf[res-1] = '\n'; /* eat the leftover space */
        return res;
 }
 
@@ -282,18 +281,18 @@ static ssize_t bonding_store_slaves(struct device *d,
 
                /* Got a slave name in ifname.  Is it already in the list? */
                found = 0;
-               read_lock_bh(&bond->lock);
+               read_lock(&bond->lock);
                bond_for_each_slave(bond, slave, i)
                        if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
                                printk(KERN_ERR DRV_NAME
                                       ": %s: Interface %s is already enslaved!\n",
                                       bond->dev->name, ifname);
                                ret = -EPERM;
-                               read_unlock_bh(&bond->lock);
+                               read_unlock(&bond->lock);
                                goto out;
                        }
 
-               read_unlock_bh(&bond->lock);
+               read_unlock(&bond->lock);
                printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n",
                       bond->dev->name, ifname);
                dev = dev_get_by_name(&init_net, ifname);
@@ -406,7 +405,7 @@ static ssize_t bonding_show_mode(struct device *d,
 
        return sprintf(buf, "%s %d\n",
                        bond_mode_tbl[bond->params.mode].modename,
-                       bond->params.mode) + 1;
+                       bond->params.mode);
 }
 
 static ssize_t bonding_store_mode(struct device *d,
@@ -457,20 +456,11 @@ static ssize_t bonding_show_xmit_hash(struct device *d,
                                      struct device_attribute *attr,
                                      char *buf)
 {
-       int count;
        struct bonding *bond = to_bond(d);
 
-       if ((bond->params.mode != BOND_MODE_XOR) &&
-           (bond->params.mode != BOND_MODE_8023AD)) {
-               // Not Applicable
-               count = sprintf(buf, "NA\n") + 1;
-       } else {
-               count = sprintf(buf, "%s %d\n",
-                       xmit_hashtype_tbl[bond->params.xmit_policy].modename,
-                       bond->params.xmit_policy) + 1;
-       }
-
-       return count;
+       return sprintf(buf, "%s %d\n",
+                      xmit_hashtype_tbl[bond->params.xmit_policy].modename,
+                      bond->params.xmit_policy);
 }
 
 static ssize_t bonding_store_xmit_hash(struct device *d,
@@ -488,15 +478,6 @@ static ssize_t bonding_store_xmit_hash(struct device *d,
                goto out;
        }
 
-       if ((bond->params.mode != BOND_MODE_XOR) &&
-           (bond->params.mode != BOND_MODE_8023AD)) {
-               printk(KERN_ERR DRV_NAME
-                      "%s: Transmit hash policy is irrelevant in this mode.\n",
-                      bond->dev->name);
-               ret = -EPERM;
-               goto out;
-       }
-
        new_value = bond_parse_parm((char *)buf, xmit_hashtype_tbl);
        if (new_value < 0)  {
                printk(KERN_ERR DRV_NAME
@@ -527,7 +508,7 @@ static ssize_t bonding_show_arp_validate(struct device *d,
 
        return sprintf(buf, "%s %d\n",
                       arp_validate_tbl[bond->params.arp_validate].modename,
-                      bond->params.arp_validate) + 1;
+                      bond->params.arp_validate);
 }
 
 static ssize_t bonding_store_arp_validate(struct device *d,
@@ -627,7 +608,7 @@ static ssize_t bonding_show_arp_interval(struct device *d,
 {
        struct bonding *bond = to_bond(d);
 
-       return sprintf(buf, "%d\n", bond->params.arp_interval) + 1;
+       return sprintf(buf, "%d\n", bond->params.arp_interval);
 }
 
 static ssize_t bonding_store_arp_interval(struct device *d,
@@ -662,12 +643,9 @@ static ssize_t bonding_store_arp_interval(struct device *d,
                       "%s Disabling MII monitoring.\n",
                       bond->dev->name, bond->dev->name);
                bond->params.miimon = 0;
-               /* Kill MII timer, else it brings bond's link down */
-               if (bond->arp_timer.function) {
-                       printk(KERN_INFO DRV_NAME
-                       ": %s: Kill MII timer, else it brings bond's link down...\n",
-                      bond->dev->name);
-                       del_timer_sync(&bond->mii_timer);
+               if (delayed_work_pending(&bond->mii_work)) {
+                       cancel_delayed_work(&bond->mii_work);
+                       flush_workqueue(bond->wq);
                }
        }
        if (!bond->params.arp_targets[0]) {
@@ -682,25 +660,15 @@ static ssize_t bonding_store_arp_interval(struct device *d,
                 * timer will get fired off when the open function
                 * is called.
                 */
-               if (bond->arp_timer.function) {
-                       /* The timer's already set up, so fire it off */
-                       mod_timer(&bond->arp_timer, jiffies + 1);
-               } else {
-                       /* Set up the timer. */
-                       init_timer(&bond->arp_timer);
-                       bond->arp_timer.expires = jiffies + 1;
-                       bond->arp_timer.data =
-                               (unsigned long) bond->dev;
-                       if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
-                               bond->arp_timer.function =
-                                       (void *)
-                                       &bond_activebackup_arp_mon;
-                       } else {
-                               bond->arp_timer.function =
-                                       (void *)
-                                       &bond_loadbalance_arp_mon;
-                       }
-                       add_timer(&bond->arp_timer);
+               if (!delayed_work_pending(&bond->arp_work)) {
+                       if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
+                               INIT_DELAYED_WORK(&bond->arp_work,
+                                                 bond_activebackup_arp_mon);
+                       else
+                               INIT_DELAYED_WORK(&bond->arp_work,
+                                                 bond_loadbalance_arp_mon);
+
+                       queue_delayed_work(bond->wq, &bond->arp_work, 0);
                }
        }
 
@@ -725,9 +693,7 @@ static ssize_t bonding_show_arp_targets(struct device *d,
                               NIPQUAD(bond->params.arp_targets[i]));
        }
        if (res)
-               res--;  /* eat the leftover space */
-       res += sprintf(buf + res, "\n");
-       res++;
+               buf[res-1] = '\n'; /* eat the leftover space */
        return res;
 }
 
@@ -828,7 +794,7 @@ static ssize_t bonding_show_downdelay(struct device *d,
 {
        struct bonding *bond = to_bond(d);
 
-       return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon) + 1;
+       return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
 }
 
 static ssize_t bonding_store_downdelay(struct device *d,
@@ -885,7 +851,7 @@ static ssize_t bonding_show_updelay(struct device *d,
 {
        struct bonding *bond = to_bond(d);
 
-       return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon) + 1;
+       return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
 
 }
 
@@ -949,7 +915,7 @@ static ssize_t bonding_show_lacp(struct device *d,
 
        return sprintf(buf, "%s %d\n",
                bond_lacp_tbl[bond->params.lacp_fast].modename,
-               bond->params.lacp_fast) + 1;
+               bond->params.lacp_fast);
 }
 
 static ssize_t bonding_store_lacp(struct device *d,
@@ -1005,7 +971,7 @@ static ssize_t bonding_show_miimon(struct device *d,
 {
        struct bonding *bond = to_bond(d);
 
-       return sprintf(buf, "%d\n", bond->params.miimon) + 1;
+       return sprintf(buf, "%d\n", bond->params.miimon);
 }
 
 static ssize_t bonding_store_miimon(struct device *d,
@@ -1056,12 +1022,9 @@ static ssize_t bonding_store_miimon(struct device *d,
                                bond->params.arp_validate =
                                        BOND_ARP_VALIDATE_NONE;
                        }
-                       /* Kill ARP timer, else it brings bond's link down */
-                       if (bond->mii_timer.function) {
-                               printk(KERN_INFO DRV_NAME
-                               ": %s: Kill ARP timer, else it brings bond's link down...\n",
-                              bond->dev->name);
-                               del_timer_sync(&bond->arp_timer);
+                       if (delayed_work_pending(&bond->arp_work)) {
+                               cancel_delayed_work(&bond->arp_work);
+                               flush_workqueue(bond->wq);
                        }
                }
 
@@ -1071,18 +1034,11 @@ static ssize_t bonding_store_miimon(struct device *d,
                         * timer will get fired off when the open function
                         * is called.
                         */
-                       if (bond->mii_timer.function) {
-                               /* The timer's already set up, so fire it off */
-                               mod_timer(&bond->mii_timer, jiffies + 1);
-                       } else {
-                               /* Set up the timer. */
-                               init_timer(&bond->mii_timer);
-                               bond->mii_timer.expires = jiffies + 1;
-                               bond->mii_timer.data =
-                                       (unsigned long) bond->dev;
-                               bond->mii_timer.function =
-                                       (void *) &bond_mii_monitor;
-                               add_timer(&bond->mii_timer);
+                       if (!delayed_work_pending(&bond->mii_work)) {
+                               INIT_DELAYED_WORK(&bond->mii_work,
+                                                 bond_mii_monitor);
+                               queue_delayed_work(bond->wq,
+                                                  &bond->mii_work, 0);
                        }
                }
        }
@@ -1106,9 +1062,7 @@ static ssize_t bonding_show_primary(struct device *d,
        struct bonding *bond = to_bond(d);
 
        if (bond->primary_slave)
-               count = sprintf(buf, "%s\n", bond->primary_slave->dev->name) + 1;
-       else
-               count = sprintf(buf, "\n") + 1;
+               count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
 
        return count;
 }
@@ -1156,6 +1110,9 @@ static ssize_t bonding_store_primary(struct device *d,
        }
 out:
        write_unlock_bh(&bond->lock);
+
+       rtnl_unlock();
+
        return count;
 }
 static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, bonding_show_primary, bonding_store_primary);
@@ -1169,7 +1126,7 @@ static ssize_t bonding_show_carrier(struct device *d,
 {
        struct bonding *bond = to_bond(d);
 
-       return sprintf(buf, "%d\n", bond->params.use_carrier) + 1;
+       return sprintf(buf, "%d\n", bond->params.use_carrier);
 }
 
 static ssize_t bonding_store_carrier(struct device *d,
@@ -1211,17 +1168,14 @@ static ssize_t bonding_show_active_slave(struct device *d,
 {
        struct slave *curr;
        struct bonding *bond = to_bond(d);
-       int count;
-
+       int count = 0;
 
        read_lock(&bond->curr_slave_lock);
        curr = bond->curr_active_slave;
        read_unlock(&bond->curr_slave_lock);
 
        if (USES_PRIMARY(bond->params.mode) && curr)
-               count = sprintf(buf, "%s\n", curr->dev->name) + 1;
-       else
-               count = sprintf(buf, "\n") + 1;
+               count = sprintf(buf, "%s\n", curr->dev->name);
        return count;
 }
 
@@ -1235,7 +1189,9 @@ static ssize_t bonding_store_active_slave(struct device *d,
         struct slave *new_active = NULL;
        struct bonding *bond = to_bond(d);
 
+       rtnl_lock();
        write_lock_bh(&bond->lock);
+
        if (!USES_PRIMARY(bond->params.mode)) {
                printk(KERN_INFO DRV_NAME
                       ": %s: Unable to change active slave; %s is in mode %d\n",
@@ -1292,6 +1248,8 @@ static ssize_t bonding_store_active_slave(struct device *d,
        }
 out:
        write_unlock_bh(&bond->lock);
+       rtnl_unlock();
+
        return count;
 
 }
@@ -1312,7 +1270,7 @@ static ssize_t bonding_show_mii_status(struct device *d,
        curr = bond->curr_active_slave;
        read_unlock(&bond->curr_slave_lock);
 
-       return sprintf(buf, "%s\n", (curr) ? "up" : "down") + 1;
+       return sprintf(buf, "%s\n", (curr) ? "up" : "down");
 }
 static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
 
@@ -1329,10 +1287,8 @@ static ssize_t bonding_show_ad_aggregator(struct device *d,
 
        if (bond->params.mode == BOND_MODE_8023AD) {
                struct ad_info ad_info;
-               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0 : ad_info.aggregator_id) + 1;
+               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0 : ad_info.aggregator_id);
        }
-       else
-               count = sprintf(buf, "\n") + 1;
 
        return count;
 }
@@ -1351,10 +1307,8 @@ static ssize_t bonding_show_ad_num_ports(struct device *d,
 
        if (bond->params.mode == BOND_MODE_8023AD) {
                struct ad_info ad_info;
-               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0: ad_info.ports) + 1;
+               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0: ad_info.ports);
        }
-       else
-               count = sprintf(buf, "\n") + 1;
 
        return count;
 }
@@ -1373,10 +1327,8 @@ static ssize_t bonding_show_ad_actor_key(struct device *d,
 
        if (bond->params.mode == BOND_MODE_8023AD) {
                struct ad_info ad_info;
-               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0 : ad_info.actor_key) + 1;
+               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0 : ad_info.actor_key);
        }
-       else
-               count = sprintf(buf, "\n") + 1;
 
        return count;
 }
@@ -1395,10 +1347,8 @@ static ssize_t bonding_show_ad_partner_key(struct device *d,
 
        if (bond->params.mode == BOND_MODE_8023AD) {
                struct ad_info ad_info;
-               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0 : ad_info.partner_key) + 1;
+               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0 : ad_info.partner_key);
        }
-       else
-               count = sprintf(buf, "\n") + 1;
 
        return count;
 }
@@ -1420,12 +1370,9 @@ static ssize_t bonding_show_ad_partner_mac(struct device *d,
                struct ad_info ad_info;
                if (!bond_3ad_get_active_agg_info(bond, &ad_info)) {
                        count = sprintf(buf,"%s\n",
-                                       print_mac(mac, ad_info.partner_system))
-                               + 1;
+                                       print_mac(mac, ad_info.partner_system));
                }
        }
-       else
-               count = sprintf(buf, "\n") + 1;
 
        return count;
 }