Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5653368rwl; Thu, 29 Dec 2022 00:16:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXtjlKUZ0GuT9d5Aqs0DfRfuPpnpQb/h4cBrSTJ0SckaVy08XUV+dyZQHf7BkTW5Ex+IQcnO X-Received: by 2002:a17:906:36ce:b0:7c1:727c:5f70 with SMTP id b14-20020a17090636ce00b007c1727c5f70mr23837312ejc.46.1672301779731; Thu, 29 Dec 2022 00:16:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672301779; cv=none; d=google.com; s=arc-20160816; b=So1pnGRoXgPex6VxWHh2kNRI3EzTn+pyOhovlHsFfyt3LTze6livAagG6wZF09a6C5 YutfU1AMwjnBU57xZ9h/FFaWGwJUM1PybrTVjV1+8q3OZfdXAU7bA5WynmgNykcKpzUI iwr747pVjM/EXNIearkSocBvpIUgsuJvDwnHBZWXFU8xUW69k0Fy09ukzYHjCbUmXKPb I6XLGJjhaJEvvj2EQtM7utIQQ9Q2EZ4Qp0XvZWt8634f8yoWlUZSgrphtC1hasj7ofCx 9RdfBsHYVi6zS33Rx53rwjJBPf5BJr/rV0hn80BO1KLRjOnr4fNOikaALCRREs4jUSPy e8fA== 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=/8DbNiGbTyMPWSOnHF8Kc/zLYgsGw2pv5SS5s5v0R+s=; b=bnHh7AgfPhLneQBk155Jia0ZOgSXBIHdYZgYQRwtVxIxWkBVzh26UwbZCaHsLs3Olr tvW8idJ3yfxSZd5tyPqsKDhzq1r5YqfWGOXFpcxg0pbSauW/RqB2wPvY7ay8EEb0LZmU d+HgPlXZrfBPUOv8VHRY7kn+JsxvxvhvGVAl8RK3MShwDug7nBCfAPDhLYgauj9valOn BOUf6kqCif+dlX8YvghZvQQjVSpzYrZiXJbm8UVVK/sJS+XhKl1g91UfsTn+3/Ikdb/o ES90N3cIDrMb0IyQy2hPsxKgi761tfmdey3mHpQweUTedfm1PKpmjho5ja7KhsM3j0p6 1t2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=g9XepsvU; 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 hd15-20020a170907968f00b007ae86742c20si15770524ejc.282.2022.12.29.00.15.55; Thu, 29 Dec 2022 00:16:19 -0800 (PST) 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=g9XepsvU; 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 S233090AbiL2IO3 (ORCPT + 99 others); Thu, 29 Dec 2022 03:14:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbiL2IOA (ORCPT ); Thu, 29 Dec 2022 03:14:00 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A76413D54 for ; Thu, 29 Dec 2022 00:13:15 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id b2so18283709pld.7 for ; Thu, 29 Dec 2022 00:13:15 -0800 (PST) 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 :message-id:reply-to; bh=/8DbNiGbTyMPWSOnHF8Kc/zLYgsGw2pv5SS5s5v0R+s=; b=g9XepsvU/uDTIkRU/0RfRztiaH4ysj5lPHnKvHquo4r2R81/t9Ab0n0lHqtHLvd81L Q99LTPfepq7s8nl2fawi9Q1Hj0cYT+r116Jc2iu54KTeJljXqfbrFWykA1a3MtFEjxbc IILAMKAGR6lSnvUPpxgAk36YR2QLLOe+csueQ= 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:message-id:reply-to; bh=/8DbNiGbTyMPWSOnHF8Kc/zLYgsGw2pv5SS5s5v0R+s=; b=Jh56AKslFeMVwjpRjRsbhZFuvNkqBJUFc2XbvtWjt5vqioAuCs6yprkMmw/BIKoO6o Rq18zEK4u4V3hrifA1isXy0vibHyMKjSAHNXMNhrlfBJO7g410zYHWWrwDKlAlA0DaFD I1KAhunfsThrKIe/CkZVhRjdUUPhYurTGd2RWezLo2vg0nRuSNYbz2OeH6en1BmFICs8 3x/kOKsJIjq43sjDACgWEW7qqpTtLOVS2DCLD9vvtPpTkh/RM+UhQhjTuNLPwbnlFibB 9WrPFqy6W6HxFNdlGUiu8cAJswws8dj+2qrFeaiEMTl5P9LHZiPg47bA9xxXRirBbdGv O62w== X-Gm-Message-State: AFqh2kpE1y5XGI2gjOxcXQPzOA9aj21drI6qC5lhUQh2i34ECm2q5GCj Og0F7Ng5CYKpS7Sm5Im2HwPa5w== X-Received: by 2002:a17:903:228a:b0:191:217f:b2ea with SMTP id b10-20020a170903228a00b00191217fb2eamr42495271plh.40.1672301595208; Thu, 29 Dec 2022 00:13:15 -0800 (PST) Received: from sarthakkukreti-glaptop.hsd1.ca.comcast.net ([2601:647:4200:b5b0:75ff:1277:3d7b:d67a]) by smtp.gmail.com with ESMTPSA id 12-20020a170902e9cc00b00192820d00d0sm6496325plk.120.2022.12.29.00.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 00:13:14 -0800 (PST) From: Sarthak Kukreti To: sarthakkukreti@google.com, 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 , "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , Daniil Lunev , "Darrick J. Wong" Subject: [PATCH v2 7/7] ext4: Add a per-file provision override xattr Date: Thu, 29 Dec 2022 00:12:52 -0800 Message-Id: <20221229081252.452240-8-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20221229081252.452240-1-sarthakkukreti@chromium.org> References: <20221229081252.452240-1-sarthakkukreti@chromium.org> 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 Adds a per-file provision override that allows select files to override the per-mount setting for provisioning blocks on allocation. This acts as a mechanism to allow mounts using provision to replicate the current behavior for fallocate() and only preserve space at the filesystem level. Signed-off-by: Sarthak Kukreti --- fs/ext4/extents.c | 32 ++++++++++++++++++++++++++++++++ fs/ext4/xattr.h | 1 + 2 files changed, 33 insertions(+) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index a73f44264fe2..9861115681b3 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4428,6 +4428,26 @@ int ext4_ext_truncate(handle_t *handle, struct inode *inode) return err; } +static int ext4_file_provision_support(struct inode *inode) +{ + char provision; + int ret = + ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED, + EXT4_XATTR_NAME_PROVISION_POLICY, &provision, 1); + + if (ret < 0) + return ret; + + switch (provision) { + case 'y': + return 1; + case 'n': + return 0; + default: + return -EINVAL; + } +} + static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset, ext4_lblk_t len, loff_t new_size, int flags) @@ -4440,12 +4460,24 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset, struct ext4_map_blocks map; unsigned int credits; loff_t epos; + bool provision = false; + int file_provision_override = -1; /* * Attempt to provision file blocks if the mount is mounted with * provision. */ if (test_opt2(inode->i_sb, PROVISION)) + provision = true; + + /* + * Use file-specific override, if available. + */ + file_provision_override = ext4_file_provision_support(inode); + if (file_provision_override >= 0) + provision &= file_provision_override; + + if (provision) flags |= EXT4_GET_BLOCKS_PROVISION; BUG_ON(!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)); diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h index 824faf0b15a8..69e97f853b0c 100644 --- a/fs/ext4/xattr.h +++ b/fs/ext4/xattr.h @@ -140,6 +140,7 @@ extern const struct xattr_handler ext4_xattr_security_handler; extern const struct xattr_handler ext4_xattr_hurd_handler; #define EXT4_XATTR_NAME_ENCRYPTION_CONTEXT "c" +#define EXT4_XATTR_NAME_PROVISION_POLICY "provision" /* * The EXT4_STATE_NO_EXPAND is overloaded and used for two purposes. -- 2.37.3