public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: torvalds@osdl.org, linux-serial@vger.kernel.org
Subject: [PATCH 20/75] pty: simplify resize
Date: Fri, 02 Jan 2009 13:43:17 +0000	[thread overview]
Message-ID: <20090102134309.13472.38770.stgit@localhost.localdomain> (raw)
In-Reply-To: <20090102133822.13472.53912.stgit@localhost.localdomain>

From: Alan Cox <alan@redhat.com>

We have special case logic for resizing pty/tty pairs. We also have a per
driver resize method so for the pty case we should use it.

Signed-off-by: Alan Cox <alan@redhat.com>
---

 drivers/char/hvc_console.c |    2 +-
 drivers/char/pty.c         |   54 +++++++++++++++++++++++++++++++++++++++++++-
 drivers/char/tty_io.c      |   31 +++++++++----------------
 drivers/char/vt.c          |   14 +++++------
 include/linux/tty.h        |    3 +-
 include/linux/tty_driver.h |    6 ++---
 6 files changed, 74 insertions(+), 36 deletions(-)


diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index 0587b66..5a8a4c2 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -529,7 +529,7 @@ static void hvc_set_winsz(struct work_struct *work)
 	tty = tty_kref_get(hp->tty);
 	spin_unlock_irqrestore(&hp->lock, hvc_flags);
 
-	tty_do_resize(tty, tty, &ws);
+	tty_do_resize(tty, &ws);
 	tty_kref_put(tty);
 }
 
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 6d45827..b5daaaa 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -230,6 +230,55 @@ static void pty_set_termios(struct tty_struct *tty,
 	tty->termios->c_cflag |= (CS8 | CREAD);
 }
 
