X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fptlrpc%2Fgss%2Fgss_keyring.c;h=5256adc0ff1af21d63cfd9a34993f86014430a45;hb=37e738fbde6220164da7b9c2097065eb323e2da7;hp=05a1b0f3a342cb97078da163b10ed98aa98ae486;hpb=2420f7ef2b7efbc715735019fa632146b23f2546;p=fs%2Flustre-release.git diff --git a/lustre/ptlrpc/gss/gss_keyring.c b/lustre/ptlrpc/gss/gss_keyring.c index 05a1b0f..5256adc 100644 --- a/lustre/ptlrpc/gss/gss_keyring.c +++ b/lustre/ptlrpc/gss/gss_keyring.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2014, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -39,7 +39,6 @@ */ #define DEBUG_SUBSYSTEM S_SEC -#ifdef __KERNEL__ #include #include #include @@ -51,9 +50,6 @@ #include #include #include -#else -#include -#endif #include #include @@ -122,7 +118,11 @@ static int sec_install_rctx_kr(struct ptlrpc_sec *sec, } #define key_cred(tsk) ((tsk)->cred) +#ifdef HAVE_CRED_TGCRED #define key_tgcred(tsk) ((tsk)->cred->tgcred) +#else +#define key_tgcred(tsk) key_cred(tsk) +#endif static inline void keyring_upcall_lock(struct gss_sec_keyring *gsec_kr) { @@ -164,7 +164,8 @@ static void ctx_start_timer_kr(struct ptlrpc_cli_ctx *ctx, long timeout) LASSERT(timer); CDEBUG(D_SEC, "ctx %p: start timer %lds\n", ctx, timeout); - timeout = timeout * HZ + cfs_time_current(); + timeout = msecs_to_jiffies(timeout * MSEC_PER_SEC) + + cfs_time_current(); init_timer(timer); timer->expires = timeout; @@ -221,55 +222,55 @@ struct ptlrpc_cli_ctx *ctx_create_kr(struct ptlrpc_sec *sec, return NULL; } - ctx->cc_expire = cfs_time_current_sec() + KEYRING_UPCALL_TIMEOUT; + ctx->cc_expire = cfs_time_current_sec() + KEYRING_UPCALL_TIMEOUT; clear_bit(PTLRPC_CTX_NEW_BIT, &ctx->cc_flags); - cfs_atomic_inc(&ctx->cc_refcount); /* for the caller */ + atomic_inc(&ctx->cc_refcount); /* for the caller */ - return ctx; + return ctx; } static void ctx_destroy_kr(struct ptlrpc_cli_ctx *ctx) { - struct ptlrpc_sec *sec = ctx->cc_sec; - struct gss_cli_ctx_keyring *gctx_kr = ctx2gctx_keyring(ctx); + struct ptlrpc_sec *sec = ctx->cc_sec; + struct gss_cli_ctx_keyring *gctx_kr = ctx2gctx_keyring(ctx); - CDEBUG(D_SEC, "destroying ctx %p\n", ctx); + CDEBUG(D_SEC, "destroying ctx %p\n", ctx); /* at this time the association with key has been broken. */ LASSERT(sec); - LASSERT(cfs_atomic_read(&sec->ps_refcount) > 0); - LASSERT(cfs_atomic_read(&sec->ps_nctx) > 0); + LASSERT(atomic_read(&sec->ps_refcount) > 0); + LASSERT(atomic_read(&sec->ps_nctx) > 0); LASSERT(test_bit(PTLRPC_CTX_CACHED_BIT, &ctx->cc_flags) == 0); LASSERT(gctx_kr->gck_key == NULL); - ctx_clear_timer_kr(ctx); - LASSERT(gctx_kr->gck_timer == NULL); + ctx_clear_timer_kr(ctx); + LASSERT(gctx_kr->gck_timer == NULL); - if (gss_cli_ctx_fini_common(sec, ctx)) - return; + if (gss_cli_ctx_fini_common(sec, ctx)) + return; - OBD_FREE_PTR(gctx_kr); + OBD_FREE_PTR(gctx_kr); - cfs_atomic_dec(&sec->ps_nctx); - sptlrpc_sec_put(sec); + atomic_dec(&sec->ps_nctx); + sptlrpc_sec_put(sec); } static void ctx_release_kr(struct ptlrpc_cli_ctx *ctx, int sync) { - if (sync) { - ctx_destroy_kr(ctx); - } else { - cfs_atomic_inc(&ctx->cc_refcount); - sptlrpc_gc_add_ctx(ctx); - } + if (sync) { + ctx_destroy_kr(ctx); + } else { + atomic_inc(&ctx->cc_refcount); + sptlrpc_gc_add_ctx(ctx); + } } static void ctx_put_kr(struct ptlrpc_cli_ctx *ctx, int sync) { - LASSERT(cfs_atomic_read(&ctx->cc_refcount) > 0); + LASSERT(atomic_read(&ctx->cc_refcount) > 0); - if (cfs_atomic_dec_and_test(&ctx->cc_refcount)) - ctx_release_kr(ctx, sync); + if (atomic_dec_and_test(&ctx->cc_refcount)) + ctx_release_kr(ctx, sync); } /* @@ -300,17 +301,17 @@ static inline void spin_unlock_if(spinlock_t *lock, int condition) static void ctx_enlist_kr(struct ptlrpc_cli_ctx *ctx, int is_root, int locked) { - struct ptlrpc_sec *sec = ctx->cc_sec; - struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec); + struct ptlrpc_sec *sec = ctx->cc_sec; + struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec); LASSERT(!test_bit(PTLRPC_CTX_CACHED_BIT, &ctx->cc_flags)); - LASSERT(cfs_atomic_read(&ctx->cc_refcount) > 0); + LASSERT(atomic_read(&ctx->cc_refcount) > 0); spin_lock_if(&sec->ps_lock, !locked); - cfs_atomic_inc(&ctx->cc_refcount); + atomic_inc(&ctx->cc_refcount); set_bit(PTLRPC_CTX_CACHED_BIT, &ctx->cc_flags); - cfs_hlist_add_head(&ctx->cc_cache, &gsec_kr->gsk_clist); + hlist_add_head(&ctx->cc_cache, &gsec_kr->gsk_clist); if (is_root) gsec_kr->gsk_root_ctx = ctx; @@ -326,24 +327,24 @@ static void ctx_enlist_kr(struct ptlrpc_cli_ctx *ctx, int is_root, int locked) */ static int ctx_unlist_kr(struct ptlrpc_cli_ctx *ctx, int locked) { - struct ptlrpc_sec *sec = ctx->cc_sec; - struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec); + struct ptlrpc_sec *sec = ctx->cc_sec; + struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec); - /* if hashed bit has gone, leave the job to somebody who is doing it */ + /* if hashed bit has gone, leave the job to somebody who is doing it */ if (test_and_clear_bit(PTLRPC_CTX_CACHED_BIT, &ctx->cc_flags) == 0) - return 0; + return 0; - /* drop ref inside spin lock to prevent race with other operations */ - spin_lock_if(&sec->ps_lock, !locked); + /* drop ref inside spin lock to prevent race with other operations */ + spin_lock_if(&sec->ps_lock, !locked); - if (gsec_kr->gsk_root_ctx == ctx) - gsec_kr->gsk_root_ctx = NULL; - cfs_hlist_del_init(&ctx->cc_cache); - cfs_atomic_dec(&ctx->cc_refcount); + if (gsec_kr->gsk_root_ctx == ctx) + gsec_kr->gsk_root_ctx = NULL; + hlist_del_init(&ctx->cc_cache); + atomic_dec(&ctx->cc_refcount); - spin_unlock_if(&sec->ps_lock, !locked); + spin_unlock_if(&sec->ps_lock, !locked); - return 1; + return 1; } /* @@ -352,16 +353,16 @@ static int ctx_unlist_kr(struct ptlrpc_cli_ctx *ctx, int locked) */ static void bind_key_ctx(struct key *key, struct ptlrpc_cli_ctx *ctx) { - LASSERT(cfs_atomic_read(&ctx->cc_refcount) > 0); + LASSERT(atomic_read(&ctx->cc_refcount) > 0); LASSERT(atomic_read(&key->usage) > 0); - LASSERT(ctx2gctx_keyring(ctx)->gck_key == NULL); - LASSERT(key->payload.data == NULL); - - /* at this time context may or may not in list. */ - key_get(key); - cfs_atomic_inc(&ctx->cc_refcount); - ctx2gctx_keyring(ctx)->gck_key = key; - key->payload.data = ctx; + LASSERT(ctx2gctx_keyring(ctx)->gck_key == NULL); + LASSERT(key->payload.data == NULL); + + /* at this time context may or may not in list. */ + key_get(key); + atomic_inc(&ctx->cc_refcount); + ctx2gctx_keyring(ctx)->gck_key = key; + key->payload.data = ctx; } /* @@ -442,38 +443,38 @@ static void kill_key_locked(struct key *key) /* * caller should hold one ref on contexts in freelist. */ -static void dispose_ctx_list_kr(cfs_hlist_head_t *freelist) +static void dispose_ctx_list_kr(struct hlist_head *freelist) { - cfs_hlist_node_t *pos, *next; - struct ptlrpc_cli_ctx *ctx; - struct gss_cli_ctx *gctx; - - cfs_hlist_for_each_entry_safe(ctx, pos, next, freelist, cc_cache) { - cfs_hlist_del_init(&ctx->cc_cache); - - /* reverse ctx: update current seq to buddy svcctx if exist. - * ideally this should be done at gss_cli_ctx_finalize(), but - * the ctx destroy could be delayed by: - * 1) ctx still has reference; - * 2) ctx destroy is asynchronous; - * and reverse import call inval_all_ctx() require this be done - *_immediately_ otherwise newly created reverse ctx might copy - * the very old sequence number from svcctx. */ - gctx = ctx2gctx(ctx); - if (!rawobj_empty(&gctx->gc_svc_handle) && - sec_is_reverse(gctx->gc_base.cc_sec)) { - gss_svc_upcall_update_sequence(&gctx->gc_svc_handle, - (__u32) cfs_atomic_read(&gctx->gc_seq)); - } - - /* we need to wakeup waiting reqs here. the context might - * be forced released before upcall finished, then the - * late-arrived downcall can't find the ctx even. */ - sptlrpc_cli_ctx_wakeup(ctx); - - unbind_ctx_kr(ctx); - ctx_put_kr(ctx, 0); - } + struct hlist_node __maybe_unused *pos, *next; + struct ptlrpc_cli_ctx *ctx; + struct gss_cli_ctx *gctx; + + cfs_hlist_for_each_entry_safe(ctx, pos, next, freelist, cc_cache) { + hlist_del_init(&ctx->cc_cache); + + /* reverse ctx: update current seq to buddy svcctx if exist. + * ideally this should be done at gss_cli_ctx_finalize(), but + * the ctx destroy could be delayed by: + * 1) ctx still has reference; + * 2) ctx destroy is asynchronous; + * and reverse import call inval_all_ctx() require this be done + * _immediately_ otherwise newly created reverse ctx might copy + * the very old sequence number from svcctx. */ + gctx = ctx2gctx(ctx); + if (!rawobj_empty(&gctx->gc_svc_handle) && + sec_is_reverse(gctx->gc_base.cc_sec)) { + gss_svc_upcall_update_sequence(&gctx->gc_svc_handle, + (__u32) atomic_read(&gctx->gc_seq)); + } + + /* we need to wakeup waiting reqs here. the context might + * be forced released before upcall finished, then the + * late-arrived downcall can't find the ctx even. */ + sptlrpc_cli_ctx_wakeup(ctx); + + unbind_ctx_kr(ctx); + ctx_put_kr(ctx, 0); + } } /* @@ -491,8 +492,8 @@ struct ptlrpc_cli_ctx * sec_lookup_root_ctx_kr(struct ptlrpc_sec *sec) ctx = gsec_kr->gsk_root_ctx; if (ctx == NULL && unlikely(sec_is_reverse(sec))) { - cfs_hlist_node_t *node; - struct ptlrpc_cli_ctx *tmp; + struct hlist_node __maybe_unused *node; + struct ptlrpc_cli_ctx *tmp; /* reverse ctx, search root ctx in list, choose the one * with shortest expire time, which is most possibly have @@ -508,11 +509,11 @@ struct ptlrpc_cli_ctx * sec_lookup_root_ctx_kr(struct ptlrpc_sec *sec) } } - if (ctx) { - LASSERT(cfs_atomic_read(&ctx->cc_refcount) > 0); - LASSERT(!cfs_hlist_empty(&gsec_kr->gsk_clist)); - cfs_atomic_inc(&ctx->cc_refcount); - } + if (ctx) { + LASSERT(atomic_read(&ctx->cc_refcount) > 0); + LASSERT(!hlist_empty(&gsec_kr->gsk_clist)); + atomic_inc(&ctx->cc_refcount); + } spin_unlock(&sec->ps_lock); @@ -526,11 +527,11 @@ void rvs_sec_install_root_ctx_kr(struct ptlrpc_sec *sec, struct ptlrpc_cli_ctx *new_ctx, struct key *key) { - struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec); - cfs_hlist_node_t *hnode; - struct ptlrpc_cli_ctx *ctx; - cfs_time_t now; - ENTRY; + struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec); + struct hlist_node __maybe_unused *hnode; + struct ptlrpc_cli_ctx *ctx; + cfs_time_t now; + ENTRY; LASSERT(sec_is_reverse(sec)); @@ -581,7 +582,7 @@ struct ptlrpc_sec * gss_sec_create_kr(struct obd_import *imp, if (gsec_kr == NULL) RETURN(NULL); - CFS_INIT_HLIST_HEAD(&gsec_kr->gsk_clist); + INIT_HLIST_HEAD(&gsec_kr->gsk_clist); gsec_kr->gsk_root_ctx = NULL; mutex_init(&gsec_kr->gsk_root_uc_lock); #ifdef HAVE_KEYRING_UPCALL_SERIALIZED @@ -613,7 +614,7 @@ void gss_sec_destroy_kr(struct ptlrpc_sec *sec) CDEBUG(D_SEC, "destroy %s@%p\n", sec->ps_policy->sp_name, sec); - LASSERT(cfs_hlist_empty(&gsec_kr->gsk_clist)); + LASSERT(hlist_empty(&gsec_kr->gsk_clist)); LASSERT(gsec_kr->gsk_root_ctx == NULL); gss_sec_destroy_common(gsec); @@ -750,6 +751,17 @@ struct ptlrpc_cli_ctx * gss_sec_lookup_ctx_kr(struct ptlrpc_sec *sec, * encode real uid/gid into callout info. */ + /* But first we need to make sure the obd type is supported */ + if (strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_MDC_NAME) && + strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_OSC_NAME) && + strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_MGC_NAME) && + strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_LWP_NAME) && + strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_OSP_NAME)) { + CERROR("obd %s is not a supported device\n", + imp->imp_obd->obd_name); + GOTO(out, ctx = NULL); + } + construct_key_desc(desc, sizeof(desc), sec, vcred->vc_uid); /* callout info format: @@ -760,11 +772,12 @@ struct ptlrpc_cli_ctx * gss_sec_lookup_ctx_kr(struct ptlrpc_sec *sec, if (coinfo == NULL) goto out; - snprintf(coinfo, coinfo_size, "%d:%s:%u:%u:%s:%d:"LPX64":%s", - sec->ps_id, sec2gsec(sec)->gs_mech->gm_name, - vcred->vc_uid, vcred->vc_gid, - co_flags, import_to_gss_svc(imp), - imp->imp_connection->c_peer.nid, imp->imp_obd->obd_name); + snprintf(coinfo, coinfo_size, "%d:%s:%u:%u:%s:%d:"LPX64":%s:"LPX64, + sec->ps_id, sec2gsec(sec)->gs_mech->gm_name, + vcred->vc_uid, vcred->vc_gid, + co_flags, import_to_gss_svc(imp), + imp->imp_connection->c_peer.nid, imp->imp_obd->obd_name, + imp->imp_connection->c_self); CDEBUG(D_SEC, "requesting key for %s\n", desc); @@ -786,37 +799,37 @@ struct ptlrpc_cli_ctx * gss_sec_lookup_ctx_kr(struct ptlrpc_sec *sec, * need wirtelock of key->sem to serialize them. */ down_write(&key->sem); - if (likely(key->payload.data != NULL)) { - ctx = key->payload.data; - - LASSERT(cfs_atomic_read(&ctx->cc_refcount) >= 1); - LASSERT(ctx2gctx_keyring(ctx)->gck_key == key); - LASSERT(atomic_read(&key->usage) >= 2); - - /* simply take a ref and return. it's upper layer's - * responsibility to detect & replace dead ctx. */ - cfs_atomic_inc(&ctx->cc_refcount); - } else { - /* pre initialization with a cli_ctx. this can't be done in - * key_instantiate() because we'v no enough information - * there. */ - ctx = ctx_create_kr(sec, vcred); - if (ctx != NULL) { - ctx_enlist_kr(ctx, is_root, 0); - bind_key_ctx(key, ctx); - - ctx_start_timer_kr(ctx, KEYRING_UPCALL_TIMEOUT); - - CDEBUG(D_SEC, "installed key %p <-> ctx %p (sec %p)\n", - key, ctx, sec); - } else { - /* we'd prefer to call key_revoke(), but we more like - * to revoke it within this key->sem locked period. */ - key_revoke_locked(key); - } - - create_new = 1; - } + if (likely(key->payload.data != NULL)) { + ctx = key->payload.data; + + LASSERT(atomic_read(&ctx->cc_refcount) >= 1); + LASSERT(ctx2gctx_keyring(ctx)->gck_key == key); + LASSERT(atomic_read(&key->usage) >= 2); + + /* simply take a ref and return. it's upper layer's + * responsibility to detect & replace dead ctx. */ + atomic_inc(&ctx->cc_refcount); + } else { + /* pre initialization with a cli_ctx. this can't be done in + * key_instantiate() because we'v no enough information + * there. */ + ctx = ctx_create_kr(sec, vcred); + if (ctx != NULL) { + ctx_enlist_kr(ctx, is_root, 0); + bind_key_ctx(key, ctx); + + ctx_start_timer_kr(ctx, KEYRING_UPCALL_TIMEOUT); + + CDEBUG(D_SEC, "installed key %p <-> ctx %p (sec %p)\n", + key, ctx, sec); + } else { + /* we'd prefer to call key_revoke(), but we more like + * to revoke it within this key->sem locked period. */ + key_revoke_locked(key); + } + + create_new = 1; + } up_write(&key->sem); @@ -835,8 +848,8 @@ void gss_sec_release_ctx_kr(struct ptlrpc_sec *sec, struct ptlrpc_cli_ctx *ctx, int sync) { - LASSERT(cfs_atomic_read(&sec->ps_refcount) > 0); - LASSERT(cfs_atomic_read(&ctx->cc_refcount) == 0); + LASSERT(atomic_read(&sec->ps_refcount) > 0); + LASSERT(atomic_read(&ctx->cc_refcount) == 0); ctx_release_kr(ctx, sync); } @@ -889,50 +902,49 @@ void flush_user_ctx_cache_kr(struct ptlrpc_sec *sec, * flush context of root or all, we iterate through the list. */ static -void flush_spec_ctx_cache_kr(struct ptlrpc_sec *sec, - uid_t uid, - int grace, int force) +void flush_spec_ctx_cache_kr(struct ptlrpc_sec *sec, uid_t uid, int grace, + int force) { - struct gss_sec_keyring *gsec_kr; - cfs_hlist_head_t freelist = CFS_HLIST_HEAD_INIT; - cfs_hlist_node_t *pos, *next; - struct ptlrpc_cli_ctx *ctx; - ENTRY; + struct gss_sec_keyring *gsec_kr; + struct hlist_head freelist = HLIST_HEAD_INIT; + struct hlist_node __maybe_unused *pos, *next; + struct ptlrpc_cli_ctx *ctx; + ENTRY; gsec_kr = sec2gsec_keyring(sec); spin_lock(&sec->ps_lock); - cfs_hlist_for_each_entry_safe(ctx, pos, next, - &gsec_kr->gsk_clist, cc_cache) { - LASSERT(cfs_atomic_read(&ctx->cc_refcount) > 0); - - if (uid != -1 && uid != ctx->cc_vcred.vc_uid) - continue; - - /* at this moment there's at least 2 base reference: - * key association and in-list. */ - if (cfs_atomic_read(&ctx->cc_refcount) > 2) { - if (!force) - continue; - CWARN("flush busy ctx %p(%u->%s, extra ref %d)\n", - ctx, ctx->cc_vcred.vc_uid, - sec2target_str(ctx->cc_sec), - cfs_atomic_read(&ctx->cc_refcount) - 2); - } + cfs_hlist_for_each_entry_safe(ctx, pos, next, + &gsec_kr->gsk_clist, cc_cache) { + LASSERT(atomic_read(&ctx->cc_refcount) > 0); + + if (uid != -1 && uid != ctx->cc_vcred.vc_uid) + continue; + + /* at this moment there's at least 2 base reference: + * key association and in-list. */ + if (atomic_read(&ctx->cc_refcount) > 2) { + if (!force) + continue; + CWARN("flush busy ctx %p(%u->%s, extra ref %d)\n", + ctx, ctx->cc_vcred.vc_uid, + sec2target_str(ctx->cc_sec), + atomic_read(&ctx->cc_refcount) - 2); + } set_bit(PTLRPC_CTX_DEAD_BIT, &ctx->cc_flags); if (!grace) clear_bit(PTLRPC_CTX_UPTODATE_BIT, &ctx->cc_flags); - cfs_atomic_inc(&ctx->cc_refcount); + atomic_inc(&ctx->cc_refcount); - if (ctx_unlist_kr(ctx, 1)) { - cfs_hlist_add_head(&ctx->cc_cache, &freelist); - } else { - LASSERT(cfs_atomic_read(&ctx->cc_refcount) >= 2); - cfs_atomic_dec(&ctx->cc_refcount); - } - } + if (ctx_unlist_kr(ctx, 1)) { + hlist_add_head(&ctx->cc_cache, &freelist); + } else { + LASSERT(atomic_read(&ctx->cc_refcount) >= 2); + atomic_dec(&ctx->cc_refcount); + } + } spin_unlock(&sec->ps_lock); dispose_ctx_list_kr(&freelist); @@ -943,47 +955,47 @@ static int gss_sec_flush_ctx_cache_kr(struct ptlrpc_sec *sec, uid_t uid, int grace, int force) { - ENTRY; + ENTRY; - CDEBUG(D_SEC, "sec %p(%d, nctx %d), uid %d, grace %d, force %d\n", - sec, cfs_atomic_read(&sec->ps_refcount), - cfs_atomic_read(&sec->ps_nctx), - uid, grace, force); + CDEBUG(D_SEC, "sec %p(%d, nctx %d), uid %d, grace %d, force %d\n", + sec, atomic_read(&sec->ps_refcount), + atomic_read(&sec->ps_nctx), + uid, grace, force); - if (uid != -1 && uid != 0) - flush_user_ctx_cache_kr(sec, uid, grace, force); - else - flush_spec_ctx_cache_kr(sec, uid, grace, force); + if (uid != -1 && uid != 0) + flush_user_ctx_cache_kr(sec, uid, grace, force); + else + flush_spec_ctx_cache_kr(sec, uid, grace, force); - RETURN(0); + RETURN(0); } static void gss_sec_gc_ctx_kr(struct ptlrpc_sec *sec) { - struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec); - cfs_hlist_head_t freelist = CFS_HLIST_HEAD_INIT; - cfs_hlist_node_t *pos, *next; - struct ptlrpc_cli_ctx *ctx; - ENTRY; + struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec); + struct hlist_head freelist = HLIST_HEAD_INIT; + struct hlist_node __maybe_unused *pos, *next; + struct ptlrpc_cli_ctx *ctx; + ENTRY; - CWARN("running gc\n"); + CWARN("running gc\n"); spin_lock(&sec->ps_lock); - cfs_hlist_for_each_entry_safe(ctx, pos, next, - &gsec_kr->gsk_clist, cc_cache) { - LASSERT(cfs_atomic_read(&ctx->cc_refcount) > 0); - - cfs_atomic_inc(&ctx->cc_refcount); - - if (cli_ctx_check_death(ctx) && ctx_unlist_kr(ctx, 1)) { - cfs_hlist_add_head(&ctx->cc_cache, &freelist); - CWARN("unhashed ctx %p\n", ctx); - } else { - LASSERT(cfs_atomic_read(&ctx->cc_refcount) >= 2); - cfs_atomic_dec(&ctx->cc_refcount); - } - } + cfs_hlist_for_each_entry_safe(ctx, pos, next, + &gsec_kr->gsk_clist, cc_cache) { + LASSERT(atomic_read(&ctx->cc_refcount) > 0); + + atomic_inc(&ctx->cc_refcount); + + if (cli_ctx_check_death(ctx) && ctx_unlist_kr(ctx, 1)) { + hlist_add_head(&ctx->cc_cache, &freelist); + CWARN("unhashed ctx %p\n", ctx); + } else { + LASSERT(atomic_read(&ctx->cc_refcount) >= 2); + atomic_dec(&ctx->cc_refcount); + } + } spin_unlock(&sec->ps_lock); dispose_ctx_list_kr(&freelist); @@ -994,16 +1006,16 @@ void gss_sec_gc_ctx_kr(struct ptlrpc_sec *sec) static int gss_sec_display_kr(struct ptlrpc_sec *sec, struct seq_file *seq) { - struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec); - cfs_hlist_node_t *pos, *next; - struct ptlrpc_cli_ctx *ctx; - struct gss_cli_ctx *gctx; - time_t now = cfs_time_current_sec(); - ENTRY; + struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec); + struct hlist_node __maybe_unused *pos, *next; + struct ptlrpc_cli_ctx *ctx; + struct gss_cli_ctx *gctx; + time_t now = cfs_time_current_sec(); + ENTRY; spin_lock(&sec->ps_lock); cfs_hlist_for_each_entry_safe(ctx, pos, next, - &gsec_kr->gsk_clist, cc_cache) { + &gsec_kr->gsk_clist, cc_cache) { struct key *key; char flags_str[40]; char mech[40]; @@ -1020,22 +1032,22 @@ int gss_sec_display_kr(struct ptlrpc_sec *sec, struct seq_file *seq) snprintf(mech, sizeof(mech), "N/A"); mech[sizeof(mech) - 1] = '\0'; - seq_printf(seq, "%p: uid %u, ref %d, expire %ld(%+ld), fl %s, " - "seq %d, win %u, key %08x(ref %d), " - "hdl "LPX64":"LPX64", mech: %s\n", - ctx, ctx->cc_vcred.vc_uid, - cfs_atomic_read(&ctx->cc_refcount), - ctx->cc_expire, - ctx->cc_expire ? ctx->cc_expire - now : 0, - flags_str, - cfs_atomic_read(&gctx->gc_seq), - gctx->gc_win, - key ? key->serial : 0, - key ? atomic_read(&key->usage) : 0, - gss_handle_to_u64(&gctx->gc_handle), - gss_handle_to_u64(&gctx->gc_svc_handle), - mech); - } + seq_printf(seq, "%p: uid %u, ref %d, expire %ld(%+ld), fl %s, " + "seq %d, win %u, key %08x(ref %d), " + "hdl "LPX64":"LPX64", mech: %s\n", + ctx, ctx->cc_vcred.vc_uid, + atomic_read(&ctx->cc_refcount), + ctx->cc_expire, + ctx->cc_expire ? ctx->cc_expire - now : 0, + flags_str, + atomic_read(&gctx->gc_seq), + gctx->gc_win, + key ? key->serial : 0, + key ? atomic_read(&key->usage) : 0, + gss_handle_to_u64(&gctx->gc_handle), + gss_handle_to_u64(&gctx->gc_svc_handle), + mech); + } spin_unlock(&sec->ps_lock); RETURN(0); @@ -1055,27 +1067,27 @@ int gss_cli_ctx_refresh_kr(struct ptlrpc_cli_ctx *ctx) static int gss_cli_ctx_validate_kr(struct ptlrpc_cli_ctx *ctx) { - LASSERT(cfs_atomic_read(&ctx->cc_refcount) > 0); - LASSERT(ctx->cc_sec); + LASSERT(atomic_read(&ctx->cc_refcount) > 0); + LASSERT(ctx->cc_sec); - if (cli_ctx_check_death(ctx)) { - kill_ctx_kr(ctx); - return 1; - } + if (cli_ctx_check_death(ctx)) { + kill_ctx_kr(ctx); + return 1; + } - if (cli_ctx_is_ready(ctx)) - return 0; - return 1; + if (cli_ctx_is_ready(ctx)) + return 0; + return 1; } static void gss_cli_ctx_die_kr(struct ptlrpc_cli_ctx *ctx, int grace) { - LASSERT(cfs_atomic_read(&ctx->cc_refcount) > 0); - LASSERT(ctx->cc_sec); + LASSERT(atomic_read(&ctx->cc_refcount) > 0); + LASSERT(ctx->cc_sec); - cli_ctx_expire(ctx); - kill_ctx_kr(ctx); + cli_ctx_expire(ctx); + kill_ctx_kr(ctx); } /**************************************** @@ -1220,8 +1232,15 @@ int gss_svc_install_rctx_kr(struct obd_import *imp, ****************************************/ static +#ifdef HAVE_KEY_TYPE_INSTANTIATE_2ARGS +int gss_kt_instantiate(struct key *key, struct key_preparsed_payload *prep) +{ + const void *data = prep->data; + size_t datalen = prep->datalen; +#else int gss_kt_instantiate(struct key *key, const void *data, size_t datalen) { +#endif int rc; ENTRY; @@ -1230,7 +1249,7 @@ int gss_kt_instantiate(struct key *key, const void *data, size_t datalen) RETURN(-EINVAL); } - if (key->payload.data != 0) { + if (key->payload.data != NULL) { CERROR("key already have payload\n"); RETURN(-EINVAL); } @@ -1266,19 +1285,26 @@ int gss_kt_instantiate(struct key *key, const void *data, size_t datalen) * on the context without fear of loosing refcount. */ static +#ifdef HAVE_KEY_TYPE_INSTANTIATE_2ARGS +int gss_kt_update(struct key *key, struct key_preparsed_payload *prep) +{ + const void *data = prep->data; + __u32 datalen32 = (__u32) prep->datalen; +#else int gss_kt_update(struct key *key, const void *data, size_t datalen) { + __u32 datalen32 = (__u32) datalen; +#endif struct ptlrpc_cli_ctx *ctx = key->payload.data; struct gss_cli_ctx *gctx; rawobj_t tmpobj = RAWOBJ_EMPTY; - __u32 datalen32 = (__u32) datalen; int rc; ENTRY; - if (data == NULL || datalen == 0) { - CWARN("invalid: data %p, len %lu\n", data, (long)datalen); - RETURN(-EINVAL); - } + if (data == NULL || datalen32 == 0) { + CWARN("invalid: data %p, len %lu\n", data, (long)datalen32); + RETURN(-EINVAL); + } /* if upcall finished negotiation too fast (mostly likely because * of local error happened) and call kt_update(), the ctx @@ -1296,10 +1322,10 @@ int gss_kt_update(struct key *key, const void *data, size_t datalen) RETURN(rc); } - LASSERT(cfs_atomic_read(&ctx->cc_refcount) > 0); - LASSERT(ctx->cc_sec); + LASSERT(atomic_read(&ctx->cc_refcount) > 0); + LASSERT(ctx->cc_sec); - ctx_clear_timer_kr(ctx); + ctx_clear_timer_kr(ctx); /* don't proceed if already refreshed */ if (cli_ctx_is_refreshed(ctx)) {