From patchwork Mon Dec 16 17:17:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13910107 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B97B2066D8 for ; Mon, 16 Dec 2024 17:17:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369449; cv=none; b=MKXFtJ0EGWVuoFMtnXJhjYCcR1AcbtMximwUMt/Enp6MadqGM+S4F0gu26SO1yFU0na0FyPvbobZrQvo+5O/EeNOjweZSd8ZnwmaahRibhwmdXlJfj4P9Xp9Ipa8r3/OIaiioSlyvG14INGGoYqTiNJurQq6zau/U+pc84oVbKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369449; c=relaxed/simple; bh=Xyd6aPrGGEfG+FrodIgUFQcK0eeWL7TsbJ89e+b9R38=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ls67AYIMnDRxuFPc5ZkXr0B8zyADi4XknDbdWe25u+/4KbVrIhOUhP0NNkzjJgqMDoK3dolFUOB81RHzUsKr9Ku1Xpd5mwzlqMlpdL68k4NVd3X1UFEuuCigJF43UKKM+5QEQSUmGcKyhB9ewKR/4TXASRShfdtwWLKLRScrdWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WeXsYko9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WeXsYko9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17CECC4CEE0 for ; Mon, 16 Dec 2024 17:17:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734369448; bh=Xyd6aPrGGEfG+FrodIgUFQcK0eeWL7TsbJ89e+b9R38=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WeXsYko900qEaiKUSrchgSzLd1G0wKcX2Rf3N9UTPXujafH+0SZXRd3MqFem4wGQM cPiDn+yH7XwKSQKZG7uqa1UKUBOYbuYBb44MqT7ubFObIhKyj/UcyT1M2wH5E4oW3S 7KlLMNFm9IHi+CUbOrsW+2IpMZLTmcsHOyCVtOXlrYmkcwrqJI05Htznkolz3XvQTi glRWKZAlePMVmRE5WzSDV2FLzqu038wWVb5seqZpTPigi/nb9Trd8HDlRpUVUh7b9b QvMBxJT3zUBsT6qB+G134LfU6OZOs8vpDdn5aCILpzGGwMJaNnyFm7Ym7Og+5IN4w5 wXAfNQR+s/gPA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/9] btrfs: move abort_should_print_stack() to transaction.h Date: Mon, 16 Dec 2024 17:17:16 +0000 Message-Id: <4854187df58426b3435f576eb63fd3f87a479ffe.1734368270.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The function abort_should_print_stack() is declared in transaction.h but its definition is in ctree.c, which doesn't make sense since ctree.c is the btree implementation and the function is related to the transaction code. Move its definition into transaction.h as an inline function since it's a very short and trivial function, and also add the 'btrfs_' prefix into its name. This change also reduces the module size. Before this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1783148 161137 16920 1961205 1decf5 fs/btrfs/btrfs.ko After this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1782126 161045 16920 1960091 1de89b fs/btrfs/btrfs.ko Signed-off-by: Filipe Manana --- fs/btrfs/ctree.c | 16 ---------------- fs/btrfs/transaction.h | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 185985a337b3..99a58ede387e 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -225,22 +225,6 @@ noinline void btrfs_release_path(struct btrfs_path *p) } } -/* - * We want the transaction abort to print stack trace only for errors where the - * cause could be a bug, eg. due to ENOSPC, and not for common errors that are - * caused by external factors. - */ -bool __cold abort_should_print_stack(int error) -{ - switch (error) { - case -EIO: - case -EROFS: - case -ENOMEM: - return false; - } - return true; -} - /* * safely gets a reference on the root node of a tree. A lock * is not taken, so a concurrent writer may put a different node diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index 184fa5c0062a..9f7c777af635 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h @@ -227,7 +227,21 @@ static inline void btrfs_clear_skip_qgroup(struct btrfs_trans_handle *trans) delayed_refs->qgroup_to_skip = 0; } -bool __cold abort_should_print_stack(int error); +/* + * We want the transaction abort to print stack trace only for errors where the + * cause could be a bug, eg. due to ENOSPC, and not for common errors that are + * caused by external factors. + */ +static inline bool btrfs_abort_should_print_stack(int error) +{ + switch (error) { + case -EIO: + case -EROFS: + case -ENOMEM: + return false; + } + return true; +} /* * Call btrfs_abort_transaction as early as possible when an error condition is @@ -240,7 +254,7 @@ do { \ if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \ &((trans)->fs_info->fs_state))) { \ __first = true; \ - if (WARN(abort_should_print_stack(error), \ + if (WARN(btrfs_abort_should_print_stack(error), \ KERN_ERR \ "BTRFS: Transaction aborted (error %d)\n", \ (error))) { \ From patchwork Mon Dec 16 17:17:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13910108 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14C94206F0A for ; Mon, 16 Dec 2024 17:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369450; cv=none; b=bInV/dUuHwVSavMjouxy8IS9NIqwqhdLFSqyUvHFdI+3Xij76PHUzw/90dpQfytXcicsmtBQrKDHo7GB14KgT8xGSdghWyMYPt68xjk1UXy7ry1GUOlAyXNj9F82+AbCOmKgAHpNVBnbCXe6RVlZHPdPkXg8ZyXaClygY8c+jG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369450; c=relaxed/simple; bh=uqh/F2IDkqkoIMGP8UQa9BlDQEoE/LFE0Wkm7eVUFGg=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=efZ+6ikK8T0e8ekSBf5Dj+hYTiaqAtR2vJD1bwCX1I2Lpnd74TR6WX0DC/K+vx7A+TzB5iCB4MiIU1jbOq6sa0faZ2wcA58dpjVCVRC3dfnPynYWVhd1nXUauTVTcqzahbRFpQb02jSROSWU5TePuPUlW1nMyBpnQ/PE+wt8KWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rcExVcxw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rcExVcxw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17589C4AF09 for ; Mon, 16 Dec 2024 17:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734369449; bh=uqh/F2IDkqkoIMGP8UQa9BlDQEoE/LFE0Wkm7eVUFGg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rcExVcxwqS3o1yIwo6sFNy/mMHFOp60tNs7xlPM1on2WO1DV/AoW5K5CKhctzyOOC tT+CVKuT6KJilGSjc6It53DJE/S+NiF0t+bS2/Z/3Q/ZR14eaOOVtFGju0GOfDlgwJ CauEbFI2ept0xe71vWWefKM4eMCHC+JxPtc1FVoYFJz4n4Fa/P4dzEOlDyx0CcKS9H i5g8Jv5GkVCNI4sC0wLLiJTBbRHLIhxAk88WaAlMJ7G6NrowjtMsMlmo7Z1RZVJdef 56yq3xDPUi5C3Kg19laA8wOfGPPgIA/2s7DBohp16afOmcE7sufgre1Vri76SAT5Vm QLKaPytJsF9SA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/9] btrfs: move csum related functions from ctree.c into fs.c Date: Mon, 16 Dec 2024 17:17:17 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The ctree module is about the implementation of the btree data structure and not a place holder for generic filesystem things like the csum algorithm details. Move the functions related to the csum algorithm details away from ctree.c and into fs.c, which is a far better place for them. Also fix missing punctuation in comments and change one multiline comment to a single line comment since everything fits in under 80 characters. For some reason this also sligthly reduces the module's size. Before this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1782126 161045 16920 1960091 1de89b fs/btrfs/btrfs.ko After this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1782094 161045 16920 1960059 1de87b fs/btrfs/btrfs.ko Signed-off-by: Filipe Manana --- fs/btrfs/ctree.c | 51 ------------------------------------------------ fs/btrfs/ctree.h | 6 ------ fs/btrfs/fs.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/fs.h | 6 ++++++ 4 files changed, 55 insertions(+), 57 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 99a58ede387e..c93f52a30a16 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -37,19 +37,6 @@ static int push_node_left(struct btrfs_trans_handle *trans, static int balance_node_right(struct btrfs_trans_handle *trans, struct extent_buffer *dst_buf, struct extent_buffer *src_buf); - -static const struct btrfs_csums { - u16 size; - const char name[10]; - const char driver[12]; -} btrfs_csums[] = { - [BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" }, - [BTRFS_CSUM_TYPE_XXHASH] = { .size = 8, .name = "xxhash64" }, - [BTRFS_CSUM_TYPE_SHA256] = { .size = 32, .name = "sha256" }, - [BTRFS_CSUM_TYPE_BLAKE2] = { .size = 32, .name = "blake2b", - .driver = "blake2b-256" }, -}; - /* * The leaf data grows from end-to-front in the node. this returns the address * of the start of the last item, which is the stop of the leaf data stack. @@ -148,44 +135,6 @@ static inline void copy_leaf_items(const struct extent_buffer *dst, nr_items * sizeof(struct btrfs_item)); } -/* This exists for btrfs-progs usages. */ -u16 btrfs_csum_type_size(u16 type) -{ - return btrfs_csums[type].size; -} - -int btrfs_super_csum_size(const struct btrfs_super_block *s) -{ - u16 t = btrfs_super_csum_type(s); - /* - * csum type is validated at mount time - */ - return btrfs_csum_type_size(t); -} - -const char *btrfs_super_csum_name(u16 csum_type) -{ - /* csum type is validated at mount time */ - return btrfs_csums[csum_type].name; -} - -/* - * Return driver name if defined, otherwise the name that's also a valid driver - * name - */ -const char *btrfs_super_csum_driver(u16 csum_type) -{ - /* csum type is validated at mount time */ - return btrfs_csums[csum_type].driver[0] ? - btrfs_csums[csum_type].driver : - btrfs_csums[csum_type].name; -} - -size_t __attribute_const__ btrfs_get_num_csums(void) -{ - return ARRAY_SIZE(btrfs_csums); -} - struct btrfs_path *btrfs_alloc_path(void) { might_sleep(); diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 2c341956a01c..a1bab0b3f193 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -756,12 +756,6 @@ static inline bool btrfs_is_data_reloc_root(const struct btrfs_root *root) return root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID; } -u16 btrfs_csum_type_size(u16 type); -int btrfs_super_csum_size(const struct btrfs_super_block *s); -const char *btrfs_super_csum_name(u16 csum_type); -const char *btrfs_super_csum_driver(u16 csum_type); -size_t __attribute_const__ btrfs_get_num_csums(void); - /* * We use folio flag owner_2 to indicate there is an ordered extent with * unfinished IO. diff --git a/fs/btrfs/fs.c b/fs/btrfs/fs.c index 31c1648bc0b4..3756a3b9c9da 100644 --- a/fs/btrfs/fs.c +++ b/fs/btrfs/fs.c @@ -5,6 +5,55 @@ #include "fs.h" #include "accessors.h" +static const struct btrfs_csums { + u16 size; + const char name[10]; + const char driver[12]; +} btrfs_csums[] = { + [BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" }, + [BTRFS_CSUM_TYPE_XXHASH] = { .size = 8, .name = "xxhash64" }, + [BTRFS_CSUM_TYPE_SHA256] = { .size = 32, .name = "sha256" }, + [BTRFS_CSUM_TYPE_BLAKE2] = { .size = 32, .name = "blake2b", + .driver = "blake2b-256" }, +}; + +/* This exists for btrfs-progs usages. */ +u16 btrfs_csum_type_size(u16 type) +{ + return btrfs_csums[type].size; +} + +int btrfs_super_csum_size(const struct btrfs_super_block *s) +{ + u16 t = btrfs_super_csum_type(s); + + /* csum type is validated at mount time. */ + return btrfs_csum_type_size(t); +} + +const char *btrfs_super_csum_name(u16 csum_type) +{ + /* csum type is validated at mount time. */ + return btrfs_csums[csum_type].name; +} + +/* + * Return driver name if defined, otherwise the name that's also a valid driver + * name. + */ +const char *btrfs_super_csum_driver(u16 csum_type) +{ + /* csum type is validated at mount time */ + return btrfs_csums[csum_type].driver[0] ? + btrfs_csums[csum_type].driver : + btrfs_csums[csum_type].name; +} + +size_t __attribute_const__ btrfs_get_num_csums(void) +{ + return ARRAY_SIZE(btrfs_csums); +} + void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag, const char *name) { diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 79a1a3d6f04d..b05f2af97140 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -982,6 +982,12 @@ void btrfs_exclop_balance(struct btrfs_fs_info *fs_info, int btrfs_check_ioctl_vol_args_path(const struct btrfs_ioctl_vol_args *vol_args); +u16 btrfs_csum_type_size(u16 type); +int btrfs_super_csum_size(const struct btrfs_super_block *s); +const char *btrfs_super_csum_name(u16 csum_type); +const char *btrfs_super_csum_driver(u16 csum_type); +size_t __attribute_const__ btrfs_get_num_csums(void); + /* Compatibility and incompatibility defines */ void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag, const char *name); From patchwork Mon Dec 16 17:17:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13910109 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FC40207644 for ; Mon, 16 Dec 2024 17:17:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369451; cv=none; b=MXWJBeKsyos+VLbRJ0Zzbro680LPpvMGqfYiDchXwuXiol+IbfHp93+9Cmv9FTpCLbUz1IKR6HO3dzmqjFhp0qpzPnOvx/uHMHvGDqjrL8E5zEz/ql4JRxDrJdYLjfwIJrYtCgKG7tLczPpRal3s+FSwzTaM5fdaYAD19nvx4Is= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369451; c=relaxed/simple; bh=dP3Ckdy3Nb33xPgAef0Qj/1WsDhSW53bFnO+MaSP4/Y=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KLB29Os29uqLti8Eq6vdrAPNSgIaxD3FPsaDrF0BZ3ZE771IAtJtC7h5N/jlKMn2pg/DS3fsAS+CbYydm4tF0L0FOyuGuQC2twelGIg1zyTpT8hLuvw+G3pVHrJHn05DxX2odv3cxH28dWXH1WD0qelBgWmfySSISD7oH1dKgyg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hcQZ/+wz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hcQZ/+wz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17225C4CED0 for ; Mon, 16 Dec 2024 17:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734369450; bh=dP3Ckdy3Nb33xPgAef0Qj/1WsDhSW53bFnO+MaSP4/Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hcQZ/+wzpz//uN1KlI1Lqoc7bNig6mbf20wutgwPEeRlnuTYMw0vwI8nRMeDwOWvx +GHqx0PNEXax7xSGofhhQYygY2toigc1xZPw15AenOtsOX1k7/3s9eddRem+4LF5Gs yG+CKKvOBviUQuHbLEjEFSop8t3gqYHvM5VpEAUmMB9DxOV3Uog2R/pYgoaM/0hndJ AkO3mrUnP4anVSenT1bqA6fzTxmVNEGwKoP5I+iCHFLRVMzMDasz8tMt740J7hKPWU Hhiaz2wWPwIylPGc3qexqiIekBD8tFZIqwAkGR4oChTsP7qlb/iwoqRqXWzU5DNjkv sFi6v5IqL3RVg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/9] btrfs: move the exclusive operation functions into fs.c Date: Mon, 16 Dec 2024 17:17:18 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The declarations for the exclusive operation functions are located at fs.h but their definitions are in ioctl.c, which doesn't make much sense since (most of them) are used in several files other than ioctl.c. Since they are used in several files and they are generic enough, move them out of ioctl.c and into fs.c, even the ones that are currently only used at ioctl.c, for the sake of having them all in the same C file. This also reduces the module's size. Before this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1782094 161045 16920 1960059 1de87b fs/btrfs/btrfs.ko After this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1781492 161037 16920 1959449 1de619 fs/btrfs/btrfs.ko Signed-off-by: Filipe Manana --- fs/btrfs/fs.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/ioctl.c | 80 ----------------------------------------------- 2 files changed, 81 insertions(+), 80 deletions(-) diff --git a/fs/btrfs/fs.c b/fs/btrfs/fs.c index 3756a3b9c9da..09cfb43580cb 100644 --- a/fs/btrfs/fs.c +++ b/fs/btrfs/fs.c @@ -4,6 +4,7 @@ #include "ctree.h" #include "fs.h" #include "accessors.h" +#include "volumes.h" static const struct btrfs_csums { u16 size; @@ -54,6 +55,86 @@ size_t __attribute_const__ btrfs_get_num_csums(void) return ARRAY_SIZE(btrfs_csums); } +/* + * Start exclusive operation @type, return true on success. + */ +bool btrfs_exclop_start(struct btrfs_fs_info *fs_info, + enum btrfs_exclusive_operation type) +{ + bool ret = false; + + spin_lock(&fs_info->super_lock); + if (fs_info->exclusive_operation == BTRFS_EXCLOP_NONE) { + fs_info->exclusive_operation = type; + ret = true; + } + spin_unlock(&fs_info->super_lock); + + return ret; +} + +/* + * Conditionally allow to enter the exclusive operation in case it's compatible + * with the running one. This must be paired with btrfs_exclop_start_unlock() + * and btrfs_exclop_finish(). + * + * Compatibility: + * - the same type is already running + * - when trying to add a device and balance has been paused + * - not BTRFS_EXCLOP_NONE - this is intentionally incompatible and the caller + * must check the condition first that would allow none -> @type + */ +bool btrfs_exclop_start_try_lock(struct btrfs_fs_info *fs_info, + enum btrfs_exclusive_operation type) +{ + spin_lock(&fs_info->super_lock); + if (fs_info->exclusive_operation == type || + (fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED && + type == BTRFS_EXCLOP_DEV_ADD)) + return true; + + spin_unlock(&fs_info->super_lock); + return false; +} + +void btrfs_exclop_start_unlock(struct btrfs_fs_info *fs_info) +{ + spin_unlock(&fs_info->super_lock); +} + +void btrfs_exclop_finish(struct btrfs_fs_info *fs_info) +{ + spin_lock(&fs_info->super_lock); + WRITE_ONCE(fs_info->exclusive_operation, BTRFS_EXCLOP_NONE); + spin_unlock(&fs_info->super_lock); + sysfs_notify(&fs_info->fs_devices->fsid_kobj, NULL, "exclusive_operation"); +} + +void btrfs_exclop_balance(struct btrfs_fs_info *fs_info, + enum btrfs_exclusive_operation op) +{ + switch (op) { + case BTRFS_EXCLOP_BALANCE_PAUSED: + spin_lock(&fs_info->super_lock); + ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE || + fs_info->exclusive_operation == BTRFS_EXCLOP_DEV_ADD || + fs_info->exclusive_operation == BTRFS_EXCLOP_NONE || + fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED); + fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE_PAUSED; + spin_unlock(&fs_info->super_lock); + break; + case BTRFS_EXCLOP_BALANCE: + spin_lock(&fs_info->super_lock); + ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED); + fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE; + spin_unlock(&fs_info->super_lock); + break; + default: + btrfs_warn(fs_info, + "invalid exclop balance operation %d requested", op); + } +} + void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag, const char *name) { diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index dc5faa89cdba..0ede6a5524c2 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -403,86 +403,6 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap, return ret; } -/* - * Start exclusive operation @type, return true on success - */ -bool btrfs_exclop_start(struct btrfs_fs_info *fs_info, - enum btrfs_exclusive_operation type) -{ - bool ret = false; - - spin_lock(&fs_info->super_lock); - if (fs_info->exclusive_operation == BTRFS_EXCLOP_NONE) { - fs_info->exclusive_operation = type; - ret = true; - } - spin_unlock(&fs_info->super_lock); - - return ret; -} - -/* - * Conditionally allow to enter the exclusive operation in case it's compatible - * with the running one. This must be paired with btrfs_exclop_start_unlock and - * btrfs_exclop_finish. - * - * Compatibility: - * - the same type is already running - * - when trying to add a device and balance has been paused - * - not BTRFS_EXCLOP_NONE - this is intentionally incompatible and the caller - * must check the condition first that would allow none -> @type - */ -bool btrfs_exclop_start_try_lock(struct btrfs_fs_info *fs_info, - enum btrfs_exclusive_operation type) -{ - spin_lock(&fs_info->super_lock); - if (fs_info->exclusive_operation == type || - (fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED && - type == BTRFS_EXCLOP_DEV_ADD)) - return true; - - spin_unlock(&fs_info->super_lock); - return false; -} - -void btrfs_exclop_start_unlock(struct btrfs_fs_info *fs_info) -{ - spin_unlock(&fs_info->super_lock); -} - -void btrfs_exclop_finish(struct btrfs_fs_info *fs_info) -{ - spin_lock(&fs_info->super_lock); - WRITE_ONCE(fs_info->exclusive_operation, BTRFS_EXCLOP_NONE); - spin_unlock(&fs_info->super_lock); - sysfs_notify(&fs_info->fs_devices->fsid_kobj, NULL, "exclusive_operation"); -} - -void btrfs_exclop_balance(struct btrfs_fs_info *fs_info, - enum btrfs_exclusive_operation op) -{ - switch (op) { - case BTRFS_EXCLOP_BALANCE_PAUSED: - spin_lock(&fs_info->super_lock); - ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE || - fs_info->exclusive_operation == BTRFS_EXCLOP_DEV_ADD || - fs_info->exclusive_operation == BTRFS_EXCLOP_NONE || - fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED); - fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE_PAUSED; - spin_unlock(&fs_info->super_lock); - break; - case BTRFS_EXCLOP_BALANCE: - spin_lock(&fs_info->super_lock); - ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED); - fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE; - spin_unlock(&fs_info->super_lock); - break; - default: - btrfs_warn(fs_info, - "invalid exclop balance operation %d requested", op); - } -} - static int btrfs_ioctl_getversion(struct inode *inode, int __user *arg) { return put_user(inode->i_generation, arg); From patchwork Mon Dec 16 17:17:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13910110 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0AA720764C for ; Mon, 16 Dec 2024 17:17:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369451; cv=none; b=MsbcI37ejZy1KA34pifnyGfnaeUWlOOSOLaa9IqbRN/Z1iiePMyef2oj1M86rjM1Z3wsVKc3HrkcsS4UlPE6CXnIbWcRG9wfhVrO0/DAmIc2aT64g1BptoR5ttE0u08MnVxxRNPfh3KKQd13M/414comNCTbDZMfpNMtcS/fnWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369451; c=relaxed/simple; bh=syc3Osv6jDM27BPrwwZx0fYRc6h6k16GBN3Sle/H91s=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UlJU6/Zj17JauNQFt6Fx7sPCD1LZVbZaLVdLqRQ+eg3UzjSyAbAK3v/J0AAO+Fzaj16rq1tleNkQ6MOlUQFOhlvinIsdtlkY3qFDofoFXZYpJfExQmm5+Nz0t2n9KzuuNRq0g2POJhYzFzWHWcsLVwb05i1pEN2o+lS+XMiq5GE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VsVO1Ugz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VsVO1Ugz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 149B3C4CEDE for ; Mon, 16 Dec 2024 17:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734369451; bh=syc3Osv6jDM27BPrwwZx0fYRc6h6k16GBN3Sle/H91s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VsVO1UgzpV+4c5d+5w5ath6UIOd/azTKcFtra/gDnuPLA0YRIkBxgBqhWOc/+DQEU 62pRilsZsLQTvmvMoSq7GoNa3EY5OSQqUJ4lssQy3kO4Jw6pIGZnZtNWJYrghYxM5W LS35fZGGJWa3wa4HeuLoVLlnJcP4Rne19vfZB5Aw7MVLK+JgBA2PLrO1CukbJvX3qZ rH/v8XfNE/HYlDu+gNilsWS7Gl5wQL3nEnWTDbGbO1YudkWmiG0qT6oWwUefJaFNIr Nu5aTNvLXq8w0vPPWUgsGiqBZBEQMD0xnFNZ4szgC+bh1BapWs85gU7KuhK+FNgcRB GGCJBH+vdxnkw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/9] btrfs: move btrfs_is_empty_uuid() from ioctl.c into fs.c Date: Mon, 16 Dec 2024 17:17:19 +0000 Message-Id: <7aef21820a6bad0e41699f18660038546adbbc9c.1734368270.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana It's a generic helper not specific to ioctls and used in several places, so move it out from ioctl.c and into fs.c. While at it change its return type from int to bool and declare the loop variable in the loop itself. This also slightly reduces the module's size. Before this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1781492 161037 16920 1959449 1de619 fs/btrfs/btrfs.ko After this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1781340 161037 16920 1959297 1de581 fs/btrfs/btrfs.ko Signed-off-by: Filipe Manana --- fs/btrfs/fs.c | 9 +++++++++ fs/btrfs/fs.h | 2 ++ fs/btrfs/ioctl.c | 11 ----------- fs/btrfs/ioctl.h | 1 - 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/fs.c b/fs/btrfs/fs.c index 09cfb43580cb..06a863252a85 100644 --- a/fs/btrfs/fs.c +++ b/fs/btrfs/fs.c @@ -55,6 +55,15 @@ size_t __attribute_const__ btrfs_get_num_csums(void) return ARRAY_SIZE(btrfs_csums); } +bool __pure btrfs_is_empty_uuid(const u8 *uuid) +{ + for (int i = 0; i < BTRFS_UUID_SIZE; i++) { + if (uuid[i] != 0) + return false; + } + return true; +} + /* * Start exclusive operation @type, return true on success. */ diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index b05f2af97140..15c26c6f4d6e 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -988,6 +988,8 @@ const char *btrfs_super_csum_name(u16 csum_type); const char *btrfs_super_csum_driver(u16 csum_type); size_t __attribute_const__ btrfs_get_num_csums(void); +bool __pure btrfs_is_empty_uuid(const u8 *uuid); + /* Compatibility and incompatibility defines */ void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag, const char *name); diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 0ede6a5524c2..7872de140489 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -471,17 +471,6 @@ static noinline int btrfs_ioctl_fitrim(struct btrfs_fs_info *fs_info, return ret; } -int __pure btrfs_is_empty_uuid(const u8 *uuid) -{ - int i; - - for (i = 0; i < BTRFS_UUID_SIZE; i++) { - if (uuid[i]) - return 0; - } - return 1; -} - /* * Calculate the number of transaction items to reserve for creating a subvolume * or snapshot, not including the inode, directory entries, or parent directory. diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index 2b760c8778f8..ce915fcda43b 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -19,7 +19,6 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry, struct fileattr *fa); int btrfs_ioctl_get_supported_features(void __user *arg); void btrfs_sync_inode_flags_to_i_flags(struct inode *inode); -int __pure btrfs_is_empty_uuid(const u8 *uuid); void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info, struct btrfs_ioctl_balance_args *bargs); int btrfs_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags); From patchwork Mon Dec 16 17:17:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13910111 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B382E207675 for ; Mon, 16 Dec 2024 17:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369452; cv=none; b=QQvCf6KcUevGg11RSXEhquDsP+tK9qWXE2xtY0eY48MYp5cfFcdPcQlKL7tDl3HQuNxEuBLl1LAtsQa+qGk44klIjxPk4KdKJ+2SsAota7vOGo2EFFG+jXjCX1S5EiS2De8Y9bR5zmUf7they3dyMLamMUdJjk66kSxiUN/TPtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369452; c=relaxed/simple; bh=OL1tO4DaYfFI4YjRiNM8vW+MNQ6TNq9bMwLKKx2xOPA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pIWuPkb4JpHzkNGyB2ekcUOOhHYq1W3cDcwDGnfmDRZCYI6I6Q9W5ZqNk42k6JKyCC0vIoV0n4eHLR4b5H9OHWpsFGCvT1Tev5/G9UkLict6hcGcJWvHuQJU4yqSc26LkekWiVUyPDW6U3mq/6cD7doFRMrFVoAiEBkJhJ+NUHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NDyat6Om; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NDyat6Om" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14342C4CEDD for ; Mon, 16 Dec 2024 17:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734369452; bh=OL1tO4DaYfFI4YjRiNM8vW+MNQ6TNq9bMwLKKx2xOPA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NDyat6Omn5jE7rmMhTi2DMzJ73S4Y30V1BQj0iFTY1zkQkro5zDhHFbOudx9bPL33 V9RHLt2t9wm7E3OXhC8d6TTConVqHEqOnbk+7lwOIOQs1ILONrpddghkLiD5fX36EV VE3ppdRWRaiVFNSX2VQh2+ylXY1qG1e/NN1gsI6SkLD1Y2GKE1HIYAc9Hu5XJYfjYO iZZIsWVx8dVvCQ2I0H+GpljXAzwBHOV10oee7YtE4TJgvWZplE83LWhBxdeK/13yaV ef7uFtJ+YateX0g8L+1j59idq6DV+5/LtcWH4ZGRpy+Ox7mIaIr8G7H2kNqmg3gTv7 3T9xpSGtgRk6A== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 5/9] btrfs: move the folio ordered helpers from ctree.h into fs.h Date: Mon, 16 Dec 2024 17:17:20 +0000 Message-Id: <730791a450c2fcee923609f85b9d2cb303aebcac.1734368270.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The folio ordered helper macros are defined at ctree.h but this is not the best place since ctree.{h,c} is all about the btree data structure implementation and not a generic module. So move these macros into the fs.h header. Signed-off-by: Filipe Manana --- fs/btrfs/ctree.h | 8 -------- fs/btrfs/fs.h | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index a1bab0b3f193..3d9855d30057 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -756,12 +756,4 @@ static inline bool btrfs_is_data_reloc_root(const struct btrfs_root *root) return root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID; } -/* - * We use folio flag owner_2 to indicate there is an ordered extent with - * unfinished IO. - */ -#define folio_test_ordered(folio) folio_test_owner_2(folio) -#define folio_set_ordered(folio) folio_set_owner_2(folio) -#define folio_clear_ordered(folio) folio_clear_owner_2(folio) - #endif diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 15c26c6f4d6e..7a27f5fe9bc2 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -1066,6 +1066,14 @@ static inline void btrfs_wake_unfinished_drop(struct btrfs_fs_info *fs_info) (unlikely(test_bit(BTRFS_FS_STATE_LOG_CLEANUP_ERROR, \ &(fs_info)->fs_state))) +/* + * We use folio flag owner_2 to indicate there is an ordered extent with + * unfinished IO. + */ +#define folio_test_ordered(folio) folio_test_owner_2(folio) +#define folio_set_ordered(folio) folio_set_owner_2(folio) +#define folio_clear_ordered(folio) folio_clear_owner_2(folio) + #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS #define EXPORT_FOR_TESTS From patchwork Mon Dec 16 17:17:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13910112 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05C11207A0E for ; Mon, 16 Dec 2024 17:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369454; cv=none; b=u+l6C3mZ3QbmqT+2zBJzhQbNlCiaz4qg2b5NoLzUW1aYSpJMgYvkRpsHUm3WaIB63WaHJmlcFqaNRtyYDTAtgtIs/Ht2+4JQ2KiSOlFiwSoEkIr0XUXEapV03EcEpHEcqLqPVwdhM7HMTggeiqv+33JS8xJD8ytSEYpgAOLiTxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369454; c=relaxed/simple; bh=LQf6MsALj6WrAaHOoGYdWNSoVfYsf+QQQ228dnO2TAg=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Acer+gzu2yILAwbd7/K0IVIZrnYvfZyj07gd1kwmu4Ft3NkJyT/SvCsSa4E3uRhAYZOtp0HOLAVg5a5gpXK2O8Q48j0084/yDvF2xKofS12HDc+pFUqW9rnGYH/GBq4afMiY+/n3CNgPY6n+S4Paut/hWfk57QHYsnLix8oX/lw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SoEKt6s6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SoEKt6s6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 145D6C4CEDE for ; Mon, 16 Dec 2024 17:17:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734369453; bh=LQf6MsALj6WrAaHOoGYdWNSoVfYsf+QQQ228dnO2TAg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=SoEKt6s6VpOgOosXN0ZgAbBnyMXqeA+wL+bXTmx9LW8A0gDkHxqBEYsdn8Ue4G8lO cX4GqtrVtT+IqBjwnPbkmLoLjFafWXfy8hD9XEVTwJoVVyoUSUZdlvkxb4c/K1hA/a 7IvTtCBqy1tDJQUySUEmLiLcjuELf/USi2TcWLoMBRpdc5GQqM8x8aA1YArxlsE7T2 H9hjVmqLgnOCeShU1/oqpLTQRL3zifCZ0vkIAtQ02EM3qILuE0IkGobYjoU0HyeSVb r/VL8PoOBxBMufC8q2t8TMX4HKx1FSayGUkQ91lNwInyxayTgrHR2GILRkd1oaKwm4 +kvTogS+sIOpA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 6/9] btrfs: move BTRFS_BYTES_TO_BLKS() into fs.h Date: Mon, 16 Dec 2024 17:17:21 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Currently BTRFS_BYTES_TO_BLKS() is defined in ctree.h but it's not related at all to the btree data structure, so move it into fs.h. Signed-off-by: Filipe Manana --- fs/btrfs/ctree.h | 3 --- fs/btrfs/fs.h | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 3d9855d30057..bf054470dcd0 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -506,9 +506,6 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item); } -#define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \ - ((bytes) >> (fs_info)->sectorsize_bits) - static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping) { return mapping_gfp_constraint(mapping, ~__GFP_FS); diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 7a27f5fe9bc2..dd1a82297d4c 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -953,6 +953,8 @@ static inline u64 btrfs_calc_metadata_size(const struct btrfs_fs_info *fs_info, #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \ sizeof(struct btrfs_item)) +#define BTRFS_BYTES_TO_BLKS(fs_info, bytes) ((bytes) >> (fs_info)->sectorsize_bits) + static inline bool btrfs_is_zoned(const struct btrfs_fs_info *fs_info) { return IS_ENABLED(CONFIG_BLK_DEV_ZONED) && fs_info->zone_size > 0; From patchwork Mon Dec 16 17:17:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13910113 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0617207A22 for ; Mon, 16 Dec 2024 17:17:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369454; cv=none; b=qunA9ZbxIjRfVM+19YxDoS3RHWDS3B6F06bsYcIWq7pdOqInq5TzBS/yIyF/CjE6skmiggccUeDr4ZOk1WMGQ9A22yF6XcNWGmOwp6q2Dj6CgdOBrcY1qFBCmWODsrkTMdPaBr7tFB+uKylQLRz1mI5dysfWakxzWlmE9u30Y0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369454; c=relaxed/simple; bh=XefyvdWOX0X0kwSr4QsRVQ9z2/IN48WK4VajsRCC9wI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KJ7CYBN5fEpL6pXPbOGW/6LfkPaF5F8n0DZfCC7Ek3cT39E/WDyGc5jSSlTmRWz+WGYaOQ58kMe+/skoouDreIl5ApBDbZY7erKn0FBnsOz1YUpl6DtA7RerQzdd2FuHqP88TvGaYpn+nbqbCn1DgcO7qeivV1zw0I81uFKmGf0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VruPtjEX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VruPtjEX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12F00C4CED0 for ; Mon, 16 Dec 2024 17:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734369454; bh=XefyvdWOX0X0kwSr4QsRVQ9z2/IN48WK4VajsRCC9wI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VruPtjEXu1/lYMcIbSixXZonujg1/W+sFnr4nuS3nsXgNSMRmIWsgWi7lvLBmbR2z I454MBVo+tcesVaNuQdF+VjHfXLTOguAsqHVoNkvJ+I3qLmeSCA+NI81tVffUaqNkO mT+DXkhIsC8mfwMvdmZxz1QG6muIEKtXN3tA1QG8svigEwD2riOTg0I001WuXKvyL/ 5MYtqSgt17MfLI/EZNcDBC58qwVrI6uXRoJqZgXWtAFqyw1woRLy+ffRvYLfMjr8Gk FaUCrT7b3nUHLzJBFxn1DRnzRiQuaY7tvXNLjKwOqj+z2PQKlUaxQmSiq7aHxM53h/ mOeKfIxbv/uMQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 7/9] btrfs: move btrfs_alloc_write_mask() into fs.h Date: Mon, 16 Dec 2024 17:17:22 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Currently btrfs_alloc_write_mask() is defined in ctree.h but it's not related at all to the btree data structure, so move it into fs.h. Signed-off-by: Filipe Manana --- fs/btrfs/ctree.h | 6 ------ fs/btrfs/fs.h | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index bf054470dcd0..53f9fc04f66f 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -7,7 +7,6 @@ #define BTRFS_CTREE_H #include "linux/cleanup.h" -#include #include #include #include @@ -506,11 +505,6 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item); } -static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping) -{ - return mapping_gfp_constraint(mapping, ~__GFP_FS); -} - void btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info, u64 start, u64 end); int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes, u64 *actual_bytes); diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index dd1a82297d4c..1113646374f3 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -887,6 +888,11 @@ struct btrfs_fs_info { #define inode_to_fs_info(_inode) (BTRFS_I(_Generic((_inode), \ struct inode *: (_inode)))->root->fs_info) +static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping) +{ + return mapping_gfp_constraint(mapping, ~__GFP_FS); +} + static inline u64 btrfs_get_fs_generation(const struct btrfs_fs_info *fs_info) { return READ_ONCE(fs_info->generation); From patchwork Mon Dec 16 17:17:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13910114 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C0B02063D0 for ; Mon, 16 Dec 2024 17:17:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369456; cv=none; b=Yy6tmfbJfoK2SJu0rqNV+eujFyR7fj1EPM5t+PYU/YZFqNetR2WTTlmyzajuYt0cf94B+eRLN2cmrvJzUtwlRXCzsr7P7FyiuRAsf7iDADVk7e6v+LldGEUnBZd0HiBxMgxu5E969b49X82qvshK8hgvCDgP/jesIMkignGZ7ms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369456; c=relaxed/simple; bh=1suv9f2S9kTUFSV2EflrnOa4ShVUnmGdE64ARGDAt8U=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Tvb2dqlXzZHhtPiZDqjAcxRzsKrkaiBxge5MFmqlCb9ufpfFQPBKO/KSxtFIUIKxmFO6usbOJZTTbjIYi3QLljrfOn5WLX7LdjUHuvMQaG0xF2MAAQxNV48exJBGL9TUADcu+3OJcwPr7KgN3/hBqQGYB6/5WbyvVY53ZjugzkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nNLNmkvl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nNLNmkvl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F660C4CED0 for ; Mon, 16 Dec 2024 17:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734369455; bh=1suv9f2S9kTUFSV2EflrnOa4ShVUnmGdE64ARGDAt8U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nNLNmkvl2WQ6OtlR8mJPuGaI8NOVXllT4hPOdl8qC4MQsWjxb1k3stJu9C0f6AUVc 7BcPu/j7JH5BwLnIyM4AGD5uPlqZRh27aB3MlwBgbnk/RKyFTg1Eb03Snl7Uu/B3H6 PLP8k1SKQMHCMlPcXgYq/2EAUJEFOjnRjfhtmXy5+OORy7wOPhipJddOnd74PmMPD6 H80uWZvoNbpz4nJbAICixgLqDyr1xl73cy5/FLd9mSzeYK15zDm1bebnjm0FZflRMU HDbP/5EDuPWFA96zkLh5KJtSxIKNZTBKtoCk1ruKNzcPcGQMS4xE8XdhpWb0pU3aP5 V5nlr7DP6uovA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 8/9] btrfs: move extent-tree function declarations out of ctree.h Date: Mon, 16 Dec 2024 17:17:23 +0000 Message-Id: <9b4b5042a21425eedfa2b5d3faecccf70704cf10.1734368270.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana We have 3 functions that have their prototypes declared in ctree.h but they are defined at extent-tree.c and they are unrelated to the btree data structure. Move the prototypes out of ctree.h and into extent-tree.h. Signed-off-by: Filipe Manana --- fs/btrfs/ctree.h | 5 ----- fs/btrfs/extent-tree.h | 4 ++++ fs/btrfs/free-space-cache.c | 2 +- fs/btrfs/volumes.c | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 53f9fc04f66f..cdf10cca8194 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -505,11 +505,6 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item); } -void btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info, u64 start, u64 end); -int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, - u64 num_bytes, u64 *actual_bytes); -int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range); - /* ctree.c */ int __init btrfs_ctree_init(void); void __cold btrfs_ctree_exit(void); diff --git a/fs/btrfs/extent-tree.h b/fs/btrfs/extent-tree.h index 46b8e19022df..cfa52264f678 100644 --- a/fs/btrfs/extent-tree.h +++ b/fs/btrfs/extent-tree.h @@ -162,5 +162,9 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *node, struct extent_buffer *parent); +void btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info, u64 start, u64 end); +int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, + u64 num_bytes, u64 *actual_bytes); +int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range); #endif diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index cfa52ef40b06..17707c898eae 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -12,7 +12,7 @@ #include #include #include -#include "ctree.h" +#include "extent-tree.h" #include "fs.h" #include "messages.h" #include "misc.h" diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1cccaf9c2b0d..7ebfc978cade 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -13,8 +13,8 @@ #include #include #include "misc.h" -#include "ctree.h" #include "disk-io.h" +#include "extent-tree.h" #include "transaction.h" #include "volumes.h" #include "raid56.h" From patchwork Mon Dec 16 17:17:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13910115 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA393207DF2 for ; Mon, 16 Dec 2024 17:17:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369456; cv=none; b=WhzMqmxmciIN3gpR3jRzWbSgTqxorE6AUwgaTvYxKx+6E/reWno6/lPkFlEBVQPR3Bvnc6ytaHsPnM4A1nQ47MPgdqvgJnax0AgiUSkTZFhZoNlK8nGhrD8ljLdu4Sx7gVFTECjeNrZJvqGyeJ5JQP9EogV2/N3xrQVmeO0ri1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369456; c=relaxed/simple; bh=TWfop68J0/V4tNQYLbzq6QHeylMcxgdDRrgDl64LAKc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t0gzyLEX9vXVseixTeCw9+nTif4SBk03rtuVCfy1h5pRlf90JtuX/bzD4vQLLjmuwOc0bv2LB0egWuSNEbowZyqjvsKrc0bEF4CNPss1J8eNxRiF+xO6RSKJwUyJp4RsnietMg3rFVey/RhV01p/dFNF846T7z43/AUmHLV/YXI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EV+9zWhw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EV+9zWhw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C307C4CED4 for ; Mon, 16 Dec 2024 17:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734369456; bh=TWfop68J0/V4tNQYLbzq6QHeylMcxgdDRrgDl64LAKc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EV+9zWhw4eBGiTYrpuqGZ2W8TmzwUxZ3xw7ygTKUh/ZoNL9y5a5P1VALPfDdjcVDt jg4ADYtDQsYlFzc7OLyBKtCmkHTDCwqY5cPmdr2WVBZRXwMexxgBsh1Md+CBQnha5W ZnnqBy4iovorblJYvn5Qb89be7Cm3i666LtCXgN7mW2d8/S3GEonDLlRBo4pUM0BRA rRX9iD5DYjATa8TcgZPTHNFV0Ea70Hqj3D3L3hdZlzn2CtzrcHhxdx21o09TEFb6nb 8nhuca/499re9zKRhXutvpCtpfncijIa7FASiVHOKLBMVDSrrmbEG+8TUYyxsMMhhJ GwPBetR2Trt0w== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 9/9] btrfs: remove pointless comment from ctree.h Date: Mon, 16 Dec 2024 17:17:24 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana It's pointless to have a comment above the prototype declarations of btrfs_ctree_init() and btrfs_ctree_exit() mentioning that they are declared in ctree.c. This is from the old days when ctree.h was used to place anything that didn't fit in any other file. So remove it. Signed-off-by: Filipe Manana --- fs/btrfs/ctree.h | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index cdf10cca8194..1096a80a64e7 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -505,7 +505,6 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item); } -/* ctree.c */ int __init btrfs_ctree_init(void); void __cold btrfs_ctree_exit(void);