public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Dave Chinner <david@fromorbit.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 10/13] xfs: provide a centralized method for verifying inline fork data
Date: Tue, 19 Dec 2017 12:50:04 -0800	[thread overview]
Message-ID: <20171219205004.GE12613@magnolia> (raw)
In-Reply-To: <20171219060640.GT4094@dastard>

On Tue, Dec 19, 2017 at 05:06:40PM +1100, Dave Chinner wrote:
> On Wed, Dec 13, 2017 at 03:59:13PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Replace the current haphazard dir2 shortform verifier callsites with a
> > centralized verifier function that can be called either with the default
> > verifier functions or with a custom set.  This helps us strengthen
> > integrity checking while providing us with flexibility for repair tools.
> > 
> > xfs_repair wants this to be able to supply its own verifier functions
> > when trying to fix possibly corrupt metadata.
> 
> I was about to say "this looks a little over-engineered" then I read
> the commit message.... :P
> 
> Ok, so it pulls the fork verication out of the libxfs inode read code,
> and instead slots it into the kernel inode cache miss path just
> after the inode has been read. Same effect - newly read inodes get
> their forks verified before use. ANd they same thing happens in
> xfs_iflush_int(), which is private to the kernel anyway....

<nod> It's a little over-engineered for the kernel; the real point of
all this is to check local format forks by default while enabling
xfs_repair to skip those checks if, say, it wants to fix an inode with
broken xattrs by zapping the attr fork.

> > +
> > +/* Default fork content verifiers. */
> > +struct xfs_ifork_ops xfs_default_ifork_ops = {
> > +	.verify_attr	= xfs_attr_shortform_verify,
> > +	.verify_dir	= xfs_dir2_sf_verify,
> > +	.verify_symlink	= xfs_symlink_shortform_verify,
> > +};
> > +
> > +/* Verify the inline contents of the data fork of an inode. */
> > +xfs_failaddr_t
> > +xfs_ifork_verify_data(
> > +	struct xfs_inode	*ip,
> > +	struct xfs_ifork_ops	*ops)
> > +{
> > +	xfs_ifork_verifier_t	fn = NULL;
> > +
> > +	/* Non-local data fork, we're done. */
> > +	if (ip->i_d.di_format != XFS_DINODE_FMT_LOCAL)
> > +		return NULL;
> > +
> > +	/* Check the inline data fork if there is one. */
> > +	if (S_ISDIR(VFS_I(ip)->i_mode))
> > +		fn = ops->verify_dir;
> > +	else if (S_ISLNK(VFS_I(ip)->i_mode))
> > +		fn = ops->verify_symlink;
> > +
> > +	if (fn)
> > +		return fn(ip);
> > +	return NULL;
> > +}
> 
> Seems a little convoluted, especially if we grow more cases. This
> seems simpler already:
> 
> 	switch(VFS_I(ip)->i_mode & S_IFMT) {
> 	case S_IFDIR:
> 		return ops->verify_dir(ip);
> 	case S_IFLNK:
> 		return ops->verify_symlink(ip);
> 	default:
> 		break;
> 	}
> 	return NULL;

Fixed.

> > +
> > +/* Verify the inline contents of the attr fork of an inode. */
> > +xfs_failaddr_t
> > +xfs_ifork_verify_attr(
> > +	struct xfs_inode	*ip,
> > +	struct xfs_ifork_ops	*ops)
> > +{
> > +	xfs_ifork_verifier_t	fn = NULL;
> > +
> > +	/* There has to be an attr fork allocated if aformat is local. */
> > +	if (ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
> > +		if (XFS_IFORK_PTR(ip, XFS_ATTR_FORK))
> > +			fn = ops->verify_attr;
> > +		else
> > +			return __this_address;
> > +	}
> > +
> > +	if (fn)
> > +		return fn(ip);
> > +	return NULL;
> 
> And this could be stright lined as:
> 
> 	if (ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)
> 		return NULL;
> 	if (!XFS_IFORK_PTR(ip, XFS_ATTR_FORK))
> 		return __this_address;
> 
> 	return ops->verify_attr(ip);

Fixed.

--D

> -Dave.
> 
> -- 
> Dave Chinner
> david@fromorbit.com
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2017-12-19 20:50 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13 23:58 [PATCH 00/13] xfs: more and better verifiers Darrick J. Wong
2017-12-13 23:58 ` [PATCH 01/13] xfs: refactor long-format btree header verification routines Darrick J. Wong
2017-12-14 22:06   ` Dave Chinner
2017-12-15  0:12     ` Darrick J. Wong
2017-12-13 23:58 ` [PATCH 02/13] xfs: remove XFS_WANT_CORRUPTED_RETURN from dir3 data verifiers Darrick J. Wong
2017-12-19  3:50   ` Dave Chinner
2017-12-13 23:58 ` [PATCH 03/13] xfs: have buffer verifier functions report failing address Darrick J. Wong
2017-12-19  4:12   ` Dave Chinner
2017-12-19 20:26     ` Darrick J. Wong
2017-12-13 23:58 ` [PATCH 04/13] xfs: refactor verifier callers to print address of failing check Darrick J. Wong
2017-12-14 22:03   ` Dave Chinner
2017-12-15  0:04     ` Darrick J. Wong
2017-12-15  3:09       ` Dave Chinner
2017-12-19 20:29         ` Darrick J. Wong
2017-12-13 23:58 ` [PATCH 05/13] xfs: verify dinode header first Darrick J. Wong
2017-12-19  4:13   ` Dave Chinner
2017-12-13 23:58 ` [PATCH 06/13] xfs: move inode fork verifiers to xfs_dinode_verify Darrick J. Wong
2017-12-19  5:16   ` Dave Chinner
2017-12-19 20:34     ` Darrick J. Wong
2017-12-19 20:48       ` Dave Chinner
2017-12-13 23:58 ` [PATCH 07/13] xfs: create structure verifier function for shortform xattrs Darrick J. Wong
2017-12-19  5:23   ` Dave Chinner
2017-12-19 20:41     ` Darrick J. Wong
2017-12-19 20:51       ` Dave Chinner
2017-12-19 21:04         ` Darrick J. Wong
2017-12-13 23:59 ` [PATCH 08/13] xfs: create structure verifier function for short form symlinks Darrick J. Wong
2017-12-19  5:27   ` Dave Chinner
2017-12-19 20:45     ` Darrick J. Wong
2017-12-13 23:59 ` [PATCH 09/13] xfs: refactor short form directory structure verifier function Darrick J. Wong
2017-12-19  5:45   ` Dave Chinner
2017-12-13 23:59 ` [PATCH 10/13] xfs: provide a centralized method for verifying inline fork data Darrick J. Wong
2017-12-19  6:06   ` Dave Chinner
2017-12-19 20:50     ` Darrick J. Wong [this message]
2017-12-13 23:59 ` [PATCH 11/13] xfs: fail out of xfs_attr3_leaf_lookup_int if it looks corrupt Darrick J. Wong
2017-12-19  6:13   ` Dave Chinner
2017-12-13 23:59 ` [PATCH 12/13] xfs: create a new buf_ops pointer to verify structure metadata Darrick J. Wong
2017-12-19  6:22   ` Dave Chinner
2017-12-19 18:15     ` Darrick J. Wong
2017-12-19 20:53       ` Dave Chinner
2017-12-13 23:59 ` [PATCH 13/13] xfs: scrub in-core metadata Darrick J. Wong
2017-12-19  6:23   ` 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=20171219205004.GE12613@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=david@fromorbit.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