Commit 8d270f7f authored by NeilBrown's avatar NeilBrown Committed by Linus Torvalds

[PATCH] knfsd: Use new cache_lookup for svc_expkey cache

Signed-off-by: default avatarNeil Brown <neilb@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 4f7774c3
...@@ -57,17 +57,6 @@ static int exp_verify_string(char *cp, int max); ...@@ -57,17 +57,6 @@ static int exp_verify_string(char *cp, int max);
#define EXPKEY_HASHMASK (EXPKEY_HASHMAX -1) #define EXPKEY_HASHMASK (EXPKEY_HASHMAX -1)
static struct cache_head *expkey_table[EXPKEY_HASHMAX]; static struct cache_head *expkey_table[EXPKEY_HASHMAX];
static inline int svc_expkey_hash(struct svc_expkey *item)
{
int hash = item->ek_fsidtype;
char * cp = (char*)item->ek_fsid;
int len = key_len(item->ek_fsidtype);
hash ^= hash_mem(cp, len, EXPKEY_HASHBITS);
hash ^= hash_ptr(item->ek_client, EXPKEY_HASHBITS);
return hash & EXPKEY_HASHMASK;
}
void expkey_put(struct cache_head *item, struct cache_detail *cd) void expkey_put(struct cache_head *item, struct cache_detail *cd)
{ {
if (cache_put(item, cd)) { if (cache_put(item, cd)) {
...@@ -97,7 +86,8 @@ static void expkey_request(struct cache_detail *cd, ...@@ -97,7 +86,8 @@ static void expkey_request(struct cache_detail *cd,
(*bpp)[-1] = '\n'; (*bpp)[-1] = '\n';
} }
static struct svc_expkey *svc_expkey_lookup(struct svc_expkey *, int); static struct svc_expkey *svc_expkey_update(struct svc_expkey *new, struct svc_expkey *old);
static struct svc_expkey *svc_expkey_lookup(struct svc_expkey *);
static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen) static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
{ {
/* client fsidtype fsid [path] */ /* client fsidtype fsid [path] */
...@@ -108,6 +98,7 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen) ...@@ -108,6 +98,7 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
int fsidtype; int fsidtype;
char *ep; char *ep;
struct svc_expkey key; struct svc_expkey key;
struct svc_expkey *ek;
if (mesg[mlen-1] != '\n') if (mesg[mlen-1] != '\n')
return -EINVAL; return -EINVAL;
...@@ -152,20 +143,25 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen) ...@@ -152,20 +143,25 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
key.ek_fsidtype = fsidtype; key.ek_fsidtype = fsidtype;
memcpy(key.ek_fsid, buf, len); memcpy(key.ek_fsid, buf, len);
ek = svc_expkey_lookup(&key);
err = -ENOMEM;
if (!ek)
goto out;
/* now we want a pathname, or empty meaning NEGATIVE */ /* now we want a pathname, or empty meaning NEGATIVE */
err = -EINVAL;
if ((len=qword_get(&mesg, buf, PAGE_SIZE)) < 0) if ((len=qword_get(&mesg, buf, PAGE_SIZE)) < 0)
goto out; goto out;
dprintk("Path seems to be <%s>\n", buf); dprintk("Path seems to be <%s>\n", buf);
err = 0; err = 0;
if (len == 0) { if (len == 0) {
struct svc_expkey *ek;
set_bit(CACHE_NEGATIVE, &key.h.flags); set_bit(CACHE_NEGATIVE, &key.h.flags);
ek = svc_expkey_lookup(&key, 1); ek = svc_expkey_update(&key, ek);
if (ek) if (ek)
expkey_put(&ek->h, &svc_expkey_cache); expkey_put(&ek->h, &svc_expkey_cache);
else err = -ENOMEM;
} else { } else {
struct nameidata nd; struct nameidata nd;
struct svc_expkey *ek;
err = path_lookup(buf, 0, &nd); err = path_lookup(buf, 0, &nd);
if (err) if (err)
goto out; goto out;
...@@ -174,10 +170,11 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen) ...@@ -174,10 +170,11 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
key.ek_mnt = nd.mnt; key.ek_mnt = nd.mnt;
key.ek_dentry = nd.dentry; key.ek_dentry = nd.dentry;
ek = svc_expkey_lookup(&key, 1); ek = svc_expkey_update(&key, ek);
if (ek) if (ek)
expkey_put(&ek->h, &svc_expkey_cache); expkey_put(&ek->h, &svc_expkey_cache);
err = 0; else
err = -ENOMEM;
path_release(&nd); path_release(&nd);
} }
cache_flush(); cache_flush();
...@@ -214,28 +211,24 @@ static int expkey_show(struct seq_file *m, ...@@ -214,28 +211,24 @@ static int expkey_show(struct seq_file *m,
return 0; return 0;
} }
struct cache_detail svc_expkey_cache = { static inline int expkey_match (struct cache_head *a, struct cache_head *b)
.owner = THIS_MODULE,
.hash_size = EXPKEY_HASHMAX,
.hash_table = expkey_table,
.name = "nfsd.fh",
.cache_put = expkey_put,
.cache_request = expkey_request,
.cache_parse = expkey_parse,
.cache_show = expkey_show,
};
static inline int svc_expkey_match (struct svc_expkey *a, struct svc_expkey *b)
{ {
if (a->ek_fsidtype != b->ek_fsidtype || struct svc_expkey *orig = container_of(a, struct svc_expkey, h);
a->ek_client != b->ek_client || struct svc_expkey *new = container_of(b, struct svc_expkey, h);
memcmp(a->ek_fsid, b->ek_fsid, key_len(a->ek_fsidtype)) != 0)
if (orig->ek_fsidtype != new->ek_fsidtype ||
orig->ek_client != new->ek_client ||
memcmp(orig->ek_fsid, new->ek_fsid, key_len(orig->ek_fsidtype)) != 0)
return 0; return 0;
return 1; return 1;
} }
static inline void svc_expkey_init(struct svc_expkey *new, struct svc_expkey *item) static inline void expkey_init(struct cache_head *cnew,
struct cache_head *citem)
{ {
struct svc_expkey *new = container_of(cnew, struct svc_expkey, h);
struct svc_expkey *item = container_of(citem, struct svc_expkey, h);
kref_get(&item->ek_client->ref); kref_get(&item->ek_client->ref);
new->ek_client = item->ek_client; new->ek_client = item->ek_client;
new->ek_fsidtype = item->ek_fsidtype; new->ek_fsidtype = item->ek_fsidtype;
...@@ -244,13 +237,80 @@ static inline void svc_expkey_init(struct svc_expkey *new, struct svc_expkey *it ...@@ -244,13 +237,80 @@ static inline void svc_expkey_init(struct svc_expkey *new, struct svc_expkey *it
new->ek_fsid[2] = item->ek_fsid[2]; new->ek_fsid[2] = item->ek_fsid[2];
} }
static inline void svc_expkey_update(struct svc_expkey *new, struct svc_expkey *item) static inline void expkey_update(struct cache_head *cnew,
struct cache_head *citem)
{ {
struct svc_expkey *new = container_of(cnew, struct svc_expkey, h);
struct svc_expkey *item = container_of(citem, struct svc_expkey, h);
new->ek_mnt = mntget(item->ek_mnt); new->ek_mnt = mntget(item->ek_mnt);
new->ek_dentry = dget(item->ek_dentry); new->ek_dentry = dget(item->ek_dentry);
} }
static DefineSimpleCacheLookup(svc_expkey, svc_expkey) static struct cache_head *expkey_alloc(void)
{
struct svc_expkey *i = kmalloc(sizeof(*i), GFP_KERNEL);
if (i)
return &i->h;
else
return NULL;
}
struct cache_detail svc_expkey_cache = {
.owner = THIS_MODULE,
.hash_size = EXPKEY_HASHMAX,
.hash_table = expkey_table,
.name = "nfsd.fh",
.cache_put = expkey_put,
.cache_request = expkey_request,
.cache_parse = expkey_parse,
.cache_show = expkey_show,
.match = expkey_match,
.init = expkey_init,
.update = expkey_update,
.alloc = expkey_alloc,
};
static struct svc_expkey *
svc_expkey_lookup(struct svc_expkey *item)
{
struct cache_head *ch;
int hash = item->ek_fsidtype;
char * cp = (char*)item->ek_fsid;
int len = key_len(item->ek_fsidtype);
hash ^= hash_mem(cp, len, EXPKEY_HASHBITS);
hash ^= hash_ptr(item->ek_client, EXPKEY_HASHBITS);
hash &= EXPKEY_HASHMASK;
ch = sunrpc_cache_lookup(&svc_expkey_cache, &item->h,
hash);
if (ch)
return container_of(ch, struct svc_expkey, h);
else
return NULL;
}
static struct svc_expkey *
svc_expkey_update(struct svc_expkey *new, struct svc_expkey *old)
{
struct cache_head *ch;
int hash = new->ek_fsidtype;
char * cp = (char*)new->ek_fsid;
int len = key_len(new->ek_fsidtype);
hash ^= hash_mem(cp, len, EXPKEY_HASHBITS);
hash ^= hash_ptr(new->ek_client, EXPKEY_HASHBITS);
hash &= EXPKEY_HASHMASK;
ch = sunrpc_cache_update(&svc_expkey_cache, &new->h,
&old->h, hash);
if (ch)
return container_of(ch, struct svc_expkey, h);
else
return NULL;
}
#define EXPORT_HASHBITS 8 #define EXPORT_HASHBITS 8
#define EXPORT_HASHMAX (1<< EXPORT_HASHBITS) #define EXPORT_HASHMAX (1<< EXPORT_HASHBITS)
...@@ -549,7 +609,7 @@ exp_find_key(svc_client *clp, int fsid_type, u32 *fsidv, struct cache_req *reqp) ...@@ -549,7 +609,7 @@ exp_find_key(svc_client *clp, int fsid_type, u32 *fsidv, struct cache_req *reqp)
key.ek_fsidtype = fsid_type; key.ek_fsidtype = fsid_type;
memcpy(key.ek_fsid, fsidv, key_len(fsid_type)); memcpy(key.ek_fsid, fsidv, key_len(fsid_type));
ek = svc_expkey_lookup(&key, 0); ek = svc_expkey_lookup(&key);
if (ek != NULL) if (ek != NULL)
if ((err = cache_check(&svc_expkey_cache, &ek->h, reqp))) if ((err = cache_check(&svc_expkey_cache, &ek->h, reqp)))
ek = ERR_PTR(err); ek = ERR_PTR(err);
...@@ -569,7 +629,9 @@ static int exp_set_key(svc_client *clp, int fsid_type, u32 *fsidv, ...@@ -569,7 +629,9 @@ static int exp_set_key(svc_client *clp, int fsid_type, u32 *fsidv,
key.h.expiry_time = NEVER; key.h.expiry_time = NEVER;
key.h.flags = 0; key.h.flags = 0;
ek = svc_expkey_lookup(&key, 1); ek = svc_expkey_lookup(&key);
if (ek)
ek = svc_expkey_update(&key,ek);
if (ek) { if (ek) {
expkey_put(&ek->h, &svc_expkey_cache); expkey_put(&ek->h, &svc_expkey_cache);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment