host.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * linux/fs/lockd/host.c
  3. *
  4. * Management for NLM peer hosts. The nlm_host struct is shared
  5. * between client and server implementation. The only reason to
  6. * do so is to reduce code bloat.
  7. *
  8. * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
  9. */
  10. #include <linux/types.h>
  11. #include <linux/slab.h>
  12. #include <linux/in.h>
  13. #include <linux/in6.h>
  14. #include <linux/sunrpc/clnt.h>
  15. #include <linux/sunrpc/addr.h>
  16. #include <linux/sunrpc/svc.h>
  17. #include <linux/lockd/lockd.h>
  18. #include <linux/mutex.h>
  19. #include <linux/sunrpc/svc_xprt.h>
  20. #include <net/ipv6.h>
  21. #include "netns.h"
  22. #define NLMDBG_FACILITY NLMDBG_HOSTCACHE
  23. #define NLM_HOST_NRHASH 32
  24. #define NLM_HOST_REBIND (60 * HZ)
  25. #define NLM_HOST_EXPIRE (300 * HZ)
  26. #define NLM_HOST_COLLECT (120 * HZ)
  27. static struct hlist_head nlm_server_hosts[NLM_HOST_NRHASH];
  28. static struct hlist_head nlm_client_hosts[NLM_HOST_NRHASH];
  29. #define for_each_host(host, pos, chain, table) \
  30. for ((chain) = (table); \
  31. (chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \
  32. hlist_for_each_entry((host), (pos), (chain), h_hash)
  33. #define for_each_host_safe(host, pos, next, chain, table) \
  34. for ((chain) = (table); \
  35. (chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \
  36. hlist_for_each_entry_safe((host), (pos), (next), \
  37. (chain), h_hash)
  38. static unsigned long nrhosts;
  39. static DEFINE_MUTEX(nlm_host_mutex);
  40. static void nlm_gc_hosts(struct net *net);
  41. struct nlm_lookup_host_info {
  42. const int server; /* search for server|client */
  43. const struct sockaddr *sap; /* address to search for */
  44. const size_t salen; /* it's length */
  45. const unsigned short protocol; /* transport to search for*/
  46. const u32 version; /* NLM version to search for */
  47. const char *hostname; /* remote's hostname */
  48. const size_t hostname_len; /* it's length */
  49. const int noresvport; /* use non-priv port */
  50. struct net *net; /* network namespace to bind */
  51. };
  52. /*
  53. * Hash function must work well on big- and little-endian platforms
  54. */
  55. static unsigned int __nlm_hash32(const __be32 n)
  56. {
  57. unsigned int hash = (__force u32)n ^ ((__force u32)n >> 16);
  58. return hash ^ (hash >> 8);
  59. }
  60. static unsigned int __nlm_hash_addr4(const struct sockaddr *sap)
  61. {
  62. const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
  63. return __nlm_hash32(sin->sin_addr.s_addr);
  64. }
  65. static unsigned int __nlm_hash_addr6(const struct sockaddr *sap)
  66. {
  67. const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
  68. const struct in6_addr addr = sin6->sin6_addr;
  69. return __nlm_hash32(addr.s6_addr32[0]) ^
  70. __nlm_hash32(addr.s6_addr32[1]) ^
  71. __nlm_hash32(addr.s6_addr32[2]) ^
  72. __nlm_hash32(addr.s6_addr32[3]);
  73. }
  74. static unsigned int nlm_hash_address(const struct sockaddr *sap)
  75. {
  76. unsigned int hash;
  77. switch (sap->sa_family) {
  78. case AF_INET:
  79. hash = __nlm_hash_addr4(sap);
  80. break;
  81. case AF_INET6:
  82. hash = __nlm_hash_addr6(sap);
  83. break;
  84. default:
  85. hash = 0;
  86. }
  87. return hash & (NLM_HOST_NRHASH - 1);
  88. }
  89. /*
  90. * Allocate and initialize an nlm_host. Common to both client and server.
  91. */
  92. static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni,
  93. struct nsm_handle *nsm)
  94. {
  95. struct nlm_host *host = NULL;
  96. unsigned long now = jiffies;
  97. if (nsm != NULL)
  98. atomic_inc(&nsm->sm_count);
  99. else {
  100. host = NULL;
  101. nsm = nsm_get_handle(ni->sap, ni->salen,
  102. ni->hostname, ni->hostname_len);
  103. if (unlikely(nsm == NULL)) {
  104. dprintk("lockd: %s failed; no nsm handle\n",
  105. __func__);
  106. goto out;
  107. }
  108. }
  109. host = kmalloc(sizeof(*host), GFP_KERNEL);
  110. if (unlikely(host == NULL)) {
  111. dprintk("lockd: %s failed; no memory\n", __func__);
  112. nsm_release(nsm);
  113. goto out;
  114. }
  115. memcpy(nlm_addr(host), ni->sap, ni->salen);
  116. host->h_addrlen = ni->salen;
  117. rpc_set_port(nlm_addr(host), 0);
  118. host->h_srcaddrlen = 0;
  119. host->h_rpcclnt = NULL;
  120. host->h_name = nsm->sm_name;
  121. host->h_version = ni->version;
  122. host->h_proto = ni->protocol;
  123. host->h_reclaiming = 0;
  124. host->h_server = ni->server;
  125. host->h_noresvport = ni->noresvport;
  126. host->h_inuse = 0;
  127. init_waitqueue_head(&host->h_gracewait);
  128. init_rwsem(&host->h_rwsem);
  129. host->h_state = 0;
  130. host->h_nsmstate = 0;
  131. host->h_pidcount = 0;
  132. atomic_set(&host->h_count, 1);
  133. mutex_init(&host->h_mutex);
  134. host->h_nextrebind = now + NLM_HOST_REBIND;
  135. host->h_expires = now + NLM_HOST_EXPIRE;
  136. INIT_LIST_HEAD(&host->h_lockowners);
  137. spin_lock_init(&host->h_lock);
  138. INIT_LIST_HEAD(&host->h_granted);
  139. INIT_LIST_HEAD(&host->h_reclaim);
  140. host->h_nsmhandle = nsm;
  141. host->h_addrbuf = nsm->sm_addrbuf;
  142. host->net = ni->net;
  143. out:
  144. return host;
  145. }
  146. /*
  147. * Destroy an nlm_host and free associated resources
  148. *
  149. * Caller must hold nlm_host_mutex.
  150. */
  151. static void nlm_destroy_host_locked(struct nlm_host *host)
  152. {
  153. struct rpc_clnt *clnt;
  154. struct lockd_net *ln = net_generic(host->net, lockd_net_id);
  155. dprintk("lockd: destroy host %s\n", host->h_name);
  156. hlist_del_init(&host->h_hash);
  157. nsm_unmonitor(host);
  158. nsm_release(host->h_nsmhandle);
  159. clnt = host->h_rpcclnt;
  160. if (clnt != NULL)
  161. rpc_shutdown_client(clnt);
  162. kfree(host);
  163. ln->nrhosts--;
  164. nrhosts--;
  165. }
  166. /**
  167. * nlmclnt_lookup_host - Find an NLM host handle matching a remote server
  168. * @sap: network address of server
  169. * @salen: length of server address
  170. * @protocol: transport protocol to use
  171. * @version: NLM protocol version
  172. * @hostname: '\0'-terminated hostname of server
  173. * @noresvport: 1 if non-privileged port should be used
  174. *
  175. * Returns an nlm_host structure that matches the passed-in
  176. * [server address, transport protocol, NLM version, server hostname].
  177. * If one doesn't already exist in the host cache, a new handle is
  178. * created and returned.
  179. */
  180. struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
  181. const size_t salen,
  182. const unsigned short protocol,
  183. const u32 version,
  184. const char *hostname,
  185. int noresvport,
  186. struct net *net)
  187. {
  188. struct nlm_lookup_host_info ni = {
  189. .server = 0,
  190. .sap = sap,
  191. .salen = salen,
  192. .protocol = protocol,
  193. .version = version,
  194. .hostname = hostname,
  195. .hostname_len = strlen(hostname),
  196. .noresvport = noresvport,
  197. .net = net,
  198. };
  199. struct hlist_head *chain;
  200. struct hlist_node *pos;
  201. struct nlm_host *host;
  202. struct nsm_handle *nsm = NULL;
  203. struct lockd_net *ln = net_generic(net, lockd_net_id);
  204. dprintk("lockd: %s(host='%s', vers=%u, proto=%s)\n", __func__,
  205. (hostname ? hostname : "<none>"), version,
  206. (protocol == IPPROTO_UDP ? "udp" : "tcp"));
  207. mutex_lock(&nlm_host_mutex);
  208. chain = &nlm_client_hosts[nlm_hash_address(sap)];
  209. hlist_for_each_entry(host, pos, chain, h_hash) {
  210. if (host->net != net)
  211. continue;
  212. if (!rpc_cmp_addr(nlm_addr(host), sap))
  213. continue;
  214. /* Same address. Share an NSM handle if we already have one */
  215. if (nsm == NULL)
  216. nsm = host->h_nsmhandle;
  217. if (host->h_proto != protocol)
  218. continue;
  219. if (host->h_version != version)
  220. continue;
  221. nlm_get_host(host);
  222. dprintk("lockd: %s found host %s (%s)\n", __func__,
  223. host->h_name, host->h_addrbuf);
  224. goto out;
  225. }
  226. host = nlm_alloc_host(&ni, nsm);
  227. if (unlikely(host == NULL))
  228. goto out;
  229. hlist_add_head(&host->h_hash, chain);
  230. ln->nrhosts++;
  231. nrhosts++;
  232. dprintk("lockd: %s created host %s (%s)\n", __func__,
  233. host->h_name, host->h_addrbuf);
  234. out:
  235. mutex_unlock(&nlm_host_mutex);
  236. return host;
  237. }
  238. /**
  239. * nlmclnt_release_host - release client nlm_host
  240. * @host: nlm_host to release
  241. *
  242. */
  243. void nlmclnt_release_host(struct nlm_host *host)
  244. {
  245. if (host == NULL)
  246. return;
  247. dprintk("lockd: release client host %s\n", host->h_name);
  248. WARN_ON_ONCE(host->h_server);
  249. if (atomic_dec_and_test(&host->h_count)) {
  250. WARN_ON_ONCE(!list_empty(&host->h_lockowners));
  251. WARN_ON_ONCE(!list_empty(&host->h_granted));
  252. WARN_ON_ONCE(!list_empty(&host->h_reclaim));
  253. mutex_lock(&nlm_host_mutex);
  254. nlm_destroy_host_locked(host);
  255. mutex_unlock(&nlm_host_mutex);
  256. }
  257. }
  258. /**
  259. * nlmsvc_lookup_host - Find an NLM host handle matching a remote client
  260. * @rqstp: incoming NLM request
  261. * @hostname: name of client host
  262. * @hostname_len: length of client hostname
  263. *
  264. * Returns an nlm_host structure that matches the [client address,
  265. * transport protocol, NLM version, client hostname] of the passed-in
  266. * NLM request. If one doesn't already exist in the host cache, a
  267. * new handle is created and returned.
  268. *
  269. * Before possibly creating a new nlm_host, construct a sockaddr
  270. * for a specific source address in case the local system has
  271. * multiple network addresses. The family of the address in
  272. * rq_daddr is guaranteed to be the same as the family of the
  273. * address in rq_addr, so it's safe to use the same family for
  274. * the source address.
  275. */
  276. struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
  277. const char *hostname,
  278. const size_t hostname_len)
  279. {
  280. struct hlist_head *chain;
  281. struct hlist_node *pos;
  282. struct nlm_host *host = NULL;
  283. struct nsm_handle *nsm = NULL;
  284. struct sockaddr *src_sap = svc_daddr(rqstp);
  285. size_t src_len = rqstp->rq_daddrlen;
  286. struct net *net = SVC_NET(rqstp);
  287. struct nlm_lookup_host_info ni = {
  288. .server = 1,
  289. .sap = svc_addr(rqstp),
  290. .salen = rqstp->rq_addrlen,
  291. .protocol = rqstp->rq_prot,
  292. .version = rqstp->rq_vers,
  293. .hostname = hostname,
  294. .hostname_len = hostname_len,
  295. .net = net,
  296. };
  297. struct lockd_net *ln = net_generic(net, lockd_net_id);
  298. dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
  299. (int)hostname_len, hostname, rqstp->rq_vers,
  300. (rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp"));
  301. mutex_lock(&nlm_host_mutex);
  302. if (time_after_eq(jiffies, ln->next_gc))
  303. nlm_gc_hosts(net);
  304. chain = &nlm_server_hosts[nlm_hash_address(ni.sap)];
  305. hlist_for_each_entry(host, pos, chain, h_hash) {
  306. if (host->net != net)
  307. continue;
  308. if (!rpc_cmp_addr(nlm_addr(host), ni.sap))
  309. continue;
  310. /* Same address. Share an NSM handle if we already have one */
  311. if (nsm == NULL)
  312. nsm = host->h_nsmhandle;
  313. if (host->h_proto != ni.protocol)
  314. continue;
  315. if (host->h_version != ni.version)
  316. continue;
  317. if (!rpc_cmp_addr(nlm_srcaddr(host), src_sap))
  318. continue;
  319. /* Move to head of hash chain. */
  320. hlist_del(&host->h_hash);
  321. hlist_add_head(&host->h_hash, chain);
  322. nlm_get_host(host);
  323. dprintk("lockd: %s found host %s (%s)\n",
  324. __func__, host->h_name, host->h_addrbuf);
  325. goto out;
  326. }
  327. host = nlm_alloc_host(&ni, nsm);
  328. if (unlikely(host == NULL))
  329. goto out;
  330. memcpy(nlm_srcaddr(host), src_sap, src_len);
  331. host->h_srcaddrlen = src_len;
  332. hlist_add_head(&host->h_hash, chain);
  333. ln->nrhosts++;
  334. nrhosts++;
  335. dprintk("lockd: %s created host %s (%s)\n",
  336. __func__, host->h_name, host->h_addrbuf);
  337. out:
  338. mutex_unlock(&nlm_host_mutex);
  339. return host;
  340. }
  341. /**
  342. * nlmsvc_release_host - release server nlm_host
  343. * @host: nlm_host to release
  344. *
  345. * Host is destroyed later in nlm_gc_host().
  346. */
  347. void nlmsvc_release_host(struct nlm_host *host)
  348. {
  349. if (host == NULL)
  350. return;
  351. dprintk("lockd: release server host %s\n", host->h_name);
  352. WARN_ON_ONCE(!host->h_server);
  353. atomic_dec(&host->h_count);
  354. }
  355. /*
  356. * Create the NLM RPC client for an NLM peer
  357. */
  358. struct rpc_clnt *
  359. nlm_bind_host(struct nlm_host *host)
  360. {
  361. struct rpc_clnt *clnt;
  362. dprintk("lockd: nlm_bind_host %s (%s)\n",
  363. host->h_name, host->h_addrbuf);
  364. /* Lock host handle */
  365. mutex_lock(&host->h_mutex);
  366. /* If we've already created an RPC client, check whether
  367. * RPC rebind is required
  368. */
  369. if ((clnt = host->h_rpcclnt) != NULL) {
  370. if (time_after_eq(jiffies, host->h_nextrebind)) {
  371. rpc_force_rebind(clnt);
  372. host->h_nextrebind = jiffies + NLM_HOST_REBIND;
  373. dprintk("lockd: next rebind in %lu jiffies\n",
  374. host->h_nextrebind - jiffies);
  375. }
  376. } else {
  377. unsigned long increment = nlmsvc_timeout;
  378. struct rpc_timeout timeparms = {
  379. .to_initval = increment,
  380. .to_increment = increment,
  381. .to_maxval = increment * 6UL,
  382. .to_retries = 5U,
  383. };
  384. struct rpc_create_args args = {
  385. .net = host->net,
  386. .protocol = host->h_proto,
  387. .address = nlm_addr(host),
  388. .addrsize = host->h_addrlen,
  389. .timeout = &timeparms,
  390. .servername = host->h_name,
  391. .program = &nlm_program,
  392. .version = host->h_version,
  393. .authflavor = RPC_AUTH_UNIX,
  394. .flags = (RPC_CLNT_CREATE_NOPING |
  395. RPC_CLNT_CREATE_AUTOBIND),
  396. };
  397. /*
  398. * lockd retries server side blocks automatically so we want
  399. * those to be soft RPC calls. Client side calls need to be
  400. * hard RPC tasks.
  401. */
  402. if (!host->h_server)
  403. args.flags |= RPC_CLNT_CREATE_HARDRTRY;
  404. if (host->h_noresvport)
  405. args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
  406. if (host->h_srcaddrlen)
  407. args.saddress = nlm_srcaddr(host);
  408. clnt = rpc_create(&args);
  409. if (!IS_ERR(clnt))
  410. host->h_rpcclnt = clnt;
  411. else {
  412. printk("lockd: couldn't create RPC handle for %s\n", host->h_name);
  413. clnt = NULL;
  414. }
  415. }
  416. mutex_unlock(&host->h_mutex);
  417. return clnt;
  418. }
  419. /*
  420. * Force a portmap lookup of the remote lockd port
  421. */
  422. void
  423. nlm_rebind_host(struct nlm_host *host)
  424. {
  425. dprintk("lockd: rebind host %s\n", host->h_name);
  426. if (host->h_rpcclnt && time_after_eq(jiffies, host->h_nextrebind)) {
  427. rpc_force_rebind(host->h_rpcclnt);
  428. host->h_nextrebind = jiffies + NLM_HOST_REBIND;
  429. }
  430. }
  431. /*
  432. * Increment NLM host count
  433. */
  434. struct nlm_host * nlm_get_host(struct nlm_host *host)
  435. {
  436. if (host) {
  437. dprintk("lockd: get host %s\n", host->h_name);
  438. atomic_inc(&host->h_count);
  439. host->h_expires = jiffies + NLM_HOST_EXPIRE;
  440. }
  441. return host;
  442. }
  443. static struct nlm_host *next_host_state(struct hlist_head *cache,
  444. struct nsm_handle *nsm,
  445. const struct nlm_reboot *info)
  446. {
  447. struct nlm_host *host;
  448. struct hlist_head *chain;
  449. struct hlist_node *pos;
  450. mutex_lock(&nlm_host_mutex);
  451. for_each_host(host, pos, chain, cache) {
  452. if (host->h_nsmhandle == nsm
  453. && host->h_nsmstate != info->state) {
  454. host->h_nsmstate = info->state;
  455. host->h_state++;
  456. nlm_get_host(host);
  457. mutex_unlock(&nlm_host_mutex);
  458. return host;
  459. }
  460. }
  461. mutex_unlock(&nlm_host_mutex);
  462. return NULL;
  463. }
  464. /**
  465. * nlm_host_rebooted - Release all resources held by rebooted host
  466. * @info: pointer to decoded results of NLM_SM_NOTIFY call
  467. *
  468. * We were notified that the specified host has rebooted. Release
  469. * all resources held by that peer.
  470. */
  471. void nlm_host_rebooted(const struct nlm_reboot *info)
  472. {
  473. struct nsm_handle *nsm;
  474. struct nlm_host *host;
  475. nsm = nsm_reboot_lookup(info);
  476. if (unlikely(nsm == NULL))
  477. return;
  478. /* Mark all hosts tied to this NSM state as having rebooted.
  479. * We run the loop repeatedly, because we drop the host table
  480. * lock for this.
  481. * To avoid processing a host several times, we match the nsmstate.
  482. */
  483. while ((host = next_host_state(nlm_server_hosts, nsm, info)) != NULL) {
  484. nlmsvc_free_host_resources(host);
  485. nlmsvc_release_host(host);
  486. }
  487. while ((host = next_host_state(nlm_client_hosts, nsm, info)) != NULL) {
  488. nlmclnt_recovery(host);
  489. nlmclnt_release_host(host);
  490. }
  491. nsm_release(nsm);
  492. }
  493. static void nlm_complain_hosts(struct net *net)
  494. {
  495. struct hlist_head *chain;
  496. struct hlist_node *pos;
  497. struct nlm_host *host;
  498. if (net) {
  499. struct lockd_net *ln = net_generic(net, lockd_net_id);
  500. if (ln->nrhosts == 0)
  501. return;
  502. printk(KERN_WARNING "lockd: couldn't shutdown host module for net %p!\n", net);
  503. dprintk("lockd: %lu hosts left in net %p:\n", ln->nrhosts, net);
  504. } else {
  505. if (nrhosts == 0)
  506. return;
  507. printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
  508. dprintk("lockd: %lu hosts left:\n", nrhosts);
  509. }
  510. for_each_host(host, pos, chain, nlm_server_hosts) {
  511. if (net && host->net != net)
  512. continue;
  513. dprintk(" %s (cnt %d use %d exp %ld net %p)\n",
  514. host->h_name, atomic_read(&host->h_count),
  515. host->h_inuse, host->h_expires, host->net);
  516. }
  517. }
  518. void
  519. nlm_shutdown_hosts_net(struct net *net)
  520. {
  521. struct hlist_head *chain;
  522. struct hlist_node *pos;
  523. struct nlm_host *host;
  524. mutex_lock(&nlm_host_mutex);
  525. /* First, make all hosts eligible for gc */
  526. dprintk("lockd: nuking all hosts in net %p...\n", net);
  527. for_each_host(host, pos, chain, nlm_server_hosts) {
  528. if (net && host->net != net)
  529. continue;
  530. host->h_expires = jiffies - 1;
  531. if (host->h_rpcclnt) {
  532. rpc_shutdown_client(host->h_rpcclnt);
  533. host->h_rpcclnt = NULL;
  534. }
  535. }
  536. /* Then, perform a garbage collection pass */
  537. nlm_gc_hosts(net);
  538. mutex_unlock(&nlm_host_mutex);
  539. nlm_complain_hosts(net);
  540. }
  541. /*
  542. * Shut down the hosts module.
  543. * Note that this routine is called only at server shutdown time.
  544. */
  545. void
  546. nlm_shutdown_hosts(void)
  547. {
  548. dprintk("lockd: shutting down host module\n");
  549. nlm_shutdown_hosts_net(NULL);
  550. }
  551. /*
  552. * Garbage collect any unused NLM hosts.
  553. * This GC combines reference counting for async operations with
  554. * mark & sweep for resources held by remote clients.
  555. */
  556. static void
  557. nlm_gc_hosts(struct net *net)
  558. {
  559. struct hlist_head *chain;
  560. struct hlist_node *pos, *next;
  561. struct nlm_host *host;
  562. dprintk("lockd: host garbage collection for net %p\n", net);
  563. for_each_host(host, pos, chain, nlm_server_hosts) {
  564. if (net && host->net != net)
  565. continue;
  566. host->h_inuse = 0;
  567. }
  568. /* Mark all hosts that hold locks, blocks or shares */
  569. nlmsvc_mark_resources(net);
  570. for_each_host_safe(host, pos, next, chain, nlm_server_hosts) {
  571. if (net && host->net != net)
  572. continue;
  573. if (atomic_read(&host->h_count) || host->h_inuse
  574. || time_before(jiffies, host->h_expires)) {
  575. dprintk("nlm_gc_hosts skipping %s "
  576. "(cnt %d use %d exp %ld net %p)\n",
  577. host->h_name, atomic_read(&host->h_count),
  578. host->h_inuse, host->h_expires, host->net);
  579. continue;
  580. }
  581. nlm_destroy_host_locked(host);
  582. }
  583. if (net) {
  584. struct lockd_net *ln = net_generic(net, lockd_net_id);
  585. ln->next_gc = jiffies + NLM_HOST_COLLECT;
  586. }
  587. }