Whamcloud - gitweb
branch: HEAD
[fs/lustre-release.git] / lustre / ptlrpc / gss / gss_pipefs.c
index ecbe43f..ade0f53 100644 (file)
@@ -2,8 +2,9 @@
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
  * Modifications for Lustre
- * Copyright 2004 - 2006, Cluster File Systems, Inc.
- * All rights reserved
+ *
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ *
  * Author: Eric Mei <ericm@clusterfs.com>
  */
 
@@ -100,13 +101,15 @@ struct ptlrpc_cli_ctx *ctx_create_pf(struct ptlrpc_sec *sec,
                                      struct vfs_cred *vcred)
 {
         struct gss_cli_ctx *gctx;
+        int                 rc;
 
         OBD_ALLOC_PTR(gctx);
         if (gctx == NULL)
                 return NULL;
 
-        if (gss_cli_ctx_init_common(sec, &gctx->gc_base, &gss_pipefs_ctxops,
-                                    vcred)) {
+        rc = gss_cli_ctx_init_common(sec, &gctx->gc_base,
+                                     &gss_pipefs_ctxops, vcred);
+        if (rc) {
                 OBD_FREE_PTR(gctx);
                 return NULL;
         }
@@ -118,16 +121,14 @@ static
 void ctx_destroy_pf(struct ptlrpc_sec *sec, struct ptlrpc_cli_ctx *ctx)
 {
         struct gss_cli_ctx *gctx = ctx2gctx(ctx);
-        int                 rc;
 
-        rc = gss_cli_ctx_fini_common(sec, ctx);
+        if (gss_cli_ctx_fini_common(sec, ctx))
+                return;
+
         OBD_FREE_PTR(gctx);
 
-        if (rc) {
-                CWARN("released the last ctx, proceed to destroy sec %s@%p\n",
-                      sec->ps_policy->sp_name, sec);
-                sptlrpc_sec_destroy(sec);
-        }
+        atomic_dec(&sec->ps_nctx);
+        sptlrpc_sec_put(sec);
 }
 
 static
@@ -154,8 +155,9 @@ void ctx_unhash_pf(struct ptlrpc_cli_ctx *ctx, struct hlist_head *freelist)
         if (atomic_dec_and_test(&ctx->cc_refcount)) {
                 __hlist_del(&ctx->cc_cache);
                 hlist_add_head(&ctx->cc_cache, freelist);
-        } else
+        } else {
                 hlist_del_init(&ctx->cc_cache);
+        }
 }
 
 /*
@@ -286,7 +288,6 @@ void gss_sec_ctx_replace_pf(struct gss_sec *gsec,
         }
 
         ctx_enhash_pf(new, &gsec_pf->gsp_chash[hash]);
-        atomic_inc(&gsec->gs_base.ps_busy);
 
         spin_unlock(&gsec->gs_base.ps_lock);
 
@@ -347,8 +348,7 @@ void gss_ctx_cache_gc_pf(struct gss_sec_pipefs *gsec_pf,
 static
 struct ptlrpc_sec* gss_sec_create_pf(struct obd_import *imp,
                                      struct ptlrpc_svc_ctx *ctx,
-                                     __u32 flavor,
-                                     unsigned long flags)
+                                     struct sptlrpc_flavor *sf)
 {
         struct gss_sec_pipefs   *gsec_pf;
         int                      alloc_size, hash_size, i;
@@ -356,7 +356,8 @@ struct ptlrpc_sec* gss_sec_create_pf(struct obd_import *imp,
 
 #define GSS_SEC_PIPEFS_CTX_HASH_SIZE    (32)
 
-        if (ctx || flags & (PTLRPC_SEC_FL_ROOTONLY | PTLRPC_SEC_FL_REVERSE))
+        if (ctx ||
+            sf->sf_flags & (PTLRPC_SEC_FL_ROOTONLY | PTLRPC_SEC_FL_REVERSE))
                 hash_size = 1;
         else
                 hash_size = GSS_SEC_PIPEFS_CTX_HASH_SIZE;
@@ -373,7 +374,7 @@ struct ptlrpc_sec* gss_sec_create_pf(struct obd_import *imp,
                 CFS_INIT_HLIST_HEAD(&gsec_pf->gsp_chash[i]);
 
         if (gss_sec_create_common(&gsec_pf->gsp_base, &gss_policy_pipefs,
-                                  imp, ctx, flavor, flags))
+                                  imp, ctx, sf))
                 goto err_free;
 
         if (ctx == NULL) {
@@ -519,8 +520,7 @@ void gss_sec_release_ctx_pf(struct ptlrpc_sec *sec,
         LASSERT(hlist_unhashed(&ctx->cc_cache));
 
         /* if required async, we must clear the UPTODATE bit to prevent extra
-         * rpcs during destroy procedure.
-         */
+         * rpcs during destroy procedure. */
         if (!sync)
                 clear_bit(PTLRPC_CTX_UPTODATE_BIT, &ctx->cc_flags);
 
