Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp747981lqh; Thu, 28 Mar 2024 15:30:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLuJgU8VbUFLredG5qoZcQI35zlGKdIq93EzwOci3DavUDzE3EPxTZDYmsVAt5eoEbi/9rMtn2nV4tQKp48ZVXiSKlQ5Hio5vxaZzLeg== X-Google-Smtp-Source: AGHT+IElYdou24ZHOQbkYWT3maN6e5DFqrT0Pv0O/UgI0ai+A/wRMFzKlGB6k5jXiHWXUrITwrhp X-Received: by 2002:a0d:f247:0:b0:60a:6640:58f1 with SMTP id b68-20020a0df247000000b0060a664058f1mr789346ywf.45.1711665015223; Thu, 28 Mar 2024 15:30:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711665015; cv=pass; d=google.com; s=arc-20160816; b=QMToipagYkyxcsty/ai5nm0WA2ksxyvQBdisuM4eSMN+MUKBtKScIDlhPx5A+ezWlM uHcjc7JAFNchemFqyQG1HjpB45gLus24BgmyHKYsmleDTqiuDcyCvKy+avsm1/z/NSjC UmsUJjZgAq7TKBwD48VnScVssvqD2FEEPO5xISXgeXjSylSsvX+fKF7saGl1cAS6gEQ1 bM5nTq87j3CpGDTlXw3Panv4+Gz+9P7ZmhR+djkPWqLmg3FBuuhI3/1UR1pVzwlZjQES 0tFixz/KtopZ9XS1Ec6CepfZs8QzECbODmlZ+uucBML5fxfApTZQBFSW1hkhBEbsoB+l NJbQ== 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=RLjxk2wc4jymH4AwmcERFao5SrhB3AXX6RO0DVW/6VI=; fh=zaNS7a0ivRt0Jtyv5L6ZQWkVjRrFTtwidT0IM+uzgbQ=; b=AvW8/soxYGqJMIO+K5UW5ex35qBG1PeRjNDeaTZ4xn89pNaOEXoKmOhHwJEi3sZEiu 5ifwqKJjXFeNtnSk/bazupMBaZCUkgWEtB14NueGkjkQF+ddWRlBp6NipVMoCC/q2Ha0 Wy7wTmIxloJkg9CjjbLcM+GCV7/19IAnIEMB324f7VFcVpXK6vvYjPnCSYWqMw0112pp 8zZJ5tCGuXmvMEh1hLOVPJ1nRKvDRWaicZvJ+Z1r+Aag8k6s275/gSITx2fxH7OFrVXD h1U2GTp//YvV8zz69mfvhjbmgbjP/Fcaek69A61PDMfhIcPF/cAaLFStfcT4w/4ZxE5V AGLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g7C7iAhH; 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-123775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123775-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l9-20020a05620a210900b007885a7c32bdsi2451947qkl.201.2024.03.28.15.30.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 15:30:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g7C7iAhH; 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-123775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123775-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 898961C29B4B for ; Thu, 28 Mar 2024 22:30:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18B5E13B292; Thu, 28 Mar 2024 22:30:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g7C7iAhH" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 90B74139D16 for ; Thu, 28 Mar 2024 22:30:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711665010; cv=none; b=T+FAQkX5eQAG7BfhOcXvSoHN4yEgXUtkgvZNdlNrg03EozRzPM//E2oiUxRuskr8IVAp89unlRbIRMSiOdW6Bg2ItJeOrLGZUqVbg7/iIbk90Q29WW2ovlv08rS7IbEbQ/Kln8FZiiJj9S6/xsOOKOWQI4JnNIY9l/cuF9cO20g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711665010; c=relaxed/simple; bh=jNMwMosRuw1ECtOuwXay6HxPvPPRqcMN2lZS7RX/vm8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cVlw5RckgmFaU6xNyjuI7HZXJkZU1Bme//MKJ+EXb+gwUItTxRn341WovjR8g1ZSu9rEVwU4DzEY9sVp20c7E+0HDkBoKk34SpZ/4ICf68fUVkp7EgEwxU/lYi9kUOjhEHS5EWBmLj8EnjEeKgLzX/WHS+s9Etvs+CYnDRkRqDM= 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=g7C7iAhH; arc=none smtp.client-ip=170.10.133.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=1711665007; 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=RLjxk2wc4jymH4AwmcERFao5SrhB3AXX6RO0DVW/6VI=; b=g7C7iAhHNNaamgdgNbAaQDv4zefKUboJS9L01xoqfuSupo/nZCO71xoNP2/yT7S9vhn9ye ijkqMQ0bqtyRMz4Wjc0YtlhBmT/UNLjJej3O1srUXJ199rcYU5870nNN99YERjYNYJRSCF r0V/mj9MkwwvKYW064dzeil9bKGa/z4= 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-488-0VoqLDZMPAWlOIYT-scMbA-1; Thu, 28 Mar 2024 18:30:05 -0400 X-MC-Unique: 0VoqLDZMPAWlOIYT-scMbA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 7B5A7101CC6B; Thu, 28 Mar 2024 22:30:05 +0000 (UTC) Received: from redhat.com (unknown [10.2.16.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D71B9200AFFC; Thu, 28 Mar 2024 22:30:03 +0000 (UTC) Date: Thu, 28 Mar 2024 17:29:57 -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 0/9] block: add llseek(SEEK_HOLE/SEEK_DATA) support Message-ID: 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20240201 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Replying to myself, On Thu, Mar 28, 2024 at 05:17:18PM -0500, Eric Blake wrote: > On Thu, Mar 28, 2024 at 04:39:01PM -0400, Stefan Hajnoczi wrote: > > cp(1) and backup tools use llseek(SEEK_HOLE/SEEK_DATA) to skip holes in files. > > > > > In the block device world there are similar concepts to holes: > > - SCSI has Logical Block Provisioning where the "mapped" state would be > > considered data and other states would be considered holes. > > BIG caveat here: the SCSI spec does not necessarily guarantee that > unmapped regions read as all zeroes; compare the difference between > FALLOC_FL_ZERO_RANGE and FALLOC_FL_PUNCH_HOLE. While lseek(SEEK_HOLE) > on a regular file guarantees that future read() in that hole will see > NUL bytes, I'm not sure whether we want to make that guarantee for > block devices. This may be yet another case where we might want to > add new SEEK_* constants to the *seek() family of functions that lets > the caller indicate whether they want offsets that are guaranteed to > read as zero, vs. merely offsets that are not allocated but may or may > not read as zero. Skipping unallocated portions, even when you don't > know if the contents reliably read as zero, is still a useful goal in > some userspace programs. > > > - NBD has NBD_CMD_BLOCK_STATUS for querying whether blocks are present. The upstream NBD spec[1] took the time to represent two bits of information per extent, _because_ of the knowledge that not all SCSI devices with TRIM support actually guarantee a read of zeroes after trimming. That is, NBD chose to convey both: NBD_STATE_HOLE: 1<<0 if region is unallocated, 0 if region has not been trimmed NBD_STATE_ZERO: 1<<1 if region reads as zeroes, 0 if region contents might be nonzero it is always safe to describe an extent as value 0 (both bits clear), whether or not lseek(SEEK_DATA) returns the same offset; meanwhile, traditional lseek(SEEK_HOLE) on filesystems generally translates to a status of 3 (both bits set), but as it is (sometimes) possible to determine that allocated data still reads as zero, or that unallocated data may not necessarily read as zero, it is also possible to implement NBD servers that don't report both bits in parallel. If we are going to enhance llseek(2) to expose more information about underlying block devices, possibly by adding more SEEK_ constants for use in the entire family of *seek() API, it may be worth thinking about whether it is worth userspace being able to query this additional distinction between unallocated vs reads-as-zero. [1] https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md#baseallocation-metadata-context -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org