+/**
+ *	pty_do_resize		-	resize event
+ *	@tty: tty being resized
+ *	@real_tty: real tty (not the same as tty if using a pty/tty pair)
+ *	@rows: rows (character)
+ *	@cols: cols (character)
+ *
+ *	Update the termios variables and send the neccessary signals to
+ *	peform a terminal resize correctly
+ */
+
+int pty_resize(struct tty_struct *tty,  struct winsize *ws)
+{
+	struct pid *pgrp, *rpgrp;
+	unsigned long flags;
+	struct tty_struct *pty = tty->link;
+
+	/* For a PTY we need to lock the tty side */
+	mutex_lock(&tty->termios_mutex);
+	if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
+		goto done;
+
+	/* Get the PID values and reference them so we can
+	   avoid holding the tty ctrl lock while sending signals.
+	   We need to lock these individually however. */
+
+	spin_lock_irqsave(&tty->ctrl_lock, flags);
+	pgrp = get_pid(tty->pgrp);
+	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+
+	spin_lock_irqsave(&pty->ctrl_lock, flags);
+	rpgrp = get_pid(pty->pgrp);
+	spin_unlock_irqrestore(&pty->ctrl_lock, flags);
+
+	if (pgrp)
+		kill_pgrp(pgrp, SIGWINCH, 1);
+	if (rpgrp != pgrp && rpgrp)
+		kill_pgrp(rpgrp, SIGWINCH, 1);
+
+	put_pid(pgrp);
+	put_pid(rpgrp);
+
+	tty->winsize = *ws;
+	pty->winsize = *ws;	/* Never used so will go away soon */
+done:
+	mutex_unlock(&tty->termios_mutex);
+	return 0;
+}
+
 static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
 {
 	struct tty_struct *o_tty;
@@ -290,6 +339,7 @@ static const struct tty_operations pty_ops = {
 	.chars_in_buffer = pty_chars_in_buffer,
 	.unthrottle = pty_unthrottle,
 	.set_termios = pty_set_termios,
+	.resize = pty_resize
 };
 
 /* Traditional BSD devices */
@@ -319,6 +369,7 @@ static const struct tty_operations pty_ops_bsd = {
 	.unthrottle = pty_unthrottle,
 	.set_termios = pty_set_termios,
 	.ioctl = pty_bsd_ioctl,
+	.resize = pty_resize
 };
 
 static void __init legacy_pty_init(void)
@@ -561,7 +612,8 @@ static const struct tty_operations ptm_unix98_ops = {
 	.unthrottle = pty_unthrottle,
 	.set_termios = pty_set_termios,
 	.ioctl = pty_unix98_ioctl,
-	.shutdown = pty_unix98_shutdown
+	.shutdown = pty_unix98_shutdown,
+	.resize = pty_resize
 };
 
 static const struct tty_operations pty_unix98_ops = {
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 2a15af6..d33e5ab 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -2048,7 +2048,6 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg)
 /**
  *	tty_do_resize		-	resize event
  *	@tty: tty being resized
- *	@real_tty: real tty (not the same as tty if using a pty/tty pair)
  *	@rows: rows (character)
  *	@cols: cols (character)
  *
@@ -2056,41 +2055,34 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg)
  *	peform a terminal resize correctly
  */
 
-int tty_do_resize(struct tty_struct *tty, struct tty_struct *real_tty,
-					struct winsize *ws)
+int tty_do_resize(struct tty_struct *tty, struct winsize *ws)
 {
-	struct pid *pgrp, *rpgrp;
+	struct pid *pgrp;
 	unsigned long flags;
 
-	/* For a PTY we need to lock the tty side */
-	mutex_lock(&real_tty->termios_mutex);
-	if (!memcmp(ws, &real_tty->winsize, sizeof(*ws)))
+	/* Lock the tty */
+	mutex_lock(&tty->termios_mutex);
+	if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
 		goto done;
 	/* Get the PID values and reference them so we can
 	   avoid holding the tty ctrl lock while sending signals */
 	spin_lock_irqsave(&tty->ctrl_lock, flags);
 	pgrp = get_pid(tty->pgrp);
-	rpgrp = get_pid(real_tty->pgrp);
 	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
 
 	if (pgrp)
 		kill_pgrp(pgrp, SIGWINCH, 1);
-	if (rpgrp != pgrp && rpgrp)
-		kill_pgrp(rpgrp, SIGWINCH, 1);
-
 	put_pid(pgrp);
-	put_pid(rpgrp);
 
 	tty->winsize = *ws;
-	real_tty->winsize = *ws;
 done:
-	mutex_unlock(&real_tty->termios_mutex);
+	mutex_unlock(&tty->termios_mutex);
 	return 0;
 }
 
 /**
  *	tiocswinsz		-	implement window size set ioctl
- *	@tty; tty
+ *	@tty; tty side of tty
  *	@arg: user buffer for result
  *
  *	Copies the user idea of the window size to the kernel. Traditionally
@@ -2103,17 +2095,16 @@ done:
  *	then calls into the default method.
  */
 
-static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
-	struct winsize __user *arg)
+static int tiocswinsz(struct tty_struct *tty, struct winsize __user *arg)
 {
 	struct winsize tmp_ws;
 	if (copy_from_user(&tmp_ws, arg, sizeof(*arg)))
 		return -EFAULT;
 
 	if (tty->ops->resize)
-		return tty->ops->resize(tty, real_tty, &tmp_ws);
+		return tty->ops->resize(tty, &tmp_ws);
 	else
-		return tty_do_resize(tty, real_tty, &tmp_ws);
+		return tty_do_resize(tty, &tmp_ws);
 }
 
 /**
@@ -2538,7 +2529,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	case TIOCGWINSZ:
 		return tiocgwinsz(real_tty, p);
 	case TIOCSWINSZ:
-		return tiocswinsz(tty, real_tty, p);
+		return tiocswinsz(real_tty, p);
 	case TIOCCONS:
 		return real_tty != tty ? -EINVAL : tioccons(file);
 	case FIONBIO:
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 639e126..8001421 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -819,8 +819,8 @@ static inline int resize_screen(struct vc_data *vc, int width, int height,
  *	ctrl_lock of the tty IFF a tty is passed.
  */
 
