Skip to content

Commit d46c0d6

Browse files
Trond Myklebustgregkh
authored andcommitted
pNFS/NFSv4: Update the layout barrier when we schedule a layoutreturn
[ Upstream commit 1bcf34f ] When we're scheduling a layoutreturn, we need to ignore any further incoming layouts with sequence ids that are going to be affected by the layout return. Fixes: 44ea8df ("NFS/pnfs: Reference the layout cred in pnfs_prepare_layoutreturn()") Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent dba0d4b commit d46c0d6

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

fs/nfs/pnfs.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,21 @@ pnfs_grab_inode_layout_hdr(struct pnfs_layout_hdr *lo)
324324
return NULL;
325325
}
326326

327+
/*
328+
* Compare 2 layout stateid sequence ids, to see which is newer,
329+
* taking into account wraparound issues.
330+
*/
331+
static bool pnfs_seqid_is_newer(u32 s1, u32 s2)
332+
{
333+
return (s32)(s1 - s2) > 0;
334+
}
335+
336+
static void pnfs_barrier_update(struct pnfs_layout_hdr *lo, u32 newseq)
337+
{
338+
if (pnfs_seqid_is_newer(newseq, lo->plh_barrier))
339+
lo->plh_barrier = newseq;
340+
}
341+
327342
static void
328343
pnfs_set_plh_return_info(struct pnfs_layout_hdr *lo, enum pnfs_iomode iomode,
329344
u32 seq)
@@ -335,6 +350,7 @@ pnfs_set_plh_return_info(struct pnfs_layout_hdr *lo, enum pnfs_iomode iomode,
335350
if (seq != 0) {
336351
WARN_ON_ONCE(lo->plh_return_seq != 0 && lo->plh_return_seq != seq);
337352
lo->plh_return_seq = seq;
353+
pnfs_barrier_update(lo, seq);
338354
}
339355
}
340356

@@ -639,15 +655,6 @@ static int mark_lseg_invalid(struct pnfs_layout_segment *lseg,
639655
return rv;
640656
}
641657

642-
/*
643-
* Compare 2 layout stateid sequence ids, to see which is newer,
644-
* taking into account wraparound issues.
645-
*/
646-
static bool pnfs_seqid_is_newer(u32 s1, u32 s2)
647-
{
648-
return (s32)(s1 - s2) > 0;
649-
}
650-
651658
static bool
652659
pnfs_should_free_range(const struct pnfs_layout_range *lseg_range,
653660
const struct pnfs_layout_range *recall_range)
@@ -984,8 +991,7 @@ pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
984991
new_barrier = be32_to_cpu(new->seqid);
985992
else if (new_barrier == 0)
986993
return;
987-
if (pnfs_seqid_is_newer(new_barrier, lo->plh_barrier))
988-
lo->plh_barrier = new_barrier;
994+
pnfs_barrier_update(lo, new_barrier);
989995
}
990996

991997
static bool
@@ -1183,20 +1189,17 @@ pnfs_prepare_layoutreturn(struct pnfs_layout_hdr *lo,
11831189
return false;
11841190
set_bit(NFS_LAYOUT_RETURN, &lo->plh_flags);
11851191
pnfs_get_layout_hdr(lo);
1192+
nfs4_stateid_copy(stateid, &lo->plh_stateid);
1193+
*cred = get_cred(lo->plh_lc_cred);
11861194
if (test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) {
1187-
nfs4_stateid_copy(stateid, &lo->plh_stateid);
1188-
*cred = get_cred(lo->plh_lc_cred);
11891195
if (lo->plh_return_seq != 0)
11901196
stateid->seqid = cpu_to_be32(lo->plh_return_seq);
11911197
if (iomode != NULL)
11921198
*iomode = lo->plh_return_iomode;
11931199
pnfs_clear_layoutreturn_info(lo);
1194-
return true;
1195-
}
1196-
nfs4_stateid_copy(stateid, &lo->plh_stateid);
1197-
*cred = get_cred(lo->plh_lc_cred);
1198-
if (iomode != NULL)
1200+
} else if (iomode != NULL)
11991201
*iomode = IOMODE_ANY;
1202+
pnfs_barrier_update(lo, be32_to_cpu(stateid->seqid));
12001203
return true;
12011204
}
12021205

0 commit comments

Comments
 (0)