Commit ee3b1e23 authored by NeilBrown's avatar NeilBrown Committed by Greg Kroah-Hartman
Browse files

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: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 508d5e0f
Loading
Loading
Loading
Loading
+1 −62
Original line number Diff line number Diff line
@@ -181,21 +181,6 @@ lnet_net_lock_current(void)

#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 *
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]);
	}

	LIBCFS_ALLOC(md, size);
	md = kzalloc(size, GFP_NOFS);

	if (md) {
		/* Set here in case of early free */
@@ -223,52 +208,6 @@ lnet_md_alloc(struct lnet_md *umd)
	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,
					  __u64 cookie);
void lnet_res_lh_initialize(struct lnet_res_container *rec,
+2 −2
Original line number Diff line number Diff line
@@ -384,10 +384,10 @@ lnet_res_container_cleanup(struct lnet_res_container *rec)

		list_del_init(e);
		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) {
			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 */
			LBUG();
+3 −3
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback,
	if (!count && callback == LNET_EQ_HANDLER_NONE)
		return -EINVAL;

	eq = lnet_eq_alloc();
	eq = kzalloc(sizeof(*eq), GFP_NOFS);
	if (!eq)
		return -ENOMEM;

@@ -138,7 +138,7 @@ failed:
	if (eq->eq_refs)
		cfs_percpt_free(eq->eq_refs);

	lnet_eq_free(eq);
	kfree(eq);
	return -ENOMEM;
}
EXPORT_SYMBOL(LNetEQAlloc);
@@ -197,7 +197,7 @@ LNetEQFree(struct lnet_handle_eq eqh)

	lnet_res_lh_invalidate(&eq->eq_lh);
	list_del(&eq->eq_list);
	lnet_eq_free(eq);
	kfree(eq);
 out:
	lnet_eq_wait_unlock();
	lnet_res_unlock(LNET_LOCK_EX);
+4 −4
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ lnet_md_unlink(struct lnet_libmd *md)

	LASSERT(!list_empty(&md->md_list));
	list_del_init(&md->md_list);
	lnet_md_free(md);
	kfree(md);
}

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.
	 * 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
@@ -329,7 +329,7 @@ LNetMDAttach(struct lnet_handle_me meh, struct lnet_md umd,
out_unlock:
	lnet_res_unlock(cpt);
out_free:
	lnet_md_free(md);
	kfree(md);
	return rc;
}
EXPORT_SYMBOL(LNetMDAttach);
@@ -390,7 +390,7 @@ LNetMDBind(struct lnet_md umd, enum lnet_unlink unlink,
out_unlock:
	lnet_res_unlock(cpt);
out_free:
	lnet_md_free(md);
	kfree(md);

	return rc;
}
+5 −5
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ LNetMEAttach(unsigned int portal,
	if (!mtable) /* can't match portal type */
		return -EPERM;

	me = lnet_me_alloc();
	me = kzalloc(sizeof(*me), GFP_NOFS);
	if (!me)
		return -ENOMEM;

@@ -157,7 +157,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
	if (pos == LNET_INS_LOCAL)
		return -EPERM;

	new_me = lnet_me_alloc();
	new_me = kzalloc(sizeof(*new_me), GFP_NOFS);
	if (!new_me)
		return -ENOMEM;

@@ -167,7 +167,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,

	current_me = lnet_handle2me(&current_meh);
	if (!current_me) {
		lnet_me_free(new_me);
		kfree(new_me);

		lnet_res_unlock(cpt);
		return -ENOENT;
@@ -178,7 +178,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
	ptl = the_lnet.ln_portals[current_me->me_portal];
	if (lnet_ptl_is_unique(ptl)) {
		/* nosense to insertion on unique portal */
		lnet_me_free(new_me);
		kfree(new_me);
		lnet_res_unlock(cpt);
		return -EPERM;
	}
@@ -270,5 +270,5 @@ lnet_me_unlink(struct lnet_me *me)
	}

	lnet_res_lh_invalidate(&me->me_lh);
	lnet_me_free(me);
	kfree(me);
}
Loading