Commit bcf9ee3d authored by Pavel Emelyanov's avatar Pavel Emelyanov

fdset: Helper for getting fd out of a set

This patch does

s/$fdset->fds[$nr]/fdset_fd($fdset, $nr)/

over the code.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 49cfa979
...@@ -154,7 +154,7 @@ static int dump_one_fdinfo(const struct fd_parms *p, int lfd, ...@@ -154,7 +154,7 @@ static int dump_one_fdinfo(const struct fd_parms *p, int lfd,
pr_info("fdinfo: type: %2x flags: %4x pos: %8lx addr: %16lx\n", pr_info("fdinfo: type: %2x flags: %4x pos: %8lx addr: %16lx\n",
p->type, p->flags, p->pos, p->fd_name); p->type, p->flags, p->pos, p->fd_name);
if (write_img(cr_fdset->fds[CR_FD_FDINFO], &e)) if (write_img(fdset_fd(cr_fdset, CR_FD_FDINFO), &e))
goto err; goto err;
ret = 0; ret = 0;
...@@ -205,7 +205,7 @@ static int dump_pipe_and_data(int lfd, struct pipe_entry *e, ...@@ -205,7 +205,7 @@ static int dump_pipe_and_data(int lfd, struct pipe_entry *e,
int has_bytes; int has_bytes;
int ret = -1; int ret = -1;
fd_pipes = cr_fdset->fds[CR_FD_PIPES]; fd_pipes = fdset_fd(cr_fdset, CR_FD_PIPES);
pr_info("Dumping data from pipe %x\n", e->pipeid); pr_info("Dumping data from pipe %x\n", e->pipeid);
if (pipe(steal_pipe) < 0) { if (pipe(steal_pipe) < 0) {
...@@ -276,7 +276,7 @@ static int dump_one_pipe(const struct fd_parms *p, unsigned int id, int lfd, ...@@ -276,7 +276,7 @@ static int dump_one_pipe(const struct fd_parms *p, unsigned int id, int lfd,
if (p->flags & O_WRONLY) { if (p->flags & O_WRONLY) {
e.bytes = 0; e.bytes = 0;
ret = write_img(cr_fdset->fds[CR_FD_PIPES], &e); ret = write_img(fdset_fd(cr_fdset, CR_FD_PIPES), &e);
} else } else
ret = dump_pipe_and_data(lfd, &e, cr_fdset); ret = dump_pipe_and_data(lfd, &e, cr_fdset);
...@@ -499,12 +499,14 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list, ...@@ -499,12 +499,14 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list,
const struct cr_fdset *cr_fdset) const struct cr_fdset *cr_fdset)
{ {
struct vma_area *vma_area; struct vma_area *vma_area;
int ret = -1, fd = cr_fdset->fds[CR_FD_VMAS]; int ret = -1, fd;
pr_info("\n"); pr_info("\n");
pr_info("Dumping mappings (pid: %d)\n", pid); pr_info("Dumping mappings (pid: %d)\n", pid);
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
fd = fdset_fd(cr_fdset, CR_FD_VMAS);
list_for_each_entry(vma_area, vma_area_list, list) { list_for_each_entry(vma_area, vma_area_list, list) {
struct vma_entry *vma = &vma_area->vma; struct vma_entry *vma = &vma_area->vma;
...@@ -572,7 +574,7 @@ static int dump_task_creds(pid_t pid, const struct parasite_dump_misc *misc, ...@@ -572,7 +574,7 @@ static int dump_task_creds(pid_t pid, const struct parasite_dump_misc *misc,
ce.secbits = misc->secbits; ce.secbits = misc->secbits;
ret = write_img(fds->fds[CR_FD_CREDS], &ce); ret = write_img(fdset_fd(fds, CR_FD_CREDS), &ce);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -787,7 +789,7 @@ static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat, ...@@ -787,7 +789,7 @@ static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
core->tc.task_state = TASK_ALIVE; core->tc.task_state = TASK_ALIVE;
core->tc.exit_code = 0; core->tc.exit_code = 0;
ret = dump_task_core(core, cr_fdset->fds[CR_FD_CORE]); ret = dump_task_core(core, fdset_fd(cr_fdset, CR_FD_CORE));
err_free: err_free:
free(core); free(core);
......
...@@ -593,7 +593,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts) ...@@ -593,7 +593,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
if (!cr_fdset) if (!cr_fdset)
goto out; goto out;
show_core(cr_fdset->fds[CR_FD_CORE], opts->show_pages_content); show_core(fdset_fd(cr_fdset, CR_FD_CORE), opts->show_pages_content);
if (item->nr_threads > 1) { if (item->nr_threads > 1) {
int i, fd_th; int i, fd_th;
...@@ -618,21 +618,21 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts) ...@@ -618,21 +618,21 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
} }
} }
show_vmas(cr_fdset->fds[CR_FD_VMAS]); show_vmas(fdset_fd(cr_fdset, CR_FD_VMAS));
show_pipes(cr_fdset->fds[CR_FD_PIPES]); show_pipes(fdset_fd(cr_fdset, CR_FD_PIPES));
show_files(cr_fdset->fds[CR_FD_FDINFO]); show_files(fdset_fd(cr_fdset, CR_FD_FDINFO));
show_sigacts(cr_fdset->fds[CR_FD_SIGACT]); show_sigacts(fdset_fd(cr_fdset, CR_FD_SIGACT));
show_unixsk(cr_fdset->fds[CR_FD_UNIXSK]); show_unixsk(fdset_fd(cr_fdset, CR_FD_UNIXSK));
show_inetsk(cr_fdset->fds[CR_FD_INETSK]); show_inetsk(fdset_fd(cr_fdset, CR_FD_INETSK));
show_itimers(cr_fdset->fds[CR_FD_ITIMERS]); show_itimers(fdset_fd(cr_fdset, CR_FD_ITIMERS));
show_creds(cr_fdset->fds[CR_FD_CREDS]); show_creds(fdset_fd(cr_fdset, CR_FD_CREDS));
close_cr_fdset(&cr_fdset); close_cr_fdset(&cr_fdset);
......
...@@ -153,7 +153,7 @@ static struct cr_fdset *alloc_cr_fdset(void) ...@@ -153,7 +153,7 @@ static struct cr_fdset *alloc_cr_fdset(void)
cr_fdset = xmalloc(sizeof(*cr_fdset)); cr_fdset = xmalloc(sizeof(*cr_fdset));
if (cr_fdset) if (cr_fdset)
for (i = 0; i < CR_FD_PID_MAX; i++) for (i = 0; i < CR_FD_PID_MAX; i++)
cr_fdset->fds[i] = -1; cr_fdset->_fds[i] = -1;
return cr_fdset; return cr_fdset;
} }
...@@ -165,10 +165,10 @@ static void __close_cr_fdset(struct cr_fdset *cr_fdset) ...@@ -165,10 +165,10 @@ static void __close_cr_fdset(struct cr_fdset *cr_fdset)
return; return;
for (i = 0; i < CR_FD_PID_MAX; i++) { for (i = 0; i < CR_FD_PID_MAX; i++) {
if (cr_fdset->fds[i] == -1) if (cr_fdset->_fds[i] == -1)
continue; continue;
close_safe(&cr_fdset->fds[i]); close_safe(&cr_fdset->_fds[i]);
cr_fdset->fds[i] = -1; cr_fdset->_fds[i] = -1;
} }
} }
...@@ -198,7 +198,7 @@ static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, ...@@ -198,7 +198,7 @@ static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask,
if (!(use_mask & CR_FD_DESC_USE(i))) if (!(use_mask & CR_FD_DESC_USE(i)))
continue; continue;
if (fdset->fds[i] != -1) if (fdset->_fds[i] != -1)
continue; continue;
ret = open_image(i, flags, pid); ret = open_image(i, flags, pid);
...@@ -209,7 +209,7 @@ static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, ...@@ -209,7 +209,7 @@ static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask,
goto err; goto err;
} }
fdset->fds[i] = ret; fdset->_fds[i] = ret;
} }
return fdset; return fdset;
......
...@@ -112,9 +112,14 @@ extern int open_image_ro_nocheck(const char *fmt, ...); ...@@ -112,9 +112,14 @@ extern int open_image_ro_nocheck(const char *fmt, ...);
#define LAST_PID_PERM 0666 #define LAST_PID_PERM 0666
struct cr_fdset { struct cr_fdset {
int fds[CR_FD_PID_MAX]; int _fds[CR_FD_PID_MAX];
}; };
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_USE(type) ((1 << (type)))
#define CR_FD_DESC_CORE CR_FD_DESC_USE(CR_FD_CORE) #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_PSTREE CR_FD_DESC_USE(CR_FD_PSTREE)
......
...@@ -428,16 +428,16 @@ static int dump_ipc_data(const struct cr_fdset *fdset) ...@@ -428,16 +428,16 @@ static int dump_ipc_data(const struct cr_fdset *fdset)
{ {
int ret; int ret;
ret = dump_ipc_var(fdset->fds[CR_FD_IPCNS_VAR]); ret = dump_ipc_var(fdset_fd(fdset, CR_FD_IPCNS_VAR));
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = dump_ipc_shm(fdset->fds[CR_FD_IPCNS_SHM]); ret = dump_ipc_shm(fdset_fd(fdset, CR_FD_IPCNS_SHM));
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = dump_ipc_msg(fdset->fds[CR_FD_IPCNS_MSG]); ret = dump_ipc_msg(fdset_fd(fdset, CR_FD_IPCNS_MSG));
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = dump_ipc_sem(fdset->fds[CR_FD_IPCNS_SEM]); ret = dump_ipc_sem(fdset_fd(fdset, CR_FD_IPCNS_SEM));
if (ret < 0) if (ret < 0)
return ret; return ret;
return 0; return 0;
......
...@@ -122,20 +122,20 @@ int try_show_namespaces(int ns_pid) ...@@ -122,20 +122,20 @@ int try_show_namespaces(int ns_pid)
if (!fdset) if (!fdset)
return -1; return -1;
if (fdset->fds[CR_FD_UTSNS] != -1) if (fdset_fd(fdset, CR_FD_UTSNS) != -1)
show_utsns(fdset->fds[CR_FD_UTSNS]); show_utsns(fdset_fd(fdset, CR_FD_UTSNS));
if (fdset->fds[CR_FD_IPCNS_VAR] != -1) if (fdset_fd(fdset, CR_FD_IPCNS_VAR) != -1)
show_ipc_var(fdset->fds[CR_FD_IPCNS_VAR]); show_ipc_var(fdset_fd(fdset, CR_FD_IPCNS_VAR));
if (fdset->fds[CR_FD_IPCNS_SHM] != -1) if (fdset_fd(fdset, CR_FD_IPCNS_SHM) != -1)
show_ipc_shm(fdset->fds[CR_FD_IPCNS_SHM]); show_ipc_shm(fdset_fd(fdset, CR_FD_IPCNS_SHM));
if (fdset->fds[CR_FD_IPCNS_MSG] != -1) if (fdset_fd(fdset, CR_FD_IPCNS_MSG) != -1)
show_ipc_msg(fdset->fds[CR_FD_IPCNS_MSG]); show_ipc_msg(fdset_fd(fdset, CR_FD_IPCNS_MSG));
if (fdset->fds[CR_FD_IPCNS_SEM] != -1) if (fdset_fd(fdset, CR_FD_IPCNS_SEM) != -1)
show_ipc_sem(fdset->fds[CR_FD_IPCNS_SEM]); show_ipc_sem(fdset_fd(fdset, CR_FD_IPCNS_SEM));
close_cr_fdset(&fdset); close_cr_fdset(&fdset);
return 0; return 0;
......
...@@ -390,7 +390,7 @@ static int parasite_file_cmd(char *what, int cmd, int type, ...@@ -390,7 +390,7 @@ static int parasite_file_cmd(char *what, int cmd, int type,
pr_info("Dumping %s (pid: %d)\n", what, ctl->pid); pr_info("Dumping %s (pid: %d)\n", what, ctl->pid);
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
fd = cr_fdset->fds[type]; fd = fdset_fd(cr_fdset, type);
ret = parasite_prep_file(fd, ctl); ret = parasite_prep_file(fd, ctl);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -534,7 +534,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a ...@@ -534,7 +534,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
pr_info("Dumping pages (type: %d pid: %d)\n", CR_FD_PAGES, ctl->pid); pr_info("Dumping pages (type: %d pid: %d)\n", CR_FD_PAGES, ctl->pid);
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
ret = parasite_prep_file(cr_fdset->fds[CR_FD_PAGES], ctl); ret = parasite_prep_file(fdset_fd(cr_fdset, CR_FD_PAGES), ctl);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -591,7 +591,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a ...@@ -591,7 +591,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
parasite_execute(PARASITE_CMD_DUMPPAGES_FINI, ctl, NULL, 0); parasite_execute(PARASITE_CMD_DUMPPAGES_FINI, ctl, NULL, 0);
if (write_img(cr_fdset->fds[CR_FD_PAGES], &zero_page_entry)) if (write_img(fdset_fd(cr_fdset, CR_FD_PAGES), &zero_page_entry))
goto out; goto out;
pr_info("\n"); pr_info("\n");
...@@ -599,7 +599,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a ...@@ -599,7 +599,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
ret = 0; ret = 0;
out: out:
fchmod(cr_fdset->fds[CR_FD_PAGES], CR_FD_PERM); fchmod(fdset_fd(cr_fdset, CR_FD_PAGES), CR_FD_PERM);
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
return ret; return ret;
......
...@@ -261,7 +261,7 @@ static int dump_one_inet(const struct socket_desc *_sk, int fd, ...@@ -261,7 +261,7 @@ static int dump_one_inet(const struct socket_desc *_sk, int fd,
memcpy(ie.src_addr, sk->src_addr, sizeof(u32) * 4); memcpy(ie.src_addr, sk->src_addr, sizeof(u32) * 4);
memcpy(ie.dst_addr, sk->dst_addr, sizeof(u32) * 4); memcpy(ie.dst_addr, sk->dst_addr, sizeof(u32) * 4);
if (write_img(cr_fdset->fds[CR_FD_INETSK], &ie)) if (write_img(fdset_fd(cr_fdset, CR_FD_INETSK), &ie))
goto err; goto err;
pr_info("Dumping inet socket at %d\n", fd); pr_info("Dumping inet socket at %d\n", fd);
...@@ -349,9 +349,9 @@ static int dump_one_unix(const struct socket_desc *_sk, int fd, ...@@ -349,9 +349,9 @@ static int dump_one_unix(const struct socket_desc *_sk, int fd,
ue.id, ue.peer); ue.id, ue.peer);
} }
if (write_img(cr_fdset->fds[CR_FD_UNIXSK], &ue)) if (write_img(fdset_fd(cr_fdset, CR_FD_UNIXSK), &ue))
goto err; goto err;
if (write_img_buf(cr_fdset->fds[CR_FD_UNIXSK], sk->name, ue.namelen)) if (write_img_buf(fdset_fd(cr_fdset, CR_FD_UNIXSK), sk->name, ue.namelen))
goto err; goto err;
if (sk->rqlen != 0 && !(sk->type == SOCK_STREAM && if (sk->rqlen != 0 && !(sk->type == SOCK_STREAM &&
......
...@@ -36,7 +36,7 @@ int dump_uts_ns(int ns_pid, struct cr_fdset *fdset) ...@@ -36,7 +36,7 @@ int dump_uts_ns(int ns_pid, struct cr_fdset *fdset)
return ret; return ret;
} }
fd = fdset->fds[CR_FD_UTSNS]; fd = fdset_fd(fdset, CR_FD_UTSNS);
ret = dump_uts_string(fd, ubuf.nodename); ret = dump_uts_string(fd, ubuf.nodename);
if (!ret) if (!ret)
......
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