From 44d860c7061f7ef375001251876d91c2ec2db86f Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 8 May 2015 00:05:25 +0200 Subject: nfs: allocate the auth_cache->cache_dict on auth_cache_init() It seems possible that auth_cache->cache_dict is not always allocated before it is accessed. Instead of allocating the dict upon the 1st access, just create it in auth_cache_init(). Cherry picked from commit eb8847703b8560a045e7ed0336f895bcceda98ea: > Change-Id: I00e60522478b433cb0aae0c1f0948eac544dfd2b > URL: http://thread.gmane.org/gmane.comp.file-systems.gluster.devel/10710 > BUG: 1143880 > Signed-off-by: Niels de Vos > Reviewed-on: http://review.gluster.org/10600 > Tested-by: Gluster Build System > Reviewed-by: Kaleb KEITHLEY > Reviewed-by: jiffin tony Thottan > Tested-by: NetBSD Build System Change-Id: I00e60522478b433cb0aae0c1f0948eac544dfd2b BUG: 1212182 Signed-off-by: Niels de Vos Reviewed-on: http://review.gluster.org/10655 Reviewed-by: Kaleb KEITHLEY Tested-by: Gluster Build System --- xlators/nfs/server/src/auth-cache.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'xlators') diff --git a/xlators/nfs/server/src/auth-cache.c b/xlators/nfs/server/src/auth-cache.c index b33dc96db6f..848eed5e8fb 100644 --- a/xlators/nfs/server/src/auth-cache.c +++ b/xlators/nfs/server/src/auth-cache.c @@ -63,6 +63,13 @@ auth_cache_init (time_t ttl_sec) GF_VALIDATE_OR_GOTO ("auth-cache", cache, out); + cache->cache_dict = dict_new (); + if (!cache->cache_dict) { + GF_FREE (cache); + cache = NULL; + goto out; + } + cache->ttl_sec = ttl_sec; out: return cache; @@ -152,9 +159,7 @@ out: } /** - * auth_cache_purge -- Purge the dict in the cache and set - * the dict pointer to NULL. It will be allocated - * on the first insert into the dict. + * auth_cache_purge -- Purge the dict in the cache and create a new empty one. * * @cache: Cache to purge * @@ -162,10 +167,10 @@ out: void auth_cache_purge (struct auth_cache *cache) { - dict_t *new_cache_dict = NULL; + dict_t *new_cache_dict = dict_new (); dict_t *old_cache_dict = cache->cache_dict; - if (!cache || !cache->cache_dict) + if (!cache) goto out; (void)__sync_lock_test_and_set (&cache->cache_dict, new_cache_dict); @@ -264,15 +269,6 @@ cache_nfs_fh (struct auth_cache *cache, struct nfs3_fh *fh, GF_VALIDATE_OR_GOTO (GF_NFS, cache, out); GF_VALIDATE_OR_GOTO (GF_NFS, fh, out); - /* If a dict has not been allocated already, allocate it. */ - if (!cache->cache_dict) { - cache->cache_dict = dict_new (); - if (!cache->cache_dict) { - ret = -ENOMEM; - goto out; - } - } - /* If we could already find it in the cache, just return */ ret = auth_cache_lookup (cache, fh, host_addr, ×tamp, &can_write); if (ret == 0) { -- cgit