From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Brian Foster <bfoster@redhat.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH v4 6/8] xfs: use verifier magic field in dir2 leaf verifiers
Date: Thu, 7 Feb 2019 11:10:06 -0800 [thread overview]
Message-ID: <20190207191005.GJ7991@magnolia> (raw)
In-Reply-To: <20190207184105.17064-7-bfoster@redhat.com>
On Thu, Feb 07, 2019 at 01:41:03PM -0500, Brian Foster wrote:
> The dir2 leaf verifiers share the same underlying structure
> verification code, but implement six accessor functions to multiplex
> the code across the two verifiers. Further, the magic value isn't
> sufficiently abstracted such that the common helper has to manually
> fix up the magic from the caller on v5 filesystems.
>
> Use the magic field in the verifier structure to eliminate the
> duplicate code and clean this all up. No functional change.
>
> Signed-off-by: Brian Foster <bfoster@redhat.com>
> ---
> fs/xfs/libxfs/xfs_dir2_leaf.c | 87 ++++++++---------------------------
> fs/xfs/xfs_ondisk.h | 11 +++++
> 2 files changed, 30 insertions(+), 68 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_dir2_leaf.c b/fs/xfs/libxfs/xfs_dir2_leaf.c
> index 1728a3e6f5cf..dee0fd333d9d 100644
> --- a/fs/xfs/libxfs/xfs_dir2_leaf.c
> +++ b/fs/xfs/libxfs/xfs_dir2_leaf.c
> @@ -142,41 +142,31 @@ xfs_dir3_leaf_check_int(
> */
> static xfs_failaddr_t
> xfs_dir3_leaf_verify(
> - struct xfs_buf *bp,
> - uint16_t magic)
> + struct xfs_buf *bp)
> {
> struct xfs_mount *mp = bp->b_target->bt_mount;
> struct xfs_dir2_leaf *leaf = bp->b_addr;
>
> - ASSERT(magic == XFS_DIR2_LEAF1_MAGIC || magic == XFS_DIR2_LEAFN_MAGIC);
> + if (!xfs_verify_magic(bp, leaf->hdr.info.magic))
> + return __this_address;
>
> if (xfs_sb_version_hascrc(&mp->m_sb)) {
> struct xfs_dir3_leaf_hdr *leaf3 = bp->b_addr;
> - uint16_t magic3;
>
> - magic3 = (magic == XFS_DIR2_LEAF1_MAGIC) ? XFS_DIR3_LEAF1_MAGIC
> - : XFS_DIR3_LEAFN_MAGIC;
> -
> - if (leaf3->info.hdr.magic != cpu_to_be16(magic3))
> - return __this_address;
> if (!uuid_equal(&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid))
> return __this_address;
> if (be64_to_cpu(leaf3->info.blkno) != bp->b_bn)
> return __this_address;
> if (!xfs_log_check_lsn(mp, be64_to_cpu(leaf3->info.lsn)))
> return __this_address;
> - } else {
> - if (leaf->hdr.info.magic != cpu_to_be16(magic))
> - return __this_address;
> }
>
> return xfs_dir3_leaf_check_int(mp, NULL, NULL, leaf);
> }
>
> static void
> -__read_verify(
> - struct xfs_buf *bp,
> - uint16_t magic)
> +xfs_dir3_leaf_read_verify(
> + struct xfs_buf *bp)
> {
> struct xfs_mount *mp = bp->b_target->bt_mount;
> xfs_failaddr_t fa;
> @@ -185,23 +175,22 @@ __read_verify(
> !xfs_buf_verify_cksum(bp, XFS_DIR3_LEAF_CRC_OFF))
> xfs_verifier_error(bp, -EFSBADCRC, __this_address);
> else {
> - fa = xfs_dir3_leaf_verify(bp, magic);
> + fa = xfs_dir3_leaf_verify(bp);
> if (fa)
> xfs_verifier_error(bp, -EFSCORRUPTED, fa);
> }
> }
>
> static void
> -__write_verify(
> - struct xfs_buf *bp,
> - uint16_t magic)
> +xfs_dir3_leaf_write_verify(
> + struct xfs_buf *bp)
> {
> struct xfs_mount *mp = bp->b_target->bt_mount;
> struct xfs_buf_log_item *bip = bp->b_log_item;
> struct xfs_dir3_leaf_hdr *hdr3 = bp->b_addr;
> xfs_failaddr_t fa;
>
> - fa = xfs_dir3_leaf_verify(bp, magic);
> + fa = xfs_dir3_leaf_verify(bp);
> if (fa) {
> xfs_verifier_error(bp, -EFSCORRUPTED, fa);
> return;
> @@ -216,60 +205,22 @@ __write_verify(
> xfs_buf_update_cksum(bp, XFS_DIR3_LEAF_CRC_OFF);
> }
>
> -static xfs_failaddr_t
> -xfs_dir3_leaf1_verify(
> - struct xfs_buf *bp)
> -{
> - return xfs_dir3_leaf_verify(bp, XFS_DIR2_LEAF1_MAGIC);
> -}
> -
> -static void
> -xfs_dir3_leaf1_read_verify(
> - struct xfs_buf *bp)
> -{
> - __read_verify(bp, XFS_DIR2_LEAF1_MAGIC);
> -}
> -
> -static void
> -xfs_dir3_leaf1_write_verify(
> - struct xfs_buf *bp)
> -{
> - __write_verify(bp, XFS_DIR2_LEAF1_MAGIC);
> -}
> -
> -static xfs_failaddr_t
> -xfs_dir3_leafn_verify(
> - struct xfs_buf *bp)
> -{
> - return xfs_dir3_leaf_verify(bp, XFS_DIR2_LEAFN_MAGIC);
> -}
> -
> -static void
> -xfs_dir3_leafn_read_verify(
> - struct xfs_buf *bp)
> -{
> - __read_verify(bp, XFS_DIR2_LEAFN_MAGIC);
> -}
> -
> -static void
> -xfs_dir3_leafn_write_verify(
> - struct xfs_buf *bp)
> -{
> - __write_verify(bp, XFS_DIR2_LEAFN_MAGIC);
> -}
> -
> const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops = {
> .name = "xfs_dir3_leaf1",
> - .verify_read = xfs_dir3_leaf1_read_verify,
> - .verify_write = xfs_dir3_leaf1_write_verify,
> - .verify_struct = xfs_dir3_leaf1_verify,
> + .magic = { cpu_to_be16(XFS_DIR2_LEAF1_MAGIC),
> + cpu_to_be16(XFS_DIR3_LEAF1_MAGIC) },
> + .verify_read = xfs_dir3_leaf_read_verify,
> + .verify_write = xfs_dir3_leaf_write_verify,
> + .verify_struct = xfs_dir3_leaf_verify,
> };
>
> const struct xfs_buf_ops xfs_dir3_leafn_buf_ops = {
> .name = "xfs_dir3_leafn",
> - .verify_read = xfs_dir3_leafn_read_verify,
> - .verify_write = xfs_dir3_leafn_write_verify,
> - .verify_struct = xfs_dir3_leafn_verify,
> + .magic = { cpu_to_be16(XFS_DIR2_LEAFN_MAGIC),
> + cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) },
> + .verify_read = xfs_dir3_leaf_read_verify,
> + .verify_write = xfs_dir3_leaf_write_verify,
> + .verify_struct = xfs_dir3_leaf_verify,
> };
>
> int
> diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h
> index d3e04d20d8d4..0209f3e91254 100644
> --- a/fs/xfs/xfs_ondisk.h
> +++ b/fs/xfs/xfs_ondisk.h
> @@ -125,6 +125,17 @@ xfs_check_ondisk_structs(void)
> XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format, 56);
> XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat, 20);
> XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header, 16);
> +
> + /*
> + * Magic value offset checks. These are here because certain on-disk
> + * structures are updated to include more information on v5 filesystems.
> + * While different in-core data structures are used depending on fs
> + * version, some buffer verifiers expect to be able to use either
> + * structure to locate the magic value as it should always be in the
> + * same place.
> + */
> + XFS_CHECK_OFFSET(struct xfs_dir2_leaf, hdr.info.magic, 8);
> + XFS_CHECK_OFFSET(struct xfs_dir3_leaf_hdr, info.hdr.magic, 8);
Sorry for the nitpick, but why not
XFS_CHECK_OFFSET(struct xfs_dir3_leaf, hdr.info.hdr.magic, 8) ?
--D
> }
>
> #endif /* __XFS_ONDISK_H */
> --
> 2.17.2
>
next prev parent reply other threads:[~2019-02-07 19:10 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-07 18:40 [PATCH v4 0/8] xfs: fix [f]inobt magic value verification Brian Foster
2019-02-07 18:40 ` [PATCH v4 1/8] xfs: always check magic values in on-disk byte order Brian Foster
2019-02-07 18:55 ` [PATCH 0.5/8] xfs: clarify documentation for the function to reverify buffers Darrick J. Wong
2019-02-07 18:40 ` [PATCH v4 2/8] xfs: create a separate finobt verifier Brian Foster
2019-02-07 18:41 ` [PATCH v4 3/8] xfs: distinguish between inobt and finobt magic values Brian Foster
2019-02-07 18:52 ` Darrick J. Wong
2019-02-07 18:59 ` Brian Foster
2019-02-07 18:41 ` [PATCH v4 4/8] xfs: split up allocation btree verifier Brian Foster
2019-02-07 18:41 ` [PATCH v4 5/8] xfs: distinguish between bnobt and cntbt magic values Brian Foster
2019-02-07 18:41 ` [PATCH v4 6/8] xfs: use verifier magic field in dir2 leaf verifiers Brian Foster
2019-02-07 19:10 ` Darrick J. Wong [this message]
2019-02-07 19:37 ` Brian Foster
2019-02-07 20:10 ` [PATCH v4.1] " Brian Foster
2019-02-07 18:41 ` [PATCH v4 7/8] xfs: miscellaneous verifier magic value fixups Brian Foster
2019-02-07 19:13 ` Darrick J. Wong
2019-02-07 19:42 ` Brian Foster
2019-02-07 20:11 ` [PATCH v4.1] " Brian Foster
2019-02-07 18:41 ` [PATCH v4 8/8] xfs: factor xfs_da3_blkinfo verification into common helper Brian Foster
2019-02-07 18:56 ` [PATCH 9/8] xfs: add inode magic to inode verifier Darrick J. Wong
2019-02-07 20:27 ` Brian Foster
2019-02-07 18:56 ` [PATCH 10/8] xfs: add magic numbers to dquot buffer ops Darrick J. Wong
2019-02-07 20:27 ` Brian Foster
2019-02-07 18:57 ` [PATCH 11/8] xfs: use buf ops magic to detect btree block type Darrick J. Wong
2019-02-07 20:27 ` Brian Foster
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=20190207191005.GJ7991@magnolia \
--to=darrick.wong@oracle.com \
--cc=bfoster@redhat.com \
--cc=linux-xfs@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;
as well as URLs for NNTP newsgroup(s).