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

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jun 1 08:11:22 PDT 2016


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

diff --git a/criu/files.c b/criu/files.c
index 15306d6..bb3b142 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -97,12 +97,26 @@ static inline struct file_desc *find_file_desc(FdinfoEntry *fe)
 	return find_file_desc_raw(fe->type, fe->id);
 }
 
+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;
+		/* List is ordered, so let's stop */
+		if (fle->fe->fd < fd)
+			break;
+	}
+	return NULL;
+}
+
 unsigned int find_unused_fd(struct list_head *head, int hint_fd)
 {
 	struct fdinfo_list_entry *fle;
 	int fd = 0, prev_fd;
 
-	if ((hint_fd >= 0) && (!fd_is_used(head, hint_fd))) {
+	if ((hint_fd >= 0) && (!find_used_fd(head, hint_fd))) {
 		fd = hint_fd;
 		goto out;
 	}
diff --git a/criu/include/files.h b/criu/include/files.h
index d46b3cd..5e3d6dc 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -125,19 +125,8 @@ static inline void collect_gen_fd(struct fdinfo_list_entry *fle, struct rst_info
 	list_add_tail(&fle->ps_list, &ri->fds);
 }
 
-static inline bool fd_is_used(struct list_head *head, int fd)
-{
-	struct fdinfo_list_entry *fle;
-
-	list_for_each_entry(fle, head, used_list) {
-		if (fle->fe->fd == fd)
-			return true;
-	}
-
-	return false;
-}
-
 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