Skip to contentSkip to conversation

cr: deal with opened files

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

lore
Share & tools
lore
#0 lore raw

PATCH 22/30 cr: deal with opened files

C/R tsk->files and opened files!
fd should have struct file::checkpoint ;-)

---

 include/linux/cr.h  |   16 +++
 kernel/cr/cpt-sys.c |    6 +
 kernel/cr/cr-file.c |  249 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/cr/cr-task.c |    5 +
 kernel/cr/cr.h      |    4 
 5 files changed, 280 insertions(+)
include/linux/cr.h +16 -0
@@ -39,6 +39,8 @@ struct cr_object_header {
 #define CR_OBJ_UTS_NS		8
 #define CR_OBJ_PID_NS		9
 #define CR_OBJ_PID		10
+#define CR_OBJ_FILES_STRUCT	11
+#define CR_OBJ_FD		12
 	__u32	cr_type;	/* object type */
 	__u32	cr_len;		/* object length in bytes including header */
 } __packed;
@@ -59,6 +61,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_files;
 	cr_pos_t	cr_pos_nsproxy;
 
 	__u8		cr_comm[16];
@@ -228,6 +231,10 @@ struct cr_image_vma_content {
 	/* __u8 cr_data[cr_nr_pages * cr_page_size]; */
 } __packed;
 
+struct cr_image_files_struct {
+	struct cr_object_header cr_hdr;
+} __packed;
+
 struct cr_image_file {
 	struct cr_object_header cr_hdr;
 
@@ -245,6 +252,15 @@ struct cr_image_file {
 	/* __u8	cr_name[cr_name_len] */
 } __packed;
 
+struct cr_image_fd {
+	struct cr_object_header cr_hdr;
+
+	cr_pos_t	cr_pos_file;
+	__u32		cr_fd;
+#define CR_FD_FLAGS_CLOEXEC	(1 << 0)
+	__u32		cr_fd_flags;
+} __packed;
+
 struct cr_image_pid {
 	struct cr_object_header cr_hdr;
 
kernel/cr/cpt-sys.c +6 -0
@@ -77,6 +77,9 @@ static int cr_collect(struct cr_context *ctx)
 	rv = cr_collect_all_mm_struct(ctx);
 	if (rv < 0)
 		return rv;
+	rv = cr_collect_all_files_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = cr_collect_all_file(ctx);
 	if (rv < 0)
 		return rv;
@@ -125,6 +128,9 @@ static int cr_dump(struct cr_context *ctx)
 	rv = cr_dump_all_file(ctx);
 	if (rv < 0)
 		return rv;
+	rv = cr_dump_all_files_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = cr_dump_all_uts_ns(ctx);
 	if (rv < 0)
 		return rv;
kernel/cr/cr-file.c +249 -0

258 lines not on this page · raw message

kernel/cr/cr-task.c +5 -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->files, CR_CTX_FILES_STRUCT);
+	i->cr_pos_files = tmp->o_pos;
 
 	BUILD_BUG_ON(TASK_COMM_LEN != 16);
 	strlcpy((char *)i->cr_comm, (const char *)tsk->comm, sizeof(i->cr_comm));
@@ -186,6 +188,9 @@ static int task_struct_restorer(void *_tsk_ctx)
 	rv = cr_restore_nsproxy(ctx, i->cr_pos_nsproxy);
 	if (rv < 0)
 		goto out;
+	rv = cr_restore_files_struct(ctx, i->cr_pos_files);
+	if (rv < 0)
+		return rv;
 	rv = cr_restore_pid(ctx, i);
 	if (rv < 0)
 		goto out;
kernel/cr/cr.h +4 -0
@@ -23,6 +23,7 @@ struct cr_object {
 /* Not visible to userspace! */
 enum cr_context_obj_type {
 	CR_CTX_FILE,
+	CR_CTX_FILES_STRUCT,
 	CR_CTX_MM_STRUCT,
 	CR_CTX_NSPROXY,
 	CR_CTX_PID,
@@ -70,6 +71,7 @@ static inline void __user *cr_restore_ptr(__u64 ptr)
 	return (void __user *)(unsigned long)ptr;
 }
 
+int cr_collect_all_files_struct(struct cr_context *ctx);
 int cr_collect_all_file(struct cr_context *ctx);
 int cr_collect_all_mm_struct(struct cr_context *ctx);
 int cr_collect_all_nsproxy(struct cr_context *ctx);
@@ -78,6 +80,7 @@ int cr_collect_all_pid(struct cr_context *ctx);
 int cr_collect_all_task_struct(struct cr_context *ctx);
 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_mm_struct(struct cr_context *ctx);
 int cr_dump_all_nsproxy(struct cr_context *ctx);
@@ -86,6 +89,7 @@ int cr_dump_all_pid(struct cr_context *ctx);
 int cr_dump_all_task_struct(struct cr_context *ctx);
 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_mm_struct(struct cr_context *ctx, loff_t pos);
 int cr_restore_nsproxy(struct cr_context *ctx, loff_t pos);