Received: by 2002:a05:7412:8d06:b0:f9:332d:97f1 with SMTP id bj6csp21449rdb; Mon, 18 Dec 2023 07:56:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFW6i5KItMDs1jjW9SBOLDXGcE1Wm2gS7kszePiTmC+vNM/UJd2qk5SBuyg1sDFcT7GyBC9 X-Received: by 2002:a17:906:74c2:b0:a23:30ab:d081 with SMTP id z2-20020a17090674c200b00a2330abd081mr1142818ejl.91.1702914965883; Mon, 18 Dec 2023 07:56:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914965; cv=none; d=google.com; s=arc-20160816; b=pfRHQuocSo6hj0+0eF3IW21/Es83U8bmHHQW0//uYdNcHVY8qtuCIKxn3vUUhqTrg4 jSQLCjGPcm/ApDNErWOv/aKlRGGR5pJthHwdMq4UasgBjhwXGaUV4W0pB2QFr74CuAdJ Ra3xTdolBqZZLVFNARzJvmtyeA4rRTxAKr7k56CCEnwbONva6O7Sx/z+VDpCUlMzMKJH +a0/+VcXKPR9D4rIx996ddqcAmey7gTopxrqJoqcUUNCVWaFUmGnyUTGQVjhfg5i8yjC ApW1+UKVbi2HcGDx9pyY/QGAVjofq2vXBL+dj7XFNCq7Ybb3SqfYNXNGk2R5l89NpeDz sKhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=XCpq8w414a7BDblV4IDtR9Mt7GInJ9kRHufQbtJxaVQ=; fh=3QIVKsEmsld8rvcEkMSr/XDw53o2lrGJeYcvS7FhzFk=; b=JqTWGGl7cnbhXdsURqzqlVJSt/v5VKA23qC5WmlgH2uWDMIMnH57SgwZQo0C4ZD0Xo 0P8hQBwFY329aFUsYIEOo9sCY9Tk8VkRHU8UGOMOAMimOfrSojfxpcnbqn6MRk9aTjX4 eB9bb3rGYeXuQydEHRv9ekNGfiqDkygrCmX7Q2dBMPZ6o5Y2C0QaViXMMUKcsSg4ZFMK SD9v8vgsNwV/CB4u/gJO9CIOTEWTcgNF2ZgcNsnDmj1Q7/QPUKIq5T8uteFkAOsX302v ak5V+RWp2bm0IJ1gcRkaSsIZLcYRqN7psdkcdvUSo29VTM2MheYN4lXfYEAOAaFlaFUi A2UQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-3980-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3980-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bl20-20020a170906c25400b00a1b75f599ccsi10210684ejb.598.2023.12.18.07.56.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:56:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3980-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-3980-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3980-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DAFBC1F267AC for ; Mon, 18 Dec 2023 15:50:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A71749899; Mon, 18 Dec 2023 15:47:10 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E6073A1D0 for ; Mon, 18 Dec 2023 15:47:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B729621F89; Mon, 18 Dec 2023 15:47:06 +0000 (UTC) Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id A811913BC8; Mon, 18 Dec 2023 15:47:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id NjsuKHppgGUXfwAAn2gu4w (envelope-from ); Mon, 18 Dec 2023 15:47:06 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Sagi Grimberg , Keith Busch , James Smart , Hannes Reinecke , Daniel Wagner Subject: [PATCH v3 06/16] nvme-fc: Do not wait in vain when unloading module Date: Mon, 18 Dec 2023 16:30:54 +0100 Message-ID: <20231218153105.12717-7-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218153105.12717-1-dwagner@suse.de> References: <20231218153105.12717-1-dwagner@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: -4.00 X-Rspamd-Queue-Id: B729621F89 The module unload code will wait for a controller to be delete even when there is no controller and we wait for completion forever to happen. Thus only wait for the completion when there is a controller which needs to be removed. Signed-off-by: Daniel Wagner --- drivers/nvme/host/fc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index 15dc9dfe88a9..69f7943c5056 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -3947,10 +3947,11 @@ static int __init nvme_fc_init_module(void) return ret; } -static void +static bool nvme_fc_delete_controllers(struct nvme_fc_rport *rport) { struct nvme_fc_ctrl *ctrl; + bool cleanup = false; spin_lock(&rport->lock); list_for_each_entry(ctrl, &rport->ctrl_list, ctrl_list) { @@ -3958,21 +3959,28 @@ nvme_fc_delete_controllers(struct nvme_fc_rport *rport) "NVME-FC{%d}: transport unloading: deleting ctrl\n", ctrl->cnum); nvme_delete_ctrl(&ctrl->ctrl); + cleanup = true; } spin_unlock(&rport->lock); + + return cleanup; } -static void +static bool nvme_fc_cleanup_for_unload(void) { struct nvme_fc_lport *lport; struct nvme_fc_rport *rport; + bool cleanup = false; list_for_each_entry(lport, &nvme_fc_lport_list, port_list) { list_for_each_entry(rport, &lport->endp_list, endp_list) { - nvme_fc_delete_controllers(rport); + if (nvme_fc_delete_controllers(rport)) + cleanup = true; } } + + return cleanup; } static void __exit nvme_fc_exit_module(void) @@ -3982,10 +3990,8 @@ static void __exit nvme_fc_exit_module(void) spin_lock_irqsave(&nvme_fc_lock, flags); nvme_fc_waiting_to_unload = true; - if (!list_empty(&nvme_fc_lport_list)) { - need_cleanup = true; - nvme_fc_cleanup_for_unload(); - } + if (!list_empty(&nvme_fc_lport_list)) + need_cleanup = nvme_fc_cleanup_for_unload(); spin_unlock_irqrestore(&nvme_fc_lock, flags); if (need_cleanup) { pr_info("%s: waiting for ctlr deletes\n", __func__); -- 2.43.0