* GPL HEADER END
*/
/*
- * Copyright (c) 2011, 2014, Intel Corporation.
+ * Copyright (c) 2014, 2016, Intel Corporation.
*
* Copyright 2012 Xyratex Technology Limited
*/
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);
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);
+ }
}
/**
}
}
+ 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) {
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
* \retval -ve error
* \retval 0 success
*/
-int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
+static int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
{
struct ptlrpc_service *svc;
struct ptlrpc_nrs_pol_desc *desc;
RETURN(rc);
}
-EXPORT_SYMBOL(ptlrpc_nrs_policy_register);
-
-/**
- * Unregisters a previously registered policy with NRS core. All instances of
- * the policy on all NRS heads of all supported services are removed.
- *
- * N.B. This function should only be called from a module's exit() function.
- * Although it can be used for policies that ship alongside NRS core, the
- * function is primarily intended for policies that register externally,
- * from other modules.
- *
- * \param[in] conf configuration information for the policy to unregister
- *
- * \retval -ve error
- * \retval 0 success
- */
-int ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_conf *conf)
-{
- struct ptlrpc_nrs_pol_desc *desc;
- int rc;
- ENTRY;
-
- LASSERT(conf != NULL);
-
- if (conf->nc_flags & PTLRPC_NRS_FL_FALLBACK) {
- CERROR("Unable to unregister a fallback policy, unless the "
- "PTLRPC service is stopping.\n");
- RETURN(-EPERM);
- }
-
- conf->nc_name[NRS_POL_NAME_MAX - 1] = '\0';
-
- mutex_lock(&nrs_core.nrs_mutex);
-
- desc = nrs_policy_find_desc_locked(conf->nc_name);
- if (desc == NULL) {
- CERROR("Failing to unregister NRS policy %s which has "
- "not been registered with NRS core!\n",
- conf->nc_name);
- GOTO(not_exist, rc = -ENOENT);
- }
-
- mutex_lock(&ptlrpc_all_services_mutex);
-
- rc = nrs_policy_unregister_locked(desc);
- if (rc < 0) {
- if (rc == -EBUSY)
- CERROR("Please first stop policy %s on all service "
- "partitions and then retry to unregister the "
- "policy.\n", conf->nc_name);
- GOTO(fail, rc);
- }
-
- CDEBUG(D_INFO, "Unregistering policy %s from NRS core.\n",
- conf->nc_name);
-
- list_del(&desc->pd_list);
- OBD_FREE_PTR(desc);
-
-fail:
- mutex_unlock(&ptlrpc_all_services_mutex);
-
-not_exist:
- mutex_unlock(&nrs_core.nrs_mutex);
-
- RETURN(rc);
-}
-EXPORT_SYMBOL(ptlrpc_nrs_policy_unregister);
/**
* Setup NRS heads on all service partitions of service \a svc, and register
GOTO(fail, rc);
#endif /* HAVE_SERVER_SUPPORT */
+ rc = ptlrpc_nrs_policy_register(&nrs_conf_delay);
+ if (rc != 0)
+ GOTO(fail, rc);
+
RETURN(rc);
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