X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fptlrpc%2Fgss%2Fgss_svc_upcall.c;h=e266f67e6a15b8dc79f2134d735911d782b48843;hb=d69538b3c370460101e5e52d3164a54542dc31e0;hp=307f1efdc5650bdb0ec722cfe5b46d5f6d9baf75;hpb=aa145aa1fdfab120acd3de5cf5af067d9ca516f6;p=fs%2Flustre-release.git diff --git a/lustre/ptlrpc/gss/gss_svc_upcall.c b/lustre/ptlrpc/gss/gss_svc_upcall.c index 307f1efd..e266f67 100644 --- a/lustre/ptlrpc/gss/gss_svc_upcall.c +++ b/lustre/ptlrpc/gss/gss_svc_upcall.c @@ -1,10 +1,10 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * Modifications for Lustre * * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * + * Copyright (c) 2012, Intel Corporation. + * * Author: Eric Mei */ @@ -74,18 +74,18 @@ #define GSS_SVC_UPCALL_TIMEOUT (20) -static cfs_spinlock_t __ctx_index_lock; +static spinlock_t __ctx_index_lock; static __u64 __ctx_index; __u64 gss_get_next_ctx_index(void) { - __u64 idx; + __u64 idx; - cfs_spin_lock(&__ctx_index_lock); - idx = __ctx_index++; - cfs_spin_unlock(&__ctx_index_lock); + spin_lock(&__ctx_index_lock); + idx = __ctx_index++; + spin_unlock(&__ctx_index_lock); - return idx; + return idx; } static inline unsigned long hash_mem(char *buf, int length, int bits) @@ -132,12 +132,8 @@ struct rsi { static struct cache_head *rsi_table[RSI_HASHMAX]; static struct cache_detail rsi_cache; -#ifdef HAVE_SUNRPC_CACHE_V2 static struct rsi *rsi_update(struct rsi *new, struct rsi *old); static struct rsi *rsi_lookup(struct rsi *item); -#else -static struct rsi *rsi_lookup(struct rsi *item, int set); -#endif static inline int rsi_hash(struct rsi *item) { @@ -181,6 +177,13 @@ static void rsi_request(struct cache_detail *cd, (*bpp)[-1] = '\n'; } +#ifdef HAVE_CACHE_UPCALL +static int rsi_upcall(struct cache_detail *cd, struct cache_head *h) +{ + return sunrpc_cache_pipe_upcall(cd, h, rsi_request); +} +#endif + static inline void __rsi_init(struct rsi *new, struct rsi *item) { new->out_handle = RAWOBJ_EMPTY; @@ -210,8 +213,6 @@ static inline void __rsi_update(struct rsi *new, struct rsi *item) new->minor_status = item->minor_status; } -#ifdef HAVE_SUNRPC_CACHE_V2 - static void rsi_put(struct kref *ref) { struct rsi *rsi = container_of(ref, struct rsi, h.ref); @@ -349,141 +350,23 @@ out: RETURN(status); } -#else /* !HAVE_SUNRPC_CACHE_V2 */ - -static void rsi_put(struct cache_head *item, struct cache_detail *cd) -{ - struct rsi *rsi = container_of(item, struct rsi, h); - - LASSERT(cfs_atomic_read(&item->refcnt) > 0); - - if (cache_put(item, cd)) { - LASSERT(item->next == NULL); - rsi_free(rsi); - kfree(rsi); /* created by cache mgmt using kmalloc */ - } -} - -static inline int rsi_match(struct rsi *item, struct rsi *tmp) -{ - return __rsi_match(item, tmp); -} - -static inline void rsi_init(struct rsi *new, struct rsi *item) -{ - __rsi_init(new, item); -} - -static inline void rsi_update(struct rsi *new, struct rsi *item) -{ - __rsi_update(new, item); -} - -static int rsi_parse(struct cache_detail *cd, char *mesg, int mlen) -{ - char *buf = mesg; - char *ep; - int len; - struct rsi rsii, *rsip = NULL; - time_t expiry; - int status = -EINVAL; - ENTRY; - - - memset(&rsii, 0, sizeof(rsii)); - - /* handle */ - len = qword_get(&mesg, buf, mlen); - if (len < 0) - goto out; - if (rawobj_alloc(&rsii.in_handle, buf, len)) { - status = -ENOMEM; - goto out; - } - - /* token */ - len = qword_get(&mesg, buf, mlen); - if (len < 0) - goto out; - if (rawobj_alloc(&rsii.in_token, buf, len)) { - status = -ENOMEM; - goto out; - } - - /* expiry */ - expiry = get_expiry(&mesg); - if (expiry == 0) - goto out; - - len = qword_get(&mesg, buf, mlen); - if (len <= 0) - goto out; - - /* major */ - rsii.major_status = simple_strtol(buf, &ep, 10); - if (*ep) - goto out; - - /* minor */ - len = qword_get(&mesg, buf, mlen); - if (len <= 0) - goto out; - rsii.minor_status = simple_strtol(buf, &ep, 10); - if (*ep) - goto out; - - /* out_handle */ - len = qword_get(&mesg, buf, mlen); - if (len < 0) - goto out; - if (rawobj_alloc(&rsii.out_handle, buf, len)) { - status = -ENOMEM; - goto out; - } - - /* out_token */ - len = qword_get(&mesg, buf, mlen); - if (len < 0) - goto out; - if (rawobj_alloc(&rsii.out_token, buf, len)) { - status = -ENOMEM; - goto out; - } - - rsii.h.expiry_time = expiry; - rsip = rsi_lookup(&rsii, 1); - status = 0; -out: - rsi_free(&rsii); - if (rsip) { - cfs_waitq_broadcast(&rsip->waitq); - rsi_put(&rsip->h, &rsi_cache); - } - - if (status) - CERROR("rsi parse error %d\n", status); - RETURN(status); -} - -#endif /* HAVE_SUNRPC_CACHE_V2 */ - static struct cache_detail rsi_cache = { .hash_size = RSI_HASHMAX, .hash_table = rsi_table, .name = "auth.sptlrpc.init", .cache_put = rsi_put, +#ifdef HAVE_CACHE_UPCALL + .cache_upcall = rsi_upcall, +#else .cache_request = rsi_request, +#endif .cache_parse = rsi_parse, -#ifdef HAVE_SUNRPC_CACHE_V2 .match = rsi_match, .init = rsi_init, .update = update_rsi, .alloc = rsi_alloc, -#endif }; -#ifdef HAVE_SUNRPC_CACHE_V2 - static struct rsi *rsi_lookup(struct rsi *item) { struct cache_head *ch; @@ -508,12 +391,6 @@ static struct rsi *rsi_update(struct rsi *new, struct rsi *old) return NULL; } -#else - -static DefineSimpleCacheLookup(rsi, 0) - -#endif - /**************************************** * rsc cache * ****************************************/ @@ -531,12 +408,8 @@ struct rsc { static struct cache_head *rsc_table[RSC_HASHMAX]; static struct cache_detail rsc_cache; -#ifdef HAVE_SUNRPC_CACHE_V2 static struct rsc *rsc_update(struct rsc *new, struct rsc *old); static struct rsc *rsc_lookup(struct rsc *item); -#else -static struct rsc *rsc_lookup(struct rsc *item, int set); -#endif static void rsc_free(struct rsc *rsci) { @@ -573,11 +446,9 @@ static inline void __rsc_update(struct rsc *new, struct rsc *tmp) tmp->ctx.gsc_mechctx = NULL; memset(&new->ctx.gsc_seqdata, 0, sizeof(new->ctx.gsc_seqdata)); - cfs_spin_lock_init(&new->ctx.gsc_seqdata.ssd_lock); + spin_lock_init(&new->ctx.gsc_seqdata.ssd_lock); } -#ifdef HAVE_SUNRPC_CACHE_V2 - static void rsc_put(struct kref *ref) { struct rsc *rsci = container_of(ref, struct rsc, h.ref); @@ -696,7 +567,7 @@ static int rsc_parse(struct cache_detail *cd, char *mesg, int mlen) goto out; if (rv == -ENOENT) { CERROR("NOENT? set rsc entry negative\n"); - cfs_set_bit(CACHE_NEGATIVE, &rsci.h.flags); + set_bit(CACHE_NEGATIVE, &rsci.h.flags); } else { rawobj_t tmp_buf; unsigned long ctx_expiry; @@ -752,183 +623,18 @@ out: return status; } -#else /* !HAVE_SUNRPC_CACHE_V2 */ - -static void rsc_put(struct cache_head *item, struct cache_detail *cd) -{ - struct rsc *rsci = container_of(item, struct rsc, h); - - LASSERT(cfs_atomic_read(&item->refcnt) > 0); - - if (cache_put(item, cd)) { - LASSERT(item->next == NULL); - rsc_free(rsci); - kfree(rsci); /* created by cache mgmt using kmalloc */ - } -} - -static inline int rsc_match(struct rsc *new, struct rsc *tmp) -{ - return __rsc_match(new, tmp); -} - -static inline void rsc_init(struct rsc *new, struct rsc *tmp) -{ - __rsc_init(new, tmp); -} - -static inline void rsc_update(struct rsc *new, struct rsc *tmp) -{ - __rsc_update(new, tmp); -} - -static int rsc_parse(struct cache_detail *cd, char *mesg, int mlen) -{ - char *buf = mesg; - int len, rv, tmp_int; - struct rsc rsci, *rscp = NULL; - time_t expiry; - int status = -EINVAL; - - memset(&rsci, 0, sizeof(rsci)); - - /* context handle */ - len = qword_get(&mesg, buf, mlen); - if (len < 0) goto out; - status = -ENOMEM; - if (rawobj_alloc(&rsci.handle, buf, len)) - goto out; - - rsci.h.flags = 0; - /* expiry */ - expiry = get_expiry(&mesg); - status = -EINVAL; - if (expiry == 0) - goto out; - - /* remote flag */ - rv = get_int(&mesg, &tmp_int); - if (rv) { - CERROR("fail to get remote flag\n"); - goto out; - } - rsci.ctx.gsc_remote = (tmp_int != 0); - - /* root user flag */ - rv = get_int(&mesg, &tmp_int); - if (rv) { - CERROR("fail to get oss user flag\n"); - goto out; - } - rsci.ctx.gsc_usr_root = (tmp_int != 0); - - /* mds user flag */ - rv = get_int(&mesg, &tmp_int); - if (rv) { - CERROR("fail to get mds user flag\n"); - goto out; - } - rsci.ctx.gsc_usr_mds = (tmp_int != 0); - - /* oss user flag */ - rv = get_int(&mesg, &tmp_int); - if (rv) { - CERROR("fail to get oss user flag\n"); - goto out; - } - rsci.ctx.gsc_usr_oss = (tmp_int != 0); - - /* mapped uid */ - rv = get_int(&mesg, (int *) &rsci.ctx.gsc_mapped_uid); - if (rv) { - CERROR("fail to get mapped uid\n"); - goto out; - } - - /* uid, or NEGATIVE */ - rv = get_int(&mesg, (int *) &rsci.ctx.gsc_uid); - if (rv == -EINVAL) - goto out; - if (rv == -ENOENT) { - CERROR("NOENT? set rsc entry negative\n"); - cfs_set_bit(CACHE_NEGATIVE, &rsci.h.flags); - } else { - struct gss_api_mech *gm; - rawobj_t tmp_buf; - unsigned long ctx_expiry; - - /* gid */ - if (get_int(&mesg, (int *) &rsci.ctx.gsc_gid)) - goto out; - - /* mech name */ - len = qword_get(&mesg, buf, mlen); - if (len < 0) - goto out; - gm = lgss_name_to_mech(buf); - status = -EOPNOTSUPP; - if (!gm) - goto out; - - status = -EINVAL; - /* mech-specific data: */ - len = qword_get(&mesg, buf, mlen); - if (len < 0) { - lgss_mech_put(gm); - goto out; - } - tmp_buf.len = len; - tmp_buf.data = (unsigned char *)buf; - if (lgss_import_sec_context(&tmp_buf, gm, - &rsci.ctx.gsc_mechctx)) { - lgss_mech_put(gm); - goto out; - } - - /* currently the expiry time passed down from user-space - * is invalid, here we retrive it from mech. */ - if (lgss_inquire_context(rsci.ctx.gsc_mechctx, &ctx_expiry)) { - CERROR("unable to get expire time, drop it\n"); - lgss_mech_put(gm); - goto out; - } - expiry = (time_t) ctx_expiry; - - lgss_mech_put(gm); - } - - rsci.h.expiry_time = expiry; - rscp = rsc_lookup(&rsci, 1); - status = 0; -out: - rsc_free(&rsci); - if (rscp) - rsc_put(&rscp->h, &rsc_cache); - - if (status) - CERROR("parse rsc error %d\n", status); - return status; -} - -#endif /* HAVE_SUNRPC_CACHE_V2 */ - - static struct cache_detail rsc_cache = { .hash_size = RSC_HASHMAX, .hash_table = rsc_table, .name = "auth.sptlrpc.context", .cache_put = rsc_put, .cache_parse = rsc_parse, -#ifdef HAVE_SUNRPC_CACHE_V2 .match = rsc_match, .init = rsc_init, .update = update_rsc, .alloc = rsc_alloc, -#endif }; -#ifdef HAVE_SUNRPC_CACHE_V2 - static struct rsc *rsc_lookup(struct rsc *item) { struct cache_head *ch; @@ -955,14 +661,6 @@ static struct rsc *rsc_update(struct rsc *new, struct rsc *old) #define COMPAT_RSC_PUT(item, cd) cache_put((item), (cd)) -#else - -static DefineSimpleCacheLookup(rsc, 0); - -#define COMPAT_RSC_PUT(item, cd) rsc_put((item), (cd)) - -#endif - /**************************************** * rsc cache flush * ****************************************/ @@ -976,7 +674,7 @@ static void rsc_flush(rsc_entry_match *match, long data) int n; ENTRY; - cfs_write_lock(&rsc_cache.hash_lock); + write_lock(&rsc_cache.hash_lock); for (n = 0; n < RSC_HASHMAX; n++) { for (ch = &rsc_cache.hash_table[n]; *ch;) { rscp = container_of(*ch, struct rsc, h); @@ -990,12 +688,12 @@ static void rsc_flush(rsc_entry_match *match, long data) *ch = (*ch)->next; rscp->h.next = NULL; cache_get(&rscp->h); - cfs_set_bit(CACHE_NEGATIVE, &rscp->h.flags); + set_bit(CACHE_NEGATIVE, &rscp->h.flags); COMPAT_RSC_PUT(&rscp->h, &rsc_cache); rsc_cache.entries--; } } - cfs_write_unlock(&rsc_cache.hash_lock); + write_unlock(&rsc_cache.hash_lock); EXIT; } @@ -1039,11 +737,7 @@ static struct rsc *gss_svc_searchbyctx(rawobj_t *handle) if (rawobj_dup(&rsci.handle, handle)) return NULL; -#ifdef HAVE_SUNRPC_CACHE_V2 found = rsc_lookup(&rsci); -#else - found = rsc_lookup(&rsci, 0); -#endif rsc_free(&rsci); if (!found) return NULL; @@ -1052,8 +746,6 @@ static struct rsc *gss_svc_searchbyctx(rawobj_t *handle) return found; } -#ifdef HAVE_SUNRPC_CACHE_V2 - int gss_svc_upcall_install_rvs_ctx(struct obd_import *imp, struct gss_sec *gsec, struct gss_cli_ctx *gctx) @@ -1113,65 +805,6 @@ out: RETURN(rc); } -#else /* !HAVE_SUNRPC_CACHE_V2 */ - -int gss_svc_upcall_install_rvs_ctx(struct obd_import *imp, - struct gss_sec *gsec, - struct gss_cli_ctx *gctx) -{ - struct rsc rsci, *rscp; - unsigned long ctx_expiry; - __u32 major; - int rc; - ENTRY; - - memset(&rsci, 0, sizeof(rsci)); - - if (rawobj_alloc(&rsci.handle, (char *) &gsec->gs_rvs_hdl, - sizeof(gsec->gs_rvs_hdl))) - GOTO(out, rc = -ENOMEM); - - major = lgss_copy_reverse_context(gctx->gc_mechctx, - &rsci.ctx.gsc_mechctx); - if (major != GSS_S_COMPLETE) - GOTO(out, rc = -ENOMEM); - - if (lgss_inquire_context(rsci.ctx.gsc_mechctx, &ctx_expiry)) { - CERROR("unable to get expire time, drop it\n"); - GOTO(out, rc = -ENOMEM); - } - rsci.h.expiry_time = (time_t) ctx_expiry; - - if (strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0) - rsci.ctx.gsc_usr_mds = 1; - else if (strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0) - rsci.ctx.gsc_usr_oss = 1; - else - rsci.ctx.gsc_usr_root = 1; - - rscp = rsc_lookup(&rsci, 1); - if (rscp == NULL) { - CERROR("rsc lookup failed\n"); - GOTO(out, rc = -ENOMEM); - } - - rscp->target = imp->imp_obd; - rawobj_dup(&gctx->gc_svc_handle, &rscp->handle); - - CWARN("create reverse svc ctx %p to %s: idx "LPX64"\n", - &rscp->ctx, obd2cli_tgt(imp->imp_obd), gsec->gs_rvs_hdl); - rsc_put(&rscp->h, &rsc_cache); - rc = 0; -out: - rsc_free(&rsci); - if (rc) - CERROR("create reverse svc ctx: idx "LPX64", rc %d\n", - gsec->gs_rvs_hdl, rc); - RETURN(rc); -} - -#endif /* HAVE_SUNRPC_CACHE_V2 */ - int gss_svc_upcall_expire_rvs_ctx(rawobj_t *handle) { const cfs_time_t expire = 20; @@ -1250,11 +883,7 @@ int gss_svc_upcall_handle_init(struct ptlrpc_request *req, GOTO(out, rc); } -#ifdef HAVE_SUNRPC_CACHE_V2 rsip = rsi_lookup(&rsikey); -#else - rsip = rsi_lookup(&rsikey, 0); -#endif rsi_free(&rsikey); if (!rsip) { CERROR("error in rsi_lookup.\n"); @@ -1283,7 +912,7 @@ cache_check: first_check = 0; read_lock(&rsi_cache.hash_lock); - valid = cfs_test_bit(CACHE_VALID, &rsip->h.flags); + valid = test_bit(CACHE_VALID, &rsip->h.flags); if (valid == 0) cfs_set_current_state(CFS_TASK_INTERRUPTIBLE); read_unlock(&rsi_cache.hash_lock); @@ -1390,7 +1019,7 @@ out: if (rsci) { /* if anything went wrong, we don't keep the context too */ if (rc != SECSVC_OK) - cfs_set_bit(CACHE_NEGATIVE, &rsci->h.flags); + set_bit(CACHE_NEGATIVE, &rsci->h.flags); else CDEBUG(D_SEC, "create rsc with idx "LPX64"\n", gss_handle_to_u64(&rsci->handle)); @@ -1428,16 +1057,16 @@ void gss_svc_upcall_destroy_ctx(struct gss_svc_ctx *ctx) struct rsc *rsc = container_of(ctx, struct rsc, ctx); /* can't be found */ - cfs_set_bit(CACHE_NEGATIVE, &rsc->h.flags); + set_bit(CACHE_NEGATIVE, &rsc->h.flags); /* to be removed at next scan */ rsc->h.expiry_time = 1; } int __init gss_init_svc_upcall(void) { - int i; + int i; - cfs_spin_lock_init(&__ctx_index_lock); + spin_lock_init(&__ctx_index_lock); /* * this helps reducing context index confliction. after server reboot, * conflicting request from clients might be filtered out by initial