Skip to content

Commit

Permalink
fs/xfs: Combine xfs_diflags_to_linux() and xfs_diflags_to_iflags()
Browse files Browse the repository at this point in the history
The functionality in xfs_diflags_to_linux() and xfs_diflags_to_iflags() are
nearly identical.  The only difference is that *_to_linux() is called after
inode setup and disallows changing the DAX flag.

Combining them can be done with a flag which indicates if this is the initial
setup to allow the DAX flag to be properly set only at init time.

So remove xfs_diflags_to_linux() and call the modified xfs_diflags_to_iflags()
directly.

While we are here simplify xfs_diflags_to_iflags() to take struct xfs_inode and
use xfs_ip2xflags() to ensure future diflags are included correctly.

Reviewed-by: Dave Chinner <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
Signed-off-by: Ira Weiny <[email protected]>
Signed-off-by: Darrick J. Wong <[email protected]>
  • Loading branch information
weiny2 authored and djwong committed May 30, 2020
1 parent f7bf743 commit b5df628
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 51 deletions.
1 change: 1 addition & 0 deletions fs/xfs/xfs_inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ int xfs_break_layouts(struct inode *inode, uint *iolock,
/* from xfs_iops.c */
extern void xfs_setup_inode(struct xfs_inode *ip);
extern void xfs_setup_iops(struct xfs_inode *ip);
extern void xfs_diflags_to_iflags(struct xfs_inode *ip, bool init);

/*
* When setting up a newly allocated inode, we need to call
Expand Down
33 changes: 1 addition & 32 deletions fs/xfs/xfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,37 +1201,6 @@ xfs_flags2diflags2(
return di_flags2;
}

STATIC void
xfs_diflags_to_linux(
struct xfs_inode *ip)
{
struct inode *inode = VFS_I(ip);
unsigned int xflags = xfs_ip2xflags(ip);

if (xflags & FS_XFLAG_IMMUTABLE)
inode->i_flags |= S_IMMUTABLE;
else
inode->i_flags &= ~S_IMMUTABLE;
if (xflags & FS_XFLAG_APPEND)
inode->i_flags |= S_APPEND;
else
inode->i_flags &= ~S_APPEND;
if (xflags & FS_XFLAG_SYNC)
inode->i_flags |= S_SYNC;
else
inode->i_flags &= ~S_SYNC;
if (xflags & FS_XFLAG_NOATIME)
inode->i_flags |= S_NOATIME;
else
inode->i_flags &= ~S_NOATIME;
#if 0 /* disabled until the flag switching races are sorted out */
if (xflags & FS_XFLAG_DAX)
inode->i_flags |= S_DAX;
else
inode->i_flags &= ~S_DAX;
#endif
}

static int
xfs_ioctl_setattr_xflags(
struct xfs_trans *tp,
Expand Down Expand Up @@ -1269,7 +1238,7 @@ xfs_ioctl_setattr_xflags(
ip->i_d.di_flags = xfs_flags2diflags(ip, fa->fsx_xflags);
ip->i_d.di_flags2 = di_flags2;

xfs_diflags_to_linux(ip);
xfs_diflags_to_iflags(ip, false);
xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
XFS_STATS_INC(mp, xs_ig_attrchg);
Expand Down
46 changes: 27 additions & 19 deletions fs/xfs/xfs_iops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,26 +1276,34 @@ xfs_inode_should_enable_dax(
return false;
}

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_should_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_should_enable_dax(ip))
flags |= S_DAX;

/*
* 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.
*/
inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME);
inode->i_flags |= flags;
}

/*
Expand All @@ -1321,7 +1329,7 @@ xfs_setup_inode(
inode_fake_hash(inode);

i_size_write(inode, ip->i_d.di_size);
xfs_diflags_to_iflags(inode, ip);
xfs_diflags_to_iflags(ip, true);

if (S_ISDIR(inode->i_mode)) {
/*
Expand Down

0 comments on commit b5df628

Please sign in to comment.