Skip to content

Commit f383ced

Browse files
edumazetkuba-moo
authored andcommitted
vlan: use xarray iterator to implement /proc/net/vlan/config
Adopt net->dev_by_index as I did in commit 0e0939c ("net-procfs: use xarray iterator to implement /proc/net/dev") Not only this removes quadratic behavior, it also makes sure an existing vlan device is always visible in the dump, regardless of concurrent net->dev_base_head changes. Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent bed90b0 commit f383ced

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

net/8021q/vlanproc.c

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -163,48 +163,34 @@ void vlan_proc_rem_dev(struct net_device *vlandev)
163163
* The following few functions build the content of /proc/net/vlan/config
164164
*/
165165

166-
/* start read of /proc/net/vlan/config */
167-
static void *vlan_seq_start(struct seq_file *seq, loff_t *pos)
168-
__acquires(rcu)
166+
static void *vlan_seq_from_index(struct seq_file *seq, loff_t *pos)
169167
{
168+
unsigned long ifindex = *pos;
170169
struct net_device *dev;
171-
struct net *net = seq_file_net(seq);
172-
loff_t i = 1;
173-
174-
rcu_read_lock();
175-
if (*pos == 0)
176-
return SEQ_START_TOKEN;
177170

178-
for_each_netdev_rcu(net, dev) {
171+
for_each_netdev_dump(seq_file_net(seq), dev, ifindex) {
179172
if (!is_vlan_dev(dev))
180173
continue;
181-
182-
if (i++ == *pos)
183-
return dev;
174+
*pos = dev->ifindex;
175+
return dev;
184176
}
177+
return NULL;
178+
}
179+
180+
static void *vlan_seq_start(struct seq_file *seq, loff_t *pos)
181+
__acquires(rcu)
182+
{
183+
rcu_read_lock();
184+
if (*pos == 0)
185+
return SEQ_START_TOKEN;
185186

186-
return NULL;
187+
return vlan_seq_from_index(seq, pos);
187188
}
188189

189190
static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
190191
{
191-
struct net_device *dev;
192-
struct net *net = seq_file_net(seq);
193-
194192
++*pos;
195-
196-
dev = v;
197-
if (v == SEQ_START_TOKEN)
198-
dev = net_device_entry(&net->dev_base_head);
199-
200-
for_each_netdev_continue_rcu(net, dev) {
201-
if (!is_vlan_dev(dev))
202-
continue;
203-
204-
return dev;
205-
}
206-
207-
return NULL;
193+
return vlan_seq_from_index(seq, pos);
208194
}
209195

210196
static void vlan_seq_stop(struct seq_file *seq, void *v)

0 commit comments

Comments
 (0)