Commit 01adc807 authored by Peter Hurley's avatar Peter Hurley Committed by Greg Kroah-Hartman

tty: Move packet mode flow control notifications to pty driver

When a master pty is set to packet mode, flow control changes to
the slave pty cause notifications to the master pty via reads and
polls. However, these tests are occurring for all ttys, not
just ptys.

Implement flow control packet mode notifications in the pty driver.
Only the slave side implements the flow control handlers since
packet mode is asymmetric; the master pty receives notifications
for slave-side changes, but not vice versa.
Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f9e053dc
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/devpts_fs.h> #include <linux/devpts_fs.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/poll.h>
#ifdef CONFIG_UNIX98_PTYS #ifdef CONFIG_UNIX98_PTYS
...@@ -312,6 +313,42 @@ static int pty_resize(struct tty_struct *tty, struct winsize *ws) ...@@ -312,6 +313,42 @@ static int pty_resize(struct tty_struct *tty, struct winsize *ws)
return 0; return 0;
} }
/**
* pty_start - start() handler
* pty_stop - stop() handler
* @tty: tty being flow-controlled
*
* Propagates the TIOCPKT status to the master pty.
*
* NB: only the master pty can be in packet mode so only the slave
* needs start()/stop() handlers
*/
static void pty_start(struct tty_struct *tty)
{
unsigned long flags;
spin_lock_irqsave(&tty->ctrl_lock, flags);
if (tty->link && tty->link->packet) {
tty->ctrl_status &= ~TIOCPKT_STOP;
tty->ctrl_status |= TIOCPKT_START;
wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
}
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
}
static void pty_stop(struct tty_struct *tty)
{
unsigned long flags;
spin_lock_irqsave(&tty->ctrl_lock, flags);
if (tty->link && tty->link->packet) {
tty->ctrl_status &= ~TIOCPKT_START;
tty->ctrl_status |= TIOCPKT_STOP;
wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
}
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
}
/** /**
* pty_common_install - set up the pty pair * pty_common_install - set up the pty pair
* @driver: the pty driver * @driver: the pty driver
...@@ -471,6 +508,8 @@ static const struct tty_operations slave_pty_ops_bsd = { ...@@ -471,6 +508,8 @@ static const struct tty_operations slave_pty_ops_bsd = {
.set_termios = pty_set_termios, .set_termios = pty_set_termios,
.cleanup = pty_cleanup, .cleanup = pty_cleanup,
.resize = pty_resize, .resize = pty_resize,
.start = pty_start,
.stop = pty_stop,
.remove = pty_remove .remove = pty_remove
}; };
...@@ -646,6 +685,8 @@ static const struct tty_operations pty_unix98_ops = { ...@@ -646,6 +685,8 @@ static const struct tty_operations pty_unix98_ops = {
.chars_in_buffer = pty_chars_in_buffer, .chars_in_buffer = pty_chars_in_buffer,
.unthrottle = pty_unthrottle, .unthrottle = pty_unthrottle,
.set_termios = pty_set_termios, .set_termios = pty_set_termios,
.start = pty_start,
.stop = pty_stop,
.shutdown = pty_unix98_shutdown, .shutdown = pty_unix98_shutdown,
.cleanup = pty_cleanup, .cleanup = pty_cleanup,
}; };
......
...@@ -908,8 +908,7 @@ void no_tty(void) ...@@ -908,8 +908,7 @@ void no_tty(void)
* stop_tty - propagate flow control * stop_tty - propagate flow control
* @tty: tty to stop * @tty: tty to stop
* *
* Perform flow control to the driver. For PTY/TTY pairs we * Perform flow control to the driver. May be called
* must also propagate the TIOCKPKT status. May be called
* on an already stopped device and will not re-call the driver * on an already stopped device and will not re-call the driver
* method. * method.
* *
...@@ -919,24 +918,14 @@ void no_tty(void) ...@@ -919,24 +918,14 @@ void no_tty(void)
* but not always. * but not always.
* *
* Locking: * Locking:
* ctrl_lock
* flow_lock * flow_lock
*/ */
void __stop_tty(struct tty_struct *tty) void __stop_tty(struct tty_struct *tty)
{ {
unsigned long flags;
if (tty->stopped) if (tty->stopped)
return; return;
tty->stopped = 1; tty->stopped = 1;
spin_lock_irqsave(&tty->ctrl_lock, flags);
if (tty->link && tty->link->packet) {
tty->ctrl_status &= ~TIOCPKT_START;
tty->ctrl_status |= TIOCPKT_STOP;
wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
}
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
if (tty->ops->stop) if (tty->ops->stop)
(tty->ops->stop)(tty); (tty->ops->stop)(tty);
} }
...@@ -955,33 +944,21 @@ EXPORT_SYMBOL(stop_tty); ...@@ -955,33 +944,21 @@ EXPORT_SYMBOL(stop_tty);
* start_tty - propagate flow control * start_tty - propagate flow control
* @tty: tty to start * @tty: tty to start
* *
* Start a tty that has been stopped if at all possible. Perform * Start a tty that has been stopped if at all possible. If this
* any necessary wakeups and propagate the TIOCPKT status. If this * tty was previous stopped and is now being started, the driver
* is the tty was previous stopped and is being started then the * start method is invoked and the line discipline woken.
* driver start method is invoked and the line discipline woken.
* *
* Locking: * Locking:
* ctrl_lock
* flow_lock * flow_lock
*/ */
void __start_tty(struct tty_struct *tty) void __start_tty(struct tty_struct *tty)
{ {
unsigned long flags;
if (!tty->stopped || tty->flow_stopped) if (!tty->stopped || tty->flow_stopped)
return; return;
tty->stopped = 0; tty->stopped = 0;
spin_lock_irqsave(&tty->ctrl_lock, flags);
if (tty->link && tty->link->packet) {
tty->ctrl_status &= ~TIOCPKT_STOP;
tty->ctrl_status |= TIOCPKT_START;
wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
}
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
if (tty->ops->start) if (tty->ops->start)
(tty->ops->start)(tty); (tty->ops->start)(tty);
/* If we have a running line discipline it may need kicking */
tty_wakeup(tty); tty_wakeup(tty);
} }
......
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