Whamcloud - gitweb
Backout "liblustre now builds" commit. It breaks building in utils:
[fs/lustre-release.git] / lustre / sec / gss / sec_gss.c
index 8bd4f02..a2e6a83 100644 (file)
@@ -76,23 +76,34 @@ struct rpc_clnt;
 #include "gss_internal.h"
 #include "gss_api.h"
 
+#define LUSTRE_PIPEDIR          "/lustre"
+
 #define GSS_CREDCACHE_EXPIRE    (30 * 60)          /* 30 minute */
-/* not used now */
-#if 0
-#define GSS_CRED_EXPIRE         (8 * 60 * 60)      /* 8 hours */
-#define GSS_CRED_SIGN_SIZE      (1024)
-#define GSS_CRED_VERIFY_SIZE    (56)
-#endif
 
-#define LUSTRE_PIPEDIR          "/lustre"
+#define GSS_TIMEOUT_DELTA       (5)
+#define CRED_REFRESH_UPCALL_TIMEOUT                             \
+        ({                                                      \
+                int timeout = obd_timeout - GSS_TIMEOUT_DELTA;  \
+                                                                \
+                if (timeout < GSS_TIMEOUT_DELTA * 2)            \
+                        timeout = GSS_TIMEOUT_DELTA * 2;        \
+                timeout;                                        \
+        })
+#define SECINIT_RPC_TIMEOUT                                     \
+        ({                                                      \
+                int timeout = CRED_REFRESH_UPCALL_TIMEOUT -     \
+                              GSS_TIMEOUT_DELTA;                \
+                if (timeout < GSS_TIMEOUT_DELTA)                \
+                        timeout = GSS_TIMEOUT_DELTA;            \
+                timeout;                                        \
+        })
+#define SECFINI_RPC_TIMEOUT     (GSS_TIMEOUT_DELTA)
+
 
 /**********************************************
  * gss security init/fini helper              *
  **********************************************/
 
