Commit b7121823 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

Gather file names formats in one place

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 0fd17a08
......@@ -297,7 +297,7 @@ static int prepare_shmem_pid(int pid)
int sh_fd;
u32 type = 0;
sh_fd = open_fmt_ro("shmem-%d.img", pid);
sh_fd = open_fmt_ro(FMT_FNAME_SHMEM, pid);
if (sh_fd < 0) {
perror("Can't open shmem info");
return 1;
......@@ -335,7 +335,7 @@ static int prepare_pipes_pid(int pid)
int p_fd;
u32 type = 0;
p_fd = open_fmt_ro("pipes-%d.img", pid);
p_fd = open_fmt_ro(FMT_FNAME_PIPES, pid);
if (p_fd < 0) {
perror("Can't open pipes image");
return 1;
......@@ -516,7 +516,7 @@ static int prepare_fds(int pid)
pr_info("%d: Opening files img\n", pid);
fdinfo_fd = open_fmt_ro("fdinfo-%d.img", pid);
fdinfo_fd = open_fmt_ro(FMT_FNAME_FDINFO, pid);
if (fdinfo_fd < 0) {
pr_perror("Can't open %d fdinfo", pid);
return 1;
......@@ -595,7 +595,7 @@ static int prepare_shmem(int pid)
int sh_fd;
u32 type = 0;
sh_fd = open_fmt_ro("shmem-%d.img", pid);
sh_fd = open_fmt_ro(FMT_FNAME_SHMEM, pid);
if (sh_fd < 0) {
perror("Can't open shmem info");
return 1;
......@@ -751,7 +751,7 @@ static int fixup_pages_data(int pid, int fd)
pr_info("%d: Reading shmem pages img\n", pid);
shfd = open_fmt_ro("pages-shmem-%d.img", pid);
shfd = open_fmt_ro(FMT_FNAME_PAGES_SHMEM, pid);
if (shfd < 0) {
pr_perror("Can't open %d shmem image %s", pid);
return 1;
......@@ -833,7 +833,7 @@ static int prepare_and_sigreturn(int pid)
int fd, fd_new;
struct stat buf;
fd = open_fmt_ro("core-%d.img", pid);
fd = open_fmt_ro(FMT_FNAME_CORE, pid);
if (fd < 0) {
perror("Can't open exec image");
return 1;
......@@ -844,7 +844,7 @@ static int prepare_and_sigreturn(int pid)
return 1;
}
sprintf(path, "core-%d.img.out", pid);
sprintf(path, FMT_FNAME_CORE_OUT, pid);
unlink(path);
fd_new = open(path, O_RDWR | O_CREAT | O_EXCL, 0700);
......@@ -1035,7 +1035,7 @@ static int prepare_pipes(int pid)
pr_info("%d: Opening pipes\n", pid);
pipes_fd = open_fmt_ro("pipes-%d.img", pid);
pipes_fd = open_fmt_ro(FMT_FNAME_PIPES, pid);
if (pipes_fd < 0) {
perror("Can't open pipes img");
return 1;
......@@ -1200,7 +1200,7 @@ static int restore_all_tasks(pid_t pid)
int pstree_fd;
u32 type = 0;
sprintf(path, "pstree-%d.img", pid);
sprintf(path, FMT_FNAME_PSTREE, pid);
pstree_fd = open(path, O_RDONLY);
if (pstree_fd < 0) {
perror("Can't open pstree image");
......@@ -1239,7 +1239,7 @@ static long restorer_vma_hint(pid_t pid, struct list_head *self_vma_list, long v
* better to stick with it.
*/
snprintf(path, sizeof(path), "core-%d.img", pid);
snprintf(path, sizeof(path), FMT_FNAME_CORE, pid);
fd = open(path, O_RDONLY, CR_FD_PERM);
if (fd < 0) {
pr_perror("Can't open %s\n", path);
......@@ -1319,14 +1319,14 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
BUILD_BUG_ON(sizeof(struct task_restore_core_args) & 1);
BUILD_BUG_ON(sizeof(struct thread_restore_args) & 1);
snprintf(path, sizeof(path), "pstree-%d.img", pstree_pid);
snprintf(path, sizeof(path), FMT_FNAME_PSTREE, pstree_pid);
fd_pstree = open(path, O_RDONLY, CR_FD_PERM);
if (fd_pstree < 0) {
pr_perror("Can't open %s\n", path);
goto err;
}
snprintf(path, sizeof(path), "vmas-%d.img", getpid());
snprintf(path, sizeof(path), FMT_FNAME_VMAS, getpid());
unlink(path);
fd_vmas = open(path, O_CREAT | O_WRONLY, CR_FD_PERM);
if (fd_vmas < 0) {
......@@ -1450,7 +1450,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
strcpy(args->self_vmas_path, path);
snprintf(path, sizeof(path), "core-%d.img.out", pid);
snprintf(path, sizeof(path), FMT_FNAME_CORE_OUT, pid);
strcpy(args->core_path, path);
pr_info("restore_task_vma_len: %li restore_task_code_len: %li\n"
......@@ -1496,7 +1496,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
thread_args[i].lock = args->lock;
snprintf(path, sizeof(path), "core-%d.img", thread_args[i].pid);
snprintf(path, sizeof(path), FMT_FNAME_CORE, thread_args[i].pid);
thread_args[i].fd_core = open(path, O_RDONLY, CR_FD_PERM);
if (thread_args[i].fd_core < 0) {
pr_perror("Can't open %s\n", path);
......
......@@ -36,53 +36,47 @@ struct page_entry zero_page_entry;
* for more details.
*/
static struct cr_fd_desc_tmpl template[CR_FD_MAX] = {
struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = {
/* info about file descriptiors */
[CR_FD_FDINFO] = {
.fmt = "fdinfo-%d.img",
.fmt = FMT_FNAME_FDINFO,
.magic = FDINFO_MAGIC,
},
/* private memory pages data */
[CR_FD_PAGES] = {
.fmt = "pages-%d.img",
.fmt = FMT_FNAME_PAGES,
.magic = PAGES_MAGIC,
},
/* shared memory pages data */
[CR_FD_PAGES_SHMEM] = {
.fmt = "pages-shmem-%d.img",
.fmt = FMT_FNAME_PAGES_SHMEM,
.magic = PAGES_MAGIC,
},
/*
* The main part of restoring a single process is calling
* execve syscall on an ELF image which contains memory
* and arch-specific (regs, fpu) data about a process.
*
* Thus this file contains the almost-ready for execve image.
*/
/* core data, such as regs and vmas and such */
[CR_FD_CORE] = {
.fmt = "core-%d.img",
.fmt = FMT_FNAME_CORE,
.magic = CORE_MAGIC,
},
/* info about pipes - fds, pipe id and pipe data */
[CR_FD_PIPES] = {
.fmt = "pipes-%d.img",
.fmt = FMT_FNAME_PIPES,
.magic = PIPES_MAGIC,
},
/* info about process linkage */
[CR_FD_PSTREE] = {
.fmt = "pstree-%d.img",
.fmt = FMT_FNAME_PSTREE,
.magic = PSTREE_MAGIC,
},
/* info about which memory areas are shared */
[CR_FD_SHMEM] = {
.fmt = "shmem-%d.img",
.fmt = FMT_FNAME_SHMEM,
.magic = SHMEM_MAGIC,
},
};
......@@ -97,7 +91,7 @@ struct cr_fdset *alloc_cr_fdset(pid_t pid)
goto err;
for (i = 0; i < CR_FD_MAX; i++) {
cr_fdset->desc[i].tmpl = &template[i];
cr_fdset->desc[i].tmpl = &fdset_template[i];
snprintf(cr_fdset->desc[i].name,
sizeof(cr_fdset->desc[i].name),
cr_fdset->desc[i].tmpl->fmt,
......
......@@ -42,6 +42,16 @@ struct cr_fd_desc_tmpl {
u32 magic; /* magic in the header */
};
#define FMT_FNAME_FDINFO "fdinfo-%d.img"
#define FMT_FNAME_PAGES "pages-%d.img"
#define FMT_FNAME_PAGES_SHMEM "pages-shmem-%d.img"
#define FMT_FNAME_CORE "core-%d.img"
#define FMT_FNAME_CORE_OUT "core-%d.img.out"
#define FMT_FNAME_PIPES "pipes-%d.img"
#define FMT_FNAME_PSTREE "pstree-%d.img"
#define FMT_FNAME_SHMEM "shmem-%d.img"
#define FMT_FNAME_VMAS "vmas-%d.img"
/* file descriptors */
struct cr_fd_desc {
struct cr_fd_desc_tmpl *tmpl; /* template we refer to */
......
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