files: Merge collect_gen_fd() and collect_used_fd(), and call it unconditionally

Since we keep files of all types in a single list (fds), it's possible
to use only function for that and to call it unconditionally.

v4: New

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
Kirill Tkhai 2017-01-18 14:59:14 +03:00 committed by Pavel Emelyanov
parent 6072bca687
commit e98c96ed4a
5 changed files with 8 additions and 21 deletions

View file

@ -875,9 +875,7 @@ static int autofs_create_fle(struct pstree_item *task, FdinfoEntry *fe,
fle_init(le, task->pid->ns[0].virt, fe);
collect_gen_fd(le, rst_info);
collect_used_fd(le, rst_info);
collect_task_fd(le, rst_info);
list_add_tail(&le->desc_list, &desc->fd_info_head);
le->desc = desc;

View file

@ -126,7 +126,6 @@ static void collect_fifo_fd(struct file_desc *d,
info = container_of(d, struct fifo_info, d);
info->reg_d = collect_special_file(info->fe->id);
BUG_ON(info->reg_d == NULL);
collect_gen_fd(fle, ri);
}
static struct file_desc_ops fifo_desc_ops = {

View file

@ -1654,12 +1654,6 @@ int collect_filemap(struct vma_area *vma)
return 0;
}
static void collect_reg_fd(struct file_desc *fdesc,
struct fdinfo_list_entry *fle, struct rst_info *ri)
{
collect_gen_fd(fle, ri);
}
static int open_fe_fd(struct file_desc *fd, int *new_fd)
{
int tmp;
@ -1682,7 +1676,6 @@ static char *reg_file_path(struct file_desc *d, char *buf, size_t s)
static struct file_desc_ops reg_desc_ops = {
.type = FD_TYPES__REG,
.open = open_fe_fd,
.collect_fd = collect_reg_fd,
.name = reg_file_path,
};

View file

@ -112,10 +112,14 @@ struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd)
return NULL;
}
void collect_used_fd(struct fdinfo_list_entry *new_fle, struct rst_info *ri)
void collect_task_fd(struct fdinfo_list_entry *new_fle, struct rst_info *ri)
{
struct fdinfo_list_entry *fle;
/* fles in fds list are disordered */
list_add_tail(&new_fle->ps_list, &ri->fds);
/* fles in used list are ordered by fd */
list_for_each_entry(fle, &ri->used, used_list) {
if (new_fle->fe->fd < fle->fe->fd)
break;
@ -705,10 +709,8 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
if (fdesc->ops->collect_fd)
fdesc->ops->collect_fd(fdesc, new_le, rst_info);
else
collect_gen_fd(new_le, rst_info);
collect_used_fd(new_le, rst_info);
collect_task_fd(new_le, rst_info);
list_add_tail(&new_le->desc_list, &le->desc_list);
new_le->desc = fdesc;

View file

@ -115,12 +115,7 @@ struct file_desc_ops {
char * (*name)(struct file_desc *, char *b, size_t s);
};
extern void collect_used_fd(struct fdinfo_list_entry *new_fle, struct rst_info *ri);
static inline void collect_gen_fd(struct fdinfo_list_entry *fle, struct rst_info *ri)
{
list_add_tail(&fle->ps_list, &ri->fds);
}
void collect_task_fd(struct fdinfo_list_entry *new_fle, struct rst_info *ri);
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);