Commit 45538c08 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Pavel Emelyanov

files: Implement find_used_fd()

Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 33a464c4
......@@ -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;
}
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment