aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/lustre/lustre/ptlrpc/nrs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/lustre/lustre/ptlrpc/nrs.c')
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/nrs.c133
1 files changed, 58 insertions, 75 deletions
diff --git a/drivers/staging/lustre/lustre/ptlrpc/nrs.c b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
index 7044e1ff6692..710fb806f122 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/nrs.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
@@ -13,10 +13,6 @@
* GNU General Public License version 2 for more details. A copy is
* included in the COPYING file that accompanied this code.
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
* GPL HEADER END
*/
/*
@@ -47,9 +43,6 @@
#include "../../include/linux/libcfs/libcfs.h"
#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. */
-
/**
* NRS core object.
*/
@@ -57,7 +50,7 @@ struct nrs_core nrs_core;
static int nrs_policy_init(struct ptlrpc_nrs_policy *policy)
{
- return policy->pol_desc->pd_ops->op_policy_init != NULL ?
+ return policy->pol_desc->pd_ops->op_policy_init ?
policy->pol_desc->pd_ops->op_policy_init(policy) : 0;
}
@@ -66,7 +59,7 @@ static void nrs_policy_fini(struct ptlrpc_nrs_policy *policy)
LASSERT(policy->pol_ref == 0);
LASSERT(policy->pol_req_queued == 0);
- if (policy->pol_desc->pd_ops->op_policy_fini != NULL)
+ if (policy->pol_desc->pd_ops->op_policy_fini)
policy->pol_desc->pd_ops->op_policy_fini(policy);
}
@@ -82,7 +75,7 @@ static int nrs_policy_ctl_locked(struct ptlrpc_nrs_policy *policy,
if (policy->pol_state == NRS_POL_STATE_STOPPED)
return -ENODEV;
- return policy->pol_desc->pd_ops->op_policy_ctl != NULL ?
+ return policy->pol_desc->pd_ops->op_policy_ctl ?
policy->pol_desc->pd_ops->op_policy_ctl(policy, opc, arg) :
-ENOSYS;
}
@@ -91,7 +84,7 @@ static void nrs_policy_stop0(struct ptlrpc_nrs_policy *policy)
{
struct ptlrpc_nrs *nrs = policy->pol_nrs;
- if (policy->pol_desc->pd_ops->op_policy_stop != NULL) {
+ if (policy->pol_desc->pd_ops->op_policy_stop) {
spin_unlock(&nrs->nrs_lock);
policy->pol_desc->pd_ops->op_policy_stop(policy);
@@ -154,7 +147,7 @@ static void nrs_policy_stop_primary(struct ptlrpc_nrs *nrs)
{
struct ptlrpc_nrs_policy *tmp = nrs->nrs_policy_primary;
- if (tmp == NULL)
+ if (!tmp)
return;
nrs->nrs_policy_primary = NULL;
@@ -220,12 +213,12 @@ static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy)
* nrs_policy_flags::PTLRPC_NRS_FL_FALLBACK flag set can
* register with NRS core.
*/
- LASSERT(nrs->nrs_policy_fallback == NULL);
+ LASSERT(!nrs->nrs_policy_fallback);
} else {
/**
* Shouldn't start primary policy if w/o fallback policy.
*/
- if (nrs->nrs_policy_fallback == NULL)
+ if (!nrs->nrs_policy_fallback)
return -EPERM;
if (policy->pol_state == NRS_POL_STATE_STARTED)
@@ -311,7 +304,7 @@ static void nrs_policy_put_locked(struct ptlrpc_nrs_policy *policy)
policy->pol_ref--;
if (unlikely(policy->pol_ref == 0 &&
- policy->pol_state == NRS_POL_STATE_STOPPING))
+ policy->pol_state == NRS_POL_STATE_STOPPING))
nrs_policy_stop0(policy);
}
@@ -326,7 +319,7 @@ static void nrs_policy_put(struct ptlrpc_nrs_policy *policy)
* Find and return a policy by name.
*/
static struct ptlrpc_nrs_policy *nrs_policy_find_locked(struct ptlrpc_nrs *nrs,
- char *name)
+ char *name)
{
struct ptlrpc_nrs_policy *tmp;
@@ -348,10 +341,10 @@ static void nrs_resource_put(struct ptlrpc_nrs_resource *res)
{
struct ptlrpc_nrs_policy *policy = res->res_policy;
- if (policy->pol_desc->pd_ops->op_res_put != NULL) {
+ if (policy->pol_desc->pd_ops->op_res_put) {
struct ptlrpc_nrs_resource *parent;
- for (; res != NULL; res = parent) {
+ for (; res; res = parent) {
parent = res->res_parent;
policy->pol_desc->pd_ops->op_res_put(policy, res);
}
@@ -390,12 +383,11 @@ struct ptlrpc_nrs_resource *nrs_resource_get(struct ptlrpc_nrs_policy *policy,
rc = policy->pol_desc->pd_ops->op_res_get(policy, nrq, res,
&tmp, moving_req);
if (rc < 0) {
- if (res != NULL)
+ if (res)
nrs_resource_put(res);
return NULL;
}
- LASSERT(tmp != NULL);
tmp->res_parent = res;
tmp->res_policy = policy;
res = tmp;
@@ -445,7 +437,7 @@ static void nrs_resource_get_safe(struct ptlrpc_nrs *nrs,
nrs_policy_get_locked(fallback);
primary = nrs->nrs_policy_primary;
- if (primary != NULL)
+ if (primary)
nrs_policy_get_locked(primary);
spin_unlock(&nrs->nrs_lock);
@@ -454,9 +446,9 @@ static void nrs_resource_get_safe(struct ptlrpc_nrs *nrs,
* Obtain resource hierarchy references.
*/
resp[NRS_RES_FALLBACK] = nrs_resource_get(fallback, nrq, moving_req);
- LASSERT(resp[NRS_RES_FALLBACK] != NULL);
+ LASSERT(resp[NRS_RES_FALLBACK]);
- if (primary != NULL) {
+ if (primary) {
resp[NRS_RES_PRIMARY] = nrs_resource_get(primary, nrq,
moving_req);
/**
@@ -465,7 +457,7 @@ static void nrs_resource_get_safe(struct ptlrpc_nrs *nrs,
* reference on the policy as it will not be used for this
* request.
*/
- if (resp[NRS_RES_PRIMARY] == NULL)
+ if (!resp[NRS_RES_PRIMARY])
nrs_policy_put(primary);
}
}
@@ -482,11 +474,10 @@ static void nrs_resource_get_safe(struct ptlrpc_nrs *nrs,
static void nrs_resource_put_safe(struct ptlrpc_nrs_resource **resp)
{
struct ptlrpc_nrs_policy *pols[NRS_RES_MAX];
- struct ptlrpc_nrs *nrs = NULL;
int i;
for (i = 0; i < NRS_RES_MAX; i++) {
- if (resp[i] != NULL) {
+ if (resp[i]) {
pols[i] = resp[i]->res_policy;
nrs_resource_put(resp[i]);
resp[i] = NULL;
@@ -496,18 +487,9 @@ static void nrs_resource_put_safe(struct ptlrpc_nrs_resource **resp)
}
for (i = 0; i < NRS_RES_MAX; i++) {
- if (pols[i] == NULL)
- continue;
-
- if (nrs == NULL) {
- nrs = pols[i]->pol_nrs;
- spin_lock(&nrs->nrs_lock);
- }
- nrs_policy_put_locked(pols[i]);
+ if (pols[i])
+ nrs_policy_put(pols[i]);
}
-
- if (nrs != NULL)
- spin_unlock(&nrs->nrs_lock);
}
/**
@@ -536,7 +518,7 @@ struct ptlrpc_nrs_request *nrs_request_get(struct ptlrpc_nrs_policy *policy,
nrq = policy->pol_desc->pd_ops->op_req_get(policy, peek, force);
- LASSERT(ergo(nrq != NULL, nrs_request_policy(nrq) == policy));
+ LASSERT(ergo(nrq, nrs_request_policy(nrq) == policy));
return nrq;
}
@@ -562,7 +544,7 @@ static inline void nrs_request_enqueue(struct ptlrpc_nrs_request *nrq)
* the preferred choice.
*/
for (i = NRS_RES_MAX - 1; i >= 0; i--) {
- if (nrq->nr_res_ptrs[i] == NULL)
+ if (!nrq->nr_res_ptrs[i])
continue;
nrq->nr_res_idx = i;
@@ -632,7 +614,7 @@ static int nrs_policy_ctl(struct ptlrpc_nrs *nrs, char *name,
spin_lock(&nrs->nrs_lock);
policy = nrs_policy_find_locked(nrs, name);
- if (policy == NULL) {
+ if (!policy) {
rc = -ENOENT;
goto out;
}
@@ -654,7 +636,7 @@ static int nrs_policy_ctl(struct ptlrpc_nrs *nrs, char *name,
break;
}
out:
- if (policy != NULL)
+ if (policy)
nrs_policy_put_locked(policy);
spin_unlock(&nrs->nrs_lock);
@@ -679,7 +661,7 @@ static int nrs_policy_unregister(struct ptlrpc_nrs *nrs, char *name)
spin_lock(&nrs->nrs_lock);
policy = nrs_policy_find_locked(nrs, name);
- if (policy == NULL) {
+ if (!policy) {
spin_unlock(&nrs->nrs_lock);
CERROR("Can't find NRS policy %s\n", name);
@@ -712,7 +694,7 @@ static int nrs_policy_unregister(struct ptlrpc_nrs *nrs, char *name)
nrs_policy_fini(policy);
- LASSERT(policy->pol_private == NULL);
+ LASSERT(!policy->pol_private);
kfree(policy);
return 0;
@@ -736,18 +718,16 @@ static int nrs_policy_register(struct ptlrpc_nrs *nrs,
struct ptlrpc_service_part *svcpt = nrs->nrs_svcpt;
int rc;
- LASSERT(svcpt != NULL);
- LASSERT(desc->pd_ops != NULL);
- LASSERT(desc->pd_ops->op_res_get != NULL);
- LASSERT(desc->pd_ops->op_req_get != NULL);
- LASSERT(desc->pd_ops->op_req_enqueue != NULL);
- LASSERT(desc->pd_ops->op_req_dequeue != NULL);
- LASSERT(desc->pd_compat != NULL);
+ LASSERT(desc->pd_ops->op_res_get);
+ LASSERT(desc->pd_ops->op_req_get);
+ LASSERT(desc->pd_ops->op_req_enqueue);
+ LASSERT(desc->pd_ops->op_req_dequeue);
+ LASSERT(desc->pd_compat);
policy = kzalloc_node(sizeof(*policy), GFP_NOFS,
cfs_cpt_spread_node(svcpt->scp_service->srv_cptable,
svcpt->scp_cpt));
- if (policy == NULL)
+ if (!policy)
return -ENOMEM;
policy->pol_nrs = nrs;
@@ -767,7 +747,7 @@ static int nrs_policy_register(struct ptlrpc_nrs *nrs,
spin_lock(&nrs->nrs_lock);
tmp = nrs_policy_find_locked(nrs, policy->pol_desc->pd_name);
- if (tmp != NULL) {
+ if (tmp) {
CERROR("NRS policy %s has been registered, can't register it for %s\n",
policy->pol_desc->pd_name,
svcpt->scp_service->srv_name);
@@ -817,7 +797,7 @@ static void ptlrpc_nrs_req_add_nolock(struct ptlrpc_request *req)
*/
if (unlikely(list_empty(&policy->pol_list_queued)))
list_add_tail(&policy->pol_list_queued,
- &policy->pol_nrs->nrs_policy_queued);
+ &policy->pol_nrs->nrs_policy_queued);
}
/**
@@ -957,14 +937,14 @@ static int nrs_svcpt_setup_locked(struct ptlrpc_service_part *svcpt)
/**
* Optionally allocate a high-priority NRS head.
*/
- if (svcpt->scp_service->srv_ops.so_hpreq_handler == NULL)
+ if (!svcpt->scp_service->srv_ops.so_hpreq_handler)
goto out;
svcpt->scp_nrs_hp =
kzalloc_node(sizeof(*svcpt->scp_nrs_hp), GFP_NOFS,
cfs_cpt_spread_node(svcpt->scp_service->srv_cptable,
svcpt->scp_cpt));
- if (svcpt->scp_nrs_hp == NULL) {
+ if (!svcpt->scp_nrs_hp) {
rc = -ENOMEM;
goto out;
}
@@ -998,8 +978,7 @@ again:
nrs = nrs_svcpt2nrs(svcpt, hp);
nrs->nrs_stopping = 1;
- list_for_each_entry_safe(policy, tmp, &nrs->nrs_policy_list,
- pol_list) {
+ list_for_each_entry_safe(policy, tmp, &nrs->nrs_policy_list, pol_list) {
rc = nrs_policy_unregister(nrs, policy->pol_desc->pd_name);
LASSERT(rc == 0);
}
@@ -1089,7 +1068,7 @@ again:
}
}
- if (desc->pd_ops->op_lprocfs_fini != NULL)
+ if (desc->pd_ops->op_lprocfs_fini)
desc->pd_ops->op_lprocfs_fini(svc);
}
@@ -1115,15 +1094,15 @@ static int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
{
struct ptlrpc_service *svc;
struct ptlrpc_nrs_pol_desc *desc;
+ size_t len;
int rc = 0;
- LASSERT(conf != NULL);
- LASSERT(conf->nc_ops != NULL);
- LASSERT(conf->nc_compat != NULL);
+ LASSERT(conf->nc_ops);
+ LASSERT(conf->nc_compat);
LASSERT(ergo(conf->nc_compat == nrs_policy_compat_one,
- conf->nc_compat_svc_name != NULL));
+ conf->nc_compat_svc_name));
LASSERT(ergo((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) != 0,
- conf->nc_owner != NULL));
+ conf->nc_owner));
conf->nc_name[NRS_POL_NAME_MAX - 1] = '\0';
@@ -1146,7 +1125,7 @@ static int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
mutex_lock(&nrs_core.nrs_mutex);
- if (nrs_policy_find_desc_locked(conf->nc_name) != NULL) {
+ if (nrs_policy_find_desc_locked(conf->nc_name)) {
CERROR("NRS: failing to register policy %s which has already been registered with NRS core!\n",
conf->nc_name);
rc = -EEXIST;
@@ -1159,7 +1138,12 @@ static int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
goto fail;
}
- strncpy(desc->pd_name, conf->nc_name, NRS_POL_NAME_MAX);
+ len = strlcpy(desc->pd_name, conf->nc_name, sizeof(desc->pd_name));
+ if (len >= sizeof(desc->pd_name)) {
+ kfree(desc);
+ rc = -E2BIG;
+ goto fail;
+ }
desc->pd_ops = conf->nc_ops;
desc->pd_compat = conf->nc_compat;
desc->pd_compat_svc_name = conf->nc_compat_svc_name;
@@ -1224,7 +1208,7 @@ again:
* No need to take a reference to other modules here, as we
* will be calling from the module's init() function.
*/
- if (desc->pd_ops->op_lprocfs_init != NULL) {
+ if (desc->pd_ops->op_lprocfs_init) {
rc = desc->pd_ops->op_lprocfs_init(svc);
if (rc != 0) {
rc2 = nrs_policy_unregister_locked(desc);
@@ -1288,7 +1272,7 @@ int ptlrpc_service_nrs_setup(struct ptlrpc_service *svc)
if (!nrs_policy_compatible(svc, desc))
continue;
- if (desc->pd_ops->op_lprocfs_init != NULL) {
+ if (desc->pd_ops->op_lprocfs_init) {
rc = desc->pd_ops->op_lprocfs_init(svc);
if (rc != 0)
goto failed;
@@ -1329,7 +1313,7 @@ void ptlrpc_service_nrs_cleanup(struct ptlrpc_service *svc)
if (!nrs_policy_compatible(svc, desc))
continue;
- if (desc->pd_ops->op_lprocfs_fini != NULL)
+ if (desc->pd_ops->op_lprocfs_fini)
desc->pd_ops->op_lprocfs_fini(svc);
}
@@ -1376,7 +1360,8 @@ void ptlrpc_nrs_req_finalize(struct ptlrpc_request *req)
if (req->rq_nrq.nr_initialized) {
nrs_resource_put_safe(req->rq_nrq.nr_res_ptrs);
/* no protection on bit nr_initialized because no
- * contention at this late stage */
+ * contention at this late stage
+ */
req->rq_nrq.nr_finalized = 1;
}
}
@@ -1434,7 +1419,7 @@ static void nrs_request_removed(struct ptlrpc_nrs_policy *policy)
policy->pol_nrs->nrs_req_queued);
list_move_tail(&policy->pol_list_queued,
- &policy->pol_nrs->nrs_policy_queued);
+ &policy->pol_nrs->nrs_policy_queued);
}
}
@@ -1466,10 +1451,9 @@ ptlrpc_nrs_req_get_nolock0(struct ptlrpc_service_part *svcpt, bool hp,
* Always try to drain requests from all NRS polices even if they are
* inactive, because the user can change policy status at runtime.
*/
- list_for_each_entry(policy, &nrs->nrs_policy_queued,
- pol_list_queued) {
+ list_for_each_entry(policy, &nrs->nrs_policy_queued, pol_list_queued) {
nrq = nrs_request_get(policy, peek, force);
- if (nrq != NULL) {
+ if (nrq) {
if (likely(!peek)) {
nrq->nr_started = 1;
@@ -1619,8 +1603,7 @@ void ptlrpc_nrs_fini(void)
struct ptlrpc_nrs_pol_desc *desc;
struct ptlrpc_nrs_pol_desc *tmp;
- list_for_each_entry_safe(desc, tmp, &nrs_core.nrs_policies,
- pd_list) {
+ list_for_each_entry_safe(desc, tmp, &nrs_core.nrs_policies, pd_list) {
list_del_init(&desc->pd_list);
kfree(desc);
}