mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: daniel.wagner@bmw-carit.de, serge.hallyn@canonical.com,
	ebiederm@xmission.com, nhorman@tuxdriver.com, tgraf@suug.ch
Cc: davem@davemloft.net, lizefan@huawei.com, cgroups@vger.kernel.org,
	containers@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>
Subject: [PATCH 1/3] netcls_cgroup: introduce netcls_mutex
Date: Fri, 16 Nov 2012 19:31:00 -0800	[thread overview]
Message-ID: <1353123062-23193-2-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1353123062-23193-1-git-send-email-tj@kernel.org>

Introduce netcls_mutex to synchronize modifications to
cgroup_cls_state.  New cgrp now inherits classid from ->css_online()
and write_classid() updates classid while holdin netcls_mutex.

As write_classid() doesn't propagate new configuration downwards, this
currently doesn't make any userland-visible difference, but will help
implementing proper hierarchy support.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 net/sched/cls_cgroup.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 8cdc18e..80a80c4 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -17,11 +17,14 @@
 #include <linux/skbuff.h>
 #include <linux/cgroup.h>
 #include <linux/rcupdate.h>
+#include <linux/mutex.h>
 #include <net/rtnetlink.h>
 #include <net/pkt_cls.h>
 #include <net/sock.h>
 #include <net/cls_cgroup.h>
 
+static DEFINE_MUTEX(netcls_mutex);
+
 static inline struct cgroup_cls_state *cgrp_cls_state(struct cgroup *cgrp)
 {
 	return container_of(cgroup_subsys_state(cgrp, net_cls_subsys_id),
@@ -42,12 +45,21 @@ static struct cgroup_subsys_state *cgrp_css_alloc(struct cgroup *cgrp)
 	if (!cs)
 		return ERR_PTR(-ENOMEM);
 
-	if (cgrp->parent)
-		cs->classid = cgrp_cls_state(cgrp->parent)->classid;
-
 	return &cs->css;
 }
 
+/* @cgrp coming online, inherit the parent's classid */
+static int cgrp_css_online(struct cgroup *cgrp)
+{
+	if (!cgrp->parent)
+		return 0;
+
+	mutex_lock(&netcls_mutex);
+	cgrp_cls_state(cgrp)->classid = cgrp_cls_state(cgrp->parent)->classid;
+	mutex_unlock(&netcls_mutex);
+	return 0;
+}
+
 static void cgrp_css_free(struct cgroup *cgrp)
 {
 	kfree(cgrp_cls_state(cgrp));
@@ -60,7 +72,9 @@ static u64 read_classid(struct cgroup *cgrp, struct cftype *cft)
 
 static int write_classid(struct cgroup *cgrp, struct cftype *cft, u64 value)
 {
+	mutex_lock(&netcls_mutex);
 	cgrp_cls_state(cgrp)->classid = (u32) value;
+	mutex_unlock(&netcls_mutex);
 	return 0;
 }
 
@@ -76,6 +90,7 @@ static struct cftype ss_files[] = {
 struct cgroup_subsys net_cls_subsys = {
 	.name		= "net_cls",
 	.css_alloc	= cgrp_css_alloc,
+	.css_online	= cgrp_css_online,
 	.css_free	= cgrp_css_free,
 	.subsys_id	= net_cls_subsys_id,
 	.base_cftypes	= ss_files,
-- 
1.7.11.7


  reply	other threads:[~2012-11-17  3:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-17  3:30 [PATCHSET cgroup/for-3.8] netcls_cgroup: implement hierarchy support Tejun Heo
2012-11-17  3:31 ` Tejun Heo [this message]
2012-11-19 14:01   ` [PATCH 1/3] netcls_cgroup: introduce netcls_mutex Daniel Wagner
2012-11-17  3:31 ` [PATCH 2/3] netcls_cgroup: introduce cgroup_cls_state->is_local Tejun Heo
2012-11-19 12:54   ` Daniel Wagner
2012-11-19 17:30   ` [PATCH v2 " Tejun Heo
2012-11-19 19:18     ` Daniel Wagner
2012-11-17  3:31 ` [PATCH 3/3] netcls_cgroup: implement proper hierarchy support Tejun Heo
2012-11-19 13:47   ` Daniel Wagner
2012-11-19 17:08     ` Tejun Heo
2012-11-19 19:17       ` Daniel Wagner
2012-11-18  3:04 ` [PATCHSET cgroup/for-3.8] netcls_cgroup: implement " David Miller
2012-11-18 14:25   ` Tejun Heo
2012-11-19 13:59 ` Daniel Wagner
2012-11-19 19:01   ` Tejun Heo
2012-11-19 15:07 ` Neil Horman
2012-11-19 19:21 ` Tejun Heo
2012-11-20  5:44   ` Tejun Heo

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=1353123062-23193-2-git-send-email-tj@kernel.org \
    --to=tj@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=containers@lists.linux-foundation.org \
    --cc=daniel.wagner@bmw-carit.de \
    --cc=davem@davemloft.net \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=nhorman@tuxdriver.com \
    --cc=serge.hallyn@canonical.com \
    --cc=tgraf@suug.ch \
    /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

Powered by JetHome