[Devel] [PATCH RHEL8 COMMIT] ve/vtty: Don't free console mapping until no clients left

Konstantin Khorenko khorenko at virtuozzo.com
Mon Jul 26 20:15:29 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-305.3.1.vz8.7.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-305.3.1.el8
------>
commit 3533bab414b6bb47e874bf3029a7667a1e38a72d
Author: Cyrill Gorcunov <gorcunov at virtuozzo.com>
Date:   Mon Jul 26 20:15:28 2021 +0300

    ve/vtty: Don't free console mapping until no clients left
    
    Currently on container's stop we free vtty mapping in a force way
    so that if there is active console hooked from the node it become
    unusable since then. It was easier to work with when we've been
    reworking virtual console code.
    
    Now lets make console fully functional as it was in pcs6:
    when opened it must survive container start/stop cycle
    and checkpoint/restore as well.
    
    For this sake we:
    
     - drop ve_hook code, it no longer needed
     - free console @map on final close of the last tty opened
    
    https://jira.sw.ru/browse/PSBM-39463
    
    Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
    
    Reviewed-by: Vladimir Davydov <vdavydov at virtuozzo.com>
    
    CC: Konstantin Khorenko <khorenko at virtuozzo.com>
    CC: Igor Sukhih <igor at virtuozzo.com>
    CC: Pavel Emelyanov <xemul at virtuozzo.com>
    
    https://jira.sw.ru/browse/PSBM-132299
    
    (cherry-picked from 00e43265ddf5044daa41db1f6d6d2c889f7be452)
    Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
---
 drivers/tty/pty.c | 49 ++++++++++++++-----------------------------------
 1 file changed, 14 insertions(+), 35 deletions(-)

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 2f99183cd561..19cbab7529ba 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -664,6 +664,13 @@ static void vtty_map_set(vtty_map_t *map, struct tty_struct *tty)
 	map->vttys[tty->index] = tty;
 }
 
+static void vtty_map_free(vtty_map_t *map)
+{
+	lockdep_assert_held(&tty_mutex);
+	idr_remove(&vtty_idr, map->veid);
+	kfree(map);
+}
+
 static void vtty_map_clear(struct tty_struct *tty)
 {
 	vtty_map_t *map = tty->driver_data;
@@ -671,28 +678,19 @@ static void vtty_map_clear(struct tty_struct *tty)
 	lockdep_assert_held(&tty_mutex);
 	if (map) {
 		struct tty_struct *p = map->vttys[tty->index];
+		int i;
 
 		WARN_ON(p != (tty->driver == vttys_driver ? tty : tty->link));
 		map->vttys[tty->index] = NULL;
 		tty->driver_data = tty->link->driver_data = NULL;
-	}
-}
-
-static void vtty_map_free(vtty_map_t *map)
-{
-	int i;
-
-	lockdep_assert_held(&tty_mutex);
 
-	for (i = 0; i < MAX_NR_VTTY_CONSOLES; i++) {
-		struct tty_struct *tty = map->vttys[i];
-		if (!tty)
-			continue;
-		tty->driver_data = tty->link->driver_data = NULL;
+		for (i = 0; i < MAX_NR_VTTY_CONSOLES; i++) {
+			if (map->vttys[i])
+				break;
+		}
+		if (i >= MAX_NR_VTTY_CONSOLES)
+			vtty_map_free(map);
 	}
-
-	idr_remove(&vtty_idr, map->veid);
-	kfree(map);
 }
 
 static vtty_map_t *vtty_map_alloc(envid_t veid)
@@ -972,24 +970,6 @@ void vtty_release(struct tty_struct *tty, struct tty_struct *o_tty,
 		*o_tty_closing = 0;
 }
 
-static void ve_vtty_fini(void *data)
-{
-	struct ve_struct *ve = data;
-	vtty_map_t *map;
-
-	mutex_lock(&tty_mutex);
-	map = vtty_map_lookup(ve->veid);
-	if (map)
-		vtty_map_free(map);
-	mutex_unlock(&tty_mutex);
-}
-
-static struct ve_hook vtty_hook = {
-	.fini           = ve_vtty_fini,
-	.priority       = HOOK_PRIO_DEFAULT,
-	.owner          = THIS_MODULE,
-};
-
 static int __init vtty_init(void)
 {
 #define VTTY_DRIVER_ALLOC_FLAGS			\
@@ -1042,7 +1022,6 @@ static int __init vtty_init(void)
 	if (tty_register_driver(vttys_driver))
 		panic(pr_fmt("Can't register slave vtty driver\n"));
 
-	ve_hook_register(VE_SS_CHAIN, &vtty_hook);
 	tty_default_fops(&vtty_fops);
 	return 0;
 }


More information about the Devel mailing list