Commit 70393313 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Dave Chinner

xfs: saner xfs_trans_commit interface

The flags argument to xfs_trans_commit is not useful for most callers, as
a commit of a transaction without a permanent log reservation must pass
0 here, and all callers for a transaction with a permanent log reservation
except for xfs_trans_roll must pass XFS_TRANS_RELEASE_LOG_RES.  So remove
the flags argument from the public xfs_trans_commit interfaces, and
introduce low-level __xfs_trans_commit variant just for xfs_trans_roll
that regrants a log reservation instead of releasing it.
Signed-off-by: 's avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: 's avatarDave Chinner <dchinner@redhat.com>
Signed-off-by: 's avatarDave Chinner <david@fromorbit.com>
parent 4906e215
......@@ -320,8 +320,7 @@ xfs_attr_set(
xfs_trans_ichgtime(args.trans, dp,
XFS_ICHGTIME_CHG);
}
err2 = xfs_trans_commit(args.trans,
XFS_TRANS_RELEASE_LOG_RES);
err2 = xfs_trans_commit(args.trans);
xfs_iunlock(dp, XFS_ILOCK_EXCL);
return error ? error : err2;
......@@ -383,7 +382,7 @@ xfs_attr_set(
* Commit the last in the sequence of transactions.
*/
xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(args.trans);
xfs_iunlock(dp, XFS_ILOCK_EXCL);
return error;
......@@ -499,7 +498,7 @@ xfs_attr_remove(
* Commit the last in the sequence of transactions.
*/
xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(args.trans);
xfs_iunlock(dp, XFS_ILOCK_EXCL);
return error;
......
......@@ -1215,7 +1215,7 @@ xfs_bmap_add_attrfork(
error = xfs_bmap_finish(&tp, &flist, &committed);
if (error)
goto bmap_cancel;
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
xfs_iunlock(ip, XFS_ILOCK_EXCL);
return error;
......@@ -5926,8 +5926,7 @@ xfs_bmap_split_extent(
if (error)
goto out;
return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
return xfs_trans_commit(tp);
out:
xfs_trans_cancel(tp);
......
......@@ -799,5 +799,5 @@ xfs_sync_sb(
xfs_log_sb(tp);
if (wait)
xfs_trans_set_sync(tp);
return xfs_trans_commit(tp, 0);
return xfs_trans_commit(tp);
}
......@@ -181,11 +181,6 @@ int xfs_log_calc_minimum_size(struct xfs_mount *);
#define XFS_TRANS_RESERVE 0x20 /* OK to use reserved data blocks */
#define XFS_TRANS_FREEZE_PROT 0x40 /* Transaction has elevated writer
count in superblock */
/*
* Values for call flags parameter.
*/
#define XFS_TRANS_RELEASE_LOG_RES 0x4
/*
* Field values for xfs_trans_mod_sb.
*/
......
......@@ -155,7 +155,7 @@ xfs_setfilesize(
xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
return xfs_trans_commit(tp, 0);
return xfs_trans_commit(tp);
}
STATIC int
......
......@@ -438,7 +438,7 @@ xfs_attr_inactive(xfs_inode_t *dp)
if (error)
goto out;
error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(trans);
xfs_iunlock(dp, XFS_ILOCK_EXCL);
return error;
......
......@@ -893,8 +893,7 @@ xfs_free_eofblocks(
*/
xfs_trans_cancel(tp);
} else {
error = xfs_trans_commit(tp,
XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (!error)
xfs_inode_clear_eofblocks_tag(ip);
}
......@@ -1034,7 +1033,7 @@ xfs_alloc_file_space(
goto error0;
}
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
xfs_iunlock(ip, XFS_ILOCK_EXCL);
if (error) {
break;
......@@ -1301,7 +1300,7 @@ xfs_free_file_space(
goto error0;
}
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
xfs_iunlock(ip, XFS_ILOCK_EXCL);
}
......@@ -1473,7 +1472,7 @@ xfs_shift_file_space(
if (error)
goto out;
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
}
return error;
......@@ -1882,7 +1881,7 @@ xfs_swap_extents(
if (mp->m_flags & XFS_MOUNT_WSYNC)
xfs_trans_set_sync(tp);
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
trace_xfs_swap_extent_after(ip, 0);
trace_xfs_swap_extent_after(tip, 1);
......
......@@ -666,7 +666,7 @@ xfs_qm_dqread(
xfs_trans_brelse(tp, bp);
if (tp) {
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error)
goto error0;
}
......
......@@ -160,7 +160,7 @@ xfs_update_prealloc_flags(
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
if (flags & XFS_PREALLOC_SYNC)
xfs_trans_set_sync(tp);
return xfs_trans_commit(tp, 0);
return xfs_trans_commit(tp);
}
/*
......
......@@ -489,7 +489,7 @@ xfs_growfs_data_private(
if (dpct)
xfs_trans_mod_sb(tp, XFS_TRANS_SB_IMAXPCT, dpct);
xfs_trans_set_sync(tp);
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
if (error)
return error;
......
......@@ -1230,7 +1230,7 @@ xfs_create(
if (error)
goto out_bmap_cancel;
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error)
goto out_release_inode;
......@@ -1339,7 +1339,7 @@ xfs_create_tmpfile(
if (error)
goto out_trans_cancel;
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error)
goto out_release_inode;
......@@ -1465,7 +1465,7 @@ xfs_link(
goto error_return;
}
return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
return xfs_trans_commit(tp);
error_return:
xfs_trans_cancel(tp);
......@@ -1702,7 +1702,7 @@ xfs_inactive_truncate(
ASSERT(ip->i_d.di_nextents == 0);
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error)
goto error_unlock;
......@@ -1799,7 +1799,7 @@ xfs_inactive_ifree(
if (error)
xfs_notice(mp, "%s: xfs_bmap_finish returned error %d",
__func__, error);
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error)
xfs_notice(mp, "%s: xfs_trans_commit returned error %d",
__func__, error);
......@@ -2569,7 +2569,7 @@ xfs_remove(
if (error)
goto out_bmap_cancel;
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error)
goto std_return;
......@@ -2659,7 +2659,7 @@ xfs_finish_rename(
return error;
}
return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
return xfs_trans_commit(tp);
}
/*
......
......@@ -346,7 +346,7 @@ xfs_set_dmattrs(
ip->i_d.di_dmstate = state;
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
return error;
}
......@@ -1253,7 +1253,7 @@ xfs_ioctl_setattr(
else
ip->i_d.di_extsize = 0;
code = xfs_trans_commit(tp, 0);
code = xfs_trans_commit(tp);
/*
* Release any dquot(s) the inode had kept before chown.
......@@ -1342,7 +1342,7 @@ xfs_ioc_setxflags(
goto out_drop_write;
}
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
out_drop_write:
mnt_drop_write_file(filp);
return error;
......
......@@ -213,7 +213,7 @@ xfs_iomap_write_direct(
error = xfs_bmap_finish(&tp, &free_list, &committed);
if (error)
goto out_bmap_cancel;
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error)
goto out_unlock;
......@@ -760,7 +760,7 @@ xfs_iomap_write_allocate(
if (error)
goto trans_cancel;
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error)
goto error0;
......@@ -890,7 +890,7 @@ xfs_iomap_write_unwritten(
if (error)
goto error_on_bmapi_transaction;
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
xfs_iunlock(ip, XFS_ILOCK_EXCL);
if (error)
return error;
......
......@@ -702,7 +702,7 @@ xfs_setattr_nonsize(
if (mp->m_flags & XFS_MOUNT_WSYNC)
xfs_trans_set_sync(tp);
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
xfs_iunlock(ip, XFS_ILOCK_EXCL);
......@@ -926,7 +926,7 @@ xfs_setattr_size(
if (mp->m_flags & XFS_MOUNT_WSYNC)
xfs_trans_set_sync(tp);
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
out_unlock:
if (lock_flags)
xfs_iunlock(ip, lock_flags);
......@@ -1002,7 +1002,7 @@ xfs_vn_update_time(
}
xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
return xfs_trans_commit(tp, 0);
return xfs_trans_commit(tp);
}
#define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR)
......
......@@ -183,7 +183,7 @@ struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
void xfs_log_ticket_put(struct xlog_ticket *ticket);
void xfs_log_commit_cil(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_lsn_t *commit_lsn, int flags);
xfs_lsn_t *commit_lsn, bool regrant);
bool xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
void xfs_log_work_queue(struct xfs_mount *mp);
......
......@@ -773,13 +773,13 @@ xfs_log_commit_cil(
struct xfs_mount *mp,
struct xfs_trans *tp,
xfs_lsn_t *commit_lsn,
int flags)
bool regrant)
{
struct xlog *log = mp->m_log;
struct xfs_cil *cil = log->l_cilp;
int log_flags = 0;
if (flags & XFS_TRANS_RELEASE_LOG_RES)
if (!regrant)
log_flags = XFS_LOG_REL_PERM_RESERV;
/* lock out background commit */
......
......@@ -3751,7 +3751,7 @@ xlog_recover_process_efi(
}
set_bit(XFS_EFI_RECOVERED, &efip->efi_flags);
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
return error;
abort_error:
......@@ -3857,7 +3857,7 @@ xlog_recover_clear_agi_bucket(
xfs_trans_log_buf(tp, agibp, offset,
(offset + sizeof(xfs_agino_t) - 1));
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
if (error)
goto out_error;
return;
......
......@@ -321,7 +321,7 @@ xfs_fs_commit_blocks(
}
xfs_trans_set_sync(tp);
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
out_drop_iolock:
xfs_iunlock(ip, XFS_IOLOCK_EXCL);
......
......@@ -795,7 +795,7 @@ xfs_qm_qino_alloc(
spin_unlock(&mp->m_sb_lock);
xfs_log_sb(tp);
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error) {
ASSERT(XFS_FORCED_SHUTDOWN(mp));
xfs_alert(mp, "%s failed (error %d)!", __func__, error);
......
......@@ -259,7 +259,7 @@ xfs_qm_scall_trunc_qfile(
ASSERT(ip->i_d.di_nextents == 0);
xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
out_unlock:
xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
......@@ -547,7 +547,7 @@ xfs_qm_scall_setqlim(
dqp->dq_flags |= XFS_DQ_DIRTY;
xfs_trans_log_dquot(tp, dqp);
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
out_rele:
xfs_qm_dqrele(dqp);
......@@ -584,8 +584,7 @@ xfs_qm_log_quotaoff_end(
* We don't care about quotoff's performance.
*/
xfs_trans_set_sync(tp);
error = xfs_trans_commit(tp, 0);
return error;
return xfs_trans_commit(tp);
}
......@@ -623,7 +622,7 @@ xfs_qm_log_quotaoff(
* We don't care about quotoff's performance.
*/
xfs_trans_set_sync(tp);
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
if (error)
goto out;
......
......@@ -815,7 +815,7 @@ xfs_growfs_rt_alloc(
error = xfs_bmap_finish(&tp, &flist, &committed);
if (error)
goto error_cancel;
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error)
goto error;
/*
......@@ -855,7 +855,7 @@ xfs_growfs_rt_alloc(
/*
* Commit the transaction.
*/
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
if (error)
goto error;
}
......@@ -1070,7 +1070,7 @@ xfs_growfs_rt(
mp->m_rsumlevels = nrsumlevels;
mp->m_rsumsize = nrsumsize;
error = xfs_trans_commit(tp, 0);
error = xfs_trans_commit(tp);
if (error)
break;
}
......
......@@ -390,7 +390,7 @@ xfs_symlink(
if (error)
goto out_bmap_cancel;
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error)
goto out_release_inode;
......@@ -528,7 +528,7 @@ xfs_inactive_symlink_rmt(
/*
* Commit the transaction containing extent freeing and EFDs.
*/
error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
error = xfs_trans_commit(tp);
if (error) {
ASSERT(XFS_FORCED_SHUTDOWN(mp));
goto error_unlock;
......
......@@ -892,26 +892,16 @@ xfs_trans_committed_bulk(
* have already been unlocked as if the commit had succeeded.
* Do not reference the transaction structure after this call.
*/
int
xfs_trans_commit(
static int
__xfs_trans_commit(
struct xfs_trans *tp,
uint flags)
bool regrant)
{
struct xfs_mount *mp = tp->t_mountp;
xfs_lsn_t commit_lsn = -1;
int error = 0;
int log_flags = 0;
int sync = tp->t_flags & XFS_TRANS_SYNC;
/*
* Determine whether this commit is releasing a permanent
* log reservation or not.
*/
if (flags & XFS_TRANS_RELEASE_LOG_RES) {
ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
log_flags = XFS_LOG_REL_PERM_RESERV;
}
/*
* If there is nothing to be logged by the transaction,
* then unlock all of the items associated with the
......@@ -936,7 +926,7 @@ xfs_trans_commit(
xfs_trans_apply_sb_deltas(tp);
xfs_trans_apply_dquot_deltas(tp);
xfs_log_commit_cil(mp, tp, &commit_lsn, flags);
xfs_log_commit_cil(mp, tp, &commit_lsn, regrant);
current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
xfs_trans_free(tp);
......@@ -964,6 +954,12 @@ xfs_trans_commit(
*/
xfs_trans_unreserve_and_mod_dquots(tp);
if (tp->t_ticket) {
int log_flags = 0;
if (regrant)
ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
else
log_flags = XFS_LOG_REL_PERM_RESERV;
commit_lsn = xfs_log_done(mp, tp->t_ticket, NULL, log_flags);
if (commit_lsn == -1 && !error)
error = -EIO;
......@@ -976,6 +972,13 @@ xfs_trans_commit(
return error;
}
int
xfs_trans_commit(
struct xfs_trans *tp)
{
return __xfs_trans_commit(tp, false);
}
/*
* Unlock all of the transaction's items and free the transaction.
* The transaction must not have modified any of its items, because
......@@ -1029,7 +1032,7 @@ xfs_trans_cancel(
/*
* Roll from one trans in the sequence of PERMANENT transactions to
* the next: permanent transactions are only flushed out when
* committed with XFS_TRANS_RELEASE_LOG_RES, but we still want as soon
* committed with xfs_trans_commit(), but we still want as soon
* as possible to let chunks of it go to the log. So we commit the
* chunk we've been working on and get a new transaction to continue.
*/
......@@ -1063,7 +1066,7 @@ xfs_trans_roll(
* is in progress. The caller takes the responsibility to cancel
* the duplicate transaction that gets returned.
*/
error = xfs_trans_commit(trans, 0);
error = __xfs_trans_commit(trans, true);
if (error)
return error;
......
......@@ -225,7 +225,7 @@ void xfs_trans_log_efd_extent(xfs_trans_t *,
struct xfs_efd_log_item *,
xfs_fsblock_t,
xfs_extlen_t);
int xfs_trans_commit(xfs_trans_t *, uint flags);
int xfs_trans_commit(struct xfs_trans *);
int xfs_trans_roll(struct xfs_trans **, struct xfs_inode *);
void xfs_trans_cancel(xfs_trans_t *);
int xfs_trans_ail_init(struct xfs_mount *);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment