LCOV - code coverage report
Current view: top level - include - files.h (source / functions) Hit Total Coverage
Test: coverage3.info Lines: 3 3 100.0 %
Date: 2014-04-22 Functions: 0 0 -
Branches: 5 6 83.3 %

           Branch data     Line data    Source code
       1                 :            : #ifndef __CR_FILES_H__
       2                 :            : #define __CR_FILES_H__
       3                 :            : 
       4                 :            : #include "compiler.h"
       5                 :            : #include "asm/types.h"
       6                 :            : #include "fcntl.h"
       7                 :            : #include "lock.h"
       8                 :            : #include "list.h"
       9                 :            : #include "image.h"
      10                 :            : #include "pid.h"
      11                 :            : #include "rst_info.h"
      12                 :            : 
      13                 :            : #include "protobuf/fdinfo.pb-c.h"
      14                 :            : #include "protobuf/fown.pb-c.h"
      15                 :            : #include "protobuf/vma.pb-c.h"
      16                 :            : 
      17                 :            : struct pstree_item;
      18                 :            : struct file_desc;
      19                 :            : struct cr_fdset;
      20                 :            : struct rst_info;
      21                 :            : struct parasite_ctl;
      22                 :            : 
      23                 :            : struct fd_link {
      24                 :            :         union {
      25                 :            :                 /* Link info for generic file (path) */
      26                 :            :                 struct {
      27                 :            :                         char    name[PATH_MAX + 1];
      28                 :            :                         size_t  len;
      29                 :            :                 };
      30                 :            : 
      31                 :            :                 /* Link info for proc-ns file */
      32                 :            :                 struct {
      33                 :            :                         struct ns_desc *ns_d;
      34                 :            :                         unsigned int ns_kid;
      35                 :            :                 };
      36                 :            :         };
      37                 :            : };
      38                 :            : 
      39                 :            : struct fd_parms {
      40                 :            :         int             fd;
      41                 :            :         off_t           pos;
      42                 :            :         unsigned int    flags;
      43                 :            :         char            fd_flags;
      44                 :            :         struct stat     stat;
      45                 :            :         pid_t           pid;
      46                 :            :         FownEntry       fown;
      47                 :            :         struct fd_link  *link;
      48                 :            :         long            fs_type;
      49                 :            :         int             mnt_id;
      50                 :            : 
      51                 :            :         struct parasite_ctl *ctl;
      52                 :            : };
      53                 :            : 
      54                 :            : #define FD_PARMS_INIT                   \
      55                 :            : (struct fd_parms) {                     \
      56                 :            :         .fd     = FD_DESC_INVALID,      \
      57                 :            :         .fown   = FOWN_ENTRY__INIT,     \
      58                 :            :         .link   = NULL,                 \
      59                 :            :         .mnt_id = -1,                   \
      60                 :            : }
      61                 :            : 
      62                 :            : extern int fill_fdlink(int lfd, const struct fd_parms *p, struct fd_link *link);
      63                 :            : 
      64                 :            : struct file_desc;
      65                 :            : 
      66                 :            : struct fdinfo_list_entry {
      67                 :            :         struct list_head        desc_list;      /* To chain on  @fd_info_head */
      68                 :            :         struct file_desc        *desc;          /* Associated file descriptor */
      69                 :            :         struct list_head        ps_list;        /* To chain  per-task files */
      70                 :            :         int                     pid;
      71                 :            :         futex_t                 real_pid;
      72                 :            :         FdinfoEntry             *fe;
      73                 :            : };
      74                 :            : 
      75                 :            : /* reports whether fd_a takes prio over fd_b */
      76                 :            : static inline int fdinfo_rst_prio(struct fdinfo_list_entry *fd_a, struct fdinfo_list_entry *fd_b)
      77                 :            : {
      78 [ +  - ][ +  + ]:        182 :         return pid_rst_prio(fd_a->pid, fd_b->pid) ||
      79         [ +  + ]:        182 :                 ((fd_a->pid == fd_b->pid) && (fd_a->fe->fd < fd_b->fe->fd));
      80                 :            : }
      81                 :            : 
      82                 :            : struct file_desc_ops {
      83                 :            :         /* fd_types from protobuf/fdinfo.proto */
      84                 :            :         unsigned int            type;
      85                 :            :         /*
      86                 :            :          * Opens a file by whatever syscall is required for that.
      87                 :            :          * The returned descriptor may be closed (dup2-ed to another)
      88                 :            :          * so it shouldn't be saved for any post-actions.
      89                 :            :          */
      90                 :            :         int                     (*open)(struct file_desc *d);
      91                 :            :         /*
      92                 :            :          * Called on a file when all files of that type are opened
      93                 :            :          * and with the fd being the "restored" one.
      94                 :            :          */
      95                 :            :         int                     (*post_open)(struct file_desc *d, int fd);
      96                 :            :         /*
      97                 :            :          * Report whether the fd in question wants a transport socket
      98                 :            :          * in it instead of a real file. See file_master for details.
      99                 :            :          */
     100                 :            :         int                     (*want_transport)(FdinfoEntry *fe, struct file_desc *d);
     101                 :            :         /*
     102                 :            :          * Called to collect a new fd before adding it on desc. Clients
     103                 :            :          * may chose to collect it to some specific rst_info list. See
     104                 :            :          * prepare_fds() for details.
     105                 :            :          */
     106                 :            :         void                    (*collect_fd)(struct file_desc *, struct fdinfo_list_entry *,
     107                 :            :                                                 struct rst_info *);
     108                 :            : };
     109                 :            : 
     110                 :            : static inline void collect_gen_fd(struct fdinfo_list_entry *fle, struct rst_info *ri)
     111                 :            : {
     112                 :       4220 :         list_add_tail(&fle->ps_list, &ri->fds);
     113                 :            : }
     114                 :            : 
     115                 :            : struct file_desc {
     116                 :            :         u32                     id;             /* File id, unique */
     117                 :            :         struct hlist_node       hash;           /* Descriptor hashing and lookup */
     118                 :            :         struct list_head        fd_info_head;   /* Chain of fdinfo_list_entry-s with same ID and type but different pids */
     119                 :            :         struct file_desc_ops    *ops;           /* Associated operations */
     120                 :            : };
     121                 :            : 
     122                 :            : struct fdtype_ops {
     123                 :            :         unsigned int            type;
     124                 :            :         int                     (*dump)(int lfd, u32 id, const struct fd_parms *p);
     125                 :            :         int                     (*pre_dump)(int pid, int lfd);
     126                 :            : };
     127                 :            : 
     128                 :            : extern int do_dump_gen_file(struct fd_parms *p, int lfd,
     129                 :            :                             const struct fdtype_ops *ops,
     130                 :            :                             const int fdinfo);
     131                 :            : struct parasite_drain_fd;
     132                 :            : int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
     133                 :            :                 struct parasite_drain_fd *dfds);
     134                 :            : int predump_task_files(int pid);
     135                 :            : 
     136                 :            : extern int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops);
     137                 :            : extern struct fdinfo_list_entry *file_master(struct file_desc *d);
     138                 :            : extern struct file_desc *find_file_desc_raw(int type, u32 id);
     139                 :            : 
     140                 :            : extern int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int sock);
     141                 :            : extern int restore_fown(int fd, FownEntry *fown);
     142                 :            : extern int rst_file_params(int fd, FownEntry *fown, int flags);
     143                 :            : 
     144                 :            : extern void show_saved_files(void);
     145                 :            : 
     146                 :            : extern int prepare_fds(struct pstree_item *me);
     147                 :            : extern int prepare_fd_pid(struct pstree_item *me);
     148                 :            : extern int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id);
     149                 :            : extern int prepare_shared_fdinfo(void);
     150                 :            : extern int get_filemap_fd(struct vma_area *);
     151                 :            : extern int prepare_fs(int pid);
     152                 :            : extern int set_fd_flags(int fd, int flags);
     153                 :            : 
     154                 :            : extern int close_old_fds(struct pstree_item *me);
     155                 :            : #ifndef AT_EMPTY_PATH
     156                 :            : #define AT_EMPTY_PATH 0x1000
     157                 :            : #endif
     158                 :            : 
     159                 :            : #define LREMAP_PARAM    "link-remap"
     160                 :            : 
     161                 :            : extern int shared_fdt_prepare(struct pstree_item *item);
     162                 :            : 
     163                 :            : extern struct collect_image_info ext_file_cinfo;
     164                 :            : extern int dump_unsupp_fd(struct fd_parms *p, int lfd,
     165                 :            :                           const int fdinfo, char *more, char *info);
     166                 :            : 
     167                 :            : #endif /* __CR_FILES_H__ */

Generated by: LCOV version 1.9