[CRIU] [PATCH v2 02/15] files: Implement find_used_fd()

Kirill Tkhai ktkhai at virtuozzo.com
Fri May 27 06:05:51 PDT 2016


Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/files.c         |   13 +++++++++++++
 criu/include/files.h |    1 +
 2 files changed, 14 insertions(+)

diff --git a/criu/files.c b/criu/files.c
index a52e12f..0e9e41d 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -128,6 +128,19 @@ unsigned int find_unused_fd(struct list_head *head, int hint_fd)
 	return fd;
 }
 
+struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd)
+{
+	struct fdinfo_list_entry *fle;
+
+	list_for_each_entry_reverse(fle, head, used_list) {
+		if (fle->fe->fd == fd)
+			return fle;
+	}
+	pr_err("Trying to unhash unexisting fd %d\n", fd);
+	BUG();
+	return NULL;
+}
+
 /*
  * A file may be shared between several file descriptors. E.g
  * when doing a fork() every fd of a forker and respective fds
diff --git a/criu/include/files.h b/criu/include/files.h
index d46b3cd..025c7d0 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -138,6 +138,7 @@ static inline bool fd_is_used(struct list_head *head, int fd)
 }
 
 unsigned int find_unused_fd(struct list_head *head, int hint_fd);
+struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd);
 
 struct file_desc {
 	u32			id;		/* File id, unique */



More information about the CRIU mailing list