Skip to contentSkip to conversation

xfs: check sizes of XFS on-disk structures at compile time

PATCH In review Darrick J. Wong 5 participants 10 messages Jan 11, 2016 – Feb 1, 2016 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: check sizes of XFS on-disk structures at compile time

Check the sizes of XFS on-disk structures when compiling the kernel. Use this to catch inadvertent changes in structure size due to padding and alignment issues, etc.

---
 fs/xfs/libxfs/xfs_format.h |    4 ++++
 fs/xfs/xfs_super.c         |   45 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
fs/xfs/libxfs/xfs_format.h +4 -0
index e2536bb..a589b47 100644
@@ -1509,4 +1509,8 @@ struct xfs_acl {
 #define SGI_ACL_FILE_SIZE	(sizeof(SGI_ACL_FILE)-1)
 #define SGI_ACL_DEFAULT_SIZE	(sizeof(SGI_ACL_DEFAULT)-1)
 
+#define XFS_CHECK_STRUCT_SIZE(structname, size) \
+	BUILD_BUG_ON_MSG(sizeof(structname) != (size), "XFS: sizeof(struct " \
+		#structname ") is wrong, expected " #size)
+
 #endif /* __XFS_FORMAT_H__ */
fs/xfs/xfs_super.c +45 -0

56 lines not on this page · raw message

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Darrick J. Wong

Check the sizes of XFS on-disk structures when compiling the kernel. Use this to catch inadvertent changes in structure size due to padding and alignment issues, etc.

---

Seems reasonable to me:

Quoted 79 lines
 fs/xfs/libxfs/xfs_format.h |    4 ++++
 fs/xfs/xfs_super.c         |   45 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
fs/xfs/libxfs/xfs_format.h +4 -0
index e2536bb..a589b47 100644
@@ -1509,4 +1509,8 @@ struct xfs_acl {
 #define SGI_ACL_FILE_SIZE	(sizeof(SGI_ACL_FILE)-1)
 #define SGI_ACL_DEFAULT_SIZE	(sizeof(SGI_ACL_DEFAULT)-1)
 
+#define XFS_CHECK_STRUCT_SIZE(structname, size) \
+	BUILD_BUG_ON_MSG(sizeof(structname) != (size), "XFS: sizeof(struct " \
+		#structname ") is wrong, expected " #size)
+
 #endif /* __XFS_FORMAT_H__ */
fs/xfs/xfs_super.c +45 -0
index 36bd882..31b69d1 100644
@@ -1812,11 +1812,56 @@ xfs_destroy_workqueues(void)
 	destroy_workqueue(xfs_alloc_wq);
 }
 
+static void __init
+xfs_check_ondisk_structs(void)
+{
+	/* on-disk structures */
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dsb,			264);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agf,			224);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agi,			336);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agfl,			36);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_timestamp,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dinode,		176);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_disk_dquot,		104);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dqblk,			136);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dsymlink_hdr,		56);
+	XFS_CHECK_STRUCT_SIZE(xfs_alloc_rec_t,			8);
+	XFS_CHECK_STRUCT_SIZE(xfs_alloc_key_t,			8);
+	XFS_CHECK_STRUCT_SIZE(xfs_alloc_ptr_t,			4);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_rec,		16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_key,		4);
+	XFS_CHECK_STRUCT_SIZE(xfs_inobt_ptr_t,			4);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_bmdr_block,		4);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_bmbt_rec,		16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_bmbt_key,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_btree_block,		72);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_acl_entry,		12);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_acl,			4);
+
+	/* log structures */
+	XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header,		16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format_32,	52);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format_64,	56);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_ictimestamp,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_icdinode,		176);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_extent_32,		12);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_extent_64,		16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32,	28);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32,	28);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat,		24);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat,	20);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_icreate_log,		28);
+}
+
 STATIC int __init
 init_xfs_fs(void)
 {
 	int			error;
 
+	xfs_check_ondisk_structs();
+
 	printk(KERN_INFO XFS_VERSION_STRING " with "
 			 XFS_BUILD_OPTIONS " enabled\n");
 
Quoted 4 lines

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
In reply to Darrick J. Wong
Quoted 8 lines · Darrick J. Wong
fs/xfs/xfs_super.c +0 -0
index 36bd882..31b69d1 100644
@@ -1812,11 +1812,56 @@ xfs_destroy_workqueues(void)
 	destroy_workqueue(xfs_alloc_wq);
 }
 

fs/xfs/xfs_super.c xfs_destroy_workqueues(void) · line 1824

Quoted 10 lines
fs/xfs/xfs_super.c +10 -0
+static void __init
+xfs_check_ondisk_structs(void)
+{
+	/* on-disk structures */
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dsb,			264);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agf,			224);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agi,			336);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agfl,			36);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_timestamp,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dinode,		176);

I'm not sure why, but all this hard-coded stuff in the codebase bugs me.

What if we did it as part of the build, but outside the code, something like (pardon my bad Make-fu):

fs/xfs/Makefile +5 -0
index f646391..da9ec6d 100644
@@ -122,3 +122,8 @@ xfs-$(CONFIG_XFS_POSIX_ACL) += xfs_acl.o
 xfs-$(CONFIG_SYSCTL)           += xfs_sysctl.o
 xfs-$(CONFIG_COMPAT)           += xfs_ioctl32.o
 xfs-$(CONFIG_NFSD_PNFS)                += xfs_pnfs.o
+
+check_structures: $(obj)/xfs.o
+       $(src)/scripts/check_structures.sh $(obj)/xfs.o
+
+$(obj)/built-in.o: check_structures

where the script executes pahole or whatever we want, to check the structure sizes and possibly even alignment explicitly? Presumably we could make running the check a Kconfig option as well...

similar tricks could surely be done for userspace as well.

-Eric

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
Quoted 40 lines · Eric Sandeen
Quoted 8 lines · Darrick J. Wong
fs/xfs/xfs_super.c +0 -0
index 36bd882..31b69d1 100644
@@ -1812,11 +1812,56 @@ xfs_destroy_workqueues(void)
 	destroy_workqueue(xfs_alloc_wq);
 }
 

fs/xfs/xfs_super.c xfs_destroy_workqueues(void) · line 1824

Quoted 10 lines
fs/xfs/xfs_super.c +10 -0
+static void __init
+xfs_check_ondisk_structs(void)
+{
+	/* on-disk structures */
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dsb,			264);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agf,			224);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agi,			336);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agfl,			36);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_timestamp,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dinode,		176);

I'm not sure why, but all this hard-coded stuff in the codebase bugs me.

What if we did it as part of the build, but outside the code, something like (pardon my bad Make-fu):

fs/xfs/Makefile +5 -0
index f646391..da9ec6d 100644
@@ -122,3 +122,8 @@ xfs-$(CONFIG_XFS_POSIX_ACL) += xfs_acl.o
 xfs-$(CONFIG_SYSCTL)           += xfs_sysctl.o
 xfs-$(CONFIG_COMPAT)           += xfs_ioctl32.o
 xfs-$(CONFIG_NFSD_PNFS)                += xfs_pnfs.o
+
+check_structures: $(obj)/xfs.o
+       $(src)/scripts/check_structures.sh $(obj)/xfs.o
+
+$(obj)/built-in.o: check_structures
Quoted 3 lines

where the script executes pahole or whatever we want, to check the structure sizes and possibly even alignment explicitly? Presumably we could make running the check a Kconfig option as well...

We certainly /could/ do that, but now the build depends on pahole or whatever being installed, whereas this macroey doesn't add more tool dependencies. I think between this and xfs/122 we're probably fine?

--D

Quoted 9 lines

similar tricks could surely be done for userspace as well.

-Eric

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#4 lore raw
In reply to Darrick J. Wong
Quoted 15 lines · Darrick J. Wong

Check the sizes of XFS on-disk structures when compiling the kernel. Use this to catch inadvertent changes in structure size due to padding and alignment issues, etc.

---
 fs/xfs/libxfs/xfs_format.h |    4 ++++
 fs/xfs/xfs_super.c         |   45 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
fs/xfs/libxfs/xfs_format.h +0 -0
index e2536bb..a589b47 100644

