2015-05-01 16:07:28

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 0/11] Use kzalloc and kfree

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree. The complete
semantic patch that makes these changes is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression ptr,e1,e2;
@@

- OBD_ALLOC(ptr,sizeof e1 * e2)
+ ptr = kcalloc(e2, sizeof e1, GFP_NOFS)

@@
expression ptr,e1,e2;
@@

- OBD_ALLOC_WAIT(ptr,sizeof e1 * e2)
+ ptr = kcalloc(sizeof e1, e2, GFP_KERNEL)

@@
expression ptr,e1,e2;
@@

- OBD_ALLOC(ptr,e2 * sizeof e1)
+ ptr = kcalloc(e2, sizeof e1, GFP_NOFS)

@@
expression ptr,e1,e2;
@@

- OBD_ALLOC_WAIT(ptr,e2 * sizeof e1)
+ ptr = kcalloc(e2, sizeof e1, GFP_KERNEL)

@@
expression ptr,e2;
type t;
@@

- OBD_ALLOC(ptr,sizeof (t) * e2)
+ ptr = kcalloc(e2, sizeof (t), GFP_NOFS)

@@
expression ptr,e2;
type t;
@@

- OBD_ALLOC_WAIT(ptr,sizeof (t) * e2)
+ ptr = kcalloc(e2, sizeof (t), GFP_KERNEL)

@@
expression ptr,e2;
type t;
@@

- OBD_ALLOC(ptr,e2 * sizeof (t))
+ ptr = kcalloc(e2, sizeof (t), GFP_NOFS)

@@
expression ptr,e2;
type t;
@@

- OBD_ALLOC_WAIT(ptr,e2 * sizeof (t))
+ ptr = kcalloc(e2, sizeof (t), GFP_KERNEL)

@@
expression ptr,e1,e2;
@@

- OBD_ALLOC(ptr,e1 * e2)
+ ptr = kcalloc(e1, e2, GFP_NOFS)

@@
expression ptr,e1,e2;
@@

- OBD_ALLOC_WAIT(ptr,e1 * e2)
+ ptr = kcalloc(e1, e2, GFP_KERNEL)

// -----------------------------------------------------------------------

@@
expression ptr,size;
@@

- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@
expression ptr,size;
@@

- OBD_ALLOC_WAIT(ptr,size)
+ ptr = kzalloc(size, GFP_KERNEL)

@@
expression ptr;
@@

- OBD_ALLOC_PTR(ptr)
+ ptr = kzalloc(sizeof(*ptr), GFP_NOFS)

@@
expression ptr;
@@

- OBD_ALLOC_PTR_WAIT(ptr)
+ ptr = kzalloc(sizeof(*ptr), GFP_KERNEL)

// ----------------------------------------------------------------------

@@
expression ptr, size;
@@

- OBD_FREE(ptr, size);
+ kfree(ptr);

@@
expression ptr;
@@

- OBD_FREE_PTR(ptr);
+ kfree(ptr);
// </smpl>


2015-05-01 16:00:13

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 11/11] staging: lustre: ptlrpc: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/ptlrpc/client.c | 18 ++++----
drivers/staging/lustre/lustre/ptlrpc/connection.c | 6 +-
drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c | 24 +++++------
drivers/staging/lustre/lustre/ptlrpc/nrs.c | 18 ++++----
drivers/staging/lustre/lustre/ptlrpc/nrs_fifo.c | 2
drivers/staging/lustre/lustre/ptlrpc/pinger.c | 6 +-
drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 14 +++---
drivers/staging/lustre/lustre/ptlrpc/sec.c | 2
drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c | 17 +++-----
drivers/staging/lustre/lustre/ptlrpc/sec_config.c | 16 +++----
drivers/staging/lustre/lustre/ptlrpc/sec_plain.c | 10 ++--
drivers/staging/lustre/lustre/ptlrpc/service.c | 42 +++++++++-----------
12 files changed, 84 insertions(+), 91 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c
--- a/drivers/staging/lustre/lustre/ptlrpc/service.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/service.c
@@ -87,7 +87,7 @@ ptlrpc_alloc_rqbd(struct ptlrpc_service_
OBD_CPT_ALLOC_LARGE(rqbd->rqbd_buffer, svc->srv_cptable,
svcpt->scp_cpt, svc->srv_buf_size);
if (rqbd->rqbd_buffer == NULL) {
- OBD_FREE_PTR(rqbd);
+ kfree(rqbd);
return NULL;
}

@@ -113,7 +113,7 @@ ptlrpc_free_rqbd(struct ptlrpc_request_b
spin_unlock(&svcpt->scp_lock);

OBD_FREE_LARGE(rqbd->rqbd_buffer, svcpt->scp_service->srv_buf_size);
- OBD_FREE_PTR(rqbd);
+ kfree(rqbd);
}

int
@@ -661,13 +661,12 @@ ptlrpc_service_part_init(struct ptlrpc_s

failed:
if (array->paa_reqs_count != NULL) {
- OBD_FREE(array->paa_reqs_count, sizeof(__u32) * size);
+ kfree(array->paa_reqs_count);
array->paa_reqs_count = NULL;
}

if (array->paa_reqs_array != NULL) {
- OBD_FREE(array->paa_reqs_array,
- sizeof(struct list_head) * array->paa_size);
+ kfree(array->paa_reqs_array);
array->paa_reqs_array = NULL;
}

@@ -724,17 +723,18 @@ ptlrpc_register_service(struct ptlrpc_se
CERROR("%s: failed to parse CPT array %s: %d\n",
conf->psc_name, cconf->cc_pattern, rc);
if (cpts != NULL)
- OBD_FREE(cpts, sizeof(*cpts) * ncpts);
+ kfree(cpts);
return ERR_PTR(rc < 0 ? rc : -EINVAL);
}
ncpts = rc;
}
}

- OBD_ALLOC(service, offsetof(struct ptlrpc_service, srv_parts[ncpts]));
+ service = kzalloc(offsetof(struct ptlrpc_service, srv_parts[ncpts]),
+ GFP_NOFS);
if (service == NULL) {
if (cpts != NULL)
- OBD_FREE(cpts, sizeof(*cpts) * ncpts);
+ kfree(cpts);
return ERR_PTR(-ENOMEM);
}

@@ -2291,7 +2291,7 @@ static int ptlrpc_main(void *arg)
goto out;
}

