static struct cache_head *rsi_table[RSI_HASHMAX];
static struct cache_detail rsi_cache;
-static struct rsi *rsi_update(struct rsi *new, struct rsi *old);
-static struct rsi *rsi_lookup(struct rsi *item);
+static struct rsi *rsi_lookup(struct rsi *item, int set);
static void rsi_free(struct rsi *rsii)
{
kfree(rsii->out_token.data);
}
-static void rsi_put(struct kref *ref)
+static void rsi_put(struct cache_head *item, struct cache_detail *cd)
{
- struct rsi *rsii = container_of(ref, struct rsi, h.ref);
- rsi_free(rsii);
- kfree(rsii);
+ struct rsi *rsii = container_of(item, struct rsi, h);
+ if (cache_put(item, cd)) {
+ rsi_free(rsii);
+ kfree(rsii);
+ }
}
static inline int rsi_hash(struct rsi *item)
^ hash_mem(item->in_token.data, item->in_token.len, RSI_HASHBITS);
}
-static int rsi_match(struct cache_head *a, struct cache_head *b)
+static inline int rsi_match(struct rsi *item, struct rsi *tmp)
{
- 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);
}
return dup_to_netobj(dst, src->data, src->len);
}
-static void rsi_init(struct cache_head *cnew, struct cache_head *citem)
+static inline void rsi_init(struct rsi *new, struct rsi *item)
{
- 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;
item->in_token.data = NULL;
}
-static void update_rsi(struct cache_head *cnew, struct cache_head *citem)
+static inline void rsi_update(struct rsi *new, struct rsi *item)
{
- 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;
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)
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);
goto out;
}
rsii.h.expiry_time = expiry;
- rsip = rsi_update(&rsii, rsip);
+ rsip = rsi_lookup(&rsii, 1);
status = 0;
out:
rsi_free(&rsii);
if (rsip)
- cache_put(&rsip->h, &rsi_cache);
- else
- status = -ENOMEM;
+ rsi_put(&rsip->h, &rsi_cache);
return status;
}
.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 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;
-}
-
+static DefineSimpleCacheLookup(rsi, 0)
/*
* The rpcsec_context cache is used to store a context that is
static struct cache_head *rsc_table[RSC_HASHMAX];
static struct cache_detail rsc_cache;
-static struct rsc *rsc_update(struct rsc *new, struct rsc *old);
-static struct rsc *rsc_lookup(struct rsc *item);
+static struct rsc *rsc_lookup(struct rsc *item, int set);
static void rsc_free(struct rsc *rsci)
{
put_group_info(rsci->cred.cr_group_info);
}
-static void rsc_put(struct kref *ref)
+static void rsc_put(struct cache_head *item, struct cache_detail *cd)
{
- struct rsc *rsci = container_of(ref, struct rsc, h.ref);
+ struct rsc *rsci = container_of(item, struct rsc, h);
- rsc_free(rsci);
- kfree(rsci);
+ if (cache_put(item, cd)) {
+ rsc_free(rsci);
+ kfree(rsci);
+ }
}
static inline int
return hash_mem(rsci->handle.data, rsci->handle.len, RSC_HASHBITS);
}
-static int
-rsc_match(struct cache_head *a, struct cache_head *b)
+static inline int
+rsc_match(struct rsc *new, struct rsc *tmp)
{
- 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);
}
-static void
-rsc_init(struct cache_head *cnew, struct cache_head *ctmp)
+static inline void
+rsc_init(struct rsc *new, struct rsc *tmp)
{
- struct rsc *new = container_of(cnew, struct rsc, h);
- struct rsc *tmp = container_of(ctmp, struct rsc, h);
-
new->handle.len = tmp->handle.len;
tmp->handle.len = 0;
new->handle.data = tmp->handle.data;
new->cred.cr_group_info = NULL;
}
-static void
-update_rsc(struct cache_head *cnew, struct cache_head *ctmp)
+static inline void
+rsc_update(struct rsc *new, struct rsc *tmp)
{
- struct rsc *new = container_of(cnew, struct rsc, h);
- struct rsc *tmp = container_of(ctmp, struct rsc, h);
-
new->mechctx = tmp->mechctx;
tmp->mechctx = NULL;
memset(&new->seqdata, 0, sizeof(new->seqdata));
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,
char *mesg, int mlen)
{
if (expiry == 0)
goto out;
- rscp = rsc_lookup(&rsci);
- if (!rscp)
- goto out;
-
/* uid, or NEGATIVE */
rv = get_int(&mesg, &rsci.cred.cr_uid);
if (rv == -EINVAL)
gss_mech_put(gm);
}
rsci.h.expiry_time = expiry;
- rscp = rsc_update(&rsci, rscp);
+ rscp = rsc_lookup(&rsci, 1);
status = 0;
out:
rsc_free(&rsci);
if (rscp)
- cache_put(&rscp->h, &rsc_cache);
- else
- status = -ENOMEM;
+ rsc_put(&rscp->h, &rsc_cache);
return status;
}
.name = "auth.rpcsec.context",
.cache_put = rsc_put,
.cache_parse = rsc_parse,
- .match = rsc_match,
- .init = rsc_init,
- .update = update_rsc,
- .alloc = rsc_alloc,
};
-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 DefineSimpleCacheLookup(rsc, 0);
static struct rsc *
gss_svc_searchbyctx(struct xdr_netobj *handle)
memset(&rsci, 0, sizeof(rsci));
if (dup_to_netobj(&rsci.handle, handle->data, handle->len))
return NULL;
- found = rsc_lookup(&rsci);
+ found = rsc_lookup(&rsci, 0);
rsc_free(&rsci);
if (!found)
return NULL;
return auth_domain_find(name);
}
-static struct auth_ops svcauthops_gss;
-
int
svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name)
{
new = kmalloc(sizeof(*new), GFP_KERNEL);
if (!new)
goto out;
- kref_init(&new->h.ref);
+ cache_init(&new->h.h);
new->h.name = kmalloc(strlen(name) + 1, GFP_KERNEL);
if (!new->h.name)
goto out_free_dom;
strcpy(new->h.name, name);
- new->h.flavour = &svcauthops_gss;
+ new->h.flavour = RPC_AUTH_GSS;
new->pseudoflavor = pseudoflavor;
+ new->h.h.expiry_time = NEVER;
- test = auth_domain_lookup(name, &new->h);
- if (test != &new->h) { /* XXX Duplicate registration? */
+ test = auth_domain_lookup(&new->h, 1);
+ if (test == &new->h) {
+ BUG_ON(atomic_dec_and_test(&new->h.h.refcnt));
+ } else { /* XXX Duplicate registration? */
auth_domain_put(&new->h);
- /* dangling ref-count... */
goto out;
}
return 0;
goto drop;
}
- rsip = rsi_lookup(&rsikey);
+ rsip = rsi_lookup(&rsikey, 0);
rsi_free(&rsikey);
if (!rsip) {
goto drop;
ret = SVC_DROP;
out:
if (rsci)
- cache_put(&rsci->h, &rsc_cache);
+ rsc_put(&rsci->h, &rsc_cache);
return ret;
}
integ_len))
BUG();
if (resbuf->page_len == 0
- && resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE
+ && resbuf->tail[0].iov_len + RPC_MAX_AUTH_SIZE
< PAGE_SIZE) {
BUG_ON(resbuf->tail[0].iov_len);
/* Use head for everything */
resv = &resbuf->head[0];
} else if (resbuf->tail[0].iov_base == NULL) {
- if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE
- > PAGE_SIZE)
- goto out_err;
- resbuf->tail[0].iov_base =
- resbuf->head[0].iov_base
- + resbuf->head[0].iov_len;
+ /* copied from nfsd4_encode_read */
+ svc_take_page(rqstp);
+ resbuf->tail[0].iov_base = page_address(rqstp
+ ->rq_respages[rqstp->rq_resused-1]);
+ rqstp->rq_restailpage = rqstp->rq_resused-1;
resbuf->tail[0].iov_len = 0;
- rqstp->rq_restailpage = 0;
resv = &resbuf->tail[0];
} else {
resv = &resbuf->tail[0];
put_group_info(rqstp->rq_cred.cr_group_info);
rqstp->rq_cred.cr_group_info = NULL;
if (gsd->rsci)
- cache_put(&gsd->rsci->h, &rsc_cache);
+ rsc_put(&gsd->rsci->h, &rsc_cache);
gsd->rsci = NULL;
return stat;