Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore: cleanup cgroup properly in error path #1541

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions criu/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1771,19 +1771,19 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
}

if (make_yard(cg_yard))
goto err;
return -1;
}

pr_debug("Opening %s as cg yard\n", cg_yard);
i = open(cg_yard, O_DIRECTORY);
if (i < 0) {
pr_perror("Can't open cgyard");
goto err;
return -1;
}

ret = install_service_fd(CGROUP_YARD, i);
if (ret < 0)
goto err;
return -1;

paux[off++] = '/';

Expand All @@ -1794,7 +1794,7 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)

if (ctrl->n_cnames < 1) {
pr_err("Each cg_controller_entry must have at least 1 controller\n");
goto err;
return -1;
}

ctl_off += ctrl_dir_and_opt(ctrl,
Expand All @@ -1811,11 +1811,11 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
pr_debug("\tMaking controller dir %s (%s)\n", paux, opt);
if (mkdir(paux, 0700)) {
pr_perror("\tCan't make controller dir %s", paux);
goto err;
return -1;
}
if (mount("none", paux, fstype, 0, opt) < 0) {
pr_perror("\tCan't mount controller dir %s", paux);
goto err;
return -1;
}
}

Expand All @@ -1827,14 +1827,10 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
if (opts.manage_cgroups &&
prepare_cgroup_dirs(ctrl->cnames, ctrl->n_cnames, yard, yard_off,
ctrl->dirs, ctrl->n_dirs))
goto err;
return -1;
}

return 0;

err:
fini_cgroup();
return -1;
}

static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controllers,
Expand Down
15 changes: 7 additions & 8 deletions criu/cr-restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ static int crtools_prepare_shared(void)
if (tty_prep_fds())
return -1;

if (prepare_cgroup())
return -1;

return 0;
}

Expand Down Expand Up @@ -2459,8 +2456,6 @@ static int restore_root_task(struct pstree_item *init)
if (restore_freezer_state())
pr_err("Unable to restore freezer state\n");

fini_cgroup();

/* Detaches from processes and they continue run through sigreturn. */
if (finalize_restore_detach())
goto out_kill_network_unlocked;
Expand Down Expand Up @@ -2507,7 +2502,6 @@ static int restore_root_task(struct pstree_item *init)
}

out:
fini_cgroup();
depopulate_roots_yard(mnt_ns_fd, true);
stop_usernsd();
__restore_switch_stage(CR_STATE_FAIL);
Expand Down Expand Up @@ -2597,13 +2591,18 @@ int cr_restore_tasks(void)
if (crtools_prepare_shared() < 0)
goto err;

if (prepare_cgroup())
goto clean_cgroup;

if (criu_signals_setup() < 0)
goto err;
goto clean_cgroup;

if (prepare_lazy_pages_socket() < 0)
goto err;
goto clean_cgroup;

ret = restore_root_task(root_item);
clean_cgroup:
fini_cgroup();
avagin marked this conversation as resolved.
Show resolved Hide resolved
err:
cr_plugin_fini(CR_PLUGIN_STAGE__RESTORE, ret);
return ret;
Expand Down