Re: [PATCH V7 6/9] fs/xfs: Combine xfs_diflags_to_linux() and xfs_diflags_to_iflags()

From: Ira Weiny
Date: Tue Apr 14 2020 - 00:07:36 EST


On Mon, Apr 13, 2020 at 09:01:38AM -0700, Darrick J. Wong wrote:
> On Sun, Apr 12, 2020 at 10:40:43PM -0700, ira.weiny@xxxxxxxxx wrote:

[snip]

> >
> > -STATIC void
> > +void
> > xfs_diflags_to_iflags(
> > - struct inode *inode,
> > - struct xfs_inode *ip)
> > + struct xfs_inode *ip,
> > + bool init)
> > {
> > - uint16_t flags = ip->i_d.di_flags;
> > -
> > - inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC |
> > - S_NOATIME | S_DAX);
> > -
> > - if (flags & XFS_DIFLAG_IMMUTABLE)
> > - inode->i_flags |= S_IMMUTABLE;
> > - if (flags & XFS_DIFLAG_APPEND)
> > - inode->i_flags |= S_APPEND;
> > - if (flags & XFS_DIFLAG_SYNC)
> > - inode->i_flags |= S_SYNC;
> > - if (flags & XFS_DIFLAG_NOATIME)
> > - inode->i_flags |= S_NOATIME;
> > - if (xfs_inode_enable_dax(ip))
> > - inode->i_flags |= S_DAX;
> > + struct inode *inode = VFS_I(ip);
> > + unsigned int xflags = xfs_ip2xflags(ip);
> > + unsigned int flags = 0;
> > +
> > + ASSERT(!(IS_DAX(inode) && init));
> > +
> > + if (xflags & FS_XFLAG_IMMUTABLE)
> > + flags |= S_IMMUTABLE;
> > + if (xflags & FS_XFLAG_APPEND)
> > + flags |= S_APPEND;
> > + if (xflags & FS_XFLAG_SYNC)
> > + flags |= S_SYNC;
> > + if (xflags & FS_XFLAG_NOATIME)
> > + flags |= S_NOATIME;
> > + if (init && xfs_inode_enable_dax(ip))
> > + flags |= S_DAX;
> > +
> > + inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME);
>
> I noticed that S_DAX drops out of the mask out operation here, which of
> course resulted in an eyebrow-raise because the other four flags are
> always set to whatever we just computed. :)
>
> Then I realized that yes, this is intentional since we can't change
> S_DAX on the fly, and that S_DAX is never set i_flags on an inode that's
> being initialized so we don't need to mask off S_DAX ever.
>
> Could we add a comment here to remind the reader that S_DAX is a bit
> special?
>
> /*
> * S_DAX can only be set during inode initialization and is never set by
> * the VFS, so we cannot mask off S_DAX in i_flags.
> */
>
> With that added,
> Reviewed-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx>

Added that comment.

Thanks for the review!
Ira

>
> --D