Commit 3858ee49 authored by Pavel Emelyanov's avatar Pavel Emelyanov

fdset: Introduce two fdsets -- task and ns

Write two helpers for opening an fdset for task and one for ns.

This probably can be done with some "generic" macro(s), but this
time it's simpler not to produce more code of that type.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent bcf9ee3d
......@@ -1304,7 +1304,7 @@ static int dump_one_task(const struct pstree_item *item)
return dump_one_zombie(item, &pps_buf);
ret = -1;
cr_fdset = cr_dump_fdset_open(item->pid, CR_FD_DESC_TASK);
cr_fdset = cr_task_fdset_open(item->pid, O_DUMP);
if (!cr_fdset)
goto err;
......
......@@ -589,7 +589,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
list_for_each_entry(item, &pstree_list, list) {
struct cr_fdset *cr_fdset = NULL;
cr_fdset = cr_show_fdset_open(item->pid, CR_FD_DESC_TASK);
cr_fdset = cr_task_fdset_open(item->pid, O_SHOW);
if (!cr_fdset)
goto out;
......
......@@ -183,6 +183,8 @@ void close_cr_fdset(struct cr_fdset **cr_fdset)
*cr_fdset = NULL;
}
#define CR_FD_DESC_USE(type) ((1 << (type)))
static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask,
unsigned long flags)
{
......@@ -219,14 +221,33 @@ err:
return NULL;
}
struct cr_fdset *cr_dump_fdset_open(int pid, unsigned long use_mask)
#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) |\
CR_FD_DESC_USE(CR_FD_VMAS) |\
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) |\
CR_FD_DESC_USE(CR_FD_ITIMERS) |\
CR_FD_DESC_USE(CR_FD_CREDS) )
struct cr_fdset *cr_task_fdset_open(int pid, int mode)
{
return cr_fdset_open(pid, use_mask, O_RDWR | O_CREAT | O_EXCL);
return cr_fdset_open(pid, CR_FD_DESC_TASK, mode);
}
struct cr_fdset *cr_show_fdset_open(int pid, unsigned long use_mask)
#define CR_FD_DESC_NS (\
CR_FD_DESC_USE(CR_FD_UTSNS) |\
CR_FD_DESC_USE(CR_FD_IPCNS_VAR) |\
CR_FD_DESC_USE(CR_FD_IPCNS_MSG) |\
CR_FD_DESC_USE(CR_FD_IPCNS_SEM) |\
CR_FD_DESC_USE(CR_FD_IPCNS_SHM) )
struct cr_fdset *cr_ns_fdset_open(int pid, int mode)
{
return cr_fdset_open(pid, use_mask, O_RDONLY);
return cr_fdset_open(pid, CR_FD_DESC_NS, mode);
}
static int parse_ns_string(const char *ptr, unsigned int *flags)
......
......@@ -120,36 +120,17 @@ static inline int fdset_fd(const struct cr_fdset *fdset, int type)
return fdset->_fds[type];
}
#define CR_FD_DESC_USE(type) ((1 << (type)))
#define CR_FD_DESC_CORE CR_FD_DESC_USE(CR_FD_CORE)
#define CR_FD_DESC_PSTREE CR_FD_DESC_USE(CR_FD_PSTREE)
#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) |\
CR_FD_DESC_USE(CR_FD_VMAS) |\
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) |\
CR_FD_DESC_USE(CR_FD_ITIMERS) |\
CR_FD_DESC_USE(CR_FD_CREDS) )
#define CR_FD_DESC_NS (\
CR_FD_DESC_USE(CR_FD_UTSNS) |\
CR_FD_DESC_USE(CR_FD_IPCNS_VAR) |\
CR_FD_DESC_USE(CR_FD_IPCNS_MSG) |\
CR_FD_DESC_USE(CR_FD_IPCNS_SEM) |\
CR_FD_DESC_USE(CR_FD_IPCNS_SHM) )
#define CR_FD_DESC_NONE (0)
int cr_dump_tasks(pid_t pid, const struct cr_options *opts);
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);
int cr_check(void);
struct cr_fdset *cr_dump_fdset_open(int pid, unsigned long use_mask);
struct cr_fdset *cr_show_fdset_open(int pid, unsigned long use_mask);
#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);
void close_cr_fdset(struct cr_fdset **cr_fdset);
void free_mappings(struct list_head *vma_area_list);
......
......@@ -33,7 +33,7 @@ static int do_dump_namespaces(int ns_pid, unsigned int ns_flags)
struct cr_fdset *fdset;
int ret = 0;
fdset = cr_dump_fdset_open(ns_pid, CR_FD_DESC_NS);
fdset = cr_ns_fdset_open(ns_pid, O_DUMP);
if (fdset == NULL)
return -1;
......@@ -118,7 +118,7 @@ int try_show_namespaces(int ns_pid)
{
struct cr_fdset *fdset;
fdset = cr_show_fdset_open(ns_pid, CR_FD_DESC_NS);
fdset = cr_ns_fdset_open(ns_pid, O_SHOW);
if (!fdset)
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment