mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
files: Add ability to use read link in dump_one_reg_file
To be able to dump procfs namespace entries we will need to analyze the link name first and then figure out if the file referred indeed a procfs entry or it's plain regular file. This means we read link early, and to escape double reading of same link, once we read it we remember it in fd_parms structure which we pass to dump_one_reg_file. Still the dump_one_reg_file is not solely used from inside of dump_one_file, but from a number of other places (fifo, special files) where fd_parms is filled only partially and fill_fd_params is not even called. Thus dump_one_reg_file must be ready for such scenario and read the link name by own if the caller has not provided one. To achieve all this we do - extend fd_parms structure to have a reference on a new fd_link structure, thus if caller already read the link name it might assign the reference and call for dump_one_reg_file - tune up dump_one_reg_file to fill own copy of fd_link structure if the caller has not provied one [ xemul: Added const to fill_fdlink arg ] Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
19ce784db5
commit
4531f0ac7d
25
files.c
25
files.c
@@ -135,6 +135,22 @@ int do_dump_gen_file(struct fd_parms *p, int lfd,
|
||||
return pb_write_one(fdinfo, &e, PB_FDINFO);
|
||||
}
|
||||
|
||||
int fill_fdlink(int lfd, const struct fd_parms *p, struct fd_link *link)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
link->name[0] = '.';
|
||||
|
||||
len = read_fd_link(lfd, &link->name[1], sizeof(link->name) - 1);
|
||||
if (len < 0) {
|
||||
pr_err("Can't read link for pid %d fd %d\n", p->pid, p->fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
link->len = len + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fill_fd_params(struct parasite_ctl *ctl, int fd, int lfd,
|
||||
struct fd_opts *opts, struct fd_parms *p)
|
||||
{
|
||||
@@ -244,8 +260,15 @@ static int dump_one_file(struct parasite_ctl *ctl, int fd, int lfd, struct fd_op
|
||||
return dump_unsupp_fd(&p);
|
||||
}
|
||||
|
||||
if (S_ISREG(p.stat.st_mode) || S_ISDIR(p.stat.st_mode))
|
||||
if (S_ISREG(p.stat.st_mode) || S_ISDIR(p.stat.st_mode)) {
|
||||
struct fd_link link;
|
||||
|
||||
if (fill_fdlink(lfd, &p, &link))
|
||||
return -1;
|
||||
|
||||
p.link = &link;
|
||||
return dump_reg_file(&p, lfd, fdinfo);
|
||||
}
|
||||
|
||||
if (S_ISFIFO(p.stat.st_mode)) {
|
||||
if (statfs.f_type == PIPEFS_MAGIC)
|
||||
|
Reference in New Issue
Block a user