Signed-off-by: Steve Dickson <steved(a)redhat.com>
---
...FSv4-Reduce-the-footprint-of-the-idmapper.patch | 46 ++++++++
...ther-reduce-the-footprint-of-the-idmapper.patch | 109 ++++++++++++++++++++
kernel.spec | 7 ++
3 files changed, 162 insertions(+), 0 deletions(-)
create mode 100644 0001-NFSv4-Reduce-the-footprint-of-the-idmapper.patch
create mode 100644 0002-NFSv4-Further-reduce-the-footprint-of-the-idmapper.patch
diff --git a/0001-NFSv4-Reduce-the-footprint-of-the-idmapper.patch
b/0001-NFSv4-Reduce-the-footprint-of-the-idmapper.patch
new file mode 100644
index 0000000..4110ef9
--- /dev/null
+++ b/0001-NFSv4-Reduce-the-footprint-of-the-idmapper.patch
@@ -0,0 +1,46 @@
+diff -up linux-3.2.noarch/fs/nfs/idmap.c.orig linux-3.2.noarch/fs/nfs/idmap.c
+--- linux-3.2.noarch/fs/nfs/idmap.c.orig 2012-02-07 07:12:52.585471833 -0500
++++ linux-3.2.noarch/fs/nfs/idmap.c 2012-03-14 13:08:37.462928792 -0400
+@@ -360,7 +360,7 @@ struct idmap_hashent {
+ unsigned long ih_expires;
+ __u32 ih_id;
+ size_t ih_namelen;
+- char ih_name[IDMAP_NAMESZ];
++ const char *ih_name;
+ };
+
+ struct idmap_hashtable {
+@@ -424,11 +424,16 @@ void
+ nfs_idmap_delete(struct nfs_client *clp)
+ {
+ struct idmap *idmap = clp->cl_idmap;
++ int i;
+
+ if (!idmap)
+ return;
+ rpc_unlink(idmap->idmap_dentry);
+ clp->cl_idmap = NULL;
++ for (i = 0; i < ARRAY_SIZE(idmap->idmap_user_hash.h_entries); i++)
++ kfree(idmap->idmap_user_hash.h_entries[i].ih_name);
++ for (i = 0; i < ARRAY_SIZE(idmap->idmap_group_hash.h_entries); i++)
++ kfree(idmap->idmap_group_hash.h_entries[i].ih_name);
+ kfree(idmap);
+ }
+
+@@ -491,9 +496,14 @@ static void
+ idmap_update_entry(struct idmap_hashent *he, const char *name,
+ size_t namelen, __u32 id)
+ {
++ char *str = kmalloc(namelen + 1, GFP_KERNEL);
++ if (str == NULL)
++ return;
++ kfree(he->ih_name);
+ he->ih_id = id;
+- memcpy(he->ih_name, name, namelen);
+- he->ih_name[namelen] = '\0';
++ memcpy(str, name, namelen);
++ str[namelen] = '\0';
++ he->ih_name = str;
+ he->ih_namelen = namelen;
+ he->ih_expires = jiffies + nfs_idmap_cache_timeout;
+ }
diff --git a/0002-NFSv4-Further-reduce-the-footprint-of-the-idmapper.patch
b/0002-NFSv4-Further-reduce-the-footprint-of-the-idmapper.patch
new file mode 100644
index 0000000..42d1052
--- /dev/null
+++ b/0002-NFSv4-Further-reduce-the-footprint-of-the-idmapper.patch
@@ -0,0 +1,109 @@
+diff -up linux-3.2.noarch/fs/nfs/idmap.c.orig linux-3.2.noarch/fs/nfs/idmap.c
+--- linux-3.2.noarch/fs/nfs/idmap.c.orig 2012-03-14 13:08:37.462928792 -0400
++++ linux-3.2.noarch/fs/nfs/idmap.c 2012-03-14 13:10:17.076030982 -0400
+@@ -365,7 +365,7 @@ struct idmap_hashent {
+
+ struct idmap_hashtable {
+ __u8 h_type;
+- struct idmap_hashent h_entries[IDMAP_HASH_SZ];
++ struct idmap_hashent *h_entries;
+ };
+
+ struct idmap {
+@@ -420,20 +420,39 @@ nfs_idmap_new(struct nfs_client *clp)
+ return 0;
+ }
+
++static void
++idmap_alloc_hashtable(struct idmap_hashtable *h)
++{
++ if (h->h_entries != NULL)
++ return;
++ h->h_entries = kcalloc(IDMAP_HASH_SZ,
++ sizeof(*h->h_entries),
++ GFP_KERNEL);
++}
++
++static void
++idmap_free_hashtable(struct idmap_hashtable *h)
++{
++ int i;
++
++ if (h->h_entries == NULL)
++ return;
++ for (i = 0; i < IDMAP_HASH_SZ; i++)
++ kfree(h->h_entries[i].ih_name);
++ kfree(h->h_entries);
++}
++
+ void
+ nfs_idmap_delete(struct nfs_client *clp)
+ {
+ struct idmap *idmap = clp->cl_idmap;
+- int i;
+
+ if (!idmap)
+ return;
+ rpc_unlink(idmap->idmap_dentry);
+ clp->cl_idmap = NULL;
+- for (i = 0; i < ARRAY_SIZE(idmap->idmap_user_hash.h_entries); i++)
+- kfree(idmap->idmap_user_hash.h_entries[i].ih_name);
+- for (i = 0; i < ARRAY_SIZE(idmap->idmap_group_hash.h_entries); i++)
+- kfree(idmap->idmap_group_hash.h_entries[i].ih_name);
++ idmap_free_hashtable(&idmap->idmap_user_hash);
++ idmap_free_hashtable(&idmap->idmap_group_hash);
+ kfree(idmap);
+ }
+
+@@ -443,6 +462,8 @@ nfs_idmap_delete(struct nfs_client *clp)
+ static inline struct idmap_hashent *
+ idmap_name_hash(struct idmap_hashtable* h, const char *name, size_t len)
+ {
++ if (h->h_entries == NULL)
++ return NULL;
+ return &h->h_entries[fnvhash32(name, len) % IDMAP_HASH_SZ];
+ }
+
+@@ -451,6 +472,8 @@ idmap_lookup_name(struct idmap_hashtable
+ {
+ struct idmap_hashent *he = idmap_name_hash(h, name, len);
+
++ if (he == NULL)
++ return NULL;
+ if (he->ih_namelen != len || memcmp(he->ih_name, name, len) != 0)
+ return NULL;
+ if (time_after(jiffies, he->ih_expires))
+@@ -461,6 +484,8 @@ idmap_lookup_name(struct idmap_hashtable
+ static inline struct idmap_hashent *
+ idmap_id_hash(struct idmap_hashtable* h, __u32 id)
+ {
++ if (h->h_entries == NULL)
++ return NULL;
+ return &h->h_entries[fnvhash32(&id, sizeof(id)) % IDMAP_HASH_SZ];
+ }
+
+@@ -468,6 +493,9 @@ static struct idmap_hashent *
+ idmap_lookup_id(struct idmap_hashtable *h, __u32 id)
+ {
+ struct idmap_hashent *he = idmap_id_hash(h, id);
++
++ if (he == NULL)
++ return NULL;
+ if (he->ih_id != id || he->ih_namelen == 0)
+ return NULL;
+ if (time_after(jiffies, he->ih_expires))
+@@ -483,12 +511,14 @@ idmap_lookup_id(struct idmap_hashtable *
+ static inline struct idmap_hashent *
+ idmap_alloc_name(struct idmap_hashtable *h, char *name, size_t len)
+ {
++ idmap_alloc_hashtable(h);
+ return idmap_name_hash(h, name, len);
+ }
+
+ static inline struct idmap_hashent *
+ idmap_alloc_id(struct idmap_hashtable *h, __u32 id)
+ {
++ idmap_alloc_hashtable(h);
+ return idmap_id_hash(h, id);
+ }
+
diff --git a/kernel.spec b/kernel.spec
index 83a2683..5023288 100644
--- a/kernel.spec
+++ b/kernel.spec
@@ -739,6 +739,8 @@ Patch2902: linux-2.6-v4l-dvb-uvcvideo-update.patch
Patch3500: jbd-jbd2-validate-sb-s_first-in-journal_get_superblo.patch
# NFSv4
+Patch4000: 0001-NFSv4-Reduce-the-footprint-of-the-idmapper.patch
+Patch4001: 0002-NFSv4-Further-reduce-the-footprint-of-the-idmapper.patch
# patches headed upstream
@@ -1402,6 +1404,8 @@ ApplyPatch
jbd-jbd2-validate-sb-s_first-in-journal_get_superblo.patch
# eCryptfs
# NFSv4
+ApplyPatch 0001-NFSv4-Reduce-the-footprint-of-the-idmapper.patch
+ApplyPatch 0002-NFSv4-Further-reduce-the-footprint-of-the-idmapper.patch
# USB
@@ -2382,6 +2386,9 @@ fi
# and build.
%changelog
+* Wed Mar 14 2012 Steve Dickson <steved(a)redhat.com>
+- Reduce the foot print of the NFSv4 idmapping coda (bz 593035)
+
* Mon Mar 12 2012 Josh Boyer <jwboyer(a)redhat.com> - 3.2.10-1
- Linux 3.2.10
--
1.7.7.5