public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Hurley <peter@hurleysoftware.com>
To: Markus Trippelsdorf <markus@trippelsdorf.de>
Cc: linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.cz>, Mikael Pettersson <mikpe@it.uu.se>,
	David Howells <dhowells@redhat.com>,
	Orion Poplawski <orion@cora.nwra.com>,
	Peter Hurley <peter@hurleysoftware.com>
Subject: [PATCH] tty: Debug EIO from write()
Date: Thu, 13 Jun 2013 11:25:52 -0400	[thread overview]
Message-ID: <1371137152-25916-1-git-send-email-peter@hurleysoftware.com> (raw)
In-Reply-To: <20130613145133.GC519@x4>


Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
---
 drivers/tty/pty.c    | 22 +++++++++++++++++++---
 drivers/tty/tty_io.c | 51 ++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 9c2f1bc..2ce2bb2 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -25,6 +25,16 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 
+#define TTY_DEBUG_EIO 1
+
+#ifdef TTY_DEBUG_EIO
+#define tty_debug_eio(tty, f, args...) ({				       \
+	char __b[64];							       \
+	printk(KERN_DEBUG "%s: %s: " f, __func__, tty_name(tty, __b), ##args); \
+})
+#else
+#define tty_debug_eio(tty, f, args...)
+#endif
 
 #ifdef CONFIG_UNIX98_PTYS
 static struct tty_driver *ptm_driver;
@@ -246,12 +256,18 @@ static int pty_open(struct tty_struct *tty, struct file *filp)
 	set_bit(TTY_IO_ERROR, &tty->flags);
 
 	retval = -EIO;
-	if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
+	if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
+		tty_debug_eio(tty, "other pty closed (%#lx)\n", tty->flags);
 		goto out;
-	if (test_bit(TTY_PTY_LOCK, &tty->link->flags))
+	}
+	if (test_bit(TTY_PTY_LOCK, &tty->link->flags)) {
+		tty_debug_eio(tty, "ptm still locked\n");
 		goto out;
-	if (tty->driver->subtype == PTY_TYPE_SLAVE && tty->link->count != 1)
+	}
+	if (tty->driver->subtype == PTY_TYPE_SLAVE && tty->link->count != 1) {
+		tty_debug_eio(tty, "ptm open count (%d)\n", tty->link->count);
 		goto out;
+	}
 
 	clear_bit(TTY_IO_ERROR, &tty->flags);
 	clear_bit(TTY_OTHER_CLOSED, &tty->link->flags);
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 62e942d..e71c61f 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -105,11 +105,21 @@
 #include <linux/kmod.h>
 #include <linux/nsproxy.h>
 
-#undef TTY_DEBUG_HANGUP
+#define TTY_DEBUG_HANGUP 1
+#define TTY_DEBUG_EIO 1
 
 #define TTY_PARANOIA_CHECK 1
 #define CHECK_TTY_COUNT 1
 
+#ifdef TTY_DEBUG_EIO
+#define tty_debug_eio(tty, f, args...) ({				       \
+	char __b[64];							       \
+	printk(KERN_DEBUG "%s: %s: " f, __func__, tty_name(tty, __b), ##args); \
+})
+#else
+#define tty_debug_eio(tty, f, args...)
+#endif
+
 struct ktermios tty_std_termios = {	/* for the benefit of tty drivers  */
 	.c_iflag = ICRNL | IXON,
 	.c_oflag = OPOST | ONLCR,
@@ -424,6 +434,7 @@ int tty_check_change(struct tty_struct *tty)
 	if (is_ignored(SIGTTOU))
 		goto out;
 	if (is_current_pgrp_orphaned()) {
+		tty_debug_eio(tty, "pgrp orphaned?? (%#lx)\n", tty->flags);
 		ret = -EIO;
 		goto out;
 	}
@@ -448,6 +459,9 @@ static ssize_t hung_up_tty_read(struct file *file, char __user *buf,
 static ssize_t hung_up_tty_write(struct file *file, const char __user *buf,
 				 size_t count, loff_t *ppos)
 {
+	struct tty_struct *tty = file_tty(file);
+
+	tty_debug_eio(tty, "%#lx\n", tty ? tty->flags : -1L);
 	return -EIO;
 }
 
@@ -1020,16 +1034,22 @@ static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
 
 	if (tty_paranoia_check(tty, inode, "tty_read"))
 		return -EIO;
-	if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags)))
+	if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) {
+		tty_debug_eio(tty, "%#lx\n", tty ? tty->flags : -1L);
 		return -EIO;
+	}
 
 	/* We want to wait for the line discipline to sort out in this
 	   situation */
 	ld = tty_ldisc_ref_wait(tty);
