Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp1070159lqh; Fri, 29 Mar 2024 06:30:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/+LjgM/sutoqCiQ+X3bmt7teAXIi4SQ0fKlqtarQR9xm5sbq/mLJssqm+ftBPVIrEI9c+WM2xdmGtlRe5zKjWtmyfLTWCZhfMIZeDdQ== X-Google-Smtp-Source: AGHT+IFG5d6bFJSTQpNfVcx9VXlp8thPS2sjrP8eOw7K4hgBbJVbdtHkR4sNDqpXmmN1+z9qtaN/ X-Received: by 2002:a05:6a00:1ad4:b0:6e6:9a11:ccec with SMTP id f20-20020a056a001ad400b006e69a11ccecmr2470492pfv.17.1711719015973; Fri, 29 Mar 2024 06:30:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711719015; cv=pass; d=google.com; s=arc-20160816; b=A+yoHyrAykLGqXkjp545wYb94Cgijlq6wllE0HwsIud1Aljow/YbmvRjdOvK9C9Rfc AqQiH8z29x85Iw4AoZPZKTNlfGh/jiM3drQ9Ghjn2jQKB7AM1R4dmbOSJU0K1wbWDJ6f leMYPo0jgZVA1VXD8S/OhpGt7jxSM5AL3qPaAgJmX8ajAQ7IkVkgnOMKEq4qmt71+rjE 5KxQoRJUAetR0L/ftTDVO+qBlS5UzP7XF5H3yYom2XleSUrg/W1QhgJSPJAqmMibS0iQ FpmjutLp4yadeUE+Ue0kVtHa184daxHUB7jZDYOkJoEfIJCZj59QfJJHpIXYsmHh/1r4 BW4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent: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=N1h/sI7lud1TUTbC3pqJNKCflJ35bQiddXm8poucTAE=; fh=zaNS7a0ivRt0Jtyv5L6ZQWkVjRrFTtwidT0IM+uzgbQ=; b=UmQxdG2D7A1UQ8yIkK0wpoPnSVEZaRRS2lw2TxAqFNK6ZH5wPLAFFtvV706AvDQfov GH0oZKZDdcuQaWa1zq4iGYnRTKgj54GGSpvPvES9F3fN8s23i952X5Eclcuiu9PfpHy0 dGFSH/RnM3dskqZGz4SywVbr4n/yGeLu1iyVDMyCFp90WesS4awtgWeGCRz3lZQJSZsq LSeCky6gfg3Isr6MlH1QkM+XR7nqw7WSfF0k3kg+07Z0hxfXAzJp9B9wCQ5Rcwrg/KzZ NETRNL90pd3zy1DTDSr7Vf7wElynVOXNWwrcisSVH73c0UKWEnDxVZD7nEjV3/Uxydef 7Vig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hfKZNYdl; 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-124708-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124708-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id by41-20020a056a0205a900b005ceca1094c3si4009655pgb.853.2024.03.29.06.30.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 06:30:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124708-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hfKZNYdl; 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-124708-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124708-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A841529435F for ; Fri, 29 Mar 2024 13:30:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B672A143C63; Fri, 29 Mar 2024 12:38:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hfKZNYdl" 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 35C5813664E for ; Fri, 29 Mar 2024 12:38:28 +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=1711715910; cv=none; b=BbuWyDXmo5g9oED/5OXX5C5aSbayQjIGR6qzbhooB+7YAn2NfRJZwFt/b9zM5iP3p4mf3f8Q/YA1LjK07nQnmNUg75YPnmc3OE83w6nHgafeyB2/PKzHHi/bdJ+OBZUcCxAc5iZ+7yMmYByfod+dAjWol9ClXX7YbB7xNWd/qJs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711715910; c=relaxed/simple; bh=/Vcs98eIwBfAVmQudxzEl/D2HfXg0h5pd/qnhUjw8Bw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fmHiqiZ6Gt9V/Kd9C/KlepDuywSUcfs5c443nHNk33B834F6FroaiF1fd9JvALpZLlSaIdM4RYhcYAdpI5lwHb/Wog4gIoD2rDs+ZvXrNNlxP3krxdFnuBAiD39RCeUN0GPFXp0Zm8c7piqsHGrU/h1pTNYKV295ZlHqCDYKC2o= 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=hfKZNYdl; 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=1711715908; 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=N1h/sI7lud1TUTbC3pqJNKCflJ35bQiddXm8poucTAE=; b=hfKZNYdlLphaCTkvHxNg2pdVcwd/IDFfmxgIKKXCFWZfi7KB6K2NiwR3ARNGmW7PUmkYJ4 mtsFG3qSlzrr3PMhWm+sCSQ7K3qrNJ4Gk63slI4hPmRvpYCprDYqQIlApXKsy3sFdPn4HQ SlJo8/nSz7P0MMAk5r7F+zKh5blJLtI= 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-647-jud4lLB8PvKF1NeK86-r7w-1; Fri, 29 Mar 2024 08:38:26 -0400 X-MC-Unique: jud4lLB8PvKF1NeK86-r7w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 9AA7B85A58C; Fri, 29 Mar 2024 12:38:25 +0000 (UTC) Received: from redhat.com (unknown [10.2.16.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ADE19111E3F3; Fri, 29 Mar 2024 12:38:22 +0000 (UTC) Date: Fri, 29 Mar 2024 07:38:17 -0500 From: Eric Blake To: Stefan Hajnoczi 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: <6mssvnoq4bpaf53kkla45np5lijptyh4c2orayqx4mqacj572u@6s4y6bhdtcpm> References: <20240328203910.2370087-1-stefanha@redhat.com> <20240328203910.2370087-4-stefanha@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240328203910.2370087-4-stefanha@redhat.com> User-Agent: NeoMutt/20240201 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 On Thu, Mar 28, 2024 at 04:39:04PM -0400, Stefan Hajnoczi wrote: > Run the tests with: > > $ make TARGETS=block_seek_hole -C tools/selftests run_tests > > 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 > > + > +def map_holes(fd): > + end = os.lseek(fd, 0, os.SEEK_END) > + offset = 0 > + > + print('TYPE START END SIZE') > + > + while offset < end: > + contents = 'DATA' > + new_offset = os.lseek(fd, offset, os.SEEK_HOLE) > + if new_offset == offset: > + contents = 'HOLE' > + try: > + new_offset = os.lseek(fd, offset, os.SEEK_DATA) > + except OSError as err: > + if err.errno == errno.ENXIO: > + new_offset = end > + else: > + raise err > + assert new_offset != offset > + print(f'{contents} {offset} {new_offset} {new_offset - offset}') > + offset = new_offset 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: if lseek(fd, offset, SEEK_HOLE) == offset: new_offset = lseek(fd, offset, SEEK_DATA) assert new_offset > offset assert lseek(fd, new_offset - 1, SEEK_HOLE) == new_offset - 1 else: assert lseek(fd, offset, SEEK_DATA) == offset new_offset = lseek(fd, offset, SEEK_HOLE) assert new_offset > offset assert lseek(fd, new_offset - 1, SEEK_DATA) == new_offset - 1 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. -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org