diff mbox series

[1/3] btrfs-progs: unify sizeof(struct btrfs_super_block) and BTRFS_SUPER_INFO_SIZE

Message ID 20211021014020.482242-2-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: cleanup related to btrfs super block | expand

Commit Message

Qu Wenruo Oct. 21, 2021, 1:40 a.m. UTC
Just like kernel change, pad struct btrfs_super_block to 4096 bytes.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 kernel-shared/ctree.h   | 7 +++++++
 kernel-shared/disk-io.h | 3 ---
 2 files changed, 7 insertions(+), 3 deletions(-)

Comments

David Sterba Oct. 21, 2021, 12:40 p.m. UTC | #1
On Thu, Oct 21, 2021 at 09:40:18AM +0800, Qu Wenruo wrote:
> Just like kernel change, pad struct btrfs_super_block to 4096 bytes.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  kernel-shared/ctree.h   | 7 +++++++
>  kernel-shared/disk-io.h | 3 ---
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
> index 563ea50b3587..6451690ce4fa 100644
> --- a/kernel-shared/ctree.h
> +++ b/kernel-shared/ctree.h
> @@ -406,6 +406,9 @@ struct btrfs_root_backup {
>  	u8 unused_8[10];
>  } __attribute__ ((__packed__));
>  
> +#define BTRFS_SUPER_INFO_OFFSET SZ_64K
> +#define BTRFS_SUPER_INFO_SIZE 4096
> +
>  /*
>   * the super block basically lists the main trees of the FS
>   * it currently lacks any block count etc etc
> @@ -456,8 +459,12 @@ struct btrfs_super_block {
>  	__le64 reserved[28];
>  	u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
>  	struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
> +	/* Padded to 4096 bytes */
> +	u8 padding[565];
>  } __attribute__ ((__packed__));
>  
> +static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);

Using static_assert breaks build on musl (you can verify that by running
ci/ci-build-musl if you have docker installed and set up).

There already is macro BUILD_ASSERT used in ioctl.h, eventually we can
copy the static_assert from kernel or use _Static_assert directly.
Qu Wenruo Oct. 21, 2021, 12:49 p.m. UTC | #2
On 2021/10/21 20:40, David Sterba wrote:
> On Thu, Oct 21, 2021 at 09:40:18AM +0800, Qu Wenruo wrote:
>> Just like kernel change, pad struct btrfs_super_block to 4096 bytes.
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>>   kernel-shared/ctree.h   | 7 +++++++
>>   kernel-shared/disk-io.h | 3 ---
>>   2 files changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
>> index 563ea50b3587..6451690ce4fa 100644
>> --- a/kernel-shared/ctree.h
>> +++ b/kernel-shared/ctree.h
>> @@ -406,6 +406,9 @@ struct btrfs_root_backup {
>>   	u8 unused_8[10];
>>   } __attribute__ ((__packed__));
>>
>> +#define BTRFS_SUPER_INFO_OFFSET SZ_64K
>> +#define BTRFS_SUPER_INFO_SIZE 4096
>> +
>>   /*
>>    * the super block basically lists the main trees of the FS
>>    * it currently lacks any block count etc etc
>> @@ -456,8 +459,12 @@ struct btrfs_super_block {
>>   	__le64 reserved[28];
>>   	u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
>>   	struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
>> +	/* Padded to 4096 bytes */
>> +	u8 padding[565];
>>   } __attribute__ ((__packed__));
>>
>> +static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
>
> Using static_assert breaks build on musl (you can verify that by running
> ci/ci-build-musl if you have docker installed and set up).
>
> There already is macro BUILD_ASSERT used in ioctl.h, eventually we can
> copy the static_assert from kernel or use _Static_assert directly.
>
Mind to fix that on your side?

As I don't yet have any building environment for musl to verify the
failure or fix.

Thanks,
Qu
diff mbox series

Patch

diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index 563ea50b3587..6451690ce4fa 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -406,6 +406,9 @@  struct btrfs_root_backup {
 	u8 unused_8[10];
 } __attribute__ ((__packed__));
 
+#define BTRFS_SUPER_INFO_OFFSET SZ_64K
+#define BTRFS_SUPER_INFO_SIZE 4096
+
 /*
  * the super block basically lists the main trees of the FS
  * it currently lacks any block count etc etc
@@ -456,8 +459,12 @@  struct btrfs_super_block {
 	__le64 reserved[28];
 	u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
 	struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
+	/* Padded to 4096 bytes */
+	u8 padding[565];
 } __attribute__ ((__packed__));
 
+static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
+
 /*
  * Compat flags that we support.  If any incompat flags are set other than the
  * ones specified below then we will fail to mount
diff --git a/kernel-shared/disk-io.h b/kernel-shared/disk-io.h
index e113d842c906..823e5af37e75 100644
--- a/kernel-shared/disk-io.h
+++ b/kernel-shared/disk-io.h
@@ -23,9 +23,6 @@ 
 #include "kernel-shared/ctree.h"
 #include "kernel-lib/sizes.h"
 
-#define BTRFS_SUPER_INFO_OFFSET SZ_64K
-#define BTRFS_SUPER_INFO_SIZE 4096
-
 #define BTRFS_SUPER_MIRROR_MAX	 3
 #define BTRFS_SUPER_MIRROR_SHIFT 12