2012-12-24 15:36:14 +04:00
|
|
|
#ifndef __CR_FILES_H__
|
|
|
|
#define __CR_FILES_H__
|
2012-01-10 18:03:00 +04:00
|
|
|
|
2012-02-22 13:46:36 +04:00
|
|
|
#include "compiler.h"
|
2013-01-09 17:02:47 +04:00
|
|
|
#include "asm/types.h"
|
2013-11-14 19:19:49 +04:00
|
|
|
#include "fcntl.h"
|
2012-03-26 23:11:00 +04:00
|
|
|
#include "lock.h"
|
2012-02-22 13:46:36 +04:00
|
|
|
#include "list.h"
|
|
|
|
#include "image.h"
|
2013-11-06 17:21:13 +04:00
|
|
|
#include "pid.h"
|
2012-02-22 13:46:36 +04:00
|
|
|
|
2013-02-15 17:33:06 +04:00
|
|
|
#include "protobuf/fdinfo.pb-c.h"
|
|
|
|
#include "protobuf/fown.pb-c.h"
|
|
|
|
#include "protobuf/vma.pb-c.h"
|
2012-07-12 13:06:00 +04:00
|
|
|
|
2012-06-22 16:24:00 +04:00
|
|
|
struct pstree_item;
|
|
|
|
struct file_desc;
|
|
|
|
struct cr_fdset;
|
|
|
|
struct rst_info;
|
2012-10-15 23:42:50 +04:00
|
|
|
struct parasite_ctl;
|
2012-06-22 16:24:00 +04:00
|
|
|
|
2013-05-20 13:30:16 +04:00
|
|
|
struct fd_link {
|
2013-05-18 04:00:05 +04:00
|
|
|
union {
|
|
|
|
/* Link info for generic file (path) */
|
|
|
|
struct {
|
|
|
|
char name[PATH_MAX + 1];
|
|
|
|
size_t len;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Link info for proc-ns file */
|
|
|
|
struct {
|
|
|
|
struct ns_desc *ns_d;
|
|
|
|
unsigned int ns_kid;
|
|
|
|
};
|
|
|
|
};
|
2013-05-20 13:30:16 +04:00
|
|
|
};
|
|
|
|
|
2012-03-29 16:40:10 +04:00
|
|
|
struct fd_parms {
|
2012-04-10 17:49:39 +04:00
|
|
|
int fd;
|
2013-08-29 14:55:37 +04:00
|
|
|
off_t pos;
|
2012-03-29 16:40:10 +04:00
|
|
|
unsigned int flags;
|
2012-04-10 18:36:59 +04:00
|
|
|
char fd_flags;
|
2012-03-29 16:40:10 +04:00
|
|
|
struct stat stat;
|
|
|
|
pid_t pid;
|
2012-07-19 09:39:00 +04:00
|
|
|
FownEntry fown;
|
2013-05-20 13:30:16 +04:00
|
|
|
struct fd_link *link;
|
2012-10-15 23:42:50 +04:00
|
|
|
|
|
|
|
struct parasite_ctl *ctl;
|
2012-03-29 16:40:10 +04:00
|
|
|
};
|
|
|
|
|
2012-07-19 09:39:00 +04:00
|
|
|
#define FD_PARMS_INIT \
|
2013-05-20 13:30:15 +04:00
|
|
|
(struct fd_parms) { \
|
2012-07-19 09:39:00 +04:00
|
|
|
.fd = FD_DESC_INVALID, \
|
|
|
|
.fown = FOWN_ENTRY__INIT, \
|
2013-05-20 13:30:16 +04:00
|
|
|
.link = NULL, \
|
2012-07-19 09:39:00 +04:00
|
|
|
}
|
|
|
|
|
2013-05-20 13:30:16 +04:00
|
|
|
extern int fill_fdlink(int lfd, const struct fd_parms *p, struct fd_link *link);
|
|
|
|
|
2012-06-03 22:56:02 +04:00
|
|
|
struct file_desc;
|
|
|
|
|
2012-02-22 13:46:36 +04:00
|
|
|
struct fdinfo_list_entry {
|
2012-09-05 19:58:30 +04:00
|
|
|
struct list_head desc_list; /* To chain on @fd_info_head */
|
|
|
|
struct file_desc *desc; /* Associated file descriptor */
|
|
|
|
struct list_head ps_list; /* To chain per-task files */
|
2012-02-22 13:46:36 +04:00
|
|
|
int pid;
|
2012-03-26 23:11:00 +04:00
|
|
|
futex_t real_pid;
|
2012-07-12 13:06:00 +04:00
|
|
|
FdinfoEntry *fe;
|
2012-02-22 13:46:36 +04:00
|
|
|
};
|
|
|
|
|
2012-09-14 22:09:22 +04:00
|
|
|
/* reports whether fd_a takes prio over fd_b */
|
|
|
|
static inline int fdinfo_rst_prio(struct fdinfo_list_entry *fd_a, struct fdinfo_list_entry *fd_b)
|
|
|
|
{
|
2013-08-29 08:07:15 +04:00
|
|
|
return pid_rst_prio(fd_a->pid, fd_b->pid) ||
|
|
|
|
((fd_a->pid == fd_b->pid) && (fd_a->fe->fd < fd_b->fe->fd));
|
2012-09-14 22:09:22 +04:00
|
|
|
}
|
|
|
|
|
2012-04-06 20:39:48 +04:00
|
|
|
struct file_desc_ops {
|
2013-04-16 14:47:10 +04:00
|
|
|
/* fd_types from protobuf/fdinfo.proto */
|
2012-06-22 16:24:00 +04:00
|
|
|
unsigned int type;
|
2013-04-16 14:47:10 +04:00
|
|
|
/*
|
|
|
|
* Opens a file by whatever syscall is required for that.
|
|
|
|
* The returned descriptor may be closed (dup2-ed to another)
|
|
|
|
* so it shouldn't be saved for any post-actions.
|
|
|
|
*/
|
2012-06-22 16:24:00 +04:00
|
|
|
int (*open)(struct file_desc *d);
|
2013-04-16 14:47:10 +04:00
|
|
|
/*
|
|
|
|
* Called on a file when all files of that type are opened
|
|
|
|
* and with the fd being the "restored" one.
|
|
|
|
*/
|
2012-08-20 17:50:01 +04:00
|
|
|
int (*post_open)(struct file_desc *d, int fd);
|
2013-04-16 14:47:10 +04:00
|
|
|
/*
|
|
|
|
* Report whether the fd in question wants a transport socket
|
2013-09-10 12:13:36 +04:00
|
|
|
* in it instead of a real file. See file_master for details.
|
2013-04-16 14:47:10 +04:00
|
|
|
*/
|
2012-07-12 13:06:00 +04:00
|
|
|
int (*want_transport)(FdinfoEntry *fe, struct file_desc *d);
|
2013-04-16 14:47:10 +04:00
|
|
|
/*
|
|
|
|
* Helps determining sequence of different file types restore.
|
|
|
|
* See the prepare_fds for details.
|
|
|
|
*/
|
2012-09-14 21:53:51 +04:00
|
|
|
struct list_head * (*select_ps_list)(struct file_desc *, struct rst_info *);
|
2012-04-06 20:39:48 +04:00
|
|
|
};
|
|
|
|
|
2012-04-06 20:03:31 +04:00
|
|
|
struct file_desc {
|
2013-09-10 12:13:36 +04:00
|
|
|
u32 id; /* File id, unique */
|
2013-08-10 16:41:18 +04:00
|
|
|
struct hlist_node hash; /* Descriptor hashing and lookup */
|
2012-09-05 19:58:30 +04:00
|
|
|
struct list_head fd_info_head; /* Chain of fdinfo_list_entry-s with same ID and type but different pids */
|
|
|
|
struct file_desc_ops *ops; /* Associated operations */
|
2012-04-06 20:03:31 +04:00
|
|
|
};
|
|
|
|
|
2012-05-04 15:34:55 +04:00
|
|
|
struct fdtype_ops {
|
2012-06-22 16:24:00 +04:00
|
|
|
unsigned int type;
|
|
|
|
int (*dump)(int lfd, u32 id, const struct fd_parms *p);
|
2012-05-04 15:34:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int do_dump_gen_file(struct fd_parms *p, int lfd,
|
2012-06-22 16:24:00 +04:00
|
|
|
const struct fdtype_ops *ops,
|
2013-01-11 13:22:41 +04:00
|
|
|
const int fdinfo);
|
2013-02-08 02:54:24 +04:00
|
|
|
struct parasite_drain_fd;
|
|
|
|
int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
|
|
|
|
struct parasite_drain_fd *dfds);
|
2012-05-04 15:34:55 +04:00
|
|
|
|
2013-08-21 01:06:58 +04:00
|
|
|
extern int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops);
|
2012-04-06 20:03:31 +04:00
|
|
|
extern struct fdinfo_list_entry *file_master(struct file_desc *d);
|
2012-04-06 20:30:48 +04:00
|
|
|
extern struct file_desc *find_file_desc_raw(int type, u32 id);
|
2012-06-22 16:24:00 +04:00
|
|
|
|
2012-08-17 15:43:22 +04:00
|
|
|
extern int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int sock);
|
2012-07-19 09:39:00 +04:00
|
|
|
extern int restore_fown(int fd, FownEntry *fown);
|
|
|
|
extern int rst_file_params(int fd, FownEntry *fown, int flags);
|
2012-07-17 07:24:51 +04:00
|
|
|
|
2012-06-22 16:24:00 +04:00
|
|
|
extern void show_saved_files(void);
|
|
|
|
|
|
|
|
extern int prepare_fds(struct pstree_item *me);
|
2013-01-11 18:16:25 +04:00
|
|
|
extern int prepare_fd_pid(struct pstree_item *me);
|
2012-09-12 20:00:58 +04:00
|
|
|
extern int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id);
|
2012-02-22 18:51:27 +04:00
|
|
|
extern int prepare_shared_fdinfo(void);
|
2012-07-19 12:43:36 +04:00
|
|
|
extern int get_filemap_fd(int pid, VmaEntry *vma_entry);
|
2012-04-09 13:41:05 +04:00
|
|
|
extern int prepare_fs(int pid);
|
2012-06-22 16:24:00 +04:00
|
|
|
extern int set_fd_flags(int fd, int flags);
|
2012-01-10 18:03:00 +04:00
|
|
|
|
2013-01-11 18:16:24 +04:00
|
|
|
extern int close_old_fds(struct pstree_item *me);
|
2012-09-26 06:22:52 +04:00
|
|
|
#ifndef AT_EMPTY_PATH
|
|
|
|
#define AT_EMPTY_PATH 0x1000
|
|
|
|
#endif
|
|
|
|
|
2012-09-26 06:39:23 +04:00
|
|
|
#define LREMAP_PARAM "link-remap"
|
|
|
|
|
2013-11-15 14:04:48 +04:00
|
|
|
extern int shared_fdt_prepare(struct pstree_item *item);
|
2013-01-19 00:30:42 +04:00
|
|
|
|
2013-12-20 16:05:17 +04:00
|
|
|
extern struct collect_image_info ext_file_cinfo;
|
|
|
|
extern int dump_unsupp_fd(struct fd_parms *p, int lfd,
|
|
|
|
const int fdinfo, char *more, char *info);
|
|
|
|
|
2012-12-25 22:40:24 +04:00
|
|
|
#endif /* __CR_FILES_H__ */
|