Skip to contentSkip to conversation

Block layout tests for LAYOUTCOMMITs of ranges without blocks

PATCH New Daejun Park 1 participant 4 messages Oct 14

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

cover Block layout tests for LAYOUTCOMMITs of ranges without blocks

Patch 1 is "Add a test for contiguous writable extents in a block layout", posted on October 6 [1] and unchanged. Patch 2 adds tests for LAYOUTCOMMITs of ranges that no layout covered, which shut XFS down or committed a block that nobody wrote before the XFS series in [2]. Patch 3 describes how the block layout tests are run against Linux nfsd, as Christoph asked [3].

Tested with Linux nfsd on nfsd-testing d918c664efd5, XFS on an NVMe/TCP namespace exported by nvmet, in QEMU guests with KASAN and lockdep:

- Without [2], BLOCK7 fails at the GETATTR after the LAYOUTCOMMIT, as XFS has shut down, and the tests after it fail for the same reason. With BLOCK7 and BLOCK8 left out, BLOCK9 fails because the server commits the hole. BLOCK10 passes; the server only logs a "non-standard errno" warning for it.
- With [2], BLOCK6 to BLOCK10 pass in 5 runs, and also on an XFS_DEBUG kernel.
- BLOCK3 fails with and without [2], on a bug in the test.

[1] https://lore.kernel.org/r/20261006002622epcms2p38e492aef17fdf79e48b05c9aada2918d@epcms2p3
[2] https://lore.kernel.org/r/[email protected]
[3] https://lore.kernel.org/r/[email protected]

---
Daejun Park (3):
Add a test for contiguous writable extents in a block layout Add tests for LAYOUTCOMMITs of ranges without blocks in a block layout Add README-blocklayout

 nfs4.1/README-blocklayout        |  41 +++++++
 nfs4.1/server41tests/st_block.py | 230 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 268 insertions(+), 3 deletions(-)

---
base-commit: cd4701827a8261fedbfb4c6e39029fb9671321a6
change-id: 20261014-pynfs-block-commit-c70fe337b684

Best regards,

Signature · 1 line
Daejun Park <[email protected]>
#1 lore raw

PATCH 1/3 Add a test for contiguous writable extents in a block layout

BLOCK5: a LAYOUTIOMODE4_RW LAYOUTGET over a hole between two allocated blocks, where the server allocates the hole, gets extents that follow three of the rules in RFC 5663 section 2.3.1: the extents are ordered by offset, the writable extents (all but PNFS_BLOCK_READ_DATA) are logically contiguous, and the first extent contains the requested offset (so the extent list is not empty). A server that maps each extent in full can return the extent that the allocation merges with the ones before it, overlapping them.

The test allocates three blocks of the layout block size (FATTR4_LAYOUT_BLKSIZE) and deallocates the middle one, so that the block the server allocates for the hole is likely to be that one and to merge with both neighbours. It warns if the layout does not cover the three blocks or they are not contiguous on the volume, as then no merge could be seen. On Linux nfsd over XFS the freed block can be reused at once on a sync export, where DEALLOCATE commits. The minimum length is one block, so that a server that returns one extent per LAYOUTGET does not have to refuse the request. Every layout in the reply is checked. The test uses ALLOCATE and DEALLOCATE, so it needs NFSv4.2, and a server without them does not support the test.

Linux nfsd over XFS fails BLOCK5 in five runs out of five on a test kernel that maps with XFS_BMAPI_ENTIRE in xfs_fs_map_blocks() and does not trim, which kernel commit 36ca6f11424a ("xfs: fix overlapping extents returned for pNFS LAYOUTGET") stopped in 7.1. nfsd-testing on top of 7.3-rc4 passes it in five runs out of five, with and without "xfs: map pNFS layouts to the end of the extent again".

---
 nfs4.1/server41tests/st_block.py | 94 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 91 insertions(+), 3 deletions(-)
nfs4.1/server41tests/st_block.py +91 -3
index 3cfc1c6..6c30585 100644
@@ -2,10 +2,11 @@ from xdrdef.nfs4_const import *
 from xdrdef.nfs4_type import *
 import nfs_ops
 op = nfs_ops.NFS4ops()
