diff options
Diffstat (limited to 'drivers/net/bonding/bond_procfs.c')
-rw-r--r-- | drivers/net/bonding/bond_procfs.c | 273 |
1 files changed, 273 insertions, 0 deletions
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c new file mode 100644 index 000000000000..c97307ddd1c9 --- /dev/null +++ b/drivers/net/bonding/bond_procfs.c | |||
@@ -0,0 +1,273 @@ | |||
1 | #include <linux/proc_fs.h> | ||
2 | #include <net/net_namespace.h> | ||
3 | #include <net/netns/generic.h> | ||
4 | #include "bonding.h" | ||
5 | |||
6 | |||
7 | static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) | ||
8 | __acquires(RCU) | ||
9 | __acquires(&bond->lock) | ||
10 | { | ||
11 | struct bonding *bond = seq->private; | ||
12 | loff_t off = 0; | ||
13 | struct slave *slave; | ||
14 | int i; | ||
15 | |||
16 | /* make sure the bond won't be taken away */ | ||
17 | rcu_read_lock(); | ||
18 | read_lock(&bond->lock); | ||
19 | |||
20 | if (*pos == 0) | ||
21 | return SEQ_START_TOKEN; | ||
22 | |||
23 | bond_for_each_slave(bond, slave, i) { | ||
24 | if (++off == *pos) | ||
25 | return slave; | ||
26 | } | ||
27 | |||
28 | return NULL; | ||
29 | } | ||
30 | |||
31 | static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos) | ||
32 | { | ||
33 | struct bonding *bond = seq->private; | ||
34 | struct slave *slave = v; | ||
35 | |||
36 | ++*pos; | ||
37 | if (v == SEQ_START_TOKEN) | ||
38 | return bond->first_slave; | ||
39 | |||
40 | slave = slave->next; | ||
41 | |||
42 | return (slave == bond->first_slave) ? NULL : slave; | ||
43 | } | ||
44 | |||
45 | static void bond_info_seq_stop(struct seq_file *seq, void *v) | ||
46 | __releases(&bond->lock) | ||
47 | __releases(RCU) | ||
48 | { | ||
49 | struct bonding *bond = seq->private; | ||
50 | |||
51 | read_unlock(&bond->lock); | ||
52 | rcu_read_unlock(); | ||
53 | } | ||
54 | |||
55 | static void bond_info_show_master(struct seq_file *seq) | ||
56 | { | ||
57 | struct bonding *bond = seq->private; | ||
58 | struct slave *curr; | ||
59 | int i; | ||
60 | |||
61 | read_lock(&bond->curr_slave_lock); | ||
62 | curr = bond->curr_active_slave; | ||
63 | read_unlock(&bond->curr_slave_lock); | ||
64 | |||
65 | seq_printf(seq, "Bonding Mode: %s", | ||
66 | bond_mode_name(bond->params.mode)); | ||
67 | |||
68 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP && | ||
69 | bond->params.fail_over_mac) | ||
70 | seq_printf(seq, " (fail_over_mac %s)", | ||
71 | fail_over_mac_tbl[bond->params.fail_over_mac].modename); | ||
72 | |||
73 | seq_printf(seq, "\n"); | ||
74 | |||
75 | if (bond->params.mode == BOND_MODE_XOR || | ||
76 | bond->params.mode == BOND_MODE_8023AD) { | ||
77 | seq_printf(seq, "Transmit Hash Policy: %s (%d)\n", | ||
78 | xmit_hashtype_tbl[bond->params.xmit_policy].modename, | ||
79 | bond->params.xmit_policy); | ||
80 | } | ||
81 | |||
82 | if (USES_PRIMARY(bond->params.mode)) { | ||
83 | seq_printf(seq, "Primary Slave: %s", | ||
84 | (bond->primary_slave) ? | ||
85 | bond->primary_slave->dev->name : "None"); | ||
86 | if (bond->primary_slave) | ||
87 | seq_printf(seq, " (primary_reselect %s)", | ||
88 | pri_reselect_tbl[bond->params.primary_reselect].modename); | ||
89 | |||
90 | seq_printf(seq, "\nCurrently Active Slave: %s\n", | ||
91 | (curr) ? curr->dev->name : "None"); | ||
92 | } | ||
93 | |||
94 | seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ? | ||
95 | "up" : "down"); | ||
96 | seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon); | ||
97 | seq_printf(seq, "Up Delay (ms): %d\n", | ||
98 | bond->params.updelay * bond->params.miimon); | ||
99 | seq_printf(seq, "Down Delay (ms): %d\n", | ||
100 | bond->params.downdelay * bond->params.miimon); | ||
101 | |||
102 | |||
103 | /* ARP information */ | ||
104 | if (bond->params.arp_interval > 0) { | ||
105 | int printed = 0; | ||
106 | seq_printf(seq, "ARP Polling Interval (ms): %d\n", | ||
107 | bond->params.arp_interval); | ||
108 | |||
109 | seq_printf(seq, "ARP IP target/s (n.n.n.n form):"); | ||
110 | |||
111 | for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { | ||
112 | if (!bond->params.arp_targets[i]) | ||
113 | break; | ||
114 | if (printed) | ||
115 | seq_printf(seq, ","); | ||
116 | seq_printf(seq, " %pI4", &bond->params.arp_targets[i]); | ||
117 | printed = 1; | ||
118 | } | ||
119 | seq_printf(seq, "\n"); | ||
120 | } | ||
121 | |||
122 | if (bond->params.mode == BOND_MODE_8023AD) { | ||
123 | struct ad_info ad_info; | ||
124 | |||
125 | seq_puts(seq, "\n802.3ad info\n"); | ||
126 | seq_printf(seq, "LACP rate: %s\n", | ||
127 | (bond->params.lacp_fast) ? "fast" : "slow"); | ||
128 | seq_printf(seq, "Aggregator selection policy (ad_select): %s\n", | ||
129 | ad_select_tbl[bond->params.ad_select].modename); | ||
130 | |||
131 | if (bond_3ad_get_active_agg_info(bond, &ad_info)) { | ||
132 | seq_printf(seq, "bond %s has no active aggregator\n", | ||
133 | bond->dev->name); | ||
134 | } else { | ||
135 | seq_printf(seq, "Active Aggregator Info:\n"); | ||
136 | |||
137 | seq_printf(seq, "\tAggregator ID: %d\n", | ||
138 | ad_info.aggregator_id); | ||
139 | seq_printf(seq, "\tNumber of ports: %d\n", | ||
140 | ad_info.ports); | ||
141 | seq_printf(seq, "\tActor Key: %d\n", | ||
142 | ad_info.actor_key); | ||
143 | seq_printf(seq, "\tPartner Key: %d\n", | ||
144 | ad_info.partner_key); | ||
145 | seq_printf(seq, "\tPartner Mac Address: %pM\n", | ||
146 | ad_info.partner_system); | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | |||
151 | static void bond_info_show_slave(struct seq_file *seq, | ||
152 | const struct slave *slave) | ||
153 | { | ||
154 | struct bonding *bond = seq->private; | ||
155 | |||
156 | seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name); | ||
157 | seq_printf(seq, "MII Status: %s\n", | ||
158 | (slave->link == BOND_LINK_UP) ? "up" : "down"); | ||
159 | seq_printf(seq, "Speed: %d Mbps\n", slave->speed); | ||
160 | seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half"); | ||
161 | seq_printf(seq, "Link Failure Count: %u\n", | ||
162 | slave->link_failure_count); | ||
163 | |||
164 | seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr); | ||
165 | |||
166 | if (bond->params.mode == BOND_MODE_8023AD) { | ||
167 | const struct aggregator *agg | ||
168 | = SLAVE_AD_INFO(slave).port.aggregator; | ||
169 | |||
170 | if (agg) | ||
171 | seq_printf(seq, "Aggregator ID: %d\n", | ||
172 | agg->aggregator_identifier); | ||
173 | else | ||
174 | seq_puts(seq, "Aggregator ID: N/A\n"); | ||
175 | } | ||
176 | seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id); | ||
177 | } | ||
178 | |||
179 | static int bond_info_seq_show(struct seq_file *seq, void *v) | ||
180 | { | ||
181 | if (v == SEQ_START_TOKEN) { | ||
182 | seq_printf(seq, "%s\n", bond_version); | ||
183 | bond_info_show_master(seq); | ||
184 | } else | ||
185 | bond_info_show_slave(seq, v); | ||
186 | |||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | static const struct seq_operations bond_info_seq_ops = { | ||
191 | .start = bond_info_seq_start, | ||
192 | .next = bond_info_seq_next, | ||
193 | .stop = bond_info_seq_stop, | ||
194 | .show = bond_info_seq_show, | ||
195 | }; | ||
196 | |||
197 | static int bond_info_open(struct inode *inode, struct file *file) | ||
198 | { | ||
199 | struct seq_file *seq; | ||
200 | struct proc_dir_entry *proc; | ||
201 | int res; | ||
202 | |||
203 | res = seq_open(file, &bond_info_seq_ops); | ||
204 | if (!res) { | ||
205 | /* recover the pointer buried in proc_dir_entry data */ | ||
206 | seq = file->private_data; | ||
207 | proc = PDE(inode); | ||
208 | seq->private = proc->data; | ||
209 | } | ||
210 | |||
211 | return res; | ||
212 | } | ||
213 | |||
214 | static const struct file_operations bond_info_fops = { | ||
215 | .owner = THIS_MODULE, | ||
216 | .open = bond_info_open, | ||
217 | .read = seq_read, | ||
218 | .llseek = seq_lseek, | ||
219 | .release = seq_release, | ||
220 | }; | ||
221 | |||
222 | void bond_create_proc_entry(struct bonding *bond) | ||
223 | { | ||
224 | struct net_device *bond_dev = bond->dev; | ||
225 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); | ||
226 | |||
227 | if (bn->proc_dir) { | ||
228 | bond->proc_entry = proc_create_data(bond_dev->name, | ||
229 | S_IRUGO, bn->proc_dir, | ||
230 | &bond_info_fops, bond); | ||
231 | if (bond->proc_entry == NULL) | ||
232 | pr_warning("Warning: Cannot create /proc/net/%s/%s\n", | ||
233 | DRV_NAME, bond_dev->name); | ||
234 | else | ||
235 | memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ); | ||
236 | } | ||
237 | } | ||
238 | |||
239 | void bond_remove_proc_entry(struct bonding *bond) | ||
240 | { | ||
241 | struct net_device *bond_dev = bond->dev; | ||
242 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); | ||
243 | |||
244 | if (bn->proc_dir && bond->proc_entry) { | ||
245 | remove_proc_entry(bond->proc_file_name, bn->proc_dir); | ||
246 | memset(bond->proc_file_name, 0, IFNAMSIZ); | ||
247 | bond->proc_entry = NULL; | ||
248 | } | ||
249 | } | ||
250 | |||
251 | /* Create the bonding directory under /proc/net, if doesn't exist yet. | ||
252 | * Caller must hold rtnl_lock. | ||
253 | */ | ||
254 | void __net_init bond_create_proc_dir(struct bond_net *bn) | ||
255 | { | ||
256 | if (!bn->proc_dir) { | ||
257 | bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net); | ||
258 | if (!bn->proc_dir) | ||
259 | pr_warning("Warning: cannot create /proc/net/%s\n", | ||
260 | DRV_NAME); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | /* Destroy the bonding directory under /proc/net, if empty. | ||
265 | * Caller must hold rtnl_lock. | ||
266 | */ | ||
267 | void __net_exit bond_destroy_proc_dir(struct bond_net *bn) | ||
268 | { | ||
269 | if (bn->proc_dir) { | ||
270 | remove_proc_entry(DRV_NAME, bn->net->proc_net); | ||
271 | bn->proc_dir = NULL; | ||
272 | } | ||
273 | } | ||