Message ID | 20221111100830.953733-1-shengyong@oppo.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp655927wru; Fri, 11 Nov 2022 02:18:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf5xxPvVAoP2IQ/7s1YNOyzdfEHJbLzLBR7mlI3VIa9LUavbPJLMpDLQLYeF3r3DBU0rnr18 X-Received: by 2002:a50:ff04:0:b0:462:709:9f7b with SMTP id a4-20020a50ff04000000b0046207099f7bmr891583edu.263.1668161881245; Fri, 11 Nov 2022 02:18:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668161881; cv=pass; d=google.com; s=arc-20160816; b=QqFGeUHOa5NCaYCBTrqZ9ly+N/jyBhlaQxpEgl8KY0lP6B08WksUuoeP6s20vnE5sU AgWiBdwvRGTsjn19ejDaD3dpKVSQVeAHIdjq8F/hVe7xdD9f7wltR33aIHc28xnt0zej YZVNmoa9QmJoEs1xEWiWVLOchka/HF0AFRi27hVGkY8D7TxAlgv9EVbG/qOWIgS9Lcs3 0e/d6hlDhsVgOcpLKmg4AfJ5HOd4qC/3vmmEG42/O9pb6ViRxFX0e7/7LzSvJVGl25as o0lxcM/82STCQNsULyWChyxB4rj939we8mjo+7lZhXKDVKtfKKL1cQtDaBdRyoODpiUh Knjg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=ffos0/zYHGurDgmO9NUd5jUgkWs+Vhq7VDzZxBNU4Vk=; b=aqfZ5wfGpYkzIhu5Fs992Tr95x+DzJH9ZhIS+Gu86Tx2M/SEaL6dxFNeffWoK/RsBT KybTYBoKCjjqpusGmFg7tKRyrsRZhpSIfq35BxknacsjpzJSEyVuwK07a8UAnAuhv3VY rWtecoau92SVcAbycBwRMkxF5d08f4kVjEjPjtLVBNQbmqAQHm+1GG1+yPkbd3gEq16C l9uuuKocKHuCiWc6oqMEnXqhVHmTnP3udJtTUt5kaCVpPdbVnHBArI7ng7VuQlJ6qX9M W254bb3iAhC7SO/cZ1iFIDwN7itwCgutB6Duq+mtpjc0NvMcj5QdtPusovduenRZUyRH XHfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oppo.com header.s=selector1 header.b=QpTkgwn6; arc=pass (i=1 spf=pass spfdomain=oppo.com dkim=pass dkdomain=oppo.com dmarc=pass fromdomain=oppo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oppo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a50c389000000b00461c314f79fsi1758835edf.284.2022.11.11.02.17.37; Fri, 11 Nov 2022 02:18:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@oppo.com header.s=selector1 header.b=QpTkgwn6; arc=pass (i=1 spf=pass spfdomain=oppo.com dkim=pass dkdomain=oppo.com dmarc=pass fromdomain=oppo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oppo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232803AbiKKKJQ (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Fri, 11 Nov 2022 05:09:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233552AbiKKKJI (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 11 Nov 2022 05:09:08 -0500 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2077.outbound.protection.outlook.com [40.107.215.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A15E7BE44 for <linux-kernel@vger.kernel.org>; Fri, 11 Nov 2022 02:08:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EbyGjDTc8yR5Od+5oekXdBQ+Bx7CJ4ud0gc5B8pSD0UPpOOhHl/F+nXkHROOSXJGGfbSn+8d+U7xDXZGNKjtLAoy7nE/arUI30CWToz4BDhLhqzXRhhjrUXpnkQuHbIKHiofJpGYdJC7AVXQ5vVDHX/STxHykqNXpeaifQyMmq2hPZMWMpychGXJDiO1+06W/DfpU8Ana1c3Q0dGF9+zUlz713ePIlrGBgS/8AywI6Ge/ve7HcliYj9lN1vcwCdAhCJUJMO+AaCfaIcdQkvHy6UUuI2V45yLpjQaV26N0waciAy4EHqPWgkpMX7oF44F/M+3wkTqyavghyT4QjcP6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ffos0/zYHGurDgmO9NUd5jUgkWs+Vhq7VDzZxBNU4Vk=; b=JoCcTg7AtTkKXYCH4kjj5/YkDNZtubmH0DbZgIb7SUV4m7/Uir6EF42+euizYQ5moYsvzAw3oRfKberQWjOgtM5Z34OXukYvFW8+Soz/PAmZDRd1kWY3wUnznI/bVVCboSkR6coyXoZR2UNf6To9GQ12LCQKeoMMNriClX6DYLO9wUN1DQlcDpsZ/vaPHu1suUFAtRSEN3VAppW0/HJhiUDku4bHjJ+mGa2vG0Hz8aG/RLIfoO99hgd9SqVpRhSe0fvJ4RgfKXCeduEbH4ADZ9fHqFYDCiR1llUzlM8HnPOLT77y69fmKGiBXFrZeF7STTFVGnG7Let6AczhVFWLGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ffos0/zYHGurDgmO9NUd5jUgkWs+Vhq7VDzZxBNU4Vk=; b=QpTkgwn6rI5p9Xj4rRAj6N3sd4KVCp6hTNNy6SA+JwzA5SyCI5xmsYWyVGMHKGNZMEImzbFyu77A3duQCJmBPuwjNE8iZLUSLApmKrsZSqj7S0+fPucVVvEWkKC6XDcNn2qUmrQKF2JNtKKkqYCHaYoZXKZuTnqccfntRHvN/4g= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SI2PR02MB5148.apcprd02.prod.outlook.com (2603:1096:4:153::6) by SG2PR02MB5901.apcprd02.prod.outlook.com (2603:1096:4:1d2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27; Fri, 11 Nov 2022 10:08:56 +0000 Received: from SI2PR02MB5148.apcprd02.prod.outlook.com ([fe80::2954:8e56:dcd1:452c]) by SI2PR02MB5148.apcprd02.prod.outlook.com ([fe80::2954:8e56:dcd1:452c%3]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 10:08:56 +0000 From: Sheng Yong <shengyong@oppo.com> To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Sheng Yong <shengyong@oppo.com> Subject: [PATCH v2 1/2] f2fs: fix to enable compress for newly created file if extension matches Date: Fri, 11 Nov 2022 18:08:29 +0800 Message-Id: <20221111100830.953733-1-shengyong@oppo.com> X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To SI2PR02MB5148.apcprd02.prod.outlook.com (2603:1096:4:153::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SI2PR02MB5148:EE_|SG2PR02MB5901:EE_ X-MS-Office365-Filtering-Correlation-Id: c80cbf0b-b008-44ed-b9b1-08dac3ccbeb2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vLma93glbT3V4aUZYG+Yqurs9nk3DvwvbIkXP3CSLtbRFCDql6u8M0lycGb2NZQgczVWnvWXhislAz3jbg7UEaUqxsM8DvcFryMYgl1itqDUSwSn8CIho64eH2ZvRBs4HYlFYlIkXV+TiX6T7JGhNCOqrhoyvv69EANkVPE+61Db4nv5D6wAb6ziaJKdHL67R2IKqvIJm07jGaXISd36XRvyKSCFb/3nLTwn0I0ISERdT67Gt0WVGoP6NwBIp+yQbf9IWR4dNVdAzQR41HjXtsKGQ1bbEuV2CL7mrPPzZoHBHhAl/xuJplEcTMQqLSMv8ht0ckIpghzEWhskRMAv1so7Sq2JOweX+sBaq7gaceX8Pb+Uxe9sYNg67kA4ssq+jqxrmUuQubXRF8QCfDo1AugKRhBgfJD74a8bAWj07NkxD+gg2H3FsCSeguS1TS7jJqYNsT6rZzNsrQC3xm1gkqluOpwgnfJct+P0Nwed8hEFo7SpiVldfunSY4hrTAM+FZjBbLpV5qNiJs5ax9wGCwUPE8HXCKQdS/lAuryOMH139QkcHaPHZYSGFF+3FxPX9RtpNY/81FTehBSz47kBNAxLDoh/RXjmItHJZo4a8gX5/upvp9gOG+AQku51XeZ5tyVHfhmj4PYGdICW1l3YTtlBn4dFbdJHcW8FEI+UFMX2wf5P0j61Kga8jO9A6RQc2LydtoXguD3nTPiyHhVQVkHizyjGEaYGlpCUZxpsSy4ykz+jam40EIWGNq13jUQI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SI2PR02MB5148.apcprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(376002)(366004)(346002)(136003)(396003)(451199015)(36756003)(38350700002)(6512007)(83380400001)(86362001)(478600001)(6486002)(186003)(2906002)(38100700002)(1076003)(52116002)(26005)(6506007)(8936002)(4326008)(107886003)(66946007)(5660300002)(6666004)(316002)(66556008)(41300700001)(2616005)(66476007)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TNr7BtdM/EkOZlm+N5Ydf9/pMz1F7G4zXHmDLmnsTL4SjTcvsrTyUMUD/MUWQi7+oh1N9EL/XfyteglnJX1ucYBO6rjK1lIOJjkl4ct3UkOObYiFu6qMQeu4hm2RCDj9jd7aTPiW1JeRIO8ZO3pAqHpWjxf5/jqQDpOOBoGoG+5z1o1plPd+ILhRc7T+NzIEwh1zKQHDn3Wxx3XY43JaMN3+9oG7cPpfw6HNFfklyaWc4i3eMh8Rlqvp8M47A2tpnshZtF7rvKNpwpKsCAh7vkSMuO0vo+ztLKjGTHxQW0m6xb4hOy2rwddYLlglbTNveY5rvQEyb8T5roBxpX2cXVM+bMUb1UtOUIhaUn44HbYciIh7bDqxIG96Dnv9vGYQ1MV/1SXiQrg0XXF14IgmHy4x29WMJgSCMJvGEbfTR5/jvMHwbIpQALT4sY0+4jYnhVzdonwy3XH61rddwGMXpylmu0TU5ReNAIJ0HuYf+GVIqUF++uEXoREnIfFGk2AMdC57xS7OymkuymXa2fn9JMDM9DNxeadG1YD4WeRmk1FH/atmY/30drSRaVYMCt+Vf+gAab8QHlKr47OSCGiVL3NuvYBIDvl4a2/eRObGXGJisKpLHlpZgPDcmkr8qNjdi3FnMo8lMo0OFJ/X1Ip+PcDAMFJ2c75hJkjBUVHxANlRvwJfPGeIKxEPGzTFbD1FTlO0ju65lJ7Nt3hltdPfJAGz0Ix65emwsNp6jHdnX+i4hSf9Z71A/a5TZUiNb+JqcNnYZqDGDVYIjkDQ4hO2TKxcAxRAWuqnYc02cvrecHLU2/E0VsAy1CH04ANobkcet109jqaZF1VTOJgNeOAeC00hPAb3AM91+WEBRvhWb6VKHZTIWz+wlKV/ZpS6aL+Ip5UU46QE5tmTcuiZFOrA9v4wgpZTplNSpwhbbke+cLtOSafNXXEcAuw4kTkHrQ4FDFDs9bNwi2stJn5AIWQUuBhgt9QhSStiw8fVyE0WSpPyuagxEQIDTi1+xzUdcdh8qZLNg8PeTGxkxl36Eh/SoJfyRTBhczGBYiCq2z/26nA96ICphgb0onxwxHDJU1PSktbi22yvuKbiLrtxH/aqVH6YwViMG0P8NK0jIoFvad/rpDo1PLQoWZfGP/5RpeIJOQTgvcv7kbIEAhPi9w1WDh1EXotLpWNI3W3bQcTrRZuxITRZlQ0QEmqsU92RqcdonU9bbWAWrpae/HxW8LrKutyj6xq5o52nh2V5yTBIQbTgdqMsxfP80gYf1FAVGUCQiibxT5Q1KQEQAH3msA1301iGLZw49kj82RcU/MDZAkB9yCFRLTbeGjnTOK0MBCGQ+uuckTi7ozLO68nE5MEQXN5iO6Rbn2V3MGvnjAYsiYwQ0NmkLQl6bksjqvGFFa1XCR+ClV868Z5iNmzm0tCzx0JDQssGfvNniamiD46YxTNd20zEE0+YEvQOHww8EZxlQyKovF5bHQpWjVITfrWX6t5FzD2sSHS1ztrMhP4uhJt2+93x+qRX1iJJlLZjbqTS40pUny72JHfHjXngFeWdaqnrQZkGl5xgrmkEok0JqnaiD3III5y7M8o91iYtnZeg X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c80cbf0b-b008-44ed-b9b1-08dac3ccbeb2 X-MS-Exchange-CrossTenant-AuthSource: SI2PR02MB5148.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 10:08:56.8662 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0D3k/01lkudxfA06Q2b1iVRBhDNSO4rL7dY7stqHBk2NV2+x6ikthZMoNdrin+Y2/agVgpOWJSh4Ie9HhhZi/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR02MB5901 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749194512625242599?= X-GMAIL-MSGID: =?utf-8?q?1749194512625242599?= |
Series |
[v2,1/2] f2fs: fix to enable compress for newly created file if extension matches
|
|
Commit Message
Sheng Yong
Nov. 11, 2022, 10:08 a.m. UTC
If compress_extension is set, and a newly created file matches the
extension, the file could be marked as compression file. However,
if inline_data is also enabled, there is no chance to check its
extension since f2fs_should_compress() always returns false.
This patch moves set_compress_inode(), which do extension check, in
f2fs_should_compress() to check extensions before setting inline
data flag.
Fixes: 7165841d578e ("f2fs: fix to check inline_data during compressed inode conversion")
Signed-off-by: Sheng Yong <shengyong@oppo.com>
---
fs/f2fs/namei.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
---
v1->v2: add filename parameter for f2fs_new_inode, and move
set_compress_inode into f2fs_new_inode
Comments
On 2022/11/11 18:08, Sheng Yong wrote: > If compress_extension is set, and a newly created file matches the > extension, the file could be marked as compression file. However, > if inline_data is also enabled, there is no chance to check its > extension since f2fs_should_compress() always returns false. > > This patch moves set_compress_inode(), which do extension check, in > f2fs_should_compress() to check extensions before setting inline > data flag. > > Fixes: 7165841d578e ("f2fs: fix to check inline_data during compressed inode conversion") > Signed-off-by: Sheng Yong <shengyong@oppo.com> Reviewed-by: Chao Yu <chao@kernel.org> Thanks,
Does thes make sense? https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/commit/?h=dev-test&id=608460dfae20b9d23aa222f7448710a086778222 https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/commit/?h=dev-test&id=962379487b5cb9f3b85ea367b130c2c6ca584edf Second one is needed to address build error. On 11/11, Sheng Yong wrote: > If compress_extension is set, and a newly created file matches the > extension, the file could be marked as compression file. However, > if inline_data is also enabled, there is no chance to check its > extension since f2fs_should_compress() always returns false. > > This patch moves set_compress_inode(), which do extension check, in > f2fs_should_compress() to check extensions before setting inline > data flag. > > Fixes: 7165841d578e ("f2fs: fix to check inline_data during compressed inode conversion") > Signed-off-by: Sheng Yong <shengyong@oppo.com> > --- > fs/f2fs/namei.c | 27 +++++++++++++-------------- > 1 file changed, 13 insertions(+), 14 deletions(-) > > --- > v1->v2: add filename parameter for f2fs_new_inode, and move > set_compress_inode into f2fs_new_inode > > diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c > index e104409c3a0e5..36e251f438568 100644 > --- a/fs/f2fs/namei.c > +++ b/fs/f2fs/namei.c > @@ -22,8 +22,12 @@ > #include "acl.h" > #include <trace/events/f2fs.h> > > +static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, > + const unsigned char *name); > + > static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, > - struct inode *dir, umode_t mode) > + struct inode *dir, umode_t mode, > + const char *name) > { > struct f2fs_sb_info *sbi = F2FS_I_SB(dir); > nid_t ino; > @@ -119,6 +123,8 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, > if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) && > f2fs_may_compress(inode)) > set_compress_context(inode); > + if (name) > + set_compress_inode(sbi, inode, name); > } > > /* Should enable inline_data after compression set */ > @@ -293,8 +299,7 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, > unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; > int i, cold_count, hot_count; > > - if (!f2fs_sb_has_compression(sbi) || > - F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || > + if (F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || > !f2fs_may_compress(inode) || > (!ext_cnt && !noext_cnt)) > return; > @@ -326,10 +331,6 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, > for (i = 0; i < ext_cnt; i++) { > if (!is_extension_exist(name, ext[i], false)) > continue; > - > - /* Do not use inline_data with compression */ > - stat_dec_inline_inode(inode); > - clear_inode_flag(inode, FI_INLINE_DATA); > set_compress_context(inode); > return; > } > @@ -352,15 +353,13 @@ static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, mode); > + inode = f2fs_new_inode(mnt_userns, dir, mode, dentry->d_name.name); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) > set_file_temperature(sbi, inode, dentry->d_name.name); > > - set_compress_inode(sbi, inode, dentry->d_name.name); > - > inode->i_op = &f2fs_file_inode_operations; > inode->i_fop = &f2fs_file_operations; > inode->i_mapping->a_ops = &f2fs_dblock_aops; > @@ -689,7 +688,7 @@ static int f2fs_symlink(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO); > + inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > @@ -760,7 +759,7 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode); > + inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > @@ -817,7 +816,7 @@ static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, mode); > + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > @@ -856,7 +855,7 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, mode); > + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > -- > 2.25.1
On 2022/11/12 9:27, Jaegeuk Kim wrote: > Does thes make sense? > > https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/commit/?h=dev-test&id=608460dfae20b9d23aa222f7448710a086778222 > https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/commit/?h=dev-test&id=962379487b5cb9f3b85ea367b130c2c6ca584edf > Hi, Jaegeuk, Absolutely. Thanks for addressing it. > Second one is needed to address build error. Sorry for missing adding a hunk of that patch :( The above 2 commits are already tested, shall I resend a new patchset? thanks, shengyong > > On 11/11, Sheng Yong wrote: >> If compress_extension is set, and a newly created file matches the >> extension, the file could be marked as compression file. However, >> if inline_data is also enabled, there is no chance to check its >> extension since f2fs_should_compress() always returns false. >> >> This patch moves set_compress_inode(), which do extension check, in >> f2fs_should_compress() to check extensions before setting inline >> data flag. >> >> Fixes: 7165841d578e ("f2fs: fix to check inline_data during compressed inode conversion") >> Signed-off-by: Sheng Yong <shengyong@oppo.com> >> --- >> fs/f2fs/namei.c | 27 +++++++++++++-------------- >> 1 file changed, 13 insertions(+), 14 deletions(-) >> >> --- >> v1->v2: add filename parameter for f2fs_new_inode, and move >> set_compress_inode into f2fs_new_inode >> >> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c >> index e104409c3a0e5..36e251f438568 100644 >> --- a/fs/f2fs/namei.c >> +++ b/fs/f2fs/namei.c >> @@ -22,8 +22,12 @@ >> #include "acl.h" >> #include <trace/events/f2fs.h> >> >> +static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, >> + const unsigned char *name); >> + >> static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, >> - struct inode *dir, umode_t mode) >> + struct inode *dir, umode_t mode, >> + const char *name) >> { >> struct f2fs_sb_info *sbi = F2FS_I_SB(dir); >> nid_t ino; >> @@ -119,6 +123,8 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, >> if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) && >> f2fs_may_compress(inode)) >> set_compress_context(inode); >> + if (name) >> + set_compress_inode(sbi, inode, name); >> } >> >> /* Should enable inline_data after compression set */ >> @@ -293,8 +299,7 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, >> unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; >> int i, cold_count, hot_count; >> >> - if (!f2fs_sb_has_compression(sbi) || >> - F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || >> + if (F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || >> !f2fs_may_compress(inode) || >> (!ext_cnt && !noext_cnt)) >> return; >> @@ -326,10 +331,6 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, >> for (i = 0; i < ext_cnt; i++) { >> if (!is_extension_exist(name, ext[i], false)) >> continue; >> - >> - /* Do not use inline_data with compression */ >> - stat_dec_inline_inode(inode); >> - clear_inode_flag(inode, FI_INLINE_DATA); >> set_compress_context(inode); >> return; >> } >> @@ -352,15 +353,13 @@ static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, mode); >> + inode = f2fs_new_inode(mnt_userns, dir, mode, dentry->d_name.name); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) >> set_file_temperature(sbi, inode, dentry->d_name.name); >> >> - set_compress_inode(sbi, inode, dentry->d_name.name); >> - >> inode->i_op = &f2fs_file_inode_operations; >> inode->i_fop = &f2fs_file_operations; >> inode->i_mapping->a_ops = &f2fs_dblock_aops; >> @@ -689,7 +688,7 @@ static int f2fs_symlink(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO); >> + inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> @@ -760,7 +759,7 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode); >> + inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> @@ -817,7 +816,7 @@ static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, mode); >> + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> @@ -856,7 +855,7 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, mode); >> + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> -- >> 2.25.1
On 2022/11/12 9:27, Jaegeuk Kim wrote: > Does thes make sense? Jaegeuk, Could you please send modified patches to mailing list, otherwise, I can not add comments on specified line. Thanks, > > https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/commit/?h=dev-test&id=608460dfae20b9d23aa222f7448710a086778222 > https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/commit/?h=dev-test&id=962379487b5cb9f3b85ea367b130c2c6ca584edf > > Second one is needed to address build error. > > On 11/11, Sheng Yong wrote: >> If compress_extension is set, and a newly created file matches the >> extension, the file could be marked as compression file. However, >> if inline_data is also enabled, there is no chance to check its >> extension since f2fs_should_compress() always returns false. >> >> This patch moves set_compress_inode(), which do extension check, in >> f2fs_should_compress() to check extensions before setting inline >> data flag. >> >> Fixes: 7165841d578e ("f2fs: fix to check inline_data during compressed inode conversion") >> Signed-off-by: Sheng Yong <shengyong@oppo.com> >> --- >> fs/f2fs/namei.c | 27 +++++++++++++-------------- >> 1 file changed, 13 insertions(+), 14 deletions(-) >> >> --- >> v1->v2: add filename parameter for f2fs_new_inode, and move >> set_compress_inode into f2fs_new_inode >> >> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c >> index e104409c3a0e5..36e251f438568 100644 >> --- a/fs/f2fs/namei.c >> +++ b/fs/f2fs/namei.c >> @@ -22,8 +22,12 @@ >> #include "acl.h" >> #include <trace/events/f2fs.h> >> >> +static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, >> + const unsigned char *name); >> + >> static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, >> - struct inode *dir, umode_t mode) >> + struct inode *dir, umode_t mode, >> + const char *name) >> { >> struct f2fs_sb_info *sbi = F2FS_I_SB(dir); >> nid_t ino; >> @@ -119,6 +123,8 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, >> if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) && >> f2fs_may_compress(inode)) >> set_compress_context(inode); >> + if (name) >> + set_compress_inode(sbi, inode, name); >> } >> >> /* Should enable inline_data after compression set */ >> @@ -293,8 +299,7 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, >> unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; >> int i, cold_count, hot_count; >> >> - if (!f2fs_sb_has_compression(sbi) || >> - F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || >> + if (F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || >> !f2fs_may_compress(inode) || >> (!ext_cnt && !noext_cnt)) >> return; >> @@ -326,10 +331,6 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, >> for (i = 0; i < ext_cnt; i++) { >> if (!is_extension_exist(name, ext[i], false)) >> continue; >> - >> - /* Do not use inline_data with compression */ >> - stat_dec_inline_inode(inode); >> - clear_inode_flag(inode, FI_INLINE_DATA); >> set_compress_context(inode); >> return; >> } >> @@ -352,15 +353,13 @@ static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, mode); >> + inode = f2fs_new_inode(mnt_userns, dir, mode, dentry->d_name.name); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) >> set_file_temperature(sbi, inode, dentry->d_name.name); >> >> - set_compress_inode(sbi, inode, dentry->d_name.name); >> - >> inode->i_op = &f2fs_file_inode_operations; >> inode->i_fop = &f2fs_file_operations; >> inode->i_mapping->a_ops = &f2fs_dblock_aops; >> @@ -689,7 +688,7 @@ static int f2fs_symlink(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO); >> + inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> @@ -760,7 +759,7 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode); >> + inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> @@ -817,7 +816,7 @@ static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, mode); >> + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> @@ -856,7 +855,7 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, mode); >> + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> -- >> 2.25.1
If compress_extension is set, and a newly created file matches the extension, the file could be marked as compression file. However, if inline_data is also enabled, there is no chance to check its extension since f2fs_should_compress() always returns false. This patch moves set_compress_inode(), which do extension check, in f2fs_should_compress() to check extensions before setting inline data flag. Fixes: 7165841d578e ("f2fs: fix to check inline_data during compressed inode conversion") Signed-off-by: Sheng Yong <shengyong@oppo.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> --- fs/f2fs/namei.c | 326 ++++++++++++++++++++++++------------------------ 1 file changed, 160 insertions(+), 166 deletions(-) diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index e104409c3a0e..43b721d8e491 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -22,8 +22,160 @@ #include "acl.h" #include <trace/events/f2fs.h> +static inline int is_extension_exist(const unsigned char *s, const char *sub, + bool tmp_ext) +{ + size_t slen = strlen(s); + size_t sublen = strlen(sub); + int i; + + if (sublen == 1 && *sub == '*') + return 1; + + /* + * filename format of multimedia file should be defined as: + * "filename + '.' + extension + (optional: '.' + temp extension)". + */ + if (slen < sublen + 2) + return 0; + + if (!tmp_ext) { + /* file has no temp extension */ + if (s[slen - sublen - 1] != '.') + return 0; + return !strncasecmp(s + slen - sublen, sub, sublen); + } + + for (i = 1; i < slen - sublen; i++) { + if (s[i] != '.') + continue; + if (!strncasecmp(s + i + 1, sub, sublen)) + return 1; + } + + return 0; +} + +int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, + bool hot, bool set) +{ + __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; + int cold_count = le32_to_cpu(sbi->raw_super->extension_count); + int hot_count = sbi->raw_super->hot_ext_count; + int total_count = cold_count + hot_count; + int start, count; + int i; + + if (set) { + if (total_count == F2FS_MAX_EXTENSION) + return -EINVAL; + } else { + if (!hot && !cold_count) + return -EINVAL; + if (hot && !hot_count) + return -EINVAL; + } + + if (hot) { + start = cold_count; + count = total_count; + } else { + start = 0; + count = cold_count; + } + + for (i = start; i < count; i++) { + if (strcmp(name, extlist[i])) + continue; + + if (set) + return -EINVAL; + + memcpy(extlist[i], extlist[i + 1], + F2FS_EXTENSION_LEN * (total_count - i - 1)); + memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN); + if (hot) + sbi->raw_super->hot_ext_count = hot_count - 1; + else + sbi->raw_super->extension_count = + cpu_to_le32(cold_count - 1); + return 0; + } + + if (!set) + return -EINVAL; + + if (hot) { + memcpy(extlist[count], name, strlen(name)); + sbi->raw_super->hot_ext_count = hot_count + 1; + } else { + char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN]; + + memcpy(buf, &extlist[cold_count], + F2FS_EXTENSION_LEN * hot_count); + memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN); + memcpy(extlist[cold_count], name, strlen(name)); + memcpy(&extlist[cold_count + 1], buf, + F2FS_EXTENSION_LEN * hot_count); + sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1); + } + return 0; +} + +static void set_compress_new_inode(struct f2fs_sb_info *sbi, struct inode *dir, + struct inode *inode, const unsigned char *name) +{ + __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; + unsigned char (*noext)[F2FS_EXTENSION_LEN] = + F2FS_OPTION(sbi).noextensions; + unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions; + unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; + unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; + int i, cold_count, hot_count; + + if (!f2fs_sb_has_compression(sbi) || !name) + return; + if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) + return; + + /* Inherit the compression flag in directory */ + if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL)) { + set_compress_context(inode); + return; + } + + /* Start to check extension list */ + if (!ext_cnt) + return; + + /* Don't compress hot files. */ + f2fs_down_read(&sbi->sb_lock); + cold_count = le32_to_cpu(sbi->raw_super->extension_count); + hot_count = sbi->raw_super->hot_ext_count; + for (i = cold_count; i < cold_count + hot_count; i++) + if (is_extension_exist(name, extlist[i], false)) + break; + f2fs_up_read(&sbi->sb_lock); + if (i < (cold_count + hot_count)) + return; + + /* Don't compress unallowed extension. */ + for (i = 0; i < noext_cnt; i++) + if (is_extension_exist(name, noext[i], false)) + return; + + /* Compress wanting extension. */ + for (i = 0; i < ext_cnt; i++) { + if (is_extension_exist(name, ext[i], false)) { + set_compress_context(inode); + return; + } + } +} + static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, - struct inode *dir, umode_t mode) + struct inode *dir, umode_t mode, + const char *name) { struct f2fs_sb_info *sbi = F2FS_I_SB(dir); nid_t ino; @@ -114,12 +266,8 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, if (F2FS_I(inode)->i_flags & F2FS_PROJINHERIT_FL) set_inode_flag(inode, FI_PROJ_INHERIT); - if (f2fs_sb_has_compression(sbi)) { - /* Inherit the compression flag in directory */ - if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) && - f2fs_may_compress(inode)) - set_compress_context(inode); - } + /* Check compression first. */ + set_compress_new_inode(sbi, dir, inode, name); /* Should enable inline_data after compression set */ if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode)) @@ -153,40 +301,6 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, return ERR_PTR(err); } -static inline int is_extension_exist(const unsigned char *s, const char *sub, - bool tmp_ext) -{ - size_t slen = strlen(s); - size_t sublen = strlen(sub); - int i; - - if (sublen == 1 && *sub == '*') - return 1; - - /* - * filename format of multimedia file should be defined as: - * "filename + '.' + extension + (optional: '.' + temp extension)". - */ - if (slen < sublen + 2) - return 0; - - if (!tmp_ext) { - /* file has no temp extension */ - if (s[slen - sublen - 1] != '.') - return 0; - return !strncasecmp(s + slen - sublen, sub, sublen); - } - - for (i = 1; i < slen - sublen; i++) { - if (s[i] != '.') - continue; - if (!strncasecmp(s + i + 1, sub, sublen)) - return 1; - } - - return 0; -} - /* * Set file's temperature for hot/cold data separation */ @@ -217,124 +331,6 @@ static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode * file_set_hot(inode); } -int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, - bool hot, bool set) -{ - __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; - int cold_count = le32_to_cpu(sbi->raw_super->extension_count); - int hot_count = sbi->raw_super->hot_ext_count; - int total_count = cold_count + hot_count; - int start, count; - int i; - - if (set) { - if (total_count == F2FS_MAX_EXTENSION) - return -EINVAL; - } else { - if (!hot && !cold_count) - return -EINVAL; - if (hot && !hot_count) - return -EINVAL; - } - - if (hot) { - start = cold_count; - count = total_count; - } else { - start = 0; - count = cold_count; - } - - for (i = start; i < count; i++) { - if (strcmp(name, extlist[i])) - continue; - - if (set) - return -EINVAL; - - memcpy(extlist[i], extlist[i + 1], - F2FS_EXTENSION_LEN * (total_count - i - 1)); - memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN); - if (hot) - sbi->raw_super->hot_ext_count = hot_count - 1; - else - sbi->raw_super->extension_count = - cpu_to_le32(cold_count - 1); - return 0; - } - - if (!set) - return -EINVAL; - - if (hot) { - memcpy(extlist[count], name, strlen(name)); - sbi->raw_super->hot_ext_count = hot_count + 1; - } else { - char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN]; - - memcpy(buf, &extlist[cold_count], - F2FS_EXTENSION_LEN * hot_count); - memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN); - memcpy(extlist[cold_count], name, strlen(name)); - memcpy(&extlist[cold_count + 1], buf, - F2FS_EXTENSION_LEN * hot_count); - sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1); - } - return 0; -} - -static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, - const unsigned char *name) -{ - __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; - unsigned char (*noext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).noextensions; - unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions; - unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; - unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; - int i, cold_count, hot_count; - - if (!f2fs_sb_has_compression(sbi) || - F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || - !f2fs_may_compress(inode) || - (!ext_cnt && !noext_cnt)) - return; - - f2fs_down_read(&sbi->sb_lock); - - cold_count = le32_to_cpu(sbi->raw_super->extension_count); - hot_count = sbi->raw_super->hot_ext_count; - - for (i = cold_count; i < cold_count + hot_count; i++) { - if (is_extension_exist(name, extlist[i], false)) { - f2fs_up_read(&sbi->sb_lock); - return; - } - } - - f2fs_up_read(&sbi->sb_lock); - - for (i = 0; i < noext_cnt; i++) { - if (is_extension_exist(name, noext[i], false)) { - f2fs_disable_compressed_file(inode); - return; - } - } - - if (is_inode_flag_set(inode, FI_COMPRESSED_FILE)) - return; - - for (i = 0; i < ext_cnt; i++) { - if (!is_extension_exist(name, ext[i], false)) - continue; - - /* Do not use inline_data with compression */ - stat_dec_inline_inode(inode); - clear_inode_flag(inode, FI_INLINE_DATA); - set_compress_context(inode); - return; - } -} - static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) { @@ -352,15 +348,13 @@ static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, if (err) return err; - inode = f2fs_new_inode(mnt_userns, dir, mode); + inode = f2fs_new_inode(mnt_userns, dir, mode, dentry->d_name.name); if (IS_ERR(inode)) return PTR_ERR(inode); if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) set_file_temperature(sbi, inode, dentry->d_name.name); - set_compress_inode(sbi, inode, dentry->d_name.name); - inode->i_op = &f2fs_file_inode_operations; inode->i_fop = &f2fs_file_operations; inode->i_mapping->a_ops = &f2fs_dblock_aops; @@ -689,7 +683,7 @@ static int f2fs_symlink(struct user_namespace *mnt_userns, struct inode *dir, if (err) return err; - inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO); + inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO, NULL); if (IS_ERR(inode)) return PTR_ERR(inode); @@ -760,7 +754,7 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, if (err) return err; - inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode); + inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL); if (IS_ERR(inode)) return PTR_ERR(inode); @@ -817,7 +811,7 @@ static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir, if (err) return err; - inode = f2fs_new_inode(mnt_userns, dir, mode); + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); if (IS_ERR(inode)) return PTR_ERR(inode); @@ -856,7 +850,7 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, if (err) return err; - inode = f2fs_new_inode(mnt_userns, dir, mode); + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); if (IS_ERR(inode)) return PTR_ERR(inode);
On 11/14, Jaegeuk Kim wrote: > If compress_extension is set, and a newly created file matches the > extension, the file could be marked as compression file. However, > if inline_data is also enabled, there is no chance to check its > extension since f2fs_should_compress() always returns false. > > This patch moves set_compress_inode(), which do extension check, in > f2fs_should_compress() to check extensions before setting inline > data flag. > > Fixes: 7165841d578e ("f2fs: fix to check inline_data during compressed inode conversion") > Signed-off-by: Sheng Yong <shengyong@oppo.com> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> > --- > fs/f2fs/namei.c | 326 ++++++++++++++++++++++++------------------------ > 1 file changed, 160 insertions(+), 166 deletions(-) > > diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c > index e104409c3a0e..43b721d8e491 100644 > --- a/fs/f2fs/namei.c > +++ b/fs/f2fs/namei.c > @@ -22,8 +22,160 @@ > #include "acl.h" > #include <trace/events/f2fs.h> > > +static inline int is_extension_exist(const unsigned char *s, const char *sub, > + bool tmp_ext) > +{ > + size_t slen = strlen(s); > + size_t sublen = strlen(sub); > + int i; > + > + if (sublen == 1 && *sub == '*') > + return 1; > + > + /* > + * filename format of multimedia file should be defined as: > + * "filename + '.' + extension + (optional: '.' + temp extension)". > + */ > + if (slen < sublen + 2) > + return 0; > + > + if (!tmp_ext) { > + /* file has no temp extension */ > + if (s[slen - sublen - 1] != '.') > + return 0; > + return !strncasecmp(s + slen - sublen, sub, sublen); > + } > + > + for (i = 1; i < slen - sublen; i++) { > + if (s[i] != '.') > + continue; > + if (!strncasecmp(s + i + 1, sub, sublen)) > + return 1; > + } > + > + return 0; > +} > + > +int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, > + bool hot, bool set) > +{ > + __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; > + int cold_count = le32_to_cpu(sbi->raw_super->extension_count); > + int hot_count = sbi->raw_super->hot_ext_count; > + int total_count = cold_count + hot_count; > + int start, count; > + int i; > + > + if (set) { > + if (total_count == F2FS_MAX_EXTENSION) > + return -EINVAL; > + } else { > + if (!hot && !cold_count) > + return -EINVAL; > + if (hot && !hot_count) > + return -EINVAL; > + } > + > + if (hot) { > + start = cold_count; > + count = total_count; > + } else { > + start = 0; > + count = cold_count; > + } > + > + for (i = start; i < count; i++) { > + if (strcmp(name, extlist[i])) > + continue; > + > + if (set) > + return -EINVAL; > + > + memcpy(extlist[i], extlist[i + 1], > + F2FS_EXTENSION_LEN * (total_count - i - 1)); > + memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN); > + if (hot) > + sbi->raw_super->hot_ext_count = hot_count - 1; > + else > + sbi->raw_super->extension_count = > + cpu_to_le32(cold_count - 1); > + return 0; > + } > + > + if (!set) > + return -EINVAL; > + > + if (hot) { > + memcpy(extlist[count], name, strlen(name)); > + sbi->raw_super->hot_ext_count = hot_count + 1; > + } else { > + char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN]; > + > + memcpy(buf, &extlist[cold_count], > + F2FS_EXTENSION_LEN * hot_count); > + memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN); > + memcpy(extlist[cold_count], name, strlen(name)); > + memcpy(&extlist[cold_count + 1], buf, > + F2FS_EXTENSION_LEN * hot_count); > + sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1); > + } > + return 0; > +} > + > +static void set_compress_new_inode(struct f2fs_sb_info *sbi, struct inode *dir, > + struct inode *inode, const unsigned char *name) > +{ > + __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; > + unsigned char (*noext)[F2FS_EXTENSION_LEN] = > + F2FS_OPTION(sbi).noextensions; > + unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions; > + unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; > + unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; > + int i, cold_count, hot_count; > + > + if (!f2fs_sb_has_compression(sbi) || !name) > + return; > + if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) > + return; > + > + /* Inherit the compression flag in directory */ > + if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL)) { > + set_compress_context(inode); > + return; > + } > + > + /* Start to check extension list */ > + if (!ext_cnt) > + return; > + > + /* Don't compress hot files. */ > + f2fs_down_read(&sbi->sb_lock); > + cold_count = le32_to_cpu(sbi->raw_super->extension_count); > + hot_count = sbi->raw_super->hot_ext_count; > + for (i = cold_count; i < cold_count + hot_count; i++) > + if (is_extension_exist(name, extlist[i], false)) > + break; > + f2fs_up_read(&sbi->sb_lock); > + if (i < (cold_count + hot_count)) > + return; > + > + /* Don't compress unallowed extension. */ > + for (i = 0; i < noext_cnt; i++) > + if (is_extension_exist(name, noext[i], false)) > + return; > + > + /* Compress wanting extension. */ > + for (i = 0; i < ext_cnt; i++) { > + if (is_extension_exist(name, ext[i], false)) { > + set_compress_context(inode); > + return; > + } > + } > +} > + > static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, > - struct inode *dir, umode_t mode) > + struct inode *dir, umode_t mode, > + const char *name) > { > struct f2fs_sb_info *sbi = F2FS_I_SB(dir); > nid_t ino; > @@ -114,12 +266,8 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, > if (F2FS_I(inode)->i_flags & F2FS_PROJINHERIT_FL) > set_inode_flag(inode, FI_PROJ_INHERIT); > > - if (f2fs_sb_has_compression(sbi)) { > - /* Inherit the compression flag in directory */ > - if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) && > - f2fs_may_compress(inode)) > - set_compress_context(inode); > - } > + /* Check compression first. */ > + set_compress_new_inode(sbi, dir, inode, name); > > /* Should enable inline_data after compression set */ > if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode)) > @@ -153,40 +301,6 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, > return ERR_PTR(err); > } > > -static inline int is_extension_exist(const unsigned char *s, const char *sub, > - bool tmp_ext) > -{ > - size_t slen = strlen(s); > - size_t sublen = strlen(sub); > - int i; > - > - if (sublen == 1 && *sub == '*') > - return 1; > - > - /* > - * filename format of multimedia file should be defined as: > - * "filename + '.' + extension + (optional: '.' + temp extension)". > - */ > - if (slen < sublen + 2) > - return 0; > - > - if (!tmp_ext) { > - /* file has no temp extension */ > - if (s[slen - sublen - 1] != '.') > - return 0; > - return !strncasecmp(s + slen - sublen, sub, sublen); > - } > - > - for (i = 1; i < slen - sublen; i++) { > - if (s[i] != '.') > - continue; > - if (!strncasecmp(s + i + 1, sub, sublen)) > - return 1; > - } > - > - return 0; > -} > - > /* > * Set file's temperature for hot/cold data separation > */ > @@ -217,124 +331,6 @@ static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode * > file_set_hot(inode); > } > > -int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, > - bool hot, bool set) > -{ > - __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; > - int cold_count = le32_to_cpu(sbi->raw_super->extension_count); > - int hot_count = sbi->raw_super->hot_ext_count; > - int total_count = cold_count + hot_count; > - int start, count; > - int i; > - > - if (set) { > - if (total_count == F2FS_MAX_EXTENSION) > - return -EINVAL; > - } else { > - if (!hot && !cold_count) > - return -EINVAL; > - if (hot && !hot_count) > - return -EINVAL; > - } > - > - if (hot) { > - start = cold_count; > - count = total_count; > - } else { > - start = 0; > - count = cold_count; > - } > - > - for (i = start; i < count; i++) { > - if (strcmp(name, extlist[i])) > - continue; > - > - if (set) > - return -EINVAL; > - > - memcpy(extlist[i], extlist[i + 1], > - F2FS_EXTENSION_LEN * (total_count - i - 1)); > - memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN); > - if (hot) > - sbi->raw_super->hot_ext_count = hot_count - 1; > - else > - sbi->raw_super->extension_count = > - cpu_to_le32(cold_count - 1); > - return 0; > - } > - > - if (!set) > - return -EINVAL; > - > - if (hot) { > - memcpy(extlist[count], name, strlen(name)); > - sbi->raw_super->hot_ext_count = hot_count + 1; > - } else { > - char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN]; > - > - memcpy(buf, &extlist[cold_count], > - F2FS_EXTENSION_LEN * hot_count); > - memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN); > - memcpy(extlist[cold_count], name, strlen(name)); > - memcpy(&extlist[cold_count + 1], buf, > - F2FS_EXTENSION_LEN * hot_count); > - sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1); > - } > - return 0; > -} > - > -static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, > - const unsigned char *name) > -{ > - __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; > - unsigned char (*noext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).noextensions; > - unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions; > - unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; > - unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; > - int i, cold_count, hot_count; > - > - if (!f2fs_sb_has_compression(sbi) || > - F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || > - !f2fs_may_compress(inode) || > - (!ext_cnt && !noext_cnt)) > - return; > - > - f2fs_down_read(&sbi->sb_lock); > - > - cold_count = le32_to_cpu(sbi->raw_super->extension_count); > - hot_count = sbi->raw_super->hot_ext_count; > - > - for (i = cold_count; i < cold_count + hot_count; i++) { > - if (is_extension_exist(name, extlist[i], false)) { > - f2fs_up_read(&sbi->sb_lock); > - return; > - } > - } > - > - f2fs_up_read(&sbi->sb_lock); > - > - for (i = 0; i < noext_cnt; i++) { > - if (is_extension_exist(name, noext[i], false)) { > - f2fs_disable_compressed_file(inode); > - return; > - } > - } > - > - if (is_inode_flag_set(inode, FI_COMPRESSED_FILE)) > - return; > - > - for (i = 0; i < ext_cnt; i++) { > - if (!is_extension_exist(name, ext[i], false)) > - continue; > - > - /* Do not use inline_data with compression */ > - stat_dec_inline_inode(inode); > - clear_inode_flag(inode, FI_INLINE_DATA); > - set_compress_context(inode); > - return; > - } > -} > - > static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, > struct dentry *dentry, umode_t mode, bool excl) > { > @@ -352,15 +348,13 @@ static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, mode); > + inode = f2fs_new_inode(mnt_userns, dir, mode, dentry->d_name.name); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) > set_file_temperature(sbi, inode, dentry->d_name.name); > > - set_compress_inode(sbi, inode, dentry->d_name.name); > - > inode->i_op = &f2fs_file_inode_operations; > inode->i_fop = &f2fs_file_operations; > inode->i_mapping->a_ops = &f2fs_dblock_aops; > @@ -689,7 +683,7 @@ static int f2fs_symlink(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO); > + inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > @@ -760,7 +754,7 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode); > + inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL); - inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL); + inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, + dentry->d_name.name); Should pass dentry. > if (IS_ERR(inode)) > return PTR_ERR(inode); > > @@ -817,7 +811,7 @@ static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, mode); > + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > @@ -856,7 +850,7 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, mode); > + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > -- > 2.38.1.493.g58b659f92b-goog > > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
On 2022/11/15 6:39, Jaegeuk Kim wrote: > If compress_extension is set, and a newly created file matches the > extension, the file could be marked as compression file. However, > if inline_data is also enabled, there is no chance to check its > extension since f2fs_should_compress() always returns false. > > This patch moves set_compress_inode(), which do extension check, in > f2fs_should_compress() to check extensions before setting inline > data flag. > > Fixes: 7165841d578e ("f2fs: fix to check inline_data during compressed inode conversion") > Signed-off-by: Sheng Yong <shengyong@oppo.com> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> > --- > fs/f2fs/namei.c | 326 ++++++++++++++++++++++++------------------------ > 1 file changed, 160 insertions(+), 166 deletions(-) > > diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c > index e104409c3a0e..43b721d8e491 100644 > --- a/fs/f2fs/namei.c > +++ b/fs/f2fs/namei.c > @@ -22,8 +22,160 @@ > #include "acl.h" > #include <trace/events/f2fs.h> > > +static inline int is_extension_exist(const unsigned char *s, const char *sub, > + bool tmp_ext) > +{ > + size_t slen = strlen(s); > + size_t sublen = strlen(sub); > + int i; > + > + if (sublen == 1 && *sub == '*') > + return 1; > + > + /* > + * filename format of multimedia file should be defined as: > + * "filename + '.' + extension + (optional: '.' + temp extension)". > + */ > + if (slen < sublen + 2) > + return 0; > + > + if (!tmp_ext) { > + /* file has no temp extension */ > + if (s[slen - sublen - 1] != '.') > + return 0; > + return !strncasecmp(s + slen - sublen, sub, sublen); > + } > + > + for (i = 1; i < slen - sublen; i++) { > + if (s[i] != '.') > + continue; > + if (!strncasecmp(s + i + 1, sub, sublen)) > + return 1; > + } > + > + return 0; > +} > + > +int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, > + bool hot, bool set) > +{ > + __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; > + int cold_count = le32_to_cpu(sbi->raw_super->extension_count); > + int hot_count = sbi->raw_super->hot_ext_count; > + int total_count = cold_count + hot_count; > + int start, count; > + int i; > + > + if (set) { > + if (total_count == F2FS_MAX_EXTENSION) > + return -EINVAL; > + } else { > + if (!hot && !cold_count) > + return -EINVAL; > + if (hot && !hot_count) > + return -EINVAL; > + } > + > + if (hot) { > + start = cold_count; > + count = total_count; > + } else { > + start = 0; > + count = cold_count; > + } > + > + for (i = start; i < count; i++) { > + if (strcmp(name, extlist[i])) > + continue; > + > + if (set) > + return -EINVAL; > + > + memcpy(extlist[i], extlist[i + 1], > + F2FS_EXTENSION_LEN * (total_count - i - 1)); > + memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN); > + if (hot) > + sbi->raw_super->hot_ext_count = hot_count - 1; > + else > + sbi->raw_super->extension_count = > + cpu_to_le32(cold_count - 1); > + return 0; > + } > + > + if (!set) > + return -EINVAL; > + > + if (hot) { > + memcpy(extlist[count], name, strlen(name)); > + sbi->raw_super->hot_ext_count = hot_count + 1; > + } else { > + char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN]; > + > + memcpy(buf, &extlist[cold_count], > + F2FS_EXTENSION_LEN * hot_count); > + memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN); > + memcpy(extlist[cold_count], name, strlen(name)); > + memcpy(&extlist[cold_count + 1], buf, > + F2FS_EXTENSION_LEN * hot_count); > + sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1); > + } > + return 0; > +} > + > +static void set_compress_new_inode(struct f2fs_sb_info *sbi, struct inode *dir, > + struct inode *inode, const unsigned char *name) > +{ > + __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; > + unsigned char (*noext)[F2FS_EXTENSION_LEN] = > + F2FS_OPTION(sbi).noextensions; > + unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions; > + unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; > + unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; > + int i, cold_count, hot_count; > + > + if (!f2fs_sb_has_compression(sbi) || !name) > + return; > + if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) > + return; > + > + /* Inherit the compression flag in directory */ > + if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL)) { > + set_compress_context(inode); > + return; > + } > + > + /* Start to check extension list */ > + if (!ext_cnt) > + return; > + > + /* Don't compress hot files. */ > + f2fs_down_read(&sbi->sb_lock); > + cold_count = le32_to_cpu(sbi->raw_super->extension_count); > + hot_count = sbi->raw_super->hot_ext_count; > + for (i = cold_count; i < cold_count + hot_count; i++) > + if (is_extension_exist(name, extlist[i], false)) > + break; > + f2fs_up_read(&sbi->sb_lock); > + if (i < (cold_count + hot_count)) > + return; > + > + /* Don't compress unallowed extension. */ > + for (i = 0; i < noext_cnt; i++) > + if (is_extension_exist(name, noext[i], false)) > + return; Should check noext before inheritting F2FS_COMPR_FL? Thanks, > + > + /* Compress wanting extension. */ > + for (i = 0; i < ext_cnt; i++) { > + if (is_extension_exist(name, ext[i], false)) { > + set_compress_context(inode); > + return; > + } > + } > +} > + > static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, > - struct inode *dir, umode_t mode) > + struct inode *dir, umode_t mode, > + const char *name) > { > struct f2fs_sb_info *sbi = F2FS_I_SB(dir); > nid_t ino; > @@ -114,12 +266,8 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, > if (F2FS_I(inode)->i_flags & F2FS_PROJINHERIT_FL) > set_inode_flag(inode, FI_PROJ_INHERIT); > > - if (f2fs_sb_has_compression(sbi)) { > - /* Inherit the compression flag in directory */ > - if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) && > - f2fs_may_compress(inode)) > - set_compress_context(inode); > - } > + /* Check compression first. */ > + set_compress_new_inode(sbi, dir, inode, name); > > /* Should enable inline_data after compression set */ > if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode)) > @@ -153,40 +301,6 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, > return ERR_PTR(err); > } > > -static inline int is_extension_exist(const unsigned char *s, const char *sub, > - bool tmp_ext) > -{ > - size_t slen = strlen(s); > - size_t sublen = strlen(sub); > - int i; > - > - if (sublen == 1 && *sub == '*') > - return 1; > - > - /* > - * filename format of multimedia file should be defined as: > - * "filename + '.' + extension + (optional: '.' + temp extension)". > - */ > - if (slen < sublen + 2) > - return 0; > - > - if (!tmp_ext) { > - /* file has no temp extension */ > - if (s[slen - sublen - 1] != '.') > - return 0; > - return !strncasecmp(s + slen - sublen, sub, sublen); > - } > - > - for (i = 1; i < slen - sublen; i++) { > - if (s[i] != '.') > - continue; > - if (!strncasecmp(s + i + 1, sub, sublen)) > - return 1; > - } > - > - return 0; > -} > - > /* > * Set file's temperature for hot/cold data separation > */ > @@ -217,124 +331,6 @@ static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode * > file_set_hot(inode); > } > > -int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, > - bool hot, bool set) > -{ > - __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; > - int cold_count = le32_to_cpu(sbi->raw_super->extension_count); > - int hot_count = sbi->raw_super->hot_ext_count; > - int total_count = cold_count + hot_count; > - int start, count; > - int i; > - > - if (set) { > - if (total_count == F2FS_MAX_EXTENSION) > - return -EINVAL; > - } else { > - if (!hot && !cold_count) > - return -EINVAL; > - if (hot && !hot_count) > - return -EINVAL; > - } > - > - if (hot) { > - start = cold_count; > - count = total_count; > - } else { > - start = 0; > - count = cold_count; > - } > - > - for (i = start; i < count; i++) { > - if (strcmp(name, extlist[i])) > - continue; > - > - if (set) > - return -EINVAL; > - > - memcpy(extlist[i], extlist[i + 1], > - F2FS_EXTENSION_LEN * (total_count - i - 1)); > - memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN); > - if (hot) > - sbi->raw_super->hot_ext_count = hot_count - 1; > - else > - sbi->raw_super->extension_count = > - cpu_to_le32(cold_count - 1); > - return 0; > - } > - > - if (!set) > - return -EINVAL; > - > - if (hot) { > - memcpy(extlist[count], name, strlen(name)); > - sbi->raw_super->hot_ext_count = hot_count + 1; > - } else { > - char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN]; > - > - memcpy(buf, &extlist[cold_count], > - F2FS_EXTENSION_LEN * hot_count); > - memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN); > - memcpy(extlist[cold_count], name, strlen(name)); > - memcpy(&extlist[cold_count + 1], buf, > - F2FS_EXTENSION_LEN * hot_count); > - sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1); > - } > - return 0; > -} > - > -static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, > - const unsigned char *name) > -{ > - __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; > - unsigned char (*noext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).noextensions; > - unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions; > - unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; > - unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; > - int i, cold_count, hot_count; > - > - if (!f2fs_sb_has_compression(sbi) || > - F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || > - !f2fs_may_compress(inode) || > - (!ext_cnt && !noext_cnt)) > - return; > - > - f2fs_down_read(&sbi->sb_lock); > - > - cold_count = le32_to_cpu(sbi->raw_super->extension_count); > - hot_count = sbi->raw_super->hot_ext_count; > - > - for (i = cold_count; i < cold_count + hot_count; i++) { > - if (is_extension_exist(name, extlist[i], false)) { > - f2fs_up_read(&sbi->sb_lock); > - return; > - } > - } > - > - f2fs_up_read(&sbi->sb_lock); > - > - for (i = 0; i < noext_cnt; i++) { > - if (is_extension_exist(name, noext[i], false)) { > - f2fs_disable_compressed_file(inode); > - return; > - } > - } > - > - if (is_inode_flag_set(inode, FI_COMPRESSED_FILE)) > - return; > - > - for (i = 0; i < ext_cnt; i++) { > - if (!is_extension_exist(name, ext[i], false)) > - continue; > - > - /* Do not use inline_data with compression */ > - stat_dec_inline_inode(inode); > - clear_inode_flag(inode, FI_INLINE_DATA); > - set_compress_context(inode); > - return; > - } > -} > - > static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, > struct dentry *dentry, umode_t mode, bool excl) > { > @@ -352,15 +348,13 @@ static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, mode); > + inode = f2fs_new_inode(mnt_userns, dir, mode, dentry->d_name.name); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) > set_file_temperature(sbi, inode, dentry->d_name.name); > > - set_compress_inode(sbi, inode, dentry->d_name.name); > - > inode->i_op = &f2fs_file_inode_operations; > inode->i_fop = &f2fs_file_operations; > inode->i_mapping->a_ops = &f2fs_dblock_aops; > @@ -689,7 +683,7 @@ static int f2fs_symlink(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO); > + inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > @@ -760,7 +754,7 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode); > + inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > @@ -817,7 +811,7 @@ static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, mode); > + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); > > @@ -856,7 +850,7 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, > if (err) > return err; > > - inode = f2fs_new_inode(mnt_userns, dir, mode); > + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); > if (IS_ERR(inode)) > return PTR_ERR(inode); >
On 2022/11/15 8:20, Jaegeuk Kim wrote: > On 11/14, Jaegeuk Kim wrote: >> If compress_extension is set, and a newly created file matches the >> extension, the file could be marked as compression file. However, >> if inline_data is also enabled, there is no chance to check its >> extension since f2fs_should_compress() always returns false. >> >> This patch moves set_compress_inode(), which do extension check, in >> f2fs_should_compress() to check extensions before setting inline >> data flag. >> >> Fixes: 7165841d578e ("f2fs: fix to check inline_data during compressed inode conversion") >> Signed-off-by: Sheng Yong <shengyong@oppo.com> >> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> >> --- >> fs/f2fs/namei.c | 326 ++++++++++++++++++++++++------------------------ >> 1 file changed, 160 insertions(+), 166 deletions(-) >> >> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c >> index e104409c3a0e..43b721d8e491 100644 >> --- a/fs/f2fs/namei.c >> +++ b/fs/f2fs/namei.c >> @@ -22,8 +22,160 @@ >> #include "acl.h" >> #include <trace/events/f2fs.h> >> >> +static inline int is_extension_exist(const unsigned char *s, const char *sub, >> + bool tmp_ext) >> +{ >> + size_t slen = strlen(s); >> + size_t sublen = strlen(sub); >> + int i; >> + >> + if (sublen == 1 && *sub == '*') >> + return 1; >> + >> + /* >> + * filename format of multimedia file should be defined as: >> + * "filename + '.' + extension + (optional: '.' + temp extension)". >> + */ >> + if (slen < sublen + 2) >> + return 0; >> + >> + if (!tmp_ext) { >> + /* file has no temp extension */ >> + if (s[slen - sublen - 1] != '.') >> + return 0; >> + return !strncasecmp(s + slen - sublen, sub, sublen); >> + } >> + >> + for (i = 1; i < slen - sublen; i++) { >> + if (s[i] != '.') >> + continue; >> + if (!strncasecmp(s + i + 1, sub, sublen)) >> + return 1; >> + } >> + >> + return 0; >> +} >> + >> +int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, >> + bool hot, bool set) >> +{ >> + __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; >> + int cold_count = le32_to_cpu(sbi->raw_super->extension_count); >> + int hot_count = sbi->raw_super->hot_ext_count; >> + int total_count = cold_count + hot_count; >> + int start, count; >> + int i; >> + >> + if (set) { >> + if (total_count == F2FS_MAX_EXTENSION) >> + return -EINVAL; >> + } else { >> + if (!hot && !cold_count) >> + return -EINVAL; >> + if (hot && !hot_count) >> + return -EINVAL; >> + } >> + >> + if (hot) { >> + start = cold_count; >> + count = total_count; >> + } else { >> + start = 0; >> + count = cold_count; >> + } >> + >> + for (i = start; i < count; i++) { >> + if (strcmp(name, extlist[i])) >> + continue; >> + >> + if (set) >> + return -EINVAL; >> + >> + memcpy(extlist[i], extlist[i + 1], >> + F2FS_EXTENSION_LEN * (total_count - i - 1)); >> + memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN); >> + if (hot) >> + sbi->raw_super->hot_ext_count = hot_count - 1; >> + else >> + sbi->raw_super->extension_count = >> + cpu_to_le32(cold_count - 1); >> + return 0; >> + } >> + >> + if (!set) >> + return -EINVAL; >> + >> + if (hot) { >> + memcpy(extlist[count], name, strlen(name)); >> + sbi->raw_super->hot_ext_count = hot_count + 1; >> + } else { >> + char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN]; >> + >> + memcpy(buf, &extlist[cold_count], >> + F2FS_EXTENSION_LEN * hot_count); >> + memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN); >> + memcpy(extlist[cold_count], name, strlen(name)); >> + memcpy(&extlist[cold_count + 1], buf, >> + F2FS_EXTENSION_LEN * hot_count); >> + sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1); >> + } >> + return 0; >> +} >> + >> +static void set_compress_new_inode(struct f2fs_sb_info *sbi, struct inode *dir, >> + struct inode *inode, const unsigned char *name) >> +{ >> + __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; >> + unsigned char (*noext)[F2FS_EXTENSION_LEN] = >> + F2FS_OPTION(sbi).noextensions; >> + unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions; >> + unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; >> + unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; >> + int i, cold_count, hot_count; >> + >> + if (!f2fs_sb_has_compression(sbi) || !name) >> + return; >> + if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) >> + return; >> + >> + /* Inherit the compression flag in directory */ >> + if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL)) { >> + set_compress_context(inode); >> + return; >> + } >> + >> + /* Start to check extension list */ >> + if (!ext_cnt) >> + return; >> + >> + /* Don't compress hot files. */ >> + f2fs_down_read(&sbi->sb_lock); >> + cold_count = le32_to_cpu(sbi->raw_super->extension_count); >> + hot_count = sbi->raw_super->hot_ext_count; >> + for (i = cold_count; i < cold_count + hot_count; i++) >> + if (is_extension_exist(name, extlist[i], false)) >> + break; >> + f2fs_up_read(&sbi->sb_lock); >> + if (i < (cold_count + hot_count)) >> + return; >> + >> + /* Don't compress unallowed extension. */ >> + for (i = 0; i < noext_cnt; i++) >> + if (is_extension_exist(name, noext[i], false)) >> + return; >> + >> + /* Compress wanting extension. */ >> + for (i = 0; i < ext_cnt; i++) { >> + if (is_extension_exist(name, ext[i], false)) { >> + set_compress_context(inode); >> + return; >> + } >> + } >> +} >> + >> static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, >> - struct inode *dir, umode_t mode) >> + struct inode *dir, umode_t mode, >> + const char *name) >> { >> struct f2fs_sb_info *sbi = F2FS_I_SB(dir); >> nid_t ino; >> @@ -114,12 +266,8 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, >> if (F2FS_I(inode)->i_flags & F2FS_PROJINHERIT_FL) >> set_inode_flag(inode, FI_PROJ_INHERIT); >> >> - if (f2fs_sb_has_compression(sbi)) { >> - /* Inherit the compression flag in directory */ >> - if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) && >> - f2fs_may_compress(inode)) >> - set_compress_context(inode); >> - } >> + /* Check compression first. */ >> + set_compress_new_inode(sbi, dir, inode, name); >> >> /* Should enable inline_data after compression set */ >> if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode)) >> @@ -153,40 +301,6 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, >> return ERR_PTR(err); >> } >> >> -static inline int is_extension_exist(const unsigned char *s, const char *sub, >> - bool tmp_ext) >> -{ >> - size_t slen = strlen(s); >> - size_t sublen = strlen(sub); >> - int i; >> - >> - if (sublen == 1 && *sub == '*') >> - return 1; >> - >> - /* >> - * filename format of multimedia file should be defined as: >> - * "filename + '.' + extension + (optional: '.' + temp extension)". >> - */ >> - if (slen < sublen + 2) >> - return 0; >> - >> - if (!tmp_ext) { >> - /* file has no temp extension */ >> - if (s[slen - sublen - 1] != '.') >> - return 0; >> - return !strncasecmp(s + slen - sublen, sub, sublen); >> - } >> - >> - for (i = 1; i < slen - sublen; i++) { >> - if (s[i] != '.') >> - continue; >> - if (!strncasecmp(s + i + 1, sub, sublen)) >> - return 1; >> - } >> - >> - return 0; >> -} >> - >> /* >> * Set file's temperature for hot/cold data separation >> */ >> @@ -217,124 +331,6 @@ static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode * >> file_set_hot(inode); >> } >> >> -int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, >> - bool hot, bool set) >> -{ >> - __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; >> - int cold_count = le32_to_cpu(sbi->raw_super->extension_count); >> - int hot_count = sbi->raw_super->hot_ext_count; >> - int total_count = cold_count + hot_count; >> - int start, count; >> - int i; >> - >> - if (set) { >> - if (total_count == F2FS_MAX_EXTENSION) >> - return -EINVAL; >> - } else { >> - if (!hot && !cold_count) >> - return -EINVAL; >> - if (hot && !hot_count) >> - return -EINVAL; >> - } >> - >> - if (hot) { >> - start = cold_count; >> - count = total_count; >> - } else { >> - start = 0; >> - count = cold_count; >> - } >> - >> - for (i = start; i < count; i++) { >> - if (strcmp(name, extlist[i])) >> - continue; >> - >> - if (set) >> - return -EINVAL; >> - >> - memcpy(extlist[i], extlist[i + 1], >> - F2FS_EXTENSION_LEN * (total_count - i - 1)); >> - memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN); >> - if (hot) >> - sbi->raw_super->hot_ext_count = hot_count - 1; >> - else >> - sbi->raw_super->extension_count = >> - cpu_to_le32(cold_count - 1); >> - return 0; >> - } >> - >> - if (!set) >> - return -EINVAL; >> - >> - if (hot) { >> - memcpy(extlist[count], name, strlen(name)); >> - sbi->raw_super->hot_ext_count = hot_count + 1; >> - } else { >> - char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN]; >> - >> - memcpy(buf, &extlist[cold_count], >> - F2FS_EXTENSION_LEN * hot_count); >> - memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN); >> - memcpy(extlist[cold_count], name, strlen(name)); >> - memcpy(&extlist[cold_count + 1], buf, >> - F2FS_EXTENSION_LEN * hot_count); >> - sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1); >> - } >> - return 0; >> -} >> - >> -static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, >> - const unsigned char *name) >> -{ >> - __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; >> - unsigned char (*noext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).noextensions; >> - unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions; >> - unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; >> - unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; >> - int i, cold_count, hot_count; >> - >> - if (!f2fs_sb_has_compression(sbi) || >> - F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || >> - !f2fs_may_compress(inode) || >> - (!ext_cnt && !noext_cnt)) >> - return; >> - >> - f2fs_down_read(&sbi->sb_lock); >> - >> - cold_count = le32_to_cpu(sbi->raw_super->extension_count); >> - hot_count = sbi->raw_super->hot_ext_count; >> - >> - for (i = cold_count; i < cold_count + hot_count; i++) { >> - if (is_extension_exist(name, extlist[i], false)) { >> - f2fs_up_read(&sbi->sb_lock); >> - return; >> - } >> - } >> - >> - f2fs_up_read(&sbi->sb_lock); >> - >> - for (i = 0; i < noext_cnt; i++) { >> - if (is_extension_exist(name, noext[i], false)) { >> - f2fs_disable_compressed_file(inode); >> - return; >> - } >> - } >> - >> - if (is_inode_flag_set(inode, FI_COMPRESSED_FILE)) >> - return; >> - >> - for (i = 0; i < ext_cnt; i++) { >> - if (!is_extension_exist(name, ext[i], false)) >> - continue; >> - >> - /* Do not use inline_data with compression */ >> - stat_dec_inline_inode(inode); >> - clear_inode_flag(inode, FI_INLINE_DATA); >> - set_compress_context(inode); >> - return; >> - } >> -} >> - >> static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, >> struct dentry *dentry, umode_t mode, bool excl) >> { >> @@ -352,15 +348,13 @@ static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, mode); >> + inode = f2fs_new_inode(mnt_userns, dir, mode, dentry->d_name.name); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) >> set_file_temperature(sbi, inode, dentry->d_name.name); >> >> - set_compress_inode(sbi, inode, dentry->d_name.name); >> - >> inode->i_op = &f2fs_file_inode_operations; >> inode->i_fop = &f2fs_file_operations; >> inode->i_mapping->a_ops = &f2fs_dblock_aops; >> @@ -689,7 +683,7 @@ static int f2fs_symlink(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO); >> + inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> @@ -760,7 +754,7 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode); >> + inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL); > > - inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL); > + inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, > + dentry->d_name.name); > > Should pass dentry. It looks F2FS_COMPR_FL should be inherited for both directory and regular inode, and the flag should be set/unset due to matched {,no}ext only for regular inode. Thanks, > >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> @@ -817,7 +811,7 @@ static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, mode); >> + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> @@ -856,7 +850,7 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, >> if (err) >> return err; >> >> - inode = f2fs_new_inode(mnt_userns, dir, mode); >> + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); >> if (IS_ERR(inode)) >> return PTR_ERR(inode); >> >> -- >> 2.38.1.493.g58b659f92b-goog >> >> >> >> _______________________________________________ >> Linux-f2fs-devel mailing list >> Linux-f2fs-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index e104409c3a0e5..36e251f438568 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -22,8 +22,12 @@ #include "acl.h" #include <trace/events/f2fs.h> +static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, + const unsigned char *name); + static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, - struct inode *dir, umode_t mode) + struct inode *dir, umode_t mode, + const char *name) { struct f2fs_sb_info *sbi = F2FS_I_SB(dir); nid_t ino; @@ -119,6 +123,8 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns, if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) && f2fs_may_compress(inode)) set_compress_context(inode); + if (name) + set_compress_inode(sbi, inode, name); } /* Should enable inline_data after compression set */ @@ -293,8 +299,7 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; int i, cold_count, hot_count; - if (!f2fs_sb_has_compression(sbi) || - F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || + if (F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || !f2fs_may_compress(inode) || (!ext_cnt && !noext_cnt)) return; @@ -326,10 +331,6 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, for (i = 0; i < ext_cnt; i++) { if (!is_extension_exist(name, ext[i], false)) continue; - - /* Do not use inline_data with compression */ - stat_dec_inline_inode(inode); - clear_inode_flag(inode, FI_INLINE_DATA); set_compress_context(inode); return; } @@ -352,15 +353,13 @@ static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir, if (err) return err; - inode = f2fs_new_inode(mnt_userns, dir, mode); + inode = f2fs_new_inode(mnt_userns, dir, mode, dentry->d_name.name); if (IS_ERR(inode)) return PTR_ERR(inode); if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) set_file_temperature(sbi, inode, dentry->d_name.name); - set_compress_inode(sbi, inode, dentry->d_name.name); - inode->i_op = &f2fs_file_inode_operations; inode->i_fop = &f2fs_file_operations; inode->i_mapping->a_ops = &f2fs_dblock_aops; @@ -689,7 +688,7 @@ static int f2fs_symlink(struct user_namespace *mnt_userns, struct inode *dir, if (err) return err; - inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO); + inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO, NULL); if (IS_ERR(inode)) return PTR_ERR(inode); @@ -760,7 +759,7 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, if (err) return err; - inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode); + inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL); if (IS_ERR(inode)) return PTR_ERR(inode); @@ -817,7 +816,7 @@ static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir, if (err) return err; - inode = f2fs_new_inode(mnt_userns, dir, mode); + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); if (IS_ERR(inode)) return PTR_ERR(inode); @@ -856,7 +855,7 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, if (err) return err; - inode = f2fs_new_inode(mnt_userns, dir, mode); + inode = f2fs_new_inode(mnt_userns, dir, mode, NULL); if (IS_ERR(inode)) return PTR_ERR(inode);