fs/xfs/libxfs/xfs_format.h struct xfs_acl { · line 1515

Quoted 7 lines
fs/xfs/libxfs/xfs_format.h +4 -0
@@ -1509,4 +1509,8 @@ struct xfs_acl {
 #define SGI_ACL_FILE_SIZE	(sizeof(SGI_ACL_FILE)-1)
 #define SGI_ACL_DEFAULT_SIZE	(sizeof(SGI_ACL_DEFAULT)-1)
 
+#define XFS_CHECK_STRUCT_SIZE(structname, size) \
+	BUILD_BUG_ON_MSG(sizeof(structname) != (size), "XFS: sizeof(struct " \
+		#structname ") is wrong, expected " #size)
+

Since xfs/122 will handle this on the userspace side, this can move to xfs_super.c.

Quoted 24 lines
fs/xfs/libxfs/xfs_format.h +0 -0
 #endif /* __XFS_FORMAT_H__ */
fs/xfs/xfs_super.c +15 -0
index 36bd882..31b69d1 100644
@@ -1812,11 +1812,56 @@ xfs_destroy_workqueues(void)
 	destroy_workqueue(xfs_alloc_wq);
 }
 
+static void __init
+xfs_check_ondisk_structs(void)
+{
+	/* on-disk structures */
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dsb,			264);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agf,			224);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agi,			336);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_agfl,			36);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_timestamp,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dinode,		176);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_disk_dquot,		104);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dqblk,			136);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dsymlink_hdr,		56);
+	XFS_CHECK_STRUCT_SIZE(xfs_alloc_rec_t,			8);
+	XFS_CHECK_STRUCT_SIZE(xfs_alloc_key_t,			8);

fs/xfs/xfs_super.c xfs_destroy_workqueues(void) · line 1839

Quoted 10 lines
fs/xfs/xfs_super.c +10 -0
+	XFS_CHECK_STRUCT_SIZE(xfs_alloc_ptr_t,			4);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_rec,		16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_key,		4);
+	XFS_CHECK_STRUCT_SIZE(xfs_inobt_ptr_t,			4);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_bmdr_block,		4);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_bmbt_rec,		16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_bmbt_key,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_btree_block,		72);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_acl_entry,		12);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_acl,			4);

Forgot the dir/attr structures here.

Quoted 6 lines
fs/xfs/xfs_super.c +6 -0
+	/* log structures */
+	XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header,		16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format_32,	52);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format_64,	56);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_ictimestamp,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_icdinode,		176);

fs/xfs/xfs_super.c xfs_destroy_workqueues(void) · line 1856

Quoted 10 lines
fs/xfs/xfs_super.c +10 -0
+	XFS_CHECK_STRUCT_SIZE(struct xfs_extent_32,		12);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_extent_64,		16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32,	28);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32,	28);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat,		24);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat,	20);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_icreate_log,		28);
+}

Perhaps this huge function ought to hide away in its own file?

--D

Quoted 12 lines
fs/xfs/xfs_super.c +3 -0
+
 STATIC int __init
 init_xfs_fs(void)
 {
 	int			error;
 
+	xfs_check_ondisk_structs();
+
 	printk(KERN_INFO XFS_VERSION_STRING " with "
 			 XFS_BUILD_OPTIONS " enabled\n");
 
Quoted 4 lines

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#5 lore raw
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Darrick J. Wong

Check the sizes of XFS on-disk structures when compiling the kernel. Use this to catch inadvertent changes in structure size due to padding and alignment issues, etc.

....

Quoted 9 lines

fs/xfs/xfs_super.c xfs_destroy_workqueues(void) · line 1856

Quoted 7 lines
fs/xfs/xfs_super.c +7 -0
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32,	28);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat,		24);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat,	20);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_icreate_log,		28);
+}

Perhaps this huge function ought to hide away in its own file?

Yes, I think that's a good idea, and I think it should only be built on debug builds, too.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#6 lore raw
Quoted 18 lines · Dave Chinner
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Darrick J. Wong

Check the sizes of XFS on-disk structures when compiling the kernel. Use this to catch inadvertent changes in structure size due to padding and alignment issues, etc.

....

Quoted 9 lines

fs/xfs/xfs_super.c xfs_destroy_workqueues(void) · line 1856

Quoted 7 lines
fs/xfs/xfs_super.c +7 -0
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32,	28);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat,		24);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat,	20);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_icreate_log,		28);
+}

Perhaps this huge function ought to hide away in its own file?

Quoted 2 lines

