Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2430619rwb; Sun, 6 Aug 2023 18:36:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG32ZINR3/HmwMKS/T61bF9dYQjLGZKxEsvbHgUR6v+v4p/99SiLvdtz4uu0CYiG1TZbsEn X-Received: by 2002:a17:906:518a:b0:98e:933:28fe with SMTP id y10-20020a170906518a00b0098e093328femr6140385ejk.66.1691372207867; Sun, 06 Aug 2023 18:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691372207; cv=none; d=google.com; s=arc-20160816; b=IqUZE1rrg8NVj3rtU07OuOb2ACc9Q024ZDuhIJyEU8Q1Gus9Lk/E4l93A68I9k8LST 0EKF7seCmA9nGG+xxTMguhrMAh4zeSuaVRM7YHPia0XTfUPBfl5CzYZ6g9gSalz7n22l s6+Xyc7Gp+L70wA8jeYz0boqi2GsQQQDBMOFDemfwI8gnlZCchRBSJZZ+7vEm/lXLYeH 2XVYcoAyy3jqdPmnqS7sTnA/5/8oeJjsBb/iMPPVYvQikEQrIznfZRdKGqHsSAEji4N7 tDtxOCHIBz3g5EU3Mn0wpd85FzuQBEQylHLDDAVP831s2w0T2LkDdQdzRMg62+ER3Fdd HvtQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=fTU1GDTT6JTWuajDRM7B273o8a1B91B56Q8gGUC8/Hg=; fh=iXXXhyfgcN+SetIsgN7mqbwwXAiTSEAIqPgtJExShGE=; b=u42G0NLW+sATmX0TOZ22ZyZt8RUAS1RD3WGztuNpriabVn9DPXcTAl0APD4KU50zOg lMPJwOle9i8wG+mTzRgt5R+Ww3gYbjaSdzwnWNVYDRzMhJCPCr4YdyM/xwdK3Mj1/gC2 he5yI17lhIAyai/dI6lfFMLUpAzfL/8mkRE2242eo8K+jaN5dp52X//qwX8pZjVUt/C/ 40L7wQLX43C8//1z7aVJwQVbz9PPYhk6nQwtG1fqwPcya4GQC9Crrx/4DQM74PSIGngi iuPpU+TrUgVd6y6LjTJAHltwMKsUGfYmw0NPfNLBx2RAlBviObg1D1TA7jGd8p9raw8s 0kiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=rTKuVWFu; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pj25-20020a170906d79900b00992169858f2si5448526ejb.3.2023.08.06.18.36.10; Sun, 06 Aug 2023 18:36:47 -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=@gmail.com header.s=20221208 header.b=rTKuVWFu; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbjHGB1H (ORCPT + 99 others); Sun, 6 Aug 2023 21:27:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjHGB1G (ORCPT ); Sun, 6 Aug 2023 21:27:06 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A63C5E6A; Sun, 6 Aug 2023 18:27:04 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fe4cdb724cso20578795e9.1; Sun, 06 Aug 2023 18:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691371623; x=1691976423; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fTU1GDTT6JTWuajDRM7B273o8a1B91B56Q8gGUC8/Hg=; b=rTKuVWFu5oheb7WuRc/V69yjK5woup6O82sH57tIutxy8fAsq+WPyoGhtAbAxc5f+E 5rLiLX8g97yeZgpPIqfVxI3uc9aJMlMu1xrKS7yXlEJoUMF0Bpp9S0olEY9a9aEZsQKW 5IX/xVWaTpthIJqiDqkptfrYY36/pyIco9pw/0EuLsOLqzu7KiSqdqgGwwig3ZnaGZEv I4ktwDNQLO5SD3wic6gq0IU40DxA7VD1uHe8aI1QSOONMyvyUbh6gFhROVOAjzkZZNVh fmEEcbIFGsud19/KMpeX4MnkBykvkDxKQMsXYFHQMqC2i8mNOdNkw4KJkTVgdNP32gkv /XkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691371623; x=1691976423; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fTU1GDTT6JTWuajDRM7B273o8a1B91B56Q8gGUC8/Hg=; b=knX+dP8xpg7gE64WJ2wYaBBiO8w/tM76Tqhd5LbZkErJMm6nYShZ5Tfbk5afW7cRUX UTMBBakAn/9YJ0ItqK5sBV7RL1OI9LjTSOi0FhXj8ttvkg3Jv24lmC/QwdeP1sCb2uIP gyzx7x675Q6PqzJFCBhJuE6eEotECxr/WIcdW63nej3oGglVaWi9ssaw3m8jbNHV5YHZ YPIPHZKlE3bxAGhJyiWwClhfVhClWVtcL7rEaIu0UdNVOEWWEO+Hj8Kn9RCj8PcPCb/5 R7O5aXuc2vn0BXvmfQZxXtr7Ibna6Dlg8/V78AmHOXX0DdmYImhNP+Nr/3RU6Oqx7vPt s20g== X-Gm-Message-State: AOJu0YyWfs89WR7SXxLbJQ4dHQbcTjKxIL+m3pZuYo8fHQFp56jbuSnl 4k8riw9LxIixDFy9npF9kxs= X-Received: by 2002:a05:600c:2159:b0:3fe:1967:447c with SMTP id v25-20020a05600c215900b003fe1967447cmr6290213wml.9.1691371622860; Sun, 06 Aug 2023 18:27:02 -0700 (PDT) Received: from localhost.localdomain ([2a05:f480:1000:b09:5400:4ff:fe6f:7099]) by smtp.gmail.com with ESMTPSA id 21-20020a05600c231500b003fe21c7386esm13393485wmo.45.2023.08.06.18.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Aug 2023 18:27:02 -0700 (PDT) From: zhangshida X-Google-Original-From: zhangshida To: tytso@mit.edu, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn, starzhangzsd@gmail.com, Andreas Dilger Subject: [PATCH] ext4: Modify the rec_len helpers to accommodate future cases Date: Mon, 7 Aug 2023 09:26:54 +0800 Message-Id: <20230807012654.55951-1-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,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: Shida Zhang Following Andreas' suggestion, it is time to adapt these helpers to handle larger records during runtime, especially in preparation for the eventual support of ext4 with a block size greater than PAGE_SIZE. Suggested-by: Andreas Dilger Signed-off-by: Shida Zhang Link: https://lore.kernel.org/lkml/A9ECDF14-95A1-4B1E-A815-4B6ABF4916C6@dilger.ca/ --- fs/ext4/ext4.h | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 0a2d55faa095..87cdf4d56da1 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2386,39 +2386,41 @@ static inline unsigned int ext4_dir_rec_len(__u8 name_len, } /* - * If we ever get support for fs block sizes > page_size, we'll need - * to remove the #if statements in the next two functions... + * The next two helpers facilitate the conversion between the encoded + * and plain forms of rec_len. Try to access rec_len through these helpers + * rather than accessing it directly. */ -static inline unsigned int -ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize) +static inline +unsigned int ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize) { unsigned len = le16_to_cpu(dlen); -#if (PAGE_SIZE >= 65536) + if (blocksize < 65536) + return len; + if (len == EXT4_MAX_REC_LEN || len == 0) return blocksize; + return (len & 65532) | ((len & 3) << 16); -#else - return len; -#endif } static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize) { - BUG_ON((len > blocksize) || (blocksize > (1 << 18)) || (len & 3)); -#if (PAGE_SIZE >= 65536) - if (len < 65536) + BUG_ON(len > blocksize); + BUG_ON(blocksize > (1 << 18)); + BUG_ON(len & 3); + + if (len < 65536) /* always true for blocksize < 65536 */ return cpu_to_le16(len); + if (len == blocksize) { if (blocksize == 65536) return cpu_to_le16(EXT4_MAX_REC_LEN); - else - return cpu_to_le16(0); + + return cpu_to_le16(0); } + return cpu_to_le16((len & 65532) | ((len >> 16) & 3)); -#else - return cpu_to_le16(len); -#endif } /* -- 2.27.0