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
43 #include <obd_support.h>
44 #include <obd_class.h>
45 #include <lustre_net.h>
46 #include <lprocfs_status.h>
47 #include <linux/libcfs/libcfs.h>
48 #include "ptlrpc_internal.h"
50 /* XXX: This is just for liblustre. Remove the #if defined directive when the
51 * "cfs_" prefix is dropped from cfs_list_head. */
52 extern struct list_head ptlrpc_all_services;
57 struct nrs_core nrs_core;
59 static int nrs_policy_init(struct ptlrpc_nrs_policy *policy)
61 return policy->pol_desc->pd_ops->op_policy_init != NULL ?
62 policy->pol_desc->pd_ops->op_policy_init(policy) : 0;
65 static void nrs_policy_fini(struct ptlrpc_nrs_policy *policy)
67 LASSERT(policy->pol_ref == 0);
68 LASSERT(policy->pol_req_queued == 0);
70 if (policy->pol_desc->pd_ops->op_policy_fini != NULL)
71 policy->pol_desc->pd_ops->op_policy_fini(policy);
74 static int nrs_policy_ctl_locked(struct ptlrpc_nrs_policy *policy,
75 enum ptlrpc_nrs_ctl opc, void *arg)
78 * The policy may be stopped, but the lprocfs files and
79 * ptlrpc_nrs_policy instances remain present until unregistration time.
80 * Do not perform the ctl operation if the policy is stopped, as
81 * policy->pol_private will be NULL in such a case.
83 if (policy->pol_state == NRS_POL_STATE_STOPPED)
86 RETURN(policy->pol_desc->pd_ops->op_policy_ctl != NULL ?
87 policy->pol_desc->pd_ops->op_policy_ctl(policy, opc, arg) :
91 static void nrs_policy_stop0(struct ptlrpc_nrs_policy *policy)
93 struct ptlrpc_nrs *nrs = policy->pol_nrs;
96 if (policy->pol_desc->pd_ops->op_policy_stop != NULL) {
97 spin_unlock(&nrs->nrs_lock);
99 policy->pol_desc->pd_ops->op_policy_stop(policy);
101 spin_lock(&nrs->nrs_lock);
104 LASSERT(list_empty(&policy->pol_list_queued));
105 LASSERT(policy->pol_req_queued == 0 &&
106 policy->pol_req_started == 0);
108 policy->pol_private = NULL;
110 policy->pol_state = NRS_POL_STATE_STOPPED;
112 if (atomic_dec_and_test(&policy->pol_desc->pd_refs))
113 module_put(policy->pol_desc->pd_owner);
118 static int nrs_policy_stop_locked(struct ptlrpc_nrs_policy *policy)
120 struct ptlrpc_nrs *nrs = policy->pol_nrs;
123 if (nrs->nrs_policy_fallback == policy && !nrs->nrs_stopping)
126 if (policy->pol_state == NRS_POL_STATE_STARTING)
129 /* In progress or already stopped */
130 if (policy->pol_state != NRS_POL_STATE_STARTED)
133 policy->pol_state = NRS_POL_STATE_STOPPING;
135 /* Immediately make it invisible */
136 if (nrs->nrs_policy_primary == policy) {
137 nrs->nrs_policy_primary = NULL;
140 LASSERT(nrs->nrs_policy_fallback == policy);
141 nrs->nrs_policy_fallback = NULL;
144 /* I have the only refcount */
145 if (policy->pol_ref == 1)
146 nrs_policy_stop0(policy);
152 * Transitions the \a nrs NRS head's primary policy to
153 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING and if the policy has no
154 * pending usage references, to ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED.
156 * \param[in] nrs the NRS head to carry out this operation on
158 static void nrs_policy_stop_primary(struct ptlrpc_nrs *nrs)
160 struct ptlrpc_nrs_policy *tmp = nrs->nrs_policy_primary;
165 * XXX: This should really be RETURN_EXIT, but the latter does
166 * not currently print anything out, and possibly should be
173 nrs->nrs_policy_primary = NULL;
175 LASSERT(tmp->pol_state == NRS_POL_STATE_STARTED);
176 tmp->pol_state = NRS_POL_STATE_STOPPING;
178 if (tmp->pol_ref == 0)
179 nrs_policy_stop0(tmp);
184 * Transitions a policy across the ptlrpc_nrs_pol_state range of values, in
185 * response to an lprocfs command to start a policy.
187 * If a primary policy different to the current one is specified, this function
188 * will transition the new policy to the
189 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTING and then to
190 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED, and will then transition
191 * the old primary policy (if there is one) to
192 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING, and if there are no outstanding
193 * references on the policy to ptlrpc_nrs_pol_stae::NRS_POL_STATE_STOPPED.
195 * If the fallback policy is specified, this is taken to indicate an instruction
196 * to stop the current primary policy, without substituting it with another
197 * primary policy, so the primary policy (if any) is transitioned to
198 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING, and if there are no outstanding
199 * references on the policy to ptlrpc_nrs_pol_stae::NRS_POL_STATE_STOPPED. In
200 * this case, the fallback policy is only left active in the NRS head.
202 static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy)
204 struct ptlrpc_nrs *nrs = policy->pol_nrs;
209 * Don't allow multiple starting which is too complex, and has no real
212 if (nrs->nrs_policy_starting)
215 LASSERT(policy->pol_state != NRS_POL_STATE_STARTING);
217 if (policy->pol_state == NRS_POL_STATE_STOPPING)
220 if (policy->pol_flags & PTLRPC_NRS_FL_FALLBACK) {
222 * This is for cases in which the user sets the policy to the
223 * fallback policy (currently fifo for all services); i.e. the
224 * user is resetting the policy to the default; so we stop the
225 * primary policy, if any.
227 if (policy == nrs->nrs_policy_fallback) {
228 nrs_policy_stop_primary(nrs);
233 * If we reach here, we must be setting up the fallback policy
234 * at service startup time, and only a single policy with the
235 * nrs_policy_flags::PTLRPC_NRS_FL_FALLBACK flag set can
236 * register with NRS core.
238 LASSERT(nrs->nrs_policy_fallback == NULL);
241 * Shouldn't start primary policy if w/o fallback policy.
243 if (nrs->nrs_policy_fallback == NULL)
246 if (policy->pol_state == NRS_POL_STATE_STARTED)
251 * Increase the module usage count for policies registering from other
254 if (atomic_inc_return(&policy->pol_desc->pd_refs) == 1 &&
255 !try_module_get(policy->pol_desc->pd_owner)) {
256 atomic_dec(&policy->pol_desc->pd_refs);
257 CERROR("NRS: cannot get module for policy %s; is it alive?\n",
258 policy->pol_desc->pd_name);
263 * Serialize policy starting across the NRS head
265 nrs->nrs_policy_starting = 1;
267 policy->pol_state = NRS_POL_STATE_STARTING;
269 if (policy->pol_desc->pd_ops->op_policy_start) {
270 spin_unlock(&nrs->nrs_lock);
272 rc = policy->pol_desc->pd_ops->op_policy_start(policy);
274 spin_lock(&nrs->nrs_lock);
276 if (atomic_dec_and_test(&policy->pol_desc->pd_refs))
277 module_put(policy->pol_desc->pd_owner);
279 policy->pol_state = NRS_POL_STATE_STOPPED;
284 policy->pol_state = NRS_POL_STATE_STARTED;
286 if (policy->pol_flags & PTLRPC_NRS_FL_FALLBACK) {
288 * This path is only used at PTLRPC service setup time.
290 nrs->nrs_policy_fallback = policy;
293 * Try to stop the current primary policy if there is one.
295 nrs_policy_stop_primary(nrs);
298 * And set the newly-started policy as the primary one.
300 nrs->nrs_policy_primary = policy;
304 nrs->nrs_policy_starting = 0;
310 * Increases the policy's usage reference count.
312 static inline void nrs_policy_get_locked(struct ptlrpc_nrs_policy *policy)
318 * Decreases the policy's usage reference count, and stops the policy in case it
319 * was already stopping and have no more outstanding usage references (which
320 * indicates it has no more queued or started requests, and can be safely
323 static void nrs_policy_put_locked(struct ptlrpc_nrs_policy *policy)
325 LASSERT(policy->pol_ref > 0);
328 if (unlikely(policy->pol_ref == 0 &&
329 policy->pol_state == NRS_POL_STATE_STOPPING))
330 nrs_policy_stop0(policy);
333 static void nrs_policy_put(struct ptlrpc_nrs_policy *policy)
335 spin_lock(&policy->pol_nrs->nrs_lock);
336 nrs_policy_put_locked(policy);
337 spin_unlock(&policy->pol_nrs->nrs_lock);
341 * Find and return a policy by name.
343 static struct ptlrpc_nrs_policy * nrs_policy_find_locked(struct ptlrpc_nrs *nrs,
346 struct ptlrpc_nrs_policy *tmp;
348 list_for_each_entry(tmp, &nrs->nrs_policy_list, pol_list) {
349 if (strncmp(tmp->pol_desc->pd_name, name,
350 NRS_POL_NAME_MAX) == 0) {
351 nrs_policy_get_locked(tmp);
359 * Release references for the resource hierarchy moving upwards towards the
360 * policy instance resource.
362 static void nrs_resource_put(struct ptlrpc_nrs_resource *res)
364 struct ptlrpc_nrs_policy *policy = res->res_policy;
366 if (policy->pol_desc->pd_ops->op_res_put != NULL) {
367 struct ptlrpc_nrs_resource *parent;
369 for (; res != NULL; res = parent) {
370 parent = res->res_parent;
371 policy->pol_desc->pd_ops->op_res_put(policy, res);
377 * Obtains references for each resource in the resource hierarchy for request
378 * \a nrq if it is to be handled by \a policy.
380 * \param[in] policy the policy
381 * \param[in] nrq the request
382 * \param[in] moving_req denotes whether this is a call to the function by
383 * ldlm_lock_reorder_req(), in order to move \a nrq to
384 * the high-priority NRS head; we should not sleep when
387 * \retval NULL resource hierarchy references not obtained
388 * \retval valid-pointer the bottom level of the resource hierarchy
390 * \see ptlrpc_nrs_pol_ops::op_res_get()
393 struct ptlrpc_nrs_resource * nrs_resource_get(struct ptlrpc_nrs_policy *policy,
394 struct ptlrpc_nrs_request *nrq,
398 * Set to NULL to traverse the resource hierarchy from the top.
400 struct ptlrpc_nrs_resource *res = NULL;
401 struct ptlrpc_nrs_resource *tmp = NULL;
405 rc = policy->pol_desc->pd_ops->op_res_get(policy, nrq, res,
409 nrs_resource_put(res);
413 LASSERT(tmp != NULL);
414 tmp->res_parent = res;
415 tmp->res_policy = policy;
419 * Return once we have obtained a reference to the bottom level
420 * of the resource hierarchy.
428 * Obtains resources for the resource hierarchies and policy references for
429 * the fallback and current primary policy (if any), that will later be used
430 * to handle request \a nrq.
432 * \param[in] nrs the NRS head instance that will be handling request \a nrq.
433 * \param[in] nrq the request that is being handled.
434 * \param[out] resp the array where references to the resource hierarchy are
436 * \param[in] moving_req is set when obtaining resources while moving a
437 * request from a policy on the regular NRS head to a
438 * policy on the HP NRS head (via
439 * ldlm_lock_reorder_req()). It signifies that
440 * allocations to get resources should be atomic; for
441 * a full explanation, see comment in
442 * ptlrpc_nrs_pol_ops::op_res_get().
444 static void nrs_resource_get_safe(struct ptlrpc_nrs *nrs,
445 struct ptlrpc_nrs_request *nrq,
446 struct ptlrpc_nrs_resource **resp,
449 struct ptlrpc_nrs_policy *primary = NULL;
450 struct ptlrpc_nrs_policy *fallback = NULL;
452 memset(resp, 0, sizeof(resp[0]) * NRS_RES_MAX);
455 * Obtain policy references.
457 spin_lock(&nrs->nrs_lock);
459 fallback = nrs->nrs_policy_fallback;
460 nrs_policy_get_locked(fallback);
462 primary = nrs->nrs_policy_primary;
464 nrs_policy_get_locked(primary);
466 spin_unlock(&nrs->nrs_lock);
469 * Obtain resource hierarchy references.
471 resp[NRS_RES_FALLBACK] = nrs_resource_get(fallback, nrq, moving_req);
472 LASSERT(resp[NRS_RES_FALLBACK] != NULL);
474 if (primary != NULL) {
475 resp[NRS_RES_PRIMARY] = nrs_resource_get(primary, nrq,
478 * A primary policy may exist which may not wish to serve a
479 * particular request for different reasons; release the
480 * reference on the policy as it will not be used for this
483 if (resp[NRS_RES_PRIMARY] == NULL)
484 nrs_policy_put(primary);
489 * Releases references to resource hierarchies and policies, because they are no
490 * longer required; used when request handling has been completed, or the
491 * request is moving to the high priority NRS head.
493 * \param resp the resource hierarchy that is being released
495 * \see ptlrpcnrs_req_hp_move()
496 * \see ptlrpc_nrs_req_finalize()
498 static void nrs_resource_put_safe(struct ptlrpc_nrs_resource **resp)
500 struct ptlrpc_nrs_policy *pols[NRS_RES_MAX];
501 struct ptlrpc_nrs *nrs = NULL;
504 for (i = 0; i < NRS_RES_MAX; i++) {
505 if (resp[i] != NULL) {
506 pols[i] = resp[i]->res_policy;
507 nrs_resource_put(resp[i]);
514 for (i = 0; i < NRS_RES_MAX; i++) {
519 nrs = pols[i]->pol_nrs;
520 spin_lock(&nrs->nrs_lock);
522 nrs_policy_put_locked(pols[i]);
526 spin_unlock(&nrs->nrs_lock);
530 * Obtains an NRS request from \a policy for handling or examination; the
531 * request should be removed in the 'handling' case.
533 * Calling into this function implies we already know the policy has a request
534 * waiting to be handled.
536 * \param[in] policy the policy from which a request
537 * \param[in] peek when set, signifies that we just want to examine the
538 * request, and not handle it, so the request is not removed
540 * \param[in] force when set, it will force a policy to return a request if it
543 * \retval the NRS request to be handled
546 struct ptlrpc_nrs_request * nrs_request_get(struct ptlrpc_nrs_policy *policy,
547 bool peek, bool force)
549 struct ptlrpc_nrs_request *nrq;
551 LASSERT(policy->pol_req_queued > 0);
553 nrq = policy->pol_desc->pd_ops->op_req_get(policy, peek, force);
555 LASSERT(ergo(nrq != NULL, nrs_request_policy(nrq) == policy));
561 * Enqueues request \a nrq for later handling, via one one the policies for
562 * which resources where earlier obtained via nrs_resource_get_safe(). The
563 * function attempts to enqueue the request first on the primary policy
564 * (if any), since this is the preferred choice.
566 * \param nrq the request being enqueued
568 * \see nrs_resource_get_safe()
570 static inline void nrs_request_enqueue(struct ptlrpc_nrs_request *nrq)
572 struct ptlrpc_nrs_policy *policy;
577 * Try in descending order, because the primary policy (if any) is
578 * the preferred choice.
580 for (i = NRS_RES_MAX - 1; i >= 0; i--) {
581 if (nrq->nr_res_ptrs[i] == NULL)
585 policy = nrq->nr_res_ptrs[i]->res_policy;
587 rc = policy->pol_desc->pd_ops->op_req_enqueue(policy, nrq);
589 policy->pol_nrs->nrs_req_queued++;
590 policy->pol_req_queued++;
595 * Should never get here, as at least the primary policy's
596 * ptlrpc_nrs_pol_ops::op_req_enqueue() implementation should always
603 * Called when a request has been handled
605 * \param[in] nrs the request that has been handled; can be used for
606 * job/resource control.
608 * \see ptlrpc_nrs_req_stop_nolock()
610 static inline void nrs_request_stop(struct ptlrpc_nrs_request *nrq)
612 struct ptlrpc_nrs_policy *policy = nrs_request_policy(nrq);
614 if (policy->pol_desc->pd_ops->op_req_stop)
615 policy->pol_desc->pd_ops->op_req_stop(policy, nrq);
617 LASSERT(policy->pol_nrs->nrs_req_started > 0);
618 LASSERT(policy->pol_req_started > 0);
620 policy->pol_nrs->nrs_req_started--;
621 policy->pol_req_started--;
625 * Handler for operations that can be carried out on policies.
627 * Handles opcodes that are common to all policy types within NRS core, and
628 * passes any unknown opcodes to the policy-specific control function.
630 * \param[in] nrs the NRS head this policy belongs to.
631 * \param[in] name the human-readable policy name; should be the same as
632 * ptlrpc_nrs_pol_desc::pd_name.
633 * \param[in] opc the opcode of the operation being carried out.
634 * \param[in,out] arg can be used to pass information in and out between when
635 * carrying an operation; usually data that is private to
636 * the policy at some level, or generic policy status
639 * \retval -ve error condition
640 * \retval 0 operation was carried out successfully
642 static int nrs_policy_ctl(struct ptlrpc_nrs *nrs, char *name,
643 enum ptlrpc_nrs_ctl opc, void *arg)
645 struct ptlrpc_nrs_policy *policy;
649 spin_lock(&nrs->nrs_lock);
651 policy = nrs_policy_find_locked(nrs, name);
653 GOTO(out, rc = -ENOENT);
657 * Unknown opcode, pass it down to the policy-specific control
658 * function for handling.
661 rc = nrs_policy_ctl_locked(policy, opc, arg);
667 case PTLRPC_NRS_CTL_START:
668 rc = nrs_policy_start_locked(policy);
673 nrs_policy_put_locked(policy);
675 spin_unlock(&nrs->nrs_lock);
681 * Unregisters a policy by name.
683 * \param[in] nrs the NRS head this policy belongs to.
684 * \param[in] name the human-readable policy name; should be the same as
685 * ptlrpc_nrs_pol_desc::pd_name
690 static int nrs_policy_unregister(struct ptlrpc_nrs *nrs, char *name)
692 struct ptlrpc_nrs_policy *policy = NULL;
695 spin_lock(&nrs->nrs_lock);
697 policy = nrs_policy_find_locked(nrs, name);
698 if (policy == NULL) {
699 spin_unlock(&nrs->nrs_lock);
701 CERROR("Can't find NRS policy %s\n", name);
705 if (policy->pol_ref > 1) {
706 CERROR("Policy %s is busy with %d references\n", name,
707 (int)policy->pol_ref);
708 nrs_policy_put_locked(policy);
710 spin_unlock(&nrs->nrs_lock);
714 LASSERT(policy->pol_req_queued == 0);
715 LASSERT(policy->pol_req_started == 0);
717 if (policy->pol_state != NRS_POL_STATE_STOPPED) {
718 nrs_policy_stop_locked(policy);
719 LASSERT(policy->pol_state == NRS_POL_STATE_STOPPED);
722 list_del(&policy->pol_list);
725 nrs_policy_put_locked(policy);
727 spin_unlock(&nrs->nrs_lock);
729 nrs_policy_fini(policy);
731 LASSERT(policy->pol_private == NULL);
732 OBD_FREE_PTR(policy);
738 * Register a policy from \policy descriptor \a desc with NRS head \a nrs.
740 * \param[in] nrs the NRS head on which the policy will be registered.
741 * \param[in] desc the policy descriptor from which the information will be
742 * obtained to register the policy.
747 static int nrs_policy_register(struct ptlrpc_nrs *nrs,
748 struct ptlrpc_nrs_pol_desc *desc)
750 struct ptlrpc_nrs_policy *policy;
751 struct ptlrpc_nrs_policy *tmp;
752 struct ptlrpc_service_part *svcpt = nrs->nrs_svcpt;
756 LASSERT(svcpt != NULL);
757 LASSERT(desc->pd_ops != NULL);
758 LASSERT(desc->pd_ops->op_res_get != NULL);
759 LASSERT(desc->pd_ops->op_req_get != NULL);
760 LASSERT(desc->pd_ops->op_req_enqueue != NULL);
761 LASSERT(desc->pd_ops->op_req_dequeue != NULL);
762 LASSERT(desc->pd_compat != NULL);
764 OBD_CPT_ALLOC_GFP(policy, svcpt->scp_service->srv_cptable,
765 svcpt->scp_cpt, sizeof(*policy), __GFP_IO);
769 policy->pol_nrs = nrs;
770 policy->pol_desc = desc;
771 policy->pol_state = NRS_POL_STATE_STOPPED;
772 policy->pol_flags = desc->pd_flags;
774 INIT_LIST_HEAD(&policy->pol_list);
775 INIT_LIST_HEAD(&policy->pol_list_queued);
777 rc = nrs_policy_init(policy);
779 OBD_FREE_PTR(policy);
783 spin_lock(&nrs->nrs_lock);
785 tmp = nrs_policy_find_locked(nrs, policy->pol_desc->pd_name);
787 CERROR("NRS policy %s has been registered, can't register it "
788 "for %s\n", policy->pol_desc->pd_name,
789 svcpt->scp_service->srv_name);
790 nrs_policy_put_locked(tmp);
792 spin_unlock(&nrs->nrs_lock);
793 nrs_policy_fini(policy);
794 OBD_FREE_PTR(policy);
799 list_add_tail(&policy->pol_list, &nrs->nrs_policy_list);
802 if (policy->pol_flags & PTLRPC_NRS_FL_REG_START)
803 rc = nrs_policy_start_locked(policy);
805 spin_unlock(&nrs->nrs_lock);
808 (void) nrs_policy_unregister(nrs, policy->pol_desc->pd_name);
814 * Enqueue request \a req using one of the policies its resources are referring
817 * \param[in] req the request to enqueue.
819 static void ptlrpc_nrs_req_add_nolock(struct ptlrpc_request *req)
821 struct ptlrpc_nrs_policy *policy;
823 LASSERT(req->rq_nrq.nr_initialized);
824 LASSERT(!req->rq_nrq.nr_enqueued);
826 nrs_request_enqueue(&req->rq_nrq);
827 req->rq_nrq.nr_enqueued = 1;
829 policy = nrs_request_policy(&req->rq_nrq);
831 * Add the policy to the NRS head's list of policies with enqueued
832 * requests, if it has not been added there.
834 if (unlikely(list_empty(&policy->pol_list_queued)))
835 list_add_tail(&policy->pol_list_queued,
836 &policy->pol_nrs->nrs_policy_queued);
840 * Enqueue a request on the high priority NRS head.
842 * \param req the request to enqueue.
844 static void ptlrpc_nrs_hpreq_add_nolock(struct ptlrpc_request *req)
846 int opc = lustre_msg_get_opc(req->rq_reqmsg);
849 spin_lock(&req->rq_lock);
851 ptlrpc_nrs_req_add_nolock(req);
853 DEBUG_REQ(D_NET, req, "high priority req");
854 spin_unlock(&req->rq_lock);
859 * Returns a boolean predicate indicating whether the policy described by
860 * \a desc is adequate for use with service \a svc.
862 * \param[in] svc the service
863 * \param[in] desc the policy descriptor
865 * \retval false the policy is not compatible with the service
866 * \retval true the policy is compatible with the service
868 static inline bool nrs_policy_compatible(const struct ptlrpc_service *svc,
869 const struct ptlrpc_nrs_pol_desc *desc)
871 return desc->pd_compat(svc, desc);
875 * Registers all compatible policies in nrs_core.nrs_policies, for NRS head
878 * \param[in] nrs the NRS head
883 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
885 * \see ptlrpc_service_nrs_setup()
887 static int nrs_register_policies_locked(struct ptlrpc_nrs *nrs)
889 struct ptlrpc_nrs_pol_desc *desc;
890 /* for convenience */
891 struct ptlrpc_service_part *svcpt = nrs->nrs_svcpt;
892 struct ptlrpc_service *svc = svcpt->scp_service;
896 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
898 list_for_each_entry(desc, &nrs_core.nrs_policies, pd_list) {
899 if (nrs_policy_compatible(svc, desc)) {
900 rc = nrs_policy_register(nrs, desc);
902 CERROR("Failed to register NRS policy %s for "
903 "partition %d of service %s: %d\n",
904 desc->pd_name, svcpt->scp_cpt,
907 * Fail registration if any of the policies'
908 * registration fails.
919 * Initializes NRS head \a nrs of service partition \a svcpt, and registers all
920 * compatible policies in NRS core, with the NRS head.
922 * \param[in] nrs the NRS head
923 * \param[in] svcpt the PTLRPC service partition to setup
928 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
930 static int nrs_svcpt_setup_locked0(struct ptlrpc_nrs *nrs,
931 struct ptlrpc_service_part *svcpt)
934 enum ptlrpc_nrs_queue_type queue;
936 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
938 if (nrs == &svcpt->scp_nrs_reg)
939 queue = PTLRPC_NRS_QUEUE_REG;
940 else if (nrs == svcpt->scp_nrs_hp)
941 queue = PTLRPC_NRS_QUEUE_HP;
945 nrs->nrs_svcpt = svcpt;
946 nrs->nrs_queue_type = queue;
947 spin_lock_init(&nrs->nrs_lock);
948 INIT_LIST_HEAD(&nrs->nrs_policy_list);
949 INIT_LIST_HEAD(&nrs->nrs_policy_queued);
951 rc = nrs_register_policies_locked(nrs);
957 * Allocates a regular and optionally a high-priority NRS head (if the service
958 * handles high-priority RPCs), and then registers all available compatible
959 * policies on those NRS heads.
961 * \param[in,out] svcpt the PTLRPC service partition to setup
963 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
965 static int nrs_svcpt_setup_locked(struct ptlrpc_service_part *svcpt)
967 struct ptlrpc_nrs *nrs;
971 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
974 * Initialize the regular NRS head.
976 nrs = nrs_svcpt2nrs(svcpt, false);
977 rc = nrs_svcpt_setup_locked0(nrs, svcpt);
982 * Optionally allocate a high-priority NRS head.
984 if (svcpt->scp_service->srv_ops.so_hpreq_handler == NULL)
987 OBD_CPT_ALLOC_PTR(svcpt->scp_nrs_hp,
988 svcpt->scp_service->srv_cptable,
990 if (svcpt->scp_nrs_hp == NULL)
991 GOTO(out, rc = -ENOMEM);
993 nrs = nrs_svcpt2nrs(svcpt, true);
994 rc = nrs_svcpt_setup_locked0(nrs, svcpt);
1001 * Unregisters all policies on all available NRS heads in a service partition;
1002 * called at PTLRPC service unregistration time.
1004 * \param[in] svcpt the PTLRPC service partition
1006 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
1008 static void nrs_svcpt_cleanup_locked(struct ptlrpc_service_part *svcpt)
1010 struct ptlrpc_nrs *nrs;
1011 struct ptlrpc_nrs_policy *policy;
1012 struct ptlrpc_nrs_policy *tmp;
1017 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
1020 nrs = nrs_svcpt2nrs(svcpt, hp);
1021 nrs->nrs_stopping = 1;
1023 list_for_each_entry_safe(policy, tmp, &nrs->nrs_policy_list,
1025 rc = nrs_policy_unregister(nrs, policy->pol_desc->pd_name);
1030 * If the service partition has an HP NRS head, clean that up as well.
1032 if (!hp && nrs_svcpt_has_hp(svcpt)) {
1044 * Returns the descriptor for a policy as identified by by \a name.
1046 * \param[in] name the policy name
1048 * \retval the policy descriptor
1051 static struct ptlrpc_nrs_pol_desc *nrs_policy_find_desc_locked(const char *name)
1053 struct ptlrpc_nrs_pol_desc *tmp;
1056 list_for_each_entry(tmp, &nrs_core.nrs_policies, pd_list) {
1057 if (strncmp(tmp->pd_name, name, NRS_POL_NAME_MAX) == 0)
1064 * Removes the policy from all supported NRS heads of all partitions of all
1067 * \param[in] desc the policy descriptor to unregister
1070 * \retval 0 successfully unregistered policy on all supported NRS heads
1072 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
1073 * \pre mutex_is_locked(&ptlrpc_all_services_mutex)
1075 static int nrs_policy_unregister_locked(struct ptlrpc_nrs_pol_desc *desc)
1077 struct ptlrpc_nrs *nrs;
1078 struct ptlrpc_service *svc;
1079 struct ptlrpc_service_part *svcpt;
1084 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
1085 LASSERT(mutex_is_locked(&ptlrpc_all_services_mutex));
1087 list_for_each_entry(svc, &ptlrpc_all_services, srv_list) {
1089 if (!nrs_policy_compatible(svc, desc) ||
1090 unlikely(svc->srv_is_stopping))
1093 ptlrpc_service_for_each_part(svcpt, i, svc) {
1097 nrs = nrs_svcpt2nrs(svcpt, hp);
1098 rc = nrs_policy_unregister(nrs, desc->pd_name);
1100 * Ignore -ENOENT as the policy may not have registered
1101 * successfully on all service partitions.
1103 if (rc == -ENOENT) {
1105 } else if (rc != 0) {
1106 CERROR("Failed to unregister NRS policy %s for "
1107 "partition %d of service %s: %d\n",
1108 desc->pd_name, svcpt->scp_cpt,
1109 svcpt->scp_service->srv_name, rc);
1113 if (!hp && nrs_svc_has_hp(svc)) {
1119 if (desc->pd_ops->op_lprocfs_fini != NULL)
1120 desc->pd_ops->op_lprocfs_fini(svc);
1127 * Registers a new policy with NRS core.
1129 * The function will only succeed if policy registration with all compatible
1130 * service partitions (if any) is successful.
1132 * N.B. This function should be called either at ptlrpc module initialization
1133 * time when registering a policy that ships with NRS core, or in a
1134 * module's init() function for policies registering from other modules.
1136 * \param[in] conf configuration information for the new policy to register
1141 int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
1143 struct ptlrpc_service *svc;
1144 struct ptlrpc_nrs_pol_desc *desc;
1148 LASSERT(conf != NULL);
1149 LASSERT(conf->nc_ops != NULL);
1150 LASSERT(conf->nc_compat != NULL);
1151 LASSERT(ergo(conf->nc_compat == nrs_policy_compat_one,
1152 conf->nc_compat_svc_name != NULL));
1153 LASSERT(ergo((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) != 0,
1154 conf->nc_owner != NULL));
1156 conf->nc_name[NRS_POL_NAME_MAX - 1] = '\0';
1159 * External policies are not allowed to start immediately upon
1160 * registration, as there is a relatively higher chance that their
1161 * registration might fail. In such a case, some policy instances may
1162 * already have requests queued wen unregistration needs to happen as
1163 * part o cleanup; since there is currently no way to drain requests
1164 * from a policy unless the service is unregistering, we just disallow
1167 if ((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) &&
1168 (conf->nc_flags & (PTLRPC_NRS_FL_FALLBACK |
1169 PTLRPC_NRS_FL_REG_START))) {
1170 CERROR("NRS: failing to register policy %s. Please check "
1171 "policy flags; external policies cannot act as fallback "
1172 "policies, or be started immediately upon registration "
1173 "without interaction with lprocfs\n", conf->nc_name);
1177 mutex_lock(&nrs_core.nrs_mutex);
1179 if (nrs_policy_find_desc_locked(conf->nc_name) != NULL) {
1180 CERROR("NRS: failing to register policy %s which has already "
1181 "been registered with NRS core!\n",
1183 GOTO(fail, rc = -EEXIST);
1186 OBD_ALLOC_PTR(desc);
1188 GOTO(fail, rc = -ENOMEM);
1190 strncpy(desc->pd_name, conf->nc_name, NRS_POL_NAME_MAX);
1191 desc->pd_ops = conf->nc_ops;
1192 desc->pd_compat = conf->nc_compat;
1193 desc->pd_compat_svc_name = conf->nc_compat_svc_name;
1194 if ((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) != 0)
1195 desc->pd_owner = conf->nc_owner;
1196 desc->pd_flags = conf->nc_flags;
1197 atomic_set(&desc->pd_refs, 0);
1200 * For policies that are held in the same module as NRS (currently
1201 * ptlrpc), do not register the policy with all compatible services,
1202 * as the services will not have started at this point, since we are
1203 * calling from ptlrpc module initialization code. In such cases each
1204 * service will register all compatible policies later, via
1205 * ptlrpc_service_nrs_setup().
1207 if ((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) == 0)
1211 * Register the new policy on all compatible services
1213 mutex_lock(&ptlrpc_all_services_mutex);
1215 list_for_each_entry(svc, &ptlrpc_all_services, srv_list) {
1216 struct ptlrpc_service_part *svcpt;
1220 if (!nrs_policy_compatible(svc, desc) ||
1221 unlikely(svc->srv_is_stopping))
1224 ptlrpc_service_for_each_part(svcpt, i, svc) {
1225 struct ptlrpc_nrs *nrs;
1228 nrs = nrs_svcpt2nrs(svcpt, hp);
1229 rc = nrs_policy_register(nrs, desc);
1231 CERROR("Failed to register NRS policy %s for "
1232 "partition %d of service %s: %d\n",
1233 desc->pd_name, svcpt->scp_cpt,
1234 svcpt->scp_service->srv_name, rc);
1236 rc2 = nrs_policy_unregister_locked(desc);
1238 * Should not fail at this point
1241 mutex_unlock(&ptlrpc_all_services_mutex);
1246 if (!hp && nrs_svc_has_hp(svc)) {
1253 * No need to take a reference to other modules here, as we
1254 * will be calling from the module's init() function.
1256 if (desc->pd_ops->op_lprocfs_init != NULL) {
1257 rc = desc->pd_ops->op_lprocfs_init(svc);
1259 rc2 = nrs_policy_unregister_locked(desc);
1261 * Should not fail at this point
1264 mutex_unlock(&ptlrpc_all_services_mutex);
1271 mutex_unlock(&ptlrpc_all_services_mutex);
1273 list_add_tail(&desc->pd_list, &nrs_core.nrs_policies);
1275 mutex_unlock(&nrs_core.nrs_mutex);
1279 EXPORT_SYMBOL(ptlrpc_nrs_policy_register);
1282 * Unregisters a previously registered policy with NRS core. All instances of
1283 * the policy on all NRS heads of all supported services are removed.
1285 * N.B. This function should only be called from a module's exit() function.
1286 * Although it can be used for policies that ship alongside NRS core, the
1287 * function is primarily intended for policies that register externally,
1288 * from other modules.
1290 * \param[in] conf configuration information for the policy to unregister
1295 int ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_conf *conf)
1297 struct ptlrpc_nrs_pol_desc *desc;
1301 LASSERT(conf != NULL);
1303 if (conf->nc_flags & PTLRPC_NRS_FL_FALLBACK) {
1304 CERROR("Unable to unregister a fallback policy, unless the "
1305 "PTLRPC service is stopping.\n");
1309 conf->nc_name[NRS_POL_NAME_MAX - 1] = '\0';
1311 mutex_lock(&nrs_core.nrs_mutex);
1313 desc = nrs_policy_find_desc_locked(conf->nc_name);
1315 CERROR("Failing to unregister NRS policy %s which has "
1316 "not been registered with NRS core!\n",
1318 GOTO(not_exist, rc = -ENOENT);
1321 mutex_lock(&ptlrpc_all_services_mutex);
1323 rc = nrs_policy_unregister_locked(desc);
1326 CERROR("Please first stop policy %s on all service "
1327 "partitions and then retry to unregister the "
1328 "policy.\n", conf->nc_name);
1332 CDEBUG(D_INFO, "Unregistering policy %s from NRS core.\n",
1335 list_del(&desc->pd_list);
1339 mutex_unlock(&ptlrpc_all_services_mutex);
1342 mutex_unlock(&nrs_core.nrs_mutex);
1346 EXPORT_SYMBOL(ptlrpc_nrs_policy_unregister);
1349 * Setup NRS heads on all service partitions of service \a svc, and register
1350 * all compatible policies on those NRS heads.
1352 * To be called from withing ptl
1353 * \param[in] svc the service to setup
1355 * \retval -ve error, the calling logic should eventually call
1356 * ptlrpc_service_nrs_cleanup() to undo any work performed
1359 * \see ptlrpc_register_service()
1360 * \see ptlrpc_service_nrs_cleanup()
1362 int ptlrpc_service_nrs_setup(struct ptlrpc_service *svc)
1364 struct ptlrpc_service_part *svcpt;
1365 const struct ptlrpc_nrs_pol_desc *desc;
1369 mutex_lock(&nrs_core.nrs_mutex);
1372 * Initialize NRS heads on all service CPTs.
1374 ptlrpc_service_for_each_part(svcpt, i, svc) {
1375 rc = nrs_svcpt_setup_locked(svcpt);
1381 * Set up lprocfs interfaces for all supported policies for the
1384 list_for_each_entry(desc, &nrs_core.nrs_policies, pd_list) {
1385 if (!nrs_policy_compatible(svc, desc))
1388 if (desc->pd_ops->op_lprocfs_init != NULL) {
1389 rc = desc->pd_ops->op_lprocfs_init(svc);
1397 mutex_unlock(&nrs_core.nrs_mutex);
1403 * Unregisters all policies on all service partitions of service \a svc.
1405 * \param[in] svc the PTLRPC service to unregister
1407 void ptlrpc_service_nrs_cleanup(struct ptlrpc_service *svc)
1409 struct ptlrpc_service_part *svcpt;
1410 const struct ptlrpc_nrs_pol_desc *desc;
1413 mutex_lock(&nrs_core.nrs_mutex);
1416 * Clean up NRS heads on all service partitions
1418 ptlrpc_service_for_each_part(svcpt, i, svc)
1419 nrs_svcpt_cleanup_locked(svcpt);
1422 * Clean up lprocfs interfaces for all supported policies for the
1425 list_for_each_entry(desc, &nrs_core.nrs_policies, pd_list) {
1426 if (!nrs_policy_compatible(svc, desc))
1429 if (desc->pd_ops->op_lprocfs_fini != NULL)
1430 desc->pd_ops->op_lprocfs_fini(svc);
1433 mutex_unlock(&nrs_core.nrs_mutex);
1437 * Obtains NRS head resources for request \a req.
1439 * These could be either on the regular or HP NRS head of \a svcpt; resources
1440 * taken on the regular head can later be swapped for HP head resources by
1441 * ldlm_lock_reorder_req().
1443 * \param[in] svcpt the service partition
1444 * \param[in] req the request
1445 * \param[in] hp which NRS head of \a svcpt to use
1447 void ptlrpc_nrs_req_initialize(struct ptlrpc_service_part *svcpt,
1448 struct ptlrpc_request *req, bool hp)
1450 struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, hp);
1452 memset(&req->rq_nrq, 0, sizeof(req->rq_nrq));
1453 nrs_resource_get_safe(nrs, &req->rq_nrq, req->rq_nrq.nr_res_ptrs,
1457 * It is fine to access \e nr_initialized without locking as there is
1458 * no contention at this early stage.
1460 req->rq_nrq.nr_initialized = 1;
1464 * Releases resources for a request; is called after the request has been
1467 * \param[in] req the request
1469 * \see ptlrpc_server_finish_request()
1471 void ptlrpc_nrs_req_finalize(struct ptlrpc_request *req)
1473 if (req->rq_nrq.nr_initialized) {
1474 nrs_resource_put_safe(req->rq_nrq.nr_res_ptrs);
1475 /* no protection on bit nr_initialized because no
1476 * contention at this late stage */
1477 req->rq_nrq.nr_finalized = 1;
1481 void ptlrpc_nrs_req_stop_nolock(struct ptlrpc_request *req)
1483 if (req->rq_nrq.nr_started)
1484 nrs_request_stop(&req->rq_nrq);
1488 * Enqueues request \a req on either the regular or high-priority NRS head
1489 * of service partition \a svcpt.
1491 * \param[in] svcpt the service partition
1492 * \param[in] req the request to be enqueued
1493 * \param[in] hp whether to enqueue the request on the regular or
1494 * high-priority NRS head.
1496 void ptlrpc_nrs_req_add(struct ptlrpc_service_part *svcpt,
1497 struct ptlrpc_request *req, bool hp)
1499 spin_lock(&svcpt->scp_req_lock);
1502 ptlrpc_nrs_hpreq_add_nolock(req);
1504 ptlrpc_nrs_req_add_nolock(req);
1506 spin_unlock(&svcpt->scp_req_lock);
1509 static void nrs_request_removed(struct ptlrpc_nrs_policy *policy)
1511 LASSERT(policy->pol_nrs->nrs_req_queued > 0);
1512 LASSERT(policy->pol_req_queued > 0);
1514 policy->pol_nrs->nrs_req_queued--;
1515 policy->pol_req_queued--;
1518 * If the policy has no more requests queued, remove it from
1519 * ptlrpc_nrs::nrs_policy_queued.
1521 if (unlikely(policy->pol_req_queued == 0)) {
1522 list_del_init(&policy->pol_list_queued);
1525 * If there are other policies with queued requests, move the
1526 * current policy to the end so that we can round robin over
1527 * all policies and drain the requests.
1529 } else if (policy->pol_req_queued != policy->pol_nrs->nrs_req_queued) {
1530 LASSERT(policy->pol_req_queued <
1531 policy->pol_nrs->nrs_req_queued);
1533 list_move_tail(&policy->pol_list_queued,
1534 &policy->pol_nrs->nrs_policy_queued);
1539 * Obtains a request for handling from an NRS head of service partition
1542 * \param[in] svcpt the service partition
1543 * \param[in] hp whether to obtain a request from the regular or
1544 * high-priority NRS head.
1545 * \param[in] peek when set, signifies that we just want to examine the
1546 * request, and not handle it, so the request is not removed
1548 * \param[in] force when set, it will force a policy to return a request if it
1551 * \retval the request to be handled
1552 * \retval NULL the head has no requests to serve
1554 struct ptlrpc_request *
1555 ptlrpc_nrs_req_get_nolock0(struct ptlrpc_service_part *svcpt, bool hp,
1556 bool peek, bool force)
1558 struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, hp);
1559 struct ptlrpc_nrs_policy *policy;
1560 struct ptlrpc_nrs_request *nrq;
1563 * Always try to drain requests from all NRS polices even if they are
1564 * inactive, because the user can change policy status at runtime.
1566 list_for_each_entry(policy, &nrs->nrs_policy_queued,
1568 nrq = nrs_request_get(policy, peek, force);
1570 if (likely(!peek)) {
1571 nrq->nr_started = 1;
1573 policy->pol_req_started++;
1574 policy->pol_nrs->nrs_req_started++;
1576 nrs_request_removed(policy);
1579 return container_of(nrq, struct ptlrpc_request, rq_nrq);
1587 * Dequeues request \a req from the policy it has been enqueued on.
1589 * \param[in] req the request
1591 void ptlrpc_nrs_req_del_nolock(struct ptlrpc_request *req)
1593 struct ptlrpc_nrs_policy *policy = nrs_request_policy(&req->rq_nrq);
1595 policy->pol_desc->pd_ops->op_req_dequeue(policy, &req->rq_nrq);
1597 req->rq_nrq.nr_enqueued = 0;
1599 nrs_request_removed(policy);
1603 * Returns whether there are any requests currently enqueued on any of the
1604 * policies of service partition's \a svcpt NRS head specified by \a hp. Should
1605 * be called while holding ptlrpc_service_part::scp_req_lock to get a reliable
1608 * \param[in] svcpt the service partition to enquire.
1609 * \param[in] hp whether the regular or high-priority NRS head is to be
1612 * \retval false the indicated NRS head has no enqueued requests.
1613 * \retval true the indicated NRS head has some enqueued requests.
1615 bool ptlrpc_nrs_req_pending_nolock(struct ptlrpc_service_part *svcpt, bool hp)
1617 struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, hp);
1619 return nrs->nrs_req_queued > 0;
1623 * Moves request \a req from the regular to the high-priority NRS head.
1625 * \param[in] req the request to move
1627 void ptlrpc_nrs_req_hp_move(struct ptlrpc_request *req)
1629 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
1630 struct ptlrpc_nrs_request *nrq = &req->rq_nrq;
1631 struct ptlrpc_nrs_resource *res1[NRS_RES_MAX];
1632 struct ptlrpc_nrs_resource *res2[NRS_RES_MAX];
1636 * Obtain the high-priority NRS head resources.
1638 nrs_resource_get_safe(nrs_svcpt2nrs(svcpt, true), nrq, res1, true);
1640 spin_lock(&svcpt->scp_req_lock);
1642 if (!ptlrpc_nrs_req_can_move(req))
1645 ptlrpc_nrs_req_del_nolock(req);
1647 memcpy(res2, nrq->nr_res_ptrs, NRS_RES_MAX * sizeof(res2[0]));
1648 memcpy(nrq->nr_res_ptrs, res1, NRS_RES_MAX * sizeof(res1[0]));
1650 ptlrpc_nrs_hpreq_add_nolock(req);
1652 memcpy(res1, res2, NRS_RES_MAX * sizeof(res1[0]));
1654 spin_unlock(&svcpt->scp_req_lock);
1657 * Release either the regular NRS head resources if we moved the
1658 * request, or the high-priority NRS head resources if we took a
1659 * reference earlier in this function and ptlrpc_nrs_req_can_move()
1662 nrs_resource_put_safe(res1);
1667 * Carries out a control operation \a opc on the policy identified by the
1668 * human-readable \a name, on either all partitions, or only on the first
1669 * partition of service \a svc.
1671 * \param[in] svc the service the policy belongs to.
1672 * \param[in] queue whether to carry out the command on the policy which
1673 * belongs to the regular, high-priority, or both NRS
1674 * heads of service partitions of \a svc.
1675 * \param[in] name the policy to act upon, by human-readable name
1676 * \param[in] opc the opcode of the operation to carry out
1677 * \param[in] single when set, the operation will only be carried out on the
1678 * NRS heads of the first service partition of \a svc.
1679 * This is useful for some policies which e.g. share
1680 * identical values on the same parameters of different
1681 * service partitions; when reading these parameters via
1682 * lprocfs, these policies may just want to obtain and
1683 * print out the values from the first service partition.
1684 * Storing these values centrally elsewhere then could be
1685 * another solution for this.
1686 * \param[in,out] arg can be used as a generic in/out buffer between control
1687 * operations and the user environment.
1689 *\retval -ve error condition
1690 *\retval 0 operation was carried out successfully
1692 int ptlrpc_nrs_policy_control(const struct ptlrpc_service *svc,
1693 enum ptlrpc_nrs_queue_type queue, char *name,
1694 enum ptlrpc_nrs_ctl opc, bool single, void *arg)
1696 struct ptlrpc_service_part *svcpt;
1701 LASSERT(opc != PTLRPC_NRS_CTL_INVALID);
1703 if ((queue & PTLRPC_NRS_QUEUE_BOTH) == 0)
1706 ptlrpc_service_for_each_part(svcpt, i, svc) {
1707 if ((queue & PTLRPC_NRS_QUEUE_REG) != 0) {
1708 rc = nrs_policy_ctl(nrs_svcpt2nrs(svcpt, false), name,
1710 if (rc != 0 || (queue == PTLRPC_NRS_QUEUE_REG &&
1715 if ((queue & PTLRPC_NRS_QUEUE_HP) != 0) {
1717 * XXX: We could optionally check for
1718 * nrs_svc_has_hp(svc) here, and return an error if it
1719 * is false. Right now we rely on the policies' lprocfs
1720 * handlers that call the present function to make this
1721 * check; if they fail to do so, they might hit the
1722 * assertion inside nrs_svcpt2nrs() below.
1724 rc = nrs_policy_ctl(nrs_svcpt2nrs(svcpt, true), name,
1726 if (rc != 0 || single)
1735 /* ptlrpc/nrs_fifo.c */
1736 extern struct ptlrpc_nrs_pol_conf nrs_conf_fifo;
1739 * Adds all policies that ship with the ptlrpc module, to NRS core's list of
1740 * policies \e nrs_core.nrs_policies.
1742 * \retval 0 all policies have been registered successfully
1745 int ptlrpc_nrs_init(void)
1750 mutex_init(&nrs_core.nrs_mutex);
1751 INIT_LIST_HEAD(&nrs_core.nrs_policies);
1753 rc = ptlrpc_nrs_policy_register(&nrs_conf_fifo);
1761 * Since no PTLRPC services have been started at this point, all we need
1762 * to do for cleanup is to free the descriptors.
1770 * Removes all policy desciptors from nrs_core::nrs_policies, and frees the
1771 * policy descriptors.
1773 * Since all PTLRPC services are stopped at this point, there are no more
1774 * instances of any policies, because each service will have stopped its policy
1775 * instances in ptlrpc_service_nrs_cleanup(), so we just need to free the
1778 void ptlrpc_nrs_fini(void)
1780 struct ptlrpc_nrs_pol_desc *desc;
1781 struct ptlrpc_nrs_pol_desc *tmp;
1783 list_for_each_entry_safe(desc, tmp, &nrs_core.nrs_policies,
1785 list_del_init(&desc->pd_list);