2011-09-23 12:00:45 +04:00
|
|
|
#ifndef CRTOOLS_H_
|
|
|
|
#define CRTOOLS_H_
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "list.h"
|
|
|
|
|
|
|
|
#include "image.h"
|
|
|
|
|
|
|
|
extern struct page_entry zero_page_entry;
|
2011-12-05 15:57:47 +04:00
|
|
|
extern void free_pstree(struct list_head *pstree_list);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2011-10-03 11:52:13 +04:00
|
|
|
#define CR_FD_PERM (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
|
|
|
|
#define CR_FD_PERM_DUMP (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
enum {
|
2012-01-26 15:23:00 +04:00
|
|
|
/*
|
|
|
|
* Task entries
|
|
|
|
*/
|
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
CR_FD_FDINFO,
|
|
|
|
CR_FD_PAGES,
|
|
|
|
CR_FD_PAGES_SHMEM,
|
|
|
|
CR_FD_CORE,
|
|
|
|
CR_FD_PIPES,
|
|
|
|
CR_FD_SHMEM,
|
2011-11-29 15:12:25 +03:00
|
|
|
CR_FD_SIGACT,
|
2011-12-26 22:12:03 +04:00
|
|
|
CR_FD_UNIXSK,
|
2012-01-17 21:30:00 +04:00
|
|
|
CR_FD_INETSK,
|
2012-01-24 16:45:19 +04:00
|
|
|
CR_FD_ITIMERS,
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-01-26 15:23:00 +04:00
|
|
|
/*
|
|
|
|
* Global entries
|
|
|
|
*/
|
|
|
|
|
|
|
|
CR_FD_PSTREE,
|
2012-01-26 15:28:00 +04:00
|
|
|
CR_FD_UTSNS,
|
2012-01-26 15:23:00 +04:00
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
CR_FD_MAX
|
|
|
|
};
|
|
|
|
|
2012-01-11 13:29:35 +04:00
|
|
|
enum cr_task_state {
|
|
|
|
CR_TASK_RUN,
|
|
|
|
CR_TASK_STOP,
|
|
|
|
CR_TASK_KILL,
|
2011-10-04 01:50:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cr_options {
|
2012-01-26 15:27:00 +04:00
|
|
|
enum cr_task_state final_state;
|
|
|
|
char *show_dump_file;
|
|
|
|
bool leader_only;
|
|
|
|
bool show_pages_content;
|
|
|
|
bool restore_detach;
|
|
|
|
bool with_namespaces;
|
2011-10-04 01:50:19 +04:00
|
|
|
};
|
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
/* file descriptors template */
|
|
|
|
struct cr_fd_desc_tmpl {
|
|
|
|
const char *fmt; /* format for the name */
|
|
|
|
u32 magic; /* magic in the header */
|
|
|
|
};
|
|
|
|
|
2011-12-29 19:56:34 +04:00
|
|
|
extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
|
|
|
|
|
2011-11-15 18:35:55 +04:00
|
|
|
#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"
|
2011-11-29 15:12:25 +03:00
|
|
|
#define FMT_FNAME_SIGACTS "sigacts-%d.img"
|
2011-12-26 22:12:03 +04:00
|
|
|
#define FMT_FNAME_UNIXSK "unixsk-%d.img"
|
2012-01-17 21:30:00 +04:00
|
|
|
#define FMT_FNAME_INETSK "inetsk-%d.img"
|
2012-01-24 16:45:19 +04:00
|
|
|
#define FMT_FNAME_ITIMERS "itimers-%d.img"
|
2012-01-26 15:28:00 +04:00
|
|
|
#define FMT_FNAME_UTSNS "utsns-%d.img"
|
2011-11-15 18:35:55 +04:00
|
|
|
|
2011-12-07 13:48:00 +04:00
|
|
|
extern int get_image_path(char *path, int size, const char *fmt, int pid);
|
|
|
|
|
|
|
|
extern char image_dir[];
|
2011-12-29 19:56:34 +04:00
|
|
|
extern int open_image_ro(int type, int pid);
|
|
|
|
extern int open_image_ro_nocheck(const char *fmt, int pid);
|
2011-12-07 13:48:00 +04:00
|
|
|
|
2011-12-01 18:21:17 +04:00
|
|
|
#define LAST_PID_PATH "/proc/sys/kernel/ns_last_pid"
|
2011-12-02 11:42:41 +04:00
|
|
|
#define LAST_PID_PERM 0666
|
2011-12-01 18:21:17 +04:00
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
struct cr_fdset {
|
2012-01-12 15:17:51 +04:00
|
|
|
int fds[CR_FD_MAX];
|
2011-09-23 12:00:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define CR_FD_DESC_USE(type) ((1 << (type)))
|
2011-10-20 17:19:26 +04:00
|
|
|
#define CR_FD_DESC_CORE CR_FD_DESC_USE(CR_FD_CORE)
|
2012-01-26 15:23:00 +04:00
|
|
|
#define CR_FD_DESC_PSTREE CR_FD_DESC_USE(CR_FD_PSTREE)
|
|
|
|
#define CR_FD_DESC_TASK (\
|
|
|
|
CR_FD_DESC_USE(CR_FD_FDINFO) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_PAGES) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_PAGES_SHMEM) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_CORE) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_PIPES) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_SHMEM) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_SIGACT) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_UNIXSK) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_INETSK) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_ITIMERS) )
|
2012-01-26 15:28:00 +04:00
|
|
|
#define CR_FD_DESC_NS (\
|
|
|
|
CR_FD_DESC_USE(CR_FD_UTSNS) )
|
2011-09-23 12:00:45 +04:00
|
|
|
#define CR_FD_DESC_NONE (0)
|
|
|
|
|
2011-10-04 01:50:19 +04:00
|
|
|
int cr_dump_tasks(pid_t pid, struct cr_options *opts);
|
|
|
|
int cr_restore_tasks(pid_t pid, struct cr_options *opts);
|
|
|
|
int cr_show(unsigned long pid, struct cr_options *opts);
|
|
|
|
int convert_to_elf(char *elf_path, int fd_core);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-01-22 20:15:11 +04:00
|
|
|
struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, struct cr_fdset *);
|
2012-01-12 15:18:32 +04:00
|
|
|
struct cr_fdset *prep_cr_fdset_for_restore(int pid, unsigned long use_mask);
|
2012-01-12 21:25:19 +04:00
|
|
|
void close_cr_fdset(struct cr_fdset **cr_fdset);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2011-10-26 22:48:10 +04:00
|
|
|
void free_mappings(struct list_head *vma_area_list);
|
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
struct vma_area {
|
|
|
|
struct list_head list;
|
|
|
|
struct vma_entry vma;
|
|
|
|
unsigned long shmid;
|
|
|
|
int vm_file_fd;
|
|
|
|
};
|
|
|
|
|
2011-11-15 17:12:29 +04:00
|
|
|
#define vma_area_is(vma_area, s) vma_entry_is(&((vma_area)->vma), s)
|
|
|
|
#define vma_area_len(vma_area) vma_entry_len(&((vma_area)->vma))
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
struct pstree_item {
|
|
|
|
struct list_head list;
|
|
|
|
pid_t pid; /* leader pid */
|
|
|
|
u32 nr_children; /* number of children */
|
2011-10-20 11:03:19 +04:00
|
|
|
u32 nr_threads; /* number of threads */
|
|
|
|
u32 *threads; /* array of threads */
|
2011-09-23 12:00:45 +04:00
|
|
|
u32 *children; /* array of children */
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int in_vma_area(struct vma_area *vma, unsigned long addr)
|
|
|
|
{
|
|
|
|
return addr >= (unsigned long)vma->vma.start &&
|
|
|
|
addr < (unsigned long)vma->vma.end;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CRTOOLS_H_ */
|