All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs-progs: kerncompat: Fix re-definition of __bitwise
@ 2017-03-16  3:18 Qu Wenruo
  2017-03-16  3:18 ` [PATCH 2/2] btrfs-progs: convert: Make btrfs_reserved_ranges const Qu Wenruo
  2017-03-27 17:37 ` [PATCH 1/2] btrfs-progs: kerncompat: Fix re-definition of __bitwise David Sterba
  0 siblings, 2 replies; 6+ messages in thread
From: Qu Wenruo @ 2017-03-16  3:18 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

In latest linux api headers, __bitwise is already defined in
/usr/include/linux/types.h.

So kerncompat.h will re-define __bitwise, and cause gcc warning.

Fix it by checking if __bitwise is already define.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
The patch is based on devel branch with the following head:
commit 64abe9f619b614e589339046b6c45dfb8fa8e2a9
Author: David Sterba <dsterba@suse.com>
Date:   Wed Mar 15 12:28:16 2017 +0100

    btrfs-progs: tests: misc/019, use fssum
---
 kerncompat.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kerncompat.h b/kerncompat.h
index 958bea43..fa96715f 100644
--- a/kerncompat.h
+++ b/kerncompat.h
@@ -317,11 +317,13 @@ static inline void assert_trace(const char *assertion, const char *filename,
 #define container_of(ptr, type, member) ({                      \
         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
 	        (type *)( (char *)__mptr - offsetof(type,member) );})
+#ifndef __bitwise
 #ifdef __CHECKER__
 #define __bitwise __bitwise__
 #else
 #define __bitwise
-#endif
+#endif /* __CHECKER__ */
+#endif	/* __bitwise */
 
 /* Alignment check */
 #define IS_ALIGNED(x, a)                (((x) & ((typeof(x))(a) - 1)) == 0)
-- 
2.12.0




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] btrfs-progs: convert: Make btrfs_reserved_ranges const
  2017-03-16  3:18 [PATCH 1/2] btrfs-progs: kerncompat: Fix re-definition of __bitwise Qu Wenruo
