1515#include <linux/namei.h>
1616#include <linux/module.h>
1717#include <linux/exportfs.h>
18+ #include <linux/sunrpc/svc_xprt.h>
1819
1920#include <net/ipv6.h>
2021
2122#include "nfsd.h"
2223#include "nfsfh.h"
24+ #include "netns.h"
2325
2426#define NFSDDBG_FACILITY NFSDDBG_EXPORT
2527
@@ -298,8 +300,6 @@ svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new,
298300#define EXPORT_HASHBITS 8
299301#define EXPORT_HASHMAX (1<< EXPORT_HASHBITS)
300302
301- static struct cache_head * export_table [EXPORT_HASHMAX ];
302-
303303static void nfsd4_fslocs_free (struct nfsd4_fs_locations * fsloc )
304304{
305305 int i ;
@@ -708,10 +708,9 @@ static struct cache_head *svc_export_alloc(void)
708708 return NULL ;
709709}
710710
711- struct cache_detail svc_export_cache = {
711+ struct cache_detail svc_export_cache_template = {
712712 .owner = THIS_MODULE ,
713713 .hash_size = EXPORT_HASHMAX ,
714- .hash_table = export_table ,
715714 .name = "nfsd.export" ,
716715 .cache_put = svc_export_put ,
717716 .cache_upcall = svc_export_upcall ,
@@ -835,15 +834,16 @@ static struct svc_export *exp_parent(struct cache_detail *cd, svc_client *clp,
835834 * since its harder to fool a kernel module than a user space program.
836835 */
837836int
838- exp_rootfh (svc_client * clp , char * name ,
837+ exp_rootfh (struct net * net , svc_client * clp , char * name ,
839838 struct knfsd_fh * f , int maxsize )
840839{
841840 struct svc_export * exp ;
842841 struct path path ;
843842 struct inode * inode ;
844843 struct svc_fh fh ;
845844 int err ;
846- struct cache_detail * cd = & svc_export_cache ;
845+ struct nfsd_net * nn = net_generic (net , nfsd_net_id );
846+ struct cache_detail * cd = nn -> svc_export_cache ;
847847
848848 err = - EPERM ;
849849 /* NB: we probably ought to check that it's NUL-terminated */
@@ -930,7 +930,8 @@ struct svc_export *
930930rqst_exp_get_by_name (struct svc_rqst * rqstp , struct path * path )
931931{
932932 struct svc_export * gssexp , * exp = ERR_PTR (- ENOENT );
933- struct cache_detail * cd = & svc_export_cache ;
933+ struct nfsd_net * nn = net_generic (rqstp -> rq_xprt -> xpt_net , nfsd_net_id );
934+ struct cache_detail * cd = nn -> svc_export_cache ;
934935
935936 if (rqstp -> rq_client == NULL )
936937 goto gss ;
@@ -960,7 +961,8 @@ struct svc_export *
960961rqst_exp_find (struct svc_rqst * rqstp , int fsid_type , u32 * fsidv )
961962{
962963 struct svc_export * gssexp , * exp = ERR_PTR (- ENOENT );
963- struct cache_detail * cd = & svc_export_cache ;
964+ struct nfsd_net * nn = net_generic (rqstp -> rq_xprt -> xpt_net , nfsd_net_id );
965+ struct cache_detail * cd = nn -> svc_export_cache ;
964966
965967 if (rqstp -> rq_client == NULL )
966968 goto gss ;
@@ -1238,26 +1240,39 @@ int
12381240nfsd_export_init (struct net * net )
12391241{
12401242 int rv ;
1243+ struct nfsd_net * nn = net_generic (net , nfsd_net_id );
1244+
12411245 dprintk ("nfsd: initializing export module (net: %p).\n" , net );
12421246
1243- rv = cache_register_net (& svc_export_cache , net );
1247+ nn -> svc_export_cache = cache_create_net (& svc_export_cache_template , net );
1248+ if (IS_ERR (nn -> svc_export_cache ))
1249+ return PTR_ERR (nn -> svc_export_cache );
1250+ rv = cache_register_net (nn -> svc_export_cache , net );
12441251 if (rv )
1245- return rv ;
1252+ goto destroy_export_cache ;
1253+
12461254 rv = cache_register_net (& svc_expkey_cache , net );
12471255 if (rv )
1248- cache_unregister_net ( & svc_export_cache , net ) ;
1249- return rv ;
1256+ goto unregister_export_cache ;
1257+ return 0 ;
12501258
1259+ unregister_export_cache :
1260+ cache_unregister_net (nn -> svc_export_cache , net );
1261+ destroy_export_cache :
1262+ cache_destroy_net (nn -> svc_export_cache , net );
1263+ return rv ;
12511264}
12521265
12531266/*
12541267 * Flush exports table - called when last nfsd thread is killed
12551268 */
12561269void
1257- nfsd_export_flush (void )
1270+ nfsd_export_flush (struct net * net )
12581271{
1272+ struct nfsd_net * nn = net_generic (net , nfsd_net_id );
1273+
12591274 cache_purge (& svc_expkey_cache );
1260- cache_purge (& svc_export_cache );
1275+ cache_purge (nn -> svc_export_cache );
12611276}
12621277
12631278/*
@@ -1266,11 +1281,13 @@ nfsd_export_flush(void)
12661281void
12671282nfsd_export_shutdown (struct net * net )
12681283{
1284+ struct nfsd_net * nn = net_generic (net , nfsd_net_id );
12691285
12701286 dprintk ("nfsd: shutting down export module (net: %p).\n" , net );
12711287
12721288 cache_unregister_net (& svc_expkey_cache , net );
1273- cache_unregister_net (& svc_export_cache , net );
1289+ cache_unregister_net (nn -> svc_export_cache , net );
1290+ cache_destroy_net (nn -> svc_export_cache , net );
12741291 svcauth_unix_purge ();
12751292
12761293 dprintk ("nfsd: export shutdown complete (net: %p).\n" , net );
0 commit comments