Commit d05cc10406893dec65b8e89746e7d4c333935415

Authored by Stanislav Kinsbursky
Committed by Trond Myklebust
1 parent a1db410d0b

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>

Showing 1 changed file with 30 additions and 41 deletions Side-by-side Diff

net/sunrpc/svcauth_unix.c
... ... @@ -211,7 +211,7 @@
211 211 len = qword_get(&mesg, buf, mlen);
212 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 215 return -EINVAL;
216 216 switch (address.sa.sa_family) {
217 217 case AF_INET:
218 218  
219 219  
220 220  
221 221  
222 222  
223 223  
224 224  
... ... @@ -876,57 +876,46 @@
876 876 .set_client = svcauth_unix_set_client,
877 877 };
878 878  
  879 +static 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 +
879 893 int ip_map_cache_create(struct net *net)
880 894 {
881   - int err = -ENOMEM;
882   - struct cache_detail *cd;
883   - struct cache_head **tbl;
884 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);
887   - if (cd == NULL)
888   - goto 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   -
  899 + cd = cache_create_net(&ip_map_cache_template, net);
  900 + if (IS_ERR(cd))
  901 + return PTR_ERR(cd);
907 902 err = cache_register_net(cd, net);
908   - if (err)
909   - goto err_reg;
910   -
  903 + if (err) {
  904 + cache_destroy_net(cd, net);
  905 + return err;
  906 + }
911 907 sn->ip_map_cache = cd;
912 908 return 0;
913   -
914   -err_reg:
915   - kfree(tbl);
916   -err_tbl:
917   - kfree(cd);
918   -err_cd:
919   - return err;
920 909 }
921 910  
922 911 void 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);
927   - cache_purge(sn->ip_map_cache);
928   - cache_unregister_net(sn->ip_map_cache, net);
929   - kfree(sn->ip_map_cache->hash_table);
930   - kfree(sn->ip_map_cache);
  916 + sn->ip_map_cache = NULL;
  917 + cache_purge(cd);
  918 + cache_unregister_net(cd, net);
  919 + cache_destroy_net(cd, net);
931 920 }