@ 2017-03-16  3:18 ` Qu Wenruo
  2017-03-16 16:33   ` David Sterba
  2017-03-27 17:37 ` [PATCH 1/2] btrfs-progs: kerncompat: Fix re-definition of __bitwise David Sterba
  1 sibling, 1 reply; 6+ messages in thread
From: Qu Wenruo @ 2017-03-16  3:18 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Since btrfs_reserved_ranges array is just used to store btrfs reserved
ranges, no one will nor should modify them at run time, make them static
and const will be better.

This also eliminates the use of immediate number 3.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 convert/main.c      | 16 ++++++++--------
 convert/source-fs.c |  6 ------
 convert/source-fs.h |  8 ++++++--
 3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/convert/main.c b/convert/main.c
index 73c9d889..96358c62 100644
--- a/convert/main.c
+++ b/convert/main.c
@@ -218,7 +218,7 @@ static int create_image_file_range(struct btrfs_trans_handle *trans,
 	 * migrate block will fail as there is already a file extent.
 	 */
 	for (i = 0; i < ARRAY_SIZE(btrfs_reserved_ranges); i++) {
-		struct simple_range *reserved = &btrfs_reserved_ranges[i];
+		const struct simple_range *reserved = &btrfs_reserved_ranges[i];
 
 		/*
 		 * |-- reserved --|
@@ -320,7 +320,7 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans,
 				      struct btrfs_root *root,
 				      struct cache_tree *used,
 				      struct btrfs_inode_item *inode, int fd,
-				      u64 ino, struct simple_range *range,
+				      u64 ino, const struct simple_range *range,
 				      u32 convert_flags)
 {
 	u64 cur_off = range->start;
@@ -423,7 +423,7 @@ static int migrate_reserved_ranges(struct btrfs_trans_handle *trans,
 	int ret = 0;
 
 	for (i = 0; i < ARRAY_SIZE(btrfs_reserved_ranges); i++) {
-		struct simple_range *range = &btrfs_reserved_ranges[i];
+		const struct simple_range *range = &btrfs_reserved_ranges[i];
 
 		if (range->start > total_bytes)
 			return ret;
@@ -609,7 +609,7 @@ static int wipe_reserved_ranges(struct cache_tree *tree, u64 min_stripe_size,
 	int ret;
 
 	for (i = 0; i < ARRAY_SIZE(btrfs_reserved_ranges); i++) {
-		struct simple_range *range = &btrfs_reserved_ranges[i];
+		const struct simple_range *range = &btrfs_reserved_ranges[i];
 
 		ret = wipe_one_reserved_range(tree, range->start, range->len,
 					      min_stripe_size, ensure_size);
@@ -1370,7 +1370,7 @@ static int read_reserved_ranges(struct btrfs_root *root, u64 ino,
 	int ret = 0;
 
 	for (i = 0; i < ARRAY_SIZE(btrfs_reserved_ranges); i++) {
-		struct simple_range *range = &btrfs_reserved_ranges[i];
+		const struct simple_range *range = &btrfs_reserved_ranges[i];
 
 		if (range->start + range->len >= total_bytes)
 			break;
@@ -1395,7 +1395,7 @@ static bool is_subset_of_reserved_ranges(u64 start, u64 len)
 	bool ret = false;
 
 	for (i = 0; i < ARRAY_SIZE(btrfs_reserved_ranges); i++) {
-		struct simple_range *range = &btrfs_reserved_ranges[i];
+		const struct simple_range *range = &btrfs_reserved_ranges[i];
 
 		if (start >= range->start && start + len <= range_end(range)) {
 			ret = true;
@@ -1620,7 +1620,7 @@ static int do_rollback(const char *devname)
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(btrfs_reserved_ranges); i++) {
-		struct simple_range *range = &btrfs_reserved_ranges[i];
+		const struct simple_range *range = &btrfs_reserved_ranges[i];
 
 		reserved_ranges[i] = calloc(1, range->len);
 		if (!reserved_ranges[i]) {
@@ -1730,7 +1730,7 @@ close_fs:
 
 	for (i = ARRAY_SIZE(btrfs_reserved_ranges) - 1; i >= 0; i--) {
 		u64 real_size;
-		struct simple_range *range = &btrfs_reserved_ranges[i];
+		const struct simple_range *range = &btrfs_reserved_ranges[i];
 
 		if (range_end(range) >= fsize)
 			continue;
diff --git a/convert/source-fs.c b/convert/source-fs.c
index 7cf515b0..8217c893 100644
--- a/convert/source-fs.c
+++ b/convert/source-fs.c
@@ -22,12 +22,6 @@
 #include "convert/common.h"
 #include "convert/source-fs.h"
 
-struct simple_range btrfs_reserved_ranges[3] = {
-	{ 0,			     SZ_1M },
-	{ BTRFS_SB_MIRROR_OFFSET(1), SZ_64K },
-	{ BTRFS_SB_MIRROR_OFFSET(2), SZ_64K }
-};
-
 static int intersect_with_sb(u64 bytenr, u64 num_bytes)
 {
 	int i;
diff --git a/convert/source-fs.h b/convert/source-fs.h
index 9f611150..7aabe96b 100644
--- a/convert/source-fs.h
+++ b/convert/source-fs.h
@@ -32,7 +32,11 @@ struct simple_range {
 	u64 len;
 };
 
-extern struct simple_range btrfs_reserved_ranges[3];
+static const struct simple_range btrfs_reserved_ranges[] = {
+	{ 0,			     SZ_1M },
+	{ BTRFS_SB_MIRROR_OFFSET(1), SZ_64K },
+	{ BTRFS_SB_MIRROR_OFFSET(2), SZ_64K }
+};
 
 struct task_info;
 
@@ -107,7 +111,7 @@ int record_file_blocks(struct blk_iterate_data *data,
  *
  * Get range end (exclusive)
  */
-static inline u64 range_end(struct simple_range *range)
+static inline u64 range_end(const struct simple_range *range)
 {
 	return (range->start + range->len);
 }
-- 
2.12.0




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] btrfs-progs: convert: Make btrfs_reserved_ranges const
  2017-03-16  3:18 ` [PATCH 2/2] btrfs-progs: convert: Make btrfs_reserved_ranges const Qu Wenruo
