Commit f509fcf0 authored by Pavel Emelyanov's avatar Pavel Emelyanov

dump: Introduce file dumping operations

Now all the fds dump look very similar and we can reimplement
it via indirect calls.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 37a3ed86
...@@ -287,8 +287,7 @@ static int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p) ...@@ -287,8 +287,7 @@ static int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
pr_info("Dumping path for %d fd via self %d [%s]\n", pr_info("Dumping path for %d fd via self %d [%s]\n",
p->fd, lfd, big_buffer); p->fd, lfd, big_buffer);
if (p->type == FDINFO_REG && if (check_path_remap(big_buffer, &p->stat, lfd, id))
check_path_remap(big_buffer, &p->stat, lfd, id))
return -1; return -1;
rfe.len = len; rfe.len = len;
...@@ -307,36 +306,61 @@ static int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p) ...@@ -307,36 +306,61 @@ static int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
return 0; return 0;
} }
static int do_dump_gen_file(const struct fd_parms *p, int lfd, struct fdtype_ops {
const struct cr_fdset *cr_fdset) unsigned int type;
u32 (*make_gen_id)(const struct fd_parms *p);
int (*dump)(int lfd, u32 id, const struct fd_parms *p);
};
static u32 make_gen_id(const struct fd_parms *p)
{
return MAKE_FD_GENID(p->stat.st_dev, p->stat.st_ino, p->pos);
}
static const struct fdtype_ops pipe_ops = {
.type = FDINFO_PIPE,
.make_gen_id = make_gen_id,
.dump = dump_one_pipe,
};
static const struct fdtype_ops eventfd_ops = {
.type = FDINFO_EVENTFD,
.make_gen_id = make_gen_id,
.dump = dump_one_eventfd,
};
static const struct fdtype_ops eventpoll_ops = {
.type = FDINFO_EVENTPOLL,
.make_gen_id = make_gen_id,
.dump = dump_one_eventpoll,
};
static const struct fdtype_ops inotify_ops = {
.type = FDINFO_INOTIFY,
.make_gen_id = make_gen_id,
.dump = dump_one_inotify,
};
static const struct fdtype_ops regfile_ops = {
.type = FDINFO_REG,
.make_gen_id = make_gen_id,
.dump = dump_one_reg_file,
};
static int do_dump_gen_file(struct fd_parms *p, int lfd,
const struct fdtype_ops *ops, const struct cr_fdset *cr_fdset)
{ {
struct fdinfo_entry e; struct fdinfo_entry e;
int ret = -1; int ret = -1;
e.type = p->type; e.type = ops->type;
e.id = p->id = ops->make_gen_id(p);
e.fd = p->fd; e.fd = p->fd;
e.id = p->id;
e.flags = p->fd_flags; e.flags = p->fd_flags;
ret = fd_id_generate(p->pid, &e); ret = fd_id_generate(p->pid, &e);
if (ret == 1) /* new ID generated */ if (ret == 1) /* new ID generated */
switch (p->type) { ret = ops->dump(lfd, e.id, p);
case FDINFO_PIPE:
ret = dump_one_pipe(lfd, e.id, p);
break;
case FDINFO_EVENTFD:
ret = dump_one_eventfd(lfd, e.id, p);
break;
case FDINFO_EVENTPOLL:
ret = dump_one_eventpoll(lfd, e.id, p);
break;
case FDINFO_INOTIFY:
ret = dump_one_inotify(lfd, e.id, p);
break;
default:
ret = dump_one_reg_file(lfd, e.id, p);
break;
}
if (ret < 0) if (ret < 0)
goto err; goto err;
...@@ -355,17 +379,13 @@ err: ...@@ -355,17 +379,13 @@ err:
static int dump_reg_file(struct fd_parms *p, int lfd, static int dump_reg_file(struct fd_parms *p, int lfd,
const struct cr_fdset *cr_fdset) const struct cr_fdset *cr_fdset)
{ {
p->id = MAKE_FD_GENID(p->stat.st_dev, p->stat.st_ino, p->pos); return do_dump_gen_file(p, lfd, &regfile_ops, cr_fdset);
p->type = FDINFO_REG;
return do_dump_gen_file(p, lfd, cr_fdset);
} }
static int dump_pipe(struct fd_parms *p, int lfd, static int dump_pipe(struct fd_parms *p, int lfd,
const struct cr_fdset *cr_fdset) const struct cr_fdset *cr_fdset)
{ {
p->id = MAKE_FD_GENID(p->stat.st_dev, p->stat.st_ino, p->pos); return do_dump_gen_file(p, lfd, &pipe_ops, cr_fdset);
p->type = FDINFO_PIPE;
return do_dump_gen_file(p, lfd, cr_fdset);
} }
static int dump_task_exe_link(pid_t pid, struct mm_entry *mm) static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
...@@ -471,23 +491,17 @@ static int dump_chrdev(struct fd_parms *p, int lfd, const struct cr_fdset *set) ...@@ -471,23 +491,17 @@ static int dump_chrdev(struct fd_parms *p, int lfd, const struct cr_fdset *set)
static int dump_eventfd(struct fd_parms *p, int lfd, const struct cr_fdset *set) static int dump_eventfd(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{ {
p->id = MAKE_FD_GENID(p->stat.st_dev, p->stat.st_ino, p->pos); return do_dump_gen_file(p, lfd, &eventfd_ops, set);
p->type = FDINFO_EVENTFD;
return do_dump_gen_file(p, lfd, set);
} }
static int dump_eventpoll(struct fd_parms *p, int lfd, const struct cr_fdset *set) static int dump_eventpoll(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{ {
p->id = MAKE_FD_GENID(p->stat.st_dev, p->stat.st_ino, p->pos); return do_dump_gen_file(p, lfd, &eventpoll_ops, set);
p->type = FDINFO_EVENTPOLL;
return do_dump_gen_file(p, lfd, set);
} }
static int dump_inotify(struct fd_parms *p, int lfd, const struct cr_fdset *set) static int dump_inotify(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{ {
p->id = MAKE_FD_GENID(p->stat.st_dev, p->stat.st_ino, p->pos); return do_dump_gen_file(p, lfd, &inotify_ops, set);
p->type = FDINFO_INOTIFY;
return do_dump_gen_file(p, lfd, set);
} }
#ifndef PIPEFS_MAGIC #ifndef PIPEFS_MAGIC
......
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