public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/2] btrfs: make sizeof(struct btrfs_super_block) to match BTRFS_SUPER_INFO_SIZE
Date: Tue, 19 Oct 2021 19:29:24 +0800	[thread overview]
Message-ID: <20211019112925.71920-2-wqu@suse.com> (raw)
In-Reply-To: <20211019112925.71920-1-wqu@suse.com>

It's a common practice to avoid use sizeof(struct btrfs_super_block)
(3531), but to use BTRFS_SUPER_INFO_SIZE (4096).

The problem is that, sizeof(struct btrfs_super_block) doesn't match
BTRFS_SUPER_INFO_SIZE from the very beginning.

Furthermore, for all call sites except selftest, we always allocate
BTRFS_SUPER_INFO_SIZE space for btrfs super block, there isn't any real
reason to use the smaller value, and it doesn't really save any space.

So let's get rid of such confusing behavior, and unify those two values.

This patch will also add a BUILD_BUG_ON() to verify the value at build
time.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/ctree.h | 3 +++
 fs/btrfs/super.c | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 140126898577..e05098ac0337 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -270,6 +270,9 @@ 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__));
 
 /*
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index a1c54a2c787c..6fb5cdfceaf5 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2552,6 +2552,8 @@ static int __init init_btrfs_fs(void)
 {
 	int err;
 
+	BUILD_BUG_ON(sizeof(struct btrfs_super_block) != BTRFS_SUPER_INFO_SIZE);
+
 	btrfs_props_init();
 
 	err = btrfs_init_sysfs();
-- 
2.33.0


  reply	other threads:[~2021-10-19 11:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19 11:29 [PATCH 0/2] btrfs: cleanup on btrfs_super_block definition Qu Wenruo
2021-10-19 11:29 ` Qu Wenruo [this message]
2021-10-19 15:46   ` [PATCH 1/2] btrfs: make sizeof(struct btrfs_super_block) to match BTRFS_SUPER_INFO_SIZE David Sterba
2021-10-19 11:29 ` [PATCH 2/2] btrfs: move btrfs_super_block to uapi/linux/btrfs_tree.h Qu Wenruo
2021-10-19 16:10   ` David Sterba
2021-10-20  0:19     ` Qu Wenruo
2021-10-20 17:13       ` David Sterba
2021-10-20 23:18         ` Qu Wenruo
2021-11-07 23:24   ` kernel test robot
2021-10-19 14:08 ` [PATCH 0/2] btrfs: cleanup on btrfs_super_block definition Josef Bacik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211019112925.71920-2-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox