diff options
author | wpaul <wpaul@FreeBSD.org> | 1995-04-26 19:03:16 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 1995-04-26 19:03:16 +0000 |
commit | b72b2e3557fca50d6b69c47a937520cbe45c26d3 (patch) | |
tree | bf5e8345e4fe172879132532c0e299a35e9937b8 /lib/libc/yp | |
parent | 321a03d090577e9d6eb90169b5ded161378501ea (diff) | |
download | FreeBSD-src-b72b2e3557fca50d6b69c47a937520cbe45c26d3.zip FreeBSD-src-b72b2e3557fca50d6b69c47a937520cbe45c26d3.tar.gz |
ypbind.c: Major overhaul.
- Moved to a more client-driven model. We aggressively attempt to keep
the default domain bound (as before) but we give up on non-default
domains if we lose contact with a server and fail to get a response
after one round of broadcasting. This helps drastically reduce the
amount of network bandwitdh that ypbind consumes: if a client references
the secondary domain at some later point, this will prod ypbind into
establishing a new binding anyway, so continuously broadcasting without
need is pointless.
Note that we still actively seek out a binding for our default domain
even if no client program has queried us yet. I'm not exactly sure if
this matches SunOS's behavior or not, but I decided to do it this way
since we can get into all sorts of trouble if our default domain comes
unbound. Even so, we're still much quieter than we used to be.
- Removed a bunch of no-longer pertinent comments and a couple of
chunks of #ifdef 0'ed code that no longer fit in to the new layout.
- Theo deRaadt must have become frustrated with the callback mechanism
in clnt_broadcast(), because he shamelessly stole the clnt_broadcast()
code right out of the RPC library and hacked it up to suit his needs.
(Comments and all! :)
I can understand why: clnt_broadcast() blocks while awaiting replies.
Changing this behavior requires surgery. However, you can work around
this: fork the broadcast into a child process and relay the results
back to the parent via a pipe. (Careful obervation has shown that the
SunOS ypbind forks children for broadcasting too, though I can only
guess what sort of interprocess communication it uses. pipe() seems to
do the job well enough.)
This may seem like the long way around, but it's not really that
hard to implement, and I'd prefer to use documented RPC library functions
wherever possible. We're careful to limit the number of simultaneous
broadcasters to avoid swamping the system (the current limit is 5).
Each clnt_broadcast() call only sends out a small number of packets
at increasing intervals. We're also careful not to spawn more than one
bradcaster for a given domain.
- Used clntudp_bufcreate() and clnt_call() to implement a ping()
function for directly querying a particular server so that we can
check if it's still alive. This lets me completely remove the old
bradcasting code and use actual RPC library calls instead, at the
cost of more than a few handfulls of torn-out hair. (Make no mistake
folks: I *HATE* RPC.) Currently, the ping interval is one minute.
- Fixed another potential 'nfds too big for select()' bug: use
_rpc_dtablesize() instead of getdtablesize().
- Quieted gcc -Wall a bit.
- Probably a bunch of other stuff that I've forgotten.
ypbind.8:
- Updated man page to reflect modifications.
ypwhich.c:
- Small mind-o fix from last time: decode error results from
ypbind correctly (*groan*)
yplib.c:
- same as above
- Change behavior of _yp_dobind() a little: if we get back a 'Domain
not bound' error for a given domain, retry a few times before giving
up and passing the error back to the caller. We have to sleep for a
few seconds between tries since the 'Domain not bound' error comes
back immediately (by repeatedly looping, we end up pounding on ypbind).
We retry at most 20 times at 5 second intervals. This gives us a full
minute to get a response. This seems to deviate a bit from SunOS
behavior -- it appears to wait forever -- but I don't like the idea
of perpetually hanging inside a library call.
Note that this should fix the problems some people have with bindings
not being established fast enough at boot time; sometimes amd is started
in /etc/rc after ypbind has run but before it gets a binding set up. The
automounter gets annoyed at this and tends to exit. By pausing ther YP
calls until a binding is ready, we avoid this situation.
- Another _yp_dobind() change: if we determine that our binding files
are unlocked or nonexistent, jump directly to code that pokes ypbind
into restablishing the binding. Again, if it fails, we'll time out
eventually and return.
Diffstat (limited to 'lib/libc/yp')
-rw-r--r-- | lib/libc/yp/yplib.c | 75 |
1 files changed, 20 insertions, 55 deletions
diff --git a/lib/libc/yp/yplib.c b/lib/libc/yp/yplib.c index da23244..c785145 100644 --- a/lib/libc/yp/yplib.c +++ b/lib/libc/yp/yplib.c @@ -28,7 +28,7 @@ */ #ifndef LINT -static char *rcsid = "$Id: yplib.c,v 1.6 1995/04/09 21:52:31 wpaul Exp $"; +static char *rcsid = "$Id: yplib.c,v 1.7 1995/04/21 18:04:22 wpaul Exp $"; #endif #include <sys/param.h> @@ -50,6 +50,7 @@ static char *rcsid = "$Id: yplib.c,v 1.6 1995/04/09 21:52:31 wpaul Exp $"; #define BINDINGDIR "/var/yp/binding" #endif #define YPMATCHCACHE +#define MAX_RETRIES 20 extern bool_t xdr_domainname(), xdr_ypbind_resp(); extern bool_t xdr_ypreq_key(), xdr_ypresp_val(); @@ -200,7 +201,8 @@ struct dom_binding **ypdb; struct sockaddr_in clnt_sin; int clnt_sock, fd, gpid; CLIENT *client; - int new=0, r; + int new = 0, r; + int retries = 0; gpid = getpid(); if( !(pid==-1 || pid==gpid) ) { @@ -233,35 +235,20 @@ struct dom_binding **ypdb; new = 1; } again: + retries++; + if (retries > MAX_RETRIES) { + if (new) + free(ysd); + return(YPERR_YPBIND); + } #ifdef BINDINGDIR if(ysd->dom_vers==0) { sprintf(path, "%s/%s.%d", BINDINGDIR, dom, 2); if( (fd=open(path, O_RDONLY)) == -1) { /* no binding file, YP is dead. */ - /* - * XXX Not necessarily: the caller might be asking - * for a domain that we simply aren't bound to yet. - * Check that the binding file for the default domain - * is also unlocked before giving up. - */ + /* Try to bring it back to life. */ close(fd); - if (new) { - char *_defaultdom; - - if (yp_get_default_domain(&_defaultdom)) - return YPERR_NODOM; - if (!strcmp(dom, _defaultdom)) - goto bail; - sprintf(path, "%s/%s.%d", BINDINGDIR, _defaultdom, 2); - if((fd=open(path, O_RDONLY)) > 0 && - (flock(fd, LOCK_EX|LOCK_NB)) == -1 && - errno==EWOULDBLOCK) { - close(fd); - goto skipit; - } else { - goto bail; - } - } + goto skipit; } if( flock(fd, LOCK_EX|LOCK_NB) == -1 && errno==EWOULDBLOCK) { struct iovec iov[2]; @@ -293,32 +280,9 @@ again: goto gotit; } else { /* no lock on binding file, YP is dead. */ - /* - * XXX Not necessarily: the caller might be asking - * for a domain that we simply aren't bound to yet. - * Check that the binding file for the default domain - * is also unlocked before giving up. - */ + /* Try to bring it back to life. */ close(fd); - if (new) { - char *_defaultdom; - - if (yp_get_default_domain(&_defaultdom)) - return YPERR_NODOM; - sprintf(path, "%s/%s.%d", BINDINGDIR, _defaultdom, 2); - if (!strcmp(dom, _defaultdom)) - goto bail; - if((fd=open(path, O_RDONLY)) > 0 && - (flock(fd, LOCK_EX|LOCK_NB)) == -1 && - errno==EWOULDBLOCK) { - close(fd); - } else { -bail: - close(fd); /* for paranoia's sake */ - free(ysd); - return YPERR_YPBIND; - } - } + goto skipit; } } skipit: @@ -335,10 +299,10 @@ skipit: clnt_pcreateerror("clnttcp_create"); if(new) free(ysd); - return YPERR_YPBIND; + return (YPERR_YPBIND); } - tv.tv_sec = _yplib_timeout; + tv.tv_sec = _yplib_timeout/2; tv.tv_usec = 0; r = clnt_call(client, YPBINDPROC_DOMAIN, xdr_domainname, dom, xdr_ypbind_resp, &ypbr, tv); @@ -350,9 +314,10 @@ skipit: goto again; } else { if (ypbr.ypbind_status != YPBIND_SUCC_VAL) { - fprintf(stderr, "yp_bind: %s\n", - ypbinderr_string(ypbr.ypbind_status)); - return YPERR_YPBIND; + clnt_destroy(client); + ysd->dom_vers = -1; + sleep(_yplib_timeout/2); + goto again; } } clnt_destroy(client); |