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