-static int vc_do_resize(struct tty_struct *tty, struct tty_struct *real_tty,
-		struct vc_data *vc, unsigned int cols, unsigned int lines)
+static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
+				unsigned int cols, unsigned int lines)
 {
 	unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0;
 	unsigned int old_cols, old_rows, old_row_size, old_screen_size;
@@ -932,7 +932,7 @@ static int vc_do_resize(struct tty_struct *tty, struct tty_struct *real_tty,
 		ws.ws_row = vc->vc_rows;
 		ws.ws_col = vc->vc_cols;
 		ws.ws_ypixel = vc->vc_scan_lines;
-		tty_do_resize(tty, real_tty, &ws);
+		tty_do_resize(tty, &ws);
 	}
 
 	if (CON_IS_VISIBLE(vc))
@@ -954,13 +954,12 @@ static int vc_do_resize(struct tty_struct *tty, struct tty_struct *real_tty,
 
 int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows)
 {
-	return vc_do_resize(vc->vc_tty, vc->vc_tty, vc, cols, rows);
+	return vc_do_resize(vc->vc_tty, vc, cols, rows);
 }
 
 /**
  *	vt_resize		-	resize a VT
  *	@tty: tty to resize
- *	@real_tty: tty if a pty/tty pair
  *	@ws: winsize attributes
  *
  *	Resize a virtual terminal. This is called by the tty layer as we
@@ -971,14 +970,13 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows)
  *	termios_mutex and the tty ctrl_lock in that order.
  */
 
-int vt_resize(struct tty_struct *tty, struct tty_struct *real_tty,
-	struct winsize *ws)
+int vt_resize(struct tty_struct *tty, struct winsize *ws)
 {
 	struct vc_data *vc = tty->driver_data;
 	int ret;
 
 	acquire_console_sem();
-	ret = vc_do_resize(tty, real_tty, vc, ws->ws_col, ws->ws_row);
+	ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row);
 	release_console_sem();
 	return ret;
 }
diff --git a/include/linux/tty.h b/include/linux/tty.h
index dfc77de..f881697 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -360,8 +360,7 @@ extern int tty_write_room(struct tty_struct *tty);
 extern void tty_driver_flush_buffer(struct tty_struct *tty);
 extern void tty_throttle(struct tty_struct *tty);
 extern void tty_unthrottle(struct tty_struct *tty);
-extern int tty_do_resize(struct tty_struct *tty, struct tty_struct *real_tty,
-						struct winsize *ws);
+extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws);
 extern void tty_shutdown(struct tty_struct *tty);
 extern void tty_free_termios(struct tty_struct *tty);
 extern int is_current_pgrp_orphaned(void);
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index 78416b9..08e0883 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -196,8 +196,7 @@
  *	Optional: If not provided then the write method is called under
  *	the atomic write lock to keep it serialized with the ldisc.
  *
- * int (*resize)(struct tty_struct *tty, struct tty_struct *real_tty,
- *				unsigned int rows, unsigned int cols);
+ * int (*resize)(struct tty_struct *tty, struct winsize *ws)
  *
  *	Called when a termios request is issued which changes the
  *	requested terminal geometry.
