Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1126274rdb; Mon, 19 Feb 2024 05:16:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUk9Ir2mPINhfgg0bBGUg2wAle+zULn8v4LyMRAUmDaI9S91jXZ6coNYw2bmlQ2oTWSGL4JMIf+CuFVxXZZVSYf1djDKWvBeZS2OVDF/A== X-Google-Smtp-Source: AGHT+IG3Rp9mVVypSdgxqVqpMSWfSVfksOVVsM2DIY8qd7nNZyVU7Bej7mGwAESWDQqaVPz1YvhR X-Received: by 2002:a05:6a20:e92:b0:19f:8639:c24f with SMTP id fk18-20020a056a200e9200b0019f8639c24fmr11480548pzb.17.1708348592247; Mon, 19 Feb 2024 05:16:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708348592; cv=pass; d=google.com; s=arc-20160816; b=1BMp9arjUrIuitpp8gnTjJTSw/+at4cGgSJ3SbgGtEcvaSbR0GxTfnydFbXsFOFYvF 495al6rjK2QB5UWZx2gncFabhXd4gicdVaNf8KlfFV8+gxIk9mjaktw/MzKKVos8nkoX kbXWDl9PZGnrd53+fjitFU9JwlSq13nFW38Wxg5DgYcE/Xccrjv+qrxk+GtTdDVoMws6 L7vJqwvKj5ksm0sY78E1Ru9ispPium4DkVVA48gSbDN++MCF4RqPX+gSKq8b4OJQ61H8 RsPK2cBScbwvbfwaDziIzchLMxBWwTBk+4yW6reFN67NRqrWKi+c8yJZqvrVZJSP2f15 L4rA== ARC-Message-Signature: i=2; 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:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=Kw0plqfmld08ZN+nRUAJpaFPy2k7TYS+QVcDgtGzVJs=; fh=RymfTjZCcjoLZ4QyuoC8uFkgj4QNYM/VblY/3wFaCcc=; b=NlQZnicAqoXtCRUQijb6uvSTNqvxCnufA5eURvWoQRj7LE+5Xf1+cS9QSqHMLnlUYW 0UsWqkoZxfnNPL6L9uqeNqcf+4TO/9GhTvTpO4iq/B6d5PJWYAqsx3SK7/xQxnKct64e RTKYL6MabGMc0DeF1ZIv/lKqyibtY+/j5KfC4sEmRNLzWhAeiVExJP+fa8wrtTNzov/h lB5GZ5wqDuICg9VSNccY9xMsg4aL4wzic5ET4X0EsL7z1xod/GaPiRHdmT5qSNHSkozB 41eYRXJd/knTVNVygxpGtX1gWjRPnx0P6R72rDGcYfOiSDyFPrnt8Qw5VgSIRGEqUUGl ruFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Nd9Oazgd; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Nd9Oazgd; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-71392-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71392-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m127-20020a632685000000b005dc351748d1si4489575pgm.660.2024.02.19.05.16.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:16:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71392-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Nd9Oazgd; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Nd9Oazgd; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-71392-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71392-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E56BF281A89 for ; Mon, 19 Feb 2024 13:16:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0894376EB; Mon, 19 Feb 2024 13:15:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Nd9Oazgd"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="U+ArTpo2"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Nd9Oazgd"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="U+ArTpo2" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 17BF2364BF for ; Mon, 19 Feb 2024 13:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708348540; cv=none; b=fttJhxBD5n/wOQZUhEcjpOZMbaF6vpJCzlZ5V+xvE7fQT2CsrKW6No/OMd9IPn8GrZ+XfqouK+kXF8KSbC4jRBUtT9EFMQirnTkaAibjGBCzuOa4lMo3RbWLoRz8bHoE4z+BioQvoqKytpd0bVhRZ9AbkdiQCvfFc38tK8hmk+0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708348540; c=relaxed/simple; bh=X3Az58JsvKbESu1sp7IOz3d8y9yK9nxoBcqPHpva7P4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jv4CzfqdzRH2scD7VcQMcJI54Hfikyo7jlalc9Bo21l8YtxdpCeV4IsiZikHBiZQhmBbIF3aVFMC+REWFbd6L0qrAFq1ZEbRxMuV/M/AOVO3iFbCNGlULTGMTxuOFO9hxWjoWk1ZzJdl+61qszCd/YNaa7c2YhbSolcsvsnB/qQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=Nd9Oazgd; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=U+ArTpo2; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=Nd9Oazgd; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=U+ArTpo2; arc=none smtp.client-ip=195.135.223.131 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 [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-out2.suse.de (Postfix) with ESMTPS id 4C47C1FD13; Mon, 19 Feb 2024 13:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708348537; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kw0plqfmld08ZN+nRUAJpaFPy2k7TYS+QVcDgtGzVJs=; b=Nd9Oazgday0UO08JBR2ybLpAzJpQrsEhi8OiMeccEmfa+BMD1lqyEBkf+Ky5aFYOzwBxc4 P89OlEbNfXONfQTLl0dyIt7NMs7QlxYEVXpDHbBt5tmQKMk6BHGkOHKZb5uOgDdR4h/cjB KAWBveB9N2r6iZ23joTU6fP0owYb1Qc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708348537; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kw0plqfmld08ZN+nRUAJpaFPy2k7TYS+QVcDgtGzVJs=; b=U+ArTpo2meRc1JPpK2wsDnYQKQUC+GryXFRr7MUq3pnMfOwSTKPWdaY6WiFPWxntnW2hJG 4TZMlsfUaKhKjQDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708348537; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kw0plqfmld08ZN+nRUAJpaFPy2k7TYS+QVcDgtGzVJs=; b=Nd9Oazgday0UO08JBR2ybLpAzJpQrsEhi8OiMeccEmfa+BMD1lqyEBkf+Ky5aFYOzwBxc4 P89OlEbNfXONfQTLl0dyIt7NMs7QlxYEVXpDHbBt5tmQKMk6BHGkOHKZb5uOgDdR4h/cjB KAWBveB9N2r6iZ23joTU6fP0owYb1Qc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708348537; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kw0plqfmld08ZN+nRUAJpaFPy2k7TYS+QVcDgtGzVJs=; b=U+ArTpo2meRc1JPpK2wsDnYQKQUC+GryXFRr7MUq3pnMfOwSTKPWdaY6WiFPWxntnW2hJG 4TZMlsfUaKhKjQDQ== 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 3A4E0139C6; Mon, 19 Feb 2024 13:15:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id CTrGDHlU02UTAwAAn2gu4w (envelope-from ); Mon, 19 Feb 2024 13:15:37 +0000 From: Daniel Wagner To: James Smart Cc: Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner Subject: [PATCH v1 6/6] nvme-fc: wait for connect attempt to finish Date: Mon, 19 Feb 2024 14:15:31 +0100 Message-ID: <20240219131531.15134-7-dwagner@suse.de> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240219131531.15134-1-dwagner@suse.de> References: <20240219131531.15134-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 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [4.89 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_RATELIMIT(0.00)[to_ip_from(RL7u6ok1g4a6hhe6aduz96x8er)]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.01)[47.55%] X-Spam-Level: **** X-Spam-Score: 4.89 X-Spam-Flag: NO The FC transport offloads the connect attempt to a workqueue. Thus userspace is not able to wait on the result. Thus, allow userspace to wait on the connect result by honnering the 'connect_sync' connect option. Signed-off-by: Daniel Wagner --- drivers/nvme/host/fc.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index 7627d10a5812..744f71a71823 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -169,6 +169,7 @@ struct nvme_fc_ctrl { struct work_struct ioerr_work; struct delayed_work connect_work; + struct completion connect_completion; struct kref ref; unsigned long flags; @@ -803,6 +804,7 @@ nvme_fc_ctrl_connectivity_loss(struct nvme_fc_ctrl *ctrl) dev_warn(ctrl->ctrl.device, "NVME-FC{%d}: Couldn't schedule reset.\n", ctrl->cnum); + complete(&ctrl->connect_completion); nvme_fc_ctrl_put(ctrl); } break; @@ -871,6 +873,7 @@ nvme_fc_unregister_remoteport(struct nvme_fc_remote_port *portptr) dev_warn(ctrl->ctrl.device, "NVME-FC{%d}: controller connectivity lost.\n", ctrl->cnum); + complete(&ctrl->connect_completion); nvme_fc_ctrl_put(ctrl); } else nvme_fc_ctrl_connectivity_loss(ctrl); @@ -3326,6 +3329,7 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status) ctrl->cnum, min_t(int, portptr->dev_loss_tmo, (ctrl->ctrl.opts->max_reconnects * ctrl->ctrl.opts->reconnect_delay))); + complete(&ctrl->connect_completion); nvme_fc_ctrl_put(ctrl); } } @@ -3385,10 +3389,12 @@ nvme_fc_connect_ctrl_work(struct work_struct *work) ret = nvme_fc_create_association(ctrl); if (ret) nvme_fc_reconnect_or_delete(ctrl, ret); - else + else { dev_info(ctrl->ctrl.device, "NVME-FC{%d}: controller connect complete\n", ctrl->cnum); + complete(&ctrl->connect_completion); + } } @@ -3494,6 +3500,7 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts, INIT_WORK(&ctrl->ctrl.reset_work, nvme_fc_reset_ctrl_work); INIT_DELAYED_WORK(&ctrl->connect_work, nvme_fc_connect_ctrl_work); + init_completion(&ctrl->connect_completion); INIT_WORK(&ctrl->ioerr_work, nvme_fc_ctrl_ioerr_work); spin_lock_init(&ctrl->lock); @@ -3541,6 +3548,9 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts, list_add_tail(&ctrl->ctrl_list, &rport->ctrl_list); spin_unlock_irqrestore(&rport->lock, flags); + if (opts->connect_sync) + nvme_fc_ctrl_get(ctrl); + if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_RESETTING) || !nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) { dev_err(ctrl->ctrl.device, @@ -3557,6 +3567,19 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts, flush_delayed_work(&ctrl->connect_work); + if (opts->connect_sync) { + enum nvme_ctrl_state state; + + wait_for_completion(&ctrl->connect_completion); + state = nvme_ctrl_state(&ctrl->ctrl); + nvme_fc_ctrl_put(ctrl); + + if (state != NVME_CTRL_LIVE) { + /* Cleanup is handled by the connect state machine */ + return ERR_PTR(-EIO); + } + } + dev_info(ctrl->ctrl.device, "NVME-FC{%d}: new ctrl: NQN \"%s\", hostnqn: %s\n", ctrl->cnum, nvmf_ctrl_subsysnqn(&ctrl->ctrl), opts->host->nqn); @@ -3913,6 +3936,7 @@ nvme_fc_delete_controllers(struct nvme_fc_rport *rport) dev_warn(ctrl->ctrl.device, "NVME-FC{%d}: transport unloading: deleting ctrl\n", ctrl->cnum); + complete(&ctrl->connect_completion); nvme_fc_ctrl_put(ctrl); } spin_unlock(&rport->lock); -- 2.43.1