Commit 17f834b6 authored by NeilBrown's avatar NeilBrown Committed by Linus Torvalds

[PATCH] knfsd: Use new cache code for rsc 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 d4d11ea9
...@@ -345,7 +345,8 @@ struct rsc { ...@@ -345,7 +345,8 @@ struct rsc {
static struct cache_head *rsc_table[RSC_HASHMAX]; static struct cache_head *rsc_table[RSC_HASHMAX];
static struct cache_detail rsc_cache; static struct cache_detail rsc_cache;
static struct rsc *rsc_lookup(struct rsc *item, int set); static struct rsc *rsc_update(struct rsc *new, struct rsc *old);
static struct rsc *rsc_lookup(struct rsc *item);
static void rsc_free(struct rsc *rsci) static void rsc_free(struct rsc *rsci)
{ {
...@@ -372,15 +373,21 @@ rsc_hash(struct rsc *rsci) ...@@ -372,15 +373,21 @@ rsc_hash(struct rsc *rsci)
return hash_mem(rsci->handle.data, rsci->handle.len, RSC_HASHBITS); return hash_mem(rsci->handle.data, rsci->handle.len, RSC_HASHBITS);
} }
static inline int static int
rsc_match(struct rsc *new, struct rsc *tmp) rsc_match(struct cache_head *a, struct cache_head *b)
{ {
struct rsc *new = container_of(a, struct rsc, h);
struct rsc *tmp = container_of(b, struct rsc, h);
return netobj_equal(&new->handle, &tmp->handle); return netobj_equal(&new->handle, &tmp->handle);
} }
static inline void static void
rsc_init(struct rsc *new, struct rsc *tmp) rsc_init(struct cache_head *cnew, struct cache_head *ctmp)
{ {
struct rsc *new = container_of(cnew, struct rsc, h);
struct rsc *tmp = container_of(ctmp, struct rsc, h);
new->handle.len = tmp->handle.len; new->handle.len = tmp->handle.len;
tmp->handle.len = 0; tmp->handle.len = 0;
new->handle.data = tmp->handle.data; new->handle.data = tmp->handle.data;
...@@ -389,9 +396,12 @@ rsc_init(struct rsc *new, struct rsc *tmp) ...@@ -389,9 +396,12 @@ rsc_init(struct rsc *new, struct rsc *tmp)
new->cred.cr_group_info = NULL; new->cred.cr_group_info = NULL;
} }
static inline void static void
rsc_update(struct rsc *new, struct rsc *tmp) update_rsc(struct cache_head *cnew, struct cache_head *ctmp)
{ {
struct rsc *new = container_of(cnew, struct rsc, h);
struct rsc *tmp = container_of(ctmp, struct rsc, h);
new->mechctx = tmp->mechctx; new->mechctx = tmp->mechctx;
tmp->mechctx = NULL; tmp->mechctx = NULL;
memset(&new->seqdata, 0, sizeof(new->seqdata)); memset(&new->seqdata, 0, sizeof(new->seqdata));
...@@ -400,6 +410,16 @@ rsc_update(struct rsc *new, struct rsc *tmp) ...@@ -400,6 +410,16 @@ rsc_update(struct rsc *new, struct rsc *tmp)
tmp->cred.cr_group_info = NULL; tmp->cred.cr_group_info = NULL;
} }
static struct cache_head *
rsc_alloc(void)
{
struct rsc *rsci = kmalloc(sizeof(*rsci), GFP_KERNEL);
if (rsci)
return &rsci->h;
else
return NULL;
}
static int rsc_parse(struct cache_detail *cd, static int rsc_parse(struct cache_detail *cd,
char *mesg, int mlen) char *mesg, int mlen)
{ {
...@@ -425,6 +445,10 @@ static int rsc_parse(struct cache_detail *cd, ...@@ -425,6 +445,10 @@ static int rsc_parse(struct cache_detail *cd,
if (expiry == 0) if (expiry == 0)
goto out; goto out;
rscp = rsc_lookup(&rsci);
if (!rscp)
goto out;
/* uid, or NEGATIVE */ /* uid, or NEGATIVE */
rv = get_int(&mesg, &rsci.cred.cr_uid); rv = get_int(&mesg, &rsci.cred.cr_uid);
if (rv == -EINVAL) if (rv == -EINVAL)
...@@ -480,12 +504,14 @@ static int rsc_parse(struct cache_detail *cd, ...@@ -480,12 +504,14 @@ static int rsc_parse(struct cache_detail *cd,
gss_mech_put(gm); gss_mech_put(gm);
} }
rsci.h.expiry_time = expiry; rsci.h.expiry_time = expiry;
rscp = rsc_lookup(&rsci, 1); rscp = rsc_update(&rsci, rscp);
status = 0; status = 0;
out: out:
rsc_free(&rsci); rsc_free(&rsci);
if (rscp) if (rscp)
rsc_put(&rscp->h, &rsc_cache); rsc_put(&rscp->h, &rsc_cache);
else
status = -ENOMEM;
return status; return status;
} }
...@@ -496,9 +522,37 @@ static struct cache_detail rsc_cache = { ...@@ -496,9 +522,37 @@ static struct cache_detail rsc_cache = {
.name = "auth.rpcsec.context", .name = "auth.rpcsec.context",
.cache_put = rsc_put, .cache_put = rsc_put,
.cache_parse = rsc_parse, .cache_parse = rsc_parse,
.match = rsc_match,
.init = rsc_init,
.update = update_rsc,
.alloc = rsc_alloc,
}; };
static DefineSimpleCacheLookup(rsc, rsc); static struct rsc *rsc_lookup(struct rsc *item)
{
struct cache_head *ch;
int hash = rsc_hash(item);
ch = sunrpc_cache_lookup(&rsc_cache, &item->h, hash);
if (ch)
return container_of(ch, struct rsc, h);
else
return NULL;
}
static struct rsc *rsc_update(struct rsc *new, struct rsc *old)
{
struct cache_head *ch;
int hash = rsc_hash(new);
ch = sunrpc_cache_update(&rsc_cache, &new->h,
&old->h, hash);
if (ch)
return container_of(ch, struct rsc, h);
else
return NULL;
}
static struct rsc * static struct rsc *
gss_svc_searchbyctx(struct xdr_netobj *handle) gss_svc_searchbyctx(struct xdr_netobj *handle)
...@@ -509,7 +563,7 @@ gss_svc_searchbyctx(struct xdr_netobj *handle) ...@@ -509,7 +563,7 @@ gss_svc_searchbyctx(struct xdr_netobj *handle)
memset(&rsci, 0, sizeof(rsci)); memset(&rsci, 0, sizeof(rsci));
if (dup_to_netobj(&rsci.handle, handle->data, handle->len)) if (dup_to_netobj(&rsci.handle, handle->data, handle->len))
return NULL; return NULL;
found = rsc_lookup(&rsci, 0); found = rsc_lookup(&rsci);
rsc_free(&rsci); rsc_free(&rsci);
if (!found) if (!found)
return NULL; return NULL;
......
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