From patchwork Wed Dec 27 13:57:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13508522 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D84764A02; Mon, 1 Jan 2024 00:57:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tJMozmzb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A500AC433C8; Mon, 1 Jan 2024 00:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704070648; bh=gr4SMOJ41U2PLOSrBIJPCzWxQeykfR4VWfQXCDEEOZs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tJMozmzbPqBToCftsFSa/yqbaNK3MAUeohXGT8ukjD7IOqurrkCWOKhUeIn7nW3mo 17Eg6rkpNMr7ctlaPPzzGQx3LCcYndqR4HLW9eUq2z1mAfd3SdcS1msAe7UphkKVCB cMijmsgnVSTTs+aYYxgKvA5fKP/mJI8dTcK7dd6Vl7ZJ8mkssuPTIEyemQyjjn2Yva wOl7ELFQIDN4HR60GZ0tUcllwrwCPc6TsjJczgl6jDu1sxpXTKoeGwyPbQzEBZPcz/ xV604IAW5TK8RD4E9YoMAFYEfSson1zC2/VzT6YSuRqtDrB9Rbo/E+yhLZq3IzTKCN /nYUt89pyeskA== Date: Sun, 31 Dec 2023 16:57:28 +9900 Subject: [PATCH 1/2] xfs: refactor statfs field extraction From: "Darrick J. Wong" To: djwong@kernel.org, zlang@redhat.com Cc: guan@eryu.me, linux-xfs@vger.kernel.org, fstests@vger.kernel.org Message-ID: <170405030881.1826812.8733545912595670620.stgit@frogsfrogsfrogs> In-Reply-To: <170405030868.1826812.10067703094837693199.stgit@frogsfrogsfrogs> References: <170405030868.1826812.10067703094837693199.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: fstests@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Prepare for the next patch by refactoring the open-coded bits that call statfs on a mounted xfs filesystem to extract a status field. Signed-off-by: Darrick J. Wong --- common/xfs | 6 ++++++ tests/xfs/176 | 4 ++-- tests/xfs/187 | 6 +++--- tests/xfs/541 | 6 ++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/common/xfs b/common/xfs index 313b7045bd..d9aa242ec7 100644 --- a/common/xfs +++ b/common/xfs @@ -2063,3 +2063,9 @@ _require_xfs_scratch_metadir() _scratch_unmount fi } + +# Extract a statfs attribute of the given mounted XFS filesystem. +_xfs_statfs_field() +{ + $XFS_IO_PROG -c 'statfs' "$1" | grep -E "$2" | cut -d ' ' -f 3 +} diff --git a/tests/xfs/176 b/tests/xfs/176 index 5231b888ba..0af81fcce3 100755 --- a/tests/xfs/176 +++ b/tests/xfs/176 @@ -49,7 +49,7 @@ fi _scratch_mount _xfs_force_bdev data $SCRATCH_MNT -old_dblocks=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | grep geom.datablocks) +old_dblocks=$(_xfs_statfs_field "$SCRATCH_MNT" geom.datablocks) mkdir $SCRATCH_MNT/save/ sino=$(stat -c '%i' $SCRATCH_MNT/save) @@ -172,7 +172,7 @@ for ((ino = target_ino; ino >= icluster_ino; ino--)); do res=$? # Make sure shrink did not work - new_dblocks=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | grep geom.datablocks) + new_dblocks=$(_xfs_statfs_field "$SCRATCH_MNT" geom.datablocks) if [ "$new_dblocks" != "$old_dblocks" ]; then echo "should not have shrank $old_dblocks -> $new_dblocks" break diff --git a/tests/xfs/187 b/tests/xfs/187 index 14c3b37670..03d92d0890 100755 --- a/tests/xfs/187 +++ b/tests/xfs/187 @@ -79,8 +79,8 @@ _xfs_force_bdev realtime $SCRATCH_MNT # Set the extent size hint larger than the realtime extent size. This is # necessary to exercise the minlen constraints on the realtime allocator. -fsbsize=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | grep geom.bsize | awk '{print $3}') -rtextsize_blks=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | grep geom.rtextsize | awk '{print $3}') +fsbsize=$(_xfs_statfs_field "$SCRATCH_MNT" geom.bsize) +rtextsize_blks=$(_xfs_statfs_field "$SCRATCH_MNT" geom.rtextsize) extsize=$((2 * rtextsize_blks * fsbsize)) echo "rtextsize_blks=$rtextsize_blks extsize=$extsize" >> $seqres.full @@ -136,7 +136,7 @@ rtextsize_bytes=$((fsbsize * rtextsize_blks)) $here/src/punch-alternating $SCRATCH_MNT/bigfile -o $((punch_off / rtextsize_bytes)) # Make sure we have some free rtextents. -free_rtx=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | grep statfs.f_bavail | awk '{print $3}') +free_rtx=$(_xfs_statfs_field "$SCRATCH_MNT" statfs.f_bavail) if [ $free_rtx -eq 0 ]; then echo "Expected fragmented free rt space, found none." fi diff --git a/tests/xfs/541 b/tests/xfs/541 index ae2fd819d5..3a0a9d5390 100755 --- a/tests/xfs/541 +++ b/tests/xfs/541 @@ -83,13 +83,11 @@ test $grow_extszhint -eq 0 || \ echo "expected post-grow extszhint 0, got $grow_extszhint" # Check that we now have rt extents. -rtextents=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | \ - grep 'geom.rtextents' | cut -d ' ' -f 3) +rtextents=$(_xfs_statfs_field "$SCRATCH_MNT" geom.rtextents) test $rtextents -gt 0 || echo "expected rtextents > 0" # Check the new rt extent size. -after_rtextsz_blocks=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | \ - grep 'geom.rtextsize' | cut -d ' ' -f 3) +after_rtextsz_blocks=$(_xfs_statfs_field "$SCRATCH_MNT" geom.rtextsize) test $after_rtextsz_blocks -eq $new_rtextsz_blocks || \ echo "expected rtextsize $new_rtextsz_blocks, got $after_rtextsz_blocks" From patchwork Wed Dec 27 13:57:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13508542 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 854104A02; Mon, 1 Jan 2024 00:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NenpGz1q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57FB5C433C8; Mon, 1 Jan 2024 00:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704070664; bh=JSbRLtytCKFgJwt/RI9Yunz+T3splF080/n1zkzNzbQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=NenpGz1qORvpTGuypfEnkQPhGb8ZJJ4jv32KvdZaEPfTB2FVCF/JOITzUsIrmG3aj FXgxllgsG0lsDPDtaDT9Jz+eUhcnvGeF4LdOwsMEKY9p9Mjb3K36bpBL83+gs6Cnxo sN8VhT3Kvy9lshUvYLhE44vqP1dktakxtgAavmz0ekb8nF2JBTn69qtbbIVc/h2YmO zVQ52NBYzoacBcK0O/TizGUmqyqF5ig5rge8k1/9jAS9Q22GEU5IHEYDhJQDf+76/I Fe/U0D2r7ufSHoUTJUm/rXH6ZrtxCtGHjr0UyUGuwqPgFqF1K04HzNAaO/V8UJJYCk 6rPDWRXR51RLw== Date: Sun, 31 Dec 2023 16:57:43 +9900 Subject: [PATCH 2/2] common/xfs: FITRIM now supports realtime volumes From: "Darrick J. Wong" To: djwong@kernel.org, zlang@redhat.com Cc: guan@eryu.me, linux-xfs@vger.kernel.org, fstests@vger.kernel.org Message-ID: <170405030894.1826812.11882587421223102904.stgit@frogsfrogsfrogs> In-Reply-To: <170405030868.1826812.10067703094837693199.stgit@frogsfrogsfrogs> References: <170405030868.1826812.10067703094837693199.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: fstests@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong XFS now supports FITRIM to the realtime volume. Detect this support and enable it. Signed-off-by: Darrick J. Wong --- common/xfs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/common/xfs b/common/xfs index d9aa242ec7..75f1bbcc3d 100644 --- a/common/xfs +++ b/common/xfs @@ -1937,8 +1937,44 @@ _require_xfs_scratch_atomicswap() # of 1024 byte blocks. _xfs_discard_max_offset_kb() { - $XFS_IO_PROG -c 'statfs' "$1" | \ - awk '{g[$1] = $3} END {print (g["geom.bsize"] * g["geom.datablocks"] / 1024)}' + local statfs + + # Use awk to read the statfs output for the XFS filesystem, compute + # the two possible FITRIM offset maximums, and then use some horrid + # bash magic to import the five numbers as an indexed array. There's + # no better way to do this in bash since you can't readarray to build + # an associative array. Elements are as follows: + # + # 0: fsblock size in bytes + # 1: Data volume size in fsblocks. + # 2: Realtime volume size in fsblocks. + # 3: Max FITRIM offset if we can only trim the data volume + # 4: Max FITRIM offset if we can trim the data and rt volumes + readarray -t statfs < <($XFS_IO_PROG -c 'statfs' "$1" | \ + awk '{g[$1] = $3} END {printf("%d\n%d\n%d\n%d\n%d\n", + g["geom.bsize"], + g["geom.datablocks"], + g["geom.rtblocks"], + g["geom.bsize"] * g["geom.datablocks"] / 1024, + g["geom.bsize"] * (g["geom.datablocks"] + g["geom.rtblocks"]) / 1024);}') + + # If the kernel supports discarding the realtime volume, then it will + # not reject a FITRIM for fsblock dblks+1, even if the len/minlen + # arguments are absurd. + if [ "${statfs[2]}" -gt 0 ]; then + if $FSTRIM_PROG -o "$((statfs[0] * statfs[1]))" \ + -l "${statfs[0]}" \ + -m "$((statfs[0] * 2))" "$1" &>/dev/null; then + # The kernel supports discarding the rt volume, so + # print out the second answer from above. + echo "${statfs[4]}" + return + fi + fi + + # The kernel does not support discarding the rt volume or there is no + # rt volume. Print out the first answer from above. + echo "${statfs[3]}" } # Adjust MKFS_OPTIONS as necessary to avoid having parent pointers formatted