]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
btrfs/058: fix test to actually have an open tmpfile during the send operation
authorFilipe Manana <fdmanana@suse.com>
Wed, 19 Mar 2025 12:13:28 +0000 (12:13 +0000)
committerZorro Lang <zlang@kernel.org>
Fri, 28 Mar 2025 01:05:35 +0000 (09:05 +0800)
The test's goal is to exercise a send operation while there's a tmpfile in
the snapshot, but that doesn't happen since the background xfs_io process
that created the tmpfile ends up exiting before we create the snapshot, so
the snapshot nevers gets a tmpfile.

Fix this by using a different approach, with a fifo and tailing it to the
stdin of a background xfs_io process and then writing to the fifo to
create the tmpfile. This keeps the xfs_io process running with the tmpfile
open while we snapshot and run the send operation.

While at it also add code to verify we have the tmpfile (an orphan inode
item) in the snapshot's tree.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
tests/btrfs/058

index 7bc4af5b0f1e738b33469f6e22400bb999daa8b5..3bb0ed21cdc39378a9fde476d2acbd71621ae449 100755 (executable)
@@ -21,6 +21,7 @@ _cleanup()
 {
        if [ ! -z $XFS_IO_PID ]; then
                kill $XFS_IO_PID > /dev/null 2>&1
+               wait
        fi
        rm -fr $tmp
 }
@@ -29,18 +30,22 @@ _cleanup()
 
 _require_scratch
 _require_xfs_io_command "-T"
+_require_mknod
+_require_btrfs_command inspect-internal dump-tree
 
 _scratch_mkfs >/dev/null 2>&1
 _scratch_mount
 
+mkfifo $SCRATCH_MNT/fifo
+
 # Create a tmpfile file, write some data to it and leave it open, so that our
 # main subvolume has an orphan inode item.
-$XFS_IO_PROG -T $SCRATCH_MNT >>$seqres.full 2>&1 < <(
-       echo "pwrite 0 65536"
-       read
-) &
+tail -f $SCRATCH_MNT/fifo | $XFS_IO_PROG >>$seqres.full &
 XFS_IO_PID=$!
 
+echo "open -T $SCRATCH_MNT" > $SCRATCH_MNT/fifo
+echo "pwrite 0 64K" > $SCRATCH_MNT/fifo
+
 # Give it some time to the xfs_io process to create the tmpfile.
 sleep 3
 
@@ -48,6 +53,21 @@ sleep 3
 # The send operation used to fail with -ESTALE due to the presence of the
 # orphan inode.
 _btrfs subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap
+
+snap_id=$(_btrfs_get_subvolid $SCRATCH_MNT mysnap)
+# Inode numbers are sequential, so our tmpfile's inode number is the number of
+# the fifo's inode plus 1.
+ino=$(( $(stat -c %i $SCRATCH_MNT/fifo) + 1 ))
+
+# Verify that we indeed have the tmpfile in the snapshot tree.
+$BTRFS_UTIL_PROG inspect-internal dump-tree -t $snap_id $SCRATCH_DEV | \
+       grep -q "(ORPHAN ORPHAN_ITEM $ino)"
+if [ $? -ne 0 ]; then
+       echo "orphan item for tmpfile not found in the snapshot tree!"
+       echo -e "snapshot tree dump is:\n"
+       $BTRFS_UTIL_PROG inspect-internal dump-tree -t $snap_id $SCRATCH_DEV
+fi
+
 _btrfs send -f /dev/null $SCRATCH_MNT/mysnap
 
 status=0