X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fptlrpc%2Fnrs.c;h=6a5182d9b5538ce930dad5441dd26f0b1b4e5a61;hb=3fc039a99f41725798d157a422174005a49200c8;hp=5343ab3a6ae22e8eee71f95902a0f412d8af40c8;hpb=c85f006d40cc5c9504ea873fc815ce2eaa1ee062;p=fs%2Flustre-release.git diff --git a/lustre/ptlrpc/nrs.c b/lustre/ptlrpc/nrs.c index 5343ab3..6a5182d 100644 --- a/lustre/ptlrpc/nrs.c +++ b/lustre/ptlrpc/nrs.c @@ -50,13 +50,7 @@ #include #include "ptlrpc_internal.h" -/* XXX: This is just for liblustre. Remove the #if defined directive when the - * "cfs_" prefix is dropped from cfs_list_head. */ -#if defined (__linux__) && defined(__KERNEL__) extern struct list_head ptlrpc_all_services; -#else -extern struct cfs_list_head ptlrpc_all_services; -#endif /** * NRS core object. @@ -116,8 +110,8 @@ static void nrs_policy_stop0(struct ptlrpc_nrs_policy *policy) policy->pol_state = NRS_POL_STATE_STOPPED; - if (cfs_atomic_dec_and_test(&policy->pol_desc->pd_refs)) - cfs_module_put(policy->pol_desc->pd_owner); + if (atomic_dec_and_test(&policy->pol_desc->pd_refs)) + module_put(policy->pol_desc->pd_owner); EXIT; } @@ -206,7 +200,7 @@ static void nrs_policy_stop_primary(struct ptlrpc_nrs *nrs) * references on the policy to ptlrpc_nrs_pol_stae::NRS_POL_STATE_STOPPED. In * this case, the fallback policy is only left active in the NRS head. */ -static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy) +static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy, char *arg) { struct ptlrpc_nrs *nrs = policy->pol_nrs; int rc = 0; @@ -258,9 +252,9 @@ static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy) * Increase the module usage count for policies registering from other * modules. */ - if (cfs_atomic_inc_return(&policy->pol_desc->pd_refs) == 1 && - !cfs_try_module_get(policy->pol_desc->pd_owner)) { - cfs_atomic_dec(&policy->pol_desc->pd_refs); + if (atomic_inc_return(&policy->pol_desc->pd_refs) == 1 && + !try_module_get(policy->pol_desc->pd_owner)) { + atomic_dec(&policy->pol_desc->pd_refs); CERROR("NRS: cannot get module for policy %s; is it alive?\n", policy->pol_desc->pd_name); RETURN(-ENODEV); @@ -276,12 +270,12 @@ static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy) if (policy->pol_desc->pd_ops->op_policy_start) { spin_unlock(&nrs->nrs_lock); - rc = policy->pol_desc->pd_ops->op_policy_start(policy); + rc = policy->pol_desc->pd_ops->op_policy_start(policy, arg); spin_lock(&nrs->nrs_lock); if (rc != 0) { - if (cfs_atomic_dec_and_test(&policy->pol_desc->pd_refs)) - cfs_module_put(policy->pol_desc->pd_owner); + if (atomic_dec_and_test(&policy->pol_desc->pd_refs)) + module_put(policy->pol_desc->pd_owner); policy->pol_state = NRS_POL_STATE_STOPPED; GOTO(out, rc); @@ -672,7 +666,7 @@ static int nrs_policy_ctl(struct ptlrpc_nrs *nrs, char *name, * Start \e policy */ case PTLRPC_NRS_CTL_START: - rc = nrs_policy_start_locked(policy); + rc = nrs_policy_start_locked(policy, arg); break; } out: @@ -769,7 +763,7 @@ static int nrs_policy_register(struct ptlrpc_nrs *nrs, LASSERT(desc->pd_compat != NULL); OBD_CPT_ALLOC_GFP(policy, svcpt->scp_service->srv_cptable, - svcpt->scp_cpt, sizeof(*policy), CFS_ALLOC_IO); + svcpt->scp_cpt, sizeof(*policy), GFP_NOFS); if (policy == NULL) RETURN(-ENOMEM); @@ -807,7 +801,7 @@ static int nrs_policy_register(struct ptlrpc_nrs *nrs, nrs->nrs_num_pols++; if (policy->pol_flags & PTLRPC_NRS_FL_REG_START) - rc = nrs_policy_start_locked(policy); + rc = nrs_policy_start_locked(policy, NULL); spin_unlock(&nrs->nrs_lock); @@ -954,6 +948,7 @@ static int nrs_svcpt_setup_locked0(struct ptlrpc_nrs *nrs, spin_lock_init(&nrs->nrs_lock); CFS_INIT_LIST_HEAD(&nrs->nrs_policy_list); CFS_INIT_LIST_HEAD(&nrs->nrs_policy_queued); + nrs->nrs_throttling = 0; rc = nrs_register_policies_locked(nrs); @@ -1024,7 +1019,13 @@ static void nrs_svcpt_cleanup_locked(struct ptlrpc_service_part *svcpt) LASSERT(mutex_is_locked(&nrs_core.nrs_mutex)); again: - nrs = nrs_svcpt2nrs(svcpt, hp); + /* scp_nrs_hp could be NULL due to short of memory. */ + nrs = hp ? svcpt->scp_nrs_hp : &svcpt->scp_nrs_reg; + /* check the nrs_svcpt to see if nrs is initialized. */ + if (!nrs || !nrs->nrs_svcpt) { + EXIT; + return; + } nrs->nrs_stopping = 1; cfs_list_for_each_entry_safe(policy, tmp, &nrs->nrs_policy_list, @@ -1194,14 +1195,18 @@ int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf) if (desc == NULL) GOTO(fail, rc = -ENOMEM); - strncpy(desc->pd_name, conf->nc_name, NRS_POL_NAME_MAX); + if (strlcpy(desc->pd_name, conf->nc_name, sizeof(desc->pd_name)) >= + sizeof(desc->pd_name)) { + OBD_FREE_PTR(desc); + GOTO(fail, rc = -E2BIG); + } desc->pd_ops = conf->nc_ops; desc->pd_compat = conf->nc_compat; desc->pd_compat_svc_name = conf->nc_compat_svc_name; if ((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) != 0) desc->pd_owner = conf->nc_owner; desc->pd_flags = conf->nc_flags; - cfs_atomic_set(&desc->pd_refs, 0); + atomic_set(&desc->pd_refs, 0); /** * For policies that are held in the same module as NRS (currently @@ -1627,6 +1632,24 @@ bool ptlrpc_nrs_req_pending_nolock(struct ptlrpc_service_part *svcpt, bool hp) }; /** + * Returns whether NRS policy is throttling reqeust + * + * \param[in] svcpt the service partition to enquire. + * \param[in] hp whether the regular or high-priority NRS head is to be + * enquired. + * + * \retval false the indicated NRS head has no enqueued requests. + * \retval true the indicated NRS head has some enqueued requests. + */ +bool ptlrpc_nrs_req_throttling_nolock(struct ptlrpc_service_part *svcpt, + bool hp) +{ + struct ptlrpc_nrs *nrs = nrs_svcpt2nrs(svcpt, hp); + + return !!nrs->nrs_throttling; +}; + +/** * Moves request \a req from the regular to the high-priority NRS head. * * \param[in] req the request to move @@ -1747,6 +1770,7 @@ extern struct ptlrpc_nrs_pol_conf nrs_conf_crrn; /* ptlrpc/nrs_orr.c */ extern struct ptlrpc_nrs_pol_conf nrs_conf_orr; extern struct ptlrpc_nrs_pol_conf nrs_conf_trr; +extern struct ptlrpc_nrs_pol_conf nrs_conf_tbf; #endif /** @@ -1780,6 +1804,9 @@ int ptlrpc_nrs_init(void) rc = ptlrpc_nrs_policy_register(&nrs_conf_trr); if (rc != 0) GOTO(fail, rc); + rc = ptlrpc_nrs_policy_register(&nrs_conf_tbf); + if (rc != 0) + GOTO(fail, rc); #endif RETURN(rc);