Yes, I think that's a good idea, and I think it should only be built on debug builds, too.

Ok, I'll make it go away when !CONFIG_XFS_DEBUG.

--D

Quoted 7 lines

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#7 lore raw
In reply to Dave Chinner
Quoted 18 lines · Dave Chinner
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Darrick J. Wong

Check the sizes of XFS on-disk structures when compiling the kernel. Use this to catch inadvertent changes in structure size due to padding and alignment issues, etc.

....

Quoted 9 lines

fs/xfs/xfs_super.c xfs_destroy_workqueues(void) · line 1856

Quoted 7 lines
fs/xfs/xfs_super.c +7 -0
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32,	28);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat,		24);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat,	20);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_icreate_log,		28);
+}

Perhaps this huge function ought to hide away in its own file?

Quoted 2 lines

Yes, I think that's a good idea, and I think it should only be built on debug builds, too.

Doesn't this turn into nothingness as far as the generated binary is concerned? Because if it does, I don't see a reason to keep it debug-only. Afterall, non-debug builds need to be correct and these are pretty important checks. We certainly don't want another ARM structure padding & alignment fiasco.

Just my 2 cents,

Jeff.

Signature · 8 lines
Only two things are infinite, the universe and human stupidity, and I'm not
sure about the former.
		- Albert Einstein

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#8 lore raw
Quoted 19 lines · Josef 'Jeff' Sipek
Quoted 18 lines · Dave Chinner
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Darrick J. Wong

Check the sizes of XFS on-disk structures when compiling the kernel. Use this to catch inadvertent changes in structure size due to padding and alignment issues, etc.

....

Quoted 9 lines

fs/xfs/xfs_super.c xfs_destroy_workqueues(void) · line 1856

Quoted 7 lines
fs/xfs/xfs_super.c +7 -0
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32,	28);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat,		24);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat,	20);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_icreate_log,		28);
+}

Perhaps this huge function ought to hide away in its own file?

Quoted 8 lines
Quoted 2 lines

Yes, I think that's a good idea, and I think it should only be built on debug builds, too.

Doesn't this turn into nothingness as far as the generated binary is concerned? Because if it does, I don't see a reason to keep it debug-only. Afterall, non-debug builds need to be correct and these are pretty important checks. We certainly don't want another ARM structure padding & alignment fiasco.

I moved the function to a separate header file and changed the declaration to:

static inline void __init xfs_check_ondisk_structs(void)

With any luck that should compile down to an empty inline function which should be optimized out of the resulting code. Worst case it's a separate function that gets discarded after the module loads. If Dave doesn't object, I'll leave it enabled for all builds.

--D

Quoted 9 lines

Just my 2 cents,

Jeff.

Signature · 3 lines
Only two things are infinite, the universe and human stupidity, and I'm not
sure about the former.
		- Albert Einstein

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#9 lore raw
Quoted 29 lines · Darrick J. Wong
Quoted 19 lines · Josef 'Jeff' Sipek
Quoted 18 lines · Dave Chinner
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Darrick J. Wong

Check the sizes of XFS on-disk structures when compiling the kernel. Use this to catch inadvertent changes in structure size due to padding and alignment issues, etc.

....

Quoted 9 lines

fs/xfs/xfs_super.c xfs_destroy_workqueues(void) · line 1856

Quoted 7 lines
fs/xfs/xfs_super.c +7 -0
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32,	28);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64,	32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat,		24);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat,	20);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_icreate_log,		28);
+}

Perhaps this huge function ought to hide away in its own file?

Quoted 8 lines
Quoted 2 lines

Yes, I think that's a good idea, and I think it should only be built on debug builds, too.

Doesn't this turn into nothingness as far as the generated binary is concerned? Because if it does, I don't see a reason to keep it debug-only. Afterall, non-debug builds need to be correct and these are pretty important checks. We certainly don't want another ARM structure padding & alignment fiasco.

Quoted 8 lines

I moved the function to a separate header file and changed the declaration to:

static inline void __init xfs_check_ondisk_structs(void)

With any luck that should compile down to an empty inline function which should be optimized out of the resulting code. Worst case it's a separate function that gets discarded after the module loads. If Dave doesn't object, I'll leave it enabled for all builds.

Really, it doesn't matter either way....

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs