diff options
Diffstat (limited to 'fs/lockd/host.c')
-rw-r--r-- | fs/lockd/host.c | 110 |
1 files changed, 65 insertions, 45 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c index 2dbf1392acfc..1911f34be976 100644 --- a/fs/lockd/host.c +++ b/fs/lockd/host.c | |||
@@ -100,6 +100,68 @@ static unsigned int nlm_hash_address(const struct sockaddr *sap) | |||
100 | } | 100 | } |
101 | 101 | ||
102 | /* | 102 | /* |
103 | * Allocate and initialize an nlm_host. Common to both client and server. | ||
104 | */ | ||
105 | static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni, | ||
106 | struct nsm_handle *nsm) | ||
107 | { | ||
108 | struct nlm_host *host = NULL; | ||
109 | unsigned long now = jiffies; | ||
110 | |||
111 | if (nsm != NULL) | ||
112 | atomic_inc(&nsm->sm_count); | ||
113 | else { | ||
114 | host = NULL; | ||
115 | nsm = nsm_get_handle(ni->sap, ni->salen, | ||
116 | ni->hostname, ni->hostname_len); | ||
117 | if (unlikely(nsm == NULL)) { | ||
118 | dprintk("lockd: %s failed; no nsm handle\n", | ||
119 | __func__); | ||
120 | goto out; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | host = kmalloc(sizeof(*host), GFP_KERNEL); | ||
125 | if (unlikely(host == NULL)) { | ||
126 | dprintk("lockd: %s failed; no memory\n", __func__); | ||
127 | nsm_release(nsm); | ||
128 | goto out; | ||
129 | } | ||
130 | |||
131 | memcpy(nlm_addr(host), ni->sap, ni->salen); | ||
132 | host->h_addrlen = ni->salen; | ||
133 | rpc_set_port(nlm_addr(host), 0); | ||
134 | host->h_srcaddrlen = 0; | ||
135 | |||
136 | host->h_rpcclnt = NULL; | ||
137 | host->h_name = nsm->sm_name; | ||
138 | host->h_version = ni->version; | ||
139 | host->h_proto = ni->protocol; | ||
140 | host->h_reclaiming = 0; | ||
141 | host->h_server = ni->server; | ||
142 | host->h_noresvport = ni->noresvport; | ||
143 | host->h_inuse = 0; | ||
144 | init_waitqueue_head(&host->h_gracewait); | ||
145 | init_rwsem(&host->h_rwsem); | ||
146 | host->h_state = 0; | ||
147 | host->h_nsmstate = 0; | ||
148 | host->h_pidcount = 0; | ||
149 | atomic_set(&host->h_count, 1); | ||
150 | mutex_init(&host->h_mutex); | ||
151 | host->h_nextrebind = now + NLM_HOST_REBIND; | ||
152 | host->h_expires = now + NLM_HOST_EXPIRE; | ||
153 | INIT_LIST_HEAD(&host->h_lockowners); | ||
154 | spin_lock_init(&host->h_lock); | ||
155 | INIT_LIST_HEAD(&host->h_granted); | ||
156 | INIT_LIST_HEAD(&host->h_reclaim); | ||
157 | host->h_nsmhandle = nsm; | ||
158 | host->h_addrbuf = nsm->sm_addrbuf; | ||
159 | |||
160 | out: | ||
161 | return host; | ||
162 | } | ||
163 | |||
164 | /* | ||
103 | * Common host lookup routine for server & client | 165 | * Common host lookup routine for server & client |
104 | */ | 166 | */ |
105 | static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni) | 167 | static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni) |
@@ -150,55 +212,13 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni) | |||
150 | goto out; | 212 | goto out; |
151 | } | 213 | } |
152 | 214 | ||
153 | /* | 215 | host = nlm_alloc_host(ni, nsm); |
154 | * The host wasn't in our hash table. If we don't | 216 | if (unlikely(host == NULL)) |
155 | * have an NSM handle for it yet, create one. | ||
156 | */ | ||
157 | if (nsm) | ||
158 | atomic_inc(&nsm->sm_count); | ||
159 | else { | ||
160 | host = NULL; | ||
161 | nsm = nsm_get_handle(ni->sap, ni->salen, | ||
162 | ni->hostname, ni->hostname_len); | ||
163 | if (!nsm) { | ||
164 | dprintk("lockd: nlm_lookup_host failed; " | ||
165 | "no nsm handle\n"); | ||
166 | goto out; | ||
167 | } | ||
168 | } | ||
169 | |||
170 | host = kzalloc(sizeof(*host), GFP_KERNEL); | ||
171 | if (!host) { | ||
172 | nsm_release(nsm); | ||
173 | dprintk("lockd: nlm_lookup_host failed; no memory\n"); | ||
174 | goto out; | 217 | goto out; |
175 | } | 218 | |
176 | host->h_name = nsm->sm_name; | ||
177 | host->h_addrbuf = nsm->sm_addrbuf; | ||
178 | memcpy(nlm_addr(host), ni->sap, ni->salen); | ||
179 | host->h_addrlen = ni->salen; | ||
180 | rpc_set_port(nlm_addr(host), 0); | ||
181 | memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len); | 219 | memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len); |
182 | host->h_srcaddrlen = ni->src_len; | 220 | host->h_srcaddrlen = ni->src_len; |
183 | host->h_version = ni->version; | ||
184 | host->h_proto = ni->protocol; | ||
185 | host->h_rpcclnt = NULL; | ||
186 | mutex_init(&host->h_mutex); | ||
187 | host->h_nextrebind = jiffies + NLM_HOST_REBIND; | ||
188 | host->h_expires = jiffies + NLM_HOST_EXPIRE; | ||
189 | atomic_set(&host->h_count, 1); | ||
190 | init_waitqueue_head(&host->h_gracewait); | ||
191 | init_rwsem(&host->h_rwsem); | ||
192 | host->h_state = 0; /* pseudo NSM state */ | ||
193 | host->h_nsmstate = 0; /* real NSM state */ | ||
194 | host->h_nsmhandle = nsm; | ||
195 | host->h_server = ni->server; | ||
196 | host->h_noresvport = ni->noresvport; | ||
197 | hlist_add_head(&host->h_hash, chain); | 221 | hlist_add_head(&host->h_hash, chain); |
198 | INIT_LIST_HEAD(&host->h_lockowners); | ||
199 | spin_lock_init(&host->h_lock); | ||
200 | INIT_LIST_HEAD(&host->h_granted); | ||
201 | INIT_LIST_HEAD(&host->h_reclaim); | ||
202 | 222 | ||
203 | nrhosts++; | 223 | nrhosts++; |
204 | 224 | ||