mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 22:35:33 +00:00
vma: Remove FDINFO_MAP fd type
The regfile's ID of a VMA is stored in its shmid field. And the file itself if sumped into regfiles.img image with 'special'-ly generated ID (i.e. -- just allocate a new unique one). Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
36
cr-dump.c
36
cr-dump.c
@@ -544,23 +544,21 @@ static int add_shmem_area(pid_t pid, struct vma_entry *vma)
|
|||||||
static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd,
|
static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd,
|
||||||
const struct cr_fdset *fdset)
|
const struct cr_fdset *fdset)
|
||||||
{
|
{
|
||||||
struct fd_parms p = {
|
struct fd_parms p;
|
||||||
.fd_name = vma->start,
|
|
||||||
.id = FD_ID_INVALID,
|
|
||||||
.pid = pid,
|
|
||||||
.type = FDINFO_MAP,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
if (fstat(file_fd, &p.stat) < 0) {
|
||||||
|
pr_perror("Can't stat file for vma");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.type = FDINFO_REG;
|
||||||
if ((vma->prot & PROT_WRITE) && vma_entry_is(vma, VMA_FILE_SHARED))
|
if ((vma->prot & PROT_WRITE) && vma_entry_is(vma, VMA_FILE_SHARED))
|
||||||
p.flags = O_RDWR;
|
p.flags = O_RDWR;
|
||||||
else
|
else
|
||||||
p.flags = O_RDONLY;
|
p.flags = O_RDONLY;
|
||||||
|
vma->shmid = fd_id_generate_special();
|
||||||
|
|
||||||
/*
|
return dump_one_reg_file(file_fd, vma->shmid, &p);
|
||||||
* XXX Strictly speaking, no need in full fdinfo here.
|
|
||||||
* This can be relaxed down to calling dump_one_reg_file.
|
|
||||||
*/
|
|
||||||
return do_dump_one_fdinfo(&p, file_fd, fdset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list,
|
static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list,
|
||||||
@@ -578,18 +576,12 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list,
|
|||||||
list_for_each_entry(vma_area, vma_area_list, list) {
|
list_for_each_entry(vma_area, vma_area_list, list) {
|
||||||
struct vma_entry *vma = &vma_area->vma;
|
struct vma_entry *vma = &vma_area->vma;
|
||||||
|
|
||||||
ret = write_img(fd, vma);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
if (!vma_entry_is(vma, VMA_AREA_REGULAR))
|
|
||||||
continue;
|
|
||||||
if (vma_entry_is(vma, VMA_AREA_SYSVIPC))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
pr_info_vma(vma_area);
|
pr_info_vma(vma_area);
|
||||||
|
|
||||||
if (vma_entry_is(vma, VMA_ANON_SHARED))
|
if (!vma_entry_is(vma, VMA_AREA_REGULAR) ||
|
||||||
|
vma_entry_is(vma, VMA_AREA_SYSVIPC))
|
||||||
|
ret = 0;
|
||||||
|
else if (vma_entry_is(vma, VMA_ANON_SHARED))
|
||||||
ret = add_shmem_area(pid, vma);
|
ret = add_shmem_area(pid, vma);
|
||||||
else if (vma_entry_is(vma, VMA_FILE_PRIVATE) ||
|
else if (vma_entry_is(vma, VMA_FILE_PRIVATE) ||
|
||||||
vma_entry_is(vma, VMA_FILE_SHARED))
|
vma_entry_is(vma, VMA_FILE_SHARED))
|
||||||
@@ -597,6 +589,8 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list,
|
|||||||
else
|
else
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
ret = write_img(fd, vma);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@@ -59,7 +59,6 @@ static char *fdtype2s(u8 type)
|
|||||||
static char und[4];
|
static char und[4];
|
||||||
static char *fdtypes[] = {
|
static char *fdtypes[] = {
|
||||||
[FDINFO_REG] = "reg",
|
[FDINFO_REG] = "reg",
|
||||||
[FDINFO_MAP] = "map",
|
|
||||||
[FDINFO_CWD] = "cwd",
|
[FDINFO_CWD] = "cwd",
|
||||||
[FDINFO_EXE] = "exe",
|
[FDINFO_EXE] = "exe",
|
||||||
[FDINFO_INETSK] = "isk",
|
[FDINFO_INETSK] = "isk",
|
||||||
|
@@ -217,13 +217,18 @@ static struct fd_id_entry *fd_id_generate_gen(pid_t pid,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 fd_id_generate_special(void)
|
||||||
|
{
|
||||||
|
return fd_id_entries_subid++;
|
||||||
|
}
|
||||||
|
|
||||||
int fd_id_generate(pid_t pid, struct fdinfo_entry *fe)
|
int fd_id_generate(pid_t pid, struct fdinfo_entry *fe)
|
||||||
{
|
{
|
||||||
struct fd_id_entry *fid;
|
struct fd_id_entry *fid;
|
||||||
int new_id = 0;
|
int new_id = 0;
|
||||||
|
|
||||||
if (fd_is_special(fe)) {
|
if (fd_is_special(fe)) {
|
||||||
fe->id = fd_id_entries_subid++;
|
fe->id = fd_id_generate_special();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
64
files.c
64
files.c
@@ -24,8 +24,6 @@
|
|||||||
static struct fdinfo_list_entry *fdinfo_list;
|
static struct fdinfo_list_entry *fdinfo_list;
|
||||||
static int nr_fdinfo_list;
|
static int nr_fdinfo_list;
|
||||||
|
|
||||||
static struct fmap_fd *fmap_fds;
|
|
||||||
|
|
||||||
#define FDESC_HASH_SIZE 64
|
#define FDESC_HASH_SIZE 64
|
||||||
static struct list_head file_descs[FDESC_HASH_SIZE];
|
static struct list_head file_descs[FDESC_HASH_SIZE];
|
||||||
|
|
||||||
@@ -460,33 +458,6 @@ static int receive_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
|
|||||||
return reopen_fd_as((int)fe->addr, tmp);
|
return reopen_fd_as((int)fe->addr, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_fmap(int pid, struct fdinfo_entry *fe, int fd)
|
|
||||||
{
|
|
||||||
struct fmap_fd *new;
|
|
||||||
int tmp;
|
|
||||||
|
|
||||||
tmp = find_open_fe_fd(fe);
|
|
||||||
if (tmp < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
pr_info("%d:\t\tWill map %lx to %d\n", pid, (unsigned long)fe->addr, tmp);
|
|
||||||
|
|
||||||
new = xmalloc(sizeof(*new));
|
|
||||||
if (!new) {
|
|
||||||
close_safe(&tmp);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
new->start = fe->addr;
|
|
||||||
new->fd = tmp;
|
|
||||||
new->next = fmap_fds;
|
|
||||||
new->pid = pid;
|
|
||||||
|
|
||||||
fmap_fds = new;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int state)
|
static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int state)
|
||||||
{
|
{
|
||||||
u32 mag;
|
u32 mag;
|
||||||
@@ -522,8 +493,6 @@ static int open_special_fdinfo(int pid, struct fdinfo_entry *fe,
|
|||||||
if (state != FD_STATE_RECV)
|
if (state != FD_STATE_RECV)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (fe->type == FDINFO_MAP)
|
|
||||||
return open_fmap(pid, fe, fdinfo_fd);
|
|
||||||
if (fe->type == FDINFO_CWD)
|
if (fe->type == FDINFO_CWD)
|
||||||
return restore_cwd(fe, fdinfo_fd);
|
return restore_cwd(fe, fdinfo_fd);
|
||||||
if (fe->type == FDINFO_EXE)
|
if (fe->type == FDINFO_EXE)
|
||||||
@@ -581,31 +550,16 @@ int prepare_fds(int pid)
|
|||||||
return run_unix_connections();
|
return run_unix_connections();
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct fmap_fd *pull_fmap_fd(int pid, unsigned long start)
|
|
||||||
{
|
|
||||||
struct fmap_fd **p, *r;
|
|
||||||
|
|
||||||
pr_info("%d: Looking for %lx : ", pid, start);
|
|
||||||
|
|
||||||
for (p = &fmap_fds; *p != NULL; p = &(*p)->next) {
|
|
||||||
if ((*p)->start != start || (*p)->pid != pid)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
r = *p;
|
|
||||||
*p = r->next;
|
|
||||||
pr_info("found\n");
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
pr_info("not found\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_filemap_fd(int pid, struct vma_entry *vma_entry)
|
int get_filemap_fd(int pid, struct vma_entry *vma_entry)
|
||||||
{
|
{
|
||||||
struct fmap_fd *fmap_fd;
|
struct file_desc *fd;
|
||||||
|
|
||||||
fmap_fd = pull_fmap_fd(pid, vma_entry->start);
|
fd = find_file_desc_raw(FDINFO_REG, vma_entry->shmid);
|
||||||
return fmap_fd ? fmap_fd->fd : -1;
|
if (fd == NULL) {
|
||||||
|
pr_err("Can't find file for mapping %lx-%lx\n",
|
||||||
|
vma_entry->start, vma_entry->end);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return open_fe_fd(fd);
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
struct fdinfo_entry;
|
struct fdinfo_entry;
|
||||||
extern int fd_id_generate(pid_t pid, struct fdinfo_entry *fe);
|
extern int fd_id_generate(pid_t pid, struct fdinfo_entry *fe);
|
||||||
|
extern u32 fd_id_generate_special(void);
|
||||||
extern void fd_id_show_tree(void);
|
extern void fd_id_show_tree(void);
|
||||||
|
|
||||||
#endif /* FILE_IDS_H__ */
|
#endif /* FILE_IDS_H__ */
|
||||||
|
@@ -35,7 +35,6 @@ enum fd_types {
|
|||||||
FDINFO_UND,
|
FDINFO_UND,
|
||||||
FDINFO_REG,
|
FDINFO_REG,
|
||||||
FDINFO_PIPE,
|
FDINFO_PIPE,
|
||||||
FDINFO_MAP,
|
|
||||||
FDINFO_INETSK,
|
FDINFO_INETSK,
|
||||||
FDINFO_UNIXSK,
|
FDINFO_UNIXSK,
|
||||||
FDINFO_CWD,
|
FDINFO_CWD,
|
||||||
@@ -62,8 +61,7 @@ struct fdinfo_entry {
|
|||||||
u32 id;
|
u32 id;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define fd_is_special(fe) \
|
#define fd_is_special(fe) ( \
|
||||||
(((fe)->type == FDINFO_MAP) || \
|
|
||||||
((fe)->type == FDINFO_CWD) || \
|
((fe)->type == FDINFO_CWD) || \
|
||||||
((fe)->type == FDINFO_EXE))
|
((fe)->type == FDINFO_EXE))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user