FreeBSD/sys/nlm/nlm_prot_impl.c
/*
 * Create a new NLM host.
 */
Create a new NLM host.
Create a new NLM host .
static struct nlm_host *
nlm_create_host(const char* caller_name)
{
	struct nlm_host *host;
	struct sysctl_oid *oid;
	mtx_assert(&nlm_global_lock, MA_OWNED);
	NLM_DEBUG(1, "NLM: new host %s (sysid %d)\n",
	    caller_name, nlm_next_sysid);
	host = malloc(sizeof(struct nlm_host), M_NLM, M_NOWAIT|M_ZERO);
	if (!host)
		return (NULL);
	mtx_init(&host->nh_lock, "nh_lock", NULL, MTX_DEF);
	host->nh_refs = 1;
	strlcpy(host->nh_caller_name, caller_name, MAXNAMELEN);
	host->nh_sysid = nlm_next_sysid++;
	snprintf(host->nh_sysid_string, sizeof(host->nh_sysid_string),
		"%d", host->nh_sysid);
	host->nh_vers = 0;
	host->nh_state = 0;
	host->nh_monstate = NLM_UNMONITORED;
	host->nh_grantcookie = 1;
	TAILQ_INIT(&host->nh_pending);
	TAILQ_INIT(&host->nh_granted);
	TAILQ_INIT(&host->nh_finished);
	TAILQ_INSERT_TAIL(&nlm_hosts, host, nh_link);
	mtx_unlock(&nlm_global_lock);
	sysctl_ctx_init(&host->nh_sysctl);
	oid = SYSCTL_ADD_NODE(&host->nh_sysctl,
	    SYSCTL_STATIC_CHILDREN(_vfs_nlm_sysid),
	    OID_AUTO, host->nh_sysid_string, CTLFLAG_RD, NULL, "");
	SYSCTL_ADD_STRING(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
	    "hostname", CTLFLAG_RD, host->nh_caller_name, 0, "");
	SYSCTL_ADD_UINT(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
	    "version", CTLFLAG_RD, &host->nh_vers, 0, "");
	SYSCTL_ADD_UINT(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
	    "monitored", CTLFLAG_RD, &host->nh_monstate, 0, "");
	SYSCTL_ADD_PROC(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
	    "lock_count", CTLTYPE_INT | CTLFLAG_RD, host, 0,
	    nlm_host_lock_count_sysctl, "I", "");
	SYSCTL_ADD_PROC(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
	    "client_lock_count", CTLTYPE_INT | CTLFLAG_RD, host, 0,
	    nlm_host_client_lock_count_sysctl, "I", "");
	mtx_lock(&nlm_global_lock);
	return (host);
}
static struct nlm_host * nlm_create_host ( const char * caller_name ) { struct nlm_host * host ; struct sysctl_oid * oid ; mtx_assert ( & nlm_global_lock , MA_OWNED ) ; NLM_DEBUG ( 1 , " \n " , caller_name , nlm_next_sysid ) ; host = malloc ( sizeof ( struct nlm_host ) , M_NLM , M_NOWAIT | M_ZERO ) ; if ( ! host ) return ( NULL ) ; mtx_init ( & host -> nh_lock , " " , NULL , MTX_DEF ) ; host -> nh_refs = 1 ; strlcpy ( host -> nh_caller_name , caller_name , MAXNAMELEN ) ; host -> nh_sysid = nlm_next_sysid ++ ; snprintf ( host -> nh_sysid_string , sizeof ( host -> nh_sysid_string ) , " " , host -> nh_sysid ) ; host -> nh_vers = 0 ; host -> nh_state = 0 ; host -> nh_monstate = NLM_UNMONITORED ; host -> nh_grantcookie = 1 ; TAILQ_INIT ( & host -> nh_pending ) ; TAILQ_INIT ( & host -> nh_granted ) ; TAILQ_INIT ( & host -> nh_finished ) ; TAILQ_INSERT_TAIL ( & nlm_hosts , host , nh_link ) ; mtx_unlock ( & nlm_global_lock ) ; sysctl_ctx_init ( & host -> nh_sysctl ) ; oid = SYSCTL_ADD_NODE ( & host -> nh_sysctl , SYSCTL_STATIC_CHILDREN ( _vfs_nlm_sysid ) , OID_AUTO , host -> nh_sysid_string , CTLFLAG_RD , NULL , " " ) ; SYSCTL_ADD_STRING ( & host -> nh_sysctl , SYSCTL_CHILDREN ( oid ) , OID_AUTO , " " , CTLFLAG_RD , host -> nh_caller_name , 0 , " " ) ; SYSCTL_ADD_UINT ( & host -> nh_sysctl , SYSCTL_CHILDREN ( oid ) , OID_AUTO , " " , CTLFLAG_RD , & host -> nh_vers , 0 , " " ) ; SYSCTL_ADD_UINT ( & host -> nh_sysctl , SYSCTL_CHILDREN ( oid ) , OID_AUTO , " " , CTLFLAG_RD , & host -> nh_monstate , 0 , " " ) ; SYSCTL_ADD_PROC ( & host -> nh_sysctl , SYSCTL_CHILDREN ( oid ) , OID_AUTO , " " , CTLTYPE_INT | CTLFLAG_RD , host , 0 , nlm_host_lock_count_sysctl , " " , " " ) ; SYSCTL_ADD_PROC ( & host -> nh_sysctl , SYSCTL_CHILDREN ( oid ) , OID_AUTO , " " , CTLTYPE_INT | CTLFLAG_RD , host , 0 , nlm_host_client_lock_count_sysctl , " " , " " ) ; mtx_lock ( & nlm_global_lock ) ; return ( host ) ; }
Create a new NLM host.
Create a new NLM host .