2011-09-23 12:00:45 +04:00
|
|
|
#ifndef CRTOOLS_H_
|
|
|
|
#define CRTOOLS_H_
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2012-05-31 14:50:00 +04:00
|
|
|
#include "list.h"
|
2011-09-23 12:00:45 +04:00
|
|
|
#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"
|
|
|
|
|
2012-07-19 12:43:36 +04:00
|
|
|
#include "../protobuf/vma.pb-c.h"
|
|
|
|
|
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
|
|
|
|
2012-07-19 16:51:58 +04:00
|
|
|
#define CRIU_VERSION_MAJOR 0
|
2012-07-23 09:37:53 +04:00
|
|
|
#define CRIU_VERSION_MINOR 1
|
2012-07-19 16:51:58 +04:00
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
enum {
|
2012-07-19 17:37:25 +04:00
|
|
|
CR_FD_INVENTORY,
|
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,
|
2012-05-12 03:30:10 +04:00
|
|
|
CR_FD_MOUNTPOINTS,
|
2012-08-02 08:17:27 +04:00
|
|
|
CR_FD_NETDEV,
|
2012-08-02 08:26:43 +04:00
|
|
|
CR_FD_IFADDR,
|
2012-08-02 08:31:46 +04:00
|
|
|
CR_FD_ROUTE,
|
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-04-13 17:54:36 +04:00
|
|
|
CR_FD_GHOST_FILE,
|
2012-04-28 17:29:14 +04:00
|
|
|
CR_FD_TCP_STREAM,
|
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-06-26 02:36:13 +04:00
|
|
|
CR_FD_FIFO,
|
|
|
|
CR_FD_FIFO_DATA,
|
2012-04-13 17:54:36 +04:00
|
|
|
CR_FD_REMAP_FPATH,
|
2012-05-04 13:38:00 +04:00
|
|
|
CR_FD_EVENTFD,
|
2012-05-04 13:38:00 +04:00
|
|
|
CR_FD_EVENTPOLL,
|
|
|
|
CR_FD_EVENTPOLL_TFD,
|
2012-08-02 12:26:35 +04:00
|
|
|
CR_FD_SIGNALFD,
|
2012-05-04 13:38:00 +04:00
|
|
|
CR_FD_INOTIFY,
|
|
|
|
CR_FD_INOTIFY_WD,
|
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 show_pages_content;
|
|
|
|
bool restore_detach;
|
2012-04-19 11:48:00 +04:00
|
|
|
bool ext_unix_sk;
|
2012-04-28 17:15:12 +04:00
|
|
|
bool tcp_established_ok;
|
2012-01-31 22:28:22 +04:00
|
|
|
unsigned int namespaces_flags;
|
2012-05-02 14:42:00 +04:00
|
|
|
bool log_file_per_pid;
|
|
|
|
char *output;
|
2011-10-04 01:50:19 +04:00
|
|
|
};
|
|
|
|
|
2012-05-02 14:42:00 +04:00
|
|
|
extern struct cr_options opts;
|
|
|
|
|
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-06-19 15:53:00 +04:00
|
|
|
PROC_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-06-26 02:36:13 +04:00
|
|
|
void show_fifo(int fd, struct cr_options *o);
|
|
|
|
void show_fifo_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-13 17:54:36 +04:00
|
|
|
void show_remap_files(int fd, struct cr_options *o);
|
|
|
|
void show_ghost_file(int fd, struct cr_options *o);
|
2012-07-19 09:39:00 +04:00
|
|
|
void show_fown_cont(void *p);
|
2012-05-04 13:38:00 +04:00
|
|
|
void show_eventfds(int fd, struct cr_options *o);
|
2012-03-27 12:01:14 +04:00
|
|
|
|
2012-07-19 17:37:25 +04:00
|
|
|
int check_img_inventory(void);
|
|
|
|
int write_img_inventory(void);
|
|
|
|
|
2012-04-12 15:33:09 +04:00
|
|
|
extern void print_data(unsigned long addr, unsigned char *data, size_t size);
|
2012-07-25 18:33:04 +04:00
|
|
|
extern void print_image_data(int fd, unsigned int length);
|
2011-12-29 19:56:34 +04:00
|
|
|
extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
|
|
|
|
|
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-04-19 11:48:00 +04:00
|
|
|
extern struct cr_options opts;
|
2012-03-26 17:47:38 +04:00
|
|
|
|
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;
|
2012-07-19 12:43:36 +04:00
|
|
|
VmaEntry vma;
|
2011-09-23 12:00:45 +04:00
|
|
|
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
|
|
|
|
2012-04-18 15:42:26 +04:00
|
|
|
struct rst_info {
|
2012-04-18 16:24:08 +04:00
|
|
|
struct list_head fds;
|
2012-05-04 16:31:00 +04:00
|
|
|
struct list_head eventpoll;
|
2012-04-18 15:42:26 +04:00
|
|
|
};
|
|
|
|
|
2012-06-19 15:53:00 +04:00
|
|
|
struct pid
|
|
|
|
{
|
2012-06-22 00:38:00 +04:00
|
|
|
u32 real; /* used to peek/poke tasks during dump stage */
|
|
|
|
u32 virt; /* used all over in the images and saved after restore */
|
2012-06-19 15:53:00 +04:00
|
|
|
};
|
|
|
|
|
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_ */
|