Commit 3b8fef52 authored by Pavel Emelyanov's avatar Pavel Emelyanov

fifo: Sanitize fifo restore

Don't push open cb onto reg_file_into, pass it into regfiles engine
as an argument.

Note: I haven't merged the fifo zdtms yet, thus this patch is untested.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Tested-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 18d89503
...@@ -72,9 +72,9 @@ int dump_fifo(struct fd_parms *p, int lfd, const struct cr_fdset *set) ...@@ -72,9 +72,9 @@ int dump_fifo(struct fd_parms *p, int lfd, const struct cr_fdset *set)
return do_dump_gen_file(p, lfd, &fifo_ops, set); return do_dump_gen_file(p, lfd, &fifo_ops, set);
} }
static int __open_fifo_fd(struct reg_file_info *rfi) static int do_open_fifo(struct reg_file_info *rfi, void *arg)
{ {
struct fifo_info *info = rfi->priv; struct fifo_info *info = arg;
int new_fifo, fake_fifo = -1; int new_fifo, fake_fifo = -1;
/* /*
...@@ -111,24 +111,8 @@ out: ...@@ -111,24 +111,8 @@ out:
static int open_fifo_fd(struct file_desc *d) static int open_fifo_fd(struct file_desc *d)
{ {
struct fifo_info *info = container_of(d, struct fifo_info, d); struct fifo_info *info = container_of(d, struct fifo_info, d);
struct reg_file_info *rfi;
struct file_desc *rd;
pr_info("\t\tCreating fifo pipe_id=%#x id=%#x\n", return open_path_by_id(info->fe.id, do_open_fifo, info);
info->fe.pipe_id, info->fe.id);
rd = find_file_desc_raw(FDINFO_REG, info->fe.id);
if (!rd) {
pr_perror("Can't find regfile for fifo %#x\n", info->fe.id);
return -1;
}
rfi = container_of(rd, struct reg_file_info, d);
if (rfi->open != __open_fifo_fd)
rfi->open = __open_fifo_fd;
rfi->priv = info;
return open_fe_fd(rd);
} }
static struct file_desc_ops fifo_desc_ops = { static struct file_desc_ops fifo_desc_ops = {
......
...@@ -340,12 +340,8 @@ int dump_reg_file(struct fd_parms *p, int lfd, ...@@ -340,12 +340,8 @@ int dump_reg_file(struct fd_parms *p, int lfd,
return do_dump_gen_file(p, lfd, &regfile_ops, cr_fdset); return do_dump_gen_file(p, lfd, &regfile_ops, cr_fdset);
} }
static int __open_reg_fd(struct reg_file_info *rfi) static int open_path(struct file_desc *d,
{ int(*open_cb)(struct reg_file_info *, void *), void *arg)
return open(rfi->path, rfi->rfe.flags);
}
int open_fe_fd(struct file_desc *d)
{ {
struct reg_file_info *rfi; struct reg_file_info *rfi;
int tmp; int tmp;
...@@ -359,7 +355,7 @@ int open_fe_fd(struct file_desc *d) ...@@ -359,7 +355,7 @@ int open_fe_fd(struct file_desc *d)
return -1; return -1;
} }
tmp = rfi->open(rfi); tmp = open_cb(rfi, arg);
if (tmp < 0) { if (tmp < 0) {
pr_perror("Can't open file %s", rfi->path); pr_perror("Can't open file %s", rfi->path);
return -1; return -1;
...@@ -376,7 +372,7 @@ int open_fe_fd(struct file_desc *d) ...@@ -376,7 +372,7 @@ int open_fe_fd(struct file_desc *d)
return tmp; return tmp;
} }
int open_reg_by_id(u32 id) int open_path_by_id(u32 id, int (*open_cb)(struct reg_file_info *, void *), void *arg)
{ {
struct file_desc *fd; struct file_desc *fd;
...@@ -386,7 +382,22 @@ int open_reg_by_id(u32 id) ...@@ -386,7 +382,22 @@ int open_reg_by_id(u32 id)
return -1; return -1;
} }
return open_fe_fd(fd); return open_path(fd, open_cb, arg);
}
static int do_open_reg(struct reg_file_info *rfi, void *arg)
{
return open(rfi->path, rfi->rfe.flags);
}
static int open_fe_fd(struct file_desc *fd)
{
return open_path(fd, do_open_reg, NULL);
}
int open_reg_by_id(u32 id)
{
return open_path_by_id(id, do_open_reg, NULL);
} }
static struct file_desc_ops reg_desc_ops = { static struct file_desc_ops reg_desc_ops = {
...@@ -419,7 +430,6 @@ int collect_reg_files(void) ...@@ -419,7 +430,6 @@ int collect_reg_files(void)
break; break;
rfi->remap_path = NULL; rfi->remap_path = NULL;
rfi->open = __open_reg_fd;
pr_info("Collected [%s] ID %#x\n", rfi->path, rfi->rfe.id); pr_info("Collected [%s] ID %#x\n", rfi->path, rfi->rfe.id);
file_desc_add(&rfi->d, rfi->rfe.id, &reg_desc_ops); file_desc_add(&rfi->d, rfi->rfe.id, &reg_desc_ops);
......
...@@ -15,15 +15,12 @@ struct reg_file_info { ...@@ -15,15 +15,12 @@ struct reg_file_info {
char *remap_path; char *remap_path;
char *path; char *path;
int (*open)(struct reg_file_info *rfi);
void *priv;
}; };
extern int open_reg_by_id(u32 id); extern int open_reg_by_id(u32 id);
extern int open_path_by_id(u32 id, int (*open_cb)(struct reg_file_info *, void *), void *arg);
extern void clear_ghost_files(void); extern void clear_ghost_files(void);
extern int collect_reg_files(void); extern int collect_reg_files(void);
extern int open_fe_fd(struct file_desc *d);
extern int dump_reg_file(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset); extern int dump_reg_file(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset);
extern int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p); extern int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p);
......
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