staging: lustre: lnet-lib: opencode some alloc/free functions.
These functions just call LIBCFS_ALLOC() which in-turn calls kvmalloc(). In none of these cases is the 'vmalloc' option needed. LIBCFS_ALLOC also produces a warning if NULL is returned, but that can be provided with CONFIG_SLAB_DEBUG. LIBCFS_ALLOC zeros the memory, so we need to use __GFP_ZERO too. So with one exception where the alloc function is not trivial, open-code the alloc and free functions using kmalloc and kfree. Note that the 'size' used in lnet_md_alloc() is limited and less than a page because LNET_MAX_IOV is 256, so kvmalloc is not needed. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
508d5e0f4d
commit
ee3b1e23bd
|
@ -181,21 +181,6 @@ lnet_net_lock_current(void)
|
||||||
|
|
||||||
#define MAX_PORTALS 64
|
#define MAX_PORTALS 64
|
||||||
|
|
||||||
static inline struct lnet_eq *
|
|
||||||
lnet_eq_alloc(void)
|
|
||||||
{
|
|
||||||
struct lnet_eq *eq;
|
|
||||||
|
|
||||||
LIBCFS_ALLOC(eq, sizeof(*eq));
|
|
||||||
return eq;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
lnet_eq_free(struct lnet_eq *eq)
|
|
||||||
{
|
|
||||||
LIBCFS_FREE(eq, sizeof(*eq));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct lnet_libmd *
|
static inline struct lnet_libmd *
|
||||||
lnet_md_alloc(struct lnet_md *umd)
|
lnet_md_alloc(struct lnet_md *umd)
|
||||||
{
|
{
|
||||||
|
@ -211,7 +196,7 @@ lnet_md_alloc(struct lnet_md *umd)
|
||||||
size = offsetof(struct lnet_libmd, md_iov.iov[niov]);
|
size = offsetof(struct lnet_libmd, md_iov.iov[niov]);
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBCFS_ALLOC(md, size);
|
md = kzalloc(size, GFP_NOFS);
|
||||||
|
|
||||||
if (md) {
|
if (md) {
|
||||||
/* Set here in case of early free */
|
/* Set here in case of early free */
|
||||||
|
@ -223,52 +208,6 @@ lnet_md_alloc(struct lnet_md *umd)
|
||||||
return md;
|
return md;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
|
||||||
lnet_md_free(struct lnet_libmd *md)
|
|
||||||
{
|
|
||||||
unsigned int size;
|
|
||||||
|
|
||||||
if (md->md_options & LNET_MD_KIOV)
|
|
||||||
size = offsetof(struct lnet_libmd, md_iov.kiov[md->md_niov]);
|
|
||||||
else
|
|
||||||
size = offsetof(struct lnet_libmd, md_iov.iov[md->md_niov]);
|
|
||||||
|
|
||||||
LIBCFS_FREE(md, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct lnet_me *
|
|
||||||
lnet_me_alloc(void)
|
|
||||||
{
|
|
||||||
struct lnet_me *me;
|
|
||||||
|
|
||||||
LIBCFS_ALLOC(me, sizeof(*me));
|
|
||||||
return me;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
lnet_me_free(struct lnet_me *me)
|
|
||||||
{
|
|
||||||
LIBCFS_FREE(me, sizeof(*me));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct lnet_msg *
|
|
||||||
lnet_msg_alloc(void)
|
|
||||||
{
|
|
||||||
struct lnet_msg *msg;
|
|
||||||
|
|
||||||
LIBCFS_ALLOC(msg, sizeof(*msg));
|
|
||||||
|
|
||||||
/* no need to zero, LIBCFS_ALLOC does for us */
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
lnet_msg_free(struct lnet_msg *msg)
|
|
||||||
{
|
|
||||||
LASSERT(!msg->msg_onactivelist);
|
|
||||||
LIBCFS_FREE(msg, sizeof(*msg));
|
|
||||||
}
|
|
||||||
|
|
||||||
struct lnet_libhandle *lnet_res_lh_lookup(struct lnet_res_container *rec,
|
struct lnet_libhandle *lnet_res_lh_lookup(struct lnet_res_container *rec,
|
||||||
__u64 cookie);
|
__u64 cookie);
|
||||||
void lnet_res_lh_initialize(struct lnet_res_container *rec,
|
void lnet_res_lh_initialize(struct lnet_res_container *rec,
|
||||||
|
|
|
@ -384,10 +384,10 @@ lnet_res_container_cleanup(struct lnet_res_container *rec)
|
||||||
|
|
||||||
list_del_init(e);
|
list_del_init(e);
|
||||||
if (rec->rec_type == LNET_COOKIE_TYPE_EQ) {
|
if (rec->rec_type == LNET_COOKIE_TYPE_EQ) {
|
||||||
lnet_eq_free(list_entry(e, struct lnet_eq, eq_list));
|
kfree(list_entry(e, struct lnet_eq, eq_list));
|
||||||
|
|
||||||
} else if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
|
} else if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
|
||||||
lnet_md_free(list_entry(e, struct lnet_libmd, md_list));
|
kfree(list_entry(e, struct lnet_libmd, md_list));
|
||||||
|
|
||||||
} else { /* NB: Active MEs should be attached on portals */
|
} else { /* NB: Active MEs should be attached on portals */
|
||||||
LBUG();
|
LBUG();
|
||||||
|
|
|
@ -90,7 +90,7 @@ LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback,
|
||||||
if (!count && callback == LNET_EQ_HANDLER_NONE)
|
if (!count && callback == LNET_EQ_HANDLER_NONE)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
eq = lnet_eq_alloc();
|
eq = kzalloc(sizeof(*eq), GFP_NOFS);
|
||||||
if (!eq)
|
if (!eq)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback,
|
||||||
if (eq->eq_refs)
|
if (eq->eq_refs)
|
||||||
cfs_percpt_free(eq->eq_refs);
|
cfs_percpt_free(eq->eq_refs);
|
||||||
|
|
||||||
lnet_eq_free(eq);
|
kfree(eq);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(LNetEQAlloc);
|
EXPORT_SYMBOL(LNetEQAlloc);
|
||||||
|
@ -197,7 +197,7 @@ LNetEQFree(struct lnet_handle_eq eqh)
|
||||||
|
|
||||||
lnet_res_lh_invalidate(&eq->eq_lh);
|
lnet_res_lh_invalidate(&eq->eq_lh);
|
||||||
list_del(&eq->eq_list);
|
list_del(&eq->eq_list);
|
||||||
lnet_eq_free(eq);
|
kfree(eq);
|
||||||
out:
|
out:
|
||||||
lnet_eq_wait_unlock();
|
lnet_eq_wait_unlock();
|
||||||
lnet_res_unlock(LNET_LOCK_EX);
|
lnet_res_unlock(LNET_LOCK_EX);
|
||||||
|
|
|
@ -81,7 +81,7 @@ lnet_md_unlink(struct lnet_libmd *md)
|
||||||
|
|
||||||
LASSERT(!list_empty(&md->md_list));
|
LASSERT(!list_empty(&md->md_list));
|
||||||
list_del_init(&md->md_list);
|
list_del_init(&md->md_list);
|
||||||
lnet_md_free(md);
|
kfree(md);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -173,7 +173,7 @@ lnet_md_link(struct lnet_libmd *md, struct lnet_handle_eq eq_handle, int cpt)
|
||||||
/*
|
/*
|
||||||
* NB we are passed an allocated, but inactive md.
|
* NB we are passed an allocated, but inactive md.
|
||||||
* if we return success, caller may lnet_md_unlink() it.
|
* if we return success, caller may lnet_md_unlink() it.
|
||||||
* otherwise caller may only lnet_md_free() it.
|
* otherwise caller may only kfree() it.
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* This implementation doesn't know how to create START events or
|
* This implementation doesn't know how to create START events or
|
||||||
|
@ -329,7 +329,7 @@ LNetMDAttach(struct lnet_handle_me meh, struct lnet_md umd,
|
||||||
out_unlock:
|
out_unlock:
|
||||||
lnet_res_unlock(cpt);
|
lnet_res_unlock(cpt);
|
||||||
out_free:
|
out_free:
|
||||||
lnet_md_free(md);
|
kfree(md);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(LNetMDAttach);
|
EXPORT_SYMBOL(LNetMDAttach);
|
||||||
|
@ -390,7 +390,7 @@ LNetMDBind(struct lnet_md umd, enum lnet_unlink unlink,
|
||||||
out_unlock:
|
out_unlock:
|
||||||
lnet_res_unlock(cpt);
|
lnet_res_unlock(cpt);
|
||||||
out_free:
|
out_free:
|
||||||
lnet_md_free(md);
|
kfree(md);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ LNetMEAttach(unsigned int portal,
|
||||||
if (!mtable) /* can't match portal type */
|
if (!mtable) /* can't match portal type */
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
me = lnet_me_alloc();
|
me = kzalloc(sizeof(*me), GFP_NOFS);
|
||||||
if (!me)
|
if (!me)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
|
||||||
if (pos == LNET_INS_LOCAL)
|
if (pos == LNET_INS_LOCAL)
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
new_me = lnet_me_alloc();
|
new_me = kzalloc(sizeof(*new_me), GFP_NOFS);
|
||||||
if (!new_me)
|
if (!new_me)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
|
||||||
|
|
||||||
current_me = lnet_handle2me(¤t_meh);
|
current_me = lnet_handle2me(¤t_meh);
|
||||||
if (!current_me) {
|
if (!current_me) {
|
||||||
lnet_me_free(new_me);
|
kfree(new_me);
|
||||||
|
|
||||||
lnet_res_unlock(cpt);
|
lnet_res_unlock(cpt);
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
@ -178,7 +178,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
|
||||||
ptl = the_lnet.ln_portals[current_me->me_portal];
|
ptl = the_lnet.ln_portals[current_me->me_portal];
|
||||||
if (lnet_ptl_is_unique(ptl)) {
|
if (lnet_ptl_is_unique(ptl)) {
|
||||||
/* nosense to insertion on unique portal */
|
/* nosense to insertion on unique portal */
|
||||||
lnet_me_free(new_me);
|
kfree(new_me);
|
||||||
lnet_res_unlock(cpt);
|
lnet_res_unlock(cpt);
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
}
|
}
|
||||||
|
@ -270,5 +270,5 @@ lnet_me_unlink(struct lnet_me *me)
|
||||||
}
|
}
|
||||||
|
|
||||||
lnet_res_lh_invalidate(&me->me_lh);
|
lnet_res_lh_invalidate(&me->me_lh);
|
||||||
lnet_me_free(me);
|
kfree(me);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1769,7 +1769,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = lnet_msg_alloc();
|
msg = kzalloc(sizeof(*msg), GFP_NOFS);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
CERROR("%s, src %s: Dropping %s (out of memory)\n",
|
CERROR("%s, src %s: Dropping %s (out of memory)\n",
|
||||||
libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
|
libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
|
||||||
|
@ -1777,7 +1777,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* msg zeroed in lnet_msg_alloc;
|
/* msg zeroed by kzalloc()
|
||||||
* i.e. flags all clear, pointers NULL etc
|
* i.e. flags all clear, pointers NULL etc
|
||||||
*/
|
*/
|
||||||
msg->msg_type = type;
|
msg->msg_type = type;
|
||||||
|
@ -1812,7 +1812,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
|
||||||
CERROR("%s, src %s: Dropping %s (error %d looking up sender)\n",
|
CERROR("%s, src %s: Dropping %s (error %d looking up sender)\n",
|
||||||
libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
|
libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
|
||||||
lnet_msgtyp2str(type), rc);
|
lnet_msgtyp2str(type), rc);
|
||||||
lnet_msg_free(msg);
|
kfree(msg);
|
||||||
if (rc == -ESHUTDOWN)
|
if (rc == -ESHUTDOWN)
|
||||||
/* We are shutting down. Don't do anything more */
|
/* We are shutting down. Don't do anything more */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2010,7 +2010,7 @@ LNetPut(lnet_nid_t self, struct lnet_handle_md mdh, enum lnet_ack_req ack,
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = lnet_msg_alloc();
|
msg = kzalloc(sizeof(*msg), GFP_NOFS);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
CERROR("Dropping PUT to %s: ENOMEM on struct lnet_msg\n",
|
CERROR("Dropping PUT to %s: ENOMEM on struct lnet_msg\n",
|
||||||
libcfs_id2str(target));
|
libcfs_id2str(target));
|
||||||
|
@ -2031,7 +2031,7 @@ LNetPut(lnet_nid_t self, struct lnet_handle_md mdh, enum lnet_ack_req ack,
|
||||||
md->md_me->me_portal);
|
md->md_me->me_portal);
|
||||||
lnet_res_unlock(cpt);
|
lnet_res_unlock(cpt);
|
||||||
|
|
||||||
lnet_msg_free(msg);
|
kfree(msg);
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2086,7 +2086,7 @@ lnet_create_reply_msg(struct lnet_ni *ni, struct lnet_msg *getmsg)
|
||||||
* CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
|
* CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
|
||||||
* lnet_finalize() is called on it, so the LND must call this first
|
* lnet_finalize() is called on it, so the LND must call this first
|
||||||
*/
|
*/
|
||||||
struct lnet_msg *msg = lnet_msg_alloc();
|
struct lnet_msg *msg = kzalloc(sizeof(*msg), GFP_NOFS);
|
||||||
struct lnet_libmd *getmd = getmsg->msg_md;
|
struct lnet_libmd *getmd = getmsg->msg_md;
|
||||||
struct lnet_process_id peer_id = getmsg->msg_target;
|
struct lnet_process_id peer_id = getmsg->msg_target;
|
||||||
int cpt;
|
int cpt;
|
||||||
|
@ -2147,7 +2147,7 @@ lnet_create_reply_msg(struct lnet_ni *ni, struct lnet_msg *getmsg)
|
||||||
lnet_net_unlock(cpt);
|
lnet_net_unlock(cpt);
|
||||||
|
|
||||||
if (msg)
|
if (msg)
|
||||||
lnet_msg_free(msg);
|
kfree(msg);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2215,7 +2215,7 @@ LNetGet(lnet_nid_t self, struct lnet_handle_md mdh,
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = lnet_msg_alloc();
|
msg = kzalloc(sizeof(*msg), GFP_NOFS);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
CERROR("Dropping GET to %s: ENOMEM on struct lnet_msg\n",
|
CERROR("Dropping GET to %s: ENOMEM on struct lnet_msg\n",
|
||||||
libcfs_id2str(target));
|
libcfs_id2str(target));
|
||||||
|
@ -2236,7 +2236,7 @@ LNetGet(lnet_nid_t self, struct lnet_handle_md mdh,
|
||||||
|
|
||||||
lnet_res_unlock(cpt);
|
lnet_res_unlock(cpt);
|
||||||
|
|
||||||
lnet_msg_free(msg);
|
kfree(msg);
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -433,7 +433,7 @@ lnet_complete_msg_locked(struct lnet_msg *msg, int cpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
lnet_msg_decommit(msg, cpt, status);
|
lnet_msg_decommit(msg, cpt, status);
|
||||||
lnet_msg_free(msg);
|
kfree(msg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,7 +466,7 @@ lnet_finalize(struct lnet_ni *ni, struct lnet_msg *msg, int status)
|
||||||
if (!msg->msg_tx_committed && !msg->msg_rx_committed) {
|
if (!msg->msg_tx_committed && !msg->msg_rx_committed) {
|
||||||
/* not committed to network yet */
|
/* not committed to network yet */
|
||||||
LASSERT(!msg->msg_onactivelist);
|
LASSERT(!msg->msg_onactivelist);
|
||||||
lnet_msg_free(msg);
|
kfree(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,7 +546,7 @@ lnet_msg_container_cleanup(struct lnet_msg_container *container)
|
||||||
LASSERT(msg->msg_onactivelist);
|
LASSERT(msg->msg_onactivelist);
|
||||||
msg->msg_onactivelist = 0;
|
msg->msg_onactivelist = 0;
|
||||||
list_del(&msg->msg_activelist);
|
list_del(&msg->msg_activelist);
|
||||||
lnet_msg_free(msg);
|
kfree(msg);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -771,7 +771,7 @@ lnet_ptl_cleanup(struct lnet_portal *ptl)
|
||||||
struct lnet_me, me_list);
|
struct lnet_me, me_list);
|
||||||
CERROR("Active ME %p on exit\n", me);
|
CERROR("Active ME %p on exit\n", me);
|
||||||
list_del(&me->me_list);
|
list_del(&me->me_list);
|
||||||
lnet_me_free(me);
|
kfree(me);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* the extra entry is for MEs with ignore bits */
|
/* the extra entry is for MEs with ignore bits */
|
||||||
|
|
Loading…
Reference in New Issue