[Devel] [PATCH RHEL8 COMMIT] ve/tty: vtty fix noctty flag in tty_open after port from vz7

Konstantin Khorenko khorenko at virtuozzo.com
Mon Jul 26 20:15:28 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 0a75a843999035e3521410ca2b02dd379655c184
Author: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
Date:   Mon Jul 26 20:15:27 2021 +0300

    ve/tty: vtty fix noctty flag in tty_open after port from vz7
    
    During vtty port tty_open has been reworked to also include scenarios
    where /dev/console /dev/tty are being opened from insided of CT (!= VE0).
    tty_open is implemented on top of some other helper functions:
    - tty_open_by_driver
    - tty_lookup_driver
    In vz7 these helpers were arranged differently. tty_lookup_driver had
    noctty as one of its argument. And in newer kernels it has been reworked.
    Now tty_open deduces noctty value itself. 'noctty' is a crucial variable
    that tells if the current terminal should be made controlling or not.
    For virtual inside-CT terminal the logic of determining this value was
    inside of tty_lookup_driver, but now there is no pointer to noctty inside
    of it and so the same logic should be put in the consolidated place.
    
    Fixes: eb2220696477f117d742f89e91e1766f4a1a29fe
    
    https://jira.sw.ru/browse/PSBM-132299
    
    Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
---
 drivers/tty/tty_io.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 5c4e68758c97..f0e8d10462a0 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1963,22 +1963,21 @@ EXPORT_SYMBOL_GPL(tty_kopen);
  *	  - concurrent tty removal from driver table
  */
 static struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,
-					     struct file *filp)
+					     struct file *filp, int *index)
 {
 	struct tty_struct *tty;
 	struct tty_driver *driver = NULL;
-	int index = -1;
 	int retval;
 
 	mutex_lock(&tty_mutex);
-	driver = tty_lookup_driver(device, filp, &index);
+	driver = tty_lookup_driver(device, filp, index);
 	if (IS_ERR(driver)) {
 		mutex_unlock(&tty_mutex);
 		return ERR_CAST(driver);
 	}
 
 	/* check whether we're reopening an existing tty */
-	tty = tty_driver_lookup_tty(driver, filp, index);
+	tty = tty_driver_lookup_tty(driver, filp, *index);
 	if (IS_ERR(tty)) {
 		mutex_unlock(&tty_mutex);
 		goto out;
@@ -2006,7 +2005,7 @@ static struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,
 			tty = ERR_PTR(retval);
 		}
 	} else { /* Returns with the tty_lock held for now */
-		tty = tty_init_dev(driver, index);
+		tty = tty_init_dev(driver, *index);
 		mutex_unlock(&tty_mutex);
 	}
 out:
@@ -2044,6 +2043,7 @@ static int tty_open(struct inode *inode, struct file *filp)
 	int noctty, retval;
 	dev_t device = inode->i_rdev;
 	unsigned saved_flags = filp->f_flags;
+	int index = -1;
 
 	nonseekable_open(inode, filp);
 
@@ -2054,7 +2054,7 @@ static int tty_open(struct inode *inode, struct file *filp)
 
 	tty = tty_open_current_tty(device, filp);
 	if (!tty)
-		tty = tty_open_by_driver(device, inode, filp);
+		tty = tty_open_by_driver(device, inode, filp, &index);
 
 	if (IS_ERR(tty)) {
 		tty_free_file(filp);
@@ -2102,6 +2102,14 @@ static int tty_open(struct inode *inode, struct file *filp)
 		 device == MKDEV(TTYAUX_MAJOR, 1) ||
 		 (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
 		  tty->driver->subtype == PTY_TYPE_MASTER);
+#ifdef CONFIG_VE
+	if (!noctty) {
+		if (vtty_driver(device, &index)) {
+			if (MINOR(device) == 0)
+				noctty = 1;
+		}
+	}
+#endif
 	if (!noctty)
 		tty_open_proc_set_tty(filp, tty);
 	tty_unlock(tty);


More information about the Devel mailing list