[CRIU] [PATCH 11/18] fd: Split file_master

Pavel Emelyanov xemul at virtuozzo.com
Mon Jul 10 12:40:21 MSK 2017


In SCM patch we'll need to generate temporary fdinfo entry
for a task that will send descriptors via sockets. Sometimes
the files in questions will NOT have any other fdinfo-s (if
they are SCM-sent and closed), so we need a helper that
would either give us existing fdinfo or say there's no such.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/files.c         | 17 ++++++++++++++---
 criu/include/files.h |  1 +
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/criu/files.c b/criu/files.c
index 0387803..bd137df 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -206,16 +206,27 @@ void wait_fds_event(void)
 	clear_fds_event();
 }
 
+struct fdinfo_list_entry *try_file_master(struct file_desc *d)
+{
+	if (list_empty(&d->fd_info_head))
+		return NULL;
+
+	return list_first_entry(&d->fd_info_head,
+			struct fdinfo_list_entry, desc_list);
+}
+
 struct fdinfo_list_entry *file_master(struct file_desc *d)
 {
-	if (list_empty(&d->fd_info_head)) {
+	struct fdinfo_list_entry *fle;
+
+	fle = try_file_master(d);
+	if (!fle) {
 		pr_err("Empty list on file desc id %#x(%d)\n", d->id,
 				d->ops ? d->ops->type : -1);
 		BUG();
 	}
 
-	return list_first_entry(&d->fd_info_head,
-			struct fdinfo_list_entry, desc_list);
+	return fle;
 }
 
 void show_saved_files(void)
diff --git a/criu/include/files.h b/criu/include/files.h
index 3dc18df..eeae8e0 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -142,6 +142,7 @@ int predump_task_files(int pid);
 
 extern void file_desc_init(struct file_desc *d, u32 id, struct file_desc_ops *ops);
 extern int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops);
+extern struct fdinfo_list_entry *try_file_master(struct file_desc *d);
 extern struct fdinfo_list_entry *file_master(struct file_desc *d);
 extern struct file_desc *find_file_desc_raw(int type, u32 id);
 
-- 
2.1.4



More information about the CRIU mailing list