Commit 12316c49 authored by Pavel Emelyanov's avatar Pavel Emelyanov

files: Ease the fd collecting

No need in separate per-type fn for doing this. We can just
find the respective fd list and do sorting in the generic code.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 9e3befe0
......@@ -82,6 +82,17 @@ static struct list_head *find_reg_fd(int id)
return &rfi->fd_head;
}
static struct list_head *find_fi_list(struct fdinfo_entry *fe)
{
if (fe->type == FDINFO_REG)
return find_reg_fd(fe->id);
if (fe->type == FDINFO_INETSK)
return find_inetsk_fd(fe->id);
BUG_ON(1);
return NULL;
}
int collect_reg_files(void)
{
struct reg_file_info *rfi = NULL;
......@@ -134,29 +145,11 @@ int collect_reg_files(void)
return ret;
}
static int collect_fd_reg(int id, struct fdinfo_list_entry *le)
{
struct reg_file_info *rfi;
struct fdinfo_list_entry *l;
rfi = find_reg_file(id);
if (rfi == NULL) {
pr_err("No file for fd %d, id %d\n", le->fd, id);
return -1;
}
list_for_each_entry(l, &rfi->fd_head, list)
if (l->pid > le->pid)
break;
list_add_tail(&le->list, &l->list);
return 0;
}
static int collect_fd(int pid, struct fdinfo_entry *e)
{
int i;
struct fdinfo_list_entry *le = &fdinfo_list[nr_fdinfo_list];
struct fdinfo_list_entry *l, *le = &fdinfo_list[nr_fdinfo_list];
struct list_head *fi_list;
pr_info("Collect fdinfo pid=%d fd=%ld id=%16x\n",
pid, e->addr, e->id);
......@@ -171,13 +164,18 @@ static int collect_fd(int pid, struct fdinfo_entry *e)
le->fd = e->addr;
futex_init(&le->real_pid);
if (e->type == FDINFO_REG)
return collect_fd_reg(e->id, le);
if (e->type == FDINFO_INETSK)
return collect_fd_inetsk(e->id, le);
BUG_ON(1);
fi_list = find_fi_list(e);
if (fi_list == NULL) {
pr_err("No file for fd %d id %d\n", (int)e->addr, e->id);
return -1;
}
list_for_each_entry(l, fi_list, list)
if (l->pid > le->pid)
break;
list_add_tail(&le->list, &l->list);
return 0;
}
int prepare_fd_pid(int pid)
......@@ -482,17 +480,6 @@ static int open_fmap(int pid, struct fdinfo_entry *fe, int fd)
return 0;
}
static struct list_head *find_fi_list(struct fdinfo_entry *fe)
{
if (fe->type == FDINFO_REG)
return find_reg_fd(fe->id);
if (fe->type == FDINFO_INETSK)
return find_inetsk_fd(fe->id);
BUG_ON(1);
return NULL;
}
static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int state)
{
u32 mag;
......
......@@ -11,7 +11,6 @@ extern int dump_socket(struct fd_parms *p, int lfd,
const struct cr_fdset *cr_fdset);
struct fdinfo_list_entry;
int collect_fd_inetsk(int id, struct fdinfo_list_entry *le);
struct list_head *find_inetsk_fd(int id);
extern int collect_sockets(void);
extern int collect_inet_sockets(void);
......
......@@ -1267,25 +1267,6 @@ struct list_head *find_inetsk_fd(int id)
return &ii->fd_head;
}
int collect_fd_inetsk(int id, struct fdinfo_list_entry *le)
{
struct inet_sk_info *ii;
struct fdinfo_list_entry *l;
ii = find_inet_sk(id);
if (ii == NULL) {
pr_err("No inet socket for %d id %d\n", le->fd, id);
return -1;
}
list_for_each_entry(l, &ii->fd_head, list)
if (l->pid > le->pid)
break;
list_add_tail(&le->list, &l->list);
return 0;
}
int collect_inet_sockets(void)
{
struct inet_sk_info *ii = NULL;
......
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