]> git.hungrycats.org Git - linux/commitdiff
NFSv4/filelayout: Anchor page coalescing on pattern_offset
authorBenjamin Coddington <ben.coddington@hammerspace.com>
Tue, 15 Sep 2026 12:22:09 +0000 (08:22 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:05 +0000 (12:06 -0500)
commit 7f2d221b01f356b6bb3bb6efef998f8b28339824 upstream.

filelayout_pg_test() bounds page coalescing to a single stripe unit
using an offset relative to pls_range.offset, but the data server is
selected by nfs4_fl_calc_j_index() using an offset relative to
pattern_offset.  When a segment's pattern_offset and range offset are
not congruent modulo the stripe unit, the coalescing window is shifted
off the DS-selection grid, so a coalesced I/O can straddle a stripe
boundary and send the bytes past it to the wrong data server.

Anchor coalescing on pattern_offset to match nfs4_fl_calc_j_index().
Stripe-congruent segments, including the common whole-file pattern_offset
0 case, are unchanged.

Fixes: c6194271f94b ("pnfs: filelayout: support non page aligned layouts")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
Signed-off-by: Anna Schumaker <anna.schumaker@hammerspace.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nfs/filelayout/filelayout.c

index c933e3b695bc3613352f019596e84c57c220a8dc..90924129b4e834137f06b2b6ec8325a053275e26 100644 (file)
@@ -796,7 +796,7 @@ filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
        unsigned int size;
        u64 p_stripe, r_stripe;
        u32 stripe_offset;
-       u64 segment_offset = pgio->pg_lseg->pls_range.offset;
+       u64 pattern_offset = FILELAYOUT_LSEG(pgio->pg_lseg)->pattern_offset;
        u32 stripe_unit = FILELAYOUT_LSEG(pgio->pg_lseg)->stripe_unit;
 
        /* calls nfs_generic_pg_test */
@@ -808,8 +808,8 @@ filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
 
        /* see if req and prev are in the same stripe */
        if (prev) {
-               p_stripe = (u64)req_offset(prev) - segment_offset;
-               r_stripe = (u64)req_offset(req) - segment_offset;
+               p_stripe = (u64)req_offset(prev) - pattern_offset;
+               r_stripe = (u64)req_offset(req) - pattern_offset;
                do_div(p_stripe, stripe_unit);
                do_div(r_stripe, stripe_unit);
 
@@ -818,7 +818,7 @@ filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
        }
 
        /* calculate remaining bytes in the current stripe */
-       div_u64_rem((u64)req_offset(req) - segment_offset,
+       div_u64_rem((u64)req_offset(req) - pattern_offset,
                        stripe_unit,
                        &stripe_offset);
        WARN_ON_ONCE(stripe_offset > stripe_unit);