From patchwork Fri Aug 9 14:55:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11086605 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2AB4613AC for ; Fri, 9 Aug 2019 14:54:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19FFE1FF7F for ; Fri, 9 Aug 2019 14:54:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DFD51FF81; Fri, 9 Aug 2019 14:54:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83CFC1FE8E for ; Fri, 9 Aug 2019 14:54:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726457AbfHIOyd (ORCPT ); Fri, 9 Aug 2019 10:54:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:39736 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726140AbfHIOyd (ORCPT ); Fri, 9 Aug 2019 10:54:33 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 426BAACBA for ; Fri, 9 Aug 2019 14:54:32 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 3B2ACDA7C5; Fri, 9 Aug 2019 16:55:03 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 1/2] btrfs: define compression levels statically Date: Fri, 9 Aug 2019 16:55:03 +0200 Message-Id: <78207f6784c457dad6583f7bc7eecc495c7d5d54.1565362438.git.dsterba@suse.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The maximum and default levels do not change and can be defined directly. The set_level callback was a temporary solution and will be removed. Signed-off-by: David Sterba --- fs/btrfs/compression.h | 4 ++++ fs/btrfs/lzo.c | 2 ++ fs/btrfs/zlib.c | 2 ++ fs/btrfs/zstd.c | 2 ++ 4 files changed, 10 insertions(+) diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 2035b8eb1290..07b2009dc63f 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -162,6 +162,10 @@ struct btrfs_compress_op { * if the level is out of bounds or the default if 0 is passed in. */ unsigned int (*set_level)(unsigned int level); + + /* Maximum level supported by the compression algorithm */ + int max_level; + int default_level; }; /* The heuristic workspaces are managed via the 0th workspace manager */ diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 579d53ae256f..adac6cb30d65 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -523,4 +523,6 @@ const struct btrfs_compress_op btrfs_lzo_compress = { .decompress_bio = lzo_decompress_bio, .decompress = lzo_decompress, .set_level = lzo_set_level, + .max_level = 1, + .default_level = 1, }; diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index b86b7ad6b900..03d6c3683bd9 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -437,4 +437,6 @@ const struct btrfs_compress_op btrfs_zlib_compress = { .decompress_bio = zlib_decompress_bio, .decompress = zlib_decompress, .set_level = zlib_set_level, + .max_level = 9, + .default_level = BTRFS_ZLIB_DEFAULT_LEVEL, }; diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 3837ca180d52..b2b23a6a497d 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -729,4 +729,6 @@ const struct btrfs_compress_op btrfs_zstd_compress = { .decompress_bio = zstd_decompress_bio, .decompress = zstd_decompress, .set_level = zstd_set_level, + .max_level = ZSTD_BTRFS_MAX_LEVEL, + .default_level = ZSTD_BTRFS_DEFAULT_LEVEL, }; From patchwork Fri Aug 9 14:55:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11086607 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47E991398 for ; Fri, 9 Aug 2019 14:54:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36B8C1FF41 for ; Fri, 9 Aug 2019 14:54:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B0A51FF83; Fri, 9 Aug 2019 14:54:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A86C41FF41 for ; Fri, 9 Aug 2019 14:54:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406320AbfHIOyg (ORCPT ); Fri, 9 Aug 2019 10:54:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:39746 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726140AbfHIOyg (ORCPT ); Fri, 9 Aug 2019 10:54:36 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 92517ACBA for ; Fri, 9 Aug 2019 14:54:34 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 8A239DA7C5; Fri, 9 Aug 2019 16:55:05 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 2/2] btrfs: compression: replace set_level callbacks by a common helper Date: Fri, 9 Aug 2019 16:55:05 +0200 Message-Id: X-Mailer: git-send-email 2.22.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The set_level callbacks do not do anything special and can be replaced by a helper that uses the levels defined in the tables. Signed-off-by: David Sterba --- fs/btrfs/compression.c | 20 ++++++++++++++++++-- fs/btrfs/compression.h | 9 ++------- fs/btrfs/lzo.c | 6 ------ fs/btrfs/zlib.c | 9 --------- fs/btrfs/zstd.c | 9 --------- 5 files changed, 20 insertions(+), 33 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 60c47b417a4b..9d08d56f2896 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -1039,7 +1039,7 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping, struct list_head *workspace; int ret; - level = btrfs_compress_op[type]->set_level(level); + level = btrfs_compress_set_level(type, level); workspace = get_workspace(type, level); ret = btrfs_compress_op[type]->compress_pages(workspace, mapping, start, pages, @@ -1611,7 +1611,23 @@ unsigned int btrfs_compress_str2level(unsigned int type, const char *str) level = 0; } - level = btrfs_compress_op[type]->set_level(level); + level = btrfs_compress_set_level(type, level); + + return level; +} + +/* + * Adjust @level according to the limits of the compression algorithm or + * fallback to default + */ +unsigned int btrfs_compress_get_level(int type, unsigned level) +{ + const struct btrfs_compress_op *ops = btrfs_compress_op[type]; + + if (level == 0) + level = ops->default_level; + else + level = min_t(unsigned int, level, ops->max_level); return level; } diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 07b2009dc63f..f0fc6304dfae 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -156,13 +156,6 @@ struct btrfs_compress_op { unsigned long start_byte, size_t srclen, size_t destlen); - /* - * This bounds the level set by the user to be within range of a - * particular compression type. It returns the level that will be used - * if the level is out of bounds or the default if 0 is passed in. - */ - unsigned int (*set_level)(unsigned int level); - /* Maximum level supported by the compression algorithm */ int max_level; int default_level; @@ -179,6 +172,8 @@ extern const struct btrfs_compress_op btrfs_zstd_compress; const char* btrfs_compress_type2str(enum btrfs_compression_type type); bool btrfs_compress_is_valid_type(const char *str, size_t len); +unsigned int btrfs_compress_set_level(int type, unsigned level); + int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end); #endif diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index adac6cb30d65..acad4174f68d 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -507,11 +507,6 @@ static int lzo_decompress(struct list_head *ws, unsigned char *data_in, return ret; } -static unsigned int lzo_set_level(unsigned int level) -{ - return 0; -} - const struct btrfs_compress_op btrfs_lzo_compress = { .init_workspace_manager = lzo_init_workspace_manager, .cleanup_workspace_manager = lzo_cleanup_workspace_manager, @@ -522,7 +517,6 @@ const struct btrfs_compress_op btrfs_lzo_compress = { .compress_pages = lzo_compress_pages, .decompress_bio = lzo_decompress_bio, .decompress = lzo_decompress, - .set_level = lzo_set_level, .max_level = 1, .default_level = 1, }; diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 03d6c3683bd9..df1aace5df50 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -418,14 +418,6 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in, return ret; } -static unsigned int zlib_set_level(unsigned int level) -{ - if (!level) - return BTRFS_ZLIB_DEFAULT_LEVEL; - - return min_t(unsigned int, level, 9); -} - const struct btrfs_compress_op btrfs_zlib_compress = { .init_workspace_manager = zlib_init_workspace_manager, .cleanup_workspace_manager = zlib_cleanup_workspace_manager, @@ -436,7 +428,6 @@ const struct btrfs_compress_op btrfs_zlib_compress = { .compress_pages = zlib_compress_pages, .decompress_bio = zlib_decompress_bio, .decompress = zlib_decompress, - .set_level = zlib_set_level, .max_level = 9, .default_level = BTRFS_ZLIB_DEFAULT_LEVEL, }; diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index b2b23a6a497d..0af4a5cd4313 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -710,14 +710,6 @@ static int zstd_decompress(struct list_head *ws, unsigned char *data_in, return ret; } -static unsigned int zstd_set_level(unsigned int level) -{ - if (!level) - return ZSTD_BTRFS_DEFAULT_LEVEL; - - return min_t(unsigned int, level, ZSTD_BTRFS_MAX_LEVEL); -} - const struct btrfs_compress_op btrfs_zstd_compress = { .init_workspace_manager = zstd_init_workspace_manager, .cleanup_workspace_manager = zstd_cleanup_workspace_manager, @@ -728,7 +720,6 @@ const struct btrfs_compress_op btrfs_zstd_compress = { .compress_pages = zstd_compress_pages, .decompress_bio = zstd_decompress_bio, .decompress = zstd_decompress, - .set_level = zstd_set_level, .max_level = ZSTD_BTRFS_MAX_LEVEL, .default_level = ZSTD_BTRFS_DEFAULT_LEVEL, };