Whamcloud - gitweb
LU-12930 various: use schedule_timeout_*interruptible
[fs/lustre-release.git] / lustre / ptlrpc / sec.c
index ec05298..5ead685 100644 (file)
@@ -37,9 +37,7 @@
 #define DEBUG_SUBSYSTEM S_SEC
 
 #include <linux/user_namespace.h>
-#ifdef HAVE_UIDGID_HEADER
-# include <linux/uidgid.h>
-#endif
+#include <linux/uidgid.h>
 #include <linux/crypto.h>
 #include <linux/key.h>
 
@@ -366,13 +364,13 @@ static int import_sec_check_expire(struct obd_import *imp)
 {
        int adapt = 0;
 
-       spin_lock(&imp->imp_lock);
+       write_lock(&imp->imp_sec_lock);
        if (imp->imp_sec_expire &&
            imp->imp_sec_expire < ktime_get_real_seconds()) {
                adapt = 1;
                imp->imp_sec_expire = 0;
        }
-       spin_unlock(&imp->imp_lock);
+       write_unlock(&imp->imp_sec_lock);
 
        if (!adapt)
                return 0;
@@ -591,8 +589,7 @@ int sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req)
                       "ctx (%p, fl %lx) doesn't switch, relax a little bit\n",
                       newctx, newctx->cc_flags);
 
-               set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC));
+               schedule_timeout_interruptible(cfs_time_seconds(1));
        } else if (unlikely(test_bit(PTLRPC_CTX_UPTODATE_BIT, &newctx->cc_flags)
                            == 0)) {
                /*
@@ -631,9 +628,8 @@ int ctx_check_refresh(struct ptlrpc_cli_ctx *ctx)
 }
 
 static
-int ctx_refresh_timeout(void *data)
+int ctx_refresh_timeout(struct ptlrpc_request *req)
 {
-       struct ptlrpc_request *req = data;
        int rc;
 
        /* conn_cnt is needed in expire_one_request */
@@ -653,9 +649,8 @@ int ctx_refresh_timeout(void *data)
 }
 
 static
