]> err.no Git - linux-2.6/blobdiff - drivers/net/bonding/bond_main.c
bonding: Relax unneeded _safe lists iterations.
[linux-2.6] / drivers / net / bonding / bond_main.c
index 6e91b4b7aabb3402629571288f43754a3b67f104..5e3b942fb515dc21caeec84a8a543fab494ac344 100644 (file)
@@ -261,14 +261,14 @@ static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id)
  */
 static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id)
 {
-       struct vlan_entry *vlan, *next;
+       struct vlan_entry *vlan;
        int res = -ENODEV;
 
        dprintk("bond: %s, vlan id %d\n", bond->dev->name, vlan_id);
 
        write_lock_bh(&bond->lock);
 
-       list_for_each_entry_safe(vlan, next, &bond->vlan_list, vlan_list) {
+       list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
                if (vlan->vlan_id == vlan_id) {
                        list_del(&vlan->vlan_list);
 
@@ -1425,13 +1425,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
        res = netdev_set_master(slave_dev, bond_dev);
        if (res) {
                dprintk("Error %d calling netdev_set_master\n", res);
-               goto err_close;
+               goto err_restore_mac;
        }
        /* open the slave since the application closed it */
        res = dev_open(slave_dev);
        if (res) {
                dprintk("Openning slave %s failed\n", slave_dev->name);
-               goto err_restore_mac;
+               goto err_unset_master;
        }
 
        new_slave->dev = slave_dev;
@@ -1444,7 +1444,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                 */
                res = bond_alb_init_slave(bond, new_slave);
                if (res) {
-                       goto err_unset_master;
+                       goto err_close;
                }
        }
 
@@ -1619,7 +1619,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
        res = bond_create_slave_symlinks(bond_dev, slave_dev);
        if (res)
-               goto err_unset_master;
+               goto err_close;
 
        printk(KERN_INFO DRV_NAME
               ": %s: enslaving %s as a%s interface with a%s link.\n",
@@ -1631,12 +1631,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
        return 0;
 
 /* Undo stages on error */
-err_unset_master:
-       netdev_set_master(slave_dev, NULL);
-
 err_close:
        dev_close(slave_dev);
 
+err_unset_master:
+       netdev_set_master(slave_dev, NULL);
+
 err_restore_mac:
        if (!bond->params.fail_over_mac) {
                memcpy(addr.sa_data, new_slave->perm_hwaddr, ETH_ALEN);
@@ -2397,7 +2397,7 @@ void bond_mii_monitor(struct work_struct *work)
                read_lock(&bond->lock);
        }
 
-       delay = ((bond->params.miimon * HZ) / 1000) ? : 1;
+       delay = msecs_to_jiffies(bond->params.miimon);
        read_unlock(&bond->lock);
        queue_delayed_work(bond->wq, &bond->mii_work, delay);
 }
@@ -2426,28 +2426,9 @@ out:
        return addr;
 }
 
-static int bond_has_ip(struct bonding *bond)
-{
-       struct vlan_entry *vlan, *vlan_next;
-
-       if (bond->master_ip)
-               return 1;
-
-       if (list_empty(&bond->vlan_list))
-               return 0;
-
-       list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
-                                vlan_list) {
-               if (vlan->vlan_ip)
-                       return 1;
-       }
-
-       return 0;
-}
-
 static int bond_has_this_ip(struct bonding *bond, __be32 ip)
 {
-       struct vlan_entry *vlan, *vlan_next;
+       struct vlan_entry *vlan;
 
        if (ip == bond->master_ip)
                return 1;
@@ -2455,8 +2436,7 @@ static int bond_has_this_ip(struct bonding *bond, __be32 ip)
        if (list_empty(&bond->vlan_list))
                return 0;
 
-       list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
-                                vlan_list) {
+       list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
                if (ip == vlan->vlan_ip)
                        return 1;
        }
