DEVEL15-fssync-poll-interface-20071022

FIXES 74708

support a poll interface

otherwise, the fd setsize can screw with us


(cherry picked from commit d0285a2193de9868024eb0f432a495bd1802663f)
This commit is contained in:
Simon Wilkinson 2007-10-22 18:29:49 +00:00 committed by Derrick Brashear
parent c9d3acb622
commit 638bdf7e80
2 changed files with 60 additions and 3 deletions

View File

@ -1159,7 +1159,7 @@ dnl checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_DIRENT
AC_CHECK_HEADERS(stdlib.h string.h unistd.h fcntl.h sys/time.h sys/file.h)
AC_CHECK_HEADERS(stdlib.h string.h unistd.h poll.h fcntl.h sys/time.h sys/file.h)
AC_CHECK_HEADERS(netinet/in.h netdb.h sys/fcntl.h sys/mnttab.h sys/mntent.h)
AC_CHECK_HEADERS(mntent.h sys/vfs.h sys/param.h sys/fs_types.h sys/fstyp.h)
AC_CHECK_HEADERS(sys/mount.h strings.h termios.h signal.h)

View File

@ -98,6 +98,10 @@ RCSID
#include "volume.h"
#include "partition.h"
#ifdef HAVE_POLL
#include <sys/poll.h>
#endif /* HAVE_POLL */
#ifdef USE_UNIX_SOCKETS
#include <sys/un.h>
#include <afs/afsutil.h>
@ -140,13 +144,17 @@ static void FSYNC_Drop();
static void AcceptOn();
static void AcceptOff();
static void InitHandler();
static void CallHandler(fd_set * fdsetp);
static int AddHandler();
static int FindHandler();
static int FindHandler_r();
static int RemoveHandler();
#if defined(HAVE_POLL) && defined (AFS_PTHREAD_ENV)
static void CallHandler(struct pollfd *fds, int nfds, int mask);
static void GetHandler(struct pollfd *fds, int maxfds, int events, int *nfds);
#else
static void CallHandler(fd_set * fdsetp);
static void GetHandler(fd_set * fdsetp, int *maxfdp);
#endif
extern int LogLevel;
static afs_int32 FSYNC_com_VolOp(int fd, SYNC_command * com, SYNC_response * res);
@ -203,7 +211,11 @@ FSYNC_fsInit(void)
#endif /* AFS_PTHREAD_ENV */
}
#if defined(HAVE_POLL) && defined(AFS_PTHREAD_ENV)
static struct pollfd FSYNC_readfds[MAXHANDLERS];
#else
static fd_set FSYNC_readfds;
#endif
#ifdef USE_UNIX_SOCKETS
static int
@ -309,6 +321,12 @@ FSYNC_sync()
InitHandler();
AcceptOn();
for (;;) {
#if defined(HAVE_POLL) && defined(AFS_PTHREAD_ENV)
int nfds;
GetHandler(FSYNC_readfds, MAXHANDLERS, POLLIN|POLLPRI, &nfds);
if (poll(FSYNC_readfds, nfds, -1) >=1)
CallHandler(FSYNC_readfds, nfds, POLLIN|POLLPRI);
#else
int maxfd;
GetHandler(&FSYNC_readfds, &maxfd);
/* Note: check for >= 1 below is essential since IOMGR_select
@ -320,6 +338,7 @@ FSYNC_sync()
if (IOMGR_Select(maxfd + 1, &FSYNC_readfds, NULL, NULL, NULL) >= 1)
#endif /* AFS_PTHREAD_ENV */
CallHandler(&FSYNC_readfds);
#endif
}
}
@ -1129,6 +1148,24 @@ InitHandler()
ReleaseWriteLock(&FSYNC_handler_lock);
}
#if defined(HAVE_POLL) && defined(AFS_PTHREAD_ENV)
static void
CallHandler(struct pollfd *fds, int nfds, int mask)
{
int i;
int handler;
ObtainReadLock(&FSYNC_handler_lock);
for (i = 0; i < nfds; i++) {
if (fds[i].revents & mask) {
handler = FindHandler_r(fds[i].fd);
ReleaseReadLock(&FSYNC_handler_lock);
(*HandlerProc[handler]) (fds[i].fd);
ObtainReadLock(&FSYNC_handler_lock);
}
}
ReleaseReadLock(&FSYNC_handler_lock);
}
#else
static void
CallHandler(fd_set * fdsetp)
{
@ -1143,6 +1180,7 @@ CallHandler(fd_set * fdsetp)
}
ReleaseReadLock(&FSYNC_handler_lock);
}
#endif
static int
AddHandler(int afd, int (*aproc) ())
@ -1198,6 +1236,24 @@ RemoveHandler(register int afd)
return 1;
}
#if defined(HAVE_POLL) && defined(AFS_PTHREAD_ENV)
static void
GetHandler(struct pollfd *fds, int maxfds, int events, int *nfds)
{
int i;
int fdi = 0;
ObtainReadLock(&FSYNC_handler_lock);
for (i = 0; i < MAXHANDLERS; i++)
if (HandlerFD[i] != -1) {
assert(fdi<maxfds);
fds[fdi].fd = HandlerFD[i];
fds[fdi].events = events;
fds[fdi].revents = 0;
fdi++;
}
*nfds = fdi;
}
#else
static void
GetHandler(fd_set * fdsetp, int *maxfdp)
{
@ -1214,5 +1270,6 @@ GetHandler(fd_set * fdsetp, int *maxfdp)
*maxfdp = maxfd;
ReleaseReadLock(&FSYNC_handler_lock); /* just in case */
}
#endif /* HAVE_POLL && AFS_PTHREAD_ENV */
#endif /* FSSYNC_BUILD_SERVER */