All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] NFSD: Fix problem with nfsd4_scsi_fence_client using the wrong reservation type
@ 2025-10-29 23:28 Dai Ngo
  2025-10-30  5:55 ` Christoph Hellwig
  2025-10-30 13:33 ` Chuck Lever
  0 siblings, 2 replies; 4+ messages in thread
From: Dai Ngo @ 2025-10-29 23:28 UTC (permalink / raw)
  To: chuck.lever, jlayton, neilb, okorniev, tom, hch; +Cc: linux-nfs

The reservation type argument for the pr_preempt call should match the
one used in nfsd4_block_get_device_info_scsi. Additionally, the pr_preempt
operation only needs to be executed once per SCSI target.

Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
 fs/nfsd/blocklayout.c | 17 +++++++++++++++--
 fs/nfsd/state.h       |  1 +
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/blocklayout.c b/fs/nfsd/blocklayout.c
index fde5539cf6a6..4ca6cb420736 100644
--- a/fs/nfsd/blocklayout.c
+++ b/fs/nfsd/blocklayout.c
@@ -340,9 +340,22 @@ nfsd4_scsi_fence_client(struct nfs4_layout_stateid *ls, struct nfsd_file *file)
 {
 	struct nfs4_client *clp = ls->ls_stid.sc_client;
 	struct block_device *bdev = file->nf_file->f_path.mnt->mnt_sb->s_bdev;
+	int error;
+
+	if (ls->ls_fenced)
+		return;
+	ls->ls_fenced = true;
+	error = bdev->bd_disk->fops->pr_ops->pr_preempt(bdev, NFSD_MDS_PR_KEY,
+			nfsd4_scsi_pr_key(clp),
+			PR_EXCLUSIVE_ACCESS_REG_ONLY, true);
+	if (error) {
+		char addr_str[INET6_ADDRSTRLEN];
 
-	bdev->bd_disk->fops->pr_ops->pr_preempt(bdev, NFSD_MDS_PR_KEY,
-			nfsd4_scsi_pr_key(clp), 0, true);
+		ls->ls_fenced = false;
+		rpc_ntop((struct sockaddr *)&clp->cl_addr, addr_str, sizeof(addr_str));
+		dprintk("nfsd: failed to fence client %s error %d\n",
+			addr_str, error);
+	}
 }
 
 const struct nfsd4_layout_ops scsi_layout_ops = {
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 1e736f402426..1de4acc7d539 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -735,6 +735,7 @@ struct nfs4_layout_stateid {
 	stateid_t			ls_recall_sid;
 	bool				ls_recalled;
 	struct mutex			ls_mutex;
+	bool				ls_fenced;
 };
 
 static inline struct nfs4_layout_stateid *layoutstateid(struct nfs4_stid *s)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-10-30 17:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29 23:28 [PATCH 1/1] NFSD: Fix problem with nfsd4_scsi_fence_client using the wrong reservation type Dai Ngo
2025-10-30  5:55 ` Christoph Hellwig
2025-10-30 17:25   ` Dai Ngo
2025-10-30 13:33 ` Chuck Lever

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.