criu/include/protobuf.h
Cyrill Gorcunov 89a7a45d37 tty: Add checkpoint/restore for unix terminals v6
Usually the PTYs represent a pair of links -- master peer and slave
peer. Master peer must be opened before slave. Internally, when kernel
creates master peer it also generates a slave interface in a form of
/dev/pts/N, where N is that named pty "index". Master/slave connection
unambiguously identified by this index.

Still, one master can carry multiple slaves -- for example a user opens
one master via /dev/ptmx and appropriate /dev/pts/N in sequence.
The result will be the following

master
`- slave 1
`- slave 2

both slave will have same master index but different file descriptors.
Still inside the kernel pty parameters are same for both slaves. Thus
only one slave parameters should be restored, there is no need to carry
all parameters for every slave peer we've found.

Not yet addressed problems:

- At moment of restore the master peer might be already closed for
  any reason so to resolve such problem we need to open a fake master
  peer with proper index and hook a slave on it, then we close
  master peer.

- Need to figure out how to deal with ttys which have some
  data in buffers not yet flushed, at moment this data will
  be simply lost during c/r

- Need to restore control terminals

- Need to fetch tty flags such as exclusive/packet-mode,
  this can't be done without kernel patching

[ avagin@:
   - ideas on contol terminals restore
   - overall code redesign and simplification
]

v4:
 - drop redundant pid from dump_chrdev
 - make sure optional fown is passed on regular ptys
 - add a comments about zeroifying termios
 - get rid of redundant empty line in files.c

v5 (by avagin@):
 - complete rework of tty image format, now we have
   two files -- tty.img and tty-info.img. The idea
   behind to reduce data being stored.

v6 (by xemul@):
 - packet mode should be set to true in image,
   until properly fetched from the kernel
 - verify image data on retrieval

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:00:54 +04:00

107 lines
2.7 KiB
C

#ifndef PROTOBUF_H__
#define PROTOBUF_H__
#include "types.h"
#include "compiler.h"
#include "util.h"
enum {
PB_INVENTORY,
PB_FDINFO,
PB_CORE,
PB_MM,
PB_VMAS,
PB_SIGACT,
PB_ITIMERS,
PB_CREDS,
PB_FS,
PB_UTSNS,
PB_IPCNS_VAR,
PB_IPCNS_SHM,
PB_IPCNS_MSG,
PB_IPCNS_MSG_ENT,
PB_IPCNS_SEM,
PB_MOUNTPOINTS,
PB_NETDEV,
PB_PSTREE,
PB_GHOST_FILE,
PB_TCP_STREAM,
PB_SK_QUEUES,
PB_REG_FILES,
PB_INETSK,
PB_UNIXSK,
PB_PACKETSK,
PB_PIPES,
PB_FIFO,
PB_PIPES_DATA,
PB_REMAP_FPATH,
PB_EVENTFD,
PB_EVENTPOLL,
PB_EVENTPOLL_TFD,
PB_SIGNALFD,
PB_INOTIFY,
PB_INOTIFY_WD,
PB_TTY,
PB_TTY_INFO,
PB_MAX
};
/*
* ATTENTION
*
* This typdefs represent "generic" prototypes for
* pack/unpack/getsize functions generated by PB
* engine, thus (!!!) if PB engine change arguments
* order or their number we may meet serious problems.
*
* FIXME
*
* Find a way to verify PB generated functions statemens
* to match this typedefs.
*/
void cr_pb_init(void);
extern int do_pb_read_one(int fd, void **objp, int type, bool eof);
#define pb_read_one(fd, objp, type) do_pb_read_one(fd, (void **)objp, type, false)
#define pb_read_one_eof(fd, objp, type) do_pb_read_one(fd, (void **)objp, type, true)
extern int pb_write_one(int fd, void *obj, int type);
#define pb_pksize(__obj, __proto_message_name) \
(__proto_message_name ##__get_packed_size(__obj) + sizeof(u32))
#define pb_repeated_size(__obj, __member) \
(sizeof(*(__obj)->__member) * (__obj)->n_ ##__member)
#define pb_msg(__base, __type) \
container_of(__base, __type, base)
#include <google/protobuf-c/protobuf-c.h>
extern void do_pb_show_plain(int fd, int type, int single_entry,
void (*payload_hadler)(int fd, void *obj, int flags),
int flags, const char *pretty_fmt);
/* Don't have objects at hands to also do typechecking here */
#define pb_show_plain_payload_pretty(__fd, __type, payload_hadler, flags, pretty) \
do_pb_show_plain(__fd, __type, 0, payload_hadler, flags, pretty)
#define pb_show_plain_payload(__fd, __proto_message_name, payload_hadler, flags) \
pb_show_plain_payload_pretty(__fd, __proto_message_name, payload_hadler, flags, NULL)
#define pb_show_plain_pretty(__fd, __proto_message_name, __pretty) \
pb_show_plain_payload_pretty(__fd, __proto_message_name, NULL, 0, __pretty)
#define pb_show_plain(__fd, __type) \
pb_show_plain_payload(__fd, __type, NULL, 0)
#define pb_show_vertical(__fd, __type) \
do_pb_show_plain(__fd, __type, 1, NULL, 0, NULL)
int collect_image(int fd_t, int obj_t, unsigned size,
int (*collect)(void *obj, ProtobufCMessage *msg));
int collect_image_sh(int fd_t, int obj_t, unsigned size,
int (*collect)(void *obj, ProtobufCMessage *msg));
#endif /* PROTOBUF_H__ */