From 8448e56a36348bba791544bbf0a74f642c51f00c Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 9 Jun 2015 19:12:52 +0200 Subject: [PATCH 32/57] nfs: allocate and return the hashkey for the auth_cache_entry The allocation of the hashkey was never returned to the calling function. Allocating it with alloca() puts it on the stack, returning from the function makes the pointer invalid. Functions that are annotated with "inline" and call alloca(), will not always be inlined. Returning a pointer allocated with alloca() is in those cases not correct. One such confirmation was provided by GCC developer Alexandre Oliva: - http://gcc.gnu.org/ml/gcc-help/2004-04/msg00158.html It is more correct to call GF_MALLOC() and GF_FREE() for the hashkey. If this would result in preformance hit, we can always think of using alloca() again and turn make_hashkey() into a macro (yuck). Cherry picked from commit cccd1e3cce7873e873c7266af703f4f77ff4c679: > Cherry picked from commit b8b59fea7822f9ab1e10d7a3f730354fe82a6097: > > Change-Id: Ia86a1f79d33240af4713bfb92f702b0ee6e87eb7 > > BUG: 1226714 > > Signed-off-by: Niels de Vos > > Reviewed-on: http://review.gluster.org/11019 > > Reviewed-by: Kaleb KEITHLEY > > Reviewed-by: jiffin tony Thottan > > Reviewed-by: soumya k > > Tested-by: Gluster Build System > > Change-Id: Ia86a1f79d33240af4713bfb92f702b0ee6e87eb7 > BUG: 1227916 > Signed-off-by: Niels de Vos > Reviewed-on: http://review.gluster.org/11075 > Tested-by: Gluster Build System > Reviewed-by: jiffin tony Thottan BUG: 1227918 Change-Id: I1652540056731412bebf5b98eed62659c610fd90 Signed-off-by: Niels de Vos Reviewed-on: https://code.engineering.redhat.com/gerrit/50371 Reviewed-by: Soumya Koduri Reviewed-by: Jiffin Thottan --- xlators/nfs/server/src/auth-cache.c | 32 +++++++++++++++++++++++++------- 1 files changed, 25 insertions(+), 7 deletions(-) diff --git a/xlators/nfs/server/src/auth-cache.c b/xlators/nfs/server/src/auth-cache.c index 848eed5..b0cb7bf 100644 --- a/xlators/nfs/server/src/auth-cache.c +++ b/xlators/nfs/server/src/auth-cache.c @@ -27,12 +27,12 @@ struct auth_cache_entry { struct export_item *item; }; -/* Given a filehandle and an ip, creates a colon delimited hashkey that is - * allocated on the stack. +/* Given a filehandle and an ip, creates a colon delimited hashkey. */ -static inline void -make_hashkey(char *hashkey, struct nfs3_fh *fh, const char *host) +static char* +make_hashkey(struct nfs3_fh *fh, const char *host) { + char *hashkey = NULL; char exportid[256] = {0, }; char gfid[256] = {0, }; char mountid[256] = {0, }; @@ -41,11 +41,17 @@ make_hashkey(char *hashkey, struct nfs3_fh *fh, const char *host) gf_uuid_unparse (fh->exportid, exportid); gf_uuid_unparse (fh->gfid, gfid); gf_uuid_unparse (fh->mountid, mountid); + nbytes = strlen (exportid) + strlen (gfid) + strlen (host) + strlen (mountid) + 5; - hashkey = alloca (nbytes); + hashkey = GF_MALLOC (nbytes, gf_common_mt_char); + if (!hashkey) + return NULL; + snprintf (hashkey, nbytes, "%s:%s:%s:%s", exportid, gfid, mountid, host); + + return hashkey; } /** @@ -127,7 +133,11 @@ auth_cache_lookup (struct auth_cache *cache, struct nfs3_fh *fh, GF_VALIDATE_OR_GOTO (GF_NFS, timestamp, out); GF_VALIDATE_OR_GOTO (GF_NFS, can_write, out); - make_hashkey (hashkey, fh, host_addr); + hashkey = make_hashkey (fh, host_addr); + if (!hashkey) { + ret = -ENOMEM; + goto out; + } entry_data = dict_get (cache->cache_dict, hashkey); if (!entry_data) { @@ -155,6 +165,8 @@ auth_cache_lookup (struct auth_cache *cache, struct nfs3_fh *fh, ret = ENTRY_FOUND; out: + GF_FREE (hashkey); + return ret; } @@ -277,7 +289,11 @@ cache_nfs_fh (struct auth_cache *cache, struct nfs3_fh *fh, goto out; } - make_hashkey (hashkey, fh, host_addr); + hashkey = make_hashkey (fh, host_addr); + if (!hashkey) { + ret = -ENOMEM; + goto out; + } entry = auth_cache_entry_init (); if (!entry) { @@ -305,5 +321,7 @@ cache_nfs_fh (struct auth_cache *cache, struct nfs3_fh *fh, gf_msg_trace (GF_NFS, 0, "Caching file-handle (%s)", host_addr); ret = 0; out: + GF_FREE (hashkey); + return ret; } -- 1.7.1