* [LTP] [PATCH v2] pty04: Retry reads when short
@ 2020-05-13 9:04 Richard Palethorpe
2020-05-13 9:31 ` Petr Vorel
0 siblings, 1 reply; 2+ messages in thread
From: Richard Palethorpe @ 2020-05-13 9:04 UTC (permalink / raw)
To: ltp
Even though reads are blocking and packets are flipped into the netdevice
buffer whole, it seems read may return before a full packet is read into user
land. Retrying read should prevent timeouts and read failures on some
machines.
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
Reported-by: Jan Stancek <jstancek@redhat.com>
Cc: Petr Vorel <pvorel@suse.cz>
---
V2:
* Remove while style fix
* Use plain while loop instead of exp backoff
testcases/kernel/pty/pty04.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/pty/pty04.c b/testcases/kernel/pty/pty04.c
index 4e16707e3..8f17aba55 100644
--- a/testcases/kernel/pty/pty04.c
+++ b/testcases/kernel/pty/pty04.c
@@ -288,6 +288,24 @@ static void check_data(const struct ldisc_info *ldisc,
tst_res(TINFO, "Will continue test without data checking");
}
+static void try_read(int fd, char *data, ssize_t size)
+{
+ ssize_t ret, n = 0;
+ int retry = mtu;
+
+ while (retry--) {
+ ret = read(fd, data, size - n);
+
+ if (ret < 0)
+ break;
+
+ if ((n += ret) >= size)
+ return;
+ }
+
+ tst_brk(TBROK | TERRNO, "Read %zd of %zd bytes", n, size);
+}
+
static void read_netdev(const struct ldisc_info *ldisc)
{
int rlen, plen = 0;
@@ -305,11 +323,11 @@ static void read_netdev(const struct ldisc_info *ldisc)
tst_res(TINFO, "Reading from socket %d", sk);
- SAFE_READ(1, sk, data, plen);
+ try_read(sk, data, plen);
check_data(ldisc, data, plen);
tst_res(TPASS, "Read netdev 1");
- SAFE_READ(1, sk, data, plen);
+ try_read(sk, data, plen);
check_data(ldisc, data, plen);
tst_res(TPASS, "Read netdev 2");
@@ -319,6 +337,7 @@ static void read_netdev(const struct ldisc_info *ldisc)
tst_res(TPASS, "Reading data from netdev interrupted by hangup");
+ close(sk);
tst_free_all();
}
@@ -357,6 +376,7 @@ static void cleanup(void)
{
ioctl(pts, TIOCVHANGUP);
ioctl(ptmx, TIOCVHANGUP);
+ close(sk);
tst_reap_children();
}
--
2.26.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [LTP] [PATCH v2] pty04: Retry reads when short
2020-05-13 9:04 [LTP] [PATCH v2] pty04: Retry reads when short Richard Palethorpe
@ 2020-05-13 9:31 ` Petr Vorel
0 siblings, 0 replies; 2+ messages in thread
From: Petr Vorel @ 2020-05-13 9:31 UTC (permalink / raw)
To: ltp
Hi Richard,
> Even though reads are blocking and packets are flipped into the netdevice
> buffer whole, it seems read may return before a full packet is read into user
> land. Retrying read should prevent timeouts and read failures on some
> machines.
I'm still able to block the test after some loops:
pty04.c:328: PASS: Read netdev 1
(using 5.7.0-rc4 from openSUSE Tumbleweed).
Kind regards,
Petr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-05-13 9:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13 9:04 [LTP] [PATCH v2] pty04: Retry reads when short Richard Palethorpe
2020-05-13 9:31 ` Petr Vorel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.