Skip to contentSkip to conversation

btrfs-progs: Make btrfs_header_fsid() return unsigned long

PATCH Superseded Ross Kirk 2 participants 3 messages Sep 24, 2013 – Sep 27, 2013 Btrfs file system

lore
Share & tools
lore

Ross Kirk

author
#0 lore raw

PATCH 1/1 btrfs-progs: Make btrfs_header_fsid() return unsigned long

Internally, btrfs_header_fsid() calculates an unsigned long, but casts it to a pointer, while all callers cast it to unsigned long again.

Committed to btrfs as fba6aa75654394fccf2530041e9451414c28084f

---
 cmds-chunk.c |    6 ++----
 ctree.c      |   18 ++++++------------
 ctree.h      |    5 ++---
 disk-io.c    |    3 +--
 print-tree.c |    2 +-
 5 files changed, 12 insertions(+), 22 deletions(-)
cmds-chunk.c +2 -4
index 03314de..a89b929 100644
@@ -742,8 +742,7 @@ static int scan_one_device(struct recover_control *rc, int fd,
 		    rc->leafsize)
 			break;
 
-		if (memcmp_extent_buffer(buf, rc->fs_devices->fsid,
-					 (unsigned long)btrfs_header_fsid(buf),
+		if (memcmp_extent_buffer(buf, rc->fs_devices->fsid, btrfs_header_fsid(buf),
 					 BTRFS_FSID_SIZE)) {
 			bytenr += rc->sectorsize;
 			continue;
@@ -1043,8 +1042,7 @@ static int __rebuild_chunk_root(struct btrfs_trans_handle *trans,
 	btrfs_set_header_level(cow, 0);
 	btrfs_set_header_backref_rev(cow, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(cow, BTRFS_CHUNK_TREE_OBJECTID);
-	write_extent_buffer(cow, root->fs_info->fsid,
-			(unsigned long)btrfs_header_fsid(cow),
+	write_extent_buffer(cow, root->fs_info->fsid, btrfs_header_fsid(cow),
 			BTRFS_FSID_SIZE);
 
 	write_extent_buffer(cow, root->fs_info->chunk_tree_uuid,
ctree.c +6 -12
index 1a4f3f0..4e9a47f 100644
@@ -121,8 +121,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 	else
 		btrfs_set_header_owner(cow, new_root_objectid);
 
-	write_extent_buffer(cow, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(cow),
+	write_extent_buffer(cow, root->fs_info->fsid, btrfs_header_fsid(cow),
 			    BTRFS_FSID_SIZE);
 
 	WARN_ON(btrfs_header_generation(buf) > trans->transid);
@@ -168,8 +167,7 @@ init:
 	btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(c, root->root_key.objectid);
 
-	write_extent_buffer(c, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(c),
+	write_extent_buffer(c, root->fs_info->fsid, btrfs_header_fsid(c),
 			    BTRFS_FSID_SIZE);
 
 	write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
@@ -342,8 +340,7 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans,
 	else
 		btrfs_set_header_owner(cow, root->root_key.objectid);
 
-	write_extent_buffer(cow, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(cow),
+	write_extent_buffer(cow, root->fs_info->fsid, btrfs_header_fsid(cow),
 			    BTRFS_FSID_SIZE);
 
 	WARN_ON(btrfs_header_generation(buf) > trans->transid);
@@ -1528,8 +1525,7 @@ static int noinline insert_new_root(struct btrfs_trans_handle *trans,
 	btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(c, root->root_key.objectid);
 
-	write_extent_buffer(c, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(c),
+	write_extent_buffer(c, root->fs_info->fsid, btrfs_header_fsid(c),
 			    BTRFS_FSID_SIZE);
 
 	write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
@@ -1649,8 +1645,7 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
 	btrfs_set_header_generation(split, trans->transid);
 	btrfs_set_header_backref_rev(split, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(split, root->root_key.objectid);
-	write_extent_buffer(split, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(split),
+	write_extent_buffer(split, root->fs_info->fsid, btrfs_header_fsid(split),
 			    BTRFS_FSID_SIZE);
 	write_extent_buffer(split, root->fs_info->chunk_tree_uuid,
 			    (unsigned long)btrfs_header_chunk_tree_uuid(split),
@@ -2210,8 +2205,7 @@ again:
 	btrfs_set_header_backref_rev(right, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(right, root->root_key.objectid);
 	btrfs_set_header_level(right, 0);
-	write_extent_buffer(right, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(right),
+	write_extent_buffer(right, root->fs_info->fsid, btrfs_header_fsid(right),
 			    BTRFS_FSID_SIZE);
 
 	write_extent_buffer(right, root->fs_info->chunk_tree_uuid,
ctree.h +2 -3
index 0b0d701..6a711c6 100644
@@ -1748,10 +1748,9 @@ static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,
 	btrfs_set_header_flags(eb, flags);
 }
 
-static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
+static inline unsigned long btrfs_header_fsid(struct extent_buffer *eb)
 {
-	unsigned long ptr = offsetof(struct btrfs_header, fsid);
-	return (u8 *)ptr;
+	return offsetof(struct btrfs_header, fsid);
 }
 
 static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
disk-io.c +1 -2
index 13dbe27..58f699e 100644
@@ -49,8 +49,7 @@ static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
 
 	fs_devices = root->fs_info->fs_devices;
 	while (fs_devices) {
-		if (!memcmp_extent_buffer(buf, fs_devices->fsid,
-					  (unsigned long)btrfs_header_fsid(buf),
+		if (!memcmp_extent_buffer(buf, fs_devices->fsid, btrfs_header_fsid(buf),
 					  BTRFS_FSID_SIZE)) {
 			ret = 0;
 			break;
print-tree.c +1 -1
index aae47a9..5027b73 100644
@@ -153,7 +153,7 @@ static void print_uuids(struct extent_buffer *eb)
 	char chunk_uuid[37];
 	u8 disk_uuid[BTRFS_UUID_SIZE];
 
-	read_extent_buffer(eb, disk_uuid, (unsigned long)btrfs_header_fsid(eb),
+	read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(eb),
 			   BTRFS_FSID_SIZE);
 
 	fs_uuid[36] = '\0';
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 2 lines · Ross Kirk

Internally, btrfs_header_fsid() calculates an unsigned long, but casts it to a pointer, while all callers cast it to unsigned long again.

Thanks for doing this; my only nitpick is to keep
the lines under 80 cols.

Quoted 16 lines

Committed to btrfs as fba6aa75654394fccf2530041e9451414c28084f

---
 cmds-chunk.c |    6 ++----
 ctree.c      |   18 ++++++------------
 ctree.h      |    5 ++---
 disk-io.c    |    3 +--
 print-tree.c |    2 +-
 5 files changed, 12 insertions(+), 22 deletions(-)
cmds-chunk.c +0 -0
index 03314de..a89b929 100644

cmds-chunk.c static int scan_one_device(struct recover_control *rc, int fd, · line 745

Quoted 6 lines
cmds-chunk.c +1 -2
@@ -742,8 +742,7 @@ static int scan_one_device(struct recover_control *rc, int fd,
 		    rc->leafsize)
 			break;
 
-		if (memcmp_extent_buffer(buf, rc->fs_devices->fsid,
-					 (unsigned long)btrfs_header_fsid(buf),
+		if (memcmp_extent_buffer(buf, rc->fs_devices->fsid, btrfs_header_fsid(buf),

this overflows 80 cols

cmds-chunk.c static int __rebuild_chunk_root(struct btrfs_trans_handle *trans, · line 1045

Quoted 10 lines
cmds-chunk.c +1 -2
 					 BTRFS_FSID_SIZE)) {
 			bytenr += rc->sectorsize;
 			continue;
@@ -1043,8 +1042,7 @@ static int __rebuild_chunk_root(struct btrfs_trans_handle *trans,
 	btrfs_set_header_level(cow, 0);
 	btrfs_set_header_backref_rev(cow, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(cow, BTRFS_CHUNK_TREE_OBJECTID);
-	write_extent_buffer(cow, root->fs_info->fsid,
-			(unsigned long)btrfs_header_fsid(cow),
+	write_extent_buffer(cow, root->fs_info->fsid, btrfs_header_fsid(cow),

this too

Quoted 48 lines
cmds-chunk.c +0 -0
 			BTRFS_FSID_SIZE);
 
 	write_extent_buffer(cow, root->fs_info->chunk_tree_uuid,
ctree.c +4 -8
index 1a4f3f0..4e9a47f 100644
@@ -121,8 +121,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 	else
 		btrfs_set_header_owner(cow, new_root_objectid);
 
-	write_extent_buffer(cow, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(cow),
+	write_extent_buffer(cow, root->fs_info->fsid, btrfs_header_fsid(cow),
 			    BTRFS_FSID_SIZE);
 
 	WARN_ON(btrfs_header_generation(buf) > trans->transid);
@@ -168,8 +167,7 @@ init:
 	btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(c, root->root_key.objectid);
 
-	write_extent_buffer(c, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(c),
+	write_extent_buffer(c, root->fs_info->fsid, btrfs_header_fsid(c),
 			    BTRFS_FSID_SIZE);
 
 	write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
@@ -342,8 +340,7 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans,
 	else
 		btrfs_set_header_owner(cow, root->root_key.objectid);
 
-	write_extent_buffer(cow, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(cow),
+	write_extent_buffer(cow, root->fs_info->fsid, btrfs_header_fsid(cow),
 			    BTRFS_FSID_SIZE);
 
 	WARN_ON(btrfs_header_generation(buf) > trans->transid);
@@ -1528,8 +1525,7 @@ static int noinline insert_new_root(struct btrfs_trans_handle *trans,
 	btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(c, root->root_key.objectid);
 
-	write_extent_buffer(c, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(c),
+	write_extent_buffer(c, root->fs_info->fsid, btrfs_header_fsid(c),
 			    BTRFS_FSID_SIZE);
 
 	write_extent_buffer(c, root->fs_info->chunk_tree_uuid,

ctree.c static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root · line 1648

Quoted 6 lines
ctree.c +1 -2
@@ -1649,8 +1645,7 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
 	btrfs_set_header_generation(split, trans->transid);
 	btrfs_set_header_backref_rev(split, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(split, root->root_key.objectid);
-	write_extent_buffer(split, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(split),
+	write_extent_buffer(split, root->fs_info->fsid, btrfs_header_fsid(split),

This too. Kernelspace split it differently:

        write_extent_buffer(split, root->fs_info->fsid,
                            btrfs_header_fsid(split), BTRFS_FSID_SIZE);

When in doubt, matching kernelspace (when the same function exists there) is good practice; some day (tm) it'll all match.

ctree.c again: · line 2208

Quoted 10 lines
ctree.c +1 -2
 			    BTRFS_FSID_SIZE);
 	write_extent_buffer(split, root->fs_info->chunk_tree_uuid,
 			    (unsigned long)btrfs_header_chunk_tree_uuid(split),
@@ -2210,8 +2205,7 @@ again:
 	btrfs_set_header_backref_rev(right, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(right, root->root_key.objectid);
 	btrfs_set_header_level(right, 0);
-	write_extent_buffer(right, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(right),
+	write_extent_buffer(right, root->fs_info->fsid, btrfs_header_fsid(right),

this too. Same comment about matching the way it's written in kernelspace, and it'll be one fewer difference to pick through.

If you don't mind checking for these & other 80-col issues, & resending V2, that'd be great.

Thanks!

-Eric

Quoted 48 lines
ctree.c +0 -0
 			    BTRFS_FSID_SIZE);
 
 	write_extent_buffer(right, root->fs_info->chunk_tree_uuid,
ctree.h +2 -3
index 0b0d701..6a711c6 100644
@@ -1748,10 +1748,9 @@ static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,
 	btrfs_set_header_flags(eb, flags);
 }
 
-static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
+static inline unsigned long btrfs_header_fsid(struct extent_buffer *eb)
 {
-	unsigned long ptr = offsetof(struct btrfs_header, fsid);
-	return (u8 *)ptr;
+	return offsetof(struct btrfs_header, fsid);
 }
 
 static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
disk-io.c +1 -2
index 13dbe27..58f699e 100644
@@ -49,8 +49,7 @@ static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
 
 	fs_devices = root->fs_info->fs_devices;
 	while (fs_devices) {
-		if (!memcmp_extent_buffer(buf, fs_devices->fsid,
-					  (unsigned long)btrfs_header_fsid(buf),
+		if (!memcmp_extent_buffer(buf, fs_devices->fsid, btrfs_header_fsid(buf),
 					  BTRFS_FSID_SIZE)) {
 			ret = 0;
 			break;
print-tree.c +1 -1
index aae47a9..5027b73 100644
@@ -153,7 +153,7 @@ static void print_uuids(struct extent_buffer *eb)
 	char chunk_uuid[37];
 	u8 disk_uuid[BTRFS_UUID_SIZE];
 
-	read_extent_buffer(eb, disk_uuid, (unsigned long)btrfs_header_fsid(eb),
+	read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(eb),
 			   BTRFS_FSID_SIZE);
 
 	fs_uuid[36] = '\0';
author
#2 lore raw

PATCH v2 1/1 btrfs-progs: Make btrfs_header_fsid() return unsigned long

In reply to Ross Kirk

Internally, btrfs_header_fsid() calculates an unsigned long, but casts it to a pointer, while all callers cast it to unsigned long again.

Committed to btrfs as fba6aa75654394fccf2530041e9451414c28084f

Fix line length issues and match changes to kernelspace

---
 cmds-chunk.c |    6 ++----
 ctree.c      |   18 ++++++------------
 ctree.h      |    5 ++---
 disk-io.c    |    3 +--
 print-tree.c |    2 +-
 5 files changed, 12 insertions(+), 22 deletions(-)
cmds-chunk.c +2 -4
index 03314de..cd2fd5f 100644
@@ -743,8 +743,7 @@ static int scan_one_device(struct recover_control *rc, int fd,
 			break;
 
 		if (memcmp_extent_buffer(buf, rc->fs_devices->fsid,
-					 (unsigned long)btrfs_header_fsid(buf),
-					 BTRFS_FSID_SIZE)) {
+					 btrfs_header_fsid(buf), BTRFS_FSID_SIZE)) {
 			bytenr += rc->sectorsize;
 			continue;
 		}
@@ -1044,8 +1043,7 @@ static int __rebuild_chunk_root(struct btrfs_trans_handle *trans,
 	btrfs_set_header_backref_rev(cow, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(cow, BTRFS_CHUNK_TREE_OBJECTID);
 	write_extent_buffer(cow, root->fs_info->fsid,
-			(unsigned long)btrfs_header_fsid(cow),
-			BTRFS_FSID_SIZE);
+			btrfs_header_fsid(cow),	BTRFS_FSID_SIZE);
 
 	write_extent_buffer(cow, root->fs_info->chunk_tree_uuid,
 			(unsigned long)btrfs_header_chunk_tree_uuid(cow),
ctree.c +6 -12
index 1a4f3f0..600c26c 100644
@@ -121,8 +121,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 	else
 		btrfs_set_header_owner(cow, new_root_objectid);
 
-	write_extent_buffer(cow, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(cow),
+	write_extent_buffer(cow, root->fs_info->fsid, btrfs_header_fsid(cow),
 			    BTRFS_FSID_SIZE);
 
 	WARN_ON(btrfs_header_generation(buf) > trans->transid);
@@ -168,8 +167,7 @@ init:
 	btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(c, root->root_key.objectid);
 
-	write_extent_buffer(c, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(c),
+	write_extent_buffer(c, root->fs_info->fsid, btrfs_header_fsid(c),
 			    BTRFS_FSID_SIZE);
 
 	write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
@@ -342,8 +340,7 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans,
 	else
 		btrfs_set_header_owner(cow, root->root_key.objectid);
 
-	write_extent_buffer(cow, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(cow),
+	write_extent_buffer(cow, root->fs_info->fsid, btrfs_header_fsid(cow),
 			    BTRFS_FSID_SIZE);
 
 	WARN_ON(btrfs_header_generation(buf) > trans->transid);
@@ -1528,8 +1525,7 @@ static int noinline insert_new_root(struct btrfs_trans_handle *trans,
 	btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(c, root->root_key.objectid);
 
-	write_extent_buffer(c, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(c),
+	write_extent_buffer(c, root->fs_info->fsid, btrfs_header_fsid(c),
 			    BTRFS_FSID_SIZE);
 
 	write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
@@ -1650,8 +1646,7 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
 	btrfs_set_header_backref_rev(split, BTRFS_MIXED_BACKREF_REV);
 	btrfs_set_header_owner(split, root->root_key.objectid);
 	write_extent_buffer(split, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(split),
-			    BTRFS_FSID_SIZE);
+			    btrfs_header_fsid(split), BTRFS_FSID_SIZE);
 	write_extent_buffer(split, root->fs_info->chunk_tree_uuid,
 			    (unsigned long)btrfs_header_chunk_tree_uuid(split),
 			    BTRFS_UUID_SIZE);
@@ -2211,8 +2206,7 @@ again:
 	btrfs_set_header_owner(right, root->root_key.objectid);
 	btrfs_set_header_level(right, 0);
 	write_extent_buffer(right, root->fs_info->fsid,
-			    (unsigned long)btrfs_header_fsid(right),
-			    BTRFS_FSID_SIZE);
+			    btrfs_header_fsid(right), BTRFS_FSID_SIZE);
 
 	write_extent_buffer(right, root->fs_info->chunk_tree_uuid,
 			    (unsigned long)btrfs_header_chunk_tree_uuid(right),
ctree.h +2 -3
index 0b0d701..6a711c6 100644
@@ -1748,10 +1748,9 @@ static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,
 	btrfs_set_header_flags(eb, flags);
 }
 
-static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
+static inline unsigned long btrfs_header_fsid(struct extent_buffer *eb)
 {
-	unsigned long ptr = offsetof(struct btrfs_header, fsid);
-	return (u8 *)ptr;
+	return offsetof(struct btrfs_header, fsid);
 }
 
 static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
disk-io.c +1 -2
index 13dbe27..1221e2c 100644
@@ -50,8 +50,7 @@ static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
 	fs_devices = root->fs_info->fs_devices;
 	while (fs_devices) {
 		if (!memcmp_extent_buffer(buf, fs_devices->fsid,
-					  (unsigned long)btrfs_header_fsid(buf),
-					  BTRFS_FSID_SIZE)) {
+					  btrfs_header_fsid(buf), BTRFS_FSID_SIZE)) {
 			ret = 0;
 			break;
 		}
print-tree.c +1 -1
index aae47a9..5027b73 100644
@@ -153,7 +153,7 @@ static void print_uuids(struct extent_buffer *eb)
 	char chunk_uuid[37];
 	u8 disk_uuid[BTRFS_UUID_SIZE];
 
-	read_extent_buffer(eb, disk_uuid, (unsigned long)btrfs_header_fsid(eb),
+	read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(eb),
 			   BTRFS_FSID_SIZE);
 
 	fs_uuid[36] = '\0';
Signature · 1 line
1.7.7.6