Whamcloud - gitweb
LU-13004 ptlrpc: Allow BULK_BUF_KIOV to accept a kvec
[fs/lustre-release.git] / lustre / ptlrpc / nrs.c
index 3164f5b..52d3225 100644 (file)
@@ -20,7 +20,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2011 Intel Corporation
+ * Copyright (c) 2014, 2016, Intel Corporation.
  *
  * Copyright 2012 Xyratex Technology Limited
  */
@@ -86,17 +86,11 @@ static int nrs_policy_ctl_locked(struct ptlrpc_nrs_policy *policy,
 
 static void nrs_policy_stop0(struct ptlrpc_nrs_policy *policy)
 {
-       struct ptlrpc_nrs *nrs = policy->pol_nrs;
        ENTRY;
 
-       if (policy->pol_desc->pd_ops->op_policy_stop != NULL) {
-               spin_unlock(&nrs->nrs_lock);
-
+       if (policy->pol_desc->pd_ops->op_policy_stop != NULL)
                policy->pol_desc->pd_ops->op_policy_stop(policy);
 
-               spin_lock(&nrs->nrs_lock);
-       }
-
        LASSERT(list_empty(&policy->pol_list_queued));
        LASSERT(policy->pol_req_queued == 0 &&
                policy->pol_req_started == 0);
@@ -239,8 +233,23 @@ static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy, char *arg)
                if (nrs->nrs_policy_fallback == NULL)
                        RETURN(-EPERM);
 
-               if (policy->pol_state == NRS_POL_STATE_STARTED)
-                       RETURN(0);
+               if (policy->pol_state == NRS_POL_STATE_STARTED) {
+                       /**
+                        * If the policy argument now is different from the last time,
+                        * stop the policy first and start it again with the new
+                        * argument.
+                        */
+                       if ((arg != NULL) && (strlen(arg) >= NRS_POL_ARG_MAX))
+                               return -EINVAL;
+
+                       if ((arg == NULL && strlen(policy->pol_arg) == 0) ||
+                           (arg != NULL && strcmp(policy->pol_arg, arg) == 0))
+                               RETURN(0);
+
+                       rc = nrs_policy_stop_locked(policy);
+                       if (rc)
+                               RETURN(-EAGAIN);
+               }
        }
 
        /**
@@ -277,6 +286,16 @@ static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy, char *arg)
                }
        }
 
+       if (arg != NULL) {
+               if (strlcpy(policy->pol_arg, arg, sizeof(policy->pol_arg)) >=
+                   sizeof(policy->pol_arg)) {
+                       CERROR("NRS: arg '%s' is too long\n", arg);
+                       GOTO(out, rc = -E2BIG);
+               }
+       } else {
+               policy->pol_arg[0] = '\0';
+       }
+
        policy->pol_state = NRS_POL_STATE_STARTED;
 
        if (policy->pol_flags & PTLRPC_NRS_FL_FALLBACK) {
@@ -648,6 +667,10 @@ static int nrs_policy_ctl(struct ptlrpc_nrs *nrs, char *name,
        if (policy == NULL)
                GOTO(out, rc = -ENOENT);
 
+       if (policy->pol_state != NRS_POL_STATE_STARTED &&
+           policy->pol_state != NRS_POL_STATE_STOPPED)
+               GOTO(out, rc = -EAGAIN);
+
        switch (opc) {
                /**
                 * Unknown opcode, pass it down to the policy-specific control
@@ -1756,18 +1779,6 @@ out:
        RETURN(rc);
 }
 
-
-/* ptlrpc/nrs_fifo.c */
-extern struct ptlrpc_nrs_pol_conf nrs_conf_fifo;
-#ifdef HAVE_SERVER_SUPPORT
-/* ptlrpc/nrs_crr.c */
-extern struct ptlrpc_nrs_pol_conf nrs_conf_crrn;
-/* ptlrpc/nrs_orr.c */
-extern struct ptlrpc_nrs_pol_conf nrs_conf_orr;
-extern struct ptlrpc_nrs_pol_conf nrs_conf_trr;
-extern struct ptlrpc_nrs_pol_conf nrs_conf_tbf;
-#endif /* HAVE_SERVER_SUPPORT */
-
 /**
  * Adds all policies that ship with the ptlrpc module, to NRS core's list of
  * policies \e nrs_core.nrs_policies.
@@ -1802,6 +1813,10 @@ int ptlrpc_nrs_init(void)
        rc = ptlrpc_nrs_policy_register(&nrs_conf_tbf);
        if (rc != 0)
                GOTO(fail, rc);
+
+       rc = ptlrpc_nrs_policy_register(&nrs_conf_delay);
+       if (rc != 0)
+               GOTO(fail, rc);
 #endif /* HAVE_SERVER_SUPPORT */
 
        RETURN(rc);
@@ -1816,7 +1831,7 @@ fail:
 }
 
 /**
- * Removes all policy desciptors from nrs_core::nrs_policies, and frees the
+ * Removes all policy descriptors from nrs_core::nrs_policies, and frees the
  * policy descriptors.
  *
  * Since all PTLRPC services are stopped at this point, there are no more