From patchwork Sun Jan 22 15:00:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5p2O5oms6Z+s?= X-Patchwork-Id: 46955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1186034wrn; Sun, 22 Jan 2023 07:03:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXtQ3TJuN99duMMOcuoL0Z7kjVwRFM8D4Y/drlh4Cnx/P1alMA4/uU9klQGtctjWrMW5qXdw X-Received: by 2002:a17:902:bb8f:b0:194:751d:978 with SMTP id m15-20020a170902bb8f00b00194751d0978mr21699965pls.61.1674399822082; Sun, 22 Jan 2023 07:03:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674399822; cv=pass; d=google.com; s=arc-20160816; b=dWEexnMakPRmWBkSzWDrRK1HE+hSsw43fcVE95PkG3xkjPAp8S+KnInvRd251fLmMK Cz2vrqcqbk0MYKtXxxhDxfB8XO2456C0B4WGbCRWH9wxgOVuBlgZDUeihL0zMB4Pa+Xa KThYdUk+oyx/cHUXlHPHvPwTPLwHxKXUozKjg+GY1P8jZr9sxKcm9VvAV0ZqeWe1DLCa 7SFXd1Tsv+dXzcSoqkSJQ0gMyMOoXnlZOXiKXWdstmPIexeBsAMzU1G4EeRJTGUAj49C JMUZgpM1MuJ2bM/xvXM94SvrYRE0tvoo90A4R1ISyG2sm4aUCppHUte2d61gBDoCfVsI MRpQ== 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=vjboX6QgYsfKFXhb2nWNGNMMZICzPrmFqiP5V0JxMAY=; b=XGJFyd8V0632ceGoWXwRQXG1ZPjSQxEt8hH1Yey2xCXKQ3wTjsfOhx0yqxxKYtmrlM o50mBZfS6LrjavkxE9RxHGDqYlXndgHvmvM7swQhtfSYeaP1kmhUpbQI/qwVfAewtHCk A36LHOCemVDznzsJ+c45+yEhKzOTtx2wDsXnRsEYupxQDQGffA/vqvCCo2mW2Pmu0pjZ v1xdt5Ab6QK8FDm2r2AeVyanR+RzfIqAlSvbq91WjSVgWWRgV/B6E3WOjDSOm7Dq8CSo vlvoW478goSAf4Jtd6JFjSDvbkvfOhp8YostvnROZgnSJiipQkd4ll5t7afo+Rosl9kN peBw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=ZvQswOU4; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.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=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a63f110000000b004d1c5a7fa02si12277541pgi.442.2023.01.22.07.03.28; Sun, 22 Jan 2023 07:03:42 -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=@vivo.com header.s=selector2 header.b=ZvQswOU4; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.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=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbjAVPBN (ORCPT + 99 others); Sun, 22 Jan 2023 10:01:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbjAVPBK (ORCPT ); Sun, 22 Jan 2023 10:01:10 -0500 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2110.outbound.protection.outlook.com [40.107.215.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EA2FF6 for ; Sun, 22 Jan 2023 07:01:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cp7Vic0QNe48/iWFka0Y6SvPzs8KP9cPaSwOrxJLeo7al93AdBKo+HsYeXNZxw4v9sM4f+gGQJ96nXrIyxvd8DACB6TtEVY7542LCwwtmeon7d8ELG7kciSThofCT1E53GdhUBkWXnKooaQ1rHsHDhaml8knO/O+2D0UyF6EWMz4K5cmEdWPZDkLCESN2RDocms3Xy3dEIdSNzat8X2pk3IL9U72dNliZSvFlBdUXiwUQ7jvUb6Zti1QsjHiFdo/0Ey0+23V7HOtni/ol07OYUyQsIsE0+Kt8du/HgX8NGBDnOyWBr/qO9SyLEJZ4+tudxCpWuSKst3H2rlseLGPGA== 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=vjboX6QgYsfKFXhb2nWNGNMMZICzPrmFqiP5V0JxMAY=; b=B7Tr6racEmsd5F355vNWLQrm84zGpPbr8ogO8BOLEcaygKX2muI8wsnJN8LFzqBeOM5cQYC1OmB+NHe3UCVNE/EY4yIfVQ+8gXOWCPspVpat06oWMwj18pAaCcDZp3Ss9XlUoCskfO/bL4kiASDhGrG6EC+m0NnjWwXdi/go8XsJUspnCvn3nhHmoXu9D9aeDR+VfJs2U5OVHpyiu9WEWP1MQCgJjkGgkjrmVwnMARyb3Y9NFHqkjtZNXyzqnlySbJ9gTTw53d5rjY5j7vs+SJBg2s2cTGfd5O3aU2/KuUCjJtVguvUirTIiA4aQTKkZfbahlPXQX3TH6nRQ6YIa/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vjboX6QgYsfKFXhb2nWNGNMMZICzPrmFqiP5V0JxMAY=; b=ZvQswOU4m+rlz7bBaIhlzyeVjDJ3W5VOaBFDkq1E18+sJY3l3gdqbu2gL0UdvC+kDGzKjo5Xtuendkcp+5RL31monLgOzhgTN+DYhrBk85hLTlZQ/tqD98dTpPCOGqXa6pgarBYGvdwf6Sf9H8eOCbiSkULjdCBEy0PyXV7TnXKO8q7dpMqZRaqMw0h/98R4FYKPfJ6hOXceKi/xM0+X4ZLpeWPmibg1f1rF+VufocL6ouZJ/3TCd9VkUjI1JRF1+n3Tt/G8Nx7BtY7ztwuxGU4dBSJq5cfmhAsrXi9fhpQdYDjGEFWF+pvRkV+m0orpvMjiTdYpACMUWwF+Rf4ebQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by TY0PR06MB5493.apcprd06.prod.outlook.com (2603:1096:400:264::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.14; Sun, 22 Jan 2023 15:01:02 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::3e52:d08c:ecf4:d572]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::3e52:d08c:ecf4:d572%5]) with mapi id 15.20.6043.009; Sun, 22 Jan 2023 15:01:02 +0000 From: Yangtao Li To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v2 1/2] f2fs: add F2FS_IOC_SET_COMPRESS_OPTION_V2 ioctl Date: Sun, 22 Jan 2023 23:00:48 +0800 Message-Id: <20230122150049.66607-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SG2PR03CA0089.apcprd03.prod.outlook.com (2603:1096:4:7c::17) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|TY0PR06MB5493:EE_ X-MS-Office365-Filtering-Correlation-Id: 0613060a-3ac3-4a0c-c735-08dafc897a18 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9ES19Rd+QsT9nxSEowerTCnQrVm+WcFMowohlLxu7RyQm0XuR/H6rnHFht23L0HEOlCZHMvR1goRC8p5uPM1+byzfbZcC3YqLm3Ay+WoDc97QjBCb+nWNC1638yDH57b+UQ0doxLb+EZoBwuJ0jYNj8cz5kQGk3Xh2eCbOZjnY0ZLbz+nbR9APiT9lAK76jleIJze7R3EHZudCSnKLph6gtWmAVnR8qaZYRMO5O/3S2ecucmxTW8+V+vUMVE3MUdM0ajUv29o8FBXr+WUqvKNZEOd95XlB5q3amjOPi5DqZs2eeYK1YCaeWqoj+08LeVoWQKQMJRaO445WHrC+8h/nrJA6PQObQAKXAJ9HnXH89hKwGYMjTeXPTejbseOeiWigThrYm/1QFq6LiuuIZU0W7IKKXE21KUUKh/WJ2QzHGXr7W6+pjMj0PAgahVGp/wd9uOKgf7Pi0kLRifwcBsfMVUYYTwBvgN6q2SlP3csHH5f4TNwjDElnGJr170D9JvwDMiSdDejmty6fJj8rEIhih862STJiw8rAArb4YEeegpHPEiZbc3IIUHFWFKvgCq2JgSWj1E5xfsszyiH7kxiENfFovdFVQr2P3JuUDt76tysPggbTks/Zl4w/Y3n6OOAChV5JZ1wGo6o7XfOyk6zWuDry1/MqC9cSe8tqQdoU4qKpYvxFKbkv5HrkTXRgwSpYtOjTB/l5oMyuUeATHvKw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5269.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(39850400004)(396003)(376002)(366004)(346002)(451199015)(83380400001)(38350700002)(38100700002)(86362001)(41300700001)(2906002)(5660300002)(8936002)(4326008)(8676002)(6512007)(6506007)(186003)(26005)(6666004)(1076003)(107886003)(2616005)(316002)(66946007)(66556008)(66476007)(478600001)(52116002)(6486002)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CSjTIR3gmhqzzvEvbDSHHehtzEiQ3RqfVs59TYIzj1wJQnjfubqtDGSVO44/kWhXsmLYn/ajCrlpSFER6pvGIa6U/F2Iicu9Gp+LKcBU2seArrIAoFChBchz3P/INHZnUoJ9fNMOritkpo/f6Ucc1NVuwXxtcdNnHTaHSjpC2xdvJk8z5XbioAegyRJe877f3td4V5FcftUZQqwlfOPvcE9OuMiYxpkI4vJCZp3SBNW2DGJGo4/o38oh/LRKKBnD2kXVh+7SJE0h1VbQSYwYjCr6+IeQCwvRbAPhSvr/1g/srKHsUHTNf/2aqvyLVLY9IzmNOIhUZ0ANj/DNrTOXdWTGOLeatpnkkq6HKzl0RtL/SqaAPHpLdqwjba6JIpcwE94O0T2FI/3yPwiS+KeslWXejnQ/lJ3AJ3obRs+7H48Y4dY2D3bFaUIveDYVS6YgV+4sQpktywivlXcSfYWMo0D2xt+T1u1o7IjIPXYhn9lmqPhfFGIUw+nwFpGAUJS1zxiupVaZtMsQ4LcHdqww0V6Z/y6jS0cBFbxhlI+tYlRuyQ3lPip7YGFU5xHma7AkJ41Z0gfhZDldWPuTmIKZIwcfshItFaGxPf3xDTS9Iv0Imx2W3u+luM/WONb2kaJZsOsdenS9TXX8PUs82gzNxQcdnd9zw/NOsot9u6Df45hlKzZj0GRJ8eodrsemaJXh0lQ0xgVpJzXNcG6SaCRMx1ddZdsbinq6Q94qJtGfrY36THUSO8/Mx++KWASBwdUZ4LbANyKn2Q/J/suuON57RvFLNQmdn4QJzefi1XTgh8DnluyuvqzZBdrcVm6ndF6AAwDDPD2Lba2xmFDlej1RF3nLm0ZV2Ys1LunjL0Ok7J4TrTlgWZwpOxs4P+WZxVUALIJ1+O4/izSOyMtcCICNz4Xddz8JVwqw5Q1Ip2KtfYAa/KOnUe4WJuks/kqmNGiKbRV1RXgA8k83siu1b/XJbE2OXEPvytFag2sVTNqFxO1t7ii2po8CGpmnlTAMKKsjCaz8ifR4I7YEUQOM2/hQBYsXnb69cOGJFA7eR8y6JQO1iXGSnBToZ1QiXDsIzNJp/JinMOJ8v6wQgONbTsgCXTS0Q1QwvAYti0GuYDqtSeGRLzBWvojc+mrM58gHTsCdhuXgpoi4/vdP/U9Ffi9c/elyhACl1Gf3MJntJAIS3rMLo0IXkljKlsVTVCAsvkhx6k80E3SQ73lTMU53rzoP/ObWQRl6f/hwYCS9CaJIkqvyRnynFlg6UuvuAUEBeVrNKqdRWIoQxbRul+0SBvZhO0CBWLK+6yt8TvRB1iNCk8apaqlxLQFT7FZRzt2Zvvj3GXEDBZICySg4kAPQCNLK+pcWVLdU2j3jgH+nNnl+Bw7SoP27dsxHDlY6NTozW8e2nrHwA0K2xy21RpC7BBxY8ImdRJauKflTvPa7jec+ePSoTxKxv/LykUkbqls2I6d7NDXNaRwuHhn1K0rtKbOiH6z9Pr5G5+4rDsMan5X5R9ds9X7SqAtMmNiiZYrzWJLP3//S5tqxCquGgX9Hem/haCBIUKHF6c3hrVikzIiY5MjlwNhvjlaf06Wh2s45kWi+ X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0613060a-3ac3-4a0c-c735-08dafc897a18 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2023 15:01:01.7072 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PesNE31rn9zp1Y1pBrt6IM9jyea39nyy/+6Eys1UVnoaKQyY/wyGqTgwa48xMcdYZBk0pCo1VN/xKz2hinVVYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY0PR06MB5493 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,URIBL_BLOCKED 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755735468074985956?= X-GMAIL-MSGID: =?utf-8?q?1755735468074985956?= Added a new F2FS_IOC_SET_COMPRESS_OPTION_V2 ioctl to change file compression option of a file. struct f2fs_comp_option_v2 { union { struct { __u8 algorithm; __u8 log_cluster_size; __u16 compress_flag; }; struct f2fs_comp_option option; }; }; struct f2fs_comp_option_v2 option; option.algorithm = 2; option.log_cluster_size = 2; option.compress_flag = (5 << COMPRESS_LEVEL_OFFSET) | BIT(COMPRESS_CHKSUM); ioctl(fd, F2FS_IOC_SET_COMPRESS_OPTION_V2, &option); Signed-off-by: Yangtao Li --- v2: -export ZSTD_MAX_CLEVEL to avoid compile error -handle COMPRESS_LZO and COMPRESS_LZORLE in f2fs_ioc_set_compress_option -handle F2FS_IOC_SET_COMPRESS_OPTION_V2 in f2fs_compat_ioctl fs/f2fs/f2fs.h | 8 +------ fs/f2fs/file.c | 47 +++++++++++++++++++++++++++++++------ include/linux/zstd_lib.h | 3 +++ include/uapi/linux/f2fs.h | 21 +++++++++++++++++ lib/zstd/compress/clevels.h | 4 ---- 5 files changed, 65 insertions(+), 18 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 9edad9ccc2cd..fa409eca293f 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -1502,11 +1503,6 @@ enum compress_algorithm_type { COMPRESS_MAX, }; -enum compress_flag { - COMPRESS_CHKSUM, - COMPRESS_MAX_FLAG, -}; - #define COMPRESS_WATERMARK 20 #define COMPRESS_PERCENT 20 @@ -1522,8 +1518,6 @@ struct compress_data { #define F2FS_COMPRESSED_PAGE_MAGIC 0xF5F2C000 -#define COMPRESS_LEVEL_OFFSET 8 - /* compress context */ struct compress_ctx { struct inode *inode; /* inode the context belong to */ diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 5e4b8c6daa1f..78b97c1fa6af 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include "f2fs.h" #include "node.h" @@ -3924,12 +3926,13 @@ static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg) return 0; } -static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) +static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg, + unsigned int cmd) { struct inode *inode = file_inode(filp); struct f2fs_sb_info *sbi = F2FS_I_SB(inode); - struct f2fs_comp_option option; - int ret = 0; + struct f2fs_comp_option_v2 option; + int ret = 0, len; if (!f2fs_sb_has_compression(sbi)) return -EOPNOTSUPP; @@ -3937,8 +3940,12 @@ static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) if (!(filp->f_mode & FMODE_WRITE)) return -EBADF; - if (copy_from_user(&option, (struct f2fs_comp_option __user *)arg, - sizeof(option))) + if (cmd == F2FS_IOC_SET_COMPRESS_OPTION_V2) + len = sizeof(struct f2fs_comp_option_v2); + else + len = sizeof(struct f2fs_comp_option); + + if (copy_from_user(&option, (void __user *)arg, len)) return -EFAULT; if (!f2fs_compressed_file(inode) || @@ -3947,6 +3954,26 @@ static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) option.algorithm >= COMPRESS_MAX) return -EINVAL; + if (cmd == F2FS_IOC_SET_COMPRESS_OPTION_V2) { + unsigned int level = GET_COMPRESS_LEVEL(option.compress_flag); + + switch (option.algorithm) { + case COMPRESS_LZO: + case COMPRESS_LZORLE: + if (level) + return -EINVAL; + break; + case COMPRESS_LZ4: + if (level < LZ4HC_MIN_CLEVEL || level > LZ4HC_MAX_CLEVEL) + return -EINVAL; + break; + case COMPRESS_ZSTD: + if (!level || level > ZSTD_MAX_CLEVEL) + return -EINVAL; + break; + } + } + file_start_write(filp); inode_lock(inode); @@ -3962,7 +3989,10 @@ static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) F2FS_I(inode)->i_compress_algorithm = option.algorithm; F2FS_I(inode)->i_log_cluster_size = option.log_cluster_size; - F2FS_I(inode)->i_cluster_size = 1 << option.log_cluster_size; + F2FS_I(inode)->i_cluster_size = BIT(option.log_cluster_size); + + if (cmd == F2FS_IOC_SET_COMPRESS_OPTION_V2) + F2FS_I(inode)->i_compress_flag = option.compress_flag & COMPRESS_OPTION_MASK; f2fs_mark_inode_dirty_sync(inode, true); if (!f2fs_is_compress_backend_ready(inode)) @@ -4235,7 +4265,9 @@ static long __f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) case F2FS_IOC_GET_COMPRESS_OPTION: return f2fs_ioc_get_compress_option(filp, arg); case F2FS_IOC_SET_COMPRESS_OPTION: - return f2fs_ioc_set_compress_option(filp, arg); + return f2fs_ioc_set_compress_option(filp, arg, F2FS_IOC_SET_COMPRESS_OPTION); + case F2FS_IOC_SET_COMPRESS_OPTION_V2: + return f2fs_ioc_set_compress_option(filp, arg, F2FS_IOC_SET_COMPRESS_OPTION_V2); case F2FS_IOC_DECOMPRESS_FILE: return f2fs_ioc_decompress_file(filp, arg); case F2FS_IOC_COMPRESS_FILE: @@ -4871,6 +4903,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case F2FS_IOC_SEC_TRIM_FILE: case F2FS_IOC_GET_COMPRESS_OPTION: case F2FS_IOC_SET_COMPRESS_OPTION: + case F2FS_IOC_SET_COMPRESS_OPTION_V2: case F2FS_IOC_DECOMPRESS_FILE: case F2FS_IOC_COMPRESS_FILE: break; diff --git a/include/linux/zstd_lib.h b/include/linux/zstd_lib.h index 79d55465d5c1..ff55f41c73d3 100644 --- a/include/linux/zstd_lib.h +++ b/include/linux/zstd_lib.h @@ -88,6 +88,9 @@ ZSTDLIB_API const char* ZSTD_versionString(void); # define ZSTD_CLEVEL_DEFAULT 3 #endif +/*-===== Pre-defined compression levels =====-*/ +#define ZSTD_MAX_CLEVEL 22 + /* ************************************* * Constants ***************************************/ diff --git a/include/uapi/linux/f2fs.h b/include/uapi/linux/f2fs.h index 955d440be104..640569444200 100644 --- a/include/uapi/linux/f2fs.h +++ b/include/uapi/linux/f2fs.h @@ -43,6 +43,8 @@ #define F2FS_IOC_DECOMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 23) #define F2FS_IOC_COMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 24) #define F2FS_IOC_START_ATOMIC_REPLACE _IO(F2FS_IOCTL_MAGIC, 25) +#define F2FS_IOC_SET_COMPRESS_OPTION_V2 _IOW(F2FS_IOCTL_MAGIC, 26, \ + struct f2fs_comp_option_v2) /* * should be same as XFS_IOC_GOINGDOWN. @@ -62,6 +64,15 @@ #define F2FS_TRIM_FILE_ZEROOUT 0x2 /* zero out */ #define F2FS_TRIM_FILE_MASK 0x3 +/* + * Flags used by F2FS_IOC_SET_COMPRESS_OPTION_V2 + */ +#define COMPRESS_CHKSUM 0x0 /* enable chksum for compress file */ +#define COMPRESS_LEVEL_OFFSET 8 +#define COMPRESS_LEVEL_MASK GENMASK(15, COMPRESS_LEVEL_OFFSET) +#define COMPRESS_OPTION_MASK (COMPRESS_LEVEL_MASK | BIT(COMPRESS_CHKSUM)) +#define GET_COMPRESS_LEVEL(x) (((x) & COMPRESS_LEVEL_MASK) >> COMPRESS_LEVEL_OFFSET) + struct f2fs_gc_range { __u32 sync; __u64 start; @@ -96,4 +107,14 @@ struct f2fs_comp_option { __u8 log_cluster_size; }; +struct f2fs_comp_option_v2 { + union { + struct { + __u8 algorithm; + __u8 log_cluster_size; + __u16 compress_flag; + }; + struct f2fs_comp_option option; + }; +}; #endif /* _UAPI_LINUX_F2FS_H */ diff --git a/lib/zstd/compress/clevels.h b/lib/zstd/compress/clevels.h index d9a76112ec3a..b040d9d29089 100644 --- a/lib/zstd/compress/clevels.h +++ b/lib/zstd/compress/clevels.h @@ -14,10 +14,6 @@ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */ #include -/*-===== Pre-defined compression levels =====-*/ - -#define ZSTD_MAX_CLEVEL 22 - __attribute__((__unused__)) static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = {