[11/18] fd: Split file_master

Submitted by Pavel Emelyanov on July 10, 2017, 9:40 a.m.

Details

Message ID 1a8dd826-f81b-08e2-0ad7-004584d7ab08@virtuozzo.com
State New
Series "Support descriptors sent over unix sockets"
Headers show

Commit Message

Pavel Emelyanov July 10, 2017, 9:40 a.m.
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@virtuozzo.com>
---
 criu/files.c         | 17 ++++++++++++++---
 criu/include/files.h |  1 +
 2 files changed, 15 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

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);
 

Comments

Pavel Emelyanov July 13, 2017, 11:25 a.m.
With [PATCH 18/18 v2] this patch is no longer needed.