Commit 05abfa5d authored by Pavel Emelyanov's avatar Pavel Emelyanov

fdinfo: Extract FdinfoEntry from dump_one_file

To support SCMs we'll need to receive them into criu task
(see the SCM patch for details), then dump the received
file as if it was in the dumpee. Then the info about received
descriptor will be written into packet entry.

For this we'll need to perform all the regular file dumping
 code BUT not write the FdinfoEntry into image, so shuffle
the code for that.

The gist of the patch is in two changes -- one in the
do_dump_gen_file(), the other in dump_task_files_seized().
The rest is just tossing the arguments of the functions
relevant to that change.
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 d4c6e785
......@@ -84,11 +84,11 @@ struct collect_image_info ext_file_cinfo = {
};
int dump_unsupp_fd(struct fd_parms *p, int lfd,
struct cr_img *img, char *more, char *info)
char *more, char *info, FdinfoEntry *e)
{
int ret;
ret = do_dump_gen_file(p, lfd, &ext_dump_ops, img);
ret = do_dump_gen_file(p, lfd, &ext_dump_ops, e);
if (ret == 0)
return 0;
if (ret == -ENOTSUP)
......
......@@ -278,27 +278,20 @@ static u32 make_gen_id(const struct fd_parms *p)
}
int do_dump_gen_file(struct fd_parms *p, int lfd,
const struct fdtype_ops *ops, struct cr_img *img)
const struct fdtype_ops *ops, FdinfoEntry *e)
{
FdinfoEntry e = FDINFO_ENTRY__INIT;
int ret = -1;
e.type = ops->type;
e.id = make_gen_id(p);
e.fd = p->fd;
e.flags = p->fd_flags;
e->type = ops->type;
e->id = make_gen_id(p);
e->fd = p->fd;
e->flags = p->fd_flags;
ret = fd_id_generate(p->pid, &e, p);
ret = fd_id_generate(p->pid, e, p);
if (ret == 1) /* new ID generated */
ret = ops->dump(lfd, e.id, p);
ret = ops->dump(lfd, e->id, p);
if (ret < 0)
return ret;
pr_info("fdinfo: type: %#2x flags: %#o/%#o pos: %#8"PRIx64" fd: %d\n",
ops->type, p->flags, (int)p->fd_flags, p->pos, p->fd);
return pb_write_one(img, &e, PB_FDINFO);
return ret;
}
int fill_fdlink(int lfd, const struct fd_parms *p, struct fd_link *link)
......@@ -407,7 +400,7 @@ static const struct fdtype_ops *get_mem_dev_ops(struct fd_parms *p, int minor)
return ops;
}
static int dump_chrdev(struct fd_parms *p, int lfd, struct cr_img *img)
static int dump_chrdev(struct fd_parms *p, int lfd, FdinfoEntry *e)
{
struct fd_link *link_old = p->link;
int maj = major(p->stat.st_rdev);
......@@ -436,19 +429,19 @@ static int dump_chrdev(struct fd_parms *p, int lfd, struct cr_img *img)
}
sprintf(more, "%d:%d", maj, minor(p->stat.st_rdev));
err = dump_unsupp_fd(p, lfd, img, "chr", more);
err = dump_unsupp_fd(p, lfd, "chr", more, e);
p->link = link_old;
return err;
}
}
err = do_dump_gen_file(p, lfd, ops, img);
err = do_dump_gen_file(p, lfd, ops, e);
p->link = link_old;
return err;
}
static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
struct cr_img *img, struct parasite_ctl *ctl)
struct parasite_ctl *ctl, FdinfoEntry *e)
{
struct fd_parms p = FD_PARMS_INIT;
const struct fdtype_ops *ops;
......@@ -465,10 +458,10 @@ static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
p.fd_ctl = ctl; /* Some dump_opts require this to talk to parasite */
if (S_ISSOCK(p.stat.st_mode))
return dump_socket(&p, lfd, img);
return dump_socket(&p, lfd, e);
if (S_ISCHR(p.stat.st_mode))
return dump_chrdev(&p, lfd, img);
return dump_chrdev(&p, lfd, e);
if (p.fs_type == ANON_INODE_FS_MAGIC) {
char link[32];
......@@ -489,9 +482,9 @@ static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
else if (is_timerfd_link(link))
ops = &timerfd_dump_ops;
else
return dump_unsupp_fd(&p, lfd, img, "anon", link);
return dump_unsupp_fd(&p, lfd, "anon", link, e);
return do_dump_gen_file(&p, lfd, ops, img);
return do_dump_gen_file(&p, lfd, ops, e);
}
if (S_ISREG(p.stat.st_mode) || S_ISDIR(p.stat.st_mode)) {
......@@ -500,12 +493,12 @@ static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
p.link = &link;
if (link.name[1] == '/')
return do_dump_gen_file(&p, lfd, &regfile_dump_ops, img);
return do_dump_gen_file(&p, lfd, &regfile_dump_ops, e);
if (check_ns_proc(&link))
return do_dump_gen_file(&p, lfd, &nsfile_dump_ops, img);
return do_dump_gen_file(&p, lfd, &nsfile_dump_ops, e);
return dump_unsupp_fd(&p, lfd, img, "reg", link.name + 1);
return dump_unsupp_fd(&p, lfd, "reg", link.name + 1, e);
}
if (S_ISFIFO(p.stat.st_mode)) {
......@@ -514,7 +507,7 @@ static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
else
ops = &fifo_dump_ops;
return do_dump_gen_file(&p, lfd, ops, img);
return do_dump_gen_file(&p, lfd, ops, e);
}
/*
......@@ -525,7 +518,7 @@ static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
if (fill_fdlink(lfd, &p, &link))
memzero(&link, sizeof(link));
return dump_unsupp_fd(&p, lfd, img, "unknown", link.name + 1);
return dump_unsupp_fd(&p, lfd, "unknown", link.name + 1, e);
}
int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
......@@ -564,11 +557,17 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
goto err;
for (i = 0; i < nr_fds; i++) {
FdinfoEntry e = FDINFO_ENTRY__INIT;
ret = dump_one_file(item->pid, dfds->fds[i + off],
lfds[i], opts + i, img, ctl);
lfds[i], opts + i, ctl, &e);
close(lfds[i]);
if (ret)
break;
ret = pb_write_one(img, &e, PB_FDINFO);
if (ret)
break;
}
}
......
......@@ -135,7 +135,7 @@ struct cr_img;
extern int do_dump_gen_file(struct fd_parms *p, int lfd,
const struct fdtype_ops *ops,
struct cr_img *);
FdinfoEntry *e);
struct parasite_drain_fd;
int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
struct parasite_drain_fd *dfds);
......@@ -175,7 +175,7 @@ extern int shared_fdt_prepare(struct pstree_item *item);
extern struct collect_image_info ext_file_cinfo;
extern int dump_unsupp_fd(struct fd_parms *p, int lfd,
struct cr_img *, char *more, char *info);
char *more, char *info, FdinfoEntry *);
extern int inherit_fd_parse(char *optarg);
extern int inherit_fd_add(int fd, char *key);
......
......@@ -5,6 +5,7 @@
#include <sys/socket.h>
#include "images/sk-opts.pb-c.h"
#include "images/fdinfo.pb-c.h"
struct fdinfo_list_entry;
struct sk_opts_entry;
......@@ -21,7 +22,7 @@ struct socket_desc {
int already_dumped;
};
extern int dump_socket(struct fd_parms *p, int lfd, struct cr_img *);
extern int dump_socket(struct fd_parms *p, int lfd, FdinfoEntry *);
extern int dump_socket_opts(int sk, SkOptsEntry *soe);
extern int restore_socket_opts(int sk, SkOptsEntry *soe);
extern void release_skopts(SkOptsEntry *);
......
......@@ -552,7 +552,7 @@ void release_skopts(SkOptsEntry *soe)
xfree(soe->so_bound_dev);
}
int dump_socket(struct fd_parms *p, int lfd, struct cr_img *img)
int dump_socket(struct fd_parms *p, int lfd, FdinfoEntry *e)
{
int family;
const struct fdtype_ops *ops;
......@@ -581,7 +581,7 @@ int dump_socket(struct fd_parms *p, int lfd, struct cr_img *img)
return -1;
}
return do_dump_gen_file(p, lfd, ops, img);
return do_dump_gen_file(p, lfd, ops, e);
}
static int inet_receive_one(struct nlmsghdr *h, void *arg)
......
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