mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-02 23:35:21 +00:00
files: dump fdinfo per files_id instead of pid
A few processes can share one fdtable. Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
bb25ed38c8
commit
d50c786c7e
26
cr-dump.c
26
cr-dump.c
@@ -355,10 +355,10 @@ static int dump_one_file(struct parasite_ctl *ctl, int fd, int lfd, struct fd_op
|
||||
return dump_unsupp_fd(&p);
|
||||
}
|
||||
|
||||
static int dump_task_files_seized(struct parasite_ctl *ctl, const int fdinfo,
|
||||
static int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
|
||||
struct parasite_drain_fd *dfds)
|
||||
{
|
||||
int *lfds;
|
||||
int *lfds, fdinfo;
|
||||
struct fd_opts *opts;
|
||||
int i, ret = -1;
|
||||
|
||||
@@ -378,13 +378,19 @@ static int dump_task_files_seized(struct parasite_ctl *ctl, const int fdinfo,
|
||||
if (ret)
|
||||
goto err2;
|
||||
|
||||
fdinfo = open_image(CR_FD_FDINFO, O_DUMP, item->ids->files_id);
|
||||
if (fdinfo < 0)
|
||||
goto err2;
|
||||
|
||||
for (i = 0; i < dfds->nr_fds; i++) {
|
||||
ret = dump_one_file(ctl, dfds->fds[i], lfds[i], opts + i, fdinfo);
|
||||
close(lfds[i]);
|
||||
if (ret)
|
||||
goto err2;
|
||||
break;
|
||||
}
|
||||
|
||||
close(fdinfo);
|
||||
|
||||
pr_info("----------------------------------------\n");
|
||||
err2:
|
||||
xfree(opts);
|
||||
@@ -1453,7 +1459,13 @@ static int dump_one_task(struct pstree_item *item)
|
||||
if (!cr_fdset)
|
||||
goto err_cure;
|
||||
|
||||
ret = dump_task_files_seized(parasite_ctl, fdset_fd(cr_fdset, CR_FD_FDINFO), dfds);
|
||||
ret = dump_task_ids(item, cr_fdset);
|
||||
if (ret) {
|
||||
pr_err("Dump ids (pid: %d) failed with %d\n", pid, ret);
|
||||
goto err_cure;
|
||||
}
|
||||
|
||||
ret = dump_task_files_seized(parasite_ctl, item, dfds);
|
||||
if (ret) {
|
||||
pr_err("Dump files (pid: %d) failed with %d\n", pid, ret);
|
||||
goto err_cure;
|
||||
@@ -1484,12 +1496,6 @@ static int dump_one_task(struct pstree_item *item)
|
||||
goto err_cure;
|
||||
}
|
||||
|
||||
ret = dump_task_ids(item, cr_fdset);
|
||||
if (ret) {
|
||||
pr_err("Dump ids (pid: %d) failed with %d\n", pid, ret);
|
||||
goto err_cure;
|
||||
}
|
||||
|
||||
ret = dump_task_threads(parasite_ctl, item);
|
||||
if (ret) {
|
||||
pr_err("Can't dump threads\n");
|
||||
|
@@ -156,7 +156,7 @@ static int root_prepare_shared(void)
|
||||
if (ret < 0)
|
||||
break;
|
||||
|
||||
ret = prepare_fd_pid(pi->pid.virt, pi->rst);
|
||||
ret = prepare_fd_pid(pi);
|
||||
if (ret < 0)
|
||||
break;
|
||||
}
|
||||
|
17
files.c
17
files.c
@@ -217,19 +217,32 @@ int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int prepare_fd_pid(int pid, struct rst_info *rst_info)
|
||||
int prepare_fd_pid(struct pstree_item *item)
|
||||
{
|
||||
int fdinfo_fd, ret = 0;
|
||||
pid_t pid = item->pid.virt;
|
||||
struct rst_info *rst_info = item->rst;
|
||||
|
||||
INIT_LIST_HEAD(&rst_info->fds);
|
||||
INIT_LIST_HEAD(&rst_info->eventpoll);
|
||||
INIT_LIST_HEAD(&rst_info->tty_slaves);
|
||||
|
||||
if (!fdinfo_per_id) {
|
||||
fdinfo_fd = open_image_ro(CR_FD_FDINFO, pid);
|
||||
if (fdinfo_fd < 0) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (item->ids == NULL) /* zombie */
|
||||
return 0;
|
||||
|
||||
if (item->rst->fdt && item->rst->fdt->pid != item->pid.virt)
|
||||
return 0;
|
||||
|
||||
fdinfo_fd = open_image_ro(CR_FD_FDINFO, item->ids->files_id);
|
||||
if (fdinfo_fd < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
6
image.c
6
image.c
@@ -15,6 +15,8 @@
|
||||
#include "protobuf.h"
|
||||
#include "protobuf/inventory.pb-c.h"
|
||||
|
||||
bool fdinfo_per_id = false;
|
||||
|
||||
int check_img_inventory(void)
|
||||
{
|
||||
int fd, ret;
|
||||
@@ -29,6 +31,8 @@ int check_img_inventory(void)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
fdinfo_per_id = he->has_fdinfo_per_id ? he->fdinfo_per_id : false;
|
||||
|
||||
ret = he->img_version;
|
||||
inventory_entry__free_unpacked(he, NULL);
|
||||
|
||||
@@ -52,6 +56,8 @@ int write_img_inventory(void)
|
||||
return -1;
|
||||
|
||||
he.img_version = CRTOOLS_IMAGES_V1;
|
||||
he.fdinfo_per_id = true;
|
||||
he.has_fdinfo_per_id = true;
|
||||
|
||||
if (pb_write_one(fd, &he, PB_INVENTORY) < 0)
|
||||
return -1;
|
||||
|
@@ -24,7 +24,6 @@ enum {
|
||||
*/
|
||||
|
||||
_CR_FD_TASK_FROM,
|
||||
CR_FD_FDINFO,
|
||||
CR_FD_PAGES,
|
||||
CR_FD_CORE,
|
||||
CR_FD_IDS,
|
||||
@@ -57,6 +56,7 @@ enum {
|
||||
CR_FD_SHMEM_PAGES,
|
||||
CR_FD_GHOST_FILE,
|
||||
CR_FD_TCP_STREAM,
|
||||
CR_FD_FDINFO,
|
||||
|
||||
_CR_FD_GLOB_FROM,
|
||||
CR_FD_SK_QUEUES,
|
||||
|
@@ -87,7 +87,7 @@ extern int rst_file_params(int fd, FownEntry *fown, int flags);
|
||||
extern void show_saved_files(void);
|
||||
|
||||
extern int prepare_fds(struct pstree_item *me);
|
||||
extern int prepare_fd_pid(int pid, struct rst_info *rst_info);
|
||||
extern int prepare_fd_pid(struct pstree_item *me);
|
||||
extern int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id);
|
||||
extern int prepare_shared_fdinfo(void);
|
||||
extern int get_filemap_fd(int pid, VmaEntry *vma_entry);
|
||||
|
@@ -135,4 +135,6 @@ struct page_entry {
|
||||
#define GET_FILE_OFF(s, m) (offsetof(s,m) + MAGIC_OFFSET)
|
||||
#define GET_FILE_OFF_AFTER(s) (sizeof(s) + MAGIC_OFFSET)
|
||||
|
||||
extern bool fdinfo_per_id;
|
||||
|
||||
#endif /* __CR_IMAGE_H__ */
|
||||
|
@@ -1,3 +1,4 @@
|
||||
message inventory_entry {
|
||||
required uint32 img_version = 1;
|
||||
optional bool fdinfo_per_id = 2;
|
||||
}
|
||||
|
Reference in New Issue
Block a user