From patchwork Thu Feb 27 21:09:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11409815 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 56BD9138D for ; Thu, 27 Feb 2020 21:23:03 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3FE0C246A2 for ; Thu, 27 Feb 2020 21:23:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3FE0C246A2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 3A14021FD46; Thu, 27 Feb 2020 13:21:18 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp3.ccs.ornl.gov (smtp3.ccs.ornl.gov [160.91.203.39]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id BA51321FADA for ; Thu, 27 Feb 2020 13:18:53 -0800 (PST) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id A85611042; Thu, 27 Feb 2020 16:18:14 -0500 (EST) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id A724346A; Thu, 27 Feb 2020 16:18:14 -0500 (EST) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Thu, 27 Feb 2020 16:09:49 -0500 Message-Id: <1582838290-17243-122-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> References: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 121/622] lustre: ptlrpc: new request vs disconnect race X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Alex Zhuravlev new request can race with disconnect-by-idle process. disconnect code detect this state and initiate a new connection. WC-bug-id: https://jira.whamcloud.com/browse/LU-11128 Lustre-commit: 93d20d171c20 ("LU-11128 ptlrpc: new request vs disconnect race") Signed-off-by: Alex Zhuravlev Reviewed-on: https://review.whamcloud.com/32980 Reviewed-by: Mike Pershin Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- fs/lustre/ptlrpc/client.c | 15 ++++++++++----- fs/lustre/ptlrpc/import.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/fs/lustre/ptlrpc/client.c b/fs/lustre/ptlrpc/client.c index 691df1a..7be597c 100644 --- a/fs/lustre/ptlrpc/client.c +++ b/fs/lustre/ptlrpc/client.c @@ -887,6 +887,13 @@ struct ptlrpc_request *__ptlrpc_request_alloc(struct obd_import *imp, struct ptlrpc_request *request; int connect = 0; + request = __ptlrpc_request_alloc(imp, pool); + if (!request) + return NULL; + + /* initiate connection if needed when the import has been + * referenced by the new request to avoid races with disconnect + */ if (unlikely(imp->imp_state == LUSTRE_IMP_IDLE)) { int rc; @@ -904,16 +911,14 @@ struct ptlrpc_request *__ptlrpc_request_alloc(struct obd_import *imp, spin_unlock(&imp->imp_lock); if (connect) { rc = ptlrpc_connect_import(imp); - if (rc < 0) + if (rc < 0) { + ptlrpc_request_free(request); return NULL; + } ptlrpc_pinger_add_import(imp); } } - request = __ptlrpc_request_alloc(imp, pool); - if (!request) - return NULL; - req_capsule_init(&request->rq_pill, request, RCL_CLIENT); req_capsule_set(&request->rq_pill, format); return request; diff --git a/fs/lustre/ptlrpc/import.c b/fs/lustre/ptlrpc/import.c index 73a345f..f59af80 100644 --- a/fs/lustre/ptlrpc/import.c +++ b/fs/lustre/ptlrpc/import.c @@ -1593,13 +1593,39 @@ static int ptlrpc_disconnect_idle_interpret(const struct lu_env *env, void *data, int rc) { struct obd_import *imp = req->rq_import; + int connect = 0; + + DEBUG_REQ(D_HA, req, "inflight=%d, refcount=%d: rc = %d\n", + atomic_read(&imp->imp_inflight), + atomic_read(&imp->imp_refcount), rc); - LASSERT(imp->imp_state == LUSTRE_IMP_CONNECTING); spin_lock(&imp->imp_lock); - IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_IDLE); - memset(&imp->imp_remote_handle, 0, sizeof(imp->imp_remote_handle)); + /* DISCONNECT reply can be late and another connection can just + * be initiated. so we have to abort disconnection. + */ + if (req->rq_import_generation == imp->imp_generation && + imp->imp_state != LUSTRE_IMP_CLOSED) { + LASSERTF(imp->imp_state == LUSTRE_IMP_CONNECTING, + "%s\n", ptlrpc_import_state_name(imp->imp_state)); + imp->imp_state = LUSTRE_IMP_IDLE; + memset(&imp->imp_remote_handle, 0, + sizeof(imp->imp_remote_handle)); + /* take our DISCONNECT into account */ + if (atomic_read(&imp->imp_inflight) > 1) { + imp->imp_generation++; + imp->imp_initiated_at = imp->imp_generation; + IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_NEW); + connect = 1; + } + } spin_unlock(&imp->imp_lock); + if (connect) { + rc = ptlrpc_connect_import(imp); + if (rc >= 0) + ptlrpc_pinger_add_import(imp); + } + return 0; }