4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (c) 2011 Intel Corporation
25 * Copyright 2012 Xyratex Technology Limited
30 * Network Request Scheduler (NRS)
32 * Allows to reorder the handling of RPCs at servers.
34 * Author: Liang Zhen <liang@whamcloud.com>
35 * Author: Nikitas Angelinas <nikitas_angelinas@xyratex.com>
42 #define DEBUG_SUBSYSTEM S_RPC
44 #include <liblustre.h>
46 #include <obd_support.h>
47 #include <obd_class.h>
48 #include <lustre_net.h>
49 #include <lprocfs_status.h>
50 #include <libcfs/libcfs.h>
51 #include "ptlrpc_internal.h"
53 /* XXX: This is just for liblustre. Remove the #if defined directive when the
54 * "cfs_" prefix is dropped from cfs_list_head. */
55 #if defined (__linux__) && defined(__KERNEL__)
56 extern struct list_head ptlrpc_all_services;
58 extern struct cfs_list_head ptlrpc_all_services;
64 struct nrs_core nrs_core;
66 static int nrs_policy_init(struct ptlrpc_nrs_policy *policy)
68 return policy->pol_desc->pd_ops->op_policy_init != NULL ?
69 policy->pol_desc->pd_ops->op_policy_init(policy) : 0;
72 static void nrs_policy_fini(struct ptlrpc_nrs_policy *policy)
74 LASSERT(policy->pol_ref == 0);
75 LASSERT(policy->pol_req_queued == 0);
77 if (policy->pol_desc->pd_ops->op_policy_fini != NULL)
78 policy->pol_desc->pd_ops->op_policy_fini(policy);
81 static int nrs_policy_ctl_locked(struct ptlrpc_nrs_policy *policy,
82 enum ptlrpc_nrs_ctl opc, void *arg)
85 * The policy may be stopped, but the lprocfs files and
86 * ptlrpc_nrs_policy instances remain present until unregistration time.
87 * Do not perform the ctl operation if the policy is stopped, as
88 * policy->pol_private will be NULL in such a case.
90 if (policy->pol_state == NRS_POL_STATE_STOPPED)
93 RETURN(policy->pol_desc->pd_ops->op_policy_ctl != NULL ?
94 policy->pol_desc->pd_ops->op_policy_ctl(policy, opc, arg) :
98 static void nrs_policy_stop0(struct ptlrpc_nrs_policy *policy)
100 struct ptlrpc_nrs *nrs = policy->pol_nrs;
103 if (policy->pol_desc->pd_ops->op_policy_stop != NULL) {
104 spin_unlock(&nrs->nrs_lock);
106 policy->pol_desc->pd_ops->op_policy_stop(policy);
108 spin_lock(&nrs->nrs_lock);
111 LASSERT(cfs_list_empty(&policy->pol_list_queued));
112 LASSERT(policy->pol_req_queued == 0 &&
113 policy->pol_req_started == 0);
115 policy->pol_private = NULL;
117 policy->pol_state = NRS_POL_STATE_STOPPED;
119 if (cfs_atomic_dec_and_test(&policy->pol_desc->pd_refs))
120 module_put(policy->pol_desc->pd_owner);
125 static int nrs_policy_stop_locked(struct ptlrpc_nrs_policy *policy)
127 struct ptlrpc_nrs *nrs = policy->pol_nrs;
130 if (nrs->nrs_policy_fallback == policy && !nrs->nrs_stopping)
133 if (policy->pol_state == NRS_POL_STATE_STARTING)
136 /* In progress or already stopped */
137 if (policy->pol_state != NRS_POL_STATE_STARTED)
140 policy->pol_state = NRS_POL_STATE_STOPPING;
142 /* Immediately make it invisible */
143 if (nrs->nrs_policy_primary == policy) {
144 nrs->nrs_policy_primary = NULL;
147 LASSERT(nrs->nrs_policy_fallback == policy);
148 nrs->nrs_policy_fallback = NULL;
151 /* I have the only refcount */
152 if (policy->pol_ref == 1)
153 nrs_policy_stop0(policy);
159 * Transitions the \a nrs NRS head's primary policy to
160 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING and if the policy has no
161 * pending usage references, to ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED.
163 * \param[in] nrs the NRS head to carry out this operation on
165 static void nrs_policy_stop_primary(struct ptlrpc_nrs *nrs)
167 struct ptlrpc_nrs_policy *tmp = nrs->nrs_policy_primary;
172 * XXX: This should really be RETURN_EXIT, but the latter does
173 * not currently print anything out, and possibly should be
180 nrs->nrs_policy_primary = NULL;
182 LASSERT(tmp->pol_state == NRS_POL_STATE_STARTED);
183 tmp->pol_state = NRS_POL_STATE_STOPPING;
185 if (tmp->pol_ref == 0)
186 nrs_policy_stop0(tmp);
191 * Transitions a policy across the ptlrpc_nrs_pol_state range of values, in
192 * response to an lprocfs command to start a policy.
194 * If a primary policy different to the current one is specified, this function
195 * will transition the new policy to the
196 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTING and then to
197 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED, and will then transition
198 * the old primary policy (if there is one) to
199 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING, and if there are no outstanding
200 * references on the policy to ptlrpc_nrs_pol_stae::NRS_POL_STATE_STOPPED.
202 * If the fallback policy is specified, this is taken to indicate an instruction
203 * to stop the current primary policy, without substituting it with another
204 * primary policy, so the primary policy (if any) is transitioned to
205 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING, and if there are no outstanding
206 * references on the policy to ptlrpc_nrs_pol_stae::NRS_POL_STATE_STOPPED. In
207 * this case, the fallback policy is only left active in the NRS head.
209 static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy)
211 struct ptlrpc_nrs *nrs = policy->pol_nrs;
216 * Don't allow multiple starting which is too complex, and has no real
219 if (nrs->nrs_policy_starting)
222 LASSERT(policy->pol_state != NRS_POL_STATE_STARTING);
224 if (policy->pol_state == NRS_POL_STATE_STOPPING)
227 if (policy->pol_flags & PTLRPC_NRS_FL_FALLBACK) {
229 * This is for cases in which the user sets the policy to the
230 * fallback policy (currently fifo for all services); i.e. the
231 * user is resetting the policy to the default; so we stop the
232 * primary policy, if any.
234 if (policy == nrs->nrs_policy_fallback) {
235 nrs_policy_stop_primary(nrs);
240 * If we reach here, we must be setting up the fallback policy
241 * at service startup time, and only a single policy with the
242 * nrs_policy_flags::PTLRPC_NRS_FL_FALLBACK flag set can
243 * register with NRS core.
245 LASSERT(nrs->nrs_policy_fallback == NULL);
248 * Shouldn't start primary policy if w/o fallback policy.
250 if (nrs->nrs_policy_fallback == NULL)
253 if (policy->pol_state == NRS_POL_STATE_STARTED)
258 * Increase the module usage count for policies registering from other
261 if (cfs_atomic_inc_return(&policy->pol_desc->pd_refs) == 1 &&
262 !try_module_get(policy->pol_desc->pd_owner)) {
263 cfs_atomic_dec(&policy->pol_desc->pd_refs);
264 CERROR("NRS: cannot get module for policy %s; is it alive?\n",
265 policy->pol_desc->pd_name);
270 * Serialize policy starting across the NRS head
272 nrs->nrs_policy_starting = 1;
274 policy->pol_state = NRS_POL_STATE_STARTING;
276 if (policy->pol_desc->pd_ops->op_policy_start) {
277 spin_unlock(&nrs->nrs_lock);
279 rc = policy->pol_desc->pd_ops->op_policy_start(policy);
281 spin_lock(&nrs->nrs_lock);
283 if (cfs_atomic_dec_and_test(&policy->pol_desc->pd_refs))
284 module_put(policy->pol_desc->pd_owner);
286 policy->pol_state = NRS_POL_STATE_STOPPED;
291 policy->pol_state = NRS_POL_STATE_STARTED;
293 if (policy->pol_flags & PTLRPC_NRS_FL_FALLBACK) {
295 * This path is only used at PTLRPC service setup time.
297 nrs->nrs_policy_fallback = policy;
300 * Try to stop the current primary policy if there is one.
302 nrs_policy_stop_primary(nrs);
305 * And set the newly-started policy as the primary one.
307 nrs->nrs_policy_primary = policy;
311 nrs->nrs_policy_starting = 0;
317 * Increases the policy's usage reference count.
319 static inline void nrs_policy_get_locked(struct ptlrpc_nrs_policy *policy)
325 * Decreases the policy's usage reference count, and stops the policy in case it
326 * was already stopping and have no more outstanding usage references (which
327 * indicates it has no more queued or started requests, and can be safely
330 static void nrs_policy_put_locked(struct ptlrpc_nrs_policy *policy)
332 LASSERT(policy->pol_ref > 0);
335 if (unlikely(policy->pol_ref == 0 &&
336 policy->pol_state == NRS_POL_STATE_STOPPING))
337 nrs_policy_stop0(policy);
340 static void nrs_policy_put(struct ptlrpc_nrs_policy *policy)
342 spin_lock(&policy->pol_nrs->nrs_lock);
343 nrs_policy_put_locked(policy);
344 spin_unlock(&policy->pol_nrs->nrs_lock);
348 * Find and return a policy by name.
350 static struct ptlrpc_nrs_policy * nrs_policy_find_locked(struct ptlrpc_nrs *nrs,
353 struct ptlrpc_nrs_policy *tmp;
355 cfs_list_for_each_entry(tmp, &nrs->nrs_policy_list, pol_list) {
356 if (strncmp(tmp->pol_desc->pd_name, name,
357 NRS_POL_NAME_MAX) == 0) {
358 nrs_policy_get_locked(tmp);
366 * Release references for the resource hierarchy moving upwards towards the
367 * policy instance resource.
369 static void nrs_resource_put(struct ptlrpc_nrs_resource *res)
371 struct ptlrpc_nrs_policy *policy = res->res_policy;
373 if (policy->pol_desc->pd_ops->op_res_put != NULL) {
374 struct ptlrpc_nrs_resource *parent;
376 for (; res != NULL; res = parent) {
377 parent = res->res_parent;
378 policy->pol_desc->pd_ops->op_res_put(policy, res);
384 * Obtains references for each resource in the resource hierarchy for request
385 * \a nrq if it is to be handled by \a policy.
387 * \param[in] policy the policy
388 * \param[in] nrq the request
389 * \param[in] moving_req denotes whether this is a call to the function by
390 * ldlm_lock_reorder_req(), in order to move \a nrq to
391 * the high-priority NRS head; we should not sleep when
394 * \retval NULL resource hierarchy references not obtained
395 * \retval valid-pointer the bottom level of the resource hierarchy
397 * \see ptlrpc_nrs_pol_ops::op_res_get()
400 struct ptlrpc_nrs_resource * nrs_resource_get(struct ptlrpc_nrs_policy *policy,
401 struct ptlrpc_nrs_request *nrq,
405 * Set to NULL to traverse the resource hierarchy from the top.
407 struct ptlrpc_nrs_resource *res = NULL;
408 struct ptlrpc_nrs_resource *tmp = NULL;
412 rc = policy->pol_desc->pd_ops->op_res_get(policy, nrq, res,
416 nrs_resource_put(res);
420 LASSERT(tmp != NULL);
421 tmp->res_parent = res;
422 tmp->res_policy = policy;
426 * Return once we have obtained a reference to the bottom level
427 * of the resource hierarchy.
435 * Obtains resources for the resource hierarchies and policy references for
436 * the fallback and current primary policy (if any), that will later be used
437 * to handle request \a nrq.
439 * \param[in] nrs the NRS head instance that will be handling request \a nrq.
440 * \param[in] nrq the request that is being handled.
441 * \param[out] resp the array where references to the resource hierarchy are
443 * \param[in] moving_req is set when obtaining resources while moving a
444 * request from a policy on the regular NRS head to a
445 * policy on the HP NRS head (via
446 * ldlm_lock_reorder_req()). It signifies that
447 * allocations to get resources should be atomic; for
448 * a full explanation, see comment in
449 * ptlrpc_nrs_pol_ops::op_res_get().
451 static void nrs_resource_get_safe(struct ptlrpc_nrs *nrs,
452 struct ptlrpc_nrs_request *nrq,
453 struct ptlrpc_nrs_resource **resp,
456 struct ptlrpc_nrs_policy *primary = NULL;
457 struct ptlrpc_nrs_policy *fallback = NULL;
459 memset(resp, 0, sizeof(resp[0]) * NRS_RES_MAX);
462 * Obtain policy references.
464 spin_lock(&nrs->nrs_lock);
466 fallback = nrs->nrs_policy_fallback;
467 nrs_policy_get_locked(fallback);
469 primary = nrs->nrs_policy_primary;
471 nrs_policy_get_locked(primary);
473 spin_unlock(&nrs->nrs_lock);
476 * Obtain resource hierarchy references.
478 resp[NRS_RES_FALLBACK] = nrs_resource_get(fallback, nrq, moving_req);
479 LASSERT(resp[NRS_RES_FALLBACK] != NULL);
481 if (primary != NULL) {
482 resp[NRS_RES_PRIMARY] = nrs_resource_get(primary, nrq,
485 * A primary policy may exist which may not wish to serve a
486 * particular request for different reasons; release the
487 * reference on the policy as it will not be used for this
490 if (resp[NRS_RES_PRIMARY] == NULL)
491 nrs_policy_put(primary);
496 * Releases references to resource hierarchies and policies, because they are no
497 * longer required; used when request handling has been completed, or the
498 * request is moving to the high priority NRS head.
500 * \param resp the resource hierarchy that is being released
502 * \see ptlrpcnrs_req_hp_move()
503 * \see ptlrpc_nrs_req_finalize()
505 static void nrs_resource_put_safe(struct ptlrpc_nrs_resource **resp)
507 struct ptlrpc_nrs_policy *pols[NRS_RES_MAX];
508 struct ptlrpc_nrs *nrs = NULL;
511 for (i = 0; i < NRS_RES_MAX; i++) {
512 if (resp[i] != NULL) {
513 pols[i] = resp[i]->res_policy;
514 nrs_resource_put(resp[i]);
521 for (i = 0; i < NRS_RES_MAX; i++) {
526 nrs = pols[i]->pol_nrs;
527 spin_lock(&nrs->nrs_lock);
529 nrs_policy_put_locked(pols[i]);
533 spin_unlock(&nrs->nrs_lock);
537 * Obtains an NRS request from \a policy for handling or examination; the
538 * request should be removed in the 'handling' case.
540 * Calling into this function implies we already know the policy has a request
541 * waiting to be handled.
543 * \param[in] policy the policy from which a request
544 * \param[in] peek when set, signifies that we just want to examine the
545 * request, and not handle it, so the request is not removed
547 * \param[in] force when set, it will force a policy to return a request if it
550 * \retval the NRS request to be handled
553 struct ptlrpc_nrs_request * nrs_request_get(struct ptlrpc_nrs_policy *policy,
554 bool peek, bool force)
556 struct ptlrpc_nrs_request *nrq;
558 LASSERT(policy->pol_req_queued > 0);
560 nrq = policy->pol_desc->pd_ops->op_req_get(policy, peek, force);
562 LASSERT(ergo(nrq != NULL, nrs_request_policy(nrq) == policy));
568 * Enqueues request \a nrq for later handling, via one one the policies for
569 * which resources where earlier obtained via nrs_resource_get_safe(). The
570 * function attempts to enqueue the request first on the primary policy
571 * (if any), since this is the preferred choice.
573 * \param nrq the request being enqueued
575 * \see nrs_resource_get_safe()
577 static inline void nrs_request_enqueue(struct ptlrpc_nrs_request *nrq)
579 struct ptlrpc_nrs_policy *policy;
584 * Try in descending order, because the primary policy (if any) is
585 * the preferred choice.
587 for (i = NRS_RES_MAX - 1; i >= 0; i--) {
588 if (nrq->nr_res_ptrs[i] == NULL)
592 policy = nrq->nr_res_ptrs[i]->res_policy;
594 rc = policy->pol_desc->pd_ops->op_req_enqueue(policy, nrq);
596 policy->pol_nrs->nrs_req_queued++;
597 policy->pol_req_queued++;
602 * Should never get here, as at least the primary policy's
603 * ptlrpc_nrs_pol_ops::op_req_enqueue() implementation should always
610 * Called when a request has been handled
612 * \param[in] nrs the request that has been handled; can be used for
613 * job/resource control.
615 * \see ptlrpc_nrs_req_stop_nolock()
617 static inline void nrs_request_stop(struct ptlrpc_nrs_request *nrq)
619 struct ptlrpc_nrs_policy *policy = nrs_request_policy(nrq);
621 if (policy->pol_desc->pd_ops->op_req_stop)
622 policy->pol_desc->pd_ops->op_req_stop(policy, nrq);
624 LASSERT(policy->pol_nrs->nrs_req_started > 0);
625 LASSERT(policy->pol_req_started > 0);
627 policy->pol_nrs->nrs_req_started--;
628 policy->pol_req_started--;
632 * Handler for operations that can be carried out on policies.
634 * Handles opcodes that are common to all policy types within NRS core, and
635 * passes any unknown opcodes to the policy-specific control function.
637 * \param[in] nrs the NRS head this policy belongs to.
638 * \param[in] name the human-readable policy name; should be the same as
639 * ptlrpc_nrs_pol_desc::pd_name.
640 * \param[in] opc the opcode of the operation being carried out.
641 * \param[in,out] arg can be used to pass information in and out between when
642 * carrying an operation; usually data that is private to
643 * the policy at some level, or generic policy status
646 * \retval -ve error condition
647 * \retval 0 operation was carried out successfully
649 static int nrs_policy_ctl(struct ptlrpc_nrs *nrs, char *name,
650 enum ptlrpc_nrs_ctl opc, void *arg)
652 struct ptlrpc_nrs_policy *policy;
656 spin_lock(&nrs->nrs_lock);
658 policy = nrs_policy_find_locked(nrs, name);
660 GOTO(out, rc = -ENOENT);
664 * Unknown opcode, pass it down to the policy-specific control
665 * function for handling.
668 rc = nrs_policy_ctl_locked(policy, opc, arg);
674 case PTLRPC_NRS_CTL_START:
675 rc = nrs_policy_start_locked(policy);
680 nrs_policy_put_locked(policy);
682 spin_unlock(&nrs->nrs_lock);
688 * Unregisters a policy by name.
690 * \param[in] nrs the NRS head this policy belongs to.
691 * \param[in] name the human-readable policy name; should be the same as
692 * ptlrpc_nrs_pol_desc::pd_name
697 static int nrs_policy_unregister(struct ptlrpc_nrs *nrs, char *name)
699 struct ptlrpc_nrs_policy *policy = NULL;
702 spin_lock(&nrs->nrs_lock);
704 policy = nrs_policy_find_locked(nrs, name);
705 if (policy == NULL) {
706 spin_unlock(&nrs->nrs_lock);
708 CERROR("Can't find NRS policy %s\n", name);
712 if (policy->pol_ref > 1) {
713 CERROR("Policy %s is busy with %d references\n", name,
714 (int)policy->pol_ref);
715 nrs_policy_put_locked(policy);
717 spin_unlock(&nrs->nrs_lock);
721 LASSERT(policy->pol_req_queued == 0);
722 LASSERT(policy->pol_req_started == 0);
724 if (policy->pol_state != NRS_POL_STATE_STOPPED) {
725 nrs_policy_stop_locked(policy);
726 LASSERT(policy->pol_state == NRS_POL_STATE_STOPPED);
729 cfs_list_del(&policy->pol_list);
732 nrs_policy_put_locked(policy);
734 spin_unlock(&nrs->nrs_lock);
736 nrs_policy_fini(policy);
738 LASSERT(policy->pol_private == NULL);
739 OBD_FREE_PTR(policy);
745 * Register a policy from \policy descriptor \a desc with NRS head \a nrs.
747 * \param[in] nrs the NRS head on which the policy will be registered.
748 * \param[in] desc the policy descriptor from which the information will be
749 * obtained to register the policy.
754 static int nrs_policy_register(struct ptlrpc_nrs *nrs,
755 struct ptlrpc_nrs_pol_desc *desc)
757 struct ptlrpc_nrs_policy *policy;
758 struct ptlrpc_nrs_policy *tmp;
759 struct ptlrpc_service_part *svcpt = nrs->nrs_svcpt;
763 LASSERT(svcpt != NULL);
764 LASSERT(desc->pd_ops != NULL);
765 LASSERT(desc->pd_ops->op_res_get != NULL);
766 LASSERT(desc->pd_ops->op_req_get != NULL);
767 LASSERT(desc->pd_ops->op_req_enqueue != NULL);
768 LASSERT(desc->pd_ops->op_req_dequeue != NULL);
769 LASSERT(desc->pd_compat != NULL);
771 OBD_CPT_ALLOC_GFP(policy, svcpt->scp_service->srv_cptable,
772 svcpt->scp_cpt, sizeof(*policy), __GFP_IO);
776 policy->pol_nrs = nrs;
777 policy->pol_desc = desc;
778 policy->pol_state = NRS_POL_STATE_STOPPED;
779 policy->pol_flags = desc->pd_flags;
781 CFS_INIT_LIST_HEAD(&policy->pol_list);
782 CFS_INIT_LIST_HEAD(&policy->pol_list_queued);
784 rc = nrs_policy_init(policy);
786 OBD_FREE_PTR(policy);
790 spin_lock(&nrs->nrs_lock);
792 tmp = nrs_policy_find_locked(nrs, policy->pol_desc->pd_name);
794 CERROR("NRS policy %s has been registered, can't register it "
795 "for %s\n", policy->pol_desc->pd_name,
796 svcpt->scp_service->srv_name);
797 nrs_policy_put_locked(tmp);
799 spin_unlock(&nrs->nrs_lock);
800 nrs_policy_fini(policy);
801 OBD_FREE_PTR(policy);
806 cfs_list_add_tail(&policy->pol_list, &nrs->nrs_policy_list);
809 if (policy->pol_flags & PTLRPC_NRS_FL_REG_START)
810 rc = nrs_policy_start_locked(policy);
812 spin_unlock(&nrs->nrs_lock);
815 (void) nrs_policy_unregister(nrs, policy->pol_desc->pd_name);
821 * Enqueue request \a req using one of the policies its resources are referring
824 * \param[in] req the request to enqueue.
826 static void ptlrpc_nrs_req_add_nolock(struct ptlrpc_request *req)
828 struct ptlrpc_nrs_policy *policy;
830 LASSERT(req->rq_nrq.nr_initialized);
831 LASSERT(!req->rq_nrq.nr_enqueued);
833 nrs_request_enqueue(&req->rq_nrq);
834 req->rq_nrq.nr_enqueued = 1;
836 policy = nrs_request_policy(&req->rq_nrq);
838 * Add the policy to the NRS head's list of policies with enqueued
839 * requests, if it has not been added there.
841 if (unlikely(cfs_list_empty(&policy->pol_list_queued)))
842 cfs_list_add_tail(&policy->pol_list_queued,
843 &policy->pol_nrs->nrs_policy_queued);
847 * Enqueue a request on the high priority NRS head.
849 * \param req the request to enqueue.
851 static void ptlrpc_nrs_hpreq_add_nolock(struct ptlrpc_request *req)
853 int opc = lustre_msg_get_opc(req->rq_reqmsg);
856 spin_lock(&req->rq_lock);
858 ptlrpc_nrs_req_add_nolock(req);
860 DEBUG_REQ(D_NET, req, "high priority req");
861 spin_unlock(&req->rq_lock);
866 * Returns a boolean predicate indicating whether the policy described by
867 * \a desc is adequate for use with service \a svc.
869 * \param[in] svc the service
870 * \param[in] desc the policy descriptor
872 * \retval false the policy is not compatible with the service
873 * \retval true the policy is compatible with the service
875 static inline bool nrs_policy_compatible(const struct ptlrpc_service *svc,
876 const struct ptlrpc_nrs_pol_desc *desc)
878 return desc->pd_compat(svc, desc);
882 * Registers all compatible policies in nrs_core.nrs_policies, for NRS head
885 * \param[in] nrs the NRS head
890 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
892 * \see ptlrpc_service_nrs_setup()
894 static int nrs_register_policies_locked(struct ptlrpc_nrs *nrs)
896 struct ptlrpc_nrs_pol_desc *desc;
897 /* for convenience */
898 struct ptlrpc_service_part *svcpt = nrs->nrs_svcpt;
899 struct ptlrpc_service *svc = svcpt->scp_service;
903 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
905 cfs_list_for_each_entry(desc, &nrs_core.nrs_policies, pd_list) {
906 if (nrs_policy_compatible(svc, desc)) {
907 rc = nrs_policy_register(nrs, desc);
909 CERROR("Failed to register NRS policy %s for "
910 "partition %d of service %s: %d\n",
911 desc->pd_name, svcpt->scp_cpt,
914 * Fail registration if any of the policies'
915 * registration fails.
926 * Initializes NRS head \a nrs of service partition \a svcpt, and registers all
927 * compatible policies in NRS core, with the NRS head.
929 * \param[in] nrs the NRS head
930 * \param[in] svcpt the PTLRPC service partition to setup
935 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
937 static int nrs_svcpt_setup_locked0(struct ptlrpc_nrs *nrs,
938 struct ptlrpc_service_part *svcpt)
941 enum ptlrpc_nrs_queue_type queue;
943 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
945 if (nrs == &svcpt->scp_nrs_reg)
946 queue = PTLRPC_NRS_QUEUE_REG;
947 else if (nrs == svcpt->scp_nrs_hp)
948 queue = PTLRPC_NRS_QUEUE_HP;
952 nrs->nrs_svcpt = svcpt;
953 nrs->nrs_queue_type = queue;
954 spin_lock_init(&nrs->nrs_lock);
955 CFS_INIT_LIST_HEAD(&nrs->nrs_policy_list);
956 CFS_INIT_LIST_HEAD(&nrs->nrs_policy_queued);
958 rc = nrs_register_policies_locked(nrs);
964 * Allocates a regular and optionally a high-priority NRS head (if the service
965 * handles high-priority RPCs), and then registers all available compatible
966 * policies on those NRS heads.
968 * \param[in,out] svcpt the PTLRPC service partition to setup
970 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
972 static int nrs_svcpt_setup_locked(struct ptlrpc_service_part *svcpt)
974 struct ptlrpc_nrs *nrs;
978 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
981 * Initialize the regular NRS head.
983 nrs = nrs_svcpt2nrs(svcpt, false);
984 rc = nrs_svcpt_setup_locked0(nrs, svcpt);
989 * Optionally allocate a high-priority NRS head.
991 if (svcpt->scp_service->srv_ops.so_hpreq_handler == NULL)
994 OBD_CPT_ALLOC_PTR(svcpt->scp_nrs_hp,
995 svcpt->scp_service->srv_cptable,
997 if (svcpt->scp_nrs_hp == NULL)
998 GOTO(out, rc = -ENOMEM);
1000 nrs = nrs_svcpt2nrs(svcpt, true);
1001 rc = nrs_svcpt_setup_locked0(nrs, svcpt);
1008 * Unregisters all policies on all available NRS heads in a service partition;
1009 * called at PTLRPC service unregistration time.
1011 * \param[in] svcpt the PTLRPC service partition
1013 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
1015 static void nrs_svcpt_cleanup_locked(struct ptlrpc_service_part *svcpt)
1017 struct ptlrpc_nrs *nrs;
1018 struct ptlrpc_nrs_policy *policy;
1019 struct ptlrpc_nrs_policy *tmp;
1024 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
1027 nrs = nrs_svcpt2nrs(svcpt, hp);
1028 nrs->nrs_stopping = 1;
1030 cfs_list_for_each_entry_safe(policy, tmp, &nrs->nrs_policy_list,
1032 rc = nrs_policy_unregister(nrs, policy->pol_desc->pd_name);
1037 * If the service partition has an HP NRS head, clean that up as well.
1039 if (!hp && nrs_svcpt_has_hp(svcpt)) {
1051 * Returns the descriptor for a policy as identified by by \a name.
1053 * \param[in] name the policy name
1055 * \retval the policy descriptor
1058 static struct ptlrpc_nrs_pol_desc *nrs_policy_find_desc_locked(const char *name)
1060 struct ptlrpc_nrs_pol_desc *tmp;
1063 cfs_list_for_each_entry(tmp, &nrs_core.nrs_policies, pd_list) {
1064 if (strncmp(tmp->pd_name, name, NRS_POL_NAME_MAX) == 0)
1071 * Removes the policy from all supported NRS heads of all partitions of all
1074 * \param[in] desc the policy descriptor to unregister
1077 * \retval 0 successfully unregistered policy on all supported NRS heads
1079 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
1080 * \pre mutex_is_locked(&ptlrpc_all_services_mutex)
1082 static int nrs_policy_unregister_locked(struct ptlrpc_nrs_pol_desc *desc)
1084 struct ptlrpc_nrs *nrs;
1085 struct ptlrpc_service *svc;
1086 struct ptlrpc_service_part *svcpt;
1091 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
1092 LASSERT(mutex_is_locked(&ptlrpc_all_services_mutex));
1094 cfs_list_for_each_entry(svc, &ptlrpc_all_services, srv_list) {
1096 if (!nrs_policy_compatible(svc, desc) ||
1097 unlikely(svc->srv_is_stopping))
1100 ptlrpc_service_for_each_part(svcpt, i, svc) {
1104 nrs = nrs_svcpt2nrs(svcpt, hp);
1105 rc = nrs_policy_unregister(nrs, desc->pd_name);
1107 * Ignore -ENOENT as the policy may not have registered
1108 * successfully on all service partitions.
1110 if (rc == -ENOENT) {
1112 } else if (rc != 0) {
1113 CERROR("Failed to unregister NRS policy %s for "
1114 "partition %d of service %s: %d\n",
1115 desc->pd_name, svcpt->scp_cpt,
1116 svcpt->scp_service->srv_name, rc);
1120 if (!hp && nrs_svc_has_hp(svc)) {
1126 if (desc->pd_ops->op_lprocfs_fini != NULL)
1127 desc->pd_ops->op_lprocfs_fini(svc);
1134 * Registers a new policy with NRS core.
1136 * The function will only succeed if policy registration with all compatible
1137 * service partitions (if any) is successful.
1139 * N.B. This function should be called either at ptlrpc module initialization
1140 * time when registering a policy that ships with NRS core, or in a
1141 * module's init() function for policies registering from other modules.
1143 * \param[in] conf configuration information for the new policy to register
1148 int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
1150 struct ptlrpc_service *svc;
1151 struct ptlrpc_nrs_pol_desc *desc;
1155 LASSERT(conf != NULL);
1156 LASSERT(conf->nc_ops != NULL);
1157 LASSERT(conf->nc_compat != NULL);
1158 LASSERT(ergo(conf->nc_compat == nrs_policy_compat_one,
1159 conf->nc_compat_svc_name != NULL));
1160 LASSERT(ergo((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) != 0,
1161 conf->nc_owner != NULL));
1163 conf->nc_name[NRS_POL_NAME_MAX - 1] = '\0';
1166 * External policies are not allowed to start immediately upon
1167 * registration, as there is a relatively higher chance that their
1168 * registration might fail. In such a case, some policy instances may
1169 * already have requests queued wen unregistration needs to happen as
1170 * part o cleanup; since there is currently no way to drain requests
1171 * from a policy unless the service is unregistering, we just disallow
1174 if ((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) &&
1175 (conf->nc_flags & (PTLRPC_NRS_FL_FALLBACK |
1176 PTLRPC_NRS_FL_REG_START))) {
1177 CERROR("NRS: failing to register policy %s. Please check "
1178 "policy flags; external policies cannot act as fallback "
1179 "policies, or be started immediately upon registration "
1180 "without interaction with lprocfs\n", conf->nc_name);
1184 mutex_lock(&nrs_core.nrs_mutex);
1186 if (nrs_policy_find_desc_locked(conf->nc_name) != NULL) {
1187 CERROR("NRS: failing to register policy %s which has already "
1188 "been registered with NRS core!\n",
1190 GOTO(fail, rc = -EEXIST);
1193 OBD_ALLOC_PTR(desc);
1195 GOTO(fail, rc = -ENOMEM);
1197 if (strlcpy(desc->pd_name, conf->nc_name, sizeof(desc->pd_name)) >=
1198 sizeof(desc->pd_name)) {
1200 GOTO(fail, rc = -E2BIG);
1202 desc->pd_ops = conf->nc_ops;
1203 desc->pd_compat = conf->nc_compat;
1204 desc->pd_compat_svc_name = conf->nc_compat_svc_name;
1205 if ((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) != 0)
1206 desc->pd_owner = conf->nc_owner;
1207 desc->pd_flags = conf->nc_flags;
1208 cfs_atomic_set(&desc->pd_refs, 0);
1211 * For policies that are held in the same module as NRS (currently
1212 * ptlrpc), do not register the policy with all compatible services,
1213 * as the services will not have started at this point, since we are
1214 * calling from ptlrpc module initialization code. In such cases each
1215 * service will register all compatible policies later, via
1216 * ptlrpc_service_nrs_setup().
1218 if ((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) == 0)
1222 * Register the new policy on all compatible services
1224 mutex_lock(&ptlrpc_all_services_mutex);
1226 cfs_list_for_each_entry(svc, &ptlrpc_all_services, srv_list) {
1227 struct ptlrpc_service_part *svcpt;
1231 if (!nrs_policy_compatible(svc, desc) ||
1232 unlikely(svc->srv_is_stopping))
1235 ptlrpc_service_for_each_part(svcpt, i, svc) {
1236 struct ptlrpc_nrs *nrs;
1239 nrs = nrs_svcpt2nrs(svcpt, hp);
1240 rc = nrs_policy_register(nrs, desc);
1242 CERROR("Failed to register NRS policy %s for "
1243 "partition %d of service %s: %d\n",
1244 desc->pd_name, svcpt->scp_cpt,
1245 svcpt->scp_service->srv_name, rc);
1247 rc2 = nrs_policy_unregister_locked(desc);
1249 * Should not fail at this point
1252 mutex_unlock(&ptlrpc_all_services_mutex);
1257 if (!hp && nrs_svc_has_hp(svc)) {
1264 * No need to take a reference to other modules here, as we
1265 * will be calling from the module's init() function.
1267 if (desc->pd_ops->op_lprocfs_init != NULL) {
1268 rc = desc->pd_ops->op_lprocfs_init(svc);
1270 rc2 = nrs_policy_unregister_locked(desc);
1272 * Should not fail at this point
1275 mutex_unlock(&ptlrpc_all_services_mutex);
1282 mutex_unlock(&ptlrpc_all_services_mutex);
1284 cfs_list_add_tail(&desc->pd_list, &nrs_core.nrs_policies);
1286 mutex_unlock(&nrs_core.nrs_mutex);
1290 EXPORT_SYMBOL(ptlrpc_nrs_policy_register);
1293 * Unregisters a previously registered policy with NRS core. All instances of
1294 * the policy on all NRS heads of all supported services are removed.
1296 * N.B. This function should only be called from a module's exit() function.
1297 * Although it can be used for policies that ship alongside NRS core, the
1298 * function is primarily intended for policies that register externally,
1299 * from other modules.
1301 * \param[in] conf configuration information for the policy to unregister
1306 int ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_conf *conf)
1308 struct ptlrpc_nrs_pol_desc *desc;
1312 LASSERT(conf != NULL);
1314 if (conf->nc_flags & PTLRPC_NRS_FL_FALLBACK) {
1315 CERROR("Unable to unregister a fallback policy, unless the "
1316 "PTLRPC service is stopping.\n");
1320 conf->nc_name[NRS_POL_NAME_MAX - 1] = '\0';
1322 mutex_lock(&nrs_core.nrs_mutex);
1324 desc = nrs_policy_find_desc_locked(conf->nc_name);
1326 CERROR("Failing to unregister NRS policy %s which has "
1327 "not been registered with NRS core!\n",
1329 GOTO(not_exist, rc = -ENOENT);
1332 mutex_lock(&ptlrpc_all_services_mutex);
1334 rc = nrs_policy_unregister_locked(desc);
1337 CERROR("Please first stop policy %s on all service "
1338 "partitions and then retry to unregister the "
1339 "policy.\n", conf->nc_name);
1343 CDEBUG(D_INFO, "Unregistering policy %s from NRS core.\n",
1346 cfs_list_del(&desc->pd_list);
1350 mutex_unlock(&ptlrpc_all_services_mutex);
1353 mutex_unlock(&nrs_core.nrs_mutex);
1357 EXPORT_SYMBOL(ptlrpc_nrs_policy_unregister);
1360 * Setup NRS heads on all service partitions of service \a svc, and register
1361 * all compatible policies on those NRS heads.
1363 * To be called from withing ptl
1364 * \param[in] svc the service to setup
1366 * \retval -ve error, the calling logic should eventually call
1367 * ptlrpc_service_nrs_cleanup() to undo any work performed
1370 * \see ptlrpc_register_service()
1371 * \see ptlrpc_service_nrs_cleanup()
1373 int ptlrpc_service_nrs_setup(struct ptlrpc_service *svc)
1375 struct ptlrpc_service_part *svcpt;
1376 const struct ptlrpc_nrs_pol_desc *desc;
1380 mutex_lock(&nrs_core.nrs_mutex);
1383 * Initialize NRS heads on all service CPTs.
1385 ptlrpc_service_for_each_part(svcpt, i, svc) {
1386 rc = nrs_svcpt_setup_locked(svcpt);
1392 * Set up lprocfs interfaces for all supported policies for the
1395 cfs_list_for_each_entry(desc, &nrs_core.nrs_policies, pd_list) {
1396 if (!nrs_policy_compatible(svc, desc))
1399 if (desc->pd_ops->op_lprocfs_init != NULL) {
1400 rc = desc->pd_ops->op_lprocfs_init(svc);
1408 mutex_unlock(&nrs_core.nrs_mutex);
1414 * Unregisters all policies on all service partitions of service \a svc.
1416 * \param[in] svc the PTLRPC service to unregister
1418 void ptlrpc_service_nrs_cleanup(struct ptlrpc_service *svc)
1420 struct ptlrpc_service_part *svcpt;
1421 const struct ptlrpc_nrs_pol_desc *desc;
1424 mutex_lock(&nrs_core.nrs_mutex);
1427 * Clean up NRS heads on all service partitions
1429 ptlrpc_service_for_each_part(svcpt, i, svc)
1430 nrs_svcpt_cleanup_locked(svcpt);
1433 * Clean up lprocfs interfaces for all supported policies for the
1436 cfs_list_for_each_entry(desc, &nrs_core.nrs_policies, pd_list) {
1437 if (!nrs_policy_compatible(svc, desc))
1440 if (desc->pd_ops->op_lprocfs_fini != NULL)
1441 desc->pd_ops->op_lprocfs_fini(svc);
1444 mutex_unlock(&nrs_core.nrs_mutex);
1448 * Obtains NRS head resources for request \a req.
1450 * These could be either on the regular or HP NRS head of \a svcpt; resources
1451 * taken on the regular head can later be swapped for HP head resources by
1452 * ldlm_lock_reorder_req().
1454 * \param[in] svcpt the service partition
1455 * \param[in] req the request
1456 * \param[in] hp which NRS head of \a svcpt to use
1458 void ptlrpc_nrs_req_initialize(struct ptlrpc_service_part *svcpt,
1459 struct ptlrpc_request *req, bool hp)
1461 struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, hp);
1463 memset(&req->rq_nrq, 0, sizeof(req->rq_nrq));
1464 nrs_resource_get_safe(nrs, &req->rq_nrq, req->rq_nrq.nr_res_ptrs,
1468 * It is fine to access \e nr_initialized without locking as there is
1469 * no contention at this early stage.
1471 req->rq_nrq.nr_initialized = 1;
1475 * Releases resources for a request; is called after the request has been
1478 * \param[in] req the request
1480 * \see ptlrpc_server_finish_request()
1482 void ptlrpc_nrs_req_finalize(struct ptlrpc_request *req)
1484 if (req->rq_nrq.nr_initialized) {
1485 nrs_resource_put_safe(req->rq_nrq.nr_res_ptrs);
1486 /* no protection on bit nr_initialized because no
1487 * contention at this late stage */
1488 req->rq_nrq.nr_finalized = 1;
1492 void ptlrpc_nrs_req_stop_nolock(struct ptlrpc_request *req)
1494 if (req->rq_nrq.nr_started)
1495 nrs_request_stop(&req->rq_nrq);
1499 * Enqueues request \a req on either the regular or high-priority NRS head
1500 * of service partition \a svcpt.
1502 * \param[in] svcpt the service partition
1503 * \param[in] req the request to be enqueued
1504 * \param[in] hp whether to enqueue the request on the regular or
1505 * high-priority NRS head.
1507 void ptlrpc_nrs_req_add(struct ptlrpc_service_part *svcpt,
1508 struct ptlrpc_request *req, bool hp)
1510 spin_lock(&svcpt->scp_req_lock);
1513 ptlrpc_nrs_hpreq_add_nolock(req);
1515 ptlrpc_nrs_req_add_nolock(req);
1517 spin_unlock(&svcpt->scp_req_lock);
1520 static void nrs_request_removed(struct ptlrpc_nrs_policy *policy)
1522 LASSERT(policy->pol_nrs->nrs_req_queued > 0);
1523 LASSERT(policy->pol_req_queued > 0);
1525 policy->pol_nrs->nrs_req_queued--;
1526 policy->pol_req_queued--;
1529 * If the policy has no more requests queued, remove it from
1530 * ptlrpc_nrs::nrs_policy_queued.
1532 if (unlikely(policy->pol_req_queued == 0)) {
1533 cfs_list_del_init(&policy->pol_list_queued);
1536 * If there are other policies with queued requests, move the
1537 * current policy to the end so that we can round robin over
1538 * all policies and drain the requests.
1540 } else if (policy->pol_req_queued != policy->pol_nrs->nrs_req_queued) {
1541 LASSERT(policy->pol_req_queued <
1542 policy->pol_nrs->nrs_req_queued);
1544 cfs_list_move_tail(&policy->pol_list_queued,
1545 &policy->pol_nrs->nrs_policy_queued);
1550 * Obtains a request for handling from an NRS head of service partition
1553 * \param[in] svcpt the service partition
1554 * \param[in] hp whether to obtain a request from the regular or
1555 * high-priority NRS head.
1556 * \param[in] peek when set, signifies that we just want to examine the
1557 * request, and not handle it, so the request is not removed
1559 * \param[in] force when set, it will force a policy to return a request if it
1562 * \retval the request to be handled
1563 * \retval NULL the head has no requests to serve
1565 struct ptlrpc_request *
1566 ptlrpc_nrs_req_get_nolock0(struct ptlrpc_service_part *svcpt, bool hp,
1567 bool peek, bool force)
1569 struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, hp);
1570 struct ptlrpc_nrs_policy *policy;
1571 struct ptlrpc_nrs_request *nrq;
1574 * Always try to drain requests from all NRS polices even if they are
1575 * inactive, because the user can change policy status at runtime.
1577 cfs_list_for_each_entry(policy, &nrs->nrs_policy_queued,
1579 nrq = nrs_request_get(policy, peek, force);
1581 if (likely(!peek)) {
1582 nrq->nr_started = 1;
1584 policy->pol_req_started++;
1585 policy->pol_nrs->nrs_req_started++;
1587 nrs_request_removed(policy);
1590 return container_of(nrq, struct ptlrpc_request, rq_nrq);
1598 * Dequeues request \a req from the policy it has been enqueued on.
1600 * \param[in] req the request
1602 void ptlrpc_nrs_req_del_nolock(struct ptlrpc_request *req)
1604 struct ptlrpc_nrs_policy *policy = nrs_request_policy(&req->rq_nrq);
1606 policy->pol_desc->pd_ops->op_req_dequeue(policy, &req->rq_nrq);
1608 req->rq_nrq.nr_enqueued = 0;
1610 nrs_request_removed(policy);
1614 * Returns whether there are any requests currently enqueued on any of the
1615 * policies of service partition's \a svcpt NRS head specified by \a hp. Should
1616 * be called while holding ptlrpc_service_part::scp_req_lock to get a reliable
1619 * \param[in] svcpt the service partition to enquire.
1620 * \param[in] hp whether the regular or high-priority NRS head is to be
1623 * \retval false the indicated NRS head has no enqueued requests.
1624 * \retval true the indicated NRS head has some enqueued requests.
1626 bool ptlrpc_nrs_req_pending_nolock(struct ptlrpc_service_part *svcpt, bool hp)
1628 struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, hp);
1630 return nrs->nrs_req_queued > 0;
1634 * Moves request \a req from the regular to the high-priority NRS head.
1636 * \param[in] req the request to move
1638 void ptlrpc_nrs_req_hp_move(struct ptlrpc_request *req)
1640 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
1641 struct ptlrpc_nrs_request *nrq = &req->rq_nrq;
1642 struct ptlrpc_nrs_resource *res1[NRS_RES_MAX];
1643 struct ptlrpc_nrs_resource *res2[NRS_RES_MAX];
1647 * Obtain the high-priority NRS head resources.
1649 nrs_resource_get_safe(nrs_svcpt2nrs(svcpt, true), nrq, res1, true);
1651 spin_lock(&svcpt->scp_req_lock);
1653 if (!ptlrpc_nrs_req_can_move(req))
1656 ptlrpc_nrs_req_del_nolock(req);
1658 memcpy(res2, nrq->nr_res_ptrs, NRS_RES_MAX * sizeof(res2[0]));
1659 memcpy(nrq->nr_res_ptrs, res1, NRS_RES_MAX * sizeof(res1[0]));
1661 ptlrpc_nrs_hpreq_add_nolock(req);
1663 memcpy(res1, res2, NRS_RES_MAX * sizeof(res1[0]));
1665 spin_unlock(&svcpt->scp_req_lock);
1668 * Release either the regular NRS head resources if we moved the
1669 * request, or the high-priority NRS head resources if we took a
1670 * reference earlier in this function and ptlrpc_nrs_req_can_move()
1673 nrs_resource_put_safe(res1);
1678 * Carries out a control operation \a opc on the policy identified by the
1679 * human-readable \a name, on either all partitions, or only on the first
1680 * partition of service \a svc.
1682 * \param[in] svc the service the policy belongs to.
1683 * \param[in] queue whether to carry out the command on the policy which
1684 * belongs to the regular, high-priority, or both NRS
1685 * heads of service partitions of \a svc.
1686 * \param[in] name the policy to act upon, by human-readable name
1687 * \param[in] opc the opcode of the operation to carry out
1688 * \param[in] single when set, the operation will only be carried out on the
1689 * NRS heads of the first service partition of \a svc.
1690 * This is useful for some policies which e.g. share
1691 * identical values on the same parameters of different
1692 * service partitions; when reading these parameters via
1693 * lprocfs, these policies may just want to obtain and
1694 * print out the values from the first service partition.
1695 * Storing these values centrally elsewhere then could be
1696 * another solution for this.
1697 * \param[in,out] arg can be used as a generic in/out buffer between control
1698 * operations and the user environment.
1700 *\retval -ve error condition
1701 *\retval 0 operation was carried out successfully
1703 int ptlrpc_nrs_policy_control(const struct ptlrpc_service *svc,
1704 enum ptlrpc_nrs_queue_type queue, char *name,
1705 enum ptlrpc_nrs_ctl opc, bool single, void *arg)
1707 struct ptlrpc_service_part *svcpt;
1712 LASSERT(opc != PTLRPC_NRS_CTL_INVALID);
1714 if ((queue & PTLRPC_NRS_QUEUE_BOTH) == 0)
1717 ptlrpc_service_for_each_part(svcpt, i, svc) {
1718 if ((queue & PTLRPC_NRS_QUEUE_REG) != 0) {
1719 rc = nrs_policy_ctl(nrs_svcpt2nrs(svcpt, false), name,
1721 if (rc != 0 || (queue == PTLRPC_NRS_QUEUE_REG &&
1726 if ((queue & PTLRPC_NRS_QUEUE_HP) != 0) {
1728 * XXX: We could optionally check for
1729 * nrs_svc_has_hp(svc) here, and return an error if it
1730 * is false. Right now we rely on the policies' lprocfs
1731 * handlers that call the present function to make this
1732 * check; if they fail to do so, they might hit the
1733 * assertion inside nrs_svcpt2nrs() below.
1735 rc = nrs_policy_ctl(nrs_svcpt2nrs(svcpt, true), name,
1737 if (rc != 0 || single)
1746 /* ptlrpc/nrs_fifo.c */
1747 extern struct ptlrpc_nrs_pol_conf nrs_conf_fifo;
1748 #if defined HAVE_SERVER_SUPPORT && defined(__KERNEL__)
1749 /* ptlrpc/nrs_crr.c */
1750 extern struct ptlrpc_nrs_pol_conf nrs_conf_crrn;
1751 /* ptlrpc/nrs_orr.c */
1752 extern struct ptlrpc_nrs_pol_conf nrs_conf_orr;
1753 extern struct ptlrpc_nrs_pol_conf nrs_conf_trr;
1757 * Adds all policies that ship with the ptlrpc module, to NRS core's list of
1758 * policies \e nrs_core.nrs_policies.
1760 * \retval 0 all policies have been registered successfully
1763 int ptlrpc_nrs_init(void)
1768 mutex_init(&nrs_core.nrs_mutex);
1769 CFS_INIT_LIST_HEAD(&nrs_core.nrs_policies);
1771 rc = ptlrpc_nrs_policy_register(&nrs_conf_fifo);
1775 #if defined HAVE_SERVER_SUPPORT && defined(__KERNEL__)
1776 rc = ptlrpc_nrs_policy_register(&nrs_conf_crrn);
1780 rc = ptlrpc_nrs_policy_register(&nrs_conf_orr);
1784 rc = ptlrpc_nrs_policy_register(&nrs_conf_trr);
1792 * Since no PTLRPC services have been started at this point, all we need
1793 * to do for cleanup is to free the descriptors.
1801 * Removes all policy desciptors from nrs_core::nrs_policies, and frees the
1802 * policy descriptors.
1804 * Since all PTLRPC services are stopped at this point, there are no more
1805 * instances of any policies, because each service will have stopped its policy
1806 * instances in ptlrpc_service_nrs_cleanup(), so we just need to free the
1809 void ptlrpc_nrs_fini(void)
1811 struct ptlrpc_nrs_pol_desc *desc;
1812 struct ptlrpc_nrs_pol_desc *tmp;
1814 cfs_list_for_each_entry_safe(desc, tmp, &nrs_core.nrs_policies,
1816 cfs_list_del_init(&desc->pd_list);