Commit 6a55c1c5 authored by Pavel Emelyanov's avatar Pavel Emelyanov

dump: Move per-type dump opts into respective .c files

No functional changes, just a code move.

TODO:

* need to write personal make_gen_id implementations for special
files (device and pos is const for them effectively)
* need to merge dump ops with restore ones (file_desc_ops)
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 2cea6414
...@@ -306,48 +306,12 @@ static int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p) ...@@ -306,48 +306,12 @@ static int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
return 0; return 0;
} }
struct fdtype_ops { u32 make_gen_id(const struct fd_parms *p)
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); return MAKE_FD_GENID(p->stat.st_dev, p->stat.st_ino, p->pos);
} }
static const struct fdtype_ops pipe_ops = { int do_dump_gen_file(struct fd_parms *p, int lfd,
.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) const struct fdtype_ops *ops, const struct cr_fdset *cr_fdset)
{ {
struct fdinfo_entry e; struct fdinfo_entry e;
...@@ -376,18 +340,18 @@ err: ...@@ -376,18 +340,18 @@ err:
return ret; return ret;
} }
static const struct fdtype_ops regfile_ops = {
.type = FDINFO_REG,
.make_gen_id = make_gen_id,
.dump = dump_one_reg_file,
};
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)
{ {
return do_dump_gen_file(p, lfd, &regfile_ops, cr_fdset); return do_dump_gen_file(p, lfd, &regfile_ops, cr_fdset);
} }
static int dump_pipe(struct fd_parms *p, int lfd,
const struct cr_fdset *cr_fdset)
{
return do_dump_gen_file(p, lfd, &pipe_ops, 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)
{ {
struct fd_parms params; struct fd_parms params;
...@@ -488,21 +452,6 @@ static int dump_chrdev(struct fd_parms *p, int lfd, const struct cr_fdset *set) ...@@ -488,21 +452,6 @@ static int dump_chrdev(struct fd_parms *p, int lfd, const struct cr_fdset *set)
return dump_unsupp_fd(p); return dump_unsupp_fd(p);
} }
static int dump_eventfd(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{
return do_dump_gen_file(p, lfd, &eventfd_ops, set);
}
static int dump_eventpoll(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{
return do_dump_gen_file(p, lfd, &eventpoll_ops, set);
}
static int dump_inotify(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{
return do_dump_gen_file(p, lfd, &inotify_ops, set);
}
#ifndef PIPEFS_MAGIC #ifndef PIPEFS_MAGIC
#define PIPEFS_MAGIC 0x50495045 #define PIPEFS_MAGIC 0x50495045
#endif #endif
......
...@@ -60,7 +60,7 @@ out: ...@@ -60,7 +60,7 @@ out:
pr_img_tail(CR_FD_EVENTFD); pr_img_tail(CR_FD_EVENTFD);
} }
int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p) static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p)
{ {
int image_fd = fdset_fd(glob_fdset, CR_FD_EVENTFD); int image_fd = fdset_fd(glob_fdset, CR_FD_EVENTFD);
struct eventfd_file_entry efe; struct eventfd_file_entry efe;
...@@ -100,6 +100,17 @@ int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p) ...@@ -100,6 +100,17 @@ int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p)
return 0; return 0;
} }
static const struct fdtype_ops eventfd_ops = {
.type = FDINFO_EVENTFD,
.make_gen_id = make_gen_id,
.dump = dump_one_eventfd,
};
int dump_eventfd(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{
return do_dump_gen_file(p, lfd, &eventfd_ops, set);
}
static int eventfd_open(struct file_desc *d) static int eventfd_open(struct file_desc *d)
{ {
struct eventfd_file_info *info; struct eventfd_file_info *info;
......
...@@ -92,7 +92,7 @@ out: ...@@ -92,7 +92,7 @@ out:
pr_img_tail(CR_FD_EVENTPOLL); pr_img_tail(CR_FD_EVENTPOLL);
} }
int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p) static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
{ {
int image_fd = fdset_fd(glob_fdset, CR_FD_EVENTPOLL); int image_fd = fdset_fd(glob_fdset, CR_FD_EVENTPOLL);
int image_tfd = fdset_fd(glob_fdset, CR_FD_EVENTPOLL_TFD); int image_tfd = fdset_fd(glob_fdset, CR_FD_EVENTPOLL_TFD);
...@@ -147,6 +147,17 @@ parsing_err: ...@@ -147,6 +147,17 @@ parsing_err:
return -1; return -1;
} }
static const struct fdtype_ops eventpoll_ops = {
.type = FDINFO_EVENTPOLL,
.make_gen_id = make_gen_id,
.dump = dump_one_eventpoll,
};
int dump_eventpoll(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{
return do_dump_gen_file(p, lfd, &eventpoll_ops, set);
}
static int eventpoll_open(struct file_desc *d) static int eventpoll_open(struct file_desc *d)
{ {
struct eventpoll_tfd_file_info *td_info; struct eventpoll_tfd_file_info *td_info;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "crtools.h" #include "crtools.h"
extern int is_eventfd_link(int lfd); extern int is_eventfd_link(int lfd);
extern int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p); extern int dump_eventfd(struct fd_parms *p, int lfd, const struct cr_fdset *set);
extern int collect_eventfd(void); extern int collect_eventfd(void);
extern void show_eventfds(int fd, struct cr_options *o); extern void show_eventfds(int fd, struct cr_options *o);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "crtools.h" #include "crtools.h"
extern int is_eventpoll_link(int lfd); extern int is_eventpoll_link(int lfd);
extern int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p); extern int dump_eventpoll(struct fd_parms *p, int lfd, const struct cr_fdset *set);
extern int collect_eventpoll(void); extern int collect_eventpoll(void);
extern void show_eventpoll(int fd, struct cr_options *o); extern void show_eventpoll(int fd, struct cr_options *o);
extern void show_eventpoll_tfd(int fd, struct cr_options *o); extern void show_eventpoll_tfd(int fd, struct cr_options *o);
......
...@@ -49,6 +49,17 @@ struct file_desc { ...@@ -49,6 +49,17 @@ struct file_desc {
struct file_desc_ops *ops; struct file_desc_ops *ops;
}; };
struct fdtype_ops {
unsigned int type;
u32 (*make_gen_id)(const struct fd_parms *p);
int (*dump)(int lfd, u32 id, const struct fd_parms *p);
};
extern u32 make_gen_id(const struct fd_parms *p);
struct cr_fdset;
extern int do_dump_gen_file(struct fd_parms *p, int lfd,
const struct fdtype_ops *ops, const struct cr_fdset *cr_fdset);
extern void file_desc_add(struct file_desc *d, int type, u32 id, extern void file_desc_add(struct file_desc *d, int type, u32 id,
struct file_desc_ops *ops); struct file_desc_ops *ops);
extern struct fdinfo_list_entry *file_master(struct file_desc *d); extern struct fdinfo_list_entry *file_master(struct file_desc *d);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "crtools.h" #include "crtools.h"
extern int is_inotify_link(int lfd); extern int is_inotify_link(int lfd);
extern int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p); extern int dump_inotify(struct fd_parms *p, int lfd, const struct cr_fdset *set);
extern int collect_inotify(void); extern int collect_inotify(void);
extern void show_inotify_wd(int fd_inotify_wd, struct cr_options *o); extern void show_inotify_wd(int fd_inotify_wd, struct cr_options *o);
extern void show_inotify(int fd_inotify, struct cr_options *o); extern void show_inotify(int fd_inotify, struct cr_options *o);
......
...@@ -4,5 +4,6 @@ extern int collect_pipes(void); ...@@ -4,5 +4,6 @@ extern int collect_pipes(void);
extern void mark_pipe_master(void); extern void mark_pipe_master(void);
int init_pipes_dump(void); int init_pipes_dump(void);
void fini_pipes_dump(void); void fini_pipes_dump(void);
int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p); int dump_pipe(struct fd_parms *p, int lfd,
const struct cr_fdset *cr_fdset);
#endif #endif
...@@ -127,7 +127,7 @@ static void parse_fhandle_encoded(char *tok, fh_t *f) ...@@ -127,7 +127,7 @@ static void parse_fhandle_encoded(char *tok, fh_t *f)
} }
} }
int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p) static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p)
{ {
struct inotify_file_entry ie; struct inotify_file_entry ie;
struct inotify_wd_entry we; struct inotify_wd_entry we;
...@@ -211,6 +211,17 @@ parse_error: ...@@ -211,6 +211,17 @@ parse_error:
goto err; goto err;
} }
static const struct fdtype_ops inotify_ops = {
.type = FDINFO_INOTIFY,
.make_gen_id = make_gen_id,
.dump = dump_one_inotify,
};
int dump_inotify(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{
return do_dump_gen_file(p, lfd, &inotify_ops, set);
}
static int restore_one_inotify(int inotify_fd, struct inotify_wd_entry *iwe) static int restore_one_inotify(int inotify_fd, struct inotify_wd_entry *iwe)
{ {
char path[32]; char path[32];
......
...@@ -304,7 +304,7 @@ out: ...@@ -304,7 +304,7 @@ out:
static u32 *pipes_with_data; /* pipes for which data already dumped */ static u32 *pipes_with_data; /* pipes for which data already dumped */
static int nr_pipes = 0; static int nr_pipes = 0;
int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p) static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p)
{ {
struct pipe_entry pe; struct pipe_entry pe;
int fd_pipes; int fd_pipes;
...@@ -409,6 +409,18 @@ err: ...@@ -409,6 +409,18 @@ err:
return ret; return ret;
} }
static const struct fdtype_ops pipe_ops = {
.type = FDINFO_PIPE,
.make_gen_id = make_gen_id,
.dump = dump_one_pipe,
};
int dump_pipe(struct fd_parms *p, int lfd,
const struct cr_fdset *cr_fdset)
{
return do_dump_gen_file(p, lfd, &pipe_ops, cr_fdset);
}
int init_pipes_dump(void) int init_pipes_dump(void)
{ {
pipes_with_data = xmalloc(PIPES_SIZE * sizeof(*pipes_with_data)); pipes_with_data = xmalloc(PIPES_SIZE * sizeof(*pipes_with_data));
......
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