From: Neil Horman <nhorman@tuxdriver.com>
To: netdev@vger.kernel.org
Cc: Neil Horman <nhorman@tuxdriver.com>,
Thomas Graf <tgraf@infradead.org>,
"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 3/4] net: use cgroup_attach method to migrate socket priotiy and classid
Date: Wed, 21 Dec 2011 09:39:49 -0500 [thread overview]
Message-ID: <1324478390-22036-4-git-send-email-nhorman@tuxdriver.com> (raw)
In-Reply-To: <1324478390-22036-1-git-send-email-nhorman@tuxdriver.com>
Now that we have an owner identified for each socket, we can use the
cgroup_attach method to migrate sockets owned by migrating tasks to their new
cgroup instances.
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
CC: Thomas Graf <tgraf@infradead.org>
CC: "David S. Miller" <davem@davemloft.net>
---
net/core/netprio_cgroup.c | 40 +++++++++++++++++++++++++++++++++++++++-
net/sched/cls_cgroup.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 1 deletions(-)
diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c
index 3a9fd48..32eef0f 100644
--- a/net/core/netprio_cgroup.c
+++ b/net/core/netprio_cgroup.c
@@ -18,6 +18,7 @@
#include <linux/cgroup.h>
#include <linux/rcupdate.h>
#include <linux/atomic.h>
+#include <linux/fdtable.h>
#include <net/rtnetlink.h>
#include <net/pkt_cls.h>
#include <net/sock.h>
@@ -27,12 +28,14 @@ static struct cgroup_subsys_state *cgrp_create(struct cgroup_subsys *ss,
struct cgroup *cgrp);
static void cgrp_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp);
static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp);
-
+static void cgrp_attach(struct cgroup_subsys *ss, struct cgroup *cgrp,
+ struct cgroup *old_cgrp, struct task_struct *tsk);
struct cgroup_subsys net_prio_subsys = {
.name = "net_prio",
.create = cgrp_create,
.destroy = cgrp_destroy,
.populate = cgrp_populate,
+ .attach = cgrp_attach,
#ifdef CONFIG_NETPRIO_CGROUP
.subsys_id = net_prio_subsys_id,
#endif
@@ -265,6 +268,41 @@ static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)
return cgroup_add_files(cgrp, ss, ss_files, ARRAY_SIZE(ss_files));
}
+static void cgrp_attach(struct cgroup_subsys *ss, struct cgroup *cgrp,
+ struct cgroup *old_cgrp, struct task_struct *tsk)
+{
+ int fd, err;
+ struct files_struct *files;
+ struct file *file;
+ struct socket *sock;
+ struct cgroup_netprio_state *old, *new;
+ pid_t task_pid;
+
+ files = get_files_struct(tsk);
+ task_pid = task_pid_nr(tsk);
+
+ old = cgrp_netprio_state(old_cgrp);
+ new = cgrp_netprio_state(cgrp);
+
+ spin_lock(&files->file_lock);
+ for (fd=0; fd < files_fdtable(files)->max_fds; fd++) {
+ file = fcheck_files(files, fd);
+ if (!file)
+ continue;
+ sock = sock_from_file(file, &err);
+ if (!sock)
+ continue;
+ if (!sock->sk)
+ continue;
+ if (sock->sk->sk_cgrp_owner == task_pid)
+ sock->sk->sk_cgrp_prioidx = new->prioidx;
+ }
+ spin_unlock(&files->file_lock);
+
+ put_files_struct(files);
+}
+
+
static int netprio_device_event(struct notifier_block *unused,
unsigned long event, void *ptr)
{
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index f84fdc3..7020cda 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -17,6 +17,7 @@
#include <linux/skbuff.h>
#include <linux/cgroup.h>
#include <linux/rcupdate.h>
+#include <linux/fdtable.h>
#include <net/rtnetlink.h>
#include <net/pkt_cls.h>
#include <net/sock.h>
@@ -26,12 +27,15 @@ static struct cgroup_subsys_state *cgrp_create(struct cgroup_subsys *ss,
struct cgroup *cgrp);
static void cgrp_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp);
static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp);
+static void cgrp_attach(struct cgroup_subsys *ss, struct cgroup *cgrp,
+ struct cgroup *old_cgrp, struct task_struct *tsk);
struct cgroup_subsys net_cls_subsys = {
.name = "net_cls",
.create = cgrp_create,
.destroy = cgrp_destroy,
.populate = cgrp_populate,
+ .attach = cgrp_attach,
#ifdef CONFIG_NET_CLS_CGROUP
.subsys_id = net_cls_subsys_id,
#endif
@@ -95,6 +99,41 @@ static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)
return cgroup_add_files(cgrp, ss, ss_files, ARRAY_SIZE(ss_files));
}
+static void cgrp_attach(struct cgroup_subsys *ss, struct cgroup *cgrp,
+ struct cgroup *old_cgrp, struct task_struct *tsk)
+{
+ int fd, err;
+ struct files_struct *files;
+ struct file *file;
+ struct socket *sock;
+ struct cgroup_cls_state *old, *new;
+ pid_t task_pid;
+
+ files = get_files_struct(tsk);
+ task_pid = task_pid_nr(tsk);
+
+ old = cgrp_cls_state(old_cgrp);
+ new = cgrp_cls_state(cgrp);
+
+ spin_lock(&files->file_lock);
+ for (fd=0; fd < files_fdtable(files)->max_fds; fd++) {
+ file = fcheck_files(files, fd);
+ if (!file)
+ continue;
+ sock = sock_from_file(file, &err);
+ if (!sock)
+ continue;
+ if (!sock->sk)
+ continue;
+ if (sock->sk->sk_cgrp_owner == task_pid)
+ sock->sk->sk_classid = new->classid;
+ }
+ spin_unlock(&files->file_lock);
+
+ put_files_struct(files);
+}
+
+
struct cls_cgroup_head {
u32 handle;
struct tcf_exts exts;
--
1.7.6.4
next prev parent reply other threads:[~2011-12-21 14:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-21 14:39 [PATCH 0/4] net: Improve socket sharing between multiple cgroups Neil Horman
2011-12-21 14:39 ` [PATCH 1/4] net_prio/classid: add cgroup process ownership filter Neil Horman
2011-12-21 14:39 ` [PATCH 2/4] vfs: Export some file manipulation functions Neil Horman
2011-12-21 15:30 ` Christoph Hellwig
2011-12-21 16:42 ` Neil Horman
2011-12-21 14:39 ` Neil Horman [this message]
2011-12-21 15:40 ` [PATCH 3/4] net: use cgroup_attach method to migrate socket priotiy and classid Al Viro
2011-12-21 14:39 ` [PATCH 4/4] net: remove no-longer needed calls to sock_update_[classid|netprioix] Neil Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1324478390-22036-4-git-send-email-nhorman@tuxdriver.com \
--to=nhorman@tuxdriver.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=tgraf@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).