Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp702774lqh; Thu, 28 Mar 2024 13:42:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVkhNRanRfTzQZ2zyEe83468F1/6PeNWJHX7pwbVvaEkUku3lWwS26KMirn7W88diGUCBzqPe344fScZsO5sjqnGRefGcHrjkS1wTWYiA== X-Google-Smtp-Source: AGHT+IFWZ3sKuI/lGuKm9dmQOW6gPEMzjiu3UW/Z6tbySM+SxLZotGzu98cLftPcU52CGTfM0UcX X-Received: by 2002:a05:620a:4489:b0:789:f0e3:d8a9 with SMTP id x9-20020a05620a448900b00789f0e3d8a9mr1214150qkp.13.1711658575128; Thu, 28 Mar 2024 13:42:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711658575; cv=pass; d=google.com; s=arc-20160816; b=cLuVG3Z9pVVTsnb7+DOWs4a6YRJCmDM3XZV6Ep55OfcF5LQ20VZhpD5FzHYhG4OYsz gqyYyxAcI3FeiIpv1p/H5omcVW/12Z815p9QFeRmqbbUqldZgv7D+jwEEj4d9FLqjTok wnyJY/a4dkIGtK6gaO8FEt5Pq4LmrxQnDo8+UNmzNbO3H4sh8hnRP0iWgB95gOzF3A6/ BdF1wBe8NHGFDDtgrld2A/OlskmmBZtBoFO4WjElzYwYiWLyLrdoObDmO1w5y1zswZad y0F347WISiJfCQ4+zyFm+ha9Nr2nzOcnlqlW3MwV6O0KEj9fyYkP3W8qaVEOiRRL12Ju kJyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=y4QwQ4LobXpOZeMcmZtW4ftxyW2t074qf+BN+wufuQA=; fh=RMJuV2Y3SJza63ZzuPXP6nO1gt49mM9k7teQJSpE9RE=; b=ARRpvEvlrcuVa+Li0/4y3kP26DfKyxmhx2r+VNexjcq7bT/YJ1lQcsfZYsmdq10DnF LWrzLjZ1QmwkyBH+aIeSJajiDx/xStlmARyYfmcXvpCz0ZRI4d9wOeXd9V0nvIYGISWu w/Gg5tzS4N68L/B+ZkfT6an9JU4y9P1nQhGE52+8m/aNf3dc8zxqrN/HI/xGF+A0fPqi Suh8+l/YNxxj8ACdndFc/lZ39+wZTWWWM7KWNM6r6Nu/q+s7o2dJiLWMX5zBcqrZnwJV C04fbZx5//Y8cvHEu2xiNZO0XqneO+oKoaCBPvW5ds68Aw2HQAZxg8iT5xTGKiBbWCE/ yqkA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WkeU1nLy; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-123609-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123609-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h9-20020a05620a400900b0078a47c3a3bdsi2462053qko.620.2024.03.28.13.42.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 13:42:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123609-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WkeU1nLy; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-123609-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123609-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C481B1C3081B for ; Thu, 28 Mar 2024 20:42:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 985E513A414; Thu, 28 Mar 2024 20:41:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WkeU1nLy" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 2036C13A271 for ; Thu, 28 Mar 2024 20:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711658462; cv=none; b=QYBo8QZ+kEVS59EWQEbLRmGesO3Bb0xojrj3fLKFwjaqbBCWE0SMkF/vEf6ErDsw5kbcc3MwugPkSXkrciO7zHPaFT34Nb0fKHf9+K+pRJJaoUwCeCA8xxV8qVGMXFxFQYi6ZCOpnrqkTf/asuHPneXPwuQfDBMoXycyM8F2Zdk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711658462; c=relaxed/simple; bh=4LVr4XIyTxfxImYgjXFnrBvXpjmjemBkyYv51+FUVj0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VpNaNNmB666R6KCDXV2xfEv54R94VfYmlnYj6tOgR5rwoGRXXBlh7XYItz4y0g/ncBe2E5FZnYiiFkX27C89WKYeBwtIY1o8yO2TYUQbiiP+SGlV1uQgN/WbYny0v6/TyWelT3MfgrdG/2JNIKY/twC2eex4z57ADy4fvQ0B4zs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WkeU1nLy; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711658460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y4QwQ4LobXpOZeMcmZtW4ftxyW2t074qf+BN+wufuQA=; b=WkeU1nLyZwpjusMGdTH8N7QNbPk1F7C7Q9lF2HmqjBKle6zFMIuGpfG/1ps70H/eFr6uOz cjOCQLV3z2z+OSYacIsIfXRSwCuldg0QareOS8jaQK5kl8xWBobFEfqJ/aDV8tID7+K8eo Jq/nMox66h5/LImMEl9UyXMlSyTdKe8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-FGHnscCFOt2rRDtvRy7V4Q-1; Thu, 28 Mar 2024 16:40:56 -0400 X-MC-Unique: FGHnscCFOt2rRDtvRy7V4Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4C74A8007A7; Thu, 28 Mar 2024 20:40:56 +0000 (UTC) Received: from localhost (unknown [10.39.194.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0F5B3C54; Thu, 28 Mar 2024 20:40:54 +0000 (UTC) From: Stefan Hajnoczi To: linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, eblake@redhat.com, Alasdair Kergon , Mikulas Patocka , dm-devel@lists.linux.dev, David Teigland , Mike Snitzer , Jens Axboe , Christoph Hellwig , Joe Thornber , Stefan Hajnoczi Subject: [RFC 9/9] selftests: block_seek_hole: add dm-thin test Date: Thu, 28 Mar 2024 16:39:10 -0400 Message-ID: <20240328203910.2370087-10-stefanha@redhat.com> In-Reply-To: <20240328203910.2370087-1-stefanha@redhat.com> References: <20240328203910.2370087-1-stefanha@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Signed-off-by: Stefan Hajnoczi --- .../selftests/block_seek_hole/Makefile | 2 +- .../selftests/block_seek_hole/dm_thin.sh | 80 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/block_seek_hole/dm_thin.sh diff --git a/tools/testing/selftests/block_seek_hole/Makefile b/tools/testing/selftests/block_seek_hole/Makefile index 1bd9e748b2acc..3b4ee1b1fb6e7 100644 --- a/tools/testing/selftests/block_seek_hole/Makefile +++ b/tools/testing/selftests/block_seek_hole/Makefile @@ -3,7 +3,7 @@ PY3 = $(shell which python3 2>/dev/null) ifneq ($(PY3),) -TEST_PROGS := test.py dm_zero.sh +TEST_PROGS := test.py dm_zero.sh dm_thin.sh include ../lib.mk diff --git a/tools/testing/selftests/block_seek_hole/dm_thin.sh b/tools/testing/selftests/block_seek_hole/dm_thin.sh new file mode 100755 index 0000000000000..a379b7c875f28 --- /dev/null +++ b/tools/testing/selftests/block_seek_hole/dm_thin.sh @@ -0,0 +1,80 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# +# dm_thin.sh +# +# Test that dm-thin supports SEEK_HOLE/SEEK_DATA. + +set -e + +# check +# Check that the actual output matches the expected output. +check() { + if [ "$1" != "$2" ]; then + echo 'FAIL expected:' + echo "$2" + echo 'Does not match device output:' + echo "$1" + exit 1 + fi +} + +cleanup() { + if [ -n "$thin_name" ]; then + dmsetup remove $thin_name + fi + if [ -n "$pool_name" ]; then + dmsetup remove $pool_name + fi + if [ -n "$metadata_path" ]; then + losetup --detach "$metadata_path" + fi + if [ -n "$data_path" ]; then + losetup --detach "$data_path" + fi + rm -f pool-metadata pool-data +} +trap cleanup EXIT + +rm -f pool-metadata pool-data +truncate -s 256M pool-metadata +truncate -s 1G pool-data + +size_sectors=$((1024 * 1024 * 1024 / 512)) # 1 GB +metadata_path=$(losetup --show --find pool-metadata) +data_path=$(losetup --show --find pool-data) +pool_name=pool-$$ +thin_name=thin-$$ + +dmsetup create $pool_name \ + --table "0 $size_sectors thin-pool $metadata_path $data_path 128 $size_sectors" +dmsetup message /dev/mapper/$pool_name 0 'create_thin 0' +dmsetup create $thin_name --table "0 $size_sectors thin /dev/mapper/$pool_name 0" + +# Verify that the device is empty +check "$(./map_holes.py /dev/mapper/$thin_name)" 'TYPE START END SIZE +HOLE 0 1073741824 1073741824' + +# Write 4k at offset 128M but dm-thin will actually map an entire 64k block +dd if=/dev/urandom of=/dev/mapper/$thin_name bs=4k count=1 seek=32768 status=none +check "$(./map_holes.py /dev/mapper/$thin_name)" 'TYPE START END SIZE +HOLE 0 134217728 134217728 +DATA 134217728 134283264 65536 +HOLE 134283264 1073741824 939458560' + +# Write at the beginning of the device +dd if=/dev/urandom of=/dev/mapper/$thin_name bs=4k count=1 status=none +check "$(./map_holes.py /dev/mapper/$thin_name)" 'TYPE START END SIZE +DATA 0 65536 65536 +HOLE 65536 134217728 134152192 +DATA 134217728 134283264 65536 +HOLE 134283264 1073741824 939458560' + +# Write at the end of the device +dd if=/dev/urandom of=/dev/mapper/$thin_name bs=4k count=1 seek=262143 status=none +check "$(./map_holes.py /dev/mapper/$thin_name)" 'TYPE START END SIZE +DATA 0 65536 65536 +HOLE 65536 134217728 134152192 +DATA 134217728 134283264 65536 +HOLE 134283264 1073676288 939393024 +DATA 1073676288 1073741824 65536' -- 2.44.0