X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=net%2Fsunrpc%2Fauth_gss%2Fsvcauth_gss.c;h=23632d84d8d7c105c2e61cf37a33e11c2e140fe5;hb=987b0145d94eecf292d8b301228356f44611ab7c;hp=d51e316c5821022690a88d93eadcf28b9ea31597;hpb=f7ed79d23a47594e7834d66a8f14449796d4f3e6;p=linux-2.6.git diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index d51e316c5..23632d84d 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -78,8 +78,7 @@ struct rsi { 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) { @@ -89,11 +88,13 @@ 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) @@ -102,10 +103,8 @@ 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); } @@ -126,11 +125,8 @@ static inline int dup_netobj(struct xdr_netobj *dst, struct xdr_netobj *src) 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; @@ -145,11 +141,8 @@ static void rsi_init(struct cache_head *cnew, struct cache_head *citem) 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; @@ -164,15 +157,6 @@ static void update_rsi(struct cache_head *cnew, struct cache_head *citem) 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) @@ -214,10 +198,6 @@ 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); @@ -260,14 +240,12 @@ static int rsi_parse(struct cache_detail *cd, 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; } @@ -279,37 +257,9 @@ 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 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 @@ -343,8 +293,7 @@ struct rsc { 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) { @@ -355,12 +304,14 @@ 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 @@ -369,21 +320,15 @@ rsc_hash(struct rsc *rsci) 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; @@ -392,12 +337,9 @@ rsc_init(struct cache_head *cnew, struct cache_head *ctmp) 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)); @@ -406,16 +348,6 @@ update_rsc(struct cache_head *cnew, struct cache_head *ctmp) 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) { @@ -441,10 +373,6 @@ static int rsc_parse(struct cache_detail *cd, 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) @@ -500,14 +428,12 @@ static int rsc_parse(struct cache_detail *cd, 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; } @@ -518,37 +444,9 @@ static struct cache_detail rsc_cache = { .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) @@ -559,7 +457,7 @@ 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; @@ -747,8 +645,6 @@ find_gss_auth_domain(struct gss_ctx *ctx, u32 svc) return auth_domain_find(name); } -static struct auth_ops svcauthops_gss; - int svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name) { @@ -759,18 +655,20 @@ 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; @@ -997,7 +895,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp, u32 *authp) goto drop; } - rsip = rsi_lookup(&rsikey); + rsip = rsi_lookup(&rsikey, 0); rsi_free(&rsikey); if (!rsip) { goto drop; @@ -1072,7 +970,7 @@ drop: ret = SVC_DROP; out: if (rsci) - cache_put(&rsci->h, &rsc_cache); + rsc_put(&rsci->h, &rsc_cache); return ret; } @@ -1122,20 +1020,18 @@ svcauth_gss_release(struct svc_rqst *rqstp) 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]; @@ -1166,7 +1062,7 @@ out_err: 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;