The commit is pushed to "branch-rh7-3.10.0-229.7.2.vz7.8.x-ovz" and will appear 
at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-229.7.2.vz7.8.8
------>
commit 77f7c920ddb6426dfb580fff5146da73c6f7f7d3
Author: Cyrill Gorcunov <gorcu...@virtuozzo.com>
Date:   Thu Oct 15 20:04:49 2015 +0400

    ve/vtty: Make indices to match pcs6 scheme
    
    In pcs6 vttys are mapped into internal kernel representation in
    nonobvious way. The /dev/console represent [maj:5,min:1], in
    turn /dev/tty[0-...] are defined as [maj:4,min:0...], where
    minor is bijective to symbol postfix of the tty. Internally
    in the pcs6 kernel any open of /dev/ttyX has been mapping
    minor into vtty index as
    
     |  if (minor > 0)
     |          index = minor - 1
     |  else
     |          index = 0
    
    which actually shifts indices and make /dev/tty0 as
    an alias to /dev/console inside container.
    
    Same time vzctl tool passes console number argument
    in a decremented way, iow when one is typing
    
        vzctl console $ctid 1
    
    here is 1 is a tty number, the kernel sees is as 0,
    opening containers /dev/console.
    
    When one types "vzctl console $ctid 2" (which implies
    to open container's /dev/tty2) the vzctl passes index 1
    and the kernel opens /dev/tty2 because of the if/else index
    mapping as show above.
    
    Lets implement same indices mapping in pcs7 for backward
    compatibility (in pcs7 there is a per-VE vtty_map_t structure
    which reserve up to MAX_NR_VTTY_CONSOLES ttys to track
    and it is simply an array addressed by tty index).
    
    Same time lets fix a few nits: disable setup of controlling
    terminal on /dev/console only, since all ttys can have
    controlling sign; make sure we're having @tty_fops for
    such terminals.
    
    https://jira.sw.ru/browse/PSBM-40088
    
    Signed-off-by: Cyrill Gorcunov <gorcu...@virtuozzo.com>
    Reviewed-by: Vladimir Davydov <vdavy...@virtuozzo.com>
    
    CC: Konstantin Khorenko <khore...@virtuozzo.com>
    CC: Igor Sukhih <i...@parallels.com>
    
     drivers/tty/pty.c    |    7 +++++--
     drivers/tty/tty_io.c |   12 ++++++++++--
     2 files changed, 15 insertions(+), 4 deletions(-)
---
 drivers/tty/pty.c    |  7 +++++--
 drivers/tty/tty_io.c | 12 ++++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index b74ddca..0ab36f9 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -1240,8 +1240,11 @@ struct tty_driver *vtty_console_driver(int *index)
 struct tty_driver *vtty_driver(dev_t dev, int *index)
 {
        if (MAJOR(dev) == TTY_MAJOR &&
-           MINOR(dev) < MAX_NR_VTTY_CONSOLES) {
-               *index = MINOR(dev);
+           MINOR(dev) <= MAX_NR_VTTY_CONSOLES) {
+               if (MINOR(dev))
+                       *index = MINOR(dev) - 1;
+               else
+                       *index = 0;
                return vttys_driver;
        }
        return NULL;
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 8fc8334..8ce0a5f 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1941,7 +1941,8 @@ static struct tty_driver *tty_lookup_driver(dev_t device, 
struct file *filp,
        if (!ve_is_super(ve)) {
                driver = vtty_driver(device, index);
                if (driver) {
-                       *noctty = 1;
+                       if (MINOR(device) == 0)
+                               *noctty = 1;
                        return tty_driver_kref_get(driver);
                }
        }
@@ -1960,8 +1961,15 @@ static struct tty_driver *tty_lookup_driver(dev_t 
device, struct file *filp,
        case MKDEV(TTYAUX_MAJOR, 1): {
                struct tty_driver *console_driver = console_device(index);
 #ifdef CONFIG_VE
-               if (!ve_is_super(ve))
+               if (!ve_is_super(ve)) {
                        console_driver = vtty_console_driver(index);
+                       /*
+                        * Reset fops, sometimes there might be
+                        * console_fops picked from inode->i_cdev
+                        * in chrdev_open()
+                        */
+                       filp->f_op = &tty_fops;
+               }
 #endif
                if (console_driver) {
                        driver = tty_driver_kref_get(console_driver);
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to