diff mbox

[07/15] btrfs-progs: fix endian bugs in chunk rebuilding

Message ID 1376522205-16992-8-git-send-email-zab@redhat.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Zach Brown Aug. 14, 2013, 11:16 p.m. UTC
A disk_key was set by hand instead of using the endian helpers.

I *think* the second one is just a typo.  The chunk's num_stripes was
already initialized from the record, but it's le16.  So we'll set the
item's size based on the record's native num_stripes.

Signed-off-by: Zach Brown <zab@redhat.com>
---
 cmds-chunk.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

David Sterba Aug. 30, 2013, 4:16 p.m. UTC | #1
On Wed, Aug 14, 2013 at 04:16:37PM -0700, Zach Brown wrote:
> I *think* the second one is just a typo.  The chunk's num_stripes was
> already initialized from the record, but it's le16.  So we'll set the
> item's size based on the record's native num_stripes.

> @@ -1117,7 +1117,7 @@ static int __rebuild_chunk_items(struct btrfs_trans_handle *trans,
>  		key.offset = chunk_rec->offset;
>  
>  		ret = btrfs_insert_item(trans, chunk_root, &key, chunk,
> -				btrfs_chunk_item_size(chunk->num_stripes));
> +				btrfs_chunk_item_size(chunk_rec->num_stripes));

AFAICS, this is an equivalent change, chunk gets copied from chunk_rec
via create_chunk_item a few lines above. It looks more consistent with
chunk_rec, though.

>  		free(chunk);
>  		if (ret)
>  			return ret;
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-chunk.c b/cmds-chunk.c
index 16f399e..54f0573 100644
--- a/cmds-chunk.c
+++ b/cmds-chunk.c
@@ -1031,9 +1031,9 @@  static int __rebuild_chunk_root(struct btrfs_trans_handle *trans,
 		if (min_devid > dev->devid)
 			min_devid = dev->devid;
 	}
-	disk_key.objectid = BTRFS_DEV_ITEMS_OBJECTID;
-	disk_key.type = BTRFS_DEV_ITEM_KEY;
-	disk_key.offset = min_devid;
+	btrfs_set_disk_key_objectid(&disk_key, BTRFS_DEV_ITEMS_OBJECTID);
+	btrfs_set_disk_key_type(&disk_key, BTRFS_DEV_ITEM_KEY);
+	btrfs_set_disk_key_offset(&disk_key, min_devid);
 
 	cow = btrfs_alloc_free_block(trans, root, root->sectorsize,
 				     BTRFS_CHUNK_TREE_OBJECTID,
@@ -1117,7 +1117,7 @@  static int __rebuild_chunk_items(struct btrfs_trans_handle *trans,
 		key.offset = chunk_rec->offset;
 
 		ret = btrfs_insert_item(trans, chunk_root, &key, chunk,
-				btrfs_chunk_item_size(chunk->num_stripes));
+				btrfs_chunk_item_size(chunk_rec->num_stripes));
 		free(chunk);
 		if (ret)
 			return ret;