aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2012-10-25 00:16:59 -0400
committerDavid S. Miller <davem@davemloft.net>2012-10-26 03:40:51 -0400
commit6a328d8c6f03501657ad580f6f98bf9a42583ff7 (patch)
treee2740717dd3233a1078872e48a7b159e71e6102b
parentfd9a08a7b83074e34c13c6340f673f7a51f53489 (diff)
cgroup: net_cls: Rework update socket logic
The cgroup logic part of net_cls is very similar as the one in net_prio. Let's stream line the net_cls logic with the net_prio one. The net_prio update logic was changed by following commit (note there were some changes necessary later on) commit 406a3c638ce8b17d9704052c07955490f732c2b8 Author: John Fastabend <john.r.fastabend@intel.com> Date: Fri Jul 20 10:39:25 2012 +0000 net: netprio_cgroup: rework update socket logic Instead of updating the sk_cgrp_prioidx struct field on every send this only updates the field when a task is moved via cgroup infrastructure. This allows sockets that may be used by a kernel worker thread to be managed. For example in the iscsi case today a user can put iscsid in a netprio cgroup and control traffic will be sent with the correct sk_cgrp_prioidx value set but as soon as data is sent the kernel worker thread isssues a send and sk_cgrp_prioidx is updated with the kernel worker threads value which is the default case. It seems more correct to only update the field when the user explicitly sets it via control group infrastructure. This allows the users to manage sockets that may be used with other threads. Since classid is now updated when the task is moved between the cgroups, we don't have to call sock_update_classid() from various places to ensure we always using the latest classid value. [v2: Use iterate_fd() instead of open coding] Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de> Cc: Li Zefan <lizefan@huawei.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Jamal Hadi Salim <jhs@mojatatu.com> Cc: Joe Perches <joe@perches.com> Cc: John Fastabend <john.r.fastabend@intel.com> Cc: Neil Horman <nhorman@tuxdriver.com> Cc: Stanislav Kinsbursky <skinsbursky@parallels.com> Cc: Tejun Heo <tj@kernel.org> Cc: <netdev@vger.kernel.org> Cc: <cgroups@vger.kernel.org> Acked-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/tun.c3
-rw-r--r--net/sched/cls_cgroup.c24
-rw-r--r--net/socket.c8
3 files changed, 24 insertions, 11 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index e4858b20bf11..315751965f35 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -68,7 +68,6 @@
68#include <net/netns/generic.h> 68#include <net/netns/generic.h>
69#include <net/rtnetlink.h> 69#include <net/rtnetlink.h>
70#include <net/sock.h> 70#include <net/sock.h>
71#include <net/cls_cgroup.h>
72 71
73#include <asm/uaccess.h> 72#include <asm/uaccess.h>
74 73
@@ -587,8 +586,6 @@ static struct sk_buff *tun_alloc_skb(struct tun_struct *tun,
587 struct sk_buff *skb; 586 struct sk_buff *skb;
588 int err; 587 int err;
589 588
590 sock_update_classid(sk, current);
591
592 /* Under a page? Don't bother with paged skb. */ 589 /* Under a page? Don't bother with paged skb. */
593 if (prepad + len < PAGE_SIZE || !linear) 590 if (prepad + len < PAGE_SIZE || !linear)
594 linear = len; 591 linear = len;
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 2ecde225ae60..709b0fb38a18 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -17,6 +17,7 @@
17#include <linux/skbuff.h> 17#include <linux/skbuff.h>
18#include <linux/cgroup.h> 18#include <linux/cgroup.h>
19#include <linux/rcupdate.h> 19#include <linux/rcupdate.h>
20#include <linux/fdtable.h>
20#include <net/rtnetlink.h> 21#include <net/rtnetlink.h>
21#include <net/pkt_cls.h> 22#include <net/pkt_cls.h>
22#include <net/sock.h> 23#include <net/sock.h>
@@ -53,6 +54,28 @@ static void cgrp_destroy(struct cgroup *cgrp)
53 kfree(cgrp_cls_state(cgrp)); 54 kfree(cgrp_cls_state(cgrp));
54} 55}
55 56
57static int update_classid(const void *v, struct file *file, unsigned n)
58{
59 int err;
60 struct socket *sock = sock_from_file(file, &err);
61 if (sock)
62 sock->sk->sk_classid = (u32)(unsigned long)v;
63 return 0;
64}
65
66static void cgrp_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
67{
68 struct task_struct *p;
69 void *v;
70
71 cgroup_taskset_for_each(p, cgrp, tset) {
72 task_lock(p);
73 v = (void *)(unsigned long)task_cls_classid(p);
74 iterate_fd(p->files, 0, update_classid, v);
75 task_unlock(p);
76 }
77}
78
56static u64 read_classid(struct cgroup *cgrp, struct cftype *cft) 79static u64 read_classid(struct cgroup *cgrp, struct cftype *cft)
57{ 80{
58 return cgrp_cls_state(cgrp)->classid; 81 return cgrp_cls_state(cgrp)->classid;
@@ -77,6 +100,7 @@ struct cgroup_subsys net_cls_subsys = {
77 .name = "net_cls", 100 .name = "net_cls",
78 .create = cgrp_create, 101 .create = cgrp_create,
79 .destroy = cgrp_destroy, 102 .destroy = cgrp_destroy,
103 .attach = cgrp_attach,
80 .subsys_id = net_cls_subsys_id, 104 .subsys_id = net_cls_subsys_id,
81 .base_cftypes = ss_files, 105 .base_cftypes = ss_files,
82 .module = THIS_MODULE, 106 .module = THIS_MODULE,
diff --git a/net/socket.c b/net/socket.c
index f1a481ab7532..2ca51c719ef9 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -620,8 +620,6 @@ static inline int __sock_sendmsg_nosec(struct kiocb *iocb, struct socket *sock,
620{ 620{
621 struct sock_iocb *si = kiocb_to_siocb(iocb); 621 struct sock_iocb *si = kiocb_to_siocb(iocb);
622 622
623 sock_update_classid(sock->sk, current);
624
625 si->sock = sock; 623 si->sock = sock;
626 si->scm = NULL; 624 si->scm = NULL;
627 si->msg = msg; 625 si->msg = msg;
@@ -784,8 +782,6 @@ static inline int __sock_recvmsg_nosec(struct kiocb *iocb, struct socket *sock,
784{ 782{
785 struct sock_iocb *si = kiocb_to_siocb(iocb); 783 struct sock_iocb *si = kiocb_to_siocb(iocb);
786 784
787 sock_update_classid(sock->sk, current);
788
789 si->sock = sock; 785 si->sock = sock;
790 si->scm = NULL; 786 si->scm = NULL;
791 si->msg = msg; 787 si->msg = msg;
@@ -896,8 +892,6 @@ static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
896 if (unlikely(!sock->ops->splice_read)) 892 if (unlikely(!sock->ops->splice_read))
897 return -EINVAL; 893 return -EINVAL;
898 894
899 sock_update_classid(sock->sk, current);
900
901 return sock->ops->splice_read(sock, ppos, pipe, len, flags); 895 return sock->ops->splice_read(sock, ppos, pipe, len, flags);
902} 896}
903 897
@@ -3437,8 +3431,6 @@ EXPORT_SYMBOL(kernel_setsockopt);
3437int kernel_sendpage(struct socket *sock, struct page *page, int offset, 3431int kernel_sendpage(struct socket *sock, struct page *page, int offset,
3438 size_t size, int flags) 3432 size_t size, int flags)
3439{ 3433{
3440 sock_update_classid(sock->sk, current);
3441
3442 if (sock->ops->sendpage) 3434 if (sock->ops->sendpage)
3443 return sock->ops->sendpage(sock, page, offset, size, flags); 3435 return sock->ops->sendpage(sock, page, offset, size, flags);
3444 3436