Commit e710c5c5 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Cyrill Gorcunov

crtools: anitize showing funtions

Remove unneeded path argument (we do know the file data is read from) and
actually bogus show_header boolean.

Also introduce two helpers for showing header and tail.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 7c73b4c1
...@@ -51,15 +51,11 @@ ...@@ -51,15 +51,11 @@
static char local_buf[PAGE_SIZE]; static char local_buf[PAGE_SIZE];
static LIST_HEAD(pstree_list); static LIST_HEAD(pstree_list);
static void show_shmem(char *name, int fd_shmem, bool show_header) static void show_shmem(int fd_shmem)
{ {
struct shmem_entry e; struct shmem_entry e;
if (show_header) { pr_img_head(CR_FD_SHMEM);
pr_info("\n");
pr_info("CR_FD_SHMEM: %s\n", name);
pr_info("----------------------------------------\n");
}
while (1) { while (1) {
int ret = read_ptr_safe_eof(fd_shmem, &e, out); int ret = read_ptr_safe_eof(fd_shmem, &e, out);
...@@ -69,19 +65,14 @@ static void show_shmem(char *name, int fd_shmem, bool show_header) ...@@ -69,19 +65,14 @@ static void show_shmem(char *name, int fd_shmem, bool show_header)
} }
out: out:
if (show_header) pr_img_tail(CR_FD_SHMEM);
pr_info("----------------------------------------\n");
} }
static void show_files(char *name, int fd_files, bool show_header) static void show_files(int fd_files)
{ {
struct fdinfo_entry e; struct fdinfo_entry e;
if (show_header) { pr_img_head(CR_FD_FDINFO);
pr_info("\n");
pr_info("CR_FD_FDINFO: %s\n", name);
pr_info("----------------------------------------\n");
}
while (1) { while (1) {
int ret = read_ptr_safe_eof(fd_files, &e, out); int ret = read_ptr_safe_eof(fd_files, &e, out);
...@@ -102,20 +93,15 @@ static void show_files(char *name, int fd_files, bool show_header) ...@@ -102,20 +93,15 @@ static void show_files(char *name, int fd_files, bool show_header)
} }
out: out:
if (show_header) pr_img_tail(CR_FD_FDINFO);
pr_info("----------------------------------------\n");
} }
static void show_pipes(char *name, int fd_pipes, bool show_header) static void show_pipes(int fd_pipes)
{ {
struct pipe_entry e; struct pipe_entry e;
int ret; int ret;
if (show_header) { pr_img_head(CR_FD_PIPES);
pr_info("\n");
pr_info("CR_FD_PIPES: %s\n", name);
pr_info("----------------------------------------\n");
}
while (1) { while (1) {
int ret = read_ptr_safe_eof(fd_pipes, &e, out); int ret = read_ptr_safe_eof(fd_pipes, &e, out);
...@@ -128,8 +114,7 @@ static void show_pipes(char *name, int fd_pipes, bool show_header) ...@@ -128,8 +114,7 @@ static void show_pipes(char *name, int fd_pipes, bool show_header)
} }
out: out:
if (show_header) pr_img_tail(CR_FD_PIPES);
pr_info("----------------------------------------\n");
} }
static void show_vma(int fd_vma) static void show_vma(int fd_vma)
...@@ -152,13 +137,9 @@ out: ...@@ -152,13 +137,9 @@ out:
; /* to placate gcc */ ; /* to placate gcc */
} }
static void show_pages(char *name, int fd_pages, bool show_header, bool show_content) static void show_pages(int fd_pages, bool show_content)
{ {
if (show_header) { pr_img_head(CR_FD_PAGES);
pr_info("\n");
pr_info("CR_FD_PAGES: %s\n", name);
pr_info("----------------------------------------\n");
}
if (show_content) { if (show_content) {
while (1) { while (1) {
...@@ -209,19 +190,14 @@ static void show_pages(char *name, int fd_pages, bool show_header, bool show_con ...@@ -209,19 +190,14 @@ static void show_pages(char *name, int fd_pages, bool show_header, bool show_con
} }
out: out:
if (show_header) pr_img_tail(CR_FD_PAGES);
pr_info("----------------------------------------\n");
} }
static void show_sigacts(char *name, int fd_sigacts, bool show_header) static void show_sigacts(int fd_sigacts)
{ {
struct sa_entry e; struct sa_entry e;
if (show_header) { pr_img_head(CR_FD_SIGACT);
pr_info("\n");
pr_info("CR_FD_SIGACT: %s\n", name);
pr_info("----------------------------------------\n");
}
while (1) { while (1) {
int ret = read_ptr_safe_eof(fd_sigacts, &e, out); int ret = read_ptr_safe_eof(fd_sigacts, &e, out);
...@@ -236,25 +212,20 @@ static void show_sigacts(char *name, int fd_sigacts, bool show_header) ...@@ -236,25 +212,20 @@ static void show_sigacts(char *name, int fd_sigacts, bool show_header)
} }
out: out:
if (show_header) pr_img_tail(CR_FD_SIGACT);
pr_info("----------------------------------------\n");
} }
static void show_pstree(char *name, int fd_sigacts, bool show_header) static void show_pstree(int fd_pstree)
{ {
struct pstree_entry e; struct pstree_entry e;
if (show_header) { pr_img_head(CR_FD_PSTREE);
pr_info("\n");
pr_info("CR_FD_PSTREE: %s\n", name);
pr_info("----------------------------------------\n");
}
while (1) { while (1) {
u32 pid; u32 pid;
int ret; int ret;
ret = read_ptr_safe_eof(fd_sigacts, &e, out); ret = read_ptr_safe_eof(fd_pstree, &e, out);
if (!ret) if (!ret)
goto out; goto out;
pr_info("pid: %8d nr_children: %8d nr_threads: %8d\n", pr_info("pid: %8d nr_children: %8d nr_threads: %8d\n",
...@@ -264,7 +235,7 @@ static void show_pstree(char *name, int fd_sigacts, bool show_header) ...@@ -264,7 +235,7 @@ static void show_pstree(char *name, int fd_sigacts, bool show_header)
pr_info("\\\n"); pr_info("\\\n");
pr_info(" +--- children: "); pr_info(" +--- children: ");
while (e.nr_children--) { while (e.nr_children--) {
ret = read_ptr_safe_eof(fd_sigacts, &pid, out); ret = read_ptr_safe_eof(fd_pstree, &pid, out);
if (!ret) if (!ret)
goto out; goto out;
pr_info(" %6d", pid); pr_info(" %6d", pid);
...@@ -276,7 +247,7 @@ static void show_pstree(char *name, int fd_sigacts, bool show_header) ...@@ -276,7 +247,7 @@ static void show_pstree(char *name, int fd_sigacts, bool show_header)
pr_info(" \\\n"); pr_info(" \\\n");
pr_info(" --- threads: "); pr_info(" --- threads: ");
while (e.nr_threads--) { while (e.nr_threads--) {
ret = read_ptr_safe_eof(fd_sigacts, &pid, out); ret = read_ptr_safe_eof(fd_pstree, &pid, out);
if (!ret) if (!ret)
goto out; goto out;
pr_info(" %6d", pid); pr_info(" %6d", pid);
...@@ -287,8 +258,7 @@ static void show_pstree(char *name, int fd_sigacts, bool show_header) ...@@ -287,8 +258,7 @@ static void show_pstree(char *name, int fd_sigacts, bool show_header)
} }
out: out:
if (show_header) pr_img_tail(CR_FD_PSTREE);
pr_info("----------------------------------------\n");
} }
static void show_core_regs(int fd_core) static void show_core_regs(int fd_core)
...@@ -367,27 +337,22 @@ err: ...@@ -367,27 +337,22 @@ err:
return; return;
} }
static void show_core(char *name, int fd_core, bool show_header, bool show_content) static void show_core(int fd_core, bool show_content)
{ {
struct stat stat; struct stat stat;
bool is_thread; bool is_thread;
if (fstat(fd_core, &stat)) { if (fstat(fd_core, &stat)) {
pr_perror("Can't get stat on %s\n", name); pr_perror("Can't get stat on core file\n");
goto out; goto out;
} }
is_thread = (stat.st_size == GET_FILE_OFF_AFTER(struct core_entry)); is_thread = (stat.st_size == GET_FILE_OFF_AFTER(struct core_entry));
if (show_header) { if (is_thread)
pr_info("\n"); pr_img_head(CR_FD_CORE, " (thread)");
pr_info("CR_FD_CORE: %s", name); else
if (is_thread) pr_img_head(CR_FD_CORE);
pr_info(" (thread)\n");
else
pr_info("\n");
pr_info("----------------------------------------\n");
}
show_core_regs(fd_core); show_core_regs(fd_core);
show_core_rest(fd_core); show_core_rest(fd_core);
...@@ -405,10 +370,9 @@ static void show_core(char *name, int fd_core, bool show_header, bool show_conte ...@@ -405,10 +370,9 @@ static void show_core(char *name, int fd_core, bool show_header, bool show_conte
show_vma(fd_core); show_vma(fd_core);
pr_info("\n\t---[Memory pages]---\n"); pr_info("\n\t---[Memory pages]---\n");
show_pages(name, fd_core, false, show_content); show_pages(fd_core, show_content);
out: out:
if (show_header) pr_img_tail(CR_FD_CORE);
pr_info("----------------------------------------\n");
} }
static int cr_parse_file(struct cr_options *opts) static int cr_parse_file(struct cr_options *opts)
...@@ -427,30 +391,28 @@ static int cr_parse_file(struct cr_options *opts) ...@@ -427,30 +391,28 @@ static int cr_parse_file(struct cr_options *opts)
switch (magic) { switch (magic) {
case FDINFO_MAGIC: case FDINFO_MAGIC:
show_files(opts->show_dump_file, fd, true); show_files(fd);
break; break;
case PAGES_MAGIC: case PAGES_MAGIC:
show_pages(opts->show_dump_file, fd, true, show_pages(fd, opts->show_pages_content);
opts->show_pages_content);
break; break;
case CORE_MAGIC: case CORE_MAGIC:
show_core(opts->show_dump_file, fd, true, show_core(fd, opts->show_pages_content);
opts->show_pages_content);
break; break;
case SHMEM_MAGIC: case SHMEM_MAGIC:
show_shmem(opts->show_dump_file, fd, true); show_shmem(fd);
break; break;
case PSTREE_MAGIC: case PSTREE_MAGIC:
show_pstree(opts->show_dump_file, fd, true); show_pstree(fd);
break; break;
case PIPES_MAGIC: case PIPES_MAGIC:
show_pipes(opts->show_dump_file, fd, true); show_pipes(fd);
break; break;
case SIGACT_MAGIC: case SIGACT_MAGIC:
show_sigacts(opts->show_dump_file, fd, true); show_sigacts(fd);
break; break;
case UNIXSK_MAGIC: case UNIXSK_MAGIC:
show_unixsk(opts->show_dump_file, fd, true); show_unixsk(fd);
break; break;
default: default:
pr_err("Unknown magic %x on %s\n", magic, opts->show_dump_file); pr_err("Unknown magic %x on %s\n", magic, opts->show_dump_file);
...@@ -553,9 +515,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts) ...@@ -553,9 +515,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
* time here, but this saves us from code duplication. * time here, but this saves us from code duplication.
*/ */
lseek(cr_fdset->desc[CR_FD_PSTREE].fd, MAGIC_OFFSET, SEEK_SET); lseek(cr_fdset->desc[CR_FD_PSTREE].fd, MAGIC_OFFSET, SEEK_SET);
show_pstree(cr_fdset->desc[CR_FD_PSTREE].path, show_pstree(cr_fdset->desc[CR_FD_PSTREE].fd);
cr_fdset->desc[CR_FD_PSTREE].fd,
true);
close_cr_fdset(cr_fdset); close_cr_fdset(cr_fdset);
free_cr_fdset(&cr_fdset); free_cr_fdset(&cr_fdset);
...@@ -571,9 +531,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts) ...@@ -571,9 +531,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
goto out; goto out;
lseek(cr_fdset->desc[CR_FD_CORE].fd, MAGIC_OFFSET, SEEK_SET); lseek(cr_fdset->desc[CR_FD_CORE].fd, MAGIC_OFFSET, SEEK_SET);
show_core(cr_fdset->desc[CR_FD_CORE].path, show_core(cr_fdset->desc[CR_FD_CORE].fd, opts->show_pages_content);
cr_fdset->desc[CR_FD_CORE].fd,
true, opts->show_pages_content);
if (item->nr_threads > 1) { if (item->nr_threads > 1) {
struct cr_fdset *cr_fdset_th; struct cr_fdset *cr_fdset_th;
...@@ -597,9 +555,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts) ...@@ -597,9 +555,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
lseek(cr_fdset_th->desc[CR_FD_CORE].fd, MAGIC_OFFSET, SEEK_SET); lseek(cr_fdset_th->desc[CR_FD_CORE].fd, MAGIC_OFFSET, SEEK_SET);
show_core(cr_fdset_th->desc[CR_FD_CORE].path, show_core(cr_fdset_th->desc[CR_FD_CORE].fd, opts->show_pages_content);
cr_fdset_th->desc[CR_FD_CORE].fd,
false, opts->show_pages_content);
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
...@@ -608,20 +564,15 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts) ...@@ -608,20 +564,15 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
} }
} }
show_pipes(cr_fdset->desc[CR_FD_PIPES].path, show_pipes(cr_fdset->desc[CR_FD_PIPES].fd);
cr_fdset->desc[CR_FD_PIPES].fd, true);
show_files(cr_fdset->desc[CR_FD_FDINFO].path, show_files(cr_fdset->desc[CR_FD_FDINFO].fd);
cr_fdset->desc[CR_FD_FDINFO].fd, true);
show_shmem(cr_fdset->desc[CR_FD_SHMEM].path, show_shmem(cr_fdset->desc[CR_FD_SHMEM].fd);
cr_fdset->desc[CR_FD_SHMEM].fd, true);
show_sigacts(cr_fdset->desc[CR_FD_SIGACT].path, show_sigacts(cr_fdset->desc[CR_FD_SIGACT].fd);
cr_fdset->desc[CR_FD_SIGACT].fd, true);
show_unixsk(cr_fdset->desc[CR_FD_UNIXSK].path, show_unixsk(cr_fdset->desc[CR_FD_UNIXSK].fd);
cr_fdset->desc[CR_FD_UNIXSK].fd, true);
close_cr_fdset(cr_fdset); close_cr_fdset(cr_fdset);
free_cr_fdset(&cr_fdset); free_cr_fdset(&cr_fdset);
......
...@@ -8,6 +8,6 @@ extern int try_dump_socket(char *dir_name, char *fd_name, struct cr_fdset *cr_fd ...@@ -8,6 +8,6 @@ extern int try_dump_socket(char *dir_name, char *fd_name, struct cr_fdset *cr_fd
extern int collect_sockets(void); extern int collect_sockets(void);
extern int prepare_sockets(int pid); extern int prepare_sockets(int pid);
extern void show_unixsk(char *name, int fd, bool show_header); extern void show_unixsk(int fd);
#endif /* CR_SOCKETS_H__ */ #endif /* CR_SOCKETS_H__ */
...@@ -203,4 +203,7 @@ extern int open_fmt(char *fmt, int mode, ...); ...@@ -203,4 +203,7 @@ extern int open_fmt(char *fmt, int mode, ...);
__ret; \ __ret; \
}) })
#define pr_img_head(type, ...) pr_info("\n"#type __VA_ARGS__ "\n----------------\n")
#define pr_img_tail(type) pr_info("\n----------------\n")
#endif /* UTIL_H_ */ #endif /* UTIL_H_ */
...@@ -803,16 +803,12 @@ int prepare_sockets(int pid) ...@@ -803,16 +803,12 @@ int prepare_sockets(int pid)
return prepare_unix_sockets(pid); return prepare_unix_sockets(pid);
} }
void show_unixsk(char *name, int fd, bool show_header) void show_unixsk(int fd)
{ {
struct unix_sk_entry ue; struct unix_sk_entry ue;
int ret = 0; int ret = 0;
if (show_header) { pr_img_head(CR_FD_UNIXSK);
pr_info("\n");
pr_info("CR_FD_UNIXSK: %s\n", name);
pr_info("----------------------------------------\n");
}
while (1) { while (1) {
ret = read_ptr_safe_eof(fd, &ue, out); ret = read_ptr_safe_eof(fd, &ue, out);
...@@ -836,7 +832,6 @@ void show_unixsk(char *name, int fd, bool show_header) ...@@ -836,7 +832,6 @@ void show_unixsk(char *name, int fd, bool show_header)
out: out:
if (ret) if (ret)
pr_info("\n"); pr_info("\n");
if (show_header) pr_img_tail(CR_FD_UNIXSK);
pr_info("----------------------------------------\n");
} }
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