Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 312026
b: refs/heads/master
c: ef209f1
h: refs/heads/master
v: v3
  • Loading branch information
Gao feng authored and David S. Miller committed Jul 17, 2012
1 parent 67bee39 commit e455a05
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 18 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: 936597631dd310e220544dc5c6075d924efd39b2
refs/heads/master: ef209f15980360f6945873df3cd710c5f62f2a3e
71 changes: 54 additions & 17 deletions trunk/net/core/netprio_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void put_prioidx(u32 idx)
spin_unlock_irqrestore(&prioidx_map_lock, flags);
}

static void extend_netdev_table(struct net_device *dev, u32 new_len)
static int extend_netdev_table(struct net_device *dev, u32 new_len)
{
size_t new_size = sizeof(struct netprio_map) +
((sizeof(u32) * new_len));
Expand All @@ -77,7 +77,7 @@ static void extend_netdev_table(struct net_device *dev, u32 new_len)

if (!new_priomap) {
pr_warn("Unable to alloc new priomap!\n");
return;
return -ENOMEM;
}

for (i = 0;
Expand All @@ -90,46 +90,79 @@ static void extend_netdev_table(struct net_device *dev, u32 new_len)
rcu_assign_pointer(dev->priomap, new_priomap);
if (old_priomap)
kfree_rcu(old_priomap, rcu);
return 0;
}

static void update_netdev_tables(void)
static int write_update_netdev_table(struct net_device *dev)
{
int ret = 0;
u32 max_len;
struct netprio_map *map;

rtnl_lock();
max_len = atomic_read(&max_prioidx) + 1;
map = rtnl_dereference(dev->priomap);
if (!map || map->priomap_len < max_len)
ret = extend_netdev_table(dev, max_len);
rtnl_unlock();

return ret;
}

static int update_netdev_tables(void)
{
int ret = 0;
struct net_device *dev;
u32 max_len = atomic_read(&max_prioidx) + 1;
u32 max_len;
struct netprio_map *map;

rtnl_lock();
max_len = atomic_read(&max_prioidx) + 1;
for_each_netdev(&init_net, dev) {
map = rtnl_dereference(dev->priomap);
if ((!map) ||
(map->priomap_len < max_len))
extend_netdev_table(dev, max_len);
/*
* don't allocate priomap if we didn't
* change net_prio.ifpriomap (map == NULL),
* this will speed up skb_update_prio.
*/
if (map && map->priomap_len < max_len) {
ret = extend_netdev_table(dev, max_len);
if (ret < 0)
break;
}
}
rtnl_unlock();
return ret;
}

static struct cgroup_subsys_state *cgrp_create(struct cgroup *cgrp)
{
struct cgroup_netprio_state *cs;
int ret;
int ret = -EINVAL;

cs = kzalloc(sizeof(*cs), GFP_KERNEL);
if (!cs)
return ERR_PTR(-ENOMEM);

if (cgrp->parent && cgrp_netprio_state(cgrp->parent)->prioidx) {
kfree(cs);
return ERR_PTR(-EINVAL);
}
if (cgrp->parent && cgrp_netprio_state(cgrp->parent)->prioidx)
goto out;

ret = get_prioidx(&cs->prioidx);
if (ret != 0) {
if (ret < 0) {
pr_warn("No space in priority index array\n");
kfree(cs);
return ERR_PTR(ret);
goto out;
}

ret = update_netdev_tables();
if (ret < 0) {
put_prioidx(cs->prioidx);
goto out;
}

return &cs->css;
out:
kfree(cs);
return ERR_PTR(ret);
}

static void cgrp_destroy(struct cgroup *cgrp)
Expand Down Expand Up @@ -221,13 +254,17 @@ static int write_priomap(struct cgroup *cgrp, struct cftype *cft,
if (!dev)
goto out_free_devname;

update_netdev_tables();
ret = 0;
ret = write_update_netdev_table(dev);
if (ret < 0)
goto out_put_dev;

rcu_read_lock();
map = rcu_dereference(dev->priomap);
if (map)
map->priomap[prioidx] = priority;
rcu_read_unlock();

out_put_dev:
dev_put(dev);

out_free_devname:
Expand Down

0 comments on commit e455a05

Please sign in to comment.