SUNRPC: make caches network namespace aware
Subsystems (4)
v2 cover SUNRPC: make caches network namespace aware
v2:
1) Fixed silly usage of unix gid cache template instead on per-net cache instance.
2) Postfix "_template" was added to all caches templates to make sure, that no misaunderstanding or direct usage of template object will happen in future.
One more step towards to "NFS in container".
With this patch set caches are allocated per network namespace.
The following series consists of:
---
Stanislav Kinsbursky (5):
SUNRPC: cache creation and destruction routines introduced
SUNRPC: create unix gid cache per network namespace
SUNRPC: create GSS auth cache per network namespace
SUNRPC: ip map cache per network namespace cleanup
SUNRPC: generic cache register routines removed
include/linux/sunrpc/cache.h | 6 + include/linux/sunrpc/svcauth_gss.h | 2 net/sunrpc/auth_gss/auth_gss.c | 21 +++++ net/sunrpc/auth_gss/svcauth_gss.c | 165 +++++++++++++++++++++++++----------- net/sunrpc/cache.c | 34 +++++-- net/sunrpc/netns.h | 3 + net/sunrpc/sunrpc_syms.c | 15 ++- net/sunrpc/svcauth_unix.c | 126 +++++++++++++++------------ 8 files changed, 252 insertions(+), 120 deletions(-)
Signature · 1 line
Signature
PATCH v2 1/5 SUNRPC: cache creation and destruction routines introduced
This patch prepares infrastructure for network namespace aware cache detail allocation.
One note about adding network namespace link to cache structure. It's going to be used later in NFS DNS cache parsing routine (nfs_dns_parse for rpc_pton() call).
--- include/linux/sunrpc/cache.h | 4 ++++ net/sunrpc/cache.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-)
include/linux/sunrpc/cache.h +4 -0
@@ -117,6 +117,7 @@ struct cache_detail {struct cache_detail_procfs procfs;struct cache_detail_pipefs pipefs; } u; +struct net *net; };
@@ -202,6 +203,9 @@ extern int cache_register_net(struct cache_detail *cd, struct net *net);extern void cache_unregister (struct cache_detail *cd);extern void cache_unregister_net (struct cache_detail *cd,struct net *net); +extern struct cache_detail *cache_create_net (struct cache_detail *tmpl,struct net *net); +extern void cache_destroy_net (struct cache_detail *cd,struct net *net); +extern void sunrpc_init_cache_detail (struct cache_detail *cd);extern void sunrpc_destroy_cache_detail (struct cache_detail *cd); extern int sunrpc_cache_register_pipefs(struct dentry *parent, const char *,
net/sunrpc/cache.c +26 -0
@@ -1662,6 +1662,32 @@ void cache_unregister(struct cache_detail *cd) }EXPORT_SYMBOL_GPL (cache_unregister); +struct cache_detail *cache_create_net (struct cache_detail *tmpl,struct net *net) +{ +struct cache_detail *cd; + + cd =kmemdup (tmpl,sizeof (struct cache_detail ),GFP_KERNEL ); +if (cd ==NULL ) +return ERR_PTR (-ENOMEM ); + + cd->hash_table =kzalloc (cd->hash_size *sizeof (struct cache_head *), +GFP_KERNEL ); +if (cd->hash_table ==NULL ) { +kfree (cd); +return ERR_PTR (-ENOMEM ); + } + cd->net = net; +return cd; +} +EXPORT_SYMBOL_GPL (cache_create_net); + +void cache_destroy_net (struct cache_detail *cd,struct net *net) +{ +kfree (cd->hash_table); +kfree (cd); +} +EXPORT_SYMBOL_GPL (cache_destroy_net); +static ssize_t cache_read_pipefs (struct file *filp,char __user *buf,size_t count,loff_t *ppos) {
PATCH v2 2/5 SUNRPC: create unix gid cache per network namespace
In reply to Stanislav Kinsburskyv2:
1) fixed silly usage of template cache as a real one (this code left from static global cache for all)
This patch makes unix_gid_cache cache detail allocated and registered per network namespace context.
Thus with this patch unix_gid_cache contents for network namespace "X" are controlled from proc file system mount for the same network namespace "X".
--- net/sunrpc/netns.h | 1 + net/sunrpc/sunrpc_syms.c | 14 ++++++++--- net/sunrpc/svcauth_unix.c | 55 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 52 insertions(+), 18 deletions(-)
net/sunrpc/netns.h +1 -0
@@ -9,6 +9,7 @@ struct cache_detail;struct sunrpc_net {struct proc_dir_entry *proc_net_rpc;struct cache_detail *ip_map_cache; +struct cache_detail *unix_gid_cache;struct super_block *pipefs_sb;struct mutex pipefs_sb_lock;
net/sunrpc/sunrpc_syms.c +10 -4
@@ -26,6 +26,9 @@int sunrpc_net_id; +extern int unix_gid_cache_create (struct net *net); +extern int unix_gid_cache_destroy (struct net *net); +static __net_init int sunrpc_init_net (struct net *net) {int err;
@@ -39,11 +42,17 @@ static __net_init int sunrpc_init_net(struct net *net)if (err) goto err_ipmap; + err =unix_gid_cache_create (net); +if (err) + goto err_unixgid; +rpc_pipefs_init_net (net);INIT_LIST_HEAD (&sn->all_clients);spin_lock_init (&sn->rpc_client_lock);return 0 ; +err_unixgid: +ip_map_cache_destroy (net); err_ipmap:rpc_proc_exit (net); err_proc:
@@ -52,6 +61,7 @@ err_proc: static __net_exit void sunrpc_exit_net(struct net *net) { +unix_gid_cache_destroy (net);ip_map_cache_destroy (net);rpc_proc_exit (net); }
@@ -63,8 +73,6 @@ static struct pernet_operations sunrpc_net_ops = { .size = sizeof(struct sunrpc_net), }; -extern struct cache_detail unix_gid_cache; -static int __init init_sunrpc (void ) {
@@ -86,7 +94,6 @@ init_sunrpc(void)#ifdef RPC_DEBUG rpc_register_sysctl ();#endif -cache_register (&unix_gid_cache);svc_init_xprt_sock ();/* svc sock transport */ init_socket_xprt ();/* clnt sock transport */ return 0 ;
@@ -109,7 +116,6 @@ cleanup_sunrpc(void)svc_cleanup_xprt_sock ();unregister_rpc_pipefs ();rpc_destroy_mempool (); -cache_unregister (&unix_gid_cache);unregister_pernet_subsys (&sunrpc_net_ops);#ifdef RPC_DEBUG rpc_unregister_sysctl ();
net/sunrpc/svcauth_unix.c +41 -14
117 lines not on this page · raw message
PATCH v2 3/5 SUNRPC: create GSS auth cache per network namespace
In reply to Stanislav KinsburskyThis patch makes GSS auth cache details allocated and registered per network namespace context.
Thus with this patch rsi_cache and rsc_cache contents for network namespace "X" are controlled from proc file system mount for the same network namespace "X".
--- include/linux/sunrpc/svcauth_gss.h | 2 net/sunrpc/auth_gss/auth_gss.c | 21 +++++ net/sunrpc/auth_gss/svcauth_gss.c | 165 +++++++++++++++++++++++++----------- net/sunrpc/cache.c | 2 net/sunrpc/netns.h | 2 net/sunrpc/sunrpc_syms.c | 1 6 files changed, 143 insertions(+), 50 deletions(-)
include/linux/sunrpc/svcauth_gss.h +2 -0
@@ -18,6 +18,8 @@int gss_svc_init (void );void gss_svc_shutdown (void ); +int gss_svc_init_net (struct net *net); +void gss_svc_shutdown_net (struct net *net);int svcauth_gss_register_pseudoflavor (u32 pseudoflavor,char * name);u32 svcauth_gss_flavor (struct auth_domain *dom);char *svc_gss_principal (struct svc_rqst *);
net/sunrpc/auth_gss/auth_gss.c +21 -0
@@ -1662,6 +1662,21 @@ static const struct rpc_pipe_ops gss_upcall_ops_v1 = { .release_pipe = gss_pipe_release, }; +static __net_init int rpcsec_gss_init_net (struct net *net) +{ +return gss_svc_init_net (net); +} + +static __net_exit void rpcsec_gss_exit_net(struct net *net) +{ +gss_svc_shutdown_net (net); +} + +static struct pernet_operations rpcsec_gss_net_ops = { + .init = rpcsec_gss_init_net, + .exit = rpcsec_gss_exit_net, +}; +/* * Initialize RPCSEC_GSS module */
@@ -1675,8 +1690,13 @@ static int __init init_rpcsec_gss(void) err =gss_svc_init ();if (err) goto out_unregister; + err =register_pernet_subsys (&rpcsec_gss_net_ops); +if (err) + goto out_svc_exit;rpc_init_wait_queue (&pipe_version_rpc_waitqueue,"gss pipe version" );return 0 ; +out_svc_exit: +gss_svc_shutdown (); out_unregister:rpcauth_unregister (&authgss_ops); out:
@@ -1685,6 +1705,7 @@ out: static void __exit exit_rpcsec_gss(void) { +unregister_pernet_subsys (&rpcsec_gss_net_ops);gss_svc_shutdown ();rpcauth_unregister (&authgss_ops);rcu_barrier ();/* Wait for completion of call_rcu()'s */
net/sunrpc/auth_gss/svcauth_gss.c +115 -50
377 lines not on this page · raw message
net/sunrpc/cache.c +2 -0
@@ -1643,6 +1643,7 @@ int cache_register_net(struct cache_detail *cd, struct net *net)sunrpc_destroy_cache_detail (cd);return ret; } +EXPORT_SYMBOL_GPL (cache_register_net);int cache_register (struct cache_detail *cd) {
@@ -1655,6 +1656,7 @@ void cache_unregister_net(struct cache_detail *cd, struct net *net)remove_cache_proc_entries (cd, net);sunrpc_destroy_cache_detail (cd); } +EXPORT_SYMBOL_GPL (cache_unregister_net);void cache_unregister (struct cache_detail *cd) {
net/sunrpc/netns.h +2 -0
@@ -10,6 +10,8 @@ struct sunrpc_net {struct proc_dir_entry *proc_net_rpc;struct cache_detail *ip_map_cache;struct cache_detail *unix_gid_cache; +struct cache_detail *rsc_cache; +struct cache_detail *rsi_cache;struct super_block *pipefs_sb;struct mutex pipefs_sb_lock;
net/sunrpc/sunrpc_syms.c +1 -0
@@ -25,6 +25,7 @@#include "netns.h" int sunrpc_net_id; +EXPORT_SYMBOL_GPL (sunrpc_net_id);extern int unix_gid_cache_create (struct net *net);extern int unix_gid_cache_destroy (struct net *net);
PATCH v2 4/5 SUNRPC: ip map cache per network namespace cleanup
In reply to Stanislav KinsburskyThis 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.
--- net/sunrpc/svcauth_unix.c | 71 +++++++++++++++++++-------------------------- 1 files changed, 30 insertions(+), 41 deletions(-)
net/sunrpc/svcauth_unix.c +30 -41
@@ -211,7 +211,7 @@ static int ip_map_parse(struct cache_detail *cd, len =qword_get (&mesg, buf, mlen);if (len <=0 )return -EINVAL ; -if (rpc_pton (&init_net, buf, len, &address.sa,sizeof (address)) ==0 ) +if (rpc_pton (cd->net, buf, len, &address.sa,sizeof (address)) ==0 )return -EINVAL ;switch (address.sa.sa_family) {case AF_INET :
@@ -876,56 +876,45 @@ struct auth_ops svcauth_unix = { .set_client = svcauth_unix_set_client, }; +static struct cache_detail ip_map_cache_template = { + .owner =THIS_MODULE , + .hash_size =IP_HASHMAX , + .name ="auth.unix.ip" , + .cache_put = ip_map_put, + .cache_upcall = ip_map_upcall, + .cache_parse = ip_map_parse, + .cache_show = ip_map_show, + .match = ip_map_match, + .init = ip_map_init, + .update = update, + .alloc = ip_map_alloc, +}; +int ip_map_cache_create (struct net *net) { -int err = -ENOMEM ; -struct cache_detail *cd; -struct cache_head **tbl;struct sunrpc_net *sn =net_generic (net, sunrpc_net_id); +struct cache_detail *cd; +int err; - cd =kzalloc (sizeof (struct cache_detail ),GFP_KERNEL ); -if (cd ==NULL ) - goto err_cd; - - tbl =kzalloc (IP_HASHMAX *sizeof (struct cache_head *),GFP_KERNEL ); -if (tbl ==NULL ) - goto err_tbl; - - cd->owner =THIS_MODULE , - cd->hash_size =IP_HASHMAX , - cd->hash_table = tbl, - cd->name ="auth.unix.ip" , - cd->cache_put = ip_map_put, - cd->cache_upcall = ip_map_upcall, - cd->cache_parse = ip_map_parse, - cd->cache_show = ip_map_show, - cd->match = ip_map_match, - cd->init = ip_map_init, - cd->update = update, - cd->alloc = ip_map_alloc, - + cd =cache_create_net (&ip_map_cache_template, net); +if (IS_ERR (cd)) +return PTR_ERR (cd); err =cache_register_net (cd, net); -if (err) - goto err_reg; - +if (err) { +cache_destroy_net (cd, net); +return err; + } sn->ip_map_cache = cd;return 0 ; - -err_reg: -kfree (tbl); -err_tbl: -kfree (cd); -err_cd: -return err; }void ip_map_cache_destroy (struct net *net) { -struct sunrpc_net *sn; +struct sunrpc_net *sn =net_generic (net, sunrpc_net_id); +struct cache_detail *cd = sn->ip_map_cache; - sn =net_generic (net, sunrpc_net_id); -cache_purge (sn->ip_map_cache); -cache_unregister_net (sn->ip_map_cache, net); -kfree (sn->ip_map_cache->hash_table); -kfree (sn->ip_map_cache); + sn->ip_map_cache =NULL ; +cache_purge (cd); +cache_unregister_net (cd, net); +cache_destroy_net (cd, net); }
PATCH v2 5/5 SUNRPC: generic cache register routines removed
In reply to Stanislav KinsburskyAll cache users now uses network-namespace-aware routines, so generic ones are obsolete.
--- include/linux/sunrpc/cache.h | 2 -- net/sunrpc/cache.c | 12 ------------ 2 files changed, 0 insertions(+), 14 deletions(-)
include/linux/sunrpc/cache.h +0 -2
@@ -198,9 +198,7 @@ extern void cache_flush(void);extern void cache_purge (struct cache_detail *detail);#define NEVER (0x7FFFFFFF)extern void __init cache_initialize (void ); -extern int cache_register (struct cache_detail *cd);extern int cache_register_net (struct cache_detail *cd,struct net *net); -extern void cache_unregister (struct cache_detail *cd);extern void cache_unregister_net (struct cache_detail *cd,struct net *net);extern struct cache_detail *cache_create_net (struct cache_detail *tmpl,struct net *net);
net/sunrpc/cache.c +0 -12
@@ -1645,12 +1645,6 @@ int cache_register_net(struct cache_detail *cd, struct net *net) }EXPORT_SYMBOL_GPL (cache_register_net); -int cache_register (struct cache_detail *cd) -{ -return cache_register_net (cd, &init_net); -} -EXPORT_SYMBOL_GPL (cache_register); -void cache_unregister_net (struct cache_detail *cd,struct net *net) {remove_cache_proc_entries (cd, net);
@@ -1658,12 +1652,6 @@ void cache_unregister_net(struct cache_detail *cd, struct net *net) }EXPORT_SYMBOL_GPL (cache_unregister_net); -void cache_unregister (struct cache_detail *cd) -{ -cache_unregister_net (cd, &init_net); -} -EXPORT_SYMBOL_GPL (cache_unregister); -struct cache_detail *cache_create_net (struct cache_detail *tmpl,struct net *net) {struct cache_detail *cd;
Re: [PATCH v2 2/5] SUNRPC: create unix gid cache per network namespace
In reply to Stanislav KinsburskyQuoted 3 lines · Stanislav Kinsbursky
v2:
1) fixed silly usage of template cache as a real one (this code left from static global cache for all)
Looks good, thanks.
--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
I've tested NFSd under load - works like a charm (showmount reported right info).
I've tested NFS mounts on host node - looks like all works fine.
Also I've tested NFS mounts on host node and in container in the same time. There are some problems here. Most likely caused by user-space daemons, conflicting between themselves because of wrong initialization environment (like rpcbind registering problems, which I've raised in the list already). So looks like the patches suitable for devel branch.
BTW, thanks to careful review, Bruce.
Signature · 2 lines
Best regards, Stanislav Kinsbursky
[email protected]
Acked-by J. Bruce FieldsQuoted 8 lines · Stanislav Kinsbursky
I've tested NFSd under load - works like a charm (showmount reported right info). I've tested NFS mounts on host node - looks like all works fine. Also I've tested NFS mounts on host node and in container in the same time. There are some problems here. Most likely caused by user-space daemons, conflicting between themselves because of wrong initialization environment (like rpcbind registering problems, which I've raised in the list already).
So looks like the patches suitable for devel branch.
OK, thanks:
We should start testing the containerized nfsd side too, though--run nfsd on a machine with multiple network namespaces, separate mountd's and rpc.svcgssd's in each, figure out how to feed of them different configurations, and check that requests to the different interfaces are treated differently.
--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html