Whamcloud - gitweb
LU-6490 gss: 3.1x kernels adjustments for gssapi code
[fs/lustre-release.git] / lustre / ptlrpc / gss / gss_keyring.c
index e6ade3b..5256adc 100644 (file)
@@ -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/
@@ -118,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)
 {
@@ -160,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;
@@ -746,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:
@@ -756,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);
 
@@ -1215,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;
 
@@ -1225,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);
         }
@@ -1261,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