[CRIU] [PATCH 6/8] files: Fix restoration of ghost cwd (and root)

Pavel Emelyanov xemul at parallels.com
Thu Jul 3 08:08:14 PDT 2014


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: Pavel Emelyanov <xemul at parallels.com>
---
 files.c            | 24 ++++++++++++++++++------
 include/rst_info.h |  4 ++--
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/files.c b/files.c
index 2326b36..023561e 100644
--- a/files.c
+++ b/files.c
@@ -1028,15 +1028,15 @@ int restore_fs(struct pstree_item *me)
 	 * 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) {
-		pr_err("Can't open root %#x\n", ri->root_id);
+		pr_err("Can't open root\n");
 		goto out;
 	}
 
-	dd_cwd = open_reg_by_id(ri->cwd_id);
+	dd_cwd = open_reg_fd(ri->cwd);
 	if (dd_cwd < 0) {
-		pr_err("Can't open cwd %#x\n", ri->cwd_id);
+		pr_err("Can't open cwd\n");
 		goto out;
 	}
 
@@ -1086,14 +1086,26 @@ int prepare_fs_pid(struct pstree_item *item)
 
 	close(ifd);
 
-	ri->cwd_id = fe->cwd_id;
-	ri->root_id = fe->root_id;
+	ri->cwd = collect_special_file(fe->cwd_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->umask = fe->umask;
 
 	fs_entry__free_unpacked(fe, NULL);
 	return 0;
 
+out_f:
+	fs_entry__free_unpacked(fe, NULL);
 out_i:
 	close(ifd);
 out:
diff --git a/include/rst_info.h b/include/rst_info.h
index a8e0d38..e89be02 100644
--- a/include/rst_info.h
+++ b/include/rst_info.h
@@ -50,8 +50,8 @@ struct rst_info {
 		futex_t			pgrp_set;
 	};
 
-	u32			cwd_id;
-	u32			root_id;
+	struct file_desc	*cwd;
+	struct file_desc	*root;
 	bool			has_umask;
 	u32			umask;
 };
-- 
1.8.3.1




More information about the CRIU mailing list