aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2012-08-21 22:32:06 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2012-09-26 21:09:59 -0400
commitc3c073f808b22dfae15ef8412b6f7b998644139a (patch)
tree3369bcbe414738d90e6ccfe257f6ce3e72f6a5ae /net/core
parentad47bd7252bf402fe7dba92f5240b5ed16832ae7 (diff)
new helper: iterate_fd()
iterates through the opened files in given descriptor table, calling a supplied function; we stop once non-zero is returned. Callback gets struct file *, descriptor number and const void * argument passed to iterator. It is called with files->file_lock held, so it is not allowed to block. tty_io, netprio_cgroup and selinux flush_unauthorized_files() converted to its use. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/netprio_cgroup.c38
1 files changed, 12 insertions, 26 deletions
diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c
index c75e3f9d060f..5ffd084c6a83 100644
--- a/net/core/netprio_cgroup.c
+++ b/net/core/netprio_cgroup.c
@@ -272,38 +272,24 @@ out_free_devname:
272 return ret; 272 return ret;
273} 273}
274 274
275static int update_netprio(const void *v, struct file *file, unsigned n)
276{
277 int err;
278 struct socket *sock = sock_from_file(file, &err);
279 if (sock)
280 sock->sk->sk_cgrp_prioidx = (u32)(unsigned long)v;
281 return 0;
282}
283
275void net_prio_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) 284void net_prio_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
276{ 285{
277 struct task_struct *p; 286 struct task_struct *p;
287 void *v;
278 288
279 cgroup_taskset_for_each(p, cgrp, tset) { 289 cgroup_taskset_for_each(p, cgrp, tset) {
280 unsigned int fd;
281 struct fdtable *fdt;
282 struct files_struct *files;
283
284 task_lock(p); 290 task_lock(p);
285 files = p->files; 291 v = (void *)(unsigned long)task_netprioidx(p);
286 if (!files) { 292 iterate_fd(p->files, 0, update_netprio, v);
287 task_unlock(p);
288 continue;
289 }
290
291 spin_lock(&files->file_lock);
292 fdt = files_fdtable(files);
293 for (fd = 0; fd < fdt->max_fds; fd++) {
294 struct file *file;
295 struct socket *sock;
296 int err;
297
298 file = fcheck_files(files, fd);
299 if (!file)
300 continue;
301
302 sock = sock_from_file(file, &err);
303 if (sock)
304 sock_update_netprioidx(sock->sk, p);
305 }
306 spin_unlock(&files->file_lock);
307 task_unlock(p); 293 task_unlock(p);
308 } 294 }
309} 295}