mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: Oleg Drokin <oleg.drokin@intel.com>,
	Andreas Dilger <andreas.dilger@intel.com>,
	James Simmons <jsimmons@infradead.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	lustre <lustre-devel@lists.lustre.org>
Subject: [PATCH 07/16] staging: lustre: simplify waiting in ldlm_completion_ast()
Date: Mon, 18 Dec 2017 18:18:00 +1100	[thread overview]
Message-ID: <151358148005.5099.1737285068022718842.stgit@noble> (raw)
In-Reply-To: <151358127190.5099.12792810096274074963.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 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.

So treat the two cases separately. In one, use
l_wait_event_abortable().  In the other, use wait_event_timeout(),
and if the timeout happens - perform the timeout-call function
(opencoded).

Signed-off-by: NeilBrown <neilb@suse.com>
---
 drivers/staging/lustre/lustre/ldlm/ldlm_request.c |   51 +++++++--------------
 1 file changed, 17 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
index a244fa717134..05bec9fd629b 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 int 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;
 
@@ -140,7 +129,7 @@ static int ldlm_expired_completion_wait(void *data)
 
 	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,
@@ -251,10 +240,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 +268,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)) {
+			LDLM_DEBUG(lock, "waiting indefinitely because of NO_TIMEOUT");
+			rc = l_wait_event_abortable(lock->l_waitq,
+						    is_granted_or_cancelled(lock));
+		} else {
+			rc = wait_event_timeout(lock->l_waitq,
+						is_granted_or_cancelled(lock),
+						timeout * HZ);
+			if (rc == 0) {
+				ldlm_expired_completion_wait(lock, imp);
+				rc = -ETIMEDOUT;
+			} else
+				rc = 0;
+		}
 	}
 
 	if (rc) {

  parent reply	other threads:[~2017-12-18  7:19 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-18  7:17 [PATCH SERIES 5: 00/16] staging: lustre: use standard wait_event macros NeilBrown
2017-12-18  7:17 ` [PATCH 03/16] staging: lustre: discard cfs_time_seconds() NeilBrown
2017-12-18  7:17 ` [PATCH 01/16] staging: lustre: discard SVC_SIGNAL and related functions NeilBrown
2017-12-18  7:17 ` [PATCH 04/16] staging: lustre: use wait_event_timeout() where appropriate NeilBrown
2017-12-18 20:23   ` [lustre-devel] " Patrick Farrell
2017-12-18  7:17 ` [PATCH 02/16] staging: lustre: replace simple cases of l_wait_event() with wait_event() NeilBrown
2017-12-18 17:48   ` [lustre-devel] " Patrick Farrell
2017-12-18 21:37     ` NeilBrown
2017-12-18 18:03   ` Patrick Farrell
2017-12-19 10:37     ` Dilger, Andreas
2017-12-19 20:49       ` NeilBrown
2017-12-18  7:18 ` [PATCH 15/16] staging: lustre: use explicit poll loop in ptlrpc_unregister_reply NeilBrown
2017-12-18 21:09   ` [lustre-devel] " Patrick Farrell
2017-12-18  7:18 ` [PATCH 12/16] staging: lustre: use wait_event_timeout in ptlrpcd() NeilBrown
2017-12-18  7:18 ` [PATCH 10/16] staging: lustre: remove back_to_sleep() and use loops NeilBrown
2017-12-18  7:18 ` [PATCH 14/16] staging: lustre: use explicit poll loop in ptlrpc_service_unlink_rqbd NeilBrown
2017-12-18  7:18 ` NeilBrown [this message]
2017-12-18  7:18 ` [PATCH 09/16] staging: lustre: simplify waiting in ptlrpc_invalidate_import() NeilBrown
2017-12-18  7:18 ` [PATCH 08/16] staging: lustre: open code polling loop instead of using l_wait_event() NeilBrown
2017-12-18 20:55   ` [lustre-devel] " Patrick Farrell
2017-12-18  7:18 ` [PATCH 11/16] staging: lustre: make polling loop in ptlrpc_unregister_bulk more obvious NeilBrown
2017-12-18 21:03   ` [lustre-devel] " Patrick Farrell
2017-12-18  7:18 ` [PATCH 06/16] staging: lustre: simplify l_wait_event when intr handler but no timeout NeilBrown
2017-12-18  7:18 ` [PATCH 16/16] staging: lustre: remove l_wait_event from ptlrpc_set_wait NeilBrown
2017-12-18  7:18 ` [PATCH 13/16] staging: lustre: improve waiting in sptlrpc_req_refresh_ctx NeilBrown
2017-12-18  7:18 ` [PATCH 05/16] staging: lustre: introduce and use l_wait_event_abortable() NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=151358148005.5099.1737285068022718842.stgit@noble \
    --to=neilb@suse.com \
    --cc=andreas.dilger@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jsimmons@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lustre-devel@lists.lustre.org \
    --cc=oleg.drokin@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®