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

tty: Write unread pty buffers on post dump stage

Updated version attached.

>From 6c0e1522e01e01aa89861862fbdf039a0892b89b Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov@openvz.org>
Date: Tue, 12 Apr 2016 20:00:24 +0300
Subject: [PATCH 1/2] tty: Write unread pty buffers on post dump stage

When unread data present on peers we currently simply ignore it but
actually we can try to fetch it in non(that)destructive way.

For this sake at the end of dump procedure (because fetching
queued data may go wrong and we will have to write it back,
which is heavy, and we need all ttys under our hands)
we walk over all collected TTYs and link PTYs peers which
indices are matching. Note to not overload tty_dump_info we
reuse @list member for new @all_ptys list.

Once link established we literally read queued data and flush
it into new tty-data.img. If something go wrong at this moment,
we stop reading queued data but walk back over already queued
ones and write them back to restore former state. Same applies
if the dump has been requested to leave task alive.

On restore we link peers back and write queued data once
peer back to live.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 4497ac8e
......@@ -1746,7 +1746,7 @@ int cr_dump_tasks(pid_t pid)
if (ret)
goto err;
ret = tty_verify_active_pairs();
ret = tty_post_actions();
if (ret)
goto err;
......
......@@ -176,6 +176,7 @@ static struct collect_image_info *cinfos[] = {
&fanotify_mark_cinfo,
&tty_info_cinfo,
&tty_cinfo,
&tty_cdata,
&tunfile_cinfo,
&ext_file_cinfo,
&timerfd_cinfo,
......@@ -243,9 +244,6 @@ static int root_prepare_shared(void)
return -1;
}
if (tty_verify_active_pairs())
return -1;
for_each_pstree_item(pi) {
if (pi->pid.state == TASK_HELPER)
continue;
......
......@@ -81,6 +81,7 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
FD_ENTRY(BINFMT_MISC, "binfmt-misc-%d"),
FD_ENTRY(TTY_FILES, "tty"),
FD_ENTRY(TTY_INFO, "tty-info"),
FD_ENTRY_F(TTY_DATA, "tty-data", O_NOBUF),
FD_ENTRY(FILE_LOCKS, "filelocks"),
FD_ENTRY(RLIMIT, "rlimit-%d"),
FD_ENTRY_F(PAGES, "pages-%u", O_NOBUF),
......
......@@ -69,6 +69,7 @@ enum {
CR_FD_FIFO_DATA,
CR_FD_TTY_FILES,
CR_FD_TTY_INFO,
CR_FD_TTY_DATA,
CR_FD_REMAP_FPATH,
CR_FD_EVENTFD_FILE,
CR_FD_EVENTPOLL_FILE,
......
......@@ -76,6 +76,7 @@
#define NETNS_MAGIC 0x55933752 /* Dolgoprudny */
#define TTY_FILES_MAGIC 0x59433025 /* Pushkin */
#define TTY_INFO_MAGIC 0x59453036 /* Kolpino */
#define TTY_DATA_MAGIC 0x59413026 /* Pavlovsk */
#define FILE_LOCKS_MAGIC 0x54323616 /* Kaluga */
#define RLIMIT_MAGIC 0x57113925 /* Rostov */
#define FANOTIFY_FILE_MAGIC 0x55096122 /* Chelyabinsk */
......
......@@ -57,6 +57,7 @@ enum {
PB_USERNS,
PB_NETNS,
PB_BINFMT_MISC, /* 50 */
PB_TTY_DATA,
/* PB_AUTOGEN_STOP */
......
......@@ -22,13 +22,13 @@ static inline int is_tty(dev_t rdev, dev_t dev)
return get_tty_driver(rdev, dev) != NULL;
}
extern int tty_post_actions(void);
extern int dump_verify_tty_sids(void);
extern struct collect_image_info tty_info_cinfo;
extern struct collect_image_info tty_cinfo;
extern struct collect_image_info tty_cdata;
extern int prepare_shared_tty(void);
extern int tty_verify_active_pairs(void);
extern int tty_prep_fds(void);
extern void tty_fini_fds(void);
......
This diff is collapsed.
......@@ -34,6 +34,11 @@ enum TtyType {
SERIAL = 6;
}
message tty_data_entry {
required uint32 tty_id = 1;
required bytes data = 2;
}
message tty_info_entry {
required uint32 id = 1;
......
......@@ -370,6 +370,7 @@ handlers = {
'MNTS' : entry_handler(mnt_entry),
'TTY_FILES' : entry_handler(tty_file_entry),
'TTY_INFO' : entry_handler(tty_info_entry),
'TTY_DATA' : entry_handler(tty_data_entry),
'RLIMIT' : entry_handler(rlimit_entry),
'TUNFILE' : entry_handler(tunfile_entry),
'EXT_FILES' : entry_handler(ext_file_entry),
......
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