Skip to contentSkip to conversation

PNFS fix dangling DS mount

PATCH In review Olga Kornievskaia 4 participants 6 messages Jun 30, 2017 – Jul 21, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 PNFS fix dangling DS mount

There is a regression by commit 8d40b0f14846 ("NFS filelayout:call GETDEVICEINFO after pnfs_layout_process completes"). It leaves the DS mount dangling.

Previously, filelayout_alloc_sec() would call filelayout_check_layout() which would call nfs4_find_get_deviceid which ups the count on the device_id. It's only called once and it's matched by the filelayout_free_lseg() that calls nfs4_fl_put_deviceid().

After that patch, each read/write ends up calling nfs4_find_get_deviceid and there is no balance for that. Instead, do nfs4_fl_put_deviceid() in the filelayout's .pg_cleanup and remove it from filelayout_free_lseg.

But we still need a reference to hold over the lifetime of the segment. For every new lseg that's created we need to take a reference on deviceid that uses it. It will be released in the "free_lseg" routine.

---
 fs/nfs/filelayout/filelayout.c         | 21 +++++++++++++++++----
 fs/nfs/flexfilelayout/flexfilelayout.c |  9 ++++++---
 fs/nfs/pnfs.c                          | 13 ++++++++++---
 fs/nfs/pnfs.h                          |  3 ++-
 4 files changed, 35 insertions(+), 11 deletions(-)
fs/nfs/filelayout/filelayout.c +17 -4
index 1cf85d6..86d694e 100644
@@ -909,9 +909,10 @@ static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
 	struct pnfs_layout_hdr *lo;
 	struct nfs4_filelayout_segment *fl;
 	int status;
+	bool new_layout = false;
 
 	lseg = pnfs_update_layout(ino, ctx, pos, count, iomode, strict_iomode,
-				  gfp_flags);
+				  gfp_flags, &new_layout);
 	if (!lseg)
 		lseg = ERR_PTR(-ENOMEM);
 	if (IS_ERR(lseg))
@@ -924,7 +925,8 @@ static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
 	if (status) {
 		pnfs_put_lseg(lseg);
 		lseg = ERR_PTR(status);
-	}
+	} else if (new_layout)
+		nfs4_get_deviceid(&fl->dsaddr->id_node);
 out:
 	return lseg;
 }
@@ -991,18 +993,29 @@ static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
 	nfs_pageio_reset_write_mds(pgio);
 }
 
+static void filelayout_pg_cleanup(struct nfs_pageio_descriptor *desc)
+{
+	if (desc->pg_lseg) {
+		struct nfs4_filelayout_segment *fl =
+			FILELAYOUT_LSEG(desc->pg_lseg);
+
+		nfs4_fl_put_deviceid(fl->dsaddr);
+	}
+	pnfs_generic_pg_cleanup(desc);
+}
+
 static const struct nfs_pageio_ops filelayout_pg_read_ops = {
 	.pg_init = filelayout_pg_init_read,
 	.pg_test = filelayout_pg_test,
 	.pg_doio = pnfs_generic_pg_readpages,
-	.pg_cleanup = pnfs_generic_pg_cleanup,
+	.pg_cleanup = filelayout_pg_cleanup,
 };
 
 static const struct nfs_pageio_ops filelayout_pg_write_ops = {
 	.pg_init = filelayout_pg_init_write,
 	.pg_test = filelayout_pg_test,
 	.pg_doio = pnfs_generic_pg_writepages,
-	.pg_cleanup = pnfs_generic_pg_cleanup,
+	.pg_cleanup = filelayout_pg_cleanup,
 };
 
 static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
fs/nfs/flexfilelayout/flexfilelayout.c +6 -3
index 23542dc..53a4a19 100644
@@ -820,7 +820,8 @@ static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout)
 					   NFS4_MAX_UINT64,
 					   IOMODE_READ,
 					   strict_iomode,
-					   GFP_KERNEL);
+					   GFP_KERNEL,
+					   NULL);
 	if (IS_ERR(pgio->pg_lseg)) {
 		pgio->pg_error = PTR_ERR(pgio->pg_lseg);
 		pgio->pg_lseg = NULL;
@@ -904,7 +905,8 @@ static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout)
 						   NFS4_MAX_UINT64,
 						   IOMODE_RW,
 						   false,
