Commit a919dbc9 authored by Pavel Emelyanov's avatar Pavel Emelyanov

files: Fix restoration of ghost cwd (and root)

When cwd is removed (it can be) we need to collect the respective
file_desc before starting opening any files to properly handle
ghost refcounts. Otherwise we will miss one refcount from the
cwd's on ghost, which in turn will either BUG inside ghost removal,
or will fail the cwd due to the respective dir being removed too
early.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent ba8671b4
...@@ -1028,15 +1028,15 @@ int restore_fs(struct pstree_item *me) ...@@ -1028,15 +1028,15 @@ int restore_fs(struct pstree_item *me)
* be able to open the cwd one after we chroot. * be able to open the cwd one after we chroot.
*/ */
dd_root = open_reg_by_id(ri->root_id); dd_root = open_reg_fd(ri->root);
if (dd_root < 0) { if (dd_root < 0) {
pr_err("Can't open root %#x\n", ri->root_id); pr_err("Can't open root\n");
goto out; goto out;
} }
dd_cwd = open_reg_by_id(ri->cwd_id); dd_cwd = open_reg_fd(ri->cwd);
if (dd_cwd < 0) { if (dd_cwd < 0) {
pr_err("Can't open cwd %#x\n", ri->cwd_id); pr_err("Can't open cwd\n");
goto out; goto out;
} }
...@@ -1086,14 +1086,26 @@ int prepare_fs_pid(struct pstree_item *item) ...@@ -1086,14 +1086,26 @@ int prepare_fs_pid(struct pstree_item *item)
close(ifd); close(ifd);
ri->cwd_id = fe->cwd_id; ri->cwd = collect_special_file(fe->cwd_id);
ri->root_id = fe->root_id; if (!ri->cwd) {
pr_err("Can't find task cwd file\n");
goto out_f;
}
ri->root = collect_special_file(fe->root_id);
if (!ri->root) {
pr_err("Can't find task root file\n");
goto out_f;
}
ri->has_umask = fe->has_umask; ri->has_umask = fe->has_umask;
ri->umask = fe->umask; ri->umask = fe->umask;
fs_entry__free_unpacked(fe, NULL); fs_entry__free_unpacked(fe, NULL);
return 0; return 0;
out_f:
fs_entry__free_unpacked(fe, NULL);
out_i: out_i:
close(ifd); close(ifd);
out: out:
......
...@@ -50,8 +50,8 @@ struct rst_info { ...@@ -50,8 +50,8 @@ struct rst_info {
futex_t pgrp_set; futex_t pgrp_set;
}; };
u32 cwd_id; struct file_desc *cwd;
u32 root_id; struct file_desc *root;
bool has_umask; bool has_umask;
u32 umask; u32 umask;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment