From: John Meneghini <jmeneghi@redhat.com>
To: hare@suse.de, kbusch@kernel.org, martin.petersen@oracle.com,
linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org
Cc: bgurney@redhat.com, axboe@kernel.dk, emilne@redhat.com,
gustavoars@kernel.org, hch@lst.de, james.smart@broadcom.com,
jmeneghi@redhat.com, kees@kernel.org,
linux-hardening@vger.kernel.org, njavali@marvell.com,
sagi@grimberg.me
Subject: [PATCH v10 10/11] scsi: scsi_transport_fc: user support for clearing NVME_CTRL_MARGINAL
Date: Thu, 25 Sep 2025 20:01:59 -0400 [thread overview]
Message-ID: <20250926000200.837025-11-jmeneghi@redhat.com> (raw)
In-Reply-To: <20250926000200.837025-1-jmeneghi@redhat.com>
Refactor and fc_rport_set_marginal_state smp safe by holding
`shost->host_lock` around all `rport->port_state` accesses.
Call nvme_fc_modify_rport_fpin_state() when FC_PORTSTATE_MARGINAL is set
or cleared. This allows the user to quickly set or clear the
NVME_CTRL_MARGINAL state from sysfs.
E.g.:
echo "Marginal" > /sys/class/fc_remote_ports/rport-13:0-5/port_state
echo "Online" > /sys/class/fc_remote_ports/rport-13:0-5/port_state
Note: nvme_fc_modify_rport_fpin_state() will only affect rports that
have FC_PORT_ROLE_NVME_TARGET set.
Signed-off-by: John Meneghini <jmeneghi@redhat.com>
---
drivers/scsi/scsi_transport_fc.c | 46 +++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 9 deletions(-)
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 4dc03cbaf3e2..811530037a1e 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -1305,34 +1305,62 @@ static ssize_t fc_rport_set_marginal_state(struct device *dev,
const char *buf, size_t count)
{
struct fc_rport *rport = transport_class_to_rport(dev);
+ struct Scsi_Host *shost = rport_to_shost(rport);
+ u64 local_wwpn = fc_host_port_name(shost);
enum fc_port_state port_state;
int ret = 0;
+ unsigned long flags;
ret = get_fc_port_state_match(buf, &port_state);
if (ret)
return -EINVAL;
- if (port_state == FC_PORTSTATE_MARGINAL) {
+
+ spin_lock_irqsave(shost->host_lock, flags);
+
+ switch (port_state) {
+ case FC_PORTSTATE_MARGINAL:
/*
* Change the state to Marginal only if the
* current rport state is Online
* Allow only Online->Marginal
*/
- if (rport->port_state == FC_PORTSTATE_ONLINE)
+ if (rport->port_state == FC_PORTSTATE_ONLINE) {
rport->port_state = port_state;
- else if (port_state != rport->port_state)
- return -EINVAL;
- } else if (port_state == FC_PORTSTATE_ONLINE) {
+ spin_unlock_irqrestore(shost->host_lock, flags);
+#if (IS_ENABLED(CONFIG_NVME_FC))
+ nvme_fc_modify_rport_fpin_state(local_wwpn,
+ rport->port_name, true);
+#endif
+ return count;
+ }
+ break;
+
+ case FC_PORTSTATE_ONLINE:
/*
* Change the state to Online only if the
* current rport state is Marginal
* Allow only Marginal->Online
*/
- if (rport->port_state == FC_PORTSTATE_MARGINAL)
+ if (rport->port_state == FC_PORTSTATE_MARGINAL) {
rport->port_state = port_state;
- else if (port_state != rport->port_state)
- return -EINVAL;
- } else
+ spin_unlock_irqrestore(shost->host_lock, flags);
+#if (IS_ENABLED(CONFIG_NVME_FC))
+ nvme_fc_modify_rport_fpin_state(local_wwpn,
+ rport->port_name, false);
+#endif
+ return count;
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (port_state != rport->port_state) {
+ spin_unlock_irqrestore(shost->host_lock, flags);
return -EINVAL;
+ }
+
+ spin_unlock_irqrestore(shost->host_lock, flags);
return count;
}
--
2.51.0
next prev parent reply other threads:[~2025-09-26 0:02 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-26 0:01 [PATCH v10 00/11] nvme-fc: FPIN link integrity handling John Meneghini
2025-09-26 0:01 ` [PATCH v10 01/11] fc_els: use 'union fc_tlv_desc' John Meneghini
2025-09-29 17:44 ` Justin Tee
2025-09-30 10:15 ` John Meneghini
2025-09-26 0:01 ` [PATCH v10 02/11] nvme: add NVME_CTRL_MARGINAL flag John Meneghini
2025-09-26 0:01 ` [PATCH v10 03/11] nvme-fc: marginal path handling John Meneghini
2025-10-03 10:15 ` Christoph Hellwig
2025-09-26 0:01 ` [PATCH v10 04/11] nvme: sysfs: emit the marginal path state in show_state() John Meneghini
2025-09-26 0:01 ` [PATCH v10 05/11] nvme-multipath: queue-depth support for marginal paths John Meneghini
2025-09-26 0:01 ` [PATCH v10 06/11] nvme-fc: add nvme_fc_modify_rport_fpin_state() John Meneghini
2025-09-26 0:01 ` [PATCH v10 07/11] scsi: scsi_transport_fc: add fc_host_fpin_set_nvme_rport_marginal() John Meneghini
2025-09-29 17:45 ` Justin Tee
2025-09-30 10:17 ` John Meneghini
2025-09-26 0:01 ` [PATCH v10 08/11] scsi: lpfc: enable FPIN notification for NVMe John Meneghini
2025-09-26 0:01 ` [PATCH v10 09/11] scsi: qla2xxx: " John Meneghini
2025-09-26 0:01 ` John Meneghini [this message]
2025-09-26 0:02 ` [PATCH v10 11/11] scsi: qla2xxx: Fix 2 memcpy field-spanning write issue John Meneghini
2025-09-26 9:00 ` Gustavo A. R. Silva
2025-09-26 9:29 ` Hannes Reinecke
2025-09-30 9:38 ` John Meneghini
2025-09-30 9:24 ` John Meneghini
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=20250926000200.837025-11-jmeneghi@redhat.com \
--to=jmeneghi@redhat.com \
--cc=axboe@kernel.dk \
--cc=bgurney@redhat.com \
--cc=emilne@redhat.com \
--cc=gustavoars@kernel.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=james.smart@broadcom.com \
--cc=kbusch@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=njavali@marvell.com \
--cc=sagi@grimberg.me \
/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