mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-30 05:48:05 +00:00
files: Split fdinfo in two parts
Make fdinfo_entry carry only the minimal info describing a file descriptor -- the fd value itself, the fd type (regular file, exe link, cwd, filemap and it will be pipes, sockets, inotifies, etc.) and the describing file ID. The mentioned ID will identify the type-d object, e.g. for regfiles this ID is already generated with file-ids.c code. The other part of this structure describes a regfile (i.e. a file opened with open syscall). I put this new entry at the end of the fdinfo_entry just to make the patching simpler. Soon this entry will be dumped into its own file. Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
159d3bdfd5
commit
500468d4e7
10
cr-dump.c
10
cr-dump.c
@ -121,9 +121,6 @@ static int dump_one_reg_file(const struct fd_parms *p, int lfd,
|
||||
close(lfd);
|
||||
|
||||
e.type = p->type;
|
||||
e.len = len;
|
||||
e.flags = p->flags;
|
||||
e.pos = p->pos;
|
||||
e.addr = p->fd_name;
|
||||
e.id = p->id;
|
||||
|
||||
@ -131,12 +128,17 @@ static int dump_one_reg_file(const struct fd_parms *p, int lfd,
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
e.rfe.len = len;
|
||||
e.rfe.flags = p->flags;
|
||||
e.rfe.pos = p->pos;
|
||||
e.rfe.id = e.id;
|
||||
|
||||
pr_info("fdinfo: type: %2x len: %2x flags: %4x pos: %8lx addr: %16lx\n",
|
||||
p->type, len, p->flags, p->pos, p->fd_name);
|
||||
|
||||
if (write_img(cr_fdset->fds[CR_FD_FDINFO], &e))
|
||||
goto err;
|
||||
if (write_img_buf(cr_fdset->fds[CR_FD_FDINFO], big_buffer, e.len))
|
||||
if (write_img_buf(cr_fdset->fds[CR_FD_FDINFO], big_buffer, e.rfe.len))
|
||||
goto err;
|
||||
|
||||
ret = 0;
|
||||
|
12
cr-show.c
12
cr-show.c
@ -85,15 +85,15 @@ static void show_files(int fd_files)
|
||||
|
||||
pr_msg("type: %s flags: %4x pos: %lx "
|
||||
"addr: %16lx id: %8x",
|
||||
fdtype2s(e.type), e.flags, e.pos, e.addr, e.id);
|
||||
fdtype2s(e.type), e.rfe.flags, e.rfe.pos, e.addr, e.id);
|
||||
|
||||
if (e.len) {
|
||||
int ret = read(fd_files, local_buf, e.len);
|
||||
if (ret != e.len) {
|
||||
pr_perror("Can't read %d bytes", e.len);
|
||||
if (e.rfe.len) {
|
||||
int ret = read(fd_files, local_buf, e.rfe.len);
|
||||
if (ret != e.rfe.len) {
|
||||
pr_perror("Can't read %d bytes", e.rfe.len);
|
||||
goto out;
|
||||
}
|
||||
local_buf[e.len] = 0;
|
||||
local_buf[e.rfe.len] = 0;
|
||||
pr_msg(" --> %s", local_buf);
|
||||
}
|
||||
|
||||
|
16
files.c
16
files.c
@ -60,12 +60,12 @@ static struct fdinfo_desc *find_fd(u64 id)
|
||||
|
||||
static int get_file_path(char *path, struct fdinfo_entry *fe, int fd)
|
||||
{
|
||||
if (read(fd, path, fe->len) != fe->len) {
|
||||
if (read(fd, path, fe->rfe.len) != fe->rfe.len) {
|
||||
pr_perror("Error reading path");
|
||||
return -1;
|
||||
}
|
||||
|
||||
path[fe->len] = '\0';
|
||||
path[fe->rfe.len] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -147,8 +147,8 @@ int prepare_fd_pid(int pid)
|
||||
if (ret <= 0)
|
||||
break;
|
||||
|
||||
if (e.len)
|
||||
lseek(fdinfo_fd, e.len, SEEK_CUR);
|
||||
if (e.rfe.len)
|
||||
lseek(fdinfo_fd, e.rfe.len, SEEK_CUR);
|
||||
|
||||
if (fd_is_special(&e))
|
||||
continue;
|
||||
@ -170,13 +170,13 @@ static int open_fe_fd(struct fdinfo_entry *fe, int fd)
|
||||
if (get_file_path(path, fe, fd))
|
||||
return -1;
|
||||
|
||||
tmp = open(path, fe->flags);
|
||||
tmp = open(path, fe->rfe.flags);
|
||||
if (tmp < 0) {
|
||||
pr_perror("Can't open file %s", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
lseek(tmp, fe->pos, SEEK_SET);
|
||||
lseek(tmp, fe->rfe.pos, SEEK_SET);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
@ -435,7 +435,7 @@ static int open_special_fdinfo(int pid, struct fdinfo_entry *fe,
|
||||
int fdinfo_fd, int state)
|
||||
{
|
||||
if (state != FD_STATE_RECV) {
|
||||
lseek(fdinfo_fd, fe->len, SEEK_CUR);
|
||||
lseek(fdinfo_fd, fe->rfe.len, SEEK_CUR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -485,7 +485,7 @@ int prepare_fds(int pid)
|
||||
else {
|
||||
offset = lseek(fdinfo_fd, 0, SEEK_CUR);
|
||||
ret = open_fdinfo(pid, &fe, &fdinfo_fd, state);
|
||||
lseek(fdinfo_fd, offset + fe.len, SEEK_SET);
|
||||
lseek(fdinfo_fd, offset + fe.rfe.len, SEEK_SET);
|
||||
}
|
||||
|
||||
if (ret)
|
||||
|
@ -44,16 +44,21 @@ enum fd_types {
|
||||
#define PAGE_RSS 1
|
||||
#define PAGE_ANON 2
|
||||
|
||||
struct fdinfo_entry {
|
||||
u8 type;
|
||||
u16 len;
|
||||
u16 flags;
|
||||
u64 pos;
|
||||
u64 addr;
|
||||
struct reg_file_entry {
|
||||
u32 id;
|
||||
u16 flags;
|
||||
u16 len;
|
||||
u64 pos;
|
||||
u8 name[0];
|
||||
} __packed;
|
||||
|
||||
struct fdinfo_entry {
|
||||
u64 addr;
|
||||
u8 type;
|
||||
u32 id;
|
||||
struct reg_file_entry rfe;
|
||||
} __packed;
|
||||
|
||||
#define fd_is_special(fe) \
|
||||
(((fe)->type == FDINFO_MAP) || \
|
||||
((fe)->type == FDINFO_CWD) || \
|
||||
|
Loading…
x
Reference in New Issue
Block a user