提交 6dfe5a04 编写于 作者: D Dave Chinner 提交者: Dave Chinner

xfs: xfs_attr_inactive leaves inconsistent attr fork state behind

xfs_attr_inactive() is supposed to clean up the attribute fork when
the inode is being freed. While it removes attribute fork extents,
it completely ignores attributes in local format, which means that
there can still be active attributes on the inode after
xfs_attr_inactive() has run.

This leads to problems with concurrent inode writeback - the in-core
inode attribute fork is removed without locking on the assumption
that nothing will be attempting to access the attribute fork after a
call to xfs_attr_inactive() because it isn't supposed to exist on
disk any more.

To fix this, make xfs_attr_inactive() completely remove all traces
of the attribute fork from the inode, regardless of it's state.
Further, also remove the in-core attribute fork structure safely so
that there is nothing further that needs to be done by callers to
clean up the attribute fork. This means we can remove the in-core
and on-disk attribute forks atomically.

Also, on error simply remove the in-memory attribute fork. There's
nothing that can be done with it once we have failed to remove the
on-disk attribute fork, so we may as well just blow it away here
anyway.

cc: <stable@vger.kernel.org> # 3.12 to 4.0
Reported-by: NWaiman Long <waiman.long@hp.com>
Signed-off-by: NDave Chinner <dchinner@redhat.com>
Reviewed-by: NBrian Foster <bfoster@redhat.com>
Signed-off-by: NDave Chinner <david@fromorbit.com>
上级 6dea405e
...@@ -574,8 +574,8 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) ...@@ -574,8 +574,8 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
* After the last attribute is removed revert to original inode format, * After the last attribute is removed revert to original inode format,
* making all literal area available to the data fork once more. * making all literal area available to the data fork once more.
*/ */
STATIC void void
xfs_attr_fork_reset( xfs_attr_fork_remove(
struct xfs_inode *ip, struct xfs_inode *ip,
struct xfs_trans *tp) struct xfs_trans *tp)
{ {
...@@ -641,7 +641,7 @@ xfs_attr_shortform_remove(xfs_da_args_t *args) ...@@ -641,7 +641,7 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
(mp->m_flags & XFS_MOUNT_ATTR2) && (mp->m_flags & XFS_MOUNT_ATTR2) &&
(dp->i_d.di_format != XFS_DINODE_FMT_BTREE) && (dp->i_d.di_format != XFS_DINODE_FMT_BTREE) &&
!(args->op_flags & XFS_DA_OP_ADDNAME)) { !(args->op_flags & XFS_DA_OP_ADDNAME)) {
xfs_attr_fork_reset(dp, args->trans); xfs_attr_fork_remove(dp, args->trans);
} else { } else {
xfs_idata_realloc(dp, -size, XFS_ATTR_FORK); xfs_idata_realloc(dp, -size, XFS_ATTR_FORK);
dp->i_d.di_forkoff = xfs_attr_shortform_bytesfit(dp, totsize); dp->i_d.di_forkoff = xfs_attr_shortform_bytesfit(dp, totsize);
...@@ -905,7 +905,7 @@ xfs_attr3_leaf_to_shortform( ...@@ -905,7 +905,7 @@ xfs_attr3_leaf_to_shortform(
if (forkoff == -1) { if (forkoff == -1) {
ASSERT(dp->i_mount->m_flags & XFS_MOUNT_ATTR2); ASSERT(dp->i_mount->m_flags & XFS_MOUNT_ATTR2);
ASSERT(dp->i_d.di_format != XFS_DINODE_FMT_BTREE); ASSERT(dp->i_d.di_format != XFS_DINODE_FMT_BTREE);
xfs_attr_fork_reset(dp, args->trans); xfs_attr_fork_remove(dp, args->trans);
goto out; goto out;
} }
......
...@@ -53,7 +53,7 @@ int xfs_attr_shortform_remove(struct xfs_da_args *args); ...@@ -53,7 +53,7 @@ int xfs_attr_shortform_remove(struct xfs_da_args *args);
int xfs_attr_shortform_list(struct xfs_attr_list_context *context); int xfs_attr_shortform_list(struct xfs_attr_list_context *context);
int xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp); int xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
int xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes); int xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes);
void xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp);
/* /*
* Internal routines when attribute fork size == XFS_LBSIZE(mp). * Internal routines when attribute fork size == XFS_LBSIZE(mp).
......
...@@ -380,23 +380,31 @@ xfs_attr3_root_inactive( ...@@ -380,23 +380,31 @@ xfs_attr3_root_inactive(
return error; return error;
} }
/*
* xfs_attr_inactive kills all traces of an attribute fork on an inode. It
* removes both the on-disk and in-memory inode fork. Note that this also has to
* handle the condition of inodes without attributes but with an attribute fork
* configured, so we can't use xfs_inode_hasattr() here.
*
* The in-memory attribute fork is removed even on error.
*/
int int
xfs_attr_inactive(xfs_inode_t *dp) xfs_attr_inactive(
struct xfs_inode *dp)
{ {
xfs_trans_t *trans; struct xfs_trans *trans;
xfs_mount_t *mp; struct xfs_mount *mp;
int error; int cancel_flags = 0;
int lock_mode = XFS_ILOCK_SHARED;
int error = 0;
mp = dp->i_mount; mp = dp->i_mount;
ASSERT(! XFS_NOT_DQATTACHED(mp, dp)); ASSERT(! XFS_NOT_DQATTACHED(mp, dp));
xfs_ilock(dp, XFS_ILOCK_SHARED); xfs_ilock(dp, lock_mode);
if (!xfs_inode_hasattr(dp) || if (!XFS_IFORK_Q(dp))
dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) { goto out_destroy_fork;
xfs_iunlock(dp, XFS_ILOCK_SHARED); xfs_iunlock(dp, lock_mode);
return 0;
}
xfs_iunlock(dp, XFS_ILOCK_SHARED);
/* /*
* Start our first transaction of the day. * Start our first transaction of the day.
...@@ -408,13 +416,18 @@ xfs_attr_inactive(xfs_inode_t *dp) ...@@ -408,13 +416,18 @@ xfs_attr_inactive(xfs_inode_t *dp)
* the inode in every transaction to let it float upward through * the inode in every transaction to let it float upward through
* the log. * the log.
*/ */
lock_mode = 0;
trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL); trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL);
error = xfs_trans_reserve(trans, &M_RES(mp)->tr_attrinval, 0, 0); error = xfs_trans_reserve(trans, &M_RES(mp)->tr_attrinval, 0, 0);
if (error) { if (error)
xfs_trans_cancel(trans, 0); goto out_cancel;
return error;
} lock_mode = XFS_ILOCK_EXCL;
xfs_ilock(dp, XFS_ILOCK_EXCL); cancel_flags = XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT;
xfs_ilock(dp, lock_mode);
if (!XFS_IFORK_Q(dp))
goto out_cancel;
/* /*
* No need to make quota reservations here. We expect to release some * No need to make quota reservations here. We expect to release some
...@@ -422,29 +435,31 @@ xfs_attr_inactive(xfs_inode_t *dp) ...@@ -422,29 +435,31 @@ xfs_attr_inactive(xfs_inode_t *dp)
*/ */
xfs_trans_ijoin(trans, dp, 0); xfs_trans_ijoin(trans, dp, 0);
/* /* invalidate and truncate the attribute fork extents */
* Decide on what work routines to call based on the inode size. if (dp->i_d.di_aformat != XFS_DINODE_FMT_LOCAL) {
*/
if (!xfs_inode_hasattr(dp) ||
dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
error = 0;
goto out;
}
error = xfs_attr3_root_inactive(&trans, dp); error = xfs_attr3_root_inactive(&trans, dp);
if (error) if (error)
goto out; goto out_cancel;
error = xfs_itruncate_extents(&trans, dp, XFS_ATTR_FORK, 0); error = xfs_itruncate_extents(&trans, dp, XFS_ATTR_FORK, 0);
if (error) if (error)
goto out; goto out_cancel;
}
error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES); /* Reset the attribute fork - this also destroys the in-core fork */
xfs_iunlock(dp, XFS_ILOCK_EXCL); xfs_attr_fork_remove(dp, trans);
error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES);
xfs_iunlock(dp, lock_mode);
return error; return error;
out: out_cancel:
xfs_trans_cancel(trans, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT); xfs_trans_cancel(trans, cancel_flags);
xfs_iunlock(dp, XFS_ILOCK_EXCL); out_destroy_fork:
/* kill the in-core attr fork before we drop the inode lock */
if (dp->i_afp)
xfs_idestroy_fork(dp, XFS_ATTR_FORK);
if (lock_mode)
xfs_iunlock(dp, lock_mode);
return error; return error;
} }
...@@ -1946,21 +1946,17 @@ xfs_inactive( ...@@ -1946,21 +1946,17 @@ xfs_inactive(
/* /*
* If there are attributes associated with the file then blow them away * If there are attributes associated with the file then blow them away
* now. The code calls a routine that recursively deconstructs the * now. The code calls a routine that recursively deconstructs the
* attribute fork. We need to just commit the current transaction * attribute fork. If also blows away the in-core attribute fork.
* because we can't use it for xfs_attr_inactive().
*/ */
if (ip->i_d.di_anextents > 0) { if (XFS_IFORK_Q(ip)) {
ASSERT(ip->i_d.di_forkoff != 0);
error = xfs_attr_inactive(ip); error = xfs_attr_inactive(ip);
if (error) if (error)
return; return;
} }
if (ip->i_afp) ASSERT(!ip->i_afp);
xfs_idestroy_fork(ip, XFS_ATTR_FORK);
ASSERT(ip->i_d.di_anextents == 0); ASSERT(ip->i_d.di_anextents == 0);
ASSERT(ip->i_d.di_forkoff == 0);
/* /*
* Free the inode. * Free the inode.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册