@ 2017-03-16 16:33   ` David Sterba
  2017-03-17  0:35     ` Qu Wenruo
  0 siblings, 1 reply; 6+ messages in thread
From: David Sterba @ 2017-03-16 16:33 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, dsterba

On Thu, Mar 16, 2017 at 11:18:31AM +0800, Qu Wenruo wrote:
> Since btrfs_reserved_ranges array is just used to store btrfs reserved
> ranges, no one will nor should modify them at run time, make them static
> and const will be better.
> 
> This also eliminates the use of immediate number 3.

Adding const is fine, but you shouldn't define the structure inside
header, even as static. The number 3 needs to stay so we can use
ARRAY_SIZE.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] btrfs-progs: convert: Make btrfs_reserved_ranges const
  2017-03-16 16:33   ` David Sterba
@ 2017-03-17  0:35     ` Qu Wenruo
  2017-03-27 13:39       ` David Sterba
  0 siblings, 1 reply; 6+ messages in thread
From: Qu Wenruo @ 2017-03-17  0:35 UTC (permalink / raw)
  To: dsterba, linux-btrfs



At 03/17/2017 12:33 AM, David Sterba wrote:
> On Thu, Mar 16, 2017 at 11:18:31AM +0800, Qu Wenruo wrote:
>> Since btrfs_reserved_ranges array is just used to store btrfs reserved
>> ranges, no one will nor should modify them at run time, make them static
>> and const will be better.
>>
>> This also eliminates the use of immediate number 3.
>
> Adding const is fine, but you shouldn't define the structure inside
> header, even as static.

Any reason why we shouldn't define const static array in header?

Is extra .text segments usage the problem?

Thanks,
Qu

> The number 3 needs to stay so we can use
> ARRAY_SIZE.
>
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] btrfs-progs: convert: Make btrfs_reserved_ranges const
  2017-03-17  0:35     ` Qu Wenruo
@ 2017-03-27 13:39       ` David Sterba
  0 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2017-03-27 13:39 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Fri, Mar 17, 2017 at 08:35:01AM +0800, Qu Wenruo wrote:
> 
> 
> At 03/17/2017 12:33 AM, David Sterba wrote:
> > On Thu, Mar 16, 2017 at 11:18:31AM +0800, Qu Wenruo wrote:
> >> Since btrfs_reserved_ranges array is just used to store btrfs reserved
> >> ranges, no one will nor should modify them at run time, make them static
> >> and const will be better.
> >>
> >> This also eliminates the use of immediate number 3.
> >
> > Adding const is fine, but you shouldn't define the structure inside
> > header, even as static.
> 
> Any reason why we shouldn't define const static array in header?
> 
> Is extra .text segments usage the problem?

No, the problem is definition in a header.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] btrfs-progs: kerncompat: Fix re-definition of __bitwise
  2017-03-16  3:18 [PATCH 1/2] btrfs-progs: kerncompat: Fix re-definition of __bitwise Qu Wenruo
  2017-03-16  3:18 ` [PATCH 2/2] btrfs-progs: convert: Make btrfs_reserved_ranges const Qu Wenruo
@ 2017-03-27 17:37 ` David Sterba
  1 sibling, 0 replies; 6+ messages in thread
From: David Sterba @ 2017-03-27 17:37 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, dsterba

On Thu, Mar 16, 2017 at 11:18:30AM +0800, Qu Wenruo wrote:
> In latest linux api headers, __bitwise is already defined in
> /usr/include/linux/types.h.
> 
> So kerncompat.h will re-define __bitwise, and cause gcc warning.
> 
> Fix it by checking if __bitwise is already define.
> 
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-27 17:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-16  3:18 [PATCH 1/2] btrfs-progs: kerncompat: Fix re-definition of __bitwise Qu Wenruo
2017-03-16  3:18 ` [PATCH 2/2] btrfs-progs: convert: Make btrfs_reserved_ranges const Qu Wenruo
2017-03-16 16:33   ` David Sterba
2017-03-17  0:35     ` Qu Wenruo
2017-03-27 13:39       ` David Sterba
2017-03-27 17:37 ` [PATCH 1/2] btrfs-progs: kerncompat: Fix re-definition of __bitwise David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.