[CRIU] [PATCH] cgroup: open cgroup mount point
Andrew Vagin
avagin at parallels.com
Tue Jul 15 04:28:10 PDT 2014
Sorry, this doesn't work too
==================================== ERROR ====================================
Test: zdtm/live/static/cwd01, Namespace: 1
Dump log : /root/criu/test/dump/cwd01/10361/1/dump.log
--------------------------------- grep Error ---------------------------------
(00.063024) Error (pie/util.c:31): Can't remove tmp dir .criu.cgmounts.cU2sCW: -16
(00.063052) Error (cr-dump.c:1601): Dump core (pid: 10361) failed with -1
(00.078414) Error (cr-dump.c:1914): Dumping FAILED.
------------------------------------- END -------------------------------------
================================= ERROR OVER =================================
On Tue, Jul 15, 2014 at 03:19:15PM +0400, Andrew Vagin wrote:
> Otherwise it can disappear in any moment.
>
> For example the test system executes tests concurrently and sometimes one
> test looks up a mount point, which has been mounted by another test.
>
> ==================================== ERROR ====================================
> Test: zdtm/live/static/inotify00, Namespace: 1
> Dump log : /var/lib/jenkins/jobs/CRIU-dump/workspace/test/dump/inotify00/15535/1/dump.log
> --------------------------------- grep Error ---------------------------------
> (00.021951) Error (cgroup.c:409): cg: failed walking /var/lib/jenkins/jobs/CRIU-dump/workspace/test/dump/signalfd00/15538/1/.criu.cgmounts.UGj28v/ for empty cgroups
> (00.021967) Error (cr-dump.c:1601): Dump core (pid: 15535) failed with -1
> (00.025509) Error (cr-dump.c:1914): Dumping FAILED.
> ------------------------------------- END -------------------------------------
> ================================= ERROR OVER =================================
>
> Reported-by: Jenkins Criuovich
> Cc: Tycho Andersen <tycho.andersen at canonical.com>
> Signed-off-by: Andrew Vagin <avagin at openvz.org>
> ---
> cgroup.c | 33 ++++++++++++++++++++-------------
> 1 file changed, 20 insertions(+), 13 deletions(-)
>
> diff --git a/cgroup.c b/cgroup.c
> index 5114935..16abb64 100644
> --- a/cgroup.c
> +++ b/cgroup.c
> @@ -14,6 +14,7 @@
> #include "proc_parse.h"
> #include "util.h"
> #include "fdset.h"
> +#include "util-pie.h"
> #include "protobuf.h"
> #include "protobuf/core.pb-c.h"
> #include "protobuf/cgroup.pb-c.h"
> @@ -168,10 +169,11 @@ int parse_cg_info(void)
> return 0;
> }
>
> -static int get_cgroup_mount_point(const char *controller, char *path)
> +static int open_cgroup_mount_point(const char *controller)
> {
> struct mount_info *m;
> char name[1024];
> + int fd;
>
> for (m = cg_mntinfo; m != NULL; m = m->next) {
> if (strcmp(m->fstype->name, "cgroup") == 0) {
> @@ -199,8 +201,14 @@ static int get_cgroup_mount_point(const char *controller, char *path)
>
> if (strcmp(name, controller) == 0) {
> /* skip the leading '.' in mountpoint */
> - strcpy(path, m->mountpoint + 1);
> - return 0;
> +
> + fd = open(m->mountpoint + 1, O_DIRECTORY);
> + if (fd < 0) {
> + pr_perror("Unable to open %s", m->mountpoint + 1);
> + continue;
> + }
> +
> + return fd;
> }
> }
> }
> @@ -346,11 +354,11 @@ static int collect_cgroups(struct list_head *ctls)
> {
> struct cg_ctl *cc;
> int ret = 0;
> + int fd = -1;
>
> list_for_each_entry(cc, ctls, l) {
> char path[PATH_MAX];
> - char *name, mount_point[PATH_MAX], prefix[] = ".criu.cgmounts.XXXXXX";
> - bool temp_mount = false;
> + char *name, prefix[] = ".criu.cgmounts.XXXXXX";
> struct cg_controller *cg;
>
> if (strstartswith(cc->name, "name="))
> @@ -358,13 +366,13 @@ static int collect_cgroups(struct list_head *ctls)
> else
> name = cc->name;
>
> - if (get_cgroup_mount_point(name, mount_point) < 0) {
> + fd = open_cgroup_mount_point(name);
> + if (fd < 0) {
> /* Someone is trying to dump a process that is in
> * a controller that isn't mounted, so we mount it for
> * them.
> */
> char opts[1024];
> - temp_mount = true;
>
> if (mkdtemp(prefix) == NULL) {
> pr_perror("can't make dir for cg mounts\n");
> @@ -382,10 +390,12 @@ static int collect_cgroups(struct list_head *ctls)
> return -1;
> }
>
> - strcpy(mount_point, prefix);
> + fd = open_detach_mount(prefix);
> + if (fd < 0)
> + return -1;
> }
>
> - snprintf(path, PATH_MAX, "%s/%s", mount_point, cc->path);
> + snprintf(path, PATH_MAX, "/proc/self/fd/%d/%s", fd, cc->path);
>
> current_controller = NULL;
>
> @@ -420,10 +430,7 @@ static int collect_cgroups(struct list_head *ctls)
> }
>
> out:
> - if (temp_mount) {
> - umount(prefix);
> - rmdir(prefix);
> - }
> + close_safe(&fd);
>
> if (ret < 0)
> return ret;
> --
> 1.9.3
>
More information about the CRIU
mailing list