Commit d50c786c authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

files: dump fdinfo per files_id instead of pid

A few processes can share one fdtable.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent bb25ed38
...@@ -355,10 +355,10 @@ static int dump_one_file(struct parasite_ctl *ctl, int fd, int lfd, struct fd_op ...@@ -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); 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) struct parasite_drain_fd *dfds)
{ {
int *lfds; int *lfds, fdinfo;
struct fd_opts *opts; struct fd_opts *opts;
int i, ret = -1; int i, ret = -1;
...@@ -378,13 +378,19 @@ static int dump_task_files_seized(struct parasite_ctl *ctl, const int fdinfo, ...@@ -378,13 +378,19 @@ static int dump_task_files_seized(struct parasite_ctl *ctl, const int fdinfo,
if (ret) if (ret)
goto err2; 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++) { for (i = 0; i < dfds->nr_fds; i++) {
ret = dump_one_file(ctl, dfds->fds[i], lfds[i], opts + i, fdinfo); ret = dump_one_file(ctl, dfds->fds[i], lfds[i], opts + i, fdinfo);
close(lfds[i]); close(lfds[i]);
if (ret) if (ret)
goto err2; break;
} }
close(fdinfo);
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
err2: err2:
xfree(opts); xfree(opts);
...@@ -1453,7 +1459,13 @@ static int dump_one_task(struct pstree_item *item) ...@@ -1453,7 +1459,13 @@ static int dump_one_task(struct pstree_item *item)
if (!cr_fdset) if (!cr_fdset)
goto err_cure; 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) { if (ret) {
pr_err("Dump files (pid: %d) failed with %d\n", pid, ret); pr_err("Dump files (pid: %d) failed with %d\n", pid, ret);
goto err_cure; goto err_cure;
...@@ -1484,12 +1496,6 @@ static int dump_one_task(struct pstree_item *item) ...@@ -1484,12 +1496,6 @@ static int dump_one_task(struct pstree_item *item)
goto err_cure; 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); ret = dump_task_threads(parasite_ctl, item);
if (ret) { if (ret) {
pr_err("Can't dump threads\n"); pr_err("Can't dump threads\n");
......
...@@ -156,7 +156,7 @@ static int root_prepare_shared(void) ...@@ -156,7 +156,7 @@ static int root_prepare_shared(void)
if (ret < 0) if (ret < 0)
break; break;
ret = prepare_fd_pid(pi->pid.virt, pi->rst); ret = prepare_fd_pid(pi);
if (ret < 0) if (ret < 0)
break; break;
} }
......
...@@ -217,19 +217,32 @@ int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id) ...@@ -217,19 +217,32 @@ int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id)
return 0; 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; 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->fds);
INIT_LIST_HEAD(&rst_info->eventpoll); INIT_LIST_HEAD(&rst_info->eventpoll);
INIT_LIST_HEAD(&rst_info->tty_slaves); INIT_LIST_HEAD(&rst_info->tty_slaves);
fdinfo_fd = open_image_ro(CR_FD_FDINFO, pid); if (!fdinfo_per_id) {
if (fdinfo_fd < 0) { fdinfo_fd = open_image_ro(CR_FD_FDINFO, pid);
if (errno == ENOENT) if (fdinfo_fd < 0) {
if (errno == ENOENT)
return 0;
return -1;
}
} else {
if (item->ids == NULL) /* zombie */
return 0; return 0;
else
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; return -1;
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "protobuf.h" #include "protobuf.h"
#include "protobuf/inventory.pb-c.h" #include "protobuf/inventory.pb-c.h"
bool fdinfo_per_id = false;
int check_img_inventory(void) int check_img_inventory(void)
{ {
int fd, ret; int fd, ret;
...@@ -29,6 +31,8 @@ int check_img_inventory(void) ...@@ -29,6 +31,8 @@ int check_img_inventory(void)
if (ret < 0) if (ret < 0)
return ret; return ret;
fdinfo_per_id = he->has_fdinfo_per_id ? he->fdinfo_per_id : false;
ret = he->img_version; ret = he->img_version;
inventory_entry__free_unpacked(he, NULL); inventory_entry__free_unpacked(he, NULL);
...@@ -52,6 +56,8 @@ int write_img_inventory(void) ...@@ -52,6 +56,8 @@ int write_img_inventory(void)
return -1; return -1;
he.img_version = CRTOOLS_IMAGES_V1; 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) if (pb_write_one(fd, &he, PB_INVENTORY) < 0)
return -1; return -1;
......
...@@ -24,7 +24,6 @@ enum { ...@@ -24,7 +24,6 @@ enum {
*/ */
_CR_FD_TASK_FROM, _CR_FD_TASK_FROM,
CR_FD_FDINFO,
CR_FD_PAGES, CR_FD_PAGES,
CR_FD_CORE, CR_FD_CORE,
CR_FD_IDS, CR_FD_IDS,
...@@ -57,6 +56,7 @@ enum { ...@@ -57,6 +56,7 @@ enum {
CR_FD_SHMEM_PAGES, CR_FD_SHMEM_PAGES,
CR_FD_GHOST_FILE, CR_FD_GHOST_FILE,
CR_FD_TCP_STREAM, CR_FD_TCP_STREAM,
CR_FD_FDINFO,
_CR_FD_GLOB_FROM, _CR_FD_GLOB_FROM,
CR_FD_SK_QUEUES, CR_FD_SK_QUEUES,
......
...@@ -87,7 +87,7 @@ extern int rst_file_params(int fd, FownEntry *fown, int flags); ...@@ -87,7 +87,7 @@ extern int rst_file_params(int fd, FownEntry *fown, int flags);
extern void show_saved_files(void); extern void show_saved_files(void);
extern int prepare_fds(struct pstree_item *me); 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_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id);
extern int prepare_shared_fdinfo(void); extern int prepare_shared_fdinfo(void);
extern int get_filemap_fd(int pid, VmaEntry *vma_entry); extern int get_filemap_fd(int pid, VmaEntry *vma_entry);
......
...@@ -135,4 +135,6 @@ struct page_entry { ...@@ -135,4 +135,6 @@ struct page_entry {
#define GET_FILE_OFF(s, m) (offsetof(s,m) + MAGIC_OFFSET) #define GET_FILE_OFF(s, m) (offsetof(s,m) + MAGIC_OFFSET)
#define GET_FILE_OFF_AFTER(s) (sizeof(s) + MAGIC_OFFSET) #define GET_FILE_OFF_AFTER(s) (sizeof(s) + MAGIC_OFFSET)
extern bool fdinfo_per_id;
#endif /* __CR_IMAGE_H__ */ #endif /* __CR_IMAGE_H__ */
message inventory_entry { message inventory_entry {
required uint32 img_version = 1; required uint32 img_version = 1;
optional bool fdinfo_per_id = 2;
} }
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