Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1060838rwn; Thu, 15 Sep 2022 09:51:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM53/EFOl809sZO6m3IDm721GxiJijwdM7nw2T5ZaDFYldm3O60IzO9W5T5ByRWQKQpGjAVm X-Received: by 2002:a05:6402:b6c:b0:44e:2faf:1ba4 with SMTP id cb12-20020a0564020b6c00b0044e2faf1ba4mr628959edb.191.1663260704616; Thu, 15 Sep 2022 09:51:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663260704; cv=none; d=google.com; s=arc-20160816; b=0EJ7VCVW9PmWshToPEgGQjXgKG/AoXSjEC+kklWOjsXtrXTLkUJmEJl+9g8VtCT3mp amha6pT4wYv14qVYF2bKznMnU70b4ISIyFrmTAnVMMC2B7/I9PZSOKsi4rt9gV7yi6HJ 1HYLZVYz2CCWpP/kaiWY9lh3jAVj2+d/46xvldJ5VildBpe1ZLli+ywkYzFSeTAx7fOS 0C5XbiogXYYjhoDMpZvnPQYHc+wwkO1a8YG2NdG2g87AsvP9zn/eKEoP3XDR8rOVGZGv ybRRfHbUaPAUXjuEEKGI6p86OfhAPoB/ztyreYBDWFxx/3/nVnGa0t3zcYWB/dFTq8Il ZDVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GHq7dVGm2OOxGrPIxR4jW0JwHX2wEssn4Ks1aVeah78=; b=w5JEjp6fXSY3/llLP2nb+dwpGDd0n1XszdqpnZTWEoIugRz0rE8Hi5PFO2z8d2bXbX ljg2d2sApV6Gq2iAN8UDniBcoJeeO9AGNx0pYCJIkF4VUPh+4m4eJgGF6z6Yz74Isl/h DKRlrM4ovzwyfVl/dpy2KyOwDTlCJe7HTLDlWkmEPsqWwpALWB4jxN/HD4MBGhWTTw9B ymAlRxr7zhVVbC+RUnGlitwfymo2sYOGPzV3NBT3DaK2BB2lZZPf1tqK2iczs5CmXdsc wJQIW/sgYrr5pQ/pmqsjrBfb7nMwy/wvzVQWmFejnBneAe2JblpruUUMslwzv005nn5b nHAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=N080U3jr; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp9-20020a1709071b0900b007392f9ad702si3682428ejc.741.2022.09.15.09.51.19; Thu, 15 Sep 2022 09:51:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=N080U3jr; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230125AbiIOQtj (ORCPT + 99 others); Thu, 15 Sep 2022 12:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbiIOQtB (ORCPT ); Thu, 15 Sep 2022 12:49:01 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08AE29E686 for ; Thu, 15 Sep 2022 09:48:53 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id p1-20020a17090a2d8100b0020040a3f75eso17984420pjd.4 for ; Thu, 15 Sep 2022 09:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=GHq7dVGm2OOxGrPIxR4jW0JwHX2wEssn4Ks1aVeah78=; b=N080U3jriplkoP0mn+6UNs5gJxyCP2n1wsAfUwiTdaLhfvKefEOQ3Jnp4joBXWoSkV PsHBuZ6zxKDriXffRGWMsJkIPwQrlz0X29bfVvN/3YJzF4V41GPn40hK7UxrsvNP/xuI 14j2sTvlzYkuFYYqjzjdseq8AKlrm90Wt6P8k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=GHq7dVGm2OOxGrPIxR4jW0JwHX2wEssn4Ks1aVeah78=; b=U7uMKV5AJ0JEdZshQJIpUth0Eac8vkZ5yxzCOIb053y8D5tf63Pp2l4Ltfz9I81lg4 NZH0d+88AOizoauYoSJTxp6xYOuYDe759UOo6cKLxhXJ1UB2FPOGkFY0FqXYWdhTLBSh wC85vHIcVXGRaT50U+9cN1TG3T0oZ2nlbjFS6ZG+p7K3xOxv6+8vOiTm9UTrlxXiwMqp fZhKDZuL0uh+p1GkbExdWeni9rjblqiK/O0D77wAJO+EXa80b3puIseSSN89gDxQoDI5 pCZmiw/H7ZGgbkeGTi9EB65Q/gjo9FCx/TSsSkict8qSXpWcows2lgmk2HWuulbdbMDp 9shQ== X-Gm-Message-State: ACrzQf3NqSUq2FHFc8rcRRs1PRBby4y5ItW57fHfyzCLryN0dQVC/ROK KIQXzYmZWztAPBVXTUVXP/VGxg== X-Received: by 2002:a17:902:dac4:b0:178:3037:680a with SMTP id q4-20020a170902dac400b001783037680amr327417plx.37.1663260532933; Thu, 15 Sep 2022 09:48:52 -0700 (PDT) Received: from sarthakkukreti-glaptop.hsd1.ca.comcast.net ([2601:647:4200:b5b0:3af2:34b2:a98a:a652]) by smtp.gmail.com with ESMTPSA id o4-20020a170902bcc400b00177ee563b6dsm13174970pls.33.2022.09.15.09.48.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 09:48:52 -0700 (PDT) From: Sarthak Kukreti X-Google-Original-From: Sarthak Kukreti To: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: Jens Axboe , "Michael S . Tsirkin" , Jason Wang , Paolo Bonzini , Stefan Hajnoczi , Alasdair Kergon , Mike Snitzer , Theodore Ts'o , Andreas Dilger , Bart Van Assche , Daniil Lunev , Evan Green , Gwendal Grignou , Sarthak Kukreti Subject: [PATCH RFC 6/8] ext4: Add support for FALLOC_FL_PROVISION Date: Thu, 15 Sep 2022 09:48:24 -0700 Message-Id: <20220915164826.1396245-7-sarthakkukreti@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220915164826.1396245-1-sarthakkukreti@google.com> References: <20220915164826.1396245-1-sarthakkukreti@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Sarthak Kukreti Once ext4 is done mapping blocks for an fallocate() request, send out an FALLOC_FL_PROVISION request to the underlying layer to ensure that the space is provisioned for the newly allocated extent or indirect blocks. Signed-off-by: Sarthak Kukreti --- fs/ext4/ext4.h | 2 ++ fs/ext4/extents.c | 15 ++++++++++++++- fs/ext4/indirect.c | 9 +++++++++ include/linux/blkdev.h | 11 +++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 9bca5565547b..ec0871e687c1 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -675,6 +675,8 @@ enum { #define EXT4_GET_BLOCKS_IO_SUBMIT 0x0400 /* Caller is in the atomic contex, find extent if it has been cached */ #define EXT4_GET_BLOCKS_CACHED_NOWAIT 0x0800 + /* Provision blocks on underlying storage */ +#define EXT4_GET_BLOCKS_PROVISION 0x1000 /* * The bit position of these flags must not overlap with any of the diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index c148bb97b527..7a096144b7f8 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4356,6 +4356,13 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, } } + /* Attempt to provision blocks on underlying storage */ + if (flags & EXT4_GET_BLOCKS_PROVISION) { + err = sb_issue_provision(inode->i_sb, pblk, ar.len, GFP_NOFS); + if (err) + goto out; + } + /* * Cache the extent and update transaction to commit on fdatasync only * when it is _not_ an unwritten extent. @@ -4690,7 +4697,7 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len) /* Return error if mode is not supported */ if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | - FALLOC_FL_INSERT_RANGE)) + FALLOC_FL_INSERT_RANGE | FALLOC_FL_PROVISION)) return -EOPNOTSUPP; inode_lock(inode); @@ -4750,6 +4757,12 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len) if (ret) goto out; + /* Ensure that preallocation provisions the blocks on the underlying + * storage device. + */ + if (mode & FALLOC_FL_PROVISION) + flags |= EXT4_GET_BLOCKS_PROVISION; + ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size, flags); if (ret) goto out; diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index 860fc5119009..860a2560872b 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -640,6 +640,15 @@ int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, if (err) goto cleanup; + /* Attempt to provision blocks on underlying storage */ + if (flags & EXT4_GET_BLOCKS_PROVISION) { + err = sb_issue_provision(inode->i_sb, + le32_to_cpu(chain[depth-1].key), + ar.len, GFP_NOFS); + if (err) + goto out; + } + map->m_flags |= EXT4_MAP_NEW; ext4_update_inode_fsync_trans(handle, inode, 1); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index a58496d3f922..26b41a6c12f4 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1107,6 +1107,17 @@ static inline int sb_issue_zeroout(struct super_block *sb, sector_t block, gfp_mask, 0); } +static inline int sb_issue_provision(struct super_block *sb, sector_t block, + sector_t nr_blocks, gfp_t gfp_mask) +{ + return blkdev_issue_provision(sb->s_bdev, + block << (sb->s_blocksize_bits - + SECTOR_SHIFT), + nr_blocks << (sb->s_blocksize_bits - + SECTOR_SHIFT), + gfp_mask); +} + static inline bool bdev_is_partition(struct block_device *bdev) { return bdev->bd_partno; -- 2.31.0