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;
67 nrs_policy_init(struct ptlrpc_nrs_policy *policy)
69 return policy->pol_ops->op_policy_init != NULL ?
70 policy->pol_ops->op_policy_init(policy) : 0;
74 nrs_policy_fini(struct ptlrpc_nrs_policy *policy)
76 LASSERT(policy->pol_ref == 0);
77 LASSERT(policy->pol_req_queued == 0);
79 if (policy->pol_ops->op_policy_fini != NULL)
80 policy->pol_ops->op_policy_fini(policy);
84 nrs_policy_ctl_locked(struct ptlrpc_nrs_policy *policy, enum ptlrpc_nrs_ctl opc,
87 return policy->pol_ops->op_policy_ctl != NULL ?
88 policy->pol_ops->op_policy_ctl(policy, opc, arg) : -ENOSYS;
92 nrs_policy_stop0(struct ptlrpc_nrs_policy *policy)
94 struct ptlrpc_nrs *nrs = policy->pol_nrs;
97 if (policy->pol_ops->op_policy_stop != NULL) {
98 spin_unlock(&nrs->nrs_lock);
100 policy->pol_ops->op_policy_stop(policy);
102 spin_lock(&nrs->nrs_lock);
105 LASSERT(cfs_list_empty(&policy->pol_list_queued));
106 LASSERT(policy->pol_req_queued == 0 &&
107 policy->pol_req_started == 0);
109 policy->pol_private = NULL;
111 policy->pol_state = NRS_POL_STATE_STOPPED;
116 nrs_policy_stop_locked(struct ptlrpc_nrs_policy *policy)
118 struct ptlrpc_nrs *nrs = policy->pol_nrs;
121 if (nrs->nrs_policy_fallback == policy && !nrs->nrs_stopping)
124 if (policy->pol_state == NRS_POL_STATE_STARTING)
127 /* In progress or already stopped */
128 if (policy->pol_state != NRS_POL_STATE_STARTED)
131 policy->pol_state = NRS_POL_STATE_STOPPING;
133 /* Immediately make it invisible */
134 if (nrs->nrs_policy_primary == policy) {
135 nrs->nrs_policy_primary = NULL;
138 LASSERT(nrs->nrs_policy_fallback == policy);
139 nrs->nrs_policy_fallback = NULL;
142 /* I have the only refcount */
143 if (policy->pol_ref == 1)
144 nrs_policy_stop0(policy);
150 * Transitions the \a nrs NRS head's primary policy to
151 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING and if the policy has no
152 * pending usage references, to ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED.
154 * \param[in] nrs The NRS head to carry out this operation on
157 nrs_policy_stop_primary(struct ptlrpc_nrs *nrs)
159 struct ptlrpc_nrs_policy *tmp = nrs->nrs_policy_primary;
164 * XXX: This should really be RETURN_EXIT, but the latter does
165 * not currently print anything out, and possibly should be
172 nrs->nrs_policy_primary = NULL;
174 LASSERT(tmp->pol_state == NRS_POL_STATE_STARTED);
175 tmp->pol_state = NRS_POL_STATE_STOPPING;
177 if (tmp->pol_ref == 0)
178 nrs_policy_stop0(tmp);
183 * Transitions a policy across the ptlrpc_nrs_pol_state range of values, in
184 * response to an lprocfs command to start a policy.
186 * If a primary policy different to the current one is specified, this function
187 * will transition the new policy to the
188 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTING and then to
189 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED, and will then transition
190 * the old primary policy (if there is one) to
191 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING, and if there are no outstanding
192 * references on the policy to ptlrpc_nrs_pol_stae::NRS_POL_STATE_STOPPED.
194 * If the fallback policy is specified, this is taken to indicate an instruction
195 * to stop the current primary policy, without substituting it with another
196 * primary policy, so the primary policy (if any) is transitioned to
197 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING, and if there are no outstanding
198 * references on the policy to ptlrpc_nrs_pol_stae::NRS_POL_STATE_STOPPED. In
199 * this case, the fallback policy is only left active in the NRS head.
202 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 ||
218 policy->pol_state == NRS_POL_STATE_UNAVAIL)
221 if (policy->pol_flags & PTLRPC_NRS_FL_FALLBACK) {
223 * This is for cases in which the user sets the policy to the
224 * fallback policy (currently fifo for all services); i.e. the
225 * user is resetting the policy to the default; so we stop the
226 * primary policy, if any.
228 if (policy == nrs->nrs_policy_fallback) {
229 nrs_policy_stop_primary(nrs);
235 * If we reach here, we must be setting up the fallback policy
236 * at service startup time, and only a single policy with the
237 * nrs_policy_flags::PTLRPC_NRS_FL_FALLBACK flag set can
238 * register with NRS core.
240 LASSERT(nrs->nrs_policy_fallback == NULL);
243 * Shouldn't start primary policy if w/o fallback policy.
245 if (nrs->nrs_policy_fallback == NULL)
248 if (policy->pol_state == NRS_POL_STATE_STARTED)
253 * Serialize policy starting.across the NRS head
255 nrs->nrs_policy_starting = 1;
257 policy->pol_state = NRS_POL_STATE_STARTING;
259 if (policy->pol_ops->op_policy_start) {
260 spin_unlock(&nrs->nrs_lock);
262 rc = policy->pol_ops->op_policy_start(policy);
264 spin_lock(&nrs->nrs_lock);
266 policy->pol_state = NRS_POL_STATE_STOPPED;
271 policy->pol_state = NRS_POL_STATE_STARTED;
273 if (policy->pol_flags & PTLRPC_NRS_FL_FALLBACK) {
275 * This path is only used at PTLRPC service setup time.
277 nrs->nrs_policy_fallback = policy;
280 * Try to stop the current primary policy if there is one.
282 nrs_policy_stop_primary(nrs);
285 * And set the newly-started policy as the primary one.
287 nrs->nrs_policy_primary = policy;
291 nrs->nrs_policy_starting = 0;
297 * Increases the policy's usage reference count.
300 nrs_policy_get_locked(struct ptlrpc_nrs_policy *policy)
306 * Decreases the policy's usage reference count, and stops the policy in case it
307 * was already stopping and have no more outstanding usage references (which
308 * indicates it has no more queued or started requests, and can be safely
312 nrs_policy_put_locked(struct ptlrpc_nrs_policy *policy)
314 LASSERT(policy->pol_ref > 0);
317 if (unlikely(policy->pol_ref == 0 &&
318 policy->pol_state == NRS_POL_STATE_STOPPING))
319 nrs_policy_stop0(policy);
323 nrs_policy_put(struct ptlrpc_nrs_policy *policy)
325 spin_lock(&policy->pol_nrs->nrs_lock);
326 nrs_policy_put_locked(policy);
327 spin_unlock(&policy->pol_nrs->nrs_lock);
331 * Find and return a policy by name.
333 static struct ptlrpc_nrs_policy *
334 nrs_policy_find_locked(struct ptlrpc_nrs *nrs, char *name)
336 struct ptlrpc_nrs_policy *tmp;
338 cfs_list_for_each_entry(tmp, &(nrs)->nrs_policy_list, pol_list) {
339 if (strncmp(tmp->pol_name, name, NRS_POL_NAME_MAX) == 0) {
340 nrs_policy_get_locked(tmp);
348 * Release references for the resource hierarchy moving upwards towards the
349 * policy instance resource.
352 nrs_resource_put(struct ptlrpc_nrs_resource *res)
354 struct ptlrpc_nrs_policy *policy = res->res_policy;
356 if (policy->pol_ops->op_res_put != NULL) {
357 struct ptlrpc_nrs_resource *parent;
359 for (; res != NULL; res = parent) {
360 parent = res->res_parent;
361 policy->pol_ops->op_res_put(policy, res);
367 * Obtains references for each resource in the resource hierarchy for request
368 * \a nrq if it is to be handled by \a policy.
370 * \param[in] policy The policy
371 * \param[in] nrq The request
372 * \param[in] moving_req Denotes whether this is a call to the function by
373 * ldlm_lock_reorder_req(), in order to move \a nrq to
374 * the high-priority NRS head; we should not sleep when
377 * \retval NULL Resource hierarchy references not obtained
378 * \retval valid-pointer The bottom level of the resource hierarchy
380 * \see ptlrpc_nrs_pol_ops::op_res_get()
382 static struct ptlrpc_nrs_resource *
383 nrs_resource_get(struct ptlrpc_nrs_policy *policy,
384 struct ptlrpc_nrs_request *nrq, bool moving_req)
387 * Set to NULL to traverse the resource hierarchy from the top.
389 struct ptlrpc_nrs_resource *res = NULL;
390 struct ptlrpc_nrs_resource *tmp = NULL;
394 rc = policy->pol_ops->op_res_get(policy, nrq, res, &tmp,
398 nrs_resource_put(res);
402 LASSERT(tmp != NULL);
403 tmp->res_parent = res;
404 tmp->res_policy = policy;
408 * Return once we have obtained a reference to the bottom level
409 * of the resource hierarchy.
417 * Obtains resources for the resource hierarchies and policy references for
418 * the fallback and current primary policy (if any), that will later be used
419 * to handle request \a nrq.
421 * \param[in] nrs The NRS head instance that will be handling request \a nrq.
422 * \param[in] nrq The request that is being handled.
423 * \param[out] resp The array where references to the resource hierarchy are
425 * \param[in] moving_req Is set when obtaining resources while moving a
426 * request from a policy on the regular NRS head to a
427 * policy on the HP NRS head (via
428 * ldlm_lock_reorder_req()). It signifies that
429 * allocations to get resources should be atomic; for
430 * a full explanation, see comment in
431 * ptlrpc_nrs_pol_ops::op_res_get().
434 nrs_resource_get_safe(struct ptlrpc_nrs *nrs, struct ptlrpc_nrs_request *nrq,
435 struct ptlrpc_nrs_resource **resp, bool moving_req)
437 struct ptlrpc_nrs_policy *primary = NULL;
438 struct ptlrpc_nrs_policy *fallback = NULL;
440 memset(resp, 0, sizeof(resp[0]) * NRS_RES_MAX);
443 * Obtain policy references.
445 spin_lock(&nrs->nrs_lock);
447 fallback = nrs->nrs_policy_fallback;
448 nrs_policy_get_locked(fallback);
450 primary = nrs->nrs_policy_primary;
452 nrs_policy_get_locked(primary);
454 spin_unlock(&nrs->nrs_lock);
457 * Obtain resource hierarchy references.
459 resp[NRS_RES_FALLBACK] = nrs_resource_get(fallback, nrq, moving_req);
460 LASSERT(resp[NRS_RES_FALLBACK] != NULL);
462 if (primary != NULL) {
463 resp[NRS_RES_PRIMARY] = nrs_resource_get(primary, nrq,
466 * A primary policy may exist which may not wish to serve a
467 * particular request for different reasons; release the
468 * reference on the policy as it will not be used for this
471 if (resp[NRS_RES_PRIMARY] == NULL)
472 nrs_policy_put(primary);
477 * Releases references to resource hierarchies and policies, because they are no
478 * longer required; used when request handling has been completed, ot the
479 * request is moving to the high priority NRS head.
481 * \param resp The resource hierarchy that is being released
483 * \see ptlrpcnrs_req_hp_move()
484 * \see ptlrpc_nrs_req_finalize()
487 nrs_resource_put_safe(struct ptlrpc_nrs_resource **resp)
489 struct ptlrpc_nrs_policy *pols[NRS_RES_MAX];
490 struct ptlrpc_nrs *nrs = NULL;
493 for (i = 0; i < NRS_RES_MAX; i++) {
494 if (resp[i] != NULL) {
495 pols[i] = resp[i]->res_policy;
496 nrs_resource_put(resp[i]);
503 for (i = 0; i < NRS_RES_MAX; i++) {
508 nrs = pols[i]->pol_nrs;
509 spin_lock(&nrs->nrs_lock);
511 nrs_policy_put_locked(pols[i]);
515 spin_unlock(&nrs->nrs_lock);
519 * Obtains an NRS request from \a policy for handling via polling.
521 * \param[in] policy The policy being polled
522 * \param[in,out] arg Reserved parameter
524 static struct ptlrpc_nrs_request *
525 nrs_request_poll(struct ptlrpc_nrs_policy *policy)
527 struct ptlrpc_nrs_request *nrq;
529 LASSERT(policy->pol_req_queued > 0);
531 nrq = policy->pol_ops->op_req_poll(policy);
533 LASSERT(nrq != NULL);
534 LASSERT(nrs_request_policy(nrq) == policy);
540 * Enqueues request \a nrq for later handling, via one one the policies for
541 * which resources where earlier obtained via nrs_resource_get_safe(). The
542 * function attempts to enqueue the request first on the primary policy
543 * (if any), since this is the preferred choice.
545 * \param nrq The request being enqueued
547 * \see nrs_resource_get_safe()
550 nrs_request_enqueue(struct ptlrpc_nrs_request *nrq)
552 struct ptlrpc_nrs_policy *policy;
557 * Try in descending order, because the primary policy (if any) is
558 * the preferred choice.
560 for (i = NRS_RES_MAX - 1; i >= 0; i--) {
561 if (nrq->nr_res_ptrs[i] == NULL)
565 policy = nrq->nr_res_ptrs[i]->res_policy;
567 rc = policy->pol_ops->op_req_enqueue(policy, nrq);
569 policy->pol_nrs->nrs_req_queued++;
570 policy->pol_req_queued++;
575 * Should never get here, as at least the primary policy's
576 * ptlrpc_nrs_pol_ops::op_req_enqueue() implementation should always
583 * Dequeues request \a nrq from the policy which was used for handling it
585 * \param nrq The request being dequeued
587 * \see ptlrpc_nrs_req_del_nolock()
590 nrs_request_dequeue(struct ptlrpc_nrs_request *nrq)
592 struct ptlrpc_nrs_policy *policy;
594 policy = nrs_request_policy(nrq);
596 policy->pol_ops->op_req_dequeue(policy, nrq);
598 LASSERT(policy->pol_nrs->nrs_req_queued > 0);
599 LASSERT(policy->pol_req_queued > 0);
601 policy->pol_nrs->nrs_req_queued--;
602 policy->pol_req_queued--;
606 * Is called when the request starts being handled, after it has been enqueued,
607 * polled and dequeued.
609 * \param[in] nrs The NRS request that is starting to be handled; can be used
610 * for job/resource control.
612 * \see ptlrpc_nrs_req_start_nolock()
615 nrs_request_start(struct ptlrpc_nrs_request *nrq)
617 struct ptlrpc_nrs_policy *policy = nrs_request_policy(nrq);
619 policy->pol_req_started++;
620 policy->pol_nrs->nrs_req_started++;
621 if (policy->pol_ops->op_req_start)
622 policy->pol_ops->op_req_start(policy, nrq);
626 * Called when a request has been handled
628 * \param[in] nrs The request that has been handled; can be used for
629 * job/resource control.
631 * \see ptlrpc_nrs_req_stop_nolock()
634 nrs_request_stop(struct ptlrpc_nrs_request *nrq)
636 struct ptlrpc_nrs_policy *policy = nrs_request_policy(nrq);
638 if (policy->pol_ops->op_req_stop)
639 policy->pol_ops->op_req_stop(policy, nrq);
641 LASSERT(policy->pol_nrs->nrs_req_started > 0);
642 LASSERT(policy->pol_req_started > 0);
644 policy->pol_nrs->nrs_req_started--;
645 policy->pol_req_started--;
649 * Handler for operations that can be carried out on policies.
651 * Handles opcodes that are common to all policy types within NRS core, and
652 * passes any unknown opcodes to the policy-specific control function.
654 * \param[in] nrs The NRS head this policy belongs to.
655 * \param[in] name The human-readable policy name; should be the same as
656 * ptlrpc_nrs_pol_desc::pd_name.
657 * \param[in] opc The opcode of the operation being carried out.
658 * \param[in,out] arg Can be used to pass information in and out between when
659 * carrying an operation; usually data that is private to
660 * the policy at some level, or generic policy status
663 * \retval -ve error condition
664 * \retval 0 operation was carried out successfully
667 nrs_policy_ctl(struct ptlrpc_nrs *nrs, char *name, enum ptlrpc_nrs_ctl opc,
670 struct ptlrpc_nrs_policy *policy;
673 spin_lock(&nrs->nrs_lock);
675 policy = nrs_policy_find_locked(nrs, name);
677 GOTO(out, rc = -ENOENT);
681 * Unknown opcode, pass it down to the policy-specific control
682 * function for handling.
685 rc = nrs_policy_ctl_locked(policy, opc, arg);
691 case PTLRPC_NRS_CTL_START:
692 rc = nrs_policy_start_locked(policy);
696 * TODO: This may need to be augmented for resource deallocation
697 * used by the policies.
699 case PTLRPC_NRS_CTL_SHRINK:
705 nrs_policy_put_locked(policy);
707 spin_unlock(&nrs->nrs_lock);
713 * Unregisters a policy by name.
715 * \param[in] nrs The NRS head this policy belongs to.
716 * \param[in] name The human-readable policy name; should be the same as
717 * ptlrpc_nrs_pol_desc::pd_name
723 nrs_policy_unregister(struct ptlrpc_nrs *nrs, char *name)
725 struct ptlrpc_nrs_policy *policy = NULL;
728 spin_lock(&nrs->nrs_lock);
730 policy = nrs_policy_find_locked(nrs, name);
731 if (policy == NULL) {
732 spin_unlock(&nrs->nrs_lock);
734 CERROR("Can't find NRS policy %s\n", name);
738 if (policy->pol_ref > 1) {
739 CERROR("Policy %s is busy with %d references\n", name,
740 (int)policy->pol_ref);
741 nrs_policy_put_locked(policy);
743 spin_unlock(&nrs->nrs_lock);
747 LASSERT(policy->pol_req_queued == 0);
748 LASSERT(policy->pol_req_started == 0);
750 if (policy->pol_state != NRS_POL_STATE_STOPPED) {
751 nrs_policy_stop_locked(policy);
752 LASSERT(policy->pol_state == NRS_POL_STATE_STOPPED);
755 cfs_list_del(&policy->pol_list);
758 nrs_policy_put_locked(policy);
760 spin_unlock(&nrs->nrs_lock);
762 nrs_policy_fini(policy);
764 LASSERT(policy->pol_private == NULL);
765 OBD_FREE_PTR(policy);
771 * Register a policy from \policy descriptor \a desc with NRS head \a nrs.
773 * \param[in] nrs The NRS head on which the policy will be registered.
774 * \param[in] desc The policy descriptor from which the information will be
775 * obtained to register the policy.
781 nrs_policy_register(struct ptlrpc_nrs *nrs,
782 struct ptlrpc_nrs_pol_desc *desc)
784 struct ptlrpc_nrs_policy *policy;
785 struct ptlrpc_nrs_policy *tmp;
786 struct ptlrpc_service_part *svcpt = nrs->nrs_svcpt;
790 LASSERT(svcpt != NULL);
791 LASSERT(desc->pd_ops != NULL);
792 LASSERT(desc->pd_ops->op_res_get != NULL);
793 LASSERT(desc->pd_ops->op_req_poll != NULL);
794 LASSERT(desc->pd_ops->op_req_enqueue != NULL);
795 LASSERT(desc->pd_ops->op_req_dequeue != NULL);
796 LASSERT(desc->pd_compat != NULL);
798 OBD_CPT_ALLOC_GFP(policy, svcpt->scp_service->srv_cptable,
799 svcpt->scp_cpt, sizeof(*policy), CFS_ALLOC_IO);
803 policy->pol_nrs = nrs;
804 policy->pol_name = desc->pd_name;
805 policy->pol_ops = desc->pd_ops;
806 policy->pol_state = desc->pd_flags & PTLRPC_NRS_FL_REG_EXTERN ?
807 NRS_POL_STATE_UNAVAIL : NRS_POL_STATE_STOPPED;
808 policy->pol_flags = desc->pd_flags & ~PTLRPC_NRS_FL_REG_EXTERN;
810 CFS_INIT_LIST_HEAD(&policy->pol_list);
811 CFS_INIT_LIST_HEAD(&policy->pol_list_queued);
813 rc = nrs_policy_init(policy);
815 OBD_FREE_PTR(policy);
819 spin_lock(&nrs->nrs_lock);
821 tmp = nrs_policy_find_locked(nrs, policy->pol_name);
823 CERROR("NRS policy %s has been registered, can't register it "
825 policy->pol_name, svcpt->scp_service->srv_name);
826 nrs_policy_put_locked(tmp);
828 spin_unlock(&nrs->nrs_lock);
829 nrs_policy_fini(policy);
830 OBD_FREE_PTR(policy);
835 cfs_list_add_tail(&policy->pol_list, &nrs->nrs_policy_list);
838 if (policy->pol_flags & PTLRPC_NRS_FL_REG_START)
839 rc = nrs_policy_start_locked(policy);
841 spin_unlock(&nrs->nrs_lock);
844 (void) nrs_policy_unregister(nrs, policy->pol_name);
850 * Enqueue request \a req using one of the policies its resources are referring
853 * \param[in] req The request to enqueue.
856 ptlrpc_nrs_req_add_nolock(struct ptlrpc_request *req)
858 struct ptlrpc_nrs_policy *policy;
860 LASSERT(req->rq_nrq.nr_initialized);
861 LASSERT(!req->rq_nrq.nr_enqueued);
863 nrs_request_enqueue(&req->rq_nrq);
864 req->rq_nrq.nr_enqueued = 1;
866 policy = nrs_request_policy(&req->rq_nrq);
868 * Add the policy to the NRS head's list of policies with enqueued
869 * requests, if it has not been added there.
871 if (cfs_list_empty(&policy->pol_list_queued))
872 cfs_list_add_tail(&policy->pol_list_queued,
873 &policy->pol_nrs->nrs_policy_queued);
877 * Enqueue a request on the high priority NRS head.
879 * \param req The request to enqueue.
882 ptlrpc_nrs_hpreq_add_nolock(struct ptlrpc_request *req)
884 int opc = lustre_msg_get_opc(req->rq_reqmsg);
887 spin_lock(&req->rq_lock);
889 ptlrpc_nrs_req_add_nolock(req);
891 DEBUG_REQ(D_NET, req, "high priority req");
892 spin_unlock(&req->rq_lock);
896 /* ptlrpc/nrs_fifo.c */
897 extern struct ptlrpc_nrs_pol_desc ptlrpc_nrs_fifo_desc;
900 * Array of policies that ship alongside NRS core; i.e. ones that do not
901 * register externally using ptlrpc_nrs_policy_register().
903 static struct ptlrpc_nrs_pol_desc *nrs_pols_builtin[] = {
904 &ptlrpc_nrs_fifo_desc,
908 * Returns a boolean predicate indicating whether the policy described by
909 * \a desc is adequate for use with service \a svc.
911 * \param[in] nrs The service
912 * \param[in] desc The policy descriptor
914 * \retval false The policy is not compatible with the service partition
915 * \retval true The policy is compatible with the service partition
918 nrs_policy_compatible(struct ptlrpc_service *svc,
919 const struct ptlrpc_nrs_pol_desc *desc)
921 return desc->pd_compat(svc, desc);
925 * Registers all compatible policies in nrs_core.nrs_policies, for NRS head
928 * \param[in] nrs The NRS head
933 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
935 * \see ptlrpc_service_nrs_setup()
938 nrs_register_policies_locked(struct ptlrpc_nrs *nrs)
940 struct ptlrpc_nrs_pol_desc *desc;
941 /* For convenience */
942 struct ptlrpc_service_part *svcpt = nrs->nrs_svcpt;
943 struct ptlrpc_service *svc = svcpt->scp_service;
947 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
949 cfs_list_for_each_entry(desc, &nrs_core.nrs_policies, pd_list) {
950 if (nrs_policy_compatible(svc, desc)) {
951 rc = nrs_policy_register(nrs, desc);
953 CERROR("Failed to register NRS policy %s for "
954 "partition %d of service %s: %d\n",
955 desc->pd_name, svcpt->scp_cpt,
958 * Fail registration if any of the policies'
959 * registration fails.
970 * Initializes NRS head \a nrs of service partition \a svcpt, and registers all
971 * compatible policies in NRS core, with the NRS head.
973 * \param[in] nrs The NRS head
974 * \param[in] svcpt The PTLRPC service partition to setup
976 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
979 nrs_svcpt_setup_locked0(struct ptlrpc_nrs *nrs,
980 struct ptlrpc_service_part *svcpt)
983 enum ptlrpc_nrs_queue_type queue;
985 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
987 if (nrs == &svcpt->scp_nrs_reg)
988 queue = PTLRPC_NRS_QUEUE_REG;
989 else if (nrs == svcpt->scp_nrs_hp)
990 queue = PTLRPC_NRS_QUEUE_HP;
994 nrs->nrs_svcpt = svcpt;
995 nrs->nrs_queue_type = queue;
996 spin_lock_init(&nrs->nrs_lock);
997 CFS_INIT_LIST_HEAD(&nrs->nrs_heads);
998 CFS_INIT_LIST_HEAD(&nrs->nrs_policy_list);
999 CFS_INIT_LIST_HEAD(&nrs->nrs_policy_queued);
1001 cfs_list_add_tail(&nrs->nrs_heads, &nrs_core.nrs_heads);
1003 rc = nrs_register_policies_locked(nrs);
1009 * Allocates a regular and optionally a high-priority NRS head (if the service
1010 * handles high-priority RPCs), and then registers all available compatible
1011 * policies on those NRS heads.
1013 * \param[n] svcpt The PTLRPC service partition to setup
1015 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
1018 nrs_svcpt_setup_locked(struct ptlrpc_service_part *svcpt)
1020 struct ptlrpc_nrs *nrs;
1024 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
1027 * Initialize the regular NRS head.
1029 nrs = nrs_svcpt2nrs(svcpt, false);
1030 rc = nrs_svcpt_setup_locked0(nrs, svcpt);
1035 * Optionally allocate a high-priority NRS head.
1037 if (svcpt->scp_service->srv_ops.so_hpreq_handler == NULL)
1040 OBD_CPT_ALLOC_PTR(svcpt->scp_nrs_hp,
1041 svcpt->scp_service->srv_cptable,
1043 if (svcpt->scp_nrs_hp == NULL)
1044 GOTO(out, rc = -ENOMEM);
1046 nrs = nrs_svcpt2nrs(svcpt, true);
1047 rc = nrs_svcpt_setup_locked0(nrs, svcpt);
1054 * Unregisters all policies on all available NRS heads in a service partition;
1055 * called at PTLRPC service unregistration time.
1057 * \param[in] svcpt The PTLRPC service partition
1059 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
1062 nrs_svcpt_cleanup_locked(struct ptlrpc_service_part *svcpt)
1064 struct ptlrpc_nrs *nrs;
1065 struct ptlrpc_nrs_policy *policy;
1066 struct ptlrpc_nrs_policy *tmp;
1071 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
1074 nrs = nrs_svcpt2nrs(svcpt, hp);
1075 nrs->nrs_stopping = 1;
1077 cfs_list_for_each_entry_safe(policy, tmp, &nrs->nrs_policy_list,
1079 rc = nrs_policy_unregister(nrs, policy->pol_name);
1083 cfs_list_del(&nrs->nrs_heads);
1086 * If the service partition has an HP NRS head, clean that up as well.
1088 if (!hp && nrs_svcpt_has_hp(svcpt)) {
1100 * Checks whether the policy in \a desc has been added to NRS core's list of
1101 * policies, \e nrs_core.nrs_policies.
1103 * \param[in] desc The policy descriptor
1105 * \retval true The policy is present
1106 * \retval false The policy is not present
1109 nrs_policy_exists_locked(const struct ptlrpc_nrs_pol_desc *desc)
1111 struct ptlrpc_nrs_pol_desc *tmp;
1114 cfs_list_for_each_entry(tmp, &nrs_core.nrs_policies, pd_list) {
1115 if (strncmp(tmp->pd_name, desc->pd_name, NRS_POL_NAME_MAX) == 0)
1122 * Removes the policy from all supported NRS heads.
1124 * \param[in] desc The policy descriptor to unregister
1127 * \retval 0 successfully unregistered policy on all supported NRS heads
1129 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
1132 nrs_policy_unregister_locked(struct ptlrpc_nrs_pol_desc *desc)
1134 struct ptlrpc_nrs *nrs;
1138 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
1140 cfs_list_for_each_entry(nrs, &nrs_core.nrs_heads, nrs_heads) {
1141 if (!nrs_policy_compatible(nrs->nrs_svcpt->scp_service, desc)) {
1143 * The policy may only have registered on compatible
1149 rc = nrs_policy_unregister(nrs, desc->pd_name);
1152 * Ignore -ENOENT as the policy may not have registered
1153 * successfully on all service partitions.
1155 if (rc == -ENOENT) {
1157 } else if (rc != 0) {
1158 CERROR("Failed to unregister NRS policy %s for "
1159 "partition %d of service %s: %d\n",
1160 desc->pd_name, nrs->nrs_svcpt->scp_cpt,
1161 nrs->nrs_svcpt->scp_service->srv_name, rc);
1169 * Transitions a policy from ptlrpc_nrs_pol_state::NRS_POL_STATE_UNAVAIL to
1170 * ptlrpc_nrs_pol_state::STOPPED; is used to prevent policies that are
1171 * registering externally using ptlrpc_nrs_policy_register from starting
1172 * before they have successfully registered on all compatible service
1175 * \param[in] nrs The NRS head that the policy belongs to
1176 * \param[in] name The human-readable policy name
1179 nrs_pol_make_available0(struct ptlrpc_nrs *nrs, char *name)
1181 struct ptlrpc_nrs_policy *pol;
1186 spin_lock(&nrs->nrs_lock);
1187 pol = nrs_policy_find_locked(nrs, name);
1189 LASSERT(pol->pol_state == NRS_POL_STATE_UNAVAIL);
1190 pol->pol_state = NRS_POL_STATE_STOPPED;
1191 nrs_policy_put_locked(pol);
1193 spin_unlock(&nrs->nrs_lock);
1197 * Make the policy available on all compatible service partitions of all PTLRPC
1200 * \param[in] desc The descriptor for the policy that is to be made available
1202 * \pre mutex_is_locked(&nrs_core.nrs_mutex)
1204 * \see nrs_pol_make_available0()
1207 nrs_pol_make_available_locked(struct ptlrpc_nrs_pol_desc *desc)
1209 struct ptlrpc_nrs *nrs;
1212 LASSERT(mutex_is_locked(&nrs_core.nrs_mutex));
1215 * Cycle through all registered instances of the policy and place them
1216 * at the STOPPED state.
1218 cfs_list_for_each_entry(nrs, &nrs_core.nrs_heads, nrs_heads) {
1219 if (!nrs_policy_compatible(nrs->nrs_svcpt->scp_service, desc))
1221 nrs_pol_make_available0(nrs, desc->pd_name);
1227 * Registers a new policy with NRS core.
1229 * Used for policies that register externally with NRS core, i.e. ones that are
1230 * not part of \e nrs_pols_builtin[]. The function will only succeed if policy
1231 * registration with all compatible service partitions is successful.
1233 * \param[in] desc The policy descriptor to register
1239 ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_desc *desc)
1241 struct ptlrpc_nrs *nrs;
1242 struct ptlrpc_service *svc;
1243 struct ptlrpc_service_part *svcpt;
1249 LASSERT(desc != NULL);
1251 desc->pd_name[NRS_POL_NAME_MAX - 1] = '\0';
1253 if (desc->pd_flags & (PTLRPC_NRS_FL_FALLBACK |
1254 PTLRPC_NRS_FL_REG_START)) {
1255 CERROR("Failing to register NRS policy %s; re-check policy "
1256 "flags, externally-registered policies cannot act as "
1257 "fallback policies or be started immediately without "
1258 "interaction with lprocfs.\n", desc->pd_name);
1262 desc->pd_flags |= PTLRPC_NRS_FL_REG_EXTERN;
1264 mutex_lock(&nrs_core.nrs_mutex);
1266 rc = nrs_policy_exists_locked(desc);
1268 CERROR("Failing to register NRS policy %s which has "
1269 "already been registered with NRS core!\n",
1271 GOTO(fail, rc = -EEXIST);
1275 * Register the new policy on all compatible services
1277 mutex_lock(&ptlrpc_all_services_mutex);
1279 cfs_list_for_each_entry(svc, &ptlrpc_all_services, srv_list) {
1281 if (unlikely(svc->srv_is_stopping)) {
1282 mutex_unlock(&ptlrpc_all_services_mutex);
1283 GOTO(fail, rc = -ESRCH);
1286 if (!nrs_policy_compatible(svc, desc)) {
1288 * Attempt to register the policy if it is
1289 * compatible, otherwise try the next service.
1293 ptlrpc_service_for_each_part(svcpt, i, svc) {
1297 nrs = nrs_svcpt2nrs(svcpt, hp);
1298 rc = nrs_policy_register(nrs, desc);
1300 CERROR("Failed to register NRS policy %s for "
1301 "partition %d of service %s: %d\n",
1302 desc->pd_name, nrs->nrs_svcpt->scp_cpt,
1303 nrs->nrs_svcpt->scp_service->srv_name,
1306 rc2 = nrs_policy_unregister_locked(desc);
1308 * Should not fail at this point
1311 mutex_unlock(&ptlrpc_all_services_mutex);
1315 if (!hp && nrs_svc_has_hp(svc)) {
1320 if (desc->pd_ops->op_lprocfs_init != NULL) {
1321 rc = desc->pd_ops->op_lprocfs_init(svc);
1323 rc2 = nrs_policy_unregister_locked(desc);
1325 * Should not fail at this point
1328 mutex_unlock(&ptlrpc_all_services_mutex);
1334 mutex_unlock(&ptlrpc_all_services_mutex);
1337 * The policy has successfully registered with all service partitions,
1338 * so mark the policy instances at the NRS heads as available.
1340 nrs_pol_make_available_locked(desc);
1342 cfs_list_add_tail(&desc->pd_list, &nrs_core.nrs_policies);
1344 mutex_unlock(&nrs_core.nrs_mutex);
1348 EXPORT_SYMBOL(ptlrpc_nrs_policy_register);
1351 * Unregisters a previously registered policy with NRS core. All instances of
1352 * the policy on all NRS heads of all supported services are removed.
1354 * \param[in] desc The descriptor of the policy to unregister
1360 ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_desc *desc)
1363 struct ptlrpc_service *svc;
1366 LASSERT(desc != NULL);
1368 if (desc->pd_flags & PTLRPC_NRS_FL_FALLBACK) {
1369 CERROR("Unable to unregister a fallback policy, unless the "
1370 "PTLRPC service is stopping.\n");
1374 desc->pd_name[NRS_POL_NAME_MAX - 1] = '\0';
1376 mutex_lock(&nrs_core.nrs_mutex);
1378 rc = nrs_policy_exists_locked(desc);
1380 CERROR("Failing to unregister NRS policy %s which has "
1381 "not been registered with NRS core!\n",
1383 GOTO(fail, rc = -ENOENT);
1386 rc = nrs_policy_unregister_locked(desc);
1388 CERROR("Please first stop policy %s on all service partitions "
1389 "and then retry to unregister the policy.\n",
1393 CDEBUG(D_INFO, "Unregistering policy %s from NRS core.\n",
1396 cfs_list_del(&desc->pd_list);
1399 * Unregister the policy's lprocfs interface from all compatible
1402 mutex_lock(&ptlrpc_all_services_mutex);
1404 cfs_list_for_each_entry(svc, &ptlrpc_all_services, srv_list) {
1405 if (!nrs_policy_compatible(svc, desc))
1408 if (desc->pd_ops->op_lprocfs_fini != NULL)
1409 desc->pd_ops->op_lprocfs_fini(svc);
1412 mutex_unlock(&ptlrpc_all_services_mutex);
1415 mutex_unlock(&nrs_core.nrs_mutex);
1419 EXPORT_SYMBOL(ptlrpc_nrs_policy_unregister);
1422 * Setup NRS heads on all service partitions of service \a svc, and register
1423 * all compatible policies on those NRS heads.
1425 * \param[in] svc The service to setup
1427 * \retval -ve error, the calling logic should eventually call
1428 * ptlrpc_service_nrs_cleanup() to undo any work performed
1431 * \see ptlrpc_register_service()
1432 * \see ptlrpc_service_nrs_cleanup()
1435 ptlrpc_service_nrs_setup(struct ptlrpc_service *svc)
1437 struct ptlrpc_service_part *svcpt;
1438 const struct ptlrpc_nrs_pol_desc *desc;
1442 mutex_lock(&nrs_core.nrs_mutex);
1445 * Initialize NRS heads on all service CPTs.
1447 ptlrpc_service_for_each_part(svcpt, i, svc) {
1448 rc = nrs_svcpt_setup_locked(svcpt);
1454 * Set up lprocfs interfaces for all supported policies for the
1457 cfs_list_for_each_entry(desc, &nrs_core.nrs_policies, pd_list) {
1458 if (!nrs_policy_compatible(svc, desc))
1461 if (desc->pd_ops->op_lprocfs_init != NULL) {
1462 rc = desc->pd_ops->op_lprocfs_init(svc);
1470 mutex_unlock(&nrs_core.nrs_mutex);
1476 * Unregisters all policies on all service partitions of service \a svc.
1478 * \param[in] svc The PTLRPC service to unregister
1481 ptlrpc_service_nrs_cleanup(struct ptlrpc_service *svc)
1483 struct ptlrpc_service_part *svcpt;
1484 const struct ptlrpc_nrs_pol_desc *desc;
1487 mutex_lock(&nrs_core.nrs_mutex);
1490 * Clean up NRS heads on all service partitions
1492 ptlrpc_service_for_each_part(svcpt, i, svc)
1493 nrs_svcpt_cleanup_locked(svcpt);
1496 * Clean up lprocfs interfaces for all supported policies for the
1499 cfs_list_for_each_entry(desc, &nrs_core.nrs_policies, pd_list) {
1500 if (!nrs_policy_compatible(svc, desc))
1503 if (desc->pd_ops->op_lprocfs_fini != NULL)
1504 desc->pd_ops->op_lprocfs_fini(svc);
1507 mutex_unlock(&nrs_core.nrs_mutex);
1511 * Obtains NRS head resources for request \a req.
1513 * These could be either on the regular or HP NRS head of \a svcpt; resources
1514 * taken on the regular head can later be swapped for HP head resources by
1515 * ldlm_lock_reorder_req().
1517 * \param[in] svcpt The service partition
1518 * \param[in] req The request
1519 * \param[in] hp Which NRS head of \a svcpt to use
1522 ptlrpc_nrs_req_initialize(struct ptlrpc_service_part *svcpt,
1523 struct ptlrpc_request *req, bool hp)
1525 struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, hp);
1527 memset(&req->rq_nrq, 0, sizeof(req->rq_nrq));
1528 nrs_resource_get_safe(nrs, &req->rq_nrq, req->rq_nrq.nr_res_ptrs,
1532 * It is fine to access \e nr_initialized without locking as there is
1533 * no contention at this early stage.
1535 req->rq_nrq.nr_initialized = 1;
1539 * Releases resources for a request; is called after the request has been
1542 * \param[in] req The request
1544 * \see ptlrpc_server_finish_request()
1547 ptlrpc_nrs_req_finalize(struct ptlrpc_request *req)
1549 if (req->rq_nrq.nr_initialized) {
1550 nrs_resource_put_safe(req->rq_nrq.nr_res_ptrs);
1551 /* no protection on bit nr_initialized because no
1552 * contention at this late stage */
1553 req->rq_nrq.nr_finalized = 1;
1558 ptlrpc_nrs_req_start_nolock(struct ptlrpc_request *req)
1560 req->rq_nrq.nr_started = 1;
1561 nrs_request_start(&req->rq_nrq);
1565 ptlrpc_nrs_req_stop_nolock(struct ptlrpc_request *req)
1567 if (req->rq_nrq.nr_started)
1568 nrs_request_stop(&req->rq_nrq);
1572 * Enqueues request \a req on either the regular or high-priority NRS head
1573 * of service partition \a svcpt.
1575 * \param[in] svcpt The service partition
1576 * \param[in] req The request to be enqueued
1577 * \param[in] hp Whether to enqueue the request on the regular or
1578 * high-priority NRS head.
1581 ptlrpc_nrs_req_add(struct ptlrpc_service_part *svcpt,
1582 struct ptlrpc_request *req, bool hp)
1584 spin_lock(&svcpt->scp_req_lock);
1587 ptlrpc_nrs_hpreq_add_nolock(req);
1589 ptlrpc_nrs_req_add_nolock(req);
1591 spin_unlock(&svcpt->scp_req_lock);
1595 * Obtains a request for handling from an NRS head of service partition
1598 * \param[in] svcpt The service partition
1599 * \param[in] hp Whether to obtain a request from the regular or
1600 * high-priority NRS head.
1602 * \retval the request to be handled
1603 * \retval NULL on failure
1605 struct ptlrpc_request *
1606 ptlrpc_nrs_req_poll_nolock(struct ptlrpc_service_part *svcpt, bool hp)
1608 struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, hp);
1609 struct ptlrpc_nrs_policy *policy;
1610 struct ptlrpc_nrs_request *nrq;
1612 if (unlikely(nrs->nrs_req_queued == 0))
1616 * Always try to drain requests from all NRS polices even if they are
1617 * inactive, because the user can change policy status at runtime.
1619 cfs_list_for_each_entry(policy, &(nrs)->nrs_policy_queued,
1621 nrq = nrs_request_poll(policy);
1622 if (likely(nrq != NULL))
1623 return container_of(nrq, struct ptlrpc_request, rq_nrq);
1630 * Dequeues a request that was previously obtained via ptlrpc_nrs_req_poll() and
1631 * is about to be handled.
1633 * \param[in] req The request
1636 ptlrpc_nrs_req_del_nolock(struct ptlrpc_request *req)
1638 struct ptlrpc_nrs_policy *policy;
1640 LASSERT(req->rq_nrq.nr_enqueued);
1641 LASSERT(!req->rq_nrq.nr_dequeued);
1643 policy = nrs_request_policy(&req->rq_nrq);
1644 nrs_request_dequeue(&req->rq_nrq);
1645 req->rq_nrq.nr_dequeued = 1;
1648 * If the policy has no more requests queued, remove it from
1649 * ptlrpc_nrs::nrs_policy_queued.
1651 if (policy->pol_req_queued == 0) {
1652 cfs_list_del_init(&policy->pol_list_queued);
1655 * If there are other policies with queued requests, move the
1656 * current policy to the end so that we can round robin over
1657 * all policies and drain the requests.
1659 } else if (policy->pol_req_queued != policy->pol_nrs->nrs_req_queued) {
1660 LASSERT(policy->pol_req_queued <
1661 policy->pol_nrs->nrs_req_queued);
1663 cfs_list_move_tail(&policy->pol_list_queued,
1664 &policy->pol_nrs->nrs_policy_queued);
1669 * Returns whether there are any requests currently enqueued on any of the
1670 * policies of service partition's \a svcpt NRS head specified by \a hp. Should
1671 * be called while holding ptlrpc_service_part::scp_req_lock to get a reliable
1674 * \param[in] svcpt The service partition to enquire.
1675 * \param[in] hp Whether the regular or high-priority NRS head is to be
1678 * \retval false The indicated NRS head has no enqueued requests.
1679 * \retval true The indicated NRS head has some enqueued requests.
1682 ptlrpc_nrs_req_pending_nolock(struct ptlrpc_service_part *svcpt, bool hp)
1684 struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, hp);
1686 return nrs->nrs_req_queued > 0;
1690 * Moves request \a req from the regular to the high-priority NRS head.
1692 * \param[in] req The request to move
1695 ptlrpc_nrs_req_hp_move(struct ptlrpc_request *req)
1697 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
1698 struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, true);
1699 struct ptlrpc_nrs_request *nrq = &req->rq_nrq;
1700 struct ptlrpc_nrs_resource *res1[NRS_RES_MAX];
1701 struct ptlrpc_nrs_resource *res2[NRS_RES_MAX];
1705 * Obtain the high-priority NRS head resources.
1706 * XXX: Maybe want to remove nrs_resource[get|put]_safe() dance
1707 * when request cannot actually move; move this further down?
1709 nrs_resource_get_safe(nrs, nrq, res1, true);
1711 spin_lock(&svcpt->scp_req_lock);
1713 if (!ptlrpc_nrs_req_can_move(req))
1716 ptlrpc_nrs_req_del_nolock(req);
1717 nrq->nr_enqueued = nrq->nr_dequeued = 0;
1719 memcpy(res2, nrq->nr_res_ptrs, NRS_RES_MAX * sizeof(res2[0]));
1720 memcpy(nrq->nr_res_ptrs, res1, NRS_RES_MAX * sizeof(res1[0]));
1722 ptlrpc_nrs_hpreq_add_nolock(req);
1724 memcpy(res1, res2, NRS_RES_MAX * sizeof(res1[0]));
1726 spin_unlock(&svcpt->scp_req_lock);
1729 * Release either the regular NRS head resources if we moved the
1730 * request, or the high-priority NRS head resources if we took a
1731 * reference earlier in this function and ptlrpc_nrs_req_can_move()
1734 nrs_resource_put_safe(res1);
1739 * Carries out a control operation \a opc on the policy identified by the
1740 * human-readable \a name, on either all partitions, or only on the first
1741 * partition of service \a svc.
1743 * \param[in] svc The service the policy belongs to.
1744 * \param[in] queue Whether to carry out the command on the policy which
1745 * belongs to the regular, high-priority, or both NRS
1746 * heads of service partitions of \a svc.
1747 * \param[in] name The policy to act upon, by human-readable name
1748 * \param[in] opc The opcode of the operation to carry out
1749 * \param[in] single When set, the operation will only be carried out on the
1750 * NRS heads of the first service partition of \a svc.
1751 * This is useful for some policies which e.g. share
1752 * identical values on the same parameters of different
1753 * service partitions; when reading these parameters via
1754 * lprocfs, these policies may just want to obtain and
1755 * print out the values from the first service partition.
1756 * Storing these values centrally elsewhere then could be
1757 * another solution for this.
1758 * \param[in,out] arg Can be used as a generic in/out buffer between control
1759 * operations and the user environment.
1761 *\retval -ve error condition
1762 *\retval 0 operation was carried out successfully
1765 ptlrpc_nrs_policy_control(struct ptlrpc_service *svc,
1766 enum ptlrpc_nrs_queue_type queue, char *name,
1767 enum ptlrpc_nrs_ctl opc, bool single, void *arg)
1769 struct ptlrpc_service_part *svcpt;
1774 ptlrpc_service_for_each_part(svcpt, i, svc) {
1779 case PTLRPC_NRS_QUEUE_BOTH:
1780 case PTLRPC_NRS_QUEUE_REG:
1781 rc = nrs_policy_ctl(nrs_svcpt2nrs(svcpt, false), name,
1783 if (rc != 0 || (queue == PTLRPC_NRS_QUEUE_REG &&
1787 if (queue == PTLRPC_NRS_QUEUE_REG)
1792 case PTLRPC_NRS_QUEUE_HP:
1794 * XXX: We could optionally check for
1795 * nrs_svc_has_hp(svc) here, and return an error if it
1796 * is false. Right now we rely on the policies' lprocfs
1797 * handlers that call the present function to make this
1798 * check; if they fail to do so, they might hit the
1799 * assertion inside nrs_svcpt2nrs() below.
1801 rc = nrs_policy_ctl(nrs_svcpt2nrs(svcpt, true), name,
1803 if (rc != 0 || single)
1814 * Adds all policies that ship with NRS, i.e. those in the \e nrs_pols_builtin
1815 * array, to NRS core's list of policies \e nrs_core.nrs_policies.
1817 * \retval 0 All policy descriptors in \e nrs_pols_builtin have been added
1818 * successfully to \e nrs_core.nrs_policies
1821 ptlrpc_nrs_init(void)
1828 * Initialize the NRS core object.
1830 mutex_init(&nrs_core.nrs_mutex);
1831 CFS_INIT_LIST_HEAD(&nrs_core.nrs_heads);
1832 CFS_INIT_LIST_HEAD(&nrs_core.nrs_policies);
1834 for (i = 0; i < ARRAY_SIZE(nrs_pols_builtin); i++) {
1836 * No need to take nrs_core.nrs_mutex as there is no contention at
1839 rc = nrs_policy_exists_locked(nrs_pols_builtin[i]);
1841 * This should not fail for in-tree policies.
1843 LASSERT(rc == false);
1844 cfs_list_add_tail(&nrs_pols_builtin[i]->pd_list,
1845 &nrs_core.nrs_policies);
1852 * Stub finalization function
1855 ptlrpc_nrs_fini(void)