Home | History | Annotate | Download | only in nlm

Lines Matching refs:host

77  * If a host is inactive (and holds no locks) for this amount of
83 * We check the host list for idle every few seconds.
185 * A lock to protect the host list and waiting lock list.
215 * nh_pending list of the NLM host.
218 TAILQ_ENTRY(nlm_async_lock) af_link; /* (l) host's list of locks */
223 struct nlm_host *af_host; /* (c) host which is locking */
231 * NLM host.
249 char nh_caller_name[MAXNAMELEN]; /* (c) printable name of host */
252 struct sockaddr_storage nh_addr; /* (s) remote address of host */
255 rpcvers_t nh_vers; /* (s) NLM version of host */
256 int nh_state; /* (s) last seen NSM state of host */
258 time_t nh_idle_timeout; /* (s) Time at which host is idle */
510 * if the host is running a portmapper at all, we should be able
566 * granted. We notify the host which initiated the request.
580 * Send the results back to the host.
651 struct nlm_host *host = af->af_host;
654 mtx_assert(&host->nh_lock, MA_OWNED);
656 mtx_unlock(&host->nh_lock);
669 mtx_lock(&host->nh_lock);
673 "cancelled\n", af, host->nh_caller_name, host->nh_sysid);
679 TAILQ_REMOVE(&host->nh_pending, af, af_link);
680 mtx_unlock(&host->nh_lock);
682 mtx_lock(&host->nh_lock);
689 nlm_check_expired_locks(struct nlm_host *host)
694 mtx_lock(&host->nh_lock);
695 while ((af = TAILQ_FIRST(&host->nh_granted)) != NULL
701 TAILQ_REMOVE(&host->nh_granted, af, af_link);
702 mtx_unlock(&host->nh_lock);
704 mtx_lock(&host->nh_lock);
706 while ((af = TAILQ_FIRST(&host->nh_finished)) != NULL) {
707 TAILQ_REMOVE(&host->nh_finished, af, af_link);
708 mtx_unlock(&host->nh_lock);
710 mtx_lock(&host->nh_lock);
712 mtx_unlock(&host->nh_lock);
716 * Free resources used by a host. This is called after the reference
720 nlm_host_destroy(struct nlm_host *host)
724 TAILQ_REMOVE(&nlm_hosts, host, nh_link);
727 if (host->nh_srvrpc.nr_client)
728 CLNT_RELEASE(host->nh_srvrpc.nr_client);
729 if (host->nh_clntrpc.nr_client)
730 CLNT_RELEASE(host->nh_clntrpc.nr_client);
731 mtx_destroy(&host->nh_lock);
732 sysctl_ctx_free(&host->nh_sysctl);
733 free(host, M_NLM);
742 struct nlm_host *host = (struct nlm_host *) arg;
745 host->nh_caller_name);
747 nlm_client_recovery(host);
750 host->nh_caller_name);
752 host->nh_monstate = NLM_MONITORED;
753 nlm_host_release(host);
759 * This is called when we receive a host state change notification. We
760 * unlock any active locks owned by the host. When rpc.lockd is
766 nlm_host_notify(struct nlm_host *host, int newstate)
771 NLM_DEBUG(1, "NLM: host %s (sysid %d) rebooted, new "
772 "state is %d\n", host->nh_caller_name,
773 host->nh_sysid, newstate);
777 * Cancel any pending async locks for this host.
779 mtx_lock(&host->nh_lock);
780 while ((af = TAILQ_FIRST(&host->nh_pending)) != NULL) {
787 mtx_unlock(&host->nh_lock);
788 nlm_check_expired_locks(host);
791 * The host just rebooted - trash its locks.
793 lf_clearremotesys(host->nh_sysid);
794 host->nh_state = newstate;
797 * If we have any remote locks for this host (i.e. it
802 && host->nh_monstate != NLM_RECOVERING
803 && lf_countlocks(NLM_SYSID_CLIENT | host->nh_sysid) > 0) {
805 host->nh_monstate = NLM_RECOVERING;
806 refcount_acquire(&host->nh_refs);
807 kthread_add(nlm_client_recovery_start, host, curproc, &td, 0, 0,
808 "NFS lock recovery for %s", host->nh_caller_name);
818 struct nlm_host *host;
821 host = oidp->oid_arg1;
822 count = lf_countlocks(host->nh_sysid);
832 struct nlm_host *host;
835 host = oidp->oid_arg1;
836 count = lf_countlocks(NLM_SYSID_CLIENT | host->nh_sysid);
841 * Create a new NLM host.
846 struct nlm_host *host;
851 NLM_DEBUG(1, "NLM: new host %s (sysid %d)\n",
853 host = malloc(sizeof(struct nlm_host), M_NLM, M_NOWAIT|M_ZERO);
854 if (!host)
856 mtx_init(&host->nh_lock, "nh_lock", NULL, MTX_DEF);
857 host->nh_refs = 1;
858 strlcpy(host->nh_caller_name, caller_name, MAXNAMELEN);
859 host->nh_sysid = nlm_next_sysid++;
860 snprintf(host->nh_sysid_string, sizeof(host->nh_sysid_string),
861 "%d", host->nh_sysid);
862 host->nh_vers = 0;
863 host->nh_state = 0;
864 host->nh_monstate = NLM_UNMONITORED;
865 host->nh_grantcookie = 1;
866 TAILQ_INIT(&host->nh_pending);
867 TAILQ_INIT(&host->nh_granted);
868 TAILQ_INIT(&host->nh_finished);
869 TAILQ_INSERT_TAIL(&nlm_hosts, host, nh_link);
873 sysctl_ctx_init(&host->nh_sysctl);
874 oid = SYSCTL_ADD_NODE(&host->nh_sysctl,
876 OID_AUTO, host->nh_sysid_string, CTLFLAG_RD, NULL, "");
877 SYSCTL_ADD_STRING(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
878 "hostname", CTLFLAG_RD, host->nh_caller_name, 0, "");
879 SYSCTL_ADD_UINT(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
880 "version", CTLFLAG_RD, &host->nh_vers, 0, "");
881 SYSCTL_ADD_UINT(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
882 "monitored", CTLFLAG_RD, &host->nh_monstate, 0, "");
883 SYSCTL_ADD_PROC(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
884 "lock_count", CTLTYPE_INT | CTLFLAG_RD, host, 0,
886 SYSCTL_ADD_PROC(&host->nh_sysctl, SYSCTL_CHILDREN(oid), OID_AUTO,
887 "client_lock_count", CTLTYPE_INT | CTLFLAG_RD, host, 0,
892 return (host);
944 * the host structure here, possibly after a larger timeout but that
951 struct nlm_host *host;
960 TAILQ_FOREACH(host, &nlm_hosts, nh_link) {
961 if (host->nh_monstate == NLM_MONITORED
962 && time_uptime > host->nh_idle_timeout) {
964 if (lf_countlocks(host->nh_sysid) > 0
966 + host->nh_sysid)) {
967 host->nh_idle_timeout =
972 nlm_host_unmonitor(host);
979 * Search for an existing NLM host that matches the given name
981 * found, create a new host. If 'addr' is non-NULL, record the remote
982 * address of the host so that we can call it back for async
990 struct nlm_host *host;
995 * The remote host is determined by caller_name.
997 TAILQ_FOREACH(host, &nlm_hosts, nh_link) {
998 if (!strcmp(host->nh_caller_name, name))
1002 if (!host) {
1003 host = nlm_create_host(name);
1004 if (!host) {
1009 refcount_acquire(&host->nh_refs);
1011 host->nh_idle_timeout = time_uptime + NLM_IDLE_TIMEOUT;
1014 * If we have an address for the host, record it so that we
1027 if (host->nh_addr.ss_len && host->nh_srvrpc.nr_client) {
1029 (struct sockaddr *) &host->nh_addr,
1031 || host->nh_vers != vers) {
1033 mtx_lock(&host->nh_lock);
1034 client = host->nh_srvrpc.nr_client;
1035 host->nh_srvrpc.nr_client = NULL;
1036 mtx_unlock(&host->nh_lock);
1042 memcpy(&host->nh_addr, addr, addr->sa_len);
1043 host->nh_vers = vers;
1050 return (host);
1054 * Search for an existing NLM host that matches the given remote
1055 * address. If none is found, create a new host with the requested
1057 * that host.
1067 struct nlm_host *host;
1090 * The remote host is determined by caller_name.
1092 TAILQ_FOREACH(host, &nlm_hosts, nh_link) {
1094 (const struct sockaddr *) &host->nh_addr))
1098 if (!host) {
1099 host = nlm_create_host(tmp);
1100 if (!host) {
1104 memcpy(&host->nh_addr, addr, addr->sa_len);
1105 host->nh_vers = vers;
1107 refcount_acquire(&host->nh_refs);
1109 host->nh_idle_timeout = time_uptime + NLM_IDLE_TIMEOUT;
1115 return (host);
1119 * Find the NLM host that matches the value of 'sysid'. If none
1125 struct nlm_host *host;
1127 TAILQ_FOREACH(host, &nlm_hosts, nh_link) {
1128 if (host->nh_sysid == sysid) {
1129 refcount_acquire(&host->nh_refs);
1130 return (host);
1137 void nlm_host_release(struct nlm_host *host)
1139 if (refcount_release(&host->nh_refs)) {
1141 * Free the host
1143 nlm_host_destroy(host);
1148 * Unregister this NLM host with the local NSM due to idleness.
1151 nlm_host_unmonitor(struct nlm_host *host)
1159 host->nh_caller_name, host->nh_sysid);
1163 * make it simpler to find the host if we are notified of a
1164 * host restart.
1166 smmonid.mon_name = host->nh_caller_name;
1184 host->nh_caller_name);
1188 host->nh_monstate = NLM_UNMONITORED;
1192 * Register this NLM host with the local NSM so that we can be
1196 nlm_host_monitor(struct nlm_host *host, int state)
1203 if (state && !host->nh_state) {
1206 * value for this host. We record it here to help
1207 * detect host reboots.
1209 host->nh_state = state;
1210 NLM_DEBUG(1, "NLM: host %s (sysid %d) has NSM state %d\n",
1211 host->nh_caller_name, host->nh_sysid, state);
1214 mtx_lock(&host->nh_lock);
1215 if (host->nh_monstate != NLM_UNMONITORED) {
1216 mtx_unlock(&host->nh_lock);
1219 host->nh_monstate = NLM_MONITORED;
1220 mtx_unlock(&host->nh_lock);
1223 host->nh_caller_name, host->nh_sysid);
1227 * make it simpler to find the host if we are notified of a
1228 * host restart.
1230 smmon.mon_id.mon_name = host->nh_caller_name;
1235 memcpy(smmon.priv, &host->nh_sysid, sizeof(host->nh_sysid));
1249 host->nh_caller_name);
1250 mtx_lock(&host->nh_lock);
1251 host->nh_monstate = NLM_MONITOR_FAILED;
1252 mtx_unlock(&host->nh_lock);
1256 host->nh_monstate = NLM_MONITORED;
1261 * running on the given host.
1264 nlm_host_get_rpc(struct nlm_host *host, bool_t isserver)
1269 mtx_lock(&host->nh_lock);
1272 rpc = &host->nh_srvrpc;
1274 rpc = &host->nh_clntrpc;
1287 mtx_unlock(&host->nh_lock);
1289 mtx_lock(&host->nh_lock);
1293 mtx_unlock(&host->nh_lock);
1294 client = nlm_get_rpc((struct sockaddr *)&host
1295 NLM_PROG, host->nh_vers);
1296 mtx_lock(&host->nh_lock);
1300 mtx_unlock(&host->nh_lock);
1302 mtx_lock(&host->nh_lock);
1313 mtx_unlock(&host->nh_lock);
1319 int nlm_host_get_sysid(struct nlm_host *host)
1322 return (host->nh_sysid);
1326 nlm_host_get_state(struct nlm_host *host)
1329 return (host->nh_state);
1546 struct nlm_host *host, *nhost;
1684 * nlm_hosts to the host (which may remove it from the list
1693 TAILQ_FOREACH_SAFE(host, &nlm_hosts, nh_link, nhost) {
1695 nlm_host_notify(host, 0);
1696 nlm_host_release(host);
1737 struct nlm_host *host;
1741 host = nlm_find_host_by_sysid(sysid);
1742 if (host) {
1743 nlm_host_notify(host, argp->state);
1744 nlm_host_release(host);
1761 nlm_get_vfs_state(struct nlm_host *host, struct svc_req *rqstp,
1777 (struct sockaddr *)&host->nh_addr, &exflags, &credanon,
1868 struct nlm_host *host, *bhost;
1876 host = nlm_find_host_by_name(argp->alock.caller_name,
1878 if (!host) {
1884 host->nh_caller_name, host->nh_sysid);
1886 nlm_check_expired_locks(host);
1887 sysid = host->nh_sysid;
1898 error = nlm_get_vfs_state(host, rqstp, &fh, &vs, accmode);
1932 * a space for the owning host's name allowing
1938 * the first four bytes of the host
1955 *rpcp = nlm_host_get_rpc(host, TRUE);
1956 nlm_host_release(host);
1966 struct nlm_host *host;
1974 host = nlm_find_host_by_name(argp->alock.caller_name,
1976 if (!host) {
1982 host->nh_caller_name, host->nh_sysid);
1984 if (monitor && host->nh_state && argp->state
1985 && host->nh_state != argp->state) {
1987 * The host rebooted without telling us. Trash its
1990 nlm_host_notify(host, argp->state);
1993 nlm_check_expired_locks(host);
1994 sysid = host->nh_sysid;
2005 error = nlm_get_vfs_state(host
2026 * First, make sure we can contact the host's NLM.
2028 client = nlm_host_get_rpc(host, TRUE);
2040 mtx_lock(&host->nh_lock);
2041 TAILQ_FOREACH(af, &host->nh_pending, af_link) {
2050 cookie.ng_sysid = host->nh_sysid;
2051 cookie.ng_cookie = host->nh_grantcookie++;
2053 mtx_unlock(&host->nh_lock);
2065 af->af_host = host;
2092 mtx_lock(&host->nh_lock);
2093 TAILQ_INSERT_TAIL(&host->nh_pending, af, af_link);
2094 mtx_unlock(&host->nh_lock);
2105 mtx_lock(&host->nh_lock);
2106 TAILQ_REMOVE(&host->nh_pending, af, af_link);
2107 mtx_unlock(&host->nh_lock);
2113 "(sysid %d)\n", af, host->nh_caller_name, sysid);
2137 nlm_host_monitor(host, argp->state);
2144 *rpcp = nlm_host_get_rpc(host, TRUE);
2145 nlm_host_release(host);
2155 struct nlm_host *host;
2163 host = nlm_find_host_by_name(argp->alock.caller_name,
2165 if (!host) {
2171 host->nh_caller_name, host->nh_sysid);
2173 nlm_check_expired_locks(host);
2174 sysid = host->nh_sysid;
2184 error = nlm_get_vfs_state(host, rqstp, &fh, &vs, (accmode_t)0);
2204 mtx_lock(&host->nh_lock);
2206 TAILQ_FOREACH(af, &host->nh_pending, af_link) {
2216 mtx_unlock(&host->nh_lock);
2229 mtx_unlock(&host->nh_lock);
2234 *rpcp = nlm_host_get_rpc(host, TRUE);
2235 nlm_host_release(host);
2245 struct nlm_host *host;
2252 host = nlm_find_host_by_name(argp->alock.caller_name,
2254 if (!host) {
2260 host->nh_caller_name, host->nh_sysid);
2262 nlm_check_expired_locks(host);
2263 sysid = host->nh_sysid;
2273 error = nlm_get_vfs_state(host, rqstp, &fh, &vs, (accmode_t)0);
2296 *rpcp = nlm_host_get_rpc(host, TRUE);
2297 nlm_host_release(host);
2306 struct nlm_host *host;
2311 host = nlm_find_host_by_addr(svc_getrpccaller(rqstp), rqstp->rq_vers);
2312 if (!host) {
2341 *rpcp = nlm_host_get_rpc(host, TRUE);
2342 nlm_host_release(host);
2349 struct nlm_host *host = NULL;
2358 host = nlm_find_host_by_sysid(ng_sysid(&argp->cookie));
2359 if (!host) {
2360 NLM_DEBUG(1, "NLM: Unknown host rejected our grant");
2364 mtx_lock(&host->nh_lock);
2365 TAILQ_FOREACH(af, &host->nh_granted, af_link)
2370 TAILQ_REMOVE(&host->nh_granted, af, af_link);
2371 mtx_unlock(&host->nh_lock);
2374 NLM_DEBUG(1, "NLM: host %s (sysid %d) replied to our grant "
2375 "with unrecognized cookie %d:%d", host->nh_caller_name,
2376 host->nh_sysid, ng_sysid(&argp->cookie),
2385 NLM_DEBUG(1, "NLM: host %s (sysid %d) rejected our grant "
2386 "and we failed to unlock (%d)", host->nh_caller_name,
2387 host->nh_sysid, error);
2391 NLM_DEBUG(5, "NLM: async lock %p rejected by host %s (sysid %d)",
2392 af, host->nh_caller_name, host->nh_sysid);
2394 NLM_DEBUG(5, "NLM: async lock %p accepted by host %s (sysid %d)",
2395 af, host->nh_caller_name, host->nh_sysid);
2401 if (host)
2402 nlm_host_release(host);
2408 struct nlm_host *host, *thost;
2410 TAILQ_FOREACH_SAFE(host, &nlm_hosts, nh_link, thost) {
2411 if (!strcmp(host->nh_caller_name, argp->name))
2412 nlm_host_notify(host, argp->state);