FreeBSD/sys/nlm/nlm_prot_impl.c
/*
 * Return an RPC client handle that can be used to talk to the NLM
 * running on the given host.
 */
Return an RPC client handle that can be used to talk to the NLM
running on the given host.
Return an RPC client handle that can be used to talk to the NLM running on the given host .
CLIENT *
nlm_host_get_rpc(struct nlm_host *host, bool_t isserver)
{
	struct nlm_rpc *rpc;
	CLIENT *client;
	mtx_lock(&host->nh_lock);
	if (isserver)
		rpc = &host->nh_srvrpc;
	else
		rpc = &host->nh_clntrpc;
	if (rpc->nr_client && time_uptime > rpc->nr_create_time + 2*60) {
		client = rpc->nr_client;
		rpc->nr_client = NULL;
		mtx_unlock(&host->nh_lock);
		CLNT_RELEASE(client);
		mtx_lock(&host->nh_lock);
	}
	if (!rpc->nr_client) {
		mtx_unlock(&host->nh_lock);
		client = nlm_get_rpc((struct sockaddr *)&host->nh_addr,
		    NLM_PROG, host->nh_vers);
		mtx_lock(&host->nh_lock);
		if (client) {
			if (rpc->nr_client) {
				mtx_unlock(&host->nh_lock);
				CLNT_DESTROY(client);
				mtx_lock(&host->nh_lock);
			} else {
				rpc->nr_client = client;
				rpc->nr_create_time = time_uptime;
			}
		}
	}
	client = rpc->nr_client;
	if (client)
		CLNT_ACQUIRE(client);
	mtx_unlock(&host->nh_lock);
	return (client);
}
CLIENT * nlm_host_get_rpc ( struct nlm_host * host , bool_t isserver ) { struct nlm_rpc * rpc ; CLIENT * client ; mtx_lock ( & host -> nh_lock ) ; if ( isserver ) rpc = & host -> nh_srvrpc ; else rpc = & host -> nh_clntrpc ; if ( rpc -> nr_client && time_uptime > rpc -> nr_create_time + 2 * 60 ) { client = rpc -> nr_client ; rpc -> nr_client = NULL ; mtx_unlock ( & host -> nh_lock ) ; CLNT_RELEASE ( client ) ; mtx_lock ( & host -> nh_lock ) ; } if ( ! rpc -> nr_client ) { mtx_unlock ( & host -> nh_lock ) ; client = nlm_get_rpc ( ( struct sockaddr * ) & host -> nh_addr , NLM_PROG , host -> nh_vers ) ; mtx_lock ( & host -> nh_lock ) ; if ( client ) { if ( rpc -> nr_client ) { mtx_unlock ( & host -> nh_lock ) ; CLNT_DESTROY ( client ) ; mtx_lock ( & host -> nh_lock ) ; } else { rpc -> nr_client = client ; rpc -> nr_create_time = time_uptime ; } } } client = rpc -> nr_client ; if ( client ) CLNT_ACQUIRE ( client ) ; mtx_unlock ( & host -> nh_lock ) ; return ( client ) ; }
Return an RPC client handle that can be used to talk to the NLM
 running on the given host.
Return an RPC client handle that can be used to talk to the NLM running on the given host .
/*
	 * We can't hold onto RPC handles for too long - the async
	 * call/reply protocol used by some NLM clients makes it hard
	 * to tell when they change port numbers (e.g. after a
	 * reboot). Note that if a client reboots while it isn't
	 * holding any locks, it won't bother to notify us. We
	 * expire the RPC handles after two minutes.
	 */