-void ctx_refresh_interrupt(void *data)
+void ctx_refresh_interrupt(struct ptlrpc_request *req)
 {
-       struct ptlrpc_request *req = data;
 
        spin_lock(&req->rq_lock);
        req->rq_intr = 1;
@@ -689,7 +684,6 @@ int sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout)
 {
        struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
        struct ptlrpc_sec *sec;
-       struct l_wait_info lwi;
        int rc;
 
        ENTRY;
@@ -823,10 +817,18 @@ again:
        req->rq_restart = 0;
        spin_unlock(&req->rq_lock);
 
-       lwi = LWI_TIMEOUT_INTR(msecs_to_jiffies(timeout * MSEC_PER_SEC),
-                              ctx_refresh_timeout,
-                              ctx_refresh_interrupt, req);
-       rc = l_wait_event(req->rq_reply_waitq, ctx_check_refresh(ctx), &lwi);
+       if (wait_event_idle_timeout(req->rq_reply_waitq,
+                                   ctx_check_refresh(ctx),
+                                   cfs_time_seconds(timeout)) == 0) {
+               rc = -ETIMEDOUT;
+               if (!ctx_refresh_timeout(req) &&
+                   l_wait_event_abortable(req->rq_reply_waitq,
+                                          ctx_check_refresh(ctx))
+                   == -ERESTARTSYS) {
+                       rc = -EINTR;
+                       ctx_refresh_interrupt(req);
+               }
+       }
 
        /*
         * following cases could lead us here:
@@ -1217,7 +1219,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req,
        rc = do_cli_unwrap_reply(early_req);
        if (rc) {
                DEBUG_REQ(D_ADAPTTO, early_req,
-                         "error %d unwrap early reply", rc);
+                         "unwrap early reply: rc = %d", rc);
                GOTO(err_ctx, rc);
        }
 
@@ -1392,9 +1394,9 @@ struct ptlrpc_sec *sptlrpc_import_sec_ref(struct obd_import *imp)
 {
        struct ptlrpc_sec *sec;
 
-       spin_lock(&imp->imp_lock);
+       read_lock(&imp->imp_sec_lock);
        sec = sptlrpc_sec_get(imp->imp_sec);
-       spin_unlock(&imp->imp_lock);
+       read_unlock(&imp->imp_sec_lock);
 
        return sec;
 }
@@ -1407,10 +1409,10 @@ static void sptlrpc_import_sec_install(struct obd_import *imp,
 
        LASSERT_ATOMIC_POS(&sec->ps_refcount);
 
-       spin_lock(&imp->imp_lock);
+       write_lock(&imp->imp_sec_lock);
        old_sec = imp->imp_sec;
        imp->imp_sec = sec;
-       spin_unlock(&imp->imp_lock);
+       write_unlock(&imp->imp_sec_lock);
 
        if (old_sec) {
                sptlrpc_sec_kill(old_sec);
@@ -1506,8 +1508,6 @@ int sptlrpc_import_sec_adapt(struct obd_import *imp,
                       sptlrpc_flavor2name(&sf, str, sizeof(str)));
        }
 
-       mutex_lock(&imp->imp_sec_mutex);
-
        newsec = sptlrpc_sec_create(imp, svc_ctx, &sf, sp);
        if (newsec) {
                sptlrpc_import_sec_install(imp, newsec);
@@ -1518,7 +1518,6 @@ int sptlrpc_import_sec_adapt(struct obd_import *imp,
                rc = -EPERM;
        }
 
-       mutex_unlock(&imp->imp_sec_mutex);
 out:
        sptlrpc_sec_put(sec);
        RETURN(rc);
@@ -1799,7 +1798,7 @@ static int sepol_helper(struct obd_import *imp)
            imp->imp_obd->obd_type == NULL) {
                rc = -EINVAL;
        } else {
-               argv[2] = imp->imp_obd->obd_type->typ_name;
+               argv[2] = (char *)imp->imp_obd->obd_type->typ_name;
                argv[4] = imp->imp_obd->obd_name;
                spin_lock(&imp->imp_sec->ps_lock);
                if (imp->imp_sec->ps_sepol_mtime == 0 &&
@@ -2161,18 +2160,21 @@ static int sptlrpc_svc_check_from(struct ptlrpc_request *req, int svc_rc)
        switch (req->rq_sp_from) {
        case LUSTRE_SP_CLI:
                if (req->rq_auth_usr_mdt || req->rq_auth_usr_ost) {
+                       /* The below message is checked in sanity-sec test_33 */
                        DEBUG_REQ(D_ERROR, req, "faked source CLI");
                        svc_rc = SECSVC_DROP;
                }
                break;
        case LUSTRE_SP_MDT:
                if (!req->rq_auth_usr_mdt) {
+                       /* The below message is checked in sanity-sec test_33 */
                        DEBUG_REQ(D_ERROR, req, "faked source MDT");
                        svc_rc = SECSVC_DROP;
                }
                break;
        case LUSTRE_SP_OST:
                if (!req->rq_auth_usr_ost) {
+                       /* The below message is checked in sanity-sec test_33 */
                        DEBUG_REQ(D_ERROR, req, "faked source OST");
                        svc_rc = SECSVC_DROP;
                }
@@ -2181,6 +2183,7 @@ static int sptlrpc_svc_check_from(struct ptlrpc_request *req, int svc_rc)
        case LUSTRE_SP_MGC:
                if (!req->rq_auth_usr_root && !req->rq_auth_usr_mdt &&
                    !req->rq_auth_usr_ost) {
+                       /* The below message is checked in sanity-sec test_33 */
                        DEBUG_REQ(D_ERROR, req, "faked source MGC/MGS");
                        svc_rc = SECSVC_DROP;
                }