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_CORE,
|
2012-03-21 14:22:00 +04:00
|
|
|
CR_FD_VMAS,
|
2011-09-23 12:00:45 +04:00
|
|
|
CR_FD_PIPES,
|
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,
|
2012-01-27 21:43:32 +04:00
|
|
|
CR_FD_CREDS,
|
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-02-08 12:13:38 +03:00
|
|
|
CR_FD_IPCNS_VAR,
|
2012-02-09 12:09:41 +03:00
|
|
|
CR_FD_IPCNS_SHM,
|
2012-02-13 20:27:35 +03:00
|
|
|
CR_FD_IPCNS_MSG,
|
2012-02-14 19:54:06 +03:00
|
|
|
CR_FD_IPCNS_SEM,
|
2012-01-26 15:23:00 +04:00
|
|
|
|
2012-02-29 16:06:48 +03:00
|
|
|
CR_FD_SK_QUEUES,
|
|
|
|
|
2012-03-19 15:38:00 +04:00
|
|
|
CR_FD_PID_MAX, /* fmt, pid */
|
|
|
|
|
2012-03-21 10:12:00 +04:00
|
|
|
CR_FD_SHMEM_PAGES,
|
2012-03-25 20:24:53 +04:00
|
|
|
CR_FD_REG_FILES,
|
2012-03-21 10:12:00 +04:00
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
CR_FD_MAX
|
|
|
|
};
|
|
|
|
|
2011-10-04 01:50:19 +04:00
|
|
|
struct cr_options {
|
2012-03-01 19:09:02 +04:00
|
|
|
int final_state;
|
2012-01-26 15:27:00 +04:00
|
|
|
char *show_dump_file;
|
|
|
|
bool leader_only;
|
|
|
|
bool show_pages_content;
|
|
|
|
bool restore_detach;
|
2012-01-31 22:28:22 +04:00
|
|
|
unsigned int namespaces_flags;
|
2011-10-04 01:50:19 +04:00
|
|
|
};
|
|
|
|
|
2012-03-16 17:21:00 +04:00
|
|
|
enum {
|
|
|
|
LOG_FD_OFF = 1,
|
|
|
|
IMG_FD_OFF,
|
2012-03-24 13:22:37 +04:00
|
|
|
SELF_EXE_FD_OFF,
|
2012-03-16 17:21:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
int get_service_fd(int type);
|
|
|
|
|
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"
|
2012-03-21 10:12:00 +04:00
|
|
|
#define FMT_FNAME_SHMEM_PAGES "pages-shmem-%ld.img"
|
2012-03-25 20:24:53 +04:00
|
|
|
#define FMT_FNAME_REG_FILES "reg-files.img"
|
2011-11-15 18:35:55 +04:00
|
|
|
#define FMT_FNAME_CORE "core-%d.img"
|
2012-03-21 14:22:00 +04:00
|
|
|
#define FMT_FNAME_VMAS "vmas-%d.img"
|
2011-11-15 18:35:55 +04:00
|
|
|
#define FMT_FNAME_PIPES "pipes-%d.img"
|
|
|
|
#define FMT_FNAME_PSTREE "pstree-%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-27 21:43:32 +04:00
|
|
|
#define FMT_FNAME_CREDS "creds-%d.img"
|
2012-01-26 15:28:00 +04:00
|
|
|
#define FMT_FNAME_UTSNS "utsns-%d.img"
|
2012-02-08 12:13:38 +03:00
|
|
|
#define FMT_FNAME_IPCNS_VAR "ipcns-var-%d.img"
|
2012-02-09 12:09:41 +03:00
|
|
|
#define FMT_FNAME_IPCNS_SHM "ipcns-shm-%d.img"
|
2012-02-13 20:27:35 +03:00
|
|
|
#define FMT_FNAME_IPCNS_MSG "ipcns-msg-%d.img"
|
2012-02-14 19:54:06 +03:00
|
|
|
#define FMT_FNAME_IPCNS_SEM "ipcns-sem-%d.img"
|
2012-02-29 16:06:48 +03:00
|
|
|
#define FMT_FNAME_SK_QUEUES "sk-queues-%d.img"
|
2011-11-15 18:35:55 +04:00
|
|
|
|
2012-03-16 17:24:00 +04:00
|
|
|
/*
|
|
|
|
* FIXME -- this is required for legacy image copy only.
|
|
|
|
* Don't use it for other reason and remove the former one.
|
|
|
|
*/
|
|
|
|
extern int image_dir_fd;
|
|
|
|
extern int open_image_dir(void);
|
|
|
|
extern void close_image_dir(void);
|
2012-03-19 15:38:00 +04:00
|
|
|
|
|
|
|
int open_image(int type, unsigned long flags, ...);
|
2012-03-25 21:05:32 +04:00
|
|
|
#define open_image_ro(type, ...) open_image(type, O_RDONLY, ##__VA_ARGS__)
|
2012-03-23 18:41:00 +04:00
|
|
|
extern int open_image_ro_nocheck(const char *fmt, ...);
|
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-03-19 15:38:00 +04:00
|
|
|
int fds[CR_FD_PID_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)
|
2012-03-02 11:09:39 +04:00
|
|
|
#define CR_FD_DESC_SK_QUEUES CR_FD_DESC_USE(CR_FD_SK_QUEUES)
|
2012-01-26 15:23:00 +04:00
|
|
|
#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_CORE) |\
|
2012-03-21 14:22:00 +04:00
|
|
|
CR_FD_DESC_USE(CR_FD_VMAS) |\
|
2012-01-26 15:23:00 +04:00
|
|
|
CR_FD_DESC_USE(CR_FD_PIPES) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_SIGACT) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_UNIXSK) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_INETSK) |\
|
2012-01-27 21:43:32 +04:00
|
|
|
CR_FD_DESC_USE(CR_FD_ITIMERS) |\
|
|
|
|
CR_FD_DESC_USE(CR_FD_CREDS) )
|
2012-01-26 15:28:00 +04:00
|
|
|
#define CR_FD_DESC_NS (\
|
2012-01-31 22:28:55 +04:00
|
|
|
CR_FD_DESC_USE(CR_FD_UTSNS) |\
|
2012-02-09 12:09:41 +03:00
|
|
|
CR_FD_DESC_USE(CR_FD_IPCNS_VAR) |\
|
2012-02-13 20:27:35 +03:00
|
|
|
CR_FD_DESC_USE(CR_FD_IPCNS_MSG) |\
|
2012-02-14 19:54:06 +03:00
|
|
|
CR_FD_DESC_USE(CR_FD_IPCNS_SEM) |\
|
2012-02-09 12:09:41 +03:00
|
|
|
CR_FD_DESC_USE(CR_FD_IPCNS_SHM) )
|
2011-09-23 12:00:45 +04:00
|
|
|
#define CR_FD_DESC_NONE (0)
|
|
|
|
|
2012-03-06 14:20:00 +04:00
|
|
|
int cr_dump_tasks(pid_t pid, const struct cr_options *opts);
|
2011-10-04 01:50:19 +04:00
|
|
|
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);
|
2012-03-02 14:01:08 +04:00
|
|
|
int cr_check(void);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-02-08 20:19:39 +03:00
|
|
|
struct cr_fdset *cr_dump_fdset_open(int pid, unsigned long use_mask, struct cr_fdset *);
|
|
|
|
struct cr_fdset *cr_show_fdset_open(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;
|
|
|
|
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 */
|
2012-03-01 19:04:31 +04:00
|
|
|
pid_t ppid;
|
ctrools: Rewrite task/threads stopping engine is back
This commit brings the former "Rewrite task/threads stopping engine"
commit back. Handling it separately is too complex so better try
to handle it in-place.
Note some tests might fault, it's expected.
---
Stopping tasks with STOP and proceeding with SEIZE is actually excessive --
the SEIZE if enough. Moreover, just killing a task with STOP is also racy,
since task should be given some time to come to sleep before its proc
can be parsed.
Rewrite all this code to SEIZE task and all its threads from the very beginning.
With this we can distinguish stopped task state and migrate it properly (not
supported now, need to implement).
This thing however has one BIG problem -- after we SEIZE-d a task we should
seize
it's threads, but we should do it in a loop -- reading /proc/pid/task and
seizing
them again and again, until the contents of this dir stops changing (not done
now).
Besides, after we seized a task and all its threads we cannot scan it's children
list once -- task can get reparented to init and any task's child can call clone
with CLONE_PARENT flag thus repopulating the children list of the already seized
task (not done also)
This patch is ugly, yes, but splitting it doesn't help to review it much, sorry
:(
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-02-01 19:45:31 +04:00
|
|
|
int state; /* TASK_XXX constants */
|
2012-03-01 19:07:15 +04:00
|
|
|
int nr_children; /* number of children */
|
|
|
|
int nr_threads; /* number of threads */
|
2011-10-20 11:03:19 +04:00
|
|
|
u32 *threads; /* array of threads */
|
2011-09-23 12:00:45 +04:00
|
|
|
u32 *children; /* array of children */
|
|
|
|
};
|
|
|
|
|
2012-02-29 16:07:19 +03:00
|
|
|
extern pid_t pstree_pid;
|
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
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_ */
|