Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netprio_cgroup: allow nesting and inherit config on cgroup creation

Inherit netprio configuration from ->css_online(), allow nesting and
remove .broken_hierarchy marking. This makes netprio_cgroup's
behavior match netcls_cgroup's.

Note that this patch changes userland-visible behavior. Nesting is
allowed and the first level cgroups below the root cgroup behave
differently - they inherit priorities from the root cgroup on creation
instead of starting with 0. This is unfortunate but not doing so is
much crazier.

Signed-off-by: Tejun Heo <tj@kernel.org>
Tested-and-Acked-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
Acked-by: David S. Miller <davem@davemloft.net>

Tejun Heo 811d8d6f 666b0ebe

+26 -18
+2
Documentation/cgroups/net_prio.txt
··· 51 51 traffic to be steered to hardware/driver based traffic classes. These mappings 52 52 can then be managed by administrators or other networking protocols such as 53 53 DCBX. 54 + 55 + A new net_prio cgroup inherits the parent's configuration.
+24 -18
net/core/netprio_cgroup.c
··· 136 136 { 137 137 struct cgroup_netprio_state *cs; 138 138 139 - if (cgrp->parent && cgrp->parent->id) 140 - return ERR_PTR(-EINVAL); 141 - 142 139 cs = kzalloc(sizeof(*cs), GFP_KERNEL); 143 140 if (!cs) 144 141 return ERR_PTR(-ENOMEM); ··· 143 146 return &cs->css; 144 147 } 145 148 146 - static void cgrp_css_free(struct cgroup *cgrp) 149 + static int cgrp_css_online(struct cgroup *cgrp) 147 150 { 148 - struct cgroup_netprio_state *cs = cgrp_netprio_state(cgrp); 151 + struct cgroup *parent = cgrp->parent; 149 152 struct net_device *dev; 153 + int ret = 0; 154 + 155 + if (!parent) 156 + return 0; 150 157 151 158 rtnl_lock(); 152 - for_each_netdev(&init_net, dev) 153 - WARN_ON_ONCE(netprio_set_prio(cgrp, dev, 0)); 159 + /* 160 + * Inherit prios from the parent. As all prios are set during 161 + * onlining, there is no need to clear them on offline. 162 + */ 163 + for_each_netdev(&init_net, dev) { 164 + u32 prio = netprio_prio(parent, dev); 165 + 166 + ret = netprio_set_prio(cgrp, dev, prio); 167 + if (ret) 168 + break; 169 + } 154 170 rtnl_unlock(); 155 - kfree(cs); 171 + return ret; 172 + } 173 + 174 + static void cgrp_css_free(struct cgroup *cgrp) 175 + { 176 + kfree(cgrp_netprio_state(cgrp)); 156 177 } 157 178 158 179 static u64 read_prioidx(struct cgroup *cgrp, struct cftype *cft) ··· 252 237 struct cgroup_subsys net_prio_subsys = { 253 238 .name = "net_prio", 254 239 .css_alloc = cgrp_css_alloc, 240 + .css_online = cgrp_css_online, 255 241 .css_free = cgrp_css_free, 256 242 .attach = net_prio_attach, 257 243 .subsys_id = net_prio_subsys_id, 258 244 .base_cftypes = ss_files, 259 245 .module = THIS_MODULE, 260 - 261 - /* 262 - * net_prio has artificial limit on the number of cgroups and 263 - * disallows nesting making it impossible to co-mount it with other 264 - * hierarchical subsystems. Remove the artificially low PRIOIDX_SZ 265 - * limit and properly nest configuration such that children follow 266 - * their parents' configurations by default and are allowed to 267 - * override and remove the following. 268 - */ 269 - .broken_hierarchy = true, 270 246 }; 271 247 272 248 static int netprio_device_event(struct notifier_block *unused,