[CRIU] [PATCH 4/9] files: Add file_desc_init helper

Cyrill Gorcunov gorcunov at openvz.org
Thu Oct 16 03:27:23 PDT 2014


To use it in tty code even when file
descriptor is not added into files chain.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 files.c         | 13 +++++++++----
 include/files.h |  1 +
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/files.c b/files.c
index 04f6a0127b59..3bd5830f1e6b 100644
--- a/files.c
+++ b/files.c
@@ -60,14 +60,19 @@ int prepare_shared_fdinfo(void)
 	return 0;
 }
 
-int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops)
+void file_desc_init(struct file_desc *d, u32 id, struct file_desc_ops *ops)
 {
-	d->id = id;
-	d->ops = ops;
 	INIT_LIST_HEAD(&d->fd_info_head);
+	INIT_HLIST_NODE(&d->hash);
 
-	hlist_add_head(&d->hash, &file_desc_hash[id % FDESC_HASH_SIZE]);
+	d->id	= id;
+	d->ops	= ops;
+}
 
+int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops)
+{
+	file_desc_init(d, id, ops);
+	hlist_add_head(&d->hash, &file_desc_hash[id % FDESC_HASH_SIZE]);
 	return 0; /* this is to make tail-calls in collect_one_foo look nice */
 }
 
diff --git a/include/files.h b/include/files.h
index 07167cbc0765..4c9300d7d6e4 100644
--- a/include/files.h
+++ b/include/files.h
@@ -135,6 +135,7 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
 		struct parasite_drain_fd *dfds);
 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 *file_master(struct file_desc *d);
 extern struct file_desc *find_file_desc_raw(int type, u32 id);
-- 
1.9.3



More information about the CRIU mailing list