[CRIU] [PATCH 3/5] tty: Verify info once

Pavel Emelyanov xemul at virtuozzo.com
Wed Jul 19 14:20:17 MSK 2017


Same here -- now when we collect info and driver at the same
place late enough we can verify info once, then attach to
files.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/tty.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/criu/tty.c b/criu/tty.c
index 222309b..abeb483 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -737,12 +737,12 @@ err:
 	return ret ? -1 : 0;
 }
 
-static bool tty_is_master(struct tty_info *info)
+static bool __tty_is_master(struct tty_driver *driver)
 {
-	if (info->driver->subtype == TTY_SUBTYPE_MASTER)
+	if (driver->subtype == TTY_SUBTYPE_MASTER)
 		return true;
 
-	switch (info->driver->type) {
+	switch (driver->type) {
 	case TTY_TYPE__CONSOLE:
 	case TTY_TYPE__CTTY:
 		return true;
@@ -758,6 +758,11 @@ static bool tty_is_master(struct tty_info *info)
 	return false;
 }
 
+static bool tty_is_master(struct tty_info *info)
+{
+	return __tty_is_master(info->driver);
+}
+
 static bool tty_is_hung(struct tty_info *info)
 {
 	return info->tie->termios == NULL;
@@ -1466,10 +1471,10 @@ static int verify_termios(u32 id, TermiosEntry *e)
 	return 0;
 }
 
-#define term_opts_missing_cmp(p, op)		\
-	(!(p)->tie->termios		op	\
-	 !(p)->tie->termios_locked	op	\
-	 !(p)->tie->winsize)
+#define term_opts_missing_cmp(tie, op)		\
+	(!(tie)->termios		op	\
+	 !(tie)->termios_locked		op	\
+	 !(tie)->winsize)
 
 #define term_opts_missing_any(p)		\
 	term_opts_missing_cmp(p, ||)
@@ -1477,33 +1482,28 @@ static int verify_termios(u32 id, TermiosEntry *e)
 #define term_opts_missing_all(p)		\
 	term_opts_missing_cmp(p, &&)
 
-static int verify_info(struct tty_info *info)
+static int verify_info(TtyInfoEntry *tie, struct tty_driver *driver)
 {
-	if (!info->driver) {
-		pr_err("Unknown driver master peer %#x\n", info->tfe->id);
-		return -1;
-	}
-
 	/*
 	 * Master peer must have all parameters present,
 	 * while slave peer must have either all parameters present
 	 * or don't have them at all.
 	 */
-	if (term_opts_missing_any(info)) {
-		if (tty_is_master(info)) {
-			pr_err("Corrupted master peer %#x\n", info->tfe->id);
+	if (term_opts_missing_any(tie)) {
+		if (__tty_is_master(driver)) {
+			pr_err("Corrupted master peer %#x\n", tie->id);
 			return -1;
-		} else if (!term_opts_missing_all(info)) {
-			pr_err("Corrupted slave peer %#x\n", info->tfe->id);
+		} else if (!term_opts_missing_all(tie)) {
+			pr_err("Corrupted slave peer %#x\n", tie->id);
 			return -1;
 		}
 	}
 
-	if (verify_termios(info->tfe->id, info->tie->termios_locked) ||
-	    verify_termios(info->tfe->id, info->tie->termios))
+	if (verify_termios(tie->id, tie->termios_locked) ||
+	    verify_termios(tie->id, tie->termios))
 		return -1;
 
-	if (info->tie->termios && info->tfe->tty_info_id > (MAX_TTYS << 1))
+	if (tie->termios && tie->id > (MAX_TTYS << 1))
 		return -1;
 
 	return 0;
@@ -1548,6 +1548,9 @@ static int collect_one_tty_info_entry(void *obj, ProtobufCMessage *msg, struct c
 		return -1;
 	}
 
+	if (verify_info(tie, driver))
+		return -1;
+
 	list_for_each_entry_safe(info, n, &collected_ttys, list) {
 		if (info->tfe->tty_info_id != tie->id)
 			continue;
@@ -1604,9 +1607,6 @@ static int tty_info_setup(struct tty_info *info)
 	info->tty_data = NULL;
 	info->link = NULL;
 
-	if (verify_info(info))
-		return -1;
-
 	/*
 	 * The image might have no reg file record in old CRIU, so
 	 * lets don't fail for a while. After a couple of releases
-- 
2.1.4



More information about the CRIU mailing list