From: Christoph Hellwig <hch@lst.de> To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Qu Wenruo <wqu@suse.com> Subject: [PATCH 01/10] btrfs: add a helpers for read repair testing Date: Fri, 27 May 2022 10:19:06 +0200 [thread overview] Message-ID: <20220527081915.2024853-2-hch@lst.de> (raw) In-Reply-To: <20220527081915.2024853-1-hch@lst.de> Add a few helpers to consolidate code for btrfs read repair testing: - _btrfs_get_first_logical() gets the btrfs logical address for the first extent in a file - _btrfs_get_device_path and _btrfs_get_physical use the btrfs-map-logical tool to find the device path and physical address for btrfs logical address for a specific mirror - _btrfs_direct_read_on_mirror and _btrfs_buffered_read_on_mirror read the data from a specific mirror These will be used to consolidate the read repair tests and avoid duplication for new tests. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Qu Wenruo <wqu@suse.com> --- common/btrfs | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ common/config | 1 + 2 files changed, 76 insertions(+) diff --git a/common/btrfs b/common/btrfs index ac597ca4..b69feeee 100644 --- a/common/btrfs +++ b/common/btrfs @@ -505,3 +505,78 @@ _btrfs_metadump() $BTRFS_IMAGE_PROG "$device" "$dumpfile" [ -n "$DUMP_COMPRESSOR" ] && $DUMP_COMPRESSOR -f "$dumpfile" &> /dev/null } + +# Return the btrfs logical address for the first block in a file +_btrfs_get_first_logical() +{ + local file=$1 + _require_command "$FILEFRAG_PROG" filefrag + + ${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar >> $seqres.full + ${FILEFRAG_PROG} -v $file | _filter_filefrag | cut -d '#' -f 1 +} + +# Find the device path for a btrfs logical offset +_btrfs_get_device_path() +{ + local logical=$1 + local stripe=$2 + + _require_command "$BTRFS_MAP_LOGICAL_PROG" btrfs-map-logical + + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV | \ + $AWK_PROG "(\$1 ~ /mirror/ && \$2 ~ /$stripe/) { print \$8 }" +} + + +# Find the device physical sector for a btrfs logical offset +_btrfs_get_physical() +{ + local logical=$1 + local stripe=$2 + + _require_command "$BTRFS_MAP_LOGICAL_PROG" btrfs-map-logical + + $BTRFS_MAP_LOGICAL_PROG -b -l $logical $SCRATCH_DEV >> $seqres.full 2>&1 + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV | \ + $AWK_PROG "(\$1 ~ /mirror/ && \$2 ~ /$stripe/) { print \$6 }" +} + +# Read from a specific stripe to test read recovery that corrupted a specific +# stripe. Btrfs uses the PID to select the mirror, so keep reading until the +# xfs_io process that performed the read was executed with a PID that ends up +# on the intended mirror. +_btrfs_direct_read_on_mirror() +{ + local mirror=$1 + local nr_mirrors=$2 + local file=$3 + local offset=$4 + local size=$5 + + while [[ -z $( (( BASHPID % nr_mirrors == mirror )) && + exec $XFS_IO_PROG -d \ + -c "pread -b $size $offset $size" $file) ]]; do + : + done +} + +# Read from a specific stripe to test read recovery that corrupted a specific +# stripe. Btrfs uses the PID to select the mirror, so keep reading until the +# xfs_io process that performed the read was executed with a PID that ends up +# on the intended mirror. +_btrfs_buffered_read_on_mirror() +{ + local mirror=$1 + local nr_mirrors=$2 + local file=$3 + local offset=$4 + local size=$5 + + echo 3 > /proc/sys/vm/drop_caches + while [[ -z $( (( BASHPID % nr_mirrors == mirror )) && + exec $XFS_IO_PROG \ + -c "pread -b $size $offset $size" $file) ]]; do + : + done +} diff --git a/common/config b/common/config index c6428f90..df20afc1 100644 --- a/common/config +++ b/common/config @@ -228,6 +228,7 @@ export E2IMAGE_PROG="$(type -P e2image)" export BLKZONE_PROG="$(type -P blkzone)" export GZIP_PROG="$(type -P gzip)" export BTRFS_IMAGE_PROG="$(type -P btrfs-image)" +export BTRFS_MAP_LOGICAL_PROG=$(type -P btrfs-map-logical) # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled. # newer systems have udevadm command but older systems like RHEL5 don't. -- 2.30.2
next prev parent reply other threads:[~2022-05-27 8:19 UTC|newest] Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-27 8:19 btrfs read repair: new tests and cleanups Christoph Hellwig 2022-05-27 8:19 ` Christoph Hellwig [this message] 2022-05-27 14:54 ` [PATCH 01/10] btrfs: add a helpers for read repair testing Zorro Lang 2022-05-27 15:03 ` Christoph Hellwig 2022-05-28 3:34 ` Zorro Lang 2022-05-28 4:56 ` Christoph Hellwig 2022-05-30 0:23 ` Anand Jain 2022-05-30 1:20 ` Qu Wenruo 2022-05-30 4:36 ` Zorro Lang 2022-05-30 5:34 ` Christoph Hellwig 2022-05-27 8:19 ` [PATCH 02/10] btrfs/140: use common read repair helpers Christoph Hellwig 2022-05-30 0:35 ` Anand Jain 2022-05-27 8:19 ` [PATCH 03/10] btrfs/141: " Christoph Hellwig 2022-05-30 0:36 ` Anand Jain 2022-05-27 8:19 ` [PATCH 04/10] btrfs/142: " Christoph Hellwig 2022-05-30 0:41 ` Anand Jain 2022-05-27 8:19 ` [PATCH 05/10] btrfs/143: " Christoph Hellwig 2022-05-30 0:43 ` Anand Jain 2022-05-27 8:19 ` [PATCH 06/10] btrfs/157: use _btrfs_get_first_logical Christoph Hellwig 2022-05-30 0:44 ` Anand Jain 2022-05-27 8:19 ` [PATCH 07/10] btrfs/215: " Christoph Hellwig 2022-05-30 0:44 ` Anand Jain 2022-05-27 8:19 ` [PATCH 08/10] btrfs: test repair with sectors corrupted in multiple mirrors Christoph Hellwig 2022-05-30 0:50 ` Anand Jain 2022-05-27 8:19 ` [PATCH 09/10] btrfs: test buffered I/O read repair with interleaved corrupted sectors Christoph Hellwig 2022-05-30 2:02 ` Anand Jain 2022-05-27 8:19 ` [PATCH 10/10] btrfs: test direct " Christoph Hellwig 2022-05-27 10:23 ` Qu Wenruo 2022-05-27 13:37 ` Christoph Hellwig 2022-05-30 2:03 ` Anand Jain 2022-05-30 2:07 ` btrfs read repair: new tests and cleanups Anand Jain
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220527081915.2024853-2-hch@lst.de \ --to=hch@lst.de \ --cc=fstests@vger.kernel.org \ --cc=linux-btrfs@vger.kernel.org \ --cc=wqu@suse.com \ --subject='Re: [PATCH 01/10] btrfs: add a helpers for read repair testing' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.