-from .environment import check, fail, create_file
+from .environment import check, fail, create_file, use_obj, \
+    get_blocksize
 from block import Packer as BlockPacker, Unpacker as BlockUnpacker, \
-    PNFS_BLOCK_READWRITE_DATA, pnfs_block_layoutupdate4, \
-    pnfs_block_extent4
+    PNFS_BLOCK_READWRITE_DATA, PNFS_BLOCK_READ_DATA, \
+    pnfs_block_layoutupdate4, pnfs_block_extent4
 from nfs4lib import FancyNFS4Packer, get_nfstime
 
 
@@ -215,3 +216,90 @@ def testSplitCommit(t, env):
                            layoutupdate4(LAYOUT4_BLOCK_VOLUME, p.get_buffer()))]
     res = sess.compound(ops)
     check(res)
+
+def testRWExtentsContiguous(t, env):
+    """RW layout over a hole between allocated blocks has contiguous extents
+
+    The server allocates the hole for the layout.  Check three of the
+    rules in RFC 5663 section 2.3.1: the extents are ordered by offset,
+    the writable extents (all but PNFS_BLOCK_READ_DATA) are logically
+    contiguous, and the first extent contains the requested offset.  A
+    server that maps each extent in full can return the extent that the
+    allocation merges with the ones before it, overlapping them.  The
+    minimum length is one block, so that a server that returns one
+    extent per LAYOUTGET does not have to refuse the request.  Warn if
+    the layout does not cover the three blocks or they are not contiguous
+    on the volume, as then no merge could be seen.
+
+    FLAGS: block
+    CODE: BLOCK5
+    VERS: 2-
+    """
+    sess = env.c1.new_pnfs_client_session(env.testname(t))
+    bs = get_blocksize(sess, use_obj(env.opts.path))
+    res = create_file(sess, env.testname(t))
+    check(res)
+    fh = res.resarray[-1].object
+    open_stateid = res.resarray[-2].stateid
+    # Allocate three blocks, then deallocate the middle one: the block
+    # the server allocates for the hole is likely to be that one, and to
+    # merge with both neighbours.  (On Linux nfsd over XFS the freed block
+    # can be reused at once on a sync export, where DEALLOCATE commits.)
+    res = sess.compound([op.putfh(fh), op.allocate(open_stateid, 0, 3*bs)])
+    if res.status == NFS4ERR_NOTSUPP:
+        t.fail_support("ALLOCATE is not supported")
+    check(res)
+    res = sess.compound([op.putfh(fh), op.deallocate(open_stateid, bs, bs)])
+    if res.status == NFS4ERR_NOTSUPP:
+        t.fail_support("DEALLOCATE is not supported")
+    check(res)
+    ops = [op.putfh(fh),
+           op.layoutget(False, LAYOUT4_BLOCK_VOLUME, LAYOUTIOMODE4_RW,
+                        0, 3*bs, bs, open_stateid, 0xffff)]
+    res = sess.compound(ops)
+    check(res)
+    found = False
+    blocks = {}
+    for layout in res.resarray[-1].logr_layout:
+        p = BlockUnpacker(layout.loc_body)
+        opaque = p.unpack_pnfs_block_layout4()
+        p.done()
+        ext = [(e.bex_file_offset, e.bex_length, e.bex_state)
+               for e in opaque.blo_extents]
+        print(layout.lo_offset, layout.lo_length, ext,
+              [e.bex_storage_offset for e in opaque.blo_extents])
+        if not ext:
+            fail("No extents in layout %d+%d" %
+                 (layout.lo_offset, layout.lo_length))
+        for a, b in zip(ext, ext[1:]):
+            if b[0] < a[0] or (b[0] == a[0] and
+                               a[2] != PNFS_BLOCK_READ_DATA and
+                               b[2] == PNFS_BLOCK_READ_DATA):
+                fail("Extents %s and %s are not in order" % (a, b))
+        writable = [e for e in ext if e[2] != PNFS_BLOCK_READ_DATA]
+        for a, b in zip(writable, writable[1:]):
+            if b[0] != a[0] + a[1]:
+                fail("Writable extents %s and %s are not logically "
+                     "contiguous" % (a, b))
+        if layout.lo_offset <= 0 < layout.lo_offset + layout.lo_length:
+            found = True
+            if not ext[0][0] <= 0 < ext[0][0] + ext[0][1]:
+                fail("First extent %s does not contain offset 0" %
+                     (ext[0],))
+        for e in opaque.blo_extents:
+            if e.bex_state == PNFS_BLOCK_READ_DATA:
+                continue
+            off = e.bex_file_offset
+            for i in range(3):
+                if off <= i*bs < off + e.bex_length:
+                    blocks[i] = (e.bex_vol_id,
+                                 e.bex_storage_offset + i*bs - off)
+    if not found:
+        fail("No layout contains offset 0")
+    if len(blocks) < 3:
+        t.pass_warn("The layout does not cover all three blocks, so a "
+                    "merge could not be seen")
+    if blocks[0][0] != blocks[1][0] or blocks[1][0] != blocks[2][0] or \
+       blocks[1][1] != blocks[0][1] + bs or blocks[2][1] != blocks[1][1] + bs:
+        t.pass_warn("The three blocks are not contiguous on the volume, "
+                    "so there were no extents to merge")
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/3 Add tests for LAYOUTCOMMITs of ranges without blocks in a block layout

