Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp195356pxu; Wed, 2 Dec 2020 19:36:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKl0eJnq+yZcMMoP/+f1OYYjtyiYJeULst17yAudXTd4HZk34un1Mr0ARjTk4UiG8ROSNZ X-Received: by 2002:a17:906:4d8d:: with SMTP id s13mr824273eju.305.1606966568055; Wed, 02 Dec 2020 19:36:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606966568; cv=none; d=google.com; s=arc-20160816; b=r3xIlAiJvtK+qQj5t4HCpZzIQCejyIBZZryxLlMQ4a89drWSor3SdY9iP8NOtifyI0 3eJllI8TCNGWnLtwFsSpMvfnPPgSTPLrU42/A1VH0iBeRCMIWCZbws8C6rPgpSYC6U1t LnqMBv2iYPHQvc452Y+8L//j+LNoyESObq7xhG3HhC0F8D/TDYXfyaSaxVY30CKvn7jL m/ZUvtyPALDySE7H1V1BtqOUUxefQT+Mq5B+Ox/2O7f88sCbxUA59NE/yBy4QjQoBYkK 3P0zdPmcAeOWZ54hkL4/K7eFoEtceffbgloQf6/oY/k7fw4HdiJebeRyzcOLoHWlWXi/ sEmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=iznV7FbIvtImhDNzpGwJ7zSw0TWZ36xYiBwcYPuQwTw=; b=ZSYAd0ha3yk9WIgb0zDrtEHzGFOrVL60Yzcepckyfo0nDz2nv4DDc1GSWAL4xmEpUR gmII5K1qxyih8uPOYviwQmYZU9NAwbihDMdzinCv3b7cXs5pBlEGPJ2UkUWI1u38C6Y7 nn0vsWRtXfG67gVFKxcAQx62z4ttmgV4WJ6AEk+XaBzB4tl9hjd+2S9j5VZVccuprgF2 /d6mBN8grD8kM3VBUrwgQ6DmiYL22Un3ZRJ8YIKB++TYVtusLFT9fQfgSV4d5TimsZzr kEzk9R9kucvVEC5K3lN9PXnhNQgYeKpqXlVfcHRjUlg5hzbKgKU9DbSo9WN6SpWHPAxd uWIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r12si177699edy.447.2020.12.02.19.35.45; Wed, 02 Dec 2020 19:36:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729657AbgLCDeH (ORCPT + 99 others); Wed, 2 Dec 2020 22:34:07 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8994 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727281AbgLCDeH (ORCPT ); Wed, 2 Dec 2020 22:34:07 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CmhHZ2HnbzhhMd; Thu, 3 Dec 2020 11:32:58 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 3 Dec 2020 11:33:14 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH] f2fs: compress: deny setting unsupported compress algorithm Date: Thu, 3 Dec 2020 11:33:09 +0800 Message-ID: <20201203033309.42734-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If kernel doesn't support certain kinds of compress algorithm, deny to set them as compress algorithm of f2fs via 'compress_algorithm=%s' mount option. Signed-off-by: Chao Yu --- fs/f2fs/super.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 6e186e365efc..1b9d2592b1ac 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -504,15 +504,10 @@ static int f2fs_compress_set_level(struct f2fs_sb_info *sbi, const char *str, return 0; #endif } else if (type == COMPRESS_ZSTD) { -#ifdef CONFIG_F2FS_FS_ZSTD if (!level || level > ZSTD_maxCLevel()) { f2fs_info(sbi, "invalid zstd compress level: %d", level); return -EINVAL; } -#else - f2fs_info(sbi, "doesn't support zstd compression"); - return 0; -#endif } F2FS_OPTION(sbi).compress_level = level; return 0; @@ -937,9 +932,14 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount) if (!name) return -ENOMEM; if (!strcmp(name, "lzo")) { +#ifdef CONFIG_F2FS_FS_LZO F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZO; +#else + f2fs_info(sbi, "Image doesn't support lzo compression"); +#endif } else if (!strncmp(name, "lz4", 3)) { +#ifdef CONFIG_F2FS_FS_LZ4 ret = f2fs_compress_set_level(sbi, name, COMPRESS_LZ4); if (ret) { @@ -948,7 +948,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount) } F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; +#else + f2fs_info(sbi, "Image doesn't support lz4 compression"); +#endif } else if (!strncmp(name, "zstd", 4)) { +#ifdef CONFIG_F2FS_FS_ZSTD ret = f2fs_compress_set_level(sbi, name, COMPRESS_ZSTD); if (ret) { @@ -957,9 +961,16 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount) } F2FS_OPTION(sbi).compress_algorithm = COMPRESS_ZSTD; +#else + f2fs_info(sbi, "Image doesn't support zstd compression"); +#endif } else if (!strcmp(name, "lzo-rle")) { +#ifdef CONFIG_F2FS_FS_LZORLE F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZORLE; +#else + f2fs_info(sbi, "Image doesn't support lzorle compression"); +#endif } else { kfree(name); return -EINVAL; -- 2.26.2