Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp702478lqh; Thu, 28 Mar 2024 13:42:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUdUUrKv5HAcgf6vv1Ljfxets99UcVPDFbktaTU8hZY84xKM2N6mBERLNmB63ifYu41YzSH0sK6wGe4GpWYkEaxn+ZY962ziR27IM7aSw== X-Google-Smtp-Source: AGHT+IGF2JU2XnHSsoP341qmGuG8vykN+adUakLL/Oy8PDetOFQR6EfXlnSglff81xolmtwFK/hu X-Received: by 2002:a17:902:ee86:b0:1e0:552d:8a1b with SMTP id a6-20020a170902ee8600b001e0552d8a1bmr520294pld.57.1711658529892; Thu, 28 Mar 2024 13:42:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711658529; cv=pass; d=google.com; s=arc-20160816; b=J227mCnt67ra8RUSgd9Avj9ne2+sEk9mF7htAcXHlxXWT55JZsvy/itL31YIyfp+Pm fc3yDYtjNHnsGhg93nMgoUf9UWd3tFlJ1bXzF9DECe9m8dIlv4o8eGnARb9KjRQAaOzw FTHbzxwn7pEA5zPtTm5URutcv5fuJdGuGSSFl0fluIHJxhymc3qtYx9jw/pzNY4zXYJV qWPfKj1e7a0WmqiX6Hnhg1hAeXgpQwc/+1KQ72rNW3xGYuDC0ilYHhzLyqmy3MGGZh18 Wv5SCM1BONkj43hGAIlU865EB7JeNp+1toRgVcyFQyTgWE6QCjS+eD5ir4KoVQDTUi9N 8FfA== 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=NXXER/zigpP/1IR48CBo1zF8A1UxNQTU4ClNAQkl164=; fh=RMJuV2Y3SJza63ZzuPXP6nO1gt49mM9k7teQJSpE9RE=; b=mvoZTYkNS4Xtvr34g+YVjJWVZ7Mkj3cjZH6b04vwepaXcuUDcMG51fu3uf+spjRg1A YhVY/f3mSgQVUzoGIb1UcdYWdKuumCxS1T164qOn/74QTi91aqlqn5JlrFR9EdVzhpbJ 4HSK3SF42BvO9J/1doEQnD1opDlfilg6xOdMeXXt3tc0sKSUrb83KXZ0/qcVOnr0df9d MTcfadWRXZt3gpgohgu3gLNd6nLwANt+I88OSxxYZyecmSP6Tb66pm/iVD05ersl3xrY KM4fispwdXD5qQhkdseA3A6kZWlOyzRd2cqN06W7aULF7wQuMPt1gjc11HEH2jLNIDtE WMsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Y9YL/Hgj"; 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-123606-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123606-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 h5-20020a170902680500b001e032f464b3si1977533plk.559.2024.03.28.13.42.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 13:42:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123606-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="Y9YL/Hgj"; 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-123606-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123606-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 8FAB8299E00 for ; Thu, 28 Mar 2024 20:42:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7140D13AA48; Thu, 28 Mar 2024 20:40:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y9YL/Hgj" 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 3678E13A879 for ; Thu, 28 Mar 2024 20:40:24 +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=1711658426; cv=none; b=PMtpX7JeZZWcPcKCqRXRb7qPqrt3XArnv6ZtlJN+7bkvvYcNpXvNwSnojo0eA+Cr0Z9euSwY0UYLdewWD1/sRJ+aSJ8eT7AhymFZzNmAc14qrkxYVKkCWv2Z4guwl2mCyxfdV11q7oQARa/AkP5hjFKHYvJ6kWKOq5X9kbyw7Rw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711658426; c=relaxed/simple; bh=9Z6YD6FPCzBTKeIPm1fHe9GnkbXDhxoo7eDcvyUvuCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JwwcVYaNileKZAEXDK09ujiq3h4sF9MbeFPG3CALqqdYVfw7HLINB+mSLZyzK3yZNu3M2hRfS7UxxVSYqY/9pAIRP5BTgc+LFu5++FwgjkB4oeF3MY8Xndx8eQt9d0MX3ZOTZ3DtO3BAyNiDUnHpjtzSNJfqDKw4awEtPcFlIfU= 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=Y9YL/Hgj; 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=1711658424; 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=NXXER/zigpP/1IR48CBo1zF8A1UxNQTU4ClNAQkl164=; b=Y9YL/HgjjPxfYCZDl767fff+NePAiuupg5PsmF7Ynm8ttbtCXYySJ4Z005lxl7O6AL8iqR n4B+Hd+hDFuS+tckyouIuNXd1Wes+Ayz1UqIrh2Kc7K7OLjjUMqt2CusYxW0qXyeRgqlux 4dOcioqxI6qTGV4uvXdYdkWsb9w/T0Y= 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-595-5C6a797YMhSPfEhO_58Kmg-1; Thu, 28 Mar 2024 16:40:20 -0400 X-MC-Unique: 5C6a797YMhSPfEhO_58Kmg-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 50E4888905E; Thu, 28 Mar 2024 20:40:20 +0000 (UTC) Received: from localhost (unknown [10.39.194.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 474F3C1576F; Thu, 28 Mar 2024 20:40:18 +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 6/9] dm-linear: add llseek(SEEK_HOLE/SEEK_DATA) support Date: Thu, 28 Mar 2024 16:39:07 -0400 Message-ID: <20240328203910.2370087-7-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.8 Signed-off-by: Stefan Hajnoczi --- drivers/md/dm-linear.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index 2d3e186ca87e3..9b6cdfa4f951d 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c @@ -147,6 +147,30 @@ static int linear_report_zones(struct dm_target *ti, #define linear_report_zones NULL #endif +static loff_t linear_seek_hole_data(struct dm_target *ti, loff_t offset, + int whence) +{ + struct linear_c *lc = ti->private; + loff_t ti_begin = ti->begin << SECTOR_SHIFT; + loff_t ti_len = ti->len << SECTOR_SHIFT; + loff_t bdev_start = lc->start << SECTOR_SHIFT; + loff_t bdev_offset; + + /* TODO underflow/overflow? */ + bdev_offset = offset - ti_begin + bdev_start; + + bdev_offset = blkdev_seek_hole_data(lc->dev->bdev, bdev_offset, + whence); + if (bdev_offset < 0) + return bdev_offset; + + offset = bdev_offset - bdev_start; + if (offset >= ti_len) + return whence == SEEK_DATA ? -ENXIO : ti_begin + ti_len; + + return offset + ti_begin; +} + static int linear_iterate_devices(struct dm_target *ti, iterate_devices_callout_fn fn, void *data) { @@ -212,6 +236,7 @@ static struct target_type linear_target = { .direct_access = linear_dax_direct_access, .dax_zero_page_range = linear_dax_zero_page_range, .dax_recovery_write = linear_dax_recovery_write, + .seek_hole_data = linear_seek_hole_data, }; int __init dm_linear_init(void) -- 2.44.0