In reply to Daejun Park

BLOCK6 gets an RW layout for the first 64 KiB of a 2 MiB file without blocks and commits that range. BLOCK7 to BLOCK10 commit ranges that no layout covered instead: a 64 KiB hole, the laid-out range together with that hole, a one-block hole, and an extent that starts at the second block and whose offset + length wraps around 2^64. Per RFC 5663 section 2.3.2, a LAYOUTCOMMIT commits regions that a layout handed out as PNFS_BLOCK_INVALID_DATA, so the server must refuse those. After the refused LAYOUTCOMMIT, the tests also check that the server can still GETATTR the file and that its space used did not grow. The client writes nothing to the volume.

On Linux, nfsd does not check the committed extents against the layouts it handed out, and XFS converted whatever range it got. A 64 KiB hole shut XFS down, a one-block hole got NFS4_OK and a block of whatever the volume held mapped into the file, and the wrapping extent got NFS4ERR_IO with a "non-standard errno" warning from nfsd. "xfs: refuse a pNFS LAYOUTCOMMIT of a range without blocks" and "xfs: clamp a pNFS LAYOUTCOMMIT extent before computing its end" fix that.

---
 nfs4.1/server41tests/st_block.py | 136 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)
nfs4.1/server41tests/st_block.py +136 -0
index 6c30585..36d7652 100644
@@ -303,3 +303,139 @@ def testRWExtentsContiguous(t, env):
        blocks[1][1] != blocks[0][1] + bs or blocks[2][1] != blocks[1][1] + bs:
         t.pass_warn("The three blocks are not contiguous on the volume, "
                     "so there were no extents to merge")
