From patchwork Fri Dec 20 03:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Kukreti X-Patchwork-Id: 2026081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=RGcQdH4w; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=jkmo=tn=vger.kernel.org=linux-ext4+bounces-5795-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4YDtdM2qMbz1yRt for ; Fri, 20 Dec 2024 14:46:46 +1100 (AEDT) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4YDtdD204dz4wp0 for ; Fri, 20 Dec 2024 14:46:40 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4YDtdD1xFKz4wyr; Fri, 20 Dec 2024 14:46:40 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=147.75.80.249 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1734666400; cv=pass; b=k1p4e14eYFsaUb/HSjEJI1D2QfLiSCbE7XuIguCvNp0DqnsMxqctPqiDY/YjmeAxbk0Fju0lWqWD+enNsdtc995SFPmp/fdUwlNpEEtzgMkArKK9FzLMkkG0o+FW1r0CwapZNORJtcwTaC+Buk88HoVQsDSEszHijami6Y7R9eeyFUg4dkumcxLA10Z1ppIlTQ23Ueb0FwbFlQNw0BB9b2xfW0vAXY7rmiK4ktS5d6CKHKHRseXZKXkfRwQpmWHMVJVhP1/2U54TYo361Zqp6LYn5HsIOBrhbiNiYijpsxJxMrI9s9dr4k5L1+2A7L5BJqCPCS1Q9SW0nT37esvCLA== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1734666400; c=relaxed/relaxed; bh=GWORy8/wFQU8P1QVtY5SXf+TsuhH732H7iICYc/uHfE=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=I5Y1ct8vU/w9o95fJMsN2rA7rwkM4RnoQ98QqyrKZjqkfl/DGYsIla3IVzx5Tiv02efTI4D0boW9BRgVv+IhXxCvp4XP5Z+Vch1IdnhWpUZUdc0pnpaXLPJfU0gIzlu54PlvDcxMzsOvsRW1h1u7CCBODKXJLuj/CbkHrwqZAINgeT/jeFooZtO+aEWeD7VBtnmQtE+uQAaI0HloX1v1/yVA/mmkHn9vhVoejKdpWgoRmTy73Z/4Ov1y9OWll2eAJsFjE1FMiDm4zL8FgzA+YkgYdx0eQbFSXd7ZBye+rwxe4ncWtmgqhbA3dLpz5LuORuG/RLcFRjHnql3fUTUgFQ== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=RGcQdH4w; dkim-atps=neutral; spf=pass (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-5795-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=RGcQdH4w; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-5795-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4YDtd74bQ7z4wp0 for ; Fri, 20 Dec 2024 14:46:35 +1100 (AEDT) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7C5501889F58 for ; Fri, 20 Dec 2024 03:46:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AB8B2F509; Fri, 20 Dec 2024 03:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RGcQdH4w" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B646918641 for ; Fri, 20 Dec 2024 03:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734666391; cv=none; b=ZfoyO+HonzxP3//MBxskRGYXveQSzmt4OQzfzdRYMDtb8d6PHuFHknqKdJjlL47uK+TW4yJxat+X5rRAzN+sc0NJ7XUcXMzqHbECiaOJjLG4rrdO+krc904pb1ZcYL/NXJ4MMvPWT8C7U4rtCcEYzKNK24TzIiHsnW4usP1QgKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734666391; c=relaxed/simple; bh=RE+73w8222oSZAST9t1x13ETpjuLRjO+n4gVipAXvZA=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=sxa3KYU7gmi6BurSabYZQu5epEvXxVl7DT8x3Pb93nbrpekUAs6kjJ9aR7B34Yd2LSzVBCWGyaiE2Muv4ZMGbBzfn7u9S9kKD0WTId31YExkgXmx0ofEer/E/ODV0sBVOw0xfjRbmP4I+NHD+P4JCHlxx7TTOyigdo2q2ehj+Dk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sarthakkukreti.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RGcQdH4w; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sarthakkukreti.bounces.google.com Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-728eda1754eso2102169b3a.2 for ; Thu, 19 Dec 2024 19:46:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734666389; x=1735271189; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=GWORy8/wFQU8P1QVtY5SXf+TsuhH732H7iICYc/uHfE=; b=RGcQdH4wxgM+9br+aX23M5kdPkGsaL4jfn1UGNSMCNbgST8JfihJMBKYoJJV8zNH7a RLnqtrvam6b4+K1eyzl5vcJgzA1IjUFdujrLEhzHZAIwYUjEg9sl7aLtLzrTTRu2yT5O Z9c8WOO3FsQ2Z3LOKc8C2UIzCzL49S03dt8qivvGwxPySQLdrTEjFgVN841nOBH9oORL bRrWrTKmHxYVgM4HAsLRqipzRSqR5+0soE6ygXdHPm7esK/ZrPBOTvHw3WL4l0US6+p8 jSy1v048mfOKoP2be4oL047QF9gWX89baxv0SqmzCLgL2qscAahmuotSMjjmxGxxOT4Q hx6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734666389; x=1735271189; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=GWORy8/wFQU8P1QVtY5SXf+TsuhH732H7iICYc/uHfE=; b=WSqGjbq9Q4cxCgWwy6z/ctVOngt+tbbUI5ErqGMCH0tJlsVuoaBriH8dpQUXFIAzy9 RveC6UFwSa29R/d2kcMWh7QQaP7u/rebxeTKilZKoqIfhGdYu778rpqT+IG2cI6G/ECi 8v3/VLORJZNIEXywAsaSfcgNjQVrHJ+UHvZEer/c+brdsFs+4zEFmgDTAcjfAopAzC4L 9dcNxIq7U1iNWcBI+N2TNM+Cfpd+mHUndptEuwJ9ksPVCuO1vYjUjFlB4C4oH23nRKHD fv4Wk+Vu+h+EwuFE38N2N+tRSYOcSMOePoYGqO/ZmEtkLBLr+cVm7eTBncmcPpWRqClC qA9g== X-Gm-Message-State: AOJu0Yz7+VGpL9UDt9//C1O3Z5mPqhzjZpWfW5MwLmT3LiGhtZx7uND5 ngnLjZ2f3AWytbHfJwwlydlao2Zdj2dVCsuWSmje/YAryuc1Gdh3D0CmmUWWGrZUnQsEUckZNew omO3KPMppripG5jr83035qnYMMSScNjuSBX5PD0D6azlXTB6zUz4H6pbpepdW1q89MWR8dAttt7 utJQ7MjkJgVp2TaAyTXzNufqbmC26ZdTHrh3pbOf2iAPu3qwCRn/3WeK/8oDI2be3ErC24ZVbct XzUqDq/ X-Google-Smtp-Source: AGHT+IGE4cgPET2apFfSsP/hIUsJmAi5bsO7KOfvtOsfPypkMQmt5OweiJ2QouN/5HnhurNZvn3yWzSJsH8Ams51D2ebwA== X-Received: from pfbbd10.prod.google.com ([2002:a05:6a00:278a:b0:728:e508:8a48]) (user=sarthakkukreti job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1706:b0:726:f7c9:7b36 with SMTP id d2e1a72fcca58-72abdd7bacdmr1883003b3a.8.1734666388909; Thu, 19 Dec 2024 19:46:28 -0800 (PST) Date: Thu, 19 Dec 2024 19:46:13 -0800 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220034613.3624898-1-sarthakkukreti@google.com> Subject: [PATCH v2] fallocate: Add support for fixed goal extent allocations From: Sarthak Kukreti To: linux-ext4@vger.kernel.org Cc: "Theodore Ts'o" , Andreas Dilger , Ojaswin Mujoo , Sarthak Kukreti X-Spam-Status: No, score=-10.8 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on gandalf.ozlabs.org Add a new flag to add support for fixed goal allocations in ext_falloc_helper. For fixed goal allocations, omit merging extents and return an error unless the exact extent is found. Use case: On ChromiumOS, we'd like to add the capability of resetting a filesystem while preserving a set of files in-place. This will be used during filesystem reset flows where everything apart from select files (which contain system applications) should be removed: the combined size of the files can exceed the amount of available space in other partitions/memory. The reset process will look something like: 1. Reset code dumps the FIEMAP of the set of preserved files into a file. 2. Mkfs.ext4 is called on the filesystem with -E nodiscard. 3. Post mkfs, the reset code will utilize ext2fs_fallocate w/ EXT2_FALLOCATE_FIXED_GOAL | EXT2_FALLOCATE_FORCE_INIT on the extent list created in step 1. Signed-off-by: Sarthak Kukreti Changes from v1 (https://lists.openwall.net/linux-ext4/2024/12/12/38): - s/EXT2_NEWRANGE_EXACT_GOAL/EXT2_NEWRANGE_FIXED_GOAL Reviewed-by: Ojaswin Mujoo --- lib/ext2fs/alloc.c | 2 +- lib/ext2fs/ext2fs.h | 3 ++- lib/ext2fs/fallocate.c | 21 +++++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/alloc.c b/lib/ext2fs/alloc.c index 3fd92167..ba5b1c5e 100644 --- a/lib/ext2fs/alloc.c +++ b/lib/ext2fs/alloc.c @@ -390,7 +390,7 @@ no_blocks: /* * Starting at _goal_, scan around the filesystem to find a run of free blocks * that's at least _len_ blocks long. Possible flags: - * - EXT2_NEWRANGE_EXACT_GOAL: The range of blocks must start at _goal_. + * - EXT2_NEWRANGE_FIXED_GOAL: The range of blocks must start at _goal_. * - EXT2_NEWRANGE_MIN_LENGTH: do not return a allocation shorter than _len_. * - EXT2_NEWRANGE_ZERO_BLOCKS: Zero blocks pblk to pblk+plen before returning. * diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 6e87829f..313c5981 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -1446,7 +1446,8 @@ extern errcode_t ext2fs_decode_extent(struct ext2fs_extent *to, void *from, #define EXT2_FALLOCATE_FORCE_INIT (0x2) #define EXT2_FALLOCATE_FORCE_UNINIT (0x4) #define EXT2_FALLOCATE_INIT_BEYOND_EOF (0x8) -#define EXT2_FALLOCATE_ALL_FLAGS (0xF) +#define EXT2_FALLOCATE_FIXED_GOAL (0x10) +#define EXT2_FALLOCATE_ALL_FLAGS (0x1F) errcode_t ext2fs_fallocate(ext2_filsys fs, int flags, ext2_ino_t ino, struct ext2_inode *inode, blk64_t goal, blk64_t start, blk64_t len); diff --git a/lib/ext2fs/fallocate.c b/lib/ext2fs/fallocate.c index 5cde7d5c..20aa9c9f 100644 --- a/lib/ext2fs/fallocate.c +++ b/lib/ext2fs/fallocate.c @@ -103,7 +103,7 @@ static errcode_t ext_falloc_helper(ext2_filsys fs, blk64_t alloc_goal) { struct ext2fs_extent newex, ex; - int op; + int op, new_range_flags = 0; blk64_t fillable, pblk, plen, x, y; blk64_t eof_blk = 0, cluster_fill = 0; errcode_t err; @@ -132,6 +132,9 @@ static errcode_t ext_falloc_helper(ext2_filsys fs, max_uninit_len = EXT_UNINIT_MAX_LEN & ~EXT2FS_CLUSTER_MASK(fs); max_init_len = EXT_INIT_MAX_LEN & ~EXT2FS_CLUSTER_MASK(fs); + if (flags & EXT2_FALLOCATE_FIXED_GOAL) + goto no_implied; + /* We must lengthen the left extent to the end of the cluster */ if (left_ext && EXT2FS_CLUSTER_RATIO(fs) > 1) { /* How many more blocks can be attached to left_ext? */ @@ -605,12 +608,15 @@ no_implied: max_extent_len = max_uninit_len; newex.e_flags = EXT2_EXTENT_FLAGS_UNINIT; } + + if (flags & EXT2_FALLOCATE_FIXED_GOAL) + new_range_flags = EXT2_NEWRANGE_FIXED_GOAL | EXT2_NEWRANGE_MIN_LENGTH; pblk = alloc_goal; y = range_len; for (x = 0; x < y;) { cluster_fill = newex.e_lblk & EXT2FS_CLUSTER_MASK(fs); fillable = min(range_len + cluster_fill, max_extent_len); - err = ext2fs_new_range(fs, 0, pblk & ~EXT2FS_CLUSTER_MASK(fs), + err = ext2fs_new_range(fs, new_range_flags, pblk & ~EXT2FS_CLUSTER_MASK(fs), fillable, NULL, &pblk, &plen); if (err) @@ -681,6 +687,16 @@ static errcode_t extent_fallocate(ext2_filsys fs, int flags, ext2_ino_t ino, if (err) return err; + /* + * For fixed goal allocations, let the allocations fail iff we can't + * find the exact goal extent. + */ + if (flags & EXT2_FALLOCATE_FIXED_GOAL) { + err = ext_falloc_helper(fs, flags, ino, inode, handle, NULL, + NULL, start, len, goal); + goto errout; + } + /* * Find the extent closest to the start of the alloc range. We don't * check the return value because _goto() sets the current node to the @@ -796,6 +812,7 @@ errout: * - EXT2_FALLOCATE_FORCE_INIT: Create only initialized extents. * - EXT2_FALLOCATE_FORCE_UNINIT: Create only uninitialized extents. * - EXT2_FALLOCATE_INIT_BEYOND_EOF: Create extents beyond EOF. + * - EXT2_FALLOCATE_FIXED_GOAL: Ensure range starts at goal. * * If neither FORCE_INIT nor FORCE_UNINIT are specified, this function will * try to expand any extents it finds, zeroing blocks as necessary.