Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 315786
b: refs/heads/master
c: 406a3c6
h: refs/heads/master
v: v3
  • Loading branch information
John Fastabend authored and David S. Miller committed Jul 22, 2012
1 parent dcfa304 commit 69f1009
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 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: 0690899b4d4501b3505be069b9a687e68ccbe15b
refs/heads/master: 406a3c638ce8b17d9704052c07955490f732c2b8
1 change: 1 addition & 0 deletions trunk/include/linux/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ extern int sock_recvmsg(struct socket *sock, struct msghdr *msg,
size_t size, int flags);
extern int sock_map_fd(struct socket *sock, int flags);
extern struct socket *sockfd_lookup(int fd, int *err);
extern struct socket *sock_from_file(struct file *file, int *err);
#define sockfd_put(sock) fput(sock->file)
extern int net_ratelimit(void);

Expand Down
4 changes: 2 additions & 2 deletions trunk/include/net/netprio_cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct cgroup_netprio_state {
extern int net_prio_subsys_id;
#endif

extern void sock_update_netprioidx(struct sock *sk);
extern void sock_update_netprioidx(struct sock *sk, struct task_struct *task);

#if IS_BUILTIN(CONFIG_NETPRIO_CGROUP)

Expand Down Expand Up @@ -82,7 +82,7 @@ static inline u32 task_netprioidx(struct task_struct *p)
#endif /* CONFIG_NETPRIO_CGROUP */

#else
#define sock_update_netprioidx(sk)
#define sock_update_netprioidx(sk, task)
#endif

#endif /* _NET_CLS_CGROUP_H */
53 changes: 53 additions & 0 deletions trunk/net/core/netprio_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <net/sock.h>
#include <net/netprio_cgroup.h>

#include <linux/fdtable.h>

#define PRIOIDX_SZ 128

static unsigned long prioidx_map[PRIOIDX_SZ];
Expand Down Expand Up @@ -272,6 +274,56 @@ static int write_priomap(struct cgroup *cgrp, struct cftype *cft,
return ret;
}

void net_prio_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
{
struct task_struct *p;
char *tmp = kzalloc(sizeof(char) * PATH_MAX, GFP_KERNEL);

if (!tmp) {
pr_warn("Unable to attach cgrp due to alloc failure!\n");
return;
}

cgroup_taskset_for_each(p, cgrp, tset) {
unsigned int fd;
struct fdtable *fdt;
struct files_struct *files;

task_lock(p);
files = p->files;
if (!files) {
task_unlock(p);
continue;
}

rcu_read_lock();
fdt = files_fdtable(files);
for (fd = 0; fd < fdt->max_fds; fd++) {
char *path;
struct file *file;
struct socket *sock;
unsigned long s;
int rv, err = 0;

file = fcheck_files(files, fd);
if (!file)
continue;

path = d_path(&file->f_path, tmp, PAGE_SIZE);
rv = sscanf(path, "socket:[%lu]", &s);
if (rv <= 0)
continue;

sock = sock_from_file(file, &err);
if (!err)
sock_update_netprioidx(sock->sk, p);
}
rcu_read_unlock();
task_unlock(p);
}
kfree(tmp);
}

static struct cftype ss_files[] = {
{
.name = "prioidx",
Expand All @@ -289,6 +341,7 @@ struct cgroup_subsys net_prio_subsys = {
.name = "net_prio",
.create = cgrp_create,
.destroy = cgrp_destroy,
.attach = net_prio_attach,
#ifdef CONFIG_NETPRIO_CGROUP
.subsys_id = net_prio_subsys_id,
#endif
Expand Down
6 changes: 3 additions & 3 deletions trunk/net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1180,12 +1180,12 @@ void sock_update_classid(struct sock *sk)
}
EXPORT_SYMBOL(sock_update_classid);

void sock_update_netprioidx(struct sock *sk)
void sock_update_netprioidx(struct sock *sk, struct task_struct *task)
{
if (in_interrupt())
return;

sk->sk_cgrp_prioidx = task_netprioidx(current);
sk->sk_cgrp_prioidx = task_netprioidx(task);
}
EXPORT_SYMBOL_GPL(sock_update_netprioidx);
#endif
Expand Down Expand Up @@ -1215,7 +1215,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
atomic_set(&sk->sk_wmem_alloc, 1);

sock_update_classid(sk);
sock_update_netprioidx(sk);
sock_update_netprioidx(sk, current);
}

return sk;
Expand Down
5 changes: 2 additions & 3 deletions trunk/net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,15 @@ int sock_map_fd(struct socket *sock, int flags)
}
EXPORT_SYMBOL(sock_map_fd);

static struct socket *sock_from_file(struct file *file, int *err)
struct socket *sock_from_file(struct file *file, int *err)
{
if (file->f_op == &socket_file_ops)
return file->private_data; /* set in sock_map_fd */

*err = -ENOTSOCK;
return NULL;
}
EXPORT_SYMBOL(sock_from_file);

/**
* sockfd_lookup - Go from a file number to its socket slot
Expand Down Expand Up @@ -554,8 +555,6 @@ static inline int __sock_sendmsg_nosec(struct kiocb *iocb, struct socket *sock,

sock_update_classid(sock->sk);

sock_update_netprioidx(sock->sk);

si->sock = sock;
si->scm = NULL;
si->msg = msg;
Expand Down

0 comments on commit 69f1009

Please sign in to comment.