+
+def _commit_setup(t, env):
+    """Make a 2 MiB file without blocks and get an RW layout for its
+    first 64 KiB, which makes the server allocate those blocks.
+
+    Returns the session, the file handle, the layout stateid, the block
+    size and the first extent of the layout.
+    """
+    sess = env.c1.new_pnfs_client_session(env.testname(t))
+    bs = get_blocksize(sess, use_obj(env.opts.path))
+    if 65536 % bs:
+        t.fail_support("Block size %d does not divide 64 KiB" % bs)
+    res = create_file(sess, env.testname(t), access=OPEN4_SHARE_ACCESS_BOTH)
+    check(res)
+    fh = res.resarray[-1].object
+    open_stateid = res.resarray[-2].stateid
+    res = sess.compound([op.putfh(fh),
+                         op.setattr(open_stateid, {FATTR4_SIZE: 2 << 20})])
+    check(res, msg="SETATTR of the size to 2 MiB")
+    res = sess.compound([op.putfh(fh),
+                         op.layoutget(False, LAYOUT4_BLOCK_VOLUME,
+                                      LAYOUTIOMODE4_RW, 0, 65536, bs,
+                                      open_stateid, 0xffff)])
+    check(res, msg="RW LAYOUTGET of the first 64 KiB")
+    layout_stateid = res.resarray[-1].logr_stateid
+    extents = []
+    for layout in res.resarray[-1].logr_layout:
+        p = BlockUnpacker(layout.loc_body)
+        extents += p.unpack_pnfs_block_layout4().blo_extents
+        p.done()
+    if not extents:
+        fail("No extents in the layout")
+    return sess, fh, layout_stateid, bs, extents[0]
+
+def _commit(sess, fh, layout_stateid, vol_id, extents):
+    """LAYOUTCOMMIT the extents, a list of (file offset, length, volume
+    offset), as written"""
+    p = BlockPacker()
+    p.pack_pnfs_block_layoutupdate4(pnfs_block_layoutupdate4(
+        [pnfs_block_extent4(vol_id, foff, length, soff,
+                            PNFS_BLOCK_READWRITE_DATA)
+         for foff, length, soff in extents]))
+    return sess.compound([op.putfh(fh),
+                          op.layoutcommit(0, 2 << 20, False, layout_stateid,
+                                          newoffset4(False),
+                                          newtime4(True, get_nfstime()),
+                                          layoutupdate4(LAYOUT4_BLOCK_VOLUME,
+                                                        p.get_buffer()))])
+
+def _space_used(sess, fh):
+    res = sess.compound([op.putfh(fh), op.getattr(1 << FATTR4_SPACE_USED)])
+    check(res, msg="GETATTR after the LAYOUTCOMMIT")
+    return res.resarray[-1].obj_attributes[FATTR4_SPACE_USED]
+
+def _commit_refused(sess, fh, lo_stateid, vol_id, extents, what):
+    """The LAYOUTCOMMIT must fail, and the server must still be able to
+    GETATTR the file and must not have allocated anything for it"""
+    before = _space_used(sess, fh)
+    res = _commit(sess, fh, lo_stateid, vol_id, extents)
+    if res.status == NFS4_OK:
+        fail("LAYOUTCOMMIT of %s succeeded" % what)
+    after = _space_used(sess, fh)
+    if after > before:
+        fail("Space used grew from %d to %d after the refused LAYOUTCOMMIT "
+             "of %s" % (before, after, what))
+
+def testCommitLaidOut(t, env):
+    """LAYOUTCOMMIT of the range of an RW layout
+
+    FLAGS: block
+    CODE: BLOCK6
+    """
+    sess, fh, lo_stateid, bs, e = _commit_setup(t, env)
+    res = _commit(sess, fh, lo_stateid, e.bex_vol_id,
+                  [(0, 65536, e.bex_storage_offset)])
+    check(res, msg="LAYOUTCOMMIT of the range of the layout")
+
+def testCommitHole(t, env):
+    """LAYOUTCOMMIT of a hole that no layout covered must fail
+
+    Per RFC 5663 section 2.3.2, a LAYOUTCOMMIT commits extents that a
+    layout handed out as PNFS_BLOCK_INVALID_DATA, so there is nothing
+    the client could have written to a hole that it never got a layout
+    for. The client writes nothing to the volume here. After the
+    LAYOUTCOMMIT fails, the server must still be able to GETATTR the
+    file, and its space used must not have grown.
+
+    FLAGS: block
+    CODE: BLOCK7
+    DEPEND: BLOCK6
+    """
+    sess, fh, lo_stateid, bs, e = _commit_setup(t, env)
+    _commit_refused(sess, fh, lo_stateid, e.bex_vol_id,
+                    [(1 << 20, 65536, e.bex_storage_offset)],
+                    "a 64 KiB hole that no layout covered")
+
+def testCommitLaidOutAndHole(t, env):
+    """LAYOUTCOMMIT of the range of an RW layout and a hole must fail
+
+    FLAGS: block
+    CODE: BLOCK8
+    DEPEND: BLOCK6
+    """
+    sess, fh, lo_stateid, bs, e = _commit_setup(t, env)
+    _commit_refused(sess, fh, lo_stateid, e.bex_vol_id,
+                    [(0, 65536, e.bex_storage_offset),
+                     (1 << 20, 65536, e.bex_storage_offset + 65536)],
+                    "the laid out range and a hole that no layout covered")
+
+def testCommitBlockHole(t, env):
+    """LAYOUTCOMMIT of a one-block hole that no layout covered must fail
+
+    FLAGS: block
+    CODE: BLOCK9
+    DEPEND: BLOCK6
+    """
+    sess, fh, lo_stateid, bs, e = _commit_setup(t, env)
+    _commit_refused(sess, fh, lo_stateid, e.bex_vol_id,
+                    [(1 << 20, bs, e.bex_storage_offset)],
+                    "a one-block hole that no layout covered")
+
+def testCommitWrap(t, env):
+    """LAYOUTCOMMIT of an extent whose offset + length wraps must fail
+
+    The extent starts at the second block of the layout and runs past
+    2^64. The server must not treat the length as if it ended below the
+    offset, and the extent covers the hole after the layout.
+
+    FLAGS: block
+    CODE: BLOCK10
+    DEPEND: BLOCK6
+    """
+    sess, fh, lo_stateid, bs, e = _commit_setup(t, env)
+    _commit_refused(sess, fh, lo_stateid, e.bex_vol_id,
+                    [(bs, 2**64 - bs, e.bex_storage_offset)],
+                    "an extent that wraps around 2^64")
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/3 Add README-blocklayout

