Commit 25abdf3a authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

tty: Rework tty_driver structure

 - rename @t to @type and use protobuf constants here instead
 - for special features use @subtype just like kernel does
 - get rid of TTY_TYPE_ constants, we don't need them
 - drop @flags, we don't need it anymore
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 7263054c
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "util-pie.h" #include "util-pie.h"
#include "protobuf/vma.pb-c.h" #include "protobuf/vma.pb-c.h"
#include "protobuf/tty.pb-c.h"
#define __head __used __section(.head.text) #define __head __used __section(.head.text)
......
...@@ -9,16 +9,6 @@ ...@@ -9,16 +9,6 @@
/* Kernel's limit */ /* Kernel's limit */
#define TERMIOS_NCC 19 #define TERMIOS_NCC 19
enum {
TTY_TYPE_UNKNOWN = 0,
TTY_TYPE_PTM = 1,
TTY_TYPE_PTS = 2,
TTY_TYPE_CONSOLE = 3,
TTY_TYPE_VT = 4,
TTY_TYPE_MAX
};
extern const struct fdtype_ops tty_dump_ops; extern const struct fdtype_ops tty_dump_ops;
struct tty_driver; struct tty_driver;
......
...@@ -436,8 +436,7 @@ static int parasite_dump_tty(struct parasite_tty_args *args) ...@@ -436,8 +436,7 @@ static int parasite_dump_tty(struct parasite_tty_args *args)
__tty_ioctl(TIOCGPGRP, args->pgrp); __tty_ioctl(TIOCGPGRP, args->pgrp);
__tty_ioctl(TIOCGEXCL, args->st_excl); __tty_ioctl(TIOCGEXCL, args->st_excl);
if (args->type == TTY_TYPE_PTM || if (args->type == TTY_TYPE__PTY) {
args->type == TTY_TYPE_PTS) {
__tty_ioctl(TIOCGPKT, args->st_pckt); __tty_ioctl(TIOCGPKT, args->st_pckt);
__tty_ioctl(TIOCGPTLCK, args->st_lock); __tty_ioctl(TIOCGPTLCK, args->st_lock);
} }
......
...@@ -132,18 +132,17 @@ static DECLARE_BITMAP(tty_bitmap, (MAX_TTYS << 1)); ...@@ -132,18 +132,17 @@ static DECLARE_BITMAP(tty_bitmap, (MAX_TTYS << 1));
static DECLARE_BITMAP(tty_active_pairs, (MAX_TTYS << 1)); static DECLARE_BITMAP(tty_active_pairs, (MAX_TTYS << 1));
struct tty_driver { struct tty_driver {
int t; short type;
short subtype;
char *name; char *name;
int index; int index;
int img_type;
unsigned int flags;
int (*fd_get_index)(int fd, const struct fd_parms *p); int (*fd_get_index)(int fd, const struct fd_parms *p);
int (*img_get_index)(struct tty_info *ti); int (*img_get_index)(struct tty_info *ti);
int (*open)(struct tty_info *ti); int (*open)(struct tty_info *ti);
}; };
#define TTY_PAIR 0x1 #define TTY_SUBTYPE_MASTER 0x0001
#define TTY_MASTER 0x2 #define TTY_SUBTYPE_SLAVE 0x0002
static int ptm_fd_get_index(int fd, const struct fd_parms *p) static int ptm_fd_get_index(int fd, const struct fd_parms *p)
{ {
...@@ -170,10 +169,9 @@ static int pty_get_index(struct tty_info *ti) ...@@ -170,10 +169,9 @@ static int pty_get_index(struct tty_info *ti)
static int pty_open_ptmx(struct tty_info *info); static int pty_open_ptmx(struct tty_info *info);
static struct tty_driver ptm_driver = { static struct tty_driver ptm_driver = {
.t = TTY_TYPE_PTM, .type = TTY_TYPE__PTY,
.flags = TTY_PAIR | TTY_MASTER, .subtype = TTY_SUBTYPE_MASTER,
.name = "ptmx", .name = "ptmx",
.img_type = TTY_TYPE__PTY,
.fd_get_index = ptm_fd_get_index, .fd_get_index = ptm_fd_get_index,
.img_get_index = pty_get_index, .img_get_index = pty_get_index,
.open = pty_open_ptmx, .open = pty_open_ptmx,
...@@ -182,19 +180,16 @@ static struct tty_driver ptm_driver = { ...@@ -182,19 +180,16 @@ static struct tty_driver ptm_driver = {
static int open_simple_tty(struct tty_info *info); static int open_simple_tty(struct tty_info *info);
static struct tty_driver console_driver = { static struct tty_driver console_driver = {
.t = TTY_TYPE_CONSOLE, .type = TTY_TYPE__CONSOLE,
.flags = TTY_MASTER, .subtype = TTY_SUBTYPE_SLAVE,
.name = "console", .name = "console",
.img_type = TTY_TYPE__CONSOLE,
.index = CONSOLE_INDEX, .index = CONSOLE_INDEX,
.open = open_simple_tty, .open = open_simple_tty,
}; };
static struct tty_driver vt_driver = { static struct tty_driver vt_driver = {
.t = TTY_TYPE_VT, .type = TTY_TYPE__VT,
.flags = 0,
.name = "vt", .name = "vt",
.img_type = TTY_TYPE__VT,
.index = VT_INDEX, .index = VT_INDEX,
.open = open_simple_tty, .open = open_simple_tty,
}; };
...@@ -220,10 +215,9 @@ static int pts_fd_get_index(int fd, const struct fd_parms *p) ...@@ -220,10 +215,9 @@ static int pts_fd_get_index(int fd, const struct fd_parms *p)
} }
static struct tty_driver pts_driver = { static struct tty_driver pts_driver = {
.t = TTY_TYPE_PTS, .type = TTY_TYPE__PTY,
.flags = TTY_PAIR, .subtype = TTY_SUBTYPE_SLAVE,
.name = "pts", .name = "pts",
.img_type = TTY_TYPE__PTY,
.fd_get_index = pts_fd_get_index, .fd_get_index = pts_fd_get_index,
.img_get_index = pty_get_index, .img_get_index = pty_get_index,
.open = pty_open_ptmx, .open = pty_open_ptmx,
...@@ -256,7 +250,7 @@ struct tty_driver *get_tty_driver(int major, int minor) ...@@ -256,7 +250,7 @@ struct tty_driver *get_tty_driver(int major, int minor)
static inline int is_pty(struct tty_driver *driver) static inline int is_pty(struct tty_driver *driver)
{ {
return driver->flags & TTY_PAIR; return driver->type == TTY_TYPE__PTY;
} }
/* /*
...@@ -304,7 +298,7 @@ int prepare_shared_tty(void) ...@@ -304,7 +298,7 @@ int prepare_shared_tty(void)
static int tty_gen_id(struct tty_driver *driver, int index) static int tty_gen_id(struct tty_driver *driver, int index)
{ {
return (index << 1) + (driver->t == TTY_TYPE_PTM); return (index << 1) + (driver->subtype == TTY_SUBTYPE_MASTER);
} }
static int tty_get_index(u32 id) static int tty_get_index(u32 id)
...@@ -408,7 +402,7 @@ static struct file_desc *pty_alloc_reg(struct tty_info *info, bool add) ...@@ -408,7 +402,7 @@ static struct file_desc *pty_alloc_reg(struct tty_info *info, bool add)
* the inverted path is /dev/pts/1, for inverted slaves it's simplier * the inverted path is /dev/pts/1, for inverted slaves it's simplier
* we just add 'ptmx' postfix. * we just add 'ptmx' postfix.
*/ */
static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int type) static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int subtype)
{ {
struct reg_file_info *new, *orig; struct reg_file_info *new, *orig;
struct file_desc *fake_desc; struct file_desc *fake_desc;
...@@ -426,8 +420,8 @@ static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int type) ...@@ -426,8 +420,8 @@ static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int type)
orig = container_of(info->reg_d, struct reg_file_info, d); orig = container_of(info->reg_d, struct reg_file_info, d);
new = container_of(fake_desc, struct reg_file_info, d); new = container_of(fake_desc, struct reg_file_info, d);
if ((type == TTY_TYPE_PTM && tty_is_master(info)) || if ((subtype == TTY_SUBTYPE_MASTER && tty_is_master(info)) ||
(type == TTY_TYPE_PTS && !tty_is_master(info))) { (subtype == TTY_SUBTYPE_SLAVE && !tty_is_master(info))) {
new->path = xstrdup(orig->path); new->path = xstrdup(orig->path);
new->rfe->name = &new->path[1]; new->rfe->name = &new->path[1];
} else { } else {
...@@ -439,7 +433,7 @@ static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int type) ...@@ -439,7 +433,7 @@ static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int type)
BUG_ON(!pos || !inverted_path); BUG_ON(!pos || !inverted_path);
memcpy(inverted_path, orig->rfe->name, slash_at + 1); memcpy(inverted_path, orig->rfe->name, slash_at + 1);
if (type == TTY_TYPE_PTM) if (subtype == TTY_SUBTYPE_MASTER)
strcat(inverted_path, "ptmx"); strcat(inverted_path, "ptmx");
else { else {
if (slash_at >= 3 && strncmp(&inverted_path[slash_at - 3], "pts", 3)) if (slash_at >= 3 && strncmp(&inverted_path[slash_at - 3], "pts", 3))
...@@ -457,8 +451,8 @@ static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int type) ...@@ -457,8 +451,8 @@ static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int type)
return new; return new;
} }
#define pty_alloc_fake_master(info) pty_alloc_fake_reg(info, TTY_TYPE_PTM) #define pty_alloc_fake_master(info) pty_alloc_fake_reg(info, TTY_SUBTYPE_MASTER)
#define pty_alloc_fake_slave(info) pty_alloc_fake_reg(info, TTY_TYPE_PTS) #define pty_alloc_fake_slave(info) pty_alloc_fake_reg(info, TTY_SUBTYPE_SLAVE)
static void pty_free_fake_reg(struct reg_file_info **r) static void pty_free_fake_reg(struct reg_file_info **r)
{ {
...@@ -627,11 +621,16 @@ err: ...@@ -627,11 +621,16 @@ err:
static bool tty_is_master(struct tty_info *info) static bool tty_is_master(struct tty_info *info)
{ {
if (info->driver->flags & TTY_MASTER) if (info->driver->subtype == TTY_SUBTYPE_MASTER)
return true; return true;
if (info->driver->t == TTY_TYPE_VT && !opts.shell_job) switch (info->driver->type) {
case TTY_TYPE__CONSOLE:
return true; return true;
case TTY_TYPE__VT:
if (!opts.shell_job)
return true;
}
return false; return false;
} }
...@@ -1414,7 +1413,7 @@ static int dump_tty_info(int lfd, u32 id, const struct fd_parms *p, struct tty_d ...@@ -1414,7 +1413,7 @@ static int dump_tty_info(int lfd, u32 id, const struct fd_parms *p, struct tty_d
BUILD_BUG_ON(sizeof(termios.c_cc) != sizeof(void *)); BUILD_BUG_ON(sizeof(termios.c_cc) != sizeof(void *));
BUILD_BUG_ON((sizeof(termios.c_cc) * TERMIOS_NCC) < sizeof(t.c_cc)); BUILD_BUG_ON((sizeof(termios.c_cc) * TERMIOS_NCC) < sizeof(t.c_cc));
pti = parasite_dump_tty(p->ctl, p->fd, driver->t); pti = parasite_dump_tty(p->ctl, p->fd, driver->type);
if (!pti) if (!pti)
return -1; return -1;
...@@ -1438,7 +1437,7 @@ static int dump_tty_info(int lfd, u32 id, const struct fd_parms *p, struct tty_d ...@@ -1438,7 +1437,7 @@ static int dump_tty_info(int lfd, u32 id, const struct fd_parms *p, struct tty_d
info.exclusive = pti->st_excl; info.exclusive = pti->st_excl;
info.packet_mode = pti->st_pckt; info.packet_mode = pti->st_pckt;
info.type = driver->img_type; info.type = driver->type;
if (info.type == TTY_TYPE__PTY) { if (info.type == TTY_TYPE__PTY) {
info.pty = &pty; info.pty = &pty;
pty.index = index; pty.index = index;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment