Skip to contentSkip to conversation

cr: deal with fs_struct

PATCH In review Alexey Dobriyan 1 participant 1 message Apr 10, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 23/30 cr: deal with fs_struct

Dump umask, root, pwd.

root, pwd are dumped as names returned by d_path.

FIXME, FIXME, FIXME: think through what to do with overmount and vfsmount themselves!!!

FIXME: restore root, pwd, tsk->fs itself

---

 include/linux/cr.h  |   12 +++
 kernel/cr/Makefile  |    1 
 kernel/cr/cpt-sys.c |    6 +
 kernel/cr/cr-fs.c   |  194 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/cr/cr-task.c |    2 
 kernel/cr/cr.h      |    4 +
 6 files changed, 219 insertions(+)
include/linux/cr.h +12 -0
@@ -41,6 +41,7 @@ struct cr_object_header {
 #define CR_OBJ_PID		10
 #define CR_OBJ_FILES_STRUCT	11
 #define CR_OBJ_FD		12
+#define CR_OBJ_FS_STRUCT	13
 	__u32	cr_type;	/* object type */
 	__u32	cr_len;		/* object length in bytes including header */
 } __packed;
@@ -61,6 +62,7 @@ struct cr_image_task_struct {
 	cr_pos_t	cr_pos_real_parent;
 	cr_pos_t	cr_pos_mm;
 	cr_pos_t	cr_pos_pids[3];
+	cr_pos_t	cr_pos_fs;
 	cr_pos_t	cr_pos_files;
 	cr_pos_t	cr_pos_nsproxy;
 
@@ -231,6 +233,16 @@ struct cr_image_vma_content {
 	/* __u8 cr_data[cr_nr_pages * cr_page_size]; */
 } __packed;
 
+struct cr_image_fs_struct {
+	struct cr_object_header cr_hdr;
+
+	__u32		cr_umask;
+	__u32		cr_root_len;
+	__u32		cr_pwd_len;
+	/* __u8 cr_root[cr_root_len] */
+	/* __u8 cr_pwd[cr_pwd_len] */
+} __packed;
+
 struct cr_image_files_struct {
 	struct cr_object_header cr_hdr;
 } __packed;
kernel/cr/Makefile +1 -0
@@ -2,6 +2,7 @@ obj-$(CONFIG_CR) += cr.o
 cr-y := cpt-sys.o rst-sys.o
 cr-y += cr-context.o
 cr-y += cr-file.o
+cr-y += cr-fs.o
 cr-y += cr-mm.o
 cr-y += cr-nsproxy.o
 cr-y += cr-pid.o
kernel/cr/cpt-sys.c +6 -0
@@ -83,6 +83,9 @@ static int cr_collect(struct cr_context *ctx)
 	rv = cr_collect_all_file(ctx);
 	if (rv < 0)
 		return rv;
+	rv = cr_collect_all_fs_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = cr_collect_all_pid(ctx);
 	if (rv < 0)
 		return rv;
@@ -131,6 +134,9 @@ static int cr_dump(struct cr_context *ctx)
 	rv = cr_dump_all_files_struct(ctx);
 	if (rv < 0)
 		return rv;
+	rv = cr_dump_all_fs_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = cr_dump_all_uts_ns(ctx);
 	if (rv < 0)
 		return rv;

new file mode 100644

kernel/cr/cr-fs.c new file +194 -0

194 lines not on this page · raw message

kernel/cr/cr-task.c +2 -0
@@ -127,6 +127,8 @@ static int cr_dump_task_struct(struct cr_context *ctx, struct cr_object *obj)
 		i->cr_pos_pids[2] = tmp->o_pos;
 	else
 		i->cr_pos_pids[2] = CR_POS_UNDEF;
+	tmp = cr_find_obj_by_ptr(ctx, tsk->fs, CR_CTX_FS_STRUCT);
+	i->cr_pos_fs = tmp->o_pos;
 	tmp = cr_find_obj_by_ptr(ctx, tsk->files, CR_CTX_FILES_STRUCT);
 	i->cr_pos_files = tmp->o_pos;
 
kernel/cr/cr.h +4 -0
@@ -24,6 +24,7 @@ struct cr_object {
 enum cr_context_obj_type {
 	CR_CTX_FILE,
 	CR_CTX_FILES_STRUCT,
+	CR_CTX_FS_STRUCT,
 	CR_CTX_MM_STRUCT,
 	CR_CTX_NSPROXY,
 	CR_CTX_PID,
@@ -73,6 +74,7 @@ static inline void __user *cr_restore_ptr(__u64 ptr)
 
 int cr_collect_all_files_struct(struct cr_context *ctx);
 int cr_collect_all_file(struct cr_context *ctx);
+int cr_collect_all_fs_struct(struct cr_context *ctx);
 int cr_collect_all_mm_struct(struct cr_context *ctx);
 int cr_collect_all_nsproxy(struct cr_context *ctx);
 int cr_collect_all_pid_ns(struct cr_context *ctx);
@@ -82,6 +84,7 @@ int cr_collect_all_uts_ns(struct cr_context *ctx);
 
 int cr_dump_all_files_struct(struct cr_context *ctx);
 int cr_dump_all_file(struct cr_context *ctx);
+int cr_dump_all_fs_struct(struct cr_context *ctx);
 int cr_dump_all_mm_struct(struct cr_context *ctx);
 int cr_dump_all_nsproxy(struct cr_context *ctx);
 int cr_dump_all_pid_ns(struct cr_context *ctx);
@@ -91,6 +94,7 @@ int cr_dump_all_uts_ns(struct cr_context *ctx);
 
 int cr_restore_files_struct(struct cr_context *ctx, loff_t pos);
 int cr_restore_file(struct cr_context *ctx, loff_t pos);
+int cr_restore_fs_struct(struct cr_context *ctx, loff_t pos);
 int cr_restore_mm_struct(struct cr_context *ctx, loff_t pos);
 int cr_restore_nsproxy(struct cr_context *ctx, loff_t pos);
 int cr_restore_pid_ns(struct cr_context *ctx, loff_t pos);