In reply to Daejun Park

Describe how the block layout tests are run against Linux nfsd: the kernel options and export option that nfsd needs to hand out block layouts, a setup that the tests have been run with, the testserver.py command line, and how to leave out the tests that commit ranges no layout covered when testing a server that shuts down on them.

---
 nfs4.1/README-blocklayout | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
nfs4.1/README-blocklayout new file +41 -0
new file mode 100644
index 0000000..48d3c1b
@@ -0,0 +1,41 @@
+Testing a block layout server
+=============================
+
+The "block" tests (server41tests/st_block.py) run testserver.py as the
+pNFS client of a server that hands out block layouts (RFC 5663). They
+only send NFS operations: none of them reads or writes the shared
+volume, so the host that runs them does not need access to it.
+
+They ask for LAYOUT4_BLOCK_VOLUME layouts. Linux nfsd hands those out
+for an XFS export with the "pnfs" option when it is built with
+CONFIG_NFSD_BLOCKLAYOUT. With CONFIG_NFSD_SCSILAYOUT it also hands out
+SCSI layouts (RFC 8154) if the device supports persistent
+reservations; the tests do not use those.
+
+One setup that the tests have been run with:
+
+  - nfsd built with CONFIG_NFSD_BLOCKLAYOUT=y, and XFS (mkfs.xfs
+    defaults, internal log) on a whole NVMe namespace, exported with
+    this line in /etc/exports:
+
+        /export  10.10.0.0/24(rw,sync,no_root_squash,pnfs)
+
+  - The namespace came over NVMe/TCP from nvmet on another host. As
+    the pynfs host never touches the volume, any block device that
+    XFS can be made on works for these tests; a shared device only
+    matters for clients that do I/O through the layout.
+
+  - A directory /export/pynfs on the server that the test user can
+    write to, and on the pynfs host:
+
+        ./testserver.py SERVER:/export/pynfs --secure --maketree block
+
+    --secure sends from a privileged port, which nfsd requires unless
+    the export has "insecure". --maketree creates the files that the
+    tests expect; it is needed the first time.
+
+BLOCK7 to BLOCK10 commit ranges that no layout covered. A server that
+does not refuse those may allocate blocks for them or, as XFS did,
+shut the filesystem down, which makes the tests after them fail. To
+leave them out, add "noBLOCK7 noBLOCK8 noBLOCK9 noBLOCK10" after
+"block".
Signature · 1 line
2.43.0