[CRIU] [crtools-bot for Cyrill Gorcunov ] show: Use pr_msg for
showing contents on console
Cyrill Gorcunov
gorcunov at openvz.org
Fri Mar 2 02:12:59 EST 2012
The commit is pushed to "master" and will appear on git://github.com/cyrillos/crtools.git
------>
commit 827cabb480448996d5797d91df37018dcf8de6d0
Author: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Fri Mar 2 00:59:59 2012 +0400
show: Use pr_msg for showing contents on console
Due to code sharing, especially in IPC area,
the unbinding is done via helper macros and
sysclt engine tuning (new CTL_SHOW action
added).
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
Acked-by: Pavel Emelyanov <xemul at parallels.com>
---
cr-show.c | 190 +++++++++++++++++++++++++++---------------------------
crtools.c | 1 -
include/sysctl.h | 1 +
include/util.h | 14 +++--
ipc_ns.c | 101 ++++++++++++++++-------------
sysctl.c | 25 +++++++-
util.c | 38 ++++++------
7 files changed, 204 insertions(+), 166 deletions(-)
diff --git a/cr-show.c b/cr-show.c
index e1977fc..9c9e2d6 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -30,26 +30,26 @@
#endif
-#define PR_SYMBOL(sym) \
+#define PR_SYMBOL(sym) \
(isprint(sym) ? sym : '.')
#define pr_regs4(s, n1, n2, n3, n4) \
- pr_info("%8s: %16lx " \
- "%8s: %16lx " \
- "%8s: %16lx " \
- "%8s: %16lx\n", \
- #n1, s.n1, \
- #n2, s.n2, \
- #n3, s.n3, \
- #n4, s.n4)
+ pr_msg("%8s: %16lx " \
+ "%8s: %16lx " \
+ "%8s: %16lx " \
+ "%8s: %16lx\n", \
+ #n1, s.n1, \
+ #n2, s.n2, \
+ #n3, s.n3, \
+ #n4, s.n4)
#define pr_regs3(s, n1, n2, n3) \
- pr_info("%8s: %16lx " \
- "%8s: %16lx " \
- "%8s: %16lx\n", \
- #n1, s.n1, \
- #n2, s.n2, \
- #n3, s.n3)
+ pr_msg("%8s: %16lx " \
+ "%8s: %16lx " \
+ "%8s: %16lx\n", \
+ #n1, s.n1, \
+ #n2, s.n2, \
+ #n3, s.n3)
static char local_buf[PAGE_SIZE];
static LIST_HEAD(pstree_list);
@@ -66,7 +66,7 @@ static void show_shmem(int fd_shmem)
ret = read_img_eof(fd_shmem, &e);
if (ret <= 0)
goto out;
- pr_info("0x%lx-0x%lx id %lu\n", e.start, e.end, e.shmid);
+ pr_msg("0x%lx-0x%lx id %lu\n", e.start, e.end, e.shmid);
}
out:
@@ -86,9 +86,9 @@ static void show_files(int fd_files)
if (ret <= 0)
goto out;
- pr_info("type: %02x len: %02x flags: %4x pos: %8x "
- "addr: %16lx id: %16lx",
- e.type, e.len, e.flags, e.pos, e.addr, e.id);
+ pr_msg("type: %02x len: %02x flags: %4x pos: %8x "
+ "addr: %16lx id: %16lx",
+ e.type, e.len, e.flags, e.pos, e.addr, e.id);
if (e.len) {
int ret = read(fd_files, local_buf, e.len);
@@ -97,10 +97,10 @@ static void show_files(int fd_files)
goto out;
}
local_buf[e.len] = 0;
- pr_info(" --> %s", local_buf);
+ pr_msg(" --> %s", local_buf);
}
- pr_info("\n");
+ pr_msg("\n");
}
out:
@@ -120,8 +120,8 @@ static void show_pipes(int fd_pipes)
ret = read_img_eof(fd_pipes, &e);
if (ret <= 0)
goto out;
- pr_info("fd: %8x pipeid: %8x flags: %8x bytes: %8x\n",
- e.fd, e.pipeid, e.flags, e.bytes);
+ pr_msg("fd: %8x pipeid: %8x flags: %8x bytes: %8x\n",
+ e.fd, e.pipeid, e.flags, e.bytes);
if (e.bytes)
lseek(fd_pipes, e.bytes, SEEK_CUR);
}
@@ -135,7 +135,7 @@ static void show_vma(int fd_vma)
struct vma_area vma_area = {};
struct vma_entry ve;
- pr_info("\n\t---[VMA areas]---\n");
+ pr_msg("\n\t---[VMA areas]---\n");
while (1) {
if (read_img(fd_vma, &ve) < 0)
break;
@@ -145,7 +145,7 @@ static void show_vma(int fd_vma)
/* Simply in a sake of fancy printing */
vma_area.vma = ve;
- pr_info_vma(&vma_area);
+ pr_msg_vma(&vma_area);
}
}
@@ -154,21 +154,21 @@ void print_data(unsigned long addr, unsigned char *data, size_t size)
int i, j;
for (i = 0; i < size; i+= 16) {
- pr_info("%16lx: ", addr + i);
+ pr_msg("%16lx: ", addr + i);
for (j = 0; j < 8; j++)
- pr_info("%02x ", data[i + j]);
- pr_info(" ");
+ pr_msg("%02x ", data[i + j]);
+ pr_msg(" ");
for (j = 8; j < 16; j++)
- pr_info("%02x ", data[i + j]);
+ pr_msg("%02x ", data[i + j]);
- pr_info(" |");
+ pr_msg(" |");
for (j = 0; j < 8; j++)
- pr_info("%c ", PR_SYMBOL(data[i + j]));
- pr_info(" ");
+ pr_msg("%c ", PR_SYMBOL(data[i + j]));
+ pr_msg(" ");
for (j = 8; j < 16; j++)
- pr_info("%c ", PR_SYMBOL(data[i + j]));
+ pr_msg("%c ", PR_SYMBOL(data[i + j]));
- pr_info("|\n");
+ pr_msg("|\n");
}
}
@@ -186,24 +186,24 @@ static void show_pages(int fd_pages, bool show_content)
break;
print_data(e.va, e.data, PAGE_IMAGE_SIZE);
- pr_info("\n --- End of page ---\n\n");
+ pr_msg("\n --- End of page ---\n\n");
}
} else {
while (1) {
struct page_entry e;
int i, j;
- pr_info("\t");
+ pr_msg("\t");
for (i = 0; i < DEF_PAGES_PER_LINE; i++) {
if (read_img(fd_pages, &e) < 0)
goto out;
if (final_page_entry(&e)) {
- pr_info("\n");
+ pr_msg("\n");
goto out;
}
- pr_info("%16lx ", e.va);
+ pr_msg("%16lx ", e.va);
}
- pr_info("\n");
+ pr_msg("\n");
}
}
@@ -223,12 +223,12 @@ static void show_sigacts(int fd_sigacts)
ret = read_img_eof(fd_sigacts, &e);
if (ret <= 0)
goto out;
- pr_info("sigaction: %016lx mask: %08lx "
- "flags: %016lx restorer: %016lx\n",
- (long)e.sigaction,
- (long)e.mask,
- (long)e.flags,
- (long)e.restorer);
+ pr_msg("sigaction: %016lx mask: %08lx "
+ "flags: %016lx restorer: %016lx\n",
+ (long)e.sigaction,
+ (long)e.mask,
+ (long)e.flags,
+ (long)e.restorer);
}
out:
@@ -237,9 +237,9 @@ out:
static void show_itimer(char *n, struct itimer_entry *ie)
{
- pr_info("%s: int %lu.%lu val %lu.%lu\n", n,
- (unsigned long)ie->isec, (unsigned long)ie->iusec,
- (unsigned long)ie->vsec, (unsigned long)ie->vusec);
+ pr_msg("%s: int %lu.%lu val %lu.%lu\n", n,
+ (unsigned long)ie->isec, (unsigned long)ie->iusec,
+ (unsigned long)ie->vsec, (unsigned long)ie->vusec);
}
static void show_itimers(int fd)
@@ -261,10 +261,10 @@ static void show_cap(char *name, u32 *v)
{
int i;
- pr_info("%s: ", name);
+ pr_msg("%s: ", name);
for (i = CR_CAP_SIZE - 1; i >= 0; i--)
- pr_info("%08x", v[i]);
- pr_info("\n");
+ pr_msg("%08x", v[i]);
+ pr_msg("\n");
}
static void show_creds(int fd)
@@ -275,17 +275,17 @@ static void show_creds(int fd)
if (read_img(fd, &ce) < 0)
goto out;
- pr_info("uid %u euid %u suid %u fsuid %u\n",
- ce.uid, ce.euid, ce.suid, ce.fsuid);
- pr_info("gid %u egid %u sgid %u fsgid %u\n",
- ce.gid, ce.egid, ce.sgid, ce.fsgid);
+ pr_msg("uid %u euid %u suid %u fsuid %u\n",
+ ce.uid, ce.euid, ce.suid, ce.fsuid);
+ pr_msg("gid %u egid %u sgid %u fsgid %u\n",
+ ce.gid, ce.egid, ce.sgid, ce.fsgid);
show_cap("Inh", ce.cap_inh);
show_cap("Eff", ce.cap_eff);
show_cap("Prm", ce.cap_prm);
show_cap("Bnd", ce.cap_bnd);
- pr_info("secbits: %x\n", ce.secbits);
+ pr_msg("secbits: %x\n", ce.secbits);
out:
pr_img_tail(CR_FD_CREDS);
}
@@ -304,8 +304,8 @@ static int show_pstree(int fd_pstree, struct list_head *collect)
ret = read_img_eof(fd_pstree, &e);
if (ret <= 0)
goto out;
- pr_info("pid: %8d nr_children: %8d nr_threads: %8d\n",
- e.pid, e.nr_children, e.nr_threads);
+ pr_msg("pid: %8d nr_children: %8d nr_threads: %8d\n",
+ e.pid, e.nr_children, e.nr_threads);
if (collect) {
item = xzalloc(sizeof(struct pstree_item));
@@ -324,29 +324,29 @@ static int show_pstree(int fd_pstree, struct list_head *collect)
}
if (e.nr_children) {
- pr_info("\\\n");
- pr_info(" +--- children: ");
+ pr_msg("\\\n");
+ pr_msg(" +--- children: ");
while (e.nr_children--) {
ret = read_img_eof(fd_pstree, &pid);
if (ret <= 0)
goto out;
- pr_info(" %6d", pid);
+ pr_msg(" %6d", pid);
}
- pr_info("\n");
+ pr_msg("\n");
}
if (e.nr_threads) {
- pr_info(" \\\n");
- pr_info(" --- threads: ");
+ pr_msg(" \\\n");
+ pr_msg(" --- threads: ");
while (e.nr_threads--) {
ret = read_img_eof(fd_pstree, &pid);
if (ret <= 0)
goto out;
- pr_info(" %6d", pid);
+ pr_msg(" %6d", pid);
if (item)
item->threads[e.nr_threads] = pid;
}
- pr_info("\n");
+ pr_msg("\n");
}
}
@@ -362,7 +362,7 @@ static void show_core_regs(int fd_core)
struct desc_struct tls;
int i;
- pr_info("\n\t---[GP registers set]---\n");
+ pr_msg("\n\t---[GP registers set]---\n");
lseek(fd_core, GET_FILE_OFF(struct core_entry, arch.gpregs), SEEK_SET);
@@ -376,7 +376,7 @@ static void show_core_regs(int fd_core)
pr_regs4(regs, r11, r12, r13, r14);
pr_regs3(regs, r15, bp, bx);
pr_regs4(regs, orig_ax, flags, fs_base, gs_base);
- pr_info("\n");
+ pr_msg("\n");
err:
return;
@@ -403,29 +403,29 @@ static void show_core_rest(int fd_core)
if (read_img(fd_core, &tc) < 0)
goto err;
- pr_info("\n\t---[Task parameters]---\n");
- pr_info("\tPersonality: %x\n", tc.personality);
- pr_info("\tCommand: %s\n", tc.comm);
- pr_info("\tState: %d (%s)\n",
- (int)tc.task_state,
- task_state_str((int)tc.task_state));
-
- pr_info("\t Exit code: %u\n",
- (unsigned int)tc.exit_code);
-
- pr_info("\tBrk: %lx\n", tc.mm_brk);
- pr_info("\tStart code: %lx\n", tc.mm_start_code);
- pr_info("\tEnd code: %lx\n", tc.mm_end_code);
- pr_info("\tStart stack: %lx\n", tc.mm_start_stack);
- pr_info("\tStart data: %lx\n", tc.mm_start_data);
- pr_info("\tEnd data: %lx\n", tc.mm_end_data);
- pr_info("\tStart brk: %lx\n", tc.mm_start_brk);
- pr_info("\tArg start: %lx\n", tc.mm_arg_start);
- pr_info("\tArg end: %lx\n", tc.mm_arg_end);
- pr_info("\tEnv start: %lx\n", tc.mm_env_start);
- pr_info("\tEnv end: %lx\n", tc.mm_env_end);
- pr_info("\n\tBlkSig: %lx\n", tc.blk_sigset);
- pr_info("\n");
+ pr_msg("\n\t---[Task parameters]---\n");
+ pr_msg("\tPersonality: %x\n", tc.personality);
+ pr_msg("\tCommand: %s\n", tc.comm);
+ pr_msg("\tState: %d (%s)\n",
+ (int)tc.task_state,
+ task_state_str((int)tc.task_state));
+
+ pr_msg("\t Exit code: %u\n",
+ (unsigned int)tc.exit_code);
+
+ pr_msg("\tBrk: %lx\n", tc.mm_brk);
+ pr_msg("\tStart code: %lx\n", tc.mm_start_code);
+ pr_msg("\tEnd code: %lx\n", tc.mm_end_code);
+ pr_msg("\tStart stack: %lx\n", tc.mm_start_stack);
+ pr_msg("\tStart data: %lx\n", tc.mm_start_data);
+ pr_msg("\tEnd data: %lx\n", tc.mm_end_data);
+ pr_msg("\tStart brk: %lx\n", tc.mm_start_brk);
+ pr_msg("\tArg start: %lx\n", tc.mm_arg_start);
+ pr_msg("\tArg end: %lx\n", tc.mm_arg_end);
+ pr_msg("\tEnv start: %lx\n", tc.mm_env_start);
+ pr_msg("\tEnv end: %lx\n", tc.mm_env_end);
+ pr_msg("\n\tBlkSig: %lx\n", tc.blk_sigset);
+ pr_msg("\n");
err:
return;
@@ -590,13 +590,13 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
if (!cr_fdset_th)
goto out;
- pr_info("\n");
- pr_info("Thread: %d\n", item->threads[i]);
- pr_info("----------------------------------------\n");
+ pr_msg("\n");
+ pr_msg("Thread: %d\n", item->threads[i]);
+ pr_msg("----------------------------------------\n");
show_core(cr_fdset_th->fds[CR_FD_CORE], opts->show_pages_content);
- pr_info("----------------------------------------\n");
+ pr_msg("----------------------------------------\n");
close_cr_fdset(&cr_fdset_th);
}
diff --git a/crtools.c b/crtools.c
index a39c02d..db68b77 100644
--- a/crtools.c
+++ b/crtools.c
@@ -404,7 +404,6 @@ int main(int argc, char *argv[])
ret = cr_restore_tasks(pid, &opts);
break;
case 's':
- log_set_loglevel(LOG_INFO);
ret = cr_show(pid, &opts);
break;
default:
diff --git a/include/sysctl.h b/include/sysctl.h
index 0d67b21..07ad4ef 100644
--- a/include/sysctl.h
+++ b/include/sysctl.h
@@ -13,6 +13,7 @@ enum {
CTL_READ,
CTL_WRITE,
CTL_PRINT,
+ CTL_SHOW,
};
#define CTL_SHIFT 4 /* Up to 16 types */
diff --git a/include/util.h b/include/util.h
index 0450bda..9d74953 100644
--- a/include/util.h
+++ b/include/util.h
@@ -136,14 +136,18 @@ extern void pr_info_siginfo(siginfo_t *siginfo);
struct vma_area;
struct list_head;
-extern void pr_info_vma(struct vma_area *vma_area);
+extern void pr_vma(unsigned int loglevel, struct vma_area *vma_area);
-#define pr_info_vma_list(head) \
+#define pr_info_vma(vma_area) pr_vma(LOG_INFO, vma_area)
+#define pr_msg_vma(vma_area) pr_vma(LOG_MSG, vma_area)
+
+#define pr_vma_list(level, head) \
do { \
struct vma_area *vma; \
list_for_each_entry(vma, head, list) \
- pr_info_vma(vma); \
+ pr_vma(level, vma); \
} while (0)
+#define pr_info_vma_list(head) pr_vma_list(LOG_INFO, head)
/*
* Note since VMA_AREA_NONE = 0 we can skip assignment
@@ -252,8 +256,8 @@ int do_open_proc(pid_t pid, int flags, const char *fmt, ...);
__ret; \
})
-#define pr_img_head(type, ...) pr_info("\n"#type __VA_ARGS__ "\n----------------\n")
-#define pr_img_tail(type) pr_info("----------------\n")
+#define pr_img_head(type, ...) pr_msg("\n"#type __VA_ARGS__ "\n----------------\n")
+#define pr_img_tail(type) pr_msg("----------------\n")
#define KDEV_MINORBITS 20
#define KDEV_MINORMASK ((1UL << KDEV_MINORBITS) - 1)
diff --git a/ipc_ns.c b/ipc_ns.c
index 61bedec..2afb509 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -51,12 +51,12 @@ struct msgbuf_a {
#define SEM_SET 20
#endif
-static void print_ipc_desc_entry(const struct ipc_desc_entry *desc)
+static void pr_ipc_desc_entry(unsigned int loglevel, const struct ipc_desc_entry *desc)
{
- pr_info("id: %-10d key: 0x%08x ", desc->id, desc->key);
- pr_info("uid: %-10d gid: %-10d ", desc->uid, desc->gid);
- pr_info("cuid: %-10d cgid: %-10d ", desc->cuid, desc->cgid);
- pr_info("mode: %-10o ", desc->mode);
+ print_on_level(loglevel, "id: %-10d key: 0x%08x ", desc->id, desc->key);
+ print_on_level(loglevel, "uid: %-10d gid: %-10d ", desc->uid, desc->gid);
+ print_on_level(loglevel, "cuid: %-10d cgid: %-10d ", desc->cuid, desc->cgid);
+ print_on_level(loglevel, "mode: %-10o ", desc->mode);
}
static void fill_ipc_desc(int id, struct ipc_desc_entry *desc,
@@ -71,19 +71,25 @@ static void fill_ipc_desc(int id, struct ipc_desc_entry *desc,
desc->mode = ipcp->mode;
}
-static void print_ipc_sem_array(int nr, u16 *values)
+static void pr_ipc_sem_array(unsigned int loglevel, int nr, u16 *values)
{
while(nr--)
- pr_info(" %-5d", values[nr]);
- pr_info("\n");
+ print_on_level(loglevel, " %-5d", values[nr]);
+ print_on_level(loglevel, "\n");
}
-static void print_ipc_sem_entry(const struct ipc_sem_entry *sem)
+#define pr_info_ipc_sem_array(nr, values) pr_ipc_sem_array(LOG_INFO, nr, values)
+#define pr_msg_ipc_sem_array(nr, values) pr_ipc_sem_array(LOG_MSG, nr, values)
+
+static void pr_ipc_sem_entry(unsigned int loglevel, const struct ipc_sem_entry *sem)
{
- print_ipc_desc_entry(&sem->desc);
- pr_info ("nsems: %-10d\n", sem->nsems);
+ pr_ipc_desc_entry(loglevel, &sem->desc);
+ print_on_level(loglevel, "nsems: %-10d\n", sem->nsems);
}
+#define pr_info_ipc_sem_entry(sem) pr_ipc_sem_entry(LOG_INFO, sem)
+#define pr_msg_ipc_sem_entry(sem) pr_ipc_sem_entry(LOG_MSG, sem)
+
static int dump_ipc_sem_set(int fd, const struct ipc_sem_entry *entry)
{
int ret, size;
@@ -102,7 +108,7 @@ static int dump_ipc_sem_set(int fd, const struct ipc_sem_entry *entry)
ret = -errno;
goto out;
}
- print_ipc_sem_array(entry->nsems, values);
+ pr_info_ipc_sem_array(entry->nsems, values);
ret = write_img_buf(fd, values, round_up(size, sizeof(u64)));
if (ret < 0) {
@@ -121,7 +127,7 @@ static int dump_ipc_sem_desc(int fd, int id, const struct semid_ds *ds)
fill_ipc_desc(id, &sem.desc, &ds->sem_perm);
sem.nsems = ds->sem_nsems;
- print_ipc_sem_entry(&sem);
+ pr_info_ipc_sem_entry(&sem);
ret = write_img(fd, &sem);
if (ret < 0) {
@@ -166,18 +172,25 @@ static int dump_ipc_sem(int fd)
return info.semusz;
}
-static void print_ipc_msg(int nr, const struct ipc_msg *msg)
+static void pr_ipc_msg(unsigned int loglevel, int nr, const struct ipc_msg *msg)
{
- pr_info(" %-5d: type: %-20ld size: %-10d\n",
- nr++, msg->mtype, msg->msize);
+ print_on_level(loglevel, " %-5d: type: %-20ld size: %-10d\n",
+ nr++, msg->mtype, msg->msize);
}
-static void print_ipc_msg_entry(const struct ipc_msg_entry *msg)
+#define pr_info_ipc_msg(nr, msg) pr_ipc_msg(LOG_INFO, nr, msg)
+#define pr_msg_ipc_msg(nr, msg) pr_ipc_msg(LOG_MSG, nr, msg)
+
+static void pr_ipc_msg_entry(unsigned int loglevel, const struct ipc_msg_entry *msg)
{
- print_ipc_desc_entry(&msg->desc);
- pr_info ("qbytes: %-10d qnum: %-10d\n", msg->qbytes, msg->qnum);
+ pr_ipc_desc_entry(loglevel, &msg->desc);
+ print_on_level(loglevel, "qbytes: %-10d qnum: %-10d\n",
+ msg->qbytes, msg->qnum);
}
+#define pr_info_ipc_msg_entry(msg) pr_ipc_msg_entry(LOG_INFO, msg)
+#define pr_msg_ipc_msg_entry(msg) pr_ipc_msg_entry(LOG_MSG, msg)
+
static int dump_ipc_msg_queue_messages(int fd, const struct ipc_msg_entry *entry, size_t cbytes)
{
void *msg_array, *ptr;
@@ -208,7 +221,7 @@ static int dump_ipc_msg_queue_messages(int fd, const struct ipc_msg_entry *entry
msg.msize = data->msize;
msg.mtype = data->mtype;
- print_ipc_msg(msg_nr, &msg);
+ pr_info_ipc_msg(msg_nr, &msg);
ret = write_img(fd, &msg);
if (ret < 0) {
@@ -237,7 +250,7 @@ static int dump_ipc_msg_queue(int fd, int id, const struct msqid_ds *ds)
fill_ipc_desc(id, &msg.desc, &ds->msg_perm);
msg.qbytes = ds->msg_qbytes;
msg.qnum = ds->msg_qnum;
- print_ipc_msg_entry(&msg);
+ pr_info_ipc_msg_entry(&msg);
ret = write_img(fd, &msg);
if (ret < 0) {
@@ -282,12 +295,15 @@ static int dump_ipc_msg(int fd)
return info.msgpool;
}
-static void print_ipc_shm(const struct ipc_shm_entry *shm)
+static void pr_ipc_shm(unsigned int loglevel, const struct ipc_shm_entry *shm)
{
- print_ipc_desc_entry(&shm->desc);
- pr_info("size: %-10lu\n", shm->size);
+ pr_ipc_desc_entry(loglevel, &shm->desc);
+ print_on_level(loglevel, "size: %-10lu\n", shm->size);
}
+#define pr_info_ipc_shm(shm) pr_ipc_shm(LOG_INFO, shm)
+#define pr_msg_ipc_shm(shm) pr_ipc_shm(LOG_MSG, shm)
+
static int ipc_sysctl_req(struct ipc_var_entry *e, int op)
{
struct sysctl_req req[] = {
@@ -342,7 +358,7 @@ static int dump_ipc_shm_seg(int fd, int id, const struct shmid_ds *ds)
fill_ipc_desc(id, &shm.desc, &ds->shm_perm);
shm.size = ds->shm_segsz;
- print_ipc_shm(&shm);
+ pr_info_ipc_shm(&shm);
ret = write_img(fd, &shm);
if (ret < 0) {
@@ -443,14 +459,9 @@ int dump_ipc_ns(int ns_pid, const struct cr_fdset *fdset)
return 0;
}
-static void show_var_entry(struct ipc_var_entry *entry)
-{
- ipc_sysctl_req(entry, CTL_PRINT);
-}
-
static void show_ipc_sem_entries(int fd)
{
- pr_info("\nSemaphores sets:\n");
+ pr_msg("\nSemaphores sets:\n");
while (1) {
int size;
struct ipc_sem_entry entry;
@@ -458,14 +469,14 @@ static void show_ipc_sem_entries(int fd)
if (read_img_eof(fd, &entry) <= 0)
return;
- print_ipc_sem_entry(&entry);
+ pr_msg_ipc_sem_entry(&entry);
size = sizeof(u16) * entry.nsems;
values = xmalloc(size);
if (values == NULL)
return;
if (read_img_buf(fd, values, round_up(size, sizeof(u64))) <= 0)
return;
- print_ipc_sem_array(entry.nsems, values);
+ pr_msg_ipc_sem_array(entry.nsems, values);
}
}
@@ -478,7 +489,7 @@ void show_ipc_sem(int fd)
static void show_ipc_msg_entries(int fd)
{
- pr_info("\nMessage queues:\n");
+ pr_msg("\nMessage queues:\n");
while (1) {
int ret;
struct ipc_msg_entry entry;
@@ -488,7 +499,7 @@ static void show_ipc_msg_entries(int fd)
if (ret <= 0)
return;
- print_ipc_msg_entry(&entry);
+ pr_msg_ipc_msg_entry(&entry);
while (msg_nr < entry.qnum) {
struct ipc_msg msg;
@@ -497,7 +508,7 @@ static void show_ipc_msg_entries(int fd)
if (ret <= 0)
return;
- print_ipc_msg(msg_nr, &msg);
+ pr_msg_ipc_msg(msg_nr, &msg);
if (lseek(fd, round_up(msg.msize, sizeof(u64)),
SEEK_CUR) == (off_t) -1)
@@ -516,7 +527,7 @@ void show_ipc_msg(int fd)
static void show_ipc_shm_entries(int fd)
{
- pr_info("\nShared memory segments:\n");
+ pr_msg("\nShared memory segments:\n");
while (1) {
int ret;
struct ipc_shm_entry shm;
@@ -525,7 +536,7 @@ static void show_ipc_shm_entries(int fd)
if (ret <= 0)
return;
- print_ipc_shm(&shm);
+ pr_msg_ipc_shm(&shm);
if (lseek(fd, round_up(shm.size, sizeof(u32)), SEEK_CUR) == (off_t) -1)
return;
@@ -547,7 +558,7 @@ static void show_ipc_var_entry(int fd)
ret = read_img_eof(fd, &var);
if (ret <= 0)
return;
- show_var_entry(&var);
+ ipc_sysctl_req(&var, CTL_SHOW);
}
void show_ipc_var(int fd)
@@ -577,7 +588,7 @@ static int prepare_ipc_sem_values(int fd, const struct ipc_sem_entry *entry)
goto out;
}
- print_ipc_sem_array(entry->nsems, values);
+ pr_info_ipc_sem_array(entry->nsems, values);
ret = semctl(entry->desc.id, 0, SETALL, values);
if (ret < 0) {
@@ -647,7 +658,7 @@ static int prepare_ipc_sem(int pid)
if (ret == 0)
break;
- print_ipc_sem_entry(&entry);
+ pr_info_ipc_sem_entry(&entry);
ret = prepare_ipc_sem_desc(fd, &entry);
if (ret < 0) {
@@ -674,7 +685,7 @@ static int prepare_ipc_msg_queue_messages(int fd, const struct ipc_msg_entry *en
if (ret <= 0)
return -EIO;
- print_ipc_msg(msg_nr, &msg);
+ pr_info_ipc_msg(msg_nr, &msg);
if (msg.msize > MSGMAX) {
pr_err("Unsupported message size: %d (MAX: %d)\n",
@@ -760,7 +771,7 @@ static int prepare_ipc_msg(int pid)
if (ret == 0)
break;
- print_ipc_msg_entry(&entry);
+ pr_info_ipc_msg_entry(&entry);
ret = prepare_ipc_msg_queue(fd, &entry);
if (ret < 0) {
@@ -852,7 +863,7 @@ static int prepare_ipc_shm(int pid)
if (ret == 0)
break;
- print_ipc_shm(&shm);
+ pr_info_ipc_shm(&shm);
ret = prepare_ipc_shm_seg(fd, &shm);
if (ret < 0) {
@@ -879,7 +890,7 @@ static int prepare_ipc_var(int pid)
return -EFAULT;
}
- show_var_entry(&var);
+ ipc_sysctl_req(&var, CTL_PRINT);
ret = ipc_sysctl_req(&var, CTL_WRITE);
if (ret < 0) {
diff --git a/sysctl.c b/sysctl.c
index 6d0f8bd..51255a9 100644
--- a/sysctl.c
+++ b/sysctl.c
@@ -20,6 +20,10 @@ do { \
__ret = sysctl_print_##__type(__fd, __req, \
(__type *)(__req)->arg, \
__nr); \
+ else if (__op == CTL_PRINT) \
+ __ret = sysctl_show_##__type(__fd, __req, \
+ (__type *)(__req)->arg, \
+ __nr); \
else \
__ret = -1; \
} while (0)
@@ -109,6 +113,21 @@ static int sysctl_print_##__type(int fd, \
return 0; \
}
+#define GEN_SYSCTL_SHOW_FUNC(__type, __fmt) \
+static int sysctl_show_##__type(int fd, \
+ struct sysctl_req *req, \
+ __type *arg, \
+ int nr) \
+{ \
+ int i; \
+ pr_msg("sysctl: <%s> = <", req->name); \
+ for (i = 0; i < nr; i++) \
+ pr_msg(__fmt, arg[i]); \
+ pr_msg(">\n"); \
+ \
+ return 0; \
+}
+
GEN_SYSCTL_READ_FUNC(u32, strtoul);
GEN_SYSCTL_READ_FUNC(u64, strtoull);
@@ -119,6 +138,10 @@ GEN_SYSCTL_PRINT_FUNC(u32, "%u ");
GEN_SYSCTL_PRINT_FUNC(u64, "%lu ");
GEN_SYSCTL_PRINT_FUNC(char, "%c");
+GEN_SYSCTL_SHOW_FUNC(u32, "%u ");
+GEN_SYSCTL_SHOW_FUNC(u64, "%lu ");
+GEN_SYSCTL_SHOW_FUNC(char, "%c");
+
static int
sysctl_write_char(int fd, struct sysctl_req *req, char *arg, int nr)
{
@@ -195,7 +218,7 @@ int sysctl_op(struct sysctl_req *req, int op)
int ret = 0;
int dir = -1;
- if (op != CTL_PRINT) {
+ if (op != CTL_PRINT && op != CTL_SHOW) {
dir = open("/proc/sys", O_RDONLY);
if (dir < 0) {
pr_perror("Can't open sysctl dir");
diff --git a/util.c b/util.c
index 4f84943..dce38c6 100644
--- a/util.c
+++ b/util.c
@@ -57,29 +57,29 @@ void pr_info_siginfo(siginfo_t *siginfo)
siginfo->si_signo, siginfo->si_errno, siginfo->si_code);
}
-void pr_info_vma(struct vma_area *vma_area)
+void pr_vma(unsigned int loglevel, struct vma_area *vma_area)
{
if (!vma_area)
return;
- pr_info("s: %16lx e: %16lx l: %4liK p: %8x f: %8x pg: %8lx "
- "vf: %s st: %s spc: %s\n",
- vma_area->vma.start, vma_area->vma.end,
- KBYTES(vma_area_len(vma_area)),
- vma_area->vma.prot,
- vma_area->vma.flags,
- vma_area->vma.pgoff,
- vma_area->vm_file_fd < 0 ? "n" : "y",
- !vma_area->vma.status ? "--" :
- ((vma_area->vma.status & VMA_FILE_PRIVATE) ? "FP" :
- ((vma_area->vma.status & VMA_FILE_SHARED) ? "FS" :
- ((vma_area->vma.status & VMA_ANON_SHARED) ? "AS" :
- ((vma_area->vma.status & VMA_ANON_PRIVATE) ? "AP" : "--")))),
- !vma_area->vma.status ? "--" :
- ((vma_area->vma.status & VMA_AREA_STACK) ? "stack" :
- ((vma_area->vma.status & VMA_AREA_HEAP) ? "heap" :
- ((vma_area->vma.status & VMA_AREA_VSYSCALL) ? "vsyscall" :
- ((vma_area->vma.status & VMA_AREA_VDSO) ? "vdso" : "n")))));
+ print_on_level(loglevel, "s: %16lx e: %16lx l: %4liK p: %8x f: %8x pg: %8lx "
+ "vf: %s st: %s spc: %s\n",
+ vma_area->vma.start, vma_area->vma.end,
+ KBYTES(vma_area_len(vma_area)),
+ vma_area->vma.prot,
+ vma_area->vma.flags,
+ vma_area->vma.pgoff,
+ vma_area->vm_file_fd < 0 ? "n" : "y",
+ !vma_area->vma.status ? "--" :
+ ((vma_area->vma.status & VMA_FILE_PRIVATE) ? "FP" :
+ ((vma_area->vma.status & VMA_FILE_SHARED) ? "FS" :
+ ((vma_area->vma.status & VMA_ANON_SHARED) ? "AS" :
+ ((vma_area->vma.status & VMA_ANON_PRIVATE) ? "AP" : "--")))),
+ !vma_area->vma.status ? "--" :
+ ((vma_area->vma.status & VMA_AREA_STACK) ? "stack" :
+ ((vma_area->vma.status & VMA_AREA_HEAP) ? "heap" :
+ ((vma_area->vma.status & VMA_AREA_VSYSCALL) ? "vsyscall" :
+ ((vma_area->vma.status & VMA_AREA_VDSO) ? "vdso" : "n")))));
}
int close_safe(int *fd)
More information about the CRIU
mailing list