-#define SECINIT_RPC_TIMEOUT     (30)
-#define SECFINI_RPC_TIMEOUT     (10)
-
 static int secinit_compose_request(struct obd_import *imp,
                                    char *buf, int bufsize,
                                    int lustre_srv,
@@ -386,6 +397,7 @@ struct gss_sec {
 static rwlock_t gss_ctx_lock = RW_LOCK_UNLOCKED;
 
 struct gss_upcall_msg_data {
+        __u64                           gum_pag;
         __u32                           gum_uid;
         __u32                           gum_svc;
         __u32                           gum_nal;
@@ -419,7 +431,19 @@ void gss_release_msg(struct gss_upcall_msg *gmsg)
                 return;
         }
         LASSERT(list_empty(&gmsg->gum_list));
+#if 0
         LASSERT(list_empty(&gmsg->gum_base.list));
+#else
+        /* XXX */
+        if (!list_empty(&gmsg->gum_base.list)) {
+                CWARN("msg %p: list: %p/%p/%p, copied %d, err %d, wq %d\n",
+                      gmsg, &gmsg->gum_base.list,
+                      gmsg->gum_base.list.prev, gmsg->gum_base.list.next,
+                      gmsg->gum_base.copied, gmsg->gum_base.errno,
+                      list_empty(&gmsg->gum_waitq.task_list));
+                LBUG();
+        }
+#endif
         OBD_FREE(gmsg, sizeof(*gmsg));
         EXIT;
 }
@@ -427,19 +451,15 @@ void gss_release_msg(struct gss_upcall_msg *gmsg)
 static void
 gss_unhash_msg_nolock(struct gss_upcall_msg *gmsg)
 {
-        ENTRY;
-        if (list_empty(&gmsg->gum_list)) {
-                EXIT;
+        LASSERT_SPIN_LOCKED(&gmsg->gum_gsec->gs_lock);
+
+        if (list_empty(&gmsg->gum_list))
                 return;
-        }
 
         list_del_init(&gmsg->gum_list);
         wake_up(&gmsg->gum_waitq);
+        LASSERT(atomic_read(&gmsg->gum_refcount) > 1);
         atomic_dec(&gmsg->gum_refcount);
-        CDEBUG(D_SEC, "gmsg %p refcount now %d\n",
-               gmsg, atomic_read(&gmsg->gum_refcount));
-        LASSERT(atomic_read(&gmsg->gum_refcount) > 0);
-        EXIT;
 }
 
 static void
@@ -460,11 +480,14 @@ struct gss_upcall_msg * gss_find_upcall(struct gss_sec *gsec,
         struct gss_upcall_msg *gmsg;
         ENTRY;
 
+        LASSERT_SPIN_LOCKED(&gsec->gs_lock);
+
         list_for_each_entry(gmsg, &gsec->gs_upcalls, gum_list) {
                 if (memcmp(&gmsg->gum_data, gmd, sizeof(*gmd)))
                         continue;
                 if (strcmp(gmsg->gum_obdname, obdname))
                         continue;
+                LASSERT(atomic_read(&gmsg->gum_refcount) > 0);
                 atomic_inc(&gmsg->gum_refcount);
                 CDEBUG(D_SEC, "found gmsg at %p: obdname %s, uid %d, ref %d\n",
                        gmsg, obdname, gmd->gum_uid,
@@ -490,8 +513,11 @@ static void gss_init_upcall_msg(struct gss_upcall_msg *gmsg,
         memcpy(&gmsg->gum_data, gmd, sizeof(*gmd));
 
         rpcmsg = &gmsg->gum_base;
+        INIT_LIST_HEAD(&rpcmsg->list);
         rpcmsg->data = &gmsg->gum_data;
         rpcmsg->len = sizeof(gmsg->gum_data);
+        rpcmsg->copied = 0;
+        rpcmsg->errno = 0;
         EXIT;
 }
 #endif /* __KERNEL__ */
@@ -633,6 +659,8 @@ int gss_parse_init_downcall(struct gss_api_mech *gm, rawobj_t *buf,
         spin_lock_init(&ctx->gc_seq_lock);
         atomic_set(&ctx->gc_refcount,1);
 
+        if (simple_get_bytes(&p, &len, &gmd->gum_pag, sizeof(gmd->gum_pag)))
+                goto err_free_ctx;
         if (simple_get_bytes(&p, &len, &gmd->gum_uid, sizeof(gmd->gum_uid)))
                 goto err_free_ctx;
         if (simple_get_bytes(&p, &len, &gmd->gum_svc, sizeof(gmd->gum_svc)))
@@ -701,7 +729,6 @@ err_free_ctx:
  * cred APIs                           *
  ***************************************/
 #ifdef __KERNEL__
-#define CRED_REFRESH_UPCALL_TIMEOUT     (50)
 static int gss_cred_refresh(struct ptlrpc_cred *cred)
 {
         struct obd_import          *import;
@@ -711,7 +738,6 @@ static int gss_cred_refresh(struct ptlrpc_cred *cred)
         struct dentry              *dentry;
         char                       *obdname, *obdtype;
         wait_queue_t                wait;
-        uid_t                       uid = cred->pc_uid;
         int                         res;
         ENTRY;
 
@@ -731,15 +757,16 @@ static int gss_cred_refresh(struct ptlrpc_cred *cred)
                 RETURN(-EINVAL);
         }
 
-        gmd.gum_uid = uid;
+        gmd.gum_pag = cred->pc_pag;
+        gmd.gum_uid = cred->pc_uid;
         gmd.gum_nal = import->imp_connection->c_peer.peer_ni->pni_number;
         gmd.gum_netid = 0;
         gmd.gum_nid = import->imp_connection->c_peer.peer_id.nid;
 
         obdtype = import->imp_obd->obd_type->typ_name;
-        if (!strcmp(obdtype, "mdc"))
+        if (!strcmp(obdtype, OBD_MDC_DEVICENAME))
                 gmd.gum_svc = LUSTRE_GSS_SVC_MDS;
-        else if (!strcmp(obdtype, "osc"))
+        else if (!strcmp(obdtype, OBD_OSC_DEVICENAME))
                 gmd.gum_svc = LUSTRE_GSS_SVC_OSS;
         else {
                 CERROR("gss on %s?\n", obdtype);
@@ -754,7 +781,7 @@ static int gss_cred_refresh(struct ptlrpc_cred *cred)
 
         CDEBUG(D_SEC, "Initiate gss context %p(%u@%s)\n",
                container_of(cred, struct gss_cred, gc_base),
-               uid, import->imp_target_uuid.uuid);
+               cred->pc_uid, import->imp_target_uuid.uuid);
 
 again:
         spin_lock(&gsec->gs_lock);
@@ -1429,7 +1456,7 @@ static void gss_cred_destroy(struct ptlrpc_cred *cred)
                 gss_put_ctx(gcred->gc_ctx);
         }
 
-        CDEBUG(D_SEC, "GSS_SEC: destroy cred %p\n", gcred);
+        CDEBUG(D_SEC, "sec.gss %p: destroy cred %p\n", cred->pc_sec, gcred);
 
         OBD_FREE(gcred, sizeof(*gcred));
         EXIT;
@@ -1524,8 +1551,8 @@ gss_pipe_downcall(struct file *filp, const char *src, size_t mlen)
         if (err)
                 CERROR("parse init downcall err %d\n", err);
 
+        vcred.vc_pag = gmd.gum_pag;
         vcred.vc_uid = gmd.gum_uid;
-        vcred.vc_pag = vcred.vc_uid; /* FIXME */
 
         cred = ptlrpcs_cred_lookup(sec, &vcred);
         if (!cred) {
@@ -1575,6 +1602,8 @@ void gss_pipe_destroy_msg(struct rpc_pipe_msg *msg)
         static unsigned long ratelimit;
         ENTRY;
 
+        LASSERT(list_empty(&msg->list));
+
         if (msg->errno >= 0) {
                 EXIT;
                 return;
@@ -1582,12 +1611,13 @@ void gss_pipe_destroy_msg(struct rpc_pipe_msg *msg)
 
         gmsg = container_of(msg, struct gss_upcall_msg, gum_base);
         CDEBUG(D_SEC, "destroy gmsg %p\n", gmsg);
+        LASSERT(atomic_read(&gmsg->gum_refcount) > 0);
         atomic_inc(&gmsg->gum_refcount);
         gss_unhash_msg(gmsg);
         if (msg->errno == -ETIMEDOUT || msg->errno == -EPIPE) {
                 unsigned long now = get_seconds();
                 if (time_after(now, ratelimit)) {
-                        CWARN("GSS_SEC upcall timed out.\n"
+                        CWARN("sec.gss upcall timed out.\n"
                               "Please check user daemon is running!\n");
                         ratelimit = now + 15;
                 }
@@ -1612,6 +1642,7 @@ void gss_pipe_release(struct inode *inode)
 
                 gmsg = list_entry(gsec->gs_upcalls.next,
                                   struct gss_upcall_msg, gum_list);
+                LASSERT(list_empty(&gmsg->gum_base.list));
                 gmsg->gum_base.errno = -EPIPE;
                 atomic_inc(&gmsg->gum_refcount);
                 gss_unhash_msg_nolock(gmsg);
@@ -1701,8 +1732,7 @@ struct ptlrpc_sec* gss_create_sec(__u32 flavor,
 
         current->fsuid = save_uid;
 
-        CDEBUG(D_SEC, "Create GSS security instance at %p(external %p)\n",
-               gsec, sec);
+        CDEBUG(D_SEC, "Create sec.gss %p\n", gsec);
         RETURN(sec);
 
 #ifdef __KERNEL__
@@ -1733,7 +1763,7 @@ void gss_destroy_sec(struct ptlrpc_sec *sec)
         ENTRY;
 
         gsec = container_of(sec, struct gss_sec, gs_base);
-        CDEBUG(D_SEC, "Destroy GSS security instance at %p\n", gsec);
+        CDEBUG(D_SEC, "Destroy sec.gss %p\n", gsec);
 
         LASSERT(gsec->gs_mech);
         LASSERT(!atomic_read(&sec->ps_refcount));