From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796036624; b=v5pptTMbESJwDqQEbz0XrGuC6PVHDZWt0szOBYi7mjq1qdJ5+KBTSpMRcT2KfPTaNKjv Au02J7TS6z6wMo4aa3lM1Wb4qBDxcjyjPDjmbAlk6mO4EcJLW1Kmvv3KhZ3Smt/0fOV/N DLrP/TuSjtXs3tmnV6kz3SMG9wtguRX9sq5naYnS5mW3wAL+9cc5kb6eQniKDhgGs/U84 a6tyEVGDAsXBgZ0LZY4OFpmk2yyrgRVxfEOJ7eqamSRT24KQ0PU0pDFuKv32Jwbjqxu/T 1omqpAi690t2YBHYzrZncNzU1ZVDLPsJ26hwfv4P7C4+3A3fgF/puMX3OGvm/pMojZA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796036624; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=5/UIxjK3K2JO0pi2VOa4oYXCNonhm7KQdx/6Uqjj/Q8=; b=wPKlJfIYoJtA9I+Mul9np5eAsXHcjF75mC8CtWyTW0OCYxmeraZV076gvIlHxh+9GGFL hKxGXPJVjJ9L/ImDakCGnFz1Q8WhdN+DlZHj7rmv9v1hV/Bf6gYobcj9aQFMc6Ynct8CA 1XZLxG80WHZ0VFRGpRyYonU1TxjCOU4IpiCAGV7RP3ZFAuEwN2p47wz0TEoxLlPZVHJyK o0coUxE6CgFHyb/KMgMpm/9e5zOIHM58LLDKffD9hqPQFRY1gvSgiOsw5PbIXY+Vicz6F V4r6gk4sBX5TgZr6bi9ApXt4fCg9Z4NLjG2hkC9u/mgYko9leNfU5JNLnr0hlFodJ6w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KFcE6nfG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0BA0606A32E; Mon, 30 Nov 2026 11:03:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KFcE6nfG Received: by smtp.kernel.org (Postfix) with ESMTPSA id D53001F00896; Mon, 30 Nov 2026 11:03:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796036623; bh=5/UIxjK3K2JO0pi2VOa4oYXCNonhm7KQdx/6Uqjj/Q8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KFcE6nfGFdWBWIiYMkCHI072DZ0dKmxWV2FzW4jDHZ8/IWeBPL+EkRvxXTfsvW6Ew cAIFXtLwcLNnczg/+0s9SHew0KcCWjVJp2pEobokpKa+rY4IdHwgRIAJpUeg88Bo7w OnG5TzCIvMfFmA0ga/DAbQosCyXGZqCttRgWS0P+lG2PyxfEiI9H4JQacMSM3Sdnm9 fxpGG9NSHNC6nEoAwIH7LSDDWPaQKBQNDsGQq5yvK+OivpZUBobjbV1/PuOxcwnEM9 Y6a5xR0rLZdFifsJ8VBp0Yw6G+i4Ij4bDkre7EqxsTLq9kQJEJhq7cTNXmdmpyRrMj 5BLyZt6O3GuwQ== From: Anand Jain To: fstests@vger.kernel.org Cc: zlang@kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v2 02/20] fstests: introduce _create_cloned_loop_devs() helper Date: Mon, 30 Nov 2026 19:03:04 +0800 Message-ID: <20261130-f_fsid-v2-2-c11fd1a5eaeb@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130-f_fsid-v2-0-c11fd1a5eaeb@kernel.org> References: <20261130-f_fsid-v2-0-c11fd1a5eaeb@kernel.org> X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Introduce _create_cloned_loop_devs() and _destroy_cloned_loop_devs to mkfs an image file and clone it to another image file, and attach a loop device to them. And its destroy part. Signed-off-by: Anand Jain --- common/rc | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/common/rc b/common/rc index e6d2acf84dc6..02d9a3562c3d 100644 --- a/common/rc +++ b/common/rc @@ -1534,6 +1534,72 @@ _scratch_resvblks() esac } +# Create a small loop image, run an optional tuning function ($2) on it, +# clone it, and attach both to loop devices, returned in ($1). +# Args: +# $1: Nameref to return the array of allocated loop devices [base, clone]. +# $2: Optional callback function to tune the base filesystem before cloning. +_create_cloned_loop_devs() +{ + local -n _ret=$1 + local pre_clone_tune_func="$2" + local img_file="$TEST_DIR/${seq}/orig.img" + local img_file_clone="$TEST_DIR/${seq}/clone.img" + local size=$(_small_fs_size_mb 128) # Smallest possible + local temp_dev + local loop_devs=() + + # All current callers mount the original and the clone simultaneously. + _require_clone_mount + + # Since we copy the block device image, we keep its size small. + _require_fs_space $TEST_DIR $((size * 1024 * 2)) + + _create_file_sized $((size * 1024 * 1024)) $img_file || + _fail "Failed: Create $img_file $size" + + temp_dev="$(_create_loop_device_like_bdev $img_file ${TEST_DEV})" + _mkfs_dev "${temp_dev}" + + # Only execute if the function argument is not empty + if [ -n "$pre_clone_tune_func" ]; then + $pre_clone_tune_func "${temp_dev}" + fi + + # We are about to copy the loop device's backing file + # Flush loop device's buffer cache + blockdev --flushbufs "${temp_dev}" + # Sync system's dirty pages including backing file's + sync + _destroy_loop_device "${temp_dev}" + + cp $img_file $img_file_clone || _fail "Failed to copy cloned image" + + loop_devs=("$(_create_loop_device_like_bdev $img_file ${TEST_DEV})") + loop_devs+=("$(_create_loop_device_like_bdev $img_file_clone ${TEST_DEV})") + + # Help debug + losetup --list "${loop_devs[0]}" >> $seqres.full + losetup --list "${loop_devs[1]}" >> $seqres.full + + _ret=("${loop_devs[@]}") +} + +# Teardown loop devices and delete their underlying backing image files. +# Accepts a list of loop device paths (e.g., /dev/loop0 /dev/loop1). +_destroy_cloned_loop_devs() +{ + for d in "$@"; do + # Retrieve the path of the backing file + local f=$(losetup --noheadings --output BACK-FILE $d) + + # Detach the loop device from the backing file + _destroy_loop_device "$d" + + # Clean up the backing disk image file + [ -n "$f" ] && rm -f "$f" + done +} # Repair scratch filesystem. Returns 0 if the FS is good to go (either no # errors found or errors were fixed) and nonzero otherwise; also spits out -- 2.43.0