@@ -2498,7 +2478,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
 {
        int i, vlan_id, rv;
        __be32 *targets = bond->params.arp_targets;
-       struct vlan_entry *vlan, *vlan_next;
+       struct vlan_entry *vlan;
        struct net_device *vlan_dev;
        struct flowi fl;
        struct rtable *rt;
@@ -2545,8 +2525,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
                }
 
                vlan_id = 0;
-               list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
-                                        vlan_list) {
+               list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
                        vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
                        if (vlan_dev == rt->u.dst.dev) {
                                vlan_id = vlan->vlan_id;
@@ -2707,7 +2686,7 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
 
        read_lock(&bond->lock);
 
-       delta_in_ticks = (bond->params.arp_interval * HZ) / 1000;
+       delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
 
        if (bond->kill_timers) {
                goto out;
@@ -2764,8 +2743,7 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
                         * if we don't know our ip yet
                         */
                        if (time_after_eq(jiffies, slave->dev->trans_start + 2*delta_in_ticks) ||
-                           (time_after_eq(jiffies, slave->dev->last_rx + 2*delta_in_ticks) &&
-                            bond_has_ip(bond))) {
+                           (time_after_eq(jiffies, slave->dev->last_rx + 2*delta_in_ticks))) {
 
                                slave->link  = BOND_LINK_DOWN;
                                slave->state = BOND_STATE_BACKUP;
@@ -2837,7 +2815,7 @@ void bond_activebackup_arp_mon(struct work_struct *work)
 
        read_lock(&bond->lock);
 
-       delta_in_ticks = (bond->params.arp_interval * HZ) / 1000;
+       delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
 
        if (bond->kill_timers) {
                goto out;
@@ -2900,8 +2878,7 @@ void bond_activebackup_arp_mon(struct work_struct *work)
 
                        if ((slave != bond->curr_active_slave) &&
                            (!bond->current_arp_slave) &&
-                           (time_after_eq(jiffies, slave_last_rx(bond, slave) + 3*delta_in_ticks) &&
-                            bond_has_ip(bond))) {
+                           (time_after_eq(jiffies, slave_last_rx(bond, slave) + 3*delta_in_ticks))) {
                                /* a backup slave has gone down; three times
                                 * the delta allows the current slave to be
                                 * taken out before the backup slave.
@@ -2947,8 +2924,7 @@ void bond_activebackup_arp_mon(struct work_struct *work)
                 * if it is up and needs to take over as the curr_active_slave
                 */
                if ((time_after_eq(jiffies, slave->dev->trans_start + 2*delta_in_ticks) ||
-                       (time_after_eq(jiffies, slave_last_rx(bond, slave) + 2*delta_in_ticks) &&
-                        bond_has_ip(bond))) &&
+                    (time_after_eq(jiffies, slave_last_rx(bond, slave) + 2*delta_in_ticks))) &&
                        time_after_eq(jiffies, slave->jiffies + 2*delta_in_ticks)) {
 
                        slave->link  = BOND_LINK_DOWN;
@@ -3000,9 +2976,8 @@ void bond_activebackup_arp_mon(struct work_struct *work)
                /* the current slave must tx an arp to ensure backup slaves
                 * rx traffic
                 */
-               if (slave && bond_has_ip(bond)) {
+               if (slave && IS_UP(slave->dev))
                        bond_arp_send_all(bond, slave);
-               }
        }
 
        /* if we don't have a curr_active_slave, search for the next available
@@ -3282,17 +3257,14 @@ static int bond_create_proc_entry(struct bonding *bond)
        struct net_device *bond_dev = bond->dev;
 
        if (bond_proc_dir) {
-               bond->proc_entry = create_proc_entry(bond_dev->name,
-                                                    S_IRUGO,
-                                                    bond_proc_dir);
+               bond->proc_entry = proc_create_data(bond_dev->name,
+                                                   S_IRUGO, bond_proc_dir,
+                                                   &bond_info_fops, bond);
                if (bond->proc_entry == NULL) {
                        printk(KERN_WARNING DRV_NAME
                               ": Warning: Cannot create /proc/net/%s/%s\n",
                               DRV_NAME, bond_dev->name);
                } else {
-                       bond->proc_entry->data = bond;
-                       bond->proc_entry->proc_fops = &bond_info_fops;
-                       bond->proc_entry->owner = THIS_MODULE;
                        memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
                }
        }
@@ -3503,13 +3475,13 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
 {
        struct in_ifaddr *ifa = ptr;
        struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev;
-       struct bonding *bond, *bond_next;
-       struct vlan_entry *vlan, *vlan_next;
+       struct bonding *bond;
+       struct vlan_entry *vlan;
 
        if (dev_net(ifa->ifa_dev->dev) != &init_net)
                return NOTIFY_DONE;
 
-       list_for_each_entry_safe(bond, bond_next, &bond_dev_list, bond_list) {
+       list_for_each_entry(bond, &bond_dev_list, bond_list) {
                if (bond->dev == event_dev) {
                        switch (event) {
                        case NETDEV_UP:
@@ -3526,8 +3498,7 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
                if (list_empty(&bond->vlan_list))
                        continue;
 
-               list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
-                                        vlan_list) {
+               list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
                        vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
                        if (vlan_dev == event_dev) {
                                switch (event) {
@@ -4874,10 +4845,10 @@ static struct lock_class_key bonding_netdev_xmit_lock_key;
  * Caller must NOT hold rtnl_lock; we need to release it here before we
  * set up our sysfs entries.
  */
-int bond_create(char *name, struct bond_params *params, struct bonding **newbond)
+int bond_create(char *name, struct bond_params *params)
 {
        struct net_device *bond_dev;
-       struct bonding *bond, *nxt;
+       struct bonding *bond;
        int res;
 
        rtnl_lock();
@@ -4885,7 +4856,7 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
 
        /* Check to see if the bond already exists. */
        if (name) {
-               list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
+               list_for_each_entry(bond, &bond_dev_list, bond_list)
                        if (strnicmp(bond->dev->name, name, IFNAMSIZ) == 0) {
                                printk(KERN_ERR DRV_NAME
                               ": cannot add bond %s; it already exists\n",
@@ -4928,9 +4899,6 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
 
        lockdep_set_class(&bond_dev->_xmit_lock, &bonding_netdev_xmit_lock_key);
 
-       if (newbond)
-               *newbond = bond_dev->priv;
-
        netif_carrier_off(bond_dev);
 
        up_write(&bonding_rwsem);
@@ -4939,7 +4907,9 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
        if (res < 0) {
                rtnl_lock();
                down_write(&bonding_rwsem);
-               goto out_bond;
+               bond_deinit(bond_dev);
+               unregister_netdevice(bond_dev);
+               goto out_rtnl;
        }
 
        return 0;
@@ -4958,7 +4928,7 @@ static int __init bonding_init(void)
 {
        int i;
        int res;
-       struct bonding *bond, *nxt;
+       struct bonding *bond;
 
        printk(KERN_INFO "%s", version);
 
@@ -4974,7 +4944,7 @@ static int __init bonding_init(void)
        init_rwsem(&bonding_rwsem);
 
        for (i = 0; i < max_bonds; i++) {
-               res = bond_create(NULL, &bonding_defaults, NULL);
+               res = bond_create(NULL, &bonding_defaults);
                if (res)
                        goto err;
        }
@@ -4988,14 +4958,15 @@ static int __init bonding_init(void)
 
        goto out;
 err:
-       list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) {
+       list_for_each_entry(bond, &bond_dev_list, bond_list) {
                bond_work_cancel_all(bond);
                destroy_workqueue(bond->wq);
        }
 
+       bond_destroy_sysfs();
+
        rtnl_lock();
        bond_free_all();
-       bond_destroy_sysfs();
        rtnl_unlock();
 out:
        return res;
@@ -5007,9 +4978,10 @@ static void __exit bonding_exit(void)
        unregister_netdevice_notifier(&bond_netdev_notifier);
        unregister_inetaddr_notifier(&bond_inetaddr_notifier);
 
+       bond_destroy_sysfs();
+
        rtnl_lock();
        bond_free_all();
-       bond_destroy_sysfs();
        rtnl_unlock();
 }