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: 13412139 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92D6DE94139 for ; Sat, 7 Oct 2023 01:28:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234043AbjJGB23 (ORCPT ); Fri, 6 Oct 2023 21:28:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234038AbjJGB21 (ORCPT ); Fri, 6 Oct 2023 21:28:27 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E701B6 for ; Fri, 6 Oct 2023 18:28:26 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-58d261807e8so6015a12.2 for ; Fri, 06 Oct 2023 18:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696642106; x=1697246906; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rQNnXBnSwzfsN2zrI7/k3aUY1SO1WpMoDwjEZpkrIxM=; b=Tkim1QONG/9kE53t1d6txbvvKmIc7Wh3I3WmMxd/izzCCouscolK1+hLMTvNI2JTHU YwgOP2Vu/g7xIlXGqixd4BJr7GHQARDHGU+UPnZDVuADEtEbBA84LE6nR9UlXw2ujStc RgerBIaeaG8VG4cR7KSNbu5p5UyQuLuOEvxUs= 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=LHwkxvBWcEMYOAwrYyvNhx/skJ7P0VAyzmJGjr5EnCWIVMmwlURu3/eYFv2X6JRJ/m 0VRH6HMfs/GgEiwObvL8kSwEApLYa6uJsiUFP5RGjhPq64D52SONmqCK+YhqYFUZK45C vh8iOYREAUurMDXnoiUUQEjXhlOcfDuey9rRWiz7HxhMbrI9VIIt9KNh+chXDISr9oeO 5R9xGOt4ojDwDG7C6kcrFvPcA3FcrXxIvtF3fcqoAZ3/itkn3+op0zOMKb2hnukypFS3 h5+/I8yvB6gLCxF5VMxOXgLMaMiCPJ5hGSJKxdCQ+2G8anYilnHzJ18+wzvPq4KA/vou acUw== X-Gm-Message-State: AOJu0YzEQ2CutskQ/FengY+KCBeIQrqyv8rsU3Ziy4abRp1ZpsQr7Vrv XtlndP6WNCiEOACLsD6AKx9T2w== 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 Cc: Jens Axboe , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , "Darrick J. Wong" , Dave Chinner , Sarthak Kukreti , stable@vger.kernel.org, Christoph Hellwig Subject: [PATCH v8 1/5] block: Don't invalidate pagecache for invalid falloc modes Date: Fri, 6 Oct 2023 18:28:13 -0700 Message-ID: <20231007012817.3052558-2-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.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: 13412141 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30DE5E9413D for ; Sat, 7 Oct 2023 01:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234073AbjJGB2k (ORCPT ); Fri, 6 Oct 2023 21:28:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234054AbjJGB2i (ORCPT ); Fri, 6 Oct 2023 21:28:38 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13331CF for ; Fri, 6 Oct 2023 18:28:29 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-694ed847889so2381717b3a.2 for ; Fri, 06 Oct 2023 18:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696642108; x=1697246908; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7lVWtirLO6S4iWrOEgizd7kpFd4X9bEhVwAoPUKWyd8=; b=RnxwfwBNjSZP63VqQiKsQUdjNqofWfECheQuz4bzBEqW+aNMZhmy7b15Yiqs/fLDIU mJTrx4WONpsQvEAzWrUHP3zJ/ycBj+NKFe6VvM0owoLwMth1giaQI/zAiT8tpLXseXQZ T0VB0h0b/WvrSQ3dTngmYxJkZfDWnARxiKriI= 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=cj5ObqevIClYGbtrsvLJ9BvGehTdeqzXLn0lXEZ6SsOXloAl9RO83xz2V2XxbcjhUZ NMTgifZlwure2NjZannsZWzvADY11ksfTc5nV6G/dOrT3h5S9/6Vm+EAMvein9RgaLLv yQyKDruCNJmS8tG4q8QiWWn/bMBDg+yU7u1XcIj/DTQ8QmKrLVm7R12prOk63jzU9/gX ZMO1jHcnjqJDochR4fsOPyuKHP7vHxHc0rFtW/KCAXPqqzEMU71QFd1mS4Z7BwO2x8Al fjqCiV2psfkT7BT9f/BTvh9qzavRkmD1rtdPBE6B1gANsYwKbtZjy+mAaXEEx96OJG/W MIlA== X-Gm-Message-State: AOJu0Yw4sAJEbpGlhySg/XfNjP+o8Dvi7tYH15zC/YgBpPrlEPRXvpEm YpPhQLko8tdERh+xjZF0Re3ZnA== 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 Cc: Jens Axboe , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , "Darrick J. Wong" , Dave Chinner , Sarthak Kukreti Subject: [PATCH v8 2/5] block: Introduce provisioning primitives Date: Fri, 6 Oct 2023 18:28:14 -0700 Message-ID: <20231007012817.3052558-3-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.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: 13412140 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0F64E94139 for ; Sat, 7 Oct 2023 01:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234046AbjJGB2l (ORCPT ); Fri, 6 Oct 2023 21:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234062AbjJGB2j (ORCPT ); Fri, 6 Oct 2023 21:28:39 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E20EE4 for ; Fri, 6 Oct 2023 18:28:31 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1c60cec8041so19971905ad.3 for ; Fri, 06 Oct 2023 18:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696642111; x=1697246911; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qwbLxQP2MlVOvPJLqOZgvAlqQEss4gZRIzs/TWsm4fw=; b=JAL7Y5nMIPObXpQQ1/i/luoEBZrnL4/t4Q5U2s0jqk7ZARrhlf/wgFNRl3gN/s18Oq TLlvu68mEPALzJV21SWzNOKZhNaOgVYcL5dTwj95XQYRUluEPgVRwLpe9ciZAAcEBFwe gIyWbQzOqqXF8EQIKN6gSw68aDfOvlaXJpLWU= 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=H5hdGKQIXwkcujPEMAbHQVh/pVN3FYcS6TyZ8tCFvo8a19rz9y2BUcuTcCAKZq0GOl BMYigvSPsbD5dCCG8jRp+FTvle8SJsAQdUGGhRwgh4aqynMScOQ2BWlLTvlWgNAmTot+ TagW6O0ea+9mTR+iw/DniNEB0cUC13iUyWekwyU0UOa0s7fmVQ2HC/uXoZpAD/YhRZ3q yK9IOxg4DhVysTyD7pDw2cBLdkKwnwhN74U8/9A/hTHCwh+uDTi/9elDm3MbyezKwZOB dPf/2XQaa/t+iJpIeAR/Fgybg20IqGaNPlso/GaNG7i8dql+AxNkzXLlnvCeo+B3Odp0 9rfw== X-Gm-Message-State: AOJu0YwLW/mI6yV3s9lmkkpZhdrAvaOa/928qtfYvakz0FeZyQ0yyCEL RhBDqsBW7Jk1Ly59chCf6Ea26w== 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 Cc: Jens Axboe , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , "Darrick J. Wong" , Dave Chinner , Sarthak Kukreti Subject: [PATCH v8 3/5] loop: Add support for provision requests Date: Fri, 6 Oct 2023 18:28:15 -0700 Message-ID: <20231007012817.3052558-4-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.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: 13412142 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEA56E9413D for ; Sat, 7 Oct 2023 01:29:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234063AbjJGB3E (ORCPT ); Fri, 6 Oct 2023 21:29:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234081AbjJGB2k (ORCPT ); Fri, 6 Oct 2023 21:28:40 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55E53101 for ; Fri, 6 Oct 2023 18:28:34 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-692779f583fso2216050b3a.0 for ; Fri, 06 Oct 2023 18:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696642113; x=1697246913; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FqB1hDPxuIIbyhAWdDDt1cqx20h+edShJFHuWVHb1Qc=; b=aWgOmSUHwsmMvbEaaTkokkzio5kkq8dXlNqM0Nt2qbGhYfAhtQ3WJb4BaiBliM9EmC EQN730lOOGn22sCAAAfEMlGWtZDQMIfZSR5jNUUY6tFGGYtqoTEOoCqUU0ScxrcWTx/n 4iWRGReDP3MdEdZrnMy5VeiOo5WzN8kmm2dD4= 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=VaDpfWKwlC4Wpv0E6qQaaYwMTirfC3aZ89NbZqN5Cp+22WNxTltDoQ+1wJhPZxFPEh XJDsVhTMUl3wKpZ8SGIoPni9WSnnCF8DZaMM4mdsOs/cuqV/8KxdU7jEogVA/G9mUFCK 0ueSjxbMXeIDeauOnA4bsAm7UmYbP+OBxA2kybrTNx8qYkyFLGGSMCzEZ2WGyuHzC9mZ n95YqvKLstoyh3OUxL95wD2vBZTZYM2GXD6N7S+Djrosa7qulfOiNRn2uoLv1NsLAN9u 9XPt/J86Buhq7YWOsQ3D3YUn9dCMeREAsRh+FyePetTJsmjq6lxYa6SwY9tt7Ugrqlf/ C63A== X-Gm-Message-State: AOJu0YycM55XD3TlfChdh6oddTe+7e4X59lI9G06aDBVmb1WvW0FC7pU mzdNrBwKkww2km5cud1wTcFSfQ== 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 Cc: Jens Axboe , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , "Darrick J. Wong" , Dave Chinner , Sarthak Kukreti Subject: [PATCH v8 4/5] dm: Add block provisioning support Date: Fri, 6 Oct 2023 18:28:16 -0700 Message-ID: <20231007012817.3052558-5-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.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: 13412143 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 326C1E9413F for ; Sat, 7 Oct 2023 01:29:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234081AbjJGB3F (ORCPT ); Fri, 6 Oct 2023 21:29:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234092AbjJGB2l (ORCPT ); Fri, 6 Oct 2023 21:28:41 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCB16116 for ; Fri, 6 Oct 2023 18:28:36 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6c4c594c0eeso1813485a34.0 for ; Fri, 06 Oct 2023 18:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696642115; x=1697246915; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rVF8rK/kC1UjwzLMGR23sx6dhVRDno9128uSIr9eCP0=; b=P0+yXjgCOTUKvlSLPHb+2kHOtP+XtZ11kXrFLvwoGtJ66JfgQBSp0acWdl8BISfCSp FThOk1VdUlynLlHNHkjSEdN+Bhc6FenoYpFSE41mWxw0YNMUYrLSYcHZAW7sANBRnnbi 3+mJkHXzd4QQqnItdnay2svjjS4LX9gzP7nT8= 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=ratv6XvjJplxC/P9mpJ9Xgl8L+qZ/PgeLQBu1aqthoHKpoV+0I+JK/4acte2W5tjRK oWErpjdXPnsV57eYlJCzzH9dihcNZjTufXL6BsCq4mFN9SQbTc5iOdVNAGJqdM142Xu5 47LI1rF6OGzeZoHaBfjqZSfZ7zz8+QRxclPDcn+hkAbvQiHRw1OmdlzQ1b0GisGSnIwx 538YgIwrHwuoRzKvm0pzO7a3nHl8EW4AujJJ+AmKHcND98BN4LBJWFPFjZGAtM5jQYDL ZlPVeBIfVSvGg2CaJ6gbcAKsEUk8CErxQt0Uco4tMKqbwxo38BfpR9aQP5xD0kWjRELY 3gYg== X-Gm-Message-State: AOJu0YzjliCTlRYpZF0Rnl/zXXag46A1kjcSA38BcRBuJVGKbrHbdctl Gp+CCHPAR0/oeZJsKX6Nd1i5S97ENKutCkW3iJk= 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 Cc: Jens Axboe , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , "Darrick J. Wong" , Dave Chinner , Sarthak Kukreti Subject: [PATCH v8 5/5] block: Pass unshare intent via REQ_OP_PROVISION Date: Fri, 6 Oct 2023 18:28:17 -0700 Message-ID: <20231007012817.3052558-6-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.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: 13412831 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A76EE95A67 for ; Sun, 8 Oct 2023 23:41:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344989AbjJHXlS (ORCPT ); Sun, 8 Oct 2023 19:41:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344978AbjJHXlS (ORCPT ); Sun, 8 Oct 2023 19:41:18 -0400 Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 937E2AB for ; Sun, 8 Oct 2023 16:41:16 -0700 (PDT) Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-1e106eb414cso2766397fac.0 for ; Sun, 08 Oct 2023 16:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20230601.gappssmtp.com; s=20230601; t=1696808476; x=1697413276; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WhYJRI062pcX8jyWpJ2qutO3TNLI93kE5AesIBQ7T3Q=; b=qfXMJSRjstnQQ9O3qQKeqa0wLdMd5xQf8I7gXIpk2V15FiFipYnG7y/ol6PmF3OFjd fHSt4C7f2lTyHpXI5ssrIa3MyInD5XSG3VG5EX9NwXK88tQUVMVRA0zP6L2F8FHLjU0M r5veBrNYhgbU32AH4X1BaK/KdTmyXkL0fmPzqXmWGjbi6i5VTcXy1LXmwnjnEXZWQPRn aAhlz+NldE06xnnRjvUj9CE1c4eKEw5MTvm0J/uQMewP3w7bZ59DTRN/91c1BtjZHof7 jr7e/E2xpLHBs1uM3rxb0TqVXwNUg/gN0+NSx4v7u2yW7KN/LonlQ4BfpomfB67JUmla UiWA== 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=k6iwb27WDrdSyfJpniLyStqyFGNHVnEN5/UknbN+trBvSzlwwjcUQHnt3GssMqYW1K rVJSILzJPdPMuRDuMKwb69IHPX8Rpao5QzO/Fqk+YW0H1e8GKx3Cx9CKfpYuSoQLwRl3 R3em9X4mJLJS9T9jrcxMh1ZGv54IAR2QMAjfnk58G0bqThsPJlA/ZG+4u5DPkGdJg7nZ fL+XWVicGrMj32WjF4Z5O13/XbI8dhKBfFuN8+tyVNnDDvR2h/xK9IUUpagTvuUvqdVA mMbKlsoHvmUzizv+T35IhRAoAouLS520mO8zv+9aTGAlq9zFCTkDNzJiinxJa104sivS v7Fw== X-Gm-Message-State: AOJu0YwTaFX4QBuGoMlf9kyMhiVT65LWsHzMBQp8O8AImOr5M7PU9KFi tBb5ZZaoIwEdSdxBua9nYw2htA== 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 Cc: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , "Darrick J. Wong" Subject: [RFC PATCH 6/5] xfs: detect block devices requiring provisioning Message-ID: References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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(-) 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: 13412834 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7C47E95A90 for ; Sun, 8 Oct 2023 23:45:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344988AbjJHXpY (ORCPT ); Sun, 8 Oct 2023 19:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344979AbjJHXpY (ORCPT ); Sun, 8 Oct 2023 19:45:24 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80232A6 for ; Sun, 8 Oct 2023 16:45:21 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3af6cd01323so2844974b6e.3 for ; Sun, 08 Oct 2023 16:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20230601.gappssmtp.com; s=20230601; t=1696808721; x=1697413521; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=iIUGA5nyGTXIkeVMBhQE5fUan1nQD7xdjAl3FqxZfHs=; b=f5MtScfDYvUPb3PwTlai8laM9QFdEr8ZDPhoTRQ0KRc8XqEdovj0S90jUsGmaOAhO0 0TSgVnUxaKTSMOsOyUVLEtm1aqgsj5Toyi7VgdfgbtM/pT1OYIfC2qu5LPdfWiQ+Y7R/ OnUytDPAcCOs/VVxa3OcQMchQuzrvwvF3GWrN32qmGwQ1SgDSx4eNBv5qYFjZzG8eWji BA2zvwAx9q5qf0JR/FeYA0bTQghKMp5UydpzCqLnSuIbbxv3ZStpfyy2rL/gTHTDLd+V jXT4Cuz329FdeFaqKq0PCs3rCTziuIZv0YRDvMg0QqroGRVNl+YTYhfzOpSyG0j/2Vh8 q0CQ== 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=wz1RH1/rkUrhUzq3d9Tq9RHnf5qDyunEEDWsL2oFap5kU5rzmvQPbEp8vAkSico3B8 Q/xsvVDCKDO2/c9V7wQ6JV8DN/X8Wp2fbRqcthQk+3mr8ocq4XcIcYrpZu+W0obAE+Lq vegejxlbhtc9/GL0JnkToQoOGyl/UPAD1v9iBkg5VFsOHcNTkh9CNFX/6EjdxiWwedJ4 GJMerHf33sN57qhsvh7o/Md0kblKr7H5hJc6R3P8i/RQsnRSV1GKkUh9Te+FHalslkpH Z8RXVVw07N+auPo2B30/+kNEhYOY6MQUlBGyfbh+NKQ/tFEvc04v3R5n9OClnTyzK6fb 2scw== X-Gm-Message-State: AOJu0Yz0nGKLXwdAv8hpAltJ3T3NNpwcjWpRFbtAYzNs3DkSt6qaWHXJ BGUHukzOGY+EchhcHYZH8HsyTQ== 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 Cc: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , "Darrick J. Wong" Subject: [RFC PATCH 7/5] xfs: add block device provisioning for fallocate Message-ID: References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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(-) 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;