Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src - Strenghen the poll(2) fifo_inout test to ensure that once ...



details:   https://anonhg.NetBSD.org/src/rev/e41c2f2e54f7
branches:  trunk
changeset: 988196:e41c2f2e54f7
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Oct 02 17:32:55 2021 +0000

description:
- Strenghen the poll(2) fifo_inout test to ensure that once the reader
  has read enough that exactly PIPE_BUF space is available that the FIFO
  becomes writable again.
- When creating a FIFO, ensure that the receive low water mark is 1
  (a FIFO must be readable when at least 1 byte is available); this
  was already the case implicitly, but this makes it explicit.
- Similarly, set the send low water mark to PIPE_BUF to ensure that
  the pipe is writable when at least PIPE_BUF bytes of space are available
  in the send buffer.  Without this change, the strengthened test case
  above does not pass (the default send low water mark is larger than
  PIPE_BUF; see soreserve()).
- Make the same low water mark changes to the PIPE_SOCKETPAIR case.

diffstat:

 sys/kern/uipc_syscalls.c       |  19 +++++++++++++++++--
 sys/miscfs/fifofs/fifo_vnops.c |  21 +++++++++++++++++++--
 tests/lib/libc/sys/t_poll.c    |  11 ++++++++++-
 3 files changed, 46 insertions(+), 5 deletions(-)

diffs (107 lines):

diff -r 0ee6b4c4ae38 -r e41c2f2e54f7 sys/kern/uipc_syscalls.c
--- a/sys/kern/uipc_syscalls.c  Sat Oct 02 15:50:06 2021 +0000
+++ b/sys/kern/uipc_syscalls.c  Sat Oct 02 17:32:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_syscalls.c,v 1.200 2020/05/23 23:42:43 ad Exp $   */
+/*     $NetBSD: uipc_syscalls.c,v 1.201 2021/10/02 17:32:55 thorpej Exp $      */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.200 2020/05/23 23:42:43 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.201 2021/10/02 17:32:55 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pipe.h"
@@ -1319,6 +1319,21 @@
        wf->f_socket = wso;
        fildes[1] = fd;
        solock(wso);
+       /*
+        * Pipes must be readable when there is at least 1
+        * byte of data available in the receive buffer.
+        *
+        * Pipes must be writable when there is space for
+        * at least PIPE_BUF bytes in the send buffer.
+        * If we're increasing the low water mark for the
+        * send buffer, then mimick how soreserve() would
+        * have set the high water mark.
+        */
+       rso->so_rcv.sb_lowat = 1;
+       if (wso->so_snd.sb_lowat < PIPE_BUF) {
+               wso->so_snd.sb_hiwat = PIPE_BUF * 2;
+       }
+       wso->so_snd.sb_lowat = PIPE_BUF;
        error = unp_connect2(wso, rso);
        sounlock(wso);
        if (error != 0)
diff -r 0ee6b4c4ae38 -r e41c2f2e54f7 sys/miscfs/fifofs/fifo_vnops.c
--- a/sys/miscfs/fifofs/fifo_vnops.c    Sat Oct 02 15:50:06 2021 +0000
+++ b/sys/miscfs/fifofs/fifo_vnops.c    Sat Oct 02 17:32:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fifo_vnops.c,v 1.87 2021/10/02 02:07:41 thorpej Exp $  */
+/*     $NetBSD: fifo_vnops.c,v 1.88 2021/10/02 17:32:55 thorpej Exp $  */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.87 2021/10/02 02:07:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.88 2021/10/02 17:32:55 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -156,6 +156,23 @@
                        kmem_free(fip, sizeof(*fip));
                        return (error);
                }
+
+               /*
+                * FIFOs must be readable when there is at least 1
+                * byte of data available in the receive buffer.
+                *
+                * FIFOs must be writable when there is space for
+                * at least PIPE_BUF bytes in the send buffer.
+                * If we're increasing the low water mark for the
+                * send buffer, then mimick how soreserve() would
+                * have set the high water mark.
+                */
+               rso->so_rcv.sb_lowat = 1;
+               if (wso->so_snd.sb_lowat < PIPE_BUF) {
+                       wso->so_snd.sb_hiwat = PIPE_BUF * 2;
+               }
+               wso->so_snd.sb_lowat = PIPE_BUF;
+
                fip->fi_readers = 0;
                fip->fi_writers = 0;
                wso->so_state |= SS_CANTRCVMORE;
diff -r 0ee6b4c4ae38 -r e41c2f2e54f7 tests/lib/libc/sys/t_poll.c
--- a/tests/lib/libc/sys/t_poll.c       Sat Oct 02 15:50:06 2021 +0000
+++ b/tests/lib/libc/sys/t_poll.c       Sat Oct 02 17:32:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_poll.c,v 1.7 2021/10/02 15:50:06 thorpej Exp $       */
+/*     $NetBSD: t_poll.c,v 1.8 2021/10/02 17:32:55 thorpej Exp $       */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -330,6 +330,15 @@
        ATF_REQUIRE(pfd[1].revents == 0);
 
        /*
+        * Now read enough so that exactly pipe_buf space should
+        * be available.  The FIFO should be writable after that.
+        * N.B. we don't care if it's readable at this point.
+        */
+       ATF_REQUIRE(read(rfd, buf, pipe_buf - 1) == pipe_buf - 1);
+       ATF_REQUIRE(poll(pfd, 2, 0) >= 1);
+       ATF_REQUIRE(pfd[1].revents == (POLLOUT | POLLWRNORM));
+
+       /*
         * Now read all of the data out of the FIFO and ensure that
         * we get back to the initial state.
         */



Home | Main Index | Thread Index | Old Index