Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2720613lqz; Wed, 3 Apr 2024 06:52:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXovdf7TybqouIXbExkXMNLXpKkVcSzsVqtM/DJ6ZTHxn9OpMEUC+XIRR35PS1r9tQSbRsJ2fCRvAyZUWpOJTCJvWocb0lRUn/d2o9VEg== X-Google-Smtp-Source: AGHT+IFGo4P7SiNcfuXkuEZVRlzKQyeRnmHrP6WtIRoFFNHZm+ZaOg4nuZC8JcEamGAk2FrKj1Bz X-Received: by 2002:a17:906:c9d5:b0:a46:ede0:2370 with SMTP id hk21-20020a170906c9d500b00a46ede02370mr11215750ejb.57.1712152327024; Wed, 03 Apr 2024 06:52:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712152327; cv=pass; d=google.com; s=arc-20160816; b=KRdh/+m8ASkkb/tKDJAPxx0uYP0YgfdXXPfTiYLA+cBB6jbxYRNmFQKVsRa4TLDHko AoBG2XGLnrM/XZ0f+Vc15rHlA1CWbogpjnbyPzIZdwXw2zplVMROdOupSuQyGVQUKUIf Oq+8Z8s106PUaGKTy9N8SrdQe8gGixprVPR7g9qmXuMPLtpHHtguRXJcHUuPklNcZ/B/ FUEvbiSURbv50hNlugYsEbHKgI2tx4cINFIcIEeZjyfRzAauyn0w2z5kh6PTb/DfUxyB 3I76/k6NteRRCCMp15vnxTtDTGqQP1x37ZK9BsALeciWzv+Bba4/CEjC+y7hMdUeTjAb Krog== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=PllW2rrzDmRw3e0KEKEhY+erPYkfL+5VU6NwuszEdv4=; fh=wCBiBTjRqgoQ8Ea5p+onfgwFbfOWx/Zorp1mtG6ilR8=; b=HAM9x/7FAqhqT7ZtwZivrtDXXsMgxnpjK0INQpiZ3ISDlwacTYIt0CkzSbXptjxLye G0dArT5Ombu8IlKC7UVNCM+jms3TrqY1qjLIT9IdgxZzA8HFA1zGrHSJlhOUJ5dTDnFu iSXR/BYf2Al4LKNjsBLtHOWMs1JtkV5/jMG9UL1mFGPDjoQPO/0uUGMWCxFotxfYpYpN nojVAHEx/XKZB4NPkenSM3aLXnDFnuWGqJkfaHMzgUg1IB8Pjek1oZxLC6z+3YLcQK7H ZCJd8mevIlj2R7aaErZqIzDA8sDnHHfevd8u4M2hGPn/pT76G8OFiwm5L0aQaDiWyK/b b2dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PND15TIU; 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-129884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129884-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q22-20020a17090622d600b00a4e6d72530csi3085057eja.130.2024.04.03.06.52.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 06:52:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PND15TIU; 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-129884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129884-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 7837B1F2627B for ; Wed, 3 Apr 2024 13:52:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5809B14885E; Wed, 3 Apr 2024 13:51:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PND15TIU" 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 CD3061487FF for ; Wed, 3 Apr 2024 13:51:53 +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=1712152315; cv=none; b=NvbG18h8w4sVSZSPovAn602jZjq09/zMZFag6GqhW6ZEoNFE+9qUsVfDknVpoR/U1xD07H2gnjCqjn1GpjgS4P/JHpcrv9Z3hrglKK62WYnu+sdQNiWxG7H84OmGV3y3UQuhiaHzNH/cLQedoCLg+ktI3Bk15an8xqWt/wLf8hY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152315; c=relaxed/simple; bh=pHG2tsAWxZn37gkN2Ny9kczSaLWLC3JNDuMK3nNmWfk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D39PEpDrsCl+byWcGawCNf+zSE05f3J7qZOfvZzTxeHQuyxT/RIu9hvVxHPTfkqN+zysQm8HsE0r98jMyfXBmnMZOrkt4uIQdzTjMT+7JGfRNuB0b6SqbKTqvlvrlnhPvYGGESz5bAZyuVaoVsbmfF+eagcvXx/WZkU25HwiJkY= 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=PND15TIU; 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=1712152312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PllW2rrzDmRw3e0KEKEhY+erPYkfL+5VU6NwuszEdv4=; b=PND15TIUNZamv5rJnsaaywSgReJ3PURFIWzcGhp73BUexl82vlFNyBES0qWlyN4ff2jhfV GvDNSYPgAkdoBbasLlO/DceiH29/ZntLPh84DI6dTCDO5eid/JzJQkFX9m7l8sPdrkkKAO iMog5ww4Qyxog4dQONN4nzfqW7yz4Mw= 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-271-VpdpYk3KMV-H449pwJ6bOw-1; Wed, 03 Apr 2024 09:51:49 -0400 X-MC-Unique: VpdpYk3KMV-H449pwJ6bOw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 CB85B8828C2; Wed, 3 Apr 2024 13:51:48 +0000 (UTC) Received: from localhost (unknown [10.39.194.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id F351BC04122; Wed, 3 Apr 2024 13:51:47 +0000 (UTC) Date: Wed, 3 Apr 2024 09:51:42 -0400 From: Stefan Hajnoczi To: Eric Blake Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Alasdair Kergon , Mikulas Patocka , dm-devel@lists.linux.dev, David Teigland , Mike Snitzer , Jens Axboe , Christoph Hellwig , Joe Thornber Subject: Re: [RFC 3/9] selftests: block_seek_hole: add loop block driver tests Message-ID: <20240403135142.GC2524049@fedora> References: <20240328203910.2370087-1-stefanha@redhat.com> <20240328203910.2370087-4-stefanha@redhat.com> <6mssvnoq4bpaf53kkla45np5lijptyh4c2orayqx4mqacj572u@6s4y6bhdtcpm> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="x2om3oEq6ukG/tIJ" Content-Disposition: inline In-Reply-To: <6mssvnoq4bpaf53kkla45np5lijptyh4c2orayqx4mqacj572u@6s4y6bhdtcpm> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 --x2om3oEq6ukG/tIJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Mar 29, 2024 at 07:38:17AM -0500, Eric Blake wrote: > On Thu, Mar 28, 2024 at 04:39:04PM -0400, Stefan Hajnoczi wrote: > > Run the tests with: > >=20 > > $ make TARGETS=3Dblock_seek_hole -C tools/selftests run_tests > >=20 > > Signed-off-by: Stefan Hajnoczi > > --- > > tools/testing/selftests/Makefile | 1 + > > .../selftests/block_seek_hole/Makefile | 17 +++ > > .../testing/selftests/block_seek_hole/config | 1 + > > .../selftests/block_seek_hole/map_holes.py | 37 +++++++ > > .../testing/selftests/block_seek_hole/test.py | 103 ++++++++++++++++++ > > 5 files changed, 159 insertions(+) > > create mode 100644 tools/testing/selftests/block_seek_hole/Makefile > > create mode 100644 tools/testing/selftests/block_seek_hole/config > > create mode 100755 tools/testing/selftests/block_seek_hole/map_holes.py > > create mode 100755 tools/testing/selftests/block_seek_hole/test.py > >=20 >=20 > > + > > +def map_holes(fd): > > + end =3D os.lseek(fd, 0, os.SEEK_END) > > + offset =3D 0 > > + > > + print('TYPE START END SIZE') > > + > > + while offset < end: > > + contents =3D 'DATA' > > + new_offset =3D os.lseek(fd, offset, os.SEEK_HOLE) > > + if new_offset =3D=3D offset: > > + contents =3D 'HOLE' > > + try: > > + new_offset =3D os.lseek(fd, offset, os.SEEK_DATA) > > + except OSError as err: > > + if err.errno =3D=3D errno.ENXIO: > > + new_offset =3D end > > + else: > > + raise err > > + assert new_offset !=3D offset > > + print(f'{contents} {offset} {new_offset} {new_offset - offset}= ') > > + offset =3D new_offset >=20 > Over the years, I've seen various SEEK_HOLE implementation bugs where > things work great on the initial boundary, but fail when requested on > an offset not aligned to the start of the extent boundary. It would > probably be worth enhancing the test to prove that: >=20 > if lseek(fd, offset, SEEK_HOLE) =3D=3D offset: > new_offset =3D lseek(fd, offset, SEEK_DATA) > assert new_offset > offset > assert lseek(fd, new_offset - 1, SEEK_HOLE) =3D=3D new_offset - 1 > else: > assert lseek(fd, offset, SEEK_DATA) =3D=3D offset > new_offset =3D lseek(fd, offset, SEEK_HOLE) > assert new_offset > offset > assert lseek(fd, new_offset - 1, SEEK_DATA) =3D=3D new_offset - 1 >=20 > Among other things, this would prove that even though block devices > generally operate on a minimum granularity of a sector, lseek() still > gives byte-accurate results for a random offset that falls in the > middle of a sector, and doesn't accidentally round down reporting an > offset less than the value passed in to the request. Sure. I'll add a test for that. Stefan --x2om3oEq6ukG/tIJ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmYNXu4ACgkQnKSrs4Gr c8jiRAgAlRZwKBwtx8HTSPWTyPF1aDumwwjfPHI+L3n47d0TYnJk8hmb5wCBUAnr FLm8+SC46srUixEQEdwLL9DdVEu3QHMKHJtQVWU3ShF+izCE3rlGT9BhNl+ZyBDY xWrnBy8kgmdxqvjwyca49jOTLmnS/LaM6uBybK3hk9zQZgcI36phl+OZCwyct7dj 3L3UuOAYCwnqxDdNvm9mVhCeAAnf5F8WECCR8ZUfw7ejPASc9Gzw90tyDn7RrQKU Gubm9DS0I0vTe5XWwnDY0PtUxE/Y+waT1YIkwE9FrE//uswssKJ01cZT0FW8HZhD 1Z4wdIuFUendZtJhVZpMcXp+cUM9lg== =chJ4 -----END PGP SIGNATURE----- --x2om3oEq6ukG/tIJ--