- OBD_ALLOC_PTR(env);
+ env = kzalloc(sizeof(*env), GFP_NOFS);
if (env == NULL) {
rc = -ENOMEM;
goto out_srv_fini;
@@ -2414,7 +2414,7 @@ out_srv_fini:

if (env != NULL) {
lu_context_fini(&env->le_ctx);
- OBD_FREE_PTR(env);
+ kfree(env);
}
out:
CDEBUG(D_RPCTRACE, "service thread [ %p : %u ] %d exiting: rc %d\n",
@@ -2596,7 +2596,7 @@ static void ptlrpc_svcpt_stop_threads(st
thread = list_entry(zombie.next,
struct ptlrpc_thread, t_link);
list_del(&thread->t_link);
- OBD_FREE_PTR(thread);
+ kfree(thread);
}
}

@@ -2678,7 +2678,7 @@ int ptlrpc_start_thread(struct ptlrpc_se
spin_lock(&svcpt->scp_lock);
if (!ptlrpc_threads_increasable(svcpt)) {
spin_unlock(&svcpt->scp_lock);
- OBD_FREE_PTR(thread);
+ kfree(thread);
return -EMFILE;
}

@@ -2687,7 +2687,7 @@ int ptlrpc_start_thread(struct ptlrpc_se
* might require unique and contiguous t_id */
LASSERT(svcpt->scp_nthrs_starting == 1);
spin_unlock(&svcpt->scp_lock);
- OBD_FREE_PTR(thread);
+ kfree(thread);
if (wait) {
CDEBUG(D_INFO, "Waiting for creating thread %s #%d\n",
svc->srv_thread_name, svcpt->scp_thr_nextid);
@@ -2733,7 +2733,7 @@ int ptlrpc_start_thread(struct ptlrpc_se
} else {
list_del(&thread->t_link);
spin_unlock(&svcpt->scp_lock);
- OBD_FREE_PTR(thread);
+ kfree(thread);
}
return rc;
}
@@ -2817,8 +2817,7 @@ void ptlrpc_hr_fini(void)

cfs_percpt_for_each(hrp, i, ptlrpc_hr.hr_partitions) {
if (hrp->hrp_thrs != NULL) {
- OBD_FREE(hrp->hrp_thrs,
- hrp->hrp_nthrs * sizeof(hrp->hrp_thrs[0]));
+ kfree(hrp->hrp_thrs);
}
}

@@ -2999,26 +2998,23 @@ ptlrpc_service_free(struct ptlrpc_servic
array = &svcpt->scp_at_array;

if (array->paa_reqs_array != NULL) {
- OBD_FREE(array->paa_reqs_array,
- sizeof(struct list_head) * array->paa_size);
+ kfree(array->paa_reqs_array);
array->paa_reqs_array = NULL;
}

if (array->paa_reqs_count != NULL) {
- OBD_FREE(array->paa_reqs_count,
- sizeof(__u32) * array->paa_size);
+ kfree(array->paa_reqs_count);
array->paa_reqs_count = NULL;
}
}

ptlrpc_service_for_each_part(svcpt, i, svc)
- OBD_FREE_PTR(svcpt);
+ kfree(svcpt);

if (svc->srv_cpts != NULL)
cfs_expr_list_values_free(svc->srv_cpts, svc->srv_ncpts);

- OBD_FREE(svc, offsetof(struct ptlrpc_service,
- srv_parts[svc->srv_ncpts]));
+ kfree(svc);
}

int ptlrpc_unregister_service(struct ptlrpc_service *service)
diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
@@ -376,7 +376,7 @@ struct ptlrpc_cli_ctx *plain_sec_install
{
struct ptlrpc_cli_ctx *ctx, *ctx_new;

- OBD_ALLOC_PTR(ctx_new);
+ ctx_new = kzalloc(sizeof(*ctx_new), GFP_NOFS);

write_lock(&plsec->pls_lock);

@@ -385,7 +385,7 @@ struct ptlrpc_cli_ctx *plain_sec_install
atomic_inc(&ctx->cc_refcount);

if (ctx_new)
- OBD_FREE_PTR(ctx_new);
+ kfree(ctx_new);
} else if (ctx_new) {
ctx = ctx_new;

@@ -424,7 +424,7 @@ void plain_destroy_sec(struct ptlrpc_sec

class_import_put(sec->ps_import);

- OBD_FREE_PTR(plsec);
+ kfree(plsec);
}

static
@@ -444,7 +444,7 @@ struct ptlrpc_sec *plain_create_sec(stru

LASSERT(SPTLRPC_FLVR_POLICY(sf->sf_rpc) == SPTLRPC_POLICY_PLAIN);

- OBD_ALLOC_PTR(plsec);
+ plsec = kzalloc(sizeof(*plsec), GFP_NOFS);
if (plsec == NULL)
return NULL;

@@ -508,7 +508,7 @@ void plain_release_ctx(struct ptlrpc_sec
LASSERT(atomic_read(&ctx->cc_refcount) == 0);
LASSERT(ctx->cc_sec == sec);

- OBD_FREE_PTR(ctx);
+ kfree(ctx);

atomic_dec(&sec->ps_nctx);
sptlrpc_sec_put(sec);
diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/sec_config.c b/drivers/staging/lustre/lustre/ptlrpc/sec_config.c
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_config.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_config.c
@@ -242,8 +242,7 @@ void sptlrpc_rule_set_free(struct sptlrp
(rset->srs_nrule == 0 && rset->srs_rules == NULL));

if (rset->srs_nslot) {
- OBD_FREE(rset->srs_rules,
- rset->srs_nslot * sizeof(*rset->srs_rules));
+ kfree(rset->srs_rules);
sptlrpc_rule_set_init(rset);
}
}
@@ -265,7 +264,7 @@ int sptlrpc_rule_set_expand(struct sptlr
nslot = rset->srs_nslot + 8;

/* better use realloc() if available */
- OBD_ALLOC(rules, nslot * sizeof(*rset->srs_rules));
+ rules = kcalloc(nslot, sizeof(*rset->srs_rules), GFP_NOFS);
if (rules == NULL)
return -ENOMEM;

@@ -274,8 +273,7 @@ int sptlrpc_rule_set_expand(struct sptlr
memcpy(rules, rset->srs_rules,
rset->srs_nrule * sizeof(*rset->srs_rules));

- OBD_FREE(rset->srs_rules,
- rset->srs_nslot * sizeof(*rset->srs_rules));
+ kfree(rset->srs_rules);
}

rset->srs_rules = rules;
@@ -509,7 +507,7 @@ static void sptlrpc_conf_free_rsets(stru
&conf->sc_tgts, sct_list) {
sptlrpc_rule_set_free(&conf_tgt->sct_rset);
list_del(&conf_tgt->sct_list);
- OBD_FREE_PTR(conf_tgt);
+ kfree(conf_tgt);
}
LASSERT(list_empty(&conf->sc_tgts));

@@ -523,7 +521,7 @@ static void sptlrpc_conf_free(struct spt

sptlrpc_conf_free_rsets(conf);
list_del(&conf->sc_list);
- OBD_FREE_PTR(conf);
+ kfree(conf);
}

static
@@ -541,7 +539,7 @@ struct sptlrpc_conf_tgt *sptlrpc_conf_ge
if (!create)
return NULL;

- OBD_ALLOC_PTR(conf_tgt);
+ conf_tgt = kzalloc(sizeof(*conf_tgt), GFP_NOFS);
if (conf_tgt) {
strlcpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name));
sptlrpc_rule_set_init(&conf_tgt->sct_rset);
@@ -565,7 +563,7 @@ struct sptlrpc_conf *sptlrpc_conf_get(co
if (!create)
return NULL;

- OBD_ALLOC_PTR(conf);
+ conf = kzalloc(sizeof(*conf), GFP_NOFS);
if (conf == NULL)
return NULL;

diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
@@ -210,7 +210,7 @@ static void enc_pools_release_free_pages
/* free unused pools */
while (p_idx_max1 < p_idx_max2) {
LASSERT(page_pools.epp_pools[p_idx_max2]);
- OBD_FREE(page_pools.epp_pools[p_idx_max2], PAGE_CACHE_SIZE);
+ kfree(page_pools.epp_pools[p_idx_max2]);
page_pools.epp_pools[p_idx_max2] = NULL;
p_idx_max2--;
}
@@ -294,7 +294,7 @@ static unsigned long enc_pools_cleanup(s
cleaned++;
}
}
- OBD_FREE(pools[i], PAGE_CACHE_SIZE);
+ kfree(pools[i]);
pools[i] = NULL;
}
}
@@ -409,12 +409,12 @@ static int enc_pools_add_pages(int npage
page_pools.epp_st_grows++;

npools = npages_to_npools(npages);
- OBD_ALLOC(pools, npools * sizeof(*pools));
+ pools = kcalloc(npools, sizeof(*pools), GFP_NOFS);
if (pools == NULL)
goto out;

for (i = 0; i < npools; i++) {
- OBD_ALLOC(pools[i], PAGE_CACHE_SIZE);
+ pools[i] = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS);
if (pools[i] == NULL)
goto out_pools;

@@ -435,7 +435,7 @@ static int enc_pools_add_pages(int npage

out_pools:
enc_pools_cleanup(pools, npools);
- OBD_FREE(pools, npools * sizeof(*pools));
+ kfree(pools);
out:
if (rc) {
page_pools.epp_st_grow_fails++;
@@ -508,8 +508,8 @@ int sptlrpc_enc_pool_get_pages(struct pt
if (desc->bd_enc_iov != NULL)
return 0;

- OBD_ALLOC(desc->bd_enc_iov,
- desc->bd_iov_count * sizeof(*desc->bd_enc_iov));
+ desc->bd_enc_iov = kcalloc(desc->bd_iov_count,
+ sizeof(*desc->bd_enc_iov), GFP_NOFS);
if (desc->bd_enc_iov == NULL)
return -ENOMEM;

@@ -646,8 +646,7 @@ void sptlrpc_enc_pool_put_pages(struct p

spin_unlock(&page_pools.epp_lock);

- OBD_FREE(desc->bd_enc_iov,
- desc->bd_iov_count * sizeof(*desc->bd_enc_iov));
+ kfree(desc->bd_enc_iov);
desc->bd_enc_iov = NULL;
}
EXPORT_SYMBOL(sptlrpc_enc_pool_put_pages);
diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/sec.c b/drivers/staging/lustre/lustre/ptlrpc/sec.c
--- a/drivers/staging/lustre/lustre/ptlrpc/sec.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec.c
@@ -866,7 +866,7 @@ void sptlrpc_request_out_callback(struct
if (req->rq_pool || !req->rq_reqbuf)
return;

- OBD_FREE(req->rq_reqbuf, req->rq_reqbuf_len);
+ kfree(req->rq_reqbuf);
req->rq_reqbuf = NULL;
req->rq_reqbuf_len = 0;
}
diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
@@ -528,8 +528,9 @@ static int ptlrpcd_bind(int index, int m
}

if (rc == 0 && pc->pc_npartners > 0) {
- OBD_ALLOC(pc->pc_partners,
- sizeof(struct ptlrpcd_ctl *) * pc->pc_npartners);
+ pc->pc_partners = kcalloc(pc->pc_npartners,
+ sizeof(struct ptlrpcd_ctl *),
+ GFP_NOFS);
if (pc->pc_partners == NULL) {
pc->pc_npartners = 0;
rc = -ENOMEM;
@@ -699,8 +700,7 @@ out:
if (pc->pc_npartners > 0) {
LASSERT(pc->pc_partners != NULL);

- OBD_FREE(pc->pc_partners,
- sizeof(struct ptlrpcd_ctl *) * pc->pc_npartners);
+ kfree(pc->pc_partners);
pc->pc_partners = NULL;
}
pc->pc_npartners = 0;
@@ -717,7 +717,7 @@ static void ptlrpcd_fini(void)
ptlrpcd_free(&ptlrpcds->pd_threads[i]);
ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
ptlrpcd_free(&ptlrpcds->pd_thread_rcv);
- OBD_FREE(ptlrpcds, ptlrpcds->pd_size);
+ kfree(ptlrpcds);
ptlrpcds = NULL;
}
}
@@ -738,7 +738,7 @@ static int ptlrpcd_init(void)
nthreads &= ~1; /* make sure it is even */

size = offsetof(struct ptlrpcd, pd_threads[nthreads]);
- OBD_ALLOC(ptlrpcds, size);
+ ptlrpcds = kzalloc(size, GFP_NOFS);
if (ptlrpcds == NULL) {
rc = -ENOMEM;
goto out;
@@ -781,7 +781,7 @@ out:
ptlrpcd_free(&ptlrpcds->pd_threads[j]);
ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
ptlrpcd_free(&ptlrpcds->pd_thread_rcv);
- OBD_FREE(ptlrpcds, size);
+ kfree(ptlrpcds);
ptlrpcds = NULL;
}

diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c
--- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c
@@ -427,7 +427,7 @@ struct timeout_item *ptlrpc_new_timeout(
{
struct timeout_item *ti;

- OBD_ALLOC_PTR(ti);
+ ti = kzalloc(sizeof(*ti), GFP_NOFS);
if (!ti)
return NULL;

@@ -514,7 +514,7 @@ int ptlrpc_del_timeout_client(struct lis
LASSERTF(ti != NULL, "ti is NULL !\n");
if (list_empty(&ti->ti_obd_list)) {
list_del(&ti->ti_chain);
- OBD_FREE_PTR(ti);
+ kfree(ti);
}
mutex_unlock(&pinger_mutex);
return 0;
@@ -529,7 +529,7 @@ int ptlrpc_pinger_remove_timeouts(void)
list_for_each_entry_safe(item, tmp, &timeout_list, ti_chain) {
LASSERT(list_empty(&item->ti_obd_list));
list_del(&item->ti_chain);
- OBD_FREE_PTR(item);
+ kfree(item);
}
mutex_unlock(&pinger_mutex);
return 0;
diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/nrs_fifo.c b/drivers/staging/lustre/lustre/ptlrpc/nrs_fifo.c
--- a/drivers/staging/lustre/lustre/ptlrpc/nrs_fifo.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/nrs_fifo.c
@@ -105,7 +105,7 @@ static void nrs_fifo_stop(struct ptlrpc_
LASSERT(head != NULL);
LASSERT(list_empty(&head->fh_list));

- OBD_FREE_PTR(head);
+ kfree(head);
}

/**
diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/nrs.c b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
--- a/drivers/staging/lustre/lustre/ptlrpc/nrs.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
@@ -715,7 +715,7 @@ static int nrs_policy_unregister(struct
nrs_policy_fini(policy);

LASSERT(policy->pol_private == NULL);
- OBD_FREE_PTR(policy);
+ kfree(policy);

return 0;
}
@@ -761,7 +761,7 @@ static int nrs_policy_register(struct pt

rc = nrs_policy_init(policy);
if (rc != 0) {
- OBD_FREE_PTR(policy);
+ kfree(policy);
return rc;
}

@@ -776,7 +776,7 @@ static int nrs_policy_register(struct pt

spin_unlock(&nrs->nrs_lock);
nrs_policy_fini(policy);
- OBD_FREE_PTR(policy);
+ kfree(policy);

return -EEXIST;
}
@@ -1013,7 +1013,7 @@ again:
}

if (hp)
- OBD_FREE_PTR(nrs);
+ kfree(nrs);
}

/**
@@ -1153,7 +1153,7 @@ int ptlrpc_nrs_policy_register(struct pt
goto fail;
}

- OBD_ALLOC_PTR(desc);
+ desc = kzalloc(sizeof(*desc), GFP_NOFS);
if (desc == NULL) {
rc = -ENOMEM;
goto fail;
@@ -1210,7 +1210,7 @@ again:
*/
LASSERT(rc2 == 0);
mutex_unlock(&ptlrpc_all_services_mutex);
- OBD_FREE_PTR(desc);
+ kfree(desc);
goto fail;
}

@@ -1233,7 +1233,7 @@ again:
*/
LASSERT(rc2 == 0);
mutex_unlock(&ptlrpc_all_services_mutex);
- OBD_FREE_PTR(desc);
+ kfree(desc);
goto fail;
}
}
@@ -1301,7 +1301,7 @@ int ptlrpc_nrs_policy_unregister(struct
conf->nc_name);

list_del(&desc->pd_list);
- OBD_FREE_PTR(desc);
+ kfree(desc);

fail:
mutex_unlock(&ptlrpc_all_services_mutex);
@@ -1747,7 +1747,7 @@ void ptlrpc_nrs_fini(void)
list_for_each_entry_safe(desc, tmp, &nrs_core.nrs_policies,
pd_list) {
list_del_init(&desc->pd_list);
- OBD_FREE_PTR(desc);
+ kfree(desc);
}
}

diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
--- a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
@@ -507,7 +507,7 @@ static int ptlrpc_lprocfs_nrs_seq_show(s
num_pols = svc->srv_parts[0]->scp_nrs_reg.nrs_num_pols;
spin_unlock(&nrs->nrs_lock);

- OBD_ALLOC(infos, num_pols * sizeof(*infos));
+ infos = kcalloc(num_pols, sizeof(*infos), GFP_NOFS);
if (infos == NULL) {
rc = -ENOMEM;
goto out;
@@ -619,7 +619,7 @@ again:

out:
if (infos)
- OBD_FREE(infos, num_pols * sizeof(*infos));
+ kfree(infos);

mutex_unlock(&nrs_core.nrs_mutex);

@@ -655,7 +655,7 @@ static ssize_t ptlrpc_lprocfs_nrs_seq_wr
goto out;
}

- OBD_ALLOC(cmd, LPROCFS_NRS_WR_MAX_CMD);
+ cmd = kzalloc(LPROCFS_NRS_WR_MAX_CMD, GFP_NOFS);
if (cmd == NULL) {
rc = -ENOMEM;
goto out;
@@ -717,7 +717,7 @@ default_queue:
mutex_unlock(&nrs_core.nrs_mutex);
out:
if (cmd_copy)
- OBD_FREE(cmd_copy, LPROCFS_NRS_WR_MAX_CMD);
+ kfree(cmd_copy);

return rc < 0 ? rc : count;
}
@@ -825,7 +825,7 @@ ptlrpc_lprocfs_svc_req_history_start(str
return NULL;
}

- OBD_ALLOC(srhi, sizeof(*srhi));
+ srhi = kzalloc(sizeof(*srhi), GFP_NOFS);
if (srhi == NULL)
return NULL;

@@ -851,7 +851,7 @@ ptlrpc_lprocfs_svc_req_history_start(str
}
}

- OBD_FREE(srhi, sizeof(*srhi));
+ kfree(srhi);
return NULL;
}

@@ -861,7 +861,7 @@ ptlrpc_lprocfs_svc_req_history_stop(stru
struct ptlrpc_srh_iterator *srhi = iter;

if (srhi != NULL)
- OBD_FREE(srhi, sizeof(*srhi));
+ kfree(srhi);
}

static void *
@@ -895,7 +895,7 @@ ptlrpc_lprocfs_svc_req_history_next(stru
}
}

- OBD_FREE(srhi, sizeof(*srhi));
+ kfree(srhi);
return NULL;
}

@@ -1191,7 +1191,7 @@ int lprocfs_wr_evict_client(struct file
char *kbuf;
char *tmpbuf;

- OBD_ALLOC(kbuf, BUFLEN);
+ kbuf = kzalloc(BUFLEN, GFP_NOFS);
if (kbuf == NULL)
return -ENOMEM;

@@ -1225,7 +1225,7 @@ int lprocfs_wr_evict_client(struct file
class_decref(obd, __func__, current);

out:
- OBD_FREE(kbuf, BUFLEN);
+ kfree(kbuf);
return count;
}
EXPORT_SYMBOL(lprocfs_wr_evict_client);
@@ -1275,7 +1275,7 @@ int lprocfs_wr_import(struct file *file,
if (count > PAGE_CACHE_SIZE - 1 || count <= prefix_len)
return -EINVAL;

- OBD_ALLOC(kbuf, count + 1);
+ kbuf = kzalloc(count + 1, GFP_NOFS);
if (kbuf == NULL)
return -ENOMEM;

@@ -1319,7 +1319,7 @@ int lprocfs_wr_import(struct file *file,
ptlrpc_recover_import(imp, uuid, 1);

out:
- OBD_FREE(kbuf, count + 1);
+ kfree(kbuf);
return count;
}
EXPORT_SYMBOL(lprocfs_wr_import);
diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/connection.c b/drivers/staging/lustre/lustre/ptlrpc/connection.c
--- a/drivers/staging/lustre/lustre/ptlrpc/connection.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/connection.c
@@ -54,7 +54,7 @@ ptlrpc_connection_get(lnet_process_id_t
if (conn)
goto out;

- OBD_ALLOC_PTR(conn);
+ conn = kzalloc(sizeof(*conn), GFP_NOFS);
if (!conn)
return NULL;

@@ -76,7 +76,7 @@ ptlrpc_connection_get(lnet_process_id_t
/* coverity[overrun-buffer-val] */
conn2 = cfs_hash_findadd_unique(conn_hash, &peer, &conn->c_hash);
if (conn != conn2) {
- OBD_FREE_PTR(conn);
+ kfree(conn);
conn = conn2;
}
out:
@@ -227,7 +227,7 @@ conn_exit(struct cfs_hash *hs, struct hl
LASSERTF(atomic_read(&conn->c_refcount) == 0,
"Busy connection with %d refs\n",
atomic_read(&conn->c_refcount));
- OBD_FREE_PTR(conn);
+ kfree(conn);
}

static cfs_hash_ops_t conn_hash_ops = {
diff -u -p a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c
--- a/drivers/staging/lustre/lustre/ptlrpc/client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/client.c
@@ -103,7 +103,8 @@ struct ptlrpc_bulk_desc *ptlrpc_new_bulk
struct ptlrpc_bulk_desc *desc;
int i;

- OBD_ALLOC(desc, offsetof(struct ptlrpc_bulk_desc, bd_iov[npages]));
+ desc = kzalloc(offsetof(struct ptlrpc_bulk_desc, bd_iov[npages]),
+ GFP_NOFS);
if (!desc)
return NULL;

@@ -205,8 +206,7 @@ void __ptlrpc_free_bulk(struct ptlrpc_bu
page_cache_release(desc->bd_iov[i].kiov_page);
}

- OBD_FREE(desc, offsetof(struct ptlrpc_bulk_desc,
- bd_iov[desc->bd_max_iov]));
+ kfree(desc);
}
EXPORT_SYMBOL(__ptlrpc_free_bulk);

@@ -439,7 +439,7 @@ void ptlrpc_free_rq_pool(struct ptlrpc_r
ptlrpc_request_cache_free(req);
}
spin_unlock(&pool->prp_lock);
- OBD_FREE(pool, sizeof(*pool));
+ kfree(pool);
}
EXPORT_SYMBOL(ptlrpc_free_rq_pool);

@@ -498,7 +498,7 @@ ptlrpc_init_rq_pool(int num_rq, int msgs
{
struct ptlrpc_request_pool *pool;

- OBD_ALLOC(pool, sizeof(struct ptlrpc_request_pool));
+ pool = kzalloc(sizeof(struct ptlrpc_request_pool), GFP_NOFS);
if (!pool)
return NULL;

@@ -514,7 +514,7 @@ ptlrpc_init_rq_pool(int num_rq, int msgs

if (list_empty(&pool->prp_req_list)) {
/* have not allocated a single request for the pool */
- OBD_FREE(pool, sizeof(struct ptlrpc_request_pool));
+ kfree(pool);
pool = NULL;
}
return pool;
@@ -856,7 +856,7 @@ struct ptlrpc_request_set *ptlrpc_prep_s
{
struct ptlrpc_request_set *set;

- OBD_ALLOC(set, sizeof(*set));
+ set = kzalloc(sizeof(*set), GFP_NOFS);
if (!set)
return NULL;
atomic_set(&set->set_refcount, 1);
@@ -970,7 +970,7 @@ int ptlrpc_set_add_cb(struct ptlrpc_requ
{
struct ptlrpc_set_cbdata *cbdata;

- OBD_ALLOC_PTR(cbdata);
+ cbdata = kzalloc(sizeof(*cbdata), GFP_NOFS);
if (cbdata == NULL)
return -ENOMEM;

@@ -2214,7 +2214,7 @@ int ptlrpc_set_wait(struct ptlrpc_reques
err = cbdata->psc_interpret(set, cbdata->psc_data, rc);
if (err && !rc)
rc = err;
- OBD_FREE_PTR(cbdata);
+ kfree(cbdata);
}
}

2015-05-01 16:00:09

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 10/11] staging: lustre: osc: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/osc/osc_dev.c | 4 +-
drivers/staging/lustre/lustre/osc/osc_request.c | 33 ++++++++++++------------
2 files changed, 19 insertions(+), 18 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -110,7 +110,7 @@ static int osc_packmd(struct obd_export
return lmm_size;

if (*lmmp != NULL && lsm == NULL) {
- OBD_FREE(*lmmp, lmm_size);
+ kfree(*lmmp);
*lmmp = NULL;
return 0;
} else if (unlikely(lsm != NULL && ostid_id(&lsm->lsm_oi) == 0)) {
@@ -118,7 +118,7 @@ static int osc_packmd(struct obd_export
}

if (*lmmp == NULL) {
- OBD_ALLOC(*lmmp, lmm_size);
+ *lmmp = kzalloc(lmm_size, GFP_NOFS);
if (*lmmp == NULL)
return -ENOMEM;
}
@@ -157,19 +157,20 @@ static int osc_unpackmd(struct obd_expor
return lsm_size;

if (*lsmp != NULL && lmm == NULL) {
- OBD_FREE((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));
- OBD_FREE(*lsmp, lsm_size);
+ kfree((*lsmp)->lsm_oinfo[0]);
+ kfree(*lsmp);
*lsmp = NULL;
return 0;
}

if (*lsmp == NULL) {
- OBD_ALLOC(*lsmp, lsm_size);
+ *lsmp = kzalloc(lsm_size, GFP_NOFS);
if (unlikely(*lsmp == NULL))
return -ENOMEM;
- OBD_ALLOC((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));
+ (*lsmp)->lsm_oinfo[0] = kzalloc(sizeof(struct lov_oinfo),
+ GFP_NOFS);
if (unlikely((*lsmp)->lsm_oinfo[0] == NULL)) {
- OBD_FREE(*lsmp, lsm_size);
+ kfree(*lsmp);
return -ENOMEM;
}
loi_init((*lsmp)->lsm_oinfo[0]);
@@ -962,7 +963,7 @@ int osc_shrink_grant_to_target(struct cl
}
client_obd_list_unlock(&cli->cl_loi_list_lock);

- OBD_ALLOC_PTR(body);
+ body = kzalloc(sizeof(*body), GFP_NOFS);
if (!body)
return -ENOMEM;

@@ -984,7 +985,7 @@ int osc_shrink_grant_to_target(struct cl
sizeof(*body), body, NULL);
if (rc != 0)
__osc_update_grant(cli, body->oa.o_grant);
- OBD_FREE_PTR(body);
+ kfree(body);
return rc;
}

@@ -1748,7 +1749,7 @@ static void sort_brw_pages(struct brw_pa
static void osc_release_ppga(struct brw_page **ppga, u32 count)
{
LASSERT(ppga != NULL);
- OBD_FREE(ppga, sizeof(*ppga) * count);
+ kfree(ppga);
}

static int brw_interpret(const struct lu_env *env,
@@ -1908,13 +1909,13 @@ int osc_build_rpc(const struct lu_env *e
if (mem_tight)
mpflag = cfs_memory_pressure_get_and_set();

- OBD_ALLOC(crattr, sizeof(*crattr));
+ crattr = kzalloc(sizeof(*crattr), GFP_NOFS);
if (crattr == NULL) {
rc = -ENOMEM;
goto out;
}

- OBD_ALLOC(pga, sizeof(*pga) * page_count);
+ pga = kcalloc(page_count, sizeof(*pga), GFP_NOFS);
if (pga == NULL) {
rc = -ENOMEM;
goto out;
@@ -2055,7 +2056,7 @@ out:

if (crattr != NULL) {
capa_put(crattr->cra_capa);
- OBD_FREE(crattr, sizeof(*crattr));
+ kfree(crattr);
}

if (rc != 0) {
@@ -2064,7 +2065,7 @@ out:
if (oa)
OBDO_FREE(oa);
if (pga)
- OBD_FREE(pga, sizeof(*pga) * page_count);
+ kfree(pga);
/* this should happen rarely and is pretty bad, it makes the
* pending list not follow the dirty order */
while (!list_empty(ext_list)) {
@@ -2617,7 +2618,7 @@ static int osc_getstripe(struct lov_stri
* because lov_user_md_vX and lov_mds_md_vX have the same size */
if (lum.lmm_stripe_count > 0) {
lum_size = lov_mds_md_size(lum.lmm_stripe_count, lum.lmm_magic);
- OBD_ALLOC(lumk, lum_size);
+ lumk = kzalloc(lum_size, GFP_NOFS);
if (!lumk)
return -ENOMEM;

@@ -2639,7 +2640,7 @@ static int osc_getstripe(struct lov_stri
rc = -EFAULT;

if (lumk != &lum)
- OBD_FREE(lumk, lum_size);
+ kfree(lumk);

return rc;
}
diff -u -p a/drivers/staging/lustre/lustre/osc/osc_dev.c b/drivers/staging/lustre/lustre/osc/osc_dev.c
--- a/drivers/staging/lustre/lustre/osc/osc_dev.c
+++ b/drivers/staging/lustre/lustre/osc/osc_dev.c
@@ -204,7 +204,7 @@ static struct lu_device *osc_device_free
struct osc_device *od = lu2osc_dev(d);

cl_device_fini(lu2cl_dev(d));
- OBD_FREE_PTR(od);
+ kfree(od);
return NULL;
}

@@ -217,7 +217,7 @@ static struct lu_device *osc_device_allo
struct obd_device *obd;
int rc;

- OBD_ALLOC_PTR(od);
+ od = kzalloc(sizeof(*od), GFP_NOFS);
if (od == NULL)
return ERR_PTR(-ENOMEM);

2015-05-01 16:00:17

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 9/11] staging: lustre: obdecho: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/obdecho/echo_client.c | 42 ++++++++++----------
1 file changed, 21 insertions(+), 21 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c
--- a/drivers/staging/lustre/lustre/obdecho/echo_client.c
+++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c
@@ -479,13 +479,13 @@ static int echo_alloc_memmd(struct echo_
lsm_size = lov_stripe_md_size(1);

LASSERT(*lsmp == NULL);
- OBD_ALLOC(*lsmp, lsm_size);
+ *lsmp = kzalloc(lsm_size, GFP_NOFS);
if (*lsmp == NULL)
return -ENOMEM;

- OBD_ALLOC((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));
+ (*lsmp)->lsm_oinfo[0] = kzalloc(sizeof(struct lov_oinfo), GFP_NOFS);
if ((*lsmp)->lsm_oinfo[0] == NULL) {
- OBD_FREE(*lsmp, lsm_size);
+ kfree(*lsmp);
return -ENOMEM;
}

@@ -507,8 +507,8 @@ static int echo_free_memmd(struct echo_d
lsm_size = lov_stripe_md_size(1);

LASSERT(*lsmp != NULL);
- OBD_FREE((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));
- OBD_FREE(*lsmp, lsm_size);
+ kfree((*lsmp)->lsm_oinfo[0]);
+ kfree(*lsmp);
*lsmp = NULL;
return 0;
}
@@ -700,7 +700,7 @@ static struct lu_device *echo_device_all
int rc;
int cleanup = 0;

- OBD_ALLOC_PTR(ed);
+ ed = kzalloc(sizeof(*ed), GFP_NOFS);
if (ed == NULL) {
rc = -ENOMEM;
goto out;
@@ -798,7 +798,7 @@ out:
case 2:
cl_device_fini(&ed->ed_cl);
case 1:
- OBD_FREE_PTR(ed);
+ kfree(ed);
case 0:
default:
break;
@@ -895,7 +895,7 @@ static struct lu_device *echo_device_fre
LASSERT(ed->ed_site == lu2cl_site(d->ld_site));
echo_site_fini(env, ed);
cl_device_fini(&ed->ed_cl);
- OBD_FREE_PTR(ed);
+ kfree(ed);

return NULL;
}
@@ -1577,13 +1577,13 @@ static int echo_client_kbrw(struct echo_
if (rw == OBD_BRW_WRITE)
brw_flags = OBD_BRW_ASYNC;

- OBD_ALLOC(pga, npages * sizeof(*pga));
+ pga = kcalloc(npages, sizeof(*pga), GFP_NOFS);
if (pga == NULL)
return -ENOMEM;

- OBD_ALLOC(pages, npages * sizeof(*pages));
+ pages = kcalloc(npages, sizeof(*pages), GFP_NOFS);
if (pages == NULL) {
- OBD_FREE(pga, npages * sizeof(*pga));
+ kfree(pga);
return -ENOMEM;
}

@@ -1632,8 +1632,8 @@ static int echo_client_kbrw(struct echo_
}
OBD_PAGE_FREE(pgp->pg);
}
- OBD_FREE(pga, npages * sizeof(*pga));
- OBD_FREE(pages, npages * sizeof(*pages));
+ kfree(pga);
+ kfree(pages);
return rc;
}

@@ -1659,8 +1659,8 @@ static int echo_client_prep_commit(const
npages = batch >> PAGE_CACHE_SHIFT;
tot_pages = count >> PAGE_CACHE_SHIFT;

- OBD_ALLOC(lnb, npages * sizeof(struct niobuf_local));
- OBD_ALLOC(rnb, npages * sizeof(struct niobuf_remote));
+ lnb = kcalloc(npages, sizeof(struct niobuf_local), GFP_NOFS);
+ rnb = kcalloc(npages, sizeof(struct niobuf_remote), GFP_NOFS);

if (lnb == NULL || rnb == NULL) {
ret = -ENOMEM;
@@ -1738,9 +1738,9 @@ static int echo_client_prep_commit(const

out:
if (lnb)
- OBD_FREE(lnb, npages * sizeof(struct niobuf_local));
+ kfree(lnb);
if (rnb)
- OBD_FREE(rnb, npages * sizeof(struct niobuf_remote));
+ kfree(rnb);
return ret;
}

@@ -1879,7 +1879,7 @@ echo_client_iocontrol(unsigned int cmd,
if (rc < 0)
return rc;

- OBD_ALLOC_PTR(env);
+ env = kzalloc(sizeof(*env), GFP_NOFS);
if (env == NULL)
return -ENOMEM;

@@ -2010,7 +2010,7 @@ echo_client_iocontrol(unsigned int cmd,

out:
lu_env_fini(env);
- OBD_FREE_PTR(env);
+ kfree(env);

/* XXX this should be in a helper also called by target_send_reply */
for (ack_lock = dummy_oti.oti_ack_locks, i = 0; i < 4;
@@ -2050,7 +2050,7 @@ static int echo_client_setup(const struc
ec->ec_unique = 0;
ec->ec_nstripes = 0;

- OBD_ALLOC(ocd, sizeof(*ocd));
+ ocd = kzalloc(sizeof(*ocd), GFP_NOFS);
if (ocd == NULL) {
CERROR("Can't alloc ocd connecting to %s\n",
lustre_cfg_string(lcfg, 1));
@@ -2074,7 +2074,7 @@ static int echo_client_setup(const struc
spin_unlock(&tgt->obd_dev_lock);
}

- OBD_FREE(ocd, sizeof(*ocd));
+ kfree(ocd);

if (rc != 0) {
CERROR("fail to connect to device %s\n",

2015-05-01 16:06:31

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 8/11] staging: lustre: obdclass: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/obdclass/acl.c | 29 ++---
drivers/staging/lustre/lustre/obdclass/capa.c | 4
drivers/staging/lustre/lustre/obdclass/cl_io.c | 13 +-
drivers/staging/lustre/lustre/obdclass/cl_page.c | 2
drivers/staging/lustre/lustre/obdclass/class_obd.c | 4
drivers/staging/lustre/lustre/obdclass/genops.c | 40 +++----
drivers/staging/lustre/lustre/obdclass/llog.c | 24 ++--
drivers/staging/lustre/lustre/obdclass/llog_obd.c | 4
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 14 +-
drivers/staging/lustre/lustre/obdclass/lu_object.c | 6 -
drivers/staging/lustre/lustre/obdclass/lustre_handles.c | 2
drivers/staging/lustre/lustre/obdclass/lustre_peer.c | 6 -
drivers/staging/lustre/lustre/obdclass/obd_config.c | 50 ++++-----
drivers/staging/lustre/lustre/obdclass/obd_mount.c | 86 +++++++---------
14 files changed, 138 insertions(+), 146 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
--- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
@@ -84,7 +84,7 @@ int lustre_process_log(struct super_bloc
LASSERT(mgc);
LASSERT(cfg);

- OBD_ALLOC_PTR(bufs);
+ bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
if (bufs == NULL)
return -ENOMEM;

@@ -97,7 +97,7 @@ int lustre_process_log(struct super_bloc
rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
lustre_cfg_free(lcfg);

- OBD_FREE_PTR(bufs);
+ kfree(bufs);

if (rc == -EINVAL)
LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s' failed from the MGS (%d). Make sure this client and the MGS are running compatible versions of Lustre.\n",
@@ -247,8 +247,8 @@ int lustre_start_mgc(struct super_block
mutex_lock(&mgc_start_lock);

len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
- OBD_ALLOC(mgcname, len);
- OBD_ALLOC(niduuid, len + 2);
+ mgcname = kzalloc(len, GFP_NOFS);
+ niduuid = kzalloc(len + 2, GFP_NOFS);
if (!mgcname || !niduuid) {
rc = -ENOMEM;
goto out_free;
@@ -257,7 +257,7 @@ int lustre_start_mgc(struct super_block

mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";

- OBD_ALLOC_PTR(data);
+ data = kzalloc(sizeof(*data), GFP_NOFS);
if (data == NULL) {
rc = -ENOMEM;
goto out_free;
@@ -375,7 +375,7 @@ int lustre_start_mgc(struct super_block
lsi->lsi_lmd->lmd_mgs_failnodes = 1;

/* Random uuid for MGC allows easier reconnects */
- OBD_ALLOC_PTR(uuid);
+ uuid = kzalloc(sizeof(*uuid), GFP_NOFS);
if (!uuid) {
rc = -ENOMEM;
goto out_free;
@@ -388,7 +388,7 @@ int lustre_start_mgc(struct super_block
rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
(char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
niduuid, NULL, NULL);
- OBD_FREE_PTR(uuid);
+ kfree(uuid);
if (rc)
goto out_free;

@@ -465,11 +465,11 @@ out_free:
mutex_unlock(&mgc_start_lock);

if (data)
- OBD_FREE_PTR(data);
+ kfree(data);
if (mgcname)
- OBD_FREE(mgcname, len);
+ kfree(mgcname);
if (niduuid)
- OBD_FREE(niduuid, len + 2);
+ kfree(niduuid);
return rc;
}

@@ -513,7 +513,7 @@ static int lustre_stop_mgc(struct super_
/* Save the obdname for cleaning the nid uuids, which are
obdname_XX */
len = strlen(obd->obd_name) + 6;
- OBD_ALLOC(niduuid, len);
+ niduuid = kzalloc(len, GFP_NOFS);
if (niduuid) {
strcpy(niduuid, obd->obd_name);
ptr = niduuid + strlen(niduuid);
@@ -539,7 +539,7 @@ static int lustre_stop_mgc(struct super_
}
out:
if (niduuid)
- OBD_FREE(niduuid, len);
+ kfree(niduuid);

/* class_import_put will get rid of the additional connections */
mutex_unlock(&mgc_start_lock);
@@ -552,12 +552,12 @@ struct lustre_sb_info *lustre_init_lsi(s
{
struct lustre_sb_info *lsi;

- OBD_ALLOC_PTR(lsi);
+ lsi = kzalloc(sizeof(*lsi), GFP_NOFS);
if (!lsi)
return NULL;
- OBD_ALLOC_PTR(lsi->lsi_lmd);
+ lsi->lsi_lmd = kzalloc(sizeof(*lsi->lsi_lmd), GFP_NOFS);
if (!lsi->lsi_lmd) {
- OBD_FREE_PTR(lsi);
+ kfree(lsi);
return NULL;
}

@@ -586,35 +586,27 @@ static int lustre_free_lsi(struct super_

if (lsi->lsi_lmd != NULL) {
if (lsi->lsi_lmd->lmd_dev != NULL)
- OBD_FREE(lsi->lsi_lmd->lmd_dev,
- strlen(lsi->lsi_lmd->lmd_dev) + 1);
+ kfree(lsi->lsi_lmd->lmd_dev);
if (lsi->lsi_lmd->lmd_profile != NULL)
- OBD_FREE(lsi->lsi_lmd->lmd_profile,
- strlen(lsi->lsi_lmd->lmd_profile) + 1);
+ kfree(lsi->lsi_lmd->lmd_profile);
if (lsi->lsi_lmd->lmd_mgssec != NULL)
- OBD_FREE(lsi->lsi_lmd->lmd_mgssec,
- strlen(lsi->lsi_lmd->lmd_mgssec) + 1);
+ kfree(lsi->lsi_lmd->lmd_mgssec);
if (lsi->lsi_lmd->lmd_opts != NULL)
- OBD_FREE(lsi->lsi_lmd->lmd_opts,
- strlen(lsi->lsi_lmd->lmd_opts) + 1);
+ kfree(lsi->lsi_lmd->lmd_opts);
if (lsi->lsi_lmd->lmd_exclude_count)
- OBD_FREE(lsi->lsi_lmd->lmd_exclude,
- sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
- lsi->lsi_lmd->lmd_exclude_count);
+ kfree(lsi->lsi_lmd->lmd_exclude);
if (lsi->lsi_lmd->lmd_mgs != NULL)
- OBD_FREE(lsi->lsi_lmd->lmd_mgs,
- strlen(lsi->lsi_lmd->lmd_mgs) + 1);
+ kfree(lsi->lsi_lmd->lmd_mgs);
if (lsi->lsi_lmd->lmd_osd_type != NULL)
- OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
- strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
+ kfree(lsi->lsi_lmd->lmd_osd_type);
if (lsi->lsi_lmd->lmd_params != NULL)
- OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
+ kfree(lsi->lsi_lmd->lmd_params);

- OBD_FREE(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
+ kfree(lsi->lsi_lmd);
}

LASSERT(lsi->lsi_llsbi == NULL);
- OBD_FREE(lsi, sizeof(*lsi));
+ kfree(lsi);
s2lsi_nocast(sb) = NULL;

return 0;
@@ -846,7 +838,7 @@ static int lmd_make_exclusion(struct lus
devmax = strlen(ptr) / 8 + 1;

/* temp storage until we figure out how many we have */
- OBD_ALLOC(exclude_list, sizeof(index) * devmax);
+ exclude_list = kcalloc(devmax, sizeof(index), GFP_NOFS);
if (!exclude_list)
return -ENOMEM;

@@ -875,8 +867,8 @@ static int lmd_make_exclusion(struct lus

if (lmd->lmd_exclude_count) {
/* permanent, freed in lustre_free_lsi */
- OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
- lmd->lmd_exclude_count);
+ lmd->lmd_exclude = kcalloc(lmd->lmd_exclude_count,
+ sizeof(index), GFP_NOFS);
if (lmd->lmd_exclude) {
memcpy(lmd->lmd_exclude, exclude_list,
sizeof(index) * lmd->lmd_exclude_count);
@@ -885,7 +877,7 @@ static int lmd_make_exclusion(struct lus
lmd->lmd_exclude_count = 0;
}
}
- OBD_FREE(exclude_list, sizeof(index) * devmax);
+ kfree(exclude_list);
return rc;
}

@@ -895,7 +887,7 @@ static int lmd_parse_mgssec(struct lustr
int length;

if (lmd->lmd_mgssec != NULL) {
- OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
+ kfree(lmd->lmd_mgssec);
lmd->lmd_mgssec = NULL;
}

@@ -905,7 +897,7 @@ static int lmd_parse_mgssec(struct lustr
else
length = tail - ptr;

- OBD_ALLOC(lmd->lmd_mgssec, length + 1);
+ lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS);
if (lmd->lmd_mgssec == NULL)
return -ENOMEM;

@@ -923,7 +915,7 @@ static int lmd_parse_string(char **handl
return -EINVAL;

if (*handle != NULL) {
- OBD_FREE(*handle, strlen(*handle) + 1);
+ kfree(*handle);
*handle = NULL;
}

@@ -933,7 +925,7 @@ static int lmd_parse_string(char **handl
else
length = tail - ptr;

- OBD_ALLOC(*handle, length + 1);
+ *handle = kzalloc(length + 1, GFP_NOFS);
if (*handle == NULL)
return -ENOMEM;

@@ -963,7 +955,7 @@ static int lmd_parse_mgs(struct lustre_m
if (lmd->lmd_mgs != NULL)
oldlen = strlen(lmd->lmd_mgs) + 1;

- OBD_ALLOC(mgsnid, oldlen + length + 1);
+ mgsnid = kzalloc(oldlen + length + 1, GFP_NOFS);
if (mgsnid == NULL)
return -ENOMEM;

@@ -971,7 +963,7 @@ static int lmd_parse_mgs(struct lustre_m
/* Multiple mgsnid= are taken to mean failover locations */
memcpy(mgsnid, lmd->lmd_mgs, oldlen);
mgsnid[oldlen - 1] = ':';
- OBD_FREE(lmd->lmd_mgs, oldlen);
+ kfree(lmd->lmd_mgs);
}
memcpy(mgsnid + oldlen, *ptr, length);
mgsnid[oldlen + length] = '\0';
@@ -1005,7 +997,7 @@ static int lmd_parse(char *options, stru
}
lmd->lmd_magic = LMD_MAGIC;

- OBD_ALLOC(lmd->lmd_params, 4096);
+ lmd->lmd_params = kzalloc(4096, GFP_NOFS);
if (lmd->lmd_params == NULL)
return -ENOMEM;
lmd->lmd_params[0] = '\0';
@@ -1143,14 +1135,14 @@ static int lmd_parse(char *options, stru
/* Remove leading /s from fsname */
while (*++s1 == '/') ;
/* Freed in lustre_free_lsi */
- OBD_ALLOC(lmd->lmd_profile, strlen(s1) + 8);
+ lmd->lmd_profile = kzalloc(strlen(s1) + 8, GFP_NOFS);
if (!lmd->lmd_profile)
return -ENOMEM;
sprintf(lmd->lmd_profile, "%s-client", s1);
}

/* Freed in lustre_free_lsi */
- OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
+ lmd->lmd_dev = kzalloc(strlen(devname) + 1, GFP_NOFS);
if (!lmd->lmd_dev)
return -ENOMEM;
strcpy(lmd->lmd_dev, devname);
@@ -1161,7 +1153,7 @@ static int lmd_parse(char *options, stru
*s1-- = 0;
if (*options != 0) {
/* Freed in lustre_free_lsi */
- OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
+ lmd->lmd_opts = kzalloc(strlen(options) + 1, GFP_NOFS);
if (!lmd->lmd_opts)
return -ENOMEM;
strcpy(lmd->lmd_opts, options);
diff -u -p a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c
--- a/drivers/staging/lustre/lustre/obdclass/obd_config.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c
@@ -860,13 +860,13 @@ int class_add_profile(int proflen, char

CDEBUG(D_CONFIG, "Add profile %s\n", prof);

- OBD_ALLOC(lprof, sizeof(*lprof));
+ lprof = kzalloc(sizeof(*lprof), GFP_NOFS);
if (lprof == NULL)
return -ENOMEM;
INIT_LIST_HEAD(&lprof->lp_list);

LASSERT(proflen == (strlen(prof) + 1));
- OBD_ALLOC(lprof->lp_profile, proflen);
+ lprof->lp_profile = kzalloc(proflen, GFP_NOFS);
if (lprof->lp_profile == NULL) {
err = -ENOMEM;
goto out;
@@ -874,7 +874,7 @@ int class_add_profile(int proflen, char
memcpy(lprof->lp_profile, prof, proflen);

LASSERT(osclen == (strlen(osc) + 1));
- OBD_ALLOC(lprof->lp_dt, osclen);
+ lprof->lp_dt = kzalloc(osclen, GFP_NOFS);
if (lprof->lp_dt == NULL) {
err = -ENOMEM;
goto out;
@@ -883,7 +883,7 @@ int class_add_profile(int proflen, char

if (mdclen > 0) {
LASSERT(mdclen == (strlen(mdc) + 1));
- OBD_ALLOC(lprof->lp_md, mdclen);
+ lprof->lp_md = kzalloc(mdclen, GFP_NOFS);
if (lprof->lp_md == NULL) {
err = -ENOMEM;
goto out;
@@ -896,12 +896,12 @@ int class_add_profile(int proflen, char

out:
if (lprof->lp_md)
- OBD_FREE(lprof->lp_md, mdclen);
+ kfree(lprof->lp_md);
if (lprof->lp_dt)
- OBD_FREE(lprof->lp_dt, osclen);
+ kfree(lprof->lp_dt);
if (lprof->lp_profile)
- OBD_FREE(lprof->lp_profile, proflen);
- OBD_FREE(lprof, sizeof(*lprof));
+ kfree(lprof->lp_profile);
+ kfree(lprof);
return err;
}

@@ -914,11 +914,11 @@ void class_del_profile(const char *prof)
lprof = class_get_profile(prof);
if (lprof) {
list_del(&lprof->lp_list);
- OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
- OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
+ kfree(lprof->lp_profile);
+ kfree(lprof->lp_dt);
if (lprof->lp_md)
- OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
- OBD_FREE(lprof, sizeof(*lprof));
+ kfree(lprof->lp_md);
+ kfree(lprof);
}
}
EXPORT_SYMBOL(class_del_profile);
@@ -930,11 +930,11 @@ void class_del_profiles(void)

list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
list_del(&lprof->lp_list);
- OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
- OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
+ kfree(lprof->lp_profile);
+ kfree(lprof->lp_dt);
if (lprof->lp_md)
- OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
- OBD_FREE(lprof, sizeof(*lprof));
+ kfree(lprof->lp_md);
+ kfree(lprof);
}
}
EXPORT_SYMBOL(class_del_profiles);
@@ -1011,7 +1011,7 @@ struct lustre_cfg *lustre_cfg_rename(str

new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;

- OBD_ALLOC(new_param, new_len);
+ new_param = kzalloc(new_len, GFP_NOFS);
if (new_param == NULL)
return ERR_PTR(-ENOMEM);

@@ -1019,9 +1019,9 @@ struct lustre_cfg *lustre_cfg_rename(str
if (value != NULL)
strcat(new_param, value);

- OBD_ALLOC_PTR(bufs);
+ bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
if (bufs == NULL) {
- OBD_FREE(new_param, new_len);
+ kfree(new_param);
return ERR_PTR(-ENOMEM);
}

@@ -1031,8 +1031,8 @@ struct lustre_cfg *lustre_cfg_rename(str

new_cfg = lustre_cfg_new(cfg->lcfg_command, bufs);

- OBD_FREE(new_param, new_len);
- OBD_FREE_PTR(bufs);
+ kfree(new_param);
+ kfree(bufs);
if (new_cfg == NULL)
return ERR_PTR(-ENOMEM);

@@ -1493,7 +1493,7 @@ int class_config_llog_handler(const stru
inst = 1;
inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
sizeof(clli->cfg_instance) * 2 + 4;
- OBD_ALLOC(inst_name, inst_len);
+ inst_name = kzalloc(inst_len, GFP_NOFS);
if (inst_name == NULL) {
rc = -ENOMEM;
goto out;
@@ -1556,7 +1556,7 @@ int class_config_llog_handler(const stru
lustre_cfg_free(lcfg_new);

if (inst)
- OBD_FREE(inst_name, inst_len);
+ kfree(inst_name);
break;
}
default:
@@ -1671,7 +1671,7 @@ int class_config_dump_handler(const stru
char *outstr;
int rc = 0;

- OBD_ALLOC(outstr, 256);
+ outstr = kzalloc(256, GFP_NOFS);
if (outstr == NULL)
return -ENOMEM;

@@ -1683,7 +1683,7 @@ int class_config_dump_handler(const stru
rc = -EINVAL;
}

- OBD_FREE(outstr, 256);
+ kfree(outstr);
return rc;
}

diff -u -p a/drivers/staging/lustre/lustre/obdclass/lustre_peer.c b/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
--- a/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
+++ b/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
@@ -104,7 +104,7 @@ int class_add_uuid(const char *uuid, __u
if (strlen(uuid) > UUID_MAX - 1)
return -EOVERFLOW;

- OBD_ALLOC_PTR(data);
+ data = kzalloc(sizeof(*data), GFP_NOFS);
if (data == NULL)
return -ENOMEM;

@@ -136,7 +136,7 @@ int class_add_uuid(const char *uuid, __u
if (found) {
CDEBUG(D_INFO, "found uuid %s %s cnt=%d\n", uuid,
libcfs_nid2str(nid), entry->un_nid_count);
- OBD_FREE(data, sizeof(*data));
+ kfree(data);
} else {
CDEBUG(D_INFO, "add uuid %s %s\n", uuid, libcfs_nid2str(nid));
}
@@ -180,7 +180,7 @@ int class_del_uuid(const char *uuid)
libcfs_nid2str(data->un_nids[0]),
data->un_nid_count);

- OBD_FREE(data, sizeof(*data));
+ kfree(data);
}

return 0;
diff -u -p a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
--- a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
+++ b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
@@ -186,7 +186,7 @@ void class_handle_free_cb(struct rcu_hea
if (h->h_ops->hop_free != NULL)
h->h_ops->hop_free(ptr, h->h_size);
else
- OBD_FREE(ptr, h->h_size);
+ kfree(ptr);
}
EXPORT_SYMBOL(class_handle_free_cb);

diff -u -p a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c
--- a/drivers/staging/lustre/lustre/obdclass/lu_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c
@@ -1532,7 +1532,7 @@ static void keys_fini(struct lu_context
for (i = 0; i < ARRAY_SIZE(lu_keys); ++i)
key_fini(ctx, i);

- OBD_FREE(ctx->lc_value, ARRAY_SIZE(lu_keys) * sizeof(ctx->lc_value[0]));
+ kfree(ctx->lc_value);
ctx->lc_value = NULL;
}

@@ -1581,8 +1581,8 @@ static int keys_fill(struct lu_context *

static int keys_init(struct lu_context *ctx)
{
- OBD_ALLOC(ctx->lc_value,
- ARRAY_SIZE(lu_keys) * sizeof(ctx->lc_value[0]));
+ ctx->lc_value = kcalloc(ARRAY_SIZE(lu_keys), sizeof(ctx->lc_value[0]),
+ GFP_NOFS);
if (likely(ctx->lc_value != NULL))
return keys_fill(ctx);

diff -u -p a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -276,7 +276,7 @@ struct proc_dir_entry *lprocfs_add_symli
if (parent == NULL || format == NULL)
return NULL;

- OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
+ dest = kzalloc(MAX_STRING_SIZE + 1, GFP_KERNEL);
if (dest == NULL)
return NULL;

@@ -289,7 +289,7 @@ struct proc_dir_entry *lprocfs_add_symli
CERROR("LprocFS: Could not create symbolic link from %s to %s",
name, dest);

- OBD_FREE(dest, MAX_STRING_SIZE + 1);
+ kfree(dest);
return entry;
}
EXPORT_SYMBOL(lprocfs_add_symlink);
@@ -1006,7 +1006,7 @@ static void lprocfs_free_client_stats(st
if (client_stat->nid_ldlm_stats)
lprocfs_free_stats(&client_stat->nid_ldlm_stats);

- OBD_FREE_PTR(client_stat);
+ kfree(client_stat);
return;

}
@@ -1681,7 +1681,7 @@ int lprocfs_exp_setup(struct obd_export

CDEBUG(D_CONFIG, "using hash %p\n", obd->obd_nid_stats_hash);

- OBD_ALLOC_PTR(new_stat);
+ new_stat = kzalloc(sizeof(*new_stat), GFP_NOFS);
if (new_stat == NULL)
return -ENOMEM;

@@ -1711,7 +1711,7 @@ int lprocfs_exp_setup(struct obd_export
goto destroy_new;
}
/* not found - create */
- OBD_ALLOC(buffer, LNET_NIDSTR_SIZE);
+ buffer = kzalloc(LNET_NIDSTR_SIZE, GFP_NOFS);
if (buffer == NULL) {
rc = -ENOMEM;
goto destroy_new;
@@ -1721,7 +1721,7 @@ int lprocfs_exp_setup(struct obd_export
new_stat->nid_proc = lprocfs_register(buffer,
obd->obd_proc_exports_entry,
NULL, NULL);
- OBD_FREE(buffer, LNET_NIDSTR_SIZE);
+ kfree(buffer);

if (IS_ERR(new_stat->nid_proc)) {
CERROR("Error making export directory for nid %s\n",
@@ -1763,7 +1763,7 @@ destroy_new_ns:

destroy_new:
nidstat_putref(new_stat);
- OBD_FREE_PTR(new_stat);
+ kfree(new_stat);
return rc;
}
EXPORT_SYMBOL(lprocfs_exp_setup);
diff -u -p a/drivers/staging/lustre/lustre/obdclass/llog_obd.c b/drivers/staging/lustre/lustre/obdclass/llog_obd.c
--- a/drivers/staging/lustre/lustre/obdclass/llog_obd.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog_obd.c
@@ -46,7 +46,7 @@ static struct llog_ctxt *llog_new_ctxt(s
{
struct llog_ctxt *ctxt;

- OBD_ALLOC_PTR(ctxt);
+ ctxt = kzalloc(sizeof(*ctxt), GFP_NOFS);
if (!ctxt)
return NULL;

@@ -66,7 +66,7 @@ static void llog_ctxt_destroy(struct llo
class_import_put(ctxt->loc_imp);
ctxt->loc_imp = NULL;
}
- OBD_FREE_PTR(ctxt);
+ kfree(ctxt);
}

int __llog_ctxt_put(const struct lu_env *env, struct llog_ctxt *ctxt)
diff -u -p a/drivers/staging/lustre/lustre/obdclass/llog.c b/drivers/staging/lustre/lustre/obdclass/llog.c
--- a/drivers/staging/lustre/lustre/obdclass/llog.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog.c
@@ -60,7 +60,7 @@ static struct llog_handle *llog_alloc_ha
{
struct llog_handle *loghandle;

- OBD_ALLOC_PTR(loghandle);
+ loghandle = kzalloc(sizeof(*loghandle), GFP_NOFS);
if (loghandle == NULL)
return NULL;

@@ -88,9 +88,9 @@ static void llog_free_handle(struct llog
else if (loghandle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)
LASSERT(list_empty(&loghandle->u.chd.chd_head));
LASSERT(sizeof(*(loghandle->lgh_hdr)) == LLOG_CHUNK_SIZE);
- OBD_FREE(loghandle->lgh_hdr, LLOG_CHUNK_SIZE);
+ kfree(loghandle->lgh_hdr);
out:
- OBD_FREE_PTR(loghandle);
+ kfree(loghandle);
}

void llog_handle_get(struct llog_handle *loghandle)
@@ -207,7 +207,7 @@ int llog_init_handle(const struct lu_env

LASSERT(handle->lgh_hdr == NULL);

- OBD_ALLOC_PTR(llh);
+ llh = kzalloc(sizeof(*llh), GFP_NOFS);
if (llh == NULL)
return -ENOMEM;
handle->lgh_hdr = llh;
@@ -261,7 +261,7 @@ int llog_init_handle(const struct lu_env
}
out:
if (rc) {
- OBD_FREE_PTR(llh);
+ kfree(llh);
handle->lgh_hdr = NULL;
}
return rc;
@@ -283,7 +283,7 @@ static int llog_process_thread(void *arg

LASSERT(llh);

- OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
+ buf = kzalloc(LLOG_CHUNK_SIZE, GFP_NOFS);
if (!buf) {
lpi->lpi_rc = -ENOMEM;
return 0;
@@ -400,7 +400,7 @@ out:
if (cd != NULL)
cd->lpcd_last_idx = last_called_index;

- OBD_FREE(buf, LLOG_CHUNK_SIZE);
+ kfree(buf);
lpi->lpi_rc = rc;
return 0;
}
@@ -434,7 +434,7 @@ int llog_process_or_fork(const struct lu
struct llog_process_info *lpi;
int rc;

- OBD_ALLOC_PTR(lpi);
+ lpi = kzalloc(sizeof(*lpi), GFP_NOFS);
if (lpi == NULL) {
CERROR("cannot alloc pointer\n");
return -ENOMEM;
@@ -454,7 +454,7 @@ int llog_process_or_fork(const struct lu
if (IS_ERR_VALUE(rc)) {
CERROR("%s: cannot start thread: rc = %d\n",
loghandle->lgh_ctxt->loc_obd->obd_name, rc);
- OBD_FREE_PTR(lpi);
+ kfree(lpi);
return rc;
}
wait_for_completion(&lpi->lpi_completion);
@@ -463,7 +463,7 @@ int llog_process_or_fork(const struct lu
llog_process_thread(lpi);
}
rc = lpi->lpi_rc;
- OBD_FREE_PTR(lpi);
+ kfree(lpi);
return rc;
}
EXPORT_SYMBOL(llog_process_or_fork);
@@ -484,7 +484,7 @@ int llog_reverse_process(const struct lu
void *buf;
int rc = 0, first_index = 1, index, idx;

- OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
+ buf = kzalloc(LLOG_CHUNK_SIZE, GFP_NOFS);
if (!buf)
return -ENOMEM;

@@ -564,7 +564,7 @@ int llog_reverse_process(const struct lu

out:
if (buf)
- OBD_FREE(buf, LLOG_CHUNK_SIZE);
+ kfree(buf);
return rc;
}
EXPORT_SYMBOL(llog_reverse_process);
diff -u -p a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c
--- a/drivers/staging/lustre/lustre/obdclass/genops.c
+++ b/drivers/staging/lustre/lustre/obdclass/genops.c
@@ -171,13 +171,13 @@ int class_register_type(struct obd_ops *
}

rc = -ENOMEM;
- OBD_ALLOC(type, sizeof(*type));
+ type = kzalloc(sizeof(*type), GFP_NOFS);
if (type == NULL)
return rc;

- OBD_ALLOC_PTR(type->typ_dt_ops);
- OBD_ALLOC_PTR(type->typ_md_ops);
- OBD_ALLOC(type->typ_name, strlen(name) + 1);
+ type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS);
+ type->typ_md_ops = kzalloc(sizeof(*type->typ_md_ops), GFP_NOFS);
+ type->typ_name = kzalloc(strlen(name) + 1, GFP_NOFS);

if (type->typ_dt_ops == NULL ||
type->typ_md_ops == NULL ||
@@ -214,12 +214,12 @@ int class_register_type(struct obd_ops *

failed:
if (type->typ_name != NULL)
- OBD_FREE(type->typ_name, strlen(name) + 1);
+ kfree(type->typ_name);
if (type->typ_md_ops != NULL)
- OBD_FREE_PTR(type->typ_md_ops);
+ kfree(type->typ_md_ops);
if (type->typ_dt_ops != NULL)
- OBD_FREE_PTR(type->typ_dt_ops);
- OBD_FREE(type, sizeof(*type));
+ kfree(type->typ_dt_ops);
+ kfree(type);
return rc;
}
EXPORT_SYMBOL(class_register_type);
@@ -237,8 +237,8 @@ int class_unregister_type(const char *na
CERROR("type %s has refcount (%d)\n", name, type->typ_refcnt);
/* This is a bad situation, let's make the best of it */
/* Remove ops, but leave the name for debugging */
- OBD_FREE_PTR(type->typ_dt_ops);
- OBD_FREE_PTR(type->typ_md_ops);
+ kfree(type->typ_dt_ops);
+ kfree(type->typ_md_ops);
return -EBUSY;
}

@@ -252,12 +252,12 @@ int class_unregister_type(const char *na
spin_lock(&obd_types_lock);
list_del(&type->typ_chain);
spin_unlock(&obd_types_lock);
- OBD_FREE(type->typ_name, strlen(name) + 1);
+ kfree(type->typ_name);
if (type->typ_dt_ops != NULL)
- OBD_FREE_PTR(type->typ_dt_ops);
+ kfree(type->typ_dt_ops);
if (type->typ_md_ops != NULL)
- OBD_FREE_PTR(type->typ_md_ops);
- OBD_FREE(type, sizeof(*type));
+ kfree(type->typ_md_ops);
+ kfree(type);
return 0;
} /* class_unregister_type */
EXPORT_SYMBOL(class_unregister_type);
@@ -819,7 +819,7 @@ struct obd_export *class_new_export(stru
struct cfs_hash *hash = NULL;
int rc = 0;

- OBD_ALLOC_PTR(export);
+ export = kzalloc(sizeof(*export), GFP_NOFS);
if (!export)
return ERR_PTR(-ENOMEM);

@@ -904,7 +904,7 @@ exit_err:
class_handle_unhash(&export->exp_handle);
LASSERT(hlist_unhashed(&export->exp_uuid_hash));
obd_destroy_export(export);
- OBD_FREE_PTR(export);
+ kfree(export);
return ERR_PTR(rc);
}
EXPORT_SYMBOL(class_new_export);
@@ -945,7 +945,7 @@ static void class_import_destroy(struct
struct obd_import_conn, oic_item);
list_del_init(&imp_conn->oic_item);
ptlrpc_put_connection_superhack(imp_conn->oic_conn);
- OBD_FREE(imp_conn, sizeof(*imp_conn));
+ kfree(imp_conn);
}

LASSERT(imp->imp_sec == NULL);
@@ -1008,7 +1008,7 @@ struct obd_import *class_new_import(stru
{
struct obd_import *imp;

- OBD_ALLOC(imp, sizeof(*imp));
+ imp = kzalloc(sizeof(*imp), GFP_NOFS);
if (imp == NULL)
return NULL;

@@ -1811,7 +1811,7 @@ void *kuc_alloc(int payload_len, int tra
struct kuc_hdr *lh;
int len = kuc_len(payload_len);

- OBD_ALLOC(lh, len);
+ lh = kzalloc(len, GFP_NOFS);
if (lh == NULL)
return ERR_PTR(-ENOMEM);

@@ -1828,6 +1828,6 @@ EXPORT_SYMBOL(kuc_alloc);
inline void kuc_free(void *p, int payload_len)
{
struct kuc_hdr *lh = kuc_ptr(p);
- OBD_FREE(lh, kuc_len(payload_len));
+ kfree(lh);
}
EXPORT_SYMBOL(kuc_free);
diff -u -p a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c
--- a/drivers/staging/lustre/lustre/obdclass/class_obd.c
+++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c
@@ -231,7 +231,7 @@ int class_handle_ioctl(unsigned int cmd,
err = -EINVAL;
goto out;
}
- OBD_ALLOC(lcfg, data->ioc_plen1);
+ lcfg = kzalloc(data->ioc_plen1, GFP_NOFS);
if (lcfg == NULL) {
err = -ENOMEM;
goto out;
@@ -243,7 +243,7 @@ int class_handle_ioctl(unsigned int cmd,
if (!err)
err = class_process_config(lcfg);

- OBD_FREE(lcfg, data->ioc_plen1);
+ kfree(lcfg);
goto out;
}

diff -u -p a/drivers/staging/lustre/lustre/obdclass/cl_page.c b/drivers/staging/lustre/lustre/obdclass/cl_page.c
--- a/drivers/staging/lustre/lustre/obdclass/cl_page.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_page.c
@@ -270,7 +270,7 @@ static void cl_page_free(const struct lu
lu_object_ref_del_at(&obj->co_lu, &page->cp_obj_ref, "cl_page", page);
cl_object_put(env, obj);
lu_ref_fini(&page->cp_reference);
- OBD_FREE(page, pagesize);
+ kfree(page);
}

/**
diff -u -p a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c
--- a/drivers/staging/lustre/lustre/obdclass/cl_io.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c
@@ -612,7 +612,7 @@ EXPORT_SYMBOL(cl_io_lock_add);
static void cl_free_io_lock_link(const struct lu_env *env,
struct cl_io_lock_link *link)
{
- OBD_FREE_PTR(link);
+ kfree(link);
}

/**
@@ -624,7 +624,7 @@ int cl_io_lock_alloc_add(const struct lu
struct cl_io_lock_link *link;
int result;

- OBD_ALLOC_PTR(link);
+ link = kzalloc(sizeof(*link), GFP_NOFS);
if (link != NULL) {
link->cill_descr = *descr;
link->cill_fini = cl_free_io_lock_link;
@@ -1387,9 +1387,9 @@ static void cl_req_free(const struct lu_
cl_object_put(env, obj);
}
}
- OBD_FREE(req->crq_o, req->crq_nrobjs * sizeof(req->crq_o[0]));
+ kfree(req->crq_o);
}
- OBD_FREE_PTR(req);
+ kfree(req);
}

static int cl_req_init(const struct lu_env *env, struct cl_req *req,
@@ -1448,7 +1448,7 @@ struct cl_req *cl_req_alloc(const struct

LINVRNT(nr_objects > 0);

- OBD_ALLOC_PTR(req);
+ req = kzalloc(sizeof(*req), GFP_NOFS);
if (req != NULL) {
int result;

@@ -1456,7 +1456,8 @@ struct cl_req *cl_req_alloc(const struct
INIT_LIST_HEAD(&req->crq_pages);
INIT_LIST_HEAD(&req->crq_layers);

- OBD_ALLOC(req->crq_o, nr_objects * sizeof(req->crq_o[0]));
+ req->crq_o = kcalloc(nr_objects, sizeof(req->crq_o[0]),
+ GFP_NOFS);
if (req->crq_o != NULL) {
req->crq_nrobjs = nr_objects;
result = cl_req_init(env, req, page);
diff -u -p a/drivers/staging/lustre/lustre/obdclass/capa.c b/drivers/staging/lustre/lustre/obdclass/capa.c
--- a/drivers/staging/lustre/lustre/obdclass/capa.c
+++ b/drivers/staging/lustre/lustre/obdclass/capa.c
@@ -87,7 +87,7 @@ struct hlist_head *init_capa_hash(void)
struct hlist_head *hash;
int nr_hash, i;

- OBD_ALLOC(hash, PAGE_CACHE_SIZE);
+ hash = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS);
if (!hash)
return NULL;

@@ -129,7 +129,7 @@ void cleanup_capa_hash(struct hlist_head
}
spin_unlock(&capa_lock);

- OBD_FREE(hash, PAGE_CACHE_SIZE);
+ kfree(hash);
}
EXPORT_SYMBOL(cleanup_capa_hash);

diff -u -p a/drivers/staging/lustre/lustre/obdclass/acl.c b/drivers/staging/lustre/lustre/obdclass/acl.c
--- a/drivers/staging/lustre/lustre/obdclass/acl.c
+++ b/drivers/staging/lustre/lustre/obdclass/acl.c
@@ -104,12 +104,12 @@ static int lustre_posix_acl_xattr_reduce
if (unlikely(old_count <= new_count))
return old_size;

- OBD_ALLOC(new, new_size);
+ new = kzalloc(new_size, GFP_NOFS);
if (unlikely(new == NULL))
return -ENOMEM;

memcpy(new, *header, new_size);
- OBD_FREE(*header, old_size);
+ kfree(*header);
*header = new;
return new_size;
}
@@ -126,12 +126,12 @@ static int lustre_ext_acl_xattr_reduce_s
if (unlikely(old_count <= ext_count))
return 0;

- OBD_ALLOC(new, ext_size);
+ new = kzalloc(ext_size, GFP_NOFS);
if (unlikely(new == NULL))
return -ENOMEM;

memcpy(new, *header, ext_size);
- OBD_FREE(*header, old_size);
+ kfree(*header);
*header = new;
return 0;
}
@@ -152,7 +152,7 @@ lustre_posix_acl_xattr_2ext(posix_acl_xa
else
count = CFS_ACL_XATTR_COUNT(size, posix_acl_xattr);
esize = CFS_ACL_XATTR_SIZE(count, ext_acl_xattr);
- OBD_ALLOC(new, esize);
+ new = kzalloc(esize, GFP_NOFS);
if (unlikely(new == NULL))
return ERR_PTR(-ENOMEM);

@@ -183,7 +183,7 @@ int lustre_posix_acl_xattr_filter(posix_
if (size < sizeof(*new))
return -EINVAL;

- OBD_ALLOC(new, size);
+ new = kzalloc(size, GFP_NOFS);
if (unlikely(new == NULL))
return -ENOMEM;

@@ -232,7 +232,7 @@ int lustre_posix_acl_xattr_filter(posix_

_out:
if (rc) {
- OBD_FREE(new, size);
+ kfree(new);
size = rc;
}
return size;
@@ -244,7 +244,7 @@ EXPORT_SYMBOL(lustre_posix_acl_xattr_fil
*/
void lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size)
{
- OBD_FREE(header, size);
+ kfree(header);
}
EXPORT_SYMBOL(lustre_posix_acl_xattr_free);

@@ -253,8 +253,7 @@ EXPORT_SYMBOL(lustre_posix_acl_xattr_fre
*/
void lustre_ext_acl_xattr_free(ext_acl_xattr_header *header)
{
- OBD_FREE(header, CFS_ACL_XATTR_SIZE(le32_to_cpu(header->a_count), \
- ext_acl_xattr));
+ kfree(header);
}
EXPORT_SYMBOL(lustre_ext_acl_xattr_free);

@@ -309,7 +308,7 @@ int lustre_acl_xattr_merge2posix(posix_a
/* there are only base ACL entries at most. */
posix_count = 3;
posix_size = CFS_ACL_XATTR_SIZE(posix_count, posix_acl_xattr);
- OBD_ALLOC(new, posix_size);
+ new = kzalloc(posix_size, GFP_NOFS);
if (unlikely(new == NULL))
return -ENOMEM;

@@ -360,7 +359,7 @@ int lustre_acl_xattr_merge2posix(posix_a
posix_count = ori_posix_count + ext_count;
posix_size =
CFS_ACL_XATTR_SIZE(posix_count, posix_acl_xattr);
- OBD_ALLOC(new, posix_size);
+ new = kzalloc(posix_size, GFP_NOFS);
if (unlikely(new == NULL))
return -ENOMEM;

@@ -402,7 +401,7 @@ int lustre_acl_xattr_merge2posix(posix_a

_out:
if (rc) {
- OBD_FREE(new, posix_size);
+ kfree(new);
posix_size = rc;
}
return posix_size;
@@ -432,7 +431,7 @@ lustre_acl_xattr_merge2ext(posix_acl_xat
ext_count = posix_count + ori_ext_count;
ext_size = CFS_ACL_XATTR_SIZE(ext_count, ext_acl_xattr);

- OBD_ALLOC(new, ext_size);
+ new = kzalloc(ext_size, GFP_NOFS);
if (unlikely(new == NULL))
return ERR_PTR(-ENOMEM);

@@ -538,7 +537,7 @@ lustre_acl_xattr_merge2ext(posix_acl_xat

out:
if (rc) {
- OBD_FREE(new, ext_size);
+ kfree(new);
new = ERR_PTR(rc);
}
return new;

2015-05-01 16:06:29

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 7/11] staging: lustre: mgc: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/mgc/mgc_request.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -149,7 +149,7 @@ static void config_log_put(struct config
sptlrpc_conf_log_stop(cld->cld_logname);

class_export_put(cld->cld_mgcexp);
- OBD_FREE(cld, sizeof(*cld) + strlen(cld->cld_logname) + 1);
+ kfree(cld);
}
}

@@ -198,7 +198,7 @@ struct config_llog_data *do_config_log_a
CDEBUG(D_MGC, "do adding config log %s:%p\n", logname,
cfg ? cfg->cfg_instance : NULL);

- OBD_ALLOC(cld, sizeof(*cld) + strlen(logname) + 1);
+ cld = kzalloc(sizeof(*cld) + strlen(logname) + 1, GFP_NOFS);
if (!cld)
return ERR_PTR(-ENOMEM);

@@ -1129,14 +1129,14 @@ static int mgc_apply_recover_logs(struct
LASSERT(cfg->cfg_instance != NULL);
LASSERT(cfg->cfg_sb == cfg->cfg_instance);

- OBD_ALLOC(inst, PAGE_CACHE_SIZE);
+ inst = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS);
if (inst == NULL)
return -ENOMEM;

if (!IS_SERVER(lsi)) {
pos = snprintf(inst, PAGE_CACHE_SIZE, "%p", cfg->cfg_instance);
if (pos >= PAGE_CACHE_SIZE) {
- OBD_FREE(inst, PAGE_CACHE_SIZE);
+ kfree(inst);
return -E2BIG;
}
} else {
@@ -1144,7 +1144,7 @@ static int mgc_apply_recover_logs(struct
rc = server_name2svname(lsi->lsi_svname, inst, NULL,
PAGE_CACHE_SIZE);
if (rc) {
- OBD_FREE(inst, PAGE_CACHE_SIZE);
+ kfree(inst);
return -EINVAL;
}
pos = strlen(inst);
@@ -1302,7 +1302,7 @@ static int mgc_apply_recover_logs(struct
/* continue, even one with error */
}

- OBD_FREE(inst, PAGE_CACHE_SIZE);
+ kfree(inst);
return rc;
}

@@ -1336,7 +1336,7 @@ static int mgc_process_recover_log(struc
if (cfg->cfg_last_idx == 0) /* the first time */
nrpages = CONFIG_READ_NRPAGES_INIT;

- OBD_ALLOC(pages, sizeof(*pages) * nrpages);
+ pages = kcalloc(nrpages, sizeof(*pages), GFP_NOFS);
if (pages == NULL) {
rc = -ENOMEM;
goto out;
@@ -1466,7 +1466,7 @@ out:
break;
__free_page(pages[i]);
}
- OBD_FREE(pages, sizeof(*pages) * nrpages);
+ kfree(pages);
}
return rc;
}
@@ -1494,7 +1494,7 @@ static int mgc_process_cfg_log(struct ob
if (cld->cld_cfg.cfg_sb)
lsi = s2lsi(cld->cld_cfg.cfg_sb);

- OBD_ALLOC_PTR(env);
+ env = kzalloc(sizeof(*env), GFP_NOFS);
if (env == NULL)
return -ENOMEM;

@@ -1540,7 +1540,7 @@ out_pop:

lu_env_fini(env);
out_free:
- OBD_FREE_PTR(env);
+ kfree(env);
return rc;
}

2015-05-01 16:06:28

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 6/11] staging: lustre: mdc: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/mdc/lproc_mdc.c | 4 +--
drivers/staging/lustre/lustre/mdc/mdc_locks.c | 2 -
drivers/staging/lustre/lustre/mdc/mdc_request.c | 30 ++++++++++++------------
3 files changed, 18 insertions(+), 18 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -1201,7 +1201,7 @@ static int mdc_ioc_fid2path(struct obd_e

/* Key is KEY_FID2PATH + getinfo_fid2path description */
keylen = cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf);
- OBD_ALLOC(key, keylen);
+ key = kzalloc(keylen, GFP_NOFS);
if (key == NULL)
return -ENOMEM;
memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH));
@@ -1234,7 +1234,7 @@ static int mdc_ioc_fid2path(struct obd_e
PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path);

out:
- OBD_FREE(key, keylen);
+ kfree(key);
return rc;
}

@@ -1604,7 +1604,7 @@ static int mdc_changelog_send_thread(voi
CDEBUG(D_CHANGELOG, "changelog to fp=%p start %llu\n",
cs->cs_fp, cs->cs_startrec);

- OBD_ALLOC(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE);
+ cs->cs_buf = kzalloc(KUC_CHANGELOG_MSG_MAXSIZE, GFP_NOFS);
if (cs->cs_buf == NULL) {
rc = -ENOMEM;
goto out;
@@ -1645,8 +1645,8 @@ out:
if (ctxt)
llog_ctxt_put(ctxt);
if (cs->cs_buf)
- OBD_FREE(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE);
- OBD_FREE_PTR(cs);
+ kfree(cs->cs_buf);
+ kfree(cs);
return rc;
}

@@ -1657,7 +1657,7 @@ static int mdc_ioc_changelog_send(struct
int rc;

/* Freed in mdc_changelog_send_thread */
- OBD_ALLOC_PTR(cs);
+ cs = kzalloc(sizeof(*cs), GFP_NOFS);
if (!cs)
return -ENOMEM;

@@ -1679,7 +1679,7 @@ static int mdc_ioc_changelog_send(struct
}

CERROR("Failed to start changelog thread: %d\n", rc);
- OBD_FREE_PTR(cs);
+ kfree(cs);
return rc;
}

@@ -1937,7 +1937,7 @@ static int mdc_iocontrol(unsigned int cm
struct if_quotactl *qctl = karg;
struct obd_quotactl *oqctl;

- OBD_ALLOC_PTR(oqctl);
+ oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
if (oqctl == NULL) {
rc = -ENOMEM;
goto out;
@@ -1951,7 +1951,7 @@ static int mdc_iocontrol(unsigned int cm
qctl->obd_uuid = obd->u.cli.cl_target_uuid;
}

- OBD_FREE_PTR(oqctl);
+ kfree(oqctl);
goto out;
}
case LL_IOC_GET_CONNECT_FLAGS:
@@ -2430,14 +2430,14 @@ static int mdc_setup(struct obd_device *
struct lprocfs_static_vars lvars = { NULL };
int rc;

- OBD_ALLOC(cli->cl_rpc_lock, sizeof(*cli->cl_rpc_lock));
+ cli->cl_rpc_lock = kzalloc(sizeof(*cli->cl_rpc_lock), GFP_NOFS);
if (!cli->cl_rpc_lock)
return -ENOMEM;
mdc_init_rpc_lock(cli->cl_rpc_lock);

ptlrpcd_addref();

- OBD_ALLOC(cli->cl_close_lock, sizeof(*cli->cl_close_lock));
+ cli->cl_close_lock = kzalloc(sizeof(*cli->cl_close_lock), GFP_NOFS);
if (!cli->cl_close_lock) {
rc = -ENOMEM;
goto err_rpc_lock;
@@ -2465,9 +2465,9 @@ static int mdc_setup(struct obd_device *
return rc;

err_close_lock:
- OBD_FREE(cli->cl_close_lock, sizeof(*cli->cl_close_lock));
+ kfree(cli->cl_close_lock);
err_rpc_lock:
- OBD_FREE(cli->cl_rpc_lock, sizeof(*cli->cl_rpc_lock));
+ kfree(cli->cl_rpc_lock);
ptlrpcd_decref();
return rc;
}
@@ -2525,8 +2525,8 @@ static int mdc_cleanup(struct obd_device
{
struct client_obd *cli = &obd->u.cli;

- OBD_FREE(cli->cl_rpc_lock, sizeof(*cli->cl_rpc_lock));
- OBD_FREE(cli->cl_close_lock, sizeof(*cli->cl_close_lock));
+ kfree(cli->cl_rpc_lock);
+ kfree(cli->cl_close_lock);

ptlrpcd_decref();

diff -u -p a/drivers/staging/lustre/lustre/mdc/mdc_locks.c b/drivers/staging/lustre/lustre/mdc/mdc_locks.c
--- a/drivers/staging/lustre/lustre/mdc/mdc_locks.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_locks.c
@@ -1251,7 +1251,7 @@ static int mdc_intent_getattr_async_inte
rc = mdc_finish_intent_lock(exp, req, &minfo->mi_data, it, lockh);

out:
- OBD_FREE_PTR(einfo);
+ kfree(einfo);
minfo->mi_cb(req, minfo, rc);
return 0;
}
diff -u -p a/drivers/staging/lustre/lustre/mdc/lproc_mdc.c b/drivers/staging/lustre/lustre/mdc/lproc_mdc.c
--- a/drivers/staging/lustre/lustre/mdc/lproc_mdc.c
+++ b/drivers/staging/lustre/lustre/mdc/lproc_mdc.c
@@ -106,7 +106,7 @@ static ssize_t mdc_kuc_write(struct file
len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
/* for mockup below */ 2 * cfs_size_round(sizeof(*hai));

- OBD_ALLOC(lh, len);
+ lh = kzalloc(len, GFP_NOFS);
if (!lh)
return -ENOMEM;

@@ -141,7 +141,7 @@ static ssize_t mdc_kuc_write(struct file
rc = libcfs_kkuc_msg_put(fp, lh);
fput(fp);
}
- OBD_FREE(lh, len);
+ kfree(lh);
if (rc < 0)
return rc;
return count;

2015-05-01 16:05:16

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 5/11] staging: lustre: lmv: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/lmv/lmv_intent.c | 4 +--
drivers/staging/lustre/lustre/lmv/lmv_obd.c | 28 ++++++++++++-------------
2 files changed, 16 insertions(+), 16 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
--- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
@@ -442,7 +442,7 @@ static void lmv_del_target(struct lmv_ob
if (lmv->tgts[index] == NULL)
return;

- OBD_FREE_PTR(lmv->tgts[index]);
+ kfree(lmv->tgts[index]);
lmv->tgts[index] = NULL;
return;
}
@@ -488,7 +488,7 @@ static int lmv_add_target(struct obd_dev

while (newsize < index + 1)
newsize <<= 1;
- OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
+ newtgts = kcalloc(newsize, sizeof(*newtgts), GFP_NOFS);
if (newtgts == NULL) {
lmv_init_unlock(lmv);
return -ENOMEM;
@@ -505,13 +505,13 @@ static int lmv_add_target(struct obd_dev
lmv->tgts_size = newsize;
smp_rmb();
if (old)
- OBD_FREE(old, sizeof(*old) * oldsize);
+ kfree(old);

CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
lmv->tgts_size);
}

- OBD_ALLOC_PTR(tgt);
+ tgt = kzalloc(sizeof(*tgt), GFP_NOFS);
if (!tgt) {
lmv_init_unlock(lmv);
return -ENOMEM;
@@ -750,7 +750,7 @@ repeat_fid2path:
/* sigh, has to go to another MDT to do path building further */
if (remote_gf == NULL) {
remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
- OBD_ALLOC(remote_gf, remote_gf_size);
+ remote_gf = kzalloc(remote_gf_size, GFP_NOFS);
if (remote_gf == NULL) {
rc = -ENOMEM;
goto out_fid2path;
@@ -781,7 +781,7 @@ repeat_fid2path:

out_fid2path:
if (remote_gf != NULL)
- OBD_FREE(remote_gf, remote_gf_size);
+ kfree(remote_gf);
return rc;
}

@@ -984,7 +984,7 @@ static int lmv_iocontrol(unsigned int cm
return -EAGAIN;

LASSERT(tgt && tgt->ltd_exp);
- OBD_ALLOC_PTR(oqctl);
+ oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
if (!oqctl)
return -ENOMEM;

@@ -995,7 +995,7 @@ static int lmv_iocontrol(unsigned int cm
qctl->qc_valid = QC_MDTIDX;
qctl->obd_uuid = tgt->ltd_uuid;
}
- OBD_FREE_PTR(oqctl);
+ kfree(oqctl);
break;
}
case OBD_IOC_CHANGELOG_SEND:
@@ -1327,7 +1327,7 @@ static int lmv_setup(struct obd_device *
return -EINVAL;
}

- OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
+ lmv->tgts = kcalloc(32, sizeof(*lmv->tgts), GFP_NOFS);
if (lmv->tgts == NULL)
return -ENOMEM;
lmv->tgts_size = 32;
@@ -1380,7 +1380,7 @@ static int lmv_cleanup(struct obd_device
continue;
lmv_del_target(lmv, i);
}
- OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
+ kfree(lmv->tgts);
lmv->tgts_size = 0;
}
return 0;
@@ -1437,7 +1437,7 @@ static int lmv_statfs(const struct lu_en
if (rc)
return rc;

- OBD_ALLOC(temp, sizeof(*temp));
+ temp = kzalloc(sizeof(*temp), GFP_NOFS);
if (temp == NULL)
return -ENOMEM;

@@ -1473,7 +1473,7 @@ static int lmv_statfs(const struct lu_en
}

out_free_temp:
- OBD_FREE(temp, sizeof(*temp));
+ kfree(temp);
return rc;
}

@@ -1769,7 +1769,7 @@ lmv_enqueue_remote(struct obd_export *ex
goto out;
}

- OBD_ALLOC_PTR(rdata);
+ rdata = kzalloc(sizeof(*rdata), GFP_NOFS);
if (rdata == NULL) {
rc = -ENOMEM;
goto out;
@@ -1780,7 +1780,7 @@ lmv_enqueue_remote(struct obd_export *ex

rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
lmm, lmmsize, NULL, extra_lock_flags);
- OBD_FREE_PTR(rdata);
+ kfree(rdata);
out:
ldlm_lock_decref(&plock, pmode);
return rc;
diff -u -p a/drivers/staging/lustre/lustre/lmv/lmv_intent.c b/drivers/staging/lustre/lustre/lmv/lmv_intent.c
--- a/drivers/staging/lustre/lustre/lmv/lmv_intent.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_intent.c
@@ -99,7 +99,7 @@ static int lmv_intent_remote(struct obd_
goto out;
}

- OBD_ALLOC_PTR(op_data);
+ op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
if (op_data == NULL) {
rc = -ENOMEM;
goto out;
@@ -142,7 +142,7 @@ static int lmv_intent_remote(struct obd_
it->d.lustre.it_lock_mode = pmode;

out_free_op_data:
- OBD_FREE_PTR(op_data);
+ kfree(op_data);
out:
if (rc && pmode)
ldlm_lock_decref(&plock, pmode);

2015-05-01 16:04:19

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 4/11] staging: lustre: ldlm: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/ldlm/ldlm_lib.c | 6 +++---
drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 10 +++++-----
drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 14 +++++++-------
drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 10 +++++-----
drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 8 ++++----
5 files changed, 24 insertions(+), 24 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
@@ -590,7 +590,7 @@ struct ldlm_namespace *ldlm_namespace_ne
break;
}

- OBD_ALLOC_PTR(ns);
+ ns = kzalloc(sizeof(*ns), GFP_NOFS);
if (!ns)
goto out_ref;

@@ -657,7 +657,7 @@ out_proc:
out_hash:
cfs_hash_putref(ns->ns_rs_hash);
out_ns:
- OBD_FREE_PTR(ns);
+ kfree(ns);
out_ref:
ldlm_put_ref();
return NULL;
@@ -904,7 +904,7 @@ void ldlm_namespace_free_post(struct ldl
* this will cause issues related to using freed \a ns in poold
* thread. */
LASSERT(list_empty(&ns->ns_list_chain));
- OBD_FREE_PTR(ns);
+ kfree(ns);
ldlm_put_ref();
}

@@ -1138,7 +1138,7 @@ ldlm_resource_get(struct ldlm_namespace
ns->ns_obd->obd_name, name->name[0],
name->name[1], rc);
if (res->lr_lvb_data) {
- OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
+ kfree(res->lr_lvb_data);
res->lr_lvb_data = NULL;
}
res->lr_lvb_len = rc;
diff -u -p a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
@@ -746,7 +746,7 @@ static int ldlm_pool_proc_init(struct ld
char *var_name = NULL;
int rc = 0;

- OBD_ALLOC(var_name, MAX_STRING_SIZE + 1);
+ var_name = kzalloc(MAX_STRING_SIZE + 1, GFP_NOFS);
if (!var_name)
return -ENOMEM;

@@ -828,7 +828,7 @@ static int ldlm_pool_proc_init(struct ld
rc = lprocfs_register_stats(pl->pl_proc_dir, "stats", pl->pl_stats);

out_free_name:
- OBD_FREE(var_name, MAX_STRING_SIZE + 1);
+ kfree(var_name);
return rc;
}

@@ -1383,7 +1383,7 @@ static int ldlm_pools_thread_start(void)
if (ldlm_pools_thread != NULL)
return -EALREADY;

- OBD_ALLOC_PTR(ldlm_pools_thread);
+ ldlm_pools_thread = kzalloc(sizeof(*ldlm_pools_thread), GFP_NOFS);
if (ldlm_pools_thread == NULL)
return -ENOMEM;

@@ -1394,7 +1394,7 @@ static int ldlm_pools_thread_start(void)
"ldlm_poold");
if (IS_ERR(task)) {
CERROR("Can't start pool thread, error %ld\n", PTR_ERR(task));
- OBD_FREE(ldlm_pools_thread, sizeof(*ldlm_pools_thread));
+ kfree(ldlm_pools_thread);
ldlm_pools_thread = NULL;
return PTR_ERR(task);
}
@@ -1417,7 +1417,7 @@ static void ldlm_pools_thread_stop(void)
* in pools thread.
*/
wait_for_completion(&ldlm_pools_comp);
- OBD_FREE_PTR(ldlm_pools_thread);
+ kfree(ldlm_pools_thread);
ldlm_pools_thread = NULL;
}

diff -u -p a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
@@ -220,7 +220,7 @@ static void ldlm_handle_cp_callback(stru
* variable length */
void *lvb_data;

- OBD_ALLOC(lvb_data, lvb_len);
+ lvb_data = kzalloc(lvb_len, GFP_NOFS);
if (lvb_data == NULL) {
LDLM_ERROR(lock, "No memory: %d.\n", lvb_len);
rc = -ENOMEM;
@@ -448,7 +448,7 @@ static int ldlm_bl_to_thread(struct ldlm
if (cancel_flags & LCF_ASYNC) {
struct ldlm_bl_work_item *blwi;

- OBD_ALLOC(blwi, sizeof(*blwi));
+ blwi = kzalloc(sizeof(*blwi), GFP_NOFS);
if (blwi == NULL)
return -ENOMEM;
init_blwi(blwi, ns, ld, cancels, count, lock, cancel_flags);
@@ -849,7 +849,7 @@ static int ldlm_bl_thread_main(void *arg
memory_pressure_clr();

if (blwi->blwi_flags & LCF_ASYNC)
- OBD_FREE(blwi, sizeof(*blwi));
+ kfree(blwi);
else
complete(&blwi->blwi_comp);
}
@@ -1012,7 +1012,7 @@ static int ldlm_setup(void)
if (ldlm_state != NULL)
return -EALREADY;

- OBD_ALLOC(ldlm_state, sizeof(*ldlm_state));
+ ldlm_state = kzalloc(sizeof(*ldlm_state), GFP_NOFS);
if (ldlm_state == NULL)
return -ENOMEM;

@@ -1059,7 +1059,7 @@ static int ldlm_setup(void)
}


- OBD_ALLOC(blp, sizeof(*blp));
+ blp = kzalloc(sizeof(*blp), GFP_NOFS);
if (blp == NULL) {
rc = -ENOMEM;
goto out;
@@ -1129,7 +1129,7 @@ static int ldlm_cleanup(void)
wait_for_completion(&blp->blp_comp);
}

- OBD_FREE(blp, sizeof(*blp));
+ kfree(blp);
}

if (ldlm_state->ldlm_cb_service != NULL)
@@ -1138,7 +1138,7 @@ static int ldlm_cleanup(void)
ldlm_proc_cleanup();


- OBD_FREE(ldlm_state, sizeof(*ldlm_state));
+ kfree(ldlm_state);
ldlm_state = NULL;

return 0;
diff -u -p a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -209,7 +209,7 @@ void ldlm_lock_put(struct ldlm_lock *loc
}

if (lock->l_lvb_data != NULL)
- OBD_FREE(lock->l_lvb_data, lock->l_lvb_len);
+ kfree(lock->l_lvb_data);

ldlm_interval_free(ldlm_interval_detach(lock));
lu_ref_fini(&lock->l_reference);
@@ -1527,7 +1527,7 @@ struct ldlm_lock *ldlm_lock_create(struc

if (lvb_len) {
lock->l_lvb_len = lvb_len;
- OBD_ALLOC(lock->l_lvb_data, lvb_len);
+ lock->l_lvb_data = kzalloc(lvb_len, GFP_NOFS);
if (lock->l_lvb_data == NULL)
goto out;
}
@@ -1791,7 +1791,7 @@ int ldlm_work_gl_ast_lock(struct ptlrpc_
LDLM_LOCK_RELEASE(lock);

if ((gl_work->gl_flags & LDLM_GL_WORK_NOFREE) == 0)
- OBD_FREE_PTR(gl_work);
+ kfree(gl_work);

return rc;
}
@@ -1812,7 +1812,7 @@ int ldlm_run_ast_work(struct ldlm_namesp
if (list_empty(rpc_list))
return 0;

- OBD_ALLOC_PTR(arg);
+ arg = kzalloc(sizeof(*arg), GFP_NOFS);
if (arg == NULL)
return -ENOMEM;

@@ -1857,7 +1857,7 @@ int ldlm_run_ast_work(struct ldlm_namesp
rc = atomic_read(&arg->restart) ? -ERESTART : 0;
goto out;
out:
- OBD_FREE_PTR(arg);
+ kfree(arg);
return rc;
}

diff -u -p a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
@@ -73,7 +73,7 @@ static int import_set_conn(struct obd_im
}

if (create) {
- OBD_ALLOC(imp_conn, sizeof(*imp_conn));
+ imp_conn = kzalloc(sizeof(*imp_conn), GFP_NOFS);
if (!imp_conn) {
rc = -ENOMEM;
goto out_put;
@@ -120,7 +120,7 @@ static int import_set_conn(struct obd_im
return 0;
out_free:
if (imp_conn)
- OBD_FREE(imp_conn, sizeof(*imp_conn));
+ kfree(imp_conn);
out_put:
ptlrpc_connection_put(ptlrpc_conn);
return rc;
@@ -179,7 +179,7 @@ int client_import_del_conn(struct obd_im

list_del(&imp_conn->oic_item);
ptlrpc_connection_put(imp_conn->oic_conn);
- OBD_FREE(imp_conn, sizeof(*imp_conn));
+ kfree(imp_conn);
CDEBUG(D_HA, "imp %p@%s: remove connection %s\n",
imp, imp->imp_obd->obd_name, uuid->uuid);
rc = 0;

2015-05-01 16:04:16

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 3/11] staging: lustre: lclient: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/lclient/lcommon_cl.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/lclient/lcommon_cl.c b/drivers/staging/lustre/lustre/lclient/lcommon_cl.c
--- a/drivers/staging/lustre/lustre/lclient/lcommon_cl.c
+++ b/drivers/staging/lustre/lustre/lclient/lcommon_cl.c
@@ -202,7 +202,7 @@ struct lu_device *ccc_device_alloc(const
struct cl_site *site;
int rc;

- OBD_ALLOC_PTR(vdv);
+ vdv = kzalloc(sizeof(*vdv), GFP_NOFS);
if (vdv == NULL)
return ERR_PTR(-ENOMEM);

@@ -211,7 +211,7 @@ struct lu_device *ccc_device_alloc(const
ccc2lu_dev(vdv)->ld_ops = luops;
vdv->cdv_cl.cd_ops = clops;

- OBD_ALLOC_PTR(site);
+ site = kzalloc(sizeof(*site), GFP_NOFS);
if (site != NULL) {
rc = cl_site_init(site, &vdv->cdv_cl);
if (rc == 0)
@@ -219,7 +219,7 @@ struct lu_device *ccc_device_alloc(const
else {
LASSERT(lud->ld_site == NULL);
CERROR("Cannot init lu_site, rc %d.\n", rc);
- OBD_FREE_PTR(site);
+ kfree(site);
}
} else
rc = -ENOMEM;
@@ -239,10 +239,10 @@ struct lu_device *ccc_device_free(const

if (d->ld_site != NULL) {
cl_site_fini(site);
- OBD_FREE_PTR(site);
+ kfree(site);
}
cl_device_fini(lu2cl_dev(d));
- OBD_FREE_PTR(vdv);
+ kfree(vdv);
return next;
}

2015-05-01 16:02:55

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/fld/fld_cache.c | 16 ++++++++--------
drivers/staging/lustre/lustre/fld/fld_request.c | 8 ++++----
2 files changed, 12 insertions(+), 12 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/fld/fld_request.c b/drivers/staging/lustre/lustre/fld/fld_request.c
--- a/drivers/staging/lustre/lustre/fld/fld_request.c
+++ b/drivers/staging/lustre/lustre/fld/fld_request.c
@@ -221,7 +221,7 @@ int fld_client_add_target(struct lu_clie
CDEBUG(D_INFO, "%s: Adding target %s (idx %llu)\n",
fld->lcf_name, name, tar->ft_idx);

- OBD_ALLOC_PTR(target);
+ target = kzalloc(sizeof(*target), GFP_NOFS);
if (target == NULL)
return -ENOMEM;

@@ -229,7 +229,7 @@ int fld_client_add_target(struct lu_clie
list_for_each_entry(tmp, &fld->lcf_targets, ft_chain) {
if (tmp->ft_idx == tar->ft_idx) {
spin_unlock(&fld->lcf_lock);
- OBD_FREE_PTR(target);
+ kfree(target);
CERROR("Target %s exists in FLD and known as %s:#%llu\n",
name, fld_target_name(tmp), tmp->ft_idx);
return -EEXIST;
@@ -268,7 +268,7 @@ int fld_client_del_target(struct lu_clie
if (target->ft_exp != NULL)
class_export_put(target->ft_exp);

- OBD_FREE_PTR(target);
+ kfree(target);
return 0;
}
}
@@ -396,7 +396,7 @@ void fld_client_fini(struct lu_client_fl
list_del(&target->ft_chain);
if (target->ft_exp != NULL)
class_export_put(target->ft_exp);
- OBD_FREE_PTR(target);
+ kfree(target);
}
spin_unlock(&fld->lcf_lock);

diff -u -p a/drivers/staging/lustre/lustre/fld/fld_cache.c b/drivers/staging/lustre/lustre/fld/fld_cache.c
--- a/drivers/staging/lustre/lustre/fld/fld_cache.c
+++ b/drivers/staging/lustre/lustre/fld/fld_cache.c
@@ -69,7 +69,7 @@ struct fld_cache *fld_cache_init(const c
LASSERT(name != NULL);
LASSERT(cache_threshold < cache_size);

- OBD_ALLOC_PTR(cache);
+ cache = kzalloc(sizeof(*cache), GFP_NOFS);
if (cache == NULL)
return ERR_PTR(-ENOMEM);

@@ -116,7 +116,7 @@ void fld_cache_fini(struct fld_cache *ca
CDEBUG(D_INFO, " Cache reqs: %llu\n", cache->fci_stat.fst_cache);
CDEBUG(D_INFO, " Cache hits: %llu%%\n", pct);

- OBD_FREE_PTR(cache);
+ kfree(cache);
}

/**
@@ -128,7 +128,7 @@ void fld_cache_entry_delete(struct fld_c
list_del(&node->fce_list);
list_del(&node->fce_lru);
cache->fci_cache_count--;
- OBD_FREE_PTR(node);
+ kfree(node);
}

/**
@@ -268,7 +268,7 @@ static void fld_cache_punch_hole(struct

OBD_ALLOC_GFP(fldt, sizeof(*fldt), GFP_ATOMIC);
if (!fldt) {
- OBD_FREE_PTR(f_new);
+ kfree(f_new);
/* overlap is not allowed, so dont mess up list. */
return;
}
@@ -315,7 +315,7 @@ static void fld_cache_overlap_handle(str
f_curr->fce_range.lsr_end = max(f_curr->fce_range.lsr_end,
new_end);

- OBD_FREE_PTR(f_new);
+ kfree(f_new);
fld_fix_new_list(cache);

} else if (new_start <= f_curr->fce_range.lsr_start &&
@@ -324,7 +324,7 @@ static void fld_cache_overlap_handle(str
* e.g. whole range migrated. update fld cache entry */

f_curr->fce_range = *range;
- OBD_FREE_PTR(f_new);
+ kfree(f_new);
fld_fix_new_list(cache);

} else if (f_curr->fce_range.lsr_start < new_start &&
@@ -364,7 +364,7 @@ struct fld_cache_entry

LASSERT(range_is_sane(range));

- OBD_ALLOC_PTR(f_new);
+ f_new = kzalloc(sizeof(*f_new), GFP_NOFS);
if (!f_new)
return ERR_PTR(-ENOMEM);

@@ -440,7 +440,7 @@ int fld_cache_insert(struct fld_cache *c
rc = fld_cache_insert_nolock(cache, flde);
write_unlock(&cache->fci_lock);
if (rc)
- OBD_FREE_PTR(flde);
+ kfree(flde);

return rc;
}

2015-05-01 16:00:19

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 1/11] staging: lustre: fid: Use kzalloc and kfree

From: Julia Lawall <[email protected]>

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/lustre/lustre/fid/fid_request.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff -u -p a/drivers/staging/lustre/lustre/fid/fid_request.c b/drivers/staging/lustre/lustre/fid/fid_request.c
--- a/drivers/staging/lustre/lustre/fid/fid_request.c
+++ b/drivers/staging/lustre/lustre/fid/fid_request.c
@@ -505,11 +505,11 @@ int client_fid_init(struct obd_device *o
char *prefix;
int rc;

- OBD_ALLOC_PTR(cli->cl_seq);
+ cli->cl_seq = kzalloc(sizeof(*cli->cl_seq), GFP_NOFS);
if (cli->cl_seq == NULL)
return -ENOMEM;

- OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
+ prefix = kzalloc(MAX_OBD_NAME + 5, GFP_NOFS);
if (prefix == NULL) {
rc = -ENOMEM;
goto out_free_seq;
@@ -519,13 +519,13 @@ int client_fid_init(struct obd_device *o

/* Init client side sequence-manager */
rc = seq_client_init(cli->cl_seq, exp, type, prefix, NULL);
- OBD_FREE(prefix, MAX_OBD_NAME + 5);
+ kfree(prefix);
if (rc)
goto out_free_seq;

return rc;
out_free_seq:
- OBD_FREE_PTR(cli->cl_seq);
+ kfree(cli->cl_seq);
cli->cl_seq = NULL;
return rc;
}
@@ -537,7 +537,7 @@ int client_fid_fini(struct obd_device *o

if (cli->cl_seq != NULL) {
seq_client_fini(cli->cl_seq);
- OBD_FREE_PTR(cli->cl_seq);
+ kfree(cli->cl_seq);
cli->cl_seq = NULL;
}

2015-05-01 17:48:31

by Simmons, James A.

[permalink] [raw]
Subject: RE: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

>From: Julia Lawall <[email protected]>
>
>Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
>kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

Nak: James Simmons <[email protected]>

A simple replace will not work. The OBD_ALLOC and OBD_FREE functions allocate memory
anywhere from one page to 4MB in size. You can't use kmalloc for the 4MB allocations.
Currently lustre uses a 4 page water mark to determine if we allocate using vmalloc. Even
using kmalloc for 4 pages has shown high failure rates on some systems. It gets even more
messy with 64K page systems like ppc64 boxes. Now I'm not suggesting to port the larger
allocations to vmalloc either since issues have been founded with using vmalloc. For example
when using large stripe count files the MDS rpc generated crosses the 4 page line and vmalloc
is used. Using vmalloc caused a global spinlock to be taken which causes meta data operations
to serialized on the MDS servers.

2015-05-01 17:48:27

by Julia Lawall

[permalink] [raw]
Subject: RE: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

On Fri, 1 May 2015, Simmons, James A. wrote:

> >From: Julia Lawall <[email protected]>
> >
> >Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
> >kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.
>
> Nak: James Simmons <[email protected]>
>
> A simple replace will not work. The OBD_ALLOC and OBD_FREE functions allocate memory
> anywhere from one page to 4MB in size. You can't use kmalloc for the 4MB allocations.
> Currently lustre uses a 4 page water mark to determine if we allocate using vmalloc. Even
> using kmalloc for 4 pages has shown high failure rates on some systems. It gets even more
> messy with 64K page systems like ppc64 boxes. Now I'm not suggesting to port the larger
> allocations to vmalloc either since issues have been founded with using vmalloc. For example
> when using large stripe count files the MDS rpc generated crosses the 4 page line and vmalloc
> is used. Using vmalloc caused a global spinlock to be taken which causes meta data operations
> to serialized on the MDS servers.

It's not the LARGE functions that do the switching? For example OBD_ALLOC
ends up at __OBD_MALLOC_VERBOSE, which as far as I can see calls kmalloc
(with __GFP_ZERO, and hance the use of kzalloc).

julia

2015-05-01 18:05:44

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

On Fri, May 01, 2015 at 05:38:49PM +0000, Simmons, James A. wrote:
> >From: Julia Lawall <[email protected]>
> >
> >Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
> >kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.
>
> Nak: James Simmons <[email protected]>
>
> A simple replace will not work. The OBD_ALLOC and OBD_FREE functions allocate memory
> anywhere from one page to 4MB in size.

OBD_FREE() just calls kfree(), it does not allocate any memory, so that
replacement is always ok.

thanks,

greg k-h

2015-05-01 18:31:09

by walter harms

[permalink] [raw]
Subject: Re: [PATCH 8/11] staging: lustre: obdclass: Use kzalloc and kfree

hi Julia,
your patch seems fine.
I tried to understand the code and it seems that much of it
can be simplified by using already available functions.
I have added some comments but i am not sure what to make of it.

re,
wh


Am 01.05.2015 17:51, schrieb Julia Lawall:
> From: Julia Lawall <[email protected]>
>
> Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
> kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.
>
> A simplified version of the semantic patch that makes these changes is as
> follows: (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@ expression ptr,size; @@
> - OBD_ALLOC(ptr,size)
> + ptr = kzalloc(size, GFP_NOFS)
>
> @@ expression ptr, size; @@
> - OBD_FREE(ptr, size);
> + kfree(ptr);
> // </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>
>
> ---
> drivers/staging/lustre/lustre/obdclass/acl.c | 29 ++---
> drivers/staging/lustre/lustre/obdclass/capa.c | 4
> drivers/staging/lustre/lustre/obdclass/cl_io.c | 13 +-
> drivers/staging/lustre/lustre/obdclass/cl_page.c | 2
> drivers/staging/lustre/lustre/obdclass/class_obd.c | 4
> drivers/staging/lustre/lustre/obdclass/genops.c | 40 +++----
> drivers/staging/lustre/lustre/obdclass/llog.c | 24 ++--
> drivers/staging/lustre/lustre/obdclass/llog_obd.c | 4
> drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 14 +-
> drivers/staging/lustre/lustre/obdclass/lu_object.c | 6 -
> drivers/staging/lustre/lustre/obdclass/lustre_handles.c | 2
> drivers/staging/lustre/lustre/obdclass/lustre_peer.c | 6 -
> drivers/staging/lustre/lustre/obdclass/obd_config.c | 50 ++++-----
> drivers/staging/lustre/lustre/obdclass/obd_mount.c | 86 +++++++---------
> 14 files changed, 138 insertions(+), 146 deletions(-)
>
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> --- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> +++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> @@ -84,7 +84,7 @@ int lustre_process_log(struct super_bloc
> LASSERT(mgc);
> LASSERT(cfg);
>
> - OBD_ALLOC_PTR(bufs);
> + bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
> if (bufs == NULL)
> return -ENOMEM;
>
> @@ -97,7 +97,7 @@ int lustre_process_log(struct super_bloc
> rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
> lustre_cfg_free(lcfg);
>
> - OBD_FREE_PTR(bufs);
> + kfree(bufs);
>
> if (rc == -EINVAL)
> LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s' failed from the MGS (%d). Make sure this client and the MGS are running compatible versions of Lustre.\n",
> @@ -247,8 +247,8 @@ int lustre_start_mgc(struct super_block
> mutex_lock(&mgc_start_lock);
>
> len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
> - OBD_ALLOC(mgcname, len);
> - OBD_ALLOC(niduuid, len + 2);
> + mgcname = kzalloc(len, GFP_NOFS);
> + niduuid = kzalloc(len + 2, GFP_NOFS);
> if (!mgcname || !niduuid) {
> rc = -ENOMEM;
> goto out_free;

this can be simplified by using
kasprintf(&mgcname,"%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));

is guess the some is true for niduuid


> @@ -257,7 +257,7 @@ int lustre_start_mgc(struct super_block
>
> mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
>
> - OBD_ALLOC_PTR(data);
> + data = kzalloc(sizeof(*data), GFP_NOFS);
> if (data == NULL) {
> rc = -ENOMEM;
> goto out_free;
> @@ -375,7 +375,7 @@ int lustre_start_mgc(struct super_block
> lsi->lsi_lmd->lmd_mgs_failnodes = 1;
>
> /* Random uuid for MGC allows easier reconnects */
> - OBD_ALLOC_PTR(uuid);
> + uuid = kzalloc(sizeof(*uuid), GFP_NOFS);
> if (!uuid) {
> rc = -ENOMEM;
> goto out_free;
> @@ -388,7 +388,7 @@ int lustre_start_mgc(struct super_block
> rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
> (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
> niduuid, NULL, NULL);
> - OBD_FREE_PTR(uuid);
> + kfree(uuid);
> if (rc)
> goto out_free;
>
> @@ -465,11 +465,11 @@ out_free:
> mutex_unlock(&mgc_start_lock);
>
> if (data)
> - OBD_FREE_PTR(data);
> + kfree(data);
> if (mgcname)
> - OBD_FREE(mgcname, len);
> + kfree(mgcname);
> if (niduuid)
> - OBD_FREE(niduuid, len + 2);
> + kfree(niduuid);
> return rc;
> }
>
> @@ -513,7 +513,7 @@ static int lustre_stop_mgc(struct super_
> /* Save the obdname for cleaning the nid uuids, which are
> obdname_XX */
> len = strlen(obd->obd_name) + 6;
> - OBD_ALLOC(niduuid, len);
> + niduuid = kzalloc(len, GFP_NOFS);
> if (niduuid) {
> strcpy(niduuid, obd->obd_name);
> ptr = niduuid + strlen(niduuid);

i guess kstrdup() would be appropiate


> @@ -539,7 +539,7 @@ static int lustre_stop_mgc(struct super_
> }
> out:
> if (niduuid)
> - OBD_FREE(niduuid, len);
> + kfree(niduuid);
>
> /* class_import_put will get rid of the additional connections */
> mutex_unlock(&mgc_start_lock);
> @@ -552,12 +552,12 @@ struct lustre_sb_info *lustre_init_lsi(s
> {
> struct lustre_sb_info *lsi;
>
> - OBD_ALLOC_PTR(lsi);
> + lsi = kzalloc(sizeof(*lsi), GFP_NOFS);
> if (!lsi)
> return NULL;
> - OBD_ALLOC_PTR(lsi->lsi_lmd);
> + lsi->lsi_lmd = kzalloc(sizeof(*lsi->lsi_lmd), GFP_NOFS);
> if (!lsi->lsi_lmd) {
> - OBD_FREE_PTR(lsi);
> + kfree(lsi);
> return NULL;
> }
>
> @@ -586,35 +586,27 @@ static int lustre_free_lsi(struct super_
>
> if (lsi->lsi_lmd != NULL) {
> if (lsi->lsi_lmd->lmd_dev != NULL)
> - OBD_FREE(lsi->lsi_lmd->lmd_dev,
> - strlen(lsi->lsi_lmd->lmd_dev) + 1);
> + kfree(lsi->lsi_lmd->lmd_dev);
> if (lsi->lsi_lmd->lmd_profile != NULL)
> - OBD_FREE(lsi->lsi_lmd->lmd_profile,
> - strlen(lsi->lsi_lmd->lmd_profile) + 1);
> + kfree(lsi->lsi_lmd->lmd_profile);
> if (lsi->lsi_lmd->lmd_mgssec != NULL)
> - OBD_FREE(lsi->lsi_lmd->lmd_mgssec,
> - strlen(lsi->lsi_lmd->lmd_mgssec) + 1);
> + kfree(lsi->lsi_lmd->lmd_mgssec);
> if (lsi->lsi_lmd->lmd_opts != NULL)
> - OBD_FREE(lsi->lsi_lmd->lmd_opts,
> - strlen(lsi->lsi_lmd->lmd_opts) + 1);
> + kfree(lsi->lsi_lmd->lmd_opts);
> if (lsi->lsi_lmd->lmd_exclude_count)
> - OBD_FREE(lsi->lsi_lmd->lmd_exclude,
> - sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
> - lsi->lsi_lmd->lmd_exclude_count);
> + kfree(lsi->lsi_lmd->lmd_exclude);
> if (lsi->lsi_lmd->lmd_mgs != NULL)
> - OBD_FREE(lsi->lsi_lmd->lmd_mgs,
> - strlen(lsi->lsi_lmd->lmd_mgs) + 1);
> + kfree(lsi->lsi_lmd->lmd_mgs);
> if (lsi->lsi_lmd->lmd_osd_type != NULL)
> - OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
> - strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
> + kfree(lsi->lsi_lmd->lmd_osd_type);
> if (lsi->lsi_lmd->lmd_params != NULL)
> - OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
> + kfree(lsi->lsi_lmd->lmd_params);
>
> - OBD_FREE(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
> + kfree(lsi->lsi_lmd);
> }
>
> LASSERT(lsi->lsi_llsbi == NULL);
> - OBD_FREE(lsi, sizeof(*lsi));
> + kfree(lsi);
> s2lsi_nocast(sb) = NULL;
>
> return 0;
> @@ -846,7 +838,7 @@ static int lmd_make_exclusion(struct lus
> devmax = strlen(ptr) / 8 + 1;
>
> /* temp storage until we figure out how many we have */
> - OBD_ALLOC(exclude_list, sizeof(index) * devmax);
> + exclude_list = kcalloc(devmax, sizeof(index), GFP_NOFS);
> if (!exclude_list)
> return -ENOMEM;
>
> @@ -875,8 +867,8 @@ static int lmd_make_exclusion(struct lus
>
> if (lmd->lmd_exclude_count) {
> /* permanent, freed in lustre_free_lsi */
> - OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
> - lmd->lmd_exclude_count);
> + lmd->lmd_exclude = kcalloc(lmd->lmd_exclude_count,
> + sizeof(index), GFP_NOFS);
> if (lmd->lmd_exclude) {
> memcpy(lmd->lmd_exclude, exclude_list,
> sizeof(index) * lmd->lmd_exclude_count);
> @@ -885,7 +877,7 @@ static int lmd_make_exclusion(struct lus
> lmd->lmd_exclude_count = 0;
> }
> }
> - OBD_FREE(exclude_list, sizeof(index) * devmax);
> + kfree(exclude_list);
> return rc;
> }
>
> @@ -895,7 +887,7 @@ static int lmd_parse_mgssec(struct lustr
> int length;
>
> if (lmd->lmd_mgssec != NULL) {
> - OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
> + kfree(lmd->lmd_mgssec);
> lmd->lmd_mgssec = NULL;
> }

is the check needed hier at all ? just
kfree(lmd->lmd_mgssec);
seems to do the same job.

>
> @@ -905,7 +897,7 @@ static int lmd_parse_mgssec(struct lustr
> else
> length = tail - ptr;
>
> - OBD_ALLOC(lmd->lmd_mgssec, length + 1);
> + lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS);
> if (lmd->lmd_mgssec == NULL)
> return -ENOMEM;
>

complicated why to say:
lmd->lmd_mgssec=kstrndup(ptr, length,GFP_NOFS);



> @@ -923,7 +915,7 @@ static int lmd_parse_string(char **handl
> return -EINVAL;
>
> if (*handle != NULL) {
> - OBD_FREE(*handle, strlen(*handle) + 1);
> + kfree(*handle);
> *handle = NULL;
> }
>
> @@ -933,7 +925,7 @@ static int lmd_parse_string(char **handl
> else
> length = tail - ptr;
>
> - OBD_ALLOC(*handle, length + 1);
> + *handle = kzalloc(length + 1, GFP_NOFS);
> if (*handle == NULL)
> return -ENOMEM;
>

lmd_parse_string() seems more or less the same as lmd_parse_mgssec().
perhaps this can be merged.



> @@ -963,7 +955,7 @@ static int lmd_parse_mgs(struct lustre_m
> if (lmd->lmd_mgs != NULL)
> oldlen = strlen(lmd->lmd_mgs) + 1;
>
> - OBD_ALLOC(mgsnid, oldlen + length + 1);
> + mgsnid = kzalloc(oldlen + length + 1, GFP_NOFS);
> if (mgsnid == NULL)
> return -ENOMEM;
>
> @@ -971,7 +963,7 @@ static int lmd_parse_mgs(struct lustre_m
> /* Multiple mgsnid= are taken to mean failover locations */
> memcpy(mgsnid, lmd->lmd_mgs, oldlen);
> mgsnid[oldlen - 1] = ':';
> - OBD_FREE(lmd->lmd_mgs, oldlen);
> + kfree(lmd->lmd_mgs);
> }
> memcpy(mgsnid + oldlen, *ptr, length);
> mgsnid[oldlen + length] = '\0';

the code lmd_parse_mgs basicly does:
kasprintf( &lmd->lmd_mgs,"%s:%s",lmd->lmd_mgs,*ptr);

> @@ -1005,7 +997,7 @@ static int lmd_parse(char *options, stru
> }
> lmd->lmd_magic = LMD_MAGIC;
>
> - OBD_ALLOC(lmd->lmd_params, 4096);
> + lmd->lmd_params = kzalloc(4096, GFP_NOFS);
> if (lmd->lmd_params == NULL)
> return -ENOMEM;
> lmd->lmd_params[0] = '\0';
> @@ -1143,14 +1135,14 @@ static int lmd_parse(char *options, stru
> /* Remove leading /s from fsname */
> while (*++s1 == '/') ;
> /* Freed in lustre_free_lsi */
> - OBD_ALLOC(lmd->lmd_profile, strlen(s1) + 8);
> + lmd->lmd_profile = kzalloc(strlen(s1) + 8, GFP_NOFS);
> if (!lmd->lmd_profile)
> return -ENOMEM;
> sprintf(lmd->lmd_profile, "%s-client", s1);
> }
>
> /* Freed in lustre_free_lsi */
> - OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
> + lmd->lmd_dev = kzalloc(strlen(devname) + 1, GFP_NOFS);
> if (!lmd->lmd_dev)
> return -ENOMEM;
> strcpy(lmd->lmd_dev, devname);
> @@ -1161,7 +1153,7 @@ static int lmd_parse(char *options, stru
> *s1-- = 0;
> if (*options != 0) {
> /* Freed in lustre_free_lsi */
> - OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
> + lmd->lmd_opts = kzalloc(strlen(options) + 1, GFP_NOFS);
> if (!lmd->lmd_opts)
> return -ENOMEM;
> strcpy(lmd->lmd_opts, options);
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c
> --- a/drivers/staging/lustre/lustre/obdclass/obd_config.c
> +++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c
> @@ -860,13 +860,13 @@ int class_add_profile(int proflen, char
>
> CDEBUG(D_CONFIG, "Add profile %s\n", prof);
>
> - OBD_ALLOC(lprof, sizeof(*lprof));
> + lprof = kzalloc(sizeof(*lprof), GFP_NOFS);
> if (lprof == NULL)
> return -ENOMEM;
> INIT_LIST_HEAD(&lprof->lp_list);
>
> LASSERT(proflen == (strlen(prof) + 1));
> - OBD_ALLOC(lprof->lp_profile, proflen);
> + lprof->lp_profile = kzalloc(proflen, GFP_NOFS);
> if (lprof->lp_profile == NULL) {
> err = -ENOMEM;
> goto out;
> @@ -874,7 +874,7 @@ int class_add_profile(int proflen, char
> memcpy(lprof->lp_profile, prof, proflen);
>
> LASSERT(osclen == (strlen(osc) + 1));
> - OBD_ALLOC(lprof->lp_dt, osclen);
> + lprof->lp_dt = kzalloc(osclen, GFP_NOFS);
> if (lprof->lp_dt == NULL) {
> err = -ENOMEM;
> goto out;
> @@ -883,7 +883,7 @@ int class_add_profile(int proflen, char
>
> if (mdclen > 0) {
> LASSERT(mdclen == (strlen(mdc) + 1));
> - OBD_ALLOC(lprof->lp_md, mdclen);
> + lprof->lp_md = kzalloc(mdclen, GFP_NOFS);
> if (lprof->lp_md == NULL) {
> err = -ENOMEM;
> goto out;
> @@ -896,12 +896,12 @@ int class_add_profile(int proflen, char
>
> out:
> if (lprof->lp_md)
> - OBD_FREE(lprof->lp_md, mdclen);
> + kfree(lprof->lp_md);
> if (lprof->lp_dt)
> - OBD_FREE(lprof->lp_dt, osclen);
> + kfree(lprof->lp_dt);
> if (lprof->lp_profile)
> - OBD_FREE(lprof->lp_profile, proflen);
> - OBD_FREE(lprof, sizeof(*lprof));
> + kfree(lprof->lp_profile);
> + kfree(lprof);
> return err;
> }
>
> @@ -914,11 +914,11 @@ void class_del_profile(const char *prof)
> lprof = class_get_profile(prof);
> if (lprof) {
> list_del(&lprof->lp_list);
> - OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
> - OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
> + kfree(lprof->lp_profile);
> + kfree(lprof->lp_dt);
> if (lprof->lp_md)
> - OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
> - OBD_FREE(lprof, sizeof(*lprof));
> + kfree(lprof->lp_md);
> + kfree(lprof);
> }
> }
> EXPORT_SYMBOL(class_del_profile);
> @@ -930,11 +930,11 @@ void class_del_profiles(void)
>
> list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
> list_del(&lprof->lp_list);
> - OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
> - OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
> + kfree(lprof->lp_profile);
> + kfree(lprof->lp_dt);
> if (lprof->lp_md)
> - OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
> - OBD_FREE(lprof, sizeof(*lprof));
> + kfree(lprof->lp_md);
> + kfree(lprof);
> }
> }
> EXPORT_SYMBOL(class_del_profiles);
> @@ -1011,7 +1011,7 @@ struct lustre_cfg *lustre_cfg_rename(str
>
> new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
>
> - OBD_ALLOC(new_param, new_len);
> + new_param = kzalloc(new_len, GFP_NOFS);
> if (new_param == NULL)
> return ERR_PTR(-ENOMEM);
>
> @@ -1019,9 +1019,9 @@ struct lustre_cfg *lustre_cfg_rename(str
> if (value != NULL)
> strcat(new_param, value);
>
> - OBD_ALLOC_PTR(bufs);
> + bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
> if (bufs == NULL) {
> - OBD_FREE(new_param, new_len);
> + kfree(new_param);
> return ERR_PTR(-ENOMEM);
> }
>
> @@ -1031,8 +1031,8 @@ struct lustre_cfg *lustre_cfg_rename(str
>
> new_cfg = lustre_cfg_new(cfg->lcfg_command, bufs);
>
> - OBD_FREE(new_param, new_len);
> - OBD_FREE_PTR(bufs);
> + kfree(new_param);
> + kfree(bufs);
> if (new_cfg == NULL)
> return ERR_PTR(-ENOMEM);
>
> @@ -1493,7 +1493,7 @@ int class_config_llog_handler(const stru
> inst = 1;
> inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
> sizeof(clli->cfg_instance) * 2 + 4;
> - OBD_ALLOC(inst_name, inst_len);
> + inst_name = kzalloc(inst_len, GFP_NOFS);
> if (inst_name == NULL) {
> rc = -ENOMEM;
> goto out;
> @@ -1556,7 +1556,7 @@ int class_config_llog_handler(const stru
> lustre_cfg_free(lcfg_new);
>
> if (inst)
> - OBD_FREE(inst_name, inst_len);
> + kfree(inst_name);
> break;
> }
> default:
> @@ -1671,7 +1671,7 @@ int class_config_dump_handler(const stru
> char *outstr;
> int rc = 0;
>
> - OBD_ALLOC(outstr, 256);
> + outstr = kzalloc(256, GFP_NOFS);
> if (outstr == NULL)
> return -ENOMEM;
>
> @@ -1683,7 +1683,7 @@ int class_config_dump_handler(const stru
> rc = -EINVAL;
> }
>
> - OBD_FREE(outstr, 256);
> + kfree(outstr);
> return rc;
> }
>
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/lustre_peer.c b/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
> --- a/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
> +++ b/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
> @@ -104,7 +104,7 @@ int class_add_uuid(const char *uuid, __u
> if (strlen(uuid) > UUID_MAX - 1)
> return -EOVERFLOW;
>
> - OBD_ALLOC_PTR(data);
> + data = kzalloc(sizeof(*data), GFP_NOFS);
> if (data == NULL)
> return -ENOMEM;
>
> @@ -136,7 +136,7 @@ int class_add_uuid(const char *uuid, __u
> if (found) {
> CDEBUG(D_INFO, "found uuid %s %s cnt=%d\n", uuid,
> libcfs_nid2str(nid), entry->un_nid_count);
> - OBD_FREE(data, sizeof(*data));
> + kfree(data);
> } else {
> CDEBUG(D_INFO, "add uuid %s %s\n", uuid, libcfs_nid2str(nid));
> }
> @@ -180,7 +180,7 @@ int class_del_uuid(const char *uuid)
> libcfs_nid2str(data->un_nids[0]),
> data->un_nid_count);
>
> - OBD_FREE(data, sizeof(*data));
> + kfree(data);
> }
>
> return 0;
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
> --- a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
> +++ b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
> @@ -186,7 +186,7 @@ void class_handle_free_cb(struct rcu_hea
> if (h->h_ops->hop_free != NULL)
> h->h_ops->hop_free(ptr, h->h_size);
> else
> - OBD_FREE(ptr, h->h_size);
> + kfree(ptr);
> }
> EXPORT_SYMBOL(class_handle_free_cb);
>
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c
> --- a/drivers/staging/lustre/lustre/obdclass/lu_object.c
> +++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c
> @@ -1532,7 +1532,7 @@ static void keys_fini(struct lu_context
> for (i = 0; i < ARRAY_SIZE(lu_keys); ++i)
> key_fini(ctx, i);
>
> - OBD_FREE(ctx->lc_value, ARRAY_SIZE(lu_keys) * sizeof(ctx->lc_value[0]));
> + kfree(ctx->lc_value);
> ctx->lc_value = NULL;
> }
>
> @@ -1581,8 +1581,8 @@ static int keys_fill(struct lu_context *
>
> static int keys_init(struct lu_context *ctx)
> {
> - OBD_ALLOC(ctx->lc_value,
> - ARRAY_SIZE(lu_keys) * sizeof(ctx->lc_value[0]));
> + ctx->lc_value = kcalloc(ARRAY_SIZE(lu_keys), sizeof(ctx->lc_value[0]),
> + GFP_NOFS);
> if (likely(ctx->lc_value != NULL))
> return keys_fill(ctx);
>
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> --- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> @@ -276,7 +276,7 @@ struct proc_dir_entry *lprocfs_add_symli
> if (parent == NULL || format == NULL)
> return NULL;
>
> - OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
> + dest = kzalloc(MAX_STRING_SIZE + 1, GFP_KERNEL);
> if (dest == NULL)
> return NULL;
>
> @@ -289,7 +289,7 @@ struct proc_dir_entry *lprocfs_add_symli
> CERROR("LprocFS: Could not create symbolic link from %s to %s",
> name, dest);
>
> - OBD_FREE(dest, MAX_STRING_SIZE + 1);
> + kfree(dest);
> return entry;
> }
> EXPORT_SYMBOL(lprocfs_add_symlink);
> @@ -1006,7 +1006,7 @@ static void lprocfs_free_client_stats(st
> if (client_stat->nid_ldlm_stats)
> lprocfs_free_stats(&client_stat->nid_ldlm_stats);
>
> - OBD_FREE_PTR(client_stat);
> + kfree(client_stat);
> return;
>
> }
> @@ -1681,7 +1681,7 @@ int lprocfs_exp_setup(struct obd_export
>
> CDEBUG(D_CONFIG, "using hash %p\n", obd->obd_nid_stats_hash);
>
> - OBD_ALLOC_PTR(new_stat);
> + new_stat = kzalloc(sizeof(*new_stat), GFP_NOFS);
> if (new_stat == NULL)
> return -ENOMEM;
>
> @@ -1711,7 +1711,7 @@ int lprocfs_exp_setup(struct obd_export
> goto destroy_new;
> }
> /* not found - create */
> - OBD_ALLOC(buffer, LNET_NIDSTR_SIZE);
> + buffer = kzalloc(LNET_NIDSTR_SIZE, GFP_NOFS);
> if (buffer == NULL) {
> rc = -ENOMEM;
> goto destroy_new;
> @@ -1721,7 +1721,7 @@ int lprocfs_exp_setup(struct obd_export
> new_stat->nid_proc = lprocfs_register(buffer,
> obd->obd_proc_exports_entry,
> NULL, NULL);
> - OBD_FREE(buffer, LNET_NIDSTR_SIZE);
> + kfree(buffer);
>
> if (IS_ERR(new_stat->nid_proc)) {
> CERROR("Error making export directory for nid %s\n",
> @@ -1763,7 +1763,7 @@ destroy_new_ns:
>
> destroy_new:
> nidstat_putref(new_stat);
> - OBD_FREE_PTR(new_stat);
> + kfree(new_stat);
> return rc;
> }
> EXPORT_SYMBOL(lprocfs_exp_setup);
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/llog_obd.c b/drivers/staging/lustre/lustre/obdclass/llog_obd.c
> --- a/drivers/staging/lustre/lustre/obdclass/llog_obd.c
> +++ b/drivers/staging/lustre/lustre/obdclass/llog_obd.c
> @@ -46,7 +46,7 @@ static struct llog_ctxt *llog_new_ctxt(s
> {
> struct llog_ctxt *ctxt;
>
> - OBD_ALLOC_PTR(ctxt);
> + ctxt = kzalloc(sizeof(*ctxt), GFP_NOFS);
> if (!ctxt)
> return NULL;
>
> @@ -66,7 +66,7 @@ static void llog_ctxt_destroy(struct llo
> class_import_put(ctxt->loc_imp);
> ctxt->loc_imp = NULL;
> }
> - OBD_FREE_PTR(ctxt);
> + kfree(ctxt);
> }
>
> int __llog_ctxt_put(const struct lu_env *env, struct llog_ctxt *ctxt)
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/llog.c b/drivers/staging/lustre/lustre/obdclass/llog.c
> --- a/drivers/staging/lustre/lustre/obdclass/llog.c
> +++ b/drivers/staging/lustre/lustre/obdclass/llog.c
> @@ -60,7 +60,7 @@ static struct llog_handle *llog_alloc_ha
> {
> struct llog_handle *loghandle;
>
> - OBD_ALLOC_PTR(loghandle);
> + loghandle = kzalloc(sizeof(*loghandle), GFP_NOFS);
> if (loghandle == NULL)
> return NULL;
>
> @@ -88,9 +88,9 @@ static void llog_free_handle(struct llog
> else if (loghandle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)
> LASSERT(list_empty(&loghandle->u.chd.chd_head));
> LASSERT(sizeof(*(loghandle->lgh_hdr)) == LLOG_CHUNK_SIZE);
> - OBD_FREE(loghandle->lgh_hdr, LLOG_CHUNK_SIZE);
> + kfree(loghandle->lgh_hdr);
> out:
> - OBD_FREE_PTR(loghandle);
> + kfree(loghandle);
> }
>
> void llog_handle_get(struct llog_handle *loghandle)
> @@ -207,7 +207,7 @@ int llog_init_handle(const struct lu_env
>
> LASSERT(handle->lgh_hdr == NULL);
>
> - OBD_ALLOC_PTR(llh);
> + llh = kzalloc(sizeof(*llh), GFP_NOFS);
> if (llh == NULL)
> return -ENOMEM;
> handle->lgh_hdr = llh;
> @@ -261,7 +261,7 @@ int llog_init_handle(const struct lu_env
> }
> out:
> if (rc) {
> - OBD_FREE_PTR(llh);
> + kfree(llh);
> handle->lgh_hdr = NULL;
> }
> return rc;
> @@ -283,7 +283,7 @@ static int llog_process_thread(void *arg
>
> LASSERT(llh);
>
> - OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
> + buf = kzalloc(LLOG_CHUNK_SIZE, GFP_NOFS);
> if (!buf) {
> lpi->lpi_rc = -ENOMEM;
> return 0;
> @@ -400,7 +400,7 @@ out:
> if (cd != NULL)
> cd->lpcd_last_idx = last_called_index;
>
> - OBD_FREE(buf, LLOG_CHUNK_SIZE);
> + kfree(buf);
> lpi->lpi_rc = rc;
> return 0;
> }
> @@ -434,7 +434,7 @@ int llog_process_or_fork(const struct lu
> struct llog_process_info *lpi;
> int rc;
>
> - OBD_ALLOC_PTR(lpi);
> + lpi = kzalloc(sizeof(*lpi), GFP_NOFS);
> if (lpi == NULL) {
> CERROR("cannot alloc pointer\n");
> return -ENOMEM;
> @@ -454,7 +454,7 @@ int llog_process_or_fork(const struct lu
> if (IS_ERR_VALUE(rc)) {
> CERROR("%s: cannot start thread: rc = %d\n",
> loghandle->lgh_ctxt->loc_obd->obd_name, rc);
> - OBD_FREE_PTR(lpi);
> + kfree(lpi);
> return rc;
> }
> wait_for_completion(&lpi->lpi_completion);
> @@ -463,7 +463,7 @@ int llog_process_or_fork(const struct lu
> llog_process_thread(lpi);
> }
> rc = lpi->lpi_rc;
> - OBD_FREE_PTR(lpi);
> + kfree(lpi);
> return rc;
> }
> EXPORT_SYMBOL(llog_process_or_fork);
> @@ -484,7 +484,7 @@ int llog_reverse_process(const struct lu
> void *buf;
> int rc = 0, first_index = 1, index, idx;
>
> - OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
> + buf = kzalloc(LLOG_CHUNK_SIZE, GFP_NOFS);
> if (!buf)
> return -ENOMEM;
>
> @@ -564,7 +564,7 @@ int llog_reverse_process(const struct lu
>
> out:
> if (buf)
> - OBD_FREE(buf, LLOG_CHUNK_SIZE);
> + kfree(buf);
> return rc;
> }
> EXPORT_SYMBOL(llog_reverse_process);
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c
> --- a/drivers/staging/lustre/lustre/obdclass/genops.c
> +++ b/drivers/staging/lustre/lustre/obdclass/genops.c
> @@ -171,13 +171,13 @@ int class_register_type(struct obd_ops *
> }
>
> rc = -ENOMEM;
> - OBD_ALLOC(type, sizeof(*type));
> + type = kzalloc(sizeof(*type), GFP_NOFS);
> if (type == NULL)
> return rc;
>
> - OBD_ALLOC_PTR(type->typ_dt_ops);
> - OBD_ALLOC_PTR(type->typ_md_ops);
> - OBD_ALLOC(type->typ_name, strlen(name) + 1);
> + type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS);
> + type->typ_md_ops = kzalloc(sizeof(*type->typ_md_ops), GFP_NOFS);
> + type->typ_name = kzalloc(strlen(name) + 1, GFP_NOFS);
>
> if (type->typ_dt_ops == NULL ||
> type->typ_md_ops == NULL ||
> @@ -214,12 +214,12 @@ int class_register_type(struct obd_ops *
>
> failed:
> if (type->typ_name != NULL)
> - OBD_FREE(type->typ_name, strlen(name) + 1);
> + kfree(type->typ_name);
> if (type->typ_md_ops != NULL)
> - OBD_FREE_PTR(type->typ_md_ops);
> + kfree(type->typ_md_ops);
> if (type->typ_dt_ops != NULL)
> - OBD_FREE_PTR(type->typ_dt_ops);
> - OBD_FREE(type, sizeof(*type));
> + kfree(type->typ_dt_ops);
> + kfree(type);
> return rc;
> }
> EXPORT_SYMBOL(class_register_type);
> @@ -237,8 +237,8 @@ int class_unregister_type(const char *na
> CERROR("type %s has refcount (%d)\n", name, type->typ_refcnt);
> /* This is a bad situation, let's make the best of it */
> /* Remove ops, but leave the name for debugging */
> - OBD_FREE_PTR(type->typ_dt_ops);
> - OBD_FREE_PTR(type->typ_md_ops);
> + kfree(type->typ_dt_ops);
> + kfree(type->typ_md_ops);
> return -EBUSY;
> }
>
> @@ -252,12 +252,12 @@ int class_unregister_type(const char *na
> spin_lock(&obd_types_lock);
> list_del(&type->typ_chain);
> spin_unlock(&obd_types_lock);
> - OBD_FREE(type->typ_name, strlen(name) + 1);
> + kfree(type->typ_name);
> if (type->typ_dt_ops != NULL)
> - OBD_FREE_PTR(type->typ_dt_ops);
> + kfree(type->typ_dt_ops);
> if (type->typ_md_ops != NULL)
> - OBD_FREE_PTR(type->typ_md_ops);
> - OBD_FREE(type, sizeof(*type));
> + kfree(type->typ_md_ops);
> + kfree(type);
> return 0;
> } /* class_unregister_type */
> EXPORT_SYMBOL(class_unregister_type);
> @@ -819,7 +819,7 @@ struct obd_export *class_new_export(stru
> struct cfs_hash *hash = NULL;
> int rc = 0;
>
> - OBD_ALLOC_PTR(export);
> + export = kzalloc(sizeof(*export), GFP_NOFS);
> if (!export)
> return ERR_PTR(-ENOMEM);
>
> @@ -904,7 +904,7 @@ exit_err:
> class_handle_unhash(&export->exp_handle);
> LASSERT(hlist_unhashed(&export->exp_uuid_hash));
> obd_destroy_export(export);
> - OBD_FREE_PTR(export);
> + kfree(export);
> return ERR_PTR(rc);
> }
> EXPORT_SYMBOL(class_new_export);
> @@ -945,7 +945,7 @@ static void class_import_destroy(struct
> struct obd_import_conn, oic_item);
> list_del_init(&imp_conn->oic_item);
> ptlrpc_put_connection_superhack(imp_conn->oic_conn);
> - OBD_FREE(imp_conn, sizeof(*imp_conn));
> + kfree(imp_conn);
> }
>
> LASSERT(imp->imp_sec == NULL);
> @@ -1008,7 +1008,7 @@ struct obd_import *class_new_import(stru
> {
> struct obd_import *imp;
>
> - OBD_ALLOC(imp, sizeof(*imp));
> + imp = kzalloc(sizeof(*imp), GFP_NOFS);
> if (imp == NULL)
> return NULL;
>
> @@ -1811,7 +1811,7 @@ void *kuc_alloc(int payload_len, int tra
> struct kuc_hdr *lh;
> int len = kuc_len(payload_len);
>
> - OBD_ALLOC(lh, len);
> + lh = kzalloc(len, GFP_NOFS);
> if (lh == NULL)
> return ERR_PTR(-ENOMEM);
>
> @@ -1828,6 +1828,6 @@ EXPORT_SYMBOL(kuc_alloc);
> inline void kuc_free(void *p, int payload_len)
> {
> struct kuc_hdr *lh = kuc_ptr(p);
> - OBD_FREE(lh, kuc_len(payload_len));
> + kfree(lh);
> }
> EXPORT_SYMBOL(kuc_free);
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c
> --- a/drivers/staging/lustre/lustre/obdclass/class_obd.c
> +++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c
> @@ -231,7 +231,7 @@ int class_handle_ioctl(unsigned int cmd,
> err = -EINVAL;
> goto out;
> }
> - OBD_ALLOC(lcfg, data->ioc_plen1);
> + lcfg = kzalloc(data->ioc_plen1, GFP_NOFS);
> if (lcfg == NULL) {
> err = -ENOMEM;
> goto out;
> @@ -243,7 +243,7 @@ int class_handle_ioctl(unsigned int cmd,
> if (!err)
> err = class_process_config(lcfg);
>
> - OBD_FREE(lcfg, data->ioc_plen1);
> + kfree(lcfg);
> goto out;
> }
>
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/cl_page.c b/drivers/staging/lustre/lustre/obdclass/cl_page.c
> --- a/drivers/staging/lustre/lustre/obdclass/cl_page.c
> +++ b/drivers/staging/lustre/lustre/obdclass/cl_page.c
> @@ -270,7 +270,7 @@ static void cl_page_free(const struct lu
> lu_object_ref_del_at(&obj->co_lu, &page->cp_obj_ref, "cl_page", page);
> cl_object_put(env, obj);
> lu_ref_fini(&page->cp_reference);
> - OBD_FREE(page, pagesize);
> + kfree(page);
> }
>
> /**
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c
> --- a/drivers/staging/lustre/lustre/obdclass/cl_io.c
> +++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c
> @@ -612,7 +612,7 @@ EXPORT_SYMBOL(cl_io_lock_add);
> static void cl_free_io_lock_link(const struct lu_env *env,
> struct cl_io_lock_link *link)
> {
> - OBD_FREE_PTR(link);
> + kfree(link);
> }
>
> /**
> @@ -624,7 +624,7 @@ int cl_io_lock_alloc_add(const struct lu
> struct cl_io_lock_link *link;
> int result;
>
> - OBD_ALLOC_PTR(link);
> + link = kzalloc(sizeof(*link), GFP_NOFS);
> if (link != NULL) {
> link->cill_descr = *descr;
> link->cill_fini = cl_free_io_lock_link;
> @@ -1387,9 +1387,9 @@ static void cl_req_free(const struct lu_
> cl_object_put(env, obj);
> }
> }
> - OBD_FREE(req->crq_o, req->crq_nrobjs * sizeof(req->crq_o[0]));
> + kfree(req->crq_o);
> }
> - OBD_FREE_PTR(req);
> + kfree(req);
> }
>
> static int cl_req_init(const struct lu_env *env, struct cl_req *req,
> @@ -1448,7 +1448,7 @@ struct cl_req *cl_req_alloc(const struct
>
> LINVRNT(nr_objects > 0);
>
> - OBD_ALLOC_PTR(req);
> + req = kzalloc(sizeof(*req), GFP_NOFS);
> if (req != NULL) {
> int result;
>
> @@ -1456,7 +1456,8 @@ struct cl_req *cl_req_alloc(const struct
> INIT_LIST_HEAD(&req->crq_pages);
> INIT_LIST_HEAD(&req->crq_layers);
>
> - OBD_ALLOC(req->crq_o, nr_objects * sizeof(req->crq_o[0]));
> + req->crq_o = kcalloc(nr_objects, sizeof(req->crq_o[0]),
> + GFP_NOFS);
> if (req->crq_o != NULL) {
> req->crq_nrobjs = nr_objects;
> result = cl_req_init(env, req, page);
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/capa.c b/drivers/staging/lustre/lustre/obdclass/capa.c
> --- a/drivers/staging/lustre/lustre/obdclass/capa.c
> +++ b/drivers/staging/lustre/lustre/obdclass/capa.c
> @@ -87,7 +87,7 @@ struct hlist_head *init_capa_hash(void)
> struct hlist_head *hash;
> int nr_hash, i;
>
> - OBD_ALLOC(hash, PAGE_CACHE_SIZE);
> + hash = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS);
> if (!hash)
> return NULL;
>
> @@ -129,7 +129,7 @@ void cleanup_capa_hash(struct hlist_head
> }
> spin_unlock(&capa_lock);
>
> - OBD_FREE(hash, PAGE_CACHE_SIZE);
> + kfree(hash);
> }
> EXPORT_SYMBOL(cleanup_capa_hash);
>
> diff -u -p a/drivers/staging/lustre/lustre/obdclass/acl.c b/drivers/staging/lustre/lustre/obdclass/acl.c
> --- a/drivers/staging/lustre/lustre/obdclass/acl.c
> +++ b/drivers/staging/lustre/lustre/obdclass/acl.c
> @@ -104,12 +104,12 @@ static int lustre_posix_acl_xattr_reduce
> if (unlikely(old_count <= new_count))
> return old_size;
>
> - OBD_ALLOC(new, new_size);
> + new = kzalloc(new_size, GFP_NOFS);
> if (unlikely(new == NULL))
> return -ENOMEM;
>
> memcpy(new, *header, new_size);
> - OBD_FREE(*header, old_size);
> + kfree(*header);
> *header = new;
> return new_size;
> }
> @@ -126,12 +126,12 @@ static int lustre_ext_acl_xattr_reduce_s
> if (unlikely(old_count <= ext_count))
> return 0;
>
> - OBD_ALLOC(new, ext_size);
> + new = kzalloc(ext_size, GFP_NOFS);
> if (unlikely(new == NULL))
> return -ENOMEM;
>
> memcpy(new, *header, ext_size);
> - OBD_FREE(*header, old_size);
> + kfree(*header);
> *header = new;
> return 0;
> }
> @@ -152,7 +152,7 @@ lustre_posix_acl_xattr_2ext(posix_acl_xa
> else
> count = CFS_ACL_XATTR_COUNT(size, posix_acl_xattr);
> esize = CFS_ACL_XATTR_SIZE(count, ext_acl_xattr);
> - OBD_ALLOC(new, esize);
> + new = kzalloc(esize, GFP_NOFS);
> if (unlikely(new == NULL))
> return ERR_PTR(-ENOMEM);
>
> @@ -183,7 +183,7 @@ int lustre_posix_acl_xattr_filter(posix_
> if (size < sizeof(*new))
> return -EINVAL;
>
> - OBD_ALLOC(new, size);
> + new = kzalloc(size, GFP_NOFS);
> if (unlikely(new == NULL))
> return -ENOMEM;
>
> @@ -232,7 +232,7 @@ int lustre_posix_acl_xattr_filter(posix_
>
> _out:
> if (rc) {
> - OBD_FREE(new, size);
> + kfree(new);
> size = rc;
> }
> return size;
> @@ -244,7 +244,7 @@ EXPORT_SYMBOL(lustre_posix_acl_xattr_fil
> */
> void lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size)
> {
> - OBD_FREE(header, size);
> + kfree(header);
> }
> EXPORT_SYMBOL(lustre_posix_acl_xattr_free);
>
> @@ -253,8 +253,7 @@ EXPORT_SYMBOL(lustre_posix_acl_xattr_fre
> */
> void lustre_ext_acl_xattr_free(ext_acl_xattr_header *header)
> {
> - OBD_FREE(header, CFS_ACL_XATTR_SIZE(le32_to_cpu(header->a_count), \
> - ext_acl_xattr));
> + kfree(header);
> }
> EXPORT_SYMBOL(lustre_ext_acl_xattr_free);
>
> @@ -309,7 +308,7 @@ int lustre_acl_xattr_merge2posix(posix_a
> /* there are only base ACL entries at most. */
> posix_count = 3;
> posix_size = CFS_ACL_XATTR_SIZE(posix_count, posix_acl_xattr);
> - OBD_ALLOC(new, posix_size);
> + new = kzalloc(posix_size, GFP_NOFS);
> if (unlikely(new == NULL))
> return -ENOMEM;
>
> @@ -360,7 +359,7 @@ int lustre_acl_xattr_merge2posix(posix_a
> posix_count = ori_posix_count + ext_count;
> posix_size =
> CFS_ACL_XATTR_SIZE(posix_count, posix_acl_xattr);
> - OBD_ALLOC(new, posix_size);
> + new = kzalloc(posix_size, GFP_NOFS);
> if (unlikely(new == NULL))
> return -ENOMEM;
>
> @@ -402,7 +401,7 @@ int lustre_acl_xattr_merge2posix(posix_a
>
> _out:
> if (rc) {
> - OBD_FREE(new, posix_size);
> + kfree(new);
> posix_size = rc;
> }
> return posix_size;
> @@ -432,7 +431,7 @@ lustre_acl_xattr_merge2ext(posix_acl_xat
> ext_count = posix_count + ori_ext_count;
> ext_size = CFS_ACL_XATTR_SIZE(ext_count, ext_acl_xattr);
>
> - OBD_ALLOC(new, ext_size);
> + new = kzalloc(ext_size, GFP_NOFS);
> if (unlikely(new == NULL))
> return ERR_PTR(-ENOMEM);
>
> @@ -538,7 +537,7 @@ lustre_acl_xattr_merge2ext(posix_acl_xat
>
> out:
> if (rc) {
> - OBD_FREE(new, ext_size);
> + kfree(new);
> new = ERR_PTR(rc);
> }
> return new;
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2015-05-01 18:42:40

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 8/11] staging: lustre: obdclass: Use kzalloc and kfree

On Fri, 1 May 2015, walter harms wrote:

> hi Julia,
> your patch seems fine.
> I tried to understand the code and it seems that much of it
> can be simplified by using already available functions.
> I have added some comments but i am not sure what to make of it.

Thanks for the review. Comments below.

> >
> > len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
> > - OBD_ALLOC(mgcname, len);
> > - OBD_ALLOC(niduuid, len + 2);
> > + mgcname = kzalloc(len, GFP_NOFS);
> > + niduuid = kzalloc(len + 2, GFP_NOFS);
> > if (!mgcname || !niduuid) {
> > rc = -ENOMEM;
> > goto out_free;
>
> this can be simplified by using
> kasprintf(&mgcname,"%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
>
> is guess the some is true for niduuid

Thanks for the suggestion. I will look into that next. It may be
applicable elsewhere.

> > /* Save the obdname for cleaning the nid uuids, which are
> > obdname_XX */
> > len = strlen(obd->obd_name) + 6;
> > - OBD_ALLOC(niduuid, len);
> > + niduuid = kzalloc(len, GFP_NOFS);
> > if (niduuid) {
> > strcpy(niduuid, obd->obd_name);
> > ptr = niduuid + strlen(niduuid);
>
> i guess kstrdup() would be appropiate

OK, I will check on this too.

> > @@ -895,7 +887,7 @@ static int lmd_parse_mgssec(struct lustr
> > int length;
> >
> > if (lmd->lmd_mgssec != NULL) {
> > - OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
> > + kfree(lmd->lmd_mgssec);
> > lmd->lmd_mgssec = NULL;
> > }
>
> is the check needed hier at all ? just
> kfree(lmd->lmd_mgssec);
> seems to do the same job.

I'm working on that right at the moment. Patch shortly.

>
> >
> > @@ -905,7 +897,7 @@ static int lmd_parse_mgssec(struct lustr
> > else
> > length = tail - ptr;
> >
> > - OBD_ALLOC(lmd->lmd_mgssec, length + 1);
> > + lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS);
> > if (lmd->lmd_mgssec == NULL)
> > return -ENOMEM;
> >
>
> complicated why to say:
> lmd->lmd_mgssec=kstrndup(ptr, length,GFP_NOFS);

OK, I will look into it.

> > @@ -933,7 +925,7 @@ static int lmd_parse_string(char **handl
> > else
> > length = tail - ptr;
> >
> > - OBD_ALLOC(*handle, length + 1);
> > + *handle = kzalloc(length + 1, GFP_NOFS);
> > if (*handle == NULL)
> > return -ENOMEM;
> >
>
> lmd_parse_string() seems more or less the same as lmd_parse_mgssec().
> perhaps this can be merged.

I will check.

> > @@ -971,7 +963,7 @@ static int lmd_parse_mgs(struct lustre_m
> > /* Multiple mgsnid= are taken to mean failover locations */
> > memcpy(mgsnid, lmd->lmd_mgs, oldlen);
> > mgsnid[oldlen - 1] = ':';
> > - OBD_FREE(lmd->lmd_mgs, oldlen);
> > + kfree(lmd->lmd_mgs);
> > }
> > memcpy(mgsnid + oldlen, *ptr, length);
> > mgsnid[oldlen + length] = '\0';
>
> the code lmd_parse_mgs basicly does:
> kasprintf( &lmd->lmd_mgs,"%s:%s",lmd->lmd_mgs,*ptr);

OK.

thanks,
julia

2015-05-01 18:50:09

by Oleg Drokin

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

Hello!

On May 1, 2015, at 1:48 PM, Julia Lawall wrote:
>>> From: Julia Lawall <[email protected]>
>>>
>>> Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
>>> kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.
>>
>> Nak: James Simmons <[email protected]>
>>
>> A simple replace will not work. The OBD_ALLOC and OBD_FREE functions allocate memory
>> anywhere from one page to 4MB in size. You can't use kmalloc for the 4MB allocations.
>> Currently lustre uses a 4 page water mark to determine if we allocate using vmalloc. Even
>> using kmalloc for 4 pages has shown high failure rates on some systems. It gets even more
>> messy with 64K page systems like ppc64 boxes. Now I'm not suggesting to port the larger
>> allocations to vmalloc either since issues have been founded with using vmalloc. For example
>> when using large stripe count files the MDS rpc generated crosses the 4 page line and vmalloc
>> is used. Using vmalloc caused a global spinlock to be taken which causes meta data operations
>> to serialized on the MDS servers.
>
> It's not the LARGE functions that do the switching? For example OBD_ALLOC
> ends up at __OBD_MALLOC_VERBOSE, which as far as I can see calls kmalloc
> (with __GFP_ZERO, and hance the use of kzalloc).

This is true. We have OBD_ALLOC that is straight kmalloc and then we have OBD_ALLOC_LARGE
that depends on allocation size whenever it's kmalloc or vmalloc.

Similarly we have OBD_FREE and OBD_FREE_LARGE (This one could be converted straight into kvfree).

I think the patches look fine.

Bye,
Oleg-

2015-05-01 20:02:37

by Dan Carpenter

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

We are hopefully going to get rid of OBD_ALLOC_LARGE() as well, though.

It's simple enough to write a function:

void *obd_zalloc(size_t size)
{
if (size > 4 * PAGE_CACHE_SIZE)
return vzalloc(size);
else
return kmalloc(size, GFP_NOFS);
}

Except, huh? Shouldn't we be using GFP_NOFS for the vzalloc() side?
There was some discussion of that GFP_NOFS was a bit buggy back in 2010
(http://marc.info/?l=linux-mm&m=128942194520631&w=4) but the current
lustre code doesn't try to pass GFP_NOFS.

Then it's simple enough to change OBD_FREE_LARGE() to kvfree().

Also it's weird that only the lustre people have thought of this trick
to allocate big chunks of RAM and no one else has. What would happen if
we just change vmalloc() so it worked this way for everyone?

regards,
dan carpenter

2015-05-01 20:12:49

by Oleg Drokin

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree


On May 1, 2015, at 4:02 PM, Dan Carpenter wrote:

> We are hopefully going to get rid of OBD_ALLOC_LARGE() as well, though.
>
> It's simple enough to write a function:
>
> void *obd_zalloc(size_t size)
> {
> if (size > 4 * PAGE_CACHE_SIZE)
> return vzalloc(size);
> else
> return kmalloc(size, GFP_NOFS);

kzalloc here too. Except e also want to have locality of allocations.

> }
>
> Except, huh? Shouldn't we be using GFP_NOFS for the vzalloc() side?
> There was some discussion of that GFP_NOFS was a bit buggy back in 2010
> (http://marc.info/?l=linux-mm&m=128942194520631&w=4) but the current
> lustre code doesn't try to pass GFP_NOFS.

The patch I submitted was rejected, or so I think to remember, because we use __vmalloc_node
or something and it's not an exported symbol.
http://www.spinics.net/lists/linux-mm/msg83997.html

> Then it's simple enough to change OBD_FREE_LARGE() to kvfree().
>
> Also it's weird that only the lustre people have thought of this trick
> to allocate big chunks of RAM and no one else has. What would happen if
> we just change vmalloc() so it worked this way for everyone?

We are certainly not alone.
I saw this in a few other pieces of code.

void *ext4_kvmalloc(size_t size, gfp_t flags)
{
void *ret;

ret = kmalloc(size, flags | __GFP_NOWARN);
if (!ret)
ret = __vmalloc(size, flags, PAGE_KERNEL);
return ret;
}

or kmem_zalloc_large in xfs.

The difference at hand is that we pessimistically assume anything over certain threshold would
fail in kmalloc anyway and others actually do try kmalloc and only switch to vmalloc if kmaloc failed.
Considerign how expensive (and unsafe) vmalloc is, there might be some benefit to converting to their
way of doing things too.

Bye,
Oleg-

2015-05-01 20:19:02

by Simmons, James A.

[permalink] [raw]
Subject: RE: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

>> >From: Julia Lawall <[email protected]>
>> >
>> >Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
>> >kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.
>>
>> Nak: James Simmons <[email protected]>
>>
>> A simple replace will not work. The OBD_ALLOC and OBD_FREE functions allocate memory
>> anywhere from one page to 4MB in size. You can't use kmalloc for the 4MB allocations.
>> Currently lustre uses a 4 page water mark to determine if we allocate using vmalloc. Even
>> using kmalloc for 4 pages has shown high failure rates on some systems. It gets even more
>> messy with 64K page systems like ppc64 boxes. Now I'm not suggesting to port the larger
>> allocations to vmalloc either since issues have been founded with using vmalloc. For example
>> when using large stripe count files the MDS rpc generated crosses the 4 page line and vmalloc
>> is used. Using vmalloc caused a global spinlock to be taken which causes meta data operations
>> to serialized on the MDS servers.
>
>It's not the LARGE functions that do the switching? For example OBD_ALLOC
>ends up at __OBD_MALLOC_VERBOSE, which as far as I can see calls kmalloc
>(with __GFP_ZERO, and hance the use of kzalloc).

Yes the LARGE functions do the switching. I was expecting also patches to remove the
OBD_ALLOC_LARGE functions as well which is not the case here. I do have one question still. The
macro __OBD_MALLOC_VERBOSE allowed the ability to simulate memory allocation failures at
a certain percentage rate. Does something exist in the kernel to duplicate that functionality?
Once these macros are gone we lose the ability to simulate high memory allocation failures.

2015-05-01 20:36:10

by Simmons, James A.

[permalink] [raw]
Subject: RE: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

>We are hopefully going to get rid of OBD_ALLOC_LARGE() as well, though.
>
>It's simple enough to write a function:
>
>void *obd_zalloc(size_t size)
>{
> if (size > 4 * PAGE_CACHE_SIZE)
> return vzalloc(size);
> else
> return kmalloc(size, GFP_NOFS);
>}
>
>Except, huh? Shouldn't we be using GFP_NOFS for the vzalloc() side?
>There was some discussion of that GFP_NOFS was a bit buggy back in 2010
>(http://marc.info/?l=linux-mm&m=128942194520631&w=4) but the current
>lustre code doesn't try to pass GFP_NOFS.

The version in the upstream client is out of date. The current macro in the Intel master
Branch is:

#define __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size) \
do { \
(ptr) = cptab == NULL ? \
__vmalloc(size, GFP_NOFS | __GFP_HIGHMEM | __GFP_ZERO, \
PAGE_KERNEL) : \
cfs_cpt_vzalloc(cptab, cpt, size); \
if (unlikely((ptr) == NULL)) { \
CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n", \
(int)(size)); \
CERROR(LPU64" total bytes allocated by Lustre, %d by LNET\n", \
obd_memory_sum(), atomic_read(&libcfs_kmemory)); \
} else { \
OBD_ALLOC_POST(ptr, size, "vmalloced"); \
} \
} while(0)

>Then it's simple enough to change OBD_FREE_LARGE() to kvfree().
>
>Also it's weird that only the lustre people have thought of this trick
>to allocate big chunks of RAM and no one else has. What would happen if
>we just change vmalloc() so it worked this way for everyone?

Do we really want to encourage vmalloc usages?

2015-05-01 20:47:40

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

On Fri, May 01, 2015 at 08:18:56PM +0000, Simmons, James A. wrote:
> >> >From: Julia Lawall <[email protected]>
> >> >
> >> >Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
> >> >kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.
> >>
> >> Nak: James Simmons <[email protected]>
> >>
> >> A simple replace will not work. The OBD_ALLOC and OBD_FREE functions allocate memory
> >> anywhere from one page to 4MB in size. You can't use kmalloc for the 4MB allocations.
> >> Currently lustre uses a 4 page water mark to determine if we allocate using vmalloc. Even
> >> using kmalloc for 4 pages has shown high failure rates on some systems. It gets even more
> >> messy with 64K page systems like ppc64 boxes. Now I'm not suggesting to port the larger
> >> allocations to vmalloc either since issues have been founded with using vmalloc. For example
> >> when using large stripe count files the MDS rpc generated crosses the 4 page line and vmalloc
> >> is used. Using vmalloc caused a global spinlock to be taken which causes meta data operations
> >> to serialized on the MDS servers.
> >
> >It's not the LARGE functions that do the switching? For example OBD_ALLOC
> >ends up at __OBD_MALLOC_VERBOSE, which as far as I can see calls kmalloc
> >(with __GFP_ZERO, and hance the use of kzalloc).
>
> Yes the LARGE functions do the switching. I was expecting also patches to remove the
> OBD_ALLOC_LARGE functions as well which is not the case here. I do have one question still. The
> macro __OBD_MALLOC_VERBOSE allowed the ability to simulate memory allocation failures at
> a certain percentage rate. Does something exist in the kernel to duplicate that functionality?

Yes, no need for lustre to duplicate yet-another-thing the kernel
already provides :)

2015-05-01 20:49:32

by Oleg Drokin

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree


On May 1, 2015, at 4:18 PM, Simmons, James A. wrote:

> Yes the LARGE functions do the switching. I was expecting also patches to remove the
> OBD_ALLOC_LARGE functions as well which is not the case here. I do have one question still. The
> macro __OBD_MALLOC_VERBOSE allowed the ability to simulate memory allocation failures at
> a certain percentage rate. Does something exist in the kernel to duplicate that functionality?
> Once these macros are gone we lose the ability to simulate high memory allocation failures.

Yes, there are things like https://lkml.org/lkml/2014/12/25/64
So I think the API is even riher compared to what our old wrapper code was able to do.

Bye,
Oleg-

2015-05-01 20:49:37

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

On Fri, May 01, 2015 at 08:36:05PM +0000, Simmons, James A. wrote:
> >We are hopefully going to get rid of OBD_ALLOC_LARGE() as well, though.
> >
> >It's simple enough to write a function:
> >
> >void *obd_zalloc(size_t size)
> >{
> > if (size > 4 * PAGE_CACHE_SIZE)
> > return vzalloc(size);
> > else
> > return kmalloc(size, GFP_NOFS);
> >}
> >
> >Except, huh? Shouldn't we be using GFP_NOFS for the vzalloc() side?
> >There was some discussion of that GFP_NOFS was a bit buggy back in 2010
> >(http://marc.info/?l=linux-mm&m=128942194520631&w=4) but the current
> >lustre code doesn't try to pass GFP_NOFS.
>
> The version in the upstream client is out of date. The current macro in the Intel master
> Branch is:

That's not helpful at all, why do we even have an in-kernel version of
this code if you don't do your development in the kernel?

Please sync with the kernel tree very soon, or I'm just going to delete
this whole thing. This is getting _really_ frustrating.

greg k-h

2015-05-01 20:52:40

by Oleg Drokin

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree


On May 1, 2015, at 4:49 PM, Greg Kroah-Hartman wrote:

> On Fri, May 01, 2015 at 08:36:05PM +0000, Simmons, James A. wrote:
>>> We are hopefully going to get rid of OBD_ALLOC_LARGE() as well, though.
>>>
>>> It's simple enough to write a function:
>>>
>>> void *obd_zalloc(size_t size)
>>> {
>>> if (size > 4 * PAGE_CACHE_SIZE)
>>> return vzalloc(size);
>>> else
>>> return kmalloc(size, GFP_NOFS);
>>> }
>>>
>>> Except, huh? Shouldn't we be using GFP_NOFS for the vzalloc() side?
>>> There was some discussion of that GFP_NOFS was a bit buggy back in 2010
>>> (http://marc.info/?l=linux-mm&m=128942194520631&w=4) but the current
>>> lustre code doesn't try to pass GFP_NOFS.
>>
>> The version in the upstream client is out of date. The current macro in the Intel master
>> Branch is:
>
> That's not helpful at all, why do we even have an in-kernel version of
> this code if you don't do your development in the kernel?
>
> Please sync with the kernel tree very soon, or I'm just going to delete
> this whole thing. This is getting _really_ frustrating.

The patch was submitted.
But it depends on a symbol that's not exported.
I was not able to change that.
http://www.spinics.net/lists/linux-mm/msg83997.html

Bye,
Oleg-

2015-05-01 20:58:42

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

On Fri, May 01, 2015 at 08:52:37PM +0000, Drokin, Oleg wrote:
>
> On May 1, 2015, at 4:49 PM, Greg Kroah-Hartman wrote:
>
> > On Fri, May 01, 2015 at 08:36:05PM +0000, Simmons, James A. wrote:
> >>> We are hopefully going to get rid of OBD_ALLOC_LARGE() as well, though.
> >>>
> >>> It's simple enough to write a function:
> >>>
> >>> void *obd_zalloc(size_t size)
> >>> {
> >>> if (size > 4 * PAGE_CACHE_SIZE)
> >>> return vzalloc(size);
> >>> else
> >>> return kmalloc(size, GFP_NOFS);
> >>> }
> >>>
> >>> Except, huh? Shouldn't we be using GFP_NOFS for the vzalloc() side?
> >>> There was some discussion of that GFP_NOFS was a bit buggy back in 2010
> >>> (http://marc.info/?l=linux-mm&m=128942194520631&w=4) but the current
> >>> lustre code doesn't try to pass GFP_NOFS.
> >>
> >> The version in the upstream client is out of date. The current macro in the Intel master
> >> Branch is:
> >
> > That's not helpful at all, why do we even have an in-kernel version of
> > this code if you don't do your development in the kernel?
> >
> > Please sync with the kernel tree very soon, or I'm just going to delete
> > this whole thing. This is getting _really_ frustrating.
>
> The patch was submitted.
> But it depends on a symbol that's not exported.
> I was not able to change that.
> http://www.spinics.net/lists/linux-mm/msg83997.html

But you were given a hint on how to change that :)

Anyway, I'd recommend switching to what ext4 and xfs does, as you point
out in another email in this thread, it looks a lot better overall.

thanks,

greg k-h

2015-05-01 21:14:06

by Oleg Drokin

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree


On May 1, 2015, at 4:58 PM, Greg Kroah-Hartman wrote:

> On Fri, May 01, 2015 at 08:52:37PM +0000, Drokin, Oleg wrote:
>>
>> On May 1, 2015, at 4:49 PM, Greg Kroah-Hartman wrote:
>>
>>> On Fri, May 01, 2015 at 08:36:05PM +0000, Simmons, James A. wrote:
>>>>> We are hopefully going to get rid of OBD_ALLOC_LARGE() as well, though.
>>>>>
>>>>> It's simple enough to write a function:
>>>>>
>>>>> void *obd_zalloc(size_t size)
>>>>> {
>>>>> if (size > 4 * PAGE_CACHE_SIZE)
>>>>> return vzalloc(size);
>>>>> else
>>>>> return kmalloc(size, GFP_NOFS);
>>>>> }
>>>>>
>>>>> Except, huh? Shouldn't we be using GFP_NOFS for the vzalloc() side?
>>>>> There was some discussion of that GFP_NOFS was a bit buggy back in 2010
>>>>> (http://marc.info/?l=linux-mm&m=128942194520631&w=4) but the current
>>>>> lustre code doesn't try to pass GFP_NOFS.
>>>>
>>>> The version in the upstream client is out of date. The current macro in the Intel master
>>>> Branch is:
>>>
>>> That's not helpful at all, why do we even have an in-kernel version of
>>> this code if you don't do your development in the kernel?
>>>
>>> Please sync with the kernel tree very soon, or I'm just going to delete
>>> this whole thing. This is getting _really_ frustrating.
>>
>> The patch was submitted.
>> But it depends on a symbol that's not exported.
>> I was not able to change that.
>> http://www.spinics.net/lists/linux-mm/msg83997.html
>
> But you were given a hint on how to change that :)

Well, the hint amounted to "don't do vmalloc if you cannot live with the
GFP_KERNEL" allocations.

In any case once we unroll the OBD_ALLOC* (esp. the _LARGE ones), it should be possible
to go through those cases and adjust GFP flags to less restrictive where possible
(right now our macro is way too rigid and does not take gfp flags at all).

> Anyway, I'd recommend switching to what ext4 and xfs does, as you point
> out in another email in this thread, it looks a lot better overall.

Yes, I imagine Julia will include that as the new lustre_kvzalloc() define
to be used in all OBD_ALLOC_LARGE instances.
I can provide the desired code if necessary (it's actually a bit less than trivial
because in some cases we also have that numa-aware node thing).

though if we are ok to review that later, then almost a copy of ext4 one would do like this:
void *lustre_kvzalloc(size_t size, gfp_t flags)
{
void *ret;

ret = kzalloc(size, flags | __GFP_NOWARN);
if (!ret)
ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
return ret;
}


Bye,
Oleg-

2015-05-01 22:57:49

by Simmons, James A.

[permalink] [raw]
Subject: RE: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

>> Yes the LARGE functions do the switching. I was expecting also patches to remove the
>> OBD_ALLOC_LARGE functions as well which is not the case here. I do have one question still. The
>> macro __OBD_MALLOC_VERBOSE allowed the ability to simulate memory allocation failures at
>> a certain percentage rate. Does something exist in the kernel to duplicate that functionality?
>
>Yes, no need for lustre to duplicate yet-another-thing the kernel
>already provides :)

The reason for this is that libcfs was written 10+ years ago which was before linux had such nice
features. At that time it was needed to fill the gaps missing which is no longer the case. Libcfs is
really showing its age :-)

2015-05-01 22:59:46

by Simmons, James A.

[permalink] [raw]
Subject: RE: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

>> Yes the LARGE functions do the switching. I was expecting also patches to remove the
>> OBD_ALLOC_LARGE functions as well which is not the case here. I do have one question still. The
>> macro __OBD_MALLOC_VERBOSE allowed the ability to simulate memory allocation failures at
>> a certain percentage rate. Does something exist in the kernel to duplicate that functionality?
>> Once these macros are gone we lose the ability to simulate high memory allocation failures.
>
>Yes, there are things like https://lkml.org/lkml/2014/12/25/64
>So I think the API is even riher compared to what our old wrapper code was able to do.

We should look to integrating that into the test suite.

2015-05-02 06:02:07

by Julia Lawall

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

> Yes, I imagine Julia will include that as the new lustre_kvzalloc() define
> to be used in all OBD_ALLOC_LARGE instances.
> I can provide the desired code if necessary (it's actually a bit less than trivial
> because in some cases we also have that numa-aware node thing).

Oleg,

If you could send a patch with the proper definition, that would be very
helpful, thanks. When that is in place, I can update the uses.

thanks,
julia

> though if we are ok to review that later, then almost a copy of ext4 one would do like this:
> void *lustre_kvzalloc(size_t size, gfp_t flags)
> {
> void *ret;
>
> ret = kzalloc(size, flags | __GFP_NOWARN);
> if (!ret)
> ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
> return ret;
> }
>
>
> Bye,
> Oleg

2015-05-02 08:14:34

by Dan Carpenter

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

On Fri, May 01, 2015 at 09:13:11PM +0000, Drokin, Oleg wrote:
> >> The patch was submitted.
> >> But it depends on a symbol that's not exported.
> >> I was not able to change that.
> >> http://www.spinics.net/lists/linux-mm/msg83997.html
> >
> > But you were given a hint on how to change that :)
>
> Well, the hint amounted to "don't do vmalloc if you cannot live with the
> GFP_KERNEL" allocations.
>

Which email is that?

I only see where David says to implement vmalloc_node_gfp() and the talk
was about if that makes sense from a style perspective and then dies.

Anyway, this only seems to affect ptlrpc_alloc_rqbd() since I think
that's the only place which calls OBD_CPT_ALLOC_PTR(). The rest can use
__vmalloc().

regards,
dan carpenter

2015-05-02 09:05:38

by Julia Lawall

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree



On Sat, 2 May 2015, Dan Carpenter wrote:

> On Fri, May 01, 2015 at 09:13:11PM +0000, Drokin, Oleg wrote:
> > >> The patch was submitted.
> > >> But it depends on a symbol that's not exported.
> > >> I was not able to change that.
> > >> http://www.spinics.net/lists/linux-mm/msg83997.html
> > >
> > > But you were given a hint on how to change that :)
> >
> > Well, the hint amounted to "don't do vmalloc if you cannot live with the
> > GFP_KERNEL" allocations.
> >
>
> Which email is that?
>
> I only see where David says to implement vmalloc_node_gfp() and the talk
> was about if that makes sense from a style perspective and then dies.
>
> Anyway, this only seems to affect ptlrpc_alloc_rqbd() since I think
> that's the only place which calls OBD_CPT_ALLOC_PTR(). The rest can use
> __vmalloc().

I think you mean "that's the only place which calls OBD_CPT_ALLOC_LARGE".

julia

>
> regards,
> dan carpenter
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2015-05-03 03:12:42

by Oleg Drokin

[permalink] [raw]
Subject: Re: [HPDD-discuss] [PATCH 2/11] Staging: lustre: fld: Use kzalloc and kfree

Hello!

On May 2, 2015, at 4:14 AM, Dan Carpenter wrote:

> On Fri, May 01, 2015 at 09:13:11PM +0000, Drokin, Oleg wrote:
>>>> The patch was submitted.
>>>> But it depends on a symbol that's not exported.
>>>> I was not able to change that.
>>>> http://www.spinics.net/lists/linux-mm/msg83997.html
>>>
>>> But you were given a hint on how to change that :)
>>
>> Well, the hint amounted to "don't do vmalloc if you cannot live with the
>> GFP_KERNEL" allocations.
>>
>
> Which email is that?

Ah, my memory is playing tricks, it appears.
There was just a pointer to the "other discussions" where this advice was given it appears.

> I only see where David says to implement vmalloc_node_gfp() and the talk
> was about if that makes sense from a style perspective and then dies.
>
> Anyway, this only seems to affect ptlrpc_alloc_rqbd() since I think
> that's the only place which calls OBD_CPT_ALLOC_PTR(). The rest can use
> __vmalloc().

I guess so.

Bye,
Oleg-

2015-05-03 18:33:24

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 0/11] Use kzalloc and kfree

On Fri, May 01, 2015 at 05:51:11PM +0200, Julia Lawall wrote:
> Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
> kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree. The complete
> semantic patch that makes these changes is as follows:
> (http://coccinelle.lip6.fr/)

<snip>

You lost the leading '0' on the early patches here, did you use git
send-email for these? I'll just sort them by hand, but in the future,
please fix it up to make it easier to apply things.

thanks,

greg k-h

2015-05-03 18:39:47

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 0/11] Use kzalloc and kfree

On Sun, 3 May 2015, Greg Kroah-Hartman wrote:

> On Fri, May 01, 2015 at 05:51:11PM +0200, Julia Lawall wrote:
> > Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
> > kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree. The complete
> > semantic patch that makes these changes is as follows:
> > (http://coccinelle.lip6.fr/)
>
> <snip>
>
> You lost the leading '0' on the early patches here, did you use git
> send-email for these? I'll just sort them by hand, but in the future,
> please fix it up to make it easier to apply things.

I will fix it.

julia