From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH] xfs: check sizes of XFS on-disk structures at compile time
Date: Tue, 12 Jan 2016 09:01:18 -0500 [thread overview]
Message-ID: <20160112140116.GB12156@bfoster.bfoster> (raw)
In-Reply-To: <20160111232657.GA7831@birch.djwong.org>
On Mon, Jan 11, 2016 at 03:26:57PM -0800, Darrick J. Wong wrote:
> 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.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
Seems reasonable to me:
Reviewed-by: Brian Foster <bfoster@redhat.com>
> fs/xfs/libxfs/xfs_format.h | 4 ++++
> fs/xfs/xfs_super.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 49 insertions(+)
>
> diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
> index e2536bb..a589b47 100644
> --- a/fs/xfs/libxfs/xfs_format.h
> +++ b/fs/xfs/libxfs/xfs_format.h
> @@ -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__ */
> diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
> index 36bd882..31b69d1 100644
> --- a/fs/xfs/xfs_super.c
> +++ b/fs/xfs/xfs_super.c
> @@ -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");
>
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2016-01-12 14:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-11 23:26 [PATCH] xfs: check sizes of XFS on-disk structures at compile time Darrick J. Wong
2016-01-12 14:01 ` Brian Foster [this message]
2016-01-13 18:25 ` Eric Sandeen
2016-01-15 21:05 ` Darrick J. Wong
2016-01-15 20:58 ` Darrick J. Wong
2016-01-15 22:52 ` Dave Chinner
2016-01-20 5:12 ` Darrick J. Wong
2016-01-20 15:40 ` Josef 'Jeff' Sipek
2016-01-22 22:01 ` Darrick J. Wong
2016-02-01 5:06 ` Dave Chinner
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=20160112140116.GB12156@bfoster.bfoster \
--to=bfoster@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=xfs@oss.sgi.com \
/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