Re: [lxc-devel] lxc_monitord - monitor exiting
On Mon, 6 May 2013 19:08:08 -0500 Serge Hallyn wrote: > Quoting Dwight Engen (dwight.en...@oracle.com): > > On Mon, 6 May 2013 15:31:14 -0500 > > Serge Hallyn wrote: > > > > > Quoting Dwight Engen (dwight.en...@oracle.com): > > > > On Mon, 6 May 2013 13:06:43 -0400 > > > > Dwight Engen wrote: > > > > > > > > > Hi Çağlar, > > > > > > > > > > Thanks for the test program, I can sort of recreate it here > > > > > with that, although once I lxc-stop them all, lxc-monitord > > > > > does go away. I put a debug in lxc_wait() to see that the > > > > > client always close the fd to the monitord and they all were > > > > > closed so I'm not sure why lxc-monitord isn't seeing the > > > > > accepted fd coming back from epoll to close. Still > > > > > investigating... > > > > > > > > Okay, so I debugged this and the problem is basically down to > > > > lxc not being thread aware. With your test program we get > > > > multiple threads in lxcapi_start() simultaneously in the > > > > daemonize case. One of them forks while another one has the > > > > client fd to the monitor open and thus the fd gets duped by the > > > > fork and that is the client fd that holds lxc-monitord open > > > > until the container shuts down. > > > > > > > > Çağlar you could try out the following patch, it essentially > > > > serializes container startup from a thread perspective. I > > > > haven't tested it thoroughly, but it did fix the problem here. > > > > Right now lxc doesn't support threaded use, so you may run into > > > > other things as well. Depending on our stance on thread support > > > > in lxc, you may need to do the serialization in the threaded > > > > app. I guess another alternative is that initially we could > > > > just thread serialize at the API (big lxc lock). > > > > > > It sounds like lxcapi_start should be locking c->slock? The > > > priv_lock is to protect the struct lxccontainer in memory (for > > > when you do c = lxc_container_new(); then clone a new thread), > > > while the slock is to protect the container data. It's being > > > taken at create, info, destroy, etc, but not at start. > > > > Hi Serge, thanks for pointing those out, lxc is more thread aware > > than I realized :) Unfortunately I don't think either lock will > > help here as both these locks are per-container and the data we > > need to synchronize is per-calling process (ie. which fd's are open > > at time of fork). To put it another way, this problem happens even > > when each c is different. > > Right you are. I was so busy worrying about how to protect the > on-disk container and in-memory container_struct I wasn't thinking > about the shared fdtable. > > Should we have a single mutex around all fd modifications? What else? I think that will certainly work here, I haven't considered other places. Do we need to think about sighand and umask? Would you prefer to use the semaphores lxc already has (ie lxc_newlock() with no name) over pthread_mutex? Since Çağlar verified the test fix worked for him also I'd like to make a real fix. -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] lxc_monitord - monitor exiting
Quoting Dwight Engen (dwight.en...@oracle.com): > On Mon, 6 May 2013 19:08:08 -0500 > Serge Hallyn wrote: > > > Quoting Dwight Engen (dwight.en...@oracle.com): > > > On Mon, 6 May 2013 15:31:14 -0500 > > > Serge Hallyn wrote: > > > > > > > Quoting Dwight Engen (dwight.en...@oracle.com): > > > > > On Mon, 6 May 2013 13:06:43 -0400 > > > > > Dwight Engen wrote: > > > > > > > > > > > Hi Çağlar, > > > > > > > > > > > > Thanks for the test program, I can sort of recreate it here > > > > > > with that, although once I lxc-stop them all, lxc-monitord > > > > > > does go away. I put a debug in lxc_wait() to see that the > > > > > > client always close the fd to the monitord and they all were > > > > > > closed so I'm not sure why lxc-monitord isn't seeing the > > > > > > accepted fd coming back from epoll to close. Still > > > > > > investigating... > > > > > > > > > > Okay, so I debugged this and the problem is basically down to > > > > > lxc not being thread aware. With your test program we get > > > > > multiple threads in lxcapi_start() simultaneously in the > > > > > daemonize case. One of them forks while another one has the > > > > > client fd to the monitor open and thus the fd gets duped by the > > > > > fork and that is the client fd that holds lxc-monitord open > > > > > until the container shuts down. > > > > > > > > > > Çağlar you could try out the following patch, it essentially > > > > > serializes container startup from a thread perspective. I > > > > > haven't tested it thoroughly, but it did fix the problem here. > > > > > Right now lxc doesn't support threaded use, so you may run into > > > > > other things as well. Depending on our stance on thread support > > > > > in lxc, you may need to do the serialization in the threaded > > > > > app. I guess another alternative is that initially we could > > > > > just thread serialize at the API (big lxc lock). > > > > > > > > It sounds like lxcapi_start should be locking c->slock? The > > > > priv_lock is to protect the struct lxccontainer in memory (for > > > > when you do c = lxc_container_new(); then clone a new thread), > > > > while the slock is to protect the container data. It's being > > > > taken at create, info, destroy, etc, but not at start. > > > > > > Hi Serge, thanks for pointing those out, lxc is more thread aware > > > than I realized :) Unfortunately I don't think either lock will > > > help here as both these locks are per-container and the data we > > > need to synchronize is per-calling process (ie. which fd's are open > > > at time of fork). To put it another way, this problem happens even > > > when each c is different. > > > > Right you are. I was so busy worrying about how to protect the > > on-disk container and in-memory container_struct I wasn't thinking > > about the shared fdtable. > > > > Should we have a single mutex around all fd modifications? What else? > > I think that will certainly work here, I haven't considered other > places. Do we need to think about sighand and umask? Would you prefer Yeah we should. (And I need to decide how to fix the fact that c->slock is just called the container name, regardless the lxcpath) > to use the semaphores lxc already has (ie lxc_newlock() with no name) Actually we're doing different things there, so I'm happy to use pthread_mutex, unless it'll cause trouble for people using different toolchains (i.e. android/bionic). The semaphores we're using are to protect the container_struct itself, and to protect the on-disk container data. For protecting the task data itself, pthread_mutex seems perfect. (And no name is needed.) > over pthread_mutex? Since Çağlar verified the test fix worked for him > also I'd like to make a real fix. Should I push the patch from yesterday as a first step, or would you prefer to do all at once with one patch? I'm fine either way. thanks, -serge PS - I'm in meetings all week (a very rare thing for me), so apologies if I'm slow in responding. -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 1/6] coverity: free malloc'ed memory in error case
Signed-off-by: Dwight Engen --- src/lxc/bdev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c index 35351a9..1a611f9 100644 --- a/src/lxc/bdev.c +++ b/src/lxc/bdev.c @@ -1203,6 +1203,8 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char return -ENOMEM; } if (do_rsync(odelta, ndelta) < 0) { + free(osrc); + free(ndelta); ERROR("copying overlayfs delta"); return -1; } -- 1.8.1.4 -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 2/6] coverity: open can return 0 as an fd, change error check to < 0
Signed-off-by: Dwight Engen --- src/lxc/bdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c index 1a611f9..181e98e 100644 --- a/src/lxc/bdev.c +++ b/src/lxc/bdev.c @@ -90,7 +90,7 @@ static int blk_getsize(const char *path, unsigned long *size) int fd, ret; fd = open(path, O_RDONLY); - if (!fd) + if (fd < 0) return -1; ret = ioctl(fd, BLKGETSIZE64, size); close(fd); -- 1.8.1.4 -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 4/6] coverity: clonetest: check correct container is cloned
Signed-off-by: Dwight Engen --- src/tests/clonetest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/clonetest.c b/src/tests/clonetest.c index fcb5ea6..5644405 100644 --- a/src/tests/clonetest.c +++ b/src/tests/clonetest.c @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) goto out; } - if (!c2->is_defined(c)) { + if (!c2->is_defined(c2)) { fprintf(stderr, "%d: %s not defined after clone\n", __LINE__, MYNAME2); goto out; } -- 1.8.1.4 -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 3/6] coverity: condition already checked for
Signed-off-by: Dwight Engen --- src/lxc/bdev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c index 181e98e..fcde16b 100644 --- a/src/lxc/bdev.c +++ b/src/lxc/bdev.c @@ -1151,8 +1151,7 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char if (strcmp(orig->type, "dir") == 0) { char *delta; int ret, len; - if (!snap) - return -1; + // if we have /var/lib/lxc/c2/rootfs, then delta will be ///var/lib/lxc/c2/delta0 delta = strdup(new->dest); -- 1.8.1.4 -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 6/6] coverity: fix potential dereference NULL returned from malloc
Signed-off-by: Dwight Engen --- src/lxc/network.c | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lxc/network.c b/src/lxc/network.c index 93fc169..d1ccc0d 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -783,8 +783,11 @@ static int ifa_get_local_ip(int family, struct ip_req *ip_info, void** res) { /* We might have found an IFA_ADDRESS before, * which we now overwrite with an IFA_LOCAL. */ - if (!*res) + if (!*res) { *res = malloc(addrlen); + if (!*res) + return -1; + } memcpy(*res, RTA_DATA(rta), addrlen); -- 1.8.1.4 -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 5/6] coverity: check return from waitpid
Signed-off-by: Dwight Engen --- src/lxc/monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c index 0521e9a..5648b86 100644 --- a/src/lxc/monitor.c +++ b/src/lxc/monitor.c @@ -207,7 +207,8 @@ int lxc_monitord_spawn(const char *lxcpath) } if (pid1) { - waitpid(pid1, NULL, 0); + if (waitpid(pid1, NULL, 0) != pid1) + return -1; return 0; } -- 1.8.1.4 -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] [PATCH 1/6] coverity: free malloc'ed memory in error case
Thanks, Dwight. Acked-by: Serge E. Hallyn to the whole set. Quoting Dwight Engen (dwight.en...@oracle.com): > Signed-off-by: Dwight Engen > --- > src/lxc/bdev.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c > index 35351a9..1a611f9 100644 > --- a/src/lxc/bdev.c > +++ b/src/lxc/bdev.c > @@ -1203,6 +1203,8 @@ static int overlayfs_clonepaths(struct bdev *orig, > struct bdev *new, const char > return -ENOMEM; > } > if (do_rsync(odelta, ndelta) < 0) { > + free(osrc); > + free(ndelta); > ERROR("copying overlayfs delta"); > return -1; > } > -- > 1.8.1.4 > > > > -- > Learn Graph Databases - Download FREE O'Reilly Book > "Graph Databases" is the definitive new guide to graph databases and > their applications. This 200-page book is written by three acclaimed > leaders in the field. The early access version is available now. > Download your free book today! http://p.sf.net/sfu/neotech_d2d_may > ___ > Lxc-devel mailing list > Lxc-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/lxc-devel -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] [PATCH] lxc-monitor multiple paths
On Fri, 26 Apr 2013 09:31:08 -0500 Serge Hallyn wrote: > Quoting Dwight Engen (dwight.en...@oracle.com): > > >From c4af03c0e6b74e550161e4c8382fb9d0889e4fe3 Mon Sep 17 00:00:00 > > >2001 > > From: Dwight Engen > > Date: Thu, 25 Apr 2013 11:45:26 -0400 > > Subject: [PATCH] lxc-monitor multiple paths > > > > Signed-off-by: Dwight Engen > > Acked-by: Serge E. Hallyn > > I wonder if it's worth adding a 'numlxcpaths' to arguments, so that > lxc-attach and the others can set that to 1, and if a second lxcpath > argument is found, it immediately returns failure? Right now the > extra lxcpaths will simply be ignored. Hi Serge, this has not been applied yet, so I updated it against head and added a lxcpaths_additional to arguments like you suggested. I made it the count of additional -P arguments to accept so most programs don't have to initialize it. Patch to follow. -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH v2] lxc-monitor multiple paths
Signed-off-by: Dwight Engen --- doc/lxc-monitor.sgml.in | 7 ++ src/lxc/arguments.c | 34 +++-- src/lxc/arguments.h | 5 - src/lxc/lxc.h| 31 +- src/lxc/lxc_attach.c | 8 +++ src/lxc/lxc_cgroup.c | 6 ++--- src/lxc/lxc_checkpoint.c | 2 +- src/lxc/lxc_console.c| 4 ++-- src/lxc/lxc_execute.c| 6 ++--- src/lxc/lxc_freeze.c | 4 ++-- src/lxc/lxc_info.c | 6 ++--- src/lxc/lxc_kill.c | 4 ++-- src/lxc/lxc_monitor.c| 35 + src/lxc/lxc_restart.c| 6 ++--- src/lxc/lxc_start.c | 6 ++--- src/lxc/lxc_stop.c | 4 ++-- src/lxc/lxc_unfreeze.c | 4 ++-- src/lxc/lxc_wait.c | 5 +++-- src/lxc/monitor.c| 57 +++- 19 files changed, 165 insertions(+), 69 deletions(-) diff --git a/doc/lxc-monitor.sgml.in b/doc/lxc-monitor.sgml.in index 336061d..b460843 100644 --- a/doc/lxc-monitor.sgml.in +++ b/doc/lxc-monitor.sgml.in @@ -63,6 +63,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to monitor all the containers, several of them or just one. + + The -P, --lxcpath=PATH option may be specified multiple + times to monitor more than one container path. Note however that + containers with the same name in multiple paths will be + indistinguishable in the output. + + &commonoptions; diff --git a/src/lxc/arguments.c b/src/lxc/arguments.c index f61c6eb..5f1c1af 100644 --- a/src/lxc/arguments.c +++ b/src/lxc/arguments.c @@ -150,13 +150,32 @@ See the %s man page for further information.\n\n", exit(code); } +static int lxc_arguments_lxcpath_add(struct lxc_arguments *args, +const char *lxcpath) +{ + if (args->lxcpath_additional != -1 && + args->lxcpath_cnt > args->lxcpath_additional) { + fprintf(stderr, "This command only accepts %d -P,--lxcpath arguments\n", + args->lxcpath_additional + 1); + exit(EXIT_FAILURE); + } + + args->lxcpath = realloc(args->lxcpath, (args->lxcpath_cnt + 1) * +sizeof(args->lxcpath[0])); + if (args->lxcpath == NULL) { + lxc_error(args, "no memory"); + return ENOMEM; + } + args->lxcpath[args->lxcpath_cnt++] = lxcpath; + return 0; +} + extern int lxc_arguments_parse(struct lxc_arguments *args, int argc, char * const argv[]) { char shortopts[256]; int ret = 0; - args->lxcpath = default_lxc_path(); ret = build_shortopts(args->options, shortopts, sizeof(shortopts)); if (ret < 0) { lxc_error(args, "build_shortopts() failed : %s", @@ -176,7 +195,11 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, case 'l': args->log_priority = optarg; break; case 'c': args->console = optarg; break; case 'q': args->quiet = 1; break; - case 'P': args->lxcpath = optarg; break; + case 'P': + ret = lxc_arguments_lxcpath_add(args, optarg); + if (ret < 0) + return ret; + break; case OPT_USAGE: print_usage(args->options, args); case '?': print_help(args, 1); case 'h': print_help(args, 0); @@ -195,6 +218,13 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, args->argv = &argv[optind]; args->argc = argc - optind; + /* If no lxcpaths were given, use default */ + if (!args->lxcpath_cnt) { + ret = lxc_arguments_lxcpath_add(args, default_lxc_path()); + if (ret < 0) + return ret; + } + /* Check the command options */ if (!args->name) { diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h index 6f6826b..002a919 100644 --- a/src/lxc/arguments.h +++ b/src/lxc/arguments.h @@ -47,7 +47,10 @@ struct lxc_arguments { const char *console; const char *console_log; const char *pidfile; - const char *lxcpath; + const char **lxcpath; + int lxcpath_cnt; + /* set to 0 to accept only 1 lxcpath, -1 for unlimited */ + int lxcpath_additional; /* for lxc-checkpoint/restart */ const char *statefile; diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index db921f0..9057757 100644 --- a/src/lxc/lxc.h +++ b/src/lxc/lxc.h @@ -28,6 +28,7 @@ extern "C" { #endif #include +#include #include struct lxc_msg; @@ -77,17 +78,37 @@ extern int lxc_execute(const char *name, char *const argv[], int quiet, extern int lxc_monitor_open(const char *lxcpath); /* - * Read the state of the container if this one has changed - * The
Re: [lxc-devel] [PATCH v2] lxc-monitor multiple paths
Quoting Dwight Engen (dwight.en...@oracle.com): > Signed-off-by: Dwight Engen Acked-by: Serge E. Hallyn > --- > doc/lxc-monitor.sgml.in | 7 ++ > src/lxc/arguments.c | 34 +++-- > src/lxc/arguments.h | 5 - > src/lxc/lxc.h| 31 +- > src/lxc/lxc_attach.c | 8 +++ > src/lxc/lxc_cgroup.c | 6 ++--- > src/lxc/lxc_checkpoint.c | 2 +- > src/lxc/lxc_console.c| 4 ++-- > src/lxc/lxc_execute.c| 6 ++--- > src/lxc/lxc_freeze.c | 4 ++-- > src/lxc/lxc_info.c | 6 ++--- > src/lxc/lxc_kill.c | 4 ++-- > src/lxc/lxc_monitor.c| 35 + > src/lxc/lxc_restart.c| 6 ++--- > src/lxc/lxc_start.c | 6 ++--- > src/lxc/lxc_stop.c | 4 ++-- > src/lxc/lxc_unfreeze.c | 4 ++-- > src/lxc/lxc_wait.c | 5 +++-- > src/lxc/monitor.c| 57 > +++- > 19 files changed, 165 insertions(+), 69 deletions(-) > > diff --git a/doc/lxc-monitor.sgml.in b/doc/lxc-monitor.sgml.in > index 336061d..b460843 100644 > --- a/doc/lxc-monitor.sgml.in > +++ b/doc/lxc-monitor.sgml.in > @@ -63,6 +63,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA > 02111-1307 USA >to monitor all the containers, several of them or just one. > > > + > + The -P, --lxcpath=PATH option may be specified > multiple > + times to monitor more than one container path. Note however that > + containers with the same name in multiple paths will be > + indistinguishable in the output. > + > + > > >&commonoptions; > diff --git a/src/lxc/arguments.c b/src/lxc/arguments.c > index f61c6eb..5f1c1af 100644 > --- a/src/lxc/arguments.c > +++ b/src/lxc/arguments.c > @@ -150,13 +150,32 @@ See the %s man page for further information.\n\n", > exit(code); > } > > +static int lxc_arguments_lxcpath_add(struct lxc_arguments *args, > + const char *lxcpath) > +{ > + if (args->lxcpath_additional != -1 && > + args->lxcpath_cnt > args->lxcpath_additional) { > + fprintf(stderr, "This command only accepts %d -P,--lxcpath > arguments\n", > + args->lxcpath_additional + 1); > + exit(EXIT_FAILURE); > + } > + > + args->lxcpath = realloc(args->lxcpath, (args->lxcpath_cnt + 1) * > + sizeof(args->lxcpath[0])); > + if (args->lxcpath == NULL) { > + lxc_error(args, "no memory"); > + return ENOMEM; > + } > + args->lxcpath[args->lxcpath_cnt++] = lxcpath; > + return 0; > +} > + > extern int lxc_arguments_parse(struct lxc_arguments *args, > int argc, char * const argv[]) > { > char shortopts[256]; > int ret = 0; > > - args->lxcpath = default_lxc_path(); > ret = build_shortopts(args->options, shortopts, sizeof(shortopts)); > if (ret < 0) { > lxc_error(args, "build_shortopts() failed : %s", > @@ -176,7 +195,11 @@ extern int lxc_arguments_parse(struct lxc_arguments > *args, > case 'l': args->log_priority = optarg; break; > case 'c': args->console = optarg; break; > case 'q': args->quiet = 1; break; > - case 'P': args->lxcpath = optarg; break; > + case 'P': > + ret = lxc_arguments_lxcpath_add(args, optarg); > + if (ret < 0) > + return ret; > + break; > case OPT_USAGE: print_usage(args->options, args); > case '?': print_help(args, 1); > case 'h': print_help(args, 0); > @@ -195,6 +218,13 @@ extern int lxc_arguments_parse(struct lxc_arguments > *args, > args->argv = &argv[optind]; > args->argc = argc - optind; > > + /* If no lxcpaths were given, use default */ > + if (!args->lxcpath_cnt) { > + ret = lxc_arguments_lxcpath_add(args, default_lxc_path()); > + if (ret < 0) > + return ret; > + } > + > /* Check the command options */ > > if (!args->name) { > diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h > index 6f6826b..002a919 100644 > --- a/src/lxc/arguments.h > +++ b/src/lxc/arguments.h > @@ -47,7 +47,10 @@ struct lxc_arguments { > const char *console; > const char *console_log; > const char *pidfile; > - const char *lxcpath; > + const char **lxcpath; > + int lxcpath_cnt; > + /* set to 0 to accept only 1 lxcpath, -1 for unlimited */ > + int lxcpath_additional; > > /* for lxc-checkpoint/restart */ > const char *statefile; > diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h > index db921f0..9057757 100644 > --- a/src/lxc/lxc.h > +++ b/src/lxc/lxc.h > @@ -28,6 +28,7 @@ extern "C" { > #endif > > #include > +#include >
[lxc-devel] [PATCH] lxc-ps: handle cgroup collisions
A few months ago cgroup handling in lxc was updated so that if /sys/fs/cgroup/$cgroup/lxc/$container already exists (most often due to another container by the same name under a different lxcpath), then /sys/fs/cgroup/$cgroup/lxc/${container}-N would be used. lxc-ps was never updated to handle this. Fix that. (Note, the ns cgroup is being special cased there, but I don't really believe ns cgroup works any more.) It would be preferable to rewrite lxc-ps in python or in C, but this at least makes the basic lxc-ps work in the case of multiple containers with the same name. Signed-off-by: Serge Hallyn --- src/lxc/lxc-ps.in | 18 +- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lxc/lxc-ps.in b/src/lxc/lxc-ps.in index 55a05ce..eaf5002 100644 --- a/src/lxc/lxc-ps.in +++ b/src/lxc/lxc-ps.in @@ -17,9 +17,11 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +. @DATADIR@/lxc/lxc.functions + usage() { -echo "usage: $(basename $0) [--lxc | --host | --name NAME] [--] [PS_OPTIONS...]" >&2 +echo "usage: $(basename $0) [-P PATH] [--lxc | --host | --name NAME] [[--] [PS_OPTIONS...]" >&2 } help() { @@ -31,6 +33,7 @@ help() { echo " --hostshow processes not related to any container, i.e. to the host" >&2 echo " --name NAME show processes in the specified container" >&2 echo " (multiple containers can be separated by commas)" >&2 +echo " -P PATH show container in lxcpath PATH" >&2 echo " PS_OPTIONSps command options (see \`ps --help')" >&2 } @@ -65,7 +68,7 @@ get_parent_cgroup() # (do not append '/lxc' if the hierarchy contains the 'ns' subsystem) case ",$subsystems," in *,ns,*) parent_cgroup="${mountpoint}${init_cgroup%/}";; -*) parent_cgroup="${mountpoint}${init_cgroup%/}/lxc";; +*) parent_cgroup="${mountpoint}${init_cgroup%/}";; esac break done @@ -83,6 +86,8 @@ while true; do list_container_processes=1; shift;; --host) list_container_processes=-1; shift;; +-P|--lxcpath) +lxc_path=$2; shift 2;; --) shift; break;; *) @@ -111,9 +116,12 @@ for container in ${containers}; do container_field_width=${#container} fi -if [ -f "$parent_cgroup/$container/tasks" ]; then -tasks_files="$tasks_files $parent_cgroup/$container/tasks" -fi +if lxc-info -P $lxc_path -t RUNNING -n z1; then +initpid=`lxc-info -P $lxc_path -p -n $container | awk -F: '{ print $2 }' | awk '{ print $1 }'` +cgroup=`head -n 1 /proc/$initpid/cgroup | awk -F: '{ print $3}'` +if [ -f "$parent_cgroup/$cgroup/tasks" ]; then +tasks_files="$tasks_files $parent_cgroup$cgroup/tasks" +fi done # first file is stdin, the rest are the container tasks -- 1.8.1.2 -- Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel