Skip to content

Commit

Permalink
[PATCH] knfsd: Use new sunrpc cache for rsi cache
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
NeilBrown authored and Linus Torvalds committed Mar 27, 2006
1 parent 8d270f7 commit d4d11ea
Showing 1 changed file with 59 additions and 7 deletions.
66 changes: 59 additions & 7 deletions net/sunrpc/auth_gss/svcauth_gss.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ struct rsi {

static struct cache_head *rsi_table[RSI_HASHMAX];
static struct cache_detail rsi_cache;
static struct rsi *rsi_lookup(struct rsi *item, int set);
static struct rsi *rsi_update(struct rsi *new, struct rsi *old);
static struct rsi *rsi_lookup(struct rsi *item);

static void rsi_free(struct rsi *rsii)
{
Expand All @@ -103,8 +104,10 @@ static inline int rsi_hash(struct rsi *item)
^ hash_mem(item->in_token.data, item->in_token.len, RSI_HASHBITS);
}

static inline int rsi_match(struct rsi *item, struct rsi *tmp)
static int rsi_match(struct cache_head *a, struct cache_head *b)
{
struct rsi *item = container_of(a, struct rsi, h);
struct rsi *tmp = container_of(b, struct rsi, h);
return netobj_equal(&item->in_handle, &tmp->in_handle)
&& netobj_equal(&item->in_token, &tmp->in_token);
}
Expand All @@ -125,8 +128,11 @@ static inline int dup_netobj(struct xdr_netobj *dst, struct xdr_netobj *src)
return dup_to_netobj(dst, src->data, src->len);
}

static inline void rsi_init(struct rsi *new, struct rsi *item)
static void rsi_init(struct cache_head *cnew, struct cache_head *citem)
{
struct rsi *new = container_of(cnew, struct rsi, h);
struct rsi *item = container_of(citem, struct rsi, h);

new->out_handle.data = NULL;
new->out_handle.len = 0;
new->out_token.data = NULL;
Expand All @@ -141,8 +147,11 @@ static inline void rsi_init(struct rsi *new, struct rsi *item)
item->in_token.data = NULL;
}

static inline void rsi_update(struct rsi *new, struct rsi *item)
static void update_rsi(struct cache_head *cnew, struct cache_head *citem)
{
struct rsi *new = container_of(cnew, struct rsi, h);
struct rsi *item = container_of(citem, struct rsi, h);

BUG_ON(new->out_handle.data || new->out_token.data);
new->out_handle.len = item->out_handle.len;
item->out_handle.len = 0;
Expand All @@ -157,6 +166,15 @@ static inline void rsi_update(struct rsi *new, struct rsi *item)
new->minor_status = item->minor_status;
}

static struct cache_head *rsi_alloc(void)
{
struct rsi *rsii = kmalloc(sizeof(*rsii), GFP_KERNEL);
if (rsii)
return &rsii->h;
else
return NULL;
}

static void rsi_request(struct cache_detail *cd,
struct cache_head *h,
char **bpp, int *blen)
Expand Down Expand Up @@ -198,6 +216,10 @@ static int rsi_parse(struct cache_detail *cd,
if (dup_to_netobj(&rsii.in_token, buf, len))
goto out;

rsip = rsi_lookup(&rsii);
if (!rsip)
goto out;

rsii.h.flags = 0;
/* expiry */
expiry = get_expiry(&mesg);
Expand Down Expand Up @@ -240,12 +262,14 @@ static int rsi_parse(struct cache_detail *cd,
goto out;
}
rsii.h.expiry_time = expiry;
rsip = rsi_lookup(&rsii, 1);
rsip = rsi_update(&rsii, rsip);
status = 0;
out:
rsi_free(&rsii);
if (rsip)
rsi_put(&rsip->h, &rsi_cache);
else
status = -ENOMEM;
return status;
}

Expand All @@ -257,9 +281,37 @@ static struct cache_detail rsi_cache = {
.cache_put = rsi_put,
.cache_request = rsi_request,
.cache_parse = rsi_parse,
.match = rsi_match,
.init = rsi_init,
.update = update_rsi,
.alloc = rsi_alloc,
};

static DefineSimpleCacheLookup(rsi, rsi)
static struct rsi *rsi_lookup(struct rsi *item)
{
struct cache_head *ch;
int hash = rsi_hash(item);

ch = sunrpc_cache_lookup(&rsi_cache, &item->h, hash);
if (ch)
return container_of(ch, struct rsi, h);
else
return NULL;
}

static struct rsi *rsi_update(struct rsi *new, struct rsi *old)
{
struct cache_head *ch;
int hash = rsi_hash(new);

ch = sunrpc_cache_update(&rsi_cache, &new->h,
&old->h, hash);
if (ch)
return container_of(ch, struct rsi, h);
else
return NULL;
}


/*
* The rpcsec_context cache is used to store a context that is
Expand Down Expand Up @@ -895,7 +947,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp, u32 *authp)
goto drop;
}

rsip = rsi_lookup(&rsikey, 0);
rsip = rsi_lookup(&rsikey);
rsi_free(&rsikey);
if (!rsip) {
goto drop;
Expand Down

0 comments on commit d4d11ea

Please sign in to comment.