mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 10:16:41 +00:00
pb: Rewrite object showing to use pb-descs
The pb_show things are no longer macros. Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
b1b0a39a58
commit
657a544fb7
12 changed files with 53 additions and 62 deletions
28
cr-show.c
28
cr-show.c
|
|
@ -56,7 +56,7 @@ static LIST_HEAD(pstree_list);
|
|||
|
||||
void show_files(int fd_files, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd_files, fdinfo_entry);
|
||||
pb_show_plain(fd_files, PB_FDINFO);
|
||||
}
|
||||
|
||||
void show_fown_cont(void *p)
|
||||
|
|
@ -68,17 +68,17 @@ void show_fown_cont(void *p)
|
|||
|
||||
void show_reg_files(int fd_reg_files, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd_reg_files, reg_file_entry);
|
||||
pb_show_plain(fd_reg_files, PB_REG_FILES);
|
||||
}
|
||||
|
||||
void show_remap_files(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd, remap_file_path_entry);
|
||||
pb_show_plain(fd, PB_REMAP_FPATH);
|
||||
}
|
||||
|
||||
void show_ghost_file(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_vertical(fd, ghost_file_entry);
|
||||
pb_show_vertical(fd, PB_GHOST_FILE);
|
||||
}
|
||||
|
||||
static void pipe_data_handler(int fd, void *obj, int show_pages_content)
|
||||
|
|
@ -94,13 +94,13 @@ static void pipe_data_handler(int fd, void *obj, int show_pages_content)
|
|||
|
||||
void show_pipes_data(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain_payload(fd, pipe_data_entry,
|
||||
pb_show_plain_payload(fd, PB_PIPES_DATA,
|
||||
pipe_data_handler, o->show_pages_content);
|
||||
}
|
||||
|
||||
void show_pipes(int fd_pipes, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd_pipes, pipe_entry);
|
||||
pb_show_plain(fd_pipes, PB_PIPES);
|
||||
}
|
||||
|
||||
void show_fifo_data(int fd, struct cr_options *o)
|
||||
|
|
@ -110,17 +110,17 @@ void show_fifo_data(int fd, struct cr_options *o)
|
|||
|
||||
void show_fifo(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd, fifo_entry);
|
||||
pb_show_plain(fd, PB_FIFO);
|
||||
}
|
||||
|
||||
void show_fs(int fd_fs, struct cr_options *o)
|
||||
{
|
||||
pb_show_vertical(fd_fs, fs_entry);
|
||||
pb_show_vertical(fd_fs, PB_FS);
|
||||
}
|
||||
|
||||
void show_vmas(int fd_vma, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd_vma, vma_entry);
|
||||
pb_show_plain(fd_vma, PB_VMAS);
|
||||
}
|
||||
|
||||
static int nice_width_for(unsigned long addr)
|
||||
|
|
@ -215,7 +215,7 @@ out:
|
|||
|
||||
void show_sigacts(int fd_sigacts, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd_sigacts, sa_entry);
|
||||
pb_show_plain(fd_sigacts, PB_SIGACT);
|
||||
}
|
||||
|
||||
static void show_itimer(char *n, ItimerEntry *ie)
|
||||
|
|
@ -255,7 +255,7 @@ out:
|
|||
|
||||
void show_creds(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_vertical(fd, creds_entry);
|
||||
pb_show_vertical(fd, PB_CREDS);
|
||||
}
|
||||
|
||||
static void pstree_handler(int fd, void *obj, int collect)
|
||||
|
|
@ -283,7 +283,7 @@ static void pstree_handler(int fd, void *obj, int collect)
|
|||
|
||||
void show_collect_pstree(int fd, int collect)
|
||||
{
|
||||
pb_show_plain_payload(fd, pstree_entry, pstree_handler, collect);
|
||||
pb_show_plain_payload(fd, PB_PSTREE, pstree_handler, collect);
|
||||
}
|
||||
|
||||
void show_pstree(int fd, struct cr_options *o)
|
||||
|
|
@ -349,12 +349,12 @@ void show_thread_info(ThreadInfoX86 *thread_info)
|
|||
|
||||
void show_core(int fd_core, struct cr_options *o)
|
||||
{
|
||||
pb_show_vertical(fd_core, core_entry);
|
||||
pb_show_vertical(fd_core, PB_CORE);
|
||||
}
|
||||
|
||||
void show_mm(int fd_mm, struct cr_options *o)
|
||||
{
|
||||
pb_show_vertical(fd_mm, mm_entry);
|
||||
pb_show_vertical(fd_mm, PB_MM);
|
||||
}
|
||||
|
||||
static int cr_parse_file(struct cr_options *opts)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ static void pr_info_eventfd(char *action, EventfdFileEntry *efe)
|
|||
|
||||
void show_eventfds(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd, eventfd_file_entry);
|
||||
pb_show_plain(fd, PB_EVENTFD);
|
||||
}
|
||||
|
||||
struct eventfd_dump_arg {
|
||||
|
|
|
|||
|
|
@ -55,12 +55,12 @@ static void pr_info_eventpoll(char *action, EventpollFileEntry *e)
|
|||
|
||||
void show_eventpoll_tfd(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd, eventpoll_tfd_entry);
|
||||
pb_show_plain(fd, PB_EVENTPOLL_TFD);
|
||||
}
|
||||
|
||||
void show_eventpoll(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd, eventpoll_file_entry);
|
||||
pb_show_plain(fd, PB_EVENTPOLL);
|
||||
}
|
||||
|
||||
static int dump_eventpoll_entry(union fdinfo_entries *e, void *arg)
|
||||
|
|
|
|||
|
|
@ -79,25 +79,17 @@ extern int pb_write_one(int fd, void *obj, int type);
|
|||
|
||||
#include <google/protobuf-c/protobuf-c.h>
|
||||
|
||||
extern void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *d,
|
||||
pb_unpack_t unpack, pb_free_t free, int single_entry,
|
||||
extern void do_pb_show_plain(int fd, int type, int single_entry,
|
||||
void (*payload_hadler)(int fd, void *obj, int flags),
|
||||
int flags);
|
||||
|
||||
/* Don't have objects at hands to also do typechecking here */
|
||||
#define pb_show_plain_payload(__fd, __proto_message_name, payload_hadler, flags) \
|
||||
do_pb_show_plain(__fd, &__proto_message_name##__descriptor, \
|
||||
(pb_unpack_t)__proto_message_name##__unpack, \
|
||||
(pb_free_t)__proto_message_name##__free_unpacked, \
|
||||
0, payload_hadler, flags)
|
||||
#define pb_show_plain_payload(__fd, __type, payload_hadler, flags) \
|
||||
do_pb_show_plain(__fd, __type, 0, payload_hadler, flags)
|
||||
|
||||
#define pb_show_plain(__fd, __proto_message_name) \
|
||||
pb_show_plain_payload(__fd, __proto_message_name, NULL, 0)
|
||||
#define pb_show_plain(__fd, __type) \
|
||||
pb_show_plain_payload(__fd, __type, NULL, 0)
|
||||
|
||||
#define pb_show_vertical(__fd, __proto_message_name) \
|
||||
do_pb_show_plain(__fd, &__proto_message_name##__descriptor, \
|
||||
(pb_unpack_t)__proto_message_name##__unpack, \
|
||||
(pb_free_t)__proto_message_name##__free_unpacked, \
|
||||
1, NULL, 0)
|
||||
#define pb_show_vertical(__fd, __type) \
|
||||
do_pb_show_plain(__fd, __type, 1, NULL, 0)
|
||||
|
||||
#endif /* PROTOBUF_H__ */
|
||||
|
|
|
|||
|
|
@ -59,12 +59,12 @@ int is_inotify_link(int lfd)
|
|||
|
||||
void show_inotify_wd(int fd_inotify_wd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd_inotify_wd, inotify_wd_entry);
|
||||
pb_show_plain(fd_inotify_wd, PB_INOTIFY_WD);
|
||||
}
|
||||
|
||||
void show_inotify(int fd_inotify, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd_inotify, inotify_file_entry);
|
||||
pb_show_plain(fd_inotify, PB_INOTIFY);
|
||||
}
|
||||
|
||||
static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
|
||||
|
|
|
|||
10
ipc_ns.c
10
ipc_ns.c
|
|
@ -486,7 +486,7 @@ static void ipc_sem_handler(int fd, void *obj, int show_pages_content)
|
|||
|
||||
void show_ipc_sem(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain_payload(fd, ipc_sem_entry, ipc_sem_handler, 0);
|
||||
pb_show_plain_payload(fd, PB_IPCNS_SEM, ipc_sem_handler, 0);
|
||||
}
|
||||
|
||||
static void ipc_msg_data_handler(int fd, void *obj, int show_pages_content)
|
||||
|
|
@ -507,14 +507,14 @@ static void ipc_msg_handler(int fd, void *obj, int show_pages_content)
|
|||
|
||||
pr_msg("\n");
|
||||
while (msg_nr++ < e->qnum)
|
||||
pb_show_plain_payload(fd, ipc_msg, ipc_msg_data_handler,
|
||||
pb_show_plain_payload(fd, PB_IPCNS_MSG, ipc_msg_data_handler,
|
||||
show_pages_content);
|
||||
|
||||
}
|
||||
|
||||
void show_ipc_msg(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain_payload(fd, ipc_msg_entry, ipc_msg_handler, o->show_pages_content);
|
||||
pb_show_plain_payload(fd, PB_IPCNS_MSG_ENT, ipc_msg_handler, o->show_pages_content);
|
||||
}
|
||||
|
||||
static void ipc_shm_handler(int fd, void *obj, int show_pages_content)
|
||||
|
|
@ -530,13 +530,13 @@ static void ipc_shm_handler(int fd, void *obj, int show_pages_content)
|
|||
|
||||
void show_ipc_shm(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain_payload(fd, ipc_shm_entry, ipc_shm_handler,
|
||||
pb_show_plain_payload(fd, PB_IPCNS_SHM, ipc_shm_handler,
|
||||
o->show_pages_content);
|
||||
}
|
||||
|
||||
void show_ipc_var(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_vertical(fd, ipc_var_entry);
|
||||
pb_show_vertical(fd, PB_IPCNS_VAR);
|
||||
}
|
||||
|
||||
static int prepare_ipc_sem_values(int fd, const IpcSemEntry *entry)
|
||||
|
|
|
|||
2
mount.c
2
mount.c
|
|
@ -542,7 +542,7 @@ int prepare_mnt_ns(int ns_pid)
|
|||
|
||||
void show_mountpoints(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd, mnt_entry);
|
||||
pb_show_plain(fd, PB_MOUNTPOINTS);
|
||||
}
|
||||
|
||||
int mntns_collect_root(pid_t pid)
|
||||
|
|
|
|||
2
net.c
2
net.c
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
void show_netdevices(int fd, struct cr_options *opt)
|
||||
{
|
||||
pb_show_plain(fd, net_device_entry);
|
||||
pb_show_plain(fd, PB_NETDEV);
|
||||
}
|
||||
|
||||
static int dump_one_netdev(int type, struct nlmsghdr *h, struct ifinfomsg *ifi, struct cr_fdset *fds)
|
||||
|
|
|
|||
35
protobuf.c
35
protobuf.c
|
|
@ -311,39 +311,32 @@ static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
|
|||
}
|
||||
}
|
||||
|
||||
static int pb_read_object_with_header(int fd, void **pobj, pb_unpack_t unpack, bool eof);
|
||||
int do_pb_read_one(int fd, void **pobj, int type, bool eof)
|
||||
{
|
||||
if (!cr_pb_descs[type].pb_desc) {
|
||||
pr_err("Wrong object requested %d\n", type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return pb_read_object_with_header(fd, pobj, cr_pb_descs[type].unpack, eof);
|
||||
}
|
||||
|
||||
static inline void pb_no_payload(int fd, void *obj, int flags) { }
|
||||
|
||||
void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
|
||||
pb_unpack_t unpack, pb_free_t free, int single_entry,
|
||||
void do_pb_show_plain(int fd, int type, int single_entry,
|
||||
void (*payload_hadler)(int fd, void *obj, int flags),
|
||||
int flags)
|
||||
{
|
||||
pb_pr_ctl_t ctl = {NULL, single_entry, 0};
|
||||
void (*handle_payload)(int fd, void *obj, int flags);
|
||||
|
||||
if (!cr_pb_descs[type].pb_desc) {
|
||||
pr_err("Wrong object requested %d\n", type);
|
||||
return;
|
||||
}
|
||||
|
||||
handle_payload = (payload_hadler) ? : pb_no_payload;
|
||||
|
||||
while (1) {
|
||||
void *obj;
|
||||
|
||||
if (pb_read_object_with_header(fd, &obj, unpack, true) <= 0)
|
||||
if (pb_read_one_eof(fd, &obj, type) <= 0)
|
||||
break;
|
||||
|
||||
ctl.arg = (void *)md;
|
||||
ctl.arg = (void *)cr_pb_descs[type].pb_desc;
|
||||
pb_show_msg(obj, &ctl);
|
||||
handle_payload(fd, obj, flags);
|
||||
free(obj, NULL);
|
||||
cr_pb_descs[type].free(obj, NULL);
|
||||
if (single_entry)
|
||||
break;
|
||||
pr_msg("\n");
|
||||
|
|
@ -360,13 +353,19 @@ void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
|
|||
*
|
||||
* Don't forget to free memory granted to unpacked object in calling code if needed
|
||||
*/
|
||||
static int pb_read_object_with_header(int fd, void **pobj, pb_unpack_t unpack, bool eof)
|
||||
|
||||
int do_pb_read_one(int fd, void **pobj, int type, bool eof)
|
||||
{
|
||||
u8 local[PB_PKOBJ_LOCAL_SIZE];
|
||||
void *buf = (void *)&local;
|
||||
u32 size;
|
||||
int ret;
|
||||
|
||||
if (!cr_pb_descs[type].pb_desc) {
|
||||
pr_err("Wrong object requested %d\n", type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*pobj = NULL;
|
||||
|
||||
ret = read(fd, &size, sizeof(size));
|
||||
|
|
@ -399,7 +398,7 @@ static int pb_read_object_with_header(int fd, void **pobj, pb_unpack_t unpack, b
|
|||
goto err;
|
||||
}
|
||||
|
||||
*pobj = unpack(NULL, size, buf);
|
||||
*pobj = cr_pb_descs[type].unpack(NULL, size, buf);
|
||||
if (!*pobj) {
|
||||
ret = -1;
|
||||
pr_err("Failed unpacking object %p\n", pobj);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ struct signalfd_dump_arg {
|
|||
|
||||
void show_signalfd(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain(fd, signalfd_entry);
|
||||
pb_show_plain(fd, PB_SIGNALFD);
|
||||
}
|
||||
|
||||
static int dump_signalfd_entry(union fdinfo_entries *e, void *arg)
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ static void sk_queue_data_handler(int fd, void *obj, int show_pages_content)
|
|||
|
||||
void show_sk_queues(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_plain_payload(fd, sk_packet_entry,
|
||||
pb_show_plain_payload(fd, PB_SK_QUEUES,
|
||||
sk_queue_data_handler, o->show_pages_content);
|
||||
}
|
||||
|
||||
|
|
|
|||
2
uts_ns.c
2
uts_ns.c
|
|
@ -66,5 +66,5 @@ out:
|
|||
|
||||
void show_utsns(int fd, struct cr_options *o)
|
||||
{
|
||||
pb_show_vertical(fd, utsns_entry);
|
||||
pb_show_vertical(fd, PB_UTSNS);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue