[09/16] fd: Split file_master

Submitted by Pavel Emelianov on July 6, 2017, 4:16 p.m.

Details

Message ID 0b6d859d-92b6-c697-093b-958d81b2fbe4@virtuozzo.com
State Accepted
Series "Support descriptors sent over unix sockets"
Commit 1f5375432d8f199bcad507f70a3b56c077d52d35
Headers show

Commit Message

Pavel Emelianov July 6, 2017, 4:16 p.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 d0297fe..1acdeb4 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -202,16 +202,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);