FreeBSD/sys/nlm/nlm_prot_impl.c
/*
 * Register this NLM host with the local NSM so that we can be
 * notified if it reboots.
 */
Register this NLM host with the local NSM so that we can be
notified if it reboots.
Register this NLM host with the local NSM so that we can be notified if it reboots .
void
nlm_host_monitor(struct nlm_host *host, int state)
{
	mon smmon;
	sm_stat_res smstat;
	struct timeval timo;
	enum clnt_stat stat;
	if (state && !host->nh_state) {
		host->nh_state = state;
		NLM_DEBUG(1, "NLM: host %s (sysid %d) has NSM state %d\n",
		    host->nh_caller_name, host->nh_sysid, state);
	}
	mtx_lock(&host->nh_lock);
	if (host->nh_monstate != NLM_UNMONITORED) {
		mtx_unlock(&host->nh_lock);
		return;
	}
	host->nh_monstate = NLM_MONITORED;
	mtx_unlock(&host->nh_lock);
	NLM_DEBUG(1, "NLM: monitoring %s (sysid %d)\n",
	    host->nh_caller_name, host->nh_sysid);
	smmon.mon_id.mon_name = host->nh_caller_name;
	smmon.mon_id.my_id.my_name = "localhost";
	smmon.mon_id.my_id.my_prog = NLM_PROG;
	smmon.mon_id.my_id.my_vers = NLM_SM;
	smmon.mon_id.my_id.my_proc = NLM_SM_NOTIFY;
	memcpy(smmon.priv, &host->nh_sysid, sizeof(host->nh_sysid));
	timo.tv_sec = 25;
	timo.tv_usec = 0;
	stat = CLNT_CALL(nlm_nsm, SM_MON,
	    (xdrproc_t) xdr_mon, &smmon,
	    (xdrproc_t) xdr_sm_stat, &smstat, timo);
	if (stat != RPC_SUCCESS) {
		NLM_ERR("Failed to contact local NSM - rpc error %d\n", stat);
		return;
	}
	if (smstat.res_stat == stat_fail) {
		NLM_ERR("Local NSM refuses to monitor %s\n",
		    host->nh_caller_name);
		mtx_lock(&host->nh_lock);
		host->nh_monstate = NLM_MONITOR_FAILED;
		mtx_unlock(&host->nh_lock);
		return;
	}
	host->nh_monstate = NLM_MONITORED;
}
void nlm_host_monitor ( struct nlm_host * host , int state ) { mon smmon ; sm_stat_res smstat ; struct timeval timo ; enum clnt_stat stat ; if ( state && ! host -> nh_state ) { host -> nh_state = state ; NLM_DEBUG ( 1 , " \n " , host -> nh_caller_name , host -> nh_sysid , state ) ; } mtx_lock ( & host -> nh_lock ) ; if ( host -> nh_monstate != NLM_UNMONITORED ) { mtx_unlock ( & host -> nh_lock ) ; return ; } host -> nh_monstate = NLM_MONITORED ; mtx_unlock ( & host -> nh_lock ) ; NLM_DEBUG ( 1 , " \n " , host -> nh_caller_name , host -> nh_sysid ) ; smmon . mon_id . mon_name = host -> nh_caller_name ; smmon . mon_id . my_id . my_name = " " ; smmon . mon_id . my_id . my_prog = NLM_PROG ; smmon . mon_id . my_id . my_vers = NLM_SM ; smmon . mon_id . my_id . my_proc = NLM_SM_NOTIFY ; memcpy ( smmon . priv , & host -> nh_sysid , sizeof ( host -> nh_sysid ) ) ; timo . tv_sec = 25 ; timo . tv_usec = 0 ; stat = CLNT_CALL ( nlm_nsm , SM_MON , ( xdrproc_t ) xdr_mon , & smmon , ( xdrproc_t ) xdr_sm_stat , & smstat , timo ) ; if ( stat != RPC_SUCCESS ) { NLM_ERR ( " \n " , stat ) ; return ; } if ( smstat . res_stat == stat_fail ) { NLM_ERR ( " \n " , host -> nh_caller_name ) ; mtx_lock ( & host -> nh_lock ) ; host -> nh_monstate = NLM_MONITOR_FAILED ; mtx_unlock ( & host -> nh_lock ) ; return ; } host -> nh_monstate = NLM_MONITORED ; }
Register this NLM host with the local NSM so that we can be
 notified if it reboots.
Register this NLM host with the local NSM so that we can be notified if it reboots .
/*
		 * This is the first time we have seen an NSM state
		 * value for this host. We record it here to help
		 * detect host reboots.
		 */ /*
	 * We put our assigned system ID value in the priv field to
	 * make it simpler to find the host if we are notified of a
	 * host restart.
	 */