2011-09-23 12:00:45 +04:00
|
|
|
#ifndef CRTOOLS_H_
|
|
|
|
#define CRTOOLS_H_
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "list.h"
|
fdset: Introduce new fdsets
Current fdsets are ugly, limited (bitmask will exhaust in several months) and
suffer from unknown problems with fdsets reuse :(
With new approach (this set) the images management is simple. The basic function
is open_image, which gives you an fd for an image. If you want to pre-open several
images at once instead of calling open_image every single time, you can use the
new fdsets.
Images CR_FD_ descriptors should be grouped like
_CR_FD_FOO_FROM,
CR_FD_FOO_ITEM1,
CR_FD_FOO_ITEM2,
..
CR_FD_FOO_ITEMN,
_CR_FD_FOO_TO,
After this you can call cr_fd_open() specifying ranges -- _FROM and _TO macros,
it will give you an cr_fdset object. Then the fdset_fd(set, type) will give you
the descriptor of the open "set" group corresponding to the "type" type.
3 groups are introduced in this set -- tasks, ns and global.
That's it.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-26 17:46:39 +04:00
|
|
|
#include "util.h"
|
2011-09-23 12:00:45 +04:00
|
|
|
#include "image.h"
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
fdset: Introduce new fdsets
Current fdsets are ugly, limited (bitmask will exhaust in several months) and
suffer from unknown problems with fdsets reuse :(
With new approach (this set) the images management is simple. The basic function
is open_image, which gives you an fd for an image. If you want to pre-open several
images at once instead of calling open_image every single time, you can use the
new fdsets.
Images CR_FD_ descriptors should be grouped like
_CR_FD_FOO_FROM,
CR_FD_FOO_ITEM1,
CR_FD_FOO_ITEM2,
..
CR_FD_FOO_ITEMN,
_CR_FD_FOO_TO,
After this you can call cr_fd_open() specifying ranges -- _FROM and _TO macros,
it will give you an cr_fdset object. Then the fdset_fd(set, type) will give you
the descriptor of the open "set" group corresponding to the "type" type.
3 groups are introduced in this set -- tasks, ns and global.
That's it.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-26 17:46:39 +04:00
|
|
|
_CR_FD_TASK_FROM,
|
2011-09-23 12:00:45 +04:00
|
|
|
CR_FD_FDINFO,
|
|
|
|
CR_FD_PAGES,
|
|
|
|
CR_FD_CORE,
|
2012-04-09 14:51:37 +04:00
|
|
|
CR_FD_MM,
|
2012-03-21 14:22:00 +04:00
|
|
|
CR_FD_VMAS,
|
2011-11-29 15:12:25 +03:00
|
|
|
CR_FD_SIGACT,
|
2012-01-24 16:45:19 +04:00
|
|
|
CR_FD_ITIMERS,
|
2012-01-27 21:43:32 +04:00
|
|
|
CR_FD_CREDS,
|
2012-04-09 13:41:05 +04:00
|
|
|
CR_FD_FS,
|
fdset: Introduce new fdsets
Current fdsets are ugly, limited (bitmask will exhaust in several months) and
suffer from unknown problems with fdsets reuse :(
With new approach (this set) the images management is simple. The basic function
is open_image, which gives you an fd for an image. If you want to pre-open several
images at once instead of calling open_image every single time, you can use the
new fdsets.
Images CR_FD_ descriptors should be grouped like
_CR_FD_FOO_FROM,
CR_FD_FOO_ITEM1,
CR_FD_FOO_ITEM2,
..
CR_FD_FOO_ITEMN,
_CR_FD_FOO_TO,
After this you can call cr_fd_open() specifying ranges -- _FROM and _TO macros,
it will give you an cr_fdset object. Then the fdset_fd(set, type) will give you
the descriptor of the open "set" group corresponding to the "type" type.
3 groups are introduced in this set -- tasks, ns and global.
That's it.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-26 17:46:39 +04:00
|
|
|
_CR_FD_TASK_TO,
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-01-26 15:23:00 +04:00
|
|
|
/*
|
fdset: Introduce new fdsets
Current fdsets are ugly, limited (bitmask will exhaust in several months) and
suffer from unknown problems with fdsets reuse :(
With new approach (this set) the images management is simple. The basic function
is open_image, which gives you an fd for an image. If you want to pre-open several
images at once instead of calling open_image every single time, you can use the
new fdsets.
Images CR_FD_ descriptors should be grouped like
_CR_FD_FOO_FROM,
CR_FD_FOO_ITEM1,
CR_FD_FOO_ITEM2,
..
CR_FD_FOO_ITEMN,
_CR_FD_FOO_TO,
After this you can call cr_fd_open() specifying ranges -- _FROM and _TO macros,
it will give you an cr_fdset object. Then the fdset_fd(set, type) will give you
the descriptor of the open "set" group corresponding to the "type" type.
3 groups are introduced in this set -- tasks, ns and global.
That's it.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-26 17:46:39 +04:00
|
|
|
* NS entries
|
2012-01-26 15:23:00 +04:00
|
|
|
*/
|
|
|
|
|
fdset: Introduce new fdsets
Current fdsets are ugly, limited (bitmask will exhaust in several months) and
suffer from unknown problems with fdsets reuse :(
With new approach (this set) the images management is simple. The basic function
is open_image, which gives you an fd for an image. If you want to pre-open several
images at once instead of calling open_image every single time, you can use the
new fdsets.
Images CR_FD_ descriptors should be grouped like
_CR_FD_FOO_FROM,
CR_FD_FOO_ITEM1,
CR_FD_FOO_ITEM2,
..
CR_FD_FOO_ITEMN,
_CR_FD_FOO_TO,
After this you can call cr_fd_open() specifying ranges -- _FROM and _TO macros,
it will give you an cr_fdset object. Then the fdset_fd(set, type) will give you
the descriptor of the open "set" group corresponding to the "type" type.
3 groups are introduced in this set -- tasks, ns and global.
That's it.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-26 17:46:39 +04:00
|
|
|
_CR_FD_NS_FROM,
|
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,
|
fdset: Introduce new fdsets
Current fdsets are ugly, limited (bitmask will exhaust in several months) and
suffer from unknown problems with fdsets reuse :(
With new approach (this set) the images management is simple. The basic function
is open_image, which gives you an fd for an image. If you want to pre-open several
images at once instead of calling open_image every single time, you can use the
new fdsets.
Images CR_FD_ descriptors should be grouped like
_CR_FD_FOO_FROM,
CR_FD_FOO_ITEM1,
CR_FD_FOO_ITEM2,
..
CR_FD_FOO_ITEMN,
_CR_FD_FOO_TO,
After this you can call cr_fd_open() specifying ranges -- _FROM and _TO macros,
it will give you an cr_fdset object. Then the fdset_fd(set, type) will give you
the descriptor of the open "set" group corresponding to the "type" type.
3 groups are introduced in this set -- tasks, ns and global.
That's it.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-26 17:46:39 +04:00
|
|
|
_CR_FD_NS_TO,
|
2012-03-19 15:38:00 +04:00
|
|
|
|
2012-03-26 17:46:04 +04:00
|
|
|
CR_FD_PSTREE,
|
2012-03-21 10:12:00 +04:00
|
|
|
CR_FD_SHMEM_PAGES,
|
2012-03-26 17:46:04 +04:00
|
|
|
|
2012-03-26 17:47:38 +04:00
|
|
|
_CR_FD_GLOB_FROM,
|
2012-03-26 17:46:04 +04:00
|
|
|
CR_FD_SK_QUEUES,
|
2012-03-25 20:24:53 +04:00
|
|
|
CR_FD_REG_FILES,
|
2012-03-27 12:42:59 +04:00
|
|
|
CR_FD_INETSK,
|
2012-04-06 19:27:08 +04:00
|
|
|
CR_FD_UNIXSK,
|
2012-04-05 20:02:00 +04:00
|
|
|
CR_FD_PIPES,
|
2012-04-05 20:02:00 +04:00
|
|
|
CR_FD_PIPES_DATA,
|
2012-03-26 17:47:38 +04:00
|
|
|
_CR_FD_GLOB_TO,
|
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 */
|
2012-03-27 12:01:14 +04:00
|
|
|
void (*show)(int fd, struct cr_options *o);
|
2011-09-23 12:00:45 +04:00
|
|
|
};
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_files(int fd_files, struct cr_options *o);
|
|
|
|
void show_pages(int fd_pages, struct cr_options *o);
|
|
|
|
void show_reg_files(int fd_reg_files, struct cr_options *o);
|
|
|
|
void show_core(int fd_core, struct cr_options *o);
|
2012-04-09 14:51:37 +04:00
|
|
|
void show_mm(int fd_mm, struct cr_options *o);
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_vmas(int fd_vma, struct cr_options *o);
|
|
|
|
void show_pipes(int fd_pipes, struct cr_options *o);
|
2012-04-05 20:02:00 +04:00
|
|
|
void show_pipes_data(int fd_pipes, struct cr_options *o);
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_pstree(int fd_pstree, struct cr_options *o);
|
|
|
|
void show_sigacts(int fd_sigacts, struct cr_options *o);
|
|
|
|
void show_itimers(int fd, struct cr_options *o);
|
|
|
|
void show_creds(int fd, struct cr_options *o);
|
2012-04-09 13:41:05 +04:00
|
|
|
void show_fs(int fd, struct cr_options *o);
|
2012-04-10 22:54:00 +04:00
|
|
|
void show_fown_cont(fown_t *fown);
|
2012-03-27 12:01:14 +04:00
|
|
|
|
2012-04-12 15:33:09 +04:00
|
|
|
extern void print_data(unsigned long addr, unsigned char *data, size_t size);
|
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-04-09 14:51:37 +04:00
|
|
|
#define FMT_FNAME_MM "mm-%d.img"
|
2012-03-21 14:22:00 +04:00
|
|
|
#define FMT_FNAME_VMAS "vmas-%d.img"
|
2012-04-05 20:02:00 +04:00
|
|
|
#define FMT_FNAME_PIPES "pipes.img"
|
2012-04-05 20:02:00 +04:00
|
|
|
#define FMT_FNAME_PIPES_DATA "pipes-data.img"
|
2012-03-23 18:42:00 +04:00
|
|
|
#define FMT_FNAME_PSTREE "pstree.img"
|
2011-11-29 15:12:25 +03:00
|
|
|
#define FMT_FNAME_SIGACTS "sigacts-%d.img"
|
2012-04-06 19:27:08 +04:00
|
|
|
#define FMT_FNAME_UNIXSK "unixsk.img"
|
2012-03-27 12:42:59 +04:00
|
|
|
#define FMT_FNAME_INETSK "inetsk.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-03-26 17:38:59 +04:00
|
|
|
#define FMT_FNAME_SK_QUEUES "sk-queues.img"
|
2012-04-09 13:41:05 +04:00
|
|
|
#define FMT_FNAME_FS "fs-%d.img"
|
2011-11-15 18:35:55 +04:00
|
|
|
|
2012-03-16 17:24:00 +04:00
|
|
|
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__)
|
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 {
|
fdset: Introduce new fdsets
Current fdsets are ugly, limited (bitmask will exhaust in several months) and
suffer from unknown problems with fdsets reuse :(
With new approach (this set) the images management is simple. The basic function
is open_image, which gives you an fd for an image. If you want to pre-open several
images at once instead of calling open_image every single time, you can use the
new fdsets.
Images CR_FD_ descriptors should be grouped like
_CR_FD_FOO_FROM,
CR_FD_FOO_ITEM1,
CR_FD_FOO_ITEM2,
..
CR_FD_FOO_ITEMN,
_CR_FD_FOO_TO,
After this you can call cr_fd_open() specifying ranges -- _FROM and _TO macros,
it will give you an cr_fdset object. Then the fdset_fd(set, type) will give you
the descriptor of the open "set" group corresponding to the "type" type.
3 groups are introduced in this set -- tasks, ns and global.
That's it.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-26 17:46:39 +04:00
|
|
|
int fd_off;
|
|
|
|
int fd_nr;
|
|
|
|
int *_fds;
|
2011-09-23 12:00:45 +04:00
|
|
|
};
|
|
|
|
|
2012-03-26 17:43:29 +04:00
|
|
|
static inline int fdset_fd(const struct cr_fdset *fdset, int type)
|
|
|
|
{
|
fdset: Introduce new fdsets
Current fdsets are ugly, limited (bitmask will exhaust in several months) and
suffer from unknown problems with fdsets reuse :(
With new approach (this set) the images management is simple. The basic function
is open_image, which gives you an fd for an image. If you want to pre-open several
images at once instead of calling open_image every single time, you can use the
new fdsets.
Images CR_FD_ descriptors should be grouped like
_CR_FD_FOO_FROM,
CR_FD_FOO_ITEM1,
CR_FD_FOO_ITEM2,
..
CR_FD_FOO_ITEMN,
_CR_FD_FOO_TO,
After this you can call cr_fd_open() specifying ranges -- _FROM and _TO macros,
it will give you an cr_fdset object. Then the fdset_fd(set, type) will give you
the descriptor of the open "set" group corresponding to the "type" type.
3 groups are introduced in this set -- tasks, ns and global.
That's it.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-26 17:46:39 +04:00
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = type - fdset->fd_off;
|
|
|
|
BUG_ON(idx > fdset->fd_nr);
|
|
|
|
|
|
|
|
return fdset->_fds[idx];
|
2012-03-26 17:43:29 +04:00
|
|
|
}
|
|
|
|
|
2012-03-26 17:47:38 +04:00
|
|
|
extern struct cr_fdset *glob_fdset;
|
|
|
|
|
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);
|
2012-03-27 11:04:23 +04:00
|
|
|
int cr_show(struct cr_options *opts);
|
2011-10-04 01:50:19 +04:00
|
|
|
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-03-26 17:45:08 +04:00
|
|
|
#define O_DUMP (O_RDWR | O_CREAT | O_EXCL)
|
|
|
|
#define O_SHOW (O_RDONLY)
|
|
|
|
|
|
|
|
struct cr_fdset *cr_task_fdset_open(int pid, int mode);
|
|
|
|
struct cr_fdset *cr_ns_fdset_open(int pid, int mode);
|
2012-03-26 17:47:38 +04:00
|
|
|
struct cr_fdset *cr_glob_fdset_open(int mode);
|
|
|
|
|
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-04-11 22:07:47 +04:00
|
|
|
struct pstree_item *parent;
|
2012-04-11 22:10:09 +04:00
|
|
|
pid_t pgid;
|
|
|
|
pid_t sid;
|
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 */
|
|
|
|
};
|
|
|
|
|
|
|
|
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_ */
|