Skip to content

Commit eab7e2e

Browse files
neilbrownLinus Torvalds
authored andcommitted
[PATCH] knfsd: Break the hard linkage from svc_expkey to svc_export
Current svc_expkey holds a pointer to the svc_export structure, so updates to that structure have to be in-place, which is a wart on the whole cache infrastruct. So we break that linkage and just do a second lookup. If this became a performance issue, it would be possible to put a direct link back in which was only used conditionally. i.e. when an object is replaced in the cache, we set a flag in the old object. When dereferencing the link from svc_expkey, if the flag is set, we drop the reference and do a fresh lookup. Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent efc36aa commit eab7e2e

2 files changed

Lines changed: 44 additions & 36 deletions

File tree

‎fs/nfsd/export.c‎

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ void expkey_put(struct cache_head *item, struct cache_detail *cd)
7373
if (cache_put(item, cd)) {
7474
struct svc_expkey *key = container_of(item, struct svc_expkey, h);
7575
if (test_bit(CACHE_VALID, &item->flags) &&
76-
!test_bit(CACHE_NEGATIVE, &item->flags))
77-
exp_put(key->ek_export);
76+
!test_bit(CACHE_NEGATIVE, &item->flags)) {
77+
dput(key->ek_dentry);
78+
mntput(key->ek_mnt);
79+
}
7880
auth_domain_put(key->ek_client);
7981
kfree(key);
8082
}
@@ -164,26 +166,18 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
164166
} else {
165167
struct nameidata nd;
166168
struct svc_expkey *ek;
167-
struct svc_export *exp;
168169
err = path_lookup(buf, 0, &nd);
169170
if (err)
170171
goto out;
171172

172173
dprintk("Found the path %s\n", buf);
173-
exp = exp_get_by_name(dom, nd.mnt, nd.dentry, NULL);
174-
175-
err = -ENOENT;
176-
if (!exp)
177-
goto out_nd;
178-
key.ek_export = exp;
179-
dprintk("And found export\n");
174+
key.ek_mnt = nd.mnt;
175+
key.ek_dentry = nd.dentry;
180176

181177
ek = svc_expkey_lookup(&key, 1);
182178
if (ek)
183179
expkey_put(&ek->h, &svc_expkey_cache);
184-
exp_put(exp);
185180
err = 0;
186-
out_nd:
187181
path_release(&nd);
188182
}
189183
cache_flush();
@@ -214,7 +208,7 @@ static int expkey_show(struct seq_file *m,
214208
if (test_bit(CACHE_VALID, &h->flags) &&
215209
!test_bit(CACHE_NEGATIVE, &h->flags)) {
216210
seq_printf(m, " ");
217-
seq_path(m, ek->ek_export->ex_mnt, ek->ek_export->ex_dentry, "\\ \t\n");
211+
seq_path(m, ek->ek_mnt, ek->ek_dentry, "\\ \t\n");
218212
}
219213
seq_printf(m, "\n");
220214
return 0;
@@ -252,8 +246,8 @@ static inline void svc_expkey_init(struct svc_expkey *new, struct svc_expkey *it
252246

253247
static inline void svc_expkey_update(struct svc_expkey *new, struct svc_expkey *item)
254248
{
255-
cache_get(&item->ek_export->h);
256-
new->ek_export = item->ek_export;
249+
new->ek_mnt = mntget(item->ek_mnt);
250+
new->ek_dentry = dget(item->ek_dentry);
257251
}
258252

259253
static DefineSimpleCacheLookup(svc_expkey,0) /* no inplace updates */
@@ -519,7 +513,8 @@ static int exp_set_key(svc_client *clp, int fsid_type, u32 *fsidv,
519513
key.ek_client = clp;
520514
key.ek_fsidtype = fsid_type;
521515
memcpy(key.ek_fsid, fsidv, key_len(fsid_type));
522-
key.ek_export = exp;
516+
key.ek_mnt = exp->ex_mnt;
517+
key.ek_dentry = exp->ex_dentry;
523518
key.h.expiry_time = NEVER;
524519
key.h.flags = 0;
525520

@@ -741,8 +736,8 @@ exp_export(struct nfsctl_export *nxp)
741736
if ((nxp->ex_flags & NFSEXP_FSID) &&
742737
(fsid_key = exp_get_fsid_key(clp, nxp->ex_dev)) &&
743738
!IS_ERR(fsid_key) &&
744-
fsid_key->ek_export &&
745-
fsid_key->ek_export != exp)
739+
fsid_key->ek_mnt &&
740+
(fsid_key->ek_mnt != nd.mnt || fsid_key->ek_dentry != nd.dentry) )
746741
goto finish;
747742

748743
if (exp) {
@@ -912,6 +907,24 @@ exp_rootfh(svc_client *clp, char *path, struct knfsd_fh *f, int maxsize)
912907
return err;
913908
}
914909

910+
struct svc_export *
911+
exp_find(struct auth_domain *clp, int fsid_type, u32 *fsidv,
912+
struct cache_req *reqp)
913+
{
914+
struct svc_export *exp;
915+
struct svc_expkey *ek = exp_find_key(clp, fsid_type, fsidv, reqp);
916+
if (!ek || IS_ERR(ek))
917+
return ERR_PTR(PTR_ERR(ek));
918+
919+
exp = exp_get_by_name(clp, ek->ek_mnt, ek->ek_dentry, reqp);
920+
expkey_put(&ek->h, &svc_expkey_cache);
921+
922+
if (!exp || IS_ERR(exp))
923+
return ERR_PTR(PTR_ERR(exp));
924+
return exp;
925+
}
926+
927+
915928
/*
916929
* Called when we need the filehandle for the root of the pseudofs,
917930
* for a given NFSv4 client. The root is defined to be the
@@ -922,6 +935,7 @@ exp_pseudoroot(struct auth_domain *clp, struct svc_fh *fhp,
922935
struct cache_req *creq)
923936
{
924937
struct svc_expkey *fsid_key;
938+
struct svc_export *exp;
925939
int rv;
926940
u32 fsidv[2];
927941

@@ -933,8 +947,14 @@ exp_pseudoroot(struct auth_domain *clp, struct svc_fh *fhp,
933947
if (!fsid_key || IS_ERR(fsid_key))
934948
return nfserr_perm;
935949

936-
rv = fh_compose(fhp, fsid_key->ek_export,
937-
fsid_key->ek_export->ex_dentry, NULL);
950+
exp = exp_get_by_name(clp, fsid_key->ek_mnt, fsid_key->ek_dentry, creq);
951+
if (exp == NULL)
952+
rv = nfserr_perm;
953+
else if (IS_ERR(exp))
954+
rv = nfserrno(PTR_ERR(exp));
955+
else
956+
rv = fh_compose(fhp, exp,
957+
fsid_key->ek_dentry, NULL);
938958
expkey_put(&fsid_key->h, &svc_expkey_cache);
939959
return rv;
940960
}

‎include/linux/nfsd/export.h‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ struct svc_expkey {
6767
int ek_fsidtype;
6868
u32 ek_fsid[3];
6969

70-
struct svc_export * ek_export;
70+
struct vfsmount * ek_mnt;
71+
struct dentry * ek_dentry;
7172
};
7273

7374
#define EX_SECURE(exp) (!((exp)->ex_flags & NFSEXP_INSECURE_PORT))
@@ -114,22 +115,9 @@ static inline void exp_get(struct svc_export *exp)
114115
{
115116
cache_get(&exp->h);
116117
}
117-
static inline struct svc_export *
118+
extern struct svc_export *
118119
exp_find(struct auth_domain *clp, int fsid_type, u32 *fsidv,
119-
struct cache_req *reqp)
120-
{
121-
struct svc_expkey *ek = exp_find_key(clp, fsid_type, fsidv, reqp);
122-
if (ek && !IS_ERR(ek)) {
123-
struct svc_export *exp = ek->ek_export;
124-
int err;
125-
exp_get(exp);
126-
expkey_put(&ek->h, &svc_expkey_cache);
127-
if ((err = cache_check(&svc_export_cache, &exp->h, reqp)))
128-
exp = ERR_PTR(err);
129-
return exp;
130-
} else
131-
return ERR_PTR(PTR_ERR(ek));
132-
}
120+
struct cache_req *reqp);
133121

134122
#endif /* __KERNEL__ */
135123

0 commit comments

Comments
 (0)