Commit fefc408b authored by Pavel Emelyanov's avatar Pavel Emelyanov

fd: Split fdinfo collect routine

In SCM code there will be the need to attach a newly created
FdinfoEntry to a particulat file desc object, then get the
created fdinfo helper object back.

Current code only allows this via two lookup calls -- first
one to attach entry to desc by ID (lookup #1), then get the
fdinfo helper by FD (lookup #2).

Fortunately, the exising code allows simple split that gives
us the optimized routine.
Reviewed-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 0d1dac2b
...@@ -761,26 +761,36 @@ static void collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_desc ...@@ -761,26 +761,36 @@ static void collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_desc
list_add_tail(&new_le->desc_list, &le->desc_list); list_add_tail(&new_le->desc_list, &le->desc_list);
} }
int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool fake) struct fdinfo_list_entry *collect_fd_to(int pid, FdinfoEntry *e,
struct rst_info *rst_info, struct file_desc *fdesc, bool fake)
{ {
struct fdinfo_list_entry *new_le; struct fdinfo_list_entry *new_le;
new_le = alloc_fle(pid, e);
if (new_le) {
new_le->fake = (!!fake);
collect_desc_fle(new_le, fdesc);
collect_task_fd(new_le, rst_info);
}
return new_le;
}
int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool fake)
{
struct file_desc *fdesc; struct file_desc *fdesc;
pr_info("Collect fdinfo pid=%d fd=%d id=%#x\n", pr_info("Collect fdinfo pid=%d fd=%d id=%#x\n",
pid, e->fd, e->id); pid, e->fd, e->id);
new_le = alloc_fle(pid, e);
if (!new_le)
return -1;
new_le->fake = (!!fake);
fdesc = find_file_desc(e); fdesc = find_file_desc(e);
if (fdesc == NULL) { if (fdesc == NULL) {
pr_err("No file for fd %d id %#x\n", e->fd, e->id); pr_err("No file for fd %d id %#x\n", e->fd, e->id);
return -1; return -1;
} }
collect_desc_fle(new_le, fdesc);
collect_task_fd(new_le, rst_info); if (!collect_fd_to(pid, e, rst_info, fdesc, fake))
return -1;
return 0; return 0;
} }
......
...@@ -112,6 +112,8 @@ struct file_desc_ops { ...@@ -112,6 +112,8 @@ struct file_desc_ops {
int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool ghost); int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool ghost);
void collect_task_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 *collect_fd_to(int pid, FdinfoEntry *e,
struct rst_info *rst_info, struct file_desc *fdesc, bool fake);
unsigned int find_unused_fd(struct pstree_item *, int hint_fd); unsigned int find_unused_fd(struct pstree_item *, int hint_fd);
struct fdinfo_list_entry *find_used_fd(struct pstree_item *, int fd); struct fdinfo_list_entry *find_used_fd(struct pstree_item *, int fd);
......
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