[Devel] [RFC rh7 v7] ve/tty: vt -- Implement per VE support for console and terminals

Vladimir Davydov vdavydov at parallels.com
Tue Sep 1 04:59:06 PDT 2015


On Tue, Sep 01, 2015 at 12:50:16PM +0300, Cyrill Gorcunov wrote:
> Previously in commit 8674c044330fad1458bd59b02f9037fb97e8b7af stubs for
> virtual terminals have been added, they support writes from kernel side
> which simply drops into the void.
> 
> In the patch the code has been moved from kernel/ve/console.c
> to drivers/tty/pty.c to reuse a couple of pty helpers.
> 
> Now we support up to MAX_NR_VTTY_CONSOLES virtual consoles inside container.
> For /dev/console we reserve the first virtual terminal.
> 
> Some details on the driver itself:
> 
>  - The drivers carries per-VE tty instances in @vtty_idr map, once
>    VE tries to open a terminal we allocate tty map internally and
>    keep it intact until VE destructed, this allow us to not bind
>    into device namespaces (ie not rely on tty_class);
> 
>  - Unlike buffered IO to unix98 driver once internal port buffer
>    get full we don't block write operations if there is no reader
>    assigned yet but zap them. This is done intentionally to behave
>    closely to native consoles;
> 
>  - The kernel choose which VE request terminal using get_exec_env
>    helper, but for opening master peer from the nodes ve0 it uses
>    vtty_set_context/vtty_get_context/vtty_drop_context to notify
>    tty layer which @vtty_idr to use instead of get_exec_env.
> 
> https://jira.sw.ru/browse/PSBM-34533
> https://jira.sw.ru/browse/PSBM-34532
> https://jira.sw.ru/browse/PSBM-34107
> https://jira.sw.ru/browse/PSBM-32686
> https://jira.sw.ru/browse/PSBM-32685
> 
> v2:
>  - Rename terminals from vtz to vtty
>  - Merge code into /drivers/tty/pty.c to reuse some of
>    pty functionality
>  - Get rid of two array of indices, use one for master
>    peers and fetch slaves via @link
>  - Drop TTY_VT_OPEN and wait() on it
>  - Add vtty_open_slave helper
> 
> v3:
>  - Reverse the scheme, the peers opened from inside of
>    container are the slave peers as it were in pcs6
>  - Add vtty_set_context/vtty_drop_context/vtty_get_context
>    to open needed tty from ve0 context
>  - In vtty_open_master reuse existing vtty_lookup, vtty_open
>    helpers
>  - In ve_vtty_fini zap active tty tracking, such ttys are
>    sitting here because the node has been opening the console
>    and didn't release file descriptors yet with tty associated.
>    The kernel will clean them up once they are closed but the
>    tacking map pointer should be zapped to escape nil dereference
> 
> v4:
>  - Use lockdep_assert_held in vtty @map operations to make sure
>    we're under @tty_mutex
>  - vtty_install now requests for port memory earlier for vtty_install_peer
>    simplification
>  - Drop tty_vhangup call from vtty_close, as been found it doesn't
>    bring any benefit
>  - Drop TTY_BUFFER_PAGE and fix typo in vtty_write_room
>  - Rework tty counting to be the same as in pcs6: drivers
>    became TTY_DRIVER_TYPE_PTY and @count adjusted accordingly
> 
> v5:
>  - Treat zero as unused flag in vtty_get_context
>  - vtty_printk helpers are dropped off
>  - Don't test for exit state in lookup procedure: the kernel
>    will do that on its own when slave is opened from inside
>    of a container and for ioctl call we do such test explicitly
>  - When pair is to open from the node and the existing peer is
>    exiting we're allocating new pair early removin old one from
>    per-VE ttys map, this is done to speedup open from the node
>  - vtty_match is no longer exported into the rest of the tty code
>  - When peer is to be closed we use own per-VE spinlock to read
>    and modify own and peer counters, this is because the general
>    tty->close routine is called without tty-mutex held and only
>    one peer is locked thus such modifications are unsafe if do
>    them locklessly. In current vanilla kernel there is no need
>    for such lock if Unix ptys are used because master peers are
>    always opened first and always get closed in constrast to the
>    our driver where any peer end may be opened sole
> 
> v6:
>  - Reworked tty counting: no need for extra reference but make
>    it close to how native Unix98 ptys are working: once master
>    is opened it takes new TTY_PINNED flags and when it getting
>    closed with active slave peer we defer tty destruction until
>    both ends are spare.
> 
> v7:
>  - Move MAX_NR_VTTY_CONSOLES from header into pty.c
>  - Drop vtty_zap_tty_map
>  - Assign @driver_data in vtty_map_set
>  - Rename vtty_map_del to vtty_map_clear
>  - Merge map cleaning into vtty_map_free
>  - Rename @current_veid to @vtty_context_veid
>  - Rename TTY_PINNED to TTY_PINNED_BY_OTHER
>  - Assing TTY_PINNED_BY_OTHER early in pair creation
>  - Wake both ends of a peer in vtty_close
> 
> FIXME: Once this is applied need to drop kernel/ve/coinsole.c
> from the source tree, dropping it immediately ruines my queue
> series, because there are other patches not yet merged but
> changing kernel/ve/console.c code.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
> CC: Vladimir Davydov <vdavydov at virtuozzo.com>
> CC: Konstantin Khorenko <khorenko at virtuozzo.com>

Reviewed-by: Vladimir Davydov <vdavydov at parallels.com>



More information about the Devel mailing list