Skip to content

Commit b3853e0

Browse files
Stanislav KinsburskyJ. Bruce Fields
authored andcommitted
nfsd: make export cache allocated per network namespace context
This patch also changes prototypes of nfsd_export_flush() and exp_rootfh(): network namespace parameter added. Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent 2a75cfa commit b3853e0

5 files changed

Lines changed: 38 additions & 19 deletions

File tree

‎fs/nfsd/export.c‎

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
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-
303303
static 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
*/
837836
int
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 *
930930
rqst_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 *
960961
rqst_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
12381240
nfsd_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
*/
12561269
void
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)
12661281
void
12671282
nfsd_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);

‎fs/nfsd/netns.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct cld_net;
2828

2929
struct nfsd_net {
3030
struct cld_net *cld_net;
31+
32+
struct cache_detail *svc_export_cache;
3133
};
3234

3335
extern int nfsd_net_id;

‎fs/nfsd/nfsctl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
354354
if (!dom)
355355
return -ENOMEM;
356356

357-
len = exp_rootfh(dom, path, &fh, maxsize);
357+
len = exp_rootfh(&init_net, dom, path, &fh, maxsize);
358358
auth_domain_put(dom);
359359
if (len)
360360
return len;

‎fs/nfsd/nfssvc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static void nfsd_last_thread(struct svc_serv *serv, struct net *net)
261261

262262
printk(KERN_WARNING "nfsd: last server has exited, flushing export "
263263
"cache\n");
264-
nfsd_export_flush();
264+
nfsd_export_flush(net);
265265
}
266266

267267
void nfsd_reset_versions(void)

‎include/linux/nfsd/export.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);
132132
*/
133133
int nfsd_export_init(struct net *);
134134
void nfsd_export_shutdown(struct net *);
135-
void nfsd_export_flush(void);
135+
void nfsd_export_flush(struct net *);
136136
struct svc_export * rqst_exp_get_by_name(struct svc_rqst *,
137137
struct path *);
138138
struct svc_export * rqst_exp_parent(struct svc_rqst *,
139139
struct path *);
140140
struct svc_export * rqst_find_fsidzero_export(struct svc_rqst *);
141-
int exp_rootfh(struct auth_domain *,
141+
int exp_rootfh(struct net *, struct auth_domain *,
142142
char *path, struct knfsd_fh *, int maxsize);
143143
__be32 exp_pseudoroot(struct svc_rqst *, struct svc_fh *);
144144
__be32 nfserrno(int errno);

0 commit comments

Comments
 (0)