From patchwork Sat Oct 7 01:28:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Kukreti X-Patchwork-Id: 13412131 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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.lore.kernel.org (Postfix) with ESMTPS id 2B705E94139 for ; Sat, 7 Oct 2023 01:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696642141; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HcFjBQb2hq2sGfh9w07VCF7PT1cALaIXoQp7PZM6Vlk=; b=P5vXlxxxkvnHzxHREYRZq3HZFJz0eUknsGpMjWspS4Y+9B6CaOPZidji9hRMKi2OegHoLJ 5qtMj0JiwZeE8Q+Nw85Nbx34LnSgtwSAXEFOnFaG89tjFDIJ64mcV7mj+Jju1Z7tA5XBq/ PHZ1lz7se0vsKF66g0c7Bmo+2B+U4Rg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-79-0srYIhn3NDmINfdV9RhBBg-1; Fri, 06 Oct 2023 21:28:48 -0400 X-MC-Unique: 0srYIhn3NDmINfdV9RhBBg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DC20E3C0F370; Sat, 7 Oct 2023 01:28:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC6A842485F; Sat, 7 Oct 2023 01:28:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AB3031946589; Sat, 7 Oct 2023 01:28:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D61A51946588 for ; Sat, 7 Oct 2023 01:28:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B56FEC158BA; Sat, 7 Oct 2023 01:28:44 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast07.extmail.prod.ext.rdu2.redhat.com [10.11.55.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD484C15BB8 for ; Sat, 7 Oct 2023 01:28:44 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (unknown [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 85F323C0F378 for ; Sat, 7 Oct 2023 01:28:44 +0000 (UTC) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-3epDXGGSPoaDwDBHDnKvkQ-1; Fri, 06 Oct 2023 21:28:27 -0400 X-MC-Unique: 3epDXGGSPoaDwDBHDnKvkQ-1 Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-58d261807e8so6017a12.2 for ; Fri, 06 Oct 2023 18:28:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696642106; x=1697246906; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rQNnXBnSwzfsN2zrI7/k3aUY1SO1WpMoDwjEZpkrIxM=; b=EBYYdjWgKnbktqiaQxHtGfTkof2ffuQfxQC6cVxFROqWnqh3KK9LPgWp16ISfrfNYJ RvLtnIRiFNfY+sZuWTJ8v7QQ1MkoQGIZF+okN/g7XQsVE4wsL4WbhPc8Z6bQZZ5sD11u fSZMAah8E/CusDhA0SOdESAWgJyJ0zcQdAIoHKcY4eVhGKG9Xf4+aR33modOApxIDInV O7a5BS0SPT9Nkmz/ZUvkCmNGpbr5ybO51EltHmjlRGlBeOKCFNIJY2RZ+St+ULGw7uOp ftiE7jLpXtpA8E73ERzo9lHonDprH7A6Wqxdq7wLpR5PpkrD/hwNlnZrssW73BX+8dk7 WzXg== X-Gm-Message-State: AOJu0Yypbx7oN7fJhnQ2JtVm0DOEEWsDF/j7Zr3cayX8jSDWvToRnF7e 9scS9VqS+S5CIWhEbeLB9StLd3nV1n5vAo8ClNQ= X-Google-Smtp-Source: AGHT+IFgSpdJXRlHpObTlC1ba3rWEGA93CD9bVltNHco7wy1/jSBrQ0keIe/jvsDstn28NxLhH5baA== X-Received: by 2002:a05:6a20:9699:b0:161:2bed:6b36 with SMTP id hp25-20020a056a20969900b001612bed6b36mr8700355pzc.31.1696642106158; Fri, 06 Oct 2023 18:28:26 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:138c:8976:eb4a:a91c]) by smtp.gmail.com with UTF8SMTPSA id kx14-20020a170902f94e00b001ab39cd875csm4580815plb.133.2023.10.06.18.28.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Oct 2023 18:28:25 -0700 (PDT) From: Sarthak Kukreti To: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Fri, 6 Oct 2023 18:28:13 -0700 Message-ID: <20231007012817.3052558-2-sarthakkukreti@chromium.org> In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Subject: [dm-devel] [PATCH v8 1/5] block: Don't invalidate pagecache for invalid falloc modes X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jens Axboe , Dave Chinner , Theodore Ts'o , "Darrick J. Wong" , Brian Foster , Bart Van Assche , Mike Snitzer , stable@vger.kernel.org, Christoph Hellwig , Andreas Dilger , Sarthak Kukreti , Christoph Hellwig , Alasdair Kergon Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: chromium.org Only call truncate_bdev_range() if the fallocate mode is supported. This fixes a bug where data in the pagecache could be invalidated if the fallocate() was called on the block device with an invalid mode. Fixes: 25f4c41415e5 ("block: implement (some of) fallocate for block devices") Cc: stable@vger.kernel.org Reported-by: Darrick J. Wong Signed-off-by: Sarthak Kukreti Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Mike Snitzer --- block/fops.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/block/fops.c b/block/fops.c index acff3d5d22d4..73e42742543f 100644 --- a/block/fops.c +++ b/block/fops.c @@ -772,24 +772,35 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, filemap_invalidate_lock(inode->i_mapping); - /* Invalidate the page cache, including dirty pages. */ - error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end); - if (error) - goto fail; - + /* + * Invalidate the page cache, including dirty pages, for valid + * de-allocate mode calls to fallocate(). + */ switch (mode) { case FALLOC_FL_ZERO_RANGE: case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE: + error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end); + if (error) + goto fail; + error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, len >> SECTOR_SHIFT, GFP_KERNEL, BLKDEV_ZERO_NOUNMAP); break; case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE: + error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end); + if (error) + goto fail; + error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, len >> SECTOR_SHIFT, GFP_KERNEL, BLKDEV_ZERO_NOFALLBACK); break; case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE | FALLOC_FL_NO_HIDE_STALE: + error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end); + if (error) + goto fail; + error = blkdev_issue_discard(bdev, start >> SECTOR_SHIFT, len >> SECTOR_SHIFT, GFP_KERNEL); break; From patchwork Sat Oct 7 01:28:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Kukreti X-Patchwork-Id: 13412145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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.lore.kernel.org (Postfix) with ESMTPS id 3F56AE94139 for ; Sat, 7 Oct 2023 01:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696642422; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=04x+ehf+BvNhqGNlvuFXAlx1IAL4DHJ+e6xKnau9kDs=; b=OtLLXihvjzqjVKCGKUR+CoW7nO/THyjexXuLfYN/3GymA9hclDIViOhnDjY29TIbWADcI9 qDeQa5LqUtMmMom5mQfFcBoOWn7RlxWU5eqRK/9SLE7/XEDaWGaVWAU9mIlbVYeXgYFOf3 Cc+QzfAMfezOC0p5+N/JsHOREUhj4dc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-677-rRGkOMGdPHSX87-OqXW0yA-1; Fri, 06 Oct 2023 21:33:40 -0400 X-MC-Unique: rRGkOMGdPHSX87-OqXW0yA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B726E1C07594; Sat, 7 Oct 2023 01:33:38 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DD5E5CC01; Sat, 7 Oct 2023 01:33:38 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 189581946589; Sat, 7 Oct 2023 01:33:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 290BF1946589 for ; Sat, 7 Oct 2023 01:33:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id ED953140E962; Sat, 7 Oct 2023 01:33:36 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E67E4140E953 for ; Sat, 7 Oct 2023 01:33:36 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD2BA85A5BA for ; Sat, 7 Oct 2023 01:33:36 +0000 (UTC) Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-7-foDYdNiZNJal9_Gh3gPFqg-1; Fri, 06 Oct 2023 21:33:35 -0400 X-MC-Unique: foDYdNiZNJal9_Gh3gPFqg-1 Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5890aa0573aso1629333a12.1 for ; Fri, 06 Oct 2023 18:33:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696642108; x=1697246908; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7lVWtirLO6S4iWrOEgizd7kpFd4X9bEhVwAoPUKWyd8=; b=exy1AbszIs1NzjE4T16YGZDC4lVQefvCtseyidws0JglpbPCgh45pAq4J1mC8vHH4W Lp9KzFl/Z3scR//3yEwREe3PYegWJP5+E7uf+a2nopf994xDoJwopCh+vwgMOCrzUDVf RMJxi2p+zvUKhEMSFPrhDdc/vgitoc25Sp4wqLhb9bsgtZIJa1Qt0vNlBFJ2GAXssZl+ P9bOvjD0qnIXCxNjPz4EwqP9AEj/0morpD6lzlIAvOJL94pt5grYl+l2UGrd4C+Y8yA5 4HpfMbwb37+1FOMfFe+op+u98I1cH94n4FK4liiS1ZpCPtEExX10wJrxl46bvBEFH/tD JkZQ== X-Gm-Message-State: AOJu0YycGAI4C/OBkY93h5yTGmfStKM2leiLLiotjJjGS556WKWzTd6d L4+aXoIGU3ZEPM8R1tNCXF5PHpfYUK15K6Q9uek= X-Google-Smtp-Source: AGHT+IGa61952yK/NyaHS0X907u96kal0smT4dnFoPeFJ622np53v6MFLPcZGh/8MT2YlgX13xxnLw== X-Received: by 2002:a05:6a20:f3b0:b0:15e:9c2f:5294 with SMTP id qr48-20020a056a20f3b000b0015e9c2f5294mr8700530pzb.56.1696642108532; Fri, 06 Oct 2023 18:28:28 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:138c:8976:eb4a:a91c]) by smtp.gmail.com with UTF8SMTPSA id p11-20020a1709026b8b00b001c60ba709b7sm4547628plk.125.2023.10.06.18.28.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Oct 2023 18:28:27 -0700 (PDT) From: Sarthak Kukreti To: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Fri, 6 Oct 2023 18:28:14 -0700 Message-ID: <20231007012817.3052558-3-sarthakkukreti@chromium.org> In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Subject: [dm-devel] [PATCH v8 2/5] block: Introduce provisioning primitives X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jens Axboe , Dave Chinner , Theodore Ts'o , "Darrick J. Wong" , Brian Foster , Bart Van Assche , Mike Snitzer , Christoph Hellwig , Andreas Dilger , Sarthak Kukreti , Alasdair Kergon Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: chromium.org Introduce block request REQ_OP_PROVISION. The intent of this request is to request underlying storage to preallocate disk space for the given block range. Block devices that support this capability will export a provision limit within their request queues. This patch also adds the capability to call fallocate() in mode 0 on block devices, which will send REQ_OP_PROVISION to the block device for the specified range, Signed-off-by: Sarthak Kukreti Signed-off-by: Mike Snitzer --- block/blk-core.c | 5 ++++ block/blk-lib.c | 51 +++++++++++++++++++++++++++++++++++++++ block/blk-merge.c | 18 ++++++++++++++ block/blk-settings.c | 19 +++++++++++++++ block/blk-sysfs.c | 9 +++++++ block/bounce.c | 1 + block/fops.c | 10 +++++++- include/linux/bio.h | 6 +++-- include/linux/blk_types.h | 5 +++- include/linux/blkdev.h | 16 ++++++++++++ 10 files changed, 136 insertions(+), 4 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 9d51e9894ece..e1615ffa71bc 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -123,6 +123,7 @@ static const char *const blk_op_name[] = { REQ_OP_NAME(WRITE_ZEROES), REQ_OP_NAME(DRV_IN), REQ_OP_NAME(DRV_OUT), + REQ_OP_NAME(PROVISION) }; #undef REQ_OP_NAME @@ -792,6 +793,10 @@ void submit_bio_noacct(struct bio *bio) if (!q->limits.max_write_zeroes_sectors) goto not_supported; break; + case REQ_OP_PROVISION: + if (!q->limits.max_provision_sectors) + goto not_supported; + break; default: break; } diff --git a/block/blk-lib.c b/block/blk-lib.c index e59c3069e835..b1f720e198cd 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -343,3 +343,54 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, return ret; } EXPORT_SYMBOL(blkdev_issue_secure_erase); + +/** + * blkdev_issue_provision - provision a block range + * @bdev: blockdev to write + * @sector: start sector + * @nr_sects: number of sectors to provision + * @gfp_mask: memory allocation flags (for bio_alloc) + * + * Description: + * Issues a provision request to the block device for the range of sectors. + * For thinly provisioned block devices, this acts as a signal for the + * underlying storage pool to allocate space for this block range. + */ +int blkdev_issue_provision(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp) +{ + sector_t bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1; + unsigned int max_sectors = bdev_max_provision_sectors(bdev); + struct bio *bio = NULL; + struct blk_plug plug; + int ret = 0; + + if (max_sectors == 0) + return -EOPNOTSUPP; + if ((sector | nr_sects) & bs_mask) + return -EINVAL; + if (bdev_read_only(bdev)) + return -EPERM; + + blk_start_plug(&plug); + for (;;) { + unsigned int req_sects = min_t(sector_t, nr_sects, max_sectors); + + bio = blk_next_bio(bio, bdev, 0, REQ_OP_PROVISION, gfp); + bio->bi_iter.bi_sector = sector; + bio->bi_iter.bi_size = req_sects << SECTOR_SHIFT; + + sector += req_sects; + nr_sects -= req_sects; + if (!nr_sects) { + ret = submit_bio_wait(bio); + bio_put(bio); + break; + } + cond_resched(); + } + blk_finish_plug(&plug); + + return ret; +} +EXPORT_SYMBOL_GPL(blkdev_issue_provision); diff --git a/block/blk-merge.c b/block/blk-merge.c index 65e75efa9bd3..83e516d2121f 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -158,6 +158,21 @@ static struct bio *bio_split_write_zeroes(struct bio *bio, return bio_split(bio, lim->max_write_zeroes_sectors, GFP_NOIO, bs); } +static struct bio *bio_split_provision(struct bio *bio, + const struct queue_limits *lim, + unsigned int *nsegs, struct bio_set *bs) +{ + *nsegs = 0; + + if (!lim->max_provision_sectors) + return NULL; + + if (bio_sectors(bio) <= lim->max_provision_sectors) + return NULL; + + return bio_split(bio, lim->max_provision_sectors, GFP_NOIO, bs); +} + /* * Return the maximum number of sectors from the start of a bio that may be * submitted as a single request to a block device. If enough sectors remain, @@ -366,6 +381,9 @@ struct bio *__bio_split_to_limits(struct bio *bio, case REQ_OP_WRITE_ZEROES: split = bio_split_write_zeroes(bio, lim, nr_segs, bs); break; + case REQ_OP_PROVISION: + split = bio_split_provision(bio, lim, nr_segs, bs); + break; default: split = bio_split_rw(bio, lim, nr_segs, bs, get_max_io_size(bio, lim) << SECTOR_SHIFT); diff --git a/block/blk-settings.c b/block/blk-settings.c index 0046b447268f..c81820406f2f 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -59,6 +59,7 @@ void blk_set_default_limits(struct queue_limits *lim) lim->zoned = BLK_ZONED_NONE; lim->zone_write_granularity = 0; lim->dma_alignment = 511; + lim->max_provision_sectors = 0; } /** @@ -82,6 +83,7 @@ void blk_set_stacking_limits(struct queue_limits *lim) lim->max_dev_sectors = UINT_MAX; lim->max_write_zeroes_sectors = UINT_MAX; lim->max_zone_append_sectors = UINT_MAX; + lim->max_provision_sectors = UINT_MAX; } EXPORT_SYMBOL(blk_set_stacking_limits); @@ -208,6 +210,20 @@ void blk_queue_max_write_zeroes_sectors(struct request_queue *q, } EXPORT_SYMBOL(blk_queue_max_write_zeroes_sectors); +/** + * blk_queue_max_provision_sectors - set max sectors for a single provision + * + * @q: the request queue for the device + * @max_provision_sectors: maximum number of sectors to provision per command + **/ + +void blk_queue_max_provision_sectors(struct request_queue *q, + unsigned int max_provision_sectors) +{ + q->limits.max_provision_sectors = max_provision_sectors; +} +EXPORT_SYMBOL(blk_queue_max_provision_sectors); + /** * blk_queue_max_zone_append_sectors - set max sectors for a single zone append * @q: the request queue for the device @@ -578,6 +594,9 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, t->max_segment_size = min_not_zero(t->max_segment_size, b->max_segment_size); + t->max_provision_sectors = min(t->max_provision_sectors, + b->max_provision_sectors); + t->misaligned |= b->misaligned; alignment = queue_limit_alignment_offset(b, start); diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 63e481262336..9a78c36f3199 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -199,6 +199,13 @@ static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *pag return queue_var_show(0, page); } +static ssize_t queue_provision_max_show(struct request_queue *q, + char *page) +{ + return sprintf(page, "%llu\n", + (unsigned long long)q->limits.max_provision_sectors << 9); +} + static ssize_t queue_write_same_max_show(struct request_queue *q, char *page) { return queue_var_show(0, page); @@ -507,6 +514,7 @@ QUEUE_RO_ENTRY(queue_discard_max_hw, "discard_max_hw_bytes"); QUEUE_RW_ENTRY(queue_discard_max, "discard_max_bytes"); QUEUE_RO_ENTRY(queue_discard_zeroes_data, "discard_zeroes_data"); +QUEUE_RO_ENTRY(queue_provision_max, "provision_max_bytes"); QUEUE_RO_ENTRY(queue_write_same_max, "write_same_max_bytes"); QUEUE_RO_ENTRY(queue_write_zeroes_max, "write_zeroes_max_bytes"); QUEUE_RO_ENTRY(queue_zone_append_max, "zone_append_max_bytes"); @@ -633,6 +641,7 @@ static struct attribute *queue_attrs[] = { &queue_discard_max_entry.attr, &queue_discard_max_hw_entry.attr, &queue_discard_zeroes_data_entry.attr, + &queue_provision_max_entry.attr, &queue_write_same_max_entry.attr, &queue_write_zeroes_max_entry.attr, &queue_zone_append_max_entry.attr, diff --git a/block/bounce.c b/block/bounce.c index 7cfcb242f9a1..ab9d8723ae64 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -176,6 +176,7 @@ static struct bio *bounce_clone_bio(struct bio *bio_src) case REQ_OP_DISCARD: case REQ_OP_SECURE_ERASE: case REQ_OP_WRITE_ZEROES: + case REQ_OP_PROVISION: break; default: bio_for_each_segment(bv, bio_src, iter) diff --git a/block/fops.c b/block/fops.c index 73e42742543f..99b24bd9d461 100644 --- a/block/fops.c +++ b/block/fops.c @@ -737,7 +737,8 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) #define BLKDEV_FALLOC_FL_SUPPORTED \ (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \ - FALLOC_FL_ZERO_RANGE | FALLOC_FL_NO_HIDE_STALE) + FALLOC_FL_ZERO_RANGE | FALLOC_FL_NO_HIDE_STALE | \ + FALLOC_FL_UNSHARE_RANGE) static long blkdev_fallocate(struct file *file, int mode, loff_t start, loff_t len) @@ -777,6 +778,13 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, * de-allocate mode calls to fallocate(). */ switch (mode) { + case 0: + case FALLOC_FL_UNSHARE_RANGE: + case FALLOC_FL_KEEP_SIZE: + case FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_KEEP_SIZE: + error = blkdev_issue_provision(bdev, start >> SECTOR_SHIFT, + len >> SECTOR_SHIFT, GFP_KERNEL); + break; case FALLOC_FL_ZERO_RANGE: case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE: error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end); diff --git a/include/linux/bio.h b/include/linux/bio.h index 41d417ee1349..aa2119f7cd5a 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -57,7 +57,8 @@ static inline bool bio_has_data(struct bio *bio) bio->bi_iter.bi_size && bio_op(bio) != REQ_OP_DISCARD && bio_op(bio) != REQ_OP_SECURE_ERASE && - bio_op(bio) != REQ_OP_WRITE_ZEROES) + bio_op(bio) != REQ_OP_WRITE_ZEROES && + bio_op(bio) != REQ_OP_PROVISION) return true; return false; @@ -67,7 +68,8 @@ static inline bool bio_no_advance_iter(const struct bio *bio) { return bio_op(bio) == REQ_OP_DISCARD || bio_op(bio) == REQ_OP_SECURE_ERASE || - bio_op(bio) == REQ_OP_WRITE_ZEROES; + bio_op(bio) == REQ_OP_WRITE_ZEROES || + bio_op(bio) == REQ_OP_PROVISION; } static inline void *bio_data(struct bio *bio) diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index d5c5e59ddbd2..e55828ddfafe 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -397,7 +397,10 @@ enum req_op { REQ_OP_DRV_IN = (__force blk_opf_t)34, REQ_OP_DRV_OUT = (__force blk_opf_t)35, - REQ_OP_LAST = (__force blk_opf_t)36, + /* request device to provision block */ + REQ_OP_PROVISION = (__force blk_opf_t)37, + + REQ_OP_LAST = (__force blk_opf_t)38, }; enum req_flag_bits { diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index eef450f25982..dcae5538f99a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -308,6 +308,7 @@ struct queue_limits { unsigned int discard_granularity; unsigned int discard_alignment; unsigned int zone_write_granularity; + unsigned int max_provision_sectors; unsigned short max_segments; unsigned short max_integrity_segments; @@ -900,6 +901,8 @@ extern void blk_queue_max_discard_sectors(struct request_queue *q, unsigned int max_discard_sectors); extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q, unsigned int max_write_same_sectors); +extern void blk_queue_max_provision_sectors(struct request_queue *q, + unsigned int max_provision_sectors); extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); extern void blk_queue_max_zone_append_sectors(struct request_queue *q, unsigned int max_zone_append_sectors); @@ -1038,6 +1041,9 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp); +extern int blkdev_issue_provision(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask); + #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */ #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */ @@ -1117,6 +1123,11 @@ static inline unsigned short queue_max_discard_segments(const struct request_que return q->limits.max_discard_segments; } +static inline unsigned short queue_max_provision_sectors(const struct request_queue *q) +{ + return q->limits.max_provision_sectors; +} + static inline unsigned int queue_max_segment_size(const struct request_queue *q) { return q->limits.max_segment_size; @@ -1259,6 +1270,11 @@ static inline bool bdev_nowait(struct block_device *bdev) return test_bit(QUEUE_FLAG_NOWAIT, &bdev_get_queue(bdev)->queue_flags); } +static inline unsigned int bdev_max_provision_sectors(struct block_device *bdev) +{ + return bdev_get_queue(bdev)->limits.max_provision_sectors; +} + static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev) { return blk_queue_zoned_model(bdev_get_queue(bdev)); From patchwork Sat Oct 7 01:28:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Kukreti X-Patchwork-Id: 13412128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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.lore.kernel.org (Postfix) with ESMTPS id 85D3EE94139 for ; Sat, 7 Oct 2023 01:28:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696642126; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=AaPMh4m6x27/LWAxttKwK4aO4v1YcZQBrbOGomkl1TY=; b=FIUeYuo+ap36I85gnkT2lccB4a7EqeKhnmQ5x74Cv/oU1TIDJmgJtKeiBMp7NH6VGZLMFx TAFkxfukqbtQdkgVFzXXd1swIkQtfUKOJkvX21oMB1Pmmm/mBsWsXDwGdmwCczSyI3SOoV IaVzuiN5gzCCNuShY8GssMY6engtbEM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-83-xT0njwcEOOWeMnUUGgXRKw-1; Fri, 06 Oct 2023 21:28:43 -0400 X-MC-Unique: xT0njwcEOOWeMnUUGgXRKw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 85DFF8039CB; Sat, 7 Oct 2023 01:28:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7365FC15BB8; Sat, 7 Oct 2023 01:28:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3C2EE1946589; Sat, 7 Oct 2023 01:28:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 269E01946588 for ; Sat, 7 Oct 2023 01:28:39 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 068882027046; Sat, 7 Oct 2023 01:28:39 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F29982027045 for ; Sat, 7 Oct 2023 01:28:38 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D475C8007A4 for ; Sat, 7 Oct 2023 01:28:38 +0000 (UTC) Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-471-KzwEYFeNPfWpjEQir4W_8w-1; Fri, 06 Oct 2023 21:28:32 -0400 X-MC-Unique: KzwEYFeNPfWpjEQir4W_8w-1 Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-564af0ac494so1959853a12.0 for ; Fri, 06 Oct 2023 18:28:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696642111; x=1697246911; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qwbLxQP2MlVOvPJLqOZgvAlqQEss4gZRIzs/TWsm4fw=; b=JT4dvHELb6uHzxu8GSArPFUgi63unmxII/WUI+NBzd3N4eAcquWctrbY1oYKp2JqlO l5lIvIXtdnOY5To+nr34QfR6V9lkZgcC07oEK1YS02z75WYj2chTQtaq1YugH2Tz4d9u bVrU9dZa9xYVZyBhs1y8RGWOF84Q5ghSMFdQIw3AqWoqINDlahiw5Hfd5EtAiq1HQdQW Jz3yJKlUSFHWZ982hE2Md7WrDSl2m2J051tTHVESPEvH+Y5LTh+Y9UsyZ0Lxy5vl7A+C bJkwPLHxx2lP4xVNeQAELn+9XNE9GmPLoLhRUPm7BVljtpukQsbfxchUyqXtgCZgwTmE Xg9g== X-Gm-Message-State: AOJu0Yzx/sKgHItSXp89WVZ9KUJFGLtzukF9KNHmxteDltLvTfMDDAsr jNia07Lg71esTzTOS1H3ApXH9fx4ufeRZq++7xA= X-Google-Smtp-Source: AGHT+IF+irPpdEsFSzOYVv3XaMow6Yl8idZjKB2cup9iOgYxOd9Vuvg5EJUKwvZgFUUl2r+4ILiQzw== X-Received: by 2002:a17:903:25c3:b0:1c5:76b6:d4f7 with SMTP id jc3-20020a17090325c300b001c576b6d4f7mr8553824plb.36.1696642110765; Fri, 06 Oct 2023 18:28:30 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:138c:8976:eb4a:a91c]) by smtp.gmail.com with UTF8SMTPSA id o18-20020a170902d4d200b001c73fb506aesm4524873plg.128.2023.10.06.18.28.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Oct 2023 18:28:30 -0700 (PDT) From: Sarthak Kukreti To: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Fri, 6 Oct 2023 18:28:15 -0700 Message-ID: <20231007012817.3052558-4-sarthakkukreti@chromium.org> In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v8 3/5] loop: Add support for provision requests X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jens Axboe , Dave Chinner , Theodore Ts'o , "Darrick J. Wong" , Brian Foster , Bart Van Assche , Mike Snitzer , Christoph Hellwig , Andreas Dilger , Sarthak Kukreti , Alasdair Kergon Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: chromium.org Add support for provision requests to loopback devices. Loop devices will configure provision support based on whether the underlying block device/file can support the provision request and upon receiving a provision bio, will map it to the backing device/storage. For loop devices over files, a REQ_OP_PROVISION request will translate to an fallocate mode 0 call on the backing file. Signed-off-by: Sarthak Kukreti Signed-off-by: Mike Snitzer --- drivers/block/loop.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 9f2d412fc560..abb4dddbd4fd 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -311,16 +311,20 @@ static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos, { /* * We use fallocate to manipulate the space mappings used by the image - * a.k.a. discard/zerorange. + * a.k.a. discard/provision/zerorange. */ struct file *file = lo->lo_backing_file; int ret; - mode |= FALLOC_FL_KEEP_SIZE; + if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE) && + !bdev_max_discard_sectors(lo->lo_device)) + return -EOPNOTSUPP; - if (!bdev_max_discard_sectors(lo->lo_device)) + if (mode == 0 && !bdev_max_provision_sectors(lo->lo_device)) return -EOPNOTSUPP; + mode |= FALLOC_FL_KEEP_SIZE; + ret = file->f_op->fallocate(file, mode, pos, blk_rq_bytes(rq)); if (unlikely(ret && ret != -EINVAL && ret != -EOPNOTSUPP)) return -EIO; @@ -488,6 +492,8 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq) FALLOC_FL_PUNCH_HOLE); case REQ_OP_DISCARD: return lo_fallocate(lo, rq, pos, FALLOC_FL_PUNCH_HOLE); + case REQ_OP_PROVISION: + return lo_fallocate(lo, rq, pos, 0); case REQ_OP_WRITE: if (cmd->use_aio) return lo_rw_aio(lo, cmd, pos, ITER_SOURCE); @@ -754,6 +760,25 @@ static void loop_sysfs_exit(struct loop_device *lo) &loop_attribute_group); } +static void loop_config_provision(struct loop_device *lo) +{ + struct file *file = lo->lo_backing_file; + struct inode *inode = file->f_mapping->host; + + /* + * If the backing device is a block device, mirror its provisioning + * capability. + */ + if (S_ISBLK(inode->i_mode)) { + blk_queue_max_provision_sectors(lo->lo_queue, + bdev_max_provision_sectors(I_BDEV(inode))); + } else if (file->f_op->fallocate) { + blk_queue_max_provision_sectors(lo->lo_queue, UINT_MAX >> 9); + } else { + blk_queue_max_provision_sectors(lo->lo_queue, 0); + } +} + static void loop_config_discard(struct loop_device *lo) { struct file *file = lo->lo_backing_file; @@ -1092,6 +1117,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode, blk_queue_io_min(lo->lo_queue, bsize); loop_config_discard(lo); + loop_config_provision(lo); loop_update_rotational(lo); loop_update_dio(lo); loop_sysfs_init(lo); @@ -1304,6 +1330,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) } loop_config_discard(lo); + loop_config_provision(lo); /* update dio if lo_offset or transfer is changed */ __loop_update_dio(lo, lo->use_dio); @@ -1857,6 +1884,7 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx, case REQ_OP_FLUSH: case REQ_OP_DISCARD: case REQ_OP_WRITE_ZEROES: + case REQ_OP_PROVISION: cmd->use_aio = false; break; default: From patchwork Sat Oct 7 01:28:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Kukreti X-Patchwork-Id: 13412129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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.lore.kernel.org (Postfix) with ESMTPS id AA38FE9413F for ; Sat, 7 Oct 2023 01:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696642127; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Owj3x/un3XBAdxDOH9Mq1Gc2M546WDmm2B2oFKi62VM=; b=FUwQknq/RWUKI1simsd8YzqDXqPHIVbHtMoJ/RS59ArHR7q08QFsW16uLubMrAspB1l+Gp OMtfvFR+EYgWXxgerw7YpnHdhUoHaphJOD3pxepd8Xk2fc7xJQVuXu6aM9yN/nlvpb88U1 Fu9KZo86IMQJXeP4UMczDR5JkFXViPQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-29-WPgox-PCOXSisJTz6W-8rQ-1; Fri, 06 Oct 2023 21:28:44 -0400 X-MC-Unique: WPgox-PCOXSisJTz6W-8rQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A54CA81163A; Sat, 7 Oct 2023 01:28:42 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93F0647AD4A; Sat, 7 Oct 2023 01:28:42 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 64F381946589; Sat, 7 Oct 2023 01:28:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B885819465A3 for ; Sat, 7 Oct 2023 01:28:41 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8E3E11006B70; Sat, 7 Oct 2023 01:28:41 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 860D81005E27 for ; Sat, 7 Oct 2023 01:28:41 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67F44380390F for ; Sat, 7 Oct 2023 01:28:41 +0000 (UTC) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-599-7pTqD6pdNlCtC5nPho2emw-1; Fri, 06 Oct 2023 21:28:34 -0400 X-MC-Unique: 7pTqD6pdNlCtC5nPho2emw-1 Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-69af8a42066so1600779b3a.1 for ; Fri, 06 Oct 2023 18:28:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696642113; x=1697246913; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FqB1hDPxuIIbyhAWdDDt1cqx20h+edShJFHuWVHb1Qc=; b=lfYcFpAJjXFeoMDMIdMykk40TFlqZaN2pJ0NjDvcR8CM7WfEZzdiryQQL/VeibUVlp L8jJ7TixDw/eh56aTo/C5k2YKMxshfjPmmgZfvtL1ocGvaSZLyw4iO64xmYcqrvbMi5V qrZCYo/+xtkJWO06mTmQtuwIEUAAMoyunKpIJdxPMkqrdPSzCGU9z6Cep+NGe3Iv0+cp zAV1RLgHb1MAONoDJDfj1/P8t5Cq4kAIU8BxahlmbMB3aoKHgP+UWw+MgouYpl1SpyLY HRVCDn3RkdGultay2BWcCDlyCWI4XgrJcSnXiJ1of2TxVDySAjIGTYWbbAPBYLq31XO1 pM6w== X-Gm-Message-State: AOJu0YxEemZn6X5MBRQQiXVrWIzrbmX/UBzzPevAtzxShcT32RDihbdL vyYxkW57uoBTPmDhpOCZb8rGpsioZb2DHAi8FTs= X-Google-Smtp-Source: AGHT+IHHJGcgIIrRozWFHSOllQB1G3Zxvy1WNHERSyRa8lFXhWz964OB7xksDw6POMFHhHNZ1hgVGg== X-Received: by 2002:a05:6a00:3a1f:b0:690:d620:7804 with SMTP id fj31-20020a056a003a1f00b00690d6207804mr10717726pfb.13.1696642113085; Fri, 06 Oct 2023 18:28:33 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:138c:8976:eb4a:a91c]) by smtp.gmail.com with UTF8SMTPSA id 20-20020aa79114000000b006969e8dac24sm2118332pfh.68.2023.10.06.18.28.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Oct 2023 18:28:32 -0700 (PDT) From: Sarthak Kukreti To: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Fri, 6 Oct 2023 18:28:16 -0700 Message-ID: <20231007012817.3052558-5-sarthakkukreti@chromium.org> In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Subject: [dm-devel] [PATCH v8 4/5] dm: Add block provisioning support X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jens Axboe , Dave Chinner , Theodore Ts'o , "Darrick J. Wong" , Brian Foster , Bart Van Assche , Mike Snitzer , Christoph Hellwig , Andreas Dilger , Sarthak Kukreti , Alasdair Kergon Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: chromium.org Add block provisioning support for device-mapper targets. dm-crypt and dm-linear will, by default, passthrough REQ_OP_PROVISION requests to the underlying device, if supported. Signed-off-by: Sarthak Kukreti Signed-off-by: Mike Snitzer --- drivers/md/dm-crypt.c | 4 +++- drivers/md/dm-linear.c | 1 + drivers/md/dm-table.c | 23 +++++++++++++++++++++++ drivers/md/dm.c | 7 +++++++ include/linux/device-mapper.h | 17 +++++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index f2662c21a6df..8f94d98e241b 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -3362,6 +3362,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) cc->tag_pool_max_sectors <<= cc->sector_shift; } + ti->num_provision_bios = 1; + ret = -ENOMEM; cc->io_queue = alloc_workqueue("kcryptd_io/%s", WQ_MEM_RECLAIM, 1, devname); if (!cc->io_queue) { @@ -3416,7 +3418,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio) * - for REQ_OP_DISCARD caller must use flush if IO ordering matters */ if (unlikely(bio->bi_opf & REQ_PREFLUSH || - bio_op(bio) == REQ_OP_DISCARD)) { + bio_op(bio) == REQ_OP_DISCARD || bio_op(bio) == REQ_OP_PROVISION)) { bio_set_dev(bio, cc->dev->bdev); if (bio_sectors(bio)) bio->bi_iter.bi_sector = cc->start + diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index f4448d520ee9..74ee27ca551a 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c @@ -62,6 +62,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->num_discard_bios = 1; ti->num_secure_erase_bios = 1; ti->num_write_zeroes_bios = 1; + ti->num_provision_bios = 1; ti->private = lc; return 0; diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 37b48f63ae6a..1839317d047e 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1856,6 +1856,26 @@ static bool dm_table_supports_write_zeroes(struct dm_table *t) return true; } +static int device_provision_capable(struct dm_target *ti, struct dm_dev *dev, + sector_t start, sector_t len, void *data) +{ + return bdev_max_provision_sectors(dev->bdev); +} + +static bool dm_table_supports_provision(struct dm_table *t) +{ + for (unsigned int i = 0; i < t->num_targets; i++) { + struct dm_target *ti = dm_table_get_target(t, i); + + if (ti->provision_supported || + (ti->type->iterate_devices && + ti->type->iterate_devices(ti, device_provision_capable, NULL))) + return true; + } + + return false; +} + static int device_not_nowait_capable(struct dm_target *ti, struct dm_dev *dev, sector_t start, sector_t len, void *data) { @@ -1989,6 +2009,9 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, if (!dm_table_supports_write_zeroes(t)) q->limits.max_write_zeroes_sectors = 0; + if (!dm_table_supports_provision(t)) + q->limits.max_provision_sectors = 0; + dm_table_verify_integrity(t); /* diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 64a1f306c96c..0e6cf1a5a414 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1598,6 +1598,7 @@ static bool is_abnormal_io(struct bio *bio) case REQ_OP_DISCARD: case REQ_OP_SECURE_ERASE: case REQ_OP_WRITE_ZEROES: + case REQ_OP_PROVISION: return true; default: break; @@ -1634,6 +1635,12 @@ static blk_status_t __process_abnormal_io(struct clone_info *ci, if (ti->max_write_zeroes_granularity) max_granularity = max_sectors; break; + case REQ_OP_PROVISION: + num_bios = ti->num_provision_bios; + max_sectors = limits->max_provision_sectors; + if (ti->max_provision_granularity) + max_granularity = max_sectors; + break; default: break; } diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 69d0435c7ebb..41fd4e456d1f 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -332,6 +332,12 @@ struct dm_target { */ unsigned int num_write_zeroes_bios; + /* + * The number of PROVISION bios that will be submitted to the target. + * The bio number can be accessed with dm_bio_get_target_bio_nr. + */ + unsigned int num_provision_bios; + /* * The minimum number of extra bytes allocated in each io for the * target to use. @@ -356,6 +362,11 @@ struct dm_target { */ bool discards_supported:1; + /* Set if this target needs to receive provision requests regardless of + * whether or not its underlying devices have support. + */ + bool provision_supported:1; + /* * Set if this target requires that discards be split on * 'max_discard_sectors' boundaries. @@ -374,6 +385,12 @@ struct dm_target { */ bool max_write_zeroes_granularity:1; + /* + * Set if this target requires that provisions be split on + * 'max_provision_sectors' boundaries. + */ + bool max_provision_granularity:1; + /* * Set if we need to limit the number of in-flight bios when swapping. */ From patchwork Sat Oct 7 01:28:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Kukreti X-Patchwork-Id: 13412130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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.lore.kernel.org (Postfix) with ESMTPS id ACE33E9413D for ; Sat, 7 Oct 2023 01:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696642139; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=x0yu8TQdNa4fhYJxL/qfqCgLBb4zJ6lVau5K3ZaVtF0=; b=gMkLgiDm3kZ4kFnnOE3b3d+MI97kubbprU5mJXB5ToAL6R2lW1Hy8JFHsW3TlE+Sj5kbBU HF0e2w9eSl+fLuCLVbSpkgLvZNIktOX18mYKCDJRhj5lpE7kgU8GZvnWFaXHQXLlbn6jzN LPQy/95k/bJ0fzk3IAwp6FZ4xF/ao3w= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-125-TVC3JHYJMKOQTbqhhqL1aw-1; Fri, 06 Oct 2023 21:28:56 -0400 X-MC-Unique: TVC3JHYJMKOQTbqhhqL1aw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 165D1101A53B; Sat, 7 Oct 2023 01:28:55 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 059671005E27; Sat, 7 Oct 2023 01:28:55 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E9FE31946589; Sat, 7 Oct 2023 01:28:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 032BD1946589 for ; Sat, 7 Oct 2023 01:28:53 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EA9F72156711; Sat, 7 Oct 2023 01:28:52 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E3B5A215670B for ; Sat, 7 Oct 2023 01:28:52 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C5ACF101AA6E for ; Sat, 7 Oct 2023 01:28:52 +0000 (UTC) Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-597-4fiLMvRCM4KDiuJ50NTVyg-1; Fri, 06 Oct 2023 21:28:38 -0400 X-MC-Unique: 4fiLMvRCM4KDiuJ50NTVyg-1 Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-6bf58009a8dso1799904a34.1 for ; Fri, 06 Oct 2023 18:28:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696642115; x=1697246915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rVF8rK/kC1UjwzLMGR23sx6dhVRDno9128uSIr9eCP0=; b=iGvTBfCxKHLpX8hgfqO4bJNeniAN3NSdGQ0+BS4cDVvoY0iKWt0EdwUPtLNZu+9J/c o3bBJrzSyd7M46LHK+18Xukud/JstHQe+1l9aN08efMHgTBjTagGhVebQKM6+/iMDJwc bTy0CglA1TjEJ88eZSF2O/YZ1lo8ZkZISWPdBaspdTlGscbOdfJgAvZ3AHKbnYTyKDVI iWmR4gzkUgDNFgiUoOftp5+HI0YDQp2+mvK7HkBGNmASNoEH8JYKzHAWLhSqrpUWkHhY 7Dkl7XMZJ7SR6gGT6wPaNBJarmNuUd7EIig5tEc7oRoM2teRo8CDPiDwn68PRJWy31lC QeLg== X-Gm-Message-State: AOJu0YzLu9E5rXPNUWqdaqpl6pcHphnDz9+PmVVYwvfsE/y0OCUhz1/h 67TDYXMrSzJiSYXDKKhDIhj+cNsC1ZdgNfZ8Aqo= X-Google-Smtp-Source: AGHT+IH2NlEgTF700gNIZ6cKPt2q6/f6H70TDkXk3G6q0Gl7oflk7/S43yTcoNGZnNyMpgrw6cyE+g== X-Received: by 2002:a05:6830:1bf2:b0:6bb:1036:46de with SMTP id k18-20020a0568301bf200b006bb103646demr10472104otb.30.1696642115522; Fri, 06 Oct 2023 18:28:35 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:138c:8976:eb4a:a91c]) by smtp.gmail.com with UTF8SMTPSA id w25-20020a639359000000b00553dcfc2179sm4002014pgm.52.2023.10.06.18.28.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Oct 2023 18:28:35 -0700 (PDT) From: Sarthak Kukreti To: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Fri, 6 Oct 2023 18:28:17 -0700 Message-ID: <20231007012817.3052558-6-sarthakkukreti@chromium.org> In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Subject: [dm-devel] [PATCH v8 5/5] block: Pass unshare intent via REQ_OP_PROVISION X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jens Axboe , Dave Chinner , Theodore Ts'o , "Darrick J. Wong" , Brian Foster , Bart Van Assche , Mike Snitzer , Christoph Hellwig , Andreas Dilger , Sarthak Kukreti , Alasdair Kergon Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: chromium.org Allow REQ_OP_PROVISION to pass in an extra REQ_UNSHARE bit to annotate unshare requests to underlying layers. Layers that support FALLOC_FL_UNSHARE will be able to use this as an indicator of which fallocate() mode to use. Suggested-by: Darrick J. Wong Signed-off-by: Sarthak Kukreti --- block/blk-lib.c | 6 +++++- block/fops.c | 6 ++++-- drivers/block/loop.c | 35 +++++++++++++++++++++++++++++------ include/linux/blk_types.h | 3 +++ include/linux/blkdev.h | 3 ++- 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index b1f720e198cd..d6cf572605f5 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -350,6 +350,7 @@ EXPORT_SYMBOL(blkdev_issue_secure_erase); * @sector: start sector * @nr_sects: number of sectors to provision * @gfp_mask: memory allocation flags (for bio_alloc) + * @flags: controls detailed behavior * * Description: * Issues a provision request to the block device for the range of sectors. @@ -357,7 +358,7 @@ EXPORT_SYMBOL(blkdev_issue_secure_erase); * underlying storage pool to allocate space for this block range. */ int blkdev_issue_provision(struct block_device *bdev, sector_t sector, - sector_t nr_sects, gfp_t gfp) + sector_t nr_sects, gfp_t gfp, unsigned flags) { sector_t bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1; unsigned int max_sectors = bdev_max_provision_sectors(bdev); @@ -380,6 +381,9 @@ int blkdev_issue_provision(struct block_device *bdev, sector_t sector, bio->bi_iter.bi_sector = sector; bio->bi_iter.bi_size = req_sects << SECTOR_SHIFT; + if (flags & BLKDEV_PROVISION_UNSHARE_RANGE) + bio->bi_opf |= REQ_UNSHARE; + sector += req_sects; nr_sects -= req_sects; if (!nr_sects) { diff --git a/block/fops.c b/block/fops.c index 99b24bd9d461..dd442b6f0486 100644 --- a/block/fops.c +++ b/block/fops.c @@ -782,8 +782,10 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, case FALLOC_FL_UNSHARE_RANGE: case FALLOC_FL_KEEP_SIZE: case FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_KEEP_SIZE: - error = blkdev_issue_provision(bdev, start >> SECTOR_SHIFT, - len >> SECTOR_SHIFT, GFP_KERNEL); + error = blkdev_issue_provision( + bdev, start >> SECTOR_SHIFT, len >> SECTOR_SHIFT, GFP_KERNEL, + (mode & FALLOC_FL_UNSHARE_RANGE) ? + BLKDEV_PROVISION_UNSHARE_RANGE : 0); break; case FALLOC_FL_ZERO_RANGE: case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE: diff --git a/drivers/block/loop.c b/drivers/block/loop.c index abb4dddbd4fd..f30479deb615 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -306,6 +306,30 @@ static int lo_read_simple(struct loop_device *lo, struct request *rq, return 0; } +static bool validate_fallocate_mode(struct loop_device *lo, int mode) +{ + bool ret = true; + + switch (mode) { + case FALLOC_FL_PUNCH_HOLE: + case FALLOC_FL_ZERO_RANGE: + if (!bdev_max_discard_sectors(lo->lo_device)) + ret = false; + break; + case 0: + case FALLOC_FL_UNSHARE_RANGE: + if (!bdev_max_provision_sectors(lo->lo_device)) + ret = false; + break; + + default: + ret = false; + } + + return ret; +} + + static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos, int mode) { @@ -316,11 +340,7 @@ static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos, struct file *file = lo->lo_backing_file; int ret; - if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE) && - !bdev_max_discard_sectors(lo->lo_device)) - return -EOPNOTSUPP; - - if (mode == 0 && !bdev_max_provision_sectors(lo->lo_device)) + if (!validate_fallocate_mode(lo, mode)) return -EOPNOTSUPP; mode |= FALLOC_FL_KEEP_SIZE; @@ -493,7 +513,10 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq) case REQ_OP_DISCARD: return lo_fallocate(lo, rq, pos, FALLOC_FL_PUNCH_HOLE); case REQ_OP_PROVISION: - return lo_fallocate(lo, rq, pos, 0); + return lo_fallocate(lo, rq, pos, + (rq->cmd_flags & REQ_UNSHARE) ? + FALLOC_FL_UNSHARE_RANGE : + 0); case REQ_OP_WRITE: if (cmd->use_aio) return lo_rw_aio(lo, cmd, pos, ITER_SOURCE); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index e55828ddfafe..f16187ae4c4a 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -430,6 +430,8 @@ enum req_flag_bits { */ /* for REQ_OP_WRITE_ZEROES: */ __REQ_NOUNMAP, /* do not free blocks when zeroing */ + /* for REQ_OP_PROVISION: */ + __REQ_UNSHARE, /* unshare blocks */ __REQ_NR_BITS, /* stops here */ }; @@ -458,6 +460,7 @@ enum req_flag_bits { #define REQ_FS_PRIVATE (__force blk_opf_t)(1ULL << __REQ_FS_PRIVATE) #define REQ_NOUNMAP (__force blk_opf_t)(1ULL << __REQ_NOUNMAP) +#define REQ_UNSHARE (__force blk_opf_t)(1ULL << __REQ_UNSHARE) #define REQ_FAILFAST_MASK \ (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index dcae5538f99a..0f88ccbde12f 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1042,10 +1042,11 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp); extern int blkdev_issue_provision(struct block_device *bdev, sector_t sector, - sector_t nr_sects, gfp_t gfp_mask); + sector_t nr_sects, gfp_t gfp_mask, unsigned int flags); #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */ #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */ +#define BLKDEV_PROVISION_UNSHARE_RANGE (1 << 2) /* unshare range on provision */ extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, From patchwork Sun Oct 8 23:41:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Chinner X-Patchwork-Id: 13412829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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.lore.kernel.org (Postfix) with ESMTPS id 06673E95A8E for ; Sun, 8 Oct 2023 23:41:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696808496; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=SWtGgtFZQ79q43gxIRuBPBLvzO7cEc1Nc8P964PZVog=; b=MD0CrRM8IaXRSfszcZRKcRZv5XMfgBkVLVWL06b9Ig7/UWNc6/mKDpjBaOWbmnGlMEOz4I 4kFy5pxGO0rOZqGouf2zVSHxzA4ZMNj+tgT8GYwxUA5+pcsLqA4GdDq70z5i7L2l8XaDwA U0HxPUSMqEKynjiWvihCgClfUK+zyxQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-416-EtIW8Ea2Pa-ALfKAxaTREg-1; Sun, 08 Oct 2023 19:41:22 -0400 X-MC-Unique: EtIW8Ea2Pa-ALfKAxaTREg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C2A05380670E; Sun, 8 Oct 2023 23:41:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1A84140E953; Sun, 8 Oct 2023 23:41:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5EDB61946595; Sun, 8 Oct 2023 23:41:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 35ADB194658C for ; Sun, 8 Oct 2023 23:41:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1DF9F2156711; Sun, 8 Oct 2023 23:41:19 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 16646215670B for ; Sun, 8 Oct 2023 23:41:18 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B2D138039C1 for ; Sun, 8 Oct 2023 23:41:18 +0000 (UTC) Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-QbCJbcxGOii-sEHuvA9tpg-1; Sun, 08 Oct 2023 19:41:16 -0400 X-MC-Unique: QbCJbcxGOii-sEHuvA9tpg-1 Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-1d544a4a2f2so2743568fac.3 for ; Sun, 08 Oct 2023 16:41:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696808476; x=1697413276; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WhYJRI062pcX8jyWpJ2qutO3TNLI93kE5AesIBQ7T3Q=; b=AxNuhawBJRUt0BfiRVLB3rIeOImgLyPYjkvRN/aX2IUknT6LLnjtPxj8Zu0XZ+CFdR pNyP9urlQae1jalfxsRr9KLw44AzYakzA/PDU7RUk61/+UH4N7Rr3BUZngA4QS41Eaj0 88APIUV3R4h5c+yieeZJGniUbxO8vjbHSQcPdcM1WW1FpnvEK4yHiA11L+XB6898FDPn ziqEwfLVTyKBQUFdbnv7lVl08SPpjVXwLfhlTXtsqewcgFjidKb1Fsq07CSkIMdKecco DG5xBXh071adzfKyCtltgByLazCunOpgSIV+UHXuQoq5FtND7UBLZTATC8QO1YBU01hx L2Rg== X-Gm-Message-State: AOJu0YzyvqtTW7ISBFLPiixxbtbYutnkYZTfl3FqRU0q8WHs15FbxsdM KBfB46WH/z5GJRIKWvTt73AraQ== X-Google-Smtp-Source: AGHT+IEzdfSk/TfN3oKWe+ZCwTpXTbsQop8JnwDS51200ueprTMLUFr7+5xNPnWdiMt6htdwMZNbVg== X-Received: by 2002:a05:6870:2050:b0:1dd:67a6:ed75 with SMTP id l16-20020a056870205000b001dd67a6ed75mr16462942oad.44.1696808475832; Sun, 08 Oct 2023 16:41:15 -0700 (PDT) Received: from dread.disaster.area (pa49-180-20-59.pa.nsw.optusnet.com.au. [49.180.20.59]) by smtp.gmail.com with ESMTPSA id x14-20020aa784ce000000b0068fb5e44827sm5000804pfn.67.2023.10.08.16.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 16:41:15 -0700 (PDT) Received: from dave by dread.disaster.area with local (Exim 4.96) (envelope-from ) id 1qpdOb-00BI8g-18; Mon, 09 Oct 2023 10:41:13 +1100 Date: Mon, 9 Oct 2023 10:41:13 +1100 From: Dave Chinner To: Sarthak Kukreti Message-ID: References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Subject: [dm-devel] [RFC PATCH 6/5] xfs: detect block devices requiring provisioning X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jens Axboe , Christoph Hellwig , Theodore Ts'o , "Darrick J. Wong" , Brian Foster , Bart Van Assche , Mike Snitzer , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@redhat.com, Andreas Dilger , linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, Alasdair Kergon Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: fromorbit.com Content-Disposition: inline From: Dave Chinner Block device provisioning detection infrastructure. Signed-off-by: Dave Chinner --- fs/xfs/xfs_buf.c | 2 ++ fs/xfs/xfs_buf.h | 1 + fs/xfs/xfs_mount.h | 11 ++++++++++- fs/xfs/xfs_super.c | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index c1ece4a08ff4..f37edae6e68e 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -2014,6 +2014,8 @@ xfs_alloc_buftarg( btp->bt_bdev = bdev; btp->bt_daxdev = fs_dax_get_by_bdev(bdev, &btp->bt_dax_part_off, mp, ops); + if (bdev_max_provision_sectors(bdev)) + btp->bt_needs_provisioning = true; /* * Buffer IO error rate limiting. Limit it to no more than 10 messages diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index df8f47953bb4..1719a8fce49f 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -106,6 +106,7 @@ typedef struct xfs_buftarg { size_t bt_meta_sectormask; size_t bt_logical_sectorsize; size_t bt_logical_sectormask; + bool bt_needs_provisioning; /* LRU control structures */ struct shrinker bt_shrinker; diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index d19cca099bc3..f1eec563c61d 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -407,6 +407,13 @@ __XFS_HAS_FEAT(nouuid, NOUUID) #define XFS_OPSTATE_WARNED_LARP 9 /* Mount time quotacheck is running */ #define XFS_OPSTATE_QUOTACHECK_RUNNING 10 +/* + * If the block device underlying either the data or rt volume needs + * provisioning to guarantee space availability, this flag will be set. + * Operations that need to check, issue or free provisioning trigger off + * this flag. + */ +#define XFS_OPSTATE_PROVISION_BLOCKS 11 #define __XFS_IS_OPSTATE(name, NAME) \ static inline bool xfs_is_ ## name (struct xfs_mount *mp) \ @@ -434,6 +441,7 @@ __XFS_IS_OPSTATE(quotacheck_running, QUOTACHECK_RUNNING) #else # define xfs_is_quotacheck_running(mp) (false) #endif +__XFS_IS_OPSTATE(provisioning_blocks, PROVISION_BLOCKS) static inline bool xfs_should_warn(struct xfs_mount *mp, long nr) @@ -452,7 +460,8 @@ xfs_should_warn(struct xfs_mount *mp, long nr) { (1UL << XFS_OPSTATE_WARNED_SCRUB), "wscrub" }, \ { (1UL << XFS_OPSTATE_WARNED_SHRINK), "wshrink" }, \ { (1UL << XFS_OPSTATE_WARNED_LARP), "wlarp" }, \ - { (1UL << XFS_OPSTATE_QUOTACHECK_RUNNING), "quotacheck" } + { (1UL << XFS_OPSTATE_QUOTACHECK_RUNNING), "quotacheck" }, \ + { (1UL << XFS_OPSTATE_PROVISION_BLOCKS), "provision" } /* * Max and min values for mount-option defined I/O diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 819a3568b28f..a5b15ddfb31e 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -471,11 +471,15 @@ xfs_open_devices( mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev); if (!mp->m_ddev_targp) goto out_close_rtdev; + if (mp->m_ddev_targp->bt_needs_provisioning) + xfs_set_provisioning_blocks(mp); if (rtdev) { mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev); if (!mp->m_rtdev_targp) goto out_free_ddev_targ; + if (mp->m_rtdev_targp->bt_needs_provisioning) + xfs_set_provisioning_blocks(mp); } if (logdev && logdev != ddev) { From patchwork Sun Oct 8 23:45:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Chinner X-Patchwork-Id: 13412832 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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.lore.kernel.org (Postfix) with ESMTPS id AB0C8E95A8E for ; Sun, 8 Oct 2023 23:45:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696808736; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4JLqQ7OfyYupFDyJlSmCIt17XnKnsnoQjMDXNH8mi2M=; b=iZHhQmKK9yVszjw843ukahOGe8l3fPg7oZZMBd6nl7m0yWc3CXBNlkIjoPqXCLTtrEf1gS yLygeNhvlrZCUNtUzFWartZBMYRrTuOF3NsAyYgt2Wgv9reN9tQ5cXlBTsTRDmI8tTk5SH +exM0Z+4C0zT3ZTSE+oiV9bQJihvON4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-29-oADOvNWlPTedifEtKmownQ-1; Sun, 08 Oct 2023 19:45:33 -0400 X-MC-Unique: oADOvNWlPTedifEtKmownQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 963678007A4; Sun, 8 Oct 2023 23:45:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BAFC400F36; Sun, 8 Oct 2023 23:45:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 06A0D1946595; Sun, 8 Oct 2023 23:45:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6CC67194658C for ; Sun, 8 Oct 2023 23:45:30 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 57397175B5; Sun, 8 Oct 2023 23:45:30 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E61F170E4 for ; Sun, 8 Oct 2023 23:45:30 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 307B385A5BA for ; Sun, 8 Oct 2023 23:45:30 +0000 (UTC) Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-epAJfkaDMPOuqh9V6pqygQ-1; Sun, 08 Oct 2023 19:45:21 -0400 X-MC-Unique: epAJfkaDMPOuqh9V6pqygQ-1 Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3af6cd01323so2844975b6e.3 for ; Sun, 08 Oct 2023 16:45:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696808721; x=1697413521; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iIUGA5nyGTXIkeVMBhQE5fUan1nQD7xdjAl3FqxZfHs=; b=ugsPX9BWU+bWl4BrU6AuMrZiD9ixY9jv5+VuLlYdaR0LdckQADRf1wRTI4jqmsjFJ4 ny3fCuDa6AGXKF2WBNjtMuDa6nZPigZDTffma0hv6Ni38Kzp6oVgLmqYYiAxMAkfUhZi NZ3zZw3AFFe8lLGsUPkNKTlBAVjU0tnFTje9OPrwh134duhOf0OT/vjTj4xL1jcFT5oS wzfkneM5020m54+eZmPkG1hYY942bbtw3cFwVug+FEuX8TTt1OkRG83I/17tHJ/H5z4l tWs9GTqB3v1Xh/gL4nVTYNG14EKV9168bA1vWTRkW0f1yO9PebbyVRKv5Wlmrx0VKGIX 2C1Q== X-Gm-Message-State: AOJu0YxMmfUBBxDKvv03IKNc8ypR9I3cSwhLJF+bmW06paSXlxnpaBVc qVbYJnFujtFt/AUOpmUOC1Is3g== X-Google-Smtp-Source: AGHT+IE4ZtKoa5V64XLddUAQlfgY0O4kC79VmJ41/fARv+skVul5l6HD62OAku+HYlksQ55wgVACwg== X-Received: by 2002:a05:6808:1406:b0:3ae:108c:57b3 with SMTP id w6-20020a056808140600b003ae108c57b3mr20743909oiv.39.1696808720820; Sun, 08 Oct 2023 16:45:20 -0700 (PDT) Received: from dread.disaster.area (pa49-180-20-59.pa.nsw.optusnet.com.au. [49.180.20.59]) by smtp.gmail.com with ESMTPSA id 19-20020aa79153000000b0069353ac3d38sm5090447pfi.69.2023.10.08.16.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 16:45:20 -0700 (PDT) Received: from dave by dread.disaster.area with local (Exim 4.96) (envelope-from ) id 1qpdSY-00BIBn-0I; Mon, 09 Oct 2023 10:45:18 +1100 Date: Mon, 9 Oct 2023 10:45:18 +1100 From: Dave Chinner To: Sarthak Kukreti Message-ID: References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Subject: [dm-devel] [RFC PATCH 7/5] xfs: add block device provisioning for fallocate X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jens Axboe , Christoph Hellwig , Theodore Ts'o , "Darrick J. Wong" , Brian Foster , Bart Van Assche , Mike Snitzer , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@redhat.com, Andreas Dilger , linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, Alasdair Kergon Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: fromorbit.com Content-Disposition: inline From: Dave Chinner Provision space in the block device for preallocated file space when userspace asks for it. Make sure to do this outside of transaction context so it can fail without causing a filesystem shutdown. XXX: async provisioning submission/completion interface would be really useful here.... Signed-off-by: Dave Chinner --- fs/xfs/xfs_bmap_util.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index fcefab687285..5dddd1e7bc47 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -772,6 +772,37 @@ xfs_free_eofblocks( return error; } +static int +xfs_bmap_provision_blocks( + struct xfs_inode *ip, + struct xfs_bmbt_irec *imap, + int nimaps) +{ + struct xfs_mount *mp = ip->i_mount; + struct xfs_buftarg *target; + int i; + + if (!xfs_is_provisioning_blocks(mp)) + return 0; + + target = xfs_inode_buftarg(ip); + if (!target->bt_needs_provisioning) + return 0; + + for (i = 0; i < nimaps; i++) { + int error; + + error = blkdev_issue_provision(target->bt_bdev, + XFS_FSB_TO_DADDR(mp, imap->br_startblock), + XFS_FSB_TO_BB(mp, imap->br_blockcount), + GFP_KERNEL, 0); + ASSERT(error != -EOPNOTSUPP); + if (error) + return error; + } + return 0; +} + int xfs_alloc_file_space( struct xfs_inode *ip, @@ -780,7 +811,6 @@ xfs_alloc_file_space( { xfs_mount_t *mp = ip->i_mount; xfs_off_t count; - xfs_filblks_t allocated_fsb; xfs_filblks_t allocatesize_fsb; xfs_extlen_t extsz, temp; xfs_fileoff_t startoffset_fsb; @@ -884,15 +914,17 @@ xfs_alloc_file_space( if (error) break; - allocated_fsb = imapp->br_blockcount; - if (nimaps == 0) { error = -ENOSPC; break; } - startoffset_fsb += allocated_fsb; - allocatesize_fsb -= allocated_fsb; + error = xfs_bmap_provision_blocks(ip, imapp, nimaps); + if (error) + break; + + startoffset_fsb += imapp->br_blockcount; + allocatesize_fsb -= imapp->br_blockcount; } return error;