diff options
Diffstat (limited to 'drivers/net/bonding/bond_sysfs.c')
-rw-r--r-- | drivers/net/bonding/bond_sysfs.c | 151 |
1 files changed, 93 insertions, 58 deletions
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 2d615a93685e..8996bd0a194a 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -47,10 +47,10 @@ static ssize_t bonding_show_bonds(struct class *cls, /* not enough space for another interface name */ if ((PAGE_SIZE - res) > 10) res = PAGE_SIZE - 10; - res += sprintf(buf + res, "++more++ "); + res += sysfs_emit_at(buf, res, "++more++ "); break; } - res += sprintf(buf + res, "%s ", bond->dev->name); + res += sysfs_emit_at(buf, res, "%s ", bond->dev->name); } if (res) buf[res-1] = '\n'; /* eat the leftover space */ @@ -178,10 +178,10 @@ static ssize_t bonding_show_slaves(struct device *d, /* not enough space for another interface name */ if ((PAGE_SIZE - res) > 10) res = PAGE_SIZE - 10; - res += sprintf(buf + res, "++more++ "); + res += sysfs_emit_at(buf, res, "++more++ "); break; } - res += sprintf(buf + res, "%s ", slave->dev->name); + res += sysfs_emit_at(buf, res, "%s ", slave->dev->name); } rtnl_unlock(); @@ -203,7 +203,7 @@ static ssize_t bonding_show_mode(struct device *d, val = bond_opt_get_val(BOND_OPT_MODE, BOND_MODE(bond)); - return sprintf(buf, "%s %d\n", val->string, BOND_MODE(bond)); + return sysfs_emit(buf, "%s %d\n", val->string, BOND_MODE(bond)); } static DEVICE_ATTR(mode, 0644, bonding_show_mode, bonding_sysfs_store_option); @@ -217,7 +217,7 @@ static ssize_t bonding_show_xmit_hash(struct device *d, val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy); - return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy); + return sysfs_emit(buf, "%s %d\n", val->string, bond->params.xmit_policy); } static DEVICE_ATTR(xmit_hash_policy, 0644, bonding_show_xmit_hash, bonding_sysfs_store_option); @@ -233,7 +233,7 @@ static ssize_t bonding_show_arp_validate(struct device *d, val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE, bond->params.arp_validate); - return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate); + return sysfs_emit(buf, "%s %d\n", val->string, bond->params.arp_validate); } static DEVICE_ATTR(arp_validate, 0644, bonding_show_arp_validate, bonding_sysfs_store_option); @@ -248,7 +248,7 @@ static ssize_t bonding_show_arp_all_targets(struct device *d, val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS, bond->params.arp_all_targets); - return sprintf(buf, "%s %d\n", + return sysfs_emit(buf, "%s %d\n", val->string, bond->params.arp_all_targets); } static DEVICE_ATTR(arp_all_targets, 0644, @@ -265,7 +265,7 @@ static ssize_t bonding_show_fail_over_mac(struct device *d, val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC, bond->params.fail_over_mac); - return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac); + return sysfs_emit(buf, "%s %d\n", val->string, bond->params.fail_over_mac); } static DEVICE_ATTR(fail_over_mac, 0644, bonding_show_fail_over_mac, bonding_sysfs_store_option); @@ -277,7 +277,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); + return sysfs_emit(buf, "%d\n", bond->params.arp_interval); } static DEVICE_ATTR(arp_interval, 0644, bonding_show_arp_interval, bonding_sysfs_store_option); @@ -292,8 +292,8 @@ static ssize_t bonding_show_arp_targets(struct device *d, for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { if (bond->params.arp_targets[i]) - res += sprintf(buf + res, "%pI4 ", - &bond->params.arp_targets[i]); + res += sysfs_emit_at(buf, res, "%pI4 ", + &bond->params.arp_targets[i]); } if (res) buf[res-1] = '\n'; /* eat the leftover space */ @@ -303,6 +303,18 @@ static ssize_t bonding_show_arp_targets(struct device *d, static DEVICE_ATTR(arp_ip_target, 0644, bonding_show_arp_targets, bonding_sysfs_store_option); +/* Show the arp missed max. */ +static ssize_t bonding_show_missed_max(struct device *d, + struct device_attribute *attr, + char *buf) +{ + struct bonding *bond = to_bond(d); + + return sysfs_emit(buf, "%u\n", bond->params.missed_max); +} +static DEVICE_ATTR(arp_missed_max, 0644, + bonding_show_missed_max, bonding_sysfs_store_option); + /* Show the up and down delays. */ static ssize_t bonding_show_downdelay(struct device *d, struct device_attribute *attr, @@ -310,7 +322,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); + return sysfs_emit(buf, "%d\n", bond->params.downdelay * bond->params.miimon); } static DEVICE_ATTR(downdelay, 0644, bonding_show_downdelay, bonding_sysfs_store_option); @@ -321,7 +333,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); + return sysfs_emit(buf, "%d\n", bond->params.updelay * bond->params.miimon); } static DEVICE_ATTR(updelay, 0644, @@ -333,26 +345,40 @@ static ssize_t bonding_show_peer_notif_delay(struct device *d, { struct bonding *bond = to_bond(d); - return sprintf(buf, "%d\n", - bond->params.peer_notif_delay * bond->params.miimon); + return sysfs_emit(buf, "%d\n", + bond->params.peer_notif_delay * bond->params.miimon); } static DEVICE_ATTR(peer_notif_delay, 0644, bonding_show_peer_notif_delay, bonding_sysfs_store_option); -/* Show the LACP interval. */ -static ssize_t bonding_show_lacp(struct device *d, - struct device_attribute *attr, - char *buf) +/* Show the LACP activity and interval. */ +static ssize_t bonding_show_lacp_active(struct device *d, + struct device_attribute *attr, + char *buf) +{ + struct bonding *bond = to_bond(d); + const struct bond_opt_value *val; + + val = bond_opt_get_val(BOND_OPT_LACP_ACTIVE, bond->params.lacp_active); + + return sysfs_emit(buf, "%s %d\n", val->string, bond->params.lacp_active); +} +static DEVICE_ATTR(lacp_active, 0644, + bonding_show_lacp_active, bonding_sysfs_store_option); + +static ssize_t bonding_show_lacp_rate(struct device *d, + struct device_attribute *attr, + char *buf) { struct bonding *bond = to_bond(d); const struct bond_opt_value *val; val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast); - return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast); + return sysfs_emit(buf, "%s %d\n", val->string, bond->params.lacp_fast); } static DEVICE_ATTR(lacp_rate, 0644, - bonding_show_lacp, bonding_sysfs_store_option); + bonding_show_lacp_rate, bonding_sysfs_store_option); static ssize_t bonding_show_min_links(struct device *d, struct device_attribute *attr, @@ -360,7 +386,7 @@ static ssize_t bonding_show_min_links(struct device *d, { struct bonding *bond = to_bond(d); - return sprintf(buf, "%u\n", bond->params.min_links); + return sysfs_emit(buf, "%u\n", bond->params.min_links); } static DEVICE_ATTR(min_links, 0644, bonding_show_min_links, bonding_sysfs_store_option); @@ -374,7 +400,7 @@ static ssize_t bonding_show_ad_select(struct device *d, val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select); - return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select); + return sysfs_emit(buf, "%s %d\n", val->string, bond->params.ad_select); } static DEVICE_ATTR(ad_select, 0644, bonding_show_ad_select, bonding_sysfs_store_option); @@ -385,7 +411,8 @@ static ssize_t bonding_show_num_peer_notif(struct device *d, char *buf) { struct bonding *bond = to_bond(d); - return sprintf(buf, "%d\n", bond->params.num_peer_notif); + + return sysfs_emit(buf, "%d\n", bond->params.num_peer_notif); } static DEVICE_ATTR(num_grat_arp, 0644, bonding_show_num_peer_notif, bonding_sysfs_store_option); @@ -399,7 +426,7 @@ static ssize_t bonding_show_miimon(struct device *d, { struct bonding *bond = to_bond(d); - return sprintf(buf, "%d\n", bond->params.miimon); + return sysfs_emit(buf, "%d\n", bond->params.miimon); } static DEVICE_ATTR(miimon, 0644, bonding_show_miimon, bonding_sysfs_store_option); @@ -416,7 +443,7 @@ static ssize_t bonding_show_primary(struct device *d, rcu_read_lock(); primary = rcu_dereference(bond->primary_slave); if (primary) - count = sprintf(buf, "%s\n", primary->dev->name); + count = sysfs_emit(buf, "%s\n", primary->dev->name); rcu_read_unlock(); return count; @@ -435,8 +462,8 @@ static ssize_t bonding_show_primary_reselect(struct device *d, val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT, bond->params.primary_reselect); - return sprintf(buf, "%s %d\n", - val->string, bond->params.primary_reselect); + return sysfs_emit(buf, "%s %d\n", + val->string, bond->params.primary_reselect); } static DEVICE_ATTR(primary_reselect, 0644, bonding_show_primary_reselect, bonding_sysfs_store_option); @@ -448,7 +475,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); + return sysfs_emit(buf, "%d\n", bond->params.use_carrier); } static DEVICE_ATTR(use_carrier, 0644, bonding_show_carrier, bonding_sysfs_store_option); @@ -466,7 +493,7 @@ static ssize_t bonding_show_active_slave(struct device *d, rcu_read_lock(); slave_dev = bond_option_active_slave_get_rcu(bond); if (slave_dev) - count = sprintf(buf, "%s\n", slave_dev->name); + count = sysfs_emit(buf, "%s\n", slave_dev->name); rcu_read_unlock(); return count; @@ -482,7 +509,7 @@ static ssize_t bonding_show_mii_status(struct device *d, struct bonding *bond = to_bond(d); bool active = netif_carrier_ok(bond->dev); - return sprintf(buf, "%s\n", active ? "up" : "down"); + return sysfs_emit(buf, "%s\n", active ? "up" : "down"); } static DEVICE_ATTR(mii_status, 0444, bonding_show_mii_status, NULL); @@ -496,9 +523,10 @@ static ssize_t bonding_show_ad_aggregator(struct device *d, if (BOND_MODE(bond) == 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); + + count = sysfs_emit(buf, "%d\n", + bond_3ad_get_active_agg_info(bond, &ad_info) + ? 0 : ad_info.aggregator_id); } return count; @@ -516,9 +544,10 @@ static ssize_t bonding_show_ad_num_ports(struct device *d, if (BOND_MODE(bond) == 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); + + count = sysfs_emit(buf, "%d\n", + bond_3ad_get_active_agg_info(bond, &ad_info) + ? 0 : ad_info.ports); } return count; @@ -536,9 +565,10 @@ static ssize_t bonding_show_ad_actor_key(struct device *d, if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { struct ad_info ad_info; - count = sprintf(buf, "%d\n", - bond_3ad_get_active_agg_info(bond, &ad_info) - ? 0 : ad_info.actor_key); + + count = sysfs_emit(buf, "%d\n", + bond_3ad_get_active_agg_info(bond, &ad_info) + ? 0 : ad_info.actor_key); } return count; @@ -556,9 +586,10 @@ static ssize_t bonding_show_ad_partner_key(struct device *d, if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { struct ad_info ad_info; - count = sprintf(buf, "%d\n", - bond_3ad_get_active_agg_info(bond, &ad_info) - ? 0 : ad_info.partner_key); + + count = sysfs_emit(buf, "%d\n", + bond_3ad_get_active_agg_info(bond, &ad_info) + ? 0 : ad_info.partner_key); } return count; @@ -576,8 +607,9 @@ static ssize_t bonding_show_ad_partner_mac(struct device *d, if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { struct ad_info ad_info; + if (!bond_3ad_get_active_agg_info(bond, &ad_info)) - count = sprintf(buf, "%pM\n", ad_info.partner_system); + count = sysfs_emit(buf, "%pM\n", ad_info.partner_system); } return count; @@ -602,11 +634,11 @@ static ssize_t bonding_show_queue_id(struct device *d, /* not enough space for another interface_name:queue_id pair */ if ((PAGE_SIZE - res) > 10) res = PAGE_SIZE - 10; - res += sprintf(buf + res, "++more++ "); + res += sysfs_emit_at(buf, res, "++more++ "); break; } - res += sprintf(buf + res, "%s:%d ", - slave->dev->name, slave->queue_id); + res += sysfs_emit_at(buf, res, "%s:%d ", + slave->dev->name, slave->queue_id); } if (res) buf[res-1] = '\n'; /* eat the leftover space */ @@ -626,7 +658,7 @@ static ssize_t bonding_show_slaves_active(struct device *d, { struct bonding *bond = to_bond(d); - return sprintf(buf, "%d\n", bond->params.all_slaves_active); + return sysfs_emit(buf, "%d\n", bond->params.all_slaves_active); } static DEVICE_ATTR(all_slaves_active, 0644, bonding_show_slaves_active, bonding_sysfs_store_option); @@ -638,7 +670,7 @@ static ssize_t bonding_show_resend_igmp(struct device *d, { struct bonding *bond = to_bond(d); - return sprintf(buf, "%d\n", bond->params.resend_igmp); + return sysfs_emit(buf, "%d\n", bond->params.resend_igmp); } static DEVICE_ATTR(resend_igmp, 0644, bonding_show_resend_igmp, bonding_sysfs_store_option); @@ -650,7 +682,7 @@ static ssize_t bonding_show_lp_interval(struct device *d, { struct bonding *bond = to_bond(d); - return sprintf(buf, "%d\n", bond->params.lp_interval); + return sysfs_emit(buf, "%d\n", bond->params.lp_interval); } static DEVICE_ATTR(lp_interval, 0644, bonding_show_lp_interval, bonding_sysfs_store_option); @@ -660,7 +692,8 @@ static ssize_t bonding_show_tlb_dynamic_lb(struct device *d, char *buf) { struct bonding *bond = to_bond(d); - return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb); + + return sysfs_emit(buf, "%d\n", bond->params.tlb_dynamic_lb); } static DEVICE_ATTR(tlb_dynamic_lb, 0644, bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option); @@ -672,7 +705,7 @@ static ssize_t bonding_show_packets_per_slave(struct device *d, struct bonding *bond = to_bond(d); unsigned int packets_per_slave = bond->params.packets_per_slave; - return sprintf(buf, "%u\n", packets_per_slave); + return sysfs_emit(buf, "%u\n", packets_per_slave); } static DEVICE_ATTR(packets_per_slave, 0644, bonding_show_packets_per_slave, bonding_sysfs_store_option); @@ -684,7 +717,7 @@ static ssize_t bonding_show_ad_actor_sys_prio(struct device *d, struct bonding *bond = to_bond(d); if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) - return sprintf(buf, "%hu\n", bond->params.ad_actor_sys_prio); + return sysfs_emit(buf, "%hu\n", bond->params.ad_actor_sys_prio); return 0; } @@ -698,7 +731,7 @@ static ssize_t bonding_show_ad_actor_system(struct device *d, struct bonding *bond = to_bond(d); if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) - return sprintf(buf, "%pM\n", bond->params.ad_actor_system); + return sysfs_emit(buf, "%pM\n", bond->params.ad_actor_system); return 0; } @@ -713,7 +746,7 @@ static ssize_t bonding_show_ad_user_port_key(struct device *d, struct bonding *bond = to_bond(d); if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) - return sprintf(buf, "%hu\n", bond->params.ad_user_port_key); + return sysfs_emit(buf, "%hu\n", bond->params.ad_user_port_key); return 0; } @@ -731,6 +764,7 @@ static struct attribute *per_bond_attrs[] = { &dev_attr_downdelay.attr, &dev_attr_updelay.attr, &dev_attr_peer_notif_delay.attr, + &dev_attr_lacp_active.attr, &dev_attr_lacp_rate.attr, &dev_attr_ad_select.attr, &dev_attr_xmit_hash_policy.attr, @@ -757,6 +791,7 @@ static struct attribute *per_bond_attrs[] = { &dev_attr_ad_actor_sys_prio.attr, &dev_attr_ad_actor_system.attr, &dev_attr_ad_user_port_key.attr, + &dev_attr_arp_missed_max.attr, NULL, }; @@ -789,8 +824,8 @@ int bond_create_sysfs(struct bond_net *bn) */ if (ret == -EEXIST) { /* Is someone being kinky and naming a device bonding_master? */ - if (__dev_get_by_name(bn->net, - class_attr_bonding_masters.attr.name)) + if (netdev_name_in_use(bn->net, + class_attr_bonding_masters.attr.name)) pr_err("network device named %s already exists in sysfs\n", class_attr_bonding_masters.attr.name); ret = 0; |