From andreas.dilger at intel.com Wed Jan 3 03:30:55 2018 From: andreas.dilger at intel.com (Dilger, Andreas) Date: Wed, 3 Jan 2018 03:30:55 +0000 Subject: [lustre-devel] [PATCH] drivers: lustre: obdclass: simplify unregister_shrinker() usage In-Reply-To: <20171223111316.3386-1-akaraliou.dev@gmail.com> References: <20171223111316.3386-1-akaraliou.dev@gmail.com> Message-ID: On Dec 23, 2017, at 04:13, Aliaksei Karaliou wrote: > > lu_global_fini() explicitly uses knowledge about shrinker's > internals to make decision about calling of unregister_shrinker(). > Now this check was integrated into unregister_shrinker(), > so it is safe to call it against unregistered shrinker. > > Signed-off-by: Aliaksei Karaliou Reviewed-by: Andreas Dilger > --- > drivers/staging/lustre/lustre/obdclass/lu_object.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c > index 8e2e6b89e494..2719abbff85f 100644 > --- a/drivers/staging/lustre/lustre/obdclass/lu_object.c > +++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c > @@ -1977,8 +1977,7 @@ int lu_global_init(void) > */ > void lu_global_fini(void) > { > - if (lu_site_shrinker.nr_deferred) > - unregister_shrinker(&lu_site_shrinker); > + unregister_shrinker(&lu_site_shrinker); > lu_context_key_degister(&lu_global_key); > > /* > -- > 2.11.0 > Cheers, Andreas -- Andreas Dilger Lustre Principal Architect Intel Corporation From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 5 v2: 00/19] staging: lustre: use standard wait_event macros Message-ID: <151538168618.23920.8261096424342988792.stgit@noble> Hi, this is a revised version of the patch series I sent under a similar subject in mid December. Improvements are: - new wait_event_idle* macros are now in include/linux/wait.h which Ack from peterz. - *all* waits are now TASK_IDLE or TASK_INTERRUPTIBLE and so don't affect the load average. There is no need to choose whether load is appropriate or not in each case. - all l_wait_event() users are handled so l_wait_event() is removed. The one case I had left out before uses wait_event_idle_exclusive() with and option of using wait_event_idle_exclusive_lifo() is that ever gets approved. I think this set is ready to go. If you only review two patches, please review staging: lustre: simplify waiting in ldlm_completion_ast() and staging: lustre: remove back_to_sleep() as in both of those, the actual behaviour of the current code (as I understand it) doesn't seem to agree with comments/debug message, or just generally looks odd. Thanks, NeilBrown --- NeilBrown (19): sched/wait: add wait_event_idle() functions. staging: lustre: discard SVC_SIGNAL and related functions staging: lustre: replace simple cases of l_wait_event() with wait_event(). staging: lustre: discard cfs_time_seconds() staging: lustre: use wait_event_idle_timeout() where appropriate. staging: lustre: introduce and use l_wait_event_abortable() staging: lustre: simplify l_wait_event when intr handler but no timeout. staging: lustre: simplify waiting in ldlm_completion_ast() staging: lustre: open code polling loop instead of using l_wait_event() staging: lustre: simplify waiting in ptlrpc_invalidate_import() staging: lustre: remove back_to_sleep() staging: lustre: make polling loop in ptlrpc_unregister_bulk more obvious staging: lustre: use wait_event_idle_timeout in ptlrpcd() staging: lustre: improve waiting in sptlrpc_req_refresh_ctx staging: lustre: use explicit poll loop in ptlrpc_service_unlink_rqbd staging: lustre: use explicit poll loop in ptlrpc_unregister_reply staging: lustre: remove l_wait_event from ptlrpc_set_wait staging: lustre: replace l_wait_event_exclusive_head() with wait_event_idle_exclusive staging: lustre: remove l_wait_event() and related code .../lustre/include/linux/libcfs/libcfs_debug.h | 4 .../lustre/include/linux/libcfs/libcfs_time.h | 2 .../lustre/include/linux/libcfs/linux/linux-time.h | 7 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 8 - .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 4 .../staging/lustre/lnet/klnds/socklnd/socklnd.c | 6 .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 22 + drivers/staging/lustre/lnet/libcfs/debug.c | 2 drivers/staging/lustre/lnet/libcfs/fail.c | 2 drivers/staging/lustre/lnet/libcfs/tracefile.c | 4 drivers/staging/lustre/lnet/lnet/acceptor.c | 2 drivers/staging/lustre/lnet/lnet/api-ni.c | 4 drivers/staging/lustre/lnet/lnet/lib-move.c | 4 drivers/staging/lustre/lnet/lnet/net_fault.c | 14 - drivers/staging/lustre/lnet/lnet/peer.c | 2 drivers/staging/lustre/lnet/lnet/router.c | 8 - drivers/staging/lustre/lnet/selftest/conrpc.c | 4 drivers/staging/lustre/lnet/selftest/rpc.c | 2 drivers/staging/lustre/lnet/selftest/selftest.h | 2 drivers/staging/lustre/lnet/selftest/timer.c | 2 drivers/staging/lustre/lustre/include/lustre_dlm.h | 2 drivers/staging/lustre/lustre/include/lustre_lib.h | 296 ++------------------ drivers/staging/lustre/lustre/include/lustre_mdc.h | 2 drivers/staging/lustre/lustre/include/lustre_net.h | 8 - drivers/staging/lustre/lustre/ldlm/ldlm_flock.c | 30 -- drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 14 - drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 12 - drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 17 - drivers/staging/lustre/lustre/ldlm/ldlm_request.c | 55 +--- drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 14 - drivers/staging/lustre/lustre/llite/llite_lib.c | 23 +- drivers/staging/lustre/lustre/llite/statahead.c | 60 ++-- drivers/staging/lustre/lustre/lov/lov_object.c | 6 drivers/staging/lustre/lustre/lov/lov_request.c | 12 - drivers/staging/lustre/lustre/mdc/mdc_request.c | 5 drivers/staging/lustre/lustre/mgc/mgc_request.c | 19 - drivers/staging/lustre/lustre/obdclass/cl_io.c | 23 +- drivers/staging/lustre/lustre/obdclass/genops.c | 24 +- drivers/staging/lustre/lustre/obdclass/llog_obd.c | 5 .../staging/lustre/lustre/obdecho/echo_client.c | 2 drivers/staging/lustre/lustre/osc/osc_cache.c | 28 +- drivers/staging/lustre/lustre/osc/osc_object.c | 6 drivers/staging/lustre/lustre/osc/osc_page.c | 6 drivers/staging/lustre/lustre/osc/osc_request.c | 6 drivers/staging/lustre/lustre/ptlrpc/client.c | 101 +++---- drivers/staging/lustre/lustre/ptlrpc/events.c | 7 drivers/staging/lustre/lustre/ptlrpc/import.c | 51 +-- drivers/staging/lustre/lustre/ptlrpc/niobuf.c | 15 + .../staging/lustre/lustre/ptlrpc/pack_generic.c | 9 - drivers/staging/lustre/lustre/ptlrpc/pinger.c | 28 +- .../staging/lustre/lustre/ptlrpc/ptlrpc_internal.h | 2 drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 18 + drivers/staging/lustre/lustre/ptlrpc/recover.c | 12 - drivers/staging/lustre/lustre/ptlrpc/sec.c | 34 ++ drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 23 -- drivers/staging/lustre/lustre/ptlrpc/service.c | 84 +++--- include/linux/wait.h | 114 ++++++++ 57 files changed, 516 insertions(+), 762 deletions(-) -- Signature From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 01/19] sched/wait: add wait_event_idle() functions. In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209329.23920.16297706354917686170.stgit@noble> The new TASK_IDLE state (TASK_UNINTERRUPTIBLE | __TASK_NOLOAD) is not much used. One way to make it easier to use is to add wait_event*() family functions that make use of it. This patch adds: wait_event_idle() wait_event_idle_timeout() wait_event_idle_exclusive() wait_event_idle_exclusive_timeout() This set was chosen because lustre needs them before it can discard its own l_wait_event() macro. Acked-by: Peter Zijlstra (Intel) Signed-off-by: NeilBrown --- include/linux/wait.h | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/include/linux/wait.h b/include/linux/wait.h index 158715445ffb..ec7e7c65cee6 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -597,6 +597,120 @@ do { \ __ret; \ }) +/** + * wait_event_idle - wait for a condition without contributing to system load + * @wq_head: the waitqueue to wait on + * @condition: a C expression for the event to wait for + * + * The process is put to sleep (TASK_IDLE) until the + * @condition evaluates to true. + * The @condition is checked each time the waitqueue @wq_head is woken up. + * + * wake_up() has to be called after changing any variable that could + * change the result of the wait condition. + * + */ +#define wait_event_idle(wq_head, condition) \ +do { \ + might_sleep(); \ + if (!(condition)) \ + ___wait_event(wq_head, condition, TASK_IDLE, 0, 0, schedule()); \ +} while (0) + +/** + * wait_event_idle_exclusive - wait for a condition with contributing to system load + * @wq_head: the waitqueue to wait on + * @condition: a C expression for the event to wait for + * + * The process is put to sleep (TASK_IDLE) until the + * @condition evaluates to true. + * The @condition is checked each time the waitqueue @wq_head is woken up. + * + * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag + * set thus if other processes wait on the same list, when this + * process is woken further processes are not considered. + * + * wake_up() has to be called after changing any variable that could + * change the result of the wait condition. + * + */ +#define wait_event_idle_exclusive(wq_head, condition) \ +do { \ + might_sleep(); \ + if (!(condition)) \ + ___wait_event(wq_head, condition, TASK_IDLE, 1, 0, schedule()); \ +} while (0) + +#define __wait_event_idle_timeout(wq_head, condition, timeout) \ + ___wait_event(wq_head, ___wait_cond_timeout(condition), \ + TASK_IDLE, 0, timeout, \ + __ret = schedule_timeout(__ret)) + +/** + * wait_event_idle_timeout - sleep without load until a condition becomes true or a timeout elapses + * @wq_head: the waitqueue to wait on + * @condition: a C expression for the event to wait for + * @timeout: timeout, in jiffies + * + * The process is put to sleep (TASK_IDLE) until the + * @condition evaluates to true. The @condition is checked each time + * the waitqueue @wq_head is woken up. + * + * wake_up() has to be called after changing any variable that could + * change the result of the wait condition. + * + * Returns: + * 0 if the @condition evaluated to %false after the @timeout elapsed, + * 1 if the @condition evaluated to %true after the @timeout elapsed, + * or the remaining jiffies (at least 1) if the @condition evaluated + * to %true before the @timeout elapsed. + */ +#define wait_event_idle_timeout(wq_head, condition, timeout) \ +({ \ + long __ret = timeout; \ + might_sleep(); \ + if (!___wait_cond_timeout(condition)) \ + __ret = __wait_event_idle_timeout(wq_head, condition, timeout); \ + __ret; \ +}) + +#define __wait_event_idle_exclusive_timeout(wq_head, condition, timeout) \ + ___wait_event(wq_head, ___wait_cond_timeout(condition), \ + TASK_IDLE, 1, timeout, \ + __ret = schedule_timeout(__ret)) + +/** + * wait_event_idle_exclusive_timeout - sleep without load until a condition becomes true or a timeout elapses + * @wq_head: the waitqueue to wait on + * @condition: a C expression for the event to wait for + * @timeout: timeout, in jiffies + * + * The process is put to sleep (TASK_IDLE) until the + * @condition evaluates to true. The @condition is checked each time + * the waitqueue @wq_head is woken up. + * + * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag + * set thus if other processes wait on the same list, when this + * process is woken further processes are not considered. + * + * wake_up() has to be called after changing any variable that could + * change the result of the wait condition. + * + * Returns: + * 0 if the @condition evaluated to %false after the @timeout elapsed, + * 1 if the @condition evaluated to %true after the @timeout elapsed, + * or the remaining jiffies (at least 1) if the @condition evaluated + * to %true before the @timeout elapsed. + */ +#define wait_event_idle_exclusive_timeout(wq_head, condition, timeout) \ +({ \ + long __ret = timeout; \ + might_sleep(); \ + if (!___wait_cond_timeout(condition)) \ + __ret = __wait_event_idle_exclusive_timeout(wq_head, condition, timeout);\ + __ret; \ +}) + extern int do_wait_intr(wait_queue_head_t *, wait_queue_entry_t *); extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *); From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 02/19] staging: lustre: discard SVC_SIGNAL and related functions In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209333.23920.9948001896186855872.stgit@noble> This flag is never set, so remove checks and remove the flag. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/include/lustre_net.h | 6 ------ drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 4 +--- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h index 3ff5de4770e8..4c665eca2467 100644 --- a/drivers/staging/lustre/lustre/include/lustre_net.h +++ b/drivers/staging/lustre/lustre/include/lustre_net.h @@ -1260,7 +1260,6 @@ enum { SVC_STARTING = 1 << 2, SVC_RUNNING = 1 << 3, SVC_EVENT = 1 << 4, - SVC_SIGNAL = 1 << 5, }; #define PTLRPC_THR_NAME_LEN 32 @@ -1333,11 +1332,6 @@ static inline int thread_is_event(struct ptlrpc_thread *thread) return !!(thread->t_flags & SVC_EVENT); } -static inline int thread_is_signal(struct ptlrpc_thread *thread) -{ - return !!(thread->t_flags & SVC_SIGNAL); -} - static inline void thread_clear_flags(struct ptlrpc_thread *thread, __u32 flags) { thread->t_flags &= ~flags; diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c index 8d1e0edfcede..d85c8638c009 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c @@ -153,7 +153,6 @@ static int sec_gc_main(void *arg) while (1) { struct ptlrpc_sec *sec; - thread_clear_flags(thread, SVC_SIGNAL); sec_process_ctx_list(); again: /* go through sec list do gc. @@ -184,8 +183,7 @@ static int sec_gc_main(void *arg) lwi = LWI_TIMEOUT(msecs_to_jiffies(SEC_GC_INTERVAL * MSEC_PER_SEC), NULL, NULL); l_wait_event(thread->t_ctl_waitq, - thread_is_stopping(thread) || - thread_is_signal(thread), + thread_is_stopping(thread), &lwi); if (thread_test_and_clear_flags(thread, SVC_STOPPING)) From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 03/19] staging: lustre: replace simple cases of l_wait_event() with wait_event(). In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209336.23920.11626260931049480889.stgit@noble> When the lwi arg is full of zeros, l_wait_event() behaves almost identically to the standard wait_event_idle() interface, so use that instead. l_wait_event() uses TASK_INTERRUPTIBLE, but blocks all signals. wait_event_idle() uses the new TASK_IDLE and so avoids adding to the load average without needing to block signals. In one case, wait_event_idle_exclusive() is needed. Also remove all l_wait_condition*() macros which were short-cuts for setting lwi to {0}. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/include/lustre_lib.h | 19 -------- drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 4 -- drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 8 +-- drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 5 +- drivers/staging/lustre/lustre/llite/statahead.c | 50 ++++++++------------ drivers/staging/lustre/lustre/lov/lov_object.c | 6 +- drivers/staging/lustre/lustre/mgc/mgc_request.c | 4 -- drivers/staging/lustre/lustre/obdclass/cl_io.c | 6 +- drivers/staging/lustre/lustre/obdclass/genops.c | 15 ++---- drivers/staging/lustre/lustre/osc/osc_cache.c | 5 +- drivers/staging/lustre/lustre/osc/osc_object.c | 4 -- drivers/staging/lustre/lustre/ptlrpc/pinger.c | 10 ++-- drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 11 ++-- drivers/staging/lustre/lustre/ptlrpc/service.c | 13 ++--- 14 files changed, 53 insertions(+), 107 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h index ca1dce15337e..7d950c53e962 100644 --- a/drivers/staging/lustre/lustre/include/lustre_lib.h +++ b/drivers/staging/lustre/lustre/include/lustre_lib.h @@ -333,24 +333,7 @@ do { \ __ret; \ }) -#define l_wait_condition(wq, condition) \ -({ \ - struct l_wait_info lwi = { 0 }; \ - l_wait_event(wq, condition, &lwi); \ -}) - -#define l_wait_condition_exclusive(wq, condition) \ -({ \ - struct l_wait_info lwi = { 0 }; \ - l_wait_event_exclusive(wq, condition, &lwi); \ -}) - -#define l_wait_condition_exclusive_head(wq, condition) \ -({ \ - struct l_wait_info lwi = { 0 }; \ - l_wait_event_exclusive_head(wq, condition, &lwi); \ -}) - /** @} lib */ + #endif /* _LUSTRE_LIB_H */ diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c index 7cbc6a06afec..4f700ddb47c6 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c @@ -1913,14 +1913,12 @@ void ldlm_cancel_callback(struct ldlm_lock *lock) ldlm_set_bl_done(lock); wake_up_all(&lock->l_waitq); } else if (!ldlm_is_bl_done(lock)) { - struct l_wait_info lwi = { 0 }; - /* * The lock is guaranteed to have been canceled once * returning from this function. */ unlock_res_and_lock(lock); - l_wait_event(lock->l_waitq, is_bl_done(lock), &lwi); + wait_event_idle(lock->l_waitq, is_bl_done(lock)); lock_res_and_lock(lock); } } diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c index 5f6e7c933b81..6c7c4b19a0a0 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c @@ -833,17 +833,15 @@ static int ldlm_bl_thread_main(void *arg) /* cannot use bltd after this, it is only on caller's stack */ while (1) { - struct l_wait_info lwi = { 0 }; struct ldlm_bl_work_item *blwi = NULL; struct obd_export *exp = NULL; int rc; rc = ldlm_bl_get_work(blp, &blwi, &exp); if (!rc) - l_wait_event_exclusive(blp->blp_waitq, - ldlm_bl_get_work(blp, &blwi, - &exp), - &lwi); + wait_event_idle_exclusive(blp->blp_waitq, + ldlm_bl_get_work(blp, &blwi, + &exp)); atomic_inc(&blp->blp_busy_threads); if (ldlm_bl_thread_need_create(blp, blwi)) diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c index 8563bd32befa..f27c2694793a 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c @@ -1031,7 +1031,6 @@ static int ldlm_pools_thread_main(void *arg) static int ldlm_pools_thread_start(void) { - struct l_wait_info lwi = { 0 }; struct task_struct *task; if (ldlm_pools_thread) @@ -1052,8 +1051,8 @@ static int ldlm_pools_thread_start(void) ldlm_pools_thread = NULL; return PTR_ERR(task); } - l_wait_event(ldlm_pools_thread->t_ctl_waitq, - thread_is_running(ldlm_pools_thread), &lwi); + wait_event_idle(ldlm_pools_thread->t_ctl_waitq, + thread_is_running(ldlm_pools_thread)); return 0; } diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c index 90c7324575e4..78005cc6e831 100644 --- a/drivers/staging/lustre/lustre/llite/statahead.c +++ b/drivers/staging/lustre/lustre/llite/statahead.c @@ -864,7 +864,6 @@ static int ll_agl_thread(void *arg) struct ll_sb_info *sbi = ll_i2sbi(dir); struct ll_statahead_info *sai; struct ptlrpc_thread *thread; - struct l_wait_info lwi = { 0 }; sai = ll_sai_get(dir); thread = &sai->sai_agl_thread; @@ -885,10 +884,9 @@ static int ll_agl_thread(void *arg) wake_up(&thread->t_ctl_waitq); while (1) { - l_wait_event(thread->t_ctl_waitq, - !list_empty(&sai->sai_agls) || - !thread_is_running(thread), - &lwi); + wait_event_idle(thread->t_ctl_waitq, + !list_empty(&sai->sai_agls) || + !thread_is_running(thread)); if (!thread_is_running(thread)) break; @@ -932,7 +930,6 @@ static int ll_agl_thread(void *arg) static void ll_start_agl(struct dentry *parent, struct ll_statahead_info *sai) { struct ptlrpc_thread *thread = &sai->sai_agl_thread; - struct l_wait_info lwi = { 0 }; struct ll_inode_info *plli; struct task_struct *task; @@ -948,9 +945,8 @@ static void ll_start_agl(struct dentry *parent, struct ll_statahead_info *sai) return; } - l_wait_event(thread->t_ctl_waitq, - thread_is_running(thread) || thread_is_stopped(thread), - &lwi); + wait_event_idle(thread->t_ctl_waitq, + thread_is_running(thread) || thread_is_stopped(thread)); } /* statahead thread main function */ @@ -968,7 +964,6 @@ static int ll_statahead_thread(void *arg) int first = 0; int rc = 0; struct md_op_data *op_data; - struct l_wait_info lwi = { 0 }; sai = ll_sai_get(dir); sa_thread = &sai->sai_thread; @@ -1069,12 +1064,11 @@ static int ll_statahead_thread(void *arg) /* wait for spare statahead window */ do { - l_wait_event(sa_thread->t_ctl_waitq, - !sa_sent_full(sai) || - sa_has_callback(sai) || - !list_empty(&sai->sai_agls) || - !thread_is_running(sa_thread), - &lwi); + wait_event_idle(sa_thread->t_ctl_waitq, + !sa_sent_full(sai) || + sa_has_callback(sai) || + !list_empty(&sai->sai_agls) || + !thread_is_running(sa_thread)); sa_handle_callback(sai); spin_lock(&lli->lli_agl_lock); @@ -1128,11 +1122,10 @@ static int ll_statahead_thread(void *arg) * for file release to stop me. */ while (thread_is_running(sa_thread)) { - l_wait_event(sa_thread->t_ctl_waitq, - sa_has_callback(sai) || - !agl_list_empty(sai) || - !thread_is_running(sa_thread), - &lwi); + wait_event_idle(sa_thread->t_ctl_waitq, + sa_has_callback(sai) || + !agl_list_empty(sai) || + !thread_is_running(sa_thread)); sa_handle_callback(sai); } @@ -1145,9 +1138,8 @@ static int ll_statahead_thread(void *arg) CDEBUG(D_READA, "stop agl thread: sai %p pid %u\n", sai, (unsigned int)agl_thread->t_pid); - l_wait_event(agl_thread->t_ctl_waitq, - thread_is_stopped(agl_thread), - &lwi); + wait_event_idle(agl_thread->t_ctl_waitq, + thread_is_stopped(agl_thread)); } else { /* Set agl_thread flags anyway. */ thread_set_flags(agl_thread, SVC_STOPPED); @@ -1159,8 +1151,8 @@ static int ll_statahead_thread(void *arg) */ while (sai->sai_sent != sai->sai_replied) { /* in case we're not woken up, timeout wait */ - lwi = LWI_TIMEOUT(msecs_to_jiffies(MSEC_PER_SEC >> 3), - NULL, NULL); + struct l_wait_info lwi = LWI_TIMEOUT(msecs_to_jiffies(MSEC_PER_SEC >> 3), + NULL, NULL); l_wait_event(sa_thread->t_ctl_waitq, sai->sai_sent == sai->sai_replied, &lwi); } @@ -1520,7 +1512,6 @@ static int start_statahead_thread(struct inode *dir, struct dentry *dentry) { struct ll_inode_info *lli = ll_i2info(dir); struct ll_statahead_info *sai = NULL; - struct l_wait_info lwi = { 0 }; struct ptlrpc_thread *thread; struct task_struct *task; struct dentry *parent = dentry->d_parent; @@ -1570,9 +1561,8 @@ static int start_statahead_thread(struct inode *dir, struct dentry *dentry) goto out; } - l_wait_event(thread->t_ctl_waitq, - thread_is_running(thread) || thread_is_stopped(thread), - &lwi); + wait_event_idle(thread->t_ctl_waitq, + thread_is_running(thread) || thread_is_stopped(thread)); ll_sai_put(sai); /* diff --git a/drivers/staging/lustre/lustre/lov/lov_object.c b/drivers/staging/lustre/lustre/lov/lov_object.c index 897cf2cd4a24..86cd4f9fbd0c 100644 --- a/drivers/staging/lustre/lustre/lov/lov_object.c +++ b/drivers/staging/lustre/lustre/lov/lov_object.c @@ -723,15 +723,13 @@ static void lov_conf_unlock(struct lov_object *lov) static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov) { - struct l_wait_info lwi = { 0 }; - while (atomic_read(&lov->lo_active_ios) > 0) { CDEBUG(D_INODE, "file:" DFID " wait for active IO, now: %d.\n", PFID(lu_object_fid(lov2lu(lov))), atomic_read(&lov->lo_active_ios)); - l_wait_event(lov->lo_waitq, - atomic_read(&lov->lo_active_ios) == 0, &lwi); + wait_event_idle(lov->lo_waitq, + atomic_read(&lov->lo_active_ios) == 0); } return 0; } diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c index 79ff85feab64..b743aee62349 100644 --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c @@ -601,9 +601,7 @@ static int mgc_requeue_thread(void *data) config_log_put(cld_prev); /* Wait a bit to see if anyone else needs a requeue */ - lwi = (struct l_wait_info) { 0 }; - l_wait_event(rq_waitq, rq_state & (RQ_NOW | RQ_STOP), - &lwi); + wait_event_idle(rq_waitq, rq_state & (RQ_NOW | RQ_STOP)); spin_lock(&config_list_lock); } diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c index 6ec5218a18c1..902bad22013b 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_io.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c @@ -1110,10 +1110,8 @@ int cl_sync_io_wait(const struct lu_env *env, struct cl_sync_io *anchor, CERROR("IO failed: %d, still wait for %d remaining entries\n", rc, atomic_read(&anchor->csi_sync_nr)); - lwi = (struct l_wait_info) { 0 }; - (void)l_wait_event(anchor->csi_waitq, - atomic_read(&anchor->csi_sync_nr) == 0, - &lwi); + wait_event_idle(anchor->csi_waitq, + atomic_read(&anchor->csi_sync_nr) == 0); } else { rc = anchor->csi_sync_rc; } diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c index b1d6ba4a3190..3ff25b8d3b48 100644 --- a/drivers/staging/lustre/lustre/obdclass/genops.c +++ b/drivers/staging/lustre/lustre/obdclass/genops.c @@ -1237,12 +1237,10 @@ static int obd_zombie_is_idle(void) */ void obd_zombie_barrier(void) { - struct l_wait_info lwi = { 0 }; - if (obd_zombie_pid == current_pid()) /* don't wait for myself */ return; - l_wait_event(obd_zombie_waitq, obd_zombie_is_idle(), &lwi); + wait_event_idle(obd_zombie_waitq, obd_zombie_is_idle()); } EXPORT_SYMBOL(obd_zombie_barrier); @@ -1257,10 +1255,8 @@ static int obd_zombie_impexp_thread(void *unused) obd_zombie_pid = current_pid(); while (!test_bit(OBD_ZOMBIE_STOP, &obd_zombie_flags)) { - struct l_wait_info lwi = { 0 }; - - l_wait_event(obd_zombie_waitq, - !obd_zombie_impexp_check(NULL), &lwi); + wait_event_idle(obd_zombie_waitq, + !obd_zombie_impexp_check(NULL)); obd_zombie_impexp_cull(); /* @@ -1593,7 +1589,6 @@ static inline bool obd_mod_rpc_slot_avail(struct client_obd *cli, u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc, struct lookup_intent *it) { - struct l_wait_info lwi = LWI_INTR(NULL, NULL); bool close_req = false; u16 i, max; @@ -1631,8 +1626,8 @@ u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc, CDEBUG(D_RPCTRACE, "%s: sleeping for a modify RPC slot opc %u, max %hu\n", cli->cl_import->imp_obd->obd_name, opc, max); - l_wait_event(cli->cl_mod_rpcs_waitq, - obd_mod_rpc_slot_avail(cli, close_req), &lwi); + wait_event_idle(cli->cl_mod_rpcs_waitq, + obd_mod_rpc_slot_avail(cli, close_req)); } while (true); } EXPORT_SYMBOL(obd_get_mod_rpc_slot); diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c index 5767ac2a7d16..b8d5adca94e1 100644 --- a/drivers/staging/lustre/lustre/osc/osc_cache.c +++ b/drivers/staging/lustre/lustre/osc/osc_cache.c @@ -964,9 +964,8 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext, "%s: wait ext to %u timedout, recovery in progress?\n", cli_name(osc_cli(obj)), state); - lwi = LWI_INTR(NULL, NULL); - rc = l_wait_event(ext->oe_waitq, extent_wait_cb(ext, state), - &lwi); + wait_event_idle(ext->oe_waitq, extent_wait_cb(ext, state)); + rc = 0; } if (rc == 0 && ext->oe_rc < 0) rc = ext->oe_rc; diff --git a/drivers/staging/lustre/lustre/osc/osc_object.c b/drivers/staging/lustre/lustre/osc/osc_object.c index f82c87a77550..6c424f0290bb 100644 --- a/drivers/staging/lustre/lustre/osc/osc_object.c +++ b/drivers/staging/lustre/lustre/osc/osc_object.c @@ -454,12 +454,10 @@ struct lu_object *osc_object_alloc(const struct lu_env *env, int osc_object_invalidate(const struct lu_env *env, struct osc_object *osc) { - struct l_wait_info lwi = { 0 }; - CDEBUG(D_INODE, "Invalidate osc object: %p, # of active IOs: %d\n", osc, atomic_read(&osc->oo_nr_ios)); - l_wait_event(osc->oo_io_waitq, !atomic_read(&osc->oo_nr_ios), &lwi); + wait_event_idle(osc->oo_io_waitq, !atomic_read(&osc->oo_nr_ios)); /* Discard all dirty pages of this object. */ osc_cache_truncate_start(env, osc, 0, NULL); diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c index fe6b47bfe8be..af707cb2b62b 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c +++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c @@ -291,7 +291,6 @@ static struct ptlrpc_thread pinger_thread; int ptlrpc_start_pinger(void) { - struct l_wait_info lwi = { 0 }; struct task_struct *task; int rc; @@ -310,8 +309,8 @@ int ptlrpc_start_pinger(void) CERROR("cannot start pinger thread: rc = %d\n", rc); return rc; } - l_wait_event(pinger_thread.t_ctl_waitq, - thread_is_running(&pinger_thread), &lwi); + wait_event_idle(pinger_thread.t_ctl_waitq, + thread_is_running(&pinger_thread)); return 0; } @@ -320,7 +319,6 @@ static int ptlrpc_pinger_remove_timeouts(void); int ptlrpc_stop_pinger(void) { - struct l_wait_info lwi = { 0 }; int rc = 0; if (thread_is_init(&pinger_thread) || @@ -331,8 +329,8 @@ int ptlrpc_stop_pinger(void) thread_set_flags(&pinger_thread, SVC_STOPPING); wake_up(&pinger_thread.t_ctl_waitq); - l_wait_event(pinger_thread.t_ctl_waitq, - thread_is_stopped(&pinger_thread), &lwi); + wait_event_idle(pinger_thread.t_ctl_waitq, + thread_is_stopped(&pinger_thread)); return rc; } diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c index d85c8638c009..b61e1aa25e8c 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c @@ -197,7 +197,6 @@ static int sec_gc_main(void *arg) int sptlrpc_gc_init(void) { - struct l_wait_info lwi = { 0 }; struct task_struct *task; mutex_init(&sec_gc_mutex); @@ -214,18 +213,16 @@ int sptlrpc_gc_init(void) return PTR_ERR(task); } - l_wait_event(sec_gc_thread.t_ctl_waitq, - thread_is_running(&sec_gc_thread), &lwi); + wait_event_idle(sec_gc_thread.t_ctl_waitq, + thread_is_running(&sec_gc_thread)); return 0; } void sptlrpc_gc_fini(void) { - struct l_wait_info lwi = { 0 }; - thread_set_flags(&sec_gc_thread, SVC_STOPPING); wake_up(&sec_gc_thread.t_ctl_waitq); - l_wait_event(sec_gc_thread.t_ctl_waitq, - thread_is_stopped(&sec_gc_thread), &lwi); + wait_event_idle(sec_gc_thread.t_ctl_waitq, + thread_is_stopped(&sec_gc_thread)); } diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c index 63be6e7273f3..1f22926c1355 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/service.c +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c @@ -2233,7 +2233,7 @@ static int ptlrpc_hr_main(void *arg) wake_up(&ptlrpc_hr.hr_waitq); while (!ptlrpc_hr.hr_stopping) { - l_wait_condition(hrt->hrt_waitq, hrt_dont_sleep(hrt, &replies)); + wait_event_idle(hrt->hrt_waitq, hrt_dont_sleep(hrt, &replies)); while (!list_empty(&replies)) { struct ptlrpc_reply_state *rs; @@ -2312,7 +2312,6 @@ static int ptlrpc_start_hr_threads(void) static void ptlrpc_svcpt_stop_threads(struct ptlrpc_service_part *svcpt) { - struct l_wait_info lwi = { 0 }; struct ptlrpc_thread *thread; LIST_HEAD(zombie); @@ -2341,8 +2340,8 @@ static void ptlrpc_svcpt_stop_threads(struct ptlrpc_service_part *svcpt) CDEBUG(D_INFO, "waiting for stopping-thread %s #%u\n", svcpt->scp_service->srv_thread_name, thread->t_id); - l_wait_event(thread->t_ctl_waitq, - thread_is_stopped(thread), &lwi); + wait_event_idle(thread->t_ctl_waitq, + thread_is_stopped(thread)); spin_lock(&svcpt->scp_lock); } @@ -2403,7 +2402,6 @@ int ptlrpc_start_threads(struct ptlrpc_service *svc) int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait) { - struct l_wait_info lwi = { 0 }; struct ptlrpc_thread *thread; struct ptlrpc_service *svc; struct task_struct *task; @@ -2499,9 +2497,8 @@ int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait) if (!wait) return 0; - l_wait_event(thread->t_ctl_waitq, - thread_is_running(thread) || thread_is_stopped(thread), - &lwi); + wait_event_idle(thread->t_ctl_waitq, + thread_is_running(thread) || thread_is_stopped(thread)); rc = thread_is_stopped(thread) ? thread->t_id : 0; return rc; From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 04/19] staging: lustre: discard cfs_time_seconds() In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209341.23920.8613572158448297057.stgit@noble> cfs_time_seconds() converts a number of seconds to the matching number of jiffies. The standard way to do this in Linux is "* HZ". So discard cfs_time_seconds() and use "* HZ" instead. Signed-off-by: NeilBrown --- .../lustre/include/linux/libcfs/libcfs_debug.h | 4 ++-- .../lustre/include/linux/libcfs/libcfs_time.h | 2 +- .../lustre/include/linux/libcfs/linux/linux-time.h | 7 +----- .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 8 ++++--- .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 4 ++-- .../staging/lustre/lnet/klnds/socklnd/socklnd.c | 6 +++-- .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 22 ++++++++++---------- drivers/staging/lustre/lnet/libcfs/debug.c | 2 +- drivers/staging/lustre/lnet/libcfs/fail.c | 2 +- drivers/staging/lustre/lnet/libcfs/tracefile.c | 4 ++-- drivers/staging/lustre/lnet/lnet/acceptor.c | 2 +- drivers/staging/lustre/lnet/lnet/api-ni.c | 4 ++-- drivers/staging/lustre/lnet/lnet/lib-move.c | 4 ++-- drivers/staging/lustre/lnet/lnet/net_fault.c | 14 +++++-------- drivers/staging/lustre/lnet/lnet/peer.c | 2 +- drivers/staging/lustre/lnet/lnet/router.c | 8 ++++--- drivers/staging/lustre/lnet/selftest/conrpc.c | 4 ++-- drivers/staging/lustre/lnet/selftest/rpc.c | 2 +- drivers/staging/lustre/lnet/selftest/selftest.h | 2 +- drivers/staging/lustre/lnet/selftest/timer.c | 2 +- drivers/staging/lustre/lustre/include/lustre_dlm.h | 2 +- drivers/staging/lustre/lustre/include/lustre_mdc.h | 2 +- drivers/staging/lustre/lustre/include/lustre_net.h | 2 +- drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 2 +- drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 4 ++-- drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 2 +- drivers/staging/lustre/lustre/ldlm/ldlm_request.c | 2 +- drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 2 +- drivers/staging/lustre/lustre/llite/llite_lib.c | 4 ++-- drivers/staging/lustre/lustre/llite/statahead.c | 2 +- drivers/staging/lustre/lustre/lov/lov_request.c | 4 ++-- drivers/staging/lustre/lustre/mdc/mdc_request.c | 2 +- drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- drivers/staging/lustre/lustre/obdclass/cl_io.c | 2 +- .../staging/lustre/lustre/obdecho/echo_client.c | 2 +- drivers/staging/lustre/lustre/osc/osc_cache.c | 4 ++-- drivers/staging/lustre/lustre/osc/osc_object.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/client.c | 10 +++++---- drivers/staging/lustre/lustre/ptlrpc/events.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/import.c | 15 ++++++-------- drivers/staging/lustre/lustre/ptlrpc/niobuf.c | 4 ++-- .../staging/lustre/lustre/ptlrpc/pack_generic.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/pinger.c | 8 ++++--- drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 4 ++-- drivers/staging/lustre/lustre/ptlrpc/recover.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/service.c | 8 ++++--- 46 files changed, 96 insertions(+), 106 deletions(-) diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h index 1b98f0953afb..9290a19429e7 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h @@ -66,8 +66,8 @@ extern unsigned int libcfs_panic_on_lbug; # define DEBUG_SUBSYSTEM S_UNDEFINED #endif -#define CDEBUG_DEFAULT_MAX_DELAY (cfs_time_seconds(600)) /* jiffies */ -#define CDEBUG_DEFAULT_MIN_DELAY ((cfs_time_seconds(1) + 1) / 2) /* jiffies */ +#define CDEBUG_DEFAULT_MAX_DELAY (600 * HZ) /* jiffies */ +#define CDEBUG_DEFAULT_MIN_DELAY ((HZ + 1) / 2) /* jiffies */ #define CDEBUG_DEFAULT_BACKOFF 2 struct cfs_debug_limit_state { unsigned long cdls_next; diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h index 9699646decb9..c4f25be78268 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h @@ -62,7 +62,7 @@ static inline int cfs_time_aftereq(unsigned long t1, unsigned long t2) static inline unsigned long cfs_time_shift(int seconds) { - return cfs_time_add(cfs_time_current(), cfs_time_seconds(seconds)); + return cfs_time_add(cfs_time_current(), seconds * HZ); } /* diff --git a/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h b/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h index aece13698eb4..805cb326af86 100644 --- a/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h +++ b/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h @@ -65,11 +65,6 @@ static inline unsigned long cfs_time_current(void) return jiffies; } -static inline long cfs_time_seconds(int seconds) -{ - return ((long)seconds) * msecs_to_jiffies(MSEC_PER_SEC); -} - static inline long cfs_duration_sec(long d) { return d / msecs_to_jiffies(MSEC_PER_SEC); @@ -85,7 +80,7 @@ static inline u64 cfs_time_add_64(u64 t, u64 d) static inline u64 cfs_time_shift_64(int seconds) { return cfs_time_add_64(cfs_time_current_64(), - cfs_time_seconds(seconds)); + seconds * HZ); } static inline int cfs_time_before_64(u64 t1, u64 t2) diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index bb7b19473e3a..8a49f7730308 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -1219,7 +1219,7 @@ static struct kib_hca_dev *kiblnd_current_hdev(struct kib_dev *dev) CDEBUG(D_NET, "%s: Wait for failover\n", dev->ibd_ifname); set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1) / 100); + schedule_timeout(HZ / 100); read_lock_irqsave(&kiblnd_data.kib_global_lock, flags); } @@ -1930,7 +1930,7 @@ struct list_head *kiblnd_pool_alloc_node(struct kib_poolset *ps) set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(interval); - if (interval < cfs_time_seconds(1)) + if (interval < HZ) interval *= 2; goto again; @@ -2567,7 +2567,7 @@ static void kiblnd_base_shutdown(void) "Waiting for %d threads to terminate\n", atomic_read(&kiblnd_data.kib_nthreads)); set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); } /* fall through */ @@ -2618,7 +2618,7 @@ static void kiblnd_shutdown(struct lnet_ni *ni) libcfs_nid2str(ni->ni_nid), atomic_read(&net->ibn_npeers)); set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); } kiblnd_net_fini_pools(net); diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c index 9b3328c5d1e7..0b30c205e760 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c @@ -3726,8 +3726,8 @@ kiblnd_failover_thread(void *arg) add_wait_queue(&kiblnd_data.kib_failover_waitq, &wait); write_unlock_irqrestore(glock, flags); - rc = schedule_timeout(long_sleep ? cfs_time_seconds(10) : - cfs_time_seconds(1)); + rc = schedule_timeout(long_sleep ? 10 * HZ : + HZ); remove_wait_queue(&kiblnd_data.kib_failover_waitq, &wait); write_lock_irqsave(glock, flags); diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c index 7dba949a95a7..6ab876d8c744 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c @@ -1677,7 +1677,7 @@ ksocknal_destroy_conn(struct ksock_conn *conn) switch (conn->ksnc_rx_state) { case SOCKNAL_RX_LNET_PAYLOAD: last_rcv = conn->ksnc_rx_deadline - - cfs_time_seconds(*ksocknal_tunables.ksnd_timeout); + *ksocknal_tunables.ksnd_timeout * HZ; CERROR("Completing partial receive from %s[%d], ip %pI4h:%d, with error, wanted: %zd, left: %d, last alive is %ld secs ago\n", libcfs_id2str(conn->ksnc_peer->ksnp_id), conn->ksnc_type, &conn->ksnc_ipaddr, conn->ksnc_port, @@ -2361,7 +2361,7 @@ ksocknal_base_shutdown(void) ksocknal_data.ksnd_nthreads); read_unlock(&ksocknal_data.ksnd_global_lock); set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); read_lock(&ksocknal_data.ksnd_global_lock); } read_unlock(&ksocknal_data.ksnd_global_lock); @@ -2604,7 +2604,7 @@ ksocknal_shutdown(struct lnet_ni *ni) "waiting for %d peers to disconnect\n", net->ksnn_npeers); set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); ksocknal_debug_peerhash(ni); diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c index 11fd3a36424f..63e452f666bf 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c @@ -189,7 +189,7 @@ ksocknal_transmit(struct ksock_conn *conn, struct ksock_tx *tx) if (ksocknal_data.ksnd_stall_tx) { set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(ksocknal_data.ksnd_stall_tx)); + schedule_timeout(ksocknal_data.ksnd_stall_tx * HZ); } LASSERT(tx->tx_resid); @@ -294,7 +294,7 @@ ksocknal_receive(struct ksock_conn *conn) if (ksocknal_data.ksnd_stall_rx) { set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(ksocknal_data.ksnd_stall_rx)); + schedule_timeout(ksocknal_data.ksnd_stall_rx * HZ); } rc = ksocknal_connsock_addref(conn); @@ -1780,7 +1780,7 @@ ksocknal_connect(struct ksock_route *route) int rc = 0; deadline = cfs_time_add(cfs_time_current(), - cfs_time_seconds(*ksocknal_tunables.ksnd_timeout)); + *ksocknal_tunables.ksnd_timeout * HZ); write_lock_bh(&ksocknal_data.ksnd_global_lock); @@ -1878,7 +1878,7 @@ ksocknal_connect(struct ksock_route *route) * so min_reconnectms should be good heuristic */ route->ksnr_retry_interval = - cfs_time_seconds(*ksocknal_tunables.ksnd_min_reconnectms) / 1000; + *ksocknal_tunables.ksnd_min_reconnectms * HZ / 1000; route->ksnr_timeout = cfs_time_add(cfs_time_current(), route->ksnr_retry_interval); } @@ -1899,10 +1899,10 @@ ksocknal_connect(struct ksock_route *route) route->ksnr_retry_interval *= 2; route->ksnr_retry_interval = max(route->ksnr_retry_interval, - cfs_time_seconds(*ksocknal_tunables.ksnd_min_reconnectms) / 1000); + (long)*ksocknal_tunables.ksnd_min_reconnectms * HZ / 1000); route->ksnr_retry_interval = min(route->ksnr_retry_interval, - cfs_time_seconds(*ksocknal_tunables.ksnd_max_reconnectms) / 1000); + (long)*ksocknal_tunables.ksnd_max_reconnectms * HZ / 1000); LASSERT(route->ksnr_retry_interval); route->ksnr_timeout = cfs_time_add(cfs_time_current(), @@ -1972,7 +1972,7 @@ ksocknal_connd_check_start(time64_t sec, long *timeout) if (sec - ksocknal_data.ksnd_connd_failed_stamp <= 1) { /* may run out of resource, retry later */ - *timeout = cfs_time_seconds(1); + *timeout = HZ; return 0; } @@ -2031,8 +2031,8 @@ ksocknal_connd_check_stop(time64_t sec, long *timeout) val = (int)(ksocknal_data.ksnd_connd_starting_stamp + SOCKNAL_CONND_TIMEOUT - sec); - *timeout = (val > 0) ? cfs_time_seconds(val) : - cfs_time_seconds(SOCKNAL_CONND_TIMEOUT); + *timeout = (val > 0) ? val * HZ : + SOCKNAL_CONND_TIMEOUT * HZ; if (val > 0) return 0; @@ -2307,7 +2307,7 @@ ksocknal_send_keepalive_locked(struct ksock_peer *peer) if (*ksocknal_tunables.ksnd_keepalive <= 0 || time_before(cfs_time_current(), cfs_time_add(peer->ksnp_last_alive, - cfs_time_seconds(*ksocknal_tunables.ksnd_keepalive)))) + *ksocknal_tunables.ksnd_keepalive * HZ))) return 0; if (time_before(cfs_time_current(), peer->ksnp_send_keepalive)) @@ -2563,7 +2563,7 @@ ksocknal_reaper(void *arg) ksocknal_data.ksnd_peer_hash_size; } - deadline = cfs_time_add(deadline, cfs_time_seconds(p)); + deadline = cfs_time_add(deadline, p * HZ); } if (nenomem_conns) { diff --git a/drivers/staging/lustre/lnet/libcfs/debug.c b/drivers/staging/lustre/lnet/libcfs/debug.c index 551c45bf4108..c70d2ae29b11 100644 --- a/drivers/staging/lustre/lnet/libcfs/debug.c +++ b/drivers/staging/lustre/lnet/libcfs/debug.c @@ -113,7 +113,7 @@ static int param_set_delay_minmax(const char *val, if (rc) return -EINVAL; - d = cfs_time_seconds(sec) / 100; + d = sec * HZ / 100; if (d < min || d > max) return -EINVAL; diff --git a/drivers/staging/lustre/lnet/libcfs/fail.c b/drivers/staging/lustre/lnet/libcfs/fail.c index 39439b303d65..d3f1e866c6a7 100644 --- a/drivers/staging/lustre/lnet/libcfs/fail.c +++ b/drivers/staging/lustre/lnet/libcfs/fail.c @@ -134,7 +134,7 @@ int __cfs_fail_timeout_set(u32 id, u32 value, int ms, int set) CERROR("cfs_fail_timeout id %x sleeping for %dms\n", id, ms); set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(ms) / 1000); + schedule_timeout(ms * HZ / 1000); CERROR("cfs_fail_timeout id %x awake\n", id); } return ret; diff --git a/drivers/staging/lustre/lnet/libcfs/tracefile.c b/drivers/staging/lustre/lnet/libcfs/tracefile.c index da2844f37edf..8c33c8fa66e2 100644 --- a/drivers/staging/lustre/lnet/libcfs/tracefile.c +++ b/drivers/staging/lustre/lnet/libcfs/tracefile.c @@ -441,7 +441,7 @@ int libcfs_debug_vmsg2(struct libcfs_debug_msg_data *msgdata, if (cfs_time_after(cfs_time_current(), cdls->cdls_next + libcfs_console_max_delay + - cfs_time_seconds(10))) { + 10 * HZ)) { /* last timeout was a long time ago */ cdls->cdls_delay /= libcfs_console_backoff * 4; } else { @@ -1071,7 +1071,7 @@ static int tracefiled(void *arg) init_waitqueue_entry(&__wait, current); add_wait_queue(&tctl->tctl_waitq, &__wait); set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); remove_wait_queue(&tctl->tctl_waitq, &__wait); } complete(&tctl->tctl_stop); diff --git a/drivers/staging/lustre/lnet/lnet/acceptor.c b/drivers/staging/lustre/lnet/lnet/acceptor.c index ee85cab6f437..6c1f4941d4ba 100644 --- a/drivers/staging/lustre/lnet/lnet/acceptor.c +++ b/drivers/staging/lustre/lnet/lnet/acceptor.c @@ -365,7 +365,7 @@ lnet_acceptor(void *arg) if (rc != -EAGAIN) { CWARN("Accept error %d: pausing...\n", rc); set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); } continue; } diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c index 6a1fb0397604..ddd37eae63c6 100644 --- a/drivers/staging/lustre/lnet/lnet/api-ni.c +++ b/drivers/staging/lustre/lnet/lnet/api-ni.c @@ -973,7 +973,7 @@ lnet_ping_md_unlink(struct lnet_ping_info *pinfo, while (pinfo->pi_features != LNET_PING_FEAT_INVAL) { CDEBUG(D_NET, "Still waiting for ping MD to unlink\n"); set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); } cfs_restore_sigs(blocked); @@ -1112,7 +1112,7 @@ lnet_clear_zombies_nis_locked(void) libcfs_nid2str(ni->ni_nid)); } set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); lnet_net_lock(LNET_LOCK_EX); continue; } diff --git a/drivers/staging/lustre/lnet/lnet/lib-move.c b/drivers/staging/lustre/lnet/lnet/lib-move.c index d724c4c73ecc..7fe7ae917273 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-move.c +++ b/drivers/staging/lustre/lnet/lnet/lib-move.c @@ -524,7 +524,7 @@ lnet_peer_is_alive(struct lnet_peer *lp, unsigned long now) return 0; deadline = cfs_time_add(lp->lp_last_alive, - cfs_time_seconds(lp->lp_ni->ni_peertimeout)); + lp->lp_ni->ni_peertimeout * HZ); alive = cfs_time_after(deadline, now); /* Update obsolete lp_alive except for routers assumed to be dead @@ -562,7 +562,7 @@ lnet_peer_alive_locked(struct lnet_peer *lp) unsigned long next_query = cfs_time_add(lp->lp_last_query, - cfs_time_seconds(lnet_queryinterval)); + lnet_queryinterval * HZ); if (time_before(now, next_query)) { if (lp->lp_alive) diff --git a/drivers/staging/lustre/lnet/lnet/net_fault.c b/drivers/staging/lustre/lnet/lnet/net_fault.c index e3468cef273b..a63b7941d435 100644 --- a/drivers/staging/lustre/lnet/lnet/net_fault.c +++ b/drivers/staging/lustre/lnet/lnet/net_fault.c @@ -315,9 +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( - prandom_u32_max(attr->u.drop.da_interval)); - rule->dr_time_base += cfs_time_seconds(attr->u.drop.da_interval); + prandom_u32_max(attr->u.drop.da_interval) * HZ; + rule->dr_time_base += attr->u.drop.da_interval * HZ; CDEBUG(D_NET, "Drop Rule %s->%s: next drop : %lu\n", libcfs_nid2str(attr->fa_src), @@ -440,8 +439,7 @@ static struct delay_daemon_data delay_dd; static unsigned long round_timeout(unsigned long timeout) { - return cfs_time_seconds((unsigned int) - cfs_duration_sec(cfs_time_sub(timeout, 0)) + 1); + return (unsigned int)rounddown(timeout, HZ) + HZ; } static void @@ -483,10 +481,8 @@ 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( - prandom_u32_max( - attr->u.delay.la_interval)); - rule->dl_time_base += cfs_time_seconds(attr->u.delay.la_interval); + prandom_u32_max(attr->u.delay.la_interval) * HZ; + rule->dl_time_base += attr->u.delay.la_interval * HZ; CDEBUG(D_NET, "Delay Rule %s->%s: next delay : %lu\n", libcfs_nid2str(attr->fa_src), diff --git a/drivers/staging/lustre/lnet/lnet/peer.c b/drivers/staging/lustre/lnet/lnet/peer.c index 19fcbcf0f642..89610f768b4f 100644 --- a/drivers/staging/lustre/lnet/lnet/peer.c +++ b/drivers/staging/lustre/lnet/lnet/peer.c @@ -137,7 +137,7 @@ lnet_peer_table_deathrow_wait_locked(struct lnet_peer_table *ptable, ptable->pt_zombies); } set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1) >> 1); + schedule_timeout(HZ >> 1); lnet_net_lock(cpt_locked); } } diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c index 476d6d296037..47a98d50ebc7 100644 --- a/drivers/staging/lustre/lnet/lnet/router.c +++ b/drivers/staging/lustre/lnet/lnet/router.c @@ -808,7 +808,7 @@ lnet_wait_known_routerstate(void) return; set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); } } @@ -1011,7 +1011,7 @@ lnet_ping_router_locked(struct lnet_peer *rtr) if (secs && !rtr->lp_ping_notsent && cfs_time_after(now, cfs_time_add(rtr->lp_ping_timestamp, - cfs_time_seconds(secs)))) { + secs * HZ))) { int rc; struct lnet_process_id id; struct lnet_handle_md mdh; @@ -1185,7 +1185,7 @@ lnet_prune_rc_data(int wait_unlink) CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET, "Waiting for rc buffers to unlink\n"); set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1) / 4); + schedule_timeout(HZ / 4); lnet_net_lock(LNET_LOCK_EX); } @@ -1282,7 +1282,7 @@ lnet_router_checker(void *arg) else wait_event_interruptible_timeout(the_lnet.ln_rc_waitq, false, - cfs_time_seconds(1)); + HZ); } lnet_prune_rc_data(1); /* wait for UNLINK */ diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c index 7aa515c34594..6dcc966b293b 100644 --- a/drivers/staging/lustre/lnet/selftest/conrpc.c +++ b/drivers/staging/lustre/lnet/selftest/conrpc.c @@ -359,7 +359,7 @@ lstcon_rpc_trans_postwait(struct lstcon_rpc_trans *trans, int timeout) rc = wait_event_interruptible_timeout(trans->tas_waitq, lstcon_rpc_trans_check(trans), - cfs_time_seconds(timeout)); + timeout * HZ); rc = (rc > 0) ? 0 : ((rc < 0) ? -EINTR : -ETIMEDOUT); mutex_lock(&console_session.ses_mutex); @@ -1350,7 +1350,7 @@ lstcon_rpc_cleanup_wait(void) CWARN("Session is shutting down, waiting for termination of transactions\n"); set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); mutex_lock(&console_session.ses_mutex); } diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c index b515138dca2c..18e0f1b87fc1 100644 --- a/drivers/staging/lustre/lnet/selftest/rpc.c +++ b/drivers/staging/lustre/lnet/selftest/rpc.c @@ -1605,7 +1605,7 @@ srpc_startup(void) /* 1 second pause to avoid timestamp reuse */ set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); srpc_data.rpc_matchbits = ((__u64)ktime_get_real_seconds()) << 48; srpc_data.rpc_state = SRPC_STATE_NONE; diff --git a/drivers/staging/lustre/lnet/selftest/selftest.h b/drivers/staging/lustre/lnet/selftest/selftest.h index ad04534f000c..05466b85e1c0 100644 --- a/drivers/staging/lustre/lnet/selftest/selftest.h +++ b/drivers/staging/lustre/lnet/selftest/selftest.h @@ -575,7 +575,7 @@ swi_state2str(int state) #define selftest_wait_events() \ do { \ set_current_state(TASK_UNINTERRUPTIBLE); \ - schedule_timeout(cfs_time_seconds(1) / 10); \ + schedule_timeout(HZ / 10); \ } while (0) #define lst_wait_until(cond, lock, fmt, ...) \ diff --git a/drivers/staging/lustre/lnet/selftest/timer.c b/drivers/staging/lustre/lnet/selftest/timer.c index ab125a8524c5..9716afeb3c94 100644 --- a/drivers/staging/lustre/lnet/selftest/timer.c +++ b/drivers/staging/lustre/lnet/selftest/timer.c @@ -177,7 +177,7 @@ stt_timer_main(void *arg) rc = wait_event_timeout(stt_data.stt_waitq, stt_data.stt_shuttingdown, - cfs_time_seconds(STTIMER_SLOTTIME)); + STTIMER_SLOTTIME * HZ); } spin_lock(&stt_data.stt_lock); diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h index e0b17052b2ea..239aa2b1268f 100644 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h @@ -60,7 +60,7 @@ struct obd_device; #define OBD_LDLM_DEVICENAME "ldlm" #define LDLM_DEFAULT_LRU_SIZE (100 * num_online_cpus()) -#define LDLM_DEFAULT_MAX_ALIVE (cfs_time_seconds(3900)) /* 65 min */ +#define LDLM_DEFAULT_MAX_ALIVE (65 * 60 * HZ) /* 65 min */ #define LDLM_DEFAULT_PARALLEL_AST_LIMIT 1024 /** diff --git a/drivers/staging/lustre/lustre/include/lustre_mdc.h b/drivers/staging/lustre/lustre/include/lustre_mdc.h index 007e1ec3f0f4..a9c9992a2502 100644 --- a/drivers/staging/lustre/lustre/include/lustre_mdc.h +++ b/drivers/staging/lustre/lustre/include/lustre_mdc.h @@ -124,7 +124,7 @@ static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck, */ while (unlikely(lck->rpcl_it == MDC_FAKE_RPCL_IT)) { mutex_unlock(&lck->rpcl_mutex); - schedule_timeout(cfs_time_seconds(1) / 4); + schedule_timeout(HZ / 4); goto again; } diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h index 4c665eca2467..5a4434e7c85a 100644 --- a/drivers/staging/lustre/lustre/include/lustre_net.h +++ b/drivers/staging/lustre/lustre/include/lustre_net.h @@ -2262,7 +2262,7 @@ static inline int ptlrpc_send_limit_expired(struct ptlrpc_request *req) { if (req->rq_delay_limit != 0 && time_before(cfs_time_add(req->rq_queued_time, - cfs_time_seconds(req->rq_delay_limit)), + req->rq_delay_limit * HZ), cfs_time_current())) { return 1; } diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c index 4f700ddb47c6..773abe78708a 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c @@ -1366,7 +1366,7 @@ enum ldlm_mode ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags, } } - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(obd_timeout), + lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, NULL, LWI_ON_SIGNAL_NOOP, NULL); /* XXX FIXME see comment on CAN_MATCH in lustre_dlm.h */ diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c index 6c7c4b19a0a0..58913e628124 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c @@ -163,7 +163,7 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req, LDLM_DEBUG(lock, "client completion callback handler START"); if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE)) { - int to = cfs_time_seconds(1); + int to = HZ; while (to > 0) { set_current_state(TASK_INTERRUPTIBLE); @@ -327,7 +327,7 @@ static void ldlm_handle_gl_callback(struct ptlrpc_request *req, !lock->l_readers && !lock->l_writers && cfs_time_after(cfs_time_current(), cfs_time_add(lock->l_last_used, - cfs_time_seconds(10)))) { + 10 * HZ))) { unlock_res_and_lock(lock); if (ldlm_bl_to_thread_lock(ns, NULL, lock)) ldlm_handle_bl_callback(ns, NULL, lock); diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c index f27c2694793a..622245a5f049 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c @@ -1008,7 +1008,7 @@ static int ldlm_pools_thread_main(void *arg) * Wait until the next check time, or until we're * stopped. */ - lwi = LWI_TIMEOUT(cfs_time_seconds(c_time), + lwi = LWI_TIMEOUT(c_time * HZ, NULL, NULL); l_wait_event(thread->t_ctl_waitq, thread_is_stopping(thread) || diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c index 6aa37463db46..a244fa717134 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c @@ -288,7 +288,7 @@ int ldlm_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) LDLM_DEBUG(lock, "waiting indefinitely because of NO_TIMEOUT"); lwi = LWI_INTR(interrupted_completion_wait, &lwd); } else { - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(timeout), + lwi = LWI_TIMEOUT_INTR(timeout * HZ, ldlm_expired_completion_wait, interrupted_completion_wait, &lwd); } diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c index 9958533cc227..2e66825c8f4b 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c @@ -799,7 +799,7 @@ static void cleanup_resource(struct ldlm_resource *res, struct list_head *q, LDLM_DEBUG(lock, "setting FL_LOCAL_ONLY"); if (lock->l_flags & LDLM_FL_FAIL_LOC) { set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(4)); + schedule_timeout(4 * HZ); set_current_state(TASK_RUNNING); } if (lock->l_completion_ast) diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c index 6735a6f006d2..0a9183f271f5 100644 --- a/drivers/staging/lustre/lustre/llite/llite_lib.c +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c @@ -2026,8 +2026,8 @@ void ll_umount_begin(struct super_block *sb) * to decrement mnt_cnt and hope to finish it within 10sec. */ init_waitqueue_head(&waitq); - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(10), - cfs_time_seconds(1), NULL, NULL); + lwi = LWI_TIMEOUT_INTERVAL(10 * HZ, + HZ, NULL, NULL); l_wait_event(waitq, may_umount(sbi->ll_mnt.mnt), &lwi); schedule(); diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c index 78005cc6e831..96360f104b92 100644 --- a/drivers/staging/lustre/lustre/llite/statahead.c +++ b/drivers/staging/lustre/lustre/llite/statahead.c @@ -1424,7 +1424,7 @@ static int revalidate_statahead_dentry(struct inode *dir, spin_lock(&lli->lli_sa_lock); sai->sai_index_wait = entry->se_index; spin_unlock(&lli->lli_sa_lock); - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(30), NULL, + lwi = LWI_TIMEOUT_INTR(30 * HZ, NULL, LWI_ON_SIGNAL_NOOP, NULL); rc = l_wait_event(sai->sai_waitq, sa_ready(entry), &lwi); if (rc < 0) { diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c index cfa1d7f92b0f..fb3b7a7fa32a 100644 --- a/drivers/staging/lustre/lustre/lov/lov_request.c +++ b/drivers/staging/lustre/lustre/lov/lov_request.c @@ -126,8 +126,8 @@ static int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx) mutex_unlock(&lov->lov_lock); init_waitqueue_head(&waitq); - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(obd_timeout), - cfs_time_seconds(1), NULL, NULL); + lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ, + HZ, NULL, NULL); rc = l_wait_event(waitq, lov_check_set(lov, ost_idx), &lwi); if (tgt->ltd_active) diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c index 03e55bca4ada..b12518ba5ae9 100644 --- a/drivers/staging/lustre/lustre/mdc/mdc_request.c +++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c @@ -888,7 +888,7 @@ static int mdc_getpage(struct obd_export *exp, const struct lu_fid *fid, exp->exp_obd->obd_name, -EIO); return -EIO; } - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends), NULL, NULL, + lwi = LWI_TIMEOUT_INTR(resends * HZ, NULL, NULL, NULL); l_wait_event(waitq, 0, &lwi); diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c index b743aee62349..a01d13bde102 100644 --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c @@ -1628,7 +1628,7 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld) if (rcl == -ESHUTDOWN && atomic_read(&mgc->u.cli.cl_mgc_refcount) > 0 && !retry) { - int secs = cfs_time_seconds(obd_timeout); + int secs = obd_timeout * HZ; struct obd_import *imp; struct l_wait_info lwi; diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c index 902bad22013b..ce5e7bdda692 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_io.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c @@ -1097,7 +1097,7 @@ EXPORT_SYMBOL(cl_sync_io_init); int cl_sync_io_wait(const struct lu_env *env, struct cl_sync_io *anchor, long timeout) { - struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(timeout), + struct l_wait_info lwi = LWI_TIMEOUT_INTR(timeout * HZ, NULL, NULL, NULL); int rc; diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c index b9c1dc7e61b0..9c5ce5074b66 100644 --- a/drivers/staging/lustre/lustre/obdecho/echo_client.c +++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c @@ -752,7 +752,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env, spin_unlock(&ec->ec_lock); CERROR("echo_client still has objects at cleanup time, wait for 1 second\n"); set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(1)); + schedule_timeout(HZ); lu_site_purge(env, ed->ed_site, -1); spin_lock(&ec->ec_lock); } diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c index b8d5adca94e1..0797e671f667 100644 --- a/drivers/staging/lustre/lustre/osc/osc_cache.c +++ b/drivers/staging/lustre/lustre/osc/osc_cache.c @@ -934,7 +934,7 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext, enum osc_extent_state state) { struct osc_object *obj = ext->oe_obj; - struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(600), NULL, + struct l_wait_info lwi = LWI_TIMEOUT_INTR(600 * HZ, NULL, LWI_ON_SIGNAL_NOOP, NULL); int rc = 0; @@ -1571,7 +1571,7 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli, struct l_wait_info lwi; int rc = -EDQUOT; - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(AT_OFF ? obd_timeout : at_max), + lwi = LWI_TIMEOUT_INTR((AT_OFF ? obd_timeout : at_max) * HZ, NULL, LWI_ON_SIGNAL_NOOP, NULL); OSC_DUMP_GRANT(D_CACHE, cli, "need:%d\n", bytes); diff --git a/drivers/staging/lustre/lustre/osc/osc_object.c b/drivers/staging/lustre/lustre/osc/osc_object.c index 6c424f0290bb..6baa8e2e00c9 100644 --- a/drivers/staging/lustre/lustre/osc/osc_object.c +++ b/drivers/staging/lustre/lustre/osc/osc_object.c @@ -328,7 +328,7 @@ int osc_object_is_contended(struct osc_object *obj) * ll_file_is_contended. */ retry_time = cfs_time_add(obj->oo_contention_time, - cfs_time_seconds(osc_contention_time)); + osc_contention_time * HZ); if (cfs_time_after(cur_time, retry_time)) { osc_object_clear_contended(obj); return 0; diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c index bac4b2304bad..0ab13f8e5993 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/client.c +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c @@ -766,7 +766,7 @@ int ptlrpc_request_bufs_pack(struct ptlrpc_request *request, * fail_loc */ set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(cfs_time_seconds(2)); + schedule_timeout(2 * HZ); set_current_state(TASK_RUNNING); } } @@ -2284,7 +2284,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) * We still want to block for a limited time, * so we allow interrupts during the timeout. */ - lwi = LWI_TIMEOUT_INTR_ALL(cfs_time_seconds(1), + lwi = LWI_TIMEOUT_INTR_ALL(HZ, ptlrpc_expired_set, ptlrpc_interrupted_set, set); else @@ -2293,7 +2293,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) * interrupts are allowed. Wait until all * complete, or an in-flight req times out. */ - lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1), + lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, ptlrpc_expired_set, set); rc = l_wait_event(set->set_waitq, ptlrpc_check_set(NULL, set), &lwi); @@ -2538,8 +2538,8 @@ static int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async) * Network access will complete in finite time but the HUGE * timeout lets us CWARN for visibility of sluggish NALs */ - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(LONG_UNLINK), - cfs_time_seconds(1), NULL, NULL); + lwi = LWI_TIMEOUT_INTERVAL(LONG_UNLINK * HZ, + HZ, NULL, NULL); rc = l_wait_event(*wq, !ptlrpc_client_recv_or_unlink(request), &lwi); if (rc == 0) { diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c index 811b7ab3a582..71f7588570ef 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/events.c +++ b/drivers/staging/lustre/lustre/ptlrpc/events.c @@ -517,7 +517,7 @@ static void ptlrpc_ni_fini(void) /* Wait for a bit */ init_waitqueue_head(&waitq); - lwi = LWI_TIMEOUT(cfs_time_seconds(2), NULL, NULL); + lwi = LWI_TIMEOUT(2 * HZ, NULL, NULL); l_wait_event(waitq, 0, &lwi); break; } diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c index 5b0f65536c29..0eba5f18bd3b 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/import.c +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c @@ -307,9 +307,9 @@ void ptlrpc_invalidate_import(struct obd_import *imp) * have been locally cancelled by ptlrpc_abort_inflight. */ lwi = LWI_TIMEOUT_INTERVAL( - cfs_timeout_cap(cfs_time_seconds(timeout)), - (timeout > 1) ? cfs_time_seconds(1) : - cfs_time_seconds(1) / 2, + cfs_timeout_cap(timeout * HZ), + (timeout > 1) ? HZ : + HZ / 2, NULL, NULL); rc = l_wait_event(imp->imp_recovery_waitq, (atomic_read(&imp->imp_inflight) == 0), @@ -431,7 +431,7 @@ void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt) int ptlrpc_reconnect_import(struct obd_import *imp) { struct l_wait_info lwi; - int secs = cfs_time_seconds(obd_timeout); + int secs = obd_timeout * HZ; int rc; ptlrpc_pinger_force(imp); @@ -1508,14 +1508,13 @@ int ptlrpc_disconnect_import(struct obd_import *imp, int noclose) if (AT_OFF) { if (imp->imp_server_timeout) - timeout = cfs_time_seconds(obd_timeout / 2); + timeout = obd_timeout * HZ / 2; else - timeout = cfs_time_seconds(obd_timeout); + timeout = obd_timeout * HZ; } else { int idx = import_at_get_index(imp, imp->imp_client->cli_request_portal); - timeout = cfs_time_seconds( - at_get(&imp->imp_at.iat_service_estimate[idx])); + timeout = at_get(&imp->imp_at.iat_service_estimate[idx]) * HZ; } lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(timeout), diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c index 047d712e850c..0c2ded721c49 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c +++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c @@ -270,8 +270,8 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async) /* Network access will complete in finite time but the HUGE * timeout lets us CWARN for visibility of sluggish LNDs */ - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(LONG_UNLINK), - cfs_time_seconds(1), NULL, NULL); + lwi = LWI_TIMEOUT_INTERVAL(LONG_UNLINK * HZ, + HZ, NULL, NULL); rc = l_wait_event(*wq, !ptlrpc_client_bulk_active(req), &lwi); if (rc == 0) { ptlrpc_rqphase_move(req, req->rq_next_phase); diff --git a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c index a64e125df95f..c060d6f5015a 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c +++ b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c @@ -267,7 +267,7 @@ lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt) /* If we cannot get anything for some long time, we better * bail out instead of waiting infinitely */ - lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL); + lwi = LWI_TIMEOUT(10 * HZ, NULL, NULL); rc = l_wait_event(svcpt->scp_rep_waitq, !list_empty(&svcpt->scp_rep_idle), &lwi); if (rc != 0) diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c index af707cb2b62b..010a1cdf05fa 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c +++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c @@ -141,7 +141,7 @@ static long pinger_check_timeout(unsigned long time) } mutex_unlock(&pinger_mutex); - return cfs_time_sub(cfs_time_add(time, cfs_time_seconds(timeout)), + return cfs_time_sub(cfs_time_add(time, timeout * HZ), cfs_time_current()); } @@ -247,7 +247,7 @@ static int ptlrpc_pinger_main(void *arg) if (imp->imp_pingable && imp->imp_next_ping && cfs_time_after(imp->imp_next_ping, cfs_time_add(this_ping, - cfs_time_seconds(PING_INTERVAL)))) + PING_INTERVAL * HZ))) ptlrpc_update_next_ping(imp, 0); } mutex_unlock(&pinger_mutex); @@ -264,10 +264,10 @@ static int ptlrpc_pinger_main(void *arg) CDEBUG(D_INFO, "next wakeup in " CFS_DURATION_T " (%ld)\n", time_to_next_wake, cfs_time_add(this_ping, - cfs_time_seconds(PING_INTERVAL))); + PING_INTERVAL * HZ)); if (time_to_next_wake > 0) { lwi = LWI_TIMEOUT(max_t(long, time_to_next_wake, - cfs_time_seconds(1)), + HZ), NULL, NULL); l_wait_event(thread->t_ctl_waitq, thread_is_stopping(thread) || diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c index 8b865294d933..dad2f9290f70 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c @@ -230,7 +230,7 @@ void ptlrpcd_add_req(struct ptlrpc_request *req) spin_lock(&req->rq_lock); if (req->rq_invalid_rqset) { - struct l_wait_info lwi = LWI_TIMEOUT(cfs_time_seconds(5), + struct l_wait_info lwi = LWI_TIMEOUT(5 * HZ, back_to_sleep, NULL); req->rq_invalid_rqset = 0; @@ -438,7 +438,7 @@ static int ptlrpcd(void *arg) int timeout; timeout = ptlrpc_set_next_timeout(set); - lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1), + lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, ptlrpc_expired_set, set); lu_context_enter(&env.le_ctx); diff --git a/drivers/staging/lustre/lustre/ptlrpc/recover.c b/drivers/staging/lustre/lustre/ptlrpc/recover.c index e4d3f23e9f3a..5bbd23eebfa6 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/recover.c +++ b/drivers/staging/lustre/lustre/ptlrpc/recover.c @@ -347,7 +347,7 @@ int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid, int async) if (!async) { struct l_wait_info lwi; - int secs = cfs_time_seconds(obd_timeout); + int secs = obd_timeout * HZ; CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n", obd2cli_tgt(imp->imp_obd), secs); diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c index 1f22926c1355..6d4229ebc9d9 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/service.c +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c @@ -2149,7 +2149,7 @@ static int ptlrpc_main(void *arg) * Wait for a timeout (unless something else * happens) before I try again */ - svcpt->scp_rqbd_timeout = cfs_time_seconds(1) / 10; + svcpt->scp_rqbd_timeout = HZ / 10; CDEBUG(D_RPCTRACE, "Posted buffers: %d\n", svcpt->scp_nrqbds_posted); } @@ -2588,7 +2588,7 @@ static void ptlrpc_wait_replies(struct ptlrpc_service_part *svcpt) { while (1) { int rc; - struct l_wait_info lwi = LWI_TIMEOUT(cfs_time_seconds(10), + struct l_wait_info lwi = LWI_TIMEOUT(10 * HZ, NULL, NULL); rc = l_wait_event(svcpt->scp_waitq, @@ -2660,8 +2660,8 @@ ptlrpc_service_unlink_rqbd(struct ptlrpc_service *svc) * of sluggish LNDs */ lwi = LWI_TIMEOUT_INTERVAL( - cfs_time_seconds(LONG_UNLINK), - cfs_time_seconds(1), NULL, NULL); + LONG_UNLINK * HZ, + HZ, NULL, NULL); rc = l_wait_event(svcpt->scp_waitq, svcpt->scp_nrqbds_posted == 0, &lwi); if (rc == -ETIMEDOUT) { From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 05/19] staging: lustre: use wait_event_idle_timeout() where appropriate. In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209348.23920.11616107274431655046.stgit@noble> When the lwi arg has a timeout, but no timeout callback function, l_wait_event() acts much the same as wait_event_idle_timeout() - the wait is not interruptible and simply waits for the event or the timeouts. The most noticable difference is that the return value is -ETIMEDOUT or 0, rather than 0 or non-zero. Another difference is that if the timeout is zero, l_wait_event() will not time out at all. In the one case where that is possible we need to conditionally use wait_event_idle(). So replace all such calls with wait_event_idle_timeout(), being careful of the return value. In one case, there is no event expected, only the timeout is needed. So use schedule_timeout_uninterruptible(). Note that the presence or absence of LWI_ON_SIGNAL_NOOP has no effect in these cases. It only has effect if the timeout callback is non-NULL, or the timeout is zero, or LWI_TIMEOUT_INTR_ALL() is used. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 10 ++------ drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 12 +++------- drivers/staging/lustre/lustre/llite/statahead.c | 14 ++++------- drivers/staging/lustre/lustre/mdc/mdc_request.c | 5 +--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 15 +++++------- drivers/staging/lustre/lustre/obdclass/cl_io.c | 17 ++++++++------ drivers/staging/lustre/lustre/osc/osc_cache.c | 25 ++++++++++---------- drivers/staging/lustre/lustre/ptlrpc/events.c | 7 +----- drivers/staging/lustre/lustre/ptlrpc/import.c | 12 ++++------ .../staging/lustre/lustre/ptlrpc/pack_generic.c | 9 +++---- drivers/staging/lustre/lustre/ptlrpc/pinger.c | 12 +++------- drivers/staging/lustre/lustre/ptlrpc/recover.c | 12 ++++------ drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 10 ++------ drivers/staging/lustre/lustre/ptlrpc/service.c | 11 ++++----- 14 files changed, 68 insertions(+), 103 deletions(-) diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c index 773abe78708a..95bea351d21d 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c @@ -1349,7 +1349,6 @@ enum ldlm_mode ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags, if ((flags & LDLM_FL_LVB_READY) && !ldlm_is_lvb_ready(lock)) { __u64 wait_flags = LDLM_FL_LVB_READY | LDLM_FL_DESTROYED | LDLM_FL_FAIL_NOTIFIED; - struct l_wait_info lwi; if (lock->l_completion_ast) { int err = lock->l_completion_ast(lock, @@ -1366,13 +1365,10 @@ enum ldlm_mode ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags, } } - lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, - NULL, LWI_ON_SIGNAL_NOOP, NULL); - /* XXX FIXME see comment on CAN_MATCH in lustre_dlm.h */ - l_wait_event(lock->l_waitq, - lock->l_flags & wait_flags, - &lwi); + wait_event_idle_timeout(lock->l_waitq, + lock->l_flags & wait_flags, + obd_timeout * HZ); if (!ldlm_is_lvb_ready(lock)) { if (flags & LDLM_FL_TEST_LOCK) LDLM_LOCK_RELEASE(lock); diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c index 622245a5f049..a0e486b57e08 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c @@ -997,8 +997,6 @@ static int ldlm_pools_thread_main(void *arg) "ldlm_poold", current_pid()); while (1) { - struct l_wait_info lwi; - /* * Recal all pools on this tick. */ @@ -1008,12 +1006,10 @@ static int ldlm_pools_thread_main(void *arg) * Wait until the next check time, or until we're * stopped. */ - lwi = LWI_TIMEOUT(c_time * HZ, - NULL, NULL); - l_wait_event(thread->t_ctl_waitq, - thread_is_stopping(thread) || - thread_is_event(thread), - &lwi); + wait_event_idle_timeout(thread->t_ctl_waitq, + thread_is_stopping(thread) || + thread_is_event(thread), + c_time * HZ); if (thread_test_and_clear_flags(thread, SVC_STOPPING)) break; diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c index 96360f104b92..6052bfd7ff05 100644 --- a/drivers/staging/lustre/lustre/llite/statahead.c +++ b/drivers/staging/lustre/lustre/llite/statahead.c @@ -1151,10 +1151,9 @@ static int ll_statahead_thread(void *arg) */ while (sai->sai_sent != sai->sai_replied) { /* in case we're not woken up, timeout wait */ - struct l_wait_info lwi = LWI_TIMEOUT(msecs_to_jiffies(MSEC_PER_SEC >> 3), - NULL, NULL); - l_wait_event(sa_thread->t_ctl_waitq, - sai->sai_sent == sai->sai_replied, &lwi); + wait_event_idle_timeout(sa_thread->t_ctl_waitq, + sai->sai_sent == sai->sai_replied, + HZ>>3); } /* release resources held by statahead RPCs */ @@ -1374,7 +1373,6 @@ static int revalidate_statahead_dentry(struct inode *dir, { struct ll_inode_info *lli = ll_i2info(dir); struct sa_entry *entry = NULL; - struct l_wait_info lwi = { 0 }; struct ll_dentry_data *ldd; int rc = 0; @@ -1424,10 +1422,8 @@ static int revalidate_statahead_dentry(struct inode *dir, spin_lock(&lli->lli_sa_lock); sai->sai_index_wait = entry->se_index; spin_unlock(&lli->lli_sa_lock); - lwi = LWI_TIMEOUT_INTR(30 * HZ, NULL, - LWI_ON_SIGNAL_NOOP, NULL); - rc = l_wait_event(sai->sai_waitq, sa_ready(entry), &lwi); - if (rc < 0) { + if (0 == wait_event_idle_timeout(sai->sai_waitq, + sa_ready(entry), 30 * HZ)) { /* * entry may not be ready, so it may be used by inflight * statahead RPC, don't free it. diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c index b12518ba5ae9..ab48746ce433 100644 --- a/drivers/staging/lustre/lustre/mdc/mdc_request.c +++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c @@ -838,7 +838,6 @@ static int mdc_getpage(struct obd_export *exp, const struct lu_fid *fid, struct ptlrpc_bulk_desc *desc; struct ptlrpc_request *req; wait_queue_head_t waitq; - struct l_wait_info lwi; int resends = 0; int rc; int i; @@ -888,9 +887,7 @@ static int mdc_getpage(struct obd_export *exp, const struct lu_fid *fid, exp->exp_obd->obd_name, -EIO); return -EIO; } - lwi = LWI_TIMEOUT_INTR(resends * HZ, NULL, NULL, - NULL); - l_wait_event(waitq, 0, &lwi); + wait_event_idle_timeout(waitq, 0, resends * HZ); goto restart_bulk; } diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c index a01d13bde102..c61cd23a96df 100644 --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c @@ -535,7 +535,6 @@ static int mgc_requeue_thread(void *data) spin_lock(&config_list_lock); rq_state |= RQ_RUNNING; while (!(rq_state & RQ_STOP)) { - struct l_wait_info lwi; struct config_llog_data *cld, *cld_prev; int rand = prandom_u32_max(MGC_TIMEOUT_RAND_CENTISEC); int to; @@ -556,9 +555,9 @@ static int mgc_requeue_thread(void *data) to = msecs_to_jiffies(MGC_TIMEOUT_MIN_SECONDS * MSEC_PER_SEC); /* rand is centi-seconds */ to += msecs_to_jiffies(rand * MSEC_PER_SEC / 100); - lwi = LWI_TIMEOUT(to, NULL, NULL); - l_wait_event(rq_waitq, rq_state & (RQ_STOP | RQ_PRECLEANUP), - &lwi); + wait_event_idle_timeout(rq_waitq, + rq_state & (RQ_STOP | RQ_PRECLEANUP), + to); /* * iterate & processing through the list. for each cld, process @@ -1628,9 +1627,7 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld) if (rcl == -ESHUTDOWN && atomic_read(&mgc->u.cli.cl_mgc_refcount) > 0 && !retry) { - int secs = obd_timeout * HZ; struct obd_import *imp; - struct l_wait_info lwi; mutex_unlock(&cld->cld_lock); imp = class_exp2cliimp(mgc->u.cli.cl_mgc_mgsexp); @@ -1645,9 +1642,9 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld) */ ptlrpc_pinger_force(imp); - lwi = LWI_TIMEOUT(secs, NULL, NULL); - l_wait_event(imp->imp_recovery_waitq, - !mgc_import_in_recovery(imp), &lwi); + wait_event_idle_timeout(imp->imp_recovery_waitq, + !mgc_import_in_recovery(imp), + obd_timeout * HZ); if (imp->imp_state == LUSTRE_IMP_FULL) { retry = true; diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c index ce5e7bdda692..ab84e011b560 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_io.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c @@ -1097,16 +1097,19 @@ EXPORT_SYMBOL(cl_sync_io_init); int cl_sync_io_wait(const struct lu_env *env, struct cl_sync_io *anchor, long timeout) { - struct l_wait_info lwi = LWI_TIMEOUT_INTR(timeout * HZ, - NULL, NULL, NULL); - int rc; + int rc = 1; LASSERT(timeout >= 0); - rc = l_wait_event(anchor->csi_waitq, - atomic_read(&anchor->csi_sync_nr) == 0, - &lwi); - if (rc < 0) { + if (timeout == 0) + wait_event_idle(anchor->csi_waitq, + atomic_read(&anchor->csi_sync_nr) == 0); + else + rc = wait_event_idle_timeout(anchor->csi_waitq, + atomic_read(&anchor->csi_sync_nr) == 0, + timeout * HZ); + if (rc == 0) { + rc = -ETIMEDOUT; CERROR("IO failed: %d, still wait for %d remaining entries\n", rc, atomic_read(&anchor->csi_sync_nr)); diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c index 0797e671f667..dacfab12c501 100644 --- a/drivers/staging/lustre/lustre/osc/osc_cache.c +++ b/drivers/staging/lustre/lustre/osc/osc_cache.c @@ -934,8 +934,6 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext, enum osc_extent_state state) { struct osc_object *obj = ext->oe_obj; - struct l_wait_info lwi = LWI_TIMEOUT_INTR(600 * HZ, NULL, - LWI_ON_SIGNAL_NOOP, NULL); int rc = 0; osc_object_lock(obj); @@ -958,17 +956,19 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext, osc_extent_release(env, ext); /* wait for the extent until its state becomes @state */ - rc = l_wait_event(ext->oe_waitq, extent_wait_cb(ext, state), &lwi); - if (rc == -ETIMEDOUT) { + rc = wait_event_idle_timeout(ext->oe_waitq, + extent_wait_cb(ext, state), 600 * HZ); + if (rc == 0) { OSC_EXTENT_DUMP(D_ERROR, ext, "%s: wait ext to %u timedout, recovery in progress?\n", cli_name(osc_cli(obj)), state); wait_event_idle(ext->oe_waitq, extent_wait_cb(ext, state)); - rc = 0; } - if (rc == 0 && ext->oe_rc < 0) + if (ext->oe_rc < 0) rc = ext->oe_rc; + else + rc = 0; return rc; } @@ -1568,12 +1568,9 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli, struct osc_object *osc = oap->oap_obj; struct lov_oinfo *loi = osc->oo_oinfo; struct osc_cache_waiter ocw; - struct l_wait_info lwi; + unsigned long timeout = (AT_OFF ? obd_timeout : at_max) * HZ; int rc = -EDQUOT; - lwi = LWI_TIMEOUT_INTR((AT_OFF ? obd_timeout : at_max) * HZ, - NULL, LWI_ON_SIGNAL_NOOP, NULL); - OSC_DUMP_GRANT(D_CACHE, cli, "need:%d\n", bytes); spin_lock(&cli->cl_loi_list_lock); @@ -1616,13 +1613,15 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli, CDEBUG(D_CACHE, "%s: sleeping for cache space @ %p for %p\n", cli_name(cli), &ocw, oap); - rc = l_wait_event(ocw.ocw_waitq, ocw_granted(cli, &ocw), &lwi); + rc = wait_event_idle_timeout(ocw.ocw_waitq, + ocw_granted(cli, &ocw), timeout); spin_lock(&cli->cl_loi_list_lock); - if (rc < 0) { - /* l_wait_event is interrupted by signal, or timed out */ + if (rc == 0) { + /* wait_event is interrupted by signal, or timed out */ list_del_init(&ocw.ocw_entry); + rc = -ETIMEDOUT; break; } LASSERT(list_empty(&ocw.ocw_entry)); diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c index 71f7588570ef..130bacc2c891 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/events.c +++ b/drivers/staging/lustre/lustre/ptlrpc/events.c @@ -490,8 +490,6 @@ int ptlrpc_uuid_to_peer(struct obd_uuid *uuid, static void ptlrpc_ni_fini(void) { - wait_queue_head_t waitq; - struct l_wait_info lwi; int rc; int retries; @@ -515,10 +513,7 @@ static void ptlrpc_ni_fini(void) if (retries != 0) CWARN("Event queue still busy\n"); - /* Wait for a bit */ - init_waitqueue_head(&waitq); - lwi = LWI_TIMEOUT(2 * HZ, NULL, NULL); - l_wait_event(waitq, 0, &lwi); + schedule_timeout_uninterruptible(2 * HZ); break; } } diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c index 0eba5f18bd3b..ed210550f61f 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/import.c +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c @@ -430,21 +430,19 @@ void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt) int ptlrpc_reconnect_import(struct obd_import *imp) { - struct l_wait_info lwi; - int secs = obd_timeout * HZ; int rc; ptlrpc_pinger_force(imp); CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n", - obd2cli_tgt(imp->imp_obd), secs); + obd2cli_tgt(imp->imp_obd), obd_timeout); - lwi = LWI_TIMEOUT(secs, NULL, NULL); - rc = l_wait_event(imp->imp_recovery_waitq, - !ptlrpc_import_in_recovery(imp), &lwi); + rc = wait_event_idle_timeout(imp->imp_recovery_waitq, + !ptlrpc_import_in_recovery(imp), + obd_timeout * HZ); CDEBUG(D_HA, "%s: recovery finished s:%s\n", obd2cli_tgt(imp->imp_obd), ptlrpc_import_state_name(imp->imp_state)); - return rc; + return rc == 0 ? -ETIMEDOUT : 0; } EXPORT_SYMBOL(ptlrpc_reconnect_import); diff --git a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c index c060d6f5015a..f73463ac401f 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c +++ b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c @@ -260,17 +260,16 @@ lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt) /* See if we have anything in a pool, and wait if nothing */ while (list_empty(&svcpt->scp_rep_idle)) { - struct l_wait_info lwi; int rc; spin_unlock(&svcpt->scp_rep_lock); /* If we cannot get anything for some long time, we better * bail out instead of waiting infinitely */ - lwi = LWI_TIMEOUT(10 * HZ, NULL, NULL); - rc = l_wait_event(svcpt->scp_rep_waitq, - !list_empty(&svcpt->scp_rep_idle), &lwi); - if (rc != 0) + rc = wait_event_idle_timeout(svcpt->scp_rep_waitq, + !list_empty(&svcpt->scp_rep_idle), + 10 * HZ); + if (rc == 0) goto out; spin_lock(&svcpt->scp_rep_lock); } diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c index 010a1cdf05fa..639070f6e68e 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c +++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c @@ -228,7 +228,6 @@ static int ptlrpc_pinger_main(void *arg) /* And now, loop forever, pinging as needed. */ while (1) { unsigned long this_ping = cfs_time_current(); - struct l_wait_info lwi; long time_to_next_wake; struct timeout_item *item; struct list_head *iter; @@ -266,13 +265,10 @@ static int ptlrpc_pinger_main(void *arg) cfs_time_add(this_ping, PING_INTERVAL * HZ)); if (time_to_next_wake > 0) { - lwi = LWI_TIMEOUT(max_t(long, time_to_next_wake, - HZ), - NULL, NULL); - l_wait_event(thread->t_ctl_waitq, - thread_is_stopping(thread) || - thread_is_event(thread), - &lwi); + wait_event_idle_timeout(thread->t_ctl_waitq, + thread_is_stopping(thread) || + thread_is_event(thread), + max_t(long, time_to_next_wake, HZ)); if (thread_test_and_clear_flags(thread, SVC_STOPPING)) break; /* woken after adding import to reset timer */ diff --git a/drivers/staging/lustre/lustre/ptlrpc/recover.c b/drivers/staging/lustre/lustre/ptlrpc/recover.c index 5bbd23eebfa6..7b5f2429d144 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/recover.c +++ b/drivers/staging/lustre/lustre/ptlrpc/recover.c @@ -346,17 +346,15 @@ int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid, int async) goto out; if (!async) { - struct l_wait_info lwi; - int secs = obd_timeout * HZ; - CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n", - obd2cli_tgt(imp->imp_obd), secs); + obd2cli_tgt(imp->imp_obd), obd_timeout); - lwi = LWI_TIMEOUT(secs, NULL, NULL); - rc = l_wait_event(imp->imp_recovery_waitq, - !ptlrpc_import_in_recovery(imp), &lwi); + rc = wait_event_idle_timeout(imp->imp_recovery_waitq, + !ptlrpc_import_in_recovery(imp), + obd_timeout * HZ); CDEBUG(D_HA, "%s: recovery finished\n", obd2cli_tgt(imp->imp_obd)); + rc = rc? 0 : -ETIMEDOUT; } out: diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c index b61e1aa25e8c..48f1a72afd77 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c @@ -142,7 +142,6 @@ static void sec_do_gc(struct ptlrpc_sec *sec) static int sec_gc_main(void *arg) { struct ptlrpc_thread *thread = arg; - struct l_wait_info lwi; unshare_fs_struct(); @@ -179,12 +178,9 @@ static int sec_gc_main(void *arg) /* check ctx list again before sleep */ sec_process_ctx_list(); - - lwi = LWI_TIMEOUT(msecs_to_jiffies(SEC_GC_INTERVAL * MSEC_PER_SEC), - NULL, NULL); - l_wait_event(thread->t_ctl_waitq, - thread_is_stopping(thread), - &lwi); + wait_event_idle_timeout(thread->t_ctl_waitq, + thread_is_stopping(thread), + SEC_GC_INTERVAL * HZ); if (thread_test_and_clear_flags(thread, SVC_STOPPING)) break; diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c index 6d4229ebc9d9..5c41297d23d2 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/service.c +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c @@ -2588,13 +2588,12 @@ static void ptlrpc_wait_replies(struct ptlrpc_service_part *svcpt) { while (1) { int rc; - struct l_wait_info lwi = LWI_TIMEOUT(10 * HZ, - NULL, NULL); - rc = l_wait_event(svcpt->scp_waitq, - atomic_read(&svcpt->scp_nreps_difficult) == 0, - &lwi); - if (rc == 0) + rc = wait_event_idle_timeout( + svcpt->scp_waitq, + atomic_read(&svcpt->scp_nreps_difficult) == 0, + 10 * HZ); + if (rc > 0) break; CWARN("Unexpectedly long timeout %s %p\n", svcpt->scp_service->srv_name, svcpt->scp_service); From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 07/19] staging: lustre: simplify l_wait_event when intr handler but no timeout. In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209356.23920.9569196568216701164.stgit@noble> If l_wait_event() is given a function to be called on a signal, but no timeout or timeout handler, then the intr function is simply called at the end if the wait was aborted by a signal. So a simpler way to write the code (in the one place this case is used) it to open-code the body of the function after the wait_event, if -ERESTARTSYS was returned. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/ldlm/ldlm_flock.c | 30 +++++------------------ 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c index 657ab95091a0..411b540b96d9 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c @@ -310,24 +310,6 @@ static int ldlm_process_flock_lock(struct ldlm_lock *req) return LDLM_ITER_CONTINUE; } -struct ldlm_flock_wait_data { - struct ldlm_lock *fwd_lock; -}; - -static void -ldlm_flock_interrupted_wait(void *data) -{ - struct ldlm_lock *lock; - - lock = ((struct ldlm_flock_wait_data *)data)->fwd_lock; - - lock_res_and_lock(lock); - - /* client side - set flag to prevent lock from being put on LRU list */ - ldlm_set_cbpending(lock); - unlock_res_and_lock(lock); -} - /** * Flock completion callback function. * @@ -342,8 +324,6 @@ int ldlm_flock_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) { struct file_lock *getlk = lock->l_ast_data; - struct ldlm_flock_wait_data fwd; - struct l_wait_info lwi; int rc = 0; OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CP_CB_WAIT2, 4); @@ -372,13 +352,17 @@ ldlm_flock_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) LDLM_DEBUG(lock, "client-side enqueue returned a blocked lock, sleeping"); - fwd.fwd_lock = lock; - lwi = LWI_TIMEOUT_INTR(0, NULL, ldlm_flock_interrupted_wait, &fwd); /* Go to sleep until the lock is granted. */ - rc = l_wait_event(lock->l_waitq, is_granted_or_cancelled(lock), &lwi); + rc = l_wait_event_abortable(lock->l_waitq, is_granted_or_cancelled(lock)); if (rc) { + lock_res_and_lock(lock); + + /* client side - set flag to prevent lock from being put on LRU list */ + ldlm_set_cbpending(lock); + unlock_res_and_lock(lock); + LDLM_DEBUG(lock, "client-side enqueue waking up: failed (%d)", rc); return rc; From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 06/19] staging: lustre: introduce and use l_wait_event_abortable() In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209353.23920.9039364039042495496.stgit@noble> lustre sometimes wants to wait for an event, but abort if one of a specific list of signals arrives. This is a little bit like wait_event_killable(), except that the signals are identified a different way. So introduce l_wait_event_abortable() which provides this functionality. Having separate functions for separate needs is more in line with the pattern set by include/linux/wait.h, than having a single function which tries to include all possible needs. Also introduce l_wait_event_abortable_exclusive(). Note that l_wait_event() return -EINTR on a signal, while Linux wait_event functions return -ERESTARTSYS. l_wait_event_{abortable_,}exclusive follow the Linux pattern. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/include/lustre_lib.h | 24 ++++++++++++++++++++ drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 12 +++++----- drivers/staging/lustre/lustre/llite/llite_lib.c | 12 +++------- drivers/staging/lustre/lustre/obdclass/genops.c | 9 +++----- drivers/staging/lustre/lustre/obdclass/llog_obd.c | 5 ++-- drivers/staging/lustre/lustre/osc/osc_page.c | 6 ++--- drivers/staging/lustre/lustre/osc/osc_request.c | 6 ++--- 7 files changed, 43 insertions(+), 31 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h index 7d950c53e962..b2a64d0e682c 100644 --- a/drivers/staging/lustre/lustre/include/lustre_lib.h +++ b/drivers/staging/lustre/lustre/include/lustre_lib.h @@ -336,4 +336,28 @@ do { \ /** @} lib */ + +/* l_wait_event_abortable() is a bit like wait_event_killable() + * except there is a fixed set of signals which will abort: + * LUSTRE_FATAL_SIGS + */ +#define l_wait_event_abortable(wq, condition) \ +({ \ + sigset_t __blocked; \ + int __ret = 0; \ + __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ + __ret = wait_event_interruptible(wq, condition); \ + cfs_restore_sigs(__blocked); \ + __ret; \ +}) + +#define l_wait_event_abortable_exclusive(wq, condition) \ +({ \ + sigset_t __blocked; \ + int __ret = 0; \ + __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ + __ret = wait_event_interruptible_exclusive(wq, condition); \ + cfs_restore_sigs(__blocked); \ + __ret; \ +}) #endif /* _LUSTRE_LIB_H */ diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c index 2e66825c8f4b..4c44603ab6f9 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c @@ -879,7 +879,6 @@ static int __ldlm_namespace_free(struct ldlm_namespace *ns, int force) ldlm_namespace_cleanup(ns, force ? LDLM_FL_LOCAL_ONLY : 0); if (atomic_read(&ns->ns_bref) > 0) { - struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); int rc; CDEBUG(D_DLMTRACE, @@ -887,11 +886,12 @@ static int __ldlm_namespace_free(struct ldlm_namespace *ns, int force) ldlm_ns_name(ns), atomic_read(&ns->ns_bref)); force_wait: if (force) - lwi = LWI_TIMEOUT(msecs_to_jiffies(obd_timeout * - MSEC_PER_SEC) / 4, NULL, NULL); - - rc = l_wait_event(ns->ns_waitq, - atomic_read(&ns->ns_bref) == 0, &lwi); + rc = wait_event_idle_timeout(ns->ns_waitq, + atomic_read(&ns->ns_bref) == 0, + obd_timeout * HZ / 4) ? 0 : -ETIMEDOUT; + else + rc = l_wait_event_abortable(ns->ns_waitq, + atomic_read(&ns->ns_bref) == 0); /* Forced cleanups should be able to reclaim all references, * so it's safe to wait forever... we can't leak locks... diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c index 0a9183f271f5..33dc15e9aebb 100644 --- a/drivers/staging/lustre/lustre/llite/llite_lib.c +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c @@ -986,16 +986,12 @@ void ll_put_super(struct super_block *sb) } /* Wait for unstable pages to be committed to stable storage */ - if (!force) { - struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); - - rc = l_wait_event(sbi->ll_cache->ccc_unstable_waitq, - !atomic_long_read(&sbi->ll_cache->ccc_unstable_nr), - &lwi); - } + if (!force) + rc = l_wait_event_abortable(sbi->ll_cache->ccc_unstable_waitq, + !atomic_long_read(&sbi->ll_cache->ccc_unstable_nr)); ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr); - if (!force && rc != -EINTR) + if (!force && rc != -ERESTARTSYS) LASSERTF(!ccc_count, "count: %li\n", ccc_count); /* We need to set force before the lov_disconnect in diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c index 3ff25b8d3b48..8f776a4058a9 100644 --- a/drivers/staging/lustre/lustre/obdclass/genops.c +++ b/drivers/staging/lustre/lustre/obdclass/genops.c @@ -1332,7 +1332,6 @@ static bool obd_request_slot_avail(struct client_obd *cli, int obd_get_request_slot(struct client_obd *cli) { struct obd_request_slot_waiter orsw; - struct l_wait_info lwi; int rc; spin_lock(&cli->cl_loi_list_lock); @@ -1347,11 +1346,9 @@ int obd_get_request_slot(struct client_obd *cli) orsw.orsw_signaled = false; spin_unlock(&cli->cl_loi_list_lock); - lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); - rc = l_wait_event(orsw.orsw_waitq, - obd_request_slot_avail(cli, &orsw) || - orsw.orsw_signaled, - &lwi); + rc = l_wait_event_abortable(orsw.orsw_waitq, + obd_request_slot_avail(cli, &orsw) || + orsw.orsw_signaled); /* * Here, we must take the lock to avoid the on-stack 'orsw' to be diff --git a/drivers/staging/lustre/lustre/obdclass/llog_obd.c b/drivers/staging/lustre/lustre/obdclass/llog_obd.c index 28bbaa2136ac..26aea114a29b 100644 --- a/drivers/staging/lustre/lustre/obdclass/llog_obd.c +++ b/drivers/staging/lustre/lustre/obdclass/llog_obd.c @@ -104,7 +104,6 @@ EXPORT_SYMBOL(__llog_ctxt_put); int llog_cleanup(const struct lu_env *env, struct llog_ctxt *ctxt) { - struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); struct obd_llog_group *olg; int rc, idx; @@ -129,8 +128,8 @@ int llog_cleanup(const struct lu_env *env, struct llog_ctxt *ctxt) CERROR("Error %d while cleaning up ctxt %p\n", rc, ctxt); - l_wait_event(olg->olg_waitq, - llog_group_ctxt_null(olg, idx), &lwi); + l_wait_event_abortable(olg->olg_waitq, + llog_group_ctxt_null(olg, idx)); return rc; } diff --git a/drivers/staging/lustre/lustre/osc/osc_page.c b/drivers/staging/lustre/lustre/osc/osc_page.c index 20094b6309f9..6fdd521feb21 100644 --- a/drivers/staging/lustre/lustre/osc/osc_page.c +++ b/drivers/staging/lustre/lustre/osc/osc_page.c @@ -759,7 +759,6 @@ static long osc_lru_reclaim(struct client_obd *cli, unsigned long npages) static int osc_lru_alloc(const struct lu_env *env, struct client_obd *cli, struct osc_page *opg) { - struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); struct osc_io *oio = osc_env_io(env); int rc = 0; @@ -782,9 +781,8 @@ static int osc_lru_alloc(const struct lu_env *env, struct client_obd *cli, cond_resched(); - rc = l_wait_event(osc_lru_waitq, - atomic_long_read(cli->cl_lru_left) > 0, - &lwi); + rc = l_wait_event_abortable(osc_lru_waitq, + atomic_long_read(cli->cl_lru_left) > 0); if (rc < 0) break; diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c index 45b1ebf33363..074b5ce6284c 100644 --- a/drivers/staging/lustre/lustre/osc/osc_request.c +++ b/drivers/staging/lustre/lustre/osc/osc_request.c @@ -552,14 +552,12 @@ static int osc_destroy(const struct lu_env *env, struct obd_export *exp, req->rq_interpret_reply = osc_destroy_interpret; if (!osc_can_send_destroy(cli)) { - struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); - /* * Wait until the number of on-going destroy RPCs drops * under max_rpc_in_flight */ - l_wait_event_exclusive(cli->cl_destroy_waitq, - osc_can_send_destroy(cli), &lwi); + l_wait_event_abortable_exclusive(cli->cl_destroy_waitq, + osc_can_send_destroy(cli)); } /* Do not wait for response */ From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 09/19] staging: lustre: open code polling loop instead of using l_wait_event() In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209364.23920.15335820464811680168.stgit@noble> Two places that LWI_TIMEOUT_INTERVAL() is used, the outcome is a simple polling loop that polls every second for some event (with a limit). So write a simple loop to make this more apparent. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/llite/llite_lib.c | 11 +++++------ drivers/staging/lustre/lustre/lov/lov_request.c | 12 +++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c index 33dc15e9aebb..f6642fa30428 100644 --- a/drivers/staging/lustre/lustre/llite/llite_lib.c +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c @@ -1984,8 +1984,7 @@ void ll_umount_begin(struct super_block *sb) struct ll_sb_info *sbi = ll_s2sbi(sb); struct obd_device *obd; struct obd_ioctl_data *ioc_data; - wait_queue_head_t waitq; - struct l_wait_info lwi; + int cnt = 0; CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb, sb->s_count, atomic_read(&sb->s_active)); @@ -2021,10 +2020,10 @@ void ll_umount_begin(struct super_block *sb) * and then continue. For now, we just periodically checking for vfs * to decrement mnt_cnt and hope to finish it within 10sec. */ - init_waitqueue_head(&waitq); - lwi = LWI_TIMEOUT_INTERVAL(10 * HZ, - HZ, NULL, NULL); - l_wait_event(waitq, may_umount(sbi->ll_mnt.mnt), &lwi); + while (cnt < 10 && !may_umount(sbi->ll_mnt.mnt)) { + schedule_timeout_uninterruptible(HZ); + cnt ++; + } schedule(); } diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c index fb3b7a7fa32a..c1e58fcc30b3 100644 --- a/drivers/staging/lustre/lustre/lov/lov_request.c +++ b/drivers/staging/lustre/lustre/lov/lov_request.c @@ -99,8 +99,7 @@ static int lov_check_set(struct lov_obd *lov, int idx) */ static int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx) { - wait_queue_head_t waitq; - struct l_wait_info lwi; + int cnt = 0; struct lov_tgt_desc *tgt; int rc = 0; @@ -125,11 +124,10 @@ static int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx) mutex_unlock(&lov->lov_lock); - init_waitqueue_head(&waitq); - lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ, - HZ, NULL, NULL); - - rc = l_wait_event(waitq, lov_check_set(lov, ost_idx), &lwi); + while (cnt < obd_timeout && !lov_check_set(lov, ost_idx)) { + schedule_timeout_uninterruptible(HZ); + cnt ++; + } if (tgt->ltd_active) return 1; From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 10/19] staging: lustre: simplify waiting in ptlrpc_invalidate_import() In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209368.23920.17745110760039469689.stgit@noble> This waiter currently wakes up every second to re-test if imp_flight is zero. If we ensure wakeup is called whenever imp_flight is decremented to zero, we can just have a simple wait_event_idle_timeout(). So add a wake_up_all to the one place it is missing, and simplify the wait_event. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/ptlrpc/client.c | 3 ++- drivers/staging/lustre/lustre/ptlrpc/import.c | 21 ++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c index 0ab13f8e5993..81b7a7046d82 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/client.c +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c @@ -1588,7 +1588,8 @@ static int ptlrpc_send_new_req(struct ptlrpc_request *req) spin_lock(&imp->imp_lock); if (!list_empty(&req->rq_list)) { list_del_init(&req->rq_list); - atomic_dec(&req->rq_import->imp_inflight); + if (atomic_dec_and_test(&req->rq_import->imp_inflight)) + wake_up_all(&req->rq_import->imp_recovery_waitq); } spin_unlock(&imp->imp_lock); ptlrpc_rqphase_move(req, RQ_PHASE_NEW); diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c index ed210550f61f..5d62c9de27eb 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/import.c +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c @@ -265,7 +265,6 @@ void ptlrpc_invalidate_import(struct obd_import *imp) { struct list_head *tmp, *n; struct ptlrpc_request *req; - struct l_wait_info lwi; unsigned int timeout; int rc; @@ -306,19 +305,15 @@ void ptlrpc_invalidate_import(struct obd_import *imp) * callbacks. Cap it at obd_timeout -- these should all * have been locally cancelled by ptlrpc_abort_inflight. */ - lwi = LWI_TIMEOUT_INTERVAL( - cfs_timeout_cap(timeout * HZ), - (timeout > 1) ? HZ : - HZ / 2, - NULL, NULL); - rc = l_wait_event(imp->imp_recovery_waitq, - (atomic_read(&imp->imp_inflight) == 0), - &lwi); - if (rc) { + rc = wait_event_idle_timeout(imp->imp_recovery_waitq, + atomic_read(&imp->imp_inflight) == 0, + obd_timeout * HZ); + + if (rc == 0) { const char *cli_tgt = obd2cli_tgt(imp->imp_obd); - CERROR("%s: rc = %d waiting for callback (%d != 0)\n", - cli_tgt, rc, + CERROR("%s: timeout waiting for callback (%d != 0)\n", + cli_tgt, atomic_read(&imp->imp_inflight)); spin_lock(&imp->imp_lock); @@ -365,7 +360,7 @@ void ptlrpc_invalidate_import(struct obd_import *imp) } spin_unlock(&imp->imp_lock); } - } while (rc != 0); + } while (rc == 0); /* * Let's additionally check that no new rpcs added to import in From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 08/19] staging: lustre: simplify waiting in ldlm_completion_ast() In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209360.23920.8603201181939332545.stgit@noble> If a signal-callback (lwi_on_signal) is set without lwi_allow_intr, as is the case in ldlm_completion_ast(), the behavior depends on the timeout set. If a timeout is set, then signals are ignored. If the timeout is reached, the timeout handler is called. If the timeout handler return 0, which ldlm_expired_completion_wait() always does, the l_wait_event() switches to exactly the behavior if no timeout was set. If no timeout is set, then "fatal" signals are not ignored. If one arrives the callback is run, but as the callback is empty in this case, that is not relevant. This can be simplified to: if a timeout is wanted wait_event_idle_timeout() if that timed out, call the timeout handler l_wait_event_abortable() i.e. the code always waits indefinitely. Sometimes it performs a non-abortable wait first. Sometimes it doesn't. But it only aborts before the condition is true if it is signaled. This doesn't quite agree with the comments and debug messages. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/ldlm/ldlm_request.c | 55 +++++++-------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c index a244fa717134..f1233d844bbd 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c @@ -72,15 +72,6 @@ MODULE_PARM_DESC(ldlm_enqueue_min, "lock enqueue timeout minimum"); /* in client side, whether the cached locks will be canceled before replay */ unsigned int ldlm_cancel_unused_locks_before_replay = 1; -static void interrupted_completion_wait(void *data) -{ -} - -struct lock_wait_data { - struct ldlm_lock *lwd_lock; - __u32 lwd_conn_cnt; -}; - struct ldlm_async_args { struct lustre_handle lock_handle; }; @@ -112,10 +103,8 @@ static int ldlm_request_bufsize(int count, int type) return sizeof(struct ldlm_request) + avail; } -static int ldlm_expired_completion_wait(void *data) +static void ldlm_expired_completion_wait(struct ldlm_lock *lock, struct obd_import *imp2) { - struct lock_wait_data *lwd = data; - struct ldlm_lock *lock = lwd->lwd_lock; struct obd_import *imp; struct obd_device *obd; @@ -135,19 +124,17 @@ static int ldlm_expired_completion_wait(void *data) if (last_dump == 0) libcfs_debug_dumplog(); } - return 0; + return; } obd = lock->l_conn_export->exp_obd; imp = obd->u.cli.cl_import; - ptlrpc_fail_import(imp, lwd->lwd_conn_cnt); + ptlrpc_fail_import(imp, imp2 ? imp2->imp_conn_cnt : 0); LDLM_ERROR(lock, "lock timed out (enqueued at %lld, %llds ago), entering recovery for %s@%s", (s64)lock->l_last_activity, (s64)(ktime_get_real_seconds() - lock->l_last_activity), obd2cli_tgt(obd), imp->imp_connection->c_remote_uuid.uuid); - - return 0; } /** @@ -251,10 +238,8 @@ EXPORT_SYMBOL(ldlm_completion_ast_async); int ldlm_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) { /* XXX ALLOCATE - 160 bytes */ - struct lock_wait_data lwd; struct obd_device *obd; struct obd_import *imp = NULL; - struct l_wait_info lwi; __u32 timeout; int rc = 0; @@ -281,32 +266,28 @@ int ldlm_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) timeout = ldlm_cp_timeout(lock); - lwd.lwd_lock = lock; lock->l_last_activity = ktime_get_real_seconds(); - if (ldlm_is_no_timeout(lock)) { - LDLM_DEBUG(lock, "waiting indefinitely because of NO_TIMEOUT"); - lwi = LWI_INTR(interrupted_completion_wait, &lwd); - } else { - lwi = LWI_TIMEOUT_INTR(timeout * HZ, - ldlm_expired_completion_wait, - interrupted_completion_wait, &lwd); - } - - if (imp) { - spin_lock(&imp->imp_lock); - lwd.lwd_conn_cnt = imp->imp_conn_cnt; - spin_unlock(&imp->imp_lock); - } - if (OBD_FAIL_CHECK_RESET(OBD_FAIL_LDLM_INTR_CP_AST, OBD_FAIL_LDLM_CP_BL_RACE | OBD_FAIL_ONCE)) { ldlm_set_fail_loc(lock); rc = -EINTR; } else { - /* Go to sleep until the lock is granted or cancelled. */ - rc = l_wait_event(lock->l_waitq, - is_granted_or_cancelled(lock), &lwi); + /* Go to sleep until the lock is granted or canceled. */ + if (!ldlm_is_no_timeout(lock)) { + /* Wait uninterruptible for a while first */ + rc = wait_event_idle_timeout(lock->l_waitq, + is_granted_or_cancelled(lock), + timeout * HZ); + if (rc == 0) + ldlm_expired_completion_wait(lock, imp); + } + /* Now wait abortable */ + if (rc == 0) + rc = l_wait_event_abortable(lock->l_waitq, + is_granted_or_cancelled(lock)); + else + rc = 0; } if (rc) { From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 11/19] staging: lustre: remove back_to_sleep() In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209372.23920.9644158038491397506.stgit@noble> When 'back_to_sleep()' is passed as the 'timeout' function, the effect is to wait indefinitely for the event, polling once after the timeout. If LWI_ON_SIGNAL_NOOP is given, then after the timeout we allow fatal signals to interrupt the wait. Make this more obvious in both places "back_to_sleep()" is used but using two explicit sleeps. The code in ptlrpcd_add_req() looks odd - why not just have one wait_event_idle()? However I believe this is a faithful transformation of the existing code. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/include/lustre_lib.h | 4 ---- drivers/staging/lustre/lustre/ptlrpc/import.c | 11 ++++++----- drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 9 +++++---- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h index b2a64d0e682c..1939e959b92a 100644 --- a/drivers/staging/lustre/lustre/include/lustre_lib.h +++ b/drivers/staging/lustre/lustre/include/lustre_lib.h @@ -140,10 +140,6 @@ void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id); * XXX nikita: some ptlrpc daemon threads have races of that sort. * */ -static inline int back_to_sleep(void *arg) -{ - return 0; -} #define LWI_ON_SIGNAL_NOOP ((void (*)(void *))(-1)) diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c index 5d62c9de27eb..faf0f606f013 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/import.c +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c @@ -1496,7 +1496,6 @@ int ptlrpc_disconnect_import(struct obd_import *imp, int noclose) } if (ptlrpc_import_in_recovery(imp)) { - struct l_wait_info lwi; long timeout; if (AT_OFF) { @@ -1510,10 +1509,12 @@ int ptlrpc_disconnect_import(struct obd_import *imp, int noclose) timeout = at_get(&imp->imp_at.iat_service_estimate[idx]) * HZ; } - lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(timeout), - back_to_sleep, LWI_ON_SIGNAL_NOOP, NULL); - rc = l_wait_event(imp->imp_recovery_waitq, - !ptlrpc_import_in_recovery(imp), &lwi); + if (wait_event_idle_timeout(imp->imp_recovery_waitq, + !ptlrpc_import_in_recovery(imp), + cfs_timeout_cap(timeout)) == 0) + l_wait_event_abortable( + imp->imp_recovery_waitq, + !ptlrpc_import_in_recovery(imp)); } spin_lock(&imp->imp_lock); diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c index dad2f9290f70..437b4b2a9072 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c @@ -230,12 +230,13 @@ void ptlrpcd_add_req(struct ptlrpc_request *req) spin_lock(&req->rq_lock); if (req->rq_invalid_rqset) { - struct l_wait_info lwi = LWI_TIMEOUT(5 * HZ, - back_to_sleep, NULL); - req->rq_invalid_rqset = 0; spin_unlock(&req->rq_lock); - l_wait_event(req->rq_set_waitq, !req->rq_set, &lwi); + if (wait_event_idle_timeout(req->rq_set_waitq, + !req->rq_set, + 5 * HZ) == 0) + wait_event_idle(req->rq_set_waitq, + !req->rq_set); } else if (req->rq_set) { /* If we have a valid "rq_set", just reuse it to avoid double * linked. From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 13/19] staging: lustre: use wait_event_idle_timeout in ptlrpcd() In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209379.23920.12930052742997185181.stgit@noble> We can replace l_wait_event() with wait_event_idle_timeout() here providing we call the timeout function when wait_event_idle_timeout() returns zero. As ptlrpc_expired_set() returns 1, the l_wait_event() aborts of the first timeout. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/ptlrpc/client.c | 12 ++++++++---- .../staging/lustre/lustre/ptlrpc/ptlrpc_internal.h | 2 +- drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 9 +++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c index 81b7a7046d82..f70176c6db08 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/client.c +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c @@ -2125,9 +2125,8 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink) * Callback used when waiting on sets with l_wait_event. * Always returns 1. */ -int ptlrpc_expired_set(void *data) +void ptlrpc_expired_set(struct ptlrpc_request_set *set) { - struct ptlrpc_request_set *set = data; struct list_head *tmp; time64_t now = ktime_get_real_seconds(); @@ -2156,7 +2155,12 @@ int ptlrpc_expired_set(void *data) */ ptlrpc_expire_one_request(req, 1); } +} +static int ptlrpc_expired_set_void(void *data) +{ + struct ptlrpc_request_set *set = data; + ptlrpc_expired_set(set); /* * When waiting for a whole set, we always break out of the * sleep so we can recalculate the timeout, or enable interrupts @@ -2286,7 +2290,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) * so we allow interrupts during the timeout. */ lwi = LWI_TIMEOUT_INTR_ALL(HZ, - ptlrpc_expired_set, + ptlrpc_expired_set_void, ptlrpc_interrupted_set, set); else /* @@ -2295,7 +2299,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) * complete, or an in-flight req times out. */ lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, - ptlrpc_expired_set, set); + ptlrpc_expired_set_void, set); rc = l_wait_event(set->set_waitq, ptlrpc_check_set(NULL, set), &lwi); diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h index f9decbd1459d..b7a8d7537a66 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h @@ -68,7 +68,7 @@ void ptlrpc_request_cache_free(struct ptlrpc_request *req); void ptlrpc_init_xid(void); void ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc, struct ptlrpc_request *req); -int ptlrpc_expired_set(void *data); +void ptlrpc_expired_set(struct ptlrpc_request_set *set); int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set); void ptlrpc_resend_req(struct ptlrpc_request *request); void ptlrpc_set_bulk_mbits(struct ptlrpc_request *req); diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c index 437b4b2a9072..6ed77521d025 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c @@ -435,16 +435,17 @@ static int ptlrpcd(void *arg) * new_req_list and ptlrpcd_check() moves them into the set. */ do { - struct l_wait_info lwi; int timeout; timeout = ptlrpc_set_next_timeout(set); - lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, - ptlrpc_expired_set, set); lu_context_enter(&env.le_ctx); lu_context_enter(env.le_ses); - l_wait_event(set->set_waitq, ptlrpcd_check(&env, pc), &lwi); + if (wait_event_idle_timeout(set->set_waitq, + ptlrpcd_check(&env, pc), + (timeout ? timeout : 1) * HZ) == 0) + ptlrpc_expired_set(set); + lu_context_exit(&env.le_ctx); lu_context_exit(env.le_ses); From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 12/19] staging: lustre: make polling loop in ptlrpc_unregister_bulk more obvious In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209376.23920.7787678507188073174.stgit@noble> This use of l_wait_event() is a polling loop that re-checks every second. Make this more obvious with a while loop and wait_event_idle_timeout(). Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/ptlrpc/niobuf.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c index 0c2ded721c49..86883abaad2c 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c +++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c @@ -229,7 +229,6 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async) { struct ptlrpc_bulk_desc *desc = req->rq_bulk; wait_queue_head_t *wq; - struct l_wait_info lwi; int rc; LASSERT(!in_interrupt()); /* might sleep */ @@ -246,7 +245,7 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async) /* the unlink ensures the callback happens ASAP and is the last * one. If it fails, it must be because completion just happened, - * but we must still l_wait_event() in this case to give liblustre + * but we must still wait_event() in this case to give liblustre * a chance to run client_bulk_callback() */ mdunlink_iterate_helper(desc->bd_mds, desc->bd_md_max_brw); @@ -270,15 +269,17 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async) /* Network access will complete in finite time but the HUGE * timeout lets us CWARN for visibility of sluggish LNDs */ - lwi = LWI_TIMEOUT_INTERVAL(LONG_UNLINK * HZ, - HZ, NULL, NULL); - rc = l_wait_event(*wq, !ptlrpc_client_bulk_active(req), &lwi); - if (rc == 0) { + int cnt = 0; + while (cnt < LONG_UNLINK && + (rc = wait_event_idle_timeout(*wq, + !ptlrpc_client_bulk_active(req), + HZ)) == 0) + cnt += 1; + if (rc > 0) { ptlrpc_rqphase_move(req, req->rq_next_phase); return 1; } - LASSERT(rc == -ETIMEDOUT); DEBUG_REQ(D_WARNING, req, "Unexpectedly long timeout: desc %p", desc); } From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 14/19] staging: lustre: improve waiting in sptlrpc_req_refresh_ctx In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209383.23920.18027403730394945280.stgit@noble> Replace l_wait_event with wait_event_idle_timeout() and call the handler function explicitly. This makes it more clear what is happening. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/ptlrpc/sec.c | 34 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec.c b/drivers/staging/lustre/lustre/ptlrpc/sec.c index 617e004d00f8..90e3b3022106 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/sec.c +++ b/drivers/staging/lustre/lustre/ptlrpc/sec.c @@ -554,9 +554,8 @@ int ctx_check_refresh(struct ptlrpc_cli_ctx *ctx) } static -int ctx_refresh_timeout(void *data) +int ctx_refresh_timeout(struct ptlrpc_request *req) { - struct ptlrpc_request *req = data; int rc; /* conn_cnt is needed in expire_one_request */ @@ -575,10 +574,8 @@ int ctx_refresh_timeout(void *data) } static -void ctx_refresh_interrupt(void *data) +void ctx_refresh_interrupt(struct ptlrpc_request *req) { - struct ptlrpc_request *req = data; - spin_lock(&req->rq_lock); req->rq_intr = 1; spin_unlock(&req->rq_lock); @@ -611,7 +608,6 @@ int sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout) { struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx; struct ptlrpc_sec *sec; - struct l_wait_info lwi; int rc; LASSERT(ctx); @@ -743,10 +739,28 @@ int sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout) req->rq_restart = 0; spin_unlock(&req->rq_lock); - lwi = LWI_TIMEOUT_INTR(msecs_to_jiffies(timeout * MSEC_PER_SEC), - ctx_refresh_timeout, ctx_refresh_interrupt, - req); - rc = l_wait_event(req->rq_reply_waitq, ctx_check_refresh(ctx), &lwi); + rc = wait_event_idle_timeout(req->rq_reply_waitq, + ctx_check_refresh(ctx), + timeout * HZ); + if (rc == 0 && ctx_refresh_timeout(req) == 0) { + /* Keep waiting, but enable some signals */ + rc = l_wait_event_abortable(req->rq_reply_waitq, + ctx_check_refresh(ctx)); + if (rc == 0) + rc = 1; + } + + if (rc > 0) + /* condition is true */ + rc = 0; + else if (rc == 0) + /* Timed out */ + rc = -ETIMEDOUT; + else { + /* Aborted by signal */ + rc = -EINTR; + ctx_refresh_interrupt(req); + } /* * following cases could lead us here: From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 15/19] staging: lustre: use explicit poll loop in ptlrpc_service_unlink_rqbd In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209387.23920.11031149890821644565.stgit@noble> Rather an using l_wait_event(), use wait_event_idle_timeout() with an explicit loop so it is easier to see what is happening. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/ptlrpc/service.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c index 5c41297d23d2..6e3403417434 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/service.c +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c @@ -2618,7 +2618,7 @@ ptlrpc_service_unlink_rqbd(struct ptlrpc_service *svc) { struct ptlrpc_service_part *svcpt; struct ptlrpc_request_buffer_desc *rqbd; - struct l_wait_info lwi; + int cnt; int rc; int i; @@ -2658,12 +2658,13 @@ ptlrpc_service_unlink_rqbd(struct ptlrpc_service *svc) * the HUGE timeout lets us CWARN for visibility * of sluggish LNDs */ - lwi = LWI_TIMEOUT_INTERVAL( - LONG_UNLINK * HZ, - HZ, NULL, NULL); - rc = l_wait_event(svcpt->scp_waitq, - svcpt->scp_nrqbds_posted == 0, &lwi); - if (rc == -ETIMEDOUT) { + cnt = 0; + while (cnt < LONG_UNLINK && + (rc = wait_event_idle_timeout(svcpt->scp_waitq, + svcpt->scp_nrqbds_posted == 0, + HZ)) == 0) + cnt ++; + if (rc == 0) { CWARN("Service %s waiting for request buffers\n", svcpt->scp_service->srv_name); } From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 16/19] staging: lustre: use explicit poll loop in ptlrpc_unregister_reply In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209390.23920.11839113414532003231.stgit@noble> replace l_wait_event() with wait_event_idle_timeout() and explicit loop. This approach is easier to understand. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/ptlrpc/client.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c index f70176c6db08..ffdd3ffd62c6 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/client.c +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c @@ -2500,7 +2500,6 @@ static int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async) { int rc; wait_queue_head_t *wq; - struct l_wait_info lwi; /* Might sleep. */ LASSERT(!in_interrupt()); @@ -2543,16 +2542,17 @@ static int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async) * Network access will complete in finite time but the HUGE * timeout lets us CWARN for visibility of sluggish NALs */ - lwi = LWI_TIMEOUT_INTERVAL(LONG_UNLINK * HZ, - HZ, NULL, NULL); - rc = l_wait_event(*wq, !ptlrpc_client_recv_or_unlink(request), - &lwi); - if (rc == 0) { + int cnt = 0; + while (cnt < LONG_UNLINK && + (rc = wait_event_idle_timeout(*wq, + !ptlrpc_client_recv_or_unlink(request), + HZ)) == 0) + cnt += 1; + if (rc > 0) { ptlrpc_rqphase_move(request, request->rq_next_phase); return 1; } - LASSERT(rc == -ETIMEDOUT); DEBUG_REQ(D_WARNING, request, "Unexpectedly long timeout receiving_reply=%d req_ulinked=%d reply_unlinked=%d", request->rq_receiving_reply, From neilb at suse.com Mon Jan 8 03:28:13 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:13 +1100 Subject: [lustre-devel] [PATCH 17/19] staging: lustre: remove l_wait_event from ptlrpc_set_wait In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209394.23920.3578408043898411296.stgit@noble> This is the last remaining use of l_wait_event(). It is the only use of LWI_TIMEOUT_INTR_ALL() which has a meaning that timeouts can be interrupted. Only interrupts by "fatal" signals are allowed, so introduce l_wait_event_abortable_timeout() to support this. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/include/lustre_lib.h | 14 +++ drivers/staging/lustre/lustre/ptlrpc/client.c | 84 ++++++++------------ 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h index 1939e959b92a..ccc1a329e42b 100644 --- a/drivers/staging/lustre/lustre/include/lustre_lib.h +++ b/drivers/staging/lustre/lustre/include/lustre_lib.h @@ -196,6 +196,10 @@ struct l_wait_info { #define LUSTRE_FATAL_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | \ sigmask(SIGTERM) | sigmask(SIGQUIT) | \ sigmask(SIGALRM)) +static inline int l_fatal_signal_pending(struct task_struct *p) +{ + return signal_pending(p) && sigtestsetmask(&p->pending.signal, LUSTRE_FATAL_SIGS); +} /** * wait_queue_entry_t of Linux (version < 2.6.34) is a FIFO list for exclusively @@ -347,6 +351,16 @@ do { \ __ret; \ }) +#define l_wait_event_abortable_timeout(wq, condition, timeout) \ +({ \ + sigset_t __blocked; \ + int __ret = 0; \ + __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ + __ret = wait_event_interruptible_timeout(wq, condition, timeout);\ + cfs_restore_sigs(__blocked); \ + __ret; \ +}) + #define l_wait_event_abortable_exclusive(wq, condition) \ ({ \ sigset_t __blocked; \ diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c index ffdd3ffd62c6..3d689d6100bc 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/client.c +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c @@ -1774,7 +1774,7 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set) } /* - * ptlrpc_set_wait->l_wait_event sets lwi_allow_intr + * ptlrpc_set_wait allow signal to abort the timeout * so it sets rq_intr regardless of individual rpc * timeouts. The synchronous IO waiting path sets * rq_intr irrespective of whether ptlrpcd @@ -2122,8 +2122,7 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink) /** * Time out all uncompleted requests in request set pointed by \a data - * Callback used when waiting on sets with l_wait_event. - * Always returns 1. + * Called when wait_event_idle_timeout times out. */ void ptlrpc_expired_set(struct ptlrpc_request_set *set) { @@ -2156,18 +2155,6 @@ void ptlrpc_expired_set(struct ptlrpc_request_set *set) ptlrpc_expire_one_request(req, 1); } } -static int ptlrpc_expired_set_void(void *data) -{ - struct ptlrpc_request_set *set = data; - - ptlrpc_expired_set(set); - /* - * When waiting for a whole set, we always break out of the - * sleep so we can recalculate the timeout, or enable interrupts - * if everyone's timed out. - */ - return 1; -} /** * Sets rq_intr flag in \a req under spinlock. @@ -2182,11 +2169,10 @@ EXPORT_SYMBOL(ptlrpc_mark_interrupted); /** * Interrupts (sets interrupted flag) all uncompleted requests in - * a set \a data. Callback for l_wait_event for interruptible waits. + * a set \a data. Called when l_wait_event_abortable_timeout receives signal. */ -static void ptlrpc_interrupted_set(void *data) +static void ptlrpc_interrupted_set(struct ptlrpc_request_set *set) { - struct ptlrpc_request_set *set = data; struct list_head *tmp; CDEBUG(D_RPCTRACE, "INTERRUPTED SET %p\n", set); @@ -2256,7 +2242,6 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) { struct list_head *tmp; struct ptlrpc_request *req; - struct l_wait_info lwi; int rc, timeout; if (set->set_producer) @@ -2282,46 +2267,47 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) CDEBUG(D_RPCTRACE, "set %p going to sleep for %d seconds\n", set, timeout); - if (timeout == 0 && !signal_pending(current)) + if (timeout == 0 && !signal_pending(current)) { /* * No requests are in-flight (ether timed out * or delayed), so we can allow interrupts. * We still want to block for a limited time, * so we allow interrupts during the timeout. */ - lwi = LWI_TIMEOUT_INTR_ALL(HZ, - ptlrpc_expired_set_void, - ptlrpc_interrupted_set, set); - else + rc = l_wait_event_abortable_timeout(set->set_waitq, + ptlrpc_check_set(NULL, set), + HZ); + if (rc == 0) { + rc = -ETIMEDOUT; + ptlrpc_expired_set(set); + } else if (rc < 0) { + rc = -EINTR; + ptlrpc_interrupted_set(set); + } else + rc = 0; + } else { /* * At least one request is in flight, so no * interrupts are allowed. Wait until all * complete, or an in-flight req times out. */ - lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, - ptlrpc_expired_set_void, set); - - rc = l_wait_event(set->set_waitq, ptlrpc_check_set(NULL, set), &lwi); - - /* - * LU-769 - if we ignored the signal because it was already - * pending when we started, we need to handle it now or we risk - * it being ignored forever - */ - if (rc == -ETIMEDOUT && !lwi.lwi_allow_intr && - signal_pending(current)) { - sigset_t blocked_sigs = - cfs_block_sigsinv(LUSTRE_FATAL_SIGS); - - /* - * In fact we only interrupt for the "fatal" signals - * like SIGINT or SIGKILL. We still ignore less - * important signals since ptlrpc set is not easily - * reentrant from userspace again - */ - if (signal_pending(current)) - ptlrpc_interrupted_set(set); - cfs_restore_sigs(blocked_sigs); + rc = wait_event_idle_timeout(set->set_waitq, + ptlrpc_check_set(NULL, set), + (timeout ? timeout : 1) * HZ); + if (rc == 0) { + ptlrpc_expired_set(set); + rc = -ETIMEDOUT; + /* + * LU-769 - if we ignored the signal + * because it was already pending when + * we started, we need to handle it + * now or we risk it being ignored + * forever + */ + if (l_fatal_signal_pending(current)) + ptlrpc_interrupted_set(set); + } else + rc = 0; } LASSERT(rc == 0 || rc == -EINTR || rc == -ETIMEDOUT); @@ -2528,7 +2514,7 @@ static int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async) return 0; /* - * We have to l_wait_event() whatever the result, to give liblustre + * We have to wait_event_idle_timeout() whatever the result, to give liblustre * a chance to run reply_in_callback(), and to make sure we've * unlinked before returning a req to the pool. */ From neilb at suse.com Mon Jan 8 03:28:14 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:14 +1100 Subject: [lustre-devel] [PATCH 19/19] staging: lustre: remove l_wait_event() and related code In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209403.23920.14521634003346477815.stgit@noble> These macros are no longer used, so they can be removed. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/include/lustre_lib.h | 249 -------------------- 1 file changed, 249 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h index ccc1a329e42b..1efd86f18c1f 100644 --- a/drivers/staging/lustre/lustre/include/lustre_lib.h +++ b/drivers/staging/lustre/lustre/include/lustre_lib.h @@ -76,123 +76,6 @@ int do_set_info_async(struct obd_import *imp, void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id); -/* - * l_wait_event is a flexible sleeping function, permitting simple caller - * configuration of interrupt and timeout sensitivity along with actions to - * be performed in the event of either exception. - * - * The first form of usage looks like this: - * - * struct l_wait_info lwi = LWI_TIMEOUT_INTR(timeout, timeout_handler, - * intr_handler, callback_data); - * rc = l_wait_event(waitq, condition, &lwi); - * - * l_wait_event() makes the current process wait on 'waitq' until 'condition' - * is TRUE or a "killable" signal (SIGTERM, SIKGILL, SIGINT) is pending. It - * returns 0 to signify 'condition' is TRUE, but if a signal wakes it before - * 'condition' becomes true, it optionally calls the specified 'intr_handler' - * if not NULL, and returns -EINTR. - * - * If a non-zero timeout is specified, signals are ignored until the timeout - * has expired. At this time, if 'timeout_handler' is not NULL it is called. - * If it returns FALSE l_wait_event() continues to wait as described above with - * signals enabled. Otherwise it returns -ETIMEDOUT. - * - * LWI_INTR(intr_handler, callback_data) is shorthand for - * LWI_TIMEOUT_INTR(0, NULL, intr_handler, callback_data) - * - * The second form of usage looks like this: - * - * struct l_wait_info lwi = LWI_TIMEOUT(timeout, timeout_handler); - * rc = l_wait_event(waitq, condition, &lwi); - * - * This form is the same as the first except that it COMPLETELY IGNORES - * SIGNALS. The caller must therefore beware that if 'timeout' is zero, or if - * 'timeout_handler' is not NULL and returns FALSE, then the ONLY thing that - * can unblock the current process is 'condition' becoming TRUE. - * - * Another form of usage is: - * struct l_wait_info lwi = LWI_TIMEOUT_INTERVAL(timeout, interval, - * timeout_handler); - * rc = l_wait_event(waitq, condition, &lwi); - * This is the same as previous case, but condition is checked once every - * 'interval' jiffies (if non-zero). - * - * Subtle synchronization point: this macro does *not* necessary takes - * wait-queue spin-lock before returning, and, hence, following idiom is safe - * ONLY when caller provides some external locking: - * - * Thread1 Thread2 - * - * l_wait_event(&obj->wq, ....); (1) - * - * wake_up(&obj->wq): (2) - * spin_lock(&q->lock); (2.1) - * __wake_up_common(q, ...); (2.2) - * spin_unlock(&q->lock, flags); (2.3) - * - * kfree(obj); (3) - * - * As l_wait_event() may "short-cut" execution and return without taking - * wait-queue spin-lock, some additional synchronization is necessary to - * guarantee that step (3) can begin only after (2.3) finishes. - * - * XXX nikita: some ptlrpc daemon threads have races of that sort. - * - */ - -#define LWI_ON_SIGNAL_NOOP ((void (*)(void *))(-1)) - -struct l_wait_info { - long lwi_timeout; - long lwi_interval; - int lwi_allow_intr; - int (*lwi_on_timeout)(void *); - void (*lwi_on_signal)(void *); - void *lwi_cb_data; -}; - -/* NB: LWI_TIMEOUT ignores signals completely */ -#define LWI_TIMEOUT(time, cb, data) \ -((struct l_wait_info) { \ - .lwi_timeout = time, \ - .lwi_on_timeout = cb, \ - .lwi_cb_data = data, \ - .lwi_interval = 0, \ - .lwi_allow_intr = 0 \ -}) - -#define LWI_TIMEOUT_INTERVAL(time, interval, cb, data) \ -((struct l_wait_info) { \ - .lwi_timeout = time, \ - .lwi_on_timeout = cb, \ - .lwi_cb_data = data, \ - .lwi_interval = interval, \ - .lwi_allow_intr = 0 \ -}) - -#define LWI_TIMEOUT_INTR(time, time_cb, sig_cb, data) \ -((struct l_wait_info) { \ - .lwi_timeout = time, \ - .lwi_on_timeout = time_cb, \ - .lwi_on_signal = sig_cb, \ - .lwi_cb_data = data, \ - .lwi_interval = 0, \ - .lwi_allow_intr = 0 \ -}) - -#define LWI_TIMEOUT_INTR_ALL(time, time_cb, sig_cb, data) \ -((struct l_wait_info) { \ - .lwi_timeout = time, \ - .lwi_on_timeout = time_cb, \ - .lwi_on_signal = sig_cb, \ - .lwi_cb_data = data, \ - .lwi_interval = 0, \ - .lwi_allow_intr = 1 \ -}) - -#define LWI_INTR(cb, data) LWI_TIMEOUT_INTR(0, NULL, cb, data) - #define LUSTRE_FATAL_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | \ sigmask(SIGTERM) | sigmask(SIGQUIT) | \ sigmask(SIGALRM)) @@ -201,138 +84,6 @@ static inline int l_fatal_signal_pending(struct task_struct *p) return signal_pending(p) && sigtestsetmask(&p->pending.signal, LUSTRE_FATAL_SIGS); } -/** - * wait_queue_entry_t of Linux (version < 2.6.34) is a FIFO list for exclusively - * waiting threads, which is not always desirable because all threads will - * be waken up again and again, even user only needs a few of them to be - * active most time. This is not good for performance because cache can - * be polluted by different threads. - * - * LIFO list can resolve this problem because we always wakeup the most - * recent active thread by default. - * - * NB: please don't call non-exclusive & exclusive wait on the same - * waitq if add_wait_queue_exclusive_head is used. - */ -#define add_wait_queue_exclusive_head(waitq, link) \ -{ \ - unsigned long flags; \ - \ - spin_lock_irqsave(&((waitq)->lock), flags); \ - __add_wait_queue_exclusive(waitq, link); \ - spin_unlock_irqrestore(&((waitq)->lock), flags); \ -} - -/* - * wait for @condition to become true, but no longer than timeout, specified - * by @info. - */ -#define __l_wait_event(wq, condition, info, ret, l_add_wait) \ -do { \ - wait_queue_entry_t __wait; \ - long __timeout = info->lwi_timeout; \ - sigset_t __blocked; \ - int __allow_intr = info->lwi_allow_intr; \ - \ - ret = 0; \ - if (condition) \ - break; \ - \ - init_waitqueue_entry(&__wait, current); \ - l_add_wait(&wq, &__wait); \ - \ - /* Block all signals (just the non-fatal ones if no timeout). */ \ - if (info->lwi_on_signal && (__timeout == 0 || __allow_intr)) \ - __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ - else \ - __blocked = cfs_block_sigsinv(0); \ - \ - for (;;) { \ - if (condition) \ - break; \ - \ - set_current_state(TASK_INTERRUPTIBLE); \ - \ - if (__timeout == 0) { \ - schedule(); \ - } else { \ - long interval = info->lwi_interval ? \ - min_t(long, \ - info->lwi_interval, __timeout) : \ - __timeout; \ - long remaining = schedule_timeout(interval);\ - __timeout = cfs_time_sub(__timeout, \ - cfs_time_sub(interval, remaining));\ - if (__timeout == 0) { \ - if (!info->lwi_on_timeout || \ - info->lwi_on_timeout(info->lwi_cb_data)) { \ - ret = -ETIMEDOUT; \ - break; \ - } \ - /* Take signals after the timeout expires. */ \ - if (info->lwi_on_signal) \ - (void)cfs_block_sigsinv(LUSTRE_FATAL_SIGS);\ - } \ - } \ - \ - set_current_state(TASK_RUNNING); \ - \ - if (condition) \ - break; \ - if (signal_pending(current)) { \ - if (info->lwi_on_signal && \ - (__timeout == 0 || __allow_intr)) { \ - if (info->lwi_on_signal != LWI_ON_SIGNAL_NOOP) \ - info->lwi_on_signal(info->lwi_cb_data);\ - ret = -EINTR; \ - break; \ - } \ - /* We have to do this here because some signals */ \ - /* are not blockable - ie from strace(1). */ \ - /* In these cases we want to schedule_timeout() */ \ - /* again, because we don't want that to return */ \ - /* -EINTR when the RPC actually succeeded. */ \ - /* the recalc_sigpending() below will deliver the */ \ - /* signal properly. */ \ - cfs_clear_sigpending(); \ - } \ - } \ - \ - cfs_restore_sigs(__blocked); \ - \ - remove_wait_queue(&wq, &__wait); \ -} while (0) - -#define l_wait_event(wq, condition, info) \ -({ \ - int __ret; \ - struct l_wait_info *__info = (info); \ - \ - __l_wait_event(wq, condition, __info, \ - __ret, add_wait_queue); \ - __ret; \ -}) - -#define l_wait_event_exclusive(wq, condition, info) \ -({ \ - int __ret; \ - struct l_wait_info *__info = (info); \ - \ - __l_wait_event(wq, condition, __info, \ - __ret, add_wait_queue_exclusive); \ - __ret; \ -}) - -#define l_wait_event_exclusive_head(wq, condition, info) \ -({ \ - int __ret; \ - struct l_wait_info *__info = (info); \ - \ - __l_wait_event(wq, condition, __info, \ - __ret, add_wait_queue_exclusive_head); \ - __ret; \ -}) - /** @} lib */ From neilb at suse.com Mon Jan 8 03:28:14 2018 From: neilb at suse.com (NeilBrown) Date: Mon, 08 Jan 2018 14:28:14 +1100 Subject: [lustre-devel] [PATCH 18/19] staging: lustre: replace l_wait_event_exclusive_head() with wait_event_idle_exclusive In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <151538209398.23920.3167444012358212836.stgit@noble> This l_wait_event_exclusive_head() will wait indefinitely if the timeout is zero. If it does wait with a timeout and times out, the timeout for next time is set to zero. The can be mapped to a call to either wait_event_idle_exclusive() or wait_event_idle_exclusive_timeout() depending in the timeout setting. The current code arrange for LIFO queuing of waiters, but include/event.h doesn't support that yet. Until it does, fall back on FIFO with wait_event_idle_exclusive{,_timeout}(). Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/ptlrpc/service.c | 43 ++++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c index 6e3403417434..29fdb54f16ca 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/service.c +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c @@ -1897,15 +1897,6 @@ ptlrpc_check_rqbd_pool(struct ptlrpc_service_part *svcpt) } } -static int -ptlrpc_retry_rqbds(void *arg) -{ - struct ptlrpc_service_part *svcpt = arg; - - svcpt->scp_rqbd_timeout = 0; - return -ETIMEDOUT; -} - static inline int ptlrpc_threads_enough(struct ptlrpc_service_part *svcpt) { @@ -1968,13 +1959,17 @@ ptlrpc_server_request_incoming(struct ptlrpc_service_part *svcpt) return !list_empty(&svcpt->scp_req_incoming); } +/* We perfer lifo queuing, but kernel doesn't provide that yet. */ +#ifndef wait_event_idle_exclusive_lifo +#define wait_event_idle_exclusive_lifo wait_event_idle_exclusive +#define wait_event_idle_exclusive_lifo_timeout wait_event_idle_exclusive_timeout +#endif + static __attribute__((__noinline__)) int ptlrpc_wait_event(struct ptlrpc_service_part *svcpt, struct ptlrpc_thread *thread) { /* Don't exit while there are replies to be handled */ - struct l_wait_info lwi = LWI_TIMEOUT(svcpt->scp_rqbd_timeout, - ptlrpc_retry_rqbds, svcpt); /* XXX: Add this back when libcfs watchdog is merged upstream lc_watchdog_disable(thread->t_watchdog); @@ -1982,13 +1977,25 @@ ptlrpc_wait_event(struct ptlrpc_service_part *svcpt, cond_resched(); - l_wait_event_exclusive_head(svcpt->scp_waitq, - ptlrpc_thread_stopping(thread) || - ptlrpc_server_request_incoming(svcpt) || - ptlrpc_server_request_pending(svcpt, - false) || - ptlrpc_rqbd_pending(svcpt) || - ptlrpc_at_check(svcpt), &lwi); + if (svcpt->scp_rqbd_timeout == 0) + wait_event_idle_exclusive_lifo( + svcpt->scp_waitq, + ptlrpc_thread_stopping(thread) || + ptlrpc_server_request_incoming(svcpt) || + ptlrpc_server_request_pending(svcpt, + false) || + ptlrpc_rqbd_pending(svcpt) || + ptlrpc_at_check(svcpt)); + else if (0 == wait_event_idle_exclusive_lifo_timeout( + svcpt->scp_waitq, + ptlrpc_thread_stopping(thread) || + ptlrpc_server_request_incoming(svcpt) || + ptlrpc_server_request_pending(svcpt, + false) || + ptlrpc_rqbd_pending(svcpt) || + ptlrpc_at_check(svcpt), + svcpt->scp_rqbd_timeout)) + svcpt->scp_rqbd_timeout = 0; if (ptlrpc_thread_stopping(thread)) return -EINTR; From gregkh at linuxfoundation.org Mon Jan 8 14:45:58 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 8 Jan 2018 15:45:58 +0100 Subject: [lustre-devel] [PATCH 3/4] staging: lustre: lnet: convert selftest to use workqueues In-Reply-To: <151356031919.15912.12406337913485020577.stgit@noble> References: <151356013394.15912.9645528414310488005.stgit@noble> <151356031919.15912.12406337913485020577.stgit@noble> Message-ID: <20180108144558.GA6826@kroah.com> On Mon, Dec 18, 2017 at 12:25:19PM +1100, NeilBrown wrote: > Instead of the cfs workitem library, use workqueues. > > As lnet wants to provide a cpu mask of allowed cpus, it > needs to be a WQ_UNBOUND work queue so that tasks can > run on cpus other than where they were submitted. This patch doesn't apply to my tree :( > apply_workqueue_atts needs to be exported for lustre to use it. That feels really odd, why is lustre so "special" that the normal workqueue api doesn't work properly for it? I've dropped this, and the next patch, from my queue now. Please fix up and resend and justify why lustre is so odd :) thanks, greg k-h From gregkh at linuxfoundation.org Mon Jan 8 14:51:57 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 8 Jan 2018 15:51:57 +0100 Subject: [lustre-devel] [PATCH 03/15] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: <151355799030.6200.8100283223734974485.stgit@noble> References: <151355781721.6200.2136335532722530242.stgit@noble> <151355799030.6200.8100283223734974485.stgit@noble> Message-ID: <20180108145157.GA32570@kroah.com> On Mon, Dec 18, 2017 at 11:46:30AM +1100, NeilBrown wrote: > All usages of the form > LIBCFS_ALLOC(variable, sizeof(variable)) > or > LIBCFS_ALLOC(variable, sizeof(variable's-type)) > > are changed to > variable = kzalloc(sizeof(...), GFP_NOFS); > > Similarly, all > LIBCFS_FREE(variable, sizeof(variable)) > become > kfree(variable); > > None of these need the vmalloc option, or any of the other minor > benefits of LIBCFS_ALLOC(). > > Signed-off-by: NeilBrown As this broke the kbuild system, I'll stop here in this patch series. Can you please fix it up, rebase and resend the remaining ones in this series? thanks, greg k-h From gregkh at linuxfoundation.org Mon Jan 8 14:52:28 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 8 Jan 2018 15:52:28 +0100 Subject: [lustre-devel] [PATCH 1/8] staging: lustre: Enclose complex macros in parantheses In-Reply-To: <4195720f60859773624344ef220517d9@christoph-volkert.de> References: <1513869932-27407-1-git-send-email-fabian_huegel@web.de> <1513869932-27407-2-git-send-email-fabian_huegel@web.de> <4195720f60859773624344ef220517d9@christoph-volkert.de> Message-ID: <20180108145228.GA32682@kroah.com> On Thu, Dec 21, 2017 at 04:43:27PM +0100, Christoph Volkert wrote: > This is a duplicate patch. We fixed a typo and this was still left as a > temporary file. (emacs…) Sorry. The patch with Message-Id > <1513869932-27407-3-git-send-email-fabian_huegel at web.de> is the right one. > > We can provide a new patch series without the fix, if needed. Please do, as I have no idea what to do otherwise. Consider this patch series dropped. thanks, greg k-h From gregkh at linuxfoundation.org Mon Jan 8 14:59:43 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 8 Jan 2018 15:59:43 +0100 Subject: [lustre-devel] [PATCH 5 v2: 00/19] staging: lustre: use standard wait_event macros In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: <20180108145943.GA5761@kroah.com> On Mon, Jan 08, 2018 at 02:28:13PM +1100, NeilBrown wrote: > Hi, > this is a revised version of the patch series I sent under a similar > subject in mid December. > Improvements are: > - new wait_event_idle* macros are now in include/linux/wait.h which > Ack from peterz. > - *all* waits are now TASK_IDLE or TASK_INTERRUPTIBLE and so don't > affect the load average. There is no need to choose whether load > is appropriate or not in each case. > - all l_wait_event() users are handled so l_wait_event() is > removed. The one case I had left out before uses > wait_event_idle_exclusive() with and option of using > wait_event_idle_exclusive_lifo() is that ever gets approved. > > I think this set is ready to go. > If you only review two patches, please review > > staging: lustre: simplify waiting in ldlm_completion_ast() > and > staging: lustre: remove back_to_sleep() > > as in both of those, the actual behaviour of the current code (as I > understand it) doesn't seem to agree with comments/debug message, or > just generally looks odd. This series broke the build, so I'll roll back my tree and drop it. Please fix it up and resend and test build it first... thanks, greg k-h From gregkh at linuxfoundation.org Mon Jan 8 15:06:00 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 8 Jan 2018 16:06:00 +0100 Subject: [lustre-devel] [PATCH 3/4] staging: lustre: lnet: convert selftest to use workqueues In-Reply-To: <20180108145527.GT3668920@devbig577.frc2.facebook.com> References: <151356013394.15912.9645528414310488005.stgit@noble> <151356031919.15912.12406337913485020577.stgit@noble> <20180108144558.GA6826@kroah.com> <20180108145527.GT3668920@devbig577.frc2.facebook.com> Message-ID: <20180108150600.GA19387@kroah.com> On Mon, Jan 08, 2018 at 06:55:27AM -0800, Tejun Heo wrote: > Hello, Greg. > > On Mon, Jan 08, 2018 at 03:45:58PM +0100, Greg Kroah-Hartman wrote: > > On Mon, Dec 18, 2017 at 12:25:19PM +1100, NeilBrown wrote: > > > Instead of the cfs workitem library, use workqueues. > > > > > > As lnet wants to provide a cpu mask of allowed cpus, it > > > needs to be a WQ_UNBOUND work queue so that tasks can > > > run on cpus other than where they were submitted. > > > > This patch doesn't apply to my tree :( > > > > > apply_workqueue_atts needs to be exported for lustre to use it. > > > > That feels really odd, why is lustre so "special" that the normal > > workqueue api doesn't work properly for it? > > > > I've dropped this, and the next patch, from my queue now. Please fix up > > and resend and justify why lustre is so odd :) > > The workqueue attrs interface is relatively new and just hasn't had > internal module users. It's not necessarily odd to want to use them > from modules. I'll be happy to ack patches which add > EXPORT_SYMBOL_GPL() on them. Ok, Neil, can you add Tejun's ack here when you respin this? thanks, greg k-h From jsimmons at infradead.org Mon Jan 8 16:21:50 2018 From: jsimmons at infradead.org (James Simmons) Date: Mon, 8 Jan 2018 16:21:50 +0000 (GMT) Subject: [lustre-devel] [PATCH 5 v2: 00/19] staging: lustre: use standard wait_event macros In-Reply-To: <20180108145943.GA5761@kroah.com> References: <151538168618.23920.8261096424342988792.stgit@noble> <20180108145943.GA5761@kroah.com> Message-ID: > On Mon, Jan 08, 2018 at 02:28:13PM +1100, NeilBrown wrote: > > Hi, > > this is a revised version of the patch series I sent under a similar > > subject in mid December. > > Improvements are: > > - new wait_event_idle* macros are now in include/linux/wait.h which > > Ack from peterz. > > - *all* waits are now TASK_IDLE or TASK_INTERRUPTIBLE and so don't > > affect the load average. There is no need to choose whether load > > is appropriate or not in each case. > > - all l_wait_event() users are handled so l_wait_event() is > > removed. The one case I had left out before uses > > wait_event_idle_exclusive() with and option of using > > wait_event_idle_exclusive_lifo() is that ever gets approved. > > > > I think this set is ready to go. > > If you only review two patches, please review > > > > staging: lustre: simplify waiting in ldlm_completion_ast() > > and > > staging: lustre: remove back_to_sleep() > > > > as in both of those, the actual behaviour of the current code (as I > > understand it) doesn't seem to agree with comments/debug message, or > > just generally looks odd. > > This series broke the build, so I'll roll back my tree and drop it. > > Please fix it up and resend and test build it first... Please don't merge these just yet. They need to be tested first. I don't want to be in a position where the lustre client is totally not usable like in the past. That kind of breakage makes no one want to use the lustre client. We have a test suite for these kinds of changes. Neill do you know how to test your patches with the test suite? Also I have been working on several things for the last 4 months to merge upstream. I like to coordinate with you so we don't step on each others toes. From gregkh at linuxfoundation.org Mon Jan 8 16:36:07 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 8 Jan 2018 17:36:07 +0100 Subject: [lustre-devel] [PATCH 5 v2: 00/19] staging: lustre: use standard wait_event macros In-Reply-To: References: <151538168618.23920.8261096424342988792.stgit@noble> <20180108145943.GA5761@kroah.com> Message-ID: <20180108163607.GA3046@kroah.com> On Mon, Jan 08, 2018 at 04:21:50PM +0000, James Simmons wrote: > > > On Mon, Jan 08, 2018 at 02:28:13PM +1100, NeilBrown wrote: > > > Hi, > > > this is a revised version of the patch series I sent under a similar > > > subject in mid December. > > > Improvements are: > > > - new wait_event_idle* macros are now in include/linux/wait.h which > > > Ack from peterz. > > > - *all* waits are now TASK_IDLE or TASK_INTERRUPTIBLE and so don't > > > affect the load average. There is no need to choose whether load > > > is appropriate or not in each case. > > > - all l_wait_event() users are handled so l_wait_event() is > > > removed. The one case I had left out before uses > > > wait_event_idle_exclusive() with and option of using > > > wait_event_idle_exclusive_lifo() is that ever gets approved. > > > > > > I think this set is ready to go. > > > If you only review two patches, please review > > > > > > staging: lustre: simplify waiting in ldlm_completion_ast() > > > and > > > staging: lustre: remove back_to_sleep() > > > > > > as in both of those, the actual behaviour of the current code (as I > > > understand it) doesn't seem to agree with comments/debug message, or > > > just generally looks odd. > > > > This series broke the build, so I'll roll back my tree and drop it. > > > > Please fix it up and resend and test build it first... > > Please don't merge these just yet. They need to be tested first. I don't > want to be in a position where the lustre client is totally not usable > like in the past. That kind of breakage makes no one want to use the > lustre client. We have a test suite for these kinds of changes. Neill do > you know how to test your patches with the test suite? Also I have been > working on several things for the last 4 months to merge upstream. I like > to coordinate with you so we don't step on each others toes. If I don't hear anything for a few weeks, I merge patches. That should be long enough to test... thanks, greg k-h From jsimmons at infradead.org Mon Jan 8 16:52:35 2018 From: jsimmons at infradead.org (James Simmons) Date: Mon, 8 Jan 2018 16:52:35 +0000 (GMT) Subject: [lustre-devel] [PATCH 04/19] staging: lustre: discard cfs_time_seconds() In-Reply-To: <151538209341.23920.8613572158448297057.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209341.23920.8613572158448297057.stgit@noble> Message-ID: > cfs_time_seconds() converts a number of seconds to the > matching number of jiffies. > The standard way to do this in Linux is "* HZ". > So discard cfs_time_seconds() and use "* HZ" instead. Just to make you aware I have been working for several months on moving lustre away from using jiffies as much as possible. The problem with using HZ is that it can vary. So when you have a parallel file system with batches of nodes that have different values of HZ you can get very interesting corner cases. So I have been moving everything over to time64_t and ktime. Also I mostly have killed off the cfs_time_shift* and crap as well. You see all work under https://jira.hpdd.intel.com/browse/LU-9019. So many of the cases you did below don't event exist any more. I was planning to push those changes after the next merge window. > > Signed-off-by: NeilBrown > --- > .../lustre/include/linux/libcfs/libcfs_debug.h | 4 ++-- > .../lustre/include/linux/libcfs/libcfs_time.h | 2 +- > .../lustre/include/linux/libcfs/linux/linux-time.h | 7 +----- > .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 8 ++++--- > .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 4 ++-- > .../staging/lustre/lnet/klnds/socklnd/socklnd.c | 6 +++-- > .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 22 ++++++++++---------- > drivers/staging/lustre/lnet/libcfs/debug.c | 2 +- > drivers/staging/lustre/lnet/libcfs/fail.c | 2 +- > drivers/staging/lustre/lnet/libcfs/tracefile.c | 4 ++-- > drivers/staging/lustre/lnet/lnet/acceptor.c | 2 +- > drivers/staging/lustre/lnet/lnet/api-ni.c | 4 ++-- > drivers/staging/lustre/lnet/lnet/lib-move.c | 4 ++-- > drivers/staging/lustre/lnet/lnet/net_fault.c | 14 +++++-------- > drivers/staging/lustre/lnet/lnet/peer.c | 2 +- > drivers/staging/lustre/lnet/lnet/router.c | 8 ++++--- > drivers/staging/lustre/lnet/selftest/conrpc.c | 4 ++-- > drivers/staging/lustre/lnet/selftest/rpc.c | 2 +- > drivers/staging/lustre/lnet/selftest/selftest.h | 2 +- > drivers/staging/lustre/lnet/selftest/timer.c | 2 +- > drivers/staging/lustre/lustre/include/lustre_dlm.h | 2 +- > drivers/staging/lustre/lustre/include/lustre_mdc.h | 2 +- > drivers/staging/lustre/lustre/include/lustre_net.h | 2 +- > drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 2 +- > drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 4 ++-- > drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 2 +- > drivers/staging/lustre/lustre/ldlm/ldlm_request.c | 2 +- > drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 2 +- > drivers/staging/lustre/lustre/llite/llite_lib.c | 4 ++-- > drivers/staging/lustre/lustre/llite/statahead.c | 2 +- > drivers/staging/lustre/lustre/lov/lov_request.c | 4 ++-- > drivers/staging/lustre/lustre/mdc/mdc_request.c | 2 +- > drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- > drivers/staging/lustre/lustre/obdclass/cl_io.c | 2 +- > .../staging/lustre/lustre/obdecho/echo_client.c | 2 +- > drivers/staging/lustre/lustre/osc/osc_cache.c | 4 ++-- > drivers/staging/lustre/lustre/osc/osc_object.c | 2 +- > drivers/staging/lustre/lustre/ptlrpc/client.c | 10 +++++---- > drivers/staging/lustre/lustre/ptlrpc/events.c | 2 +- > drivers/staging/lustre/lustre/ptlrpc/import.c | 15 ++++++-------- > drivers/staging/lustre/lustre/ptlrpc/niobuf.c | 4 ++-- > .../staging/lustre/lustre/ptlrpc/pack_generic.c | 2 +- > drivers/staging/lustre/lustre/ptlrpc/pinger.c | 8 ++++--- > drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 4 ++-- > drivers/staging/lustre/lustre/ptlrpc/recover.c | 2 +- > drivers/staging/lustre/lustre/ptlrpc/service.c | 8 ++++--- > 46 files changed, 96 insertions(+), 106 deletions(-) > > diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h > index 1b98f0953afb..9290a19429e7 100644 > --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h > +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h > @@ -66,8 +66,8 @@ extern unsigned int libcfs_panic_on_lbug; > # define DEBUG_SUBSYSTEM S_UNDEFINED > #endif > > -#define CDEBUG_DEFAULT_MAX_DELAY (cfs_time_seconds(600)) /* jiffies */ > -#define CDEBUG_DEFAULT_MIN_DELAY ((cfs_time_seconds(1) + 1) / 2) /* jiffies */ > +#define CDEBUG_DEFAULT_MAX_DELAY (600 * HZ) /* jiffies */ > +#define CDEBUG_DEFAULT_MIN_DELAY ((HZ + 1) / 2) /* jiffies */ > #define CDEBUG_DEFAULT_BACKOFF 2 > struct cfs_debug_limit_state { > unsigned long cdls_next; > diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h > index 9699646decb9..c4f25be78268 100644 > --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h > +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h > @@ -62,7 +62,7 @@ static inline int cfs_time_aftereq(unsigned long t1, unsigned long t2) > > static inline unsigned long cfs_time_shift(int seconds) > { > - return cfs_time_add(cfs_time_current(), cfs_time_seconds(seconds)); > + return cfs_time_add(cfs_time_current(), seconds * HZ); > } > > /* > diff --git a/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h b/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h > index aece13698eb4..805cb326af86 100644 > --- a/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h > +++ b/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h > @@ -65,11 +65,6 @@ static inline unsigned long cfs_time_current(void) > return jiffies; > } > > -static inline long cfs_time_seconds(int seconds) > -{ > - return ((long)seconds) * msecs_to_jiffies(MSEC_PER_SEC); > -} > - > static inline long cfs_duration_sec(long d) > { > return d / msecs_to_jiffies(MSEC_PER_SEC); > @@ -85,7 +80,7 @@ static inline u64 cfs_time_add_64(u64 t, u64 d) > static inline u64 cfs_time_shift_64(int seconds) > { > return cfs_time_add_64(cfs_time_current_64(), > - cfs_time_seconds(seconds)); > + seconds * HZ); > } > > static inline int cfs_time_before_64(u64 t1, u64 t2) > diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > index bb7b19473e3a..8a49f7730308 100644 > --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > @@ -1219,7 +1219,7 @@ static struct kib_hca_dev *kiblnd_current_hdev(struct kib_dev *dev) > CDEBUG(D_NET, "%s: Wait for failover\n", > dev->ibd_ifname); > set_current_state(TASK_INTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1) / 100); > + schedule_timeout(HZ / 100); > > read_lock_irqsave(&kiblnd_data.kib_global_lock, flags); > } > @@ -1930,7 +1930,7 @@ struct list_head *kiblnd_pool_alloc_node(struct kib_poolset *ps) > > set_current_state(TASK_INTERRUPTIBLE); > schedule_timeout(interval); > - if (interval < cfs_time_seconds(1)) > + if (interval < HZ) > interval *= 2; > > goto again; > @@ -2567,7 +2567,7 @@ static void kiblnd_base_shutdown(void) > "Waiting for %d threads to terminate\n", > atomic_read(&kiblnd_data.kib_nthreads)); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > } > > /* fall through */ > @@ -2618,7 +2618,7 @@ static void kiblnd_shutdown(struct lnet_ni *ni) > libcfs_nid2str(ni->ni_nid), > atomic_read(&net->ibn_npeers)); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > } > > kiblnd_net_fini_pools(net); > diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > index 9b3328c5d1e7..0b30c205e760 100644 > --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > @@ -3726,8 +3726,8 @@ kiblnd_failover_thread(void *arg) > add_wait_queue(&kiblnd_data.kib_failover_waitq, &wait); > write_unlock_irqrestore(glock, flags); > > - rc = schedule_timeout(long_sleep ? cfs_time_seconds(10) : > - cfs_time_seconds(1)); > + rc = schedule_timeout(long_sleep ? 10 * HZ : > + HZ); > remove_wait_queue(&kiblnd_data.kib_failover_waitq, &wait); > write_lock_irqsave(glock, flags); > > diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c > index 7dba949a95a7..6ab876d8c744 100644 > --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c > +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c > @@ -1677,7 +1677,7 @@ ksocknal_destroy_conn(struct ksock_conn *conn) > switch (conn->ksnc_rx_state) { > case SOCKNAL_RX_LNET_PAYLOAD: > last_rcv = conn->ksnc_rx_deadline - > - cfs_time_seconds(*ksocknal_tunables.ksnd_timeout); > + *ksocknal_tunables.ksnd_timeout * HZ; > CERROR("Completing partial receive from %s[%d], ip %pI4h:%d, with error, wanted: %zd, left: %d, last alive is %ld secs ago\n", > libcfs_id2str(conn->ksnc_peer->ksnp_id), conn->ksnc_type, > &conn->ksnc_ipaddr, conn->ksnc_port, > @@ -2361,7 +2361,7 @@ ksocknal_base_shutdown(void) > ksocknal_data.ksnd_nthreads); > read_unlock(&ksocknal_data.ksnd_global_lock); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > read_lock(&ksocknal_data.ksnd_global_lock); > } > read_unlock(&ksocknal_data.ksnd_global_lock); > @@ -2604,7 +2604,7 @@ ksocknal_shutdown(struct lnet_ni *ni) > "waiting for %d peers to disconnect\n", > net->ksnn_npeers); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > > ksocknal_debug_peerhash(ni); > > diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c > index 11fd3a36424f..63e452f666bf 100644 > --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c > +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c > @@ -189,7 +189,7 @@ ksocknal_transmit(struct ksock_conn *conn, struct ksock_tx *tx) > > if (ksocknal_data.ksnd_stall_tx) { > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(ksocknal_data.ksnd_stall_tx)); > + schedule_timeout(ksocknal_data.ksnd_stall_tx * HZ); > } > > LASSERT(tx->tx_resid); > @@ -294,7 +294,7 @@ ksocknal_receive(struct ksock_conn *conn) > > if (ksocknal_data.ksnd_stall_rx) { > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(ksocknal_data.ksnd_stall_rx)); > + schedule_timeout(ksocknal_data.ksnd_stall_rx * HZ); > } > > rc = ksocknal_connsock_addref(conn); > @@ -1780,7 +1780,7 @@ ksocknal_connect(struct ksock_route *route) > int rc = 0; > > deadline = cfs_time_add(cfs_time_current(), > - cfs_time_seconds(*ksocknal_tunables.ksnd_timeout)); > + *ksocknal_tunables.ksnd_timeout * HZ); > > write_lock_bh(&ksocknal_data.ksnd_global_lock); > > @@ -1878,7 +1878,7 @@ ksocknal_connect(struct ksock_route *route) > * so min_reconnectms should be good heuristic > */ > route->ksnr_retry_interval = > - cfs_time_seconds(*ksocknal_tunables.ksnd_min_reconnectms) / 1000; > + *ksocknal_tunables.ksnd_min_reconnectms * HZ / 1000; > route->ksnr_timeout = cfs_time_add(cfs_time_current(), > route->ksnr_retry_interval); > } > @@ -1899,10 +1899,10 @@ ksocknal_connect(struct ksock_route *route) > route->ksnr_retry_interval *= 2; > route->ksnr_retry_interval = > max(route->ksnr_retry_interval, > - cfs_time_seconds(*ksocknal_tunables.ksnd_min_reconnectms) / 1000); > + (long)*ksocknal_tunables.ksnd_min_reconnectms * HZ / 1000); > route->ksnr_retry_interval = > min(route->ksnr_retry_interval, > - cfs_time_seconds(*ksocknal_tunables.ksnd_max_reconnectms) / 1000); > + (long)*ksocknal_tunables.ksnd_max_reconnectms * HZ / 1000); > > LASSERT(route->ksnr_retry_interval); > route->ksnr_timeout = cfs_time_add(cfs_time_current(), > @@ -1972,7 +1972,7 @@ ksocknal_connd_check_start(time64_t sec, long *timeout) > > if (sec - ksocknal_data.ksnd_connd_failed_stamp <= 1) { > /* may run out of resource, retry later */ > - *timeout = cfs_time_seconds(1); > + *timeout = HZ; > return 0; > } > > @@ -2031,8 +2031,8 @@ ksocknal_connd_check_stop(time64_t sec, long *timeout) > val = (int)(ksocknal_data.ksnd_connd_starting_stamp + > SOCKNAL_CONND_TIMEOUT - sec); > > - *timeout = (val > 0) ? cfs_time_seconds(val) : > - cfs_time_seconds(SOCKNAL_CONND_TIMEOUT); > + *timeout = (val > 0) ? val * HZ : > + SOCKNAL_CONND_TIMEOUT * HZ; > if (val > 0) > return 0; > > @@ -2307,7 +2307,7 @@ ksocknal_send_keepalive_locked(struct ksock_peer *peer) > if (*ksocknal_tunables.ksnd_keepalive <= 0 || > time_before(cfs_time_current(), > cfs_time_add(peer->ksnp_last_alive, > - cfs_time_seconds(*ksocknal_tunables.ksnd_keepalive)))) > + *ksocknal_tunables.ksnd_keepalive * HZ))) > return 0; > > if (time_before(cfs_time_current(), peer->ksnp_send_keepalive)) > @@ -2563,7 +2563,7 @@ ksocknal_reaper(void *arg) > ksocknal_data.ksnd_peer_hash_size; > } > > - deadline = cfs_time_add(deadline, cfs_time_seconds(p)); > + deadline = cfs_time_add(deadline, p * HZ); > } > > if (nenomem_conns) { > diff --git a/drivers/staging/lustre/lnet/libcfs/debug.c b/drivers/staging/lustre/lnet/libcfs/debug.c > index 551c45bf4108..c70d2ae29b11 100644 > --- a/drivers/staging/lustre/lnet/libcfs/debug.c > +++ b/drivers/staging/lustre/lnet/libcfs/debug.c > @@ -113,7 +113,7 @@ static int param_set_delay_minmax(const char *val, > if (rc) > return -EINVAL; > > - d = cfs_time_seconds(sec) / 100; > + d = sec * HZ / 100; > if (d < min || d > max) > return -EINVAL; > > diff --git a/drivers/staging/lustre/lnet/libcfs/fail.c b/drivers/staging/lustre/lnet/libcfs/fail.c > index 39439b303d65..d3f1e866c6a7 100644 > --- a/drivers/staging/lustre/lnet/libcfs/fail.c > +++ b/drivers/staging/lustre/lnet/libcfs/fail.c > @@ -134,7 +134,7 @@ int __cfs_fail_timeout_set(u32 id, u32 value, int ms, int set) > CERROR("cfs_fail_timeout id %x sleeping for %dms\n", > id, ms); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(ms) / 1000); > + schedule_timeout(ms * HZ / 1000); > CERROR("cfs_fail_timeout id %x awake\n", id); > } > return ret; > diff --git a/drivers/staging/lustre/lnet/libcfs/tracefile.c b/drivers/staging/lustre/lnet/libcfs/tracefile.c > index da2844f37edf..8c33c8fa66e2 100644 > --- a/drivers/staging/lustre/lnet/libcfs/tracefile.c > +++ b/drivers/staging/lustre/lnet/libcfs/tracefile.c > @@ -441,7 +441,7 @@ int libcfs_debug_vmsg2(struct libcfs_debug_msg_data *msgdata, > > if (cfs_time_after(cfs_time_current(), > cdls->cdls_next + libcfs_console_max_delay + > - cfs_time_seconds(10))) { > + 10 * HZ)) { > /* last timeout was a long time ago */ > cdls->cdls_delay /= libcfs_console_backoff * 4; > } else { > @@ -1071,7 +1071,7 @@ static int tracefiled(void *arg) > init_waitqueue_entry(&__wait, current); > add_wait_queue(&tctl->tctl_waitq, &__wait); > set_current_state(TASK_INTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > remove_wait_queue(&tctl->tctl_waitq, &__wait); > } > complete(&tctl->tctl_stop); > diff --git a/drivers/staging/lustre/lnet/lnet/acceptor.c b/drivers/staging/lustre/lnet/lnet/acceptor.c > index ee85cab6f437..6c1f4941d4ba 100644 > --- a/drivers/staging/lustre/lnet/lnet/acceptor.c > +++ b/drivers/staging/lustre/lnet/lnet/acceptor.c > @@ -365,7 +365,7 @@ lnet_acceptor(void *arg) > if (rc != -EAGAIN) { > CWARN("Accept error %d: pausing...\n", rc); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > } > continue; > } > diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c > index 6a1fb0397604..ddd37eae63c6 100644 > --- a/drivers/staging/lustre/lnet/lnet/api-ni.c > +++ b/drivers/staging/lustre/lnet/lnet/api-ni.c > @@ -973,7 +973,7 @@ lnet_ping_md_unlink(struct lnet_ping_info *pinfo, > while (pinfo->pi_features != LNET_PING_FEAT_INVAL) { > CDEBUG(D_NET, "Still waiting for ping MD to unlink\n"); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > } > > cfs_restore_sigs(blocked); > @@ -1112,7 +1112,7 @@ lnet_clear_zombies_nis_locked(void) > libcfs_nid2str(ni->ni_nid)); > } > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > lnet_net_lock(LNET_LOCK_EX); > continue; > } > diff --git a/drivers/staging/lustre/lnet/lnet/lib-move.c b/drivers/staging/lustre/lnet/lnet/lib-move.c > index d724c4c73ecc..7fe7ae917273 100644 > --- a/drivers/staging/lustre/lnet/lnet/lib-move.c > +++ b/drivers/staging/lustre/lnet/lnet/lib-move.c > @@ -524,7 +524,7 @@ lnet_peer_is_alive(struct lnet_peer *lp, unsigned long now) > return 0; > > deadline = cfs_time_add(lp->lp_last_alive, > - cfs_time_seconds(lp->lp_ni->ni_peertimeout)); > + lp->lp_ni->ni_peertimeout * HZ); > alive = cfs_time_after(deadline, now); > > /* Update obsolete lp_alive except for routers assumed to be dead > @@ -562,7 +562,7 @@ lnet_peer_alive_locked(struct lnet_peer *lp) > > unsigned long next_query = > cfs_time_add(lp->lp_last_query, > - cfs_time_seconds(lnet_queryinterval)); > + lnet_queryinterval * HZ); > > if (time_before(now, next_query)) { > if (lp->lp_alive) > diff --git a/drivers/staging/lustre/lnet/lnet/net_fault.c b/drivers/staging/lustre/lnet/lnet/net_fault.c > index e3468cef273b..a63b7941d435 100644 > --- a/drivers/staging/lustre/lnet/lnet/net_fault.c > +++ b/drivers/staging/lustre/lnet/lnet/net_fault.c > @@ -315,9 +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( > - prandom_u32_max(attr->u.drop.da_interval)); > - rule->dr_time_base += cfs_time_seconds(attr->u.drop.da_interval); > + prandom_u32_max(attr->u.drop.da_interval) * HZ; > + rule->dr_time_base += attr->u.drop.da_interval * HZ; > > CDEBUG(D_NET, "Drop Rule %s->%s: next drop : %lu\n", > libcfs_nid2str(attr->fa_src), > @@ -440,8 +439,7 @@ static struct delay_daemon_data delay_dd; > static unsigned long > round_timeout(unsigned long timeout) > { > - return cfs_time_seconds((unsigned int) > - cfs_duration_sec(cfs_time_sub(timeout, 0)) + 1); > + return (unsigned int)rounddown(timeout, HZ) + HZ; > } > > static void > @@ -483,10 +481,8 @@ 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( > - prandom_u32_max( > - attr->u.delay.la_interval)); > - rule->dl_time_base += cfs_time_seconds(attr->u.delay.la_interval); > + prandom_u32_max(attr->u.delay.la_interval) * HZ; > + rule->dl_time_base += attr->u.delay.la_interval * HZ; > > CDEBUG(D_NET, "Delay Rule %s->%s: next delay : %lu\n", > libcfs_nid2str(attr->fa_src), > diff --git a/drivers/staging/lustre/lnet/lnet/peer.c b/drivers/staging/lustre/lnet/lnet/peer.c > index 19fcbcf0f642..89610f768b4f 100644 > --- a/drivers/staging/lustre/lnet/lnet/peer.c > +++ b/drivers/staging/lustre/lnet/lnet/peer.c > @@ -137,7 +137,7 @@ lnet_peer_table_deathrow_wait_locked(struct lnet_peer_table *ptable, > ptable->pt_zombies); > } > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1) >> 1); > + schedule_timeout(HZ >> 1); > lnet_net_lock(cpt_locked); > } > } > diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c > index 476d6d296037..47a98d50ebc7 100644 > --- a/drivers/staging/lustre/lnet/lnet/router.c > +++ b/drivers/staging/lustre/lnet/lnet/router.c > @@ -808,7 +808,7 @@ lnet_wait_known_routerstate(void) > return; > > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > } > } > > @@ -1011,7 +1011,7 @@ lnet_ping_router_locked(struct lnet_peer *rtr) > > if (secs && !rtr->lp_ping_notsent && > cfs_time_after(now, cfs_time_add(rtr->lp_ping_timestamp, > - cfs_time_seconds(secs)))) { > + secs * HZ))) { > int rc; > struct lnet_process_id id; > struct lnet_handle_md mdh; > @@ -1185,7 +1185,7 @@ lnet_prune_rc_data(int wait_unlink) > CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET, > "Waiting for rc buffers to unlink\n"); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1) / 4); > + schedule_timeout(HZ / 4); > > lnet_net_lock(LNET_LOCK_EX); > } > @@ -1282,7 +1282,7 @@ lnet_router_checker(void *arg) > else > wait_event_interruptible_timeout(the_lnet.ln_rc_waitq, > false, > - cfs_time_seconds(1)); > + HZ); > } > > lnet_prune_rc_data(1); /* wait for UNLINK */ > diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c > index 7aa515c34594..6dcc966b293b 100644 > --- a/drivers/staging/lustre/lnet/selftest/conrpc.c > +++ b/drivers/staging/lustre/lnet/selftest/conrpc.c > @@ -359,7 +359,7 @@ lstcon_rpc_trans_postwait(struct lstcon_rpc_trans *trans, int timeout) > > rc = wait_event_interruptible_timeout(trans->tas_waitq, > lstcon_rpc_trans_check(trans), > - cfs_time_seconds(timeout)); > + timeout * HZ); > rc = (rc > 0) ? 0 : ((rc < 0) ? -EINTR : -ETIMEDOUT); > > mutex_lock(&console_session.ses_mutex); > @@ -1350,7 +1350,7 @@ lstcon_rpc_cleanup_wait(void) > > CWARN("Session is shutting down, waiting for termination of transactions\n"); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > > mutex_lock(&console_session.ses_mutex); > } > diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c > index b515138dca2c..18e0f1b87fc1 100644 > --- a/drivers/staging/lustre/lnet/selftest/rpc.c > +++ b/drivers/staging/lustre/lnet/selftest/rpc.c > @@ -1605,7 +1605,7 @@ srpc_startup(void) > > /* 1 second pause to avoid timestamp reuse */ > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > srpc_data.rpc_matchbits = ((__u64)ktime_get_real_seconds()) << 48; > > srpc_data.rpc_state = SRPC_STATE_NONE; > diff --git a/drivers/staging/lustre/lnet/selftest/selftest.h b/drivers/staging/lustre/lnet/selftest/selftest.h > index ad04534f000c..05466b85e1c0 100644 > --- a/drivers/staging/lustre/lnet/selftest/selftest.h > +++ b/drivers/staging/lustre/lnet/selftest/selftest.h > @@ -575,7 +575,7 @@ swi_state2str(int state) > #define selftest_wait_events() \ > do { \ > set_current_state(TASK_UNINTERRUPTIBLE); \ > - schedule_timeout(cfs_time_seconds(1) / 10); \ > + schedule_timeout(HZ / 10); \ > } while (0) > > #define lst_wait_until(cond, lock, fmt, ...) \ > diff --git a/drivers/staging/lustre/lnet/selftest/timer.c b/drivers/staging/lustre/lnet/selftest/timer.c > index ab125a8524c5..9716afeb3c94 100644 > --- a/drivers/staging/lustre/lnet/selftest/timer.c > +++ b/drivers/staging/lustre/lnet/selftest/timer.c > @@ -177,7 +177,7 @@ stt_timer_main(void *arg) > > rc = wait_event_timeout(stt_data.stt_waitq, > stt_data.stt_shuttingdown, > - cfs_time_seconds(STTIMER_SLOTTIME)); > + STTIMER_SLOTTIME * HZ); > } > > spin_lock(&stt_data.stt_lock); > diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h > index e0b17052b2ea..239aa2b1268f 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h > +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h > @@ -60,7 +60,7 @@ struct obd_device; > #define OBD_LDLM_DEVICENAME "ldlm" > > #define LDLM_DEFAULT_LRU_SIZE (100 * num_online_cpus()) > -#define LDLM_DEFAULT_MAX_ALIVE (cfs_time_seconds(3900)) /* 65 min */ > +#define LDLM_DEFAULT_MAX_ALIVE (65 * 60 * HZ) /* 65 min */ > #define LDLM_DEFAULT_PARALLEL_AST_LIMIT 1024 > > /** > diff --git a/drivers/staging/lustre/lustre/include/lustre_mdc.h b/drivers/staging/lustre/lustre/include/lustre_mdc.h > index 007e1ec3f0f4..a9c9992a2502 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_mdc.h > +++ b/drivers/staging/lustre/lustre/include/lustre_mdc.h > @@ -124,7 +124,7 @@ static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck, > */ > while (unlikely(lck->rpcl_it == MDC_FAKE_RPCL_IT)) { > mutex_unlock(&lck->rpcl_mutex); > - schedule_timeout(cfs_time_seconds(1) / 4); > + schedule_timeout(HZ / 4); > goto again; > } > > diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h > index 4c665eca2467..5a4434e7c85a 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_net.h > +++ b/drivers/staging/lustre/lustre/include/lustre_net.h > @@ -2262,7 +2262,7 @@ static inline int ptlrpc_send_limit_expired(struct ptlrpc_request *req) > { > if (req->rq_delay_limit != 0 && > time_before(cfs_time_add(req->rq_queued_time, > - cfs_time_seconds(req->rq_delay_limit)), > + req->rq_delay_limit * HZ), > cfs_time_current())) { > return 1; > } > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > index 4f700ddb47c6..773abe78708a 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > @@ -1366,7 +1366,7 @@ enum ldlm_mode ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags, > } > } > > - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(obd_timeout), > + lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, > NULL, LWI_ON_SIGNAL_NOOP, NULL); > > /* XXX FIXME see comment on CAN_MATCH in lustre_dlm.h */ > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c > index 6c7c4b19a0a0..58913e628124 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c > @@ -163,7 +163,7 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req, > LDLM_DEBUG(lock, "client completion callback handler START"); > > if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE)) { > - int to = cfs_time_seconds(1); > + int to = HZ; > > while (to > 0) { > set_current_state(TASK_INTERRUPTIBLE); > @@ -327,7 +327,7 @@ static void ldlm_handle_gl_callback(struct ptlrpc_request *req, > !lock->l_readers && !lock->l_writers && > cfs_time_after(cfs_time_current(), > cfs_time_add(lock->l_last_used, > - cfs_time_seconds(10)))) { > + 10 * HZ))) { > unlock_res_and_lock(lock); > if (ldlm_bl_to_thread_lock(ns, NULL, lock)) > ldlm_handle_bl_callback(ns, NULL, lock); > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > index f27c2694793a..622245a5f049 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > @@ -1008,7 +1008,7 @@ static int ldlm_pools_thread_main(void *arg) > * Wait until the next check time, or until we're > * stopped. > */ > - lwi = LWI_TIMEOUT(cfs_time_seconds(c_time), > + lwi = LWI_TIMEOUT(c_time * HZ, > NULL, NULL); > l_wait_event(thread->t_ctl_waitq, > thread_is_stopping(thread) || > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c > index 6aa37463db46..a244fa717134 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c > @@ -288,7 +288,7 @@ int ldlm_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) > LDLM_DEBUG(lock, "waiting indefinitely because of NO_TIMEOUT"); > lwi = LWI_INTR(interrupted_completion_wait, &lwd); > } else { > - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(timeout), > + lwi = LWI_TIMEOUT_INTR(timeout * HZ, > ldlm_expired_completion_wait, > interrupted_completion_wait, &lwd); > } > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c > index 9958533cc227..2e66825c8f4b 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c > @@ -799,7 +799,7 @@ static void cleanup_resource(struct ldlm_resource *res, struct list_head *q, > LDLM_DEBUG(lock, "setting FL_LOCAL_ONLY"); > if (lock->l_flags & LDLM_FL_FAIL_LOC) { > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(4)); > + schedule_timeout(4 * HZ); > set_current_state(TASK_RUNNING); > } > if (lock->l_completion_ast) > diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c > index 6735a6f006d2..0a9183f271f5 100644 > --- a/drivers/staging/lustre/lustre/llite/llite_lib.c > +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c > @@ -2026,8 +2026,8 @@ void ll_umount_begin(struct super_block *sb) > * to decrement mnt_cnt and hope to finish it within 10sec. > */ > init_waitqueue_head(&waitq); > - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(10), > - cfs_time_seconds(1), NULL, NULL); > + lwi = LWI_TIMEOUT_INTERVAL(10 * HZ, > + HZ, NULL, NULL); > l_wait_event(waitq, may_umount(sbi->ll_mnt.mnt), &lwi); > > schedule(); > diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c > index 78005cc6e831..96360f104b92 100644 > --- a/drivers/staging/lustre/lustre/llite/statahead.c > +++ b/drivers/staging/lustre/lustre/llite/statahead.c > @@ -1424,7 +1424,7 @@ static int revalidate_statahead_dentry(struct inode *dir, > spin_lock(&lli->lli_sa_lock); > sai->sai_index_wait = entry->se_index; > spin_unlock(&lli->lli_sa_lock); > - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(30), NULL, > + lwi = LWI_TIMEOUT_INTR(30 * HZ, NULL, > LWI_ON_SIGNAL_NOOP, NULL); > rc = l_wait_event(sai->sai_waitq, sa_ready(entry), &lwi); > if (rc < 0) { > diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c > index cfa1d7f92b0f..fb3b7a7fa32a 100644 > --- a/drivers/staging/lustre/lustre/lov/lov_request.c > +++ b/drivers/staging/lustre/lustre/lov/lov_request.c > @@ -126,8 +126,8 @@ static int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx) > mutex_unlock(&lov->lov_lock); > > init_waitqueue_head(&waitq); > - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(obd_timeout), > - cfs_time_seconds(1), NULL, NULL); > + lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ, > + HZ, NULL, NULL); > > rc = l_wait_event(waitq, lov_check_set(lov, ost_idx), &lwi); > if (tgt->ltd_active) > diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c > index 03e55bca4ada..b12518ba5ae9 100644 > --- a/drivers/staging/lustre/lustre/mdc/mdc_request.c > +++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c > @@ -888,7 +888,7 @@ static int mdc_getpage(struct obd_export *exp, const struct lu_fid *fid, > exp->exp_obd->obd_name, -EIO); > return -EIO; > } > - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends), NULL, NULL, > + lwi = LWI_TIMEOUT_INTR(resends * HZ, NULL, NULL, > NULL); > l_wait_event(waitq, 0, &lwi); > > diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c > index b743aee62349..a01d13bde102 100644 > --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c > +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c > @@ -1628,7 +1628,7 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld) > > if (rcl == -ESHUTDOWN && > atomic_read(&mgc->u.cli.cl_mgc_refcount) > 0 && !retry) { > - int secs = cfs_time_seconds(obd_timeout); > + int secs = obd_timeout * HZ; > struct obd_import *imp; > struct l_wait_info lwi; > > diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c > index 902bad22013b..ce5e7bdda692 100644 > --- a/drivers/staging/lustre/lustre/obdclass/cl_io.c > +++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c > @@ -1097,7 +1097,7 @@ EXPORT_SYMBOL(cl_sync_io_init); > int cl_sync_io_wait(const struct lu_env *env, struct cl_sync_io *anchor, > long timeout) > { > - struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(timeout), > + struct l_wait_info lwi = LWI_TIMEOUT_INTR(timeout * HZ, > NULL, NULL, NULL); > int rc; > > diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c > index b9c1dc7e61b0..9c5ce5074b66 100644 > --- a/drivers/staging/lustre/lustre/obdecho/echo_client.c > +++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c > @@ -752,7 +752,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env, > spin_unlock(&ec->ec_lock); > CERROR("echo_client still has objects at cleanup time, wait for 1 second\n"); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > lu_site_purge(env, ed->ed_site, -1); > spin_lock(&ec->ec_lock); > } > diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c > index b8d5adca94e1..0797e671f667 100644 > --- a/drivers/staging/lustre/lustre/osc/osc_cache.c > +++ b/drivers/staging/lustre/lustre/osc/osc_cache.c > @@ -934,7 +934,7 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext, > enum osc_extent_state state) > { > struct osc_object *obj = ext->oe_obj; > - struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(600), NULL, > + struct l_wait_info lwi = LWI_TIMEOUT_INTR(600 * HZ, NULL, > LWI_ON_SIGNAL_NOOP, NULL); > int rc = 0; > > @@ -1571,7 +1571,7 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli, > struct l_wait_info lwi; > int rc = -EDQUOT; > > - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(AT_OFF ? obd_timeout : at_max), > + lwi = LWI_TIMEOUT_INTR((AT_OFF ? obd_timeout : at_max) * HZ, > NULL, LWI_ON_SIGNAL_NOOP, NULL); > > OSC_DUMP_GRANT(D_CACHE, cli, "need:%d\n", bytes); > diff --git a/drivers/staging/lustre/lustre/osc/osc_object.c b/drivers/staging/lustre/lustre/osc/osc_object.c > index 6c424f0290bb..6baa8e2e00c9 100644 > --- a/drivers/staging/lustre/lustre/osc/osc_object.c > +++ b/drivers/staging/lustre/lustre/osc/osc_object.c > @@ -328,7 +328,7 @@ int osc_object_is_contended(struct osc_object *obj) > * ll_file_is_contended. > */ > retry_time = cfs_time_add(obj->oo_contention_time, > - cfs_time_seconds(osc_contention_time)); > + osc_contention_time * HZ); > if (cfs_time_after(cur_time, retry_time)) { > osc_object_clear_contended(obj); > return 0; > diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c > index bac4b2304bad..0ab13f8e5993 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/client.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c > @@ -766,7 +766,7 @@ int ptlrpc_request_bufs_pack(struct ptlrpc_request *request, > * fail_loc > */ > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(2)); > + schedule_timeout(2 * HZ); > set_current_state(TASK_RUNNING); > } > } > @@ -2284,7 +2284,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) > * We still want to block for a limited time, > * so we allow interrupts during the timeout. > */ > - lwi = LWI_TIMEOUT_INTR_ALL(cfs_time_seconds(1), > + lwi = LWI_TIMEOUT_INTR_ALL(HZ, > ptlrpc_expired_set, > ptlrpc_interrupted_set, set); > else > @@ -2293,7 +2293,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) > * interrupts are allowed. Wait until all > * complete, or an in-flight req times out. > */ > - lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1), > + lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, > ptlrpc_expired_set, set); > > rc = l_wait_event(set->set_waitq, ptlrpc_check_set(NULL, set), &lwi); > @@ -2538,8 +2538,8 @@ static int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async) > * Network access will complete in finite time but the HUGE > * timeout lets us CWARN for visibility of sluggish NALs > */ > - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(LONG_UNLINK), > - cfs_time_seconds(1), NULL, NULL); > + lwi = LWI_TIMEOUT_INTERVAL(LONG_UNLINK * HZ, > + HZ, NULL, NULL); > rc = l_wait_event(*wq, !ptlrpc_client_recv_or_unlink(request), > &lwi); > if (rc == 0) { > diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c > index 811b7ab3a582..71f7588570ef 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/events.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/events.c > @@ -517,7 +517,7 @@ static void ptlrpc_ni_fini(void) > > /* Wait for a bit */ > init_waitqueue_head(&waitq); > - lwi = LWI_TIMEOUT(cfs_time_seconds(2), NULL, NULL); > + lwi = LWI_TIMEOUT(2 * HZ, NULL, NULL); > l_wait_event(waitq, 0, &lwi); > break; > } > diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c > index 5b0f65536c29..0eba5f18bd3b 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/import.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c > @@ -307,9 +307,9 @@ void ptlrpc_invalidate_import(struct obd_import *imp) > * have been locally cancelled by ptlrpc_abort_inflight. > */ > lwi = LWI_TIMEOUT_INTERVAL( > - cfs_timeout_cap(cfs_time_seconds(timeout)), > - (timeout > 1) ? cfs_time_seconds(1) : > - cfs_time_seconds(1) / 2, > + cfs_timeout_cap(timeout * HZ), > + (timeout > 1) ? HZ : > + HZ / 2, > NULL, NULL); > rc = l_wait_event(imp->imp_recovery_waitq, > (atomic_read(&imp->imp_inflight) == 0), > @@ -431,7 +431,7 @@ void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt) > int ptlrpc_reconnect_import(struct obd_import *imp) > { > struct l_wait_info lwi; > - int secs = cfs_time_seconds(obd_timeout); > + int secs = obd_timeout * HZ; > int rc; > > ptlrpc_pinger_force(imp); > @@ -1508,14 +1508,13 @@ int ptlrpc_disconnect_import(struct obd_import *imp, int noclose) > > if (AT_OFF) { > if (imp->imp_server_timeout) > - timeout = cfs_time_seconds(obd_timeout / 2); > + timeout = obd_timeout * HZ / 2; > else > - timeout = cfs_time_seconds(obd_timeout); > + timeout = obd_timeout * HZ; > } else { > int idx = import_at_get_index(imp, > imp->imp_client->cli_request_portal); > - timeout = cfs_time_seconds( > - at_get(&imp->imp_at.iat_service_estimate[idx])); > + timeout = at_get(&imp->imp_at.iat_service_estimate[idx]) * HZ; > } > > lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(timeout), > diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c > index 047d712e850c..0c2ded721c49 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c > @@ -270,8 +270,8 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async) > /* Network access will complete in finite time but the HUGE > * timeout lets us CWARN for visibility of sluggish LNDs > */ > - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(LONG_UNLINK), > - cfs_time_seconds(1), NULL, NULL); > + lwi = LWI_TIMEOUT_INTERVAL(LONG_UNLINK * HZ, > + HZ, NULL, NULL); > rc = l_wait_event(*wq, !ptlrpc_client_bulk_active(req), &lwi); > if (rc == 0) { > ptlrpc_rqphase_move(req, req->rq_next_phase); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c > index a64e125df95f..c060d6f5015a 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c > @@ -267,7 +267,7 @@ lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt) > /* If we cannot get anything for some long time, we better > * bail out instead of waiting infinitely > */ > - lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL); > + lwi = LWI_TIMEOUT(10 * HZ, NULL, NULL); > rc = l_wait_event(svcpt->scp_rep_waitq, > !list_empty(&svcpt->scp_rep_idle), &lwi); > if (rc != 0) > diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c > index af707cb2b62b..010a1cdf05fa 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c > @@ -141,7 +141,7 @@ static long pinger_check_timeout(unsigned long time) > } > mutex_unlock(&pinger_mutex); > > - return cfs_time_sub(cfs_time_add(time, cfs_time_seconds(timeout)), > + return cfs_time_sub(cfs_time_add(time, timeout * HZ), > cfs_time_current()); > } > > @@ -247,7 +247,7 @@ static int ptlrpc_pinger_main(void *arg) > if (imp->imp_pingable && imp->imp_next_ping && > cfs_time_after(imp->imp_next_ping, > cfs_time_add(this_ping, > - cfs_time_seconds(PING_INTERVAL)))) > + PING_INTERVAL * HZ))) > ptlrpc_update_next_ping(imp, 0); > } > mutex_unlock(&pinger_mutex); > @@ -264,10 +264,10 @@ static int ptlrpc_pinger_main(void *arg) > CDEBUG(D_INFO, "next wakeup in " CFS_DURATION_T " (%ld)\n", > time_to_next_wake, > cfs_time_add(this_ping, > - cfs_time_seconds(PING_INTERVAL))); > + PING_INTERVAL * HZ)); > if (time_to_next_wake > 0) { > lwi = LWI_TIMEOUT(max_t(long, time_to_next_wake, > - cfs_time_seconds(1)), > + HZ), > NULL, NULL); > l_wait_event(thread->t_ctl_waitq, > thread_is_stopping(thread) || > diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > index 8b865294d933..dad2f9290f70 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > @@ -230,7 +230,7 @@ void ptlrpcd_add_req(struct ptlrpc_request *req) > > spin_lock(&req->rq_lock); > if (req->rq_invalid_rqset) { > - struct l_wait_info lwi = LWI_TIMEOUT(cfs_time_seconds(5), > + struct l_wait_info lwi = LWI_TIMEOUT(5 * HZ, > back_to_sleep, NULL); > > req->rq_invalid_rqset = 0; > @@ -438,7 +438,7 @@ static int ptlrpcd(void *arg) > int timeout; > > timeout = ptlrpc_set_next_timeout(set); > - lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1), > + lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, > ptlrpc_expired_set, set); > > lu_context_enter(&env.le_ctx); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/recover.c b/drivers/staging/lustre/lustre/ptlrpc/recover.c > index e4d3f23e9f3a..5bbd23eebfa6 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/recover.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/recover.c > @@ -347,7 +347,7 @@ int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid, int async) > > if (!async) { > struct l_wait_info lwi; > - int secs = cfs_time_seconds(obd_timeout); > + int secs = obd_timeout * HZ; > > CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n", > obd2cli_tgt(imp->imp_obd), secs); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c > index 1f22926c1355..6d4229ebc9d9 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/service.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c > @@ -2149,7 +2149,7 @@ static int ptlrpc_main(void *arg) > * Wait for a timeout (unless something else > * happens) before I try again > */ > - svcpt->scp_rqbd_timeout = cfs_time_seconds(1) / 10; > + svcpt->scp_rqbd_timeout = HZ / 10; > CDEBUG(D_RPCTRACE, "Posted buffers: %d\n", > svcpt->scp_nrqbds_posted); > } > @@ -2588,7 +2588,7 @@ static void ptlrpc_wait_replies(struct ptlrpc_service_part *svcpt) > { > while (1) { > int rc; > - struct l_wait_info lwi = LWI_TIMEOUT(cfs_time_seconds(10), > + struct l_wait_info lwi = LWI_TIMEOUT(10 * HZ, > NULL, NULL); > > rc = l_wait_event(svcpt->scp_waitq, > @@ -2660,8 +2660,8 @@ ptlrpc_service_unlink_rqbd(struct ptlrpc_service *svc) > * of sluggish LNDs > */ > lwi = LWI_TIMEOUT_INTERVAL( > - cfs_time_seconds(LONG_UNLINK), > - cfs_time_seconds(1), NULL, NULL); > + LONG_UNLINK * HZ, > + HZ, NULL, NULL); > rc = l_wait_event(svcpt->scp_waitq, > svcpt->scp_nrqbds_posted == 0, &lwi); > if (rc == -ETIMEDOUT) { > > > From gregkh at linuxfoundation.org Mon Jan 8 17:00:43 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 8 Jan 2018 18:00:43 +0100 Subject: [lustre-devel] [PATCH 04/19] staging: lustre: discard cfs_time_seconds() In-Reply-To: References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209341.23920.8613572158448297057.stgit@noble> Message-ID: <20180108170043.GA28139@kroah.com> On Mon, Jan 08, 2018 at 04:52:35PM +0000, James Simmons wrote: > > > cfs_time_seconds() converts a number of seconds to the > > matching number of jiffies. > > The standard way to do this in Linux is "* HZ". > > So discard cfs_time_seconds() and use "* HZ" instead. > > Just to make you aware I have been working for several months on > moving lustre away from using jiffies as much as possible. The > problem with using HZ is that it can vary. So when you have a > parallel file system with batches of nodes that have different > values of HZ you can get very interesting corner cases. So I have > been moving everything over to time64_t and ktime. Also I mostly > have killed off the cfs_time_shift* and crap as well. You see all > work under https://jira.hpdd.intel.com/browse/LU-9019. So many > of the cases you did below don't event exist any more. I was > planning to push those changes after the next merge window. First patch to me "wins", none of this "don't touch this code because I'm going to work on it in the future" stuff. That has been documented to kill contributions and in one case, a whole opensource kernel project. So Neil's patches should be evaluated first, don't develop behind closed walls like you are doing. I've merged almost all of them now, except for the ones that broke the build :) thanks, greg k-h From jsimmons at infradead.org Mon Jan 8 18:04:33 2018 From: jsimmons at infradead.org (James Simmons) Date: Mon, 8 Jan 2018 18:04:33 +0000 (GMT) Subject: [lustre-devel] [PATCH 04/19] staging: lustre: discard cfs_time_seconds() In-Reply-To: <20180108170043.GA28139@kroah.com> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209341.23920.8613572158448297057.stgit@noble> <20180108170043.GA28139@kroah.com> Message-ID: > On Mon, Jan 08, 2018 at 04:52:35PM +0000, James Simmons wrote: > > > > > cfs_time_seconds() converts a number of seconds to the > > > matching number of jiffies. > > > The standard way to do this in Linux is "* HZ". > > > So discard cfs_time_seconds() and use "* HZ" instead. > > > > Just to make you aware I have been working for several months on > > moving lustre away from using jiffies as much as possible. The > > problem with using HZ is that it can vary. So when you have a > > parallel file system with batches of nodes that have different > > values of HZ you can get very interesting corner cases. So I have > > been moving everything over to time64_t and ktime. Also I mostly > > have killed off the cfs_time_shift* and crap as well. You see all > > work under https://jira.hpdd.intel.com/browse/LU-9019. So many > > of the cases you did below don't event exist any more. I was > > planning to push those changes after the next merge window. > > First patch to me "wins", none of this "don't touch this code because > I'm going to work on it in the future" stuff. That has been documented > to kill contributions and in one case, a whole opensource kernel > project. > > So Neil's patches should be evaluated first, don't develop behind closed > walls like you are doing What I'm saying is my work had been tested and various bugs have been worked out before it gets to you. His work is new and untested. His work can be evaluated first but that doesn't mean it ready to land first. The wait event changes is a pretty big change that can have unseen consequences. > I've merged almost all of them now, except for the ones that broke the > build :) He just posted a updated the version of the l_wait_event changes a few hours ago based on feed back. Please give it more than a few hours to bake. I like to test them to make sure things don't break. I hate to find out it breaks things and have it reverted. Please. From jsimmons at infradead.org Mon Jan 8 18:06:01 2018 From: jsimmons at infradead.org (James Simmons) Date: Mon, 8 Jan 2018 18:06:01 +0000 (GMT) Subject: [lustre-devel] [PATCH 5 v2: 00/19] staging: lustre: use standard wait_event macros In-Reply-To: <20180108163607.GA3046@kroah.com> References: <151538168618.23920.8261096424342988792.stgit@noble> <20180108145943.GA5761@kroah.com> <20180108163607.GA3046@kroah.com> Message-ID: > On Mon, Jan 08, 2018 at 04:21:50PM +0000, James Simmons wrote: > > > > > On Mon, Jan 08, 2018 at 02:28:13PM +1100, NeilBrown wrote: > > > > Hi, > > > > this is a revised version of the patch series I sent under a similar > > > > subject in mid December. > > > > Improvements are: > > > > - new wait_event_idle* macros are now in include/linux/wait.h which > > > > Ack from peterz. > > > > - *all* waits are now TASK_IDLE or TASK_INTERRUPTIBLE and so don't > > > > affect the load average. There is no need to choose whether load > > > > is appropriate or not in each case. > > > > - all l_wait_event() users are handled so l_wait_event() is > > > > removed. The one case I had left out before uses > > > > wait_event_idle_exclusive() with and option of using > > > > wait_event_idle_exclusive_lifo() is that ever gets approved. > > > > > > > > I think this set is ready to go. > > > > If you only review two patches, please review > > > > > > > > staging: lustre: simplify waiting in ldlm_completion_ast() > > > > and > > > > staging: lustre: remove back_to_sleep() > > > > > > > > as in both of those, the actual behaviour of the current code (as I > > > > understand it) doesn't seem to agree with comments/debug message, or > > > > just generally looks odd. > > > > > > This series broke the build, so I'll roll back my tree and drop it. > > > > > > Please fix it up and resend and test build it first... > > > > Please don't merge these just yet. They need to be tested first. I don't > > want to be in a position where the lustre client is totally not usable > > like in the past. That kind of breakage makes no one want to use the > > lustre client. We have a test suite for these kinds of changes. Neill do > > you know how to test your patches with the test suite? Also I have been > > working on several things for the last 4 months to merge upstream. I like > > to coordinate with you so we don't step on each others toes. > > If I don't hear anything for a few weeks, I merge patches. That should > be long enough to test... Agree. This patch set is only a few hours old. From neilb at suse.com Mon Jan 8 21:39:17 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 08:39:17 +1100 Subject: [lustre-devel] [PATCH 03/15] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: <20180108145157.GA32570@kroah.com> References: <151355781721.6200.2136335532722530242.stgit@noble> <151355799030.6200.8100283223734974485.stgit@noble> <20180108145157.GA32570@kroah.com> Message-ID: <87y3l8av3u.fsf@notabene.neil.brown.name> On Mon, Jan 08 2018, Greg Kroah-Hartman wrote: > On Mon, Dec 18, 2017 at 11:46:30AM +1100, NeilBrown wrote: >> All usages of the form >> LIBCFS_ALLOC(variable, sizeof(variable)) >> or >> LIBCFS_ALLOC(variable, sizeof(variable's-type)) >> >> are changed to >> variable = kzalloc(sizeof(...), GFP_NOFS); >> >> Similarly, all >> LIBCFS_FREE(variable, sizeof(variable)) >> become >> kfree(variable); >> >> None of these need the vmalloc option, or any of the other minor >> benefits of LIBCFS_ALLOC(). >> >> Signed-off-by: NeilBrown > > As this broke the kbuild system, I'll stop here in this patch series. > Can you please fix it up, rebase and resend the remaining ones in this > series? Hi Greg, thanks for applying the patches. That patch had a typo in code that was only included if CONFIG_INFINIBAND is enabled, which I didn't have in my testing at the time. I hadn't resent when I fixed it as I was waiting to see if there would be feedback. If the protocol is "you apply sometime after two weeks if there is no feedback (and no breakage)", then I'll aim to work with that. I'll resend with the rest of the kmalloc patches. Thanks, NeilBrown -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 832 bytes Desc: not available URL: From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 00/14] staging:lustre: convert most LIBCFS*ALLOC to k*malloc - V2 Message-ID: <151546052331.9776.7408338350463291753.stgit@noble> This is a revised version of my LIBCFS*ALLOC cleanup series. - the compile error is fixed - some cases of "if (x) kfree(x)" have been simplified - LIBCFS_CPT_ALLOC() has been replaced as well. This based on staging-testing (430505962765fc1). Intro from original posting is below. Thanks, NeilBrown ============== Lustre has some "convenience" macros for allocating and freeing memory. They: - warn if called from interrupt context - use kvmalloc - assume GFP_NOFS (which kvmalloc doesn't support) - print an error if the allocation fails - initialize the memory to zeroes. though the _ATOMIC version skips the first three. - kmalloc family functions already produce the warning. - kvmalloc is best kept for allocations which might be large, and where GFP_KERNEL is permitted - Assuming GFP_NOFS does hurt much for small allocation - though it increases the chance of failure a little - but is unnecessary in many cases and shouldn't be assumed. - Giving an error on failure can be achieved with CONFIG_SLAB_DEBUG. - Initializing to zeroes, where needed, can be done with __GFP_ZERO or kzalloc() So having these "convenience" functions tends to obscure the intention of the code by reducing the variety of calls (homogenising the code). This series converts many of the calls to kmalloc or kvmalloc or similar, and converts the corresponding LIBCFS_FREE() calls to kfree() or kvfree(). The LIBCFS_CPT_ALLOC() calls have not been changed as they are a little less straight forward, and deserve closer analysis before a clean conversion is possible. This series does not remove the zeroing in all cases where is isn't needed, but does remove it in some. Similarly GFP_NOFS is left is some cases where it might not be necessary. These omissions can be rectified later following proper analysis. --- NeilBrown (14): staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. staging: lustre: lnet: switch to cpumask_var_t staging: lustre: lnet: selftest: don't allocate small strings. staging: lustre: lnet: use kmalloc/kvmalloc in router_proc staging: lustre: change some LIBCFS_ALLOC calls to k?alloc(GFP_KERNEL) staging: lustre: Convert more LIBCFS_ALLOC allocation to direct GFP_KERNEL staging: lustre: more LIBCFS_ALLOC conversions to GFP_KERNEL allocations. staging: lustre: more conversions to GFP_KERNEL allocations. staging: lustre: lnet-route: use kmalloc for small allocation staging: lustre: use kmalloc for allocating ksock_tx staging: lustre: cfs_percpt_alloc: use kvmalloc(GFP_KERNEL) staging: lustre: opencode LIBCFS_ALLOC_ATOMIC calls. staging: lustre: replace LIBCFS_CPT_ALLOC() staging: lustre: remove LIBCFS_ALLOC, LIBCFS_FREE and related macros. .../lustre/include/linux/libcfs/libcfs_cpu.h | 4 .../lustre/include/linux/libcfs/libcfs_private.h | 60 +----- .../lustre/include/linux/libcfs/libcfs_string.h | 4 .../lustre/include/linux/libcfs/linux/linux-cpu.h | 4 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 155 +++++++--------- .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 4 .../lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c | 4 .../staging/lustre/lnet/klnds/socklnd/socklnd.c | 61 +++--- .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 6 - .../lustre/lnet/klnds/socklnd/socklnd_proto.c | 8 - drivers/staging/lustre/lnet/libcfs/hash.c | 18 +- drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c | 6 - drivers/staging/lustre/lnet/libcfs/libcfs_lock.c | 6 - drivers/staging/lustre/lnet/libcfs/libcfs_mem.c | 24 +-- drivers/staging/lustre/lnet/libcfs/libcfs_string.c | 12 + .../staging/lustre/lnet/libcfs/linux/linux-cpu.c | 130 ++++++-------- .../lustre/lnet/libcfs/linux/linux-module.c | 4 drivers/staging/lustre/lnet/libcfs/module.c | 9 - drivers/staging/lustre/lnet/libcfs/workitem.c | 8 - drivers/staging/lustre/lnet/lnet/api-ni.c | 32 +-- drivers/staging/lustre/lnet/lnet/config.c | 43 ++--- drivers/staging/lustre/lnet/lnet/lib-eq.c | 9 - drivers/staging/lustre/lnet/lnet/lib-move.c | 6 - drivers/staging/lustre/lnet/lnet/lib-msg.c | 14 + drivers/staging/lustre/lnet/lnet/lib-ptl.c | 6 - drivers/staging/lustre/lnet/lnet/lib-socket.c | 14 + drivers/staging/lustre/lnet/lnet/nidstrings.c | 8 - drivers/staging/lustre/lnet/lnet/peer.c | 10 + drivers/staging/lustre/lnet/lnet/router.c | 41 ++-- drivers/staging/lustre/lnet/lnet/router_proc.c | 40 ++-- drivers/staging/lustre/lnet/selftest/conctl.c | 191 ++++---------------- drivers/staging/lustre/lnet/selftest/conrpc.c | 10 + drivers/staging/lustre/lnet/selftest/console.c | 83 ++++----- drivers/staging/lustre/lnet/selftest/framework.c | 26 +-- drivers/staging/lustre/lnet/selftest/module.c | 7 - drivers/staging/lustre/lnet/selftest/rpc.c | 25 +-- drivers/staging/lustre/lnet/selftest/selftest.h | 2 .../lustre/lustre/obdclass/lprocfs_status.c | 21 +- 38 files changed, 431 insertions(+), 684 deletions(-) -- Signature From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 01/14] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077813.9776.9595918013533133469.stgit@noble> All usages of the form LIBCFS_ALLOC(variable, sizeof(variable)) or LIBCFS_ALLOC(variable, sizeof(variable's-type)) are changed to variable = kzalloc(sizeof(...), GFP_NOFS); Similarly, all LIBCFS_FREE(variable, sizeof(variable)) become kfree(variable); None of these need the vmalloc option, or any of the other minor benefits of LIBCFS_ALLOC(). Signed-off-by: NeilBrown --- .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 39 ++++++++++---------- .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 4 +- .../lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c | 4 +- .../staging/lustre/lnet/klnds/socklnd/socklnd.c | 22 ++++++----- .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 2 + .../lustre/lnet/klnds/socklnd/socklnd_proto.c | 8 ++-- drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c | 4 +- drivers/staging/lustre/lnet/libcfs/libcfs_lock.c | 6 ++- drivers/staging/lustre/lnet/libcfs/libcfs_string.c | 10 +++-- .../staging/lustre/lnet/libcfs/linux/linux-cpu.c | 19 ++++------ drivers/staging/lustre/lnet/libcfs/workitem.c | 8 ++-- drivers/staging/lustre/lnet/lnet/api-ni.c | 4 +- drivers/staging/lustre/lnet/lnet/config.c | 7 ++-- drivers/staging/lustre/lnet/lnet/lib-move.c | 6 ++- drivers/staging/lustre/lnet/lnet/nidstrings.c | 8 ++-- drivers/staging/lustre/lnet/lnet/peer.c | 2 + drivers/staging/lustre/lnet/lnet/router.c | 28 ++++++-------- drivers/staging/lustre/lnet/lnet/router_proc.c | 6 ++- drivers/staging/lustre/lnet/selftest/conrpc.c | 10 +++-- drivers/staging/lustre/lnet/selftest/console.c | 26 +++++++------ drivers/staging/lustre/lnet/selftest/framework.c | 22 ++++++----- drivers/staging/lustre/lnet/selftest/rpc.c | 12 +++--- 22 files changed, 124 insertions(+), 133 deletions(-) diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 8024843521ab..3aa81168c84f 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -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 @@ -776,7 +776,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)); @@ -828,7 +828,7 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm failed_2: kiblnd_destroy_conn(conn, true); failed_1: - LIBCFS_FREE(init_qp_attr, sizeof(*init_qp_attr)); + kfree(init_qp_attr); failed_0: return NULL; } @@ -882,8 +882,7 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) IBLND_RX_MSGS(conn) * sizeof(struct kib_rx)); } - if (conn->ibc_connvars) - LIBCFS_FREE(conn->ibc_connvars, sizeof(*conn->ibc_connvars)); + kfree(conn->ibc_connvars); if (conn->ibc_hdev) kiblnd_hdev_decref(conn->ibc_hdev); @@ -897,7 +896,7 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) atomic_dec(&net->ibn_nconns); } - LIBCFS_FREE(conn, sizeof(*conn)); + kfree(conn); } int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) @@ -1299,7 +1298,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 +1309,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) @@ -1405,14 +1404,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; @@ -1464,7 +1463,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; } @@ -2011,7 +2010,7 @@ static void kiblnd_destroy_tx_pool(struct kib_pool *pool) pool->po_size * sizeof(struct kib_tx)); out: kiblnd_fini_pool(pool); - LIBCFS_FREE(tpo, sizeof(*tpo)); + kfree(tpo); } static int kiblnd_tx_pool_size(int ncpts) @@ -2043,7 +2042,7 @@ 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; } @@ -2263,7 +2262,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 +2391,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 +2470,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 +2494,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 +2516,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; } @@ -2648,7 +2647,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)) @@ -2865,7 +2864,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_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c index 40e3af5d8b04..9b3328c5d1e7 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) { @@ -3363,7 +3363,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..51157ae14a9e 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 @@ -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; @@ -1419,7 +1419,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route, LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg, kshm_ips[LNET_MAX_INTERFACES])); - LIBCFS_FREE(conn, sizeof(*conn)); + kfree(conn); failed_0: sock_release(sock); @@ -1716,7 +1716,7 @@ ksocknal_destroy_conn(struct ksock_conn *conn) ksocknal_peer_decref(conn->ksnc_peer); - LIBCFS_FREE(conn, sizeof(*conn)); + kfree(conn); } int @@ -2622,7 +2622,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 +2815,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 +2877,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..994b6693c6b7 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c @@ -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/libcfs_cpu.c b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c index e3a4c67a66b5..d05c3932b3b9 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); 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_string.c b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c index cb0533b36cc7..b8d1ce831ff1 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_string.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c @@ -260,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; @@ -313,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; } @@ -468,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); @@ -490,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 2f5d8f300ef5..9679bd73025d 100644 --- a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c +++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c @@ -102,11 +102,7 @@ cfs_cpt_table_free(struct cfs_cpt_table *cptab) 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)); - } - + kfree(part->cpt_nodemask); if (part->cpt_cpumask) LIBCFS_FREE(part->cpt_cpumask, cpumask_size()); } @@ -116,12 +112,11 @@ cfs_cpt_table_free(struct cfs_cpt_table *cptab) cptab->ctb_nparts * sizeof(cptab->ctb_parts[0])); } - if (cptab->ctb_nodemask) - LIBCFS_FREE(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); + kfree(cptab->ctb_nodemask); if (cptab->ctb_cpumask) LIBCFS_FREE(cptab->ctb_cpumask, cpumask_size()); - LIBCFS_FREE(cptab, sizeof(*cptab)); + kfree(cptab); } EXPORT_SYMBOL(cfs_cpt_table_free); @@ -131,14 +126,15 @@ 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)); + cptab->ctb_nodemask = kzalloc(sizeof(*cptab->ctb_nodemask), + GFP_NOFS); if (!cptab->ctb_cpumask || !cptab->ctb_nodemask) goto failed; @@ -159,7 +155,8 @@ cfs_cpt_table_alloc(unsigned int ncpt) 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)); + part->cpt_nodemask = kzalloc(sizeof(*part->cpt_nodemask), + GFP_NOFS); if (!part->cpt_cpumask || !part->cpt_nodemask) goto failed; } diff --git a/drivers/staging/lustre/lnet/libcfs/workitem.c b/drivers/staging/lustre/lnet/libcfs/workitem.c index 6a05d9bab8dc..74a9595dc730 100644 --- a/drivers/staging/lustre/lnet/libcfs/workitem.c +++ b/drivers/staging/lustre/lnet/libcfs/workitem.c @@ -328,7 +328,7 @@ cfs_wi_sched_destroy(struct cfs_wi_sched *sched) spin_unlock(&cfs_wi_data.wi_glock); LASSERT(!sched->ws_nscheduled); - LIBCFS_FREE(sched, sizeof(*sched)); + kfree(sched); } EXPORT_SYMBOL(cfs_wi_sched_destroy); @@ -344,12 +344,12 @@ cfs_wi_sched_create(char *name, struct cfs_cpt_table *cptab, LASSERT(!cptab || cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cfs_cpt_number(cptab))); - LIBCFS_ALLOC(sched, sizeof(*sched)); + sched = kzalloc(sizeof(*sched), GFP_NOFS); if (!sched) return -ENOMEM; if (strlen(name) > sizeof(sched->ws_name) - 1) { - LIBCFS_FREE(sched, sizeof(*sched)); + kfree(sched); return -E2BIG; } strncpy(sched->ws_name, name, sizeof(sched->ws_name)); @@ -458,7 +458,7 @@ cfs_wi_shutdown(void) } list_for_each_entry_safe(sched, temp, &cfs_wi_data.wi_scheds, ws_list) { list_del(&sched->ws_list); - LIBCFS_FREE(sched, sizeof(*sched)); + kfree(sched); } cfs_wi_data.wi_stopping = 0; diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c index 30d0999118c7..e8f623190133 100644 --- a/drivers/staging/lustre/lnet/lnet/api-ni.c +++ b/drivers/staging/lustre/lnet/lnet/api-ni.c @@ -1280,8 +1280,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; diff --git a/drivers/staging/lustre/lnet/lnet/config.c b/drivers/staging/lustre/lnet/lnet/config.c index 0ba2a3940009..a1a3c35ea4dc 100644 --- a/drivers/staging/lustre/lnet/lnet/config.c +++ b/drivers/staging/lustre/lnet/lnet/config.c @@ -106,8 +106,7 @@ 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], @@ -118,7 +117,7 @@ lnet_ni_free(struct lnet_ni *ni) if (ni->ni_net_ns) put_net(ni->ni_net_ns); - LIBCFS_FREE(ni, sizeof(*ni)); + kfree(ni); } struct lnet_ni * @@ -135,7 +134,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)); diff --git a/drivers/staging/lustre/lnet/lnet/lib-move.c b/drivers/staging/lustre/lnet/lnet/lib-move.c index 137e3ab970dc..d724c4c73ecc 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; 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..19fcbcf0f642 100644 --- a/drivers/staging/lustre/lnet/lnet/peer.c +++ b/drivers/staging/lustre/lnet/lnet/peer.c @@ -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); } } diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c index f5b21c51c49c..409244e57a31 100644 --- a/drivers/staging/lustre/lnet/lnet/router.c +++ b/drivers/staging/lustre/lnet/lnet/router.c @@ -315,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; } @@ -339,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 */ @@ -395,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); @@ -517,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,7 +887,7 @@ lnet_destroy_rc_data(struct lnet_rc_data *rcd) if (rcd->rcd_pinginfo) LIBCFS_FREE(rcd->rcd_pinginfo, LNET_PINGINFO_SIZE); - LIBCFS_FREE(rcd, sizeof(*rcd)); + kfree(rcd); } static struct lnet_rc_data * @@ -905,7 +901,7 @@ 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; diff --git a/drivers/staging/lustre/lnet/lnet/router_proc.c b/drivers/staging/lustre/lnet/lnet/router_proc.c index e863a5e0ab38..43038f930ba1 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); if (!tmpstr) { - LIBCFS_FREE(ctrs, sizeof(*ctrs)); + kfree(ctrs); return -ENOMEM; } @@ -119,7 +119,7 @@ static int __proc_lnet_stats(void *data, int write, tmpstr + pos, "\n"); LIBCFS_FREE(tmpstr, tmpsiz); - LIBCFS_FREE(ctrs, sizeof(*ctrs)); + kfree(ctrs); 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..edf5e59a4351 100644 --- a/drivers/staging/lustre/lnet/selftest/console.c +++ b/drivers/staging/lustre/lnet/selftest/console.c @@ -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 @@ -807,7 +807,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 +821,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,7 +856,7 @@ 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; @@ -866,7 +866,7 @@ lstcon_batch_add(char *name) sizeof(struct list_head) * LST_NODE_HASHSIZE); 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; } @@ -876,7 +876,7 @@ lstcon_batch_add(char *name) 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); return -ENOMEM; } @@ -884,7 +884,7 @@ lstcon_batch_add(char *name) 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); return -E2BIG; } strncpy(bat->bat_name, name, sizeof(bat->bat_name)); @@ -971,7 +971,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 +993,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; } @@ -1138,7 +1138,7 @@ lstcon_batch_destroy(struct lstcon_batch *bat) 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); } static int @@ -1790,7 +1790,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 +1807,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; } diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c index 6c2091ef8dba..b734e629bf29 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,7 +632,7 @@ 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)) { @@ -644,7 +644,7 @@ sfw_destroy_test_instance(struct sfw_test_instance *tsi) 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", @@ -1785,6 +1785,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/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c index fe0d735487b9..eb76447b2b8d 100644 --- a/drivers/staging/lustre/lnet/selftest/rpc.c +++ b/drivers/staging/lustre/lnet/selftest/rpc.c @@ -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); } } @@ -508,7 +508,7 @@ __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; @@ -535,7 +535,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 +547,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; @@ -725,7 +725,7 @@ __must_hold(&scd->scd_lock) } spin_unlock(&scd->scd_lock); - LIBCFS_FREE(buf, sizeof(*buf)); + kfree(buf); spin_lock(&scd->scd_lock); } From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 03/14] staging: lustre: lnet: selftest: don't allocate small strings. In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077824.9776.8054352998150567657.stgit@noble> All of the "name" buffers here are at most LST_NAME_SIZE+1 bytes, so 33 bytes at most. They are only used temporarily during the life of the function that allocates them. So it is much simpler to just allocate on the stack. Worst case is lst_tet_add_ioct(), which allocates 3 for these which 99 bytes on the stack, instead of the 24 that would have been allocated for 64-bit pointers. Signed-off-by: NeilBrown --- drivers/staging/lustre/lnet/selftest/conctl.c | 180 ++++--------------------- 1 file changed, 29 insertions(+), 151 deletions(-) diff --git a/drivers/staging/lustre/lnet/selftest/conctl.c b/drivers/staging/lustre/lnet/selftest/conctl.c index 082c0afacf23..442a18ddd41f 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,18 +647,6 @@ 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); if (!param) @@ -791,15 +678,6 @@ 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); From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 02/14] staging: lustre: lnet: switch to cpumask_var_t In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077819.9776.10909300709167847835.stgit@noble> So that we can use the common cpumask allocation functions, switch to cpumask_var_t. We need to be careful not to free a cpumask_var_t until the variable has been initialized, and it cannot be initialized directly. So we must be sure either that it is filled with zeros, or that zalloc_cpumask_var() has been called on it. Signed-off-by: NeilBrown --- .../lustre/include/linux/libcfs/libcfs_cpu.h | 4 - .../lustre/include/linux/libcfs/linux/linux-cpu.h | 4 - .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 6 + drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c | 2 .../staging/lustre/lnet/libcfs/linux/linux-cpu.c | 92 +++++++++----------- 5 files changed, 49 insertions(+), 59 deletions(-) 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/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/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 3aa81168c84f..9fbf8a044962 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -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; } diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c index d05c3932b3b9..76291a350406 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c @@ -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/linux/linux-cpu.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c index 9679bd73025d..51196fda2a32 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; @@ -103,8 +103,7 @@ cfs_cpt_table_free(struct cfs_cpt_table *cptab) struct cfs_cpu_partition *part = &cptab->ctb_parts[i]; kfree(part->cpt_nodemask); - if (part->cpt_cpumask) - LIBCFS_FREE(part->cpt_cpumask, cpumask_size()); + free_cpumask_var(part->cpt_cpumask); } if (cptab->ctb_parts) { @@ -113,8 +112,7 @@ cfs_cpt_table_free(struct cfs_cpt_table *cptab) } kfree(cptab->ctb_nodemask); - if (cptab->ctb_cpumask) - LIBCFS_FREE(cptab->ctb_cpumask, cpumask_size()); + free_cpumask_var(cptab->ctb_cpumask); kfree(cptab); } @@ -132,11 +130,10 @@ cfs_cpt_table_alloc(unsigned int ncpt) cptab->ctb_nparts = ncpt; - LIBCFS_ALLOC(cptab->ctb_cpumask, cpumask_size()); cptab->ctb_nodemask = kzalloc(sizeof(*cptab->ctb_nodemask), GFP_NOFS); - - if (!cptab->ctb_cpumask || !cptab->ctb_nodemask) + if (!zalloc_cpumask_var(&cptab->ctb_cpumask, GFP_NOFS) || + !cptab->ctb_nodemask) goto failed; LIBCFS_ALLOC(cptab->ctb_cpu2cpt, @@ -154,10 +151,10 @@ cfs_cpt_table_alloc(unsigned int ncpt) for (i = 0; i < ncpt; i++) { struct cfs_cpu_partition *part = &cptab->ctb_parts[i]; - LIBCFS_ALLOC(part->cpt_cpumask, cpumask_size()); part->cpt_nodemask = kzalloc(sizeof(*part->cpt_nodemask), GFP_NOFS); - if (!part->cpt_cpumask || !part->cpt_nodemask) + if (!zalloc_cpumask_var(&part->cpt_cpumask, GFP_NOFS) || + !part->cpt_nodemask) goto failed; } @@ -248,13 +245,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); @@ -402,7 +399,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) { @@ -413,10 +409,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); @@ -427,8 +422,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); @@ -437,10 +430,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); } @@ -556,7 +548,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; @@ -564,24 +556,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 */ @@ -602,8 +594,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; @@ -621,13 +613,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); @@ -665,10 +661,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; } @@ -721,7 +715,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; @@ -754,8 +748,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; } @@ -782,7 +775,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)) @@ -795,20 +788,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); @@ -1011,8 +1003,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 @@ -1024,8 +1015,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; } From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 04/14] staging: lustre: lnet: use kmalloc/kvmalloc in router_proc In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077828.9776.11145434430358194964.stgit@noble> The buffers allocated in router_proc are to temporarily hold strings created for procfs files. So they do not need to be zeroed and are safe to use GFP_KERNEL. So use kmalloc() directly except in two cases where it isn't trivial to confirm that the size is always small. In those cases, use kvmalloc(). Signed-off-by: NeilBrown --- drivers/staging/lustre/lnet/lnet/router_proc.c | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/staging/lustre/lnet/lnet/router_proc.c b/drivers/staging/lustre/lnet/lnet/router_proc.c index 43038f930ba1..1a71ffebc889 100644 --- a/drivers/staging/lustre/lnet/lnet/router_proc.c +++ b/drivers/staging/lustre/lnet/lnet/router_proc.c @@ -95,7 +95,7 @@ static int __proc_lnet_stats(void *data, int write, if (!ctrs) return -ENOMEM; - LIBCFS_ALLOC(tmpstr, tmpsiz); + tmpstr = kmalloc(tmpsiz, GFP_KERNEL); if (!tmpstr) { kfree(ctrs); return -ENOMEM; @@ -118,7 +118,7 @@ static int __proc_lnet_stats(void *data, int write, rc = cfs_trace_copyout_string(buffer, nob, tmpstr + pos, "\n"); - LIBCFS_FREE(tmpstr, tmpsiz); + 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; @@ -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; } From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 05/14] staging: lustre: change some LIBCFS_ALLOC calls to k?alloc(GFP_KERNEL) In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077832.9776.10331372787316896708.stgit@noble> When an allocation happens from process context rather than filesystem context, it is best to use GFP_KERNEL rather than LIBCFS_ALLOC() which always uses GFP_NOFS. This include initialization during, or prior to, mount, and code run from separate worker threads. So for some of these cases, switch to kmalloc, kvmalloc, or kvmalloc_array() as appropriate. In some cases we preserve __GFP_ZERO (via kzalloc/kvzalloc), but in others it is clear that allocated memory is immediately initialized. In each case, the matching LIBCFS_FREE() is converted to kfree() or kvfree() This is just a subset of locations that need changing. As there are quite a lot, I've broken them up into several ad-hoc sets to avoid review-fatigue. Signed-off-by: NeilBrown --- .../lustre/include/linux/libcfs/libcfs_string.h | 4 ++-- .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 11 ++++------ .../staging/lustre/lnet/klnds/socklnd/socklnd.c | 22 ++++++++------------ drivers/staging/lustre/lnet/libcfs/hash.c | 18 +++++++--------- drivers/staging/lustre/lnet/libcfs/libcfs_mem.c | 9 ++++---- drivers/staging/lustre/lnet/libcfs/libcfs_string.c | 2 +- drivers/staging/lustre/lnet/lnet/config.c | 2 +- 7 files changed, 29 insertions(+), 39 deletions(-) diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h index bb95eaf9f3d5..66463477074a 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h @@ -85,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/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 9fbf8a044962..bb7b19473e3a 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -2576,11 +2576,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); @@ -2672,8 +2668,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++) diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c index 51157ae14a9e..dc63ed2ceb97 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c @@ -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,9 +1415,7 @@ 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); kfree(conn); @@ -2269,9 +2267,7 @@ ksocknal_free_buffers(void) 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); @@ -2401,9 +2397,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; diff --git a/drivers/staging/lustre/lnet/libcfs/hash.c b/drivers/staging/lustre/lnet/libcfs/hash.c index 4d16147602a6..f7b3c9306456 100644 --- a/drivers/staging/lustre/lnet/libcfs/hash.c +++ b/drivers/staging/lustre/lnet/libcfs/hash.c @@ -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); @@ -1014,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; @@ -1046,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); @@ -1109,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) diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c index df93d8f77ea2..23734cfb5d44 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c @@ -130,10 +130,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 +147,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 +155,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 b8d1ce831ff1..442889a3d729 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_string.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c @@ -437,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; diff --git a/drivers/staging/lustre/lnet/lnet/config.c b/drivers/staging/lustre/lnet/lnet/config.c index a1a3c35ea4dc..4b24842e9b16 100644 --- a/drivers/staging/lustre/lnet/lnet/config.c +++ b/drivers/staging/lustre/lnet/lnet/config.c @@ -169,7 +169,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; } From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 07/14] staging: lustre: more LIBCFS_ALLOC conversions to GFP_KERNEL allocations. In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077841.9776.3578098217779896126.stgit@noble> None of these need GFP_NOFS so allocate directly. Change matching LIBCFS_FREE() to kfree() or kvfree(). Signed-off-by: NeilBrown --- .../staging/lustre/lnet/libcfs/linux/linux-cpu.c | 19 +++++++------------ drivers/staging/lustre/lnet/lnet/lib-eq.c | 9 ++++----- drivers/staging/lustre/lnet/lnet/lib-socket.c | 14 +++++++------- drivers/staging/lustre/lnet/selftest/conctl.c | 11 +++++------ 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c index 51196fda2a32..c07165e0ad95 100644 --- a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c +++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c @@ -93,11 +93,7 @@ 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]; @@ -106,10 +102,7 @@ cfs_cpt_table_free(struct cfs_cpt_table *cptab) 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); kfree(cptab->ctb_nodemask); free_cpumask_var(cptab->ctb_cpumask); @@ -136,15 +129,17 @@ cfs_cpt_table_alloc(unsigned int ncpt) !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; diff --git a/drivers/staging/lustre/lnet/lnet/lib-eq.c b/drivers/staging/lustre/lnet/lnet/lib-eq.c index 7a4d1f7a693e..a173b69e2f92 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-eq.c +++ b/drivers/staging/lustre/lnet/lnet/lib-eq.c @@ -95,7 +95,8 @@ LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback, 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,8 +133,7 @@ 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); @@ -202,8 +202,7 @@ LNetEQFree(struct lnet_handle_eq eqh) 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-socket.c b/drivers/staging/lustre/lnet/lnet/lib-socket.c index 7d49d4865298..fcd9d1b7c619 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 @@ lnet_ipif_enumerate(char ***namesp) 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/selftest/conctl.c b/drivers/staging/lustre/lnet/selftest/conctl.c index 442a18ddd41f..34ba440b3c02 100644 --- a/drivers/staging/lustre/lnet/selftest/conctl.c +++ b/drivers/staging/lustre/lnet/selftest/conctl.c @@ -648,7 +648,7 @@ static int lst_test_add_ioctl(struct lstio_test_args *args) return -EINVAL; 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, @@ -678,8 +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 (param) - LIBCFS_FREE(param, args->lstio_tes_param_len); + kfree(param); return rc; } @@ -702,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; } @@ -798,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; } From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 06/14] staging: lustre: Convert more LIBCFS_ALLOC allocation to direct GFP_KERNEL In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077837.9776.15653995287936476858.stgit@noble> None of these need to be GFP_NOFS, so use GFP_KERNEL explicitly with kmalloc(), kvmalloc(), or kvmalloc_array(). Change matching LIBCFS_FREE() to kfree() or kvfree() Signed-off-by: NeilBrown --- .../lustre/lnet/libcfs/linux/linux-module.c | 4 +- drivers/staging/lustre/lnet/libcfs/module.c | 9 ++--- drivers/staging/lustre/lnet/lnet/api-ni.c | 17 ++++------ drivers/staging/lustre/lnet/lnet/config.c | 34 ++++++++------------ 4 files changed, 26 insertions(+), 38 deletions(-) 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 eb1a1dea723d..555f47651730 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; } diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c index e8f623190133..6a1fb0397604 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; } @@ -831,7 +830,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 +863,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 @@ -2160,7 +2157,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 +2307,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 4b24842e9b16..1516ac61108d 100644 --- a/drivers/staging/lustre/lnet/lnet/config.c +++ b/drivers/staging/lustre/lnet/lnet/config.c @@ -108,10 +108,8 @@ lnet_ni_free(struct lnet_ni *ni) 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) @@ -197,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; @@ -218,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; @@ -348,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); @@ -383,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: @@ -399,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; } @@ -423,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; @@ -437,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 @@ -1155,7 +1146,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) if (nif <= 0) return nif; - LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs)); + ipaddrs = kzalloc(nif * sizeof(*ipaddrs), GFP_KERNEL); if (!ipaddrs) { CERROR("Can't allocate ipaddrs[%d]\n", nif); lnet_ipif_free_enumeration(ifnames, nif); @@ -1188,7 +1179,8 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) *ipaddrsp = ipaddrs; } else { if (nip > 0) { - LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2)); + ipaddrs2 = kzalloc(nip * sizeof(*ipaddrs2), + GFP_KERNEL); if (!ipaddrs2) { CERROR("Can't allocate ipaddrs[%d]\n", nip); nip = -ENOMEM; @@ -1199,7 +1191,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) rc = nip; } } - LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); + kfree(ipaddrs); } return nip; } @@ -1225,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); From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 08/14] staging: lustre: more conversions to GFP_KERNEL allocations. In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077845.9776.2557689958322120971.stgit@noble> These are not called from filesystem context, so use GFP_KERNEL, not LIBCFS_ALLOC(). Signed-off-by: NeilBrown --- drivers/staging/lustre/lnet/selftest/console.c | 57 +++++++++----------- drivers/staging/lustre/lnet/selftest/framework.c | 4 + drivers/staging/lustre/lnet/selftest/module.c | 7 +- drivers/staging/lustre/lnet/selftest/rpc.c | 4 + drivers/staging/lustre/lnet/selftest/selftest.h | 2 - .../lustre/lustre/obdclass/lprocfs_status.c | 14 ++--- 6 files changed, 40 insertions(+), 48 deletions(-) diff --git a/drivers/staging/lustre/lnet/selftest/console.c b/drivers/staging/lustre/lnet/selftest/console.c index edf5e59a4351..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 @@ -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 @@ -862,8 +861,8 @@ lstcon_batch_add(char *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); kfree(bat); @@ -871,19 +870,19 @@ lstcon_batch_add(char *name) 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); + 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); + kfree(bat->bat_srv_hash); + kfree(bat->bat_cli_hash); kfree(bat); return -E2BIG; } @@ -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,10 +1132,8 @@ 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); + kfree(bat->bat_cli_hash); + kfree(bat->bat_srv_hash); kfree(bat); } @@ -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); @@ -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 @@ lstcon_console_init(void) 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 b734e629bf29..2e1126552e18 100644 --- a/drivers/staging/lustre/lnet/selftest/framework.c +++ b/drivers/staging/lustre/lnet/selftest/framework.c @@ -639,7 +639,7 @@ sfw_destroy_test_instance(struct sfw_test_instance *tsi) 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: @@ -1767,7 +1767,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++) { diff --git a/drivers/staging/lustre/lnet/selftest/module.c b/drivers/staging/lustre/lnet/selftest/module.c index 1d44d912f014..ba4b6145c953 100644 --- a/drivers/staging/lustre/lnet/selftest/module.c +++ b/drivers/staging/lustre/lnet/selftest/module.c @@ -72,9 +72,7 @@ lnet_selftest_exit(void) continue; cfs_wi_sched_destroy(lst_sched_test[i]); } - LIBCFS_FREE(lst_sched_test, - sizeof(lst_sched_test[0]) * - cfs_cpt_number(lnet_cpt_table())); + kvfree(lst_sched_test); lst_sched_test = NULL; /* fall through */ case LST_INIT_WI_SERIAL: @@ -103,7 +101,8 @@ lnet_selftest_init(void) 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); + lst_sched_test = kvmalloc_array(nscheds, sizeof(lst_sched_test[0]), + GFP_KERNEL | __GFP_ZERO); if (!lst_sched_test) goto error; diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c index eb76447b2b8d..4ebb5a1107be 100644 --- a/drivers/staging/lustre/lnet/selftest/rpc.c +++ b/drivers/staging/lustre/lnet/selftest/rpc.c @@ -1322,8 +1322,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 929a1c3eb290..465417263ef1 100644 --- a/drivers/staging/lustre/lnet/selftest/selftest.h +++ b/drivers/staging/lustre/lnet/selftest/selftest.h @@ -516,7 +516,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); } diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c index 05d71f568837..85483a38c6c4 100644 --- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c @@ -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,8 +1147,9 @@ 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; @@ -1193,10 +1195,8 @@ void lprocfs_free_stats(struct lprocfs_stats **statsh) 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])); + kvfree(stats->ls_cnt_header); + kvfree(stats); } EXPORT_SYMBOL(lprocfs_free_stats); From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 10/14] staging: lustre: use kmalloc for allocating ksock_tx In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077852.9776.2149131708167902397.stgit@noble> The size of the data structure is primarily controlled by the iovec size, which is limited to 256. Entries in this vector are 12 bytes, so the whole will always fit in a page. So it is safe to use kmalloc (kvmalloc not needed). So replace LIBCFS_ALLOC with kmalloc. Signed-off-by: NeilBrown --- .../staging/lustre/lnet/klnds/socklnd/socklnd.c | 2 +- .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c index dc63ed2ceb97..7dba949a95a7 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c @@ -2282,7 +2282,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); diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c index 994b6693c6b7..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); } } From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 09/14] staging: lustre: lnet-route: use kmalloc for small allocation In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077849.9776.5734351152485517837.stgit@noble> This allocation is reasonably small. As the function is called "*_locked", it might not be safe to perform a GFP_KERNEL allocation, so be safe and use GFP_NOFS. Signed-off-by: NeilBrown --- drivers/staging/lustre/lnet/lnet/router.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c index 409244e57a31..476d6d296037 100644 --- a/drivers/staging/lustre/lnet/lnet/router.c +++ b/drivers/staging/lustre/lnet/lnet/router.c @@ -884,8 +884,7 @@ 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); kfree(rcd); } @@ -908,7 +907,7 @@ lnet_create_rc_data_locked(struct lnet_peer *gateway) 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; From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 11/14] staging: lustre: cfs_percpt_alloc: use kvmalloc(GFP_KERNEL) In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077856.9776.9058981558717379813.stgit@noble> this allocation is called from several places, but all are during initialization, so GFP_NOFS is not needed. So use kvmalloc and GFP_KERNEL. Signed-off-by: NeilBrown --- drivers/staging/lustre/lnet/libcfs/libcfs_mem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c index 23734cfb5d44..8e2b4f1db0a1 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c @@ -54,8 +54,7 @@ cfs_percpt_free(void *vars) LIBCFS_FREE(arr->va_ptrs[i], arr->va_size); } - LIBCFS_FREE(arr, offsetof(struct cfs_var_array, - va_ptrs[arr->va_count])); + kvfree(arr); } EXPORT_SYMBOL(cfs_percpt_free); @@ -79,7 +78,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; From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 13/14] staging: lustre: replace LIBCFS_CPT_ALLOC() In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077863.9776.14166250328540990773.stgit@noble> LIBCFS_APT_ALLOC() calls kvmalloc_node() with GFP_NOFS which is not permitted. Mostly, a kmalloc_node(GFP_NOFS) is appropriate, though occasionally the allocation is large and GFP_KERNEL is acceptable, so kvmalloc_node() can be used. This patch introduces 4 alternatives to LIBCFS_CPT_ALLOC(): kmalloc_cpt() kzalloc_cpt() kvmalloc_cpt() kvzalloc_cpt(). Each takes a size, gfp flags, and cpt number. Almost every call to LIBCFS_CPT_ALLOC() passes lnet_cpt_table() as the table. This patch embeds that choice in the k*alloc_cpt() macros, and opencode kzalloc_node(..., cfs_cpt_spread_node(..)) in the one case that lnet_cpt_table() isn't used. When LIBCFS_CPT_ALLOC() is replaced, the matching LIBCFS_FREE() is also replaced, with with kfree() or kvfree() as appropriate. Signed-off-by: NeilBrown --- .../lustre/include/linux/libcfs/libcfs_private.h | 19 ++++ .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 99 +++++++------------- .../staging/lustre/lnet/klnds/socklnd/socklnd.c | 15 +-- drivers/staging/lustre/lnet/libcfs/libcfs_mem.c | 9 +- drivers/staging/lustre/lnet/lnet/api-ni.c | 11 +- drivers/staging/lustre/lnet/lnet/lib-msg.c | 14 +-- drivers/staging/lustre/lnet/lnet/lib-ptl.c | 6 + drivers/staging/lustre/lnet/lnet/peer.c | 8 +- drivers/staging/lustre/lnet/lnet/router.c | 8 +- drivers/staging/lustre/lnet/selftest/rpc.c | 9 +- 10 files changed, 88 insertions(+), 110 deletions(-) diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h index d230c7f7cced..50a600564fb2 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h @@ -126,6 +126,25 @@ do { \ kvfree(ptr); \ } while (0) +/* + * Use #define rather than inline, as lnet_cpt_table() might + * not be defined yet + */ +#define kmalloc_cpt(size, flags, cpt) \ + kmalloc_node(size, flags, cfs_cpt_spread_node(lnet_cpt_table(), cpt)) + +#define kzalloc_cpt(size, flags, cpt) \ + kmalloc_node(size, flags | __GFP_ZERO, \ + cfs_cpt_spread_node(lnet_cpt_table(), cpt)) + +#define kvmalloc_cpt(size, flags, cpt) \ + kvmalloc_node(size, flags, \ + cfs_cpt_spread_node(lnet_cpt_table(), cpt)) + +#define kvzalloc_cpt(size, flags, cpt) \ + kvmalloc_node(size, flags | __GFP_ZERO, \ + cfs_cpt_spread_node(lnet_cpt_table(), cpt)) + /******************************************************************************/ void libcfs_debug_dumplog(void); diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index bb7b19473e3a..2ebc484385b3 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; @@ -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; @@ -877,11 +875,7 @@ 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)); - } - + kfree(conn->ibc_rxs); kfree(conn->ibc_connvars); if (conn->ibc_hdev) @@ -1088,7 +1082,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) @@ -1096,14 +1090,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++) { @@ -1375,8 +1368,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; @@ -1425,7 +1417,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; @@ -1984,30 +1976,14 @@ 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); kfree(tpo); @@ -2028,7 +2004,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; @@ -2046,8 +2022,8 @@ static int kiblnd_create_tx_pool(struct kib_poolset *ps, int size, 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); @@ -2061,36 +2037,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; } diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c index 7dba949a95a7..ff292216290d 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c @@ -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; @@ -2257,13 +2257,8 @@ 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); } @@ -2452,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; diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c index 8e2b4f1db0a1..7faed94994ea 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c @@ -49,10 +49,8 @@ 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]); kvfree(arr); } @@ -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; diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c index 6a1fb0397604..2c7abad57104 100644 --- a/drivers/staging/lustre/lnet/lnet/api-ni.c +++ b/drivers/staging/lustre/lnet/lnet/api-ni.c @@ -404,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 */ } @@ -426,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; diff --git a/drivers/staging/lustre/lnet/lnet/lib-msg.c b/drivers/staging/lustre/lnet/lnet/lib-msg.c index ff6c43323fb5..0091273c04b9 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-msg.c +++ b/drivers/staging/lustre/lnet/lnet/lib-msg.c @@ -553,12 +553,8 @@ lnet_msg_container_cleanup(struct lnet_msg_container *container) 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 519cfebaaa88..471f2f6c86f4 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-ptl.c +++ b/drivers/staging/lustre/lnet/lnet/lib-ptl.c @@ -775,7 +775,7 @@ lnet_ptl_cleanup(struct lnet_portal *ptl) } } /* 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/peer.c b/drivers/staging/lustre/lnet/lnet/peer.c index 19fcbcf0f642..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); @@ -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 476d6d296037..6504761ca598 100644 --- a/drivers/staging/lustre/lnet/lnet/router.c +++ b/drivers/staging/lustre/lnet/lnet/router.c @@ -1296,12 +1296,10 @@ lnet_router_checker(void *arg) 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 * @@ -1313,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; @@ -1327,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/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c index 4ebb5a1107be..b6c9ab92c288 100644 --- a/drivers/staging/lustre/lnet/selftest/rpc.c +++ b/drivers/staging/lustre/lnet/selftest/rpc.c @@ -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; @@ -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; From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 12/14] staging: lustre: opencode LIBCFS_ALLOC_ATOMIC calls. In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077859.9776.5353432944670337893.stgit@noble> Just call kzalloc(GFP_ATOMIC) directly. We don't need the warning on failure. Signed-off-by: NeilBrown --- .../lustre/lustre/obdclass/lprocfs_status.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c index 85483a38c6c4..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)) { @@ -1156,7 +1156,7 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num, 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; @@ -1193,8 +1193,7 @@ 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); + kfree(stats->ls_percpu[i]); kvfree(stats->ls_cnt_header); kvfree(stats); } From neilb at suse.com Tue Jan 9 01:19:38 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:19:38 +1100 Subject: [lustre-devel] [PATCH 14/14] staging: lustre: remove LIBCFS_ALLOC, LIBCFS_FREE and related macros. In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <151546077867.9776.6765866963367159386.stgit@noble> LIBCFS_ALLOC LIBCFS_ALLOC_ATOMIC LIBCFS_ALLOC_POST LIBCFS_CPT_ALLOC LIBCFS_FREE are no longer used, and so are removed. Signed-off-by: NeilBrown --- .../lustre/include/linux/libcfs/libcfs_private.h | 51 -------------------- 1 file changed, 51 deletions(-) diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h index 50a600564fb2..491d5971d199 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h @@ -75,57 +75,6 @@ do { \ lbug_with_loc(&msgdata); \ } while (0) -#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) - -/** - * default allocator - */ -#define LIBCFS_ALLOC(ptr, size) \ -do { \ - LASSERT(!in_interrupt()); \ - (ptr) = kvmalloc((size), GFP_NOFS); \ - LIBCFS_ALLOC_POST((ptr), (size)); \ -} while (0) - -/** - * non-sleeping allocator - */ -#define LIBCFS_ALLOC_ATOMIC(ptr, size) \ -do { \ - (ptr) = kmalloc((size), GFP_ATOMIC); \ - LIBCFS_ALLOC_POST(ptr, size); \ -} while (0) - -/** - * 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(ptr, cptab, cpt, size) \ -do { \ - LASSERT(!in_interrupt()); \ - (ptr) = kvmalloc_node((size), GFP_NOFS, cfs_cpt_spread_node(cptab, cpt)); \ - LIBCFS_ALLOC_POST((ptr), (size)); \ -} while (0) - -#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) - /* * Use #define rather than inline, as lnet_cpt_table() might * not be defined yet From neilb at suse.com Tue Jan 9 01:29:28 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:29:28 +1100 Subject: [lustre-devel] [PATCH 3/4] staging: lustre: lnet: convert selftest to use workqueues In-Reply-To: <20180108144558.GA6826@kroah.com> References: <151356013394.15912.9645528414310488005.stgit@noble> <151356031919.15912.12406337913485020577.stgit@noble> <20180108144558.GA6826@kroah.com> Message-ID: <87shbfbz0n.fsf@notabene.neil.brown.name> On Mon, Jan 08 2018, Greg Kroah-Hartman wrote: > On Mon, Dec 18, 2017 at 12:25:19PM +1100, NeilBrown wrote: >> Instead of the cfs workitem library, use workqueues. >> >> As lnet wants to provide a cpu mask of allowed cpus, it >> needs to be a WQ_UNBOUND work queue so that tasks can >> run on cpus other than where they were submitted. > > This patch doesn't apply to my tree :( Probably because some of the kmalloc changes didn't land, and that caused a context change. > >> apply_workqueue_atts needs to be exported for lustre to use it. > > That feels really odd, why is lustre so "special" that the normal > workqueue api doesn't work properly for it? You could ask: what is so special about apply_workqueue_atts() that it isn't exported? It seems as much a part of the workqueue api as anything else. It is even documented in Documentation/core-api/workqueue.rst lustre is using it to identify a subset of CPUs for the workqueue to run on. lustre allows workers to be restricted to select cpus to avoid interfering with other tasks. workqueue has an interface to support this, it just forgot to export it. I've added a note to the patch with some of this explanation, and will re-post once the kmalloc changes land. Thanks, NeilBrown > > I've dropped this, and the next patch, from my queue now. Please fix up > and resend and justify why lustre is so odd :) > > thanks, > > greg k-h -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 832 bytes Desc: not available URL: From neilb at suse.com Tue Jan 9 01:44:23 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 09 Jan 2018 12:44:23 +1100 Subject: [lustre-devel] [PATCH 5 v2: 00/19] staging: lustre: use standard wait_event macros In-Reply-To: References: <151538168618.23920.8261096424342988792.stgit@noble> <20180108145943.GA5761@kroah.com> Message-ID: <87po6jbybs.fsf@notabene.neil.brown.name> On Mon, Jan 08 2018, James Simmons wrote: >> On Mon, Jan 08, 2018 at 02:28:13PM +1100, NeilBrown wrote: >> > Hi, >> > this is a revised version of the patch series I sent under a similar >> > subject in mid December. >> > Improvements are: >> > - new wait_event_idle* macros are now in include/linux/wait.h which >> > Ack from peterz. >> > - *all* waits are now TASK_IDLE or TASK_INTERRUPTIBLE and so don't >> > affect the load average. There is no need to choose whether load >> > is appropriate or not in each case. >> > - all l_wait_event() users are handled so l_wait_event() is >> > removed. The one case I had left out before uses >> > wait_event_idle_exclusive() with and option of using >> > wait_event_idle_exclusive_lifo() is that ever gets approved. >> > >> > I think this set is ready to go. >> > If you only review two patches, please review >> > >> > staging: lustre: simplify waiting in ldlm_completion_ast() >> > and >> > staging: lustre: remove back_to_sleep() >> > >> > as in both of those, the actual behaviour of the current code (as I >> > understand it) doesn't seem to agree with comments/debug message, or >> > just generally looks odd. >> >> This series broke the build, so I'll roll back my tree and drop it. >> >> Please fix it up and resend and test build it first... > > Please don't merge these just yet. They need to be tested first. I don't > want to be in a position where the lustre client is totally not usable > like in the past. That kind of breakage makes no one want to use the > lustre client. We have a test suite for these kinds of changes. Neill do > you know how to test your patches with the test suite? Also I have been > working on several things for the last 4 months to merge upstream. I like > to coordinate with you so we don't step on each others toes. I've only been doing fairly basic testing so far. I will look into setting up the test suite, though probably not until the end of the month. I'm keen to coordinate. However I do wonder if we should be merging new functionality/improvements (as I think you suggest) until we have the code cleaned up to upstream standards and have it ready to move out of staging. I don't object to new functionality at all, but I would object to a patch that added new functionality in a style that conflicted with upstream. It is common practice when enhancing old code to tidy it up first, then add the enhancements. Of course, people have have valid disagreements about what "upstream style" means.... If/when you have patches ready-to-go for upstream, please do post them, even if only as an RFC. I'll happily rebase anything I have on top of them. Thanks, NeilBrown -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 832 bytes Desc: not available URL: From gregkh at linuxfoundation.org Tue Jan 9 08:24:47 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Tue, 9 Jan 2018 09:24:47 +0100 Subject: [lustre-devel] [PATCH 04/19] staging: lustre: discard cfs_time_seconds() In-Reply-To: References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209341.23920.8613572158448297057.stgit@noble> <20180108170043.GA28139@kroah.com> Message-ID: <20180109082447.GA13112@kroah.com> On Mon, Jan 08, 2018 at 06:04:33PM +0000, James Simmons wrote: > > > On Mon, Jan 08, 2018 at 04:52:35PM +0000, James Simmons wrote: > > > > > > > cfs_time_seconds() converts a number of seconds to the > > > > matching number of jiffies. > > > > The standard way to do this in Linux is "* HZ". > > > > So discard cfs_time_seconds() and use "* HZ" instead. > > > > > > Just to make you aware I have been working for several months on > > > moving lustre away from using jiffies as much as possible. The > > > problem with using HZ is that it can vary. So when you have a > > > parallel file system with batches of nodes that have different > > > values of HZ you can get very interesting corner cases. So I have > > > been moving everything over to time64_t and ktime. Also I mostly > > > have killed off the cfs_time_shift* and crap as well. You see all > > > work under https://jira.hpdd.intel.com/browse/LU-9019. So many > > > of the cases you did below don't event exist any more. I was > > > planning to push those changes after the next merge window. > > > > First patch to me "wins", none of this "don't touch this code because > > I'm going to work on it in the future" stuff. That has been documented > > to kill contributions and in one case, a whole opensource kernel > > project. > > > > So Neil's patches should be evaluated first, don't develop behind closed > > walls like you are doing > > What I'm saying is my work had been tested and various bugs have > been worked out before it gets to you. His work is new and untested. His > work can be evaluated first but that doesn't mean it ready to land first. > The wait event changes is a pretty big change that can have unseen > consequences. And how in the world am I supposed to know that your work is somehow better than his? I don't see your work in my inbox at all, so am I supposed to just guess? Come on, you all know how kernel development works, and it sure isn't this way. > > I've merged almost all of them now, except for the ones that broke the > > build :) > > He just posted a updated the version of the l_wait_event changes a few > hours ago based on feed back. Please give it more than a few hours to > bake. I like to test them to make sure things don't break. I hate to > find out it breaks things and have it reverted. Please. reverts are trivial, delaying patch acceptance for no good reason is not. thanks, greg k-h From gregkh at linuxfoundation.org Tue Jan 9 08:25:11 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Tue, 9 Jan 2018 09:25:11 +0100 Subject: [lustre-devel] [PATCH 5 v2: 00/19] staging: lustre: use standard wait_event macros In-Reply-To: References: <151538168618.23920.8261096424342988792.stgit@noble> <20180108145943.GA5761@kroah.com> <20180108163607.GA3046@kroah.com> Message-ID: <20180109082511.GB13112@kroah.com> On Mon, Jan 08, 2018 at 06:06:01PM +0000, James Simmons wrote: > > > On Mon, Jan 08, 2018 at 04:21:50PM +0000, James Simmons wrote: > > > > > > > On Mon, Jan 08, 2018 at 02:28:13PM +1100, NeilBrown wrote: > > > > > Hi, > > > > > this is a revised version of the patch series I sent under a similar > > > > > subject in mid December. > > > > > Improvements are: > > > > > - new wait_event_idle* macros are now in include/linux/wait.h which > > > > > Ack from peterz. > > > > > - *all* waits are now TASK_IDLE or TASK_INTERRUPTIBLE and so don't > > > > > affect the load average. There is no need to choose whether load > > > > > is appropriate or not in each case. > > > > > - all l_wait_event() users are handled so l_wait_event() is > > > > > removed. The one case I had left out before uses > > > > > wait_event_idle_exclusive() with and option of using > > > > > wait_event_idle_exclusive_lifo() is that ever gets approved. > > > > > > > > > > I think this set is ready to go. > > > > > If you only review two patches, please review > > > > > > > > > > staging: lustre: simplify waiting in ldlm_completion_ast() > > > > > and > > > > > staging: lustre: remove back_to_sleep() > > > > > > > > > > as in both of those, the actual behaviour of the current code (as I > > > > > understand it) doesn't seem to agree with comments/debug message, or > > > > > just generally looks odd. > > > > > > > > This series broke the build, so I'll roll back my tree and drop it. > > > > > > > > Please fix it up and resend and test build it first... > > > > > > Please don't merge these just yet. They need to be tested first. I don't > > > want to be in a position where the lustre client is totally not usable > > > like in the past. That kind of breakage makes no one want to use the > > > lustre client. We have a test suite for these kinds of changes. Neill do > > > you know how to test your patches with the test suite? Also I have been > > > working on several things for the last 4 months to merge upstream. I like > > > to coordinate with you so we don't step on each others toes. > > > > If I don't hear anything for a few weeks, I merge patches. That should > > be long enough to test... > > Agree. This patch set is only a few hours old. The v2 was, v1 was not. greg k-h From gregkh at linuxfoundation.org Tue Jan 9 15:00:00 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Tue, 9 Jan 2018 16:00:00 +0100 Subject: [lustre-devel] [PATCH 00/14] staging:lustre: convert most LIBCFS*ALLOC to k*malloc - V2 In-Reply-To: <151546052331.9776.7408338350463291753.stgit@noble> References: <151546052331.9776.7408338350463291753.stgit@noble> Message-ID: <20180109150000.GA9846@kroah.com> On Tue, Jan 09, 2018 at 12:19:38PM +1100, NeilBrown wrote: > This is a revised version of my LIBCFS*ALLOC cleanup series. > - the compile error is fixed > - some cases of "if (x) kfree(x)" have been simplified > - LIBCFS_CPT_ALLOC() has been replaced as well. Very nice, I've been wanting to see this happen for a very long time now. All now queued up, thanks. greg k-h From neilb at suse.com Thu Jan 11 04:06:40 2018 From: neilb at suse.com (NeilBrown) Date: Thu, 11 Jan 2018 15:06:40 +1100 Subject: [lustre-devel] [PATCH 0/2] staging: lustre: finish removal of workitem code. Message-ID: <151564345630.21794.1667069238139184132.stgit@noble> This is a resend of the last two patches of my "remove workitem code", which resolve a merge conflict and add and 'Ack-by' from Tejun. The first two patches have already been merged. Thanks, NeilBrown Original intro: Lustre has a "workitem" subsystem with much the same functionality as the Linux workqueue subsystem. This patch converts all users of workitem to workqueue, then removes workitem. --- NeilBrown (2): staging: lustre: lnet: convert selftest to use workqueues staging: lustre: libcfs: remove workitem code. .../staging/lustre/include/linux/libcfs/libcfs.h | 1 .../lustre/include/linux/libcfs/libcfs_workitem.h | 104 ---- drivers/staging/lustre/lnet/libcfs/Makefile | 2 drivers/staging/lustre/lnet/libcfs/module.c | 11 drivers/staging/lustre/lnet/libcfs/workitem.c | 466 -------------------- drivers/staging/lustre/lnet/selftest/framework.c | 10 drivers/staging/lustre/lnet/selftest/module.c | 39 +- drivers/staging/lustre/lnet/selftest/rpc.c | 61 +-- drivers/staging/lustre/lnet/selftest/selftest.h | 40 +- kernel/workqueue.c | 1 10 files changed, 71 insertions(+), 664 deletions(-) delete mode 100644 drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h delete mode 100644 drivers/staging/lustre/lnet/libcfs/workitem.c -- Signature From neilb at suse.com Thu Jan 11 04:06:40 2018 From: neilb at suse.com (NeilBrown) Date: Thu, 11 Jan 2018 15:06:40 +1100 Subject: [lustre-devel] [PATCH 1/2] staging: lustre: lnet: convert selftest to use workqueues In-Reply-To: <151564345630.21794.1667069238139184132.stgit@noble> References: <151564345630.21794.1667069238139184132.stgit@noble> Message-ID: <151564360053.21794.4058863911958997341.stgit@noble> Instead of the cfs workitem library, use workqueues. As lnet wants to provide a cpu mask of allowed cpus, it needs to be a WQ_UNBOUND work queue so that tasks can run on cpus other than where they were submitted. This patch also exported apply_workqueue_attrs() which is a documented part of the workqueue API, that isn't currently exported. lustre needs it to allow workqueue thread to be limited to a subset of CPUs. Acked-by: Tejun Heo (for export of apply_workqueue_attrs) Signed-off-by: NeilBrown --- drivers/staging/lustre/lnet/selftest/framework.c | 10 +--- drivers/staging/lustre/lnet/selftest/module.c | 39 ++++++++------ drivers/staging/lustre/lnet/selftest/rpc.c | 61 +++++++++------------- drivers/staging/lustre/lnet/selftest/selftest.h | 40 ++++++-------- kernel/workqueue.c | 1 5 files changed, 69 insertions(+), 82 deletions(-) diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c index 2e1126552e18..c7697f66f663 100644 --- a/drivers/staging/lustre/lnet/selftest/framework.c +++ b/drivers/staging/lustre/lnet/selftest/framework.c @@ -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 = 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 @@ sfw_run_test(struct swi_workitem *wi) * - 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 @@ -1017,7 +1013,7 @@ sfw_run_batch(struct sfw_batch *tsb) tsu->tsu_loop = tsi->tsi_loop; wi = &tsu->tsu_worker; swi_init_workitem(wi, sfw_run_test, - lst_sched_test[lnet_cpt_of_nid(tsu->tsu_dest.nid)]); + lst_test_wq[lnet_cpt_of_nid(tsu->tsu_dest.nid)]); swi_schedule_workitem(wi); } } diff --git a/drivers/staging/lustre/lnet/selftest/module.c b/drivers/staging/lustre/lnet/selftest/module.c index ba4b6145c953..aa6bfd5baf2f 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,16 +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]); } - kvfree(lst_sched_test); - 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: @@ -92,33 +92,40 @@ lnet_selftest_init(void) int rc; 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; } lst_init_step = LST_INIT_WI_SERIAL; nscheds = cfs_cpt_number(lnet_cpt_table()); - lst_sched_test = kvmalloc_array(nscheds, sizeof(lst_sched_test[0]), + lst_test_wq = kvmalloc_array(nscheds, sizeof(lst_test_wq[0]), GFP_KERNEL | __GFP_ZERO); - if (!lst_sched_test) + if (!lst_test_wq) 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; /* 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); goto error; } + attrs.nice = 0; + #ifdef CONFIG_CPUMASK_OFFSTACK + attrs.cpumask = lnet_cpt_table()->ctb_parts[i].cpt_cpumask; + #else + cpumask_copy(attrs.cpumask, lnet_cpt_table()->ctb_parts[i].cpt_cpumask); + #endif + attrs.no_numa = false; + apply_workqueue_attrs(lst_test_wq[i], &attrs); } rc = srpc_startup(); diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c index b6c9ab92c288..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) { @@ -178,7 +178,7 @@ srpc_init_server_rpc(struct srpc_server_rpc *rpc, memset(rpc, 0, sizeof(*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 */ @@ -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, - srpc_add_buffer, lst_sched_test[i]); + srpc_add_buffer, lst_test_wq[i]); if (i && srpc_serv_is_framework(svc)) { /* @@ -513,7 +513,7 @@ __must_hold(&scd->scd_lock) return rc; } -int +void srpc_add_buffer(struct swi_workitem *wi) { struct srpc_service_cd *scd = container_of(wi, struct srpc_service_cd, scd_buf_wi); @@ -572,7 +572,6 @@ srpc_add_buffer(struct swi_workitem *wi) } spin_unlock(&scd->scd_lock); - return 0; } int @@ -604,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 || @@ -659,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", @@ -679,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); @@ -946,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, @@ -964,7 +958,7 @@ 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 = container_of(wi, struct srpc_server_rpc, srpc_wi); @@ -986,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); @@ -1006,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); @@ -1022,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; } } @@ -1031,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; @@ -1049,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) { @@ -1071,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 @@ -1169,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); @@ -1177,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; @@ -1213,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); @@ -1290,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) { @@ -1307,10 +1297,9 @@ srpc_send_rpc(struct swi_workitem *wi) if (!srpc_event_pending(rpc)) { srpc_client_rpc_done(rpc, -EINTR); - return 1; + return; } } - return 0; } struct srpc_client_rpc * diff --git a/drivers/staging/lustre/lnet/selftest/selftest.h b/drivers/staging/lustre/lnet/selftest/selftest.h index 465417263ef1..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, - swi_action_t action, struct cfs_wi_sched *sched) + 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, 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); @@ -534,7 +528,7 @@ srpc_init_client_rpc(struct srpc_client_rpc *rpc, struct lnet_process_id peer, INIT_LIST_HEAD(&rpc->crpc_list); swi_init_workitem(&rpc->crpc_wi, srpc_send_rpc, - lst_sched_test[lnet_cpt_of_nid(peer.nid)]); + 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/kernel/workqueue.c b/kernel/workqueue.c index 43d18cb46308..d1d460bb9b02 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -3806,6 +3806,7 @@ int apply_workqueue_attrs(struct workqueue_struct *wq, return ret; } +EXPORT_SYMBOL_GPL(apply_workqueue_attrs); /** * wq_update_unbound_numa - update NUMA affinity of a wq for CPU hot[un]plug From neilb at suse.com Thu Jan 11 04:06:40 2018 From: neilb at suse.com (NeilBrown) Date: Thu, 11 Jan 2018 15:06:40 +1100 Subject: [lustre-devel] [PATCH 2/2] staging: lustre: libcfs: remove workitem code. In-Reply-To: <151564345630.21794.1667069238139184132.stgit@noble> References: <151564345630.21794.1667069238139184132.stgit@noble> Message-ID: <151564360057.21794.11425170365180959335.stgit@noble> There are now no users. workqueues are doing the job that this used to do. Signed-off-by: NeilBrown --- .../staging/lustre/include/linux/libcfs/libcfs.h | 1 .../lustre/include/linux/libcfs/libcfs_workitem.h | 104 ---- drivers/staging/lustre/lnet/libcfs/Makefile | 2 drivers/staging/lustre/lnet/libcfs/module.c | 11 drivers/staging/lustre/lnet/libcfs/workitem.c | 466 -------------------- 5 files changed, 2 insertions(+), 582 deletions(-) delete mode 100644 drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h delete mode 100644 drivers/staging/lustre/lnet/libcfs/workitem.c diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/libcfs.h index 5bd7bee0624b..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 #include #include -#include #include #include #include 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 ddaca33a13ac..000000000000 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h +++ /dev/null @@ -1,104 +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 - * Liang Zhen - * - * 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; - /** in running */ - unsigned short wi_running:1; - /** scheduled */ - unsigned short wi_scheduled:1; -}; - -static inline void -cfs_wi_init(struct cfs_workitem *wi, cfs_wi_action_t action) -{ - INIT_LIST_HEAD(&wi->wi_list); - - wi->wi_running = 0; - wi->wi_scheduled = 0; - 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/lnet/libcfs/Makefile b/drivers/staging/lustre/lnet/libcfs/Makefile index db5b36cc3e6d..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 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/module.c b/drivers/staging/lustre/lnet/libcfs/module.c index 555f47651730..a03f924f1d7c 100644 --- a/drivers/staging/lustre/lnet/libcfs/module.c +++ b/drivers/staging/lustre/lnet/libcfs/module.c @@ -547,12 +547,6 @@ static int libcfs_init(void) goto cleanup_cpu; } - rc = cfs_wi_startup(); - if (rc) { - CERROR("initialize workitem: error %d\n", rc); - goto cleanup_deregister; - } - cfs_rehash_wq = alloc_workqueue("cfs_rh", WQ_SYSFS, 4); if (!cfs_rehash_wq) { CERROR("Failed to start rehash workqueue.\n"); @@ -563,15 +557,13 @@ static int libcfs_init(void) 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: @@ -593,7 +585,6 @@ static void libcfs_exit(void) } cfs_crypto_unregister(); - cfs_wi_shutdown(); misc_deregister(&libcfs_dev); diff --git a/drivers/staging/lustre/lnet/libcfs/workitem.c b/drivers/staging/lustre/lnet/libcfs/workitem.c deleted file mode 100644 index 74a9595dc730..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 - * Liang Zhen - */ - -#define DEBUG_SUBSYSTEM S_LNET - -#include - -#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); - - kfree(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))); - - sched = kzalloc(sizeof(*sched), GFP_NOFS); - if (!sched) - return -ENOMEM; - - if (strlen(name) > sizeof(sched->ws_name) - 1) { - kfree(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); - kfree(sched); - } - - cfs_wi_data.wi_stopping = 0; - cfs_wi_data.wi_init = 0; -} From bevans at cray.com Thu Jan 11 17:25:20 2018 From: bevans at cray.com (Ben Evans) Date: Thu, 11 Jan 2018 17:25:20 +0000 Subject: [lustre-devel] (no subject) In-Reply-To: <1515691022-22729-1-git-send-email-fabian_huegel@web.de> References: <1515691022-22729-1-git-send-email-fabian_huegel@web.de> Message-ID: I've been working off and on with this. Since you're getting into the counters in a couple of the patches, part of the reason for all the #defines here are because MDC, MDT and OST counters are all shoved into the same array dynamically, sometimes. It would be a much cleaner approach to have a separate array for the MDC stats, then print them conditionally. This would reduce all of the calls to these macros to counter increments. -Ben Evans On 1/11/18, 12:16 PM, "Fabian Huegel" wrote: >We cleaned up a lot of checkpatch errors and warnings in obd_class.h, >but there are still some CHECKs and two warnings about flow control >inside macros left. > >Changing those macros to inline functions would probably >be a good idea, unfortunatly it's not straightforward since they use >'#op' to print the name of the operation. > >We also did some aligning to make the code more readable and removed >an unnecessary macro. > >We only tested, that the kernel still compiles and the lustre kernel >module loads successfully, but given the harmless nature of these >changes we don't expect any problems. > >The patches are based on the staging-testing branch of the staging tree. > From dan.carpenter at oracle.com Mon Jan 15 09:26:57 2018 From: dan.carpenter at oracle.com (Dan Carpenter) Date: Mon, 15 Jan 2018 12:26:57 +0300 Subject: [lustre-devel] [bug report] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. Message-ID: <20180115092657.om2gdrcwlajo2tvi@mwanda> [ This code was already buggy, it's just that Neil's change made it show up in static analysis. - dan ] Hello NeilBrown, The patch 3c88bdbbf919: "staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc." from Jan 9, 2018, leads to the following static checker warning: drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c:3323 kiblnd_connd() error: dereferencing freed memory 'conn' drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c 3303 if (!list_empty(&kiblnd_data.kib_connd_zombies)) { 3304 struct kib_peer *peer = NULL; 3305 3306 conn = list_entry(kiblnd_data.kib_connd_zombies.next, 3307 struct kib_conn, ibc_list); 3308 list_del(&conn->ibc_list); 3309 if (conn->ibc_reconnect) { 3310 peer = conn->ibc_peer; 3311 kiblnd_peer_addref(peer); 3312 } 3313 3314 spin_unlock_irqrestore(lock, flags); 3315 dropped_lock = 1; 3316 3317 kiblnd_destroy_conn(conn, !peer); ^^^^ Freed 3318 3319 spin_lock_irqsave(lock, flags); 3320 if (!peer) 3321 continue; 3322 3323 conn->ibc_peer = peer; ^^^^^^^^^^^^^^ Use after free 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) 3325 list_add_tail(&conn->ibc_list, ^^^^^^^^^^^^^^ 3326 &kiblnd_data.kib_reconn_list); 3327 else 3328 list_add_tail(&conn->ibc_list, ^^^^^^^^^^^^^^ 3329 &kiblnd_data.kib_reconn_wait); 3330 } regards, dan carpenter From dan.carpenter at oracle.com Mon Jan 15 09:36:27 2018 From: dan.carpenter at oracle.com (Dan Carpenter) Date: Mon, 15 Jan 2018 12:36:27 +0300 Subject: [lustre-devel] [bug report] staging: lustre: DLC Feature dynamic net config Message-ID: <20180115093627.wwygrvhxbrthb5cx@mwanda> Hello Amir Shehata, The patch 6c9e5a55cb62: "staging: lustre: DLC Feature dynamic net config" from Feb 15, 2016, leads to the following static checker warning: drivers/staging/lustre/lnet/lnet/api-ni.c:1804 lnet_dyn_add_ni() error: dereferencing freed memory 'ni' drivers/staging/lustre/lnet/lnet/api-ni.c 1212 static int 1213 lnet_startup_lndni(struct lnet_ni *ni, struct lnet_ioctl_config_data *conf) 1214 { 1215 struct lnet_ioctl_config_lnd_tunables *lnd_tunables = NULL; 1216 int rc = -EINVAL; 1217 int lnd_type; 1218 struct lnet_lnd *lnd; 1219 struct lnet_tx_queue *tq; 1220 int i; 1221 1222 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid)); 1223 1224 LASSERT(libcfs_isknown_lnd(lnd_type)); 1225 1226 if (lnd_type == CIBLND || lnd_type == OPENIBLND || 1227 lnd_type == IIBLND || lnd_type == VIBLND) { 1228 CERROR("LND %s obsoleted\n", libcfs_lnd2str(lnd_type)); 1229 goto failed0; 1230 } 1231 1232 /* Make sure this new NI is unique. */ 1233 lnet_net_lock(LNET_LOCK_EX); 1234 rc = lnet_net_unique(LNET_NIDNET(ni->ni_nid), &the_lnet.ln_nis); 1235 lnet_net_unlock(LNET_LOCK_EX); 1236 if (!rc) { 1237 if (lnd_type == LOLND) { 1238 lnet_ni_free(ni); ^^^^^^^^^^^^^^^^ The caller is not expecting this to be freed on the success path. 1239 return 0; 1240 } 1241 1242 CERROR("Net %s is not unique\n", 1243 libcfs_net2str(LNET_NIDNET(ni->ni_nid))); 1244 rc = -EEXIST; 1245 goto failed0; 1246 } 1247 regards, dan carpenter From gregkh at linuxfoundation.org Mon Jan 15 14:48:19 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 15 Jan 2018 15:48:19 +0100 Subject: [lustre-devel] [PATCH 1/2] staging: lustre: lnet: convert selftest to use workqueues In-Reply-To: <151564360053.21794.4058863911958997341.stgit@noble> References: <151564345630.21794.1667069238139184132.stgit@noble> <151564360053.21794.4058863911958997341.stgit@noble> Message-ID: <20180115144819.GA21012@kroah.com> On Thu, Jan 11, 2018 at 03:06:40PM +1100, NeilBrown wrote: > Instead of the cfs workitem library, use workqueues. > > As lnet wants to provide a cpu mask of allowed cpus, it > needs to be a WQ_UNBOUND work queue so that tasks can > run on cpus other than where they were submitted. > > This patch also exported apply_workqueue_attrs() which is > a documented part of the workqueue API, that isn't currently > exported. lustre needs it to allow workqueue thread to be limited > to a subset of CPUs. > > Acked-by: Tejun Heo (for export of apply_workqueue_attrs) > Signed-off-by: NeilBrown I now see the following build warning with this patch applied: drivers/staging/lustre/lnet/selftest/module.c: In function ‘lnet_selftest_init’: drivers/staging/lustre/lnet/selftest/module.c:98:10: warning: ‘rc’ may be used uninitialized in this function [-Wmaybe-uninitialized] return rc; ^~ Care to send a follow-on patch to fix it up? thanks, greg k-h From gregkh at linuxfoundation.org Mon Jan 15 15:00:28 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 15 Jan 2018 16:00:28 +0100 Subject: [lustre-devel] [PATCH 1/8] staging: lustre: Enclose complex macros in parentheses In-Reply-To: <1515691022-22729-2-git-send-email-fabian_huegel@web.de> References: <1515691022-22729-1-git-send-email-fabian_huegel@web.de> <1515691022-22729-2-git-send-email-fabian_huegel@web.de> Message-ID: <20180115150028.GA10946@kroah.com> On Thu, Jan 11, 2018 at 06:16:55PM +0100, Fabian Huegel wrote: > Checkpatch wants complex macros to be enclosed in parentheses, so we > put parentheses around these four macros. > > Signed-off-by: Fabian Huegel > Signed-off-by: Christoph Volkert > --- > drivers/staging/lustre/lustre/include/obd_class.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h > index 67c535c..5c8cf30 100644 > --- a/drivers/staging/lustre/lustre/include/obd_class.h > +++ b/drivers/staging/lustre/lustre/include/obd_class.h > @@ -294,10 +294,10 @@ struct obdo; > > void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj); > > -#define OBT(dev) (dev)->obd_type > -#define OBP(dev, op) (dev)->obd_type->typ_dt_ops->op > -#define MDP(dev, op) (dev)->obd_type->typ_md_ops->op > -#define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op > +#define OBT(dev) ((dev)->obd_type) > +#define OBP(dev, op) ((dev)->obd_type->typ_dt_ops->op) > +#define MDP(dev, op) ((dev)->obd_type->typ_md_ops->op) > +#define CTXTP(ctxt, op) ((ctxt)->loc_logops->lop_##op) That really doesn't make any sense, as this can only be a variable in here, not any "complex expression". Sometimes checkpatch.pl isn't very smart. Also, these macros are horridly named, odds are they are not even needed... thanks, greg k-h From gregkh at linuxfoundation.org Mon Jan 15 15:02:59 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 15 Jan 2018 16:02:59 +0100 Subject: [lustre-devel] [PATCH 4/8] staging: lustre: Fix comment style In-Reply-To: <1515691022-22729-5-git-send-email-fabian_huegel@web.de> References: <1515691022-22729-1-git-send-email-fabian_huegel@web.de> <1515691022-22729-5-git-send-email-fabian_huegel@web.de> Message-ID: <20180115150259.GA17991@kroah.com> On Thu, Jan 11, 2018 at 06:16:58PM +0100, Fabian Huegel wrote: > Most multi-line comments started on the first line, but the preferred > linux kernel style is to start multi-line comments on the second line. > Some comments became less readable after the change, so we changed them > to single-line comments. > > Signed-off-by: Fabian Huegel > Signed-off-by: Christoph Volkert > --- > drivers/staging/lustre/lustre/include/obd_class.h | 47 +++++++++++++---------- > 1 file changed, 27 insertions(+), 20 deletions(-) This, and another patch, did not apply to my tree, probably because I didn't take the first one. Please rebase and resend the remaining ones. thanks, greg k-h From dmitry.eremin at intel.com Mon Jan 15 18:27:26 2018 From: dmitry.eremin at intel.com (Eremin, Dmitry) Date: Mon, 15 Jan 2018 18:27:26 +0000 Subject: [lustre-devel] [bug report] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: <20180115092657.om2gdrcwlajo2tvi@mwanda> References: <20180115092657.om2gdrcwlajo2tvi@mwanda> Message-ID: <9FC73D3DBECE0941BD2ED069D26863425CE75889@irsmsx110.ger.corp.intel.com> Hello Dan, The function kiblnd_destroy_conn() is conditionally free the conn pointer. void kiblnd_destroy_conn(kib_conn_t *conn, bool free_conn) { […] if (free_conn) LIBCFS_FREE(conn, sizeof(*conn)); } Therefore > 3317 kiblnd_destroy_conn(conn, !peer); > ^^^^ Freed Conditionally free if !peer. > 3318 > 3319 spin_lock_irqsave(lock, flags); > 3320 if (!peer) > 3321 continue; ^^^^^^^^^^ Check for freed or not. If freed go to next loop. > 3322 > 3323 conn->ibc_peer = peer; > ^^^^^^^^^^^^^^ Use after free This access is legal because of It was not freed. Dmitry. > -----Original Message----- > From: lustre-devel [mailto:lustre-devel-bounces at lists.lustre.org] On Behalf > Of Dan Carpenter > Sent: Monday, January 15, 2018 12:27 PM > To: neilb at suse.com > Cc: devel at driverdev.osuosl.org; lustre-devel at lists.lustre.org > Subject: [lustre-devel] [bug report] staging: lustre: replace simple cases of > LIBCFS_ALLOC with kzalloc. > > [ This code was already buggy, it's just that Neil's change made it > show up in static analysis. - dan ] > > Hello NeilBrown, > > The patch 3c88bdbbf919: "staging: lustre: replace simple cases of > LIBCFS_ALLOC with kzalloc." from Jan 9, 2018, leads to the following static > checker warning: > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c:3323 > kiblnd_connd() > error: dereferencing freed memory 'conn' > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > 3303 if (!list_empty(&kiblnd_data.kib_connd_zombies)) { > 3304 struct kib_peer *peer = NULL; > 3305 > 3306 conn = list_entry(kiblnd_data.kib_connd_zombies.next, > 3307 struct kib_conn, ibc_list); > 3308 list_del(&conn->ibc_list); > 3309 if (conn->ibc_reconnect) { > 3310 peer = conn->ibc_peer; > 3311 kiblnd_peer_addref(peer); > 3312 } > 3313 > 3314 spin_unlock_irqrestore(lock, flags); > 3315 dropped_lock = 1; > 3316 > 3317 kiblnd_destroy_conn(conn, !peer); > ^^^^ Freed > > 3318 > 3319 spin_lock_irqsave(lock, flags); > 3320 if (!peer) > 3321 continue; > 3322 > 3323 conn->ibc_peer = peer; > ^^^^^^^^^^^^^^ Use after free > > 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) > 3325 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ > > 3326 &kiblnd_data.kib_reconn_list); > 3327 else > 3328 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ > > 3329 &kiblnd_data.kib_reconn_wait); > 3330 } > > regards, > dan carpenter > _______________________________________________ > lustre-devel mailing list > lustre-devel at lists.lustre.org > http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org -------------------------------------------------------------------- Joint Stock Company Intel A/O Registered legal address: Krylatsky Hills Business Park, 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. From dmitry.eremin at intel.com Mon Jan 15 18:37:16 2018 From: dmitry.eremin at intel.com (Eremin, Dmitry) Date: Mon, 15 Jan 2018 18:37:16 +0000 Subject: [lustre-devel] [bug report] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: <9FC73D3DBECE0941BD2ED069D26863425CE75889@irsmsx110.ger.corp.intel.com> References: <20180115092657.om2gdrcwlajo2tvi@mwanda> <9FC73D3DBECE0941BD2ED069D26863425CE75889@irsmsx110.ger.corp.intel.com> Message-ID: <9FC73D3DBECE0941BD2ED069D26863425CE758A6@irsmsx110.ger.corp.intel.com> Hello Dan, It looks this condition is missed in the code. Sorry we should fix this. Dmitry. > -----Original Message----- > From: Eremin, Dmitry > Sent: Monday, January 15, 2018 9:27 PM > To: Dan Carpenter ; neilb at suse.com > Cc: devel at driverdev.osuosl.org; lustre-devel at lists.lustre.org > Subject: RE: [lustre-devel] [bug report] staging: lustre: replace simple cases > of LIBCFS_ALLOC with kzalloc. > > Hello Dan, > > The function kiblnd_destroy_conn() is conditionally free the conn pointer. > > void kiblnd_destroy_conn(kib_conn_t *conn, bool free_conn) { […] > if (free_conn) > LIBCFS_FREE(conn, sizeof(*conn)); } > > Therefore > > 3317 kiblnd_destroy_conn(conn, !peer); > > ^^^^ Freed > > Conditionally free if !peer. > > > 3318 > > 3319 spin_lock_irqsave(lock, flags); > > 3320 if (!peer) > > 3321 continue; > ^^^^^^^^^^ Check for freed or not. If freed go to next > loop. > > > 3322 > > 3323 conn->ibc_peer = peer; > > ^^^^^^^^^^^^^^ Use after free > > This access is legal because of It was not freed. > > Dmitry. > > -----Original Message----- > > From: lustre-devel [mailto:lustre-devel-bounces at lists.lustre.org] On > > Behalf Of Dan Carpenter > > Sent: Monday, January 15, 2018 12:27 PM > > To: neilb at suse.com > > Cc: devel at driverdev.osuosl.org; lustre-devel at lists.lustre.org > > Subject: [lustre-devel] [bug report] staging: lustre: replace simple > > cases of LIBCFS_ALLOC with kzalloc. > > > > [ This code was already buggy, it's just that Neil's change made it > > show up in static analysis. - dan ] > > > > Hello NeilBrown, > > > > The patch 3c88bdbbf919: "staging: lustre: replace simple cases of > > LIBCFS_ALLOC with kzalloc." from Jan 9, 2018, leads to the following > > static checker warning: > > > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c:3323 > > kiblnd_connd() > > error: dereferencing freed memory 'conn' > > > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > > 3303 if (!list_empty(&kiblnd_data.kib_connd_zombies)) { > > 3304 struct kib_peer *peer = NULL; > > 3305 > > 3306 conn = list_entry(kiblnd_data.kib_connd_zombies.next, > > 3307 struct kib_conn, ibc_list); > > 3308 list_del(&conn->ibc_list); > > 3309 if (conn->ibc_reconnect) { > > 3310 peer = conn->ibc_peer; > > 3311 kiblnd_peer_addref(peer); > > 3312 } > > 3313 > > 3314 spin_unlock_irqrestore(lock, flags); > > 3315 dropped_lock = 1; > > 3316 > > 3317 kiblnd_destroy_conn(conn, !peer); > > ^^^^ Freed > > > > 3318 > > 3319 spin_lock_irqsave(lock, flags); > > 3320 if (!peer) > > 3321 continue; > > 3322 > > 3323 conn->ibc_peer = peer; > > ^^^^^^^^^^^^^^ Use after free > > > > 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) > > 3325 list_add_tail(&conn->ibc_list, > > ^^^^^^^^^^^^^^ > > > > 3326 &kiblnd_data.kib_reconn_list); > > 3327 else > > 3328 list_add_tail(&conn->ibc_list, > > ^^^^^^^^^^^^^^ > > > > 3329 &kiblnd_data.kib_reconn_wait); > > 3330 } > > > > regards, > > dan carpenter > > _______________________________________________ > > lustre-devel mailing list > > lustre-devel at lists.lustre.org > > http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org -------------------------------------------------------------------- Joint Stock Company Intel A/O Registered legal address: Krylatsky Hills Business Park, 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. From dan.carpenter at oracle.com Tue Jan 16 08:12:08 2018 From: dan.carpenter at oracle.com (Dan Carpenter) Date: Tue, 16 Jan 2018 11:12:08 +0300 Subject: [lustre-devel] [bug report] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: <9FC73D3DBECE0941BD2ED069D26863425CE75889@irsmsx110.ger.corp.intel.com> References: <20180115092657.om2gdrcwlajo2tvi@mwanda> <9FC73D3DBECE0941BD2ED069D26863425CE75889@irsmsx110.ger.corp.intel.com> Message-ID: <20180116081208.memd4z76ncbpnb6l@mwanda> On Mon, Jan 15, 2018 at 06:27:26PM +0000, Eremin, Dmitry wrote: > Hello Dan, > > The function kiblnd_destroy_conn() is conditionally free the conn pointer. > > void kiblnd_destroy_conn(kib_conn_t *conn, bool free_conn) > { > […] > if (free_conn) > LIBCFS_FREE(conn, sizeof(*conn)); This check is not there in the kernel.org kernel. In the upstream kernel it frees it unconditionally. The "free_conn" parameter was added in commit 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") but that line must have been left out. regards, dan carpenter From arnd at arndb.de Tue Jan 16 09:34:25 2018 From: arnd at arndb.de (Arnd Bergmann) Date: Tue, 16 Jan 2018 10:34:25 +0100 Subject: [lustre-devel] [PATCH] staging: lustre: lnet: avoid uninitialized return value Message-ID: <20180116093511.3197459-1-arnd@arndb.de> gcc warns that the latest workqueue change leads to returning an uninitialized variable: drivers/staging/lustre/lnet/selftest/module.c: In function 'lnet_selftest_init': drivers/staging/lustre/lnet/selftest/module.c:98:10: error: 'rc' may be used uninitialized in this function [-Werror=maybe-uninitialized] A failure from alloc_ordered_workqueue() tends to indicate an out-of-memory condition, so return -ENOMEM in both cases. The second error path was a preexisting bug, where we always returned zero after a kvmalloc_array() failure. Fixes: 6106c0f82481 ("staging: lustre: lnet: convert selftest to use workqueues") Signed-off-by: Arnd Bergmann --- drivers/staging/lustre/lnet/selftest/module.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/staging/lustre/lnet/selftest/module.c b/drivers/staging/lustre/lnet/selftest/module.c index aa6bfd5baf2f..c8d999e64f28 100644 --- a/drivers/staging/lustre/lnet/selftest/module.c +++ b/drivers/staging/lustre/lnet/selftest/module.c @@ -95,15 +95,17 @@ lnet_selftest_init(void) 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()); lst_test_wq = kvmalloc_array(nscheds, sizeof(lst_test_wq[0]), GFP_KERNEL | __GFP_ZERO); - if (!lst_test_wq) + if (!lst_test_wq) { + rc = -ENOMEM; goto error; + } lst_init_step = LST_INIT_WI_TEST; for (i = 0; i < nscheds; i++) { @@ -116,6 +118,7 @@ lnet_selftest_init(void) if (!lst_test_wq[i]) { CWARN("Failed to create CPU partition affinity WI scheduler %d for LST\n", i); + rc = -ENOMEM; goto error; } attrs.nice = 0; -- 2.9.0 From dmitry.eremin at intel.com Tue Jan 16 15:01:49 2018 From: dmitry.eremin at intel.com (Eremin, Dmitry) Date: Tue, 16 Jan 2018 15:01:49 +0000 Subject: [lustre-devel] [PATCH] staging: lustre: Fix avoid intensive reconnecting for ko2iblnd patch In-Reply-To: <1516114161-27679-1-git-send-email-Dmitry.Eremin@intel.com> References: <1516114161-27679-1-git-send-email-Dmitry.Eremin@intel.com> Message-ID: <9FC73D3DBECE0941BD2ED069D26863425CE75F26@irsmsx110.ger.corp.intel.com> In the original commit 4d99b2581effe115376402e710fbcb1c3c073769 was missed one hunk. Added it now to avoid issue with use after free. Signed-off-by: Dmitry Eremin --- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 2ebc484..a15a625 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -890,7 +890,8 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) atomic_dec(&net->ibn_nconns); } - kfree(conn); + if (free_conn) + kfree(conn); } int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) -- 1.8.3.1 -------------------------------------------------------------------- Joint Stock Company Intel A/O Registered legal address: Krylatsky Hills Business Park, 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. From colin.king at canonical.com Tue Jan 16 15:59:58 2018 From: colin.king at canonical.com (Colin Ian King) Date: Tue, 16 Jan 2018 15:59:58 +0000 Subject: [lustre-devel] staging: lustre: lnet: convert selftest to use workqueues Message-ID: <8724a144-6e84-7237-3a0a-21812901d88a@canonical.com> Hi, CoverityScan detected a couple of issues, one of which was introduced with the following commit: commit 6106c0f82481e686b337ee0c403821fb5c3c17ef Author: NeilBrown Date: Thu Jan 11 15:06:40 2018 +1100 CoverityScan CID#1464078 ("Uninitialized scalar variable") I'm not sure what the expected error return for these conditions are, so I've not fixed these as I didn't want to hazard a guess. static int lnet_selftest_init(void) { int nscheds; int rc; // note here rc is not initialized int i; 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; // garbage value in rc is returned } lst_init_step = LST_INIT_WI_SERIAL; nscheds = cfs_cpt_number(lnet_cpt_table()); lst_test_wq = kvmalloc_array(nscheds, sizeof(lst_test_wq[0]), GFP_KERNEL | __GFP_ZERO); if (!lst_test_wq) goto error; // this also returns garbage in rc From gregkh at linuxfoundation.org Tue Jan 16 16:53:47 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Tue, 16 Jan 2018 17:53:47 +0100 Subject: [lustre-devel] staging: lustre: lnet: convert selftest to use workqueues In-Reply-To: <8724a144-6e84-7237-3a0a-21812901d88a@canonical.com> References: <8724a144-6e84-7237-3a0a-21812901d88a@canonical.com> Message-ID: <20180116165347.GC3682@kroah.com> On Tue, Jan 16, 2018 at 03:59:58PM +0000, Colin Ian King wrote: > Hi, > > CoverityScan detected a couple of issues, one of which was introduced > with the following commit: > > commit 6106c0f82481e686b337ee0c403821fb5c3c17ef > Author: NeilBrown > Date: Thu Jan 11 15:06:40 2018 +1100 > > CoverityScan CID#1464078 ("Uninitialized scalar variable") > > I'm not sure what the expected error return for these conditions are, so > I've not fixed these as I didn't want to hazard a guess. > > static int > lnet_selftest_init(void) > { > int nscheds; > int rc; > > // note here rc is not initialized > > int i; > > 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; > > // garbage value in rc is returned > > } > lst_init_step = LST_INIT_WI_SERIAL; > > nscheds = cfs_cpt_number(lnet_cpt_table()); > lst_test_wq = kvmalloc_array(nscheds, sizeof(lst_test_wq[0]), > GFP_KERNEL | __GFP_ZERO); > if (!lst_test_wq) > goto error; > > // this also returns garbage in rc Already fixed in my tree by a patch from Arnd and me :) thanks, greg k-h From gregkh at linuxfoundation.org Tue Jan 16 16:56:28 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Tue, 16 Jan 2018 17:56:28 +0100 Subject: [lustre-devel] [PATCH] staging: lustre: Fix avoid intensive reconnecting for ko2iblnd patch In-Reply-To: <9FC73D3DBECE0941BD2ED069D26863425CE75F26@irsmsx110.ger.corp.intel.com> References: <1516114161-27679-1-git-send-email-Dmitry.Eremin@intel.com> <9FC73D3DBECE0941BD2ED069D26863425CE75F26@irsmsx110.ger.corp.intel.com> Message-ID: <20180116165628.GB7066@kroah.com> On Tue, Jan 16, 2018 at 03:01:49PM +0000, Eremin, Dmitry wrote: > In the original commit 4d99b2581effe115376402e710fbcb1c3c073769 Please use the documented way to write this: 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") > was missed one hunk. Added it now to avoid issue with use after free. And I do not understand this commit message at all. > > Signed-off-by: Dmitry Eremin > --- > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > index 2ebc484..a15a625 100644 > --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > @@ -890,7 +890,8 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) > atomic_dec(&net->ibn_nconns); > } > > - kfree(conn); > + if (free_conn) > + kfree(conn); This looks really odd, don't you think? thanks, greg k-h From dmitry.eremin at intel.com Tue Jan 16 18:02:07 2018 From: dmitry.eremin at intel.com (Eremin, Dmitry) Date: Tue, 16 Jan 2018 18:02:07 +0000 Subject: [lustre-devel] [PATCH] staging: lustre: Fix avoid intensive reconnecting for ko2iblnd patch In-Reply-To: <1516114161-27679-1-git-send-email-Dmitry.Eremin@intel.com> References: <1516114161-27679-1-git-send-email-Dmitry.Eremin@intel.com> Message-ID: <9FC73D3DBECE0941BD2ED069D26863425CE76069@irsmsx110.ger.corp.intel.com> The logic of the original commit 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") was assumed conditional free of struct kib_conn if the second argument free_conn in function kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) is true. But this hunk of code was dropped from original commit. As result the logic works wrong and current code use struct kib_conn after free. > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > 3317 kiblnd_destroy_conn(conn, !peer); > ^^^^ Freed always (but should be conditionally) > 3318 > 3319 spin_lock_irqsave(lock, flags); > 3320 if (!peer) > 3321 continue; > 3322 > 3323 conn->ibc_peer = peer; > ^^^^^^^^^^^^^ Use after free > 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) > 3325 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^ > 3326 &kiblnd_data.kib_reconn_list); > 3327 else > 3328 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^ > 3329 &kiblnd_data.kib_reconn_wait); After attached patch this code will use struct kib_conn only when it was not freed. Signed-off-by: Dmitry Eremin --- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 2ebc484..a15a625 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -890,7 +890,8 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) atomic_dec(&net->ibn_nconns); } - kfree(conn); + if (free_conn) + kfree(conn); } int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) -- 1.8.3.1 -------------------------------------------------------------------- Joint Stock Company Intel A/O Registered legal address: Krylatsky Hills Business Park, 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. From andreas.dilger at intel.com Wed Jan 17 00:36:19 2018 From: andreas.dilger at intel.com (Dilger, Andreas) Date: Wed, 17 Jan 2018 00:36:19 +0000 Subject: [lustre-devel] [PATCH] staging: lustre: Fix avoid intensive reconnecting for ko2iblnd patch In-Reply-To: <20180116165628.GB7066@kroah.com> References: <1516114161-27679-1-git-send-email-Dmitry.Eremin@intel.com> <9FC73D3DBECE0941BD2ED069D26863425CE75F26@irsmsx110.ger.corp.intel.com> <20180116165628.GB7066@kroah.com> Message-ID: <6D19AB36-CDDF-4743-AF46-ADF31E26B4F4@intel.com> > On Jan 16, 2018, at 09:56, Greg Kroah-Hartman wrote: > > On Tue, Jan 16, 2018 at 03:01:49PM +0000, Eremin, Dmitry wrote: >> In the original commit 4d99b2581effe115376402e710fbcb1c3c073769 > > Please use the documented way to write this: > 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") > >> was missed one hunk. Added it now to avoid issue with use after free. > > And I do not understand this commit message at all. > >> Signed-off-by: Dmitry Eremin >> --- >> drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c >> index 2ebc484..a15a625 100644 >> --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c >> +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c >> @@ -890,7 +890,8 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) >> atomic_dec(&net->ibn_nconns); >> } >> >> - kfree(conn); >> + if (free_conn) >> + kfree(conn); > > This looks really odd, don't you think? I'm not sure what the objection is here? There is an argument to this this function named "free_conn" which determines if the structure should be freed, or if the network connection is just being torn down and reconnected. Cheers, Andreas -- Andreas Dilger Lustre Principal Architect Intel Corporation From gregkh at linuxfoundation.org Wed Jan 17 14:02:16 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Wed, 17 Jan 2018 15:02:16 +0100 Subject: [lustre-devel] [PATCH] staging: lustre: Fix avoid intensive reconnecting for ko2iblnd patch In-Reply-To: <6D19AB36-CDDF-4743-AF46-ADF31E26B4F4@intel.com> References: <1516114161-27679-1-git-send-email-Dmitry.Eremin@intel.com> <9FC73D3DBECE0941BD2ED069D26863425CE75F26@irsmsx110.ger.corp.intel.com> <20180116165628.GB7066@kroah.com> <6D19AB36-CDDF-4743-AF46-ADF31E26B4F4@intel.com> Message-ID: <20180117140216.GA5449@kroah.com> On Wed, Jan 17, 2018 at 12:36:19AM +0000, Dilger, Andreas wrote: > > > On Jan 16, 2018, at 09:56, Greg Kroah-Hartman wrote: > > > > On Tue, Jan 16, 2018 at 03:01:49PM +0000, Eremin, Dmitry wrote: > >> In the original commit 4d99b2581effe115376402e710fbcb1c3c073769 > > > > Please use the documented way to write this: > > 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") > > > > >> was missed one hunk. Added it now to avoid issue with use after free. > > > > And I do not understand this commit message at all. > > > >> Signed-off-by: Dmitry Eremin > >> --- > >> drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 3 ++- > >> 1 file changed, 2 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > >> index 2ebc484..a15a625 100644 > >> --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > >> +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > >> @@ -890,7 +890,8 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) > >> atomic_dec(&net->ibn_nconns); > >> } > >> > >> - kfree(conn); > >> + if (free_conn) > >> + kfree(conn); > > > > This looks really odd, don't you think? > > I'm not sure what the objection is here? There is an argument to this > this function named "free_conn" which determines if the structure should > be freed, or if the network connection is just being torn down and > reconnected. At first glance it really looks like the normal pattern of: if (foo_ptr) kfree(foo_ptr); right? If you don't want to free the variable, set it to NULL. Even then, this is a horrible function, you should have 2 different ones: kiblnd_destroy_conn(...) kiblnd_free_conn() and then just free the variable in the free_conn() function if you were going to set the free_conn variable, right? That way no odd code paths are taken, and it's obvious what you are doing just by reading the code at the callsite. thanks, greg k-h From jsimmons at infradead.org Wed Jan 17 15:24:29 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:24:29 +0000 (GMT) Subject: [lustre-devel] [PATCH 5 v2: 00/19] staging: lustre: use standard wait_event macros In-Reply-To: <151538168618.23920.8261096424342988792.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> Message-ID: > Hi, > this is a revised version of the patch series I sent under a similar > subject in mid December. > Improvements are: > - new wait_event_idle* macros are now in include/linux/wait.h which > Ack from peterz. > - *all* waits are now TASK_IDLE or TASK_INTERRUPTIBLE and so don't > affect the load average. There is no need to choose whether load > is appropriate or not in each case. > - all l_wait_event() users are handled so l_wait_event() is > removed. The one case I had left out before uses > wait_event_idle_exclusive() with and option of using > wait_event_idle_exclusive_lifo() is that ever gets approved. > > I think this set is ready to go. > If you only review two patches, please review > > staging: lustre: simplify waiting in ldlm_completion_ast() > and > staging: lustre: remove back_to_sleep() > > as in both of those, the actual behaviour of the current code (as I > understand it) doesn't seem to agree with comments/debug message, or > just generally looks odd. I have been doing extenstive test with this patch set on my local test cluster and its looking good. So the reason for the original code is in times past under very heavy IO load the cpu loads would spike due to the work queues. I don't have a large enough test cluster to exercise that case. I trust it works even in those conditions and it can be fixed if its not the case. Thanks Neil for this work. > Thanks, > NeilBrown > > > --- > > NeilBrown (19): > sched/wait: add wait_event_idle() functions. > staging: lustre: discard SVC_SIGNAL and related functions > staging: lustre: replace simple cases of l_wait_event() with wait_event(). > staging: lustre: discard cfs_time_seconds() > staging: lustre: use wait_event_idle_timeout() where appropriate. > staging: lustre: introduce and use l_wait_event_abortable() > staging: lustre: simplify l_wait_event when intr handler but no timeout. > staging: lustre: simplify waiting in ldlm_completion_ast() > staging: lustre: open code polling loop instead of using l_wait_event() > staging: lustre: simplify waiting in ptlrpc_invalidate_import() > staging: lustre: remove back_to_sleep() > staging: lustre: make polling loop in ptlrpc_unregister_bulk more obvious > staging: lustre: use wait_event_idle_timeout in ptlrpcd() > staging: lustre: improve waiting in sptlrpc_req_refresh_ctx > staging: lustre: use explicit poll loop in ptlrpc_service_unlink_rqbd > staging: lustre: use explicit poll loop in ptlrpc_unregister_reply > staging: lustre: remove l_wait_event from ptlrpc_set_wait > staging: lustre: replace l_wait_event_exclusive_head() with wait_event_idle_exclusive > staging: lustre: remove l_wait_event() and related code > > > .../lustre/include/linux/libcfs/libcfs_debug.h | 4 > .../lustre/include/linux/libcfs/libcfs_time.h | 2 > .../lustre/include/linux/libcfs/linux/linux-time.h | 7 > .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 8 - > .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 4 > .../staging/lustre/lnet/klnds/socklnd/socklnd.c | 6 > .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 22 + > drivers/staging/lustre/lnet/libcfs/debug.c | 2 > drivers/staging/lustre/lnet/libcfs/fail.c | 2 > drivers/staging/lustre/lnet/libcfs/tracefile.c | 4 > drivers/staging/lustre/lnet/lnet/acceptor.c | 2 > drivers/staging/lustre/lnet/lnet/api-ni.c | 4 > drivers/staging/lustre/lnet/lnet/lib-move.c | 4 > drivers/staging/lustre/lnet/lnet/net_fault.c | 14 - > drivers/staging/lustre/lnet/lnet/peer.c | 2 > drivers/staging/lustre/lnet/lnet/router.c | 8 - > drivers/staging/lustre/lnet/selftest/conrpc.c | 4 > drivers/staging/lustre/lnet/selftest/rpc.c | 2 > drivers/staging/lustre/lnet/selftest/selftest.h | 2 > drivers/staging/lustre/lnet/selftest/timer.c | 2 > drivers/staging/lustre/lustre/include/lustre_dlm.h | 2 > drivers/staging/lustre/lustre/include/lustre_lib.h | 296 ++------------------ > drivers/staging/lustre/lustre/include/lustre_mdc.h | 2 > drivers/staging/lustre/lustre/include/lustre_net.h | 8 - > drivers/staging/lustre/lustre/ldlm/ldlm_flock.c | 30 -- > drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 14 - > drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 12 - > drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 17 - > drivers/staging/lustre/lustre/ldlm/ldlm_request.c | 55 +--- > drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 14 - > drivers/staging/lustre/lustre/llite/llite_lib.c | 23 +- > drivers/staging/lustre/lustre/llite/statahead.c | 60 ++-- > drivers/staging/lustre/lustre/lov/lov_object.c | 6 > drivers/staging/lustre/lustre/lov/lov_request.c | 12 - > drivers/staging/lustre/lustre/mdc/mdc_request.c | 5 > drivers/staging/lustre/lustre/mgc/mgc_request.c | 19 - > drivers/staging/lustre/lustre/obdclass/cl_io.c | 23 +- > drivers/staging/lustre/lustre/obdclass/genops.c | 24 +- > drivers/staging/lustre/lustre/obdclass/llog_obd.c | 5 > .../staging/lustre/lustre/obdecho/echo_client.c | 2 > drivers/staging/lustre/lustre/osc/osc_cache.c | 28 +- > drivers/staging/lustre/lustre/osc/osc_object.c | 6 > drivers/staging/lustre/lustre/osc/osc_page.c | 6 > drivers/staging/lustre/lustre/osc/osc_request.c | 6 > drivers/staging/lustre/lustre/ptlrpc/client.c | 101 +++---- > drivers/staging/lustre/lustre/ptlrpc/events.c | 7 > drivers/staging/lustre/lustre/ptlrpc/import.c | 51 +-- > drivers/staging/lustre/lustre/ptlrpc/niobuf.c | 15 + > .../staging/lustre/lustre/ptlrpc/pack_generic.c | 9 - > drivers/staging/lustre/lustre/ptlrpc/pinger.c | 28 +- > .../staging/lustre/lustre/ptlrpc/ptlrpc_internal.h | 2 > drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 18 + > drivers/staging/lustre/lustre/ptlrpc/recover.c | 12 - > drivers/staging/lustre/lustre/ptlrpc/sec.c | 34 ++ > drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 23 -- > drivers/staging/lustre/lustre/ptlrpc/service.c | 84 +++--- > include/linux/wait.h | 114 ++++++++ > 57 files changed, 516 insertions(+), 762 deletions(-) > > -- > Signature > > From jsimmons at infradead.org Wed Jan 17 15:26:15 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:26:15 +0000 (GMT) Subject: [lustre-devel] [PATCH 01/19] sched/wait: add wait_event_idle() functions. In-Reply-To: <151538209329.23920.16297706354917686170.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209329.23920.16297706354917686170.stgit@noble> Message-ID: > The new TASK_IDLE state (TASK_UNINTERRUPTIBLE | __TASK_NOLOAD) > is not much used. One way to make it easier to use is to > add wait_event*() family functions that make use of it. > This patch adds: > wait_event_idle() > wait_event_idle_timeout() > wait_event_idle_exclusive() > wait_event_idle_exclusive_timeout() > > This set was chosen because lustre needs them before > it can discard its own l_wait_event() macro. Reviewed-by: James Simmons > Acked-by: Peter Zijlstra (Intel) > Signed-off-by: NeilBrown > --- > include/linux/wait.h | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 114 insertions(+) > > diff --git a/include/linux/wait.h b/include/linux/wait.h > index 158715445ffb..ec7e7c65cee6 100644 > --- a/include/linux/wait.h > +++ b/include/linux/wait.h > @@ -597,6 +597,120 @@ do { \ > __ret; \ > }) > > +/** > + * wait_event_idle - wait for a condition without contributing to system load > + * @wq_head: the waitqueue to wait on > + * @condition: a C expression for the event to wait for > + * > + * The process is put to sleep (TASK_IDLE) until the > + * @condition evaluates to true. > + * The @condition is checked each time the waitqueue @wq_head is woken up. > + * > + * wake_up() has to be called after changing any variable that could > + * change the result of the wait condition. > + * > + */ > +#define wait_event_idle(wq_head, condition) \ > +do { \ > + might_sleep(); \ > + if (!(condition)) \ > + ___wait_event(wq_head, condition, TASK_IDLE, 0, 0, schedule()); \ > +} while (0) > + > +/** > + * wait_event_idle_exclusive - wait for a condition with contributing to system load > + * @wq_head: the waitqueue to wait on > + * @condition: a C expression for the event to wait for > + * > + * The process is put to sleep (TASK_IDLE) until the > + * @condition evaluates to true. > + * The @condition is checked each time the waitqueue @wq_head is woken up. > + * > + * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag > + * set thus if other processes wait on the same list, when this > + * process is woken further processes are not considered. > + * > + * wake_up() has to be called after changing any variable that could > + * change the result of the wait condition. > + * > + */ > +#define wait_event_idle_exclusive(wq_head, condition) \ > +do { \ > + might_sleep(); \ > + if (!(condition)) \ > + ___wait_event(wq_head, condition, TASK_IDLE, 1, 0, schedule()); \ > +} while (0) > + > +#define __wait_event_idle_timeout(wq_head, condition, timeout) \ > + ___wait_event(wq_head, ___wait_cond_timeout(condition), \ > + TASK_IDLE, 0, timeout, \ > + __ret = schedule_timeout(__ret)) > + > +/** > + * wait_event_idle_timeout - sleep without load until a condition becomes true or a timeout elapses > + * @wq_head: the waitqueue to wait on > + * @condition: a C expression for the event to wait for > + * @timeout: timeout, in jiffies > + * > + * The process is put to sleep (TASK_IDLE) until the > + * @condition evaluates to true. The @condition is checked each time > + * the waitqueue @wq_head is woken up. > + * > + * wake_up() has to be called after changing any variable that could > + * change the result of the wait condition. > + * > + * Returns: > + * 0 if the @condition evaluated to %false after the @timeout elapsed, > + * 1 if the @condition evaluated to %true after the @timeout elapsed, > + * or the remaining jiffies (at least 1) if the @condition evaluated > + * to %true before the @timeout elapsed. > + */ > +#define wait_event_idle_timeout(wq_head, condition, timeout) \ > +({ \ > + long __ret = timeout; \ > + might_sleep(); \ > + if (!___wait_cond_timeout(condition)) \ > + __ret = __wait_event_idle_timeout(wq_head, condition, timeout); \ > + __ret; \ > +}) > + > +#define __wait_event_idle_exclusive_timeout(wq_head, condition, timeout) \ > + ___wait_event(wq_head, ___wait_cond_timeout(condition), \ > + TASK_IDLE, 1, timeout, \ > + __ret = schedule_timeout(__ret)) > + > +/** > + * wait_event_idle_exclusive_timeout - sleep without load until a condition becomes true or a timeout elapses > + * @wq_head: the waitqueue to wait on > + * @condition: a C expression for the event to wait for > + * @timeout: timeout, in jiffies > + * > + * The process is put to sleep (TASK_IDLE) until the > + * @condition evaluates to true. The @condition is checked each time > + * the waitqueue @wq_head is woken up. > + * > + * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag > + * set thus if other processes wait on the same list, when this > + * process is woken further processes are not considered. > + * > + * wake_up() has to be called after changing any variable that could > + * change the result of the wait condition. > + * > + * Returns: > + * 0 if the @condition evaluated to %false after the @timeout elapsed, > + * 1 if the @condition evaluated to %true after the @timeout elapsed, > + * or the remaining jiffies (at least 1) if the @condition evaluated > + * to %true before the @timeout elapsed. > + */ > +#define wait_event_idle_exclusive_timeout(wq_head, condition, timeout) \ > +({ \ > + long __ret = timeout; \ > + might_sleep(); \ > + if (!___wait_cond_timeout(condition)) \ > + __ret = __wait_event_idle_exclusive_timeout(wq_head, condition, timeout);\ > + __ret; \ > +}) > + > extern int do_wait_intr(wait_queue_head_t *, wait_queue_entry_t *); > extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *); > > > > From jsimmons at infradead.org Wed Jan 17 15:26:48 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:26:48 +0000 (GMT) Subject: [lustre-devel] [PATCH 02/19] staging: lustre: discard SVC_SIGNAL and related functions In-Reply-To: <151538209333.23920.9948001896186855872.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209333.23920.9948001896186855872.stgit@noble> Message-ID: > This flag is never set, so remove checks and remove > the flag. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/include/lustre_net.h | 6 ------ > drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 4 +--- > 2 files changed, 1 insertion(+), 9 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h > index 3ff5de4770e8..4c665eca2467 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_net.h > +++ b/drivers/staging/lustre/lustre/include/lustre_net.h > @@ -1260,7 +1260,6 @@ enum { > SVC_STARTING = 1 << 2, > SVC_RUNNING = 1 << 3, > SVC_EVENT = 1 << 4, > - SVC_SIGNAL = 1 << 5, > }; > > #define PTLRPC_THR_NAME_LEN 32 > @@ -1333,11 +1332,6 @@ static inline int thread_is_event(struct ptlrpc_thread *thread) > return !!(thread->t_flags & SVC_EVENT); > } > > -static inline int thread_is_signal(struct ptlrpc_thread *thread) > -{ > - return !!(thread->t_flags & SVC_SIGNAL); > -} > - > static inline void thread_clear_flags(struct ptlrpc_thread *thread, __u32 flags) > { > thread->t_flags &= ~flags; > diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c > index 8d1e0edfcede..d85c8638c009 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c > @@ -153,7 +153,6 @@ static int sec_gc_main(void *arg) > while (1) { > struct ptlrpc_sec *sec; > > - thread_clear_flags(thread, SVC_SIGNAL); > sec_process_ctx_list(); > again: > /* go through sec list do gc. > @@ -184,8 +183,7 @@ static int sec_gc_main(void *arg) > lwi = LWI_TIMEOUT(msecs_to_jiffies(SEC_GC_INTERVAL * MSEC_PER_SEC), > NULL, NULL); > l_wait_event(thread->t_ctl_waitq, > - thread_is_stopping(thread) || > - thread_is_signal(thread), > + thread_is_stopping(thread), > &lwi); > > if (thread_test_and_clear_flags(thread, SVC_STOPPING)) > > > From jsimmons at infradead.org Wed Jan 17 15:27:18 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:27:18 +0000 (GMT) Subject: [lustre-devel] [PATCH 03/19] staging: lustre: replace simple cases of l_wait_event() with wait_event(). In-Reply-To: <151538209336.23920.11626260931049480889.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209336.23920.11626260931049480889.stgit@noble> Message-ID: > When the lwi arg is full of zeros, l_wait_event() behaves almost > identically to the standard wait_event_idle() interface, so use that > instead. > > l_wait_event() uses TASK_INTERRUPTIBLE, but blocks all signals. > wait_event_idle() uses the new TASK_IDLE and so avoids adding > to the load average without needing to block signals. > > In one case, wait_event_idle_exclusive() is needed. > > Also remove all l_wait_condition*() macros which were short-cuts > for setting lwi to {0}. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/include/lustre_lib.h | 19 -------- > drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 4 -- > drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 8 +-- > drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 5 +- > drivers/staging/lustre/lustre/llite/statahead.c | 50 ++++++++------------ > drivers/staging/lustre/lustre/lov/lov_object.c | 6 +- > drivers/staging/lustre/lustre/mgc/mgc_request.c | 4 -- > drivers/staging/lustre/lustre/obdclass/cl_io.c | 6 +- > drivers/staging/lustre/lustre/obdclass/genops.c | 15 ++---- > drivers/staging/lustre/lustre/osc/osc_cache.c | 5 +- > drivers/staging/lustre/lustre/osc/osc_object.c | 4 -- > drivers/staging/lustre/lustre/ptlrpc/pinger.c | 10 ++-- > drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 11 ++-- > drivers/staging/lustre/lustre/ptlrpc/service.c | 13 ++--- > 14 files changed, 53 insertions(+), 107 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h > index ca1dce15337e..7d950c53e962 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_lib.h > +++ b/drivers/staging/lustre/lustre/include/lustre_lib.h > @@ -333,24 +333,7 @@ do { \ > __ret; \ > }) > > -#define l_wait_condition(wq, condition) \ > -({ \ > - struct l_wait_info lwi = { 0 }; \ > - l_wait_event(wq, condition, &lwi); \ > -}) > - > -#define l_wait_condition_exclusive(wq, condition) \ > -({ \ > - struct l_wait_info lwi = { 0 }; \ > - l_wait_event_exclusive(wq, condition, &lwi); \ > -}) > - > -#define l_wait_condition_exclusive_head(wq, condition) \ > -({ \ > - struct l_wait_info lwi = { 0 }; \ > - l_wait_event_exclusive_head(wq, condition, &lwi); \ > -}) > - > /** @} lib */ > > + > #endif /* _LUSTRE_LIB_H */ > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > index 7cbc6a06afec..4f700ddb47c6 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > @@ -1913,14 +1913,12 @@ void ldlm_cancel_callback(struct ldlm_lock *lock) > ldlm_set_bl_done(lock); > wake_up_all(&lock->l_waitq); > } else if (!ldlm_is_bl_done(lock)) { > - struct l_wait_info lwi = { 0 }; > - > /* > * The lock is guaranteed to have been canceled once > * returning from this function. > */ > unlock_res_and_lock(lock); > - l_wait_event(lock->l_waitq, is_bl_done(lock), &lwi); > + wait_event_idle(lock->l_waitq, is_bl_done(lock)); > lock_res_and_lock(lock); > } > } > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c > index 5f6e7c933b81..6c7c4b19a0a0 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c > @@ -833,17 +833,15 @@ static int ldlm_bl_thread_main(void *arg) > /* cannot use bltd after this, it is only on caller's stack */ > > while (1) { > - struct l_wait_info lwi = { 0 }; > struct ldlm_bl_work_item *blwi = NULL; > struct obd_export *exp = NULL; > int rc; > > rc = ldlm_bl_get_work(blp, &blwi, &exp); > if (!rc) > - l_wait_event_exclusive(blp->blp_waitq, > - ldlm_bl_get_work(blp, &blwi, > - &exp), > - &lwi); > + wait_event_idle_exclusive(blp->blp_waitq, > + ldlm_bl_get_work(blp, &blwi, > + &exp)); > atomic_inc(&blp->blp_busy_threads); > > if (ldlm_bl_thread_need_create(blp, blwi)) > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > index 8563bd32befa..f27c2694793a 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > @@ -1031,7 +1031,6 @@ static int ldlm_pools_thread_main(void *arg) > > static int ldlm_pools_thread_start(void) > { > - struct l_wait_info lwi = { 0 }; > struct task_struct *task; > > if (ldlm_pools_thread) > @@ -1052,8 +1051,8 @@ static int ldlm_pools_thread_start(void) > ldlm_pools_thread = NULL; > return PTR_ERR(task); > } > - l_wait_event(ldlm_pools_thread->t_ctl_waitq, > - thread_is_running(ldlm_pools_thread), &lwi); > + wait_event_idle(ldlm_pools_thread->t_ctl_waitq, > + thread_is_running(ldlm_pools_thread)); > return 0; > } > > diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c > index 90c7324575e4..78005cc6e831 100644 > --- a/drivers/staging/lustre/lustre/llite/statahead.c > +++ b/drivers/staging/lustre/lustre/llite/statahead.c > @@ -864,7 +864,6 @@ static int ll_agl_thread(void *arg) > struct ll_sb_info *sbi = ll_i2sbi(dir); > struct ll_statahead_info *sai; > struct ptlrpc_thread *thread; > - struct l_wait_info lwi = { 0 }; > > sai = ll_sai_get(dir); > thread = &sai->sai_agl_thread; > @@ -885,10 +884,9 @@ static int ll_agl_thread(void *arg) > wake_up(&thread->t_ctl_waitq); > > while (1) { > - l_wait_event(thread->t_ctl_waitq, > - !list_empty(&sai->sai_agls) || > - !thread_is_running(thread), > - &lwi); > + wait_event_idle(thread->t_ctl_waitq, > + !list_empty(&sai->sai_agls) || > + !thread_is_running(thread)); > > if (!thread_is_running(thread)) > break; > @@ -932,7 +930,6 @@ static int ll_agl_thread(void *arg) > static void ll_start_agl(struct dentry *parent, struct ll_statahead_info *sai) > { > struct ptlrpc_thread *thread = &sai->sai_agl_thread; > - struct l_wait_info lwi = { 0 }; > struct ll_inode_info *plli; > struct task_struct *task; > > @@ -948,9 +945,8 @@ static void ll_start_agl(struct dentry *parent, struct ll_statahead_info *sai) > return; > } > > - l_wait_event(thread->t_ctl_waitq, > - thread_is_running(thread) || thread_is_stopped(thread), > - &lwi); > + wait_event_idle(thread->t_ctl_waitq, > + thread_is_running(thread) || thread_is_stopped(thread)); > } > > /* statahead thread main function */ > @@ -968,7 +964,6 @@ static int ll_statahead_thread(void *arg) > int first = 0; > int rc = 0; > struct md_op_data *op_data; > - struct l_wait_info lwi = { 0 }; > > sai = ll_sai_get(dir); > sa_thread = &sai->sai_thread; > @@ -1069,12 +1064,11 @@ static int ll_statahead_thread(void *arg) > > /* wait for spare statahead window */ > do { > - l_wait_event(sa_thread->t_ctl_waitq, > - !sa_sent_full(sai) || > - sa_has_callback(sai) || > - !list_empty(&sai->sai_agls) || > - !thread_is_running(sa_thread), > - &lwi); > + wait_event_idle(sa_thread->t_ctl_waitq, > + !sa_sent_full(sai) || > + sa_has_callback(sai) || > + !list_empty(&sai->sai_agls) || > + !thread_is_running(sa_thread)); > sa_handle_callback(sai); > > spin_lock(&lli->lli_agl_lock); > @@ -1128,11 +1122,10 @@ static int ll_statahead_thread(void *arg) > * for file release to stop me. > */ > while (thread_is_running(sa_thread)) { > - l_wait_event(sa_thread->t_ctl_waitq, > - sa_has_callback(sai) || > - !agl_list_empty(sai) || > - !thread_is_running(sa_thread), > - &lwi); > + wait_event_idle(sa_thread->t_ctl_waitq, > + sa_has_callback(sai) || > + !agl_list_empty(sai) || > + !thread_is_running(sa_thread)); > > sa_handle_callback(sai); > } > @@ -1145,9 +1138,8 @@ static int ll_statahead_thread(void *arg) > > CDEBUG(D_READA, "stop agl thread: sai %p pid %u\n", > sai, (unsigned int)agl_thread->t_pid); > - l_wait_event(agl_thread->t_ctl_waitq, > - thread_is_stopped(agl_thread), > - &lwi); > + wait_event_idle(agl_thread->t_ctl_waitq, > + thread_is_stopped(agl_thread)); > } else { > /* Set agl_thread flags anyway. */ > thread_set_flags(agl_thread, SVC_STOPPED); > @@ -1159,8 +1151,8 @@ static int ll_statahead_thread(void *arg) > */ > while (sai->sai_sent != sai->sai_replied) { > /* in case we're not woken up, timeout wait */ > - lwi = LWI_TIMEOUT(msecs_to_jiffies(MSEC_PER_SEC >> 3), > - NULL, NULL); > + struct l_wait_info lwi = LWI_TIMEOUT(msecs_to_jiffies(MSEC_PER_SEC >> 3), > + NULL, NULL); > l_wait_event(sa_thread->t_ctl_waitq, > sai->sai_sent == sai->sai_replied, &lwi); > } > @@ -1520,7 +1512,6 @@ static int start_statahead_thread(struct inode *dir, struct dentry *dentry) > { > struct ll_inode_info *lli = ll_i2info(dir); > struct ll_statahead_info *sai = NULL; > - struct l_wait_info lwi = { 0 }; > struct ptlrpc_thread *thread; > struct task_struct *task; > struct dentry *parent = dentry->d_parent; > @@ -1570,9 +1561,8 @@ static int start_statahead_thread(struct inode *dir, struct dentry *dentry) > goto out; > } > > - l_wait_event(thread->t_ctl_waitq, > - thread_is_running(thread) || thread_is_stopped(thread), > - &lwi); > + wait_event_idle(thread->t_ctl_waitq, > + thread_is_running(thread) || thread_is_stopped(thread)); > ll_sai_put(sai); > > /* > diff --git a/drivers/staging/lustre/lustre/lov/lov_object.c b/drivers/staging/lustre/lustre/lov/lov_object.c > index 897cf2cd4a24..86cd4f9fbd0c 100644 > --- a/drivers/staging/lustre/lustre/lov/lov_object.c > +++ b/drivers/staging/lustre/lustre/lov/lov_object.c > @@ -723,15 +723,13 @@ static void lov_conf_unlock(struct lov_object *lov) > > static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov) > { > - struct l_wait_info lwi = { 0 }; > - > while (atomic_read(&lov->lo_active_ios) > 0) { > CDEBUG(D_INODE, "file:" DFID " wait for active IO, now: %d.\n", > PFID(lu_object_fid(lov2lu(lov))), > atomic_read(&lov->lo_active_ios)); > > - l_wait_event(lov->lo_waitq, > - atomic_read(&lov->lo_active_ios) == 0, &lwi); > + wait_event_idle(lov->lo_waitq, > + atomic_read(&lov->lo_active_ios) == 0); > } > return 0; > } > diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c > index 79ff85feab64..b743aee62349 100644 > --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c > +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c > @@ -601,9 +601,7 @@ static int mgc_requeue_thread(void *data) > config_log_put(cld_prev); > > /* Wait a bit to see if anyone else needs a requeue */ > - lwi = (struct l_wait_info) { 0 }; > - l_wait_event(rq_waitq, rq_state & (RQ_NOW | RQ_STOP), > - &lwi); > + wait_event_idle(rq_waitq, rq_state & (RQ_NOW | RQ_STOP)); > spin_lock(&config_list_lock); > } > > diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c > index 6ec5218a18c1..902bad22013b 100644 > --- a/drivers/staging/lustre/lustre/obdclass/cl_io.c > +++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c > @@ -1110,10 +1110,8 @@ int cl_sync_io_wait(const struct lu_env *env, struct cl_sync_io *anchor, > CERROR("IO failed: %d, still wait for %d remaining entries\n", > rc, atomic_read(&anchor->csi_sync_nr)); > > - lwi = (struct l_wait_info) { 0 }; > - (void)l_wait_event(anchor->csi_waitq, > - atomic_read(&anchor->csi_sync_nr) == 0, > - &lwi); > + wait_event_idle(anchor->csi_waitq, > + atomic_read(&anchor->csi_sync_nr) == 0); > } else { > rc = anchor->csi_sync_rc; > } > diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c > index b1d6ba4a3190..3ff25b8d3b48 100644 > --- a/drivers/staging/lustre/lustre/obdclass/genops.c > +++ b/drivers/staging/lustre/lustre/obdclass/genops.c > @@ -1237,12 +1237,10 @@ static int obd_zombie_is_idle(void) > */ > void obd_zombie_barrier(void) > { > - struct l_wait_info lwi = { 0 }; > - > if (obd_zombie_pid == current_pid()) > /* don't wait for myself */ > return; > - l_wait_event(obd_zombie_waitq, obd_zombie_is_idle(), &lwi); > + wait_event_idle(obd_zombie_waitq, obd_zombie_is_idle()); > } > EXPORT_SYMBOL(obd_zombie_barrier); > > @@ -1257,10 +1255,8 @@ static int obd_zombie_impexp_thread(void *unused) > obd_zombie_pid = current_pid(); > > while (!test_bit(OBD_ZOMBIE_STOP, &obd_zombie_flags)) { > - struct l_wait_info lwi = { 0 }; > - > - l_wait_event(obd_zombie_waitq, > - !obd_zombie_impexp_check(NULL), &lwi); > + wait_event_idle(obd_zombie_waitq, > + !obd_zombie_impexp_check(NULL)); > obd_zombie_impexp_cull(); > > /* > @@ -1593,7 +1589,6 @@ static inline bool obd_mod_rpc_slot_avail(struct client_obd *cli, > u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc, > struct lookup_intent *it) > { > - struct l_wait_info lwi = LWI_INTR(NULL, NULL); > bool close_req = false; > u16 i, max; > > @@ -1631,8 +1626,8 @@ u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc, > CDEBUG(D_RPCTRACE, "%s: sleeping for a modify RPC slot opc %u, max %hu\n", > cli->cl_import->imp_obd->obd_name, opc, max); > > - l_wait_event(cli->cl_mod_rpcs_waitq, > - obd_mod_rpc_slot_avail(cli, close_req), &lwi); > + wait_event_idle(cli->cl_mod_rpcs_waitq, > + obd_mod_rpc_slot_avail(cli, close_req)); > } while (true); > } > EXPORT_SYMBOL(obd_get_mod_rpc_slot); > diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c > index 5767ac2a7d16..b8d5adca94e1 100644 > --- a/drivers/staging/lustre/lustre/osc/osc_cache.c > +++ b/drivers/staging/lustre/lustre/osc/osc_cache.c > @@ -964,9 +964,8 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext, > "%s: wait ext to %u timedout, recovery in progress?\n", > cli_name(osc_cli(obj)), state); > > - lwi = LWI_INTR(NULL, NULL); > - rc = l_wait_event(ext->oe_waitq, extent_wait_cb(ext, state), > - &lwi); > + wait_event_idle(ext->oe_waitq, extent_wait_cb(ext, state)); > + rc = 0; > } > if (rc == 0 && ext->oe_rc < 0) > rc = ext->oe_rc; > diff --git a/drivers/staging/lustre/lustre/osc/osc_object.c b/drivers/staging/lustre/lustre/osc/osc_object.c > index f82c87a77550..6c424f0290bb 100644 > --- a/drivers/staging/lustre/lustre/osc/osc_object.c > +++ b/drivers/staging/lustre/lustre/osc/osc_object.c > @@ -454,12 +454,10 @@ struct lu_object *osc_object_alloc(const struct lu_env *env, > > int osc_object_invalidate(const struct lu_env *env, struct osc_object *osc) > { > - struct l_wait_info lwi = { 0 }; > - > CDEBUG(D_INODE, "Invalidate osc object: %p, # of active IOs: %d\n", > osc, atomic_read(&osc->oo_nr_ios)); > > - l_wait_event(osc->oo_io_waitq, !atomic_read(&osc->oo_nr_ios), &lwi); > + wait_event_idle(osc->oo_io_waitq, !atomic_read(&osc->oo_nr_ios)); > > /* Discard all dirty pages of this object. */ > osc_cache_truncate_start(env, osc, 0, NULL); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c > index fe6b47bfe8be..af707cb2b62b 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c > @@ -291,7 +291,6 @@ static struct ptlrpc_thread pinger_thread; > > int ptlrpc_start_pinger(void) > { > - struct l_wait_info lwi = { 0 }; > struct task_struct *task; > int rc; > > @@ -310,8 +309,8 @@ int ptlrpc_start_pinger(void) > CERROR("cannot start pinger thread: rc = %d\n", rc); > return rc; > } > - l_wait_event(pinger_thread.t_ctl_waitq, > - thread_is_running(&pinger_thread), &lwi); > + wait_event_idle(pinger_thread.t_ctl_waitq, > + thread_is_running(&pinger_thread)); > > return 0; > } > @@ -320,7 +319,6 @@ static int ptlrpc_pinger_remove_timeouts(void); > > int ptlrpc_stop_pinger(void) > { > - struct l_wait_info lwi = { 0 }; > int rc = 0; > > if (thread_is_init(&pinger_thread) || > @@ -331,8 +329,8 @@ int ptlrpc_stop_pinger(void) > thread_set_flags(&pinger_thread, SVC_STOPPING); > wake_up(&pinger_thread.t_ctl_waitq); > > - l_wait_event(pinger_thread.t_ctl_waitq, > - thread_is_stopped(&pinger_thread), &lwi); > + wait_event_idle(pinger_thread.t_ctl_waitq, > + thread_is_stopped(&pinger_thread)); > > return rc; > } > diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c > index d85c8638c009..b61e1aa25e8c 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c > @@ -197,7 +197,6 @@ static int sec_gc_main(void *arg) > > int sptlrpc_gc_init(void) > { > - struct l_wait_info lwi = { 0 }; > struct task_struct *task; > > mutex_init(&sec_gc_mutex); > @@ -214,18 +213,16 @@ int sptlrpc_gc_init(void) > return PTR_ERR(task); > } > > - l_wait_event(sec_gc_thread.t_ctl_waitq, > - thread_is_running(&sec_gc_thread), &lwi); > + wait_event_idle(sec_gc_thread.t_ctl_waitq, > + thread_is_running(&sec_gc_thread)); > return 0; > } > > void sptlrpc_gc_fini(void) > { > - struct l_wait_info lwi = { 0 }; > - > thread_set_flags(&sec_gc_thread, SVC_STOPPING); > wake_up(&sec_gc_thread.t_ctl_waitq); > > - l_wait_event(sec_gc_thread.t_ctl_waitq, > - thread_is_stopped(&sec_gc_thread), &lwi); > + wait_event_idle(sec_gc_thread.t_ctl_waitq, > + thread_is_stopped(&sec_gc_thread)); > } > diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c > index 63be6e7273f3..1f22926c1355 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/service.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c > @@ -2233,7 +2233,7 @@ static int ptlrpc_hr_main(void *arg) > wake_up(&ptlrpc_hr.hr_waitq); > > while (!ptlrpc_hr.hr_stopping) { > - l_wait_condition(hrt->hrt_waitq, hrt_dont_sleep(hrt, &replies)); > + wait_event_idle(hrt->hrt_waitq, hrt_dont_sleep(hrt, &replies)); > > while (!list_empty(&replies)) { > struct ptlrpc_reply_state *rs; > @@ -2312,7 +2312,6 @@ static int ptlrpc_start_hr_threads(void) > > static void ptlrpc_svcpt_stop_threads(struct ptlrpc_service_part *svcpt) > { > - struct l_wait_info lwi = { 0 }; > struct ptlrpc_thread *thread; > LIST_HEAD(zombie); > > @@ -2341,8 +2340,8 @@ static void ptlrpc_svcpt_stop_threads(struct ptlrpc_service_part *svcpt) > > CDEBUG(D_INFO, "waiting for stopping-thread %s #%u\n", > svcpt->scp_service->srv_thread_name, thread->t_id); > - l_wait_event(thread->t_ctl_waitq, > - thread_is_stopped(thread), &lwi); > + wait_event_idle(thread->t_ctl_waitq, > + thread_is_stopped(thread)); > > spin_lock(&svcpt->scp_lock); > } > @@ -2403,7 +2402,6 @@ int ptlrpc_start_threads(struct ptlrpc_service *svc) > > int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait) > { > - struct l_wait_info lwi = { 0 }; > struct ptlrpc_thread *thread; > struct ptlrpc_service *svc; > struct task_struct *task; > @@ -2499,9 +2497,8 @@ int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait) > if (!wait) > return 0; > > - l_wait_event(thread->t_ctl_waitq, > - thread_is_running(thread) || thread_is_stopped(thread), > - &lwi); > + wait_event_idle(thread->t_ctl_waitq, > + thread_is_running(thread) || thread_is_stopped(thread)); > > rc = thread_is_stopped(thread) ? thread->t_id : 0; > return rc; > > > From jsimmons at infradead.org Wed Jan 17 15:27:55 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:27:55 +0000 (GMT) Subject: [lustre-devel] [PATCH 05/19] staging: lustre: use wait_event_idle_timeout() where appropriate. In-Reply-To: <151538209348.23920.11616107274431655046.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209348.23920.11616107274431655046.stgit@noble> Message-ID: > When the lwi arg has a timeout, but no timeout > callback function, l_wait_event() acts much the same as > wait_event_idle_timeout() - the wait is not interruptible and > simply waits for the event or the timeouts. > > The most noticable difference is that the return value is > -ETIMEDOUT or 0, rather than 0 or non-zero. > > Another difference is that if the timeout is zero, l_wait_event() > will not time out at all. In the one case where that is possible > we need to conditionally use wait_event_idle(). > > So replace all such calls with wait_event_idle_timeout(), being > careful of the return value. > > In one case, there is no event expected, only the timeout > is needed. So use schedule_timeout_uninterruptible(). > > Note that the presence or absence of LWI_ON_SIGNAL_NOOP > has no effect in these cases. It only has effect if the timeout > callback is non-NULL, or the timeout is zero, or > LWI_TIMEOUT_INTR_ALL() is used. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 10 ++------ > drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 12 +++------- > drivers/staging/lustre/lustre/llite/statahead.c | 14 ++++------- > drivers/staging/lustre/lustre/mdc/mdc_request.c | 5 +--- > drivers/staging/lustre/lustre/mgc/mgc_request.c | 15 +++++------- > drivers/staging/lustre/lustre/obdclass/cl_io.c | 17 ++++++++------ > drivers/staging/lustre/lustre/osc/osc_cache.c | 25 ++++++++++---------- > drivers/staging/lustre/lustre/ptlrpc/events.c | 7 +----- > drivers/staging/lustre/lustre/ptlrpc/import.c | 12 ++++------ > .../staging/lustre/lustre/ptlrpc/pack_generic.c | 9 +++---- > drivers/staging/lustre/lustre/ptlrpc/pinger.c | 12 +++------- > drivers/staging/lustre/lustre/ptlrpc/recover.c | 12 ++++------ > drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 10 ++------ > drivers/staging/lustre/lustre/ptlrpc/service.c | 11 ++++----- > 14 files changed, 68 insertions(+), 103 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > index 773abe78708a..95bea351d21d 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > @@ -1349,7 +1349,6 @@ enum ldlm_mode ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags, > if ((flags & LDLM_FL_LVB_READY) && !ldlm_is_lvb_ready(lock)) { > __u64 wait_flags = LDLM_FL_LVB_READY | > LDLM_FL_DESTROYED | LDLM_FL_FAIL_NOTIFIED; > - struct l_wait_info lwi; > > if (lock->l_completion_ast) { > int err = lock->l_completion_ast(lock, > @@ -1366,13 +1365,10 @@ enum ldlm_mode ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags, > } > } > > - lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, > - NULL, LWI_ON_SIGNAL_NOOP, NULL); > - > /* XXX FIXME see comment on CAN_MATCH in lustre_dlm.h */ > - l_wait_event(lock->l_waitq, > - lock->l_flags & wait_flags, > - &lwi); > + wait_event_idle_timeout(lock->l_waitq, > + lock->l_flags & wait_flags, > + obd_timeout * HZ); > if (!ldlm_is_lvb_ready(lock)) { > if (flags & LDLM_FL_TEST_LOCK) > LDLM_LOCK_RELEASE(lock); > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > index 622245a5f049..a0e486b57e08 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > @@ -997,8 +997,6 @@ static int ldlm_pools_thread_main(void *arg) > "ldlm_poold", current_pid()); > > while (1) { > - struct l_wait_info lwi; > - > /* > * Recal all pools on this tick. > */ > @@ -1008,12 +1006,10 @@ static int ldlm_pools_thread_main(void *arg) > * Wait until the next check time, or until we're > * stopped. > */ > - lwi = LWI_TIMEOUT(c_time * HZ, > - NULL, NULL); > - l_wait_event(thread->t_ctl_waitq, > - thread_is_stopping(thread) || > - thread_is_event(thread), > - &lwi); > + wait_event_idle_timeout(thread->t_ctl_waitq, > + thread_is_stopping(thread) || > + thread_is_event(thread), > + c_time * HZ); > > if (thread_test_and_clear_flags(thread, SVC_STOPPING)) > break; > diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c > index 96360f104b92..6052bfd7ff05 100644 > --- a/drivers/staging/lustre/lustre/llite/statahead.c > +++ b/drivers/staging/lustre/lustre/llite/statahead.c > @@ -1151,10 +1151,9 @@ static int ll_statahead_thread(void *arg) > */ > while (sai->sai_sent != sai->sai_replied) { > /* in case we're not woken up, timeout wait */ > - struct l_wait_info lwi = LWI_TIMEOUT(msecs_to_jiffies(MSEC_PER_SEC >> 3), > - NULL, NULL); > - l_wait_event(sa_thread->t_ctl_waitq, > - sai->sai_sent == sai->sai_replied, &lwi); > + wait_event_idle_timeout(sa_thread->t_ctl_waitq, > + sai->sai_sent == sai->sai_replied, > + HZ>>3); > } > > /* release resources held by statahead RPCs */ > @@ -1374,7 +1373,6 @@ static int revalidate_statahead_dentry(struct inode *dir, > { > struct ll_inode_info *lli = ll_i2info(dir); > struct sa_entry *entry = NULL; > - struct l_wait_info lwi = { 0 }; > struct ll_dentry_data *ldd; > int rc = 0; > > @@ -1424,10 +1422,8 @@ static int revalidate_statahead_dentry(struct inode *dir, > spin_lock(&lli->lli_sa_lock); > sai->sai_index_wait = entry->se_index; > spin_unlock(&lli->lli_sa_lock); > - lwi = LWI_TIMEOUT_INTR(30 * HZ, NULL, > - LWI_ON_SIGNAL_NOOP, NULL); > - rc = l_wait_event(sai->sai_waitq, sa_ready(entry), &lwi); > - if (rc < 0) { > + if (0 == wait_event_idle_timeout(sai->sai_waitq, > + sa_ready(entry), 30 * HZ)) { > /* > * entry may not be ready, so it may be used by inflight > * statahead RPC, don't free it. > diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c > index b12518ba5ae9..ab48746ce433 100644 > --- a/drivers/staging/lustre/lustre/mdc/mdc_request.c > +++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c > @@ -838,7 +838,6 @@ static int mdc_getpage(struct obd_export *exp, const struct lu_fid *fid, > struct ptlrpc_bulk_desc *desc; > struct ptlrpc_request *req; > wait_queue_head_t waitq; > - struct l_wait_info lwi; > int resends = 0; > int rc; > int i; > @@ -888,9 +887,7 @@ static int mdc_getpage(struct obd_export *exp, const struct lu_fid *fid, > exp->exp_obd->obd_name, -EIO); > return -EIO; > } > - lwi = LWI_TIMEOUT_INTR(resends * HZ, NULL, NULL, > - NULL); > - l_wait_event(waitq, 0, &lwi); > + wait_event_idle_timeout(waitq, 0, resends * HZ); > > goto restart_bulk; > } > diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c > index a01d13bde102..c61cd23a96df 100644 > --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c > +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c > @@ -535,7 +535,6 @@ static int mgc_requeue_thread(void *data) > spin_lock(&config_list_lock); > rq_state |= RQ_RUNNING; > while (!(rq_state & RQ_STOP)) { > - struct l_wait_info lwi; > struct config_llog_data *cld, *cld_prev; > int rand = prandom_u32_max(MGC_TIMEOUT_RAND_CENTISEC); > int to; > @@ -556,9 +555,9 @@ static int mgc_requeue_thread(void *data) > to = msecs_to_jiffies(MGC_TIMEOUT_MIN_SECONDS * MSEC_PER_SEC); > /* rand is centi-seconds */ > to += msecs_to_jiffies(rand * MSEC_PER_SEC / 100); > - lwi = LWI_TIMEOUT(to, NULL, NULL); > - l_wait_event(rq_waitq, rq_state & (RQ_STOP | RQ_PRECLEANUP), > - &lwi); > + wait_event_idle_timeout(rq_waitq, > + rq_state & (RQ_STOP | RQ_PRECLEANUP), > + to); > > /* > * iterate & processing through the list. for each cld, process > @@ -1628,9 +1627,7 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld) > > if (rcl == -ESHUTDOWN && > atomic_read(&mgc->u.cli.cl_mgc_refcount) > 0 && !retry) { > - int secs = obd_timeout * HZ; > struct obd_import *imp; > - struct l_wait_info lwi; > > mutex_unlock(&cld->cld_lock); > imp = class_exp2cliimp(mgc->u.cli.cl_mgc_mgsexp); > @@ -1645,9 +1642,9 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld) > */ > ptlrpc_pinger_force(imp); > > - lwi = LWI_TIMEOUT(secs, NULL, NULL); > - l_wait_event(imp->imp_recovery_waitq, > - !mgc_import_in_recovery(imp), &lwi); > + wait_event_idle_timeout(imp->imp_recovery_waitq, > + !mgc_import_in_recovery(imp), > + obd_timeout * HZ); > > if (imp->imp_state == LUSTRE_IMP_FULL) { > retry = true; > diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c > index ce5e7bdda692..ab84e011b560 100644 > --- a/drivers/staging/lustre/lustre/obdclass/cl_io.c > +++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c > @@ -1097,16 +1097,19 @@ EXPORT_SYMBOL(cl_sync_io_init); > int cl_sync_io_wait(const struct lu_env *env, struct cl_sync_io *anchor, > long timeout) > { > - struct l_wait_info lwi = LWI_TIMEOUT_INTR(timeout * HZ, > - NULL, NULL, NULL); > - int rc; > + int rc = 1; > > LASSERT(timeout >= 0); > > - rc = l_wait_event(anchor->csi_waitq, > - atomic_read(&anchor->csi_sync_nr) == 0, > - &lwi); > - if (rc < 0) { > + if (timeout == 0) > + wait_event_idle(anchor->csi_waitq, > + atomic_read(&anchor->csi_sync_nr) == 0); > + else > + rc = wait_event_idle_timeout(anchor->csi_waitq, > + atomic_read(&anchor->csi_sync_nr) == 0, > + timeout * HZ); > + if (rc == 0) { > + rc = -ETIMEDOUT; > CERROR("IO failed: %d, still wait for %d remaining entries\n", > rc, atomic_read(&anchor->csi_sync_nr)); > > diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c > index 0797e671f667..dacfab12c501 100644 > --- a/drivers/staging/lustre/lustre/osc/osc_cache.c > +++ b/drivers/staging/lustre/lustre/osc/osc_cache.c > @@ -934,8 +934,6 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext, > enum osc_extent_state state) > { > struct osc_object *obj = ext->oe_obj; > - struct l_wait_info lwi = LWI_TIMEOUT_INTR(600 * HZ, NULL, > - LWI_ON_SIGNAL_NOOP, NULL); > int rc = 0; > > osc_object_lock(obj); > @@ -958,17 +956,19 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext, > osc_extent_release(env, ext); > > /* wait for the extent until its state becomes @state */ > - rc = l_wait_event(ext->oe_waitq, extent_wait_cb(ext, state), &lwi); > - if (rc == -ETIMEDOUT) { > + rc = wait_event_idle_timeout(ext->oe_waitq, > + extent_wait_cb(ext, state), 600 * HZ); > + if (rc == 0) { > OSC_EXTENT_DUMP(D_ERROR, ext, > "%s: wait ext to %u timedout, recovery in progress?\n", > cli_name(osc_cli(obj)), state); > > wait_event_idle(ext->oe_waitq, extent_wait_cb(ext, state)); > - rc = 0; > } > - if (rc == 0 && ext->oe_rc < 0) > + if (ext->oe_rc < 0) > rc = ext->oe_rc; > + else > + rc = 0; > return rc; > } > > @@ -1568,12 +1568,9 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli, > struct osc_object *osc = oap->oap_obj; > struct lov_oinfo *loi = osc->oo_oinfo; > struct osc_cache_waiter ocw; > - struct l_wait_info lwi; > + unsigned long timeout = (AT_OFF ? obd_timeout : at_max) * HZ; > int rc = -EDQUOT; > > - lwi = LWI_TIMEOUT_INTR((AT_OFF ? obd_timeout : at_max) * HZ, > - NULL, LWI_ON_SIGNAL_NOOP, NULL); > - > OSC_DUMP_GRANT(D_CACHE, cli, "need:%d\n", bytes); > > spin_lock(&cli->cl_loi_list_lock); > @@ -1616,13 +1613,15 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli, > CDEBUG(D_CACHE, "%s: sleeping for cache space @ %p for %p\n", > cli_name(cli), &ocw, oap); > > - rc = l_wait_event(ocw.ocw_waitq, ocw_granted(cli, &ocw), &lwi); > + rc = wait_event_idle_timeout(ocw.ocw_waitq, > + ocw_granted(cli, &ocw), timeout); > > spin_lock(&cli->cl_loi_list_lock); > > - if (rc < 0) { > - /* l_wait_event is interrupted by signal, or timed out */ > + if (rc == 0) { > + /* wait_event is interrupted by signal, or timed out */ > list_del_init(&ocw.ocw_entry); > + rc = -ETIMEDOUT; > break; > } > LASSERT(list_empty(&ocw.ocw_entry)); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c > index 71f7588570ef..130bacc2c891 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/events.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/events.c > @@ -490,8 +490,6 @@ int ptlrpc_uuid_to_peer(struct obd_uuid *uuid, > > static void ptlrpc_ni_fini(void) > { > - wait_queue_head_t waitq; > - struct l_wait_info lwi; > int rc; > int retries; > > @@ -515,10 +513,7 @@ static void ptlrpc_ni_fini(void) > if (retries != 0) > CWARN("Event queue still busy\n"); > > - /* Wait for a bit */ > - init_waitqueue_head(&waitq); > - lwi = LWI_TIMEOUT(2 * HZ, NULL, NULL); > - l_wait_event(waitq, 0, &lwi); > + schedule_timeout_uninterruptible(2 * HZ); > break; > } > } > diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c > index 0eba5f18bd3b..ed210550f61f 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/import.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c > @@ -430,21 +430,19 @@ void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt) > > int ptlrpc_reconnect_import(struct obd_import *imp) > { > - struct l_wait_info lwi; > - int secs = obd_timeout * HZ; > int rc; > > ptlrpc_pinger_force(imp); > > CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n", > - obd2cli_tgt(imp->imp_obd), secs); > + obd2cli_tgt(imp->imp_obd), obd_timeout); > > - lwi = LWI_TIMEOUT(secs, NULL, NULL); > - rc = l_wait_event(imp->imp_recovery_waitq, > - !ptlrpc_import_in_recovery(imp), &lwi); > + rc = wait_event_idle_timeout(imp->imp_recovery_waitq, > + !ptlrpc_import_in_recovery(imp), > + obd_timeout * HZ); > CDEBUG(D_HA, "%s: recovery finished s:%s\n", obd2cli_tgt(imp->imp_obd), > ptlrpc_import_state_name(imp->imp_state)); > - return rc; > + return rc == 0 ? -ETIMEDOUT : 0; > } > EXPORT_SYMBOL(ptlrpc_reconnect_import); > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c > index c060d6f5015a..f73463ac401f 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c > @@ -260,17 +260,16 @@ lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt) > > /* See if we have anything in a pool, and wait if nothing */ > while (list_empty(&svcpt->scp_rep_idle)) { > - struct l_wait_info lwi; > int rc; > > spin_unlock(&svcpt->scp_rep_lock); > /* If we cannot get anything for some long time, we better > * bail out instead of waiting infinitely > */ > - lwi = LWI_TIMEOUT(10 * HZ, NULL, NULL); > - rc = l_wait_event(svcpt->scp_rep_waitq, > - !list_empty(&svcpt->scp_rep_idle), &lwi); > - if (rc != 0) > + rc = wait_event_idle_timeout(svcpt->scp_rep_waitq, > + !list_empty(&svcpt->scp_rep_idle), > + 10 * HZ); > + if (rc == 0) > goto out; > spin_lock(&svcpt->scp_rep_lock); > } > diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c > index 010a1cdf05fa..639070f6e68e 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c > @@ -228,7 +228,6 @@ static int ptlrpc_pinger_main(void *arg) > /* And now, loop forever, pinging as needed. */ > while (1) { > unsigned long this_ping = cfs_time_current(); > - struct l_wait_info lwi; > long time_to_next_wake; > struct timeout_item *item; > struct list_head *iter; > @@ -266,13 +265,10 @@ static int ptlrpc_pinger_main(void *arg) > cfs_time_add(this_ping, > PING_INTERVAL * HZ)); > if (time_to_next_wake > 0) { > - lwi = LWI_TIMEOUT(max_t(long, time_to_next_wake, > - HZ), > - NULL, NULL); > - l_wait_event(thread->t_ctl_waitq, > - thread_is_stopping(thread) || > - thread_is_event(thread), > - &lwi); > + wait_event_idle_timeout(thread->t_ctl_waitq, > + thread_is_stopping(thread) || > + thread_is_event(thread), > + max_t(long, time_to_next_wake, HZ)); > if (thread_test_and_clear_flags(thread, SVC_STOPPING)) > break; > /* woken after adding import to reset timer */ > diff --git a/drivers/staging/lustre/lustre/ptlrpc/recover.c b/drivers/staging/lustre/lustre/ptlrpc/recover.c > index 5bbd23eebfa6..7b5f2429d144 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/recover.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/recover.c > @@ -346,17 +346,15 @@ int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid, int async) > goto out; > > if (!async) { > - struct l_wait_info lwi; > - int secs = obd_timeout * HZ; > - > CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n", > - obd2cli_tgt(imp->imp_obd), secs); > + obd2cli_tgt(imp->imp_obd), obd_timeout); > > - lwi = LWI_TIMEOUT(secs, NULL, NULL); > - rc = l_wait_event(imp->imp_recovery_waitq, > - !ptlrpc_import_in_recovery(imp), &lwi); > + rc = wait_event_idle_timeout(imp->imp_recovery_waitq, > + !ptlrpc_import_in_recovery(imp), > + obd_timeout * HZ); > CDEBUG(D_HA, "%s: recovery finished\n", > obd2cli_tgt(imp->imp_obd)); > + rc = rc? 0 : -ETIMEDOUT; > } > > out: > diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c > index b61e1aa25e8c..48f1a72afd77 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c > @@ -142,7 +142,6 @@ static void sec_do_gc(struct ptlrpc_sec *sec) > static int sec_gc_main(void *arg) > { > struct ptlrpc_thread *thread = arg; > - struct l_wait_info lwi; > > unshare_fs_struct(); > > @@ -179,12 +178,9 @@ static int sec_gc_main(void *arg) > > /* check ctx list again before sleep */ > sec_process_ctx_list(); > - > - lwi = LWI_TIMEOUT(msecs_to_jiffies(SEC_GC_INTERVAL * MSEC_PER_SEC), > - NULL, NULL); > - l_wait_event(thread->t_ctl_waitq, > - thread_is_stopping(thread), > - &lwi); > + wait_event_idle_timeout(thread->t_ctl_waitq, > + thread_is_stopping(thread), > + SEC_GC_INTERVAL * HZ); > > if (thread_test_and_clear_flags(thread, SVC_STOPPING)) > break; > diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c > index 6d4229ebc9d9..5c41297d23d2 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/service.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c > @@ -2588,13 +2588,12 @@ static void ptlrpc_wait_replies(struct ptlrpc_service_part *svcpt) > { > while (1) { > int rc; > - struct l_wait_info lwi = LWI_TIMEOUT(10 * HZ, > - NULL, NULL); > > - rc = l_wait_event(svcpt->scp_waitq, > - atomic_read(&svcpt->scp_nreps_difficult) == 0, > - &lwi); > - if (rc == 0) > + rc = wait_event_idle_timeout( > + svcpt->scp_waitq, > + atomic_read(&svcpt->scp_nreps_difficult) == 0, > + 10 * HZ); > + if (rc > 0) > break; > CWARN("Unexpectedly long timeout %s %p\n", > svcpt->scp_service->srv_name, svcpt->scp_service); > > > From jsimmons at infradead.org Wed Jan 17 15:29:23 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:29:23 +0000 (GMT) Subject: [lustre-devel] [PATCH 04/19] staging: lustre: discard cfs_time_seconds() In-Reply-To: <151538209341.23920.8613572158448297057.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209341.23920.8613572158448297057.stgit@noble> Message-ID: > cfs_time_seconds() converts a number of seconds to the > matching number of jiffies. > The standard way to do this in Linux is "* HZ". > So discard cfs_time_seconds() and use "* HZ" instead. This doesn't collide as bad as I thought it did. Also it builds now that the lnet seltest changes landed. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > .../lustre/include/linux/libcfs/libcfs_debug.h | 4 ++-- > .../lustre/include/linux/libcfs/libcfs_time.h | 2 +- > .../lustre/include/linux/libcfs/linux/linux-time.h | 7 +----- > .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 8 ++++--- > .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 4 ++-- > .../staging/lustre/lnet/klnds/socklnd/socklnd.c | 6 +++-- > .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 22 ++++++++++---------- > drivers/staging/lustre/lnet/libcfs/debug.c | 2 +- > drivers/staging/lustre/lnet/libcfs/fail.c | 2 +- > drivers/staging/lustre/lnet/libcfs/tracefile.c | 4 ++-- > drivers/staging/lustre/lnet/lnet/acceptor.c | 2 +- > drivers/staging/lustre/lnet/lnet/api-ni.c | 4 ++-- > drivers/staging/lustre/lnet/lnet/lib-move.c | 4 ++-- > drivers/staging/lustre/lnet/lnet/net_fault.c | 14 +++++-------- > drivers/staging/lustre/lnet/lnet/peer.c | 2 +- > drivers/staging/lustre/lnet/lnet/router.c | 8 ++++--- > drivers/staging/lustre/lnet/selftest/conrpc.c | 4 ++-- > drivers/staging/lustre/lnet/selftest/rpc.c | 2 +- > drivers/staging/lustre/lnet/selftest/selftest.h | 2 +- > drivers/staging/lustre/lnet/selftest/timer.c | 2 +- > drivers/staging/lustre/lustre/include/lustre_dlm.h | 2 +- > drivers/staging/lustre/lustre/include/lustre_mdc.h | 2 +- > drivers/staging/lustre/lustre/include/lustre_net.h | 2 +- > drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 2 +- > drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 4 ++-- > drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 2 +- > drivers/staging/lustre/lustre/ldlm/ldlm_request.c | 2 +- > drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 2 +- > drivers/staging/lustre/lustre/llite/llite_lib.c | 4 ++-- > drivers/staging/lustre/lustre/llite/statahead.c | 2 +- > drivers/staging/lustre/lustre/lov/lov_request.c | 4 ++-- > drivers/staging/lustre/lustre/mdc/mdc_request.c | 2 +- > drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- > drivers/staging/lustre/lustre/obdclass/cl_io.c | 2 +- > .../staging/lustre/lustre/obdecho/echo_client.c | 2 +- > drivers/staging/lustre/lustre/osc/osc_cache.c | 4 ++-- > drivers/staging/lustre/lustre/osc/osc_object.c | 2 +- > drivers/staging/lustre/lustre/ptlrpc/client.c | 10 +++++---- > drivers/staging/lustre/lustre/ptlrpc/events.c | 2 +- > drivers/staging/lustre/lustre/ptlrpc/import.c | 15 ++++++-------- > drivers/staging/lustre/lustre/ptlrpc/niobuf.c | 4 ++-- > .../staging/lustre/lustre/ptlrpc/pack_generic.c | 2 +- > drivers/staging/lustre/lustre/ptlrpc/pinger.c | 8 ++++--- > drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 4 ++-- > drivers/staging/lustre/lustre/ptlrpc/recover.c | 2 +- > drivers/staging/lustre/lustre/ptlrpc/service.c | 8 ++++--- > 46 files changed, 96 insertions(+), 106 deletions(-) > > diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h > index 1b98f0953afb..9290a19429e7 100644 > --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h > +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h > @@ -66,8 +66,8 @@ extern unsigned int libcfs_panic_on_lbug; > # define DEBUG_SUBSYSTEM S_UNDEFINED > #endif > > -#define CDEBUG_DEFAULT_MAX_DELAY (cfs_time_seconds(600)) /* jiffies */ > -#define CDEBUG_DEFAULT_MIN_DELAY ((cfs_time_seconds(1) + 1) / 2) /* jiffies */ > +#define CDEBUG_DEFAULT_MAX_DELAY (600 * HZ) /* jiffies */ > +#define CDEBUG_DEFAULT_MIN_DELAY ((HZ + 1) / 2) /* jiffies */ > #define CDEBUG_DEFAULT_BACKOFF 2 > struct cfs_debug_limit_state { > unsigned long cdls_next; > diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h > index 9699646decb9..c4f25be78268 100644 > --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h > +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h > @@ -62,7 +62,7 @@ static inline int cfs_time_aftereq(unsigned long t1, unsigned long t2) > > static inline unsigned long cfs_time_shift(int seconds) > { > - return cfs_time_add(cfs_time_current(), cfs_time_seconds(seconds)); > + return cfs_time_add(cfs_time_current(), seconds * HZ); > } > > /* > diff --git a/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h b/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h > index aece13698eb4..805cb326af86 100644 > --- a/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h > +++ b/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h > @@ -65,11 +65,6 @@ static inline unsigned long cfs_time_current(void) > return jiffies; > } > > -static inline long cfs_time_seconds(int seconds) > -{ > - return ((long)seconds) * msecs_to_jiffies(MSEC_PER_SEC); > -} > - > static inline long cfs_duration_sec(long d) > { > return d / msecs_to_jiffies(MSEC_PER_SEC); > @@ -85,7 +80,7 @@ static inline u64 cfs_time_add_64(u64 t, u64 d) > static inline u64 cfs_time_shift_64(int seconds) > { > return cfs_time_add_64(cfs_time_current_64(), > - cfs_time_seconds(seconds)); > + seconds * HZ); > } > > static inline int cfs_time_before_64(u64 t1, u64 t2) > diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > index bb7b19473e3a..8a49f7730308 100644 > --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > @@ -1219,7 +1219,7 @@ static struct kib_hca_dev *kiblnd_current_hdev(struct kib_dev *dev) > CDEBUG(D_NET, "%s: Wait for failover\n", > dev->ibd_ifname); > set_current_state(TASK_INTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1) / 100); > + schedule_timeout(HZ / 100); > > read_lock_irqsave(&kiblnd_data.kib_global_lock, flags); > } > @@ -1930,7 +1930,7 @@ struct list_head *kiblnd_pool_alloc_node(struct kib_poolset *ps) > > set_current_state(TASK_INTERRUPTIBLE); > schedule_timeout(interval); > - if (interval < cfs_time_seconds(1)) > + if (interval < HZ) > interval *= 2; > > goto again; > @@ -2567,7 +2567,7 @@ static void kiblnd_base_shutdown(void) > "Waiting for %d threads to terminate\n", > atomic_read(&kiblnd_data.kib_nthreads)); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > } > > /* fall through */ > @@ -2618,7 +2618,7 @@ static void kiblnd_shutdown(struct lnet_ni *ni) > libcfs_nid2str(ni->ni_nid), > atomic_read(&net->ibn_npeers)); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > } > > kiblnd_net_fini_pools(net); > diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > index 9b3328c5d1e7..0b30c205e760 100644 > --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > @@ -3726,8 +3726,8 @@ kiblnd_failover_thread(void *arg) > add_wait_queue(&kiblnd_data.kib_failover_waitq, &wait); > write_unlock_irqrestore(glock, flags); > > - rc = schedule_timeout(long_sleep ? cfs_time_seconds(10) : > - cfs_time_seconds(1)); > + rc = schedule_timeout(long_sleep ? 10 * HZ : > + HZ); > remove_wait_queue(&kiblnd_data.kib_failover_waitq, &wait); > write_lock_irqsave(glock, flags); > > diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c > index 7dba949a95a7..6ab876d8c744 100644 > --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c > +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c > @@ -1677,7 +1677,7 @@ ksocknal_destroy_conn(struct ksock_conn *conn) > switch (conn->ksnc_rx_state) { > case SOCKNAL_RX_LNET_PAYLOAD: > last_rcv = conn->ksnc_rx_deadline - > - cfs_time_seconds(*ksocknal_tunables.ksnd_timeout); > + *ksocknal_tunables.ksnd_timeout * HZ; > CERROR("Completing partial receive from %s[%d], ip %pI4h:%d, with error, wanted: %zd, left: %d, last alive is %ld secs ago\n", > libcfs_id2str(conn->ksnc_peer->ksnp_id), conn->ksnc_type, > &conn->ksnc_ipaddr, conn->ksnc_port, > @@ -2361,7 +2361,7 @@ ksocknal_base_shutdown(void) > ksocknal_data.ksnd_nthreads); > read_unlock(&ksocknal_data.ksnd_global_lock); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > read_lock(&ksocknal_data.ksnd_global_lock); > } > read_unlock(&ksocknal_data.ksnd_global_lock); > @@ -2604,7 +2604,7 @@ ksocknal_shutdown(struct lnet_ni *ni) > "waiting for %d peers to disconnect\n", > net->ksnn_npeers); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > > ksocknal_debug_peerhash(ni); > > diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c > index 11fd3a36424f..63e452f666bf 100644 > --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c > +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c > @@ -189,7 +189,7 @@ ksocknal_transmit(struct ksock_conn *conn, struct ksock_tx *tx) > > if (ksocknal_data.ksnd_stall_tx) { > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(ksocknal_data.ksnd_stall_tx)); > + schedule_timeout(ksocknal_data.ksnd_stall_tx * HZ); > } > > LASSERT(tx->tx_resid); > @@ -294,7 +294,7 @@ ksocknal_receive(struct ksock_conn *conn) > > if (ksocknal_data.ksnd_stall_rx) { > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(ksocknal_data.ksnd_stall_rx)); > + schedule_timeout(ksocknal_data.ksnd_stall_rx * HZ); > } > > rc = ksocknal_connsock_addref(conn); > @@ -1780,7 +1780,7 @@ ksocknal_connect(struct ksock_route *route) > int rc = 0; > > deadline = cfs_time_add(cfs_time_current(), > - cfs_time_seconds(*ksocknal_tunables.ksnd_timeout)); > + *ksocknal_tunables.ksnd_timeout * HZ); > > write_lock_bh(&ksocknal_data.ksnd_global_lock); > > @@ -1878,7 +1878,7 @@ ksocknal_connect(struct ksock_route *route) > * so min_reconnectms should be good heuristic > */ > route->ksnr_retry_interval = > - cfs_time_seconds(*ksocknal_tunables.ksnd_min_reconnectms) / 1000; > + *ksocknal_tunables.ksnd_min_reconnectms * HZ / 1000; > route->ksnr_timeout = cfs_time_add(cfs_time_current(), > route->ksnr_retry_interval); > } > @@ -1899,10 +1899,10 @@ ksocknal_connect(struct ksock_route *route) > route->ksnr_retry_interval *= 2; > route->ksnr_retry_interval = > max(route->ksnr_retry_interval, > - cfs_time_seconds(*ksocknal_tunables.ksnd_min_reconnectms) / 1000); > + (long)*ksocknal_tunables.ksnd_min_reconnectms * HZ / 1000); > route->ksnr_retry_interval = > min(route->ksnr_retry_interval, > - cfs_time_seconds(*ksocknal_tunables.ksnd_max_reconnectms) / 1000); > + (long)*ksocknal_tunables.ksnd_max_reconnectms * HZ / 1000); > > LASSERT(route->ksnr_retry_interval); > route->ksnr_timeout = cfs_time_add(cfs_time_current(), > @@ -1972,7 +1972,7 @@ ksocknal_connd_check_start(time64_t sec, long *timeout) > > if (sec - ksocknal_data.ksnd_connd_failed_stamp <= 1) { > /* may run out of resource, retry later */ > - *timeout = cfs_time_seconds(1); > + *timeout = HZ; > return 0; > } > > @@ -2031,8 +2031,8 @@ ksocknal_connd_check_stop(time64_t sec, long *timeout) > val = (int)(ksocknal_data.ksnd_connd_starting_stamp + > SOCKNAL_CONND_TIMEOUT - sec); > > - *timeout = (val > 0) ? cfs_time_seconds(val) : > - cfs_time_seconds(SOCKNAL_CONND_TIMEOUT); > + *timeout = (val > 0) ? val * HZ : > + SOCKNAL_CONND_TIMEOUT * HZ; > if (val > 0) > return 0; > > @@ -2307,7 +2307,7 @@ ksocknal_send_keepalive_locked(struct ksock_peer *peer) > if (*ksocknal_tunables.ksnd_keepalive <= 0 || > time_before(cfs_time_current(), > cfs_time_add(peer->ksnp_last_alive, > - cfs_time_seconds(*ksocknal_tunables.ksnd_keepalive)))) > + *ksocknal_tunables.ksnd_keepalive * HZ))) > return 0; > > if (time_before(cfs_time_current(), peer->ksnp_send_keepalive)) > @@ -2563,7 +2563,7 @@ ksocknal_reaper(void *arg) > ksocknal_data.ksnd_peer_hash_size; > } > > - deadline = cfs_time_add(deadline, cfs_time_seconds(p)); > + deadline = cfs_time_add(deadline, p * HZ); > } > > if (nenomem_conns) { > diff --git a/drivers/staging/lustre/lnet/libcfs/debug.c b/drivers/staging/lustre/lnet/libcfs/debug.c > index 551c45bf4108..c70d2ae29b11 100644 > --- a/drivers/staging/lustre/lnet/libcfs/debug.c > +++ b/drivers/staging/lustre/lnet/libcfs/debug.c > @@ -113,7 +113,7 @@ static int param_set_delay_minmax(const char *val, > if (rc) > return -EINVAL; > > - d = cfs_time_seconds(sec) / 100; > + d = sec * HZ / 100; > if (d < min || d > max) > return -EINVAL; > > diff --git a/drivers/staging/lustre/lnet/libcfs/fail.c b/drivers/staging/lustre/lnet/libcfs/fail.c > index 39439b303d65..d3f1e866c6a7 100644 > --- a/drivers/staging/lustre/lnet/libcfs/fail.c > +++ b/drivers/staging/lustre/lnet/libcfs/fail.c > @@ -134,7 +134,7 @@ int __cfs_fail_timeout_set(u32 id, u32 value, int ms, int set) > CERROR("cfs_fail_timeout id %x sleeping for %dms\n", > id, ms); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(ms) / 1000); > + schedule_timeout(ms * HZ / 1000); > CERROR("cfs_fail_timeout id %x awake\n", id); > } > return ret; > diff --git a/drivers/staging/lustre/lnet/libcfs/tracefile.c b/drivers/staging/lustre/lnet/libcfs/tracefile.c > index da2844f37edf..8c33c8fa66e2 100644 > --- a/drivers/staging/lustre/lnet/libcfs/tracefile.c > +++ b/drivers/staging/lustre/lnet/libcfs/tracefile.c > @@ -441,7 +441,7 @@ int libcfs_debug_vmsg2(struct libcfs_debug_msg_data *msgdata, > > if (cfs_time_after(cfs_time_current(), > cdls->cdls_next + libcfs_console_max_delay + > - cfs_time_seconds(10))) { > + 10 * HZ)) { > /* last timeout was a long time ago */ > cdls->cdls_delay /= libcfs_console_backoff * 4; > } else { > @@ -1071,7 +1071,7 @@ static int tracefiled(void *arg) > init_waitqueue_entry(&__wait, current); > add_wait_queue(&tctl->tctl_waitq, &__wait); > set_current_state(TASK_INTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > remove_wait_queue(&tctl->tctl_waitq, &__wait); > } > complete(&tctl->tctl_stop); > diff --git a/drivers/staging/lustre/lnet/lnet/acceptor.c b/drivers/staging/lustre/lnet/lnet/acceptor.c > index ee85cab6f437..6c1f4941d4ba 100644 > --- a/drivers/staging/lustre/lnet/lnet/acceptor.c > +++ b/drivers/staging/lustre/lnet/lnet/acceptor.c > @@ -365,7 +365,7 @@ lnet_acceptor(void *arg) > if (rc != -EAGAIN) { > CWARN("Accept error %d: pausing...\n", rc); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > } > continue; > } > diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c > index 6a1fb0397604..ddd37eae63c6 100644 > --- a/drivers/staging/lustre/lnet/lnet/api-ni.c > +++ b/drivers/staging/lustre/lnet/lnet/api-ni.c > @@ -973,7 +973,7 @@ lnet_ping_md_unlink(struct lnet_ping_info *pinfo, > while (pinfo->pi_features != LNET_PING_FEAT_INVAL) { > CDEBUG(D_NET, "Still waiting for ping MD to unlink\n"); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > } > > cfs_restore_sigs(blocked); > @@ -1112,7 +1112,7 @@ lnet_clear_zombies_nis_locked(void) > libcfs_nid2str(ni->ni_nid)); > } > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > lnet_net_lock(LNET_LOCK_EX); > continue; > } > diff --git a/drivers/staging/lustre/lnet/lnet/lib-move.c b/drivers/staging/lustre/lnet/lnet/lib-move.c > index d724c4c73ecc..7fe7ae917273 100644 > --- a/drivers/staging/lustre/lnet/lnet/lib-move.c > +++ b/drivers/staging/lustre/lnet/lnet/lib-move.c > @@ -524,7 +524,7 @@ lnet_peer_is_alive(struct lnet_peer *lp, unsigned long now) > return 0; > > deadline = cfs_time_add(lp->lp_last_alive, > - cfs_time_seconds(lp->lp_ni->ni_peertimeout)); > + lp->lp_ni->ni_peertimeout * HZ); > alive = cfs_time_after(deadline, now); > > /* Update obsolete lp_alive except for routers assumed to be dead > @@ -562,7 +562,7 @@ lnet_peer_alive_locked(struct lnet_peer *lp) > > unsigned long next_query = > cfs_time_add(lp->lp_last_query, > - cfs_time_seconds(lnet_queryinterval)); > + lnet_queryinterval * HZ); > > if (time_before(now, next_query)) { > if (lp->lp_alive) > diff --git a/drivers/staging/lustre/lnet/lnet/net_fault.c b/drivers/staging/lustre/lnet/lnet/net_fault.c > index e3468cef273b..a63b7941d435 100644 > --- a/drivers/staging/lustre/lnet/lnet/net_fault.c > +++ b/drivers/staging/lustre/lnet/lnet/net_fault.c > @@ -315,9 +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( > - prandom_u32_max(attr->u.drop.da_interval)); > - rule->dr_time_base += cfs_time_seconds(attr->u.drop.da_interval); > + prandom_u32_max(attr->u.drop.da_interval) * HZ; > + rule->dr_time_base += attr->u.drop.da_interval * HZ; > > CDEBUG(D_NET, "Drop Rule %s->%s: next drop : %lu\n", > libcfs_nid2str(attr->fa_src), > @@ -440,8 +439,7 @@ static struct delay_daemon_data delay_dd; > static unsigned long > round_timeout(unsigned long timeout) > { > - return cfs_time_seconds((unsigned int) > - cfs_duration_sec(cfs_time_sub(timeout, 0)) + 1); > + return (unsigned int)rounddown(timeout, HZ) + HZ; > } > > static void > @@ -483,10 +481,8 @@ 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( > - prandom_u32_max( > - attr->u.delay.la_interval)); > - rule->dl_time_base += cfs_time_seconds(attr->u.delay.la_interval); > + prandom_u32_max(attr->u.delay.la_interval) * HZ; > + rule->dl_time_base += attr->u.delay.la_interval * HZ; > > CDEBUG(D_NET, "Delay Rule %s->%s: next delay : %lu\n", > libcfs_nid2str(attr->fa_src), > diff --git a/drivers/staging/lustre/lnet/lnet/peer.c b/drivers/staging/lustre/lnet/lnet/peer.c > index 19fcbcf0f642..89610f768b4f 100644 > --- a/drivers/staging/lustre/lnet/lnet/peer.c > +++ b/drivers/staging/lustre/lnet/lnet/peer.c > @@ -137,7 +137,7 @@ lnet_peer_table_deathrow_wait_locked(struct lnet_peer_table *ptable, > ptable->pt_zombies); > } > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1) >> 1); > + schedule_timeout(HZ >> 1); > lnet_net_lock(cpt_locked); > } > } > diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c > index 476d6d296037..47a98d50ebc7 100644 > --- a/drivers/staging/lustre/lnet/lnet/router.c > +++ b/drivers/staging/lustre/lnet/lnet/router.c > @@ -808,7 +808,7 @@ lnet_wait_known_routerstate(void) > return; > > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > } > } > > @@ -1011,7 +1011,7 @@ lnet_ping_router_locked(struct lnet_peer *rtr) > > if (secs && !rtr->lp_ping_notsent && > cfs_time_after(now, cfs_time_add(rtr->lp_ping_timestamp, > - cfs_time_seconds(secs)))) { > + secs * HZ))) { > int rc; > struct lnet_process_id id; > struct lnet_handle_md mdh; > @@ -1185,7 +1185,7 @@ lnet_prune_rc_data(int wait_unlink) > CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET, > "Waiting for rc buffers to unlink\n"); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1) / 4); > + schedule_timeout(HZ / 4); > > lnet_net_lock(LNET_LOCK_EX); > } > @@ -1282,7 +1282,7 @@ lnet_router_checker(void *arg) > else > wait_event_interruptible_timeout(the_lnet.ln_rc_waitq, > false, > - cfs_time_seconds(1)); > + HZ); > } > > lnet_prune_rc_data(1); /* wait for UNLINK */ > diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c > index 7aa515c34594..6dcc966b293b 100644 > --- a/drivers/staging/lustre/lnet/selftest/conrpc.c > +++ b/drivers/staging/lustre/lnet/selftest/conrpc.c > @@ -359,7 +359,7 @@ lstcon_rpc_trans_postwait(struct lstcon_rpc_trans *trans, int timeout) > > rc = wait_event_interruptible_timeout(trans->tas_waitq, > lstcon_rpc_trans_check(trans), > - cfs_time_seconds(timeout)); > + timeout * HZ); > rc = (rc > 0) ? 0 : ((rc < 0) ? -EINTR : -ETIMEDOUT); > > mutex_lock(&console_session.ses_mutex); > @@ -1350,7 +1350,7 @@ lstcon_rpc_cleanup_wait(void) > > CWARN("Session is shutting down, waiting for termination of transactions\n"); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > > mutex_lock(&console_session.ses_mutex); > } > diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c > index b515138dca2c..18e0f1b87fc1 100644 > --- a/drivers/staging/lustre/lnet/selftest/rpc.c > +++ b/drivers/staging/lustre/lnet/selftest/rpc.c > @@ -1605,7 +1605,7 @@ srpc_startup(void) > > /* 1 second pause to avoid timestamp reuse */ > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > srpc_data.rpc_matchbits = ((__u64)ktime_get_real_seconds()) << 48; > > srpc_data.rpc_state = SRPC_STATE_NONE; > diff --git a/drivers/staging/lustre/lnet/selftest/selftest.h b/drivers/staging/lustre/lnet/selftest/selftest.h > index ad04534f000c..05466b85e1c0 100644 > --- a/drivers/staging/lustre/lnet/selftest/selftest.h > +++ b/drivers/staging/lustre/lnet/selftest/selftest.h > @@ -575,7 +575,7 @@ swi_state2str(int state) > #define selftest_wait_events() \ > do { \ > set_current_state(TASK_UNINTERRUPTIBLE); \ > - schedule_timeout(cfs_time_seconds(1) / 10); \ > + schedule_timeout(HZ / 10); \ > } while (0) > > #define lst_wait_until(cond, lock, fmt, ...) \ > diff --git a/drivers/staging/lustre/lnet/selftest/timer.c b/drivers/staging/lustre/lnet/selftest/timer.c > index ab125a8524c5..9716afeb3c94 100644 > --- a/drivers/staging/lustre/lnet/selftest/timer.c > +++ b/drivers/staging/lustre/lnet/selftest/timer.c > @@ -177,7 +177,7 @@ stt_timer_main(void *arg) > > rc = wait_event_timeout(stt_data.stt_waitq, > stt_data.stt_shuttingdown, > - cfs_time_seconds(STTIMER_SLOTTIME)); > + STTIMER_SLOTTIME * HZ); > } > > spin_lock(&stt_data.stt_lock); > diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h > index e0b17052b2ea..239aa2b1268f 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h > +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h > @@ -60,7 +60,7 @@ struct obd_device; > #define OBD_LDLM_DEVICENAME "ldlm" > > #define LDLM_DEFAULT_LRU_SIZE (100 * num_online_cpus()) > -#define LDLM_DEFAULT_MAX_ALIVE (cfs_time_seconds(3900)) /* 65 min */ > +#define LDLM_DEFAULT_MAX_ALIVE (65 * 60 * HZ) /* 65 min */ > #define LDLM_DEFAULT_PARALLEL_AST_LIMIT 1024 > > /** > diff --git a/drivers/staging/lustre/lustre/include/lustre_mdc.h b/drivers/staging/lustre/lustre/include/lustre_mdc.h > index 007e1ec3f0f4..a9c9992a2502 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_mdc.h > +++ b/drivers/staging/lustre/lustre/include/lustre_mdc.h > @@ -124,7 +124,7 @@ static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck, > */ > while (unlikely(lck->rpcl_it == MDC_FAKE_RPCL_IT)) { > mutex_unlock(&lck->rpcl_mutex); > - schedule_timeout(cfs_time_seconds(1) / 4); > + schedule_timeout(HZ / 4); > goto again; > } > > diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h > index 4c665eca2467..5a4434e7c85a 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_net.h > +++ b/drivers/staging/lustre/lustre/include/lustre_net.h > @@ -2262,7 +2262,7 @@ static inline int ptlrpc_send_limit_expired(struct ptlrpc_request *req) > { > if (req->rq_delay_limit != 0 && > time_before(cfs_time_add(req->rq_queued_time, > - cfs_time_seconds(req->rq_delay_limit)), > + req->rq_delay_limit * HZ), > cfs_time_current())) { > return 1; > } > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > index 4f700ddb47c6..773abe78708a 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c > @@ -1366,7 +1366,7 @@ enum ldlm_mode ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags, > } > } > > - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(obd_timeout), > + lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, > NULL, LWI_ON_SIGNAL_NOOP, NULL); > > /* XXX FIXME see comment on CAN_MATCH in lustre_dlm.h */ > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c > index 6c7c4b19a0a0..58913e628124 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c > @@ -163,7 +163,7 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req, > LDLM_DEBUG(lock, "client completion callback handler START"); > > if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE)) { > - int to = cfs_time_seconds(1); > + int to = HZ; > > while (to > 0) { > set_current_state(TASK_INTERRUPTIBLE); > @@ -327,7 +327,7 @@ static void ldlm_handle_gl_callback(struct ptlrpc_request *req, > !lock->l_readers && !lock->l_writers && > cfs_time_after(cfs_time_current(), > cfs_time_add(lock->l_last_used, > - cfs_time_seconds(10)))) { > + 10 * HZ))) { > unlock_res_and_lock(lock); > if (ldlm_bl_to_thread_lock(ns, NULL, lock)) > ldlm_handle_bl_callback(ns, NULL, lock); > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > index f27c2694793a..622245a5f049 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c > @@ -1008,7 +1008,7 @@ static int ldlm_pools_thread_main(void *arg) > * Wait until the next check time, or until we're > * stopped. > */ > - lwi = LWI_TIMEOUT(cfs_time_seconds(c_time), > + lwi = LWI_TIMEOUT(c_time * HZ, > NULL, NULL); > l_wait_event(thread->t_ctl_waitq, > thread_is_stopping(thread) || > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c > index 6aa37463db46..a244fa717134 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c > @@ -288,7 +288,7 @@ int ldlm_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) > LDLM_DEBUG(lock, "waiting indefinitely because of NO_TIMEOUT"); > lwi = LWI_INTR(interrupted_completion_wait, &lwd); > } else { > - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(timeout), > + lwi = LWI_TIMEOUT_INTR(timeout * HZ, > ldlm_expired_completion_wait, > interrupted_completion_wait, &lwd); > } > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c > index 9958533cc227..2e66825c8f4b 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c > @@ -799,7 +799,7 @@ static void cleanup_resource(struct ldlm_resource *res, struct list_head *q, > LDLM_DEBUG(lock, "setting FL_LOCAL_ONLY"); > if (lock->l_flags & LDLM_FL_FAIL_LOC) { > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(4)); > + schedule_timeout(4 * HZ); > set_current_state(TASK_RUNNING); > } > if (lock->l_completion_ast) > diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c > index 6735a6f006d2..0a9183f271f5 100644 > --- a/drivers/staging/lustre/lustre/llite/llite_lib.c > +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c > @@ -2026,8 +2026,8 @@ void ll_umount_begin(struct super_block *sb) > * to decrement mnt_cnt and hope to finish it within 10sec. > */ > init_waitqueue_head(&waitq); > - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(10), > - cfs_time_seconds(1), NULL, NULL); > + lwi = LWI_TIMEOUT_INTERVAL(10 * HZ, > + HZ, NULL, NULL); > l_wait_event(waitq, may_umount(sbi->ll_mnt.mnt), &lwi); > > schedule(); > diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c > index 78005cc6e831..96360f104b92 100644 > --- a/drivers/staging/lustre/lustre/llite/statahead.c > +++ b/drivers/staging/lustre/lustre/llite/statahead.c > @@ -1424,7 +1424,7 @@ static int revalidate_statahead_dentry(struct inode *dir, > spin_lock(&lli->lli_sa_lock); > sai->sai_index_wait = entry->se_index; > spin_unlock(&lli->lli_sa_lock); > - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(30), NULL, > + lwi = LWI_TIMEOUT_INTR(30 * HZ, NULL, > LWI_ON_SIGNAL_NOOP, NULL); > rc = l_wait_event(sai->sai_waitq, sa_ready(entry), &lwi); > if (rc < 0) { > diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c > index cfa1d7f92b0f..fb3b7a7fa32a 100644 > --- a/drivers/staging/lustre/lustre/lov/lov_request.c > +++ b/drivers/staging/lustre/lustre/lov/lov_request.c > @@ -126,8 +126,8 @@ static int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx) > mutex_unlock(&lov->lov_lock); > > init_waitqueue_head(&waitq); > - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(obd_timeout), > - cfs_time_seconds(1), NULL, NULL); > + lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ, > + HZ, NULL, NULL); > > rc = l_wait_event(waitq, lov_check_set(lov, ost_idx), &lwi); > if (tgt->ltd_active) > diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c > index 03e55bca4ada..b12518ba5ae9 100644 > --- a/drivers/staging/lustre/lustre/mdc/mdc_request.c > +++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c > @@ -888,7 +888,7 @@ static int mdc_getpage(struct obd_export *exp, const struct lu_fid *fid, > exp->exp_obd->obd_name, -EIO); > return -EIO; > } > - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends), NULL, NULL, > + lwi = LWI_TIMEOUT_INTR(resends * HZ, NULL, NULL, > NULL); > l_wait_event(waitq, 0, &lwi); > > diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c > index b743aee62349..a01d13bde102 100644 > --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c > +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c > @@ -1628,7 +1628,7 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld) > > if (rcl == -ESHUTDOWN && > atomic_read(&mgc->u.cli.cl_mgc_refcount) > 0 && !retry) { > - int secs = cfs_time_seconds(obd_timeout); > + int secs = obd_timeout * HZ; > struct obd_import *imp; > struct l_wait_info lwi; > > diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c > index 902bad22013b..ce5e7bdda692 100644 > --- a/drivers/staging/lustre/lustre/obdclass/cl_io.c > +++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c > @@ -1097,7 +1097,7 @@ EXPORT_SYMBOL(cl_sync_io_init); > int cl_sync_io_wait(const struct lu_env *env, struct cl_sync_io *anchor, > long timeout) > { > - struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(timeout), > + struct l_wait_info lwi = LWI_TIMEOUT_INTR(timeout * HZ, > NULL, NULL, NULL); > int rc; > > diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c > index b9c1dc7e61b0..9c5ce5074b66 100644 > --- a/drivers/staging/lustre/lustre/obdecho/echo_client.c > +++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c > @@ -752,7 +752,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env, > spin_unlock(&ec->ec_lock); > CERROR("echo_client still has objects at cleanup time, wait for 1 second\n"); > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(1)); > + schedule_timeout(HZ); > lu_site_purge(env, ed->ed_site, -1); > spin_lock(&ec->ec_lock); > } > diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c > index b8d5adca94e1..0797e671f667 100644 > --- a/drivers/staging/lustre/lustre/osc/osc_cache.c > +++ b/drivers/staging/lustre/lustre/osc/osc_cache.c > @@ -934,7 +934,7 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext, > enum osc_extent_state state) > { > struct osc_object *obj = ext->oe_obj; > - struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(600), NULL, > + struct l_wait_info lwi = LWI_TIMEOUT_INTR(600 * HZ, NULL, > LWI_ON_SIGNAL_NOOP, NULL); > int rc = 0; > > @@ -1571,7 +1571,7 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli, > struct l_wait_info lwi; > int rc = -EDQUOT; > > - lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(AT_OFF ? obd_timeout : at_max), > + lwi = LWI_TIMEOUT_INTR((AT_OFF ? obd_timeout : at_max) * HZ, > NULL, LWI_ON_SIGNAL_NOOP, NULL); > > OSC_DUMP_GRANT(D_CACHE, cli, "need:%d\n", bytes); > diff --git a/drivers/staging/lustre/lustre/osc/osc_object.c b/drivers/staging/lustre/lustre/osc/osc_object.c > index 6c424f0290bb..6baa8e2e00c9 100644 > --- a/drivers/staging/lustre/lustre/osc/osc_object.c > +++ b/drivers/staging/lustre/lustre/osc/osc_object.c > @@ -328,7 +328,7 @@ int osc_object_is_contended(struct osc_object *obj) > * ll_file_is_contended. > */ > retry_time = cfs_time_add(obj->oo_contention_time, > - cfs_time_seconds(osc_contention_time)); > + osc_contention_time * HZ); > if (cfs_time_after(cur_time, retry_time)) { > osc_object_clear_contended(obj); > return 0; > diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c > index bac4b2304bad..0ab13f8e5993 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/client.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c > @@ -766,7 +766,7 @@ int ptlrpc_request_bufs_pack(struct ptlrpc_request *request, > * fail_loc > */ > set_current_state(TASK_UNINTERRUPTIBLE); > - schedule_timeout(cfs_time_seconds(2)); > + schedule_timeout(2 * HZ); > set_current_state(TASK_RUNNING); > } > } > @@ -2284,7 +2284,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) > * We still want to block for a limited time, > * so we allow interrupts during the timeout. > */ > - lwi = LWI_TIMEOUT_INTR_ALL(cfs_time_seconds(1), > + lwi = LWI_TIMEOUT_INTR_ALL(HZ, > ptlrpc_expired_set, > ptlrpc_interrupted_set, set); > else > @@ -2293,7 +2293,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) > * interrupts are allowed. Wait until all > * complete, or an in-flight req times out. > */ > - lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1), > + lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, > ptlrpc_expired_set, set); > > rc = l_wait_event(set->set_waitq, ptlrpc_check_set(NULL, set), &lwi); > @@ -2538,8 +2538,8 @@ static int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async) > * Network access will complete in finite time but the HUGE > * timeout lets us CWARN for visibility of sluggish NALs > */ > - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(LONG_UNLINK), > - cfs_time_seconds(1), NULL, NULL); > + lwi = LWI_TIMEOUT_INTERVAL(LONG_UNLINK * HZ, > + HZ, NULL, NULL); > rc = l_wait_event(*wq, !ptlrpc_client_recv_or_unlink(request), > &lwi); > if (rc == 0) { > diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c > index 811b7ab3a582..71f7588570ef 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/events.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/events.c > @@ -517,7 +517,7 @@ static void ptlrpc_ni_fini(void) > > /* Wait for a bit */ > init_waitqueue_head(&waitq); > - lwi = LWI_TIMEOUT(cfs_time_seconds(2), NULL, NULL); > + lwi = LWI_TIMEOUT(2 * HZ, NULL, NULL); > l_wait_event(waitq, 0, &lwi); > break; > } > diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c > index 5b0f65536c29..0eba5f18bd3b 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/import.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c > @@ -307,9 +307,9 @@ void ptlrpc_invalidate_import(struct obd_import *imp) > * have been locally cancelled by ptlrpc_abort_inflight. > */ > lwi = LWI_TIMEOUT_INTERVAL( > - cfs_timeout_cap(cfs_time_seconds(timeout)), > - (timeout > 1) ? cfs_time_seconds(1) : > - cfs_time_seconds(1) / 2, > + cfs_timeout_cap(timeout * HZ), > + (timeout > 1) ? HZ : > + HZ / 2, > NULL, NULL); > rc = l_wait_event(imp->imp_recovery_waitq, > (atomic_read(&imp->imp_inflight) == 0), > @@ -431,7 +431,7 @@ void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt) > int ptlrpc_reconnect_import(struct obd_import *imp) > { > struct l_wait_info lwi; > - int secs = cfs_time_seconds(obd_timeout); > + int secs = obd_timeout * HZ; > int rc; > > ptlrpc_pinger_force(imp); > @@ -1508,14 +1508,13 @@ int ptlrpc_disconnect_import(struct obd_import *imp, int noclose) > > if (AT_OFF) { > if (imp->imp_server_timeout) > - timeout = cfs_time_seconds(obd_timeout / 2); > + timeout = obd_timeout * HZ / 2; > else > - timeout = cfs_time_seconds(obd_timeout); > + timeout = obd_timeout * HZ; > } else { > int idx = import_at_get_index(imp, > imp->imp_client->cli_request_portal); > - timeout = cfs_time_seconds( > - at_get(&imp->imp_at.iat_service_estimate[idx])); > + timeout = at_get(&imp->imp_at.iat_service_estimate[idx]) * HZ; > } > > lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(timeout), > diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c > index 047d712e850c..0c2ded721c49 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c > @@ -270,8 +270,8 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async) > /* Network access will complete in finite time but the HUGE > * timeout lets us CWARN for visibility of sluggish LNDs > */ > - lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(LONG_UNLINK), > - cfs_time_seconds(1), NULL, NULL); > + lwi = LWI_TIMEOUT_INTERVAL(LONG_UNLINK * HZ, > + HZ, NULL, NULL); > rc = l_wait_event(*wq, !ptlrpc_client_bulk_active(req), &lwi); > if (rc == 0) { > ptlrpc_rqphase_move(req, req->rq_next_phase); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c > index a64e125df95f..c060d6f5015a 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c > @@ -267,7 +267,7 @@ lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt) > /* If we cannot get anything for some long time, we better > * bail out instead of waiting infinitely > */ > - lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL); > + lwi = LWI_TIMEOUT(10 * HZ, NULL, NULL); > rc = l_wait_event(svcpt->scp_rep_waitq, > !list_empty(&svcpt->scp_rep_idle), &lwi); > if (rc != 0) > diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c > index af707cb2b62b..010a1cdf05fa 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c > @@ -141,7 +141,7 @@ static long pinger_check_timeout(unsigned long time) > } > mutex_unlock(&pinger_mutex); > > - return cfs_time_sub(cfs_time_add(time, cfs_time_seconds(timeout)), > + return cfs_time_sub(cfs_time_add(time, timeout * HZ), > cfs_time_current()); > } > > @@ -247,7 +247,7 @@ static int ptlrpc_pinger_main(void *arg) > if (imp->imp_pingable && imp->imp_next_ping && > cfs_time_after(imp->imp_next_ping, > cfs_time_add(this_ping, > - cfs_time_seconds(PING_INTERVAL)))) > + PING_INTERVAL * HZ))) > ptlrpc_update_next_ping(imp, 0); > } > mutex_unlock(&pinger_mutex); > @@ -264,10 +264,10 @@ static int ptlrpc_pinger_main(void *arg) > CDEBUG(D_INFO, "next wakeup in " CFS_DURATION_T " (%ld)\n", > time_to_next_wake, > cfs_time_add(this_ping, > - cfs_time_seconds(PING_INTERVAL))); > + PING_INTERVAL * HZ)); > if (time_to_next_wake > 0) { > lwi = LWI_TIMEOUT(max_t(long, time_to_next_wake, > - cfs_time_seconds(1)), > + HZ), > NULL, NULL); > l_wait_event(thread->t_ctl_waitq, > thread_is_stopping(thread) || > diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > index 8b865294d933..dad2f9290f70 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > @@ -230,7 +230,7 @@ void ptlrpcd_add_req(struct ptlrpc_request *req) > > spin_lock(&req->rq_lock); > if (req->rq_invalid_rqset) { > - struct l_wait_info lwi = LWI_TIMEOUT(cfs_time_seconds(5), > + struct l_wait_info lwi = LWI_TIMEOUT(5 * HZ, > back_to_sleep, NULL); > > req->rq_invalid_rqset = 0; > @@ -438,7 +438,7 @@ static int ptlrpcd(void *arg) > int timeout; > > timeout = ptlrpc_set_next_timeout(set); > - lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1), > + lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, > ptlrpc_expired_set, set); > > lu_context_enter(&env.le_ctx); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/recover.c b/drivers/staging/lustre/lustre/ptlrpc/recover.c > index e4d3f23e9f3a..5bbd23eebfa6 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/recover.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/recover.c > @@ -347,7 +347,7 @@ int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid, int async) > > if (!async) { > struct l_wait_info lwi; > - int secs = cfs_time_seconds(obd_timeout); > + int secs = obd_timeout * HZ; > > CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n", > obd2cli_tgt(imp->imp_obd), secs); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c > index 1f22926c1355..6d4229ebc9d9 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/service.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c > @@ -2149,7 +2149,7 @@ static int ptlrpc_main(void *arg) > * Wait for a timeout (unless something else > * happens) before I try again > */ > - svcpt->scp_rqbd_timeout = cfs_time_seconds(1) / 10; > + svcpt->scp_rqbd_timeout = HZ / 10; > CDEBUG(D_RPCTRACE, "Posted buffers: %d\n", > svcpt->scp_nrqbds_posted); > } > @@ -2588,7 +2588,7 @@ static void ptlrpc_wait_replies(struct ptlrpc_service_part *svcpt) > { > while (1) { > int rc; > - struct l_wait_info lwi = LWI_TIMEOUT(cfs_time_seconds(10), > + struct l_wait_info lwi = LWI_TIMEOUT(10 * HZ, > NULL, NULL); > > rc = l_wait_event(svcpt->scp_waitq, > @@ -2660,8 +2660,8 @@ ptlrpc_service_unlink_rqbd(struct ptlrpc_service *svc) > * of sluggish LNDs > */ > lwi = LWI_TIMEOUT_INTERVAL( > - cfs_time_seconds(LONG_UNLINK), > - cfs_time_seconds(1), NULL, NULL); > + LONG_UNLINK * HZ, > + HZ, NULL, NULL); > rc = l_wait_event(svcpt->scp_waitq, > svcpt->scp_nrqbds_posted == 0, &lwi); > if (rc == -ETIMEDOUT) { > > > From jsimmons at infradead.org Wed Jan 17 15:29:52 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:29:52 +0000 (GMT) Subject: [lustre-devel] [PATCH 07/19] staging: lustre: simplify l_wait_event when intr handler but no timeout. In-Reply-To: <151538209356.23920.9569196568216701164.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209356.23920.9569196568216701164.stgit@noble> Message-ID: > If l_wait_event() is given a function to be called on a signal, > but no timeout or timeout handler, then the intr function is simply > called at the end if the wait was aborted by a signal. > So a simpler way to write the code (in the one place this case is > used) it to open-code the body of the function after the > wait_event, if -ERESTARTSYS was returned. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/ldlm/ldlm_flock.c | 30 +++++------------------ > 1 file changed, 7 insertions(+), 23 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c > index 657ab95091a0..411b540b96d9 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c > @@ -310,24 +310,6 @@ static int ldlm_process_flock_lock(struct ldlm_lock *req) > return LDLM_ITER_CONTINUE; > } > > -struct ldlm_flock_wait_data { > - struct ldlm_lock *fwd_lock; > -}; > - > -static void > -ldlm_flock_interrupted_wait(void *data) > -{ > - struct ldlm_lock *lock; > - > - lock = ((struct ldlm_flock_wait_data *)data)->fwd_lock; > - > - lock_res_and_lock(lock); > - > - /* client side - set flag to prevent lock from being put on LRU list */ > - ldlm_set_cbpending(lock); > - unlock_res_and_lock(lock); > -} > - > /** > * Flock completion callback function. > * > @@ -342,8 +324,6 @@ int > ldlm_flock_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) > { > struct file_lock *getlk = lock->l_ast_data; > - struct ldlm_flock_wait_data fwd; > - struct l_wait_info lwi; > int rc = 0; > > OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CP_CB_WAIT2, 4); > @@ -372,13 +352,17 @@ ldlm_flock_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) > > LDLM_DEBUG(lock, > "client-side enqueue returned a blocked lock, sleeping"); > - fwd.fwd_lock = lock; > - lwi = LWI_TIMEOUT_INTR(0, NULL, ldlm_flock_interrupted_wait, &fwd); > > /* Go to sleep until the lock is granted. */ > - rc = l_wait_event(lock->l_waitq, is_granted_or_cancelled(lock), &lwi); > + rc = l_wait_event_abortable(lock->l_waitq, is_granted_or_cancelled(lock)); > > if (rc) { > + lock_res_and_lock(lock); > + > + /* client side - set flag to prevent lock from being put on LRU list */ > + ldlm_set_cbpending(lock); > + unlock_res_and_lock(lock); > + > LDLM_DEBUG(lock, "client-side enqueue waking up: failed (%d)", > rc); > return rc; > > > From jsimmons at infradead.org Wed Jan 17 15:30:28 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:30:28 +0000 (GMT) Subject: [lustre-devel] [PATCH 06/19] staging: lustre: introduce and use l_wait_event_abortable() In-Reply-To: <151538209353.23920.9039364039042495496.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209353.23920.9039364039042495496.stgit@noble> Message-ID: > lustre sometimes wants to wait for an event, but abort if > one of a specific list of signals arrives. This is a little > bit like wait_event_killable(), except that the signals are > identified a different way. > > So introduce l_wait_event_abortable() which provides this > functionality. > Having separate functions for separate needs is more in line > with the pattern set by include/linux/wait.h, than having a > single function which tries to include all possible needs. > > Also introduce l_wait_event_abortable_exclusive(). > > Note that l_wait_event() return -EINTR on a signal, while > Linux wait_event functions return -ERESTARTSYS. > l_wait_event_{abortable_,}exclusive follow the Linux pattern. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/include/lustre_lib.h | 24 ++++++++++++++++++++ > drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 12 +++++----- > drivers/staging/lustre/lustre/llite/llite_lib.c | 12 +++------- > drivers/staging/lustre/lustre/obdclass/genops.c | 9 +++----- > drivers/staging/lustre/lustre/obdclass/llog_obd.c | 5 ++-- > drivers/staging/lustre/lustre/osc/osc_page.c | 6 ++--- > drivers/staging/lustre/lustre/osc/osc_request.c | 6 ++--- > 7 files changed, 43 insertions(+), 31 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h > index 7d950c53e962..b2a64d0e682c 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_lib.h > +++ b/drivers/staging/lustre/lustre/include/lustre_lib.h > @@ -336,4 +336,28 @@ do { \ > /** @} lib */ > > > + > +/* l_wait_event_abortable() is a bit like wait_event_killable() > + * except there is a fixed set of signals which will abort: > + * LUSTRE_FATAL_SIGS > + */ > +#define l_wait_event_abortable(wq, condition) \ > +({ \ > + sigset_t __blocked; \ > + int __ret = 0; \ > + __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ > + __ret = wait_event_interruptible(wq, condition); \ > + cfs_restore_sigs(__blocked); \ > + __ret; \ > +}) > + > +#define l_wait_event_abortable_exclusive(wq, condition) \ > +({ \ > + sigset_t __blocked; \ > + int __ret = 0; \ > + __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ > + __ret = wait_event_interruptible_exclusive(wq, condition); \ > + cfs_restore_sigs(__blocked); \ > + __ret; \ > +}) > #endif /* _LUSTRE_LIB_H */ > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c > index 2e66825c8f4b..4c44603ab6f9 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c > @@ -879,7 +879,6 @@ static int __ldlm_namespace_free(struct ldlm_namespace *ns, int force) > ldlm_namespace_cleanup(ns, force ? LDLM_FL_LOCAL_ONLY : 0); > > if (atomic_read(&ns->ns_bref) > 0) { > - struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); > int rc; > > CDEBUG(D_DLMTRACE, > @@ -887,11 +886,12 @@ static int __ldlm_namespace_free(struct ldlm_namespace *ns, int force) > ldlm_ns_name(ns), atomic_read(&ns->ns_bref)); > force_wait: > if (force) > - lwi = LWI_TIMEOUT(msecs_to_jiffies(obd_timeout * > - MSEC_PER_SEC) / 4, NULL, NULL); > - > - rc = l_wait_event(ns->ns_waitq, > - atomic_read(&ns->ns_bref) == 0, &lwi); > + rc = wait_event_idle_timeout(ns->ns_waitq, > + atomic_read(&ns->ns_bref) == 0, > + obd_timeout * HZ / 4) ? 0 : -ETIMEDOUT; > + else > + rc = l_wait_event_abortable(ns->ns_waitq, > + atomic_read(&ns->ns_bref) == 0); > > /* Forced cleanups should be able to reclaim all references, > * so it's safe to wait forever... we can't leak locks... > diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c > index 0a9183f271f5..33dc15e9aebb 100644 > --- a/drivers/staging/lustre/lustre/llite/llite_lib.c > +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c > @@ -986,16 +986,12 @@ void ll_put_super(struct super_block *sb) > } > > /* Wait for unstable pages to be committed to stable storage */ > - if (!force) { > - struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); > - > - rc = l_wait_event(sbi->ll_cache->ccc_unstable_waitq, > - !atomic_long_read(&sbi->ll_cache->ccc_unstable_nr), > - &lwi); > - } > + if (!force) > + rc = l_wait_event_abortable(sbi->ll_cache->ccc_unstable_waitq, > + !atomic_long_read(&sbi->ll_cache->ccc_unstable_nr)); > > ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr); > - if (!force && rc != -EINTR) > + if (!force && rc != -ERESTARTSYS) > LASSERTF(!ccc_count, "count: %li\n", ccc_count); > > /* We need to set force before the lov_disconnect in > diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c > index 3ff25b8d3b48..8f776a4058a9 100644 > --- a/drivers/staging/lustre/lustre/obdclass/genops.c > +++ b/drivers/staging/lustre/lustre/obdclass/genops.c > @@ -1332,7 +1332,6 @@ static bool obd_request_slot_avail(struct client_obd *cli, > int obd_get_request_slot(struct client_obd *cli) > { > struct obd_request_slot_waiter orsw; > - struct l_wait_info lwi; > int rc; > > spin_lock(&cli->cl_loi_list_lock); > @@ -1347,11 +1346,9 @@ int obd_get_request_slot(struct client_obd *cli) > orsw.orsw_signaled = false; > spin_unlock(&cli->cl_loi_list_lock); > > - lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); > - rc = l_wait_event(orsw.orsw_waitq, > - obd_request_slot_avail(cli, &orsw) || > - orsw.orsw_signaled, > - &lwi); > + rc = l_wait_event_abortable(orsw.orsw_waitq, > + obd_request_slot_avail(cli, &orsw) || > + orsw.orsw_signaled); > > /* > * Here, we must take the lock to avoid the on-stack 'orsw' to be > diff --git a/drivers/staging/lustre/lustre/obdclass/llog_obd.c b/drivers/staging/lustre/lustre/obdclass/llog_obd.c > index 28bbaa2136ac..26aea114a29b 100644 > --- a/drivers/staging/lustre/lustre/obdclass/llog_obd.c > +++ b/drivers/staging/lustre/lustre/obdclass/llog_obd.c > @@ -104,7 +104,6 @@ EXPORT_SYMBOL(__llog_ctxt_put); > > int llog_cleanup(const struct lu_env *env, struct llog_ctxt *ctxt) > { > - struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); > struct obd_llog_group *olg; > int rc, idx; > > @@ -129,8 +128,8 @@ int llog_cleanup(const struct lu_env *env, struct llog_ctxt *ctxt) > CERROR("Error %d while cleaning up ctxt %p\n", > rc, ctxt); > > - l_wait_event(olg->olg_waitq, > - llog_group_ctxt_null(olg, idx), &lwi); > + l_wait_event_abortable(olg->olg_waitq, > + llog_group_ctxt_null(olg, idx)); > > return rc; > } > diff --git a/drivers/staging/lustre/lustre/osc/osc_page.c b/drivers/staging/lustre/lustre/osc/osc_page.c > index 20094b6309f9..6fdd521feb21 100644 > --- a/drivers/staging/lustre/lustre/osc/osc_page.c > +++ b/drivers/staging/lustre/lustre/osc/osc_page.c > @@ -759,7 +759,6 @@ static long osc_lru_reclaim(struct client_obd *cli, unsigned long npages) > static int osc_lru_alloc(const struct lu_env *env, struct client_obd *cli, > struct osc_page *opg) > { > - struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); > struct osc_io *oio = osc_env_io(env); > int rc = 0; > > @@ -782,9 +781,8 @@ static int osc_lru_alloc(const struct lu_env *env, struct client_obd *cli, > > cond_resched(); > > - rc = l_wait_event(osc_lru_waitq, > - atomic_long_read(cli->cl_lru_left) > 0, > - &lwi); > + rc = l_wait_event_abortable(osc_lru_waitq, > + atomic_long_read(cli->cl_lru_left) > 0); > > if (rc < 0) > break; > diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c > index 45b1ebf33363..074b5ce6284c 100644 > --- a/drivers/staging/lustre/lustre/osc/osc_request.c > +++ b/drivers/staging/lustre/lustre/osc/osc_request.c > @@ -552,14 +552,12 @@ static int osc_destroy(const struct lu_env *env, struct obd_export *exp, > > req->rq_interpret_reply = osc_destroy_interpret; > if (!osc_can_send_destroy(cli)) { > - struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); > - > /* > * Wait until the number of on-going destroy RPCs drops > * under max_rpc_in_flight > */ > - l_wait_event_exclusive(cli->cl_destroy_waitq, > - osc_can_send_destroy(cli), &lwi); > + l_wait_event_abortable_exclusive(cli->cl_destroy_waitq, > + osc_can_send_destroy(cli)); > } > > /* Do not wait for response */ > > > From jsimmons at infradead.org Wed Jan 17 15:31:16 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:31:16 +0000 (GMT) Subject: [lustre-devel] [PATCH 08/19] staging: lustre: simplify waiting in ldlm_completion_ast() In-Reply-To: <151538209360.23920.8603201181939332545.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209360.23920.8603201181939332545.stgit@noble> Message-ID: > If a signal-callback (lwi_on_signal) is set without lwi_allow_intr, as > is the case in ldlm_completion_ast(), the behavior depends on the > timeout set. > > If a timeout is set, then signals are ignored. If the timeout is > reached, the timeout handler is called. If the timeout handler > return 0, which ldlm_expired_completion_wait() always does, the > l_wait_event() switches to exactly the behavior if no timeout was set. > > If no timeout is set, then "fatal" signals are not ignored. If one > arrives the callback is run, but as the callback is empty in this > case, that is not relevant. > > This can be simplified to: > if a timeout is wanted > wait_event_idle_timeout() > if that timed out, call the timeout handler > l_wait_event_abortable() > > i.e. the code always waits indefinitely. Sometimes it performs a > non-abortable wait first. Sometimes it doesn't. But it only > aborts before the condition is true if it is signaled. > This doesn't quite agree with the comments and debug messages. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/ldlm/ldlm_request.c | 55 +++++++-------------- > 1 file changed, 18 insertions(+), 37 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c > index a244fa717134..f1233d844bbd 100644 > --- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c > +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c > @@ -72,15 +72,6 @@ MODULE_PARM_DESC(ldlm_enqueue_min, "lock enqueue timeout minimum"); > /* in client side, whether the cached locks will be canceled before replay */ > unsigned int ldlm_cancel_unused_locks_before_replay = 1; > > -static void interrupted_completion_wait(void *data) > -{ > -} > - > -struct lock_wait_data { > - struct ldlm_lock *lwd_lock; > - __u32 lwd_conn_cnt; > -}; > - > struct ldlm_async_args { > struct lustre_handle lock_handle; > }; > @@ -112,10 +103,8 @@ static int ldlm_request_bufsize(int count, int type) > return sizeof(struct ldlm_request) + avail; > } > > -static int ldlm_expired_completion_wait(void *data) > +static void ldlm_expired_completion_wait(struct ldlm_lock *lock, struct obd_import *imp2) > { > - struct lock_wait_data *lwd = data; > - struct ldlm_lock *lock = lwd->lwd_lock; > struct obd_import *imp; > struct obd_device *obd; > > @@ -135,19 +124,17 @@ static int ldlm_expired_completion_wait(void *data) > if (last_dump == 0) > libcfs_debug_dumplog(); > } > - return 0; > + return; > } > > obd = lock->l_conn_export->exp_obd; > imp = obd->u.cli.cl_import; > - ptlrpc_fail_import(imp, lwd->lwd_conn_cnt); > + ptlrpc_fail_import(imp, imp2 ? imp2->imp_conn_cnt : 0); > LDLM_ERROR(lock, > "lock timed out (enqueued at %lld, %llds ago), entering recovery for %s@%s", > (s64)lock->l_last_activity, > (s64)(ktime_get_real_seconds() - lock->l_last_activity), > obd2cli_tgt(obd), imp->imp_connection->c_remote_uuid.uuid); > - > - return 0; > } > > /** > @@ -251,10 +238,8 @@ EXPORT_SYMBOL(ldlm_completion_ast_async); > int ldlm_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) > { > /* XXX ALLOCATE - 160 bytes */ > - struct lock_wait_data lwd; > struct obd_device *obd; > struct obd_import *imp = NULL; > - struct l_wait_info lwi; > __u32 timeout; > int rc = 0; > > @@ -281,32 +266,28 @@ int ldlm_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data) > > timeout = ldlm_cp_timeout(lock); > > - lwd.lwd_lock = lock; > lock->l_last_activity = ktime_get_real_seconds(); > > - if (ldlm_is_no_timeout(lock)) { > - LDLM_DEBUG(lock, "waiting indefinitely because of NO_TIMEOUT"); > - lwi = LWI_INTR(interrupted_completion_wait, &lwd); > - } else { > - lwi = LWI_TIMEOUT_INTR(timeout * HZ, > - ldlm_expired_completion_wait, > - interrupted_completion_wait, &lwd); > - } > - > - if (imp) { > - spin_lock(&imp->imp_lock); > - lwd.lwd_conn_cnt = imp->imp_conn_cnt; > - spin_unlock(&imp->imp_lock); > - } > - > if (OBD_FAIL_CHECK_RESET(OBD_FAIL_LDLM_INTR_CP_AST, > OBD_FAIL_LDLM_CP_BL_RACE | OBD_FAIL_ONCE)) { > ldlm_set_fail_loc(lock); > rc = -EINTR; > } else { > - /* Go to sleep until the lock is granted or cancelled. */ > - rc = l_wait_event(lock->l_waitq, > - is_granted_or_cancelled(lock), &lwi); > + /* Go to sleep until the lock is granted or canceled. */ > + if (!ldlm_is_no_timeout(lock)) { > + /* Wait uninterruptible for a while first */ > + rc = wait_event_idle_timeout(lock->l_waitq, > + is_granted_or_cancelled(lock), > + timeout * HZ); > + if (rc == 0) > + ldlm_expired_completion_wait(lock, imp); > + } > + /* Now wait abortable */ > + if (rc == 0) > + rc = l_wait_event_abortable(lock->l_waitq, > + is_granted_or_cancelled(lock)); > + else > + rc = 0; > } > > if (rc) { > > > From jsimmons at infradead.org Wed Jan 17 15:32:04 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:32:04 +0000 (GMT) Subject: [lustre-devel] [PATCH 09/19] staging: lustre: open code polling loop instead of using l_wait_event() In-Reply-To: <151538209364.23920.15335820464811680168.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209364.23920.15335820464811680168.stgit@noble> Message-ID: > Two places that LWI_TIMEOUT_INTERVAL() is used, the outcome is a > simple polling loop that polls every second for some event (with a > limit). > > So write a simple loop to make this more apparent. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/llite/llite_lib.c | 11 +++++------ > drivers/staging/lustre/lustre/lov/lov_request.c | 12 +++++------- > 2 files changed, 10 insertions(+), 13 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c > index 33dc15e9aebb..f6642fa30428 100644 > --- a/drivers/staging/lustre/lustre/llite/llite_lib.c > +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c > @@ -1984,8 +1984,7 @@ void ll_umount_begin(struct super_block *sb) > struct ll_sb_info *sbi = ll_s2sbi(sb); > struct obd_device *obd; > struct obd_ioctl_data *ioc_data; > - wait_queue_head_t waitq; > - struct l_wait_info lwi; > + int cnt = 0; > > CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb, > sb->s_count, atomic_read(&sb->s_active)); > @@ -2021,10 +2020,10 @@ void ll_umount_begin(struct super_block *sb) > * and then continue. For now, we just periodically checking for vfs > * to decrement mnt_cnt and hope to finish it within 10sec. > */ > - init_waitqueue_head(&waitq); > - lwi = LWI_TIMEOUT_INTERVAL(10 * HZ, > - HZ, NULL, NULL); > - l_wait_event(waitq, may_umount(sbi->ll_mnt.mnt), &lwi); > + while (cnt < 10 && !may_umount(sbi->ll_mnt.mnt)) { > + schedule_timeout_uninterruptible(HZ); > + cnt ++; > + } > > schedule(); > } > diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c > index fb3b7a7fa32a..c1e58fcc30b3 100644 > --- a/drivers/staging/lustre/lustre/lov/lov_request.c > +++ b/drivers/staging/lustre/lustre/lov/lov_request.c > @@ -99,8 +99,7 @@ static int lov_check_set(struct lov_obd *lov, int idx) > */ > static int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx) > { > - wait_queue_head_t waitq; > - struct l_wait_info lwi; > + int cnt = 0; > struct lov_tgt_desc *tgt; > int rc = 0; > > @@ -125,11 +124,10 @@ static int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx) > > mutex_unlock(&lov->lov_lock); > > - init_waitqueue_head(&waitq); > - lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ, > - HZ, NULL, NULL); > - > - rc = l_wait_event(waitq, lov_check_set(lov, ost_idx), &lwi); > + while (cnt < obd_timeout && !lov_check_set(lov, ost_idx)) { > + schedule_timeout_uninterruptible(HZ); > + cnt ++; > + } > if (tgt->ltd_active) > return 1; > > > > From jsimmons at infradead.org Wed Jan 17 15:32:38 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:32:38 +0000 (GMT) Subject: [lustre-devel] [PATCH 10/19] staging: lustre: simplify waiting in ptlrpc_invalidate_import() In-Reply-To: <151538209368.23920.17745110760039469689.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209368.23920.17745110760039469689.stgit@noble> Message-ID: > This waiter currently wakes up every second to re-test if > imp_flight is zero. If we ensure wakeup is called whenever > imp_flight is decremented to zero, we can just have a simple > wait_event_idle_timeout(). > > So add a wake_up_all to the one place it is missing, and simplify > the wait_event. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/ptlrpc/client.c | 3 ++- > drivers/staging/lustre/lustre/ptlrpc/import.c | 21 ++++++++------------- > 2 files changed, 10 insertions(+), 14 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c > index 0ab13f8e5993..81b7a7046d82 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/client.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c > @@ -1588,7 +1588,8 @@ static int ptlrpc_send_new_req(struct ptlrpc_request *req) > spin_lock(&imp->imp_lock); > if (!list_empty(&req->rq_list)) { > list_del_init(&req->rq_list); > - atomic_dec(&req->rq_import->imp_inflight); > + if (atomic_dec_and_test(&req->rq_import->imp_inflight)) > + wake_up_all(&req->rq_import->imp_recovery_waitq); > } > spin_unlock(&imp->imp_lock); > ptlrpc_rqphase_move(req, RQ_PHASE_NEW); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c > index ed210550f61f..5d62c9de27eb 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/import.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c > @@ -265,7 +265,6 @@ void ptlrpc_invalidate_import(struct obd_import *imp) > { > struct list_head *tmp, *n; > struct ptlrpc_request *req; > - struct l_wait_info lwi; > unsigned int timeout; > int rc; > > @@ -306,19 +305,15 @@ void ptlrpc_invalidate_import(struct obd_import *imp) > * callbacks. Cap it at obd_timeout -- these should all > * have been locally cancelled by ptlrpc_abort_inflight. > */ > - lwi = LWI_TIMEOUT_INTERVAL( > - cfs_timeout_cap(timeout * HZ), > - (timeout > 1) ? HZ : > - HZ / 2, > - NULL, NULL); > - rc = l_wait_event(imp->imp_recovery_waitq, > - (atomic_read(&imp->imp_inflight) == 0), > - &lwi); > - if (rc) { > + rc = wait_event_idle_timeout(imp->imp_recovery_waitq, > + atomic_read(&imp->imp_inflight) == 0, > + obd_timeout * HZ); > + > + if (rc == 0) { > const char *cli_tgt = obd2cli_tgt(imp->imp_obd); > > - CERROR("%s: rc = %d waiting for callback (%d != 0)\n", > - cli_tgt, rc, > + CERROR("%s: timeout waiting for callback (%d != 0)\n", > + cli_tgt, > atomic_read(&imp->imp_inflight)); > > spin_lock(&imp->imp_lock); > @@ -365,7 +360,7 @@ void ptlrpc_invalidate_import(struct obd_import *imp) > } > spin_unlock(&imp->imp_lock); > } > - } while (rc != 0); > + } while (rc == 0); > > /* > * Let's additionally check that no new rpcs added to import in > > > From jsimmons at infradead.org Wed Jan 17 15:33:07 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:33:07 +0000 (GMT) Subject: [lustre-devel] [PATCH 11/19] staging: lustre: remove back_to_sleep() In-Reply-To: <151538209372.23920.9644158038491397506.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209372.23920.9644158038491397506.stgit@noble> Message-ID: > When 'back_to_sleep()' is passed as the 'timeout' function, > the effect is to wait indefinitely for the event, polling > once after the timeout. > If LWI_ON_SIGNAL_NOOP is given, then after the timeout > we allow fatal signals to interrupt the wait. > > Make this more obvious in both places "back_to_sleep()" is > used but using two explicit sleeps. > > The code in ptlrpcd_add_req() looks odd - why not just have one > wait_event_idle()? However I believe this is a faithful > transformation of the existing code. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/include/lustre_lib.h | 4 ---- > drivers/staging/lustre/lustre/ptlrpc/import.c | 11 ++++++----- > drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 9 +++++---- > 3 files changed, 11 insertions(+), 13 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h > index b2a64d0e682c..1939e959b92a 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_lib.h > +++ b/drivers/staging/lustre/lustre/include/lustre_lib.h > @@ -140,10 +140,6 @@ void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id); > * XXX nikita: some ptlrpc daemon threads have races of that sort. > * > */ > -static inline int back_to_sleep(void *arg) > -{ > - return 0; > -} > > #define LWI_ON_SIGNAL_NOOP ((void (*)(void *))(-1)) > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c > index 5d62c9de27eb..faf0f606f013 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/import.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c > @@ -1496,7 +1496,6 @@ int ptlrpc_disconnect_import(struct obd_import *imp, int noclose) > } > > if (ptlrpc_import_in_recovery(imp)) { > - struct l_wait_info lwi; > long timeout; > > if (AT_OFF) { > @@ -1510,10 +1509,12 @@ int ptlrpc_disconnect_import(struct obd_import *imp, int noclose) > timeout = at_get(&imp->imp_at.iat_service_estimate[idx]) * HZ; > } > > - lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(timeout), > - back_to_sleep, LWI_ON_SIGNAL_NOOP, NULL); > - rc = l_wait_event(imp->imp_recovery_waitq, > - !ptlrpc_import_in_recovery(imp), &lwi); > + if (wait_event_idle_timeout(imp->imp_recovery_waitq, > + !ptlrpc_import_in_recovery(imp), > + cfs_timeout_cap(timeout)) == 0) > + l_wait_event_abortable( > + imp->imp_recovery_waitq, > + !ptlrpc_import_in_recovery(imp)); > } > > spin_lock(&imp->imp_lock); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > index dad2f9290f70..437b4b2a9072 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > @@ -230,12 +230,13 @@ void ptlrpcd_add_req(struct ptlrpc_request *req) > > spin_lock(&req->rq_lock); > if (req->rq_invalid_rqset) { > - struct l_wait_info lwi = LWI_TIMEOUT(5 * HZ, > - back_to_sleep, NULL); > - > req->rq_invalid_rqset = 0; > spin_unlock(&req->rq_lock); > - l_wait_event(req->rq_set_waitq, !req->rq_set, &lwi); > + if (wait_event_idle_timeout(req->rq_set_waitq, > + !req->rq_set, > + 5 * HZ) == 0) > + wait_event_idle(req->rq_set_waitq, > + !req->rq_set); > } else if (req->rq_set) { > /* If we have a valid "rq_set", just reuse it to avoid double > * linked. > > > From jsimmons at infradead.org Wed Jan 17 15:33:32 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:33:32 +0000 (GMT) Subject: [lustre-devel] [PATCH 12/19] staging: lustre: make polling loop in ptlrpc_unregister_bulk more obvious In-Reply-To: <151538209376.23920.7787678507188073174.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209376.23920.7787678507188073174.stgit@noble> Message-ID: > This use of l_wait_event() is a polling loop that re-checks > every second. Make this more obvious with a while loop > and wait_event_idle_timeout(). Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/ptlrpc/niobuf.c | 15 ++++++++------- > 1 file changed, 8 insertions(+), 7 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c > index 0c2ded721c49..86883abaad2c 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c > @@ -229,7 +229,6 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async) > { > struct ptlrpc_bulk_desc *desc = req->rq_bulk; > wait_queue_head_t *wq; > - struct l_wait_info lwi; > int rc; > > LASSERT(!in_interrupt()); /* might sleep */ > @@ -246,7 +245,7 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async) > > /* the unlink ensures the callback happens ASAP and is the last > * one. If it fails, it must be because completion just happened, > - * but we must still l_wait_event() in this case to give liblustre > + * but we must still wait_event() in this case to give liblustre > * a chance to run client_bulk_callback() > */ > mdunlink_iterate_helper(desc->bd_mds, desc->bd_md_max_brw); > @@ -270,15 +269,17 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async) > /* Network access will complete in finite time but the HUGE > * timeout lets us CWARN for visibility of sluggish LNDs > */ > - lwi = LWI_TIMEOUT_INTERVAL(LONG_UNLINK * HZ, > - HZ, NULL, NULL); > - rc = l_wait_event(*wq, !ptlrpc_client_bulk_active(req), &lwi); > - if (rc == 0) { > + int cnt = 0; > + while (cnt < LONG_UNLINK && > + (rc = wait_event_idle_timeout(*wq, > + !ptlrpc_client_bulk_active(req), > + HZ)) == 0) > + cnt += 1; > + if (rc > 0) { > ptlrpc_rqphase_move(req, req->rq_next_phase); > return 1; > } > > - LASSERT(rc == -ETIMEDOUT); > DEBUG_REQ(D_WARNING, req, "Unexpectedly long timeout: desc %p", > desc); > } > > > From jsimmons at infradead.org Wed Jan 17 15:34:20 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:34:20 +0000 (GMT) Subject: [lustre-devel] [PATCH 13/19] staging: lustre: use wait_event_idle_timeout in ptlrpcd() In-Reply-To: <151538209379.23920.12930052742997185181.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209379.23920.12930052742997185181.stgit@noble> Message-ID: > We can replace l_wait_event() with > wait_event_idle_timeout() here providing we call the > timeout function when wait_event_idle_timeout() returns zero. > > As ptlrpc_expired_set() returns 1, the l_wait_event() aborts of the > first timeout. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/ptlrpc/client.c | 12 ++++++++---- > .../staging/lustre/lustre/ptlrpc/ptlrpc_internal.h | 2 +- > drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 9 +++++---- > 3 files changed, 14 insertions(+), 9 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c > index 81b7a7046d82..f70176c6db08 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/client.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c > @@ -2125,9 +2125,8 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink) > * Callback used when waiting on sets with l_wait_event. > * Always returns 1. > */ > -int ptlrpc_expired_set(void *data) > +void ptlrpc_expired_set(struct ptlrpc_request_set *set) > { > - struct ptlrpc_request_set *set = data; > struct list_head *tmp; > time64_t now = ktime_get_real_seconds(); > > @@ -2156,7 +2155,12 @@ int ptlrpc_expired_set(void *data) > */ > ptlrpc_expire_one_request(req, 1); > } > +} > +static int ptlrpc_expired_set_void(void *data) > +{ > + struct ptlrpc_request_set *set = data; > > + ptlrpc_expired_set(set); > /* > * When waiting for a whole set, we always break out of the > * sleep so we can recalculate the timeout, or enable interrupts > @@ -2286,7 +2290,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) > * so we allow interrupts during the timeout. > */ > lwi = LWI_TIMEOUT_INTR_ALL(HZ, > - ptlrpc_expired_set, > + ptlrpc_expired_set_void, > ptlrpc_interrupted_set, set); > else > /* > @@ -2295,7 +2299,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) > * complete, or an in-flight req times out. > */ > lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, > - ptlrpc_expired_set, set); > + ptlrpc_expired_set_void, set); > > rc = l_wait_event(set->set_waitq, ptlrpc_check_set(NULL, set), &lwi); > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h > index f9decbd1459d..b7a8d7537a66 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h > +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h > @@ -68,7 +68,7 @@ void ptlrpc_request_cache_free(struct ptlrpc_request *req); > void ptlrpc_init_xid(void); > void ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc, > struct ptlrpc_request *req); > -int ptlrpc_expired_set(void *data); > +void ptlrpc_expired_set(struct ptlrpc_request_set *set); > int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set); > void ptlrpc_resend_req(struct ptlrpc_request *request); > void ptlrpc_set_bulk_mbits(struct ptlrpc_request *req); > diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > index 437b4b2a9072..6ed77521d025 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c > @@ -435,16 +435,17 @@ static int ptlrpcd(void *arg) > * new_req_list and ptlrpcd_check() moves them into the set. > */ > do { > - struct l_wait_info lwi; > int timeout; > > timeout = ptlrpc_set_next_timeout(set); > - lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, > - ptlrpc_expired_set, set); > > lu_context_enter(&env.le_ctx); > lu_context_enter(env.le_ses); > - l_wait_event(set->set_waitq, ptlrpcd_check(&env, pc), &lwi); > + if (wait_event_idle_timeout(set->set_waitq, > + ptlrpcd_check(&env, pc), > + (timeout ? timeout : 1) * HZ) == 0) > + ptlrpc_expired_set(set); > + > lu_context_exit(&env.le_ctx); > lu_context_exit(env.le_ses); > > > > From jsimmons at infradead.org Wed Jan 17 15:34:46 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:34:46 +0000 (GMT) Subject: [lustre-devel] [PATCH 14/19] staging: lustre: improve waiting in sptlrpc_req_refresh_ctx In-Reply-To: <151538209383.23920.18027403730394945280.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209383.23920.18027403730394945280.stgit@noble> Message-ID: > Replace l_wait_event with wait_event_idle_timeout() and call the > handler function explicitly. This makes it more clear > what is happening. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/ptlrpc/sec.c | 34 ++++++++++++++++++++-------- > 1 file changed, 24 insertions(+), 10 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec.c b/drivers/staging/lustre/lustre/ptlrpc/sec.c > index 617e004d00f8..90e3b3022106 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/sec.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/sec.c > @@ -554,9 +554,8 @@ int ctx_check_refresh(struct ptlrpc_cli_ctx *ctx) > } > > static > -int ctx_refresh_timeout(void *data) > +int ctx_refresh_timeout(struct ptlrpc_request *req) > { > - struct ptlrpc_request *req = data; > int rc; > > /* conn_cnt is needed in expire_one_request */ > @@ -575,10 +574,8 @@ int ctx_refresh_timeout(void *data) > } > > static > -void ctx_refresh_interrupt(void *data) > +void ctx_refresh_interrupt(struct ptlrpc_request *req) > { > - struct ptlrpc_request *req = data; > - > spin_lock(&req->rq_lock); > req->rq_intr = 1; > spin_unlock(&req->rq_lock); > @@ -611,7 +608,6 @@ int sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout) > { > struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx; > struct ptlrpc_sec *sec; > - struct l_wait_info lwi; > int rc; > > LASSERT(ctx); > @@ -743,10 +739,28 @@ int sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout) > req->rq_restart = 0; > spin_unlock(&req->rq_lock); > > - lwi = LWI_TIMEOUT_INTR(msecs_to_jiffies(timeout * MSEC_PER_SEC), > - ctx_refresh_timeout, ctx_refresh_interrupt, > - req); > - rc = l_wait_event(req->rq_reply_waitq, ctx_check_refresh(ctx), &lwi); > + rc = wait_event_idle_timeout(req->rq_reply_waitq, > + ctx_check_refresh(ctx), > + timeout * HZ); > + if (rc == 0 && ctx_refresh_timeout(req) == 0) { > + /* Keep waiting, but enable some signals */ > + rc = l_wait_event_abortable(req->rq_reply_waitq, > + ctx_check_refresh(ctx)); > + if (rc == 0) > + rc = 1; > + } > + > + if (rc > 0) > + /* condition is true */ > + rc = 0; > + else if (rc == 0) > + /* Timed out */ > + rc = -ETIMEDOUT; > + else { > + /* Aborted by signal */ > + rc = -EINTR; > + ctx_refresh_interrupt(req); > + } > > /* > * following cases could lead us here: > > > From jsimmons at infradead.org Wed Jan 17 15:35:14 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:35:14 +0000 (GMT) Subject: [lustre-devel] [PATCH 15/19] staging: lustre: use explicit poll loop in ptlrpc_service_unlink_rqbd In-Reply-To: <151538209387.23920.11031149890821644565.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209387.23920.11031149890821644565.stgit@noble> Message-ID: > Rather an using l_wait_event(), use wait_event_idle_timeout() > with an explicit loop so it is easier to see what is happening. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/ptlrpc/service.c | 15 ++++++++------- > 1 file changed, 8 insertions(+), 7 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c > index 5c41297d23d2..6e3403417434 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/service.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c > @@ -2618,7 +2618,7 @@ ptlrpc_service_unlink_rqbd(struct ptlrpc_service *svc) > { > struct ptlrpc_service_part *svcpt; > struct ptlrpc_request_buffer_desc *rqbd; > - struct l_wait_info lwi; > + int cnt; > int rc; > int i; > > @@ -2658,12 +2658,13 @@ ptlrpc_service_unlink_rqbd(struct ptlrpc_service *svc) > * the HUGE timeout lets us CWARN for visibility > * of sluggish LNDs > */ > - lwi = LWI_TIMEOUT_INTERVAL( > - LONG_UNLINK * HZ, > - HZ, NULL, NULL); > - rc = l_wait_event(svcpt->scp_waitq, > - svcpt->scp_nrqbds_posted == 0, &lwi); > - if (rc == -ETIMEDOUT) { > + cnt = 0; > + while (cnt < LONG_UNLINK && > + (rc = wait_event_idle_timeout(svcpt->scp_waitq, > + svcpt->scp_nrqbds_posted == 0, > + HZ)) == 0) > + cnt ++; > + if (rc == 0) { > CWARN("Service %s waiting for request buffers\n", > svcpt->scp_service->srv_name); > } > > > From jsimmons at infradead.org Wed Jan 17 15:35:39 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:35:39 +0000 (GMT) Subject: [lustre-devel] [PATCH 16/19] staging: lustre: use explicit poll loop in ptlrpc_unregister_reply In-Reply-To: <151538209390.23920.11839113414532003231.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209390.23920.11839113414532003231.stgit@noble> Message-ID: > replace l_wait_event() with wait_event_idle_timeout() and explicit > loop. This approach is easier to understand. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/ptlrpc/client.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c > index f70176c6db08..ffdd3ffd62c6 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/client.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c > @@ -2500,7 +2500,6 @@ static int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async) > { > int rc; > wait_queue_head_t *wq; > - struct l_wait_info lwi; > > /* Might sleep. */ > LASSERT(!in_interrupt()); > @@ -2543,16 +2542,17 @@ static int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async) > * Network access will complete in finite time but the HUGE > * timeout lets us CWARN for visibility of sluggish NALs > */ > - lwi = LWI_TIMEOUT_INTERVAL(LONG_UNLINK * HZ, > - HZ, NULL, NULL); > - rc = l_wait_event(*wq, !ptlrpc_client_recv_or_unlink(request), > - &lwi); > - if (rc == 0) { > + int cnt = 0; > + while (cnt < LONG_UNLINK && > + (rc = wait_event_idle_timeout(*wq, > + !ptlrpc_client_recv_or_unlink(request), > + HZ)) == 0) > + cnt += 1; > + if (rc > 0) { > ptlrpc_rqphase_move(request, request->rq_next_phase); > return 1; > } > > - LASSERT(rc == -ETIMEDOUT); > DEBUG_REQ(D_WARNING, request, > "Unexpectedly long timeout receiving_reply=%d req_ulinked=%d reply_unlinked=%d", > request->rq_receiving_reply, > > > From jsimmons at infradead.org Wed Jan 17 15:36:05 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:36:05 +0000 (GMT) Subject: [lustre-devel] [PATCH 17/19] staging: lustre: remove l_wait_event from ptlrpc_set_wait In-Reply-To: <151538209394.23920.3578408043898411296.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209394.23920.3578408043898411296.stgit@noble> Message-ID: > This is the last remaining use of l_wait_event(). > It is the only use of LWI_TIMEOUT_INTR_ALL() which > has a meaning that timeouts can be interrupted. > Only interrupts by "fatal" signals are allowed, so > introduce l_wait_event_abortable_timeout() to > support this. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/include/lustre_lib.h | 14 +++ > drivers/staging/lustre/lustre/ptlrpc/client.c | 84 ++++++++------------ > 2 files changed, 49 insertions(+), 49 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h > index 1939e959b92a..ccc1a329e42b 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_lib.h > +++ b/drivers/staging/lustre/lustre/include/lustre_lib.h > @@ -196,6 +196,10 @@ struct l_wait_info { > #define LUSTRE_FATAL_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | \ > sigmask(SIGTERM) | sigmask(SIGQUIT) | \ > sigmask(SIGALRM)) > +static inline int l_fatal_signal_pending(struct task_struct *p) > +{ > + return signal_pending(p) && sigtestsetmask(&p->pending.signal, LUSTRE_FATAL_SIGS); > +} > > /** > * wait_queue_entry_t of Linux (version < 2.6.34) is a FIFO list for exclusively > @@ -347,6 +351,16 @@ do { \ > __ret; \ > }) > > +#define l_wait_event_abortable_timeout(wq, condition, timeout) \ > +({ \ > + sigset_t __blocked; \ > + int __ret = 0; \ > + __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ > + __ret = wait_event_interruptible_timeout(wq, condition, timeout);\ > + cfs_restore_sigs(__blocked); \ > + __ret; \ > +}) > + > #define l_wait_event_abortable_exclusive(wq, condition) \ > ({ \ > sigset_t __blocked; \ > diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c > index ffdd3ffd62c6..3d689d6100bc 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/client.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c > @@ -1774,7 +1774,7 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set) > } > > /* > - * ptlrpc_set_wait->l_wait_event sets lwi_allow_intr > + * ptlrpc_set_wait allow signal to abort the timeout > * so it sets rq_intr regardless of individual rpc > * timeouts. The synchronous IO waiting path sets > * rq_intr irrespective of whether ptlrpcd > @@ -2122,8 +2122,7 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink) > > /** > * Time out all uncompleted requests in request set pointed by \a data > - * Callback used when waiting on sets with l_wait_event. > - * Always returns 1. > + * Called when wait_event_idle_timeout times out. > */ > void ptlrpc_expired_set(struct ptlrpc_request_set *set) > { > @@ -2156,18 +2155,6 @@ void ptlrpc_expired_set(struct ptlrpc_request_set *set) > ptlrpc_expire_one_request(req, 1); > } > } > -static int ptlrpc_expired_set_void(void *data) > -{ > - struct ptlrpc_request_set *set = data; > - > - ptlrpc_expired_set(set); > - /* > - * When waiting for a whole set, we always break out of the > - * sleep so we can recalculate the timeout, or enable interrupts > - * if everyone's timed out. > - */ > - return 1; > -} > > /** > * Sets rq_intr flag in \a req under spinlock. > @@ -2182,11 +2169,10 @@ EXPORT_SYMBOL(ptlrpc_mark_interrupted); > > /** > * Interrupts (sets interrupted flag) all uncompleted requests in > - * a set \a data. Callback for l_wait_event for interruptible waits. > + * a set \a data. Called when l_wait_event_abortable_timeout receives signal. > */ > -static void ptlrpc_interrupted_set(void *data) > +static void ptlrpc_interrupted_set(struct ptlrpc_request_set *set) > { > - struct ptlrpc_request_set *set = data; > struct list_head *tmp; > > CDEBUG(D_RPCTRACE, "INTERRUPTED SET %p\n", set); > @@ -2256,7 +2242,6 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) > { > struct list_head *tmp; > struct ptlrpc_request *req; > - struct l_wait_info lwi; > int rc, timeout; > > if (set->set_producer) > @@ -2282,46 +2267,47 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set) > CDEBUG(D_RPCTRACE, "set %p going to sleep for %d seconds\n", > set, timeout); > > - if (timeout == 0 && !signal_pending(current)) > + if (timeout == 0 && !signal_pending(current)) { > /* > * No requests are in-flight (ether timed out > * or delayed), so we can allow interrupts. > * We still want to block for a limited time, > * so we allow interrupts during the timeout. > */ > - lwi = LWI_TIMEOUT_INTR_ALL(HZ, > - ptlrpc_expired_set_void, > - ptlrpc_interrupted_set, set); > - else > + rc = l_wait_event_abortable_timeout(set->set_waitq, > + ptlrpc_check_set(NULL, set), > + HZ); > + if (rc == 0) { > + rc = -ETIMEDOUT; > + ptlrpc_expired_set(set); > + } else if (rc < 0) { > + rc = -EINTR; > + ptlrpc_interrupted_set(set); > + } else > + rc = 0; > + } else { > /* > * At least one request is in flight, so no > * interrupts are allowed. Wait until all > * complete, or an in-flight req times out. > */ > - lwi = LWI_TIMEOUT((timeout ? timeout : 1) * HZ, > - ptlrpc_expired_set_void, set); > - > - rc = l_wait_event(set->set_waitq, ptlrpc_check_set(NULL, set), &lwi); > - > - /* > - * LU-769 - if we ignored the signal because it was already > - * pending when we started, we need to handle it now or we risk > - * it being ignored forever > - */ > - if (rc == -ETIMEDOUT && !lwi.lwi_allow_intr && > - signal_pending(current)) { > - sigset_t blocked_sigs = > - cfs_block_sigsinv(LUSTRE_FATAL_SIGS); > - > - /* > - * In fact we only interrupt for the "fatal" signals > - * like SIGINT or SIGKILL. We still ignore less > - * important signals since ptlrpc set is not easily > - * reentrant from userspace again > - */ > - if (signal_pending(current)) > - ptlrpc_interrupted_set(set); > - cfs_restore_sigs(blocked_sigs); > + rc = wait_event_idle_timeout(set->set_waitq, > + ptlrpc_check_set(NULL, set), > + (timeout ? timeout : 1) * HZ); > + if (rc == 0) { > + ptlrpc_expired_set(set); > + rc = -ETIMEDOUT; > + /* > + * LU-769 - if we ignored the signal > + * because it was already pending when > + * we started, we need to handle it > + * now or we risk it being ignored > + * forever > + */ > + if (l_fatal_signal_pending(current)) > + ptlrpc_interrupted_set(set); > + } else > + rc = 0; > } > > LASSERT(rc == 0 || rc == -EINTR || rc == -ETIMEDOUT); > @@ -2528,7 +2514,7 @@ static int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async) > return 0; > > /* > - * We have to l_wait_event() whatever the result, to give liblustre > + * We have to wait_event_idle_timeout() whatever the result, to give liblustre > * a chance to run reply_in_callback(), and to make sure we've > * unlinked before returning a req to the pool. > */ > > > From jsimmons at infradead.org Wed Jan 17 15:36:28 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:36:28 +0000 (GMT) Subject: [lustre-devel] [PATCH 18/19] staging: lustre: replace l_wait_event_exclusive_head() with wait_event_idle_exclusive In-Reply-To: <151538209398.23920.3167444012358212836.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209398.23920.3167444012358212836.stgit@noble> Message-ID: > This l_wait_event_exclusive_head() will wait indefinitely > if the timeout is zero. If it does wait with a timeout > and times out, the timeout for next time is set to zero. > > The can be mapped to a call to either > wait_event_idle_exclusive() > or > wait_event_idle_exclusive_timeout() > depending in the timeout setting. > > The current code arrange for LIFO queuing of waiters, > but include/event.h doesn't support that yet. > Until it does, fall back on FIFO with > wait_event_idle_exclusive{,_timeout}(). Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/ptlrpc/service.c | 43 ++++++++++++++---------- > 1 file changed, 25 insertions(+), 18 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c > index 6e3403417434..29fdb54f16ca 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/service.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c > @@ -1897,15 +1897,6 @@ ptlrpc_check_rqbd_pool(struct ptlrpc_service_part *svcpt) > } > } > > -static int > -ptlrpc_retry_rqbds(void *arg) > -{ > - struct ptlrpc_service_part *svcpt = arg; > - > - svcpt->scp_rqbd_timeout = 0; > - return -ETIMEDOUT; > -} > - > static inline int > ptlrpc_threads_enough(struct ptlrpc_service_part *svcpt) > { > @@ -1968,13 +1959,17 @@ ptlrpc_server_request_incoming(struct ptlrpc_service_part *svcpt) > return !list_empty(&svcpt->scp_req_incoming); > } > > +/* We perfer lifo queuing, but kernel doesn't provide that yet. */ > +#ifndef wait_event_idle_exclusive_lifo > +#define wait_event_idle_exclusive_lifo wait_event_idle_exclusive > +#define wait_event_idle_exclusive_lifo_timeout wait_event_idle_exclusive_timeout > +#endif > + > static __attribute__((__noinline__)) int > ptlrpc_wait_event(struct ptlrpc_service_part *svcpt, > struct ptlrpc_thread *thread) > { > /* Don't exit while there are replies to be handled */ > - struct l_wait_info lwi = LWI_TIMEOUT(svcpt->scp_rqbd_timeout, > - ptlrpc_retry_rqbds, svcpt); > > /* XXX: Add this back when libcfs watchdog is merged upstream > lc_watchdog_disable(thread->t_watchdog); > @@ -1982,13 +1977,25 @@ ptlrpc_wait_event(struct ptlrpc_service_part *svcpt, > > cond_resched(); > > - l_wait_event_exclusive_head(svcpt->scp_waitq, > - ptlrpc_thread_stopping(thread) || > - ptlrpc_server_request_incoming(svcpt) || > - ptlrpc_server_request_pending(svcpt, > - false) || > - ptlrpc_rqbd_pending(svcpt) || > - ptlrpc_at_check(svcpt), &lwi); > + if (svcpt->scp_rqbd_timeout == 0) > + wait_event_idle_exclusive_lifo( > + svcpt->scp_waitq, > + ptlrpc_thread_stopping(thread) || > + ptlrpc_server_request_incoming(svcpt) || > + ptlrpc_server_request_pending(svcpt, > + false) || > + ptlrpc_rqbd_pending(svcpt) || > + ptlrpc_at_check(svcpt)); > + else if (0 == wait_event_idle_exclusive_lifo_timeout( > + svcpt->scp_waitq, > + ptlrpc_thread_stopping(thread) || > + ptlrpc_server_request_incoming(svcpt) || > + ptlrpc_server_request_pending(svcpt, > + false) || > + ptlrpc_rqbd_pending(svcpt) || > + ptlrpc_at_check(svcpt), > + svcpt->scp_rqbd_timeout)) > + svcpt->scp_rqbd_timeout = 0; > > if (ptlrpc_thread_stopping(thread)) > return -EINTR; > > > From jsimmons at infradead.org Wed Jan 17 15:36:49 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 15:36:49 +0000 (GMT) Subject: [lustre-devel] [PATCH 19/19] staging: lustre: remove l_wait_event() and related code In-Reply-To: <151538209403.23920.14521634003346477815.stgit@noble> References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209403.23920.14521634003346477815.stgit@noble> Message-ID: > These macros are no longer used, so they can > be removed. Reviewed-by: James Simmons > Signed-off-by: NeilBrown > --- > drivers/staging/lustre/lustre/include/lustre_lib.h | 249 -------------------- > 1 file changed, 249 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h > index ccc1a329e42b..1efd86f18c1f 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_lib.h > +++ b/drivers/staging/lustre/lustre/include/lustre_lib.h > @@ -76,123 +76,6 @@ int do_set_info_async(struct obd_import *imp, > > void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id); > > -/* > - * l_wait_event is a flexible sleeping function, permitting simple caller > - * configuration of interrupt and timeout sensitivity along with actions to > - * be performed in the event of either exception. > - * > - * The first form of usage looks like this: > - * > - * struct l_wait_info lwi = LWI_TIMEOUT_INTR(timeout, timeout_handler, > - * intr_handler, callback_data); > - * rc = l_wait_event(waitq, condition, &lwi); > - * > - * l_wait_event() makes the current process wait on 'waitq' until 'condition' > - * is TRUE or a "killable" signal (SIGTERM, SIKGILL, SIGINT) is pending. It > - * returns 0 to signify 'condition' is TRUE, but if a signal wakes it before > - * 'condition' becomes true, it optionally calls the specified 'intr_handler' > - * if not NULL, and returns -EINTR. > - * > - * If a non-zero timeout is specified, signals are ignored until the timeout > - * has expired. At this time, if 'timeout_handler' is not NULL it is called. > - * If it returns FALSE l_wait_event() continues to wait as described above with > - * signals enabled. Otherwise it returns -ETIMEDOUT. > - * > - * LWI_INTR(intr_handler, callback_data) is shorthand for > - * LWI_TIMEOUT_INTR(0, NULL, intr_handler, callback_data) > - * > - * The second form of usage looks like this: > - * > - * struct l_wait_info lwi = LWI_TIMEOUT(timeout, timeout_handler); > - * rc = l_wait_event(waitq, condition, &lwi); > - * > - * This form is the same as the first except that it COMPLETELY IGNORES > - * SIGNALS. The caller must therefore beware that if 'timeout' is zero, or if > - * 'timeout_handler' is not NULL and returns FALSE, then the ONLY thing that > - * can unblock the current process is 'condition' becoming TRUE. > - * > - * Another form of usage is: > - * struct l_wait_info lwi = LWI_TIMEOUT_INTERVAL(timeout, interval, > - * timeout_handler); > - * rc = l_wait_event(waitq, condition, &lwi); > - * This is the same as previous case, but condition is checked once every > - * 'interval' jiffies (if non-zero). > - * > - * Subtle synchronization point: this macro does *not* necessary takes > - * wait-queue spin-lock before returning, and, hence, following idiom is safe > - * ONLY when caller provides some external locking: > - * > - * Thread1 Thread2 > - * > - * l_wait_event(&obj->wq, ....); (1) > - * > - * wake_up(&obj->wq): (2) > - * spin_lock(&q->lock); (2.1) > - * __wake_up_common(q, ...); (2.2) > - * spin_unlock(&q->lock, flags); (2.3) > - * > - * kfree(obj); (3) > - * > - * As l_wait_event() may "short-cut" execution and return without taking > - * wait-queue spin-lock, some additional synchronization is necessary to > - * guarantee that step (3) can begin only after (2.3) finishes. > - * > - * XXX nikita: some ptlrpc daemon threads have races of that sort. > - * > - */ > - > -#define LWI_ON_SIGNAL_NOOP ((void (*)(void *))(-1)) > - > -struct l_wait_info { > - long lwi_timeout; > - long lwi_interval; > - int lwi_allow_intr; > - int (*lwi_on_timeout)(void *); > - void (*lwi_on_signal)(void *); > - void *lwi_cb_data; > -}; > - > -/* NB: LWI_TIMEOUT ignores signals completely */ > -#define LWI_TIMEOUT(time, cb, data) \ > -((struct l_wait_info) { \ > - .lwi_timeout = time, \ > - .lwi_on_timeout = cb, \ > - .lwi_cb_data = data, \ > - .lwi_interval = 0, \ > - .lwi_allow_intr = 0 \ > -}) > - > -#define LWI_TIMEOUT_INTERVAL(time, interval, cb, data) \ > -((struct l_wait_info) { \ > - .lwi_timeout = time, \ > - .lwi_on_timeout = cb, \ > - .lwi_cb_data = data, \ > - .lwi_interval = interval, \ > - .lwi_allow_intr = 0 \ > -}) > - > -#define LWI_TIMEOUT_INTR(time, time_cb, sig_cb, data) \ > -((struct l_wait_info) { \ > - .lwi_timeout = time, \ > - .lwi_on_timeout = time_cb, \ > - .lwi_on_signal = sig_cb, \ > - .lwi_cb_data = data, \ > - .lwi_interval = 0, \ > - .lwi_allow_intr = 0 \ > -}) > - > -#define LWI_TIMEOUT_INTR_ALL(time, time_cb, sig_cb, data) \ > -((struct l_wait_info) { \ > - .lwi_timeout = time, \ > - .lwi_on_timeout = time_cb, \ > - .lwi_on_signal = sig_cb, \ > - .lwi_cb_data = data, \ > - .lwi_interval = 0, \ > - .lwi_allow_intr = 1 \ > -}) > - > -#define LWI_INTR(cb, data) LWI_TIMEOUT_INTR(0, NULL, cb, data) > - > #define LUSTRE_FATAL_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | \ > sigmask(SIGTERM) | sigmask(SIGQUIT) | \ > sigmask(SIGALRM)) > @@ -201,138 +84,6 @@ static inline int l_fatal_signal_pending(struct task_struct *p) > return signal_pending(p) && sigtestsetmask(&p->pending.signal, LUSTRE_FATAL_SIGS); > } > > -/** > - * wait_queue_entry_t of Linux (version < 2.6.34) is a FIFO list for exclusively > - * waiting threads, which is not always desirable because all threads will > - * be waken up again and again, even user only needs a few of them to be > - * active most time. This is not good for performance because cache can > - * be polluted by different threads. > - * > - * LIFO list can resolve this problem because we always wakeup the most > - * recent active thread by default. > - * > - * NB: please don't call non-exclusive & exclusive wait on the same > - * waitq if add_wait_queue_exclusive_head is used. > - */ > -#define add_wait_queue_exclusive_head(waitq, link) \ > -{ \ > - unsigned long flags; \ > - \ > - spin_lock_irqsave(&((waitq)->lock), flags); \ > - __add_wait_queue_exclusive(waitq, link); \ > - spin_unlock_irqrestore(&((waitq)->lock), flags); \ > -} > - > -/* > - * wait for @condition to become true, but no longer than timeout, specified > - * by @info. > - */ > -#define __l_wait_event(wq, condition, info, ret, l_add_wait) \ > -do { \ > - wait_queue_entry_t __wait; \ > - long __timeout = info->lwi_timeout; \ > - sigset_t __blocked; \ > - int __allow_intr = info->lwi_allow_intr; \ > - \ > - ret = 0; \ > - if (condition) \ > - break; \ > - \ > - init_waitqueue_entry(&__wait, current); \ > - l_add_wait(&wq, &__wait); \ > - \ > - /* Block all signals (just the non-fatal ones if no timeout). */ \ > - if (info->lwi_on_signal && (__timeout == 0 || __allow_intr)) \ > - __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ > - else \ > - __blocked = cfs_block_sigsinv(0); \ > - \ > - for (;;) { \ > - if (condition) \ > - break; \ > - \ > - set_current_state(TASK_INTERRUPTIBLE); \ > - \ > - if (__timeout == 0) { \ > - schedule(); \ > - } else { \ > - long interval = info->lwi_interval ? \ > - min_t(long, \ > - info->lwi_interval, __timeout) : \ > - __timeout; \ > - long remaining = schedule_timeout(interval);\ > - __timeout = cfs_time_sub(__timeout, \ > - cfs_time_sub(interval, remaining));\ > - if (__timeout == 0) { \ > - if (!info->lwi_on_timeout || \ > - info->lwi_on_timeout(info->lwi_cb_data)) { \ > - ret = -ETIMEDOUT; \ > - break; \ > - } \ > - /* Take signals after the timeout expires. */ \ > - if (info->lwi_on_signal) \ > - (void)cfs_block_sigsinv(LUSTRE_FATAL_SIGS);\ > - } \ > - } \ > - \ > - set_current_state(TASK_RUNNING); \ > - \ > - if (condition) \ > - break; \ > - if (signal_pending(current)) { \ > - if (info->lwi_on_signal && \ > - (__timeout == 0 || __allow_intr)) { \ > - if (info->lwi_on_signal != LWI_ON_SIGNAL_NOOP) \ > - info->lwi_on_signal(info->lwi_cb_data);\ > - ret = -EINTR; \ > - break; \ > - } \ > - /* We have to do this here because some signals */ \ > - /* are not blockable - ie from strace(1). */ \ > - /* In these cases we want to schedule_timeout() */ \ > - /* again, because we don't want that to return */ \ > - /* -EINTR when the RPC actually succeeded. */ \ > - /* the recalc_sigpending() below will deliver the */ \ > - /* signal properly. */ \ > - cfs_clear_sigpending(); \ > - } \ > - } \ > - \ > - cfs_restore_sigs(__blocked); \ > - \ > - remove_wait_queue(&wq, &__wait); \ > -} while (0) > - > -#define l_wait_event(wq, condition, info) \ > -({ \ > - int __ret; \ > - struct l_wait_info *__info = (info); \ > - \ > - __l_wait_event(wq, condition, __info, \ > - __ret, add_wait_queue); \ > - __ret; \ > -}) > - > -#define l_wait_event_exclusive(wq, condition, info) \ > -({ \ > - int __ret; \ > - struct l_wait_info *__info = (info); \ > - \ > - __l_wait_event(wq, condition, __info, \ > - __ret, add_wait_queue_exclusive); \ > - __ret; \ > -}) > - > -#define l_wait_event_exclusive_head(wq, condition, info) \ > -({ \ > - int __ret; \ > - struct l_wait_info *__info = (info); \ > - \ > - __l_wait_event(wq, condition, __info, \ > - __ret, add_wait_queue_exclusive_head); \ > - __ret; \ > -}) > - > /** @} lib */ > > > > > From jsimmons at infradead.org Wed Jan 17 16:05:45 2018 From: jsimmons at infradead.org (James Simmons) Date: Wed, 17 Jan 2018 16:05:45 +0000 (GMT) Subject: [lustre-devel] [PATCH] staging: lustre: lnet: avoid uninitialized return value In-Reply-To: <20180116093511.3197459-1-arnd@arndb.de> References: <20180116093511.3197459-1-arnd@arndb.de> Message-ID: > gcc warns that the latest workqueue change leads to returning an > uninitialized variable: > > drivers/staging/lustre/lnet/selftest/module.c: In function 'lnet_selftest_init': > drivers/staging/lustre/lnet/selftest/module.c:98:10: error: 'rc' may be used uninitialized in this function [-Werror=maybe-uninitialized] > > A failure from alloc_ordered_workqueue() tends to indicate an > out-of-memory condition, so return -ENOMEM in both cases. > The second error path was a preexisting bug, where we always > returned zero after a kvmalloc_array() failure. Reviewed-by: James Simmons > Fixes: 6106c0f82481 ("staging: lustre: lnet: convert selftest to use workqueues") > Signed-off-by: Arnd Bergmann > --- > drivers/staging/lustre/lnet/selftest/module.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/staging/lustre/lnet/selftest/module.c b/drivers/staging/lustre/lnet/selftest/module.c > index aa6bfd5baf2f..c8d999e64f28 100644 > --- a/drivers/staging/lustre/lnet/selftest/module.c > +++ b/drivers/staging/lustre/lnet/selftest/module.c > @@ -95,15 +95,17 @@ lnet_selftest_init(void) > 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()); > lst_test_wq = kvmalloc_array(nscheds, sizeof(lst_test_wq[0]), > GFP_KERNEL | __GFP_ZERO); > - if (!lst_test_wq) > + if (!lst_test_wq) { > + rc = -ENOMEM; > goto error; > + } > > lst_init_step = LST_INIT_WI_TEST; > for (i = 0; i < nscheds; i++) { > @@ -116,6 +118,7 @@ lnet_selftest_init(void) > if (!lst_test_wq[i]) { > CWARN("Failed to create CPU partition affinity WI scheduler %d for LST\n", > i); > + rc = -ENOMEM; > goto error; > } > attrs.nice = 0; > -- > 2.9.0 > > From charlie.olmstead at intel.com Fri Jan 12 17:31:33 2018 From: charlie.olmstead at intel.com (Olmstead, Charlie) Date: Fri, 12 Jan 2018 17:31:33 +0000 Subject: [lustre-devel] Optional test session for lustre-reviews Message-ID: Hello all, We are adding an optional test session to lustre-reviews builds called dne-zfs-part-1. This optional session will only run if the Autotest instance has the capacity to run it immediately (it will not queue up and wait for resources). It runs the same test suites as dne-part-1 but has a ZFS filesystem. Its outcome does not impact the +/-1 sent by Maloo. The ultimate goal is to replace all DNE sessions with dne-zfs sessions. Let me know if you have any questions, Charlie Olmstead -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.dilger at intel.com Fri Jan 19 03:36:43 2018 From: andreas.dilger at intel.com (Dilger, Andreas) Date: Fri, 19 Jan 2018 03:36:43 +0000 Subject: [lustre-devel] [PATCH 6/8] staging: lustre: Fix overlong lines In-Reply-To: <1515691022-22729-7-git-send-email-fabian_huegel@web.de> References: <1515691022-22729-1-git-send-email-fabian_huegel@web.de> <1515691022-22729-7-git-send-email-fabian_huegel@web.de> Message-ID: <00C20AD1-618E-4F27-8DA1-4D6C4339CFFA@intel.com> On Jan 11, 2018, at 10:17, Fabian Huegel wrote: > > Fixed four lines that went over the 80 character limit > to reduce checkpatch warnings. > > Signed-off-by: Fabian Huegel > Signed-off-by: Christoph Volkert > --- > drivers/staging/lustre/lustre/include/obd_class.h | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h > index d195866..06f825b 100644 > --- a/drivers/staging/lustre/lustre/include/obd_class.h > +++ b/drivers/staging/lustre/lustre/include/obd_class.h > @@ -850,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) This only needs a single field moved onto the next line, like: +static inline int obd_pool_add(struct obd_device *obd, char *poolname, + char *ostname) > @@ -861,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) Same. > @@ -997,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); > @@ -1579,7 +1584,8 @@ int class_procfs_init(void); > int class_procfs_clean(void); > > /* prng.c */ > -#define ll_generate_random_uuid(uuid_out) 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)) This looks like it would be better to replace ll_generate_random_uuid() callers with generate_random_uuid(). Cheers, Andreas -- Andreas Dilger Lustre Principal Architect Intel Corporation From joe at perches.com Sat Jan 20 01:53:59 2018 From: joe at perches.com (Joe Perches) Date: Fri, 19 Jan 2018 17:53:59 -0800 Subject: [lustre-devel] [PATCH 1/2] staging: lustre: Fix comment style In-Reply-To: <1516290692-11642-2-git-send-email-fabian_huegel@web.de> References: <20180115150259.GA17991@kroah.com> <1516290692-11642-1-git-send-email-fabian_huegel@web.de> <1516290692-11642-2-git-send-email-fabian_huegel@web.de> Message-ID: <1516413239.14739.0.camel@perches.com> On Thu, 2018-01-18 at 16:51 +0100, Fabian Huegel wrote: > Most multi-line comments started on the first line, but the preferred > linux kernel style is to start multi-line comments on the second line. > Some comments became less readable after the change, so we changed them > to single-line comments. [] > diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h > > @@ -182,7 +179,8 @@ struct config_llog_data { > struct obd_export *cld_mgcexp; > struct mutex cld_lock; > int cld_type; > - unsigned int cld_stopping:1, /* we were told to stop > + unsigned int cld_stopping:1, /* > + * we were told to stop > * watching > */ > cld_lostlock:1; /* lock not requeued */ probably better for both of these to be bool instead of bitfield. From dan.carpenter at oracle.com Mon Jan 22 10:26:14 2018 From: dan.carpenter at oracle.com (Dan Carpenter) Date: Mon, 22 Jan 2018 13:26:14 +0300 Subject: [lustre-devel] [PATCH] staging: lustre: libcfs: Prevent harmless read underflow Message-ID: <20180122102614.GC23912@mwanda> Because this is a post-op instead of a pre-op, then it means we check if knl_buffer[-1] is a space. It doesn't really hurt anything, but it causes a static checker warning so let's fix it. Fixes: d7e09d0397e8 ("staging: add Lustre file system client support") Signed-off-by: Dan Carpenter 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; From gregkh at linuxfoundation.org Mon Jan 22 10:37:45 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 22 Jan 2018 11:37:45 +0100 Subject: [lustre-devel] [PATCH 1/2] staging: lustre: Fix comment style In-Reply-To: <1516413239.14739.0.camel@perches.com> References: <20180115150259.GA17991@kroah.com> <1516290692-11642-1-git-send-email-fabian_huegel@web.de> <1516290692-11642-2-git-send-email-fabian_huegel@web.de> <1516413239.14739.0.camel@perches.com> Message-ID: <20180122103745.GA23996@kroah.com> On Fri, Jan 19, 2018 at 05:53:59PM -0800, Joe Perches wrote: > On Thu, 2018-01-18 at 16:51 +0100, Fabian Huegel wrote: > > Most multi-line comments started on the first line, but the preferred > > linux kernel style is to start multi-line comments on the second line. > > Some comments became less readable after the change, so we changed them > > to single-line comments. > [] > > diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h > > > > @@ -182,7 +179,8 @@ struct config_llog_data { > > struct obd_export *cld_mgcexp; > > struct mutex cld_lock; > > int cld_type; > > - unsigned int cld_stopping:1, /* we were told to stop > > + unsigned int cld_stopping:1, /* > > + * we were told to stop > > * watching > > */ > > cld_lostlock:1; /* lock not requeued */ > > probably better for both of these to be bool > instead of bitfield. That's a change best left for a separate patch :) thanks, greg k-h From gregkh at linuxfoundation.org Mon Jan 22 10:39:24 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Mon, 22 Jan 2018 11:39:24 +0100 Subject: [lustre-devel] [PATCH] staging: lustre: Fix avoid intensive reconnecting for ko2iblnd patch In-Reply-To: <9FC73D3DBECE0941BD2ED069D26863425CE76069@irsmsx110.ger.corp.intel.com> References: <1516114161-27679-1-git-send-email-Dmitry.Eremin@intel.com> <9FC73D3DBECE0941BD2ED069D26863425CE76069@irsmsx110.ger.corp.intel.com> Message-ID: <20180122103924.GB23996@kroah.com> On Tue, Jan 16, 2018 at 06:02:07PM +0000, Eremin, Dmitry wrote: > The logic of the original commit 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") > was assumed conditional free of struct kib_conn if the second argument free_conn in function > kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) is true. But this hunk of code was dropped > from original commit. As result the logic works wrong and current code use struct kib_conn after > free. > > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > > 3317 kiblnd_destroy_conn(conn, !peer); > > ^^^^ Freed always (but should be conditionally) > > 3318 > > 3319 spin_lock_irqsave(lock, flags); > > 3320 if (!peer) > > 3321 continue; > > 3322 > > 3323 conn->ibc_peer = peer; > > ^^^^^^^^^^^^^ Use after free > > 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) > > 3325 list_add_tail(&conn->ibc_list, > > ^^^^^^^^^^^^ > > 3326 &kiblnd_data.kib_reconn_list); > > 3327 else > > 3328 list_add_tail(&conn->ibc_list, > > ^^^^^^^^^^^^ > > 3329 &kiblnd_data.kib_reconn_wait); > > After attached patch this code will use struct kib_conn only when it was not freed. > > Signed-off-by: Dmitry Eremin > --- > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > index 2ebc484..a15a625 100644 > --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > @@ -890,7 +890,8 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) > atomic_dec(&net->ibn_nconns); > } > > - kfree(conn); > + if (free_conn) > + kfree(conn); > } > > int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) This patch needs a real "Fixes:" tag, right? Also, as this was from 4.6, it should go to the stable trees, right? Can you resend this with that info, and then send a follow-on patch to fix this up the way I recommended so that no one is confused in the future? thanks, greg k-h From neilb at suse.com Tue Jan 23 06:27:47 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 23 Jan 2018 17:27:47 +1100 Subject: [lustre-devel] [PATCH] staging: lustre: lnet/selftest: fix compile error on UP build In-Reply-To: <151564360053.21794.4058863911958997341.stgit@noble> References: <151564345630.21794.1667069238139184132.stgit@noble> <151564360053.21794.4058863911958997341.stgit@noble> Message-ID: <87tvvd84yk.fsf@notabene.neil.brown.name> When compiled without CONFIG_SMP, we get a compile error as ->ctb_parts is not defined. There is already a function, cfs_cpt_cpumask(), which will get the cpumask we need, and which handles the UP case by returning a NULL pointer. So use that and handle NULL. Also avoid the #ifdef by allocating a cpumask_var and copying into it, rather than sharing the mask. Reported-by: kbuild test robot Fixes: 6106c0f82481 ("staging: lustre: lnet: convert selftest to use workqueues") Signed-off-by: NeilBrown ctb_parts[i].cpt_cpumask; - #else - cpumask_copy(attrs.cpumask, lnet_cpt_table()->ctb_parts[i].cpt_cpumask); - #endif - attrs.no_numa = false; - apply_workqueue_attrs(lst_test_wq[i], &attrs); + + 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(); -- 2.14.0.rc0.dirty -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 832 bytes Desc: not available URL: From neilb at suse.com Tue Jan 23 06:55:54 2018 From: neilb at suse.com (NeilBrown) Date: Tue, 23 Jan 2018 17:55:54 +1100 Subject: [lustre-devel] [bug report] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: <20180115092657.om2gdrcwlajo2tvi@mwanda> References: <20180115092657.om2gdrcwlajo2tvi@mwanda> Message-ID: <87r2qh83np.fsf@notabene.neil.brown.name> On Mon, Jan 15 2018, Dan Carpenter wrote: > [ This code was already buggy, it's just that Neil's change made it > show up in static analysis. - dan ] Thanks! This bug was introduced by Commit: 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") which added a "free_conn" arg to kiblnd_destroy_conn(), but never used the arg. Presumably it is meant to say "Don't free something", but exactly what should be free and what shouldn't isn't immediately clear. Liang: do you remember what you intended for that arg to do? Thanks, NeilBrown > > Hello NeilBrown, > > The patch 3c88bdbbf919: "staging: lustre: replace simple cases of > LIBCFS_ALLOC with kzalloc." from Jan 9, 2018, leads to the following > static checker warning: > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c:3323 kiblnd_connd() > error: dereferencing freed memory 'conn' > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > 3303 if (!list_empty(&kiblnd_data.kib_connd_zombies)) { > 3304 struct kib_peer *peer = NULL; > 3305 > 3306 conn = list_entry(kiblnd_data.kib_connd_zombies.next, > 3307 struct kib_conn, ibc_list); > 3308 list_del(&conn->ibc_list); > 3309 if (conn->ibc_reconnect) { > 3310 peer = conn->ibc_peer; > 3311 kiblnd_peer_addref(peer); > 3312 } > 3313 > 3314 spin_unlock_irqrestore(lock, flags); > 3315 dropped_lock = 1; > 3316 > 3317 kiblnd_destroy_conn(conn, !peer); > ^^^^ > Freed > > 3318 > 3319 spin_lock_irqsave(lock, flags); > 3320 if (!peer) > 3321 continue; > 3322 > 3323 conn->ibc_peer = peer; > ^^^^^^^^^^^^^^ > Use after free > > 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) > 3325 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ > > 3326 &kiblnd_data.kib_reconn_list); > 3327 else > 3328 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ > > 3329 &kiblnd_data.kib_reconn_wait); > 3330 } > > regards, > dan carpenter -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 832 bytes Desc: not available URL: From liang.zhen at intel.com Tue Jan 23 08:02:49 2018 From: liang.zhen at intel.com (Zhen, Liang) Date: Tue, 23 Jan 2018 08:02:49 +0000 Subject: [lustre-devel] [bug report] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: <87r2qh83np.fsf@notabene.neil.brown.name> References: <20180115092657.om2gdrcwlajo2tvi@mwanda> <87r2qh83np.fsf@notabene.neil.brown.name> Message-ID: Hi there, probably the function name is misleading, but L3317: kiblnd_destroy_conn(conn, !peer); This function will NOT free the connection if peer is NULL, and… L3320: if (!peer) L3321 continue; It means the connection is not freed in L3322 and later. Regards Liang On 23/01/2018, 2:55 PM, "NeilBrown" wrote: On Mon, Jan 15 2018, Dan Carpenter wrote: > [ This code was already buggy, it's just that Neil's change made it > show up in static analysis. - dan ] Thanks! This bug was introduced by Commit: 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") which added a "free_conn" arg to kiblnd_destroy_conn(), but never used the arg. Presumably it is meant to say "Don't free something", but exactly what should be free and what shouldn't isn't immediately clear. Liang: do you remember what you intended for that arg to do? Thanks, NeilBrown > > Hello NeilBrown, > > The patch 3c88bdbbf919: "staging: lustre: replace simple cases of > LIBCFS_ALLOC with kzalloc." from Jan 9, 2018, leads to the following > static checker warning: > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c:3323 kiblnd_connd() > error: dereferencing freed memory 'conn' > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > 3303 if (!list_empty(&kiblnd_data.kib_connd_zombies)) { > 3304 struct kib_peer *peer = NULL; > 3305 > 3306 conn = list_entry(kiblnd_data.kib_connd_zombies.next, > 3307 struct kib_conn, ibc_list); > 3308 list_del(&conn->ibc_list); > 3309 if (conn->ibc_reconnect) { > 3310 peer = conn->ibc_peer; > 3311 kiblnd_peer_addref(peer); > 3312 } > 3313 > 3314 spin_unlock_irqrestore(lock, flags); > 3315 dropped_lock = 1; > 3316 > 3317 kiblnd_destroy_conn(conn, !peer); > ^^^^ > Freed > > 3318 > 3319 spin_lock_irqsave(lock, flags); > 3320 if (!peer) > 3321 continue; > 3322 > 3323 conn->ibc_peer = peer; > ^^^^^^^^^^^^^^ > Use after free > > 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) > 3325 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ > > 3326 &kiblnd_data.kib_reconn_list); > 3327 else > 3328 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ > > 3329 &kiblnd_data.kib_reconn_wait); > 3330 } > > regards, > dan carpenter From liang.zhen at intel.com Tue Jan 23 09:25:41 2018 From: liang.zhen at intel.com (Zhen, Liang) Date: Tue, 23 Jan 2018 09:25:41 +0000 Subject: [lustre-devel] [bug report] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: References: <20180115092657.om2gdrcwlajo2tvi@mwanda> <87r2qh83np.fsf@notabene.neil.brown.name> Message-ID: <4EDC2CF6-F999-4B09-B7CE-71281845F6F6@intel.com> Hi, I just realized the “free_conn” parameter is unused in kernel source, but it’s actually used in the original patch: https://review.whamcloud.com/#/c/17892 , so I think it should be fixed in the kernel. Regards Liang On 23/01/2018, 4:02 PM, "Zhen, Liang" wrote: Hi there, probably the function name is misleading, but L3317: kiblnd_destroy_conn(conn, !peer); This function will NOT free the connection if peer is NULL, and… L3320: if (!peer) L3321 continue; It means the connection is not freed in L3322 and later. Regards Liang On 23/01/2018, 2:55 PM, "NeilBrown" wrote: On Mon, Jan 15 2018, Dan Carpenter wrote: > [ This code was already buggy, it's just that Neil's change made it > show up in static analysis. - dan ] Thanks! This bug was introduced by Commit: 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") which added a "free_conn" arg to kiblnd_destroy_conn(), but never used the arg. Presumably it is meant to say "Don't free something", but exactly what should be free and what shouldn't isn't immediately clear. Liang: do you remember what you intended for that arg to do? Thanks, NeilBrown > > Hello NeilBrown, > > The patch 3c88bdbbf919: "staging: lustre: replace simple cases of > LIBCFS_ALLOC with kzalloc." from Jan 9, 2018, leads to the following > static checker warning: > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c:3323 kiblnd_connd() > error: dereferencing freed memory 'conn' > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > 3303 if (!list_empty(&kiblnd_data.kib_connd_zombies)) { > 3304 struct kib_peer *peer = NULL; > 3305 > 3306 conn = list_entry(kiblnd_data.kib_connd_zombies.next, > 3307 struct kib_conn, ibc_list); > 3308 list_del(&conn->ibc_list); > 3309 if (conn->ibc_reconnect) { > 3310 peer = conn->ibc_peer; > 3311 kiblnd_peer_addref(peer); > 3312 } > 3313 > 3314 spin_unlock_irqrestore(lock, flags); > 3315 dropped_lock = 1; > 3316 > 3317 kiblnd_destroy_conn(conn, !peer); > ^^^^ > Freed > > 3318 > 3319 spin_lock_irqsave(lock, flags); > 3320 if (!peer) > 3321 continue; > 3322 > 3323 conn->ibc_peer = peer; > ^^^^^^^^^^^^^^ > Use after free > > 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) > 3325 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ > > 3326 &kiblnd_data.kib_reconn_list); > 3327 else > 3328 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ > > 3329 &kiblnd_data.kib_reconn_wait); > 3330 } > > regards, > dan carpenter From dan.carpenter at oracle.com Tue Jan 23 09:28:59 2018 From: dan.carpenter at oracle.com (Dan Carpenter) Date: Tue, 23 Jan 2018 12:28:59 +0300 Subject: [lustre-devel] [bug report] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: <4EDC2CF6-F999-4B09-B7CE-71281845F6F6@intel.com> References: <20180115092657.om2gdrcwlajo2tvi@mwanda> <87r2qh83np.fsf@notabene.neil.brown.name> <4EDC2CF6-F999-4B09-B7CE-71281845F6F6@intel.com> Message-ID: <20180123092859.ghhehynmuxstdijv@mwanda> On Tue, Jan 23, 2018 at 09:25:41AM +0000, Zhen, Liang wrote: > Hi, I just realized the “free_conn” parameter is unused in kernel source, but it’s actually used in the original patch: https://review.whamcloud.com/#/c/17892 , so I think it should be fixed in the kernel. > Dmitry already sent a patch for this. regards, dan carpenter From neilb at suse.com Tue Jan 23 22:02:06 2018 From: neilb at suse.com (NeilBrown) Date: Wed, 24 Jan 2018 09:02:06 +1100 Subject: [lustre-devel] [bug report] staging: lustre: replace simple cases of LIBCFS_ALLOC with kzalloc. In-Reply-To: <20180123092859.ghhehynmuxstdijv@mwanda> References: <20180115092657.om2gdrcwlajo2tvi@mwanda> <87r2qh83np.fsf@notabene.neil.brown.name> <4EDC2CF6-F999-4B09-B7CE-71281845F6F6@intel.com> <20180123092859.ghhehynmuxstdijv@mwanda> Message-ID: <87a7x48c9t.fsf@notabene.neil.brown.name> On Tue, Jan 23 2018, Dan Carpenter wrote: > On Tue, Jan 23, 2018 at 09:25:41AM +0000, Zhen, Liang wrote: >> Hi, I just realized the “free_conn” parameter is unused in kernel source, but it’s actually used in the original patch: https://review.whamcloud.com/#/c/17892 , so I think it should be fixed in the kernel. >> > > Dmitry already sent a patch for this. Thanks - I hadn't seen that. Though it seems Greg isn't too happy with the patch yet... unless I failed to find the update too. Hopefully it will get sorted soon. And thanks for finding this bug - it validates the work of converting to more standard interfaces :-) Thanks, NeilBrown -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 832 bytes Desc: not available URL: From dmitry.eremin at intel.com Wed Jan 24 12:45:36 2018 From: dmitry.eremin at intel.com (Dmitry Eremin) Date: Wed, 24 Jan 2018 15:45:36 +0300 Subject: [lustre-devel] [PATCH v2] staging: lustre: Fix avoid intensive reconnecting for ko2iblnd patch In-Reply-To: <20180122103924.GB23996@kroah.com> References: <20180122103924.GB23996@kroah.com> Message-ID: <1516797936-5938-1-git-send-email-dmitry.eremin@intel.com> From: Dmitry Eremin The logic of the original commit 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") was assumed conditional free of struct kib_conn if the second argument free_conn in function kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) is true. But this hunk of code was dropped from original commit. As result the logic works wrong and current code use struct kib_conn after free. > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > 3317 kiblnd_destroy_conn(conn, !peer); > ^^^^ Freed always (but should be conditionally) > 3318 > 3319 spin_lock_irqsave(lock, flags); > 3320 if (!peer) > 3321 continue; > 3322 > 3323 conn->ibc_peer = peer; > ^^^^^^^^^^^^^^ Use after free > 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) > 3325 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ Use after free > 3326 &kiblnd_data.kib_reconn_list); > 3327 else > 3328 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ Use after free > 3329 &kiblnd_data.kib_reconn_wait); After attached patch this code will use struct kib_conn only when it was not freed. Cc: # v4.6 Fixes: 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") Signed-off-by: Dmitry Eremin Signed-off-by: Dmitry Eremin --- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 2ebc484385b3..a15a625ee9b6 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -890,7 +890,8 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) atomic_dec(&net->ibn_nconns); } - kfree(conn); + if (free_conn) + kfree(conn); } int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) -- 1.8.3.1 -------------------------------------------------------------------- Joint Stock Company Intel A/O Registered legal address: Krylatsky Hills Business Park, 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. From dmitry.eremin at intel.com Wed Jan 24 14:14:12 2018 From: dmitry.eremin at intel.com (Dmitry Eremin) Date: Wed, 24 Jan 2018 17:14:12 +0300 Subject: [lustre-devel] [PATCH v3] staging: lustre: separate a connection destroy from free struct kib_conn In-Reply-To: <20180122103924.GB23996@kroah.com> References: <20180122103924.GB23996@kroah.com> Message-ID: <1516803252-14266-1-git-send-email-dmitry.eremin@intel.com> Rewrite the logic of the original commit 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") and move the freeing a struct kib_conn outside of the function kiblnd_destroy_conn(). The freeing of struct kib_conn should be depending on the second argument free_conn of function kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn). If it true the structure should be freed. Fixes: 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") Signed-off-by: Dmitry Eremin --- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 7 +++---- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h | 2 +- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 6 ++++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 2ebc484385b3..ec84edfda271 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -824,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: 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; @@ -889,8 +890,6 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) rdma_destroy_id(cmid); atomic_dec(&net->ibn_nconns); } - - kfree(conn); } int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) 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_stale_conns_locked(struct kib_peer *peer, 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 9b3328c5d1e7..b3e7f28eb978 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c @@ -3314,11 +3314,13 @@ static int kiblnd_resolve_addr(struct rdma_cm_id *cmid, 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) -- 1.8.3.1 -------------------------------------------------------------------- Joint Stock Company Intel A/O Registered legal address: Krylatsky Hills Business Park, 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. From gregkh at linuxfoundation.org Wed Jan 24 14:29:54 2018 From: gregkh at linuxfoundation.org (Greg Kroah-Hartman) Date: Wed, 24 Jan 2018 15:29:54 +0100 Subject: [lustre-devel] [PATCH v3] staging: lustre: separate a connection destroy from free struct kib_conn In-Reply-To: <1516803252-14266-1-git-send-email-dmitry.eremin@intel.com> References: <20180122103924.GB23996@kroah.com> <1516803252-14266-1-git-send-email-dmitry.eremin@intel.com> Message-ID: <20180124142954.GA4658@kroah.com> On Wed, Jan 24, 2018 at 05:14:12PM +0300, Dmitry Eremin wrote: > Rewrite the logic of the original commit 4d99b2581eff ("staging: lustre: avoid > intensive reconnecting for ko2iblnd") and move the freeing a struct kib_conn > outside of the function kiblnd_destroy_conn(). The freeing of struct kib_conn > should be depending on the second argument free_conn of function > kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn). If it true the > structure should be freed. > > Fixes: 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") > Signed-off-by: Dmitry Eremin > --- > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 7 +++---- > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h | 2 +- > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 6 ++++-- > 3 files changed, 8 insertions(+), 7 deletions(-) What changed from version 2 and 1? Always included that below the --- line please. 4th try is a charm? :) thanks, greg k-h From dmitry.eremin at intel.com Thu Jan 25 13:51:04 2018 From: dmitry.eremin at intel.com (Dmitry Eremin) Date: Thu, 25 Jan 2018 16:51:04 +0300 Subject: [lustre-devel] [PATCH v4] staging: lustre: separate a connection destroy from free struct kib_conn In-Reply-To: <20180124142954.GA4658@kroah.com> References: <20180124142954.GA4658@kroah.com> Message-ID: <1516888264-26273-1-git-send-email-dmitry.eremin@intel.com> The logic of the original commit 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") was assumed conditional free of struct kib_conn if the second argument free_conn in function kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) is true. But this hunk of code was dropped from original commit. As result the logic works wrong and current code use struct kib_conn after free. > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > 3317 kiblnd_destroy_conn(conn, !peer); > ^^^^ Freed always (but should be conditionally) > 3318 > 3319 spin_lock_irqsave(lock, flags); > 3320 if (!peer) > 3321 continue; > 3322 > 3323 conn->ibc_peer = peer; > ^^^^^^^^^^^^^^ Use after free > 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) > 3325 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ Use after free > 3326 &kiblnd_data.kib_reconn_list); > 3327 else > 3328 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ Use after free > 3329 &kiblnd_data.kib_reconn_wait); To avoid confusion this fix moved the freeing a struct kib_conn outside of the function kiblnd_destroy_conn() and free as it was intended in original commit. Cc: # v4.6 Fixes: 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") Signed-off-by: Dmitry Eremin --- Changes in v4: - fixed the issue with use after free by moving the freeing a struct kib_conn outside of the function kiblnd_destroy_conn() drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 7 +++---- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h | 2 +- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 6 ++++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 2ebc484385b3..ec84edfda271 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -824,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: 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; @@ -889,8 +890,6 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) rdma_destroy_id(cmid); atomic_dec(&net->ibn_nconns); } - - kfree(conn); } int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) 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_stale_conns_locked(struct kib_peer *peer, 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 9b3328c5d1e7..b3e7f28eb978 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c @@ -3314,11 +3314,13 @@ static int kiblnd_resolve_addr(struct rdma_cm_id *cmid, 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) -- 1.8.3.1 -------------------------------------------------------------------- Joint Stock Company Intel A/O Registered legal address: Krylatsky Hills Business Park, 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. From andreas.dilger at intel.com Fri Jan 26 04:34:07 2018 From: andreas.dilger at intel.com (Dilger, Andreas) Date: Fri, 26 Jan 2018 04:34:07 +0000 Subject: [lustre-devel] [PATCH v4] staging: lustre: separate a connection destroy from free struct kib_conn In-Reply-To: <1516888264-26273-1-git-send-email-dmitry.eremin@intel.com> References: <20180124142954.GA4658@kroah.com> <1516888264-26273-1-git-send-email-dmitry.eremin@intel.com> Message-ID: <33F9CC96-70A5-4B03-9434-64DD37532B29@intel.com> On Jan 25, 2018, at 06:51, Eremin, Dmitry wrote: > > The logic of the original commit 4d99b2581eff ("staging: lustre: avoid > intensive reconnecting for ko2iblnd") was assumed conditional free of > struct kib_conn if the second argument free_conn in function > kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) is true. > But this hunk of code was dropped from original commit. As result the logic > works wrong and current code use struct kib_conn after free. > >> drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c >> 3317 kiblnd_destroy_conn(conn, !peer); >> ^^^^ Freed always (but should be conditionally) >> 3318 >> 3319 spin_lock_irqsave(lock, flags); >> 3320 if (!peer) >> 3321 continue; >> 3322 >> 3323 conn->ibc_peer = peer; >> ^^^^^^^^^^^^^^ Use after free >> 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) >> 3325 list_add_tail(&conn->ibc_list, >> ^^^^^^^^^^^^^^ Use after free >> 3326 &kiblnd_data.kib_reconn_list); >> 3327 else >> 3328 list_add_tail(&conn->ibc_list, >> ^^^^^^^^^^^^^^ Use after free >> 3329 &kiblnd_data.kib_reconn_wait); > > To avoid confusion this fix moved the freeing a struct kib_conn outside of > the function kiblnd_destroy_conn() and free as it was intended in original > commit. > > Cc: # v4.6 > Fixes: 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") > Signed-off-by: Dmitry Eremin Reviewed-by: Andreas Dilger > --- > Changes in v4: > - fixed the issue with use after free by moving the freeing a struct > kib_conn outside of the function kiblnd_destroy_conn() > > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 7 +++---- > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h | 2 +- > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 6 ++++-- > 3 files changed, 8 insertions(+), 7 deletions(-) > > diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > index 2ebc484385b3..ec84edfda271 100644 > --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c > @@ -824,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: > 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; > @@ -889,8 +890,6 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) > rdma_destroy_id(cmid); > atomic_dec(&net->ibn_nconns); > } > - > - kfree(conn); > } > > int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) > 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_stale_conns_locked(struct kib_peer *peer, > 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 9b3328c5d1e7..b3e7f28eb978 100644 > --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > @@ -3314,11 +3314,13 @@ static int kiblnd_resolve_addr(struct rdma_cm_id *cmid, > 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) > -- > 1.8.3.1 > Cheers, Andreas -- Andreas Dilger Lustre Principal Architect Intel Corporation From andreas.dilger at intel.com Sat Jan 27 00:41:35 2018 From: andreas.dilger at intel.com (Dilger, Andreas) Date: Sat, 27 Jan 2018 00:41:35 +0000 Subject: [lustre-devel] [PATCH] staging: lustre: lnet/selftest: fix compile error on UP build In-Reply-To: <87tvvd84yk.fsf@notabene.neil.brown.name> References: <151564345630.21794.1667069238139184132.stgit@noble> <151564360053.21794.4058863911958997341.stgit@noble> <87tvvd84yk.fsf@notabene.neil.brown.name> Message-ID: <37717983-8436-431F-ABCC-365E3425E35C@intel.com> On Jan 22, 2018, at 23:27, NeilBrown wrote: > > When compiled without CONFIG_SMP, we get a compile error > as ->ctb_parts is not defined. > > There is already a function, cfs_cpt_cpumask(), which will get the > cpumask we need, and which handles the UP case by returning a NULL pointer. > So use that and handle NULL. > Also avoid the #ifdef by allocating a cpumask_var and copying > into it, rather than sharing the mask. > > Reported-by: kbuild test robot > Fixes: 6106c0f82481 ("staging: lustre: lnet: convert selftest to use workqueues") > Signed-off-by: NeilBrown Reviewed-by: Andreas Dilger > --- > drivers/staging/lustre/lnet/selftest/module.c | 17 ++++++++--------- > 1 file changed, 8 insertions(+), 9 deletions(-) > > diff --git a/drivers/staging/lustre/lnet/selftest/module.c b/drivers/staging/lustre/lnet/selftest/module.c > index 31a74b48c995..7359aa56d9b3 100644 > --- a/drivers/staging/lustre/lnet/selftest/module.c > +++ b/drivers/staging/lustre/lnet/selftest/module.c > @@ -110,7 +110,8 @@ lnet_selftest_init(void) > 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; > + 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); > @@ -121,14 +122,12 @@ lnet_selftest_init(void) > rc = -ENOMEM; > goto error; > } > - attrs.nice = 0; > - #ifdef CONFIG_CPUMASK_OFFSTACK > - attrs.cpumask = lnet_cpt_table()->ctb_parts[i].cpt_cpumask; > - #else > - cpumask_copy(attrs.cpumask, lnet_cpt_table()->ctb_parts[i].cpt_cpumask); > - #endif > - attrs.no_numa = false; > - apply_workqueue_attrs(lst_test_wq[i], &attrs); > + > + 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(); > -- > 2.14.0.rc0.dirty > Cheers, Andreas -- Andreas Dilger Lustre Principal Architect Intel Corporation From andreas.dilger at intel.com Tue Jan 30 01:49:17 2018 From: andreas.dilger at intel.com (Dilger, Andreas) Date: Tue, 30 Jan 2018 01:49:17 +0000 Subject: [lustre-devel] [PATCH] staging: lustre: lnet: return of an error code should be negative In-Reply-To: <1517117095-12643-1-git-send-email-pundirsumit11@gmail.com> References: <1517117095-12643-1-git-send-email-pundirsumit11@gmail.com> Message-ID: <0FF5C462-31A2-4D8F-9288-EE941D37826B@intel.com> On Jan 27, 2018, at 22:24, Sumit Pundir wrote: > > Return value of error codes should typically be negative. > Issue reported by checkpatch.pl > > Signed-off-by: Sumit Pundir Reviewed-by: Andreas Dilger > --- > drivers/staging/lustre/lnet/selftest/framework.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c > index c7697f6..0ca1e3a 100644 > --- a/drivers/staging/lustre/lnet/selftest/framework.c > +++ b/drivers/staging/lustre/lnet/selftest/framework.c > @@ -187,7 +187,7 @@ sfw_del_session_timer(void) > return 0; > } > > - return EBUSY; /* racing with sfw_session_expired() */ > + return -EBUSY; /* racing with sfw_session_expired() */ > } > > static void > -- > 2.7.4 > Cheers, Andreas -- Andreas Dilger Lustre Principal Architect Intel Corporation From andreas.dilger at intel.com Tue Jan 30 02:04:23 2018 From: andreas.dilger at intel.com (Dilger, Andreas) Date: Tue, 30 Jan 2018 02:04:23 +0000 Subject: [lustre-devel] [PATCH] staging: lustre: llite: replace variable length array In-Reply-To: <20180127214228.26986-1-sven.dziadek@gmx.de> References: <20180127214228.26986-1-sven.dziadek@gmx.de> Message-ID: On Jan 27, 2018, at 14:42, Sven Dziadek wrote: > > The functionality of the removed variable length array is already > implemented by the function xattr_full_name in fs/xattr.c > > This fixes the sparse warning: > warning: Variable length array is used. > > Signed-off-by: Sven Dziadek > --- > drivers/staging/lustre/lustre/llite/xattr.c | 12 ++++-------- > 1 file changed, 4 insertions(+), 8 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c > index 532384c91447..4fd28213c6a1 100644 > --- a/drivers/staging/lustre/lustre/llite/xattr.c > +++ b/drivers/staging/lustre/lustre/llite/xattr.c > @@ -87,7 +87,6 @@ ll_xattr_set_common(const struct xattr_handler *handler, > const char *name, const void *value, size_t size, > int flags) > { > - char fullname[strlen(handler->prefix) + strlen(name) + 1]; > struct ll_sb_info *sbi = ll_i2sbi(inode); > struct ptlrpc_request *req = NULL; > const char *pv = value; > @@ -141,9 +140,8 @@ ll_xattr_set_common(const struct xattr_handler *handler, > return -EPERM; > } > > - sprintf(fullname, "%s%s\n", handler->prefix, name); > - rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), > - valid, fullname, pv, size, 0, flags, > + rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), valid, > + xattr_full_name(handler, name), pv, size, 0, flags, > ll_i2suppgid(inode), &req); Hi Sven, thanks for the patch. Looking at the details of "xattr_full_name()", this seems quite risky. This is essentially returning the pointer _before_ "name" on the assumption that it contains the full "prefix.name" string. IMHO, that is not necessarily a safe assumption to make several layers down in the code. James, I thought you had a patch for this to use kasprintf() instead of the on-stack "fullname" declaration? Cheers, Andreas > if (rc) { > if (rc == -EOPNOTSUPP && handler->flags == XATTR_USER_T) { > @@ -364,7 +362,6 @@ static int ll_xattr_get_common(const struct xattr_handler *handler, > struct dentry *dentry, struct inode *inode, > const char *name, void *buffer, size_t size) > { > - char fullname[strlen(handler->prefix) + strlen(name) + 1]; > struct ll_sb_info *sbi = ll_i2sbi(inode); > #ifdef CONFIG_FS_POSIX_ACL > struct ll_inode_info *lli = ll_i2info(inode); > @@ -411,9 +408,8 @@ static int ll_xattr_get_common(const struct xattr_handler *handler, > if (handler->flags == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode)) > return -ENODATA; > #endif > - sprintf(fullname, "%s%s\n", handler->prefix, name); > - return ll_xattr_list(inode, fullname, handler->flags, buffer, size, > - OBD_MD_FLXATTR); > + return ll_xattr_list(inode, xattr_full_name(handler, name), > + handler->flags, buffer, size, OBD_MD_FLXATTR); > } > > static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size) > -- > 2.11.0 > Cheers, Andreas -- Andreas Dilger Lustre Principal Architect Intel Corporation