From: Aristeu Rozanski <aris@redhat.com> Date: Tue, 2 Sep 2008 15:37:09 -0400 Subject: [vt] add shutdown method Message-id: 20080902193709.GE10700@redhat.com O-Subject: [RHEL5.3 PATCH 3/3] vt: add shutdown() method v2 Bugzilla: 239604 RH-Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com> https://bugzilla.redhat.com/show_bug.cgi?id=239604 This patch adds the shutdown() method to the vt driver. Since its close() method don't do anything before the last close, everything was moved to the shutdown() method. All patches tested with the reproducer and with basic sanity tests with success. upstream: 413c68538dc90edb4b0dea1eddab793804120d93 diff --git a/drivers/char/vt.c b/drivers/char/vt.c index 8bce52f..6ff0a56 100644 --- a/drivers/char/vt.c +++ b/drivers/char/vt.c @@ -2499,6 +2499,13 @@ static int con_open(struct tty_struct *tty, struct file *filp) ret = vc_allocate(currcons); if (ret == 0) { struct vc_data *vc = vc_cons[currcons].d; + + /* Still being freed */ + if (vc->vc_tty) { + release_console_sem(); + return -ERESTARTSYS; + } + tty->driver_data = vc; vc->vc_tty = tty; @@ -2524,25 +2531,18 @@ static int con_open(struct tty_struct *tty, struct file *filp) */ static void con_close(struct tty_struct *tty, struct file *filp) { - mutex_lock(&tty_mutex); - acquire_console_sem(); - if (tty && tty->count == 1) { - struct vc_data *vc = tty->driver_data; + /* Nothing to do - we defer to shutdown */ +} - if (vc) - vc->vc_tty = NULL; - tty->driver_data = NULL; - release_console_sem(); - vcs_remove_devfs(tty); - mutex_unlock(&tty_mutex); - /* - * tty_mutex is released, but we still hold BKL, so there is - * still exclusion against init_dev() - */ - return; - } +static void con_shutdown(struct tty_struct *tty) +{ + struct vc_data *vc = tty->driver_data; + BUG_ON(vc == NULL); + acquire_console_sem(); + vc->vc_tty = NULL; + vcs_remove_devfs(tty); release_console_sem(); - mutex_unlock(&tty_mutex); + tty_shutdown(tty); } static void vc_init(struct vc_data *vc, unsigned int rows, @@ -2677,8 +2677,9 @@ int __init vty_init(void) console_driver->minor_start = 1; console_driver->type = TTY_DRIVER_TYPE_CONSOLE; console_driver->init_termios = tty_std_termios; - console_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS; + console_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_HAS_SHUTDOWN; tty_set_operations(console_driver, &con_ops); + console_driver->shutdown = con_shutdown; if (tty_register_driver(console_driver)) panic("Couldn't register console driver\n");