@@ -258,8 +257,7 @@ struct tty_operations {
 	int (*tiocmget)(struct tty_struct *tty, struct file *file);
 	int (*tiocmset)(struct tty_struct *tty, struct file *file,
 			unsigned int set, unsigned int clear);
-	int (*resize)(struct tty_struct *tty, struct tty_struct *real_tty,
-				struct winsize *ws);
+	int (*resize)(struct tty_struct *tty, struct winsize *ws);
 	int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
 #ifdef CONFIG_CONSOLE_POLL
 	int (*poll_init)(struct tty_driver *driver, int line, char *options);


  parent reply	other threads:[~2009-01-02 13:43 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-02 13:40 [PATCH 00/75] TTY updates for 2.6.29-rc Alan Cox
2009-01-02 13:40 ` [PATCH 01/75] Blackfin Serial Driver: updates kgdb over Blackfin serial driver with kgdb framework Alan Cox
2009-01-02 13:40 ` [PATCH 02/75] Blackfin Serial Driver: fix bug - SIR driver stop receiving randomly Alan Cox
2009-01-02 13:40 ` [PATCH 03/75] Blackfin Serial Driver: Clean serial console and early prink code Alan Cox
2009-01-02 13:40 ` [PATCH 04/75] Blackfin Serial Driver: Fix bug - BF527-EZKIT unable to receive large files over UART in DMA mode Alan Cox
2009-01-02 13:40 ` [PATCH 05/75] Blackfin Serial Driver: Remove BI status for known_good_char Alan Cox
2009-01-02 13:40 ` [PATCH 06/75] n_tty: Fix loss of echoed characters and remove bkl from n_tty Alan Cox
2009-01-02 13:41 ` [PATCH 07/75] n_tty: clean up coding style Alan Cox
2009-01-02 13:41 ` [PATCH 08/75] Remove devpts_root global Alan Cox
2009-01-02 13:41 ` [PATCH 09/75] Per-mount allocated_ptys Alan Cox
2009-01-02 19:47   ` Michał Mirosław
2009-01-02 13:41 ` [PATCH 10/75] Per-mount 'config' object Alan Cox
2009-01-02 13:41 ` [PATCH 11/75] Extract option parsing to new function Alan Cox
2009-01-02 13:41 ` [PATCH 12/75] Add DEVPTS_MULTIPLE_INSTANCES config token Alan Cox
2009-01-02 13:42 ` [PATCH 13/75] Define mknod_ptmx() Alan Cox
2009-01-02 13:42 ` [PATCH 14/75] Define get_init_pts_sb() Alan Cox
2009-01-02 13:42 ` [PATCH 15/75] Enable multiple instances of devpts Alan Cox
2009-01-02 13:42 ` [PATCH 16/75] Document usage of multiple-instances " Alan Cox
2009-01-02 13:42 ` [PATCH 17/75] devpts: Coding style clean up Alan Cox
2009-01-02 13:42 ` [PATCH 18/75] sierra: Fix formatting Alan Cox
2009-01-02 13:43 ` [PATCH 19/75] tty: Fix sparse static warning for tty_driver_lookup_tty Alan Cox
2009-01-02 13:43 ` Alan Cox [this message]
2009-01-02 13:43 ` [PATCH 21/75] n_tty: Fix handling of control characters and continuations Alan Cox
2009-01-02 13:43 ` [PATCH 22/75] n_tty: Fix hanfling of buffer full corner cases Alan Cox
2009-01-02 13:43 ` [PATCH 23/75] n_tty: Output bells immediately on a full buffer Alan Cox
2009-01-02 13:44 ` [PATCH 24/75] tty: Fix close races in USB serial Alan Cox
2009-01-02 13:44 ` [PATCH 25/75] devpts: fix unused function warning Alan Cox
2009-01-02 13:44 ` [PATCH 26/75] Convert the oxsemi tornado special cases to use the quirk interface and not Alan Cox
2009-01-02 13:44 ` [PATCH 27/75] And here's a patch (to be applied on top of the last) which prevents Alan Cox
2009-01-02 13:44 ` [PATCH 28/75] Add device function for USB serial console Alan Cox
2009-01-02 13:44 ` [PATCH 29/75] CRED: Wrap task credential accesses in the devpts filesystem Alan Cox
2009-01-02 13:44 ` [PATCH 30/75] tty: Fix PPP hang under load Alan Cox
2009-01-02 13:45 ` [PATCH 31/75] tty_port: Add a port level carrier detect operation Alan Cox
2009-01-02 13:45 ` [PATCH 32/75] rio: Kill off ckmalloc Alan Cox
2009-01-02 13:45 ` [PATCH 33/75] tty: Pull the dtr raise into tty port Alan Cox
2009-01-02 13:45 ` [PATCH 34/75] isicom: redo locking to use tty port locks Alan Cox
2009-01-02 13:45 ` [PATCH 35/75] tty: relock generic_serial Alan Cox
2009-01-02 13:45 ` [PATCH 36/75] tty: rocketport uses different port flags to everyone else Alan Cox
2009-01-02 13:45 ` [PATCH 37/75] tty: relock riscom8 using port locks Alan Cox
2009-01-02 13:45 ` [PATCH 38/75] tty: relock the mxser driver Alan Cox
2009-01-02 13:46 ` [PATCH 39/75] tty: Introduce a tty_port generic block_til_ready Alan Cox
2009-01-02 13:46 ` [PATCH 40/75] tty: Rework istallion to use the tty port changes Alan Cox
2009-01-02 13:46 ` [PATCH 41/75] tty: rework stallion to use the tty_port bits Alan Cox
2009-01-02 13:46 ` [PATCH 42/75] tty: ESP has been broken for locking etc forver Alan Cox
2009-01-02 13:46 ` [PATCH 43/75] tty: tty port zero baud open Alan Cox
2009-01-02 13:46 ` [PATCH 44/75] tty: Introduce some close helpers for ports Alan Cox
2009-01-02 13:46 ` [PATCH 45/75] serial: set correct baud_base for Oxford Semiconductor Ltd EXSYS EX-41092 Dual 16950 Serial adapter Alan Cox
2009-01-02 13:47 ` [PATCH 46/75] tty: USB tty devices can block in tcdrain when unplugged Alan Cox
2009-01-02 13:47 ` [PATCH 47/75] tty: N_TTY SIGIO only works for read Alan Cox
2009-01-02 13:47 ` [PATCH 48/75] tty: PTYs set TTY_DO_WRITE_WAKEUP when they don't need to Alan Cox
2009-01-02 13:47 ` [PATCH 49/75] tty: Remove some pointless casts Alan Cox
2009-01-02 13:47 ` [PATCH 50/75] tty: kref nozomi Alan Cox
2009-01-02 13:47 ` [PATCH 51/75] hso: net driver using tty without locking Alan Cox
2009-01-02 13:47 ` [PATCH 52/75] tty: Fix the HSO termios handling a bit Alan Cox
2009-01-02 13:47 ` [PATCH 53/75] tty: Modem functions for the HSO driver Alan Cox
2009-01-02 13:47 ` [PATCH 54/75] tty: relock epca Alan Cox
2009-01-02 13:48 ` [PATCH 55/75] tty: refcount the epca driver Alan Cox
2009-01-02 13:48 ` [PATCH 56/75] tty: Make epca use the port helpers Alan Cox
2009-01-02 13:48 ` [PATCH 57/75] tty: Redo the rocket driver locking Alan Cox
2009-01-02 13:48 ` [PATCH 58/75] tty: make rocketport use standard port->flags Alan Cox
2009-01-02 13:48 ` [PATCH 59/75] tty: kref the rocket driver Alan Cox
2009-01-02 13:48 ` [PATCH 60/75] tty: use port methods for " Alan Cox
2009-01-02 13:48 ` [PATCH 61/75] synclink_cs: Convert to tty_port Alan Cox
2009-01-02 13:48 ` [PATCH 62/75] tty: Drop the lock_kernel in the private ioctl hook Alan Cox
2009-01-02 13:49 ` [PATCH 63/75] serial: RS485 ioctl structure uses __u32 include linux/types.h Alan Cox
2009-01-02 13:49 ` [PATCH 64/75] __FUNCTION__ is gcc-specific, use __func__ Alan Cox
2009-01-02 13:49 ` [PATCH 65/75] tty: We want the port object to be persistent Alan Cox
2009-01-02 13:49 ` [PATCH 66/75] fix for tty-serial-move-port Alan Cox
2009-01-02 13:49 ` [PATCH 67/75] 8250: Don't clobber spinlocks Alan Cox
2009-01-02 13:49 ` [PATCH 68/75] 8250: Serial driver changes to support future Cavium OCTEON serial patches Alan Cox
2009-01-02 13:49 ` [PATCH 69/75] Serial: Allow port type to be specified when calling serial8250_register_port Alan Cox
2009-01-02 13:50 ` [PATCH 70/75] Serial: UART driver changes for Cavium OCTEON Alan Cox
2009-01-02 13:50 ` [PATCH 71/75] drivers/char/cyclades.c: cy_pci_probe: fix error path Alan Cox
2009-01-02 13:50 ` [PATCH 72/75] tty: Fix an ircomm warning and note another bug Alan Cox
2009-01-05 17:42   ` Wolfram Sang
2009-01-05 18:01     ` Alan Cox
2009-01-02 13:50 ` [PATCH 73/75] hso modem detect fix patch against Alan Cox'es tty tree Alan Cox
2009-01-02 13:50 ` [PATCH 74/75] hso maintainers update patch Alan Cox
2009-01-02 13:50 ` [PATCH 75/75] serial_8250: support for Sealevel Systems Model 7803 COMM+8 Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090102134309.13472.38770.stgit@localhost.localdomain \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=linux-serial@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox