[Devel] [PATCH RHEL7 COMMIT] ve/vtty: Register devices in sysfs
Konstantin Khorenko
khorenko at virtuozzo.com
Wed Dec 2 07:30:41 PST 2015
The commit is pushed to "branch-rh7-3.10.0-229.7.2.vz7.9.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rebase
------>
commit 0644d0fb4d20c8c0af9e8b31ab4034216407afbe
Author: Cyrill Gorcunov <gorcunov at odin.com>
Date: Wed Dec 2 19:30:41 2015 +0400
ve/vtty: Register devices in sysfs
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>
Reviewed-by: Vladimir Davydov <vdavydov at virtuozzo.com>
This fix is going to be a temporary one, later, in the scope of
https://jira.sw.ru/browse/PSBM-41804
we'll do the following:
- revert all our tty device-namespace code leaving with native code instead
- setup proper rules (such as sys/devices/virtual/tty[0-12] rx
in default CT permissions)
- drop legacy pty support (in kernel config)
---
drivers/tty/pty.c | 1 -
drivers/tty/tty_io.c | 29 +++++++++++++++++++++++++++--
include/linux/ve.h | 1 +
3 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index b312635..93ab642 100644
--- a/drivers/tty/pty.c
+++ b/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 {
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 8ce0a5f..fc80ccb 100644
--- a/drivers/tty/tty_io.c
+++ b/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 *ve)
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;
diff --git a/include/linux/ve.h b/include/linux/ve.h
index 2554337..87450c1 100644
--- a/include/linux/ve.h
+++ b/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