Lines Matching refs:host

69  * If a host is inactive (and holds no locks) for this amount of
75 * We check the host list for idle every few seconds.
177 * A lock to protect the host list and waiting lock list.
207 * nh_pending list of the NLM host.
210 TAILQ_ENTRY(nlm_async_lock) af_link; /* (l) host's list of locks */
215 struct nlm_host *af_host; /* (c) host which is locking */
223 * NLM host.
241 char nh_caller_name[MAXNAMELEN]; /* (c) printable name of host */
244 struct sockaddr_storage nh_addr; /* (s) remote address of host */
247 rpcvers_t nh_vers; /* (s) NLM version of host */
248 int nh_state; /* (s) last seen NSM state of host */
250 time_t nh_idle_timeout; /* (s) Time at which host is idle */
502 * if the host is running a portmapper at all, we should be able
558 * granted. We notify the host which initiated the request.
572 * Send the results back to the host.
643 struct nlm_host *host = af->af_host;
646 mtx_assert(&host->nh_lock, MA_OWNED);
648 mtx_unlock(&host->nh_lock);
661 mtx_lock(&host->nh_lock);
665 "cancelled\n", af, host->nh_caller_name, host->nh_sysid);
671 TAILQ_REMOVE(&host->nh_pending, af, af_link);
672 mtx_unlock(&host->nh_lock);
674 mtx_lock(&host->nh_lock);
681 nlm_check_expired_locks(struct nlm_host *host)
686 mtx_lock(&host->nh_lock);
687 while ((af = TAILQ_FIRST(&host->nh_granted)) != NULL
693 TAILQ_REMOVE(&host->nh_granted, af, af_link);
694 mtx_unlock(&host->nh_lock);
696 mtx_lock(&host->nh_lock);
698 while ((af = TAILQ_FIRST(&host->nh_finished)) != NULL) {
699 TAILQ_REMOVE(&host->nh_finished, af, af_link);
700 mtx_unlock(&host->nh_lock);
702 mtx_lock(&host->nh_lock);
704 mtx_unlock(&host->nh_lock);
708 * Free resources used by a host. This is called after the reference
712 nlm_host_destroy(struct nlm_host *host)
716 TAILQ_REMOVE(&nlm_hosts, host, nh_link);
719 if (host->nh_srvrpc.nr_client)
720 CLNT_RELEASE(host->nh_srvrpc.nr_client);
721 if (host->nh_clntrpc.nr_client)
722 CLNT_RELEASE(host->nh_clntrpc.nr_client);
723 mtx_destroy(&host->nh_lock);
724 sysctl_ctx_free(&host->nh_sysctl);
725 free(host, M_NLM);
734 struct nlm_host *host = (struct nlm_host *) arg;
737 host->nh_caller_name);
739 nlm_client_recovery(host);
742 host->nh_caller_name);
744 host->nh_monstate = NLM_MONITORED;
745 nlm_host_release(host);
751 * This is called when we receive a host state change notification. We
752 * unlock any active locks owned by the host. When rpc.lockd is
758 nlm_host_notify(struct nlm_host *host, int newstate)
763 NLM_DEBUG(1, "NLM: host %s (sysid %d) rebooted, new "
764 "state is %d\n", host->nh_caller_name,
765 host->nh_sysid, newstate);
769 * Cancel any pending async locks for this host.
771 mtx_lock(&host->nh_lock);
772 while ((af = TAILQ_FIRST(&host->nh_pending)) != NULL) {
779 mtx_unlock(&host->nh_lock);
780 nlm_check_expired_locks(host);
783 * The host just rebooted - trash its locks.
785 lf_clearremotesys(host->nh_sysid);
786 host->nh_state = newstate;
789 * If we have any remote locks for this host (i.e. it
794 && host->nh_monstate != NLM_RECOVERING
795 && lf_countlocks(NLM_SYSID_CLIENT | host->nh_sysid) > 0) {
797 host->nh_monstate = NLM_RECOVERING;
798 refcount_acquire(&host->nh_refs);
799 kthread_add(nlm_client_recovery_start, host, curproc, &td, 0, 0,
800 "NFS lock recovery for %s", host->nh_caller_name);
810 struct nlm_host *host;
813 host = oidp->oid_arg1;
814 count = lf_countlocks(host->nh_sysid);
824 struct nlm_host *host;
827 host = oidp->oid_arg1;
828 count = lf_countlocks(NLM_SYSID_CLIENT | host->nh_sysid);
833 * Create a new NLM host.
838 struct nlm_host *host;
843 NLM_DEBUG(1, "NLM: new host %s (sysid %d)\n",
845 host = malloc(sizeof(struct nlm_host), M_NLM, M_NOWAIT|M_ZERO);
846 if (!host)
848 mtx_init(&host->nh_lock, "nh_lock", NULL, MTX_DEF);
849 host->nh_refs = 1;
850 strlcpy(host->nh_caller_name, caller_name, MAXNAMELEN);
851 host->nh_sysid = nlm_next_sysid++;
852 snprintf(host->nh_sysid_string, sizeof(host->nh_sysid_string),
853 "%d", host->nh_sysid);
854 host->nh_vers = 0;
855 host->nh_state = 0;
856 host->nh_monstate = NLM_UNMONITORED;
857 host->nh_grantcookie = 1;
858 TAILQ_INIT(&host->nh_pending);
859 TAILQ_INIT(&host->nh_granted);
860 TAILQ_INIT(&host->nh_finished);
861 TAILQ_INSERT_TAIL(&nlm_hosts, host, nh_link);
865 sysctl_ctx_init(&host->nh_sysctl);
866 oid = SYSCTL_ADD_NODE(&host->nh_sysctl,
868 OID_AUTO, host->nh_sysid_string, CTLFLAG_RD, NULL, "");
869 SYSCTL_ADD_STRING(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
870 "hostname", CTLFLAG_RD, host->nh_caller_name, 0, "");
871 SYSCTL_ADD_UINT(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
872 "version", CTLFLAG_RD, &host->nh_vers, 0, "");
873 SYSCTL_ADD_UINT(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
874 "monitored", CTLFLAG_RD, &host->nh_monstate, 0, "");
875 SYSCTL_ADD_PROC(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
876 "lock_count", CTLTYPE_INT | CTLFLAG_RD, host, 0,
878 SYSCTL_ADD_PROC(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
879 "client_lock_count", CTLTYPE_INT | CTLFLAG_RD, host, 0,
884 return (host);
936 * the host structure here, possibly after a larger timeout but that
943 struct nlm_host *host;
952 TAILQ_FOREACH(host, &nlm_hosts, nh_link) {
953 if (host->nh_monstate == NLM_MONITORED
954 && time_uptime > host->nh_idle_timeout) {
956 if (lf_countlocks(host->nh_sysid) > 0
958 + host->nh_sysid)) {
959 host->nh_idle_timeout =
964 nlm_host_unmonitor(host);
971 * Search for an existing NLM host that matches the given name
973 * found, create a new host. If 'addr' is non-NULL, record the remote
974 * address of the host so that we can call it back for async
982 struct nlm_host *host;
987 * The remote host is determined by caller_name.
989 TAILQ_FOREACH(host, &nlm_hosts, nh_link) {
990 if (!strcmp(host->nh_caller_name, name))
994 if (!host) {
995 host = nlm_create_host(name);
996 if (!host) {
1001 refcount_acquire(&host->nh_refs);
1003 host->nh_idle_timeout = time_uptime + NLM_IDLE_TIMEOUT;
1006 * If we have an address for the host, record it so that we
1019 if (host->nh_addr.ss_len && host->nh_srvrpc.nr_client) {
1021 (struct sockaddr *) &host->nh_addr,
1023 || host->nh_vers != vers) {
1025 mtx_lock(&host->nh_lock);
1026 client = host->nh_srvrpc.nr_client;
1027 host->nh_srvrpc.nr_client = NULL;
1028 mtx_unlock(&host->nh_lock);
1034 memcpy(&host->nh_addr, addr, addr->sa_len);
1035 host->nh_vers = vers;
1042 return (host);
1046 * Search for an existing NLM host that matches the given remote
1047 * address. If none is found, create a new host with the requested
1049 * that host.
1059 struct nlm_host *host;
1082 * The remote host is determined by caller_name.
1084 TAILQ_FOREACH(host, &nlm_hosts, nh_link) {
1086 (const struct sockaddr *) &host->nh_addr))
1090 if (!host) {
1091 host = nlm_create_host(tmp);
1092 if (!host) {
1096 memcpy(&host->nh_addr, addr, addr->sa_len);
1097 host->nh_vers = vers;
1099 refcount_acquire(&host->nh_refs);
1101 host->nh_idle_timeout = time_uptime + NLM_IDLE_TIMEOUT;
1107 return (host);
1111 * Find the NLM host that matches the value of 'sysid'. If none
1117 struct nlm_host *host;
1119 TAILQ_FOREACH(host, &nlm_hosts, nh_link) {
1120 if (host->nh_sysid == sysid) {
1121 refcount_acquire(&host->nh_refs);
1122 return (host);
1129 void nlm_host_release(struct nlm_host *host)
1131 if (refcount_release(&host->nh_refs)) {
1133 * Free the host
1135 nlm_host_destroy(host);
1140 * Unregister this NLM host with the local NSM due to idleness.
1143 nlm_host_unmonitor(struct nlm_host *host)
1151 host->nh_caller_name, host->nh_sysid);
1155 * make it simpler to find the host if we are notified of a
1156 * host restart.
1158 smmonid.mon_name = host->nh_caller_name;
1176 host->nh_caller_name);
1180 host->nh_monstate = NLM_UNMONITORED;
1184 * Register this NLM host with the local NSM so that we can be
1188 nlm_host_monitor(struct nlm_host *host, int state)
1195 if (state && !host->nh_state) {
1198 * value for this host. We record it here to help
1199 * detect host reboots.
1201 host->nh_state = state;
1202 NLM_DEBUG(1, "NLM: host %s (sysid %d) has NSM state %d\n",
1203 host->nh_caller_name, host->nh_sysid, state);
1206 mtx_lock(&host->nh_lock);
1207 if (host->nh_monstate != NLM_UNMONITORED) {
1208 mtx_unlock(&host->nh_lock);
1211 host->nh_monstate = NLM_MONITORED;
1212 mtx_unlock(&host->nh_lock);
1215 host->nh_caller_name, host->nh_sysid);
1219 * make it simpler to find the host if we are notified of a
1220 * host restart.
1222 smmon.mon_id.mon_name = host->nh_caller_name;
1227 memcpy(smmon.priv, &host->nh_sysid, sizeof(host->nh_sysid));
1241 host->nh_caller_name);
1242 mtx_lock(&host->nh_lock);
1243 host->nh_monstate = NLM_MONITOR_FAILED;
1244 mtx_unlock(&host->nh_lock);
1248 host->nh_monstate = NLM_MONITORED;
1253 * running on the given host.
1256 nlm_host_get_rpc(struct nlm_host *host, bool_t isserver)
1261 mtx_lock(&host->nh_lock);
1264 rpc = &host->nh_srvrpc;
1266 rpc = &host->nh_clntrpc;
1279 mtx_unlock(&host->nh_lock);
1281 mtx_lock(&host->nh_lock);
1285 mtx_unlock(&host->nh_lock);
1286 client = nlm_get_rpc((struct sockaddr *)&host->nh_addr,
1287 NLM_PROG, host->nh_vers);
1288 mtx_lock(&host->nh_lock);
1292 mtx_unlock(&host->nh_lock);
1294 mtx_lock(&host->nh_lock);
1305 mtx_unlock(&host->nh_lock);
1311 int nlm_host_get_sysid(struct nlm_host *host)
1314 return (host->nh_sysid);
1318 nlm_host_get_state(struct nlm_host *host)
1321 return (host->nh_state);
1530 struct nlm_host *host, *nhost;
1668 * nlm_hosts to the host (which may remove it from the list
1677 TAILQ_FOREACH_SAFE(host, &nlm_hosts, nh_link, nhost) {
1679 nlm_host_notify(host, 0);
1680 nlm_host_release(host);
1721 struct nlm_host *host;
1725 host = nlm_find_host_by_sysid(sysid);
1726 if (host) {
1727 nlm_host_notify(host, argp->state);
1728 nlm_host_release(host);
1745 nlm_get_vfs_state(struct nlm_host *host, struct svc_req *rqstp,
1761 (struct sockaddr *)&host->nh_addr, &exflags, &credanon,
1852 struct nlm_host *host, *bhost;
1860 host = nlm_find_host_by_name(argp->alock.caller_name,
1862 if (!host) {
1868 host->nh_caller_name, host->nh_sysid);
1870 nlm_check_expired_locks(host);
1871 sysid = host->nh_sysid;
1882 error = nlm_get_vfs_state(host, rqstp, &fh, &vs, accmode);
1916 * a space for the owning host's name allowing
1922 * the first four bytes of the host
1939 *rpcp = nlm_host_get_rpc(host, TRUE);
1940 nlm_host_release(host);
1950 struct nlm_host *host;
1958 host = nlm_find_host_by_name(argp->alock.caller_name,
1960 if (!host) {
1966 host->nh_caller_name, host->nh_sysid);
1968 if (monitor && host->nh_state && argp->state
1969 && host->nh_state != argp->state) {
1971 * The host rebooted without telling us. Trash its
1974 nlm_host_notify(host, argp->state);
1977 nlm_check_expired_locks(host);
1978 sysid = host->nh_sysid;
1989 error = nlm_get_vfs_state(host, rqstp, &fh, &vs, accmode);
2010 * First, make sure we can contact the host's NLM.
2012 client = nlm_host_get_rpc(host, TRUE);
2024 mtx_lock(&host->nh_lock);
2025 TAILQ_FOREACH(af, &host->nh_pending, af_link) {
2034 cookie.ng_sysid = host->nh_sysid;
2035 cookie.ng_cookie = host->nh_grantcookie++;
2037 mtx_unlock(&host->nh_lock);
2049 af->af_host = host;
2076 mtx_lock(&host->nh_lock);
2077 TAILQ_INSERT_TAIL(&host->nh_pending, af, af_link);
2078 mtx_unlock(&host->nh_lock);
2089 mtx_lock(&host->nh_lock);
2090 TAILQ_REMOVE(&host->nh_pending, af, af_link);
2091 mtx_unlock(&host->nh_lock);
2097 "(sysid %d)\n", af, host->nh_caller_name, sysid);
2121 nlm_host_monitor(host, argp->state);
2128 *rpcp = nlm_host_get_rpc(host, TRUE);
2129 nlm_host_release(host);
2139 struct nlm_host *host;
2147 host = nlm_find_host_by_name(argp->alock.caller_name,
2149 if (!host) {
2155 host->nh_caller_name, host->nh_sysid);
2157 nlm_check_expired_locks(host);
2158 sysid = host->nh_sysid;
2168 error = nlm_get_vfs_state(host, rqstp, &fh, &vs, (accmode_t)0);
2188 mtx_lock(&host->nh_lock);
2190 TAILQ_FOREACH(af, &host->nh_pending, af_link) {
2200 mtx_unlock(&host->nh_lock);
2213 mtx_unlock(&host->nh_lock);
2218 *rpcp = nlm_host_get_rpc(host, TRUE);
2219 nlm_host_release(host);
2229 struct nlm_host *host;
2236 host = nlm_find_host_by_name(argp->alock.caller_name,
2238 if (!host) {
2244 host->nh_caller_name, host->nh_sysid);
2246 nlm_check_expired_locks(host);
2247 sysid = host->nh_sysid;
2257 error = nlm_get_vfs_state(host, rqstp, &fh, &vs, (accmode_t)0);
2280 *rpcp = nlm_host_get_rpc(host, TRUE);
2281 nlm_host_release(host);
2290 struct nlm_host *host;
2295 host = nlm_find_host_by_addr(svc_getrpccaller(rqstp), rqstp->rq_vers);
2296 if (!host) {
2325 *rpcp = nlm_host_get_rpc(host, TRUE);
2326 nlm_host_release(host);
2333 struct nlm_host *host = NULL;
2342 host = nlm_find_host_by_sysid(ng_sysid(&argp->cookie));
2343 if (!host) {
2344 NLM_DEBUG(1, "NLM: Unknown host rejected our grant");
2348 mtx_lock(&host->nh_lock);
2349 TAILQ_FOREACH(af, &host->nh_granted, af_link)
2354 TAILQ_REMOVE(&host->nh_granted, af, af_link);
2355 mtx_unlock(&host->nh_lock);
2358 NLM_DEBUG(1, "NLM: host %s (sysid %d) replied to our grant "
2359 "with unrecognized cookie %d:%d", host->nh_caller_name,
2360 host->nh_sysid, ng_sysid(&argp->cookie),
2369 NLM_DEBUG(1, "NLM: host %s (sysid %d) rejected our grant "
2370 "and we failed to unlock (%d)", host->nh_caller_name,
2371 host->nh_sysid, error);
2375 NLM_DEBUG(5, "NLM: async lock %p rejected by host %s (sysid %d)",
2376 af, host->nh_caller_name, host->nh_sysid);
2378 NLM_DEBUG(5, "NLM: async lock %p accepted by host %s (sysid %d)",
2379 af, host->nh_caller_name, host->nh_sysid);
2385 if (host)
2386 nlm_host_release(host);
2392 struct nlm_host *host, *thost;
2394 TAILQ_FOREACH_SAFE(host, &nlm_hosts, nh_link, thost) {
2395 if (!strcmp(host->nh_caller_name, argp->name))
2396 nlm_host_notify(host, argp->state);