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

Submitted by Kirill Tkhai on June 1, 2016, 3:11 p.m.

Details

Message ID 146479388296.19418.6958520172504890000.stgit@pro
State Accepted
Series "Support for packet's msg_name in receive queue of promiscous DGRAM sockets"
Commit ef996af9acc74f9283c072609f98de060374e8c5
Headers show

Commit Message

Kirill Tkhai June 1, 2016, 3:11 p.m.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/files.c         |   16 +++++++++++++++-
 criu/include/files.h |   13 +------------
 2 files changed, 16 insertions(+), 13 deletions(-)

Patch hide | download patch | download mbox

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 */