<span style="color:rgb(69,69,69);font-family:arial,helvetica,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Applied the patch. Able to lxc-execute without any issues (2.6.32 kernel).</span><br style="color:rgb(69,69,69);font-family:arial,helvetica,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br style="color:rgb(69,69,69);font-family:arial,helvetica,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(69,69,69);font-family:arial,helvetica,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Thanks,</span><br style="color:rgb(69,69,69);font-family:arial,helvetica,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(69,69,69);font-family:arial,helvetica,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Arun</span><br><br><div class="gmail_quote">On Tue, Mar 6, 2012 at 12:43 AM, Serge Hallyn <span dir="ltr"><<a href="mailto:serge.hallyn@canonical.com">serge.hallyn@canonical.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">when using ns cgroup, use /cgroup/<init-cgroup> rather than<br>
/cgroup/<init-cgroup>/lxc<br>
<br>
At least lxc-start, lxc-stop, lxc-cgroup, lxc-console and lxc-ls work<br>
with this patch. I've tested this in a 2.6.35 kernel with ns cgroup,<br>
and in a 3.2 kernel without ns cgroup.<br>
<br>
Note also that because of the check for container reboot support,<br>
if we're using the ns cgroup we now end up with a /cgroup/<container>/2<br>
cgroup created, empty, by the clone(CLONE_NEWPID). I'm really not<br>
sure how much time we want to spend cleaning such things up since<br>
ns cgroup is deprecated in kernel.<br>
<br>
Signed-off-by: Serge Hallyn <<a href="mailto:serge@hallyn.com">serge@hallyn.com</a>><br>
---<br>
src/lxc/cgroup.c | 60 +++++++++++++++++++++++++++++++---------------------<br>
src/lxc/<a href="http://lxc-ls.in" target="_blank">lxc-ls.in</a> | 6 ++++-<br>
2 files changed, 41 insertions(+), 25 deletions(-)<br>
<br>
diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c<br>
index cc3910a..9af199d 100644<br>
--- a/src/lxc/cgroup.c<br>
+++ b/src/lxc/cgroup.c<br>
@@ -137,6 +137,21 @@ found:<br>
return dsg;<br>
}<br>
<br>
+static int get_cgroup_flags(struct mntent *mntent)<br>
+{<br>
+ int flags = 0;<br>
+<br>
+<br>
+ if (hasmntopt(mntent, "ns"))<br>
+ flags |= CGROUP_NS_CGROUP;<br>
+<br>
+ if (hasmntopt(mntent, "clone_children"))<br>
+ flags |= CGROUP_CLONE_CHILDREN;<br>
+<br>
+ DEBUG("cgroup %s has flags 0x%x", mntent->mnt_dir, flags);<br>
+ return flags;<br>
+}<br>
+<br>
static int get_cgroup_mount(const char *subsystem, char *mnt)<br>
{<br>
struct mntent *mntent;<br>
@@ -155,10 +170,12 @@ static int get_cgroup_mount(const char *subsystem, char *mnt)<br>
continue;<br>
if (!subsystem || hasmntopt_multiple(mntent, subsystem)) {<br>
int ret;<br>
- ret = snprintf(mnt, MAXPATHLEN, "%s%s/lxc",<br>
+ int flags = get_cgroup_flags(mntent);<br>
+ ret = snprintf(mnt, MAXPATHLEN, "%s%s%s",<br>
mntent->mnt_dir,<br>
get_init_cgroup(subsystem, NULL,<br>
- initcgroup));<br>
+ initcgroup),<br>
+ (flags & CGROUP_NS_CGROUP) ? "" : "/lxc");<br>
if (ret < 0 || ret >= MAXPATHLEN)<br>
goto fail;<br>
fclose(file);<br>
@@ -183,33 +200,26 @@ int lxc_ns_is_mounted(void)<br>
return (get_cgroup_mount("ns", buf) == 0);<br>
}<br>
<br>
-static int get_cgroup_flags(struct mntent *mntent)<br>
-{<br>
- int flags = 0;<br>
-<br>
-<br>
- if (hasmntopt(mntent, "ns"))<br>
- flags |= CGROUP_NS_CGROUP;<br>
-<br>
- if (hasmntopt(mntent, "clone_children"))<br>
- flags |= CGROUP_CLONE_CHILDREN;<br>
-<br>
- DEBUG("cgroup %s has flags 0x%x", mntent->mnt_dir, flags);<br>
- return flags;<br>
-}<br>
-<br>
static int cgroup_rename_nsgroup(const char *mnt, const char *name, pid_t pid)<br>
{<br>
char oldname[MAXPATHLEN];<br>
+ char newname[MAXPATHLEN];<br>
+ int ret;<br>
+<br>
+ ret = snprintf(oldname, MAXPATHLEN, "%s/%d", mnt, pid);<br>
+ if (ret >= MAXPATHLEN)<br>
+ return -1;<br>
<br>
- snprintf(oldname, MAXPATHLEN, "%s/%d", mnt, pid);<br>
+ ret = snprintf(newname, MAXPATHLEN, "%s/%s", mnt, name);<br>
+ if (ret >= MAXPATHLEN)<br>
+ return -1;<br>
<br>
- if (rename(oldname, name)) {<br>
- SYSERROR("failed to rename cgroup %s->%s", oldname, name);<br>
+ if (rename(oldname, newname)) {<br>
+ SYSERROR("failed to rename cgroup %s->%s", oldname, newname);<br>
return -1;<br>
}<br>
<br>
- DEBUG("'%s' renamed to '%s'", oldname, name);<br>
+ DEBUG("'%s' renamed to '%s'", oldname, newname);<br>
<br>
return 0;<br>
}<br>
@@ -321,7 +331,7 @@ static int lxc_one_cgroup_create(const char *name,<br>
/* Do we have the deprecated ns_cgroup subsystem? */<br>
if (flags & CGROUP_NS_CGROUP) {<br>
WARN("using deprecated ns_cgroup");<br>
- return cgroup_rename_nsgroup(cgparent, cgname, pid);<br>
+ return cgroup_rename_nsgroup(cginit, name, pid);<br>
}<br>
<br>
ret = snprintf(clonechild, MAXPATHLEN, "%s/cgroup.clone_children",<br>
@@ -464,9 +474,11 @@ int lxc_one_cgroup_destroy(struct mntent *mntent, const char *name)<br>
{<br>
char cgname[MAXPATHLEN], initcgroup[MAXPATHLEN];<br>
char *cgmnt = mntent->mnt_dir;<br>
+ int flags = get_cgroup_flags(mntent);<br>
<br>
- snprintf(cgname, MAXPATHLEN, "%s%s/lxc/%s", cgmnt,<br>
- get_init_cgroup(NULL, mntent, initcgroup), name);<br>
+ snprintf(cgname, MAXPATHLEN, "%s%s%s/%s", cgmnt,<br>
+ get_init_cgroup(NULL, mntent, initcgroup),<br>
+ (flags & CGROUP_NS_CGROUP) ? "" : "/lxc", name);<br>
DEBUG("destroying %s\n", cgname);<br>
if (recursive_rmdir(cgname)) {<br>
SYSERROR("failed to remove cgroup '%s'", cgname);<br>
diff --git a/src/lxc/<a href="http://lxc-ls.in" target="_blank">lxc-ls.in</a> b/src/lxc/<a href="http://lxc-ls.in" target="_blank">lxc-ls.in</a><br>
index d200509..a1ad642 100644<br>
--- a/src/lxc/<a href="http://lxc-ls.in" target="_blank">lxc-ls.in</a><br>
+++ b/src/lxc/<a href="http://lxc-ls.in" target="_blank">lxc-ls.in</a><br>
@@ -33,7 +33,11 @@ if test -n "$active"; then<br>
if test -n "$mount_point"; then<br>
# get cgroup for init<br>
init_cgroup=`cat /proc/1/cgroup | awk -F: '{ print $3 }' | head -1`<br>
- cd $mount_point/$init_cgroup/lxc<br>
+ if [ ! -d $mount_point/$init_cgroup/lxc ]; then<br>
+ cd $mount_point/$init_cgroup<br>
+ else<br>
+ cd $mount_point/$init_cgroup/lxc<br>
+ fi<br>
ls "$@" -d $active<br>
fi<br>
fi<br>
--<br>
1.7.1<br>
<br>
<br>
------------------------------------------------------------------------------<br>
Try before you buy = See our experts in action!<br>
The most comprehensive online learning library for Microsoft developers<br>
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,<br>
Metro Style Apps, more. Free future releases when you subscribe now!<br>
<a href="http://p.sf.net/sfu/learndevnow-dev2" target="_blank">http://p.sf.net/sfu/learndevnow-dev2</a><br>
_______________________________________________<br>
Lxc-users mailing list<br>
<a href="mailto:Lxc-users@lists.sourceforge.net">Lxc-users@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/lxc-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/lxc-users</a><br>
</blockquote></div><br>