aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStanislav Kinsbursky <skinsbursky@parallels.com>2012-01-19 12:42:45 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2012-01-31 19:28:16 -0500
commitd05cc10406893dec65b8e89746e7d4c333935415 (patch)
treee9ec5767d68fb461447bf577da840a00b451cc64
parenta1db410d0bbadc49943f0fcddb21702ceb429396 (diff)
SUNRPC: ip map cache per network namespace cleanup
This patch converts ip_map_cache per network namespace implemenetation to the same view, as other caches done in the series. Besides generalization, code becomes shorter with this patch. Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com> Acked-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r--net/sunrpc/svcauth_unix.c71
1 files changed, 30 insertions, 41 deletions
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index a6eef38fb35..bcd574f2ac5 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -211,7 +211,7 @@ static int ip_map_parse(struct cache_detail *cd,
211 len = qword_get(&mesg, buf, mlen); 211 len = qword_get(&mesg, buf, mlen);
212 if (len <= 0) return -EINVAL; 212 if (len <= 0) return -EINVAL;
213 213
214 if (rpc_pton(&init_net, buf, len, &address.sa, sizeof(address)) == 0) 214 if (rpc_pton(cd->net, buf, len, &address.sa, sizeof(address)) == 0)
215 return -EINVAL; 215 return -EINVAL;
216 switch (address.sa.sa_family) { 216 switch (address.sa.sa_family) {
217 case AF_INET: 217 case AF_INET:
@@ -876,56 +876,45 @@ struct auth_ops svcauth_unix = {
876 .set_client = svcauth_unix_set_client, 876 .set_client = svcauth_unix_set_client,
877}; 877};
878 878
879static struct cache_detail ip_map_cache_template = {
880 .owner = THIS_MODULE,
881 .hash_size = IP_HASHMAX,
882 .name = "auth.unix.ip",
883 .cache_put = ip_map_put,
884 .cache_upcall = ip_map_upcall,
885 .cache_parse = ip_map_parse,
886 .cache_show = ip_map_show,
887 .match = ip_map_match,
888 .init = ip_map_init,
889 .update = update,
890 .alloc = ip_map_alloc,
891};
892
879int ip_map_cache_create(struct net *net) 893int ip_map_cache_create(struct net *net)
880{ 894{
881 int err = -ENOMEM;
882 struct cache_detail *cd;
883 struct cache_head **tbl;
884 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); 895 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
896 struct cache_detail *cd;
897 int err;
885 898
886 cd = kzalloc(sizeof(struct cache_detail), GFP_KERNEL); 899 cd = cache_create_net(&ip_map_cache_template, net);
887 if (cd == NULL) 900 if (IS_ERR(cd))
888 goto err_cd; 901 return PTR_ERR(cd);
889
890 tbl = kzalloc(IP_HASHMAX * sizeof(struct cache_head *), GFP_KERNEL);
891 if (tbl == NULL)
892 goto err_tbl;
893
894 cd->owner = THIS_MODULE,
895 cd->hash_size = IP_HASHMAX,
896 cd->hash_table = tbl,
897 cd->name = "auth.unix.ip",
898 cd->cache_put = ip_map_put,
899 cd->cache_upcall = ip_map_upcall,
900 cd->cache_parse = ip_map_parse,
901 cd->cache_show = ip_map_show,
902 cd->match = ip_map_match,
903 cd->init = ip_map_init,
904 cd->update = update,
905 cd->alloc = ip_map_alloc,
906
907 err = cache_register_net(cd, net); 902 err = cache_register_net(cd, net);
908 if (err) 903 if (err) {
909 goto err_reg; 904 cache_destroy_net(cd, net);
910 905 return err;
906 }
911 sn->ip_map_cache = cd; 907 sn->ip_map_cache = cd;
912 return 0; 908 return 0;
913
914err_reg:
915 kfree(tbl);
916err_tbl:
917 kfree(cd);
918err_cd:
919 return err;
920} 909}
921 910
922void ip_map_cache_destroy(struct net *net) 911void ip_map_cache_destroy(struct net *net)
923{ 912{
924 struct sunrpc_net *sn; 913 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
914 struct cache_detail *cd = sn->ip_map_cache;
925 915
926 sn = net_generic(net, sunrpc_net_id); 916 sn->ip_map_cache = NULL;
927 cache_purge(sn->ip_map_cache); 917 cache_purge(cd);
928 cache_unregister_net(sn->ip_map_cache, net); 918 cache_unregister_net(cd, net);
929 kfree(sn->ip_map_cache->hash_table); 919 cache_destroy_net(cd, net);
930 kfree(sn->ip_map_cache);
931} 920}