Self-test cleanups
David Sterba
maintainercover Self-test cleanups
I've noticed a new use of the STATIC macro in Nikolay's patches cleaning up delayed refs. My series removes the macro and does a other minor reorganization to reduce ifdefs used in the test code.
David Sterba (4):
btrfs: tests: add separate stub for find_lock_delalloc_range
btrfs: tests: move testing members of struct btrfs_root to the end
btrfs: tests: group declarations of self-test helpers
btrfs: tests: polish ifdefs around testing helper
fs/btrfs/ctree.h | 28 +++++++++++----------------- fs/btrfs/extent_io.c | 13 ++++++++++++- fs/btrfs/extent_io.h | 2 +- fs/btrfs/tests/extent-io-tests.c | 10 +++++----- 4 files changed, 29 insertions(+), 24 deletions(-)
Signature · 1 line
2.18.0
David Sterba
maintainerPATCH 1/4 btrfs: tests: add separate stub for find_lock_delalloc_range
The helper find_lock_delalloc_range is now conditionally built static, dpending on whether the self-tests are enabled or not. There's a macro that is suppsed to hide the export, used only once. To discourage further use, drop it an add a public stub for the helper required by tests.
--- fs/btrfs/ctree.h | 6 ------ fs/btrfs/extent_io.c | 13 ++++++++++++- fs/btrfs/extent_io.h | 2 +- fs/btrfs/tests/extent-io-tests.c | 10 +++++----- 4 files changed, 18 insertions(+), 13 deletions(-)
fs/btrfs/ctree.h +0 -6
@@ -41,12 +41,6 @@ extern struct kmem_cache *btrfs_path_cachep;extern struct kmem_cache *btrfs_free_space_cachep;struct btrfs_ordered_sum ; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -#define STATIC noinline -#else -#define STATIC static noinline -#endif -#define BTRFS_MAGIC 0x4D5F53665248425FULL/* ascii _BHRfS_M, no null */ #define BTRFS_MAX_MIRRORS 3
fs/btrfs/extent_io.c +12 -1
@@ -1568,7 +1568,7 @@ static noinline int lock_delalloc_pages(struct inode *inode,* * 1 is returned if we find something, 0 if nothing was in the tree */ -STATIC u64 find_lock_delalloc_range(struct inode *inode, +static u64 find_lock_delalloc_range (struct inode *inode,struct extent_io_tree *tree,struct page *locked_page,u64 *start,u64 *end,u64 max_bytes)
@@ -1648,6 +1648,17 @@ STATIC u64 find_lock_delalloc_range(struct inode *inode,return found; } +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +u64 btrfs_find_lock_delalloc_range (struct inode *inode, +struct extent_io_tree *tree, +struct page *locked_page,u64 *start, +u64 *end,u64 max_bytes) +{ +return find_lock_delalloc_range (inode, tree, locked_page, start, end, + max_bytes); +} +#endif + static int __process_pages_contig(struct address_space *mapping, struct page *locked_page, pgoff_t start_index, pgoff_t end_index,
fs/btrfs/extent_io.h +1 -1
@@ -546,7 +546,7 @@ int free_io_failure(struct extent_io_tree *failure_tree,struct extent_io_tree *io_tree, struct io_failure_record *rec);#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -noinline u64 find_lock_delalloc_range(struct inode *inode, +u64 btrfs_find_lock_delalloc_range (struct inode *inode,struct extent_io_tree *tree,struct page *locked_page,u64 *start,u64 *end,u64 max_bytes);
fs/btrfs/tests/extent-io-tests.c +5 -5
@@ -106,7 +106,7 @@ static int test_find_delalloc(u32 sectorsize)set_extent_delalloc (&tmp,0 , sectorsize -1 ,0 ,NULL ); start =0 ; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("should have found at least one delalloc" );
@@ -137,7 +137,7 @@ static int test_find_delalloc(u32 sectorsize)set_extent_delalloc (&tmp, sectorsize, max_bytes -1 ,0 ,NULL ); start = test_start; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("couldn't find delalloc in our range" );
@@ -171,7 +171,7 @@ static int test_find_delalloc(u32 sectorsize) } start = test_start; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (found) {test_err ("found range when we shouldn't have" );
@@ -192,7 +192,7 @@ static int test_find_delalloc(u32 sectorsize)set_extent_delalloc (&tmp, max_bytes, total_dirty -1 ,0 ,NULL ); start = test_start; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("didn't find our range" );
@@ -233,7 +233,7 @@ static int test_find_delalloc(u32 sectorsize)* this changes at any point in the future we will need to fix this * tests expected behavior. */ - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("didn't find our range" );
Signature · 1 line
2.18.0
Re: [PATCH 1/4] btrfs: tests: add separate stub for find_lock_delalloc_range
Quoted 36 lines · David Sterba
The helper
find_lock_delalloc_rangeis now conditionally built static, dpending on whether the self-tests are enabled or not. There's a macro that is suppsed to hide the export, used only once. To discourage further use, drop it an add a public stub for the helper required by tests.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ctree.h | 6 ------ fs/btrfs/extent_io.c | 13 ++++++++++++- fs/btrfs/extent_io.h | 2 +- fs/btrfs/tests/extent-io-tests.c | 10 +++++----- 4 files changed, 18 insertions(+), 13 deletions(-)fs/btrfs/ctree.h +0
-6@@ -41,12 +41,6 @@ extern struct kmem_cache *btrfs_path_cachep;extern struct kmem_cache *btrfs_free_space_cachep;struct btrfs_ordered_sum ; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -#define STATIC noinline -#else -#define STATIC static noinline -#endif -#define BTRFS_MAGIC 0x4D5F53665248425FULL/* ascii _BHRfS_M, no null */ #define BTRFS_MAX_MIRRORS 3fs/btrfs/extent_io.c +0
-0
fs/btrfs/extent_io.c static noinline int lock_delalloc_pages(struct inode *inode, · line 1571
Quoted 5 lines
fs/btrfs/extent_io.c +1
-1@@ -1568,7 +1568,7 @@ static noinline int lock_delalloc_pages(struct inode *inode,* * 1 is returned if we find something, 0 if nothing was in the tree */ -STATIC u64 find_lock_delalloc_range(struct inode *inode, +static u64 find_lock_delalloc_range(struct inode *inode,
Now this won't be noinline, was that intentional? It has been since way back in d352ac68148b ("Btrfs: add and improve comments"), presumably because Chris wanted it in stack traces.
Re: [PATCH 1/4] btrfs: tests: add separate stub for find_lock_delalloc_range
Quoted 31 lines · Omar Sandoval
Quoted 30 lines · David Sterba
The helper
find_lock_delalloc_rangeis now conditionally built static, dpending on whether the self-tests are enabled or not. There's a macro that is suppsed to hide the export, used only once. To discourage further use, drop it an add a public stub for the helper required by tests.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ctree.h | 6 ------ fs/btrfs/extent_io.c | 13 ++++++++++++- fs/btrfs/extent_io.h | 2 +- fs/btrfs/tests/extent-io-tests.c | 10 +++++----- 4 files changed, 18 insertions(+), 13 deletions(-)fs/btrfs/ctree.h +0
-6@@ -41,12 +41,6 @@ extern struct kmem_cache *btrfs_path_cachep;extern struct kmem_cache *btrfs_free_space_cachep;struct btrfs_ordered_sum ; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -#define STATIC noinline -#else -#define STATIC static noinline -#endif -#define BTRFS_MAGIC 0x4D5F53665248425FULL/* ascii _BHRfS_M, no null */
Quoted 15 lines
fs/btrfs/extent_io.c static noinline int lock_delalloc_pages(struct inode *inode, · line 1571
Quoted 11 lines
fs/btrfs/ctree.h +0
-0#define BTRFS_MAX_MIRRORS 3fs/btrfs/extent_io.c +1
-1@@ -1568,7 +1568,7 @@ static noinline int lock_delalloc_pages(struct inode *inode,* * 1 is returned if we find something, 0 if nothing was in the tree */ -STATIC u64 find_lock_delalloc_range(struct inode *inode, +static u64 find_lock_delalloc_range(struct inode *inode,Now this won't be noinline, was that intentional? It has been since way back in
d352ac68148b("Btrfs: add and improve comments"), presumably because Chris wanted it in stack traces.
Heh, the commit is from 2008, besides others removes the original TODO, I think there were way more important things to do at that time than noinline, but you're right.
Removing noinline was not intentional and it would be better to see it on the stack. As there's only one caller, the function will most likely be inlined from writepage_delalloc. I'll update it to noinline_for_stack.
David Sterba
maintainerPATCH v2 1/4 btrfs: tests: add separate stub for find_lock_delalloc_range
In reply to Omar SandovalThe helper find_lock_delalloc_range is now conditionally built static, dpending on whether the self-tests are enabled or not. There's a macro that is supposed to hide the export, used only once. To discourage further use, drop it an add a public wrapper for the helper needed by tests.
---
v2:
- add noinline_for_stack back
fs/btrfs/ctree.h | 6 ------ fs/btrfs/extent_io.c | 13 ++++++++++++- fs/btrfs/extent_io.h | 2 +- fs/btrfs/tests/extent-io-tests.c | 10 +++++----- 4 files changed, 18 insertions(+), 13 deletions(-)
fs/btrfs/ctree.h +0 -6
@@ -41,12 +41,6 @@ extern struct kmem_cache *btrfs_path_cachep;extern struct kmem_cache *btrfs_free_space_cachep;struct btrfs_ordered_sum ; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -#define STATIC noinline -#else -#define STATIC static noinline -#endif -#define BTRFS_MAGIC 0x4D5F53665248425FULL/* ascii _BHRfS_M, no null */ #define BTRFS_MAX_MIRRORS 3
fs/btrfs/extent_io.c +12 -1
@@ -1568,7 +1568,7 @@ static noinline int lock_delalloc_pages(struct inode *inode,* * 1 is returned if we find something, 0 if nothing was in the tree */ -STATIC u64 find_lock_delalloc_range(struct inode *inode, +static noinline_for_stack u64 find_lock_delalloc_range(struct inode *inode,struct extent_io_tree *tree,struct page *locked_page,u64 *start,u64 *end,u64 max_bytes)
@@ -1648,6 +1648,17 @@ STATIC u64 find_lock_delalloc_range(struct inode *inode,return found; } +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +u64 btrfs_find_lock_delalloc_range (struct inode *inode, +struct extent_io_tree *tree, +struct page *locked_page,u64 *start, +u64 *end,u64 max_bytes) +{ +return find_lock_delalloc_range (inode, tree, locked_page, start, end, + max_bytes); +} +#endif + static int __process_pages_contig(struct address_space *mapping, struct page *locked_page, pgoff_t start_index, pgoff_t end_index,
fs/btrfs/extent_io.h +1 -1
@@ -546,7 +546,7 @@ int free_io_failure(struct extent_io_tree *failure_tree,struct extent_io_tree *io_tree, struct io_failure_record *rec);#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -noinline u64 find_lock_delalloc_range(struct inode *inode, +u64 btrfs_find_lock_delalloc_range (struct inode *inode,struct extent_io_tree *tree,struct page *locked_page,u64 *start,u64 *end,u64 max_bytes);
fs/btrfs/tests/extent-io-tests.c +5 -5
@@ -106,7 +106,7 @@ static int test_find_delalloc(u32 sectorsize)set_extent_delalloc (&tmp,0 , sectorsize -1 ,0 ,NULL ); start =0 ; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("should have found at least one delalloc" );
@@ -137,7 +137,7 @@ static int test_find_delalloc(u32 sectorsize)set_extent_delalloc (&tmp, sectorsize, max_bytes -1 ,0 ,NULL ); start = test_start; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("couldn't find delalloc in our range" );
@@ -171,7 +171,7 @@ static int test_find_delalloc(u32 sectorsize) } start = test_start; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (found) {test_err ("found range when we shouldn't have" );
@@ -192,7 +192,7 @@ static int test_find_delalloc(u32 sectorsize)set_extent_delalloc (&tmp, max_bytes, total_dirty -1 ,0 ,NULL ); start = test_start; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("didn't find our range" );
@@ -233,7 +233,7 @@ static int test_find_delalloc(u32 sectorsize)* this changes at any point in the future we will need to fix this * tests expected behavior. */ - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("didn't find our range" );
Signature · 1 line
2.18.0
Re: [PATCH 1/4 v2] btrfs: tests: add separate stub for find_lock_delalloc_range
Quoted 5 lines · David Sterba
The helper
find_lock_delalloc_rangeis now conditionally built static, dpending on whether the self-tests are enabled or not. There's a macro that is supposed to hide the export, used only once. To discourage further use, drop it an add a public wrapper for the helper needed by tests.
Quoted 124 lines
Signed-off-by David Sterba <[email protected]>---
v2:
- addnoinline_for_stackbackfs/btrfs/ctree.h | 6 ------ fs/btrfs/extent_io.c | 13 ++++++++++++- fs/btrfs/extent_io.h | 2 +- fs/btrfs/tests/extent-io-tests.c | 10 +++++----- 4 files changed, 18 insertions(+), 13 deletions(-)fs/btrfs/ctree.h +0
-6@@ -41,12 +41,6 @@ extern struct kmem_cache *btrfs_path_cachep;extern struct kmem_cache *btrfs_free_space_cachep;struct btrfs_ordered_sum ; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -#define STATIC noinline -#else -#define STATIC static noinline -#endif -#define BTRFS_MAGIC 0x4D5F53665248425FULL/* ascii _BHRfS_M, no null */ #define BTRFS_MAX_MIRRORS 3fs/btrfs/extent_io.c +12
-1@@ -1568,7 +1568,7 @@ static noinline int lock_delalloc_pages(struct inode *inode,* * 1 is returned if we find something, 0 if nothing was in the tree */ -STATIC u64 find_lock_delalloc_range(struct inode *inode, +static noinline_for_stack u64 find_lock_delalloc_range(struct inode *inode,struct extent_io_tree *tree,struct page *locked_page,u64 *start,u64 *end,u64 max_bytes)@@ -1648,6 +1648,17 @@ STATIC u64 find_lock_delalloc_range(struct inode *inode,return found; } +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +u64 btrfs_find_lock_delalloc_range (struct inode *inode, +struct extent_io_tree *tree, +struct page *locked_page,u64 *start, +u64 *end,u64 max_bytes) +{ +return find_lock_delalloc_range (inode, tree, locked_page, start, end, + max_bytes); +} +#endif + static int __process_pages_contig(struct address_space *mapping, struct page *locked_page, pgoff_t start_index, pgoff_t end_index,fs/btrfs/extent_io.h +1
-1@@ -546,7 +546,7 @@ int free_io_failure(struct extent_io_tree *failure_tree,struct extent_io_tree *io_tree, struct io_failure_record *rec);#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -noinline u64 find_lock_delalloc_range(struct inode *inode, +u64 btrfs_find_lock_delalloc_range (struct inode *inode,struct extent_io_tree *tree,struct page *locked_page,u64 *start,u64 *end,u64 max_bytes);fs/btrfs/tests/extent-io-tests.c +5
-5@@ -106,7 +106,7 @@ static int test_find_delalloc(u32 sectorsize)set_extent_delalloc (&tmp,0 , sectorsize -1 ,0 ,NULL ); start =0 ; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("should have found at least one delalloc" );@@ -137,7 +137,7 @@ static int test_find_delalloc(u32 sectorsize)set_extent_delalloc (&tmp, sectorsize, max_bytes -1 ,0 ,NULL ); start = test_start; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("couldn't find delalloc in our range" );@@ -171,7 +171,7 @@ static int test_find_delalloc(u32 sectorsize) } start = test_start; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (found) {test_err ("found range when we shouldn't have" );@@ -192,7 +192,7 @@ static int test_find_delalloc(u32 sectorsize)set_extent_delalloc (&tmp, max_bytes, total_dirty -1 ,0 ,NULL ); start = test_start; end =0 ; - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("didn't find our range" );@@ -233,7 +233,7 @@ static int test_find_delalloc(u32 sectorsize)* this changes at any point in the future we will need to fix this * tests expected behavior. */ - found =find_lock_delalloc_range (inode, &tmp, locked_page, &start, + found =btrfs_find_lock_delalloc_range (inode, &tmp, locked_page, &start, &end, max_bytes);if (!found) {test_err ("didn't find our range" );Signature · 1 line
2.18.0
David Sterba
maintainerPATCH 2/4 btrfs: tests: move testing members of struct btrfs_root to the end
In reply to David SterbaThe data used only for tests are better placed at the end of the structure so that they don't change the structure layout. All new members of btrfs_root should be placed before.
--- fs/btrfs/ctree.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/btrfs/ctree.h +4 -5
@@ -1203,11 +1203,6 @@ struct btrfs_root {u64 highest_objectid; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -/* only used with CONFIG_BTRFS_FS_RUN_SANITY_TESTS is enabled */ -u64 alloc_bytenr; -#endif -u64 defrag_trans_start;struct btrfs_key defrag_progress;struct btrfs_key defrag_max;
@@ -1280,6 +1275,10 @@ struct btrfs_root {spinlock_t qgroup_meta_rsv_lock;u64 qgroup_meta_rsv_pertrans;u64 qgroup_meta_rsv_prealloc; + +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +u64 alloc_bytenr; +#endif };struct btrfs_file_private {
Signature · 1 line
2.18.0
Re: [PATCH 2/4] btrfs: tests: move testing members of struct btrfs_root to the end
Quoted 3 lines · David Sterba
The data used only for tests are better placed at the end of the structure so that they don't change the structure layout. All new members of
btrfs_rootshould be placed before.
Quoted 35 lines
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ctree.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)fs/btrfs/ctree.h +4
-5@@ -1203,11 +1203,6 @@ struct btrfs_root {u64 highest_objectid; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -/* only used with CONFIG_BTRFS_FS_RUN_SANITY_TESTS is enabled */ -u64 alloc_bytenr; -#endif -u64 defrag_trans_start;struct btrfs_key defrag_progress;struct btrfs_key defrag_max;@@ -1280,6 +1275,10 @@ struct btrfs_root {spinlock_t qgroup_meta_rsv_lock;u64 qgroup_meta_rsv_pertrans;u64 qgroup_meta_rsv_prealloc; + +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +u64 alloc_bytenr; +#endif };struct btrfs_file_private {Signature · 1 line
2.18.0
David Sterba
maintainerPATCH 3/4 btrfs: tests: group declarations of self-test helpers
In reply to David Sterba--- fs/btrfs/ctree.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/ctree.h +1 -3
@@ -3194,9 +3194,6 @@ int btrfs_prealloc_file_range_trans(struct inode *inode, u64 start, u64 num_bytes, u64 min_size, loff_t actual_len, u64 *alloc_hint);extern const struct dentry_operations btrfs_dentry_operations; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -void btrfs_test_inode_set_ops (struct inode *inode); -#endif /* ioctl.c */ long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg);
@@ -3709,6 +3706,7 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)/* Sanity test specific functions */ #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +void btrfs_test_inode_set_ops (struct inode *inode);void btrfs_test_destroy_inode (struct inode *inode);#endif
Signature · 1 line
2.18.0
Re: [PATCH 3/4] btrfs: tests: group declarations of self-test helpers
On Mon, Sep 10, 2018 at 07:22:29PM +0200, David Sterba wrote:
Quoted 30 lines
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ctree.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/btrfs/ctree.h +1
-3@@ -3194,9 +3194,6 @@ int btrfs_prealloc_file_range_trans(struct inode *inode, u64 start, u64 num_bytes, u64 min_size, loff_t actual_len, u64 *alloc_hint);extern const struct dentry_operations btrfs_dentry_operations; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -void btrfs_test_inode_set_ops (struct inode *inode); -#endif /* ioctl.c */ long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg);@@ -3709,6 +3706,7 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)/* Sanity test specific functions */ #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +void btrfs_test_inode_set_ops (struct inode *inode);void btrfs_test_destroy_inode (struct inode *inode);#endif Signature · 1 line
2.18.0
David Sterba
maintainerPATCH 4/4 btrfs: tests: polish ifdefs around testing helper
In reply to David SterbaAvoid the inline ifdefs and use two sections for self-tests enabled and disabled.
--- fs/btrfs/ctree.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/btrfs/ctree.h +6 -3
@@ -3708,17 +3708,20 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS void btrfs_test_inode_set_ops (struct inode *inode);void btrfs_test_destroy_inode (struct inode *inode); -#endif static inline int btrfs_is_testing (struct btrfs_fs_info *fs_info) { -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS if (unlikely (test_bit (BTRFS_FS_STATE_DUMMY_FS_INFO , &fs_info->fs_state)))return 1 ; -#endif return 0 ; } +#else +static inline int btrfs_is_testing (struct btrfs_fs_info *fs_info) +{ +return 0 ; +} +#endif static inline void cond_wake_up (struct wait_queue_head *wq) {
Signature · 1 line
2.18.0
Re: [PATCH 4/4] btrfs: tests: polish ifdefs around testing helper
Quoted 16 lines · David Sterba
Avoid the inline ifdefs and use two sections for self-tests enabled and disabled.
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ctree.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)fs/btrfs/ctree.h +0
-0@@ -3708,17 +3708,20 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS void btrfs_test_inode_set_ops (struct inode *inode);void btrfs_test_destroy_inode (struct inode *inode);
fs/btrfs/ctree.h static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info) · line 3717
Quoted 10 lines
fs/btrfs/ctree.h +0
-3-#endif static inline int btrfs_is_testing (struct btrfs_fs_info *fs_info) { -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS if (unlikely (test_bit (BTRFS_FS_STATE_DUMMY_FS_INFO , &fs_info->fs_state)))return 1 ; -#endif return 0 ;
How about just:
return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
We can probably get away without the unlikely() considering that no one sane is going to run a kernel with CONFIG_BTRFS_FS_RUN_SANITY_TESTS in production.
Re: [PATCH 4/4] btrfs: tests: polish ifdefs around testing helper
Quoted 30 lines · Omar Sandoval
Quoted 16 lines · David Sterba
Avoid the inline ifdefs and use two sections for self-tests enabled and disabled.
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ctree.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)fs/btrfs/ctree.h +0
-0@@ -3708,17 +3708,20 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS void btrfs_test_inode_set_ops (struct inode *inode);void btrfs_test_destroy_inode (struct inode *inode);fs/btrfs/ctree.h static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info) · line 3717
Quoted 10 lines
fs/btrfs/ctree.h +0
-3-#endif static inline int btrfs_is_testing (struct btrfs_fs_info *fs_info) { -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS if (unlikely (test_bit (BTRFS_FS_STATE_DUMMY_FS_INFO , &fs_info->fs_state)))return 1 ; -#endif return 0 ;How about just:
Quoted 5 lines
return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);We can probably get away without the
unlikely()considering that no one sane is going to run a kernel withCONFIG_BTRFS_FS_RUN_SANITY_TESTSin production.
The unlikely can go away, sure.
I would still like to remove the test_bit call when tests are compiled out. There are about 10 calls to btrfs_is_testing in various core functions, followed by further statements. This would have a (negligible) runtime penalty but generates effectively unused code on production builds.
The static inline function returning 0 allows to optimize out the unused code, so smaller code, fewer inctructions, etc.
Re: [PATCH 4/4] btrfs: tests: polish ifdefs around testing helper
Quoted 39 lines · David Sterba
Quoted 30 lines · Omar Sandoval
Quoted 16 lines · David Sterba
Avoid the inline ifdefs and use two sections for self-tests enabled and disabled.
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ctree.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)fs/btrfs/ctree.h +0
-0@@ -3708,17 +3708,20 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS void btrfs_test_inode_set_ops (struct inode *inode);void btrfs_test_destroy_inode (struct inode *inode);fs/btrfs/ctree.h static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info) · line 3717
Quoted 10 lines
fs/btrfs/ctree.h +0
-3-#endif static inline int btrfs_is_testing (struct btrfs_fs_info *fs_info) { -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS if (unlikely (test_bit (BTRFS_FS_STATE_DUMMY_FS_INFO , &fs_info->fs_state)))return 1 ; -#endif return 0 ;How about just:
Quoted 5 lines
return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);We can probably get away without the
unlikely()considering that no one sane is going to run a kernel withCONFIG_BTRFS_FS_RUN_SANITY_TESTSin production.The unlikely can go away, sure.
Quoted 8 lines
I would still like to remove the
test_bitcall when tests are compiled out. There are about 10 calls tobtrfs_is_testingin various core functions, followed by further statements. This would have a (negligible) runtime penalty but generates effectively unused code on production builds.The static inline function returning 0 allows to optimize out the unused code, so smaller code, fewer inctructions, etc.
Absolutely, I just mean that the CONFIG_BTRFS_FS_RUN_SANITY_TESTS version can be cleaner:
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
{
return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
}
#else
static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
{
return 0;
}#endif
I find if (1) return 1; else return 0; really icky.
Re: [PATCH 4/4] btrfs: tests: polish ifdefs around testing helper
Quoted 24 lines · Omar Sandoval
Quoted 10 lines
The unlikely can go away, sure.
I would still like to remove the
test_bitcall when tests are compiled out. There are about 10 calls tobtrfs_is_testingin various core functions, followed by further statements. This would have a (negligible) runtime penalty but generates effectively unused code on production builds.The static inline function returning 0 allows to optimize out the unused code, so smaller code, fewer inctructions, etc.
Absolutely, I just mean that the
CONFIG_BTRFS_FS_RUN_SANITY_TESTSversion can be cleaner:#ifdef
CONFIG_BTRFS_FS_RUN_SANITY_TESTS
static inline intbtrfs_is_testing(struct btrfs_fs_info *fs_info){ return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); } #else static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info) { return 0; }
Quoted 3 lines
#endif
I find
if (1) return 1; else return 0;really icky.
I see what you mean, will fix it.
David Sterba
maintainerPATCH v2 4/4 btrfs: tests: polish ifdefs around testing helper
In reply to Omar SandovalAvoid the inline ifdefs and use two sections for self-tests enabled and disabled.
Though there could be no ifdef and unconditional test_bit of BTRFS_FS_STATE_DUMMY_FS_INFO, the static inline can help to optimize out any code that would depend on conditions using btrfs_is_testing.
As this is only for the testing code, drop unlikely().
---
v2:
- remove unlikely
- simplify to: return test_bit(...)
fs/btrfs/ctree.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
fs/btrfs/ctree.h +6 -6
@@ -3708,17 +3708,17 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS void btrfs_test_inode_set_ops (struct inode *inode);void btrfs_test_destroy_inode (struct inode *inode); -#endif static inline int btrfs_is_testing (struct btrfs_fs_info *fs_info) { -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -if (unlikely (test_bit (BTRFS_FS_STATE_DUMMY_FS_INFO , - &fs_info->fs_state))) -return 1 ; -#endif +return test_bit (BTRFS_FS_STATE_DUMMY_FS_INFO , &fs_info->fs_state); +} +#else +static inline int btrfs_is_testing (struct btrfs_fs_info *fs_info) +{return 0 ; } +#endif static inline void cond_wake_up (struct wait_queue_head *wq) {
Signature · 1 line
2.18.0
Re: [PATCH 4/4 v2] btrfs: tests: polish ifdefs around testing helper
Quoted 8 lines · David Sterba
Avoid the inline ifdefs and use two sections for self-tests enabled and disabled.
Though there could be no ifdef and unconditional
test_bitofBTRFS_FS_STATE_DUMMY_FS_INFO, the static inline can help to optimize out any code that would depend on conditions usingbtrfs_is_testing.As this is only for the testing code, drop
unlikely().
Quoted 41 lines
Signed-off-by David Sterba <[email protected]>---
v2:
- remove unlikely
- simplify to: returntest_bit(...)fs/btrfs/ctree.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)fs/btrfs/ctree.h +6
-6@@ -3708,17 +3708,17 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS void btrfs_test_inode_set_ops (struct inode *inode);void btrfs_test_destroy_inode (struct inode *inode); -#endif static inline int btrfs_is_testing (struct btrfs_fs_info *fs_info) { -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -if (unlikely (test_bit (BTRFS_FS_STATE_DUMMY_FS_INFO , - &fs_info->fs_state))) -return 1 ; -#endif +return test_bit (BTRFS_FS_STATE_DUMMY_FS_INFO , &fs_info->fs_state); +} +#else +static inline int btrfs_is_testing (struct btrfs_fs_info *fs_info) +{return 0 ; } +#endif static inline void cond_wake_up (struct wait_queue_head *wq) {Signature · 1 line
2.18.0