aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/lockd/mon.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
index 740702216042..315ca07715c7 100644
--- a/fs/lockd/mon.c
+++ b/fs/lockd/mon.c
@@ -239,6 +239,30 @@ static void nsm_init_private(struct nsm_handle *nsm)
239 *p = nsm_addr_in(nsm)->sin_addr.s_addr; 239 *p = nsm_addr_in(nsm)->sin_addr.s_addr;
240} 240}
241 241
242static struct nsm_handle *nsm_create_handle(const struct sockaddr *sap,
243 const size_t salen,
244 const char *hostname,
245 const size_t hostname_len)
246{
247 struct nsm_handle *new;
248
249 new = kzalloc(sizeof(*new) + hostname_len + 1, GFP_KERNEL);
250 if (unlikely(new == NULL))
251 return NULL;
252
253 atomic_set(&new->sm_count, 1);
254 new->sm_name = (char *)(new + 1);
255 memcpy(nsm_addr(new), sap, salen);
256 new->sm_addrlen = salen;
257 nsm_init_private(new);
258 nsm_display_address((const struct sockaddr *)&new->sm_addr,
259 new->sm_addrbuf, sizeof(new->sm_addrbuf));
260 memcpy(new->sm_name, hostname, hostname_len);
261 new->sm_name[hostname_len] = '\0';
262
263 return new;
264}
265
242/** 266/**
243 * nsm_get_handle - Find or create a cached nsm_handle 267 * nsm_get_handle - Find or create a cached nsm_handle
244 * @sap: pointer to socket address of handle to find 268 * @sap: pointer to socket address of handle to find
@@ -295,19 +319,9 @@ retry:
295 } 319 }
296 spin_unlock(&nsm_lock); 320 spin_unlock(&nsm_lock);
297 321
298 nsm = kzalloc(sizeof(*nsm) + hostname_len + 1, GFP_KERNEL); 322 nsm = nsm_create_handle(sap, salen, hostname, hostname_len);
299 if (nsm == NULL) 323 if (unlikely(nsm == NULL))
300 return NULL; 324 return NULL;
301
302 memcpy(nsm_addr(nsm), sap, salen);
303 nsm->sm_addrlen = salen;
304 nsm->sm_name = (char *) (nsm + 1);
305 memcpy(nsm->sm_name, hostname, hostname_len);
306 nsm->sm_name[hostname_len] = '\0';
307 nsm_init_private(nsm);
308 nsm_display_address((struct sockaddr *)&nsm->sm_addr,
309 nsm->sm_addrbuf, sizeof(nsm->sm_addrbuf));
310 atomic_set(&nsm->sm_count, 1);
311 goto retry; 325 goto retry;
312 326
313found: 327found: