Merge branch 'mv-merge'
[powerpc.git] / net / sunrpc / auth_gss / svcauth_gss.c
index 237d935..4d7eb9e 100644 (file)
@@ -89,13 +89,11 @@ static void rsi_free(struct rsi *rsii)
        kfree(rsii->out_token.data);
 }
 
-static void rsi_put(struct cache_head *item, struct cache_detail *cd)
+static void rsi_put(struct kref *ref)
 {
-       struct rsi *rsii = container_of(item, struct rsi, h);
-       if (cache_put(item, cd)) {
-               rsi_free(rsii);
-               kfree(rsii);
-       }
+       struct rsi *rsii = container_of(ref, struct rsi, h.ref);
+       rsi_free(rsii);
+       kfree(rsii);
 }
 
 static inline int rsi_hash(struct rsi *item)
@@ -267,7 +265,7 @@ static int rsi_parse(struct cache_detail *cd,
 out:
        rsi_free(&rsii);
        if (rsip)
-               rsi_put(&rsip->h, &rsi_cache);
+               cache_put(&rsip->h, &rsi_cache);
        else
                status = -ENOMEM;
        return status;
@@ -345,7 +343,8 @@ struct rsc {
 
 static struct cache_head *rsc_table[RSC_HASHMAX];
 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)
 {
@@ -356,14 +355,12 @@ static void rsc_free(struct rsc *rsci)
                put_group_info(rsci->cred.cr_group_info);
 }
 
-static void rsc_put(struct cache_head *item, struct cache_detail *cd)
+static void rsc_put(struct kref *ref)
 {
-       struct rsc *rsci = container_of(item, struct rsc, h);
+       struct rsc *rsci = container_of(ref, struct rsc, h.ref);
 
-       if (cache_put(item, cd)) {
-               rsc_free(rsci);
-               kfree(rsci);
-       }
+       rsc_free(rsci);
+       kfree(rsci);
 }
 
 static inline int
@@ -372,15 +369,21 @@ rsc_hash(struct rsc *rsci)
        return hash_mem(rsci->handle.data, rsci->handle.len, RSC_HASHBITS);
 }
 
-static inline int
-rsc_match(struct rsc *new, struct rsc *tmp)
+static int
+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);
 }
 
-static inline void
-rsc_init(struct rsc *new, struct rsc *tmp)
+static void
+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;
        tmp->handle.len = 0;
        new->handle.data = tmp->handle.data;
@@ -389,9 +392,12 @@ rsc_init(struct rsc *new, struct rsc *tmp)
        new->cred.cr_group_info = NULL;
 }
 
-static inline void
-rsc_update(struct rsc *new, struct rsc *tmp)
+static void
+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;
        tmp->mechctx = NULL;
        memset(&new->seqdata, 0, sizeof(new->seqdata));
@@ -400,6 +406,16 @@ rsc_update(struct rsc *new, struct rsc *tmp)
        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)
 {
@@ -425,6 +441,10 @@ 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)
@@ -480,12 +500,14 @@ static int rsc_parse(struct cache_detail *cd,
                gss_mech_put(gm);
        }
        rsci.h.expiry_time = expiry;
-       rscp = rsc_lookup(&rsci, 1);
+       rscp = rsc_update(&rsci, rscp);
        status = 0;
 out:
        rsc_free(&rsci);
        if (rscp)
-               rsc_put(&rscp->h, &rsc_cache);
+               cache_put(&rscp->h, &rsc_cache);
+       else
+               status = -ENOMEM;
        return status;
 }
 
@@ -496,9 +518,37 @@ 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 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 *
 gss_svc_searchbyctx(struct xdr_netobj *handle)
@@ -509,7 +559,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, 0);
+       found = rsc_lookup(&rsci);
        rsc_free(&rsci);
        if (!found)
                return NULL;
@@ -1022,7 +1072,7 @@ drop:
        ret = SVC_DROP;
 out:
        if (rsci)
-               rsc_put(&rsci->h, &rsc_cache);
+               cache_put(&rsci->h, &rsc_cache);
        return ret;
 }
 
@@ -1114,7 +1164,7 @@ out_err:
                put_group_info(rqstp->rq_cred.cr_group_info);
        rqstp->rq_cred.cr_group_info = NULL;
        if (gsd->rsci)
-               rsc_put(&gsd->rsci->h, &rsc_cache);
+               cache_put(&gsd->rsci->h, &rsc_cache);
        gsd->rsci = NULL;
 
        return stat;