All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: xfs <linux-xfs@vger.kernel.org>, Jan Kara <jack@suse.cz>,
	Christoph Hellwig <hch@infradead.org>
Subject: Re: [PATCH v2] xfs: don't set v3 xflags for v2 inodes
Date: Thu, 31 Aug 2017 09:35:50 -0400	[thread overview]
Message-ID: <20170831133550.GC21939@bfoster.bfoster> (raw)
In-Reply-To: <20170830163825.GQ4757@magnolia>

On Wed, Aug 30, 2017 at 09:38:25AM -0700, Darrick J. Wong wrote:
> Reject attempts to set XFLAGS that correspond to di_flags2 inode flags
> if the inode isn't a v3 inode, because di_flags2 only exists on v3.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---

That lazy reflink flag clear still seems hacky. That aside, this looks
fine to me:

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/xfs/xfs_ioctl.c |   37 +++++++++++++++++++++++++++++--------
>  1 file changed, 29 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index 06ca244..82d14fe 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -1016,32 +1016,37 @@ xfs_diflags_to_linux(
>  #endif
>  }
>  
> +#define XFS_V3_INODE_XFLAGS	(FS_XFLAG_DAX | \
> +				 FS_XFLAG_COWEXTSIZE)
>  static int
> -xfs_ioctl_setattr_xflags(
> -	struct xfs_trans	*tp,
> +xfs_check_diflags(
>  	struct xfs_inode	*ip,
> -	struct fsxattr		*fa)
> +	__u32			xflags)
>  {
>  	struct xfs_mount	*mp = ip->i_mount;
>  
> +	/* Can't set flags2 fields on a v2 inode. */
> +	if (ip->i_d.di_version < 3 && (xflags & XFS_V3_INODE_XFLAGS))
> +		return -EINVAL;
> +
>  	/* Can't change realtime flag if any extents are allocated. */
>  	if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
> -	    XFS_IS_REALTIME_INODE(ip) != (fa->fsx_xflags & FS_XFLAG_REALTIME))
> +	    XFS_IS_REALTIME_INODE(ip) != (xflags & FS_XFLAG_REALTIME))
>  		return -EINVAL;
>  
>  	/* If realtime flag is set then must have realtime device */
> -	if (fa->fsx_xflags & FS_XFLAG_REALTIME) {
> +	if (xflags & FS_XFLAG_REALTIME) {
>  		if (mp->m_sb.sb_rblocks == 0 || mp->m_sb.sb_rextsize == 0 ||
>  		    (ip->i_d.di_extsize % mp->m_sb.sb_rextsize))
>  			return -EINVAL;
>  	}
>  
>  	/* Clear reflink if we are actually able to set the rt flag. */
> -	if ((fa->fsx_xflags & FS_XFLAG_REALTIME) && xfs_is_reflink_inode(ip))
> +	if ((xflags & FS_XFLAG_REALTIME) && xfs_is_reflink_inode(ip))
>  		ip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK;
>  
>  	/* Don't allow us to set DAX mode for a reflinked file for now. */
> -	if ((fa->fsx_xflags & FS_XFLAG_DAX) && xfs_is_reflink_inode(ip))
> +	if ((xflags & FS_XFLAG_DAX) && xfs_is_reflink_inode(ip))
>  		return -EINVAL;
>  
>  	/*
> @@ -1049,10 +1054,26 @@ xfs_ioctl_setattr_xflags(
>  	 * we have appropriate permission.
>  	 */
>  	if (((ip->i_d.di_flags & (XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND)) ||
> -	     (fa->fsx_xflags & (FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND))) &&
> +	     (xflags & (FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND))) &&
>  	    !capable(CAP_LINUX_IMMUTABLE))
>  		return -EPERM;
>  
> +	return 0;
> +}
> +
> +static int
> +xfs_ioctl_setattr_xflags(
> +	struct xfs_trans	*tp,
> +	struct xfs_inode	*ip,
> +	struct fsxattr		*fa)
> +{
> +	struct xfs_mount	*mp = ip->i_mount;
> +	int			ret;
> +
> +	ret = xfs_check_diflags(ip, fa->fsx_xflags);
> +	if (ret)
> +		return ret;
> +
>  	xfs_set_diflags(ip, fa->fsx_xflags);
>  	xfs_diflags_to_linux(ip);
>  	xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
> --
> 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

      parent reply	other threads:[~2017-08-31 13:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-30 15:55 [PATCH] xfs: don't set DAX flag for v2 inodes Darrick J. Wong
2017-08-30 16:15 ` Christoph Hellwig
2017-08-30 16:22   ` Darrick J. Wong
2017-08-30 16:38 ` [PATCH v2] xfs: don't set v3 xflags " Darrick J. Wong
2017-08-31 13:17   ` Christoph Hellwig
2017-08-31 13:34     ` Brian Foster
2017-08-31 14:06       ` Christoph Hellwig
2017-08-31 14:09       ` Christoph Hellwig
2017-08-31 14:17         ` Brian Foster
2017-08-31 19:57         ` Darrick J. Wong
2017-09-01  7:21           ` Christoph Hellwig
2017-09-01 17:52             ` Darrick J. Wong
2017-09-01 19:29               ` Christoph Hellwig
2017-09-01 19:40                 ` Darrick J. Wong
2017-09-01 20:06                   ` Darrick J. Wong
2017-09-01 20:08                     ` Christoph Hellwig
2017-08-31 13:35   ` Brian Foster [this message]

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=20170831133550.GC21939@bfoster.bfoster \
    --to=bfoster@redhat.com \
    --cc=darrick.wong@oracle.com \
    --cc=hch@infradead.org \
    --cc=jack@suse.cz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.