All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] cls_cgroup: unify classid syntax to tc
@ 2009-06-11  9:05 Minoru Usui
  2009-06-11  9:13 ` David Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Minoru Usui @ 2009-06-11  9:05 UTC (permalink / raw)
  To: containers, netdev; +Cc: tgraf, hadi, jarkao2

cls_cgroup: unify classid syntax to tc

This patch unifies classid syntax of cls_cgroup to tc.
In present implementation of cls_cgroup, classid read/write syntax is different from tc's one.

  tc     1:10
  write  0x10010 (hexadecimal)
  read   65552   (decimal)

-------------------------------------------------
  # echo 0x10010 > /cgroup/net/net_cls.classid
  # cat /cgroup/net/net_cls.classid
  65552
-------------------------------------------------

This is very inconvenient, so I made a patch which enables only tc syntax.
If we don't classify with net_cls.classid, we write 0 to net_cls.classid.
(This behavior is the same as present implementation.)

-------------------------------------------------
  # echo 1:10 > /cgroup/net/net_cls.classid
  # cat /cgroup/net/net_cls.classid
  1:10
  # echo 0 > /cgroup/net/net_cls.classid
  # cat /cgroup/net/net_cls.classid
  0
-------------------------------------------------


Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>

diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index e5becb9..6d87d00 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/string.h>
+#include <linux/ctype.h>
 #include <linux/errno.h>
 #include <linux/skbuff.h>
 #include <linux/cgroup.h>
@@ -55,17 +56,76 @@ static void cgrp_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp)
 	kfree(cgrp_cls_state(cgrp));
 }
 
-static u64 read_classid(struct cgroup *cgrp, struct cftype *cft)
+#define CLS_CGROUP_CLASSID_LEN 16
+
+static ssize_t read_classid(struct cgroup *cgrp, struct cftype *cft,
+				struct file *file, char __user *buf,
+				size_t nbytes, loff_t *ppos)
+{
+	u32 value;
+	char classid[CLS_CGROUP_CLASSID_LEN];
+
+	value = cgrp_cls_state(cgrp)->classid;
+	if (value)
+		sprintf(classid, "%x:%x\n",
+			TC_H_MAJ(value)>>16, TC_H_MIN(value));
+	else
+		strcpy(classid, "0\n");
+
+	return simple_read_from_buffer(buf, nbytes, ppos,
+					classid, strlen(classid));
+}
+
+static int get_tc_classid(u32 *classid, const char *str)
 {
-	return cgrp_cls_state(cgrp)->classid;
+	u32 maj, min;
+	char *p;
+
+	/* check "0" for reset request */
+	if (!strcmp(str, "0")) {
+		*classid = 0;
+		return 0;
+	}
+
+	/* parse major number */
+	maj = simple_strtoul(str, &p, 16);
+	if (p == str) {
+		maj = 0;
+		if (*p != ':')
+			return -EINVAL;
+	}
+
+	/* parse minor number */
+	if (*p == ':') {
+		if (maj >= (1<<16))
+			return -EINVAL;
+
+		str = p + 1;
+		min = simple_strtoul(str, &p, 16);
+		if (*p != 0)
+			return -EINVAL;
+		if (min >= (1<<16))
+			return -EINVAL;
+	} else if (*p != 0)
+		return -EINVAL;
+
+	*classid = TC_H_MAKE(maj<<16, min);
+
+	return 0;
 }
 
-static int write_classid(struct cgroup *cgrp, struct cftype *cft, u64 value)
+static int write_classid(struct cgroup *cgrp, struct cftype *cft,
+				const char *buf)
 {
+	u32 classid;
+
 	if (!cgroup_lock_live_group(cgrp))
 		return -ENODEV;
 
-	cgrp_cls_state(cgrp)->classid = (u32) value;
+	if (get_tc_classid(&classid, buf) < 0)
+		return -EINVAL;
+
+	cgrp_cls_state(cgrp)->classid = classid;
 
 	cgroup_unlock();
 
@@ -75,8 +135,8 @@ static int write_classid(struct cgroup *cgrp, struct cftype *cft, u64 value)
 static struct cftype ss_files[] = {
 	{
 		.name = "classid",
-		.read_u64 = read_classid,
-		.write_u64 = write_classid,
+		.read = read_classid,
+		.write_string = write_classid,
 	},
 };
 

-- 
Minoru Usui <usui@mxm.nes.nec.co.jp>

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2009-06-18 15:21 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-11  9:05 [PATCH 1/1] cls_cgroup: unify classid syntax to tc Minoru Usui
2009-06-11  9:13 ` David Miller
2009-06-12  3:40   ` Minoru Usui
     [not found]     ` <20090612124028.fe4c2100.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
2009-06-12  4:36       ` David Miller
2009-06-12  5:06       ` [Devel] " Paul Menage
2009-06-12  4:36     ` David Miller
2009-06-12  5:06     ` [Devel] " Paul Menage
     [not found]       ` <6599ad830906112206n745fb0dw19cdb75d7c40b2a4-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-06-15  3:00         ` Minoru Usui
     [not found]           ` <20090615120035.a8b7b38f.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
2009-06-15 10:19             ` Thomas Graf
2009-06-15 10:19           ` Thomas Graf
     [not found]             ` <20090615101919.GC7768-PfSpb0PWhxZc2C7mugBRk2EX/6BAtgUQ@public.gmane.org>
2009-06-17  0:49               ` Minoru Usui
2009-06-17  0:49             ` Minoru Usui
2009-06-18  2:01               ` Li Zefan
2009-06-18  6:15                 ` Minoru Usui
     [not found]                   ` <20090618151516.73daf5d8.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
2009-06-18 15:21                     ` Paul Menage
2009-06-18 15:21                   ` Paul Menage
     [not found]                 ` <4A399FF7.5060209-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-06-18  6:15                   ` Minoru Usui
     [not found]               ` <20090617094907.e8cd77bd.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
2009-06-18  2:01                 ` Li Zefan
     [not found]   ` <20090611.021347.142243970.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2009-06-12  3:40     ` Minoru Usui
     [not found] ` <20090611180555.f2c76568.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
2009-06-11  9:13   ` David Miller
2009-06-11  9:31   ` Thomas Graf
2009-06-11  9:31 ` Thomas Graf
     [not found]   ` <20090611093149.GA12543-PfSpb0PWhxZc2C7mugBRk2EX/6BAtgUQ@public.gmane.org>
2009-06-12  1:02     ` Minoru Usui
2009-06-12  1:02   ` Minoru Usui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.