[Devel] [PATCH rh7] vtty: Register devices in sysfs
Cyrill Gorcunov
gorcunov at odin.com
Mon Nov 30 06:14:53 PST 2015
In pcs6 we explicitly create /sys/devices/virtual/ttyX
in init_ve_vtty, but in pcs7 the code has been reworked:
now all device matching is done via common tty_class
and dev_match_devt helper.
https://jira.sw.ru/browse/PSBM-41628
Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
CC: Vladimir Davydov <vdavydov at virtuozzo.com>
CC: Konstantin Khorenko <khorenko at virtuozzo.com>
CC: Igor Sukhih <igor at parallels.com>
---
drivers/tty/pty.c | 1 -
drivers/tty/tty_io.c | 29 +++++++++++++++++++++++++++--
include/linux/ve.h | 1 +
3 files changed, 28 insertions(+), 3 deletions(-)
Index: linux-pcs7.git/drivers/tty/pty.c
===================================================================
--- linux-pcs7.git.orig/drivers/tty/pty.c
+++ linux-pcs7.git/drivers/tty/pty.c
@@ -950,7 +950,6 @@ static DEFINE_IDR(vtty_idr);
static struct file_operations vtty_fops;
-#define MAX_NR_VTTY_CONSOLES (12)
#define vtty_match_index(idx) ((idx) >= 0 && (idx) < MAX_NR_VTTY_CONSOLES)
typedef struct {
Index: linux-pcs7.git/drivers/tty/tty_io.c
===================================================================
--- linux-pcs7.git.orig/drivers/tty/tty_io.c
+++ linux-pcs7.git/drivers/tty/tty_io.c
@@ -3653,17 +3653,25 @@ void console_sysfs_notify(void)
void ve_tty_console_fini(struct ve_struct *ve)
{
struct device *consdev = ve->consdev;
+ int i;
ve->consdev = NULL;
device_remove_file(consdev, &dev_attr_active);
device_destroy_namespace(tty_class, MKDEV(TTYAUX_MAJOR, 1), ve);
device_destroy_namespace(tty_class, MKDEV(TTYAUX_MAJOR, 0), ve);
+
+ if (!ve_is_super(ve)) {
+ for (i = 0; i <= MAX_NR_VTTY_CONSOLES; i++) {
+ device_destroy_namespace(tty_class,
+ MKDEV(TTY_MAJOR, i), ve);
+ }
+ }
}
int ve_tty_console_init(struct ve_struct *ve)
{
- struct device *dev;
- int err;
+ struct device *dev, *d;
+ int err, i;
dev = device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), ve, "tty");
if (IS_ERR(dev))
@@ -3679,6 +3687,23 @@ int ve_tty_console_init(struct ve_struct
if (err)
goto err_consfile;
+ if (!ve_is_super(ve)) {
+ for (i = 0; i <= MAX_NR_VTTY_CONSOLES; i++) {
+ d = device_create(tty_class, NULL, MKDEV(TTY_MAJOR, i),
+ ve, "tty%d", i);
+ if (IS_ERR(d)) {
+ err = PTR_ERR(dev);
+
+ while (i-- > 0)
+ device_destroy_namespace(tty_class,
+ MKDEV(TTY_MAJOR, i),
+ ve);
+ device_remove_file(dev, &dev_attr_active);
+ goto err_consfile;
+ }
+ }
+ }
+
ve->consdev = dev;
return 0;
Index: linux-pcs7.git/include/linux/ve.h
===================================================================
--- linux-pcs7.git.orig/include/linux/ve.h
+++ linux-pcs7.git/include/linux/ve.h
@@ -220,6 +220,7 @@ extern bool current_user_ns_initial(void
struct user_namespace *ve_init_user_ns(void);
#ifdef CONFIG_TTY
+#define MAX_NR_VTTY_CONSOLES (12)
extern struct tty_driver *vtty_driver(dev_t dev, int *index);
extern struct tty_driver *vtty_console_driver(int *index);
extern int vtty_open_master(envid_t veid, int idx);
More information about the Devel
mailing list