diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-02-01 09:51:57 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-02-01 09:51:57 -0800 |
commit | 5d8515bc232172963a4cef007e97b08c5e4d0533 (patch) | |
tree | 13e774dbe2d663ca1fbf2a77933ef8deabd4d507 /drivers/staging/lustre | |
parent | db5933225f2fe50d3b91ebbba73ed9c3b703b99a (diff) | |
parent | 3384e01179eff2b2fe91ba7bcad98ee2be5f87f7 (diff) | |
download | linux-5d8515bc232172963a4cef007e97b08c5e4d0533.tar.bz2 |
Merge tag 'staging-4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging/IIO updates from Greg KH:
"Here is the big Staging and IIO driver patches for 4.16-rc1.
There is the normal amount of new IIO drivers added, like all
releases.
The networking IPX and the ncpfs filesystem are moved into the staging
tree, as they are on their way out of the kernel due to lack of use
anymore.
The visorbus subsystem finall has started moving out of the staging
tree to the "real" part of the kernel, and the most and fsl-mc
codebases are almost ready to move out, that will probably happen for
4.17-rc1 if all goes well.
Other than that, there is a bunch of license header cleanups in the
tree, along with the normal amount of coding style churn that we all
know and love for this codebase. I also got frustrated at the
Meltdown/Spectre mess and took it out on the dgnc tty driver, deleting
huge chunks of it that were never even being used.
Full details of everything is in the shortlog.
All of these patches have been in linux-next for a while with no
reported issues"
* tag 'staging-4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (627 commits)
staging: rtlwifi: remove redundant initialization of 'cfg_cmd'
staging: rtl8723bs: remove a couple of redundant initializations
staging: comedi: reformat lines to 80 chars or less
staging: lustre: separate a connection destroy from free struct kib_conn
Staging: rtl8723bs: Use !x instead of NULL comparison
Staging: rtl8723bs: Remove dead code
Staging: rtl8723bs: Change names to conform to the kernel code
staging: ccree: Fix missing blank line after declaration
staging: rtl8188eu: remove redundant initialization of 'pwrcfgcmd'
staging: rtlwifi: remove unused RTLHALMAC_ST and RTLPHYDM_ST
staging: fbtft: remove unused FB_TFT_SSD1325 kconfig
staging: comedi: dt2811: remove redundant initialization of 'ns'
staging: wilc1000: fix alignments to match open parenthesis
staging: wilc1000: removed unnecessary defined enums typedef
staging: wilc1000: remove unnecessary use of parentheses
staging: rtl8192u: remove redundant initialization of 'timeout'
staging: sm750fb: fix CamelCase for dispSet var
staging: lustre: lnet/selftest: fix compile error on UP build
staging: rtl8723bs: hal_com_phycfg: Remove unneeded semicolons
staging: rts5208: Fix "seg_no" calculation in reset_ms_card()
...
Diffstat (limited to 'drivers/staging/lustre')
84 files changed, 949 insertions, 2121 deletions
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/libcfs.h index 6ad8867e5451..ca3472cc952f 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h @@ -45,7 +45,6 @@ #include <linux/libcfs/libcfs_prim.h> #include <linux/libcfs/libcfs_time.h> #include <linux/libcfs/libcfs_string.h> -#include <linux/libcfs/libcfs_workitem.h> #include <linux/libcfs/libcfs_hash.h> #include <linux/libcfs/libcfs_fail.h> #include <linux/libcfs/curproc.h> @@ -74,16 +73,6 @@ sigset_t cfs_block_sigsinv(unsigned long sigs); void cfs_restore_sigs(sigset_t sigset); void cfs_clear_sigpending(void); -/* - * Random number handling - */ - -/* returns a random 32-bit integer */ -unsigned int cfs_rand(void); -/* seed the generator */ -void cfs_srand(unsigned int seed1, unsigned int seed2); -void cfs_get_random_bytes(void *buf, int size); - struct libcfs_ioctl_handler { struct list_head item; int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr); @@ -126,7 +115,7 @@ extern struct miscdevice libcfs_dev; */ extern char lnet_debug_log_upcall[1024]; -extern struct cfs_wi_sched *cfs_sched_rehash; +extern struct workqueue_struct *cfs_rehash_wq; struct lnet_debugfs_symlink_def { char *name; diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h index 6d132f941281..61bce77fddd6 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h @@ -79,7 +79,7 @@ /** * return cpumask of CPU partition \a cpt */ -cpumask_t *cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt); +cpumask_var_t *cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt); /** * print string information of cpt-table */ @@ -96,7 +96,7 @@ struct cfs_cpt_table { u64 ctb_version; }; -static inline cpumask_t * +static inline cpumask_var_t * cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt) { return NULL; diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h index 5a27220cc608..0506f1d45757 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h @@ -248,7 +248,7 @@ struct cfs_hash { /** # of iterators (caller of cfs_hash_for_each_*) */ u32 hs_iterators; /** rehash workitem */ - struct cfs_workitem hs_rehash_wi; + struct work_struct hs_rehash_work; /** refcount on this hash table */ atomic_t hs_refcount; /** rehash buckets-table */ @@ -265,7 +265,7 @@ struct cfs_hash { /** bits when we found the max depth */ unsigned int hs_dep_bits; /** workitem to output max depth */ - struct cfs_workitem hs_dep_wi; + struct work_struct hs_dep_work; #endif /** name of htable */ char hs_name[0]; @@ -738,7 +738,7 @@ u64 cfs_hash_size_get(struct cfs_hash *hs); */ void cfs_hash_rehash_cancel_locked(struct cfs_hash *hs); void cfs_hash_rehash_cancel(struct cfs_hash *hs); -int cfs_hash_rehash(struct cfs_hash *hs, int do_rehash); +void cfs_hash_rehash(struct cfs_hash *hs, int do_rehash); void cfs_hash_rehash_key(struct cfs_hash *hs, const void *old_key, void *new_key, struct hlist_node *hnode); diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h index 2f4ff595fac9..491d5971d199 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h @@ -43,13 +43,6 @@ # define DEBUG_SUBSYSTEM S_UNDEFINED #endif -/* - * When this is on, LASSERT macro includes check for assignment used instead - * of equality check, but doesn't have unlikely(). Turn this on from time to - * time to make test-builds. This shouldn't be on for production release. - */ -#define LASSERT_CHECKED (0) - #define LASSERTF(cond, fmt, ...) \ do { \ if (unlikely(!(cond))) { \ @@ -74,8 +67,6 @@ do { \ # define LINVRNT(exp) ((void)sizeof !!(exp)) #endif -#define KLASSERT(e) LASSERT(e) - void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *msg); #define LBUG() \ @@ -84,74 +75,24 @@ do { \ lbug_with_loc(&msgdata); \ } while (0) -#ifndef LIBCFS_VMALLOC_SIZE -#define LIBCFS_VMALLOC_SIZE (2 << PAGE_SHIFT) /* 2 pages */ -#endif - -#define LIBCFS_ALLOC_PRE(size, mask) \ - LASSERT(!in_interrupt() || ((size) <= LIBCFS_VMALLOC_SIZE && \ - !gfpflags_allow_blocking(mask))) - -#define LIBCFS_ALLOC_POST(ptr, size) \ -do { \ - if (unlikely(!(ptr))) { \ - CERROR("LNET: out of memory at %s:%d (tried to alloc '" \ - #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size)); \ - } else { \ - memset((ptr), 0, (size)); \ - } \ -} while (0) - -/** - * allocate memory with GFP flags @mask - */ -#define LIBCFS_ALLOC_GFP(ptr, size, mask) \ -do { \ - LIBCFS_ALLOC_PRE((size), (mask)); \ - (ptr) = (size) <= LIBCFS_VMALLOC_SIZE ? \ - kmalloc((size), (mask)) : vmalloc(size); \ - LIBCFS_ALLOC_POST((ptr), (size)); \ -} while (0) - -/** - * default allocator - */ -#define LIBCFS_ALLOC(ptr, size) \ - LIBCFS_ALLOC_GFP(ptr, size, GFP_NOFS) - -/** - * non-sleeping allocator +/* + * Use #define rather than inline, as lnet_cpt_table() might + * not be defined yet */ -#define LIBCFS_ALLOC_ATOMIC(ptr, size) \ - LIBCFS_ALLOC_GFP(ptr, size, GFP_ATOMIC) +#define kmalloc_cpt(size, flags, cpt) \ + kmalloc_node(size, flags, cfs_cpt_spread_node(lnet_cpt_table(), cpt)) -/** - * allocate memory for specified CPU partition - * \a cptab != NULL, \a cpt is CPU partition id of \a cptab - * \a cptab == NULL, \a cpt is HW NUMA node id - */ -#define LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, mask) \ -do { \ - LIBCFS_ALLOC_PRE((size), (mask)); \ - (ptr) = (size) <= LIBCFS_VMALLOC_SIZE ? \ - kmalloc_node((size), (mask), cfs_cpt_spread_node(cptab, cpt)) :\ - vmalloc_node(size, cfs_cpt_spread_node(cptab, cpt)); \ - LIBCFS_ALLOC_POST((ptr), (size)); \ -} while (0) +#define kzalloc_cpt(size, flags, cpt) \ + kmalloc_node(size, flags | __GFP_ZERO, \ + cfs_cpt_spread_node(lnet_cpt_table(), cpt)) -/** default numa allocator */ -#define LIBCFS_CPT_ALLOC(ptr, cptab, cpt, size) \ - LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, GFP_NOFS) +#define kvmalloc_cpt(size, flags, cpt) \ + kvmalloc_node(size, flags, \ + cfs_cpt_spread_node(lnet_cpt_table(), cpt)) -#define LIBCFS_FREE(ptr, size) \ -do { \ - if (unlikely(!(ptr))) { \ - CERROR("LIBCFS: free NULL '" #ptr "' (%d bytes) at " \ - "%s:%d\n", (int)(size), __FILE__, __LINE__); \ - break; \ - } \ - kvfree(ptr); \ -} while (0) +#define kvzalloc_cpt(size, flags, cpt) \ + kvmalloc_node(size, flags | __GFP_ZERO, \ + cfs_cpt_spread_node(lnet_cpt_table(), cpt)) /******************************************************************************/ @@ -242,59 +183,18 @@ do { \ #define LASSERT_ATOMIC_ZERO(a) LASSERT_ATOMIC_EQ(a, 0) #define LASSERT_ATOMIC_POS(a) LASSERT_ATOMIC_GT(a, 0) -#define CFS_ALLOC_PTR(ptr) LIBCFS_ALLOC(ptr, sizeof(*(ptr))) -#define CFS_FREE_PTR(ptr) LIBCFS_FREE(ptr, sizeof(*(ptr))) - -/* max value for numeric network address */ -#define MAX_NUMERIC_VALUE 0xffffffff - /* implication */ #define ergo(a, b) (!(a) || (b)) /* logical equivalence */ #define equi(a, b) (!!(a) == !!(b)) -/* -------------------------------------------------------------------- - * Light-weight trace - * Support for temporary event tracing with minimal Heisenberg effect. - * -------------------------------------------------------------------- - */ - -#define MKSTR(ptr) ((ptr)) ? (ptr) : "" - -static inline size_t cfs_size_round4(int val) -{ - return (val + 3) & (~0x3); -} - #ifndef HAVE_CFS_SIZE_ROUND static inline size_t cfs_size_round(int val) { - return (val + 7) & (~0x7); + return round_up(val, 8); } #define HAVE_CFS_SIZE_ROUND #endif -static inline size_t cfs_size_round16(int val) -{ - return (val + 0xf) & (~0xf); -} - -static inline size_t cfs_size_round32(int val) -{ - return (val + 0x1f) & (~0x1f); -} - -static inline size_t cfs_size_round0(int val) -{ - if (!val) - return 0; - return (val + 1 + 7) & (~0x7); -} - -static inline size_t cfs_round_strlen(char *fset) -{ - return cfs_size_round((int)strlen(fset) + 1); -} - #endif diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h index 1191764c431a..66463477074a 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h @@ -73,7 +73,6 @@ struct cfs_expr_list { struct list_head el_exprs; }; -char *cfs_trimwhite(char *str); int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res); int cfs_str2num_check(char *str, int nob, unsigned int *num, unsigned int min, unsigned int max); @@ -86,11 +85,11 @@ static inline void cfs_expr_list_values_free(u32 *values, int num) { /* - * This array is allocated by LIBCFS_ALLOC(), so it shouldn't be freed + * This array is allocated by kvalloc(), so it shouldn't be freed * by OBD_FREE() if it's called by module other than libcfs & LNet, * otherwise we will see fake memory leak */ - LIBCFS_FREE(values, num * sizeof(values[0])); + kvfree(values); } void cfs_expr_list_free(struct cfs_expr_list *expr_list); diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h deleted file mode 100644 index fc780f608e57..000000000000 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h +++ /dev/null @@ -1,107 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * GPL HEADER START - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License version 2 for more details (a copy is included - * in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see - * http://www.gnu.org/licenses/gpl-2.0.html - * - * GPL HEADER END - */ -/* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * Copyright (c) 2012, Intel Corporation. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * libcfs/include/libcfs/libcfs_workitem.h - * - * Author: Isaac Huang <he.h.huang@oracle.com> - * Liang Zhen <zhen.liang@sun.com> - * - * A workitems is deferred work with these semantics: - * - a workitem always runs in thread context. - * - a workitem can be concurrent with other workitems but is strictly - * serialized with respect to itself. - * - no CPU affinity, a workitem does not necessarily run on the same CPU - * that schedules it. However, this might change in the future. - * - if a workitem is scheduled again before it has a chance to run, it - * runs only once. - * - if a workitem is scheduled while it runs, it runs again after it - * completes; this ensures that events occurring while other events are - * being processed receive due attention. This behavior also allows a - * workitem to reschedule itself. - * - * Usage notes: - * - a workitem can sleep but it should be aware of how that sleep might - * affect others. - * - a workitem runs inside a kernel thread so there's no user space to access. - * - do not use a workitem if the scheduling latency can't be tolerated. - * - * When wi_action returns non-zero, it means the workitem has either been - * freed or reused and workitem scheduler won't touch it any more. - */ - -#ifndef __LIBCFS_WORKITEM_H__ -#define __LIBCFS_WORKITEM_H__ - -struct cfs_wi_sched; - -void cfs_wi_sched_destroy(struct cfs_wi_sched *sched); -int cfs_wi_sched_create(char *name, struct cfs_cpt_table *cptab, int cpt, - int nthrs, struct cfs_wi_sched **sched_pp); - -struct cfs_workitem; - -typedef int (*cfs_wi_action_t) (struct cfs_workitem *); -struct cfs_workitem { - /** chain on runq or rerunq */ - struct list_head wi_list; - /** working function */ - cfs_wi_action_t wi_action; - /** arg for working function */ - void *wi_data; - /** in running */ - unsigned short wi_running:1; - /** scheduled */ - unsigned short wi_scheduled:1; -}; - -static inline void -cfs_wi_init(struct cfs_workitem *wi, void *data, cfs_wi_action_t action) -{ - INIT_LIST_HEAD(&wi->wi_list); - - wi->wi_running = 0; - wi->wi_scheduled = 0; - wi->wi_data = data; - wi->wi_action = action; -} - -void cfs_wi_schedule(struct cfs_wi_sched *sched, struct cfs_workitem *wi); -int cfs_wi_deschedule(struct cfs_wi_sched *sched, struct cfs_workitem *wi); -void cfs_wi_exit(struct cfs_wi_sched *sched, struct cfs_workitem *wi); - -int cfs_wi_startup(void); -void cfs_wi_shutdown(void); - -/** # workitem scheduler loops before reschedule */ -#define CFS_WI_RESCHED 128 - -#endif /* __LIBCFS_WORKITEM_H__ */ diff --git a/drivers/staging/lustre/include/linux/libcfs/linux/linux-cpu.h b/drivers/staging/lustre/include/linux/libcfs/linux/linux-cpu.h index 854c84358ab4..6035376f2830 100644 --- a/drivers/staging/lustre/include/linux/libcfs/linux/linux-cpu.h +++ b/drivers/staging/lustre/include/linux/libcfs/linux/linux-cpu.h @@ -49,7 +49,7 @@ /** virtual processing unit */ struct cfs_cpu_partition { /* CPUs mask for this partition */ - cpumask_t *cpt_cpumask; + cpumask_var_t cpt_cpumask; /* nodes mask for this partition */ nodemask_t *cpt_nodemask; /* spread rotor for NUMA allocator */ @@ -69,7 +69,7 @@ struct cfs_cpt_table { /* shadow HW CPU to CPU partition ID */ int *ctb_cpu2cpt; /* all cpus in this partition table */ - cpumask_t *ctb_cpumask; + cpumask_var_t ctb_cpumask; /* all nodes in this partition table */ nodemask_t *ctb_nodemask; }; diff --git a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h index c1626726fa05..df4c72507a15 100644 --- a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h +++ b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h @@ -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, diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 8024843521ab..ec84edfda271 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -325,7 +325,7 @@ int kiblnd_create_peer(struct lnet_ni *ni, struct kib_peer **peerp, LASSERT(net); LASSERT(nid != LNET_NID_ANY); - LIBCFS_CPT_ALLOC(peer, lnet_cpt_table(), cpt, sizeof(*peer)); + peer = kzalloc_cpt(sizeof(*peer), GFP_NOFS, cpt); if (!peer) { CERROR("Cannot allocate peer\n"); return -ENOMEM; @@ -367,7 +367,7 @@ void kiblnd_destroy_peer(struct kib_peer *peer) LASSERT(kiblnd_peer_idle(peer)); LASSERT(list_empty(&peer->ibp_tx_queue)); - LIBCFS_FREE(peer, sizeof(*peer)); + kfree(peer); /* * NB a peer's connections keep a reference on their peer until @@ -596,7 +596,7 @@ static void kiblnd_setup_mtu_locked(struct rdma_cm_id *cmid) static int kiblnd_get_completion_vector(struct kib_conn *conn, int cpt) { - cpumask_t *mask; + cpumask_var_t *mask; int vectors; int off; int i; @@ -611,8 +611,8 @@ static int kiblnd_get_completion_vector(struct kib_conn *conn, int cpt) return 0; /* hash NID to CPU id in this partition... */ - off = do_div(nid, cpumask_weight(mask)); - for_each_cpu(i, mask) { + off = do_div(nid, cpumask_weight(*mask)); + for_each_cpu(i, *mask) { if (!off--) return i % vectors; } @@ -656,15 +656,14 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm LASSERT(sched->ibs_nthreads > 0); - LIBCFS_CPT_ALLOC(init_qp_attr, lnet_cpt_table(), cpt, - sizeof(*init_qp_attr)); + init_qp_attr = kzalloc_cpt(sizeof(*init_qp_attr), GFP_NOFS, cpt); if (!init_qp_attr) { CERROR("Can't allocate qp_attr for %s\n", libcfs_nid2str(peer->ibp_nid)); goto failed_0; } - LIBCFS_CPT_ALLOC(conn, lnet_cpt_table(), cpt, sizeof(*conn)); + conn = kzalloc_cpt(sizeof(*conn), GFP_NOFS, cpt); if (!conn) { CERROR("Can't allocate connection for %s\n", libcfs_nid2str(peer->ibp_nid)); @@ -687,8 +686,7 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm INIT_LIST_HEAD(&conn->ibc_active_txs); spin_lock_init(&conn->ibc_lock); - LIBCFS_CPT_ALLOC(conn->ibc_connvars, lnet_cpt_table(), cpt, - sizeof(*conn->ibc_connvars)); + conn->ibc_connvars = kzalloc_cpt(sizeof(*conn->ibc_connvars), GFP_NOFS, cpt); if (!conn->ibc_connvars) { CERROR("Can't allocate in-progress connection state\n"); goto failed_2; @@ -722,8 +720,8 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm write_unlock_irqrestore(glock, flags); - LIBCFS_CPT_ALLOC(conn->ibc_rxs, lnet_cpt_table(), cpt, - IBLND_RX_MSGS(conn) * sizeof(struct kib_rx)); + conn->ibc_rxs = kzalloc_cpt(IBLND_RX_MSGS(conn) * sizeof(struct kib_rx), + GFP_NOFS, cpt); if (!conn->ibc_rxs) { CERROR("Cannot allocate RX buffers\n"); goto failed_2; @@ -776,7 +774,7 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm goto failed_2; } - LIBCFS_FREE(init_qp_attr, sizeof(*init_qp_attr)); + kfree(init_qp_attr); /* 1 ref for caller and each rxmsg */ atomic_set(&conn->ibc_refcount, 1 + IBLND_RX_MSGS(conn)); @@ -826,14 +824,15 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm return conn; failed_2: - kiblnd_destroy_conn(conn, true); + kiblnd_destroy_conn(conn); + kfree(conn); failed_1: - LIBCFS_FREE(init_qp_attr, sizeof(*init_qp_attr)); + kfree(init_qp_attr); failed_0: return NULL; } -void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) +void kiblnd_destroy_conn(struct kib_conn *conn) { struct rdma_cm_id *cmid = conn->ibc_cmid; struct kib_peer *peer = conn->ibc_peer; @@ -877,13 +876,8 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) if (conn->ibc_rx_pages) kiblnd_unmap_rx_descs(conn); - if (conn->ibc_rxs) { - LIBCFS_FREE(conn->ibc_rxs, - IBLND_RX_MSGS(conn) * sizeof(struct kib_rx)); - } - - if (conn->ibc_connvars) - LIBCFS_FREE(conn->ibc_connvars, sizeof(*conn->ibc_connvars)); + kfree(conn->ibc_rxs); + kfree(conn->ibc_connvars); if (conn->ibc_hdev) kiblnd_hdev_decref(conn->ibc_hdev); @@ -896,8 +890,6 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) rdma_destroy_id(cmid); atomic_dec(&net->ibn_nconns); } - - LIBCFS_FREE(conn, sizeof(*conn)); } int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) @@ -1089,7 +1081,7 @@ static void kiblnd_free_pages(struct kib_pages *p) __free_page(p->ibp_pages[i]); } - LIBCFS_FREE(p, offsetof(struct kib_pages, ibp_pages[npages])); + kfree(p); } int kiblnd_alloc_pages(struct kib_pages **pp, int cpt, int npages) @@ -1097,14 +1089,13 @@ int kiblnd_alloc_pages(struct kib_pages **pp, int cpt, int npages) struct kib_pages *p; int i; - LIBCFS_CPT_ALLOC(p, lnet_cpt_table(), cpt, - offsetof(struct kib_pages, ibp_pages[npages])); + p = kzalloc_cpt(offsetof(struct kib_pages, ibp_pages[npages]), + GFP_NOFS, cpt); if (!p) { CERROR("Can't allocate descriptor for %d pages\n", npages); return -ENOMEM; } - memset(p, 0, offsetof(struct kib_pages, ibp_pages[npages])); p->ibp_npages = npages; for (i = 0; i < npages; i++) { @@ -1299,7 +1290,7 @@ static void kiblnd_destroy_fmr_pool(struct kib_fmr_pool *fpo) frd_list) { list_del(&frd->frd_list); ib_dereg_mr(frd->frd_mr); - LIBCFS_FREE(frd, sizeof(*frd)); + kfree(frd); i++; } if (i < fpo->fast_reg.fpo_pool_size) @@ -1310,7 +1301,7 @@ static void kiblnd_destroy_fmr_pool(struct kib_fmr_pool *fpo) if (fpo->fpo_hdev) kiblnd_hdev_decref(fpo->fpo_hdev); - LIBCFS_FREE(fpo, sizeof(*fpo)); + kfree(fpo); } static void kiblnd_destroy_fmr_pool_list(struct list_head *head) @@ -1376,8 +1367,7 @@ static int kiblnd_alloc_freg_pool(struct kib_fmr_poolset *fps, struct kib_fmr_po INIT_LIST_HEAD(&fpo->fast_reg.fpo_pool_list); fpo->fast_reg.fpo_pool_size = 0; for (i = 0; i < fps->fps_pool_size; i++) { - LIBCFS_CPT_ALLOC(frd, lnet_cpt_table(), fps->fps_cpt, - sizeof(*frd)); + frd = kzalloc_cpt(sizeof(*frd), GFP_NOFS, fps->fps_cpt); if (!frd) { CERROR("Failed to allocate a new fast_reg descriptor\n"); rc = -ENOMEM; @@ -1405,14 +1395,14 @@ static int kiblnd_alloc_freg_pool(struct kib_fmr_poolset *fps, struct kib_fmr_po out_middle: if (frd->frd_mr) ib_dereg_mr(frd->frd_mr); - LIBCFS_FREE(frd, sizeof(*frd)); + kfree(frd); out: list_for_each_entry_safe(frd, tmp, &fpo->fast_reg.fpo_pool_list, frd_list) { list_del(&frd->frd_list); ib_dereg_mr(frd->frd_mr); - LIBCFS_FREE(frd, sizeof(*frd)); + kfree(frd); } return rc; @@ -1426,7 +1416,7 @@ static int kiblnd_create_fmr_pool(struct kib_fmr_poolset *fps, struct kib_fmr_pool *fpo; int rc; - LIBCFS_CPT_ALLOC(fpo, lnet_cpt_table(), fps->fps_cpt, sizeof(*fpo)); + fpo = kzalloc_cpt(sizeof(*fpo), GFP_NOFS, fps->fps_cpt); if (!fpo) return -ENOMEM; @@ -1464,7 +1454,7 @@ static int kiblnd_create_fmr_pool(struct kib_fmr_poolset *fps, out_fpo: kiblnd_hdev_decref(fpo->fpo_hdev); - LIBCFS_FREE(fpo, sizeof(*fpo)); + kfree(fpo); return rc; } @@ -1985,33 +1975,17 @@ static void kiblnd_destroy_tx_pool(struct kib_pool *pool) struct kib_tx *tx = &tpo->tpo_tx_descs[i]; list_del(&tx->tx_list); - if (tx->tx_pages) - LIBCFS_FREE(tx->tx_pages, - LNET_MAX_IOV * - sizeof(*tx->tx_pages)); - if (tx->tx_frags) - LIBCFS_FREE(tx->tx_frags, - (1 + IBLND_MAX_RDMA_FRAGS) * - sizeof(*tx->tx_frags)); - if (tx->tx_wrq) - LIBCFS_FREE(tx->tx_wrq, - (1 + IBLND_MAX_RDMA_FRAGS) * - sizeof(*tx->tx_wrq)); - if (tx->tx_sge) - LIBCFS_FREE(tx->tx_sge, - (1 + IBLND_MAX_RDMA_FRAGS) * - sizeof(*tx->tx_sge)); - if (tx->tx_rd) - LIBCFS_FREE(tx->tx_rd, - offsetof(struct kib_rdma_desc, - rd_frags[IBLND_MAX_RDMA_FRAGS])); - } - - LIBCFS_FREE(tpo->tpo_tx_descs, - pool->po_size * sizeof(struct kib_tx)); + kfree(tx->tx_pages); + kfree(tx->tx_frags); + kfree(tx->tx_wrq); + kfree(tx->tx_sge); + kfree(tx->tx_rd); + } + + kfree(tpo->tpo_tx_descs); out: kiblnd_fini_pool(pool); - LIBCFS_FREE(tpo, sizeof(*tpo)); + kfree(tpo); } static int kiblnd_tx_pool_size(int ncpts) @@ -2029,7 +2003,7 @@ static int kiblnd_create_tx_pool(struct kib_poolset *ps, int size, struct kib_pool *pool; struct kib_tx_pool *tpo; - LIBCFS_CPT_ALLOC(tpo, lnet_cpt_table(), ps->ps_cpt, sizeof(*tpo)); + tpo = kzalloc_cpt(sizeof(*tpo), GFP_NOFS, ps->ps_cpt); if (!tpo) { CERROR("Failed to allocate TX pool\n"); return -ENOMEM; @@ -2043,12 +2017,12 @@ static int kiblnd_create_tx_pool(struct kib_poolset *ps, int size, npg = DIV_ROUND_UP(size * IBLND_MSG_SIZE, PAGE_SIZE); if (kiblnd_alloc_pages(&tpo->tpo_tx_pages, ps->ps_cpt, npg)) { CERROR("Can't allocate tx pages: %d\n", npg); - LIBCFS_FREE(tpo, sizeof(*tpo)); + kfree(tpo); return -ENOMEM; } - LIBCFS_CPT_ALLOC(tpo->tpo_tx_descs, lnet_cpt_table(), ps->ps_cpt, - size * sizeof(struct kib_tx)); + tpo->tpo_tx_descs = kzalloc_cpt(size * sizeof(struct kib_tx), + GFP_NOFS, ps->ps_cpt); if (!tpo->tpo_tx_descs) { CERROR("Can't allocate %d tx descriptors\n", size); ps->ps_pool_destroy(pool); @@ -2062,36 +2036,35 @@ static int kiblnd_create_tx_pool(struct kib_poolset *ps, int size, tx->tx_pool = tpo; if (ps->ps_net->ibn_fmr_ps) { - LIBCFS_CPT_ALLOC(tx->tx_pages, - lnet_cpt_table(), ps->ps_cpt, - LNET_MAX_IOV * sizeof(*tx->tx_pages)); + tx->tx_pages = kzalloc_cpt(LNET_MAX_IOV * sizeof(*tx->tx_pages), + GFP_NOFS, ps->ps_cpt); if (!tx->tx_pages) break; } - LIBCFS_CPT_ALLOC(tx->tx_frags, lnet_cpt_table(), ps->ps_cpt, - (1 + IBLND_MAX_RDMA_FRAGS) * - sizeof(*tx->tx_frags)); + tx->tx_frags = kzalloc_cpt((1 + IBLND_MAX_RDMA_FRAGS) * + sizeof(*tx->tx_frags), + GFP_NOFS, ps->ps_cpt); if (!tx->tx_frags) break; sg_init_table(tx->tx_frags, IBLND_MAX_RDMA_FRAGS + 1); - LIBCFS_CPT_ALLOC(tx->tx_wrq, lnet_cpt_table(), ps->ps_cpt, - (1 + IBLND_MAX_RDMA_FRAGS) * - sizeof(*tx->tx_wrq)); + tx->tx_wrq = kzalloc_cpt((1 + IBLND_MAX_RDMA_FRAGS) * + sizeof(*tx->tx_wrq), + GFP_NOFS, ps->ps_cpt); if (!tx->tx_wrq) break; - LIBCFS_CPT_ALLOC(tx->tx_sge, lnet_cpt_table(), ps->ps_cpt, - (1 + IBLND_MAX_RDMA_FRAGS) * - sizeof(*tx->tx_sge)); + tx->tx_sge = kzalloc_cpt((1 + IBLND_MAX_RDMA_FRAGS) * + sizeof(*tx->tx_sge), + GFP_NOFS, ps->ps_cpt); if (!tx->tx_sge) break; - LIBCFS_CPT_ALLOC(tx->tx_rd, lnet_cpt_table(), ps->ps_cpt, - offsetof(struct kib_rdma_desc, - rd_frags[IBLND_MAX_RDMA_FRAGS])); + tx->tx_rd = kzalloc_cpt(offsetof(struct kib_rdma_desc, + rd_frags[IBLND_MAX_RDMA_FRAGS]), + GFP_NOFS, ps->ps_cpt); if (!tx->tx_rd) break; } @@ -2263,7 +2236,7 @@ void kiblnd_hdev_destroy(struct kib_hca_dev *hdev) if (hdev->ibh_cmid) rdma_destroy_id(hdev->ibh_cmid); - LIBCFS_FREE(hdev, sizeof(*hdev)); + kfree(hdev); } /* DUMMY */ @@ -2392,7 +2365,7 @@ int kiblnd_dev_failover(struct kib_dev *dev) goto out; } - LIBCFS_ALLOC(hdev, sizeof(*hdev)); + hdev = kzalloc(sizeof(*hdev), GFP_NOFS); if (!hdev) { CERROR("Failed to allocate kib_hca_dev\n"); rdma_destroy_id(cmid); @@ -2471,7 +2444,7 @@ void kiblnd_destroy_dev(struct kib_dev *dev) if (dev->ibd_hdev) kiblnd_hdev_decref(dev->ibd_hdev); - LIBCFS_FREE(dev, sizeof(*dev)); + kfree(dev); } static struct kib_dev *kiblnd_create_dev(char *ifname) @@ -2495,7 +2468,7 @@ static struct kib_dev *kiblnd_create_dev(char *ifname) return NULL; } - LIBCFS_ALLOC(dev, sizeof(*dev)); + dev = kzalloc(sizeof(*dev), GFP_NOFS); if (!dev) return NULL; @@ -2517,7 +2490,7 @@ static struct kib_dev *kiblnd_create_dev(char *ifname) rc = kiblnd_dev_failover(dev); if (rc) { CERROR("Can't initialize device: %d\n", rc); - LIBCFS_FREE(dev, sizeof(*dev)); + kfree(dev); return NULL; } @@ -2577,11 +2550,7 @@ static void kiblnd_base_shutdown(void) break; } - if (kiblnd_data.kib_peers) { - LIBCFS_FREE(kiblnd_data.kib_peers, - sizeof(struct list_head) * - kiblnd_data.kib_peer_hash_size); - } + kvfree(kiblnd_data.kib_peers); if (kiblnd_data.kib_scheds) cfs_percpt_free(kiblnd_data.kib_scheds); @@ -2648,7 +2617,7 @@ static void kiblnd_shutdown(struct lnet_ni *ni) net->ibn_init = IBLND_INIT_NOTHING; ni->ni_data = NULL; - LIBCFS_FREE(net, sizeof(*net)); + kfree(net); out: if (list_empty(&kiblnd_data.kib_devs)) @@ -2673,8 +2642,9 @@ static int kiblnd_base_startup(void) INIT_LIST_HEAD(&kiblnd_data.kib_failed_devs); kiblnd_data.kib_peer_hash_size = IBLND_PEER_HASH_SIZE; - LIBCFS_ALLOC(kiblnd_data.kib_peers, - sizeof(struct list_head) * kiblnd_data.kib_peer_hash_size); + kiblnd_data.kib_peers = kvmalloc_array(kiblnd_data.kib_peer_hash_size, + sizeof(struct list_head), + GFP_KERNEL); if (!kiblnd_data.kib_peers) goto failed; for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) @@ -2865,7 +2835,7 @@ static int kiblnd_startup(struct lnet_ni *ni) return rc; } - LIBCFS_ALLOC(net, sizeof(*net)); + net = kzalloc(sizeof(*net), GFP_NOFS); ni->ni_data = net; if (!net) goto net_failed; diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h index 171eced213f8..b18911d09e9a 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h @@ -1016,7 +1016,7 @@ int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why); struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cmid, int state, int version); -void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn); +void kiblnd_destroy_conn(struct kib_conn *conn); void kiblnd_close_conn(struct kib_conn *conn, int error); void kiblnd_close_conn_locked(struct kib_conn *conn, int error); diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c index 40e3af5d8b04..b3e7f28eb978 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c @@ -2124,7 +2124,7 @@ kiblnd_connreq_done(struct kib_conn *conn, int status) (conn->ibc_state == IBLND_CONN_PASSIVE_WAIT && peer->ibp_accepting > 0)); - LIBCFS_FREE(conn->ibc_connvars, sizeof(*conn->ibc_connvars)); + kfree(conn->ibc_connvars); conn->ibc_connvars = NULL; if (status) { @@ -3314,11 +3314,13 @@ kiblnd_connd(void *arg) spin_unlock_irqrestore(lock, flags); dropped_lock = 1; - kiblnd_destroy_conn(conn, !peer); + kiblnd_destroy_conn(conn); spin_lock_irqsave(lock, flags); - if (!peer) + if (!peer) { + kfree(conn); continue; + } conn->ibc_peer = peer; if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) @@ -3363,7 +3365,7 @@ kiblnd_connd(void *arg) reconn += kiblnd_reconnect_peer(conn->ibc_peer); kiblnd_peer_decref(conn->ibc_peer); - LIBCFS_FREE(conn, sizeof(*conn)); + kfree(conn); spin_lock_irqsave(lock, flags); } diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c index a71b765215ad..b9235400bf1d 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c @@ -181,8 +181,8 @@ int kiblnd_tunables_setup(struct lnet_ni *ni) * defaulted */ if (!ni->ni_lnd_tunables) { - LIBCFS_ALLOC(ni->ni_lnd_tunables, - sizeof(*ni->ni_lnd_tunables)); + ni->ni_lnd_tunables = kzalloc(sizeof(*ni->ni_lnd_tunables), + GFP_NOFS); if (!ni->ni_lnd_tunables) return -ENOMEM; diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c index 8267119ccc8e..ff292216290d 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c @@ -66,7 +66,7 @@ ksocknal_create_route(__u32 ipaddr, int port) { struct ksock_route *route; - LIBCFS_ALLOC(route, sizeof(*route)); + route = kzalloc(sizeof(*route), GFP_NOFS); if (!route) return NULL; @@ -93,7 +93,7 @@ ksocknal_destroy_route(struct ksock_route *route) if (route->ksnr_peer) ksocknal_peer_decref(route->ksnr_peer); - LIBCFS_FREE(route, sizeof(*route)); + kfree(route); } static int @@ -108,7 +108,7 @@ ksocknal_create_peer(struct ksock_peer **peerp, struct lnet_ni *ni, LASSERT(id.pid != LNET_PID_ANY); LASSERT(!in_interrupt()); - LIBCFS_CPT_ALLOC(peer, lnet_cpt_table(), cpt, sizeof(*peer)); + peer = kzalloc_cpt(sizeof(*peer), GFP_NOFS, cpt); if (!peer) return -ENOMEM; @@ -132,7 +132,7 @@ ksocknal_create_peer(struct ksock_peer **peerp, struct lnet_ni *ni, if (net->ksnn_shutdown) { spin_unlock_bh(&net->ksnn_lock); - LIBCFS_FREE(peer, sizeof(*peer)); + kfree(peer); CERROR("Can't create peer: network shutdown\n"); return -ESHUTDOWN; } @@ -160,7 +160,7 @@ ksocknal_destroy_peer(struct ksock_peer *peer) LASSERT(list_empty(&peer->ksnp_tx_queue)); LASSERT(list_empty(&peer->ksnp_zc_req_list)); - LIBCFS_FREE(peer, sizeof(*peer)); + kfree(peer); /* * NB a peer's connections and routes keep a reference on their peer @@ -985,7 +985,7 @@ ksocknal_accept(struct lnet_ni *ni, struct socket *sock) rc = lnet_sock_getaddr(sock, 1, &peer_ip, &peer_port); LASSERT(!rc); /* we succeeded before */ - LIBCFS_ALLOC(cr, sizeof(*cr)); + cr = kzalloc(sizeof(*cr), GFP_NOFS); if (!cr) { LCONSOLE_ERROR_MSG(0x12f, "Dropping connection request from %pI4h: memory exhausted\n", &peer_ip); @@ -1043,7 +1043,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route, LASSERT(active == (type != SOCKLND_CONN_NONE)); - LIBCFS_ALLOC(conn, sizeof(*conn)); + conn = kzalloc(sizeof(*conn), GFP_NOFS); if (!conn) { rc = -ENOMEM; goto failed_0; @@ -1070,8 +1070,9 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route, conn->ksnc_tx_carrier = NULL; atomic_set(&conn->ksnc_tx_nob, 0); - LIBCFS_ALLOC(hello, offsetof(struct ksock_hello_msg, - kshm_ips[LNET_MAX_INTERFACES])); + hello = kvzalloc(offsetof(struct ksock_hello_msg, + kshm_ips[LNET_MAX_INTERFACES]), + GFP_KERNEL); if (!hello) { rc = -ENOMEM; goto failed_1; @@ -1334,8 +1335,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route, rc = ksocknal_send_hello(ni, conn, peerid.nid, hello); } - LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg, - kshm_ips[LNET_MAX_INTERFACES])); + kvfree(hello); /* * setup the socket AFTER I've received hello (it disables @@ -1415,11 +1415,9 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route, ksocknal_peer_decref(peer); failed_1: - if (hello) - LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg, - kshm_ips[LNET_MAX_INTERFACES])); + kvfree(hello); - LIBCFS_FREE(conn, sizeof(*conn)); + kfree(conn); failed_0: sock_release(sock); @@ -1716,7 +1714,7 @@ ksocknal_destroy_conn(struct ksock_conn *conn) ksocknal_peer_decref(conn->ksnc_peer); - LIBCFS_FREE(conn, sizeof(*conn)); + kfree(conn); } int @@ -2259,19 +2257,12 @@ ksocknal_free_buffers(void) struct ksock_sched_info *info; int i; - cfs_percpt_for_each(info, i, ksocknal_data.ksnd_sched_info) { - if (info->ksi_scheds) { - LIBCFS_FREE(info->ksi_scheds, - info->ksi_nthreads_max * - sizeof(info->ksi_scheds[0])); - } - } + cfs_percpt_for_each(info, i, ksocknal_data.ksnd_sched_info) + kfree(info->ksi_scheds); cfs_percpt_free(ksocknal_data.ksnd_sched_info); } - LIBCFS_FREE(ksocknal_data.ksnd_peers, - sizeof(struct list_head) * - ksocknal_data.ksnd_peer_hash_size); + kvfree(ksocknal_data.ksnd_peers); spin_lock(&ksocknal_data.ksnd_tx_lock); @@ -2286,7 +2277,7 @@ ksocknal_free_buffers(void) list_for_each_entry_safe(tx, temp, &zlist, tx_list) { list_del(&tx->tx_list); - LIBCFS_FREE(tx, tx->tx_desc_size); + kfree(tx); } } else { spin_unlock(&ksocknal_data.ksnd_tx_lock); @@ -2401,9 +2392,9 @@ ksocknal_base_startup(void) memset(&ksocknal_data, 0, sizeof(ksocknal_data)); /* zero pointers */ ksocknal_data.ksnd_peer_hash_size = SOCKNAL_PEER_HASH_SIZE; - LIBCFS_ALLOC(ksocknal_data.ksnd_peers, - sizeof(struct list_head) * - ksocknal_data.ksnd_peer_hash_size); + ksocknal_data.ksnd_peers = kvmalloc_array(ksocknal_data.ksnd_peer_hash_size, + sizeof(struct list_head), + GFP_KERNEL); if (!ksocknal_data.ksnd_peers) return -ENOMEM; @@ -2456,8 +2447,8 @@ ksocknal_base_startup(void) info->ksi_nthreads_max = nthrs; info->ksi_cpt = i; - LIBCFS_CPT_ALLOC(info->ksi_scheds, lnet_cpt_table(), i, - info->ksi_nthreads_max * sizeof(*sched)); + info->ksi_scheds = kzalloc_cpt(info->ksi_nthreads_max * sizeof(*sched), + GFP_NOFS, i); if (!info->ksi_scheds) goto failed; @@ -2622,7 +2613,7 @@ ksocknal_shutdown(struct lnet_ni *ni) } list_del(&net->ksnn_list); - LIBCFS_FREE(net, sizeof(*net)); + kfree(net); ksocknal_data.ksnd_nnets--; if (!ksocknal_data.ksnd_nnets) @@ -2815,7 +2806,7 @@ ksocknal_startup(struct lnet_ni *ni) return rc; } - LIBCFS_ALLOC(net, sizeof(*net)); + net = kzalloc(sizeof(*net), GFP_NOFS); if (!net) goto fail_0; @@ -2877,7 +2868,7 @@ ksocknal_startup(struct lnet_ni *ni) return 0; fail_1: - LIBCFS_FREE(net, sizeof(*net)); + kfree(net); fail_0: if (!ksocknal_data.ksnd_nnets) ksocknal_base_shutdown(); diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c index 27c56d5ae4e5..11fd3a36424f 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c @@ -46,7 +46,7 @@ ksocknal_alloc_tx(int type, int size) } if (!tx) - LIBCFS_ALLOC(tx, size); + tx = kzalloc(size, GFP_NOFS); if (!tx) return NULL; @@ -102,7 +102,7 @@ ksocknal_free_tx(struct ksock_tx *tx) spin_unlock(&ksocknal_data.ksnd_tx_lock); } else { - LIBCFS_FREE(tx, tx->tx_desc_size); + kfree(tx); } } @@ -2117,7 +2117,7 @@ ksocknal_connd(void *arg) ksocknal_create_conn(cr->ksncr_ni, NULL, cr->ksncr_sock, SOCKLND_CONN_NONE); lnet_ni_decref(cr->ksncr_ni); - LIBCFS_FREE(cr, sizeof(*cr)); + kfree(cr); spin_lock_bh(connd_lock); } diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c index d827f770e831..05982dac781c 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c @@ -467,7 +467,7 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello) BUILD_BUG_ON(sizeof(struct lnet_magicversion) != offsetof(struct lnet_hdr, src_nid)); - LIBCFS_ALLOC(hdr, sizeof(*hdr)); + hdr = kzalloc(sizeof(*hdr), GFP_NOFS); if (!hdr) { CERROR("Can't allocate struct lnet_hdr\n"); return -ENOMEM; @@ -526,7 +526,7 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello) &conn->ksnc_ipaddr, conn->ksnc_port); } out: - LIBCFS_FREE(hdr, sizeof(*hdr)); + kfree(hdr); return rc; } @@ -582,7 +582,7 @@ ksocknal_recv_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello, int rc; int i; - LIBCFS_ALLOC(hdr, sizeof(*hdr)); + hdr = kzalloc(sizeof(*hdr), GFP_NOFS); if (!hdr) { CERROR("Can't allocate struct lnet_hdr\n"); return -ENOMEM; @@ -644,7 +644,7 @@ ksocknal_recv_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello, } } out: - LIBCFS_FREE(hdr, sizeof(*hdr)); + kfree(hdr); return rc; } diff --git a/drivers/staging/lustre/lnet/libcfs/Makefile b/drivers/staging/lustre/lnet/libcfs/Makefile index 1607570ef8de..730f2c675047 100644 --- a/drivers/staging/lustre/lnet/libcfs/Makefile +++ b/drivers/staging/lustre/lnet/libcfs/Makefile @@ -15,7 +15,7 @@ libcfs-linux-objs += linux-mem.o libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs)) libcfs-all-objs := debug.o fail.o module.o tracefile.o \ - libcfs_string.o hash.o prng.o workitem.o \ + libcfs_string.o hash.o \ libcfs_cpu.o libcfs_mem.o libcfs_lock.o libcfs-objs := $(libcfs-linux-objs) $(libcfs-all-objs) diff --git a/drivers/staging/lustre/lnet/libcfs/fail.c b/drivers/staging/lustre/lnet/libcfs/fail.c index 5d501beeb622..39439b303d65 100644 --- a/drivers/staging/lustre/lnet/libcfs/fail.c +++ b/drivers/staging/lustre/lnet/libcfs/fail.c @@ -61,7 +61,7 @@ int __cfs_fail_check_set(u32 id, u32 value, int set) /* Fail 1/cfs_fail_val times */ if (cfs_fail_loc & CFS_FAIL_RAND) { - if (cfs_fail_val < 2 || cfs_rand() % cfs_fail_val > 0) + if (cfs_fail_val < 2 || prandom_u32_max(cfs_fail_val) > 0) return 0; } diff --git a/drivers/staging/lustre/lnet/libcfs/hash.c b/drivers/staging/lustre/lnet/libcfs/hash.c index f4f67d2b301e..f7b3c9306456 100644 --- a/drivers/staging/lustre/lnet/libcfs/hash.c +++ b/drivers/staging/lustre/lnet/libcfs/hash.c @@ -114,7 +114,7 @@ module_param(warn_on_depth, uint, 0644); MODULE_PARM_DESC(warn_on_depth, "warning when hash depth is high."); #endif -struct cfs_wi_sched *cfs_sched_rehash; +struct workqueue_struct *cfs_rehash_wq; static inline void cfs_hash_nl_lock(union cfs_hash_lock *lock, int exclusive) {} @@ -519,7 +519,7 @@ cfs_hash_bd_dep_record(struct cfs_hash *hs, struct cfs_hash_bd *bd, int dep_cur) hs->hs_dep_bits = hs->hs_cur_bits; spin_unlock(&hs->hs_dep_lock); - cfs_wi_schedule(cfs_sched_rehash, &hs->hs_dep_wi); + queue_work(cfs_rehash_wq, &hs->hs_dep_work); # endif } @@ -864,12 +864,10 @@ cfs_hash_buckets_free(struct cfs_hash_bucket **buckets, { int i; - for (i = prev_size; i < size; i++) { - if (buckets[i]) - LIBCFS_FREE(buckets[i], bkt_size); - } + for (i = prev_size; i < size; i++) + kfree(buckets[i]); - LIBCFS_FREE(buckets, sizeof(buckets[0]) * size); + kvfree(buckets); } /* @@ -889,7 +887,7 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts, if (old_bkts && old_size == new_size) return old_bkts; - LIBCFS_ALLOC(new_bkts, sizeof(new_bkts[0]) * new_size); + new_bkts = kvmalloc_array(new_size, sizeof(new_bkts[0]), GFP_KERNEL); if (!new_bkts) return NULL; @@ -902,7 +900,7 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts, struct hlist_head *hhead; struct cfs_hash_bd bd; - LIBCFS_ALLOC(new_bkts[i], cfs_hash_bkt_size(hs)); + new_bkts[i] = kzalloc(cfs_hash_bkt_size(hs), GFP_KERNEL); if (!new_bkts[i]) { cfs_hash_buckets_free(new_bkts, cfs_hash_bkt_size(hs), old_size, new_size); @@ -939,12 +937,12 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts, * @flags - CFS_HASH_REHASH enable synamic hash resizing * - CFS_HASH_SORT enable chained hash sort */ -static int cfs_hash_rehash_worker(struct cfs_workitem *wi); +static void cfs_hash_rehash_worker(struct work_struct *work); #if CFS_HASH_DEBUG_LEVEL >= CFS_HASH_DEBUG_1 -static int cfs_hash_dep_print(struct cfs_workitem *wi) +static void cfs_hash_dep_print(struct work_struct *work) { - struct cfs_hash *hs = container_of(wi, struct cfs_hash, hs_dep_wi); + struct cfs_hash *hs = container_of(work, struct cfs_hash, hs_dep_work); int dep; int bkt; int off; @@ -968,21 +966,12 @@ static int cfs_hash_dep_print(struct cfs_workitem *wi) static void cfs_hash_depth_wi_init(struct cfs_hash *hs) { spin_lock_init(&hs->hs_dep_lock); - cfs_wi_init(&hs->hs_dep_wi, hs, cfs_hash_dep_print); + INIT_WORK(&hs->hs_dep_work, cfs_hash_dep_print); } static void cfs_hash_depth_wi_cancel(struct cfs_hash *hs) { - if (cfs_wi_deschedule(cfs_sched_rehash, &hs->hs_dep_wi)) - return; - - spin_lock(&hs->hs_dep_lock); - while (hs->hs_dep_bits) { - spin_unlock(&hs->hs_dep_lock); - cond_resched(); - spin_lock(&hs->hs_dep_lock); - } - spin_unlock(&hs->hs_dep_lock); + cancel_work_sync(&hs->hs_dep_work); } #else /* CFS_HASH_DEBUG_LEVEL < CFS_HASH_DEBUG_1 */ @@ -1023,7 +1012,7 @@ cfs_hash_create(char *name, unsigned int cur_bits, unsigned int max_bits, len = !(flags & CFS_HASH_BIGNAME) ? CFS_HASH_NAME_LEN : CFS_HASH_BIGNAME_LEN; - LIBCFS_ALLOC(hs, offsetof(struct cfs_hash, hs_name[len])); + hs = kzalloc(offsetof(struct cfs_hash, hs_name[len]), GFP_KERNEL); if (!hs) return NULL; @@ -1044,7 +1033,7 @@ cfs_hash_create(char *name, unsigned int cur_bits, unsigned int max_bits, hs->hs_ops = ops; hs->hs_extra_bytes = extra_bytes; hs->hs_rehash_bits = 0; - cfs_wi_init(&hs->hs_rehash_wi, hs, cfs_hash_rehash_worker); + INIT_WORK(&hs->hs_rehash_work, cfs_hash_rehash_worker); cfs_hash_depth_wi_init(hs); if (cfs_hash_with_rehash(hs)) @@ -1055,7 +1044,7 @@ cfs_hash_create(char *name, unsigned int cur_bits, unsigned int max_bits, if (hs->hs_buckets) return hs; - LIBCFS_FREE(hs, offsetof(struct cfs_hash, hs_name[len])); + kfree(hs); return NULL; } EXPORT_SYMBOL(cfs_hash_create); @@ -1118,7 +1107,7 @@ cfs_hash_destroy(struct cfs_hash *hs) 0, CFS_HASH_NBKT(hs)); i = cfs_hash_with_bigname(hs) ? CFS_HASH_BIGNAME_LEN : CFS_HASH_NAME_LEN; - LIBCFS_FREE(hs, offsetof(struct cfs_hash, hs_name[i])); + kfree(hs); } struct cfs_hash *cfs_hash_getref(struct cfs_hash *hs) @@ -1364,6 +1353,7 @@ cfs_hash_for_each_enter(struct cfs_hash *hs) cfs_hash_lock(hs, 1); hs->hs_iterators++; + cfs_hash_unlock(hs, 1); /* NB: iteration is mostly called by service thread, * we tend to cancel pending rehash-request, instead of @@ -1371,8 +1361,7 @@ cfs_hash_for_each_enter(struct cfs_hash *hs) * after iteration */ if (cfs_hash_is_rehashing(hs)) - cfs_hash_rehash_cancel_locked(hs); - cfs_hash_unlock(hs, 1); + cfs_hash_rehash_cancel(hs); } static void @@ -1774,42 +1763,13 @@ EXPORT_SYMBOL(cfs_hash_for_each_key); * theta thresholds for @hs are tunable via cfs_hash_set_theta(). */ void -cfs_hash_rehash_cancel_locked(struct cfs_hash *hs) -{ - int i; - - /* need hold cfs_hash_lock(hs, 1) */ - LASSERT(cfs_hash_with_rehash(hs) && - !cfs_hash_with_no_lock(hs)); - - if (!cfs_hash_is_rehashing(hs)) - return; - - if (cfs_wi_deschedule(cfs_sched_rehash, &hs->hs_rehash_wi)) { - hs->hs_rehash_bits = 0; - return; - } - - for (i = 2; cfs_hash_is_rehashing(hs); i++) { - cfs_hash_unlock(hs, 1); - /* raise console warning while waiting too long */ - CDEBUG(is_power_of_2(i >> 3) ? D_WARNING : D_INFO, - "hash %s is still rehashing, rescheded %d\n", - hs->hs_name, i - 1); - cond_resched(); - cfs_hash_lock(hs, 1); - } -} - -void cfs_hash_rehash_cancel(struct cfs_hash *hs) { - cfs_hash_lock(hs, 1); - cfs_hash_rehash_cancel_locked(hs); - cfs_hash_unlock(hs, 1); + LASSERT(cfs_hash_with_rehash(hs)); + cancel_work_sync(&hs->hs_rehash_work); } -int +void cfs_hash_rehash(struct cfs_hash *hs, int do_rehash) { int rc; @@ -1821,21 +1781,21 @@ cfs_hash_rehash(struct cfs_hash *hs, int do_rehash) rc = cfs_hash_rehash_bits(hs); if (rc <= 0) { cfs_hash_unlock(hs, 1); - return rc; + return; } hs->hs_rehash_bits = rc; if (!do_rehash) { /* launch and return */ - cfs_wi_schedule(cfs_sched_rehash, &hs->hs_rehash_wi); + queue_work(cfs_rehash_wq, &hs->hs_rehash_work); cfs_hash_unlock(hs, 1); - return 0; + return; } /* rehash right now */ cfs_hash_unlock(hs, 1); - return cfs_hash_rehash_worker(&hs->hs_rehash_wi); + cfs_hash_rehash_worker(&hs->hs_rehash_work); } static int @@ -1869,10 +1829,10 @@ cfs_hash_rehash_bd(struct cfs_hash *hs, struct cfs_hash_bd *old) return c; } -static int -cfs_hash_rehash_worker(struct cfs_workitem *wi) +static void +cfs_hash_rehash_worker(struct work_struct *work) { - struct cfs_hash *hs = container_of(wi, struct cfs_hash, hs_rehash_wi); + struct cfs_hash *hs = container_of(work, struct cfs_hash, hs_rehash_work); struct cfs_hash_bucket **bkts; struct cfs_hash_bd bd; unsigned int old_size; @@ -1956,8 +1916,6 @@ cfs_hash_rehash_worker(struct cfs_workitem *wi) hs->hs_cur_bits = hs->hs_rehash_bits; out: hs->hs_rehash_bits = 0; - if (rc == -ESRCH) /* never be scheduled again */ - cfs_wi_exit(cfs_sched_rehash, wi); bsize = cfs_hash_bkt_size(hs); cfs_hash_unlock(hs, 1); /* can't refer to @hs anymore because it could be destroyed */ @@ -1965,8 +1923,6 @@ out: cfs_hash_buckets_free(bkts, bsize, new_size, old_size); if (rc) CDEBUG(D_INFO, "early quit of rehashing: %d\n", rc); - /* return 1 only if cfs_wi_exit is called */ - return rc == -ESRCH; } /** diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c index e3a4c67a66b5..76291a350406 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c @@ -51,7 +51,7 @@ cfs_cpt_table_alloc(unsigned int ncpt) return NULL; } - LIBCFS_ALLOC(cptab, sizeof(*cptab)); + cptab = kzalloc(sizeof(*cptab), GFP_NOFS); if (cptab) { cptab->ctb_version = CFS_CPU_VERSION_MAGIC; node_set(0, cptab->ctb_nodemask); @@ -67,7 +67,7 @@ cfs_cpt_table_free(struct cfs_cpt_table *cptab) { LASSERT(cptab->ctb_version == CFS_CPU_VERSION_MAGIC); - LIBCFS_FREE(cptab, sizeof(*cptab)); + kfree(cptab); } EXPORT_SYMBOL(cfs_cpt_table_free); @@ -113,7 +113,7 @@ cfs_cpt_nodemask(struct cfs_cpt_table *cptab, int cpt) { return &cptab->ctb_nodemask; } -EXPORT_SYMBOL(cfs_cpt_cpumask); +EXPORT_SYMBOL(cfs_cpt_nodemask); int cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu) diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c b/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c index f6a0040f4ab1..670ad5a34224 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c @@ -38,7 +38,7 @@ cfs_percpt_lock_free(struct cfs_percpt_lock *pcl) LASSERT(!pcl->pcl_locked); cfs_percpt_free(pcl->pcl_locks); - LIBCFS_FREE(pcl, sizeof(*pcl)); + kfree(pcl); } EXPORT_SYMBOL(cfs_percpt_lock_free); @@ -58,14 +58,14 @@ cfs_percpt_lock_create(struct cfs_cpt_table *cptab, int i; /* NB: cptab can be NULL, pcl will be for HW CPUs on that case */ - LIBCFS_ALLOC(pcl, sizeof(*pcl)); + pcl = kzalloc(sizeof(*pcl), GFP_NOFS); if (!pcl) return NULL; pcl->pcl_cptab = cptab; pcl->pcl_locks = cfs_percpt_alloc(cptab, sizeof(*lock)); if (!pcl->pcl_locks) { - LIBCFS_FREE(pcl, sizeof(*pcl)); + kfree(pcl); return NULL; } diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c index df93d8f77ea2..7faed94994ea 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c @@ -49,13 +49,10 @@ cfs_percpt_free(void *vars) arr = container_of(vars, struct cfs_var_array, va_ptrs[0]); - for (i = 0; i < arr->va_count; i++) { - if (arr->va_ptrs[i]) - LIBCFS_FREE(arr->va_ptrs[i], arr->va_size); - } + for (i = 0; i < arr->va_count; i++) + kfree(arr->va_ptrs[i]); - LIBCFS_FREE(arr, offsetof(struct cfs_var_array, - va_ptrs[arr->va_count])); + kvfree(arr); } EXPORT_SYMBOL(cfs_percpt_free); @@ -79,7 +76,8 @@ cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size) count = cfs_cpt_number(cptab); - LIBCFS_ALLOC(arr, offsetof(struct cfs_var_array, va_ptrs[count])); + arr = kvzalloc(offsetof(struct cfs_var_array, va_ptrs[count]), + GFP_KERNEL); if (!arr) return NULL; @@ -89,7 +87,8 @@ cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size) arr->va_cptab = cptab; for (i = 0; i < count; i++) { - LIBCFS_CPT_ALLOC(arr->va_ptrs[i], cptab, i, size); + arr->va_ptrs[i] = kzalloc_node(size, GFP_KERNEL, + cfs_cpt_spread_node(cptab, i)); if (!arr->va_ptrs[i]) { cfs_percpt_free((void *)&arr->va_ptrs[0]); return NULL; @@ -130,10 +129,9 @@ cfs_array_free(void *vars) if (!arr->va_ptrs[i]) continue; - LIBCFS_FREE(arr->va_ptrs[i], arr->va_size); + kvfree(arr->va_ptrs[i]); } - LIBCFS_FREE(arr, offsetof(struct cfs_var_array, - va_ptrs[arr->va_count])); + kvfree(arr); } EXPORT_SYMBOL(cfs_array_free); @@ -148,7 +146,7 @@ cfs_array_alloc(int count, unsigned int size) struct cfs_var_array *arr; int i; - LIBCFS_ALLOC(arr, offsetof(struct cfs_var_array, va_ptrs[count])); + arr = kvmalloc(offsetof(struct cfs_var_array, va_ptrs[count]), GFP_KERNEL); if (!arr) return NULL; @@ -156,7 +154,7 @@ cfs_array_alloc(int count, unsigned int size) arr->va_size = size; for (i = 0; i < count; i++) { - LIBCFS_ALLOC(arr->va_ptrs[i], size); + arr->va_ptrs[i] = kvzalloc(size, GFP_KERNEL); if (!arr->va_ptrs[i]) { cfs_array_free((void *)&arr->va_ptrs[0]); diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_string.c b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c index bcac5074bf80..442889a3d729 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_string.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c @@ -137,26 +137,6 @@ out: } EXPORT_SYMBOL(cfs_firststr); -char * -cfs_trimwhite(char *str) -{ - char *end; - - while (isspace(*str)) - str++; - - end = str + strlen(str); - while (end > str) { - if (!isspace(end[-1])) - break; - end--; - } - - *end = 0; - return str; -} -EXPORT_SYMBOL(cfs_trimwhite); - /** * Extracts tokens from strings. * @@ -280,7 +260,7 @@ cfs_range_expr_parse(struct cfs_lstr *src, unsigned int min, unsigned int max, struct cfs_range_expr *re; struct cfs_lstr tok; - LIBCFS_ALLOC(re, sizeof(*re)); + re = kzalloc(sizeof(*re), GFP_NOFS); if (!re) return -ENOMEM; @@ -333,7 +313,7 @@ cfs_range_expr_parse(struct cfs_lstr *src, unsigned int min, unsigned int max, return 0; failed: - LIBCFS_FREE(re, sizeof(*re)); + kfree(re); return -EINVAL; } @@ -457,7 +437,7 @@ cfs_expr_list_values(struct cfs_expr_list *expr_list, int max, u32 **valpp) return -EINVAL; } - LIBCFS_ALLOC(val, sizeof(val[0]) * count); + val = kvmalloc_array(count, sizeof(val[0]), GFP_KERNEL | __GFP_ZERO); if (!val) return -ENOMEM; @@ -488,10 +468,10 @@ cfs_expr_list_free(struct cfs_expr_list *expr_list) expr = list_entry(expr_list->el_exprs.next, struct cfs_range_expr, re_link); list_del(&expr->re_link); - LIBCFS_FREE(expr, sizeof(*expr)); + kfree(expr); } - LIBCFS_FREE(expr_list, sizeof(*expr_list)); + kfree(expr_list); } EXPORT_SYMBOL(cfs_expr_list_free); @@ -510,7 +490,7 @@ cfs_expr_list_parse(char *str, int len, unsigned int min, unsigned int max, struct cfs_lstr src; int rc; - LIBCFS_ALLOC(expr_list, sizeof(*expr_list)); + expr_list = kzalloc(sizeof(*expr_list), GFP_NOFS); if (!expr_list) return -ENOMEM; diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c index 51823ce71773..c07165e0ad95 100644 --- a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c +++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c @@ -72,7 +72,7 @@ struct cfs_cpt_data { /* mutex to protect cpt_cpumask */ struct mutex cpt_mutex; /* scratch buffer for set/unset_node */ - cpumask_t *cpt_cpumask; + cpumask_var_t cpt_cpumask; }; static struct cfs_cpt_data cpt_data; @@ -93,35 +93,21 @@ cfs_cpt_table_free(struct cfs_cpt_table *cptab) { int i; - if (cptab->ctb_cpu2cpt) { - LIBCFS_FREE(cptab->ctb_cpu2cpt, - num_possible_cpus() * - sizeof(cptab->ctb_cpu2cpt[0])); - } + kvfree(cptab->ctb_cpu2cpt); for (i = 0; cptab->ctb_parts && i < cptab->ctb_nparts; i++) { struct cfs_cpu_partition *part = &cptab->ctb_parts[i]; - if (part->cpt_nodemask) { - LIBCFS_FREE(part->cpt_nodemask, - sizeof(*part->cpt_nodemask)); - } - - if (part->cpt_cpumask) - LIBCFS_FREE(part->cpt_cpumask, cpumask_size()); + kfree(part->cpt_nodemask); + free_cpumask_var(part->cpt_cpumask); } - if (cptab->ctb_parts) { - LIBCFS_FREE(cptab->ctb_parts, - cptab->ctb_nparts * sizeof(cptab->ctb_parts[0])); - } + kvfree(cptab->ctb_parts); - if (cptab->ctb_nodemask) - LIBCFS_FREE(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); - if (cptab->ctb_cpumask) - LIBCFS_FREE(cptab->ctb_cpumask, cpumask_size()); + kfree(cptab->ctb_nodemask); + free_cpumask_var(cptab->ctb_cpumask); - LIBCFS_FREE(cptab, sizeof(*cptab)); + kfree(cptab); } EXPORT_SYMBOL(cfs_cpt_table_free); @@ -131,36 +117,39 @@ cfs_cpt_table_alloc(unsigned int ncpt) struct cfs_cpt_table *cptab; int i; - LIBCFS_ALLOC(cptab, sizeof(*cptab)); + cptab = kzalloc(sizeof(*cptab), GFP_NOFS); if (!cptab) return NULL; cptab->ctb_nparts = ncpt; - LIBCFS_ALLOC(cptab->ctb_cpumask, cpumask_size()); - LIBCFS_ALLOC(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); - - if (!cptab->ctb_cpumask || !cptab->ctb_nodemask) + cptab->ctb_nodemask = kzalloc(sizeof(*cptab->ctb_nodemask), + GFP_NOFS); + if (!zalloc_cpumask_var(&cptab->ctb_cpumask, GFP_NOFS) || + !cptab->ctb_nodemask) goto failed; - LIBCFS_ALLOC(cptab->ctb_cpu2cpt, - num_possible_cpus() * sizeof(cptab->ctb_cpu2cpt[0])); + cptab->ctb_cpu2cpt = kvmalloc_array(num_possible_cpus(), + sizeof(cptab->ctb_cpu2cpt[0]), + GFP_KERNEL); if (!cptab->ctb_cpu2cpt) goto failed; memset(cptab->ctb_cpu2cpt, -1, num_possible_cpus() * sizeof(cptab->ctb_cpu2cpt[0])); - LIBCFS_ALLOC(cptab->ctb_parts, ncpt * sizeof(cptab->ctb_parts[0])); + cptab->ctb_parts = kvmalloc_array(ncpt, sizeof(cptab->ctb_parts[0]), + GFP_KERNEL); if (!cptab->ctb_parts) goto failed; for (i = 0; i < ncpt; i++) { struct cfs_cpu_partition *part = &cptab->ctb_parts[i]; - LIBCFS_ALLOC(part->cpt_cpumask, cpumask_size()); - LIBCFS_ALLOC(part->cpt_nodemask, sizeof(*part->cpt_nodemask)); - if (!part->cpt_cpumask || !part->cpt_nodemask) + part->cpt_nodemask = kzalloc(sizeof(*part->cpt_nodemask), + GFP_NOFS); + if (!zalloc_cpumask_var(&part->cpt_cpumask, GFP_NOFS) || + !part->cpt_nodemask) goto failed; } @@ -251,13 +240,13 @@ cfs_cpt_online(struct cfs_cpt_table *cptab, int cpt) } EXPORT_SYMBOL(cfs_cpt_online); -cpumask_t * +cpumask_var_t * cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt) { LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts)); return cpt == CFS_CPT_ANY ? - cptab->ctb_cpumask : cptab->ctb_parts[cpt].cpt_cpumask; + &cptab->ctb_cpumask : &cptab->ctb_parts[cpt].cpt_cpumask; } EXPORT_SYMBOL(cfs_cpt_cpumask); @@ -405,7 +394,6 @@ EXPORT_SYMBOL(cfs_cpt_unset_cpumask); int cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node) { - cpumask_t *mask; int rc; if (node < 0 || node >= MAX_NUMNODES) { @@ -416,10 +404,9 @@ cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node) mutex_lock(&cpt_data.cpt_mutex); - mask = cpt_data.cpt_cpumask; - cfs_node_to_cpumask(node, mask); + cfs_node_to_cpumask(node, cpt_data.cpt_cpumask); - rc = cfs_cpt_set_cpumask(cptab, cpt, mask); + rc = cfs_cpt_set_cpumask(cptab, cpt, cpt_data.cpt_cpumask); mutex_unlock(&cpt_data.cpt_mutex); @@ -430,8 +417,6 @@ EXPORT_SYMBOL(cfs_cpt_set_node); void cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node) { - cpumask_t *mask; - if (node < 0 || node >= MAX_NUMNODES) { CDEBUG(D_INFO, "Invalid NUMA id %d for CPU partition %d\n", node, cpt); @@ -440,10 +425,9 @@ cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node) mutex_lock(&cpt_data.cpt_mutex); - mask = cpt_data.cpt_cpumask; - cfs_node_to_cpumask(node, mask); + cfs_node_to_cpumask(node, cpt_data.cpt_cpumask); - cfs_cpt_unset_cpumask(cptab, cpt, mask); + cfs_cpt_unset_cpumask(cptab, cpt, cpt_data.cpt_cpumask); mutex_unlock(&cpt_data.cpt_mutex); } @@ -529,19 +513,20 @@ EXPORT_SYMBOL(cfs_cpt_spread_node); int cfs_cpt_current(struct cfs_cpt_table *cptab, int remap) { - int cpu = smp_processor_id(); - int cpt = cptab->ctb_cpu2cpt[cpu]; + int cpu; + int cpt; - if (cpt < 0) { - if (!remap) - return cpt; + preempt_disable(); + cpu = smp_processor_id(); + cpt = cptab->ctb_cpu2cpt[cpu]; + if (cpt < 0 && remap) { /* don't return negative value for safety of upper layer, * instead we shadow the unknown cpu to a valid partition ID */ cpt = cpu % cptab->ctb_nparts; } - + preempt_enable(); return cpt; } EXPORT_SYMBOL(cfs_cpt_current); @@ -558,7 +543,7 @@ EXPORT_SYMBOL(cfs_cpt_of_cpu); int cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt) { - cpumask_t *cpumask; + cpumask_var_t *cpumask; nodemask_t *nodemask; int rc; int i; @@ -566,24 +551,24 @@ cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt) LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts)); if (cpt == CFS_CPT_ANY) { - cpumask = cptab->ctb_cpumask; + cpumask = &cptab->ctb_cpumask; nodemask = cptab->ctb_nodemask; } else { - cpumask = cptab->ctb_parts[cpt].cpt_cpumask; + cpumask = &cptab->ctb_parts[cpt].cpt_cpumask; nodemask = cptab->ctb_parts[cpt].cpt_nodemask; } - if (cpumask_any_and(cpumask, cpu_online_mask) >= nr_cpu_ids) { + if (cpumask_any_and(*cpumask, cpu_online_mask) >= nr_cpu_ids) { CERROR("No online CPU found in CPU partition %d, did someone do CPU hotplug on system? You might need to reload Lustre modules to keep system working well.\n", cpt); return -EINVAL; } for_each_online_cpu(i) { - if (cpumask_test_cpu(i, cpumask)) + if (cpumask_test_cpu(i, *cpumask)) continue; - rc = set_cpus_allowed_ptr(current, cpumask); + rc = set_cpus_allowed_ptr(current, *cpumask); set_mems_allowed(*nodemask); if (!rc) schedule(); /* switch to allowed CPU */ @@ -604,8 +589,8 @@ static int cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, cpumask_t *node, int number) { - cpumask_t *socket = NULL; - cpumask_t *core = NULL; + cpumask_var_t socket; + cpumask_var_t core; int rc = 0; int cpu; @@ -623,13 +608,17 @@ cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, return 0; } - /* allocate scratch buffer */ - LIBCFS_ALLOC(socket, cpumask_size()); - LIBCFS_ALLOC(core, cpumask_size()); - if (!socket || !core) { + /* + * Allocate scratch buffers + * As we cannot initialize a cpumask_var_t, we need + * to alloc both before we can risk trying to free either + */ + if (!zalloc_cpumask_var(&socket, GFP_NOFS)) rc = -ENOMEM; + if (!zalloc_cpumask_var(&core, GFP_NOFS)) + rc = -ENOMEM; + if (rc) goto out; - } while (!cpumask_empty(node)) { cpu = cpumask_first(node); @@ -667,10 +656,8 @@ cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, } out: - if (socket) - LIBCFS_FREE(socket, cpumask_size()); - if (core) - LIBCFS_FREE(core, cpumask_size()); + free_cpumask_var(socket); + free_cpumask_var(core); return rc; } @@ -723,7 +710,7 @@ static struct cfs_cpt_table * cfs_cpt_table_create(int ncpt) { struct cfs_cpt_table *cptab = NULL; - cpumask_t *mask = NULL; + cpumask_var_t mask; int cpt = 0; int num; int rc; @@ -756,8 +743,7 @@ cfs_cpt_table_create(int ncpt) goto failed; } - LIBCFS_ALLOC(mask, cpumask_size()); - if (!mask) { + if (!zalloc_cpumask_var(&mask, GFP_NOFS)){ CERROR("Failed to allocate scratch cpumask\n"); goto failed; } @@ -784,7 +770,7 @@ cfs_cpt_table_create(int ncpt) rc = cfs_cpt_choose_ncpus(cptab, cpt, mask, n); if (rc < 0) - goto failed; + goto failed_mask; LASSERT(num >= cpumask_weight(part->cpt_cpumask)); if (num == cpumask_weight(part->cpt_cpumask)) @@ -797,20 +783,19 @@ cfs_cpt_table_create(int ncpt) CERROR("Expect %d(%d) CPU partitions but got %d(%d), CPU hotplug/unplug while setting?\n", cptab->ctb_nparts, num, cpt, cpumask_weight(cptab->ctb_parts[ncpt - 1].cpt_cpumask)); - goto failed; + goto failed_mask; } - LIBCFS_FREE(mask, cpumask_size()); + free_cpumask_var(mask); return cptab; + failed_mask: + free_cpumask_var(mask); failed: CERROR("Failed to setup CPU-partition-table with %d CPU-partitions, online HW nodes: %d, HW cpus: %d.\n", ncpt, num_online_nodes(), num_online_cpus()); - if (mask) - LIBCFS_FREE(mask, cpumask_size()); - if (cptab) cfs_cpt_table_free(cptab); @@ -830,7 +815,7 @@ cfs_cpt_table_create_pattern(char *pattern) int c; int i; - str = cfs_trimwhite(pattern); + str = strim(pattern); if (*str == 'n' || *str == 'N') { pattern = str + 1; if (*pattern != '\0') { @@ -882,7 +867,7 @@ cfs_cpt_table_create_pattern(char *pattern) high = node ? MAX_NUMNODES - 1 : nr_cpu_ids - 1; - for (str = cfs_trimwhite(pattern), c = 0;; c++) { + for (str = strim(pattern), c = 0;; c++) { struct cfs_range_expr *range; struct cfs_expr_list *el; char *bracket = strchr(str, '['); @@ -917,7 +902,7 @@ cfs_cpt_table_create_pattern(char *pattern) goto failed; } - str = cfs_trimwhite(str + n); + str = strim(str + n); if (str != bracket) { CERROR("Invalid pattern %s\n", str); goto failed; @@ -957,7 +942,7 @@ cfs_cpt_table_create_pattern(char *pattern) goto failed; } - str = cfs_trimwhite(bracket + 1); + str = strim(bracket + 1); } return cptab; @@ -1013,8 +998,7 @@ cfs_cpu_fini(void) cpuhp_remove_state_nocalls(lustre_cpu_online); cpuhp_remove_state_nocalls(CPUHP_LUSTRE_CFS_DEAD); #endif - if (cpt_data.cpt_cpumask) - LIBCFS_FREE(cpt_data.cpt_cpumask, cpumask_size()); + free_cpumask_var(cpt_data.cpt_cpumask); } int @@ -1026,8 +1010,7 @@ cfs_cpu_init(void) memset(&cpt_data, 0, sizeof(cpt_data)); - LIBCFS_ALLOC(cpt_data.cpt_cpumask, cpumask_size()); - if (!cpt_data.cpt_cpumask) { + if (!zalloc_cpumask_var(&cpt_data.cpt_cpumask, GFP_NOFS)) { CERROR("Failed to allocate scratch buffer\n"); return -1; } diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c index b5746230ab31..ddf625669bff 100644 --- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c +++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c @@ -146,7 +146,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp, return -EINVAL; } - LIBCFS_ALLOC(*hdr_pp, hdr.ioc_len); + *hdr_pp = kvmalloc(hdr.ioc_len, GFP_KERNEL); if (!*hdr_pp) return -ENOMEM; @@ -164,7 +164,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp, return 0; free: - LIBCFS_FREE(*hdr_pp, hdr.ioc_len); + kvfree(*hdr_pp); return err; } diff --git a/drivers/staging/lustre/lnet/libcfs/module.c b/drivers/staging/lustre/lnet/libcfs/module.c index 4ead55920e79..a03f924f1d7c 100644 --- a/drivers/staging/lustre/lnet/libcfs/module.c +++ b/drivers/staging/lustre/lnet/libcfs/module.c @@ -156,7 +156,7 @@ int libcfs_ioctl(unsigned long cmd, void __user *uparam) break; } } out: - LIBCFS_FREE(hdr, hdr->ioc_len); + kvfree(hdr); return err; } @@ -302,7 +302,7 @@ static int __proc_cpt_table(void *data, int write, LASSERT(cfs_cpt_table); while (1) { - LIBCFS_ALLOC(buf, len); + buf = kzalloc(len, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -311,7 +311,7 @@ static int __proc_cpt_table(void *data, int write, break; if (rc == -EFBIG) { - LIBCFS_FREE(buf, len); + kfree(buf); len <<= 1; continue; } @@ -325,8 +325,7 @@ static int __proc_cpt_table(void *data, int write, rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL); out: - if (buf) - LIBCFS_FREE(buf, len); + kfree(buf); return rc; } @@ -548,33 +547,23 @@ static int libcfs_init(void) goto cleanup_cpu; } - rc = cfs_wi_startup(); - if (rc) { - CERROR("initialize workitem: error %d\n", rc); - goto cleanup_deregister; - } - - /* max to 4 threads, should be enough for rehash */ - rc = min(cfs_cpt_weight(cfs_cpt_table, CFS_CPT_ANY), 4); - rc = cfs_wi_sched_create("cfs_rh", cfs_cpt_table, CFS_CPT_ANY, - rc, &cfs_sched_rehash); - if (rc) { - CERROR("Startup workitem scheduler: error: %d\n", rc); + cfs_rehash_wq = alloc_workqueue("cfs_rh", WQ_SYSFS, 4); + if (!cfs_rehash_wq) { + CERROR("Failed to start rehash workqueue.\n"); + rc = -ENOMEM; goto cleanup_deregister; } rc = cfs_crypto_register(); if (rc) { CERROR("cfs_crypto_register: error %d\n", rc); - goto cleanup_wi; + goto cleanup_deregister; } lustre_insert_debugfs(lnet_table, lnet_debugfs_symlinks); CDEBUG(D_OTHER, "portals setup OK\n"); return 0; - cleanup_wi: - cfs_wi_shutdown(); cleanup_deregister: misc_deregister(&libcfs_dev); cleanup_cpu: @@ -590,13 +579,12 @@ static void libcfs_exit(void) lustre_remove_debugfs(); - if (cfs_sched_rehash) { - cfs_wi_sched_destroy(cfs_sched_rehash); - cfs_sched_rehash = NULL; + if (cfs_rehash_wq) { + destroy_workqueue(cfs_rehash_wq); + cfs_rehash_wq = NULL; } cfs_crypto_unregister(); - cfs_wi_shutdown(); misc_deregister(&libcfs_dev); diff --git a/drivers/staging/lustre/lnet/libcfs/prng.c b/drivers/staging/lustre/lnet/libcfs/prng.c deleted file mode 100644 index f47cf67a92e3..000000000000 --- a/drivers/staging/lustre/lnet/libcfs/prng.c +++ /dev/null @@ -1,137 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * GPL HEADER START - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License version 2 for more details (a copy is included - * in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see - * http://www.gnu.org/licenses/gpl-2.0.html - * - * GPL HEADER END - */ -/* - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * libcfs/libcfs/prng.c - * - * concatenation of following two 16-bit multiply with carry generators - * x(n)=a*x(n-1)+carry mod 2^16 and y(n)=b*y(n-1)+carry mod 2^16, - * number and carry packed within the same 32 bit integer. - * algorithm recommended by Marsaglia - */ - -#include <linux/libcfs/libcfs.h> - -/* - * From: George Marsaglia <geo@stat.fsu.edu> - * Newsgroups: sci.math - * Subject: Re: A RANDOM NUMBER GENERATOR FOR C - * Date: Tue, 30 Sep 1997 05:29:35 -0700 - * - * You may replace the two constants 36969 and 18000 by any - * pair of distinct constants from this list: - * 18000 18030 18273 18513 18879 19074 19098 19164 19215 19584 - * 19599 19950 20088 20508 20544 20664 20814 20970 21153 21243 - * 21423 21723 21954 22125 22188 22293 22860 22938 22965 22974 - * 23109 23124 23163 23208 23508 23520 23553 23658 23865 24114 - * 24219 24660 24699 24864 24948 25023 25308 25443 26004 26088 - * 26154 26550 26679 26838 27183 27258 27753 27795 27810 27834 - * 27960 28320 28380 28689 28710 28794 28854 28959 28980 29013 - * 29379 29889 30135 30345 30459 30714 30903 30963 31059 31083 - * (or any other 16-bit constants k for which both k*2^16-1 - * and k*2^15-1 are prime) - */ - -#define RANDOM_CONST_A 18030 -#define RANDOM_CONST_B 29013 - -static unsigned int seed_x = 521288629; -static unsigned int seed_y = 362436069; - -/** - * cfs_rand - creates new seeds - * - * First it creates new seeds from the previous seeds. Then it generates a - * new pseudo random number for use. - * - * Returns a pseudo-random 32-bit integer - */ -unsigned int cfs_rand(void) -{ - seed_x = RANDOM_CONST_A * (seed_x & 65535) + (seed_x >> 16); - seed_y = RANDOM_CONST_B * (seed_y & 65535) + (seed_y >> 16); - - return ((seed_x << 16) + (seed_y & 65535)); -} -EXPORT_SYMBOL(cfs_rand); - -/** - * cfs_srand - sets the initial seed - * @seed1 : (seed_x) should have the most entropy in the low bits of the word - * @seed2 : (seed_y) should have the most entropy in the high bits of the word - * - * Replaces the original seeds with new values. Used to generate a new pseudo - * random numbers. - */ -void cfs_srand(unsigned int seed1, unsigned int seed2) -{ - if (seed1) - seed_x = seed1; /* use default seeds if parameter is 0 */ - if (seed2) - seed_y = seed2; -} -EXPORT_SYMBOL(cfs_srand); - -/** - * cfs_get_random_bytes - generate a bunch of random numbers - * @buf : buffer to fill with random numbers - * @size: size of passed in buffer - * - * Fills a buffer with random bytes - */ -void cfs_get_random_bytes(void *buf, int size) -{ - int *p = buf; - int rem, tmp; - - LASSERT(size >= 0); - - rem = min((int)((unsigned long)buf & (sizeof(int) - 1)), size); - if (rem) { - get_random_bytes(&tmp, sizeof(tmp)); - tmp ^= cfs_rand(); - memcpy(buf, &tmp, rem); - p = buf + rem; - size -= rem; - } - - while (size >= sizeof(int)) { - get_random_bytes(&tmp, sizeof(tmp)); - *p = cfs_rand() ^ tmp; - size -= sizeof(int); - p++; - } - buf = p; - if (size) { - get_random_bytes(&tmp, sizeof(tmp)); - tmp ^= cfs_rand(); - memcpy(buf, &tmp, size); - } -} -EXPORT_SYMBOL(cfs_get_random_bytes); diff --git a/drivers/staging/lustre/lnet/libcfs/tracefile.c b/drivers/staging/lustre/lnet/libcfs/tracefile.c index da2844f37edf..57913aae1d88 100644 --- a/drivers/staging/lustre/lnet/libcfs/tracefile.c +++ b/drivers/staging/lustre/lnet/libcfs/tracefile.c @@ -785,7 +785,7 @@ int cfs_trace_copyin_string(char *knl_buffer, int knl_buffer_nob, return -EFAULT; nob = strnlen(knl_buffer, usr_buffer_nob); - while (nob-- >= 0) /* strip trailing whitespace */ + while (--nob >= 0) /* strip trailing whitespace */ if (!isspace(knl_buffer[nob])) break; diff --git a/drivers/staging/lustre/lnet/libcfs/workitem.c b/drivers/staging/lustre/lnet/libcfs/workitem.c deleted file mode 100644 index 6a05d9bab8dc..000000000000 --- a/drivers/staging/lustre/lnet/libcfs/workitem.c +++ /dev/null @@ -1,466 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * GPL HEADER START - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License version 2 for more details (a copy is included - * in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see - * http://www.gnu.org/licenses/gpl-2.0.html - * - * GPL HEADER END - */ -/* - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * Copyright (c) 2011, 2012, Intel Corporation. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * libcfs/libcfs/workitem.c - * - * Author: Isaac Huang <isaac@clusterfs.com> - * Liang Zhen <zhen.liang@sun.com> - */ - -#define DEBUG_SUBSYSTEM S_LNET - -#include <linux/libcfs/libcfs.h> - -#define CFS_WS_NAME_LEN 16 - -struct cfs_wi_sched { - /* chain on global list */ - struct list_head ws_list; - /** serialised workitems */ - spinlock_t ws_lock; - /** where schedulers sleep */ - wait_queue_head_t ws_waitq; - /** concurrent workitems */ - struct list_head ws_runq; - /** - * rescheduled running-workitems, a workitem can be rescheduled - * while running in wi_action(), but we don't to execute it again - * unless it returns from wi_action(), so we put it on ws_rerunq - * while rescheduling, and move it to runq after it returns - * from wi_action() - */ - struct list_head ws_rerunq; - /** CPT-table for this scheduler */ - struct cfs_cpt_table *ws_cptab; - /** CPT id for affinity */ - int ws_cpt; - /** number of scheduled workitems */ - int ws_nscheduled; - /** started scheduler thread, protected by cfs_wi_data::wi_glock */ - unsigned int ws_nthreads:30; - /** shutting down, protected by cfs_wi_data::wi_glock */ - unsigned int ws_stopping:1; - /** serialize starting thread, protected by cfs_wi_data::wi_glock */ - unsigned int ws_starting:1; - /** scheduler name */ - char ws_name[CFS_WS_NAME_LEN]; -}; - -static struct cfs_workitem_data { - /** serialize */ - spinlock_t wi_glock; - /** list of all schedulers */ - struct list_head wi_scheds; - /** WI module is initialized */ - int wi_init; - /** shutting down the whole WI module */ - int wi_stopping; -} cfs_wi_data; - -static inline int -cfs_wi_sched_cansleep(struct cfs_wi_sched *sched) -{ - spin_lock(&sched->ws_lock); - if (sched->ws_stopping) { - spin_unlock(&sched->ws_lock); - return 0; - } - - if (!list_empty(&sched->ws_runq)) { - spin_unlock(&sched->ws_lock); - return 0; - } - spin_unlock(&sched->ws_lock); - return 1; -} - -/* XXX: - * 0. it only works when called from wi->wi_action. - * 1. when it returns no one shall try to schedule the workitem. - */ -void -cfs_wi_exit(struct cfs_wi_sched *sched, struct cfs_workitem *wi) -{ - LASSERT(!in_interrupt()); /* because we use plain spinlock */ - LASSERT(!sched->ws_stopping); - - spin_lock(&sched->ws_lock); - - LASSERT(wi->wi_running); - if (wi->wi_scheduled) { /* cancel pending schedules */ - LASSERT(!list_empty(&wi->wi_list)); - list_del_init(&wi->wi_list); - - LASSERT(sched->ws_nscheduled > 0); - sched->ws_nscheduled--; - } - - LASSERT(list_empty(&wi->wi_list)); - - wi->wi_scheduled = 1; /* LBUG future schedule attempts */ - spin_unlock(&sched->ws_lock); -} -EXPORT_SYMBOL(cfs_wi_exit); - -/** - * cancel schedule request of workitem \a wi - */ -int -cfs_wi_deschedule(struct cfs_wi_sched *sched, struct cfs_workitem *wi) -{ - int rc; - - LASSERT(!in_interrupt()); /* because we use plain spinlock */ - LASSERT(!sched->ws_stopping); - - /* - * return 0 if it's running already, otherwise return 1, which - * means the workitem will not be scheduled and will not have - * any race with wi_action. - */ - spin_lock(&sched->ws_lock); - - rc = !(wi->wi_running); - - if (wi->wi_scheduled) { /* cancel pending schedules */ - LASSERT(!list_empty(&wi->wi_list)); - list_del_init(&wi->wi_list); - - LASSERT(sched->ws_nscheduled > 0); - sched->ws_nscheduled--; - - wi->wi_scheduled = 0; - } - - LASSERT(list_empty(&wi->wi_list)); - - spin_unlock(&sched->ws_lock); - return rc; -} -EXPORT_SYMBOL(cfs_wi_deschedule); - -/* - * Workitem scheduled with (serial == 1) is strictly serialised not only with - * itself, but also with others scheduled this way. - * - * Now there's only one static serialised queue, but in the future more might - * be added, and even dynamic creation of serialised queues might be supported. - */ -void -cfs_wi_schedule(struct cfs_wi_sched *sched, struct cfs_workitem *wi) -{ - LASSERT(!in_interrupt()); /* because we use plain spinlock */ - LASSERT(!sched->ws_stopping); - - spin_lock(&sched->ws_lock); - - if (!wi->wi_scheduled) { - LASSERT(list_empty(&wi->wi_list)); - - wi->wi_scheduled = 1; - sched->ws_nscheduled++; - if (!wi->wi_running) { - list_add_tail(&wi->wi_list, &sched->ws_runq); - wake_up(&sched->ws_waitq); - } else { - list_add(&wi->wi_list, &sched->ws_rerunq); - } - } - - LASSERT(!list_empty(&wi->wi_list)); - spin_unlock(&sched->ws_lock); -} -EXPORT_SYMBOL(cfs_wi_schedule); - -static int cfs_wi_scheduler(void *arg) -{ - struct cfs_wi_sched *sched = (struct cfs_wi_sched *)arg; - - cfs_block_allsigs(); - - /* CPT affinity scheduler? */ - if (sched->ws_cptab) - if (cfs_cpt_bind(sched->ws_cptab, sched->ws_cpt)) - CWARN("Unable to bind %s on CPU partition %d\n", - sched->ws_name, sched->ws_cpt); - - spin_lock(&cfs_wi_data.wi_glock); - - LASSERT(sched->ws_starting == 1); - sched->ws_starting--; - sched->ws_nthreads++; - - spin_unlock(&cfs_wi_data.wi_glock); - - spin_lock(&sched->ws_lock); - - while (!sched->ws_stopping) { - int nloops = 0; - int rc; - struct cfs_workitem *wi; - - while (!list_empty(&sched->ws_runq) && - nloops < CFS_WI_RESCHED) { - wi = list_entry(sched->ws_runq.next, - struct cfs_workitem, wi_list); - LASSERT(wi->wi_scheduled && !wi->wi_running); - - list_del_init(&wi->wi_list); - - LASSERT(sched->ws_nscheduled > 0); - sched->ws_nscheduled--; - - wi->wi_running = 1; - wi->wi_scheduled = 0; - - spin_unlock(&sched->ws_lock); - nloops++; - - rc = (*wi->wi_action)(wi); - - spin_lock(&sched->ws_lock); - if (rc) /* WI should be dead, even be freed! */ - continue; - - wi->wi_running = 0; - if (list_empty(&wi->wi_list)) - continue; - - LASSERT(wi->wi_scheduled); - /* wi is rescheduled, should be on rerunq now, we - * move it to runq so it can run action now - */ - list_move_tail(&wi->wi_list, &sched->ws_runq); - } - - if (!list_empty(&sched->ws_runq)) { - spin_unlock(&sched->ws_lock); - /* don't sleep because some workitems still - * expect me to come back soon - */ - cond_resched(); - spin_lock(&sched->ws_lock); - continue; - } - - spin_unlock(&sched->ws_lock); - rc = wait_event_interruptible_exclusive(sched->ws_waitq, - !cfs_wi_sched_cansleep(sched)); - spin_lock(&sched->ws_lock); - } - - spin_unlock(&sched->ws_lock); - - spin_lock(&cfs_wi_data.wi_glock); - sched->ws_nthreads--; - spin_unlock(&cfs_wi_data.wi_glock); - - return 0; -} - -void -cfs_wi_sched_destroy(struct cfs_wi_sched *sched) -{ - int i; - - LASSERT(cfs_wi_data.wi_init); - LASSERT(!cfs_wi_data.wi_stopping); - - spin_lock(&cfs_wi_data.wi_glock); - if (sched->ws_stopping) { - CDEBUG(D_INFO, "%s is in progress of stopping\n", - sched->ws_name); - spin_unlock(&cfs_wi_data.wi_glock); - return; - } - - LASSERT(!list_empty(&sched->ws_list)); - sched->ws_stopping = 1; - - spin_unlock(&cfs_wi_data.wi_glock); - - i = 2; - wake_up_all(&sched->ws_waitq); - - spin_lock(&cfs_wi_data.wi_glock); - while (sched->ws_nthreads > 0) { - CDEBUG(is_power_of_2(++i) ? D_WARNING : D_NET, - "waiting for %d threads of WI sched[%s] to terminate\n", - sched->ws_nthreads, sched->ws_name); - - spin_unlock(&cfs_wi_data.wi_glock); - set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1) / 20); - spin_lock(&cfs_wi_data.wi_glock); - } - - list_del(&sched->ws_list); - - spin_unlock(&cfs_wi_data.wi_glock); - LASSERT(!sched->ws_nscheduled); - - LIBCFS_FREE(sched, sizeof(*sched)); -} -EXPORT_SYMBOL(cfs_wi_sched_destroy); - -int -cfs_wi_sched_create(char *name, struct cfs_cpt_table *cptab, - int cpt, int nthrs, struct cfs_wi_sched **sched_pp) -{ - struct cfs_wi_sched *sched; - int rc; - - LASSERT(cfs_wi_data.wi_init); - LASSERT(!cfs_wi_data.wi_stopping); - LASSERT(!cptab || cpt == CFS_CPT_ANY || - (cpt >= 0 && cpt < cfs_cpt_number(cptab))); - - LIBCFS_ALLOC(sched, sizeof(*sched)); - if (!sched) - return -ENOMEM; - - if (strlen(name) > sizeof(sched->ws_name) - 1) { - LIBCFS_FREE(sched, sizeof(*sched)); - return -E2BIG; - } - strncpy(sched->ws_name, name, sizeof(sched->ws_name)); - - sched->ws_cptab = cptab; - sched->ws_cpt = cpt; - - spin_lock_init(&sched->ws_lock); - init_waitqueue_head(&sched->ws_waitq); - INIT_LIST_HEAD(&sched->ws_runq); - INIT_LIST_HEAD(&sched->ws_rerunq); - INIT_LIST_HEAD(&sched->ws_list); - - rc = 0; - while (nthrs > 0) { - char name[16]; - struct task_struct *task; - - spin_lock(&cfs_wi_data.wi_glock); - while (sched->ws_starting > 0) { - spin_unlock(&cfs_wi_data.wi_glock); - schedule(); - spin_lock(&cfs_wi_data.wi_glock); - } - - sched->ws_starting++; - spin_unlock(&cfs_wi_data.wi_glock); - - if (sched->ws_cptab && sched->ws_cpt >= 0) { - snprintf(name, sizeof(name), "%s_%02d_%02u", - sched->ws_name, sched->ws_cpt, - sched->ws_nthreads); - } else { - snprintf(name, sizeof(name), "%s_%02u", - sched->ws_name, sched->ws_nthreads); - } - - task = kthread_run(cfs_wi_scheduler, sched, "%s", name); - if (!IS_ERR(task)) { - nthrs--; - continue; - } - rc = PTR_ERR(task); - - CERROR("Failed to create thread for WI scheduler %s: %d\n", - name, rc); - - spin_lock(&cfs_wi_data.wi_glock); - - /* make up for cfs_wi_sched_destroy */ - list_add(&sched->ws_list, &cfs_wi_data.wi_scheds); - sched->ws_starting--; - - spin_unlock(&cfs_wi_data.wi_glock); - - cfs_wi_sched_destroy(sched); - return rc; - } - spin_lock(&cfs_wi_data.wi_glock); - list_add(&sched->ws_list, &cfs_wi_data.wi_scheds); - spin_unlock(&cfs_wi_data.wi_glock); - - *sched_pp = sched; - return 0; -} -EXPORT_SYMBOL(cfs_wi_sched_create); - -int -cfs_wi_startup(void) -{ - memset(&cfs_wi_data, 0, sizeof(cfs_wi_data)); - - spin_lock_init(&cfs_wi_data.wi_glock); - INIT_LIST_HEAD(&cfs_wi_data.wi_scheds); - cfs_wi_data.wi_init = 1; - - return 0; -} - -void -cfs_wi_shutdown(void) -{ - struct cfs_wi_sched *sched; - struct cfs_wi_sched *temp; - - spin_lock(&cfs_wi_data.wi_glock); - cfs_wi_data.wi_stopping = 1; - spin_unlock(&cfs_wi_data.wi_glock); - - /* nobody should contend on this list */ - list_for_each_entry(sched, &cfs_wi_data.wi_scheds, ws_list) { - sched->ws_stopping = 1; - wake_up_all(&sched->ws_waitq); - } - - list_for_each_entry(sched, &cfs_wi_data.wi_scheds, ws_list) { - spin_lock(&cfs_wi_data.wi_glock); - - while (sched->ws_nthreads) { - spin_unlock(&cfs_wi_data.wi_glock); - set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1) / 20); - spin_lock(&cfs_wi_data.wi_glock); - } - spin_unlock(&cfs_wi_data.wi_glock); - } - list_for_each_entry_safe(sched, temp, &cfs_wi_data.wi_scheds, ws_list) { - list_del(&sched->ws_list); - LIBCFS_FREE(sched, sizeof(*sched)); - } - - cfs_wi_data.wi_stopping = 0; - cfs_wi_data.wi_init = 0; -} diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c index 7caff290c146..2c7abad57104 100644 --- a/drivers/staging/lustre/lnet/lnet/api-ni.c +++ b/drivers/staging/lustre/lnet/lnet/api-ni.c @@ -108,7 +108,8 @@ lnet_create_remote_nets_table(void) LASSERT(!the_lnet.ln_remote_nets_hash); LASSERT(the_lnet.ln_remote_nets_hbits > 0); - LIBCFS_ALLOC(hash, LNET_REMOTE_NETS_HASH_SIZE * sizeof(*hash)); + hash = kvmalloc_array(LNET_REMOTE_NETS_HASH_SIZE, sizeof(*hash), + GFP_KERNEL); if (!hash) { CERROR("Failed to create remote nets hash table\n"); return -ENOMEM; @@ -131,9 +132,7 @@ lnet_destroy_remote_nets_table(void) for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i])); - LIBCFS_FREE(the_lnet.ln_remote_nets_hash, - LNET_REMOTE_NETS_HASH_SIZE * - sizeof(the_lnet.ln_remote_nets_hash[0])); + kvfree(the_lnet.ln_remote_nets_hash); the_lnet.ln_remote_nets_hash = NULL; } @@ -384,10 +383,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(); @@ -405,11 +404,8 @@ lnet_res_container_cleanup(struct lnet_res_container *rec) count, lnet_res_type2str(rec->rec_type)); } - if (rec->rec_lh_hash) { - LIBCFS_FREE(rec->rec_lh_hash, - LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0])); - rec->rec_lh_hash = NULL; - } + kfree(rec->rec_lh_hash); + rec->rec_lh_hash = NULL; rec->rec_type = 0; /* mark it as finalized */ } @@ -427,8 +423,8 @@ lnet_res_container_setup(struct lnet_res_container *rec, int cpt, int type) rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type; /* Arbitrary choice of hash table size */ - LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt, - LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0])); + rec->rec_lh_hash = kvmalloc_cpt(LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]), + GFP_KERNEL, cpt); if (!rec->rec_lh_hash) { rc = -ENOMEM; goto out; @@ -831,7 +827,7 @@ lnet_ping_info_create(int num_ni) unsigned int infosz; infosz = offsetof(struct lnet_ping_info, pi_ni[num_ni]); - LIBCFS_ALLOC(ping_info, infosz); + ping_info = kvzalloc(infosz, GFP_KERNEL); if (!ping_info) { CERROR("Can't allocate ping info[%d]\n", num_ni); return NULL; @@ -864,9 +860,7 @@ lnet_get_ni_count(void) static inline void lnet_ping_info_free(struct lnet_ping_info *pinfo) { - LIBCFS_FREE(pinfo, - offsetof(struct lnet_ping_info, - pi_ni[pinfo->pi_nnis])); + kvfree(pinfo); } static void @@ -1280,8 +1274,8 @@ lnet_startup_lndni(struct lnet_ni *ni, struct lnet_ioctl_config_data *conf) lnd_tunables = (struct lnet_ioctl_config_lnd_tunables *)conf->cfg_bulk; if (lnd_tunables) { - LIBCFS_ALLOC(ni->ni_lnd_tunables, - sizeof(*ni->ni_lnd_tunables)); + ni->ni_lnd_tunables = kzalloc(sizeof(*ni->ni_lnd_tunables), + GFP_NOFS); if (!ni->ni_lnd_tunables) { mutex_unlock(&the_lnet.ln_lnd_mutex); rc = -ENOMEM; @@ -2160,7 +2154,7 @@ static int lnet_ping(struct lnet_process_id id, int timeout_ms, if (id.pid == LNET_PID_ANY) id.pid = LNET_PID_LUSTRE; - LIBCFS_ALLOC(info, infosz); + info = kzalloc(infosz, GFP_KERNEL); if (!info) return -ENOMEM; @@ -2310,6 +2304,6 @@ static int lnet_ping(struct lnet_process_id id, int timeout_ms, LASSERT(!rc2); out_0: - LIBCFS_FREE(info, infosz); + kfree(info); return rc; } diff --git a/drivers/staging/lustre/lnet/lnet/config.c b/drivers/staging/lustre/lnet/lnet/config.c index 0cf0f4f99435..0aea268a4f1c 100644 --- a/drivers/staging/lustre/lnet/lnet/config.c +++ b/drivers/staging/lustre/lnet/lnet/config.c @@ -106,19 +106,16 @@ lnet_ni_free(struct lnet_ni *ni) if (ni->ni_cpts) cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts); - if (ni->ni_lnd_tunables) - LIBCFS_FREE(ni->ni_lnd_tunables, sizeof(*ni->ni_lnd_tunables)); + kfree(ni->ni_lnd_tunables); - for (i = 0; i < LNET_MAX_INTERFACES && ni->ni_interfaces[i]; i++) { - LIBCFS_FREE(ni->ni_interfaces[i], - strlen(ni->ni_interfaces[i]) + 1); - } + for (i = 0; i < LNET_MAX_INTERFACES && ni->ni_interfaces[i]; i++) + kfree(ni->ni_interfaces[i]); /* release reference to net namespace */ if (ni->ni_net_ns) put_net(ni->ni_net_ns); - LIBCFS_FREE(ni, sizeof(*ni)); + kfree(ni); } struct lnet_ni * @@ -135,7 +132,7 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist) return NULL; } - LIBCFS_ALLOC(ni, sizeof(*ni)); + ni = kzalloc(sizeof(*ni), GFP_NOFS); if (!ni) { CERROR("Out of memory creating network %s\n", libcfs_net2str(net)); @@ -170,7 +167,7 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist) LASSERT(rc <= LNET_CPT_NUMBER); if (rc == LNET_CPT_NUMBER) { - LIBCFS_FREE(ni->ni_cpts, rc * sizeof(ni->ni_cpts[0])); + cfs_expr_list_values_free(ni->ni_cpts, LNET_CPT_NUMBER); ni->ni_cpts = NULL; } @@ -198,7 +195,6 @@ int lnet_parse_networks(struct list_head *nilist, char *networks) { struct cfs_expr_list *el = NULL; - int tokensize; char *tokens; char *str; char *tmp; @@ -219,15 +215,12 @@ lnet_parse_networks(struct list_head *nilist, char *networks) return -EINVAL; } - tokensize = strlen(networks) + 1; - - LIBCFS_ALLOC(tokens, tokensize); + tokens = kstrdup(networks, GFP_KERNEL); if (!tokens) { CERROR("Can't allocate net tokens\n"); return -ENOMEM; } - memcpy(tokens, networks, tokensize); tmp = tokens; str = tokens; @@ -275,7 +268,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks) if (comma) *comma++ = 0; - net = libcfs_str2net(cfs_trimwhite(str)); + net = libcfs_str2net(strim(str)); if (net == LNET_NIDNET(LNET_NID_ANY)) { LCONSOLE_ERROR_MSG(0x113, @@ -298,7 +291,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks) } *bracket = 0; - net = libcfs_str2net(cfs_trimwhite(str)); + net = libcfs_str2net(strim(str)); if (net == LNET_NIDNET(LNET_NID_ANY)) { tmp = str; goto failed_syntax; @@ -328,7 +321,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks) if (comma) *comma++ = 0; - iface = cfs_trimwhite(iface); + iface = strim(iface); if (!*iface) { tmp = iface; goto failed_syntax; @@ -349,14 +342,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks) * The newly allocated ni_interfaces[] can be * freed when freeing the NI */ - LIBCFS_ALLOC(ni->ni_interfaces[niface], - strlen(iface) + 1); + ni->ni_interfaces[niface] = kstrdup(iface, GFP_KERNEL); if (!ni->ni_interfaces[niface]) { CERROR("Can't allocate net interface name\n"); goto failed; } - strncpy(ni->ni_interfaces[niface], iface, - strlen(iface)); niface++; iface = comma; } while (iface); @@ -365,7 +355,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks) comma = strchr(bracket + 1, ','); if (comma) { *comma = 0; - str = cfs_trimwhite(str); + str = strim(str); if (*str) { tmp = str; goto failed_syntax; @@ -374,7 +364,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks) continue; } - str = cfs_trimwhite(str); + str = strim(str); if (*str) { tmp = str; goto failed_syntax; @@ -384,7 +374,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks) list_for_each(temp_node, nilist) nnets++; - LIBCFS_FREE(tokens, tokensize); + kfree(tokens); return nnets; failed_syntax: @@ -400,7 +390,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks) if (el) cfs_expr_list_free(el); - LIBCFS_FREE(tokens, tokensize); + kfree(tokens); return -EINVAL; } @@ -424,7 +414,7 @@ lnet_new_text_buf(int str_len) return NULL; } - LIBCFS_ALLOC(ltb, nob); + ltb = kzalloc(nob, GFP_KERNEL); if (!ltb) return NULL; @@ -438,7 +428,7 @@ static void lnet_free_text_buf(struct lnet_text_buf *ltb) { lnet_tbnob -= ltb->ltb_size; - LIBCFS_FREE(ltb, ltb->ltb_size); + kfree(ltb); } static void @@ -1156,7 +1146,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) if (nif <= 0) return nif; - LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs)); + ipaddrs = kcalloc(nif, sizeof(*ipaddrs), GFP_KERNEL); if (!ipaddrs) { CERROR("Can't allocate ipaddrs[%d]\n", nif); lnet_ipif_free_enumeration(ifnames, nif); @@ -1189,7 +1179,8 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) *ipaddrsp = ipaddrs; } else { if (nip > 0) { - LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2)); + ipaddrs2 = kcalloc(nip, sizeof(*ipaddrs2), + GFP_KERNEL); if (!ipaddrs2) { CERROR("Can't allocate ipaddrs[%d]\n", nip); nip = -ENOMEM; @@ -1200,7 +1191,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) rc = nip; } } - LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); + kfree(ipaddrs); } return nip; } @@ -1226,7 +1217,7 @@ lnet_parse_ip2nets(char **networksp, char *ip2nets) } rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip); - LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); + kfree(ipaddrs); if (rc < 0) { LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc); diff --git a/drivers/staging/lustre/lnet/lnet/lib-eq.c b/drivers/staging/lustre/lnet/lnet/lib-eq.c index daf744277003..a173b69e2f92 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-eq.c +++ b/drivers/staging/lustre/lnet/lnet/lib-eq.c @@ -90,12 +90,13 @@ 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; if (count) { - LIBCFS_ALLOC(eq->eq_events, count * sizeof(struct lnet_event)); + eq->eq_events = kvmalloc_array(count, sizeof(struct lnet_event), + GFP_KERNEL | __GFP_ZERO); if (!eq->eq_events) goto failed; /* @@ -132,13 +133,12 @@ LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback, return 0; failed: - if (eq->eq_events) - LIBCFS_FREE(eq->eq_events, count * sizeof(struct lnet_event)); + kvfree(eq->eq_events); if (eq->eq_refs) cfs_percpt_free(eq->eq_refs); - lnet_eq_free(eq); + kfree(eq); return -ENOMEM; } EXPORT_SYMBOL(LNetEQAlloc); @@ -197,13 +197,12 @@ 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); - if (events) - LIBCFS_FREE(events, size * sizeof(struct lnet_event)); + kvfree(events); if (refs) cfs_percpt_free(refs); diff --git a/drivers/staging/lustre/lnet/lnet/lib-md.c b/drivers/staging/lustre/lnet/lnet/lib-md.c index ac5b9593d597..8a22514aaf71 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-md.c +++ b/drivers/staging/lustre/lnet/lnet/lib-md.c @@ -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; } diff --git a/drivers/staging/lustre/lnet/lnet/lib-me.c b/drivers/staging/lustre/lnet/lnet/lib-me.c index dd5d3cf6d3e2..672e37bdd045 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-me.c +++ b/drivers/staging/lustre/lnet/lnet/lib-me.c @@ -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(¤t_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); } diff --git a/drivers/staging/lustre/lnet/lnet/lib-move.c b/drivers/staging/lustre/lnet/lnet/lib-move.c index 68d16ffec980..c673037dbce4 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-move.c +++ b/drivers/staging/lustre/lnet/lnet/lib-move.c @@ -57,7 +57,7 @@ lnet_fail_nid(lnet_nid_t nid, unsigned int threshold) /* NB: use lnet_net_lock(0) to serialize operations on test peers */ if (threshold) { /* Adding a new entry */ - LIBCFS_ALLOC(tp, sizeof(*tp)); + tp = kzalloc(sizeof(*tp), GFP_NOFS); if (!tp) return -ENOMEM; @@ -90,7 +90,7 @@ lnet_fail_nid(lnet_nid_t nid, unsigned int threshold) list_for_each_entry_safe(tp, temp, &cull, tp_list) { list_del(&tp->tp_list); - LIBCFS_FREE(tp, sizeof(*tp)); + kfree(tp); } return 0; } @@ -149,7 +149,7 @@ fail_peer(lnet_nid_t nid, int outgoing) list_for_each_entry_safe(tp, temp, &cull, tp_list) { list_del(&tp->tp_list); - LIBCFS_FREE(tp, sizeof(*tp)); + kfree(tp); } return fail; @@ -1769,7 +1769,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid, goto drop; } - msg = lnet_msg_alloc(); + msg = kzalloc(sizeof(*msg), GFP_NOFS); if (!msg) { CERROR("%s, src %s: Dropping %s (out of memory)\n", 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; } - /* msg zeroed in lnet_msg_alloc; + /* msg zeroed by kzalloc() * i.e. flags all clear, pointers NULL etc */ 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", libcfs_nid2str(from_nid), libcfs_nid2str(src_nid), lnet_msgtyp2str(type), rc); - lnet_msg_free(msg); + kfree(msg); if (rc == -ESHUTDOWN) /* We are shutting down. Don't do anything more */ return 0; @@ -2010,7 +2010,7 @@ LNetPut(lnet_nid_t self, struct lnet_handle_md mdh, enum lnet_ack_req ack, return -EIO; } - msg = lnet_msg_alloc(); + msg = kzalloc(sizeof(*msg), GFP_NOFS); if (!msg) { CERROR("Dropping PUT to %s: ENOMEM on struct lnet_msg\n", 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); lnet_res_unlock(cpt); - lnet_msg_free(msg); + kfree(msg); 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 * 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_process_id peer_id = getmsg->msg_target; int cpt; @@ -2146,8 +2146,7 @@ lnet_create_reply_msg(struct lnet_ni *ni, struct lnet_msg *getmsg) the_lnet.ln_counters[cpt]->drop_length += getmd->md_length; lnet_net_unlock(cpt); - if (msg) - lnet_msg_free(msg); + kfree(msg); return NULL; } @@ -2215,7 +2214,7 @@ LNetGet(lnet_nid_t self, struct lnet_handle_md mdh, return -EIO; } - msg = lnet_msg_alloc(); + msg = kzalloc(sizeof(*msg), GFP_NOFS); if (!msg) { CERROR("Dropping GET to %s: ENOMEM on struct lnet_msg\n", libcfs_id2str(target)); @@ -2236,7 +2235,7 @@ LNetGet(lnet_nid_t self, struct lnet_handle_md mdh, lnet_res_unlock(cpt); - lnet_msg_free(msg); + kfree(msg); return -ENOENT; } diff --git a/drivers/staging/lustre/lnet/lnet/lib-msg.c b/drivers/staging/lustre/lnet/lnet/lib-msg.c index c72ef05b2420..0091273c04b9 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-msg.c +++ b/drivers/staging/lustre/lnet/lnet/lib-msg.c @@ -433,7 +433,7 @@ lnet_complete_msg_locked(struct lnet_msg *msg, int cpt) } lnet_msg_decommit(msg, cpt, status); - lnet_msg_free(msg); + kfree(msg); 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) { /* not committed to network yet */ LASSERT(!msg->msg_onactivelist); - lnet_msg_free(msg); + kfree(msg); return; } @@ -546,19 +546,15 @@ lnet_msg_container_cleanup(struct lnet_msg_container *container) LASSERT(msg->msg_onactivelist); msg->msg_onactivelist = 0; list_del(&msg->msg_activelist); - lnet_msg_free(msg); + kfree(msg); count++; } if (count > 0) CERROR("%d active msg on exit\n", count); - if (container->msc_finalizers) { - LIBCFS_FREE(container->msc_finalizers, - container->msc_nfinalizers * - sizeof(*container->msc_finalizers)); - container->msc_finalizers = NULL; - } + kvfree(container->msc_finalizers); + container->msc_finalizers = NULL; container->msc_init = 0; } @@ -573,9 +569,9 @@ lnet_msg_container_setup(struct lnet_msg_container *container, int cpt) /* number of CPUs */ container->msc_nfinalizers = cfs_cpt_weight(lnet_cpt_table(), cpt); - LIBCFS_CPT_ALLOC(container->msc_finalizers, lnet_cpt_table(), cpt, - container->msc_nfinalizers * - sizeof(*container->msc_finalizers)); + container->msc_finalizers = kvzalloc_cpt(container->msc_nfinalizers * + sizeof(*container->msc_finalizers), + GFP_KERNEL, cpt); if (!container->msc_finalizers) { CERROR("Failed to allocate message finalizers\n"); diff --git a/drivers/staging/lustre/lnet/lnet/lib-ptl.c b/drivers/staging/lustre/lnet/lnet/lib-ptl.c index 8ae93bf6fd1b..471f2f6c86f4 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-ptl.c +++ b/drivers/staging/lustre/lnet/lnet/lib-ptl.c @@ -771,11 +771,11 @@ lnet_ptl_cleanup(struct lnet_portal *ptl) struct lnet_me, me_list); CERROR("Active ME %p on exit\n", me); list_del(&me->me_list); - lnet_me_free(me); + kfree(me); } } /* the extra entry is for MEs with ignore bits */ - LIBCFS_FREE(mhash, sizeof(*mhash) * (LNET_MT_HASH_SIZE + 1)); + kvfree(mhash); } cfs_percpt_free(ptl->ptl_mtables); @@ -803,8 +803,8 @@ lnet_ptl_setup(struct lnet_portal *ptl, int index) spin_lock_init(&ptl->ptl_lock); cfs_percpt_for_each(mtable, i, ptl->ptl_mtables) { /* the extra entry is for MEs with ignore bits */ - LIBCFS_CPT_ALLOC(mhash, lnet_cpt_table(), i, - sizeof(*mhash) * (LNET_MT_HASH_SIZE + 1)); + mhash = kvzalloc_cpt(sizeof(*mhash) * (LNET_MT_HASH_SIZE + 1), + GFP_KERNEL, i); if (!mhash) { CERROR("Failed to create match hash for portal %d\n", index); diff --git a/drivers/staging/lustre/lnet/lnet/lib-socket.c b/drivers/staging/lustre/lnet/lnet/lib-socket.c index ed46aaca0ba3..ce93806eefca 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-socket.c +++ b/drivers/staging/lustre/lnet/lnet/lib-socket.c @@ -170,7 +170,7 @@ lnet_ipif_enumerate(char ***namesp) nalloc); } - LIBCFS_ALLOC(ifr, nalloc * sizeof(*ifr)); + ifr = kzalloc(nalloc * sizeof(*ifr), GFP_KERNEL); if (!ifr) { CERROR("ENOMEM enumerating up to %d interfaces\n", nalloc); @@ -195,14 +195,14 @@ lnet_ipif_enumerate(char ***namesp) if (nfound < nalloc || toobig) break; - LIBCFS_FREE(ifr, nalloc * sizeof(*ifr)); + kfree(ifr); nalloc *= 2; } if (!nfound) goto out1; - LIBCFS_ALLOC(names, nfound * sizeof(*names)); + names = kzalloc(nfound * sizeof(*names), GFP_KERNEL); if (!names) { rc = -ENOMEM; goto out1; @@ -218,7 +218,7 @@ lnet_ipif_enumerate(char ***namesp) goto out2; } - LIBCFS_ALLOC(names[i], IFNAMSIZ); + names[i] = kmalloc(IFNAMSIZ, GFP_KERNEL); if (!names[i]) { rc = -ENOMEM; goto out2; @@ -235,7 +235,7 @@ out2: if (rc < 0) lnet_ipif_free_enumeration(names, nfound); out1: - LIBCFS_FREE(ifr, nalloc * sizeof(*ifr)); + kfree(ifr); out0: return rc; } @@ -249,9 +249,9 @@ lnet_ipif_free_enumeration(char **names, int n) LASSERT(n > 0); for (i = 0; i < n && names[i]; i++) - LIBCFS_FREE(names[i], IFNAMSIZ); + kfree(names[i]); - LIBCFS_FREE(names, n * sizeof(*names)); + kfree(names); } EXPORT_SYMBOL(lnet_ipif_free_enumeration); diff --git a/drivers/staging/lustre/lnet/lnet/net_fault.c b/drivers/staging/lustre/lnet/lnet/net_fault.c index 5a5d1811ffbe..e3468cef273b 100644 --- a/drivers/staging/lustre/lnet/lnet/net_fault.c +++ b/drivers/staging/lustre/lnet/lnet/net_fault.c @@ -161,7 +161,7 @@ lnet_drop_rule_add(struct lnet_fault_attr *attr) if (lnet_fault_attr_validate(attr)) return -EINVAL; - CFS_ALLOC_PTR(rule); + rule = kzalloc(sizeof(*rule), GFP_NOFS); if (!rule) return -ENOMEM; @@ -170,10 +170,10 @@ lnet_drop_rule_add(struct lnet_fault_attr *attr) rule->dr_attr = *attr; if (attr->u.drop.da_interval) { rule->dr_time_base = cfs_time_shift(attr->u.drop.da_interval); - rule->dr_drop_time = cfs_time_shift(cfs_rand() % - attr->u.drop.da_interval); + rule->dr_drop_time = cfs_time_shift( + prandom_u32_max(attr->u.drop.da_interval)); } else { - rule->dr_drop_at = cfs_rand() % attr->u.drop.da_rate; + rule->dr_drop_at = prandom_u32_max(attr->u.drop.da_rate); } lnet_net_lock(LNET_LOCK_EX); @@ -223,7 +223,7 @@ lnet_drop_rule_del(lnet_nid_t src, lnet_nid_t dst) rule->dr_attr.u.drop.da_interval); list_del(&rule->dr_link); - CFS_FREE_PTR(rule); + kfree(rule); n++; } @@ -277,10 +277,10 @@ lnet_drop_rule_reset(void) memset(&rule->dr_stat, 0, sizeof(rule->dr_stat)); if (attr->u.drop.da_rate) { - rule->dr_drop_at = cfs_rand() % attr->u.drop.da_rate; + rule->dr_drop_at = prandom_u32_max(attr->u.drop.da_rate); } else { - rule->dr_drop_time = cfs_time_shift(cfs_rand() % - attr->u.drop.da_interval); + rule->dr_drop_time = cfs_time_shift( + prandom_u32_max(attr->u.drop.da_interval)); rule->dr_time_base = cfs_time_shift(attr->u.drop.da_interval); } spin_unlock(&rule->dr_lock); @@ -315,8 +315,8 @@ drop_rule_match(struct lnet_drop_rule *rule, lnet_nid_t src, rule->dr_time_base = now; rule->dr_drop_time = rule->dr_time_base + - cfs_time_seconds(cfs_rand() % - attr->u.drop.da_interval); + cfs_time_seconds( + prandom_u32_max(attr->u.drop.da_interval)); rule->dr_time_base += cfs_time_seconds(attr->u.drop.da_interval); CDEBUG(D_NET, "Drop Rule %s->%s: next drop : %lu\n", @@ -330,7 +330,7 @@ drop_rule_match(struct lnet_drop_rule *rule, lnet_nid_t src, if (!do_div(rule->dr_stat.fs_count, attr->u.drop.da_rate)) { rule->dr_drop_at = rule->dr_stat.fs_count + - cfs_rand() % attr->u.drop.da_rate; + prandom_u32_max(attr->u.drop.da_rate); CDEBUG(D_NET, "Drop Rule %s->%s: next drop: %lu\n", libcfs_nid2str(attr->fa_src), libcfs_nid2str(attr->fa_dst), rule->dr_drop_at); @@ -452,7 +452,7 @@ delay_rule_decref(struct lnet_delay_rule *rule) LASSERT(list_empty(&rule->dl_msg_list)); LASSERT(list_empty(&rule->dl_link)); - CFS_FREE_PTR(rule); + kfree(rule); } } @@ -483,8 +483,9 @@ delay_rule_match(struct lnet_delay_rule *rule, lnet_nid_t src, rule->dl_time_base = now; rule->dl_delay_time = rule->dl_time_base + - cfs_time_seconds(cfs_rand() % - attr->u.delay.la_interval); + cfs_time_seconds( + prandom_u32_max( + attr->u.delay.la_interval)); rule->dl_time_base += cfs_time_seconds(attr->u.delay.la_interval); CDEBUG(D_NET, "Delay Rule %s->%s: next delay : %lu\n", @@ -498,7 +499,7 @@ delay_rule_match(struct lnet_delay_rule *rule, lnet_nid_t src, /* generate the next random rate sequence */ if (!do_div(rule->dl_stat.fs_count, attr->u.delay.la_rate)) { rule->dl_delay_at = rule->dl_stat.fs_count + - cfs_rand() % attr->u.delay.la_rate; + prandom_u32_max(attr->u.delay.la_rate); CDEBUG(D_NET, "Delay Rule %s->%s: next delay: %lu\n", libcfs_nid2str(attr->fa_src), libcfs_nid2str(attr->fa_dst), rule->dl_delay_at); @@ -738,7 +739,7 @@ lnet_delay_rule_add(struct lnet_fault_attr *attr) if (lnet_fault_attr_validate(attr)) return -EINVAL; - CFS_ALLOC_PTR(rule); + rule = kzalloc(sizeof(*rule), GFP_NOFS); if (!rule) return -ENOMEM; @@ -771,10 +772,10 @@ lnet_delay_rule_add(struct lnet_fault_attr *attr) rule->dl_attr = *attr; if (attr->u.delay.la_interval) { rule->dl_time_base = cfs_time_shift(attr->u.delay.la_interval); - rule->dl_delay_time = cfs_time_shift(cfs_rand() % - attr->u.delay.la_interval); + rule->dl_delay_time = cfs_time_shift( + prandom_u32_max(attr->u.delay.la_interval)); } else { - rule->dl_delay_at = cfs_rand() % attr->u.delay.la_rate; + rule->dl_delay_at = prandom_u32_max(attr->u.delay.la_rate); } rule->dl_msg_send = -1; @@ -792,7 +793,7 @@ lnet_delay_rule_add(struct lnet_fault_attr *attr) return 0; failed: mutex_unlock(&delay_dd.dd_mutex); - CFS_FREE_PTR(rule); + kfree(rule); return rc; } @@ -920,10 +921,11 @@ lnet_delay_rule_reset(void) memset(&rule->dl_stat, 0, sizeof(rule->dl_stat)); if (attr->u.delay.la_rate) { - rule->dl_delay_at = cfs_rand() % attr->u.delay.la_rate; + rule->dl_delay_at = prandom_u32_max(attr->u.delay.la_rate); } else { - rule->dl_delay_time = cfs_time_shift(cfs_rand() % - attr->u.delay.la_interval); + rule->dl_delay_time = + cfs_time_shift(prandom_u32_max( + attr->u.delay.la_interval)); rule->dl_time_base = cfs_time_shift(attr->u.delay.la_interval); } spin_unlock(&rule->dl_lock); diff --git a/drivers/staging/lustre/lnet/lnet/nidstrings.c b/drivers/staging/lustre/lnet/lnet/nidstrings.c index 05b120c2d45a..3aba1421c741 100644 --- a/drivers/staging/lustre/lnet/lnet/nidstrings.c +++ b/drivers/staging/lustre/lnet/lnet/nidstrings.c @@ -166,7 +166,7 @@ parse_addrange(const struct cfs_lstr *src, struct nidrange *nidrange) return 0; } - LIBCFS_ALLOC(addrrange, sizeof(struct addrrange)); + addrrange = kzalloc(sizeof(struct addrrange), GFP_NOFS); if (!addrrange) return -ENOMEM; list_add_tail(&addrrange->ar_link, &nidrange->nr_addrranges); @@ -225,7 +225,7 @@ add_nidrange(const struct cfs_lstr *src, return nr; } - LIBCFS_ALLOC(nr, sizeof(struct nidrange)); + nr = kzalloc(sizeof(struct nidrange), GFP_NOFS); if (!nr) return NULL; list_add_tail(&nr->nr_link, nidlist); @@ -286,7 +286,7 @@ free_addrranges(struct list_head *list) cfs_expr_list_free_list(&ar->ar_numaddr_ranges); list_del(&ar->ar_link); - LIBCFS_FREE(ar, sizeof(struct addrrange)); + kfree(ar); } } @@ -308,7 +308,7 @@ cfs_free_nidlist(struct list_head *list) nr = list_entry(pos, struct nidrange, nr_link); free_addrranges(&nr->nr_addrranges); list_del(pos); - LIBCFS_FREE(nr, sizeof(struct nidrange)); + kfree(nr); } } EXPORT_SYMBOL(cfs_free_nidlist); diff --git a/drivers/staging/lustre/lnet/lnet/peer.c b/drivers/staging/lustre/lnet/lnet/peer.c index 5e94ad349454..3e157c10fec4 100644 --- a/drivers/staging/lustre/lnet/lnet/peer.c +++ b/drivers/staging/lustre/lnet/lnet/peer.c @@ -56,8 +56,8 @@ lnet_peer_tables_create(void) cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) { INIT_LIST_HEAD(&ptable->pt_deathrow); - LIBCFS_CPT_ALLOC(hash, lnet_cpt_table(), i, - LNET_PEER_HASH_SIZE * sizeof(*hash)); + hash = kvmalloc_cpt(LNET_PEER_HASH_SIZE * sizeof(*hash), + GFP_KERNEL, i); if (!hash) { CERROR("Failed to create peer hash table\n"); lnet_peer_tables_destroy(); @@ -94,7 +94,7 @@ lnet_peer_tables_destroy(void) for (j = 0; j < LNET_PEER_HASH_SIZE; j++) LASSERT(list_empty(&hash[j])); - LIBCFS_FREE(hash, LNET_PEER_HASH_SIZE * sizeof(*hash)); + kvfree(hash); } cfs_percpt_free(the_lnet.ln_peer_tables); @@ -212,7 +212,7 @@ lnet_peer_tables_cleanup(struct lnet_ni *ni) list_for_each_entry_safe(lp, temp, &deathrow, lp_hashlist) { list_del(&lp->lp_hashlist); - LIBCFS_FREE(lp, sizeof(*lp)); + kfree(lp); } } @@ -297,7 +297,7 @@ lnet_nid2peer_locked(struct lnet_peer **lpp, lnet_nid_t nid, int cpt) if (lp) memset(lp, 0, sizeof(*lp)); else - LIBCFS_CPT_ALLOC(lp, lnet_cpt_table(), cpt2, sizeof(*lp)); + lp = kzalloc_cpt(sizeof(*lp), GFP_NOFS, cpt2); if (!lp) { rc = -ENOMEM; diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c index 88283ca3f860..6504761ca598 100644 --- a/drivers/staging/lustre/lnet/lnet/router.c +++ b/drivers/staging/lustre/lnet/lnet/router.c @@ -238,28 +238,25 @@ lnet_find_net_locked(__u32 net) static void lnet_shuffle_seed(void) { static int seeded; - __u32 lnd_type, seed[2]; - struct timespec64 ts; struct lnet_ni *ni; if (seeded) return; - cfs_get_random_bytes(seed, sizeof(seed)); - /* * Nodes with small feet have little entropy * the NID for this node gives the most entropy in the low bits */ list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) { - lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid)); + __u32 lnd_type, seed; - if (lnd_type != LOLND) - seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type); + lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid)); + if (lnd_type != LOLND) { + seed = (LNET_NIDADDR(ni->ni_nid) | lnd_type); + add_device_randomness(&seed, sizeof(seed)); + } } - ktime_get_ts64(&ts); - cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); seeded = 1; } @@ -277,8 +274,8 @@ lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route) len++; } - /* len+1 positions to add a new entry, also prevents division by 0 */ - offset = cfs_rand() % (len + 1); + /* len+1 positions to add a new entry */ + offset = prandom_u32_max(len + 1); list_for_each(e, &rnet->lrn_routes) { if (!offset) break; @@ -318,15 +315,13 @@ lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway, return -EEXIST; /* Assume net, route, all new */ - LIBCFS_ALLOC(route, sizeof(*route)); - LIBCFS_ALLOC(rnet, sizeof(*rnet)); + route = kzalloc(sizeof(*route), GFP_NOFS); + rnet = kzalloc(sizeof(*rnet), GFP_NOFS); if (!route || !rnet) { CERROR("Out of memory creating route %s %d %s\n", libcfs_net2str(net), hops, libcfs_nid2str(gateway)); - if (route) - LIBCFS_FREE(route, sizeof(*route)); - if (rnet) - LIBCFS_FREE(rnet, sizeof(*rnet)); + kfree(route); + kfree(rnet); return -ENOMEM; } @@ -342,8 +337,8 @@ lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway, if (rc) { lnet_net_unlock(LNET_LOCK_EX); - LIBCFS_FREE(route, sizeof(*route)); - LIBCFS_FREE(rnet, sizeof(*rnet)); + kfree(route); + kfree(rnet); if (rc == -EHOSTUNREACH) /* gateway is not on a local net */ return rc; /* ignore the route entry */ @@ -398,11 +393,11 @@ lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway, if (!add_route) { rc = -EEXIST; - LIBCFS_FREE(route, sizeof(*route)); + kfree(route); } if (rnet != rnet2) - LIBCFS_FREE(rnet, sizeof(*rnet)); + kfree(rnet); /* indicate to startup the router checker if configured */ wake_up(&the_lnet.ln_rc_waitq); @@ -520,10 +515,8 @@ lnet_del_route(__u32 net, lnet_nid_t gw_nid) lnet_net_unlock(LNET_LOCK_EX); - LIBCFS_FREE(route, sizeof(*route)); - - if (rnet) - LIBCFS_FREE(rnet, sizeof(*rnet)); + kfree(route); + kfree(rnet); rc = 0; lnet_net_lock(LNET_LOCK_EX); @@ -891,10 +884,9 @@ lnet_destroy_rc_data(struct lnet_rc_data *rcd) lnet_net_unlock(cpt); } - if (rcd->rcd_pinginfo) - LIBCFS_FREE(rcd->rcd_pinginfo, LNET_PINGINFO_SIZE); + kfree(rcd->rcd_pinginfo); - LIBCFS_FREE(rcd, sizeof(*rcd)); + kfree(rcd); } static struct lnet_rc_data * @@ -908,14 +900,14 @@ lnet_create_rc_data_locked(struct lnet_peer *gateway) lnet_net_unlock(gateway->lp_cpt); - LIBCFS_ALLOC(rcd, sizeof(*rcd)); + rcd = kzalloc(sizeof(*rcd), GFP_NOFS); if (!rcd) goto out; LNetInvalidateMDHandle(&rcd->rcd_mdh); INIT_LIST_HEAD(&rcd->rcd_list); - LIBCFS_ALLOC(pi, LNET_PINGINFO_SIZE); + pi = kzalloc(LNET_PINGINFO_SIZE, GFP_NOFS); if (!pi) goto out; @@ -1304,12 +1296,10 @@ rescan: void lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages) { - int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]); - while (--npages >= 0) __free_page(rb->rb_kiov[npages].bv_page); - LIBCFS_FREE(rb, sz); + kfree(rb); } static struct lnet_rtrbuf * @@ -1321,7 +1311,7 @@ lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt) struct lnet_rtrbuf *rb; int i; - LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz); + rb = kzalloc_cpt(sz, GFP_NOFS, cpt); if (!rb) return NULL; @@ -1335,7 +1325,7 @@ lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt) while (--i >= 0) __free_page(rb->rb_kiov[i].bv_page); - LIBCFS_FREE(rb, sz); + kfree(rb); return NULL; } diff --git a/drivers/staging/lustre/lnet/lnet/router_proc.c b/drivers/staging/lustre/lnet/lnet/router_proc.c index d32d653edcb0..1a71ffebc889 100644 --- a/drivers/staging/lustre/lnet/lnet/router_proc.c +++ b/drivers/staging/lustre/lnet/lnet/router_proc.c @@ -91,13 +91,13 @@ static int __proc_lnet_stats(void *data, int write, /* read */ - LIBCFS_ALLOC(ctrs, sizeof(*ctrs)); + ctrs = kzalloc(sizeof(*ctrs), GFP_NOFS); if (!ctrs) return -ENOMEM; - LIBCFS_ALLOC(tmpstr, tmpsiz); + tmpstr = kmalloc(tmpsiz, GFP_KERNEL); if (!tmpstr) { - LIBCFS_FREE(ctrs, sizeof(*ctrs)); + kfree(ctrs); return -ENOMEM; } @@ -118,8 +118,8 @@ static int __proc_lnet_stats(void *data, int write, rc = cfs_trace_copyout_string(buffer, nob, tmpstr + pos, "\n"); - LIBCFS_FREE(tmpstr, tmpsiz); - LIBCFS_FREE(ctrs, sizeof(*ctrs)); + kfree(tmpstr); + kfree(ctrs); return rc; } @@ -151,7 +151,7 @@ static int proc_lnet_routes(struct ctl_table *table, int write, if (!*lenp) return 0; - LIBCFS_ALLOC(tmpstr, tmpsiz); + tmpstr = kmalloc(tmpsiz, GFP_KERNEL); if (!tmpstr) return -ENOMEM; @@ -183,7 +183,7 @@ static int proc_lnet_routes(struct ctl_table *table, int write, if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) { lnet_net_unlock(0); - LIBCFS_FREE(tmpstr, tmpsiz); + kfree(tmpstr); return -ESTALE; } @@ -248,7 +248,7 @@ static int proc_lnet_routes(struct ctl_table *table, int write, } } - LIBCFS_FREE(tmpstr, tmpsiz); + kfree(tmpstr); if (!rc) *lenp = len; @@ -275,7 +275,7 @@ static int proc_lnet_routers(struct ctl_table *table, int write, if (!*lenp) return 0; - LIBCFS_ALLOC(tmpstr, tmpsiz); + tmpstr = kmalloc(tmpsiz, GFP_KERNEL); if (!tmpstr) return -ENOMEM; @@ -303,7 +303,7 @@ static int proc_lnet_routers(struct ctl_table *table, int write, if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) { lnet_net_unlock(0); - LIBCFS_FREE(tmpstr, tmpsiz); + kfree(tmpstr); return -ESTALE; } @@ -385,7 +385,7 @@ static int proc_lnet_routers(struct ctl_table *table, int write, } } - LIBCFS_FREE(tmpstr, tmpsiz); + kfree(tmpstr); if (!rc) *lenp = len; @@ -418,7 +418,7 @@ static int proc_lnet_peers(struct ctl_table *table, int write, return 0; } - LIBCFS_ALLOC(tmpstr, tmpsiz); + tmpstr = kmalloc(tmpsiz, GFP_KERNEL); if (!tmpstr) return -ENOMEM; @@ -448,7 +448,7 @@ static int proc_lnet_peers(struct ctl_table *table, int write, if (ver != LNET_PROC_VERSION(ptable->pt_version)) { lnet_net_unlock(cpt); - LIBCFS_FREE(tmpstr, tmpsiz); + kfree(tmpstr); return -ESTALE; } @@ -556,7 +556,7 @@ static int proc_lnet_peers(struct ctl_table *table, int write, *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff); } - LIBCFS_FREE(tmpstr, tmpsiz); + kfree(tmpstr); if (!rc) *lenp = len; @@ -579,7 +579,7 @@ static int __proc_lnet_buffers(void *data, int write, /* (4 %d) * 4 * LNET_CPT_NUMBER */ tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER; - LIBCFS_ALLOC(tmpstr, tmpsiz); + tmpstr = kvmalloc(tmpsiz, GFP_KERNEL); if (!tmpstr) return -ENOMEM; @@ -618,7 +618,7 @@ static int __proc_lnet_buffers(void *data, int write, rc = cfs_trace_copyout_string(buffer, nob, tmpstr + pos, NULL); - LIBCFS_FREE(tmpstr, tmpsiz); + kvfree(tmpstr); return rc; } @@ -643,7 +643,7 @@ static int proc_lnet_nis(struct ctl_table *table, int write, if (!*lenp) return 0; - LIBCFS_ALLOC(tmpstr, tmpsiz); + tmpstr = kvmalloc(tmpsiz, GFP_KERNEL); if (!tmpstr) return -ENOMEM; @@ -744,7 +744,7 @@ static int proc_lnet_nis(struct ctl_table *table, int write, *ppos += 1; } - LIBCFS_FREE(tmpstr, tmpsiz); + kvfree(tmpstr); if (!rc) *lenp = len; @@ -795,7 +795,7 @@ static int __proc_lnet_portal_rotor(void *data, int write, int rc; int i; - LIBCFS_ALLOC(buf, buf_len); + buf = kmalloc(buf_len, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -829,7 +829,7 @@ static int __proc_lnet_portal_rotor(void *data, int write, if (rc < 0) goto out; - tmp = cfs_trimwhite(buf); + tmp = strim(buf); rc = -EINVAL; lnet_res_lock(0); @@ -843,7 +843,7 @@ static int __proc_lnet_portal_rotor(void *data, int write, } lnet_res_unlock(0); out: - LIBCFS_FREE(buf, buf_len); + kfree(buf); return rc; } diff --git a/drivers/staging/lustre/lnet/selftest/conctl.c b/drivers/staging/lustre/lnet/selftest/conctl.c index 082c0afacf23..34ba440b3c02 100644 --- a/drivers/staging/lustre/lnet/selftest/conctl.c +++ b/drivers/staging/lustre/lnet/selftest/conctl.c @@ -45,7 +45,7 @@ static int lst_session_new_ioctl(struct lstio_session_new_args *args) { - char *name; + char name[LST_NAME_SIZE + 1]; int rc; if (!args->lstio_ses_idp || /* address for output sid */ @@ -55,13 +55,8 @@ lst_session_new_ioctl(struct lstio_session_new_args *args) args->lstio_ses_nmlen > LST_NAME_SIZE) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_ses_namep, args->lstio_ses_nmlen)) { - LIBCFS_FREE(name, args->lstio_ses_nmlen + 1); return -EFAULT; } @@ -74,7 +69,6 @@ lst_session_new_ioctl(struct lstio_session_new_args *args) args->lstio_ses_force, args->lstio_ses_idp); - LIBCFS_FREE(name, args->lstio_ses_nmlen + 1); return rc; } @@ -112,7 +106,7 @@ lst_session_info_ioctl(struct lstio_session_info_args *args) static int lst_debug_ioctl(struct lstio_debug_args *args) { - char *name = NULL; + char name[LST_NAME_SIZE + 1]; int client = 1; int rc; @@ -128,16 +122,10 @@ lst_debug_ioctl(struct lstio_debug_args *args) return -EINVAL; if (args->lstio_dbg_namep) { - LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1); - if (!name) - return -ENOMEM; if (copy_from_user(name, args->lstio_dbg_namep, - args->lstio_dbg_nmlen)) { - LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1); - + args->lstio_dbg_nmlen)) return -EFAULT; - } name[args->lstio_dbg_nmlen] = 0; } @@ -154,7 +142,7 @@ lst_debug_ioctl(struct lstio_debug_args *args) client = 0; /* fall through */ case LST_OPC_BATCHCLI: - if (!name) + if (!args->lstio_dbg_namep) goto out; rc = lstcon_batch_debug(args->lstio_dbg_timeout, @@ -162,7 +150,7 @@ lst_debug_ioctl(struct lstio_debug_args *args) break; case LST_OPC_GROUP: - if (!name) + if (!args->lstio_dbg_namep) goto out; rc = lstcon_group_debug(args->lstio_dbg_timeout, @@ -185,16 +173,13 @@ lst_debug_ioctl(struct lstio_debug_args *args) } out: - if (name) - LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1); - return rc; } static int lst_group_add_ioctl(struct lstio_group_add_args *args) { - char *name; + char name[LST_NAME_SIZE + 1]; int rc; if (args->lstio_grp_key != console_session.ses_key) @@ -205,22 +190,14 @@ lst_group_add_ioctl(struct lstio_group_add_args *args) args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_grp_namep, - args->lstio_grp_nmlen)) { - LIBCFS_FREE(name, args->lstio_grp_nmlen); + args->lstio_grp_nmlen)) return -EFAULT; - } name[args->lstio_grp_nmlen] = 0; rc = lstcon_group_add(name); - LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); - return rc; } @@ -228,7 +205,7 @@ static int lst_group_del_ioctl(struct lstio_group_del_args *args) { int rc; - char *name; + char name[LST_NAME_SIZE + 1]; if (args->lstio_grp_key != console_session.ses_key) return -EACCES; @@ -238,22 +215,14 @@ lst_group_del_ioctl(struct lstio_group_del_args *args) args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_grp_namep, - args->lstio_grp_nmlen)) { - LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); + args->lstio_grp_nmlen)) return -EFAULT; - } name[args->lstio_grp_nmlen] = 0; rc = lstcon_group_del(name); - LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); - return rc; } @@ -261,7 +230,7 @@ static int lst_group_update_ioctl(struct lstio_group_update_args *args) { int rc; - char *name; + char name[LST_NAME_SIZE + 1]; if (args->lstio_grp_key != console_session.ses_key) return -EACCES; @@ -272,15 +241,9 @@ lst_group_update_ioctl(struct lstio_group_update_args *args) args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_grp_namep, - args->lstio_grp_nmlen)) { - LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); + args->lstio_grp_nmlen)) return -EFAULT; - } name[args->lstio_grp_nmlen] = 0; @@ -309,8 +272,6 @@ lst_group_update_ioctl(struct lstio_group_update_args *args) break; } - LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); - return rc; } @@ -319,7 +280,7 @@ lst_nodes_add_ioctl(struct lstio_group_nodes_args *args) { unsigned int feats; int rc; - char *name; + char name[LST_NAME_SIZE + 1]; if (args->lstio_grp_key != console_session.ses_key) return -EACCES; @@ -333,16 +294,9 @@ lst_nodes_add_ioctl(struct lstio_group_nodes_args *args) args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_grp_namep, - args->lstio_grp_nmlen)) { - LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); - + args->lstio_grp_nmlen)) return -EFAULT; - } name[args->lstio_grp_nmlen] = 0; @@ -350,7 +304,6 @@ lst_nodes_add_ioctl(struct lstio_group_nodes_args *args) args->lstio_grp_idsp, &feats, args->lstio_grp_resultp); - LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); if (!rc && copy_to_user(args->lstio_grp_featp, &feats, sizeof(feats))) { return -EINVAL; @@ -379,7 +332,7 @@ lst_group_list_ioctl(struct lstio_group_list_args *args) static int lst_group_info_ioctl(struct lstio_group_info_args *args) { - char *name; + char name[LST_NAME_SIZE + 1]; int ndent; int index; int rc; @@ -411,23 +364,15 @@ lst_group_info_ioctl(struct lstio_group_info_args *args) return -EINVAL; } - LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_grp_namep, - args->lstio_grp_nmlen)) { - LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); + args->lstio_grp_nmlen)) return -EFAULT; - } name[args->lstio_grp_nmlen] = 0; rc = lstcon_group_info(name, args->lstio_grp_entp, &index, &ndent, args->lstio_grp_dentsp); - LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); - if (rc) return rc; @@ -443,7 +388,7 @@ static int lst_batch_add_ioctl(struct lstio_batch_add_args *args) { int rc; - char *name; + char name[LST_NAME_SIZE + 1]; if (args->lstio_bat_key != console_session.ses_key) return -EACCES; @@ -453,22 +398,14 @@ lst_batch_add_ioctl(struct lstio_batch_add_args *args) args->lstio_bat_nmlen > LST_NAME_SIZE) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_bat_namep, - args->lstio_bat_nmlen)) { - LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); + args->lstio_bat_nmlen)) return -EFAULT; - } name[args->lstio_bat_nmlen] = 0; rc = lstcon_batch_add(name); - LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); - return rc; } @@ -476,7 +413,7 @@ static int lst_batch_run_ioctl(struct lstio_batch_run_args *args) { int rc; - char *name; + char name[LST_NAME_SIZE + 1]; if (args->lstio_bat_key != console_session.ses_key) return -EACCES; @@ -486,23 +423,15 @@ lst_batch_run_ioctl(struct lstio_batch_run_args *args) args->lstio_bat_nmlen > LST_NAME_SIZE) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_bat_namep, - args->lstio_bat_nmlen)) { - LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); + args->lstio_bat_nmlen)) return -EFAULT; - } name[args->lstio_bat_nmlen] = 0; rc = lstcon_batch_run(name, args->lstio_bat_timeout, args->lstio_bat_resultp); - LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); - return rc; } @@ -510,7 +439,7 @@ static int lst_batch_stop_ioctl(struct lstio_batch_stop_args *args) { int rc; - char *name; + char name[LST_NAME_SIZE + 1]; if (args->lstio_bat_key != console_session.ses_key) return -EACCES; @@ -521,30 +450,22 @@ lst_batch_stop_ioctl(struct lstio_batch_stop_args *args) args->lstio_bat_nmlen > LST_NAME_SIZE) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_bat_namep, - args->lstio_bat_nmlen)) { - LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); + args->lstio_bat_nmlen)) return -EFAULT; - } name[args->lstio_bat_nmlen] = 0; rc = lstcon_batch_stop(name, args->lstio_bat_force, args->lstio_bat_resultp); - LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); - return rc; } static int lst_batch_query_ioctl(struct lstio_batch_query_args *args) { - char *name; + char name[LST_NAME_SIZE + 1]; int rc; if (args->lstio_bat_key != console_session.ses_key) @@ -559,15 +480,9 @@ lst_batch_query_ioctl(struct lstio_batch_query_args *args) if (args->lstio_bat_testidx < 0) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_bat_namep, - args->lstio_bat_nmlen)) { - LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); + args->lstio_bat_nmlen)) return -EFAULT; - } name[args->lstio_bat_nmlen] = 0; @@ -577,8 +492,6 @@ lst_batch_query_ioctl(struct lstio_batch_query_args *args) args->lstio_bat_timeout, args->lstio_bat_resultp); - LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); - return rc; } @@ -602,7 +515,7 @@ lst_batch_list_ioctl(struct lstio_batch_list_args *args) static int lst_batch_info_ioctl(struct lstio_batch_info_args *args) { - char *name; + char name[LST_NAME_SIZE + 1]; int rc; int index; int ndent; @@ -634,15 +547,9 @@ lst_batch_info_ioctl(struct lstio_batch_info_args *args) return -EINVAL; } - LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1); - if (!name) - return -ENOMEM; - if (copy_from_user(name, args->lstio_bat_namep, - args->lstio_bat_nmlen)) { - LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); + args->lstio_bat_nmlen)) return -EFAULT; - } name[args->lstio_bat_nmlen] = 0; @@ -650,8 +557,6 @@ lst_batch_info_ioctl(struct lstio_batch_info_args *args) args->lstio_bat_server, args->lstio_bat_testidx, &index, &ndent, args->lstio_bat_dentsp); - LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); - if (rc) return rc; @@ -667,7 +572,7 @@ static int lst_stat_query_ioctl(struct lstio_stat_args *args) { int rc; - char *name = NULL; + char name[LST_NAME_SIZE + 1]; /* TODO: not finished */ if (args->lstio_sta_key != console_session.ses_key) @@ -689,10 +594,6 @@ lst_stat_query_ioctl(struct lstio_stat_args *args) args->lstio_sta_nmlen > LST_NAME_SIZE) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1); - if (!name) - return -ENOMEM; - rc = copy_from_user(name, args->lstio_sta_namep, args->lstio_sta_nmlen); if (!rc) @@ -704,16 +605,14 @@ lst_stat_query_ioctl(struct lstio_stat_args *args) rc = -EINVAL; } - if (name) - LIBCFS_FREE(name, args->lstio_sta_nmlen + 1); return rc; } static int lst_test_add_ioctl(struct lstio_test_args *args) { - char *batch_name; - char *src_name = NULL; - char *dst_name = NULL; + char batch_name[LST_NAME_SIZE + 1]; + char src_name[LST_NAME_SIZE + 1]; + char dst_name[LST_NAME_SIZE + 1]; void *param = NULL; int ret = 0; int rc = -ENOMEM; @@ -748,20 +647,8 @@ static int lst_test_add_ioctl(struct lstio_test_args *args) if (!args->lstio_tes_param && args->lstio_tes_param_len) return -EINVAL; - LIBCFS_ALLOC(batch_name, args->lstio_tes_bat_nmlen + 1); - if (!batch_name) - return rc; - - LIBCFS_ALLOC(src_name, args->lstio_tes_sgrp_nmlen + 1); - if (!src_name) - goto out; - - LIBCFS_ALLOC(dst_name, args->lstio_tes_dgrp_nmlen + 1); - if (!dst_name) - goto out; - if (args->lstio_tes_param) { - LIBCFS_ALLOC(param, args->lstio_tes_param_len); + param = kmalloc(args->lstio_tes_param_len, GFP_KERNEL); if (!param) goto out; if (copy_from_user(param, args->lstio_tes_param, @@ -791,17 +678,7 @@ static int lst_test_add_ioctl(struct lstio_test_args *args) rc = (copy_to_user(args->lstio_tes_retp, &ret, sizeof(ret))) ? -EFAULT : 0; out: - if (batch_name) - LIBCFS_FREE(batch_name, args->lstio_tes_bat_nmlen + 1); - - if (src_name) - LIBCFS_FREE(src_name, args->lstio_tes_sgrp_nmlen + 1); - - if (dst_name) - LIBCFS_FREE(dst_name, args->lstio_tes_dgrp_nmlen + 1); - - if (param) - LIBCFS_FREE(param, args->lstio_tes_param_len); + kfree(param); return rc; } @@ -824,13 +701,13 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr) if (data->ioc_plen1 > PAGE_SIZE) return -EINVAL; - LIBCFS_ALLOC(buf, data->ioc_plen1); + buf = kmalloc(data->ioc_plen1, GFP_KERNEL); if (!buf) return -ENOMEM; /* copy in parameter */ if (copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) { - LIBCFS_FREE(buf, data->ioc_plen1); + kfree(buf); return -EFAULT; } @@ -920,7 +797,7 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr) out: mutex_unlock(&console_session.ses_mutex); - LIBCFS_FREE(buf, data->ioc_plen1); + kfree(buf); return rc; } diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c index 6a0f770e0e24..7aa515c34594 100644 --- a/drivers/staging/lustre/lnet/selftest/conrpc.c +++ b/drivers/staging/lustre/lnet/selftest/conrpc.c @@ -129,7 +129,7 @@ lstcon_rpc_prep(struct lstcon_node *nd, int service, unsigned int feats, spin_unlock(&console_session.ses_rpc_lock); if (!crpc) { - LIBCFS_ALLOC(crpc, sizeof(*crpc)); + crpc = kzalloc(sizeof(*crpc), GFP_NOFS); if (!crpc) return -ENOMEM; } @@ -140,7 +140,7 @@ lstcon_rpc_prep(struct lstcon_node *nd, int service, unsigned int feats, return 0; } - LIBCFS_FREE(crpc, sizeof(*crpc)); + kfree(crpc); return rc; } @@ -250,7 +250,7 @@ lstcon_rpc_trans_prep(struct list_head *translist, int transop, } /* create a trans group */ - LIBCFS_ALLOC(trans, sizeof(*trans)); + trans = kzalloc(sizeof(*trans), GFP_NOFS); if (!trans) return -ENOMEM; @@ -585,7 +585,7 @@ lstcon_rpc_trans_destroy(struct lstcon_rpc_trans *trans) CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n", lstcon_rpc_trans_name(trans->tas_opc), count); - LIBCFS_FREE(trans, sizeof(*trans)); + kfree(trans); } int @@ -1369,7 +1369,7 @@ lstcon_rpc_cleanup_wait(void) list_for_each_entry_safe(crpc, temp, &zlist, crp_link) { list_del(&crpc->crp_link); - LIBCFS_FREE(crpc, sizeof(struct lstcon_rpc)); + kfree(crpc); } } diff --git a/drivers/staging/lustre/lnet/selftest/console.c b/drivers/staging/lustre/lnet/selftest/console.c index a2662638d599..1acd5cb324b1 100644 --- a/drivers/staging/lustre/lnet/selftest/console.c +++ b/drivers/staging/lustre/lnet/selftest/console.c @@ -88,7 +88,7 @@ lstcon_node_find(struct lnet_process_id id, struct lstcon_node **ndpp, if (!create) return -ENOENT; - LIBCFS_ALLOC(*ndpp, sizeof(**ndpp) + sizeof(*ndl)); + *ndpp = kzalloc(sizeof(**ndpp) + sizeof(*ndl), GFP_KERNEL); if (!*ndpp) return -ENOMEM; @@ -133,7 +133,7 @@ lstcon_node_put(struct lstcon_node *nd) list_del(&ndl->ndl_link); list_del(&ndl->ndl_hlink); - LIBCFS_FREE(nd, sizeof(*nd) + sizeof(*ndl)); + kfree(nd); } static int @@ -166,7 +166,7 @@ lstcon_ndlink_find(struct list_head *hash, struct lnet_process_id id, if (rc) return rc; - LIBCFS_ALLOC(ndl, sizeof(struct lstcon_ndlink)); + ndl = kzalloc(sizeof(struct lstcon_ndlink), GFP_NOFS); if (!ndl) { lstcon_node_put(nd); return -ENOMEM; @@ -190,7 +190,7 @@ lstcon_ndlink_release(struct lstcon_ndlink *ndl) list_del(&ndl->ndl_hlink); /* delete from hash */ lstcon_node_put(ndl->ndl_node); - LIBCFS_FREE(ndl, sizeof(*ndl)); + kfree(ndl); } static int @@ -199,16 +199,16 @@ lstcon_group_alloc(char *name, struct lstcon_group **grpp) struct lstcon_group *grp; int i; - LIBCFS_ALLOC(grp, offsetof(struct lstcon_group, - grp_ndl_hash[LST_NODE_HASHSIZE])); + grp = kmalloc(offsetof(struct lstcon_group, + grp_ndl_hash[LST_NODE_HASHSIZE]), + GFP_KERNEL); if (!grp) return -ENOMEM; grp->grp_ref = 1; if (name) { if (strlen(name) > sizeof(grp->grp_name) - 1) { - LIBCFS_FREE(grp, offsetof(struct lstcon_group, - grp_ndl_hash[LST_NODE_HASHSIZE])); + kfree(grp); return -E2BIG; } strncpy(grp->grp_name, name, sizeof(grp->grp_name)); @@ -263,8 +263,7 @@ lstcon_group_decref(struct lstcon_group *grp) for (i = 0; i < LST_NODE_HASHSIZE; i++) LASSERT(list_empty(&grp->grp_ndl_hash[i])); - LIBCFS_FREE(grp, offsetof(struct lstcon_group, - grp_ndl_hash[LST_NODE_HASHSIZE])); + kfree(grp); } static int @@ -807,7 +806,7 @@ lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gents_p, } /* non-verbose query */ - LIBCFS_ALLOC(gentp, sizeof(struct lstcon_ndlist_ent)); + gentp = kzalloc(sizeof(struct lstcon_ndlist_ent), GFP_NOFS); if (!gentp) { CERROR("Can't allocate ndlist_ent\n"); lstcon_group_decref(grp); @@ -821,7 +820,7 @@ lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gents_p, rc = copy_to_user(gents_p, gentp, sizeof(struct lstcon_ndlist_ent)) ? -EFAULT : 0; - LIBCFS_FREE(gentp, sizeof(struct lstcon_ndlist_ent)); + kfree(gentp); lstcon_group_decref(grp); @@ -856,35 +855,35 @@ lstcon_batch_add(char *name) return rc; } - LIBCFS_ALLOC(bat, sizeof(struct lstcon_batch)); + bat = kzalloc(sizeof(struct lstcon_batch), GFP_NOFS); if (!bat) { CERROR("Can't allocate descriptor for batch %s\n", name); return -ENOMEM; } - LIBCFS_ALLOC(bat->bat_cli_hash, - sizeof(struct list_head) * LST_NODE_HASHSIZE); + bat->bat_cli_hash = kmalloc(sizeof(struct list_head) * LST_NODE_HASHSIZE, + GFP_KERNEL); if (!bat->bat_cli_hash) { CERROR("Can't allocate hash for batch %s\n", name); - LIBCFS_FREE(bat, sizeof(struct lstcon_batch)); + kfree(bat); return -ENOMEM; } - LIBCFS_ALLOC(bat->bat_srv_hash, - sizeof(struct list_head) * LST_NODE_HASHSIZE); + bat->bat_srv_hash = kmalloc(sizeof(struct list_head) * LST_NODE_HASHSIZE, + GFP_KERNEL); if (!bat->bat_srv_hash) { CERROR("Can't allocate hash for batch %s\n", name); - LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE); - LIBCFS_FREE(bat, sizeof(struct lstcon_batch)); + kfree(bat->bat_cli_hash); + kfree(bat); return -ENOMEM; } if (strlen(name) > sizeof(bat->bat_name) - 1) { - LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE); - LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE); - LIBCFS_FREE(bat, sizeof(struct lstcon_batch)); + kfree(bat->bat_srv_hash); + kfree(bat->bat_cli_hash); + kfree(bat); return -E2BIG; } strncpy(bat->bat_name, name, sizeof(bat->bat_name)); @@ -971,7 +970,7 @@ lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up, } /* non-verbose query */ - LIBCFS_ALLOC(entp, sizeof(struct lstcon_test_batch_ent)); + entp = kzalloc(sizeof(struct lstcon_test_batch_ent), GFP_NOFS); if (!entp) return -ENOMEM; @@ -993,7 +992,7 @@ lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up, rc = copy_to_user(ent_up, entp, sizeof(struct lstcon_test_batch_ent)) ? -EFAULT : 0; - LIBCFS_FREE(entp, sizeof(struct lstcon_test_batch_ent)); + kfree(entp); return rc; } @@ -1107,8 +1106,7 @@ lstcon_batch_destroy(struct lstcon_batch *bat) lstcon_group_decref(test->tes_src_grp); lstcon_group_decref(test->tes_dst_grp); - LIBCFS_FREE(test, offsetof(struct lstcon_test, - tes_param[test->tes_paramlen])); + kfree(test); } LASSERT(list_empty(&bat->bat_trans_list)); @@ -1134,11 +1132,9 @@ lstcon_batch_destroy(struct lstcon_batch *bat) LASSERT(list_empty(&bat->bat_srv_hash[i])); } - LIBCFS_FREE(bat->bat_cli_hash, - sizeof(struct list_head) * LST_NODE_HASHSIZE); - LIBCFS_FREE(bat->bat_srv_hash, - sizeof(struct list_head) * LST_NODE_HASHSIZE); - LIBCFS_FREE(bat, sizeof(struct lstcon_batch)); + kfree(bat->bat_cli_hash); + kfree(bat->bat_srv_hash); + kfree(bat); } static int @@ -1311,7 +1307,8 @@ lstcon_test_add(char *batch_name, int type, int loop, if (dst_grp->grp_userland) *retp = 1; - LIBCFS_ALLOC(test, offsetof(struct lstcon_test, tes_param[paramlen])); + test = kzalloc(offsetof(struct lstcon_test, tes_param[paramlen]), + GFP_KERNEL); if (!test) { CERROR("Can't allocate test descriptor\n"); rc = -ENOMEM; @@ -1357,8 +1354,7 @@ lstcon_test_add(char *batch_name, int type, int loop, /* hold groups so nobody can change them */ return rc; out: - if (test) - LIBCFS_FREE(test, offsetof(struct lstcon_test, tes_param[paramlen])); + kfree(test); if (dst_grp) lstcon_group_decref(dst_grp); @@ -1790,7 +1786,7 @@ lstcon_session_info(struct lst_sid __user *sid_up, int __user *key_up, if (console_session.ses_state != LST_SESSION_ACTIVE) return -ESRCH; - LIBCFS_ALLOC(entp, sizeof(*entp)); + entp = kzalloc(sizeof(*entp), GFP_NOFS); if (!entp) return -ENOMEM; @@ -1807,7 +1803,7 @@ lstcon_session_info(struct lst_sid __user *sid_up, int __user *key_up, copy_to_user(name_up, console_session.ses_name, len)) rc = -EFAULT; - LIBCFS_FREE(entp, sizeof(*entp)); + kfree(entp); return rc; } @@ -2027,8 +2023,8 @@ lstcon_console_init(void) INIT_LIST_HEAD(&console_session.ses_bat_list); INIT_LIST_HEAD(&console_session.ses_trans_list); - LIBCFS_ALLOC(console_session.ses_ndl_hash, - sizeof(struct list_head) * LST_GLOBAL_HASHSIZE); + console_session.ses_ndl_hash = + kmalloc(sizeof(struct list_head) * LST_GLOBAL_HASHSIZE, GFP_KERNEL); if (!console_session.ses_ndl_hash) return -ENOMEM; @@ -2041,8 +2037,7 @@ lstcon_console_init(void) rc = srpc_add_service(&lstcon_acceptor_service); LASSERT(rc != -EBUSY); if (rc) { - LIBCFS_FREE(console_session.ses_ndl_hash, - sizeof(struct list_head) * LST_GLOBAL_HASHSIZE); + kfree(console_session.ses_ndl_hash); return rc; } @@ -2064,8 +2059,7 @@ out: srpc_shutdown_service(&lstcon_acceptor_service); srpc_remove_service(&lstcon_acceptor_service); - LIBCFS_FREE(console_session.ses_ndl_hash, - sizeof(struct list_head) * LST_GLOBAL_HASHSIZE); + kfree(console_session.ses_ndl_hash); srpc_wait_service_shutdown(&lstcon_acceptor_service); @@ -2099,8 +2093,7 @@ lstcon_console_fini(void) for (i = 0; i < LST_NODE_HASHSIZE; i++) LASSERT(list_empty(&console_session.ses_ndl_hash[i])); - LIBCFS_FREE(console_session.ses_ndl_hash, - sizeof(struct list_head) * LST_GLOBAL_HASHSIZE); + kfree(console_session.ses_ndl_hash); srpc_wait_service_shutdown(&lstcon_acceptor_service); diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c index fe889607ff3f..c7697f66f663 100644 --- a/drivers/staging/lustre/lnet/selftest/framework.c +++ b/drivers/staging/lustre/lnet/selftest/framework.c @@ -143,7 +143,7 @@ sfw_register_test(struct srpc_service *service, return -EEXIST; } - LIBCFS_ALLOC(tsc, sizeof(struct sfw_test_case)); + tsc = kzalloc(sizeof(struct sfw_test_case), GFP_NOFS); if (!tsc) return -ENOMEM; @@ -344,7 +344,7 @@ sfw_bid2batch(struct lst_bid bid) if (bat) return bat; - LIBCFS_ALLOC(bat, sizeof(struct sfw_batch)); + bat = kzalloc(sizeof(struct sfw_batch), GFP_NOFS); if (!bat) return NULL; @@ -447,7 +447,7 @@ sfw_make_session(struct srpc_mksn_reqst *request, struct srpc_mksn_reply *reply) } /* brand new or create by force */ - LIBCFS_ALLOC(sn, sizeof(struct sfw_session)); + sn = kzalloc(sizeof(struct sfw_session), GFP_NOFS); if (!sn) { CERROR("dropping RPC mksn under memory pressure\n"); return -ENOMEM; @@ -632,19 +632,19 @@ sfw_destroy_test_instance(struct sfw_test_instance *tsi) tsu = list_entry(tsi->tsi_units.next, struct sfw_test_unit, tsu_list); list_del(&tsu->tsu_list); - LIBCFS_FREE(tsu, sizeof(*tsu)); + kfree(tsu); } while (!list_empty(&tsi->tsi_free_rpcs)) { rpc = list_entry(tsi->tsi_free_rpcs.next, struct srpc_client_rpc, crpc_list); list_del(&rpc->crpc_list); - LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc)); + kfree(rpc); } clean: sfw_unload_test(tsi); - LIBCFS_FREE(tsi, sizeof(*tsi)); + kfree(tsi); } static void @@ -662,7 +662,7 @@ sfw_destroy_batch(struct sfw_batch *tsb) sfw_destroy_test_instance(tsi); } - LIBCFS_FREE(tsb, sizeof(struct sfw_batch)); + kfree(tsb); } void @@ -680,7 +680,7 @@ sfw_destroy_session(struct sfw_session *sn) sfw_destroy_batch(batch); } - LIBCFS_FREE(sn, sizeof(*sn)); + kfree(sn); atomic_dec(&sfw_data.fw_nzombies); } @@ -740,7 +740,7 @@ sfw_add_test_instance(struct sfw_batch *tsb, struct srpc_server_rpc *rpc) int i; int rc; - LIBCFS_ALLOC(tsi, sizeof(*tsi)); + tsi = kzalloc(sizeof(*tsi), GFP_NOFS); if (!tsi) { CERROR("Can't allocate test instance for batch: %llu\n", tsb->bat_id.bat_id); @@ -763,7 +763,7 @@ sfw_add_test_instance(struct sfw_batch *tsb, struct srpc_server_rpc *rpc) rc = sfw_load_test(tsi); if (rc) { - LIBCFS_FREE(tsi, sizeof(*tsi)); + kfree(tsi); return rc; } @@ -795,7 +795,7 @@ sfw_add_test_instance(struct sfw_batch *tsb, struct srpc_server_rpc *rpc) sfw_unpack_id(id); for (j = 0; j < tsi->tsi_concur; j++) { - LIBCFS_ALLOC(tsu, sizeof(struct sfw_test_unit)); + tsu = kzalloc(sizeof(struct sfw_test_unit), GFP_NOFS); if (!tsu) { rc = -ENOMEM; CERROR("Can't allocate tsu for %d\n", @@ -941,15 +941,13 @@ sfw_create_test_rpc(struct sfw_test_unit *tsu, struct lnet_process_id peer, return 0; } -static int +static void sfw_run_test(struct swi_workitem *wi) { - struct sfw_test_unit *tsu = wi->swi_workitem.wi_data; + struct sfw_test_unit *tsu = container_of(wi, struct sfw_test_unit, tsu_worker); struct sfw_test_instance *tsi = tsu->tsu_instance; struct srpc_client_rpc *rpc = NULL; - LASSERT(wi == &tsu->tsu_worker); - if (tsi->tsi_ops->tso_prep_rpc(tsu, tsu->tsu_dest, &rpc)) { LASSERT(!rpc); goto test_done; @@ -975,7 +973,7 @@ sfw_run_test(struct swi_workitem *wi) rpc->crpc_timeout = rpc_timeout; srpc_post_rpc(rpc); spin_unlock(&rpc->crpc_lock); - return 0; + return; test_done: /* @@ -985,9 +983,7 @@ test_done: * - my batch is still active; no one can run it again now. * Cancel pending schedules and prevent future schedule attempts: */ - swi_exit_workitem(wi); sfw_test_unit_done(tsu); - return 1; } static int @@ -1016,8 +1012,8 @@ sfw_run_batch(struct sfw_batch *tsb) atomic_inc(&tsi->tsi_nactive); tsu->tsu_loop = tsi->tsi_loop; wi = &tsu->tsu_worker; - swi_init_workitem(wi, tsu, sfw_run_test, - lst_sched_test[lnet_cpt_of_nid(tsu->tsu_dest.nid)]); + swi_init_workitem(wi, sfw_run_test, + lst_test_wq[lnet_cpt_of_nid(tsu->tsu_dest.nid)]); swi_schedule_workitem(wi); } } @@ -1767,7 +1763,7 @@ sfw_shutdown(void) struct srpc_client_rpc, crpc_list); list_del(&rpc->crpc_list); - LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc)); + kfree(rpc); } for (i = 0; ; i++) { @@ -1785,6 +1781,6 @@ sfw_shutdown(void) srpc_wait_service_shutdown(tsc->tsc_srv_service); list_del(&tsc->tsc_list); - LIBCFS_FREE(tsc, sizeof(*tsc)); + kfree(tsc); } } diff --git a/drivers/staging/lustre/lnet/selftest/module.c b/drivers/staging/lustre/lnet/selftest/module.c index 1d44d912f014..7359aa56d9b3 100644 --- a/drivers/staging/lustre/lnet/selftest/module.c +++ b/drivers/staging/lustre/lnet/selftest/module.c @@ -47,8 +47,8 @@ enum { static int lst_init_step = LST_INIT_NONE; -struct cfs_wi_sched *lst_sched_serial; -struct cfs_wi_sched **lst_sched_test; +struct workqueue_struct *lst_serial_wq; +struct workqueue_struct **lst_test_wq; static void lnet_selftest_exit(void) @@ -68,18 +68,16 @@ lnet_selftest_exit(void) case LST_INIT_WI_TEST: for (i = 0; i < cfs_cpt_number(lnet_cpt_table()); i++) { - if (!lst_sched_test[i]) + if (!lst_test_wq[i]) continue; - cfs_wi_sched_destroy(lst_sched_test[i]); + destroy_workqueue(lst_test_wq[i]); } - LIBCFS_FREE(lst_sched_test, - sizeof(lst_sched_test[0]) * - cfs_cpt_number(lnet_cpt_table())); - lst_sched_test = NULL; + kvfree(lst_test_wq); + lst_test_wq = NULL; /* fall through */ case LST_INIT_WI_SERIAL: - cfs_wi_sched_destroy(lst_sched_serial); - lst_sched_serial = NULL; + destroy_workqueue(lst_serial_wq); + lst_serial_wq = NULL; case LST_INIT_NONE: break; default: @@ -91,35 +89,45 @@ static int lnet_selftest_init(void) { int nscheds; - int rc; + int rc = -ENOMEM; int i; - rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY, - 1, &lst_sched_serial); - if (rc) { + lst_serial_wq = alloc_ordered_workqueue("lst_s", 0); + if (!lst_serial_wq) { CERROR("Failed to create serial WI scheduler for LST\n"); - return rc; + return -ENOMEM; } lst_init_step = LST_INIT_WI_SERIAL; nscheds = cfs_cpt_number(lnet_cpt_table()); - LIBCFS_ALLOC(lst_sched_test, sizeof(lst_sched_test[0]) * nscheds); - if (!lst_sched_test) + lst_test_wq = kvmalloc_array(nscheds, sizeof(lst_test_wq[0]), + GFP_KERNEL | __GFP_ZERO); + if (!lst_test_wq) { + rc = -ENOMEM; goto error; + } lst_init_step = LST_INIT_WI_TEST; for (i = 0; i < nscheds; i++) { int nthrs = cfs_cpt_weight(lnet_cpt_table(), i); + struct workqueue_attrs attrs = {0}; + cpumask_var_t *mask = cfs_cpt_cpumask(lnet_cpt_table(), i); /* reserve at least one CPU for LND */ nthrs = max(nthrs - 1, 1); - rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i, - nthrs, &lst_sched_test[i]); - if (rc) { + lst_test_wq[i] = alloc_workqueue("lst_t", WQ_UNBOUND, nthrs); + if (!lst_test_wq[i]) { CWARN("Failed to create CPU partition affinity WI scheduler %d for LST\n", i); + rc = -ENOMEM; goto error; } + + if (mask && alloc_cpumask_var(&attrs.cpumask, GFP_KERNEL)) { + cpumask_copy(attrs.cpumask, *mask); + apply_workqueue_attrs(lst_test_wq[i], &attrs); + free_cpumask_var(attrs.cpumask); + } } rc = srpc_startup(); diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c index ab7e8a8e58b8..f8198ad1046e 100644 --- a/drivers/staging/lustre/lnet/selftest/rpc.c +++ b/drivers/staging/lustre/lnet/selftest/rpc.c @@ -68,7 +68,7 @@ srpc_serv_portal(int svc_id) } /* forward ref's */ -int srpc_handle_rpc(struct swi_workitem *wi); +void srpc_handle_rpc(struct swi_workitem *wi); void srpc_get_counters(struct srpc_counters *cnt) { @@ -113,7 +113,7 @@ srpc_free_bulk(struct srpc_bulk *bk) __free_page(pg); } - LIBCFS_FREE(bk, offsetof(struct srpc_bulk, bk_iovs[bk->bk_niov])); + kfree(bk); } struct srpc_bulk * @@ -125,8 +125,8 @@ srpc_alloc_bulk(int cpt, unsigned int bulk_off, unsigned int bulk_npg, LASSERT(bulk_npg > 0 && bulk_npg <= LNET_MAX_IOV); - LIBCFS_CPT_ALLOC(bk, lnet_cpt_table(), cpt, - offsetof(struct srpc_bulk, bk_iovs[bulk_npg])); + bk = kzalloc_cpt(offsetof(struct srpc_bulk, bk_iovs[bulk_npg]), + GFP_KERNEL, cpt); if (!bk) { CERROR("Can't allocate descriptor for %d pages\n", bulk_npg); return NULL; @@ -176,9 +176,9 @@ srpc_init_server_rpc(struct srpc_server_rpc *rpc, struct srpc_buffer *buffer) { memset(rpc, 0, sizeof(*rpc)); - swi_init_workitem(&rpc->srpc_wi, rpc, srpc_handle_rpc, + swi_init_workitem(&rpc->srpc_wi, srpc_handle_rpc, srpc_serv_is_framework(scd->scd_svc) ? - lst_sched_serial : lst_sched_test[scd->scd_cpt]); + lst_serial_wq : lst_test_wq[scd->scd_cpt]); rpc->srpc_ev.ev_fired = 1; /* no event expected now */ @@ -214,7 +214,7 @@ srpc_service_fini(struct srpc_service *svc) buf = list_entry(q->next, struct srpc_buffer, buf_list); list_del(&buf->buf_list); - LIBCFS_FREE(buf, sizeof(*buf)); + kfree(buf); } } @@ -225,7 +225,7 @@ srpc_service_fini(struct srpc_service *svc) struct srpc_server_rpc, srpc_list); list_del(&rpc->srpc_list); - LIBCFS_FREE(rpc, sizeof(*rpc)); + kfree(rpc); } } @@ -242,7 +242,7 @@ srpc_service_nrpcs(struct srpc_service *svc) max(nrpcs, SFW_FRWK_WI_MIN) : max(nrpcs, SFW_TEST_WI_MIN); } -int srpc_add_buffer(struct swi_workitem *wi); +void srpc_add_buffer(struct swi_workitem *wi); static int srpc_service_init(struct srpc_service *svc) @@ -277,11 +277,11 @@ srpc_service_init(struct srpc_service *svc) scd->scd_ev.ev_type = SRPC_REQUEST_RCVD; /* - * NB: don't use lst_sched_serial for adding buffer, + * NB: don't use lst_serial_wq for adding buffer, * see details in srpc_service_add_buffers() */ - swi_init_workitem(&scd->scd_buf_wi, scd, - srpc_add_buffer, lst_sched_test[i]); + swi_init_workitem(&scd->scd_buf_wi, + srpc_add_buffer, lst_test_wq[i]); if (i && srpc_serv_is_framework(svc)) { /* @@ -294,8 +294,7 @@ srpc_service_init(struct srpc_service *svc) } for (j = 0; j < nrpcs; j++) { - LIBCFS_CPT_ALLOC(rpc, lnet_cpt_table(), - i, sizeof(*rpc)); + rpc = kzalloc_cpt(sizeof(*rpc), GFP_NOFS, i); if (!rpc) { srpc_service_fini(svc); return -ENOMEM; @@ -508,16 +507,16 @@ __must_hold(&scd->scd_lock) list_del(&buf->buf_list); spin_unlock(&scd->scd_lock); - LIBCFS_FREE(buf, sizeof(*buf)); + kfree(buf); spin_lock(&scd->scd_lock); return rc; } -int +void srpc_add_buffer(struct swi_workitem *wi) { - struct srpc_service_cd *scd = wi->swi_workitem.wi_data; + struct srpc_service_cd *scd = container_of(wi, struct srpc_service_cd, scd_buf_wi); struct srpc_buffer *buf; int rc = 0; @@ -535,7 +534,7 @@ srpc_add_buffer(struct swi_workitem *wi) spin_unlock(&scd->scd_lock); - LIBCFS_ALLOC(buf, sizeof(*buf)); + buf = kzalloc(sizeof(*buf), GFP_NOFS); if (!buf) { CERROR("Failed to add new buf to service: %s\n", scd->scd_svc->sv_name); @@ -547,7 +546,7 @@ srpc_add_buffer(struct swi_workitem *wi) spin_lock(&scd->scd_lock); if (scd->scd_svc->sv_shuttingdown) { spin_unlock(&scd->scd_lock); - LIBCFS_FREE(buf, sizeof(*buf)); + kfree(buf); spin_lock(&scd->scd_lock); rc = -ESHUTDOWN; @@ -573,7 +572,6 @@ srpc_add_buffer(struct swi_workitem *wi) } spin_unlock(&scd->scd_lock); - return 0; } int @@ -605,15 +603,15 @@ srpc_service_add_buffers(struct srpc_service *sv, int nbuffer) spin_lock(&scd->scd_lock); /* * NB: srpc_service_add_buffers() can be called inside - * thread context of lst_sched_serial, and we don't normally + * thread context of lst_serial_wq, and we don't normally * allow to sleep inside thread context of WI scheduler * because it will block current scheduler thread from doing * anything else, even worse, it could deadlock if it's * waiting on result from another WI of the same scheduler. * However, it's safe at here because scd_buf_wi is scheduled - * by thread in a different WI scheduler (lst_sched_test), + * by thread in a different WI scheduler (lst_test_wq), * so we don't have any risk of deadlock, though this could - * block all WIs pending on lst_sched_serial for a moment + * block all WIs pending on lst_serial_wq for a moment * which is not good but not fatal. */ lst_wait_until(scd->scd_buf_err || @@ -660,11 +658,9 @@ srpc_finish_service(struct srpc_service *sv) LASSERT(sv->sv_shuttingdown); /* srpc_shutdown_service called */ cfs_percpt_for_each(scd, i, sv->sv_cpt_data) { + swi_cancel_workitem(&scd->scd_buf_wi); + spin_lock(&scd->scd_lock); - if (!swi_deschedule_workitem(&scd->scd_buf_wi)) { - spin_unlock(&scd->scd_lock); - return 0; - } if (scd->scd_buf_nposted > 0) { CDEBUG(D_NET, "waiting for %d posted buffers to unlink\n", @@ -680,11 +676,9 @@ srpc_finish_service(struct srpc_service *sv) rpc = list_entry(scd->scd_rpc_active.next, struct srpc_server_rpc, srpc_list); - CNETERR("Active RPC %p on shutdown: sv %s, peer %s, wi %s scheduled %d running %d, ev fired %d type %d status %d lnet %d\n", + CNETERR("Active RPC %p on shutdown: sv %s, peer %s, wi %s, ev fired %d type %d status %d lnet %d\n", rpc, sv->sv_name, libcfs_id2str(rpc->srpc_peer), swi_state2str(rpc->srpc_wi.swi_state), - rpc->srpc_wi.swi_workitem.wi_scheduled, - rpc->srpc_wi.swi_workitem.wi_running, rpc->srpc_ev.ev_fired, rpc->srpc_ev.ev_type, rpc->srpc_ev.ev_status, rpc->srpc_ev.ev_lnet); spin_unlock(&scd->scd_lock); @@ -725,7 +719,7 @@ __must_hold(&scd->scd_lock) } spin_unlock(&scd->scd_lock); - LIBCFS_FREE(buf, sizeof(*buf)); + kfree(buf); spin_lock(&scd->scd_lock); } @@ -947,7 +941,6 @@ srpc_server_rpc_done(struct srpc_server_rpc *rpc, int status) * Cancel pending schedules and prevent future schedule attempts: */ LASSERT(rpc->srpc_ev.ev_fired); - swi_exit_workitem(&rpc->srpc_wi); if (!sv->sv_shuttingdown && !list_empty(&scd->scd_buf_blocked)) { buffer = list_entry(scd->scd_buf_blocked.next, @@ -965,10 +958,10 @@ srpc_server_rpc_done(struct srpc_server_rpc *rpc, int status) } /* handles an incoming RPC */ -int +void srpc_handle_rpc(struct swi_workitem *wi) { - struct srpc_server_rpc *rpc = wi->swi_workitem.wi_data; + struct srpc_server_rpc *rpc = container_of(wi, struct srpc_server_rpc, srpc_wi); struct srpc_service_cd *scd = rpc->srpc_scd; struct srpc_service *sv = scd->scd_svc; struct srpc_event *ev = &rpc->srpc_ev; @@ -987,9 +980,8 @@ srpc_handle_rpc(struct swi_workitem *wi) if (ev->ev_fired) { /* no more event, OK to finish */ srpc_server_rpc_done(rpc, -ESHUTDOWN); - return 1; } - return 0; + return; } spin_unlock(&scd->scd_lock); @@ -1007,7 +999,7 @@ srpc_handle_rpc(struct swi_workitem *wi) if (!msg->msg_magic) { /* moaned already in srpc_lnet_ev_handler */ srpc_server_rpc_done(rpc, EBADMSG); - return 1; + return; } srpc_unpack_msg_hdr(msg); @@ -1023,7 +1015,7 @@ srpc_handle_rpc(struct swi_workitem *wi) LASSERT(!reply->status || !rpc->srpc_bulk); if (rc) { srpc_server_rpc_done(rpc, rc); - return 1; + return; } } @@ -1032,7 +1024,7 @@ srpc_handle_rpc(struct swi_workitem *wi) if (rpc->srpc_bulk) { rc = srpc_do_bulk(rpc); if (!rc) - return 0; /* wait for bulk */ + return; /* wait for bulk */ LASSERT(ev->ev_fired); ev->ev_status = rc; @@ -1050,16 +1042,16 @@ srpc_handle_rpc(struct swi_workitem *wi) if (rc) { srpc_server_rpc_done(rpc, rc); - return 1; + return; } } wi->swi_state = SWI_STATE_REPLY_SUBMITTED; rc = srpc_send_reply(rpc); if (!rc) - return 0; /* wait for reply */ + return; /* wait for reply */ srpc_server_rpc_done(rpc, rc); - return 1; + return; case SWI_STATE_REPLY_SUBMITTED: if (!ev->ev_fired) { @@ -1072,10 +1064,8 @@ srpc_handle_rpc(struct swi_workitem *wi) wi->swi_state = SWI_STATE_DONE; srpc_server_rpc_done(rpc, ev->ev_status); - return 1; + return; } - - return 0; } static void @@ -1170,7 +1160,6 @@ srpc_client_rpc_done(struct srpc_client_rpc *rpc, int status) * Cancel pending schedules and prevent future schedule attempts: */ LASSERT(!srpc_event_pending(rpc)); - swi_exit_workitem(wi); spin_unlock(&rpc->crpc_lock); @@ -1178,7 +1167,7 @@ srpc_client_rpc_done(struct srpc_client_rpc *rpc, int status) } /* sends an outgoing RPC */ -int +void srpc_send_rpc(struct swi_workitem *wi) { int rc = 0; @@ -1188,7 +1177,7 @@ srpc_send_rpc(struct swi_workitem *wi) LASSERT(wi); - rpc = wi->swi_workitem.wi_data; + rpc = container_of(wi, struct srpc_client_rpc, crpc_wi); LASSERT(rpc); LASSERT(wi == &rpc->crpc_wi); @@ -1214,7 +1203,7 @@ srpc_send_rpc(struct swi_workitem *wi) rc = srpc_prepare_reply(rpc); if (rc) { srpc_client_rpc_done(rpc, rc); - return 1; + return; } rc = srpc_prepare_bulk(rpc); @@ -1291,7 +1280,7 @@ srpc_send_rpc(struct swi_workitem *wi) wi->swi_state = SWI_STATE_DONE; srpc_client_rpc_done(rpc, rc); - return 1; + return; } if (rc) { @@ -1308,10 +1297,9 @@ abort: if (!srpc_event_pending(rpc)) { srpc_client_rpc_done(rpc, -EINTR); - return 1; + return; } } - return 0; } struct srpc_client_rpc * @@ -1322,8 +1310,8 @@ srpc_create_client_rpc(struct lnet_process_id peer, int service, { struct srpc_client_rpc *rpc; - LIBCFS_ALLOC(rpc, offsetof(struct srpc_client_rpc, - crpc_bulk.bk_iovs[nbulkiov])); + rpc = kzalloc(offsetof(struct srpc_client_rpc, + crpc_bulk.bk_iovs[nbulkiov]), GFP_KERNEL); if (!rpc) return NULL; diff --git a/drivers/staging/lustre/lnet/selftest/selftest.h b/drivers/staging/lustre/lnet/selftest/selftest.h index 8c10f0f149d5..ad04534f000c 100644 --- a/drivers/staging/lustre/lnet/selftest/selftest.h +++ b/drivers/staging/lustre/lnet/selftest/selftest.h @@ -169,11 +169,11 @@ struct srpc_buffer { }; struct swi_workitem; -typedef int (*swi_action_t) (struct swi_workitem *); +typedef void (*swi_action_t) (struct swi_workitem *); struct swi_workitem { - struct cfs_wi_sched *swi_sched; - struct cfs_workitem swi_workitem; + struct workqueue_struct *swi_wq; + struct work_struct swi_work; swi_action_t swi_action; int swi_state; }; @@ -444,7 +444,7 @@ void srpc_free_bulk(struct srpc_bulk *bk); struct srpc_bulk *srpc_alloc_bulk(int cpt, unsigned int off, unsigned int bulk_npg, unsigned int bulk_len, int sink); -int srpc_send_rpc(struct swi_workitem *wi); +void srpc_send_rpc(struct swi_workitem *wi); int srpc_send_reply(struct srpc_server_rpc *rpc); int srpc_add_service(struct srpc_service *sv); int srpc_remove_service(struct srpc_service *sv); @@ -456,8 +456,8 @@ void srpc_service_remove_buffers(struct srpc_service *sv, int nbuffer); void srpc_get_counters(struct srpc_counters *cnt); void srpc_set_counters(const struct srpc_counters *cnt); -extern struct cfs_wi_sched *lst_sched_serial; -extern struct cfs_wi_sched **lst_sched_test; +extern struct workqueue_struct *lst_serial_wq; +extern struct workqueue_struct **lst_test_wq; static inline int srpc_serv_is_framework(struct srpc_service *svc) @@ -465,42 +465,36 @@ srpc_serv_is_framework(struct srpc_service *svc) return svc->sv_id < SRPC_FRAMEWORK_SERVICE_MAX_ID; } -static inline int -swi_wi_action(struct cfs_workitem *wi) +static void +swi_wi_action(struct work_struct *wi) { struct swi_workitem *swi; - swi = container_of(wi, struct swi_workitem, swi_workitem); + swi = container_of(wi, struct swi_workitem, swi_work); - return swi->swi_action(swi); + swi->swi_action(swi); } static inline void -swi_init_workitem(struct swi_workitem *swi, void *data, - swi_action_t action, struct cfs_wi_sched *sched) +swi_init_workitem(struct swi_workitem *swi, + swi_action_t action, struct workqueue_struct *wq) { - swi->swi_sched = sched; + swi->swi_wq = wq; swi->swi_action = action; swi->swi_state = SWI_STATE_NEWBORN; - cfs_wi_init(&swi->swi_workitem, data, swi_wi_action); + INIT_WORK(&swi->swi_work, swi_wi_action); } static inline void swi_schedule_workitem(struct swi_workitem *wi) { - cfs_wi_schedule(wi->swi_sched, &wi->swi_workitem); -} - -static inline void -swi_exit_workitem(struct swi_workitem *swi) -{ - cfs_wi_exit(swi->swi_sched, &swi->swi_workitem); + queue_work(wi->swi_wq, &wi->swi_work); } static inline int -swi_deschedule_workitem(struct swi_workitem *swi) +swi_cancel_workitem(struct swi_workitem *swi) { - return cfs_wi_deschedule(swi->swi_sched, &swi->swi_workitem); + return cancel_work_sync(&swi->swi_work); } int sfw_startup(void); @@ -516,7 +510,7 @@ srpc_destroy_client_rpc(struct srpc_client_rpc *rpc) LASSERT(!atomic_read(&rpc->crpc_refcount)); if (!rpc->crpc_fini) - LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc)); + kfree(rpc); else (*rpc->crpc_fini)(rpc); } @@ -533,8 +527,8 @@ srpc_init_client_rpc(struct srpc_client_rpc *rpc, struct lnet_process_id peer, crpc_bulk.bk_iovs[nbulkiov])); INIT_LIST_HEAD(&rpc->crpc_list); - swi_init_workitem(&rpc->crpc_wi, rpc, srpc_send_rpc, - lst_sched_test[lnet_cpt_of_nid(peer.nid)]); + swi_init_workitem(&rpc->crpc_wi, srpc_send_rpc, + lst_test_wq[lnet_cpt_of_nid(peer.nid)]); spin_lock_init(&rpc->crpc_lock); atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */ diff --git a/drivers/staging/lustre/lustre/fld/fld_cache.c b/drivers/staging/lustre/lustre/fld/fld_cache.c index 7d6a7106c0a5..ecf8b9e1ed5c 100644 --- a/drivers/staging/lustre/lustre/fld/fld_cache.c +++ b/drivers/staging/lustre/lustre/fld/fld_cache.c @@ -213,19 +213,18 @@ static inline void fld_cache_entry_add(struct fld_cache *cache, */ static int fld_cache_shrink(struct fld_cache *cache) { - struct fld_cache_entry *flde; - struct list_head *curr; int num = 0; if (cache->fci_cache_count < cache->fci_cache_size) return 0; - curr = cache->fci_lru.prev; - while (cache->fci_cache_count + cache->fci_threshold > - cache->fci_cache_size && curr != &cache->fci_lru) { - flde = list_entry(curr, struct fld_cache_entry, fce_lru); - curr = curr->prev; + cache->fci_cache_size && + !list_empty(&cache->fci_lru)) { + struct fld_cache_entry *flde = + list_last_entry(&cache->fci_lru, + struct fld_cache_entry, fce_lru); + fld_cache_entry_delete(cache, flde); num++; } diff --git a/drivers/staging/lustre/lustre/include/lustre_disk.h b/drivers/staging/lustre/lustre/include/lustre_disk.h index 8f1a22527006..100e993ab00b 100644 --- a/drivers/staging/lustre/lustre/include/lustre_disk.h +++ b/drivers/staging/lustre/lustre/include/lustre_disk.h @@ -141,9 +141,9 @@ struct lustre_sb_info { /* obd_mount.c */ int lustre_start_mgc(struct super_block *sb); -void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb, - struct vfsmount *mnt)); -void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb)); +void lustre_register_super_ops(struct module *mod, + int (*cfs)(struct super_block *sb), + void (*ksc)(struct super_block *sb)); int lustre_common_put_super(struct super_block *sb); int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id, int type); diff --git a/drivers/staging/lustre/lustre/include/lustre_sec.h b/drivers/staging/lustre/lustre/include/lustre_sec.h index a40f706a53a1..64b6fd4fed8f 100644 --- a/drivers/staging/lustre/lustre/include/lustre_sec.h +++ b/drivers/staging/lustre/lustre/include/lustre_sec.h @@ -341,8 +341,8 @@ void sptlrpc_conf_client_adapt(struct obd_device *obd); #define SPTLRPC_MAX_PAYLOAD (1024) struct vfs_cred { - uint32_t vc_uid; - uint32_t vc_gid; + u32 vc_uid; + u32 vc_gid; }; struct ptlrpc_ctx_ops { diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h index 67c535c5aa98..531e8ddfa9e5 100644 --- a/drivers/staging/lustre/lustre/include/obd_class.h +++ b/drivers/staging/lustre/lustre/include/obd_class.h @@ -40,22 +40,19 @@ #include <lustre_lib.h> #include <lprocfs_status.h> -#define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay - * and resends for avoid deadlocks - */ -#define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update - * obd_osfs_age - */ -#define OBD_STATFS_FOR_MDT0 0x0004 /* The statfs is only for retrieving - * information from MDT0. - */ +/* requests should be send without delay and resends for avoid deadlocks */ +#define OBD_STATFS_NODELAY 0x0001 +/* the statfs callback should not update obd_osfs_age */ +#define OBD_STATFS_FROM_CACHE 0x0002 +/* the statfs is only for retrieving information from MDT0 */ +#define OBD_STATFS_FOR_MDT0 0x0004 /* OBD Device Declarations */ extern struct obd_device *obd_devs[MAX_OBD_DEVICES]; extern rwlock_t obd_dev_lock; /* OBD Operations Declarations */ -struct obd_device *class_exp2obd(struct obd_export *); +struct obd_device *class_exp2obd(struct obd_export *exp); int class_handle_ioctl(unsigned int cmd, unsigned long arg); int lustre_get_jobid(char *jobid); @@ -63,10 +60,10 @@ struct lu_device_type; /* genops.c */ extern struct list_head obd_types; -struct obd_export *class_conn2export(struct lustre_handle *); -int class_register_type(struct obd_ops *, struct md_ops *, - const char *nm, struct lu_device_type *ldt); -int class_unregister_type(const char *nm); +struct obd_export *class_conn2export(struct lustre_handle *conn); +int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, + const char *name, struct lu_device_type *ldt); +int class_unregister_type(const char *name); struct obd_device *class_newdev(const char *type_name, const char *name); void class_release_dev(struct obd_device *obd); @@ -137,7 +134,7 @@ int class_config_llog_handler(const struct lu_env *env, struct llog_rec_hdr *rec, void *data); int class_add_uuid(const char *uuid, __u64 nid); -/*obdecho*/ +/* obdecho */ void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars); #define CFG_F_START 0x01 /* Set when we start updating from a log */ @@ -148,13 +145,13 @@ void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars); /* Passed as data param to class_config_parse_llog */ struct config_llog_instance { - char *cfg_obdname; - void *cfg_instance; + char *cfg_obdname; + void *cfg_instance; struct super_block *cfg_sb; struct obd_uuid cfg_uuid; llog_cb_t cfg_callback; - int cfg_last_idx; /* for partial llog processing */ - int cfg_flags; + int cfg_last_idx; /* for partial llog processing */ + int cfg_flags; }; int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt, @@ -172,30 +169,31 @@ enum { /* list of active configuration logs */ struct config_llog_data { - struct ldlm_res_id cld_resid; + struct ldlm_res_id cld_resid; struct config_llog_instance cld_cfg; - struct list_head cld_list_chain; - atomic_t cld_refcount; + struct list_head cld_list_chain; + atomic_t cld_refcount; struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */ struct config_llog_data *cld_params; /* common parameters log */ struct config_llog_data *cld_recover;/* imperative recover log */ - struct obd_export *cld_mgcexp; + struct obd_export *cld_mgcexp; struct mutex cld_lock; - int cld_type; - unsigned int cld_stopping:1, /* we were told to stop - * watching - */ - cld_lostlock:1; /* lock not requeued */ - char cld_logname[0]; + int cld_type; + unsigned int cld_stopping:1, /* + * we were told to stop + * watching + */ + cld_lostlock:1; /* lock not requeued */ + char cld_logname[0]; }; struct lustre_profile { - struct list_head lp_list; - char *lp_profile; - char *lp_dt; - char *lp_md; - int lp_refs; - bool lp_list_deleted; + struct list_head lp_list; + char *lp_profile; + char *lp_dt; + char *lp_md; + int lp_refs; + bool lp_list_deleted; }; struct lustre_profile *class_get_profile(const char *prof); @@ -205,9 +203,11 @@ void class_del_profiles(void); #if LUSTRE_TRACKS_LOCK_EXP_REFS -void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *); -void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *); -extern void (*class_export_dump_hook)(struct obd_export *); +void __class_export_add_lock_ref(struct obd_export *exp, + struct ldlm_lock *lock); +void __class_export_del_lock_ref(struct obd_export *exp, + struct ldlm_lock *lock); +extern void (*class_export_dump_hook)(struct obd_export *exp); #else @@ -223,8 +223,8 @@ struct obd_export *class_new_export(struct obd_device *obddev, struct obd_uuid *cluuid); void class_unlink_export(struct obd_export *exp); -struct obd_import *class_import_get(struct obd_import *); -void class_import_put(struct obd_import *); +struct obd_import *class_import_get(struct obd_import *imp); +void class_import_put(struct obd_import *imp); struct obd_import *class_new_import(struct obd_device *obd); void class_destroy_import(struct obd_import *exp); @@ -299,7 +299,8 @@ void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj); #define MDP(dev, op) (dev)->obd_type->typ_md_ops->op #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op -/* Ensure obd_setup: used for cleanup which must be called +/* + * Ensure obd_setup: used for cleanup which must be called * while obd is stopping */ static inline int obd_check_dev(struct obd_device *obd) @@ -326,108 +327,116 @@ static inline int obd_check_dev_active(struct obd_device *obd) return rc; } -#define OBD_COUNTER_OFFSET(op) \ - ((offsetof(struct obd_ops, op) - \ - offsetof(struct obd_ops, iocontrol)) \ - / sizeof(((struct obd_ops *)(0))->iocontrol)) - -#define OBD_COUNTER_INCREMENT(obdx, op) \ - if ((obdx)->obd_stats) { \ - unsigned int coffset; \ - coffset = (unsigned int)((obdx)->obd_cntr_base) + \ - OBD_COUNTER_OFFSET(op); \ - LASSERT(coffset < (obdx)->obd_stats->ls_num); \ - lprocfs_counter_incr((obdx)->obd_stats, coffset); \ - } +#define OBD_COUNTER_OFFSET(op) \ + ((offsetof(struct obd_ops, op) - \ + offsetof(struct obd_ops, iocontrol)) \ + / sizeof(((struct obd_ops *)(0))->iocontrol)) -#define EXP_COUNTER_INCREMENT(export, op) \ - if ((export)->exp_obd->obd_stats) { \ +#define OBD_COUNTER_INCREMENT(obdx, op) \ +do { \ + if ((obdx)->obd_stats) { \ unsigned int coffset; \ + coffset = (unsigned int)((obdx)->obd_cntr_base) + \ + OBD_COUNTER_OFFSET(op); \ + LASSERT(coffset < (obdx)->obd_stats->ls_num); \ + lprocfs_counter_incr((obdx)->obd_stats, coffset); \ + } \ +} while (0) + +#define EXP_COUNTER_INCREMENT(export, op) \ +do { \ + if ((export)->exp_obd->obd_stats) { \ + unsigned int coffset; \ coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \ - OBD_COUNTER_OFFSET(op); \ + OBD_COUNTER_OFFSET(op); \ LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \ lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \ - } + } \ +} while (0) -#define MD_COUNTER_OFFSET(op) \ - ((offsetof(struct md_ops, op) - \ - offsetof(struct md_ops, getstatus)) \ - / sizeof(((struct md_ops *)(0))->getstatus)) +#define MD_COUNTER_OFFSET(op) \ + ((offsetof(struct md_ops, op) - \ + offsetof(struct md_ops, getstatus)) \ + / sizeof(((struct md_ops *)(0))->getstatus)) -#define MD_COUNTER_INCREMENT(obdx, op) \ - if ((obd)->md_stats) { \ - unsigned int coffset; \ +#define MD_COUNTER_INCREMENT(obdx, op) \ +do { \ + if ((obd)->md_stats) { \ + unsigned int coffset; \ coffset = (unsigned int)((obdx)->md_cntr_base) + \ - MD_COUNTER_OFFSET(op); \ - LASSERT(coffset < (obdx)->md_stats->ls_num); \ + MD_COUNTER_OFFSET(op); \ + LASSERT(coffset < (obdx)->md_stats->ls_num); \ lprocfs_counter_incr((obdx)->md_stats, coffset); \ - } + } \ +} while (0) -#define EXP_MD_COUNTER_INCREMENT(export, op) \ - if ((export)->exp_obd->obd_stats) { \ - unsigned int coffset; \ - coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \ - MD_COUNTER_OFFSET(op); \ - LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \ - lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \ - if ((export)->exp_md_stats) \ - lprocfs_counter_incr( \ +#define EXP_MD_COUNTER_INCREMENT(export, op) \ +do { \ + if ((export)->exp_obd->obd_stats) { \ + unsigned int coffset; \ + coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \ + MD_COUNTER_OFFSET(op); \ + LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \ + lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \ + if ((export)->exp_md_stats) \ + lprocfs_counter_incr( \ (export)->exp_md_stats, coffset); \ - } + } \ +} while (0) #define EXP_CHECK_MD_OP(exp, op) \ -do { \ - if (!(exp)) { \ - CERROR("obd_" #op ": NULL export\n"); \ - return -ENODEV; \ - } \ - if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \ +do { \ + if (!(exp)) { \ + CERROR("obd_" #op ": NULL export\n"); \ + return -ENODEV; \ + } \ + if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \ CERROR("obd_" #op ": cleaned up obd\n"); \ - return -EOPNOTSUPP; \ - } \ - if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \ + return -EOPNOTSUPP; \ + } \ + if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \ CERROR("obd_" #op ": dev %s/%d no operation\n", \ - (exp)->exp_obd->obd_name, \ - (exp)->exp_obd->obd_minor); \ - return -EOPNOTSUPP; \ - } \ + (exp)->exp_obd->obd_name, \ + (exp)->exp_obd->obd_minor); \ + return -EOPNOTSUPP; \ + } \ } while (0) -#define OBD_CHECK_DT_OP(obd, op, err) \ -do { \ - if (!OBT(obd) || !OBP((obd), op)) { \ - if (err) \ - CERROR("obd_" #op ": dev %d no operation\n", \ - obd->obd_minor); \ - return err; \ - } \ +#define OBD_CHECK_DT_OP(obd, op, err) \ +do { \ + if (!OBT(obd) || !OBP((obd), op)) { \ + if (err) \ + CERROR("obd_" #op ": dev %d no operation\n", \ + obd->obd_minor); \ + return err; \ + } \ } while (0) #define EXP_CHECK_DT_OP(exp, op) \ -do { \ - if (!(exp)) { \ - CERROR("obd_" #op ": NULL export\n"); \ - return -ENODEV; \ - } \ - if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \ +do { \ + if (!(exp)) { \ + CERROR("obd_" #op ": NULL export\n"); \ + return -ENODEV; \ + } \ + if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \ CERROR("obd_" #op ": cleaned up obd\n"); \ - return -EOPNOTSUPP; \ - } \ - if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \ - CERROR("obd_" #op ": dev %d no operation\n", \ - (exp)->exp_obd->obd_minor); \ - return -EOPNOTSUPP; \ - } \ + return -EOPNOTSUPP; \ + } \ + if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \ + CERROR("obd_" #op ": dev %d no operation\n", \ + (exp)->exp_obd->obd_minor); \ + return -EOPNOTSUPP; \ + } \ } while (0) -#define CTXT_CHECK_OP(ctxt, op, err) \ -do { \ - if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \ - if (err) \ - CERROR("lop_" #op ": dev %d no operation\n", \ - ctxt->loc_obd->obd_minor); \ - return err; \ - } \ +#define CTXT_CHECK_OP(ctxt, op, err) \ +do { \ + if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \ + if (err) \ + CERROR("lop_" #op ": dev %d no operation\n", \ + ctxt->loc_obd->obd_minor); \ + return err; \ + } \ } while (0) static inline int class_devno_max(void) @@ -481,14 +490,11 @@ static inline int obd_set_info_async(const struct lu_env *env, * obd_precleanup() and obd_cleanup() call both lu_device and obd operations. */ -#define DECLARE_LU_VARS(ldt, d) \ - struct lu_device_type *ldt; \ - struct lu_device *d - static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg) { int rc; - DECLARE_LU_VARS(ldt, d); + struct lu_device_type *ldt; + struct lu_device *d; ldt = obd->obd_type->typ_lu; if (ldt) { @@ -526,7 +532,8 @@ static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg) static inline int obd_precleanup(struct obd_device *obd) { int rc; - DECLARE_LU_VARS(ldt, d); + struct lu_device_type *ldt; + struct lu_device *d; rc = obd_check_dev(obd); if (rc) @@ -552,7 +559,8 @@ static inline int obd_precleanup(struct obd_device *obd) static inline int obd_cleanup(struct obd_device *obd) { int rc; - DECLARE_LU_VARS(ldt, d); + struct lu_device_type *ldt; + struct lu_device *d; rc = obd_check_dev(obd); if (rc) @@ -579,7 +587,8 @@ static inline int obd_cleanup(struct obd_device *obd) static inline void obd_cleanup_client_import(struct obd_device *obd) { - /* If we set up but never connected, the + /* + * If we set up but never connected, the * client import will not have been cleaned. */ down_write(&obd->u.cli.cl_sem); @@ -600,7 +609,8 @@ static inline int obd_process_config(struct obd_device *obd, int datalen, void *data) { int rc; - DECLARE_LU_VARS(ldt, d); + struct lu_device_type *ldt; + struct lu_device *d; rc = obd_check_dev(obd); if (rc) @@ -717,7 +727,8 @@ static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp) return uuid; } -/** Create a new /a exp on device /a obd for the uuid /a cluuid +/* + * Create a new /a exp on device /a obd for the uuid /a cluuid * @param exp New export handle * @param d Connect data, supported flags are set, flags also understood * by obd are returned. @@ -729,7 +740,8 @@ static inline int obd_connect(const struct lu_env *env, void *localdata) { int rc; - __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition + __u64 ocf = data ? data->ocd_connect_flags : 0; /* + * for post-condition * check */ @@ -838,7 +850,9 @@ static inline int obd_pool_del(struct obd_device *obd, char *poolname) return rc; } -static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname) +static inline int obd_pool_add(struct obd_device *obd, + char *poolname, + char *ostname) { int rc; @@ -849,7 +863,9 @@ static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ost return rc; } -static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname) +static inline int obd_pool_rem(struct obd_device *obd, + char *poolname, + char *ostname) { int rc; @@ -894,7 +910,8 @@ static inline int obd_destroy_export(struct obd_export *exp) return 0; } -/* @max_age is the oldest time in jiffies that we accept using a cached data. +/* + * @max_age is the oldest time in jiffies that we accept using a cached data. * If the cache is older than @max_age we will get a new value from the * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */ @@ -955,7 +972,8 @@ static inline int obd_statfs_rqset(struct obd_export *exp, return rc; } -/* @max_age is the oldest time in jiffies that we accept using a cached data. +/* + * @max_age is the oldest time in jiffies that we accept using a cached data. * If the cache is older than @max_age we will get a new value from the * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */ @@ -983,7 +1001,8 @@ static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp, spin_unlock(&obd->obd_osfs_lock); } } else { - CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n", + CDEBUG(D_SUPER, + "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n", obd->obd_name, &obd->obd_osfs, obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks, obd->obd_osfs.os_ffree, obd->obd_osfs.os_files); @@ -1118,7 +1137,8 @@ static inline int obd_quotactl(struct obd_export *exp, static inline int obd_health_check(const struct lu_env *env, struct obd_device *obd) { - /* returns: 0 on healthy + /* + * returns: 0 on healthy * >0 on unhealthy + reason code/flag * however the only supported reason == 1 right now * We'll need to define some better reasons @@ -1491,7 +1511,8 @@ static inline int md_get_fid_from_lsm(struct obd_export *exp, return rc; } -/* Unpack an MD struct from disk to in-memory format. +/* + * Unpack an MD struct from disk to in-memory format. * Returns +ve size of unpacked MD (0 for free), or -ve error. * * If *plsm != NULL and lmm == NULL then *lsm will be freed. @@ -1523,11 +1544,12 @@ struct lwp_register_item { struct obd_export **lri_exp; register_lwp_cb lri_cb_func; void *lri_cb_data; - struct list_head lri_list; + struct list_head lri_list; char lri_name[MTI_NAME_MAXLEN]; }; -/* I'm as embarrassed about this as you are. +/* + * I'm as embarrassed about this as you are. * * <shaver> // XXX do not look into _superhack with remaining eye * <shaver> // XXX if this were any uglier, I'd get my own show on MTV @@ -1562,7 +1584,8 @@ int class_procfs_init(void); int class_procfs_clean(void); /* prng.c */ -#define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t)) +#define ll_generate_random_uuid(uuid_out) \ + get_random_bytes(uuid_out, sizeof(class_uuid_t)) /* statfs_pack.c */ struct kstatfs; diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c index fac9d19d50b6..11b11b5f3216 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c @@ -64,7 +64,6 @@ __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms) { struct ldlm_resource *res = lock->l_resource; - struct list_head *tmp; struct ldlm_lock *lck; __u64 kms = 0; @@ -74,8 +73,7 @@ __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms) */ ldlm_set_kms_ignore(lock); - list_for_each(tmp, &res->lr_granted) { - lck = list_entry(tmp, struct ldlm_lock, l_res_link); + list_for_each_entry(lck, &res->lr_granted, l_res_link) { if (ldlm_is_kms_ignore(lck)) continue; diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c index 7cb61e2e7d3b..7cbc6a06afec 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c @@ -886,17 +886,15 @@ static void search_granted_lock(struct list_head *queue, struct ldlm_lock *req, struct sl_insert_point *prev) { - struct list_head *tmp; struct ldlm_lock *lock, *mode_end, *policy_end; - list_for_each(tmp, queue) { - lock = list_entry(tmp, struct ldlm_lock, l_res_link); + list_for_each_entry(lock, queue, l_res_link) { mode_end = list_prev_entry(lock, l_sl_mode); if (lock->l_req_mode != req->l_req_mode) { /* jump to last lock of mode group */ - tmp = &mode_end->l_res_link; + lock = mode_end; continue; } @@ -933,9 +931,7 @@ static void search_granted_lock(struct list_head *queue, break; /* go to next policy group within mode group */ - tmp = policy_end->l_res_link.next; - lock = list_entry(tmp, struct ldlm_lock, - l_res_link); + lock = list_next_entry(policy_end, l_res_link); } /* loop over policy groups within the mode group */ /* insert point is last lock of the mode group, @@ -1687,7 +1683,7 @@ ldlm_work_bl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq) if (list_empty(arg->list)) return -ENOENT; - lock = list_entry(arg->list->next, struct ldlm_lock, l_bl_ast); + lock = list_first_entry(arg->list, struct ldlm_lock, l_bl_ast); /* nobody should touch l_bl_ast */ lock_res_and_lock(lock); @@ -1723,7 +1719,7 @@ ldlm_work_cp_ast_lock(struct ptlrpc_request_set *rqset, void *opaq) if (list_empty(arg->list)) return -ENOENT; - lock = list_entry(arg->list->next, struct ldlm_lock, l_cp_ast); + lock = list_first_entry(arg->list, struct ldlm_lock, l_cp_ast); /* It's possible to receive a completion AST before we've set * the l_completion_ast pointer: either because the AST arrived @@ -1769,7 +1765,7 @@ ldlm_work_revoke_ast_lock(struct ptlrpc_request_set *rqset, void *opaq) if (list_empty(arg->list)) return -ENOENT; - lock = list_entry(arg->list->next, struct ldlm_lock, l_rk_ast); + lock = list_first_entry(arg->list, struct ldlm_lock, l_rk_ast); list_del_init(&lock->l_rk_ast); /* the desc just pretend to exclusive */ @@ -1796,7 +1792,7 @@ static int ldlm_work_gl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq) if (list_empty(arg->list)) return -ENOENT; - gl_work = list_entry(arg->list->next, struct ldlm_glimpse_work, + gl_work = list_first_entry(arg->list, struct ldlm_glimpse_work, gl_list); list_del_init(&gl_work->gl_list); diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c index 2d5a2c932ddc..5f6e7c933b81 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c @@ -696,13 +696,13 @@ static int ldlm_bl_get_work(struct ldlm_bl_pool *blp, /* process a request from the blp_list at least every blp_num_threads */ if (!list_empty(&blp->blp_list) && (list_empty(&blp->blp_prio_list) || num_bl == 0)) - blwi = list_entry(blp->blp_list.next, - struct ldlm_bl_work_item, blwi_entry); + blwi = list_first_entry(&blp->blp_list, + struct ldlm_bl_work_item, blwi_entry); else if (!list_empty(&blp->blp_prio_list)) - blwi = list_entry(blp->blp_prio_list.next, - struct ldlm_bl_work_item, - blwi_entry); + blwi = list_first_entry(&blp->blp_prio_list, + struct ldlm_bl_work_item, + blwi_entry); if (blwi) { if (++num_bl >= num_th) @@ -1093,8 +1093,10 @@ static int ldlm_cleanup(void) kset_unregister(ldlm_ns_kset); if (ldlm_svc_kset) kset_unregister(ldlm_svc_kset); - if (ldlm_kobj) + if (ldlm_kobj) { + sysfs_remove_group(ldlm_kobj, &ldlm_attr_group); kobject_put(ldlm_kobj); + } ldlm_debugfs_cleanup(); diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c index da65d00a7811..8563bd32befa 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c @@ -1086,8 +1086,12 @@ int ldlm_pools_init(void) int rc; rc = ldlm_pools_thread_start(); - if (rc == 0) - register_shrinker(&ldlm_pools_cli_shrinker); + if (rc) + return rc; + + rc = register_shrinker(&ldlm_pools_cli_shrinker); + if (rc) + ldlm_pools_thread_stop(); return rc; } diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c index 02ea14c9b089..6aa37463db46 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c @@ -1656,7 +1656,7 @@ int ldlm_cli_cancel_list(struct list_head *cancels, int count, */ while (count > 0) { LASSERT(!list_empty(cancels)); - lock = list_entry(cancels->next, struct ldlm_lock, l_bl_ast); + lock = list_first_entry(cancels, struct ldlm_lock, l_bl_ast); LASSERT(lock->l_conn_export); if (exp_connect_cancelset(lock->l_conn_export)) { @@ -1780,7 +1780,7 @@ EXPORT_SYMBOL(ldlm_cli_cancel_unused); static int ldlm_resource_foreach(struct ldlm_resource *res, ldlm_iterator_t iter, void *closure) { - struct list_head *tmp, *next; + struct ldlm_lock *tmp; struct ldlm_lock *lock; int rc = LDLM_ITER_CONTINUE; @@ -1788,18 +1788,14 @@ static int ldlm_resource_foreach(struct ldlm_resource *res, return LDLM_ITER_CONTINUE; lock_res(res); - list_for_each_safe(tmp, next, &res->lr_granted) { - lock = list_entry(tmp, struct ldlm_lock, l_res_link); - + list_for_each_entry_safe(lock, tmp, &res->lr_granted, l_res_link) { if (iter(lock, closure) == LDLM_ITER_STOP) { rc = LDLM_ITER_STOP; goto out; } } - list_for_each_safe(tmp, next, &res->lr_waiting) { - lock = list_entry(tmp, struct ldlm_lock, l_res_link); - + list_for_each_entry_safe(lock, tmp, &res->lr_waiting, l_res_link) { if (iter(lock, closure) == LDLM_ITER_STOP) { rc = LDLM_ITER_STOP; goto out; diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c index 2689ffdf10e3..9958533cc227 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c @@ -752,24 +752,22 @@ extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock); static void cleanup_resource(struct ldlm_resource *res, struct list_head *q, __u64 flags) { - struct list_head *tmp; int rc = 0; bool local_only = !!(flags & LDLM_FL_LOCAL_ONLY); do { - struct ldlm_lock *lock = NULL; + struct ldlm_lock *lock = NULL, *tmp; struct lustre_handle lockh; /* First, we look for non-cleaned-yet lock * all cleaned locks are marked by CLEANED flag. */ lock_res(res); - list_for_each(tmp, q) { - lock = list_entry(tmp, struct ldlm_lock, l_res_link); - if (ldlm_is_cleaned(lock)) { - lock = NULL; + list_for_each_entry(tmp, q, l_res_link) { + if (ldlm_is_cleaned(tmp)) continue; - } + + lock = tmp; LDLM_LOCK_GET(lock); ldlm_set_cleaned(lock); break; @@ -1283,19 +1281,15 @@ void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc) */ void ldlm_dump_all_namespaces(enum ldlm_side client, int level) { - struct list_head *tmp; + struct ldlm_namespace *ns; if (!((libcfs_debug | D_ERROR) & level)) return; mutex_lock(ldlm_namespace_lock(client)); - list_for_each(tmp, ldlm_namespace_list(client)) { - struct ldlm_namespace *ns; - - ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain); + list_for_each_entry(ns, ldlm_namespace_list(client), ns_list_chain) ldlm_namespace_dump(level, ns); - } mutex_unlock(ldlm_namespace_lock(client)); } diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c index 6f59045be0f9..99b0b77c75f5 100644 --- a/drivers/staging/lustre/lustre/llite/dir.c +++ b/drivers/staging/lustre/lustre/llite/dir.c @@ -1337,9 +1337,9 @@ finish_req: cmd == LL_IOC_MDC_GETINFO)) { rc = 0; goto skip_lmm; - } else { - goto out_req; } + + goto out_req; } if (cmd == IOC_MDC_GETFILESTRIPE || diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h index 0d62fcf016dc..f68c2e88f12b 100644 --- a/drivers/staging/lustre/lustre/llite/llite_internal.h +++ b/drivers/staging/lustre/lustre/llite/llite_internal.h @@ -792,7 +792,7 @@ int ll_revalidate_it_finish(struct ptlrpc_request *request, extern struct super_operations lustre_super_operations; void ll_lli_init(struct ll_inode_info *lli); -int ll_fill_super(struct super_block *sb, struct vfsmount *mnt); +int ll_fill_super(struct super_block *sb); void ll_put_super(struct super_block *sb); void ll_kill_super(struct super_block *sb); struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock); diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c index 8666f1e81ade..6735a6f006d2 100644 --- a/drivers/staging/lustre/lustre/llite/llite_lib.c +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c @@ -146,8 +146,7 @@ static void ll_free_sbi(struct super_block *sb) kfree(sbi); } -static int client_common_fill_super(struct super_block *sb, char *md, char *dt, - struct vfsmount *mnt) +static int client_common_fill_super(struct super_block *sb, char *md, char *dt) { struct inode *root = NULL; struct ll_sb_info *sbi = ll_s2sbi(sb); @@ -236,7 +235,9 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt, "An MDT (md %s) is performing recovery, of which this client is not a part. Please wait for recovery to complete, abort, or time out.\n", md); goto out; - } else if (err) { + } + + if (err) { CERROR("cannot connect to %s: rc = %d\n", md, err); goto out; } @@ -865,7 +866,7 @@ void ll_lli_init(struct ll_inode_info *lli) mutex_init(&lli->lli_layout_mutex); } -int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) +int ll_fill_super(struct super_block *sb) { struct lustre_profile *lprof = NULL; struct lustre_sb_info *lsi = s2lsi(sb); @@ -942,7 +943,7 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) } /* connections, registrations, sb setup */ - err = client_common_fill_super(sb, md, dt, mnt); + err = client_common_fill_super(sb, md, dt); if (!err) sbi->ll_client_common_fill_super_succeeded = 1; diff --git a/drivers/staging/lustre/lustre/llite/super25.c b/drivers/staging/lustre/lustre/llite/super25.c index 0bda111a096e..9b0bb3541a84 100644 --- a/drivers/staging/lustre/lustre/llite/super25.c +++ b/drivers/staging/lustre/lustre/llite/super25.c @@ -86,8 +86,7 @@ MODULE_ALIAS_FS("lustre"); static int __init lustre_init(void) { struct lnet_process_id lnet_id; - struct timespec64 ts; - int i, rc, seed[2]; + int i, rc; BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) != LUSTRE_VOLATILE_HDR_LEN + 1); @@ -126,22 +125,20 @@ static int __init lustre_init(void) goto out_debugfs; } - cfs_get_random_bytes(seed, sizeof(seed)); - /* Nodes with small feet have little entropy. The NID for this * node gives the most entropy in the low bits */ for (i = 0;; i++) { + u32 seed; + if (LNetGetId(i, &lnet_id) == -ENOENT) break; - - if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) - seed[0] ^= LNET_NIDADDR(lnet_id.nid); + if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) { + seed = LNET_NIDADDR(lnet_id.nid); + add_device_randomness(&seed, sizeof(seed)); + } } - ktime_get_ts64(&ts); - cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); - rc = vvp_global_init(); if (rc != 0) goto out_sysfs; @@ -159,8 +156,7 @@ static int __init lustre_init(void) if (rc != 0) goto out_inode_fini_env; - lustre_register_client_fill_super(ll_fill_super); - lustre_register_kill_super_cb(ll_kill_super); + lustre_register_super_ops(THIS_MODULE, ll_fill_super, ll_kill_super); lustre_register_client_process_config(ll_process_config); return 0; @@ -181,8 +177,7 @@ out_cache: static void __exit lustre_exit(void) { - lustre_register_client_fill_super(NULL); - lustre_register_kill_super_cb(NULL); + lustre_register_super_ops(NULL, NULL, NULL); lustre_register_client_process_config(NULL); debugfs_remove(llite_root); diff --git a/drivers/staging/lustre/lustre/llite/vvp_dev.c b/drivers/staging/lustre/lustre/llite/vvp_dev.c index 8ccc8b799c02..987c03b058e6 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_dev.c +++ b/drivers/staging/lustre/lustre/llite/vvp_dev.c @@ -384,7 +384,7 @@ int cl_sb_fini(struct super_block *sb) struct vvp_pgcache_id { unsigned int vpi_bucket; unsigned int vpi_depth; - uint32_t vpi_index; + u32 vpi_index; unsigned int vpi_curdep; struct lu_object_header *vpi_obj; diff --git a/drivers/staging/lustre/lustre/llite/vvp_io.c b/drivers/staging/lustre/lustre/llite/vvp_io.c index bfae98e82d6f..e7a4778e02e4 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_io.c +++ b/drivers/staging/lustre/lustre/llite/vvp_io.c @@ -699,7 +699,7 @@ static int vvp_io_read_start(const struct lu_env *env, result = vvp_prep_size(env, obj, io, pos, tot, &exceed); if (result != 0) return result; - else if (exceed != 0) + if (exceed != 0) goto out; LU_OBJECT_HEADER(D_INODE, env, &obj->co_lu, diff --git a/drivers/staging/lustre/lustre/lov/lov_internal.h b/drivers/staging/lustre/lustre/lov/lov_internal.h index ae28ddf80d9b..a56d71c2dda2 100644 --- a/drivers/staging/lustre/lustre/lov/lov_internal.h +++ b/drivers/staging/lustre/lustre/lov/lov_internal.h @@ -115,19 +115,19 @@ static inline const struct lsm_operations *lsm_op_find(int magic) */ #if BITS_PER_LONG == 64 # define lov_do_div64(n, base) ({ \ - uint64_t __base = (base); \ - uint64_t __rem; \ - __rem = ((uint64_t)(n)) % __base; \ - (n) = ((uint64_t)(n)) / __base; \ + u64 __base = (base); \ + u64 __rem; \ + __rem = ((u64)(n)) % __base; \ + (n) = ((u64)(n)) / __base; \ __rem; \ }) #elif BITS_PER_LONG == 32 # define lov_do_div64(n, base) ({ \ - uint64_t __rem; \ + u64 __rem; \ if ((sizeof(base) > 4) && (((base) & 0xffffffff00000000ULL) != 0)) { \ int __remainder; \ LASSERTF(!((base) & (LOV_MIN_STRIPE_SIZE - 1)), "64 bit lov " \ - "division %llu / %llu\n", (n), (uint64_t)(base)); \ + "division %llu / %llu\n", (n), (u64)(base)); \ __remainder = (n) & (LOV_MIN_STRIPE_SIZE - 1); \ (n) >>= LOV_MIN_STRIPE_BITS; \ __rem = do_div(n, (base) >> LOV_MIN_STRIPE_BITS); \ diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c index 7ce01026a409..ec70c12e5b40 100644 --- a/drivers/staging/lustre/lustre/lov/lov_obd.c +++ b/drivers/staging/lustre/lustre/lov/lov_obd.c @@ -828,11 +828,9 @@ out: static int lov_cleanup(struct obd_device *obd) { struct lov_obd *lov = &obd->u.lov; - struct list_head *pos, *tmp; - struct pool_desc *pool; + struct pool_desc *pool, *tmp; - list_for_each_safe(pos, tmp, &lov->lov_pool_list) { - pool = list_entry(pos, struct pool_desc, pool_list); + list_for_each_entry_safe(pool, tmp, &lov->lov_pool_list, pool_list) { /* free pool structs */ CDEBUG(D_INFO, "delete pool %p\n", pool); /* In the function below, .hs_keycmp resolves to diff --git a/drivers/staging/lustre/lustre/lov/lov_object.c b/drivers/staging/lustre/lustre/lov/lov_object.c index 105b707eed14..897cf2cd4a24 100644 --- a/drivers/staging/lustre/lustre/lov/lov_object.c +++ b/drivers/staging/lustre/lustre/lov/lov_object.c @@ -1335,7 +1335,7 @@ static int lov_object_fiemap(const struct lu_env *env, struct cl_object *obj, int rc = 0; int cur_stripe; int stripe_count; - struct fiemap_state fs = { 0 }; + struct fiemap_state fs = { NULL }; lsm = lov_lsm_addref(cl2lov(obj)); if (!lsm) diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c index 3bdf48e4edb4..cfa1d7f92b0f 100644 --- a/drivers/staging/lustre/lustre/lov/lov_request.c +++ b/drivers/staging/lustre/lustre/lov/lov_request.c @@ -49,15 +49,13 @@ static void lov_init_set(struct lov_request_set *set) static void lov_finish_set(struct lov_request_set *set) { - struct list_head *pos, *n; + struct lov_request *req; LASSERT(set); - list_for_each_safe(pos, n, &set->set_list) { - struct lov_request *req = list_entry(pos, - struct lov_request, - rq_link); + while ((req = list_first_entry_or_null(&set->set_list, + struct lov_request, + rq_link)) != NULL) { list_del_init(&req->rq_link); - kfree(req->rq_oi.oi_osfs); kfree(req); } diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c index 77fa8fea0249..79ff85feab64 100644 --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c @@ -523,7 +523,7 @@ static void do_requeue(struct config_llog_data *cld) * in order to not flood the MGS. */ #define MGC_TIMEOUT_MIN_SECONDS 5 -#define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 */ +#define MGC_TIMEOUT_RAND_CENTISEC 500 static int mgc_requeue_thread(void *data) { @@ -537,7 +537,7 @@ static int mgc_requeue_thread(void *data) while (!(rq_state & RQ_STOP)) { struct l_wait_info lwi; struct config_llog_data *cld, *cld_prev; - int rand = cfs_rand() & MGC_TIMEOUT_RAND_CENTISEC; + int rand = prandom_u32_max(MGC_TIMEOUT_RAND_CENTISEC); int to; /* Any new or requeued lostlocks will change the state */ diff --git a/drivers/staging/lustre/lustre/obdclass/cl_lock.c b/drivers/staging/lustre/lustre/obdclass/cl_lock.c index d415f8396038..3b683b774fef 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_lock.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_lock.c @@ -79,13 +79,12 @@ EXPORT_SYMBOL(cl_lock_slice_add); void cl_lock_fini(const struct lu_env *env, struct cl_lock *lock) { + struct cl_lock_slice *slice; cl_lock_trace(D_DLMTRACE, env, "destroy lock", lock); - while (!list_empty(&lock->cll_layers)) { - struct cl_lock_slice *slice; - - slice = list_entry(lock->cll_layers.next, - struct cl_lock_slice, cls_linkage); + while ((slice = list_first_entry_or_null(&lock->cll_layers, + struct cl_lock_slice, + cls_linkage)) != NULL) { list_del_init(lock->cll_layers.next); slice->cls_ops->clo_fini(env, slice); } diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c index fdd27ce46fda..7b18d775b001 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_object.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c @@ -510,13 +510,13 @@ locks: ...... ...... ...... ...... ...... [...... ...... ...... ...... ......] */ lu_site_stats_print(&site->cs_lu, m); cache_stats_print(&site->cs_pages, m, 1); - seq_printf(m, " ["); + seq_puts(m, " ["); for (i = 0; i < ARRAY_SIZE(site->cs_pages_state); ++i) seq_printf(m, "%s: %u ", pstate[i], atomic_read(&site->cs_pages_state[i])); - seq_printf(m, "]\n"); + seq_puts(m, "]\n"); cache_stats_print(&cl_env_stats, m, 0); - seq_printf(m, "\n"); + seq_puts(m, "\n"); return 0; } EXPORT_SYMBOL(cl_site_stats_print); @@ -1017,7 +1017,7 @@ int cl_global_init(void) { int result; - cl_envs = kzalloc(sizeof(*cl_envs) * num_possible_cpus(), GFP_KERNEL); + cl_envs = kcalloc(num_possible_cpus(), sizeof(*cl_envs), GFP_KERNEL); if (!cl_envs) { result = -ENOMEM; goto out; diff --git a/drivers/staging/lustre/lustre/obdclass/cl_page.c b/drivers/staging/lustre/lustre/obdclass/cl_page.c index 7f65439f9b95..d3b25667bc3a 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_page.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_page.c @@ -202,7 +202,7 @@ struct cl_page *cl_page_find(const struct lu_env *env, * vmpage lock is used to protect the child/parent * relationship */ - KLASSERT(PageLocked(vmpage)); + LASSERT(PageLocked(vmpage)); /* * cl_vmpage_page() can be called here without any locks as * @@ -340,7 +340,7 @@ struct cl_page *cl_vmpage_page(struct page *vmpage, struct cl_object *obj) { struct cl_page *page; - KLASSERT(PageLocked(vmpage)); + LASSERT(PageLocked(vmpage)); /* * NOTE: absence of races and liveness of data are guaranteed by page diff --git a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c index 2985bca4dc4c..3e24b76f6301 100644 --- a/drivers/staging/lustre/lustre/obdclass/class_obd.c +++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c @@ -377,7 +377,8 @@ static int obd_init_checks(void) char buf[64]; int len, ret = 0; - CDEBUG(D_INFO, "LPU64=%s, LPD64=%s, LPX64=%s\n", "%llu", "%lld", "%#llx"); + CDEBUG(D_INFO, "LPU64=%s, LPD64=%s, LPX64=%s\n", "%llu", "%lld", + "%#llx"); CDEBUG(D_INFO, "OBD_OBJECT_EOF = %#llx\n", (__u64)OBD_OBJECT_EOF); diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c index fc59f29a4290..57951237def2 100644 --- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c +++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c @@ -501,6 +501,7 @@ int class_procfs_init(void) rc = debugfs_lustre_root ? PTR_ERR(debugfs_lustre_root) : -ENOMEM; debugfs_lustre_root = NULL; + sysfs_remove_group(lustre_kobj, &lustre_attr_group); kobject_put(lustre_kobj); goto out; } @@ -509,6 +510,7 @@ int class_procfs_init(void) &obd_device_list_fops); if (IS_ERR_OR_NULL(file)) { rc = file ? PTR_ERR(file) : -ENOMEM; + sysfs_remove_group(lustre_kobj, &lustre_attr_group); kobject_put(lustre_kobj); goto out; } @@ -522,6 +524,7 @@ int class_procfs_clean(void) debugfs_lustre_root = NULL; + sysfs_remove_group(lustre_kobj, &lustre_attr_group); kobject_put(lustre_kobj); return 0; diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c index 05d71f568837..e1f4ef2bddd4 100644 --- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c @@ -1093,7 +1093,7 @@ int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid) LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0); percpusize = lprocfs_stats_counter_size(stats); - LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize); + stats->ls_percpu[cpuid] = kzalloc(percpusize, GFP_ATOMIC); if (stats->ls_percpu[cpuid]) { rc = 0; if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) { @@ -1137,7 +1137,8 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num, num_entry = num_possible_cpus(); /* alloc percpu pointers for all possible cpu slots */ - LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry])); + stats = kvzalloc(offsetof(typeof(*stats), ls_percpu[num_entry]), + GFP_KERNEL); if (!stats) return NULL; @@ -1146,15 +1147,16 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num, spin_lock_init(&stats->ls_lock); /* alloc num of counter headers */ - LIBCFS_ALLOC(stats->ls_cnt_header, - stats->ls_num * sizeof(struct lprocfs_counter_header)); + stats->ls_cnt_header = kvmalloc_array(stats->ls_num, + sizeof(struct lprocfs_counter_header), + GFP_KERNEL | __GFP_ZERO); if (!stats->ls_cnt_header) goto fail; if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) { /* contains only one set counters */ percpusize = lprocfs_stats_counter_size(stats); - LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize); + stats->ls_percpu[0] = kzalloc(percpusize, GFP_ATOMIC); if (!stats->ls_percpu[0]) goto fail; stats->ls_biggest_alloc_num = 1; @@ -1191,12 +1193,9 @@ void lprocfs_free_stats(struct lprocfs_stats **statsh) percpusize = lprocfs_stats_counter_size(stats); for (i = 0; i < num_entry; i++) - if (stats->ls_percpu[i]) - LIBCFS_FREE(stats->ls_percpu[i], percpusize); - if (stats->ls_cnt_header) - LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num * - sizeof(struct lprocfs_counter_header)); - LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry])); + kfree(stats->ls_percpu[i]); + kvfree(stats->ls_cnt_header); + kvfree(stats); } EXPORT_SYMBOL(lprocfs_free_stats); diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c index b938a3f9d50a..2719abbff85f 100644 --- a/drivers/staging/lustre/lustre/obdclass/lu_object.c +++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c @@ -1932,8 +1932,10 @@ int lu_global_init(void) LU_CONTEXT_KEY_INIT(&lu_global_key); result = lu_context_key_register(&lu_global_key); - if (result != 0) + if (result != 0) { + lu_ref_global_fini(); return result; + } /* * At this level, we don't know what tags are needed, so allocate them @@ -1943,17 +1945,31 @@ int lu_global_init(void) down_write(&lu_sites_guard); result = lu_env_init(&lu_shrink_env, LCT_SHRINKER); up_write(&lu_sites_guard); - if (result != 0) + if (result != 0) { + lu_context_key_degister(&lu_global_key); + lu_ref_global_fini(); return result; + } /* * seeks estimation: 3 seeks to read a record from oi, one to read * inode, one for ea. Unfortunately setting this high value results in * lu_object/inode cache consuming all the memory. */ - register_shrinker(&lu_site_shrinker); + result = register_shrinker(&lu_site_shrinker); + if (result != 0) { + /* Order explained in lu_global_fini(). */ + lu_context_key_degister(&lu_global_key); - return result; + down_write(&lu_sites_guard); + lu_env_fini(&lu_shrink_env); + up_write(&lu_sites_guard); + + lu_ref_global_fini(); + return result; + } + + return 0; } /** diff --git a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c index 71329adc0318..2d6da2431a09 100644 --- a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c +++ b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c @@ -181,8 +181,6 @@ EXPORT_SYMBOL(class_handle_free_cb); int class_handle_init(void) { struct handle_bucket *bucket; - struct timespec64 ts; - int seed[2]; LASSERT(!handle_hash); @@ -198,12 +196,7 @@ int class_handle_init(void) spin_lock_init(&bucket->lock); } - /** bug 21430: add randomness to the initial base */ - cfs_get_random_bytes(seed, sizeof(seed)); - ktime_get_ts64(&ts); - cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); - - cfs_get_random_bytes(&handle_base, sizeof(handle_base)); + get_random_bytes(&handle_base, sizeof(handle_base)); LASSERT(handle_base != 0ULL); return 0; diff --git a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c index c0e192ae22a9..997c0f9aafb5 100644 --- a/drivers/staging/lustre/lustre/obdclass/obd_config.c +++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c @@ -236,7 +236,7 @@ static int class_attach(struct lustre_cfg *lcfg) uuid = lustre_cfg_string(lcfg, 2); CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n", - MKSTR(typename), MKSTR(name), MKSTR(uuid)); + typename, name, uuid); obd = class_newdev(typename, name); if (IS_ERR(obd)) { diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c index 2a79a223b98a..acc1ea773c9c 100644 --- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c +++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c @@ -49,9 +49,9 @@ #include <lustre_disk.h> #include <uapi/linux/lustre/lustre_param.h> -static int (*client_fill_super)(struct super_block *sb, - struct vfsmount *mnt); - +static DEFINE_SPINLOCK(client_lock); +static struct module *client_mod; +static int (*client_fill_super)(struct super_block *sb); static void (*kill_super_cb)(struct super_block *sb); /**************** config llog ********************/ @@ -1107,20 +1107,14 @@ invalid: return -EINVAL; } -struct lustre_mount_data2 { - void *lmd2_data; - struct vfsmount *lmd2_mnt; -}; - /** This is the entry point for the mount call into Lustre. * This is called when a server or client is mounted, * and this is where we start setting things up. * @param data Mount options (e.g. -o flock,abort_recov) */ -static int lustre_fill_super(struct super_block *sb, void *data, int silent) +static int lustre_fill_super(struct super_block *sb, void *lmd2_data, int silent) { struct lustre_mount_data *lmd; - struct lustre_mount_data2 *lmd2 = data; struct lustre_sb_info *lsi; int rc; @@ -1143,17 +1137,22 @@ static int lustre_fill_super(struct super_block *sb, void *data, int silent) obd_zombie_barrier(); /* Figure out the lmd from the mount options */ - if (lmd_parse((lmd2->lmd2_data), lmd)) { + if (lmd_parse(lmd2_data, lmd)) { lustre_put_lsi(sb); rc = -EINVAL; goto out; } if (lmd_is_client(lmd)) { + bool have_client = false; CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile); if (!client_fill_super) request_module("lustre"); - if (!client_fill_super) { + spin_lock(&client_lock); + if (client_fill_super && try_module_get(client_mod)) + have_client = true; + spin_unlock(&client_lock); + if (!have_client) { LCONSOLE_ERROR_MSG(0x165, "Nothing registered for client mount! Is the 'lustre' module loaded?\n"); lustre_put_lsi(sb); rc = -ENODEV; @@ -1165,8 +1164,10 @@ static int lustre_fill_super(struct super_block *sb, void *data, int silent) } /* Connect and start */ /* (should always be ll_fill_super) */ - rc = (*client_fill_super)(sb, lmd2->lmd2_mnt); - /* c_f_s will call lustre_common_put_super on failure */ + rc = (*client_fill_super)(sb); + /* c_f_s will call lustre_common_put_super on failure, otherwise + * c_f_s will have taken another reference to the module */ + module_put(client_mod); } } else { CERROR("This is client-side-only module, cannot handle server mount.\n"); @@ -1192,29 +1193,23 @@ out: /* We can't call ll_fill_super by name because it lives in a module that * must be loaded after this one. */ -void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb, - struct vfsmount *mnt)) +void lustre_register_super_ops(struct module *mod, + int (*cfs)(struct super_block *sb), + void (*ksc)(struct super_block *sb)) { + spin_lock(&client_lock); + client_mod = mod; client_fill_super = cfs; + kill_super_cb = ksc; + spin_unlock(&client_lock); } -EXPORT_SYMBOL(lustre_register_client_fill_super); - -void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb)) -{ - kill_super_cb = cfs; -} -EXPORT_SYMBOL(lustre_register_kill_super_cb); +EXPORT_SYMBOL(lustre_register_super_ops); /***************** FS registration ******************/ static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags, const char *devname, void *data) { - struct lustre_mount_data2 lmd2 = { - .lmd2_data = data, - .lmd2_mnt = NULL - }; - - return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super); + return mount_nodev(fs_type, flags, data, lustre_fill_super); } static void lustre_kill_super(struct super_block *sb) @@ -1230,11 +1225,11 @@ static void lustre_kill_super(struct super_block *sb) /** Register the "lustre" fs type */ static struct file_system_type lustre_fs_type = { - .owner = THIS_MODULE, - .name = "lustre", - .mount = lustre_mount, - .kill_sb = lustre_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_RENAME_DOES_D_MOVE, + .owner = THIS_MODULE, + .name = "lustre", + .mount = lustre_mount, + .kill_sb = lustre_kill_super, + .fs_flags = FS_RENAME_DOES_D_MOVE, }; MODULE_ALIAS_FS("lustre"); diff --git a/drivers/staging/lustre/lustre/osc/osc_internal.h b/drivers/staging/lustre/lustre/osc/osc_internal.h index feda61bcdb9b..32db150fd42e 100644 --- a/drivers/staging/lustre/lustre/osc/osc_internal.h +++ b/drivers/staging/lustre/lustre/osc/osc_internal.h @@ -168,9 +168,9 @@ struct osc_device { /* Write stats is actually protected by client_obd's lock. */ struct osc_stats { - uint64_t os_lockless_writes; /* by bytes */ - uint64_t os_lockless_reads; /* by bytes */ - uint64_t os_lockless_truncates; /* by times */ + u64 os_lockless_writes; /* by bytes */ + u64 os_lockless_reads; /* by bytes */ + u64 os_lockless_truncates; /* by times */ } od_stats; /* configuration item(s) */ diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c index 53eda4c99142..45b1ebf33363 100644 --- a/drivers/staging/lustre/lustre/osc/osc_request.c +++ b/drivers/staging/lustre/lustre/osc/osc_request.c @@ -2844,7 +2844,9 @@ static int __init osc_init(void) if (rc) goto out_kmem; - register_shrinker(&osc_cache_shrinker); + rc = register_shrinker(&osc_cache_shrinker); + if (rc) + goto out_type; /* This is obviously too much memory, only prevent overflow here */ if (osc_reqpool_mem_max >= 1 << 12 || osc_reqpool_mem_max == 0) { diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c index 2a9f2f2ebaa8..bac4b2304bad 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/client.c +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c @@ -3067,7 +3067,7 @@ void ptlrpc_init_xid(void) spin_lock_init(&ptlrpc_last_xid_lock); if (now < YEAR_2004) { - cfs_get_random_bytes(&ptlrpc_last_xid, sizeof(ptlrpc_last_xid)); + get_random_bytes(&ptlrpc_last_xid, sizeof(ptlrpc_last_xid)); ptlrpc_last_xid >>= 2; ptlrpc_last_xid |= (1ULL << 61); } else { diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c index 77a3721beaee..134ee727e8b7 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c @@ -396,6 +396,8 @@ static struct shrinker pools_shrinker = { int sptlrpc_enc_pool_init(void) { + int rc; + /* * maximum capacity is 1/8 of total physical memory. * is the 1/8 a good number? @@ -432,9 +434,11 @@ int sptlrpc_enc_pool_init(void) if (!page_pools.epp_pools) return -ENOMEM; - register_shrinker(&pools_shrinker); + rc = register_shrinker(&pools_shrinker); + if (rc) + enc_pools_free(); - return 0; + return rc; } void sptlrpc_enc_pool_fini(void) |