diff options
Diffstat (limited to 'fs/lockd/host.c')
-rw-r--r-- | fs/lockd/host.c | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c index 1d523c1a7b62..dbdeaa88d2fa 100644 --- a/fs/lockd/host.c +++ b/fs/lockd/host.c | |||
@@ -32,12 +32,6 @@ static int nrhosts; | |||
32 | static DEFINE_MUTEX(nlm_host_mutex); | 32 | static DEFINE_MUTEX(nlm_host_mutex); |
33 | 33 | ||
34 | static void nlm_gc_hosts(void); | 34 | static void nlm_gc_hosts(void); |
35 | static struct nsm_handle *nsm_find(const struct sockaddr *sap, | ||
36 | const size_t salen, | ||
37 | const char *hostname, | ||
38 | const size_t hostname_len, | ||
39 | const int create); | ||
40 | static void nsm_release(struct nsm_handle *nsm); | ||
41 | 35 | ||
42 | struct nlm_lookup_host_info { | 36 | struct nlm_lookup_host_info { |
43 | const int server; /* search for server|client */ | 37 | const int server; /* search for server|client */ |
@@ -106,43 +100,6 @@ static void nlm_clear_port(struct sockaddr *sap) | |||
106 | } | 100 | } |
107 | } | 101 | } |
108 | 102 | ||
109 | static void nlm_display_ipv4_address(const struct sockaddr *sap, char *buf, | ||
110 | const size_t len) | ||
111 | { | ||
112 | const struct sockaddr_in *sin = (struct sockaddr_in *)sap; | ||
113 | snprintf(buf, len, "%pI4", &sin->sin_addr.s_addr); | ||
114 | } | ||
115 | |||
116 | static void nlm_display_ipv6_address(const struct sockaddr *sap, char *buf, | ||
117 | const size_t len) | ||
118 | { | ||
119 | const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; | ||
120 | |||
121 | if (ipv6_addr_v4mapped(&sin6->sin6_addr)) | ||
122 | snprintf(buf, len, "%pI4", &sin6->sin6_addr.s6_addr32[3]); | ||
123 | else if (sin6->sin6_scope_id != 0) | ||
124 | snprintf(buf, len, "%pI6%%%u", &sin6->sin6_addr, | ||
125 | sin6->sin6_scope_id); | ||
126 | else | ||
127 | snprintf(buf, len, "%pI6", &sin6->sin6_addr); | ||
128 | } | ||
129 | |||
130 | static void nlm_display_address(const struct sockaddr *sap, | ||
131 | char *buf, const size_t len) | ||
132 | { | ||
133 | switch (sap->sa_family) { | ||
134 | case AF_INET: | ||
135 | nlm_display_ipv4_address(sap, buf, len); | ||
136 | break; | ||
137 | case AF_INET6: | ||
138 | nlm_display_ipv6_address(sap, buf, len); | ||
139 | break; | ||
140 | default: | ||
141 | snprintf(buf, len, "unsupported address family"); | ||
142 | break; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | /* | 103 | /* |
147 | * Common host lookup routine for server & client | 104 | * Common host lookup routine for server & client |
148 | */ | 105 | */ |
@@ -635,88 +592,3 @@ nlm_gc_hosts(void) | |||
635 | 592 | ||
636 | next_gc = jiffies + NLM_HOST_COLLECT; | 593 | next_gc = jiffies + NLM_HOST_COLLECT; |
637 | } | 594 | } |
638 | |||
639 | |||
640 | /* | ||
641 | * Manage NSM handles | ||
642 | */ | ||
643 | static LIST_HEAD(nsm_handles); | ||
644 | static DEFINE_SPINLOCK(nsm_lock); | ||
645 | |||
646 | static struct nsm_handle *nsm_find(const struct sockaddr *sap, | ||
647 | const size_t salen, | ||
648 | const char *hostname, | ||
649 | const size_t hostname_len, | ||
650 | const int create) | ||
651 | { | ||
652 | struct nsm_handle *nsm = NULL; | ||
653 | struct nsm_handle *pos; | ||
654 | |||
655 | if (!sap) | ||
656 | return NULL; | ||
657 | |||
658 | if (hostname && memchr(hostname, '/', hostname_len) != NULL) { | ||
659 | if (printk_ratelimit()) { | ||
660 | printk(KERN_WARNING "Invalid hostname \"%.*s\" " | ||
661 | "in NFS lock request\n", | ||
662 | (int)hostname_len, hostname); | ||
663 | } | ||
664 | return NULL; | ||
665 | } | ||
666 | |||
667 | retry: | ||
668 | spin_lock(&nsm_lock); | ||
669 | list_for_each_entry(pos, &nsm_handles, sm_link) { | ||
670 | |||
671 | if (hostname && nsm_use_hostnames) { | ||
672 | if (strlen(pos->sm_name) != hostname_len | ||
673 | || memcmp(pos->sm_name, hostname, hostname_len)) | ||
674 | continue; | ||
675 | } else if (!nlm_cmp_addr(nsm_addr(pos), sap)) | ||
676 | continue; | ||
677 | atomic_inc(&pos->sm_count); | ||
678 | kfree(nsm); | ||
679 | nsm = pos; | ||
680 | goto found; | ||
681 | } | ||
682 | if (nsm) { | ||
683 | list_add(&nsm->sm_link, &nsm_handles); | ||
684 | goto found; | ||
685 | } | ||
686 | spin_unlock(&nsm_lock); | ||
687 | |||
688 | if (!create) | ||
689 | return NULL; | ||
690 | |||
691 | nsm = kzalloc(sizeof(*nsm) + hostname_len + 1, GFP_KERNEL); | ||
692 | if (nsm == NULL) | ||
693 | return NULL; | ||
694 | |||
695 | memcpy(nsm_addr(nsm), sap, salen); | ||
696 | nsm->sm_addrlen = salen; | ||
697 | nsm->sm_name = (char *) (nsm + 1); | ||
698 | memcpy(nsm->sm_name, hostname, hostname_len); | ||
699 | nsm->sm_name[hostname_len] = '\0'; | ||
700 | nlm_display_address((struct sockaddr *)&nsm->sm_addr, | ||
701 | nsm->sm_addrbuf, sizeof(nsm->sm_addrbuf)); | ||
702 | atomic_set(&nsm->sm_count, 1); | ||
703 | goto retry; | ||
704 | |||
705 | found: | ||
706 | spin_unlock(&nsm_lock); | ||
707 | return nsm; | ||
708 | } | ||
709 | |||
710 | /* | ||
711 | * Release an NSM handle | ||
712 | */ | ||
713 | static void nsm_release(struct nsm_handle *nsm) | ||
714 | { | ||
715 | if (!nsm) | ||
716 | return; | ||
717 | if (atomic_dec_and_lock(&nsm->sm_count, &nsm_lock)) { | ||
718 | list_del(&nsm->sm_link); | ||
719 | spin_unlock(&nsm_lock); | ||
720 | kfree(nsm); | ||
721 | } | ||
722 | } | ||