-	if (ld->ops->read)
+	if (ld->ops->read) {
 		i = (ld->ops->read)(tty, file, buf, count);
-	else
+		if (i == -EIO)
+			tty_debug_eio(tty, "ldisc error (%#lx)\n", tty->flags);
+	} else {
+		tty_debug_eio(tty, "no ldisc read method???\n");
 		i = -EIO;
+	}
 	tty_ldisc_deref(ld);
 
 	if (i > 0)
@@ -1197,18 +1217,31 @@ static ssize_t tty_write(struct file *file, const char __user *buf,
 
 	if (tty_paranoia_check(tty, file_inode(file), "tty_write"))
 		return -EIO;
-	if (!tty || !tty->ops->write ||
-		(test_bit(TTY_IO_ERROR, &tty->flags)))
-			return -EIO;
+	if (!tty || !tty->ops->write || (test_bit(TTY_IO_ERROR, &tty->flags))) {
+		if (tty && !tty->ops->write)
+			tty_debug_eio(tty, "no driver write method???\n");
+		else
+			tty_debug_eio(tty, "%#lx\n", tty ? tty->flags : -1L);
+		return -EIO;
+	}
 	/* Short term debug to catch buggy drivers */
 	if (tty->ops->write_room == NULL)
 		printk(KERN_ERR "tty driver %s lacks a write_room method.\n",
 			tty->driver->name);
 	ld = tty_ldisc_ref_wait(tty);
-	if (!ld->ops->write)
+	if (!ld->ops->write) {
+		tty_debug_eio(tty, "no ldisc write method???\n");
 		ret = -EIO;
-	else
+	} else {
 		ret = do_tty_write(ld->ops->write, tty, file, buf, count);
+		if (ret == -EIO) {
+			if (tty_hung_up_p(file))
+				tty_debug_eio(tty, "hung up\n");
+			else
+				tty_debug_eio(tty, "ldisc error: flags=%#lx count=%d other=%d\n",
+					      tty->flags, tty->count, tty->link ? tty->link->count : -1);
+		}
+	}
 	tty_ldisc_deref(ld);
 	return ret;
 }
-- 
1.8.1.2


  reply	other threads:[~2013-06-13 15:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-06 11:54 Strange intermittent EIO error when writing to stdout since v3.8.0 Markus Trippelsdorf
2013-06-06 14:18 ` Peter Hurley
2013-06-06 14:37   ` Markus Trippelsdorf
2013-06-07 15:39     ` Peter Hurley
2013-06-07 16:07       ` Markus Trippelsdorf
2013-06-07 18:22       ` Mikael Pettersson
2013-06-13 10:39         ` Markus Trippelsdorf
2013-06-13 14:16           ` Peter Hurley
2013-06-13 14:51             ` Markus Trippelsdorf
2013-06-13 15:25               ` Peter Hurley [this message]
2013-06-13 16:16                 ` [PATCH] tty: Debug EIO from write() Markus Trippelsdorf
2013-06-13 16:29                   ` Peter Hurley
2013-06-13 19:56                     ` [PATCH] tty: Fix transient pty write() EIO Peter Hurley
2013-06-16 17:31                       ` Mikael Pettersson
2013-06-07 19:56       ` Strange intermittent EIO error when writing to stdout since v3.8.0 David Howells
2013-06-11 22:14       ` Orion Poplawski
2013-06-13 10:38         ` Markus Trippelsdorf
2013-06-06 14:41 ` Mikael Pettersson
2013-06-06 17:31 ` David Howells
2013-06-06 18:41   ` Markus Trippelsdorf
2013-06-08 18:56 ` Rob Landley

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=1371137152-25916-1-git-send-email-peter@hurleysoftware.com \
    --to=peter@hurleysoftware.com \
    --cc=dhowells@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markus@trippelsdorf.de \
    --cc=mikpe@it.uu.se \
    --cc=orion@cora.nwra.com \
    /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