@@ -604,13 +604,15 @@ static
 int gss_svc_install_rctx_pf(struct obd_import *imp,
                             struct ptlrpc_svc_ctx *ctx)
 {
-        struct gss_sec *gsec;
+        struct ptlrpc_sec *sec;
+        int                rc;
 
-        LASSERT(imp->imp_sec);
-        LASSERT(ctx);
+        sec = sptlrpc_import_sec_ref(imp);
+        LASSERT(sec);
+        rc = gss_install_rvs_cli_ctx_pf(sec2gsec(sec), ctx);
 
-        gsec = container_of(imp->imp_sec, struct gss_sec, gs_base);
-        return gss_install_rvs_cli_ctx_pf(gsec, ctx);
+        sptlrpc_sec_put(sec);
+        return rc;
 }
 
 /****************************************
@@ -939,8 +941,7 @@ out_free:
         OBD_FREE(buf, mlen);
         /* FIXME
          * hack pipefs: always return asked length unless all following
-         * downcalls might be messed up.
-         */
+         * downcalls might be messed up. */
         rc = mlen;
         RETURN(rc);
 }
@@ -1085,8 +1086,7 @@ int gss_ctx_refresh_pf(struct ptlrpc_cli_ctx *ctx)
                 sizeof(gmsg->gum_data.gum_obd));
 
         /* This only could happen when sysadmin set it dead/expired
-         * using lctl by force.
-         */
+         * using lctl by force. */
         if (ctx->cc_flags & PTLRPC_CTX_STATUS_MASK) {
                 CWARN("ctx %p(%u->%s) was set flags %lx unexpectedly\n",
                       ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
@@ -1120,8 +1120,7 @@ static
 int gss_cli_ctx_refresh_pf(struct ptlrpc_cli_ctx *ctx)
 {
         /* if we are refreshing for root, also update the reverse
-         * handle index, do not confuse reverse contexts.
-         */
+         * handle index, do not confuse reverse contexts. */
         if (ctx->cc_vcred.vc_uid == 0) {
                 struct gss_sec *gsec;
 
@@ -1152,6 +1151,7 @@ static struct ptlrpc_ctx_ops gss_pipefs_ctxops = {
 static struct ptlrpc_sec_cops gss_sec_pipefs_cops = {
         .create_sec             = gss_sec_create_pf,
         .destroy_sec            = gss_sec_destroy_pf,
+        .kill_sec               = gss_sec_kill,
         .lookup_ctx             = gss_sec_lookup_ctx_pf,
         .release_ctx            = gss_sec_release_ctx_pf,
         .flush_ctx_cache        = gss_sec_flush_ctx_cache_pf,
@@ -1194,11 +1194,9 @@ int __init gss_init_pipefs_upcall(void)
                 CERROR("Failed to create gss pipe dir: %ld\n", PTR_ERR(de));
                 return PTR_ERR(de);
         }
-        /* FIXME
-         * hack pipefs: dput will sometimes cause oops during module unload
-         * and lgssd close the pipe fds.
-         */
-        //dput(de);
+
+        /* FIXME hack pipefs: dput will sometimes cause oops during module
+         * unload and lgssd close the pipe fds. */
 
         /* krb5 mechanism */
         de = rpc_mkpipe(LUSTRE_PIPE_KRB5, (void *) MECH_KRB5, &gss_upcall_ops,
@@ -1212,7 +1210,7 @@ int __init gss_init_pipefs_upcall(void)
 
         de_pipes[MECH_KRB5] = de;
         CFS_INIT_LIST_HEAD(&upcall_lists[MECH_KRB5]);
-        upcall_locks[MECH_KRB5] = SPIN_LOCK_UNLOCKED;
+        spin_lock_init(&upcall_locks[MECH_KRB5]);
 
         return 0;
 }
@@ -1224,10 +1222,8 @@ void __exit gss_exit_pipefs_upcall(void)
 
         for (i = 0; i < MECH_MAX; i++) {
                 LASSERT(list_empty(&upcall_lists[i]));
-                /*
-                 * dput pipe dentry here might cause lgssd oops.
-                 */
-                //dput(de_pipes[i]);
+
+                /* dput pipe dentry here might cause lgssd oops. */
                 de_pipes[i] = NULL;
         }