-						   GFP_NOFS);
+						   GFP_NOFS,
+						   NULL);
 		if (IS_ERR(pgio->pg_lseg)) {
 			pgio->pg_error = PTR_ERR(pgio->pg_lseg);
 			pgio->pg_lseg = NULL;
@@ -960,7 +962,8 @@ static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout)
 						   NFS4_MAX_UINT64,
 						   IOMODE_RW,
 						   false,
-						   GFP_NOFS);
+						   GFP_NOFS,
+						   NULL);
 		if (IS_ERR(pgio->pg_lseg)) {
 			pgio->pg_error = PTR_ERR(pgio->pg_lseg);
 			pgio->pg_lseg = NULL;
fs/nfs/pnfs.c +10 -3
index c383d09..fb011c6 100644
@@ -1698,7 +1698,8 @@ struct pnfs_layout_segment *
 		   u64 count,
 		   enum pnfs_iomode iomode,
 		   bool strict_iomode,
-		   gfp_t gfp_flags)
+		   gfp_t gfp_flags,
+		   bool *new)
 {
 	struct pnfs_layout_range arg = {
 		.iomode = iomode,
@@ -1764,8 +1765,12 @@ struct pnfs_layout_segment *
 	if (lseg) {
 		trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg,
 				PNFS_UPDATE_LAYOUT_FOUND_CACHED);
+		if (new)
+			*new = false;
 		goto out_unlock;
 	}
+	if (new)
+		*new = true;
 
 	if (!nfs4_valid_open_stateid(ctx->state)) {
 		trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg,
@@ -2126,7 +2131,8 @@ void pnfs_error_mark_layout_for_return(struct inode *inode,
 						   rd_size,
 						   IOMODE_READ,
 						   false,
-						   GFP_KERNEL);
+						   GFP_KERNEL,
+						   NULL);
 		if (IS_ERR(pgio->pg_lseg)) {
 			pgio->pg_error = PTR_ERR(pgio->pg_lseg);
 			pgio->pg_lseg = NULL;
@@ -2153,7 +2159,8 @@ void pnfs_error_mark_layout_for_return(struct inode *inode,
 						   wb_size,
 						   IOMODE_RW,
 						   false,
-						   GFP_NOFS);
+						   GFP_NOFS,
+						   NULL);
 		if (IS_ERR(pgio->pg_lseg)) {
 			pgio->pg_error = PTR_ERR(pgio->pg_lseg);
 			pgio->pg_lseg = NULL;
fs/nfs/pnfs.h +2 -1
index 99731e3..978fab0 100644
@@ -291,7 +291,8 @@ struct pnfs_layout_segment *pnfs_update_layout(struct inode *ino,
 					       u64 count,
 					       enum pnfs_iomode iomode,
 					       bool strict_iomode,
-					       gfp_t gfp_flags);
+					       gfp_t gfp_flags,
+					       bool *new);
 void pnfs_layoutreturn_free_lsegs(struct pnfs_layout_hdr *lo,
 		const nfs4_stateid *arg_stateid,
 		const struct pnfs_layout_range *range,
Signature · 1 line
1.8.3.1
Tested-by on v3 1/1
#1 lore raw
Quoted 13 lines · Olga Kornievskaia

There is a regression by commit 8d40b0f14846 ("NFS filelayout:call GETDEVICEINFO after pnfs_layout_process completes"). It leaves the DS mount dangling.

Previously, filelayout_alloc_sec() would call filelayout_check_layout() which would call nfs4_find_get_deviceid which ups the count on the device_id. It's only called once and it's matched by the filelayout_free_lseg() that calls nfs4_fl_put_deviceid().

After that patch, each read/write ends up calling nfs4_find_get_deviceid and there is no balance for that. Instead, do nfs4_fl_put_deviceid() in the filelayout's .pg_cleanup and remove it from filelayout_free_lseg.

Quoted 5 lines

But we still need a reference to hold over the lifetime of the segment. For every new lseg that's created we need to take a reference on deviceid that uses it. It will be released in the "free_lseg" routine.

steved.

Quoted 161 lines
---
 fs/nfs/filelayout/filelayout.c         | 21 +++++++++++++++++----
 fs/nfs/flexfilelayout/flexfilelayout.c |  9 ++++++---
 fs/nfs/pnfs.c                          | 13 ++++++++++---
 fs/nfs/pnfs.h                          |  3 ++-
 4 files changed, 35 insertions(+), 11 deletions(-)
fs/nfs/filelayout/filelayout.c +17 -4
index 1cf85d6..86d694e 100644
@@ -909,9 +909,10 @@ static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
 	struct pnfs_layout_hdr *lo;
 	struct nfs4_filelayout_segment *fl;
 	int status;
+	bool new_layout = false;
 
 	lseg = pnfs_update_layout(ino, ctx, pos, count, iomode, strict_iomode,
-				  gfp_flags);
+				  gfp_flags, &new_layout);
 	if (!lseg)
 		lseg = ERR_PTR(-ENOMEM);
 	if (IS_ERR(lseg))
@@ -924,7 +925,8 @@ static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
 	if (status) {
 		pnfs_put_lseg(lseg);
 		lseg = ERR_PTR(status);
-	}
+	} else if (new_layout)
+		nfs4_get_deviceid(&fl->dsaddr->id_node);
 out:
 	return lseg;
 }
@@ -991,18 +993,29 @@ static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
 	nfs_pageio_reset_write_mds(pgio);
 }
 
+static void filelayout_pg_cleanup(struct nfs_pageio_descriptor *desc)
+{
+	if (desc->pg_lseg) {
+		struct nfs4_filelayout_segment *fl =
+			FILELAYOUT_LSEG(desc->pg_lseg);
+
+		nfs4_fl_put_deviceid(fl->dsaddr);
+	}
+	pnfs_generic_pg_cleanup(desc);
+}
+
 static const struct nfs_pageio_ops filelayout_pg_read_ops = {
 	.pg_init = filelayout_pg_init_read,
 	.pg_test = filelayout_pg_test,
 	.pg_doio = pnfs_generic_pg_readpages,
-	.pg_cleanup = pnfs_generic_pg_cleanup,
+	.pg_cleanup = filelayout_pg_cleanup,
 };
 
 static const struct nfs_pageio_ops filelayout_pg_write_ops = {
 	.pg_init = filelayout_pg_init_write,
 	.pg_test = filelayout_pg_test,
 	.pg_doio = pnfs_generic_pg_writepages,
-	.pg_cleanup = pnfs_generic_pg_cleanup,
+	.pg_cleanup = filelayout_pg_cleanup,
 };
 
 static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
fs/nfs/flexfilelayout/flexfilelayout.c +6 -3
index 23542dc..53a4a19 100644
@@ -820,7 +820,8 @@ static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout)
 					   NFS4_MAX_UINT64,
 					   IOMODE_READ,
 					   strict_iomode,
-					   GFP_KERNEL);
+					   GFP_KERNEL,
+					   NULL);
 	if (IS_ERR(pgio->pg_lseg)) {
 		pgio->pg_error = PTR_ERR(pgio->pg_lseg);
 		pgio->pg_lseg = NULL;
@@ -904,7 +905,8 @@ static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout)
 						   NFS4_MAX_UINT64,
 						   IOMODE_RW,
 						   false,
-						   GFP_NOFS);
+						   GFP_NOFS,
+						   NULL);
 		if (IS_ERR(pgio->pg_lseg)) {
 			pgio->pg_error = PTR_ERR(pgio->pg_lseg);
 			pgio->pg_lseg = NULL;
@@ -960,7 +962,8 @@ static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout)
 						   NFS4_MAX_UINT64,
 						   IOMODE_RW,
 						   false,
-						   GFP_NOFS);
+						   GFP_NOFS,
+						   NULL);
 		if (IS_ERR(pgio->pg_lseg)) {
 			pgio->pg_error = PTR_ERR(pgio->pg_lseg);
 			pgio->pg_lseg = NULL;
fs/nfs/pnfs.c +10 -3
index c383d09..fb011c6 100644
@@ -1698,7 +1698,8 @@ struct pnfs_layout_segment *
 		   u64 count,
 		   enum pnfs_iomode iomode,
 		   bool strict_iomode,
-		   gfp_t gfp_flags)
+		   gfp_t gfp_flags,
+		   bool *new)
 {
 	struct pnfs_layout_range arg = {
 		.iomode = iomode,
@@ -1764,8 +1765,12 @@ struct pnfs_layout_segment *
 	if (lseg) {
 		trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg,
 				PNFS_UPDATE_LAYOUT_FOUND_CACHED);
+		if (new)
+			*new = false;
 		goto out_unlock;
 	}
+	if (new)
+		*new = true;
 
 	if (!nfs4_valid_open_stateid(ctx->state)) {
 		trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg,
@@ -2126,7 +2131,8 @@ void pnfs_error_mark_layout_for_return(struct inode *inode,
 						   rd_size,
 						   IOMODE_READ,
 						   false,
-						   GFP_KERNEL);
+						   GFP_KERNEL,
+						   NULL);
 		if (IS_ERR(pgio->pg_lseg)) {
 			pgio->pg_error = PTR_ERR(pgio->pg_lseg);
 			pgio->pg_lseg = NULL;
@@ -2153,7 +2159,8 @@ void pnfs_error_mark_layout_for_return(struct inode *inode,
 						   wb_size,
 						   IOMODE_RW,
 						   false,
-						   GFP_NOFS);
+						   GFP_NOFS,
+						   NULL);
 		if (IS_ERR(pgio->pg_lseg)) {
 			pgio->pg_error = PTR_ERR(pgio->pg_lseg);
 			pgio->pg_lseg = NULL;
fs/nfs/pnfs.h +2 -1
index 99731e3..978fab0 100644
@@ -291,7 +291,8 @@ struct pnfs_layout_segment *pnfs_update_layout(struct inode *ino,
 					       u64 count,
 					       enum pnfs_iomode iomode,
 					       bool strict_iomode,
-					       gfp_t gfp_flags);
+					       gfp_t gfp_flags,
+					       bool *new);
 void pnfs_layoutreturn_free_lsegs(struct pnfs_layout_hdr *lo,
 		const nfs4_stateid *arg_stateid,
 		const struct pnfs_layout_range *range,
#2 lore raw
In reply to Olga Kornievskaia

Hi Olga,

Apologies for missing this patch. It was hiding in my 'linux-fsdevel' mailbox, so I didn't recognise it as a NFS patch.

Quoted 16 lines · Olga Kornievskaia

There is a regression by commit 8d40b0f14846 ("NFS filelayout:call GETDEVICEINFO after pnfs_layout_process completes"). It leaves the DS mount dangling.

Previously, filelayout_alloc_sec() would call filelayout_check_layout()
which would call nfs4_find_get_deviceid which ups the count on the device_id. It's only called once and it's matched by the filelayout_free_lseg() that calls nfs4_fl_put_deviceid().

After that patch, each read/write ends up calling nfs4_find_get_deviceid
and there is no balance for that. Instead, do nfs4_fl_put_deviceid() in the filelayout's .pg_cleanup and remove it from filelayout_free_lseg.

Quoted 5 lines

But we still need a reference to hold over the lifetime of the segment.
For every new lseg that's created we need to take a reference on deviceid
that uses it. It will be released in the "free_lseg" routine.

This is what I'm not understanding. If you have a reference in the layout segment, then why do you need to call nfs4_find_get_deviceid() in the read/write code?

Isn't it sufficient to change the "pg_init" calls to check whether or not the struct nfs4_filelayout_segment has set a value for dsaddr (that needs to be done with care to avoid races - cmpxchg() is your friend), and then rely on that reference being set for the remainder of the layout segment lifetime?

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, PrimaryData
[email protected]
#3 lore raw
Quoted 2 lines

On Jul 20, 2017, at 3:56 PM, Trond Myklebust <[email protected]> =

Quoted 6 lines · wrote:

=20
Hi Olga,
=20
Apologies for missing this patch. It was hiding in my 'linux-fsdevel' mailbox, so I didn't recognise it as a NFS patch.
=20

Yeah after I mailed it out I realized I cc-ed fsdevel incorrectly.

Quoted 22 lines · Olga Kornievskaia
Quoted 13 lines

There is a regression by commit 8d40b0f14846 ("NFS filelayout:call GETDEVICEINFO after pnfs_layout_process completes"). It leaves the DS mount dangling.
=20
Previously, filelayout_alloc_sec() would call filelayout_check_layout()
which would call nfs4_find_get_deviceid which ups the count on the device_id. It's only called once and it's matched by the filelayout_free_lseg() that calls nfs4_fl_put_deviceid(). =20
After that patch, each read/write ends up calling nfs4_find_get_deviceid
and there is no balance for that. Instead, do nfs4_fl_put_deviceid()

Quoted 8 lines

in the filelayout's .pg_cleanup and remove it from filelayout_free_lseg.
=20
But we still need a reference to hold over the lifetime of the segment.
For every new lseg that's created we need to take a reference on deviceid
that uses it. It will be released in the "free_lseg" routine.

Quoted 4 lines

=20
This is what I'm not understanding. If you have a reference in the layout segment, then why do you need to call nfs4_find_get_deviceid() in the read/write code?

I think I=E2=80=99m probably misunderstanding the question. It sounds to = me that you asking me for why the commit 8d40b0f14846 was done the way = it was done (I=E2=80=99d would say it was done as per your suggestion).

I would say the call to nfs4_find_get_deviceid() has always been in the = read/write code. It was a part of the pnfs_update_layout() but the = commit 8d40b0f14846 moved it out of it (so that the layoutget was = complete) and then the call to the getdeviceinfo would be done.=20

Quoted 2 lines

Isn't it sufficient to change the "pg_init" calls to check whether or not the struct nfs4_filelayout_segment has set a value for dsaddr =

(that

Quoted 3 lines

needs to be done with care to avoid races - cmpxchg() is your friend), and then rely on that reference being set for the remainder of the layout segment lifetime?

Are you suggesting to change when getdeviceinfo is suppose to be called?

Quoted 6 lines

=20
=20
--=20
Trond Myklebust
Linux NFS client maintainer, PrimaryData
[email protected]

#4 lore raw

T24gVGh1LCAyMDE3LTA3LTIwIGF0IDE2OjE0IC0wNDAwLCBPbGdhIEtvcm5pZXZza2FpYSB3cm90 ZToNCj4gPiBPbiBKdWwgMjAsIDIwMTcsIGF0IDM6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W51eCBORlMgY2xpZW50IG1haW50YWlu ZXIsIFByaW1hcnlEYXRhDQp0cm9uZC5teWtsZWJ1c3RAcHJpbWFyeWRhdGEuY29tDQo=

#5 lore raw
Quoted 40 lines · Trond Myklebust
Quoted 39 lines · Olga Kornievskaia
Quoted 9 lines

On Jul 20, 2017, at 3:56 PM, Trond Myklebust <[email protected] om> wrote:

Hi Olga,

Apologies for missing this patch. It was hiding in my 'linux- fsdevel'
mailbox, so I didn't recognise it as a NFS patch.

Yeah after I mailed it out I realized I cc-ed fsdevel incorrectly.

Quoted 27 lines · Olga Kornievskaia
Quoted 25 lines

There is a regression by commit 8d40b0f14846 ("NFS filelayout:call
GETDEVICEINFO after pnfs_layout_process completes"). It leaves the
DS mount dangling.

Previously, filelayout_alloc_sec() would call filelayout_check_layout()
which would call nfs4_find_get_deviceid which ups the count on the
device_id. It's only called once and it's matched by the filelayout_free_lseg() that calls nfs4_fl_put_deviceid().

After that patch, each read/write ends up calling nfs4_find_get_deviceid
and there is no balance for that. Instead, do nfs4_fl_put_deviceid()
in the filelayout's .pg_cleanup and remove it from filelayout_free_lseg.

But we still need a reference to hold over the lifetime of the segment.
For every new lseg that's created we need to take a reference on deviceid
that uses it. It will be released in the "free_lseg" routine.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

This is what I'm not understanding. If you have a reference in the layout segment, then why do you need to call nfs4_find_get_deviceid()
in the read/write code?

I think I=E2=80=99m probably misunderstanding the question. It sounds to=

me

fs/nfs/filelayout/filelayou=

Quoted 45 lines
Quoted 17 lines

that you asking me for why the commit 8d40b0f14846 was done the way it was done (I=E2=80=99d would say it was done as per your suggestion).

I would say the call to nfs4_find_get_deviceid() has always been in the read/write code. It was a part of the pnfs_update_layout() but the commit 8d40b0f14846 moved it out of it (so that the layoutget was complete) and then the call to the getdeviceinfo would be done.

Quoted 8 lines

Isn't it sufficient to change the "pg_init" calls to check whether or
not the struct nfs4_filelayout_segment has set a value for dsaddr (that
needs to be done with care to avoid races - cmpxchg() is your friend),
and then rely on that reference being set for the remainder of the layout segment lifetime?

Quoted 3 lines

Are you suggesting to change when getdeviceinfo is suppose to be called?

No. Now that I'm looking at filelayout_check_deviceid(), here is what I
suggest: we need to ensure that filelayout_check_deviceid() sets the
deviceid once, and only once!

How about something like the following (untested) patch?

8<------------------------------------------------------- From 1e40ee13950d03ad2a54a0d1dba35f2a04c28ca0 Mon Sep 17 00:00:00 2001
From: Trond Myklebust <[email protected]>
Date: Thu, 20 Jul 2017 17:00:02 -0400
Subject: [PATCH] NFS/filelayout: Fix racy setting of fl->dsaddr in
filelayout_check_deviceid()

We must set fl->dsaddr once, and once only, even if there are multiple processes calling filelayout_check_deviceid() for the same layout segment.

---
 fs/nfs/filelayout/filelayout.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
fs/nfs/filelayout/filelayou= renamed from fs/nfs/filelayout/filelayout.c +0 -0

t.c

fs/nfs/filelayout/filelayout.c filelayout_check_deviceid(struct pnfs_layout_hdr *lo=

Quoted 4 lines

index 080fc6b278bd..44c638b7876c 100644

fs/nfs/filelayout/filelayout.c +0 -0
@@ -542,6 +542,10 @@ filelayout_check_deviceid(struct pnfs_layout_hdr *lo=

,

fs/nfs/filelayout/filelayout.c filelayout_check_deviceid(struct pnfs_layout_hdr *lo= · line 550

Quoted 9 lines
fs/nfs/filelayout/filelayout.c +4 -0
        struct nfs4_file_layout_dsaddr *dsaddr;
        int status =3D -EINVAL;
 
+       /* Is the deviceid already set? If so, we're good. */
+       if (fl->dsaddr !=3D NULL)
+               return 0;
+
        /* find and reference the deviceid */
        d =3D nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode), &fl->devi=

ceid,

fs/nfs/filelayout/filelayout.c filelayout_check_deviceid(struct pnfs_layout_hdr *lo=

Quoted 11 lines
fs/nfs/filelayout/filelayout.c +0 -2
                        lo->plh_lc_cred, gfp_flags);
@@ -553,8 +557,6 @@ filelayout_check_deviceid(struct pnfs_layout_hdr *lo,
        if (filelayout_test_devid_unavailable(&dsaddr->id_node))
                goto out_put;
 
-       fl->dsaddr =3D dsaddr;
-
        if (fl->first_stripe_index >=3D dsaddr->stripe_count) {
                dprintk("%s Bad first_stripe_index %u\n",
                                __func__, fl->first_stripe_index);
@@ -570,6 +572,13 @@ filelayout_check_deviceid(struct pnfs_layout_hdr *lo=

,

Quoted 14 lines
fs/nfs/filelayout/filelayout.c +7 -1
                goto out_put;
        }
        status =3D 0;
+
+       /*
+        * Atomic compare and xchange to ensure we don't scribble
+        * over a non-NULL pointer.
+        */
+       if (cmpxchg(&fl->dsaddr, NULL, dsaddr) !=3D NULL)
+               goto out_put;
 out:
        return status;
 out_put:
--
Quoted 2 lines

2.13.3

No dangling DS after this patch as well.

Question: do we need to worry about that the checks that are done on the deviceid done after finding one are skipped with this patch?