aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsfeldma@cumulusnetworks.com <sfeldma@cumulusnetworks.com>2014-01-17 01:57:49 -0500
committerDavid S. Miller <davem@davemloft.net>2014-01-17 21:51:58 -0500
commit07699f9a7c8d1002e07011d5aa382cd63241eea8 (patch)
tree3fb131944eee1d84e4bb41fa9a6b9c2cf098e5a4
parentfd27e0d44a893b45832df3cb8e021bd1d773a73f (diff)
bonding: add sysfs /slave dir for bond slave devices.
Add sub-directory under /sys/class/net/<interface>/slave with read-only attributes for slave. Directory only appears when <interface> is a slave. $ tree /sys/class/net/eth2/slave/ /sys/class/net/eth2/slave/ ├── ad_aggregator_id ├── link_failure_count ├── mii_status ├── perm_hwaddr ├── queue_id └── state $ cat /sys/class/net/eth2/slave/* 2 0 up 40:02:10:ef:06:01 0 active Signed-off-by: Scott Feldman <sfeldma@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/bonding/Makefile2
-rw-r--r--drivers/net/bonding/bond_main.c27
-rw-r--r--drivers/net/bonding/bond_procfs.c12
-rw-r--r--drivers/net/bonding/bond_sysfs_slave.c144
-rw-r--r--drivers/net/bonding/bonding.h4
5 files changed, 176 insertions, 13 deletions
diff --git a/drivers/net/bonding/Makefile b/drivers/net/bonding/Makefile
index 5a5d720da929..6f4e80853ed4 100644
--- a/drivers/net/bonding/Makefile
+++ b/drivers/net/bonding/Makefile
@@ -4,7 +4,7 @@
4 4
5obj-$(CONFIG_BONDING) += bonding.o 5obj-$(CONFIG_BONDING) += bonding.o
6 6
7bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o bond_netlink.o bond_options.o 7bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_sysfs_slave.o bond_debugfs.o bond_netlink.o bond_options.o
8 8
9proc-$(CONFIG_PROC_FS) += bond_procfs.o 9proc-$(CONFIG_PROC_FS) += bond_procfs.o
10bonding-objs += $(proc-y) 10bonding-objs += $(proc-y)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index f00dd45b0308..df85cec3e5d9 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -466,6 +466,22 @@ static void bond_update_speed_duplex(struct slave *slave)
466 return; 466 return;
467} 467}
468 468
469const char *bond_slave_link_status(s8 link)
470{
471 switch (link) {
472 case BOND_LINK_UP:
473 return "up";
474 case BOND_LINK_FAIL:
475 return "going down";
476 case BOND_LINK_DOWN:
477 return "down";
478 case BOND_LINK_BACK:
479 return "going back";
480 default:
481 return "unknown";
482 }
483}
484
469/* 485/*
470 * if <dev> supports MII link status reporting, check its link status. 486 * if <dev> supports MII link status reporting, check its link status.
471 * 487 *
@@ -1576,6 +1592,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1576 goto err_unregister; 1592 goto err_unregister;
1577 } 1593 }
1578 1594
1595 res = bond_sysfs_slave_add(new_slave);
1596 if (res) {
1597 pr_debug("Error %d calling bond_sysfs_slave_add\n", res);
1598 goto err_upper_unlink;
1599 }
1600
1579 bond->slave_cnt++; 1601 bond->slave_cnt++;
1580 bond_compute_features(bond); 1602 bond_compute_features(bond);
1581 bond_set_carrier(bond); 1603 bond_set_carrier(bond);
@@ -1595,6 +1617,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1595 return 0; 1617 return 0;
1596 1618
1597/* Undo stages on error */ 1619/* Undo stages on error */
1620err_upper_unlink:
1621 bond_upper_dev_unlink(bond_dev, slave_dev);
1622
1598err_unregister: 1623err_unregister:
1599 netdev_rx_handler_unregister(slave_dev); 1624 netdev_rx_handler_unregister(slave_dev);
1600 1625
@@ -1687,6 +1712,8 @@ static int __bond_release_one(struct net_device *bond_dev,
1687 /* release the slave from its bond */ 1712 /* release the slave from its bond */
1688 bond->slave_cnt--; 1713 bond->slave_cnt--;
1689 1714
1715 bond_sysfs_slave_del(slave);
1716
1690 bond_upper_dev_unlink(bond_dev, slave_dev); 1717 bond_upper_dev_unlink(bond_dev, slave_dev);
1691 /* unregister rx_handler early so bond_handle_frame wouldn't be called 1718 /* unregister rx_handler early so bond_handle_frame wouldn't be called
1692 * for this slave anymore. 1719 * for this slave anymore.
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c
index fb868d6c22da..8515b3442583 100644
--- a/drivers/net/bonding/bond_procfs.c
+++ b/drivers/net/bonding/bond_procfs.c
@@ -159,18 +159,6 @@ static void bond_info_show_master(struct seq_file *seq)
159 } 159 }
160} 160}
161 161
162static const char *bond_slave_link_status(s8 link)
163{
164 static const char * const status[] = {
165 [BOND_LINK_UP] = "up",
166 [BOND_LINK_FAIL] = "going down",
167 [BOND_LINK_DOWN] = "down",
168 [BOND_LINK_BACK] = "going back",
169 };
170
171 return status[link];
172}
173
174static void bond_info_show_slave(struct seq_file *seq, 162static void bond_info_show_slave(struct seq_file *seq,
175 const struct slave *slave) 163 const struct slave *slave)
176{ 164{
diff --git a/drivers/net/bonding/bond_sysfs_slave.c b/drivers/net/bonding/bond_sysfs_slave.c
new file mode 100644
index 000000000000..7cb97de3cf63
--- /dev/null
+++ b/drivers/net/bonding/bond_sysfs_slave.c
@@ -0,0 +1,144 @@
1/* Sysfs attributes of bond slaves
2 *
3 * Copyright (c) 2014 Scott Feldman <sfeldma@cumulusnetworks.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
9 */
10
11#include <linux/capability.h>
12#include <linux/kernel.h>
13#include <linux/netdevice.h>
14
15#include "bonding.h"
16
17struct slave_attribute {
18 struct attribute attr;
19 ssize_t (*show)(struct slave *, char *);
20};
21
22#define SLAVE_ATTR(_name, _mode, _show) \
23const struct slave_attribute slave_attr_##_name = { \
24 .attr = {.name = __stringify(_name), \
25 .mode = _mode }, \
26 .show = _show, \
27};
28#define SLAVE_ATTR_RO(_name) \
29 SLAVE_ATTR(_name, S_IRUGO, _name##_show)
30
31static ssize_t state_show(struct slave *slave, char *buf)
32{
33 switch (bond_slave_state(slave)) {
34 case BOND_STATE_ACTIVE:
35 return sprintf(buf, "active\n");
36 case BOND_STATE_BACKUP:
37 return sprintf(buf, "backup\n");
38 default:
39 return sprintf(buf, "UNKONWN\n");
40 }
41}
42static SLAVE_ATTR_RO(state);
43
44static ssize_t mii_status_show(struct slave *slave, char *buf)
45{
46 return sprintf(buf, "%s\n", bond_slave_link_status(slave->link));
47}
48static SLAVE_ATTR_RO(mii_status);
49
50static ssize_t link_failure_count_show(struct slave *slave, char *buf)
51{
52 return sprintf(buf, "%d\n", slave->link_failure_count);
53}
54static SLAVE_ATTR_RO(link_failure_count);
55
56static ssize_t perm_hwaddr_show(struct slave *slave, char *buf)
57{
58 return sprintf(buf, "%pM\n", slave->perm_hwaddr);
59}
60static SLAVE_ATTR_RO(perm_hwaddr);
61
62static ssize_t queue_id_show(struct slave *slave, char *buf)
63{
64 return sprintf(buf, "%d\n", slave->queue_id);
65}
66static SLAVE_ATTR_RO(queue_id);
67
68static ssize_t ad_aggregator_id_show(struct slave *slave, char *buf)
69{
70 const struct aggregator *agg;
71
72 if (slave->bond->params.mode == BOND_MODE_8023AD) {
73 agg = SLAVE_AD_INFO(slave).port.aggregator;
74 if (agg)
75 return sprintf(buf, "%d\n",
76 agg->aggregator_identifier);
77 }
78
79 return sprintf(buf, "N/A\n");
80}
81static SLAVE_ATTR_RO(ad_aggregator_id);
82
83static const struct slave_attribute *slave_attrs[] = {
84 &slave_attr_state,
85 &slave_attr_mii_status,
86 &slave_attr_link_failure_count,
87 &slave_attr_perm_hwaddr,
88 &slave_attr_queue_id,
89 &slave_attr_ad_aggregator_id,
90 NULL
91};
92
93#define to_slave_attr(_at) container_of(_at, struct slave_attribute, attr)
94#define to_slave(obj) container_of(obj, struct slave, kobj)
95
96static ssize_t slave_show(struct kobject *kobj,
97 struct attribute *attr, char *buf)
98{
99 struct slave_attribute *slave_attr = to_slave_attr(attr);
100 struct slave *slave = to_slave(kobj);
101
102 return slave_attr->show(slave, buf);
103}
104
105const struct sysfs_ops slave_sysfs_ops = {
106 .show = slave_show,
107};
108
109static struct kobj_type slave_ktype = {
110#ifdef CONFIG_SYSFS
111 .sysfs_ops = &slave_sysfs_ops,
112#endif
113};
114
115int bond_sysfs_slave_add(struct slave *slave)
116{
117 const struct slave_attribute **a;
118 int err;
119
120 err = kobject_init_and_add(&slave->kobj, &slave_ktype,
121 &(slave->dev->dev.kobj), "slave");
122 if (err)
123 return err;
124
125 for (a = slave_attrs; *a; ++a) {
126 err = sysfs_create_file(&slave->kobj, &((*a)->attr));
127 if (err) {
128 kobject_del(&slave->kobj);
129 return err;
130 }
131 }
132
133 return 0;
134}
135
136void bond_sysfs_slave_del(struct slave *slave)
137{
138 const struct slave_attribute **a;
139
140 for (a = slave_attrs; *a; ++a)
141 sysfs_remove_file(&slave->kobj, &((*a)->attr));
142
143 kobject_del(&slave->kobj);
144}
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 955dc4839f1d..309757d8482b 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -203,6 +203,7 @@ struct slave {
203#ifdef CONFIG_NET_POLL_CONTROLLER 203#ifdef CONFIG_NET_POLL_CONTROLLER
204 struct netpoll *np; 204 struct netpoll *np;
205#endif 205#endif
206 struct kobject kobj;
206}; 207};
207 208
208/* 209/*
@@ -421,6 +422,8 @@ int bond_create(struct net *net, const char *name);
421int bond_create_sysfs(struct bond_net *net); 422int bond_create_sysfs(struct bond_net *net);
422void bond_destroy_sysfs(struct bond_net *net); 423void bond_destroy_sysfs(struct bond_net *net);
423void bond_prepare_sysfs_group(struct bonding *bond); 424void bond_prepare_sysfs_group(struct bonding *bond);
425int bond_sysfs_slave_add(struct slave *slave);
426void bond_sysfs_slave_del(struct slave *slave);
424int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev); 427int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev);
425int bond_release(struct net_device *bond_dev, struct net_device *slave_dev); 428int bond_release(struct net_device *bond_dev, struct net_device *slave_dev);
426int bond_xmit_hash(struct bonding *bond, struct sk_buff *skb, int count); 429int bond_xmit_hash(struct bonding *bond, struct sk_buff *skb, int count);
@@ -469,6 +472,7 @@ int bond_option_lacp_rate_set(struct bonding *bond, int lacp_rate);
469int bond_option_ad_select_set(struct bonding *bond, int ad_select); 472int bond_option_ad_select_set(struct bonding *bond, int ad_select);
470struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond); 473struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
471struct net_device *bond_option_active_slave_get(struct bonding *bond); 474struct net_device *bond_option_active_slave_get(struct bonding *bond);
475const char *bond_slave_link_status(s8 link);
472 476
473struct bond_net { 477struct bond_net {
474 struct net * net; /* Associated network namespace */ 478 struct net * net; /* Associated network namespace */