diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-10-21 20:57:09 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-10-21 20:57:09 +0000 |
commit | f98cee89b8397af6b85864313d610bc98a124988 (patch) | |
tree | 7a2742b339ec39ebb0d3c9f8fed52a723b83460e | |
parent | b6022135dfdcbee7f0697274a23e7ab05b76ddaf (diff) |
Backout poll changes; the first mount gets an error for some reason.
-rw-r--r-- | usr.sbin/amd/amd/amd.c | 10 | ||||
-rw-r--r-- | usr.sbin/amd/amd/nfs_start.c | 150 | ||||
-rw-r--r-- | usr.sbin/amd/amd/sched.c | 12 |
3 files changed, 119 insertions, 53 deletions
diff --git a/usr.sbin/amd/amd/amd.c b/usr.sbin/amd/amd/amd.c index 3eba87d23cb..25bbc506b6f 100644 --- a/usr.sbin/amd/amd/amd.c +++ b/usr.sbin/amd/amd/amd.c @@ -32,7 +32,7 @@ * SUCH DAMAGE. * * from: @(#)amd.c 8.1 (Berkeley) 6/6/93 - * $Id: amd.c,v 1.13 2004/10/04 15:19:04 millert Exp $ + * $Id: amd.c,v 1.14 2004/10/21 20:57:08 millert Exp $ */ #ifndef lint @@ -78,8 +78,8 @@ struct in_addr myipaddr; /* (An) IP address of this host */ serv_state amd_state; struct amd_stats amd_stats; /* Server statistics */ time_t do_mapc_reload = 0; /* mapc_reload() call required? */ -jmp_buf poll_intr; -int poll_intr_valid; +jmp_buf select_intr; +int select_intr_valid; int orig_umask; /* @@ -107,8 +107,8 @@ sigterm(int sig) plog(XLOG_WARNING, "WARNING: automounter going down on signal %d", sig); break; } - if (poll_intr_valid) - longjmp(poll_intr, sig); + if (select_intr_valid) + longjmp(select_intr, sig); } /* diff --git a/usr.sbin/amd/amd/nfs_start.c b/usr.sbin/amd/amd/nfs_start.c index 53beb213d62..742ab279e49 100644 --- a/usr.sbin/amd/amd/nfs_start.c +++ b/usr.sbin/amd/amd/nfs_start.c @@ -32,7 +32,7 @@ * SUCH DAMAGE. * * from: @(#)nfs_start.c 8.1 (Berkeley) 6/6/93 - * $Id: nfs_start.c,v 1.14 2004/10/04 15:19:04 millert Exp $ + * $Id: nfs_start.c,v 1.15 2004/10/21 20:57:08 millert Exp $ */ #include "am.h" @@ -41,8 +41,8 @@ #include <unistd.h> #include <setjmp.h> -extern jmp_buf poll_intr; -extern int poll_intr_valid; +extern jmp_buf select_intr; +extern int select_intr_valid; #ifdef HAS_TFS /* @@ -61,6 +61,7 @@ SVCXPRT *nfsxprt, *lnfsxprt; SVCXPRT *amqp, *lamqp; extern int fwd_sock; +int max_fds = -1; #ifdef DEBUG /* @@ -98,14 +99,14 @@ checkup(void) #endif /* DEBUG */ static int -do_poll(sigset_t *mask, sigset_t *omask, struct pollfd *pfd, int nfds, - int timeout) +do_select(sigset_t *mask, sigset_t *omask, int fds, fd_set *fdp, + struct timeval *tvp) { int sig; - int nready; + int nsel; - if ((sig = setjmp(poll_intr))) { - poll_intr_valid = 0; + if ((sig = setjmp(select_intr))) { + select_intr_valid = 0; /* Got a signal */ switch (sig) { case SIGINT: @@ -114,10 +115,10 @@ do_poll(sigset_t *mask, sigset_t *omask, struct pollfd *pfd, int nfds, reschedule_timeout_mp(); break; } - nready = -1; + nsel = -1; errno = EINTR; } else { - poll_intr_valid = 1; + select_intr_valid = 1; /* * Invalidate the current clock value */ @@ -131,7 +132,9 @@ do_poll(sigset_t *mask, sigset_t *omask, struct pollfd *pfd, int nfds, /* * Wait for input */ - nready = poll(pfd, nfds, timeout ? timeout * 1000 : INFTIM); + nsel = select(fds, fdp, NULL, NULL, + tvp->tv_sec ? tvp : (struct timeval *) 0); + } sigprocmask(SIG_BLOCK, mask, NULL); @@ -143,7 +146,7 @@ do_poll(sigset_t *mask, sigset_t *omask, struct pollfd *pfd, int nfds, mapc_reload(); do_mapc_reload = clocktime() + ONE_HOUR; } - return nready; + return nsel; } /* @@ -153,12 +156,29 @@ do_poll(sigset_t *mask, sigset_t *omask, struct pollfd *pfd, int nfds, static int rpc_pending_now() { - struct pollfd pfd[1]; - - pfd[0].fd = fwd_sock; - pfd[0].events = POLLIN; - - return (poll(pfd, 1, 0) == 1); + struct timeval tvv; + int nsel; + fd_set *fdsp; + int fdsn; + + fdsn = howmany(max_fds+1, NFDBITS) * sizeof(fd_mask); + if ((fdsp = (fd_set *)malloc(fdsn)) == NULL) + return(0); + memset(fdsp, 0, fdsn); + FD_SET(fwd_sock, fdsp); + + tvv.tv_sec = tvv.tv_usec = 0; + nsel = select(max_fds+1, fdsp, NULL, NULL, &tvv); + if (nsel < 1) { + free(fdsp); + return(0); + } + if (FD_ISSET(fwd_sock, fdsp)) { + free(fdsp); + return(1); + } + free(fdsp); + return(0); } static serv_state @@ -183,14 +203,39 @@ run_rpc(void) * been unmounted. */ while ((int)amd_state <= (int)Finishing) { - struct pollfd *pfd; - int nready, timeout; + struct timeval tvv; + int nsel; time_t now; - - pfd = xmalloc(sizeof(*pfd) * (svc_max_pollfd + 1)); - memcpy(&pfd[1], svc_pollfd, sizeof(*pfd) * svc_max_pollfd); - pfd[0].fd = fwd_sock; - pfd[0].events = POLLIN; +#ifdef RPC_4 +#ifdef __OpenBSD__ + extern int __svc_fdsetsize; + extern fd_set *__svc_fdset; + fd_set *fdsp; + int fdsn = __svc_fdsetsize; + int bytes; + + if (fwd_sock > fdsn) + fdsn = fwd_sock; + bytes = howmany(fdsn, NFDBITS) * sizeof(fd_mask); + + fdsp = malloc(bytes); + memset(fdsp, 0, bytes); + memcpy(fdsp, __svc_fdset, bytes); + FD_SET(fwd_sock, fdsp); +#else + fd_set *fdsp; + int fdsn = FDSETSIZE; + bytes = howmany(fdsn, NFDBITS) * sizeof(fd_mask); + fdsp = malloc(bytes); + memcpy(fdsp, &svc_fdset, bytes); + FD_SET(fwd_sock, fdsp); +#endif +#else + fd_set readfds; + FD_ZERO(&readfds); + readfds.fds_bits[0] = svc_fds; + FD_SET(fwd_sock, &readfds); +#endif /* RPC_4 */ #ifdef DEBUG checkup(); @@ -205,10 +250,11 @@ run_rpc(void) if (next_softclock <= now) { if (amd_state == Finishing) umount_exported(); - timeout = softclock(); + tvv.tv_sec = softclock(); } else { - timeout = next_softclock - now; + tvv.tv_sec = next_softclock - now; } + tvv.tv_usec = 0; if (amd_state == Finishing && last_used_map < 0) { flush_mntfs(); @@ -217,28 +263,29 @@ run_rpc(void) } #ifdef DEBUG - if (timeout) - dlog("Poll waits for %ds", timeout); + if (tvv.tv_sec) + dlog("Select waits for %ds", tvv.tv_sec); else - dlog("Poll waits for Godot"); + dlog("Select waits for Godot"); #endif /* DEBUG */ - nready = do_poll(&mask, &omask, pfd, svc_max_pollfd + 1, timeout); + nsel = do_select(&mask, &omask, fdsn + 1, fdsp, &tvv); + - switch (nready) { + switch (nsel) { case -1: if (errno == EINTR) { #ifdef DEBUG - dlog("poll interrupted"); + dlog("select interrupted"); #endif /* DEBUG */ continue; } - perror("poll"); + perror("select"); break; case 0: #ifdef DEBUG - /*dlog("poll returned 0");*/ + /*dlog("select returned 0");*/ #endif /* DEBUG */ break; @@ -246,25 +293,32 @@ run_rpc(void) /* Read all pending NFS responses at once to avoid having responses queue up as a consequence of retransmissions. */ - if (pfd[0].revents & (POLLIN|POLLHUP)) { - pfd[0].fd = -1; - pfd[0].events = pfd[0].revents = 0; - --nready; + if (FD_ISSET(fwd_sock, fdsp)) { + FD_CLR(fwd_sock, fdsp); + --nsel; do { fwd_reply(); } while (rpc_pending_now() > 0); } - if (nready) { + if (nsel) { /* * Anything left must be a normal * RPC request. */ - svc_getreq_poll(pfd + 1, nready); +#ifdef RPC_4 +#ifdef __OpenBSD__ + svc_getreqset2(fdsp, fdsn); +#else + svc_getreqset(fdsp); +#endif +#else + svc_getreq(readfds.fds_bits[0]); +#endif /* RPC_4 */ } break; } - free(pfd); + free(fdsp); } sigprocmask(SIG_SETMASK, &omask, NULL); @@ -353,6 +407,18 @@ mount_automounter(pid_t ppid) return 3; /* + * One or other of so, fwd_sock + * must be the highest fd on + * which to select. + */ + if (so > max_fds) + max_fds = so; + if (so2 > max_fds) + max_fds = so2; + if (fwd_sock > max_fds) + max_fds = fwd_sock; + + /* * Construct the root automount node */ make_root_node(); diff --git a/usr.sbin/amd/amd/sched.c b/usr.sbin/amd/amd/sched.c index b745fcf5896..38e37433aa7 100644 --- a/usr.sbin/amd/amd/sched.c +++ b/usr.sbin/amd/amd/sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sched.c,v 1.12 2004/10/04 15:19:04 millert Exp $ */ +/* $OpenBSD: sched.c,v 1.13 2004/10/21 20:57:08 millert Exp $ */ /* * Copyright (c) 1990 Jan-Simon Pendry @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)sched.c 8.1 (Berkeley) 6/6/93 - * $Id: sched.c,v 1.12 2004/10/04 15:19:04 millert Exp $ + * $Id: sched.c,v 1.13 2004/10/21 20:57:08 millert Exp $ */ /* @@ -45,8 +45,8 @@ #include <signal.h> #include WAIT #include <setjmp.h> -extern jmp_buf poll_intr; -extern int poll_intr_valid; +extern jmp_buf select_intr; +extern int select_intr_valid; typedef struct pjob pjob; struct pjob { @@ -232,8 +232,8 @@ sigchld(int sig) #ifdef SYS5_SIGNALS signal(sig, sigchld); #endif /* SYS5_SIGNALS */ - if (poll_intr_valid) - longjmp(poll_intr, sig); + if (select_intr_valid) + longjmp(select_intr, sig); errno = save_errno; } |