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] = { From patchwork Sun Jan 22 15:00:49 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: 46956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1187342wrn; Sun, 22 Jan 2023 07:06:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXtyc0o8WlNJ1F0bjKQn3tgOI9393NCfeDRoIguYsR37j4rM4Fm8/WDmmw5vdKyE+940KpFH X-Received: by 2002:a17:903:54d:b0:193:a5b:ccf6 with SMTP id jo13-20020a170903054d00b001930a5bccf6mr19388466plb.0.1674399984900; Sun, 22 Jan 2023 07:06:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674399984; cv=pass; d=google.com; s=arc-20160816; b=jkZWgMDYEGOtpxUW4hc+o7Uzv7pVMAyS0orZZZ1Jdticw+On0Ha389T9zhM28bhQdn GHalvbu7JChDSYr/GOX7CHsXBUu2LOsIkCGX92r9J7VdIlhTYNGqVGWdhWbCpfyMaKuE d1nFG9sQuhmypY8LH30RN5ARZzdESkTuCJsxINurynuqOjq0w3/6jdidlxjQjpt0rKwR h2pqUYvdV9xZCdycfBzVeAMHGdoc9wai0qJJ2RN5NJCN3nvDdh/ERMxOTPuXk6WX5t3h vnSYBOJzqovY+4fbWDH/iLt3R4vb9CZh6pQZLGOO/eYmN5XgRc5aRJ6d6n6eVeQBGJYs JlZQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6jnjLZ60Pd7PhsNp1UPSHWmQXV1wz1fLOvWQK8N/O3k=; b=QdLMYFKsrczAPAF/cN3cbsFUpYc4BpH8SpKdHsKBBiHvH+yofv19Z5NuFDbavk6sAy Pm1vyB0pqYJ4pnghp/Pu05Kus2XNUkgM7RI0XvPIIElVOVaaNlDS7SqaKJ+GH8rZfZtX nNDnbAyxoR2q3NxjMWXDrcvBJyYqVwlO6/ldm2tgNwAAOpEBEBPQhAz1Xa2HVGrda/b4 OK4/sVT2Wkryj3dpp8Yru5CTqnXVxwpAob8yf5zW+oi1xuYZO684VqXP+7BZoJcBRKjk k3ESiKO3O8g0PGC2L9qbXerQrixD2c6JFIsKFzqs0/1GBDCvtYQYrUXWXSokQIuLIeUf 53RA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b="Puls/jiP"; 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 z13-20020a63d00d000000b0047702d2fe08si48950964pgf.493.2023.01.22.07.06.12; Sun, 22 Jan 2023 07:06:24 -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="Puls/jiP"; 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 S230011AbjAVPBK (ORCPT + 99 others); Sun, 22 Jan 2023 10:01:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbjAVPBJ (ORCPT ); Sun, 22 Jan 2023 10:01:09 -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 690432685 for ; Sun, 22 Jan 2023 07:01:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=id8DrF7q3fGz2u6Lj/wUamubfJu4CBYkReSQpS7Vm/xUv/BG4YB5MxuyfBqopDiv6Z4PjQuG8LhC3KU9nWC8Gf5XEtnPs5g9TmS38P/B8wbR6TyDxesZEJAfM5wEgJXQhpzPbZFk8xIfo+iz3Xe9dB5p8vkkw9PDa39AItVRtdKcAPyzChVaOCJXgtPDqDCZnjHqxlKHTMWdu3DQa6kgDKHObEDiW0o2m8TD5regiYfc1lNYH9zTpoqqo+6BWS5z+eV3cazvEZOznlXdLU1cAU0ZiCYsTJ0YqwfjK3XjM6rKjVf86mhh6xhJ8LFZIw1q5DJr0fc13MqUAmnLiOFx3w== 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=6jnjLZ60Pd7PhsNp1UPSHWmQXV1wz1fLOvWQK8N/O3k=; b=k+ihVqdmj9f0cTaxY5HvB3+4kQ21pZ8DUREMWUHGZKszSSk0+k82+Ox7WjpIfnu+/Sz6tmyirDEzr9+rvHLsXzy0SpbH9DirnQKn/s36NQ4iKSkX7rpdZt3vwXdrXMEEtjrJNPvsgtGUGILwKHsSxx6fl7ByFJJg5oQ81aXg6fqUjkf4COwD5TKYpEWGG0IQEkWuhO+DQ11hx4Pca95vZTFzVT5TTY7ehFnD6udGBsltkQgRj0JJEPsgFWFoNte/uji2VpqUdBLEP38dyP2MRIbr0PqvGGYck3XyDI8UA0YxlSLsP82ZoYEFRxNFIYnVwOkF/z2u/+EQHuFNTBrCJg== 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=6jnjLZ60Pd7PhsNp1UPSHWmQXV1wz1fLOvWQK8N/O3k=; b=Puls/jiPBbHYvkPrPVCqM7ihLf+0qXIrm1Y6ywJstgs4XEhCOk73D7e2f5tCGmbdzNR88hnr6D50mAHF8oyHwvotsY65FQorjK9TJkyuci0rkeZBYWrVIT4sCLUhrg8P6m8/eIFSrgUTvKmBbQCINT1CBhH808Sg6UTeVrs2CRrK4a9kd44/uz4vFjgIGiiVeUxz6hz469sKi6RvoxaMFbqYA/TD511kXgvkKdlHWrDVyuhaGscJLHv59PJ2nTj+GzgDEtDp1llo+/R2jpYSUjdAbiPY4RXeAK4ebae6xgpkZ4jg4IKYqo877MbQ78oPckLmVFkkH1khxNy/qUEUog== 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:04 +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:03 +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 2/2] f2fs: add F2FS_IOC_GET_COMPRESS_OPTION_V2 ioctl Date: Sun, 22 Jan 2023 23:00:49 +0800 Message-Id: <20230122150049.66607-2-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230122150049.66607-1-frank.li@vivo.com> References: <20230122150049.66607-1-frank.li@vivo.com> 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: 354d89b5-63f9-492e-0ee9-08dafc897b69 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7jHqjfsC/NM6RtQ5jgGh6+om65I8M874cr6tYDLztfSEHmWJ2bJYk0A1qghpVxYTRR/x/RM+wNo7hkNS13hTYyQlA7syYAzPfpqtkQNf2/b+wmY15DR6XH/sNkDlQxU8hqrkVVp2UcBCDaGL0MUGkKFO4eKEStPrZJ0tUbk0ig4MfYWn1+Pi1YTsHQdbihHlkr/uwr/2DAv+MRBoDKZYehhT5OKEsToQiQ75X8KER4fcp6G081W6vsCscMT2gpCEe71Dv8RguinRANEgESlJ5qSzViWo5QVBFCdF0C7dCDd9KwSQmPC7U74kE05kXSp+EhXCMdEY01hZ9bG4UUA5RtvG5g2CftzIuS5iD4CS2fG3UZou0tC/A/jlVQEXlBBqyW99ryFTdMPW7sYYSBER/nGh48YsUjbYtL7y1gNr+5BKsT/8jeyDG3/BpS/kBvGnvZU22yu1HgTLxy4NdhUKj1cW8pliVJ0CQtu5HwSDJXhkOWSMLk5MxlWBU5yoUY/2oS3lPaFBz9PyjDE76i4FNy9b6Cwl8LRUqsohGED90/wujZIKDJ5X3iy5CpZ8eHWAMWYPT8PDX2BeYOrK5YPwr6RWu3x98b/IHhL2hnhP0R8TfRBmlyYZC3yQX4O1OLhNGF4XxD+7BGqZPx16ffhMzyamWrtN6ObNmA/rJ6J0MjSghfXzgsHaoL6Wa58fKg6ho0/QcvetIybGzit6qfE4ZQ== 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: Fe1YAcPXp9mM0OiAEIYdJ8FBT6nY0TZGdsXdE3KkyU8KFwRH8dJGAnX6W17abpCw6bo4pJZD9XQNlPrhLvrByXVlcY6c/oYIXV6wN/CA+TIOeFBZT3+RCbXj3AXrWfzfyB3ewFj/yE74s+/e1WvLAXWowiD9JOQBjn3IPf/3mpykgo9csySlWhJe6Lv9hQmAim1gthh7nzPkkCKIKyui1DNOEiI8EyhUiB0cluKCBMtOsvN0p0cVdZxPTHKV0bOyLgaE5KgMkqHTf+fPzf0lQiSke8f/9HLrxnV8JtqFfaxrK1NJLsHhgRdmjHrvm94opTOYGtKhBWg9yuafC6dsqcoHx6z9rBQ9m5ebhXQOKIk4AFy6vZlfQPBRLb3aexkfVyvqfnnU0OtetygfG5gRjCNOsKeOznVR32OTB1q6+BmRTNfO1cYBUkYCFC+RxcBK82ROD4hGUlzik+4bcGixMh9YQAAZEdDnLhbOAencTFXU385FKYUx62fMfBd1ck26N9Cn8I+YI2QiNHqElQ/K3sjIv7MBSX9y0oj7qJGIHBd8iCPuaq8TdRneuUlkvKUEHoLA9jbUDd9x0I8GgU3OlVX08no1ckYfsSc5XVPLGv1Ggeld2ccEhX2pV8Af3eadRzwYP2FRnMm/vas8ZhZY9HB9oWWffHaT2CDA7H+JWYC32pWQG76i05MSfNxFMLhhaXXPkdGjrCI4Gqe3/fg1Kx/z8m/3bnUEM5tW0LvQqAspb6mXi4rw6V3ET7kIkjXtoDUoLM5CEk6sajlH7imdUC7u4Kby7r2Ev14axC6kBy6Z7K05lWdzZ5xTttl8RhS6BqK5uiFd96jQyQoSx0ALdNDX11jHEo3ANpFltm96Wq8PjBwAUxpGUe2gs7T3IgkcBUXHH2CpaqxX5JaNvYCXCfdXwuiGE7+JI46DJk9fjzyq4W5kU4WL5VlD+LuxnK4zifsS68SvDJVWW61rq5k1CDEBpSl945tAWpyQJ+qlKj7I3ckQi+AL1UoTQSsKZ3svfEmQrbUbn5aK7ZzW6dLA8SRJ5iXkUYTrPiwayTKkRg+4UcGpoCdsXEpvEmzAjCJfP4IWrYIfIs4yQTb4RX90IbcB8ObYIayQtZ5VQ+9YXwq5fX8BM6kyApLtVwz4zTU1vLfP4Y77uG4kKfeYdvuvt8UnR1AXGKTqi/3kRJso4KR+pIs34sJr6LubZtxv1cAaHiIo65I0ctrZgsVIIjm6LFHekIj2Yj6Beu1BV7rMb8CuR7ObL/jFaHMGf7ZaAnAJ1tn80SfXKJOrcnJM4CHfGqqW1OQ+rCqNVy6tj5JK8H7xarpAAAPkeuL0s1BUeF2q3devjcHRGue4UFEQ/kfn+Frc8M+y95KDnV64N3Tbnq+15TpgEBnY/xR83g7fJWNo7KJEDGxKgPxTArObh6wrd0Uqfsj7WrGSBzGvMyLOFLNLpsuecbQWGiy3qhSM7bZzrDSf2F4pHixHtEb3aZ5WFRS1OnSHjL4yijS6Yi5HJ5YR/lVA+sybXumwWy4q9VL+pz4I/aPLVaNR8ZukVuDYRlQZwy8aCqXfoAG9TuhGDSyY121CmPzTpPHKWU9ul4xj X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 354d89b5-63f9-492e-0ee9-08dafc897b69 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:03.8954 (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: 8dnVQxgIvHZK/DA29Rzgc+63Ep5RB3Qkpo7wNyKg4pSf72jpJieHHCwJ734BZFFr2JzSSgkHc0GrR3ewy7aCcA== 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?1755735638463311921?= X-GMAIL-MSGID: =?utf-8?q?1755735638463311921?= Added a new F2FS_IOC_GET_COMPRESS_OPTION_V2 ioctl to get 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; ioctl(fd, F2FS_IOC_GET_COMPRESS_OPTION_V2, &option); printf("compression algorithm:%u\n", option.algorithm); printf("compression cluster log size:%u\n", option.log_cluster_size); printf("compress level:%u\n", GET_COMPRESS_LEVEL(option.compress_flag)); printf("compress chksum:%s\n", (BIT(COMPRESS_CHKSUM) & option.compress_flag) ? "true" : "false"); Signed-off-by: Yangtao Li --- v2: -handle F2FS_IOC_GET_COMPRESS_OPTION_V2 in f2fs_compat_ioctl fs/f2fs/file.c | 21 ++++++++++++++++----- include/uapi/linux/f2fs.h | 4 +++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 78b97c1fa6af..b3bcb50490bd 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3899,10 +3899,12 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) return ret; } -static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg) +static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg, + unsigned int cmd) { struct inode *inode = file_inode(filp); - struct f2fs_comp_option option; + struct f2fs_comp_option_v2 option; + int len; if (!f2fs_sb_has_compression(F2FS_I_SB(inode))) return -EOPNOTSUPP; @@ -3916,11 +3918,17 @@ static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg) option.algorithm = F2FS_I(inode)->i_compress_algorithm; option.log_cluster_size = F2FS_I(inode)->i_log_cluster_size; + if (cmd == F2FS_IOC_GET_COMPRESS_OPTION_V2) + option.compress_flag = F2FS_I(inode)->i_compress_flag; inode_unlock_shared(inode); - if (copy_to_user((struct f2fs_comp_option __user *)arg, &option, - sizeof(option))) + if (cmd == F2FS_IOC_GET_COMPRESS_OPTION_V2) + len = sizeof(struct f2fs_comp_option_v2); + else + len = sizeof(struct f2fs_comp_option); + + if (copy_to_user((void __user *)arg, &option, len)) return -EFAULT; return 0; @@ -4263,7 +4271,9 @@ static long __f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) case F2FS_IOC_SEC_TRIM_FILE: return f2fs_sec_trim_file(filp, arg); case F2FS_IOC_GET_COMPRESS_OPTION: - return f2fs_ioc_get_compress_option(filp, arg); + return f2fs_ioc_get_compress_option(filp, arg, F2FS_IOC_GET_COMPRESS_OPTION); + case F2FS_IOC_GET_COMPRESS_OPTION_V2: + return f2fs_ioc_get_compress_option(filp, arg, F2FS_IOC_GET_COMPRESS_OPTION_V2); case F2FS_IOC_SET_COMPRESS_OPTION: return f2fs_ioc_set_compress_option(filp, arg, F2FS_IOC_SET_COMPRESS_OPTION); case F2FS_IOC_SET_COMPRESS_OPTION_V2: @@ -4902,6 +4912,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case F2FS_IOC_RESERVE_COMPRESS_BLOCKS: case F2FS_IOC_SEC_TRIM_FILE: case F2FS_IOC_GET_COMPRESS_OPTION: + case F2FS_IOC_GET_COMPRESS_OPTION_V2: case F2FS_IOC_SET_COMPRESS_OPTION: case F2FS_IOC_SET_COMPRESS_OPTION_V2: case F2FS_IOC_DECOMPRESS_FILE: diff --git a/include/uapi/linux/f2fs.h b/include/uapi/linux/f2fs.h index 640569444200..b82dc386e59e 100644 --- a/include/uapi/linux/f2fs.h +++ b/include/uapi/linux/f2fs.h @@ -45,6 +45,8 @@ #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) +#define F2FS_IOC_GET_COMPRESS_OPTION_V2 _IOW(F2FS_IOCTL_MAGIC, 27, \ + struct f2fs_comp_option_v2) /* * should be same as XFS_IOC_GOINGDOWN. @@ -65,7 +67,7 @@ #define F2FS_TRIM_FILE_MASK 0x3 /* - * Flags used by F2FS_IOC_SET_COMPRESS_OPTION_V2 + * Flags used by F2FS_IOC_SET_COMPRESS_OPTION_V2 and F2FS_IOC_GET_COMPRESS_OPTION */ #define COMPRESS_CHKSUM 0x0 /* enable chksum for compress file */ #define COMPRESS_LEVEL_OFFSET 8