* [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; 25+ 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] 25+ messages in thread
* Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
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] ` <20090611.021347.142243970.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
[not found] ` <20090611180555.f2c76568.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
2009-06-11 9:31 ` Thomas Graf
2 siblings, 2 replies; 25+ messages in thread
From: David Miller @ 2009-06-11 9:13 UTC (permalink / raw)
To: usui; +Cc: containers, netdev, tgraf, hadi, jarkao2
From: Minoru Usui <usui@mxm.nes.nec.co.jp>
Date: Thu, 11 Jun 2009 18:05:55 +0900
> This patch unifies classid syntax of cls_cgroup to tc.
Won't this break existing users?
We really can't say "oh sorry" and change things after it's
been effectively deployed already.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
2009-06-11 9:13 ` David Miller
@ 2009-06-12 3:40 ` Minoru Usui
[not found] ` <20090612124028.fe4c2100.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
` (2 more replies)
[not found] ` <20090611.021347.142243970.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
1 sibling, 3 replies; 25+ messages in thread
From: Minoru Usui @ 2009-06-12 3:40 UTC (permalink / raw)
To: David Miller; +Cc: containers, netdev, tgraf, hadi, jarkao2
Hi, David
Thank you for your comments.
On Thu, 11 Jun 2009 02:13:47 -0700 (PDT)
David Miller <davem@davemloft.net> wrote:
> From: Minoru Usui <usui@mxm.nes.nec.co.jp>
> Date: Thu, 11 Jun 2009 18:05:55 +0900
>
> > This patch unifies classid syntax of cls_cgroup to tc.
>
> Won't this break existing users?
>
> We really can't say "oh sorry" and change things after it's
> been effectively deployed already.
It's true. If my patch applied, old syntax can't use.
But I think compatibility is important, too.
So I'll make a new patch which can use both old and new syntax, when we write classid to net_cls.classid file.
Present implementation is an asymmetry with read and write.(read: decimal, write: hexadecimal)
I think this might be interface bug, so I think we should unify to read/write syntax.
Of course, if read syntax change from decimal expression, there isn't compatibility.
But I think it's better to fix this problem.
What do you think?
If it's ok, I'd like to be able to use tc syntax(X:Y style),
because cls_cgroup's purpose is select class which create by tc command.
tc command can only use classid syntax X:Y style, so we should be able to use X:Y style to cls_cgroup.
--
Minoru Usui <usui@mxm.nes.nec.co.jp>
^ permalink raw reply [flat|nested] 25+ messages in thread
[parent not found: <20090612124028.fe4c2100.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>]
* Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
[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
1 sibling, 0 replies; 25+ messages in thread
From: David Miller @ 2009-06-12 4:36 UTC (permalink / raw)
To: usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil
Cc: tgraf-G/eBtMaohhA, netdev-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
hadi-fAAogVwAN2Kw5LPnMra/2Q, jarkao2-Re5JQEeQqe8AvxtiuMwx3w
From: Minoru Usui <usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
Date: Fri, 12 Jun 2009 12:40:28 +0900
> Of course, if read syntax change from decimal expression, there
> isn't compatibility. But I think it's better to fix this problem.
> What do you think?
I think compatibility is more important than symmetry.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [Devel] Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
[not found] ` <20090612124028.fe4c2100.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
2009-06-12 4:36 ` David Miller
@ 2009-06-12 5:06 ` Paul Menage
1 sibling, 0 replies; 25+ messages in thread
From: Paul Menage @ 2009-06-12 5:06 UTC (permalink / raw)
To: Minoru Usui
Cc: netdev-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
hadi-fAAogVwAN2Kw5LPnMra/2Q, tgraf-G/eBtMaohhA, David Miller,
jarkao2-Re5JQEeQqe8AvxtiuMwx3w
On Thu, Jun 11, 2009 at 8:40 PM, Minoru Usui<usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org> wrote:
>
> It's true. If my patch applied, old syntax can't use.
> But I think compatibility is important, too.
> So I'll make a new patch which can use both old and new syntax, when we write classid to net_cls.classid file.
>
> Present implementation is an asymmetry with read and write.(read: decimal, write: hexadecimal)
You can write the classid value in decimal too, or even octal - it
just uses strtoull() to convert the string to an integer, so
0x-prefixed hex values are handled automatically.
>
> If it's ok, I'd like to be able to use tc syntax(X:Y style),
> because cls_cgroup's purpose is select class which create by tc command.
> tc command can only use classid syntax X:Y style, so we should be able to use X:Y style to cls_cgroup.
We should keep it as it is - purely apart from compatibility issues,
there's no need to introduce the complexity of the tc interface into
the cls_cgroup kernel code. When a cgroup control file represents a
simple integer, then it should be exposed as such.
Paul
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
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
2 siblings, 0 replies; 25+ messages in thread
From: David Miller @ 2009-06-12 4:36 UTC (permalink / raw)
To: usui; +Cc: containers, netdev, tgraf, hadi, jarkao2
From: Minoru Usui <usui@mxm.nes.nec.co.jp>
Date: Fri, 12 Jun 2009 12:40:28 +0900
> Of course, if read syntax change from decimal expression, there
> isn't compatibility. But I think it's better to fix this problem.
> What do you think?
I think compatibility is more important than symmetry.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [Devel] Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
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 ` Paul Menage
[not found] ` <6599ad830906112206n745fb0dw19cdb75d7c40b2a4-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2 siblings, 1 reply; 25+ messages in thread
From: Paul Menage @ 2009-06-12 5:06 UTC (permalink / raw)
To: Minoru Usui; +Cc: David Miller, tgraf, netdev, containers, hadi, jarkao2
On Thu, Jun 11, 2009 at 8:40 PM, Minoru Usui<usui@mxm.nes.nec.co.jp> wrote:
>
> It's true. If my patch applied, old syntax can't use.
> But I think compatibility is important, too.
> So I'll make a new patch which can use both old and new syntax, when we write classid to net_cls.classid file.
>
> Present implementation is an asymmetry with read and write.(read: decimal, write: hexadecimal)
You can write the classid value in decimal too, or even octal - it
just uses strtoull() to convert the string to an integer, so
0x-prefixed hex values are handled automatically.
>
> If it's ok, I'd like to be able to use tc syntax(X:Y style),
> because cls_cgroup's purpose is select class which create by tc command.
> tc command can only use classid syntax X:Y style, so we should be able to use X:Y style to cls_cgroup.
We should keep it as it is - purely apart from compatibility issues,
there's no need to introduce the complexity of the tc interface into
the cls_cgroup kernel code. When a cgroup control file represents a
simple integer, then it should be exposed as such.
Paul
^ permalink raw reply [flat|nested] 25+ messages in thread
[parent not found: <20090611.021347.142243970.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>]
* Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
[not found] ` <20090611.021347.142243970.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
@ 2009-06-12 3:40 ` Minoru Usui
0 siblings, 0 replies; 25+ messages in thread
From: Minoru Usui @ 2009-06-12 3:40 UTC (permalink / raw)
To: David Miller
Cc: tgraf-G/eBtMaohhA, netdev-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
hadi-fAAogVwAN2Kw5LPnMra/2Q, jarkao2-Re5JQEeQqe8AvxtiuMwx3w
Hi, David
Thank you for your comments.
On Thu, 11 Jun 2009 02:13:47 -0700 (PDT)
David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org> wrote:
> From: Minoru Usui <usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
> Date: Thu, 11 Jun 2009 18:05:55 +0900
>
> > This patch unifies classid syntax of cls_cgroup to tc.
>
> Won't this break existing users?
>
> We really can't say "oh sorry" and change things after it's
> been effectively deployed already.
It's true. If my patch applied, old syntax can't use.
But I think compatibility is important, too.
So I'll make a new patch which can use both old and new syntax, when we write classid to net_cls.classid file.
Present implementation is an asymmetry with read and write.(read: decimal, write: hexadecimal)
I think this might be interface bug, so I think we should unify to read/write syntax.
Of course, if read syntax change from decimal expression, there isn't compatibility.
But I think it's better to fix this problem.
What do you think?
If it's ok, I'd like to be able to use tc syntax(X:Y style),
because cls_cgroup's purpose is select class which create by tc command.
tc command can only use classid syntax X:Y style, so we should be able to use X:Y style to cls_cgroup.
--
Minoru Usui <usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
^ permalink raw reply [flat|nested] 25+ messages in thread
[parent not found: <20090611180555.f2c76568.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>]
* Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
[not found] ` <20090611180555.f2c76568.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
@ 2009-06-11 9:13 ` David Miller
2009-06-11 9:31 ` Thomas Graf
1 sibling, 0 replies; 25+ messages in thread
From: David Miller @ 2009-06-11 9:13 UTC (permalink / raw)
To: usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil
Cc: tgraf-G/eBtMaohhA, netdev-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
hadi-fAAogVwAN2Kw5LPnMra/2Q, jarkao2-Re5JQEeQqe8AvxtiuMwx3w
From: Minoru Usui <usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
Date: Thu, 11 Jun 2009 18:05:55 +0900
> This patch unifies classid syntax of cls_cgroup to tc.
Won't this break existing users?
We really can't say "oh sorry" and change things after it's
been effectively deployed already.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
[not found] ` <20090611180555.f2c76568.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
2009-06-11 9:13 ` David Miller
@ 2009-06-11 9:31 ` Thomas Graf
1 sibling, 0 replies; 25+ messages in thread
From: Thomas Graf @ 2009-06-11 9:31 UTC (permalink / raw)
To: Minoru Usui
Cc: tgraf-G/eBtMaohhA, netdev-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
hadi-fAAogVwAN2Kw5LPnMra/2Q, jarkao2-Re5JQEeQqe8AvxtiuMwx3w
Very nice, this is a big improvement.
On Thu, Jun 11, 2009 at 06:05:55PM +0900, Minoru Usui wrote:
> +static int get_tc_classid(u32 *classid, const char *str)
Maybe make this return u32?
> {
> - 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;
What do you think about keeping things backwards compatible by
accepting both the X:Y and XY format?
} else if (*p != 0)
return strtoul(str, NULL, 0);
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
2009-06-11 9:05 [PATCH 1/1] cls_cgroup: unify classid syntax to tc Minoru Usui
2009-06-11 9:13 ` David Miller
[not found] ` <20090611180555.f2c76568.usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
@ 2009-06-11 9:31 ` Thomas Graf
[not found] ` <20090611093149.GA12543-PfSpb0PWhxZc2C7mugBRk2EX/6BAtgUQ@public.gmane.org>
2009-06-12 1:02 ` Minoru Usui
2 siblings, 2 replies; 25+ messages in thread
From: Thomas Graf @ 2009-06-11 9:31 UTC (permalink / raw)
To: Minoru Usui; +Cc: containers, netdev, tgraf, hadi, jarkao2
Very nice, this is a big improvement.
On Thu, Jun 11, 2009 at 06:05:55PM +0900, Minoru Usui wrote:
> +static int get_tc_classid(u32 *classid, const char *str)
Maybe make this return u32?
> {
> - 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;
What do you think about keeping things backwards compatible by
accepting both the X:Y and XY format?
} else if (*p != 0)
return strtoul(str, NULL, 0);
^ permalink raw reply [flat|nested] 25+ messages in thread
[parent not found: <20090611093149.GA12543-PfSpb0PWhxZc2C7mugBRk2EX/6BAtgUQ@public.gmane.org>]
* Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
[not found] ` <20090611093149.GA12543-PfSpb0PWhxZc2C7mugBRk2EX/6BAtgUQ@public.gmane.org>
@ 2009-06-12 1:02 ` Minoru Usui
0 siblings, 0 replies; 25+ messages in thread
From: Minoru Usui @ 2009-06-12 1:02 UTC (permalink / raw)
To: Thomas Graf
Cc: tgraf-G/eBtMaohhA, netdev-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
hadi-fAAogVwAN2Kw5LPnMra/2Q, jarkao2-Re5JQEeQqe8AvxtiuMwx3w
Hi, Thomas
Thank you for your comments.
On Thu, 11 Jun 2009 05:31:49 -0400
Thomas Graf <tgraf-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org> wrote:
> Very nice, this is a big improvement.
>
> On Thu, Jun 11, 2009 at 06:05:55PM +0900, Minoru Usui wrote:
> > +static int get_tc_classid(u32 *classid, const char *str)
>
> Maybe make this return u32?
Yes, you are right.
I'll fix it.
>
> > {
> > - 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;
>
> What do you think about keeping things backwards compatible by
> accepting both the X:Y and XY format?
>
> } else if (*p != 0)
> return strtoul(str, NULL, 0);
OK. I'll do it.
--
Minoru Usui <usui-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/1] cls_cgroup: unify classid syntax to tc
2009-06-11 9:31 ` Thomas Graf
[not found] ` <20090611093149.GA12543-PfSpb0PWhxZc2C7mugBRk2EX/6BAtgUQ@public.gmane.org>
@ 2009-06-12 1:02 ` Minoru Usui
1 sibling, 0 replies; 25+ messages in thread
From: Minoru Usui @ 2009-06-12 1:02 UTC (permalink / raw)
To: Thomas Graf; +Cc: containers, netdev, tgraf, hadi, jarkao2
Hi, Thomas
Thank you for your comments.
On Thu, 11 Jun 2009 05:31:49 -0400
Thomas Graf <tgraf@infradead.org> wrote:
> Very nice, this is a big improvement.
>
> On Thu, Jun 11, 2009 at 06:05:55PM +0900, Minoru Usui wrote:
> > +static int get_tc_classid(u32 *classid, const char *str)
>
> Maybe make this return u32?
Yes, you are right.
I'll fix it.
>
> > {
> > - 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;
>
> What do you think about keeping things backwards compatible by
> accepting both the X:Y and XY format?
>
> } else if (*p != 0)
> return strtoul(str, NULL, 0);
OK. I'll do it.
--
Minoru Usui <usui@mxm.nes.nec.co.jp>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 1/1] cls_cgroup: unify classid syntax to tc
@ 2009-06-11 9:05 Minoru Usui
0 siblings, 0 replies; 25+ messages in thread
From: Minoru Usui @ 2009-06-11 9:05 UTC (permalink / raw)
To: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
netdev-u79uwXL29TY76Z2rM5mHXA
Cc: tgraf-G/eBtMaohhA, hadi-fAAogVwAN2Kw5LPnMra/2Q,
jarkao2-Re5JQEeQqe8AvxtiuMwx3w
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-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
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-vEbCzmPPqHe45+QrQBaojngSJqDPrsil@public.gmane.org>
^ permalink raw reply related [flat|nested] 25+ messages in thread
end of thread, other threads:[~2009-06-18 15:21 UTC | newest]
Thread overview: 25+ 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
-- strict thread matches above, loose matches on Subject: below --
2009-06-11 9:05 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.