Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 266911
b: refs/heads/master
c: f04565d
h: refs/heads/master
i:
  266909: 5fc6836
  266907: f0880fc
  266903: 38b4ddb
  266895: 9c93c63
  266879: da3d851
v: v3
  • Loading branch information
Mihai Maruseac authored and David S. Miller committed Oct 21, 2011
1 parent e8af534 commit e926f25
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 16 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e09eff7fc1c6f011f7bdb304e10d2ceef08c88ab
refs/heads/master: f04565ddf52e401880f8ba51de0dff8ba51c99fd
84 changes: 69 additions & 15 deletions trunk/net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -4093,40 +4093,94 @@ static int dev_ifconf(struct net *net, char __user *arg)
}

#ifdef CONFIG_PROC_FS

#define BUCKET_SPACE (32 - NETDEV_HASHBITS)

struct dev_iter_state {
struct seq_net_private p;
unsigned int pos; /* bucket << BUCKET_SPACE + offset */
};

#define get_bucket(x) ((x) >> BUCKET_SPACE)
#define get_offset(x) ((x) & ((1 << BUCKET_SPACE) - 1))
#define set_bucket_offset(b, o) ((b) << BUCKET_SPACE | (o))

static inline struct net_device *dev_from_same_bucket(struct seq_file *seq)
{
struct dev_iter_state *state = seq->private;
struct net *net = seq_file_net(seq);
struct net_device *dev;
struct hlist_node *p;
struct hlist_head *h;
unsigned int count, bucket, offset;

bucket = get_bucket(state->pos);
offset = get_offset(state->pos);
h = &net->dev_name_head[bucket];
count = 0;
hlist_for_each_entry_rcu(dev, p, h, name_hlist) {
if (count++ == offset) {
state->pos = set_bucket_offset(bucket, count);
return dev;
}
}

return NULL;
}

static inline struct net_device *dev_from_new_bucket(struct seq_file *seq)
{
struct dev_iter_state *state = seq->private;
struct net_device *dev;
unsigned int bucket;

bucket = get_bucket(state->pos);
do {
dev = dev_from_same_bucket(seq);
if (dev)
return dev;

bucket++;
state->pos = set_bucket_offset(bucket, 0);
} while (bucket < NETDEV_HASHENTRIES);

return NULL;
}

/*
* This is invoked by the /proc filesystem handler to display a device
* in detail.
*/
void *dev_seq_start(struct seq_file *seq, loff_t *pos)
__acquires(RCU)
{
struct net *net = seq_file_net(seq);
loff_t off;
struct net_device *dev;
struct dev_iter_state *state = seq->private;

rcu_read_lock();
if (!*pos)
return SEQ_START_TOKEN;

off = 1;
for_each_netdev_rcu(net, dev)
if (off++ == *pos)
return dev;
/* check for end of the hash */
if (state->pos == 0 && *pos > 1)
return NULL;

return NULL;
return dev_from_new_bucket(seq);
}

void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
struct net_device *dev = v;
struct net_device *dev;

++*pos;

if (v == SEQ_START_TOKEN)
dev = first_net_device_rcu(seq_file_net(seq));
else
dev = next_net_device_rcu(dev);
return dev_from_new_bucket(seq);

++*pos;
return dev;
dev = dev_from_same_bucket(seq);
if (dev)
return dev;

return dev_from_new_bucket(seq);
}

void dev_seq_stop(struct seq_file *seq, void *v)
Expand Down Expand Up @@ -4225,7 +4279,7 @@ static const struct seq_operations dev_seq_ops = {
static int dev_seq_open(struct inode *inode, struct file *file)
{
return seq_open_net(inode, file, &dev_seq_ops,
sizeof(struct seq_net_private));
sizeof(struct dev_iter_state));
}

static const struct file_operations dev_seq_fops = {
Expand Down

0 comments on commit e926f25

Please sign in to comment.