* [PATCH 0/4] xfsprogs-4.19: transaction cleanups
@ 2018-09-18 18:54 Darrick J. Wong
2018-09-18 18:54 ` [PATCH 1/4] libxfs: port kernel transaction code Darrick J. Wong
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Darrick J. Wong @ 2018-09-18 18:54 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
<urk>
Here are four cleanups to the userspace transaction code that make the
commit and roll code more closely resemble their kernel counterparts.
This was supposed to go ahead of the libxfs sync so that it might be
easier to port the changes made by Brian's defer ops rework to
userspace.
Regrettably I wasn't able to push these out before Eric posted his own
libxfs sync branch... so, uh, yeah. I guess I'll post them so we can
figure out whether we should rebase the branch or the series or
something.
--D
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] libxfs: port kernel transaction code
2018-09-18 18:54 [PATCH 0/4] xfsprogs-4.19: transaction cleanups Darrick J. Wong
@ 2018-09-18 18:54 ` Darrick J. Wong
2018-09-18 18:55 ` [PATCH 2/4] libxfs: fix libxfs_trans_alloc callsite problems Darrick J. Wong
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2018-09-18 18:54 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
Restructure the userspace transaction code to resemble the kernel code
more closely. This will simplify porting the upcoming defer_ops
refactoring.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
libxfs/trans.c | 206 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 165 insertions(+), 41 deletions(-)
diff --git a/libxfs/trans.c b/libxfs/trans.c
index 2bb0d3b8..e827f0df 100644
--- a/libxfs/trans.c
+++ b/libxfs/trans.c
@@ -19,6 +19,10 @@
#include "xfs_sb.h"
static void xfs_trans_free_items(struct xfs_trans *tp);
+STATIC struct xfs_trans *xfs_trans_dup(struct xfs_trans *tp);
+static int xfs_trans_reserve(struct xfs_trans *tp, struct xfs_trans_res *resp,
+ uint blocks, uint rtextents);
+static int __xfs_trans_commit(struct xfs_trans *tp, bool regrant);
/*
* Simple transaction interface
@@ -75,19 +79,17 @@ int
libxfs_trans_roll(
struct xfs_trans **tpp)
{
- struct xfs_mount *mp;
struct xfs_trans *trans = *tpp;
struct xfs_trans_res tres;
- unsigned int old_blk_res;
int error;
/*
* Copy the critical parameters from one trans to the next.
*/
- mp = trans->t_mountp;
tres.tr_logres = trans->t_log_res;
tres.tr_logcount = trans->t_log_count;
- old_blk_res = trans->t_blk_res;
+
+ *tpp = xfs_trans_dup(trans);
/*
* Commit the current transaction.
@@ -96,7 +98,7 @@ libxfs_trans_roll(
* is in progress. The caller takes the responsibility to cancel
* the duplicate transaction that gets returned.
*/
- error = xfs_trans_commit(trans);
+ error = __xfs_trans_commit(trans, true);
if (error)
return error;
@@ -109,11 +111,7 @@ libxfs_trans_roll(
* the prior and the next transactions.
*/
tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
- error = libxfs_trans_alloc(mp, &tres, 0, 0, 0, tpp);
- trans = *tpp;
- trans->t_blk_res = old_blk_res;
-
- return 0;
+ return xfs_trans_reserve(*tpp, &tres, 0, 0);
}
/*
@@ -127,38 +125,145 @@ xfs_trans_free(
kmem_zone_free(xfs_trans_zone, tp);
}
-int
-libxfs_trans_alloc(
- struct xfs_mount *mp,
- struct xfs_trans_res *resp,
- unsigned int blocks,
- unsigned int rtextents,
- unsigned int flags,
- struct xfs_trans **tpp)
+/*
+ * This is called to create a new transaction which will share the
+ * permanent log reservation of the given transaction. The remaining
+ * unused block and rt extent reservations are also inherited. This
+ * implies that the original transaction is no longer allowed to allocate
+ * blocks. Locks and log items, however, are no inherited. They must
+ * be added to the new transaction explicitly.
+ */
+STATIC struct xfs_trans *
+xfs_trans_dup(
+ struct xfs_trans *tp)
+{
+ struct xfs_trans *ntp;
+
+ ntp = kmem_zone_zalloc(xfs_trans_zone, KM_SLEEP);
+
+ /*
+ * Initialize the new transaction structure.
+ */
+ ntp->t_mountp = tp->t_mountp;
+ INIT_LIST_HEAD(&ntp->t_items);
+
+ ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
+
+ ntp->t_flags = XFS_TRANS_PERM_LOG_RES |
+ (tp->t_flags & XFS_TRANS_RESERVE) |
+ (tp->t_flags & XFS_TRANS_NO_WRITECOUNT);
+ /* We gave our writer reference to the new transaction */
+ tp->t_flags |= XFS_TRANS_NO_WRITECOUNT;
+ ntp->t_agfl_dfops = tp->t_agfl_dfops;
+
+ return ntp;
+}
+
+/*
+ * This is called to reserve free disk blocks and log space for the
+ * given transaction. This must be done before allocating any resources
+ * within the transaction.
+ *
+ * This will return ENOSPC if there are not enough blocks available.
+ * It will sleep waiting for available log space.
+ * The only valid value for the flags parameter is XFS_RES_LOG_PERM, which
+ * is used by long running transactions. If any one of the reservations
+ * fails then they will all be backed out.
+ *
+ * This does not do quota reservations. That typically is done by the
+ * caller afterwards.
+ */
+static int
+xfs_trans_reserve(
+ struct xfs_trans *tp,
+ struct xfs_trans_res *resp,
+ uint blocks,
+ uint rtextents)
{
- struct xfs_sb *sb = &mp->m_sb;
- struct xfs_trans *ptr;
+ int error = 0;
/*
* Attempt to reserve the needed disk blocks by decrementing
- * the number needed from the number available. This will
+ * the number needed from the number available. This will
* fail if the count would go below zero.
*/
if (blocks > 0) {
- if (sb->sb_fdblocks < blocks)
+ if (tp->t_mountp->m_sb.sb_fdblocks < blocks)
return -ENOSPC;
+ tp->t_blk_res += blocks;
}
- ptr = kmem_zone_zalloc(xfs_trans_zone,
+ /*
+ * Reserve the log space needed for this transaction.
+ */
+ if (resp->tr_logres > 0) {
+ ASSERT(tp->t_log_res == 0 ||
+ tp->t_log_res == resp->tr_logres);
+ ASSERT(tp->t_log_count == 0 ||
+ tp->t_log_count == resp->tr_logcount);
+
+ if (resp->tr_logflags & XFS_TRANS_PERM_LOG_RES)
+ tp->t_flags |= XFS_TRANS_PERM_LOG_RES;
+ else
+ ASSERT(!(tp->t_flags & XFS_TRANS_PERM_LOG_RES));
+
+ tp->t_log_res = resp->tr_logres;
+ tp->t_log_count = resp->tr_logcount;
+ }
+
+ /*
+ * Attempt to reserve the needed realtime extents by decrementing
+ * the number needed from the number available. This will
+ * fail if the count would go below zero.
+ */
+ if (rtextents > 0) {
+ if (tp->t_mountp->m_sb.sb_rextents < rtextents) {
+ error = -ENOSPC;
+ goto undo_blocks;
+ }
+ }
+
+ return 0;
+
+ /*
+ * Error cases jump to one of these labels to undo any
+ * reservations which have already been performed.
+ */
+undo_blocks:
+ if (blocks > 0)
+ tp->t_blk_res = 0;
+
+ return error;
+}
+
+int
+libxfs_trans_alloc(
+ struct xfs_mount *mp,
+ struct xfs_trans_res *resp,
+ unsigned int blocks,
+ unsigned int rtextents,
+ unsigned int flags,
+ struct xfs_trans **tpp)
+
+{
+ struct xfs_trans *tp;
+ int error;
+
+ tp = kmem_zone_zalloc(xfs_trans_zone,
(flags & XFS_TRANS_NOFS) ? KM_NOFS : KM_SLEEP);
- ptr->t_mountp = mp;
- ptr->t_blk_res = blocks;
- INIT_LIST_HEAD(&ptr->t_items);
+ tp->t_mountp = mp;
+ INIT_LIST_HEAD(&tp->t_items);
+
+ error = xfs_trans_reserve(tp, resp, blocks, rtextents);
+ if (error) {
+ xfs_trans_cancel(tp);
+ return error;
+ }
#ifdef XACT_DEBUG
- fprintf(stderr, "allocated new transaction %p\n", ptr);
+ fprintf(stderr, "allocated new transaction %p\n", tp);
#endif
- *tpp = ptr;
+ *tpp = tp;
return 0;
}
@@ -186,18 +291,22 @@ libxfs_trans_alloc_empty(
void
libxfs_trans_cancel(
- xfs_trans_t *tp)
+ struct xfs_trans *tp)
{
#ifdef XACT_DEBUG
- xfs_trans_t *otp = tp;
+ struct xfs_trans *otp = tp;
#endif
- if (tp != NULL) {
- xfs_trans_free_items(tp);
- xfs_trans_free(tp);
- }
+ if (tp == NULL)
+ goto out;
+
+ xfs_trans_free_items(tp);
+ xfs_trans_free(tp);
+
+out:
#ifdef XACT_DEBUG
fprintf(stderr, "## cancelled transaction %p\n", otp);
#endif
+ return;
}
int
@@ -828,22 +937,25 @@ xfs_trans_free_items(
/*
* Commit the changes represented by this transaction
*/
-int
-libxfs_trans_commit(
- xfs_trans_t *tp)
+static int
+__xfs_trans_commit(
+ struct xfs_trans *tp,
+ bool regrant)
{
- xfs_sb_t *sbp;
+ struct xfs_sb *sbp;
+ int error = 0;
if (tp == NULL)
return 0;
+ ASSERT(!tp->t_agfl_dfops ||
+ !xfs_defer_has_unfinished_work(tp->t_agfl_dfops) || regrant);
+
if (!(tp->t_flags & XFS_TRANS_DIRTY)) {
#ifdef XACT_DEBUG
fprintf(stderr, "committed clean transaction %p\n", tp);
#endif
- xfs_trans_free_items(tp);
- xfs_trans_free(tp);
- return 0;
+ goto out_unreserve;
}
if (tp->t_flags & XFS_TRANS_SB_DIRTY) {
@@ -867,4 +979,16 @@ libxfs_trans_commit(
/* That's it for the transaction structure. Free it. */
xfs_trans_free(tp);
return 0;
+
+out_unreserve:
+ xfs_trans_free_items(tp);
+ xfs_trans_free(tp);
+ return error;
+}
+
+int
+libxfs_trans_commit(
+ struct xfs_trans *tp)
+{
+ return __xfs_trans_commit(tp, false);
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] libxfs: fix libxfs_trans_alloc callsite problems
2018-09-18 18:54 [PATCH 0/4] xfsprogs-4.19: transaction cleanups Darrick J. Wong
2018-09-18 18:54 ` [PATCH 1/4] libxfs: port kernel transaction code Darrick J. Wong
@ 2018-09-18 18:55 ` Darrick J. Wong
2018-09-18 18:55 ` [PATCH 3/4] libxfs: fix xfs_trans_alloc reservation abuse Darrick J. Wong
2018-09-18 18:55 ` [PATCH 4/4] libxfs: check libxfs_trans_commit return values Darrick J. Wong
3 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2018-09-18 18:55 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
Fix some incorrect libxfs_trans_alloc callers to check return values
correctly.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
mkfs/proto.c | 4 +++-
mkfs/xfs_mkfs.c | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/mkfs/proto.c b/mkfs/proto.c
index 7186036e..9eb15ab0 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -192,7 +192,9 @@ rsvfile(
/*
* update the inode timestamp, mode, and prealloc flag bits
*/
- libxfs_trans_alloc(mp, &tres, 0, 0, 0, &tp);
+ error = -libxfs_trans_alloc(mp, &tres, 0, 0, 0, &tp);
+ if (error)
+ fail(_("allocating transaction for a file"), error);
libxfs_trans_ijoin(tp, ip, 0);
VFS_I(ip)->i_mode &= ~S_ISUID;
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 2e53c1e8..c6ef3a71 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3677,7 +3677,7 @@ initialise_ag_freespace(
struct xfs_trans_res tres = {0};
int c;
- c = libxfs_trans_alloc(mp, &tres, worst_freelist, 0, 0, &tp);
+ c = -libxfs_trans_alloc(mp, &tres, worst_freelist, 0, 0, &tp);
if (c)
res_failed(c);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] libxfs: fix xfs_trans_alloc reservation abuse
2018-09-18 18:54 [PATCH 0/4] xfsprogs-4.19: transaction cleanups Darrick J. Wong
2018-09-18 18:54 ` [PATCH 1/4] libxfs: port kernel transaction code Darrick J. Wong
2018-09-18 18:55 ` [PATCH 2/4] libxfs: fix libxfs_trans_alloc callsite problems Darrick J. Wong
@ 2018-09-18 18:55 ` Darrick J. Wong
2018-09-18 18:55 ` [PATCH 4/4] libxfs: check libxfs_trans_commit return values Darrick J. Wong
3 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2018-09-18 18:55 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
Various xfsprogs tools have been abusing the transaction reservation
system by allocating the transaction with zero reservation. This has
always worked in the past because userspace transactions do not require
reservations. However, once we merge deferred ops into the transaction
structure, we will need to use a permanent reservation type to set up
any transaction that can roll. tr_itruncate has all we need, so use
that as the reservation dummy.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
mkfs/proto.c | 19 +++++++++----------
mkfs/xfs_mkfs.c | 4 ++--
repair/phase5.c | 4 ++--
repair/phase6.c | 20 ++++++++------------
repair/rmap.c | 7 +++----
5 files changed, 24 insertions(+), 30 deletions(-)
diff --git a/mkfs/proto.c b/mkfs/proto.c
index 9eb15ab0..141c27b8 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -123,9 +123,8 @@ getres(
uint r;
for (i = 0, r = MKFS_BLOCKRES(blocks); r >= blocks; r--) {
- struct xfs_trans_res tres = {0};
-
- i = -libxfs_trans_alloc(mp, &tres, r, 0, 0, &tp);
+ i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
+ r, 0, 0, &tp);
if (i == 0)
return tp;
}
@@ -180,7 +179,6 @@ rsvfile(
{
int error;
xfs_trans_t *tp;
- struct xfs_trans_res tres = {0};
error = -libxfs_alloc_file_space(ip, 0, llen, 1, 0);
@@ -192,7 +190,7 @@ rsvfile(
/*
* update the inode timestamp, mode, and prealloc flag bits
*/
- error = -libxfs_trans_alloc(mp, &tres, 0, 0, 0, &tp);
+ error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
if (error)
fail(_("allocating transaction for a file"), error);
libxfs_trans_ijoin(tp, ip, 0);
@@ -636,12 +634,12 @@ rtinit(
xfs_trans_t *tp;
struct cred creds;
struct fsxattr fsxattrs;
- struct xfs_trans_res tres = {0};
/*
* First, allocate the inodes.
*/
- i = -libxfs_trans_alloc(mp, &tres, MKFS_BLOCKRES_INODE, 0, 0, &tp);
+ i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
+ MKFS_BLOCKRES_INODE, 0, 0, &tp);
if (i)
res_failed(i);
@@ -678,7 +676,7 @@ rtinit(
/*
* Next, give the bitmap file some zero-filled blocks.
*/
- i = -libxfs_trans_alloc(mp, &tres,
+ i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
mp->m_sb.sb_rbmblocks + (XFS_BM_MAXLEVELS(mp,XFS_DATA_FORK) - 1),
0, 0, &tp);
if (i)
@@ -716,7 +714,7 @@ rtinit(
* Give the summary file some zero-filled blocks.
*/
nsumblocks = mp->m_rsumsize >> mp->m_sb.sb_blocklog;
- i = -libxfs_trans_alloc(mp, &tres,
+ i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
nsumblocks + (XFS_BM_MAXLEVELS(mp,XFS_DATA_FORK) - 1),
0, 0, &tp);
if (i)
@@ -753,7 +751,8 @@ rtinit(
* Do one transaction per bitmap block.
*/
for (bno = 0; bno < mp->m_sb.sb_rextents; bno = ebno) {
- i = -libxfs_trans_alloc(mp, &tres, 0, 0, 0, &tp);
+ i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
+ 0, 0, 0, &tp);
if (i)
res_failed(i);
libxfs_trans_ijoin(tp, rbmip, 0);
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index c6ef3a71..9ef6e84a 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3674,10 +3674,10 @@ initialise_ag_freespace(
{
struct xfs_alloc_arg args;
struct xfs_trans *tp;
- struct xfs_trans_res tres = {0};
int c;
- c = -libxfs_trans_alloc(mp, &tres, worst_freelist, 0, 0, &tp);
+ c = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
+ worst_freelist, 0, 0, &tp);
if (c)
res_failed(c);
diff --git a/repair/phase5.c b/repair/phase5.c
index 64f7b6e8..ac2eea54 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -2421,7 +2421,6 @@ inject_lost_blocks(
struct xfs_trans *tp = NULL;
struct xfs_slab_cursor *cur = NULL;
xfs_fsblock_t *fsb;
- struct xfs_trans_res tres = {0};
struct xfs_owner_info oinfo;
int error;
@@ -2431,7 +2430,8 @@ inject_lost_blocks(
return error;
while ((fsb = pop_slab_cursor(cur)) != NULL) {
- error = -libxfs_trans_alloc(mp, &tres, 16, 0, 0, &tp);
+ error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
+ 16, 0, 0, &tp);
if (error)
goto out_cancel;
diff --git a/repair/phase6.c b/repair/phase6.c
index 19ad54d3..58b23aa3 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -528,12 +528,12 @@ mk_rbmino(xfs_mount_t *mp)
xfs_bmbt_irec_t map[XFS_BMAP_MAX_NMAP];
int vers;
int times;
- struct xfs_trans_res tres = {0};
/*
* first set up inode
*/
- i = -libxfs_trans_alloc(mp, &tres, 10, 0, 0, &tp);
+ i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
+ 10, 0, 0, &tp);
if (i)
res_failed(i);
@@ -581,7 +581,7 @@ mk_rbmino(xfs_mount_t *mp)
* then allocate blocks for file and fill with zeroes (stolen
* from mkfs)
*/
- error = -libxfs_trans_alloc(mp, &tres,
+ error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
mp->m_sb.sb_rbmblocks + (XFS_BM_MAXLEVELS(mp,XFS_DATA_FORK) - 1),
0, 0, &tp);
if (error)
@@ -631,12 +631,12 @@ fill_rbmino(xfs_mount_t *mp)
int error;
xfs_fileoff_t bno;
xfs_bmbt_irec_t map;
- struct xfs_trans_res tres = {0};
bmp = btmcompute;
bno = 0;
- error = -libxfs_trans_alloc(mp, &tres, 10, 0, 0, &tp);
+ error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
+ 10, 0, 0, &tp);
if (error)
res_failed(error);
@@ -701,13 +701,13 @@ fill_rsumino(xfs_mount_t *mp)
xfs_fileoff_t bno;
xfs_fileoff_t end_bno;
xfs_bmbt_irec_t map;
- struct xfs_trans_res tres = {0};
smp = sumcompute;
bno = 0;
end_bno = mp->m_rsumsize >> mp->m_sb.sb_blocklog;
- error = -libxfs_trans_alloc(mp, &tres, 10, 0, 0, &tp);
+ error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
+ 10, 0, 0, &tp);
if (error)
res_failed(error);
@@ -776,7 +776,6 @@ mk_rsumino(xfs_mount_t *mp)
xfs_bmbt_irec_t map[XFS_BMAP_MAX_NMAP];
int vers;
int times;
- struct xfs_trans_res tres = {0};
/*
* first set up inode
@@ -832,10 +831,7 @@ mk_rsumino(xfs_mount_t *mp)
libxfs_defer_init(&dfops, &first);
nsumblocks = mp->m_rsumsize >> mp->m_sb.sb_blocklog;
- tres.tr_logres = BBTOB(128);
- tres.tr_logcount = XFS_DEFAULT_PERM_LOG_COUNT;
- tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
- error = -libxfs_trans_alloc(mp, &tres,
+ error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
mp->m_sb.sb_rbmblocks + (XFS_BM_MAXLEVELS(mp,XFS_DATA_FORK) - 1),
0, 0, &tp);
if (error)
diff --git a/repair/rmap.c b/repair/rmap.c
index bffb5b61..43eac288 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -449,7 +449,6 @@ rmap_store_ag_btree_rec(
struct xfs_buf *agbp = NULL;
struct xfs_buf *agflbp = NULL;
struct xfs_trans *tp;
- struct xfs_trans_res tres = {0};
__be32 *agfl_bno, *b;
int error = 0;
struct xfs_owner_info oinfo;
@@ -507,7 +506,8 @@ rmap_store_ag_btree_rec(
/* Insert rmaps into the btree one at a time */
rm_rec = pop_slab_cursor(rm_cur);
while (rm_rec) {
- error = -libxfs_trans_alloc(mp, &tres, 16, 0, 0, &tp);
+ error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
+ 16, 0, 0, &tp);
if (error)
goto err_slab;
@@ -1366,7 +1366,6 @@ fix_freelist(
{
xfs_alloc_arg_t args;
xfs_trans_t *tp;
- struct xfs_trans_res tres = {0};
int flags;
int error;
@@ -1375,7 +1374,7 @@ fix_freelist(
args.agno = agno;
args.alignment = 1;
args.pag = libxfs_perag_get(mp, agno);
- error = -libxfs_trans_alloc(mp, &tres,
+ error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
libxfs_alloc_min_freelist(mp, args.pag), 0, 0, &tp);
if (error)
do_error(_("failed to fix AGFL on AG %d, error %d\n"),
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] libxfs: check libxfs_trans_commit return values
2018-09-18 18:54 [PATCH 0/4] xfsprogs-4.19: transaction cleanups Darrick J. Wong
` (2 preceding siblings ...)
2018-09-18 18:55 ` [PATCH 3/4] libxfs: fix xfs_trans_alloc reservation abuse Darrick J. Wong
@ 2018-09-18 18:55 ` Darrick J. Wong
3 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2018-09-18 18:55 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
Check the return value from libxfs_trans_commit since it can now return
error codes.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
mkfs/proto.c | 9 +++++++--
mkfs/xfs_mkfs.c | 4 +++-
repair/phase6.c | 25 +++++++++++++++++++------
repair/rmap.c | 4 +++-
4 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/mkfs/proto.c b/mkfs/proto.c
index 141c27b8..d65170d7 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -212,7 +212,9 @@ rsvfile(
ip->i_d.di_flags |= XFS_DIFLAG_PREALLOC;
libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
- libxfs_trans_commit(tp);
+ error = -libxfs_trans_commit(tp);
+ if (error)
+ fail(_("committing space for a file failed"), error);
}
static int
@@ -671,7 +673,10 @@ rtinit(
rsumip->i_d.di_size = mp->m_rsumsize;
libxfs_trans_log_inode(tp, rsumip, XFS_ILOG_CORE);
libxfs_log_sb(tp);
- libxfs_trans_commit(tp);
+ error = -libxfs_trans_commit(tp);
+ if (error)
+ fail(_("Completion of the realtime summary inode failed"),
+ error);
mp->m_rsumip = rsumip;
/*
* Next, give the bitmap file some zero-filled blocks.
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 9ef6e84a..b04a705f 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3690,7 +3690,9 @@ initialise_ag_freespace(
libxfs_alloc_fix_freelist(&args, 0);
libxfs_perag_put(args.pag);
- libxfs_trans_commit(tp);
+ c = -libxfs_trans_commit(tp);
+ if (c)
+ res_failed(c);
}
/*
diff --git a/repair/phase6.c b/repair/phase6.c
index 58b23aa3..ecf8975e 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -575,7 +575,9 @@ mk_rbmino(xfs_mount_t *mp)
* commit changes
*/
libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
- libxfs_trans_commit(tp);
+ error = -libxfs_trans_commit(tp);
+ if (error)
+ do_error(_("%s: commit failed, error %d\n"), __func__, error);
/*
* then allocate blocks for file and fill with zeroes (stolen
@@ -683,7 +685,9 @@ _("can't access block %" PRIu64 " (fsbno %" PRIu64 ") of realtime bitmap inode %
bno++;
}
- libxfs_trans_commit(tp);
+ error = -libxfs_trans_commit(tp);
+ if (error)
+ do_error(_("%s: commit failed, error %d\n"), __func__, error);
IRELE(ip);
return(0);
}
@@ -755,7 +759,9 @@ _("can't access block %" PRIu64 " (fsbno %" PRIu64 ") of realtime summary inode
bno++;
}
- libxfs_trans_commit(tp);
+ error = -libxfs_trans_commit(tp);
+ if (error)
+ do_error(_("%s: commit failed, error %d\n"), __func__, error);
IRELE(ip);
return(0);
}
@@ -822,7 +828,9 @@ mk_rsumino(xfs_mount_t *mp)
* commit changes
*/
libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
- libxfs_trans_commit(tp);
+ error = -libxfs_trans_commit(tp);
+ if (error)
+ do_error(_("%s: commit failed, error %d\n"), __func__, error);
/*
* then allocate blocks for file and fill with zeroes (stolen
@@ -931,7 +939,10 @@ mk_root_dir(xfs_mount_t *mp)
ip->d_ops = mp->m_dir_inode_ops;
libxfs_dir_init(tp, ip, ip);
- libxfs_trans_commit(tp);
+ error = -libxfs_trans_commit(tp);
+ if (error)
+ do_error(_("%s: commit failed, error %d\n"), __func__, error);
+
IRELE(ip);
irec = find_inode_rec(mp, XFS_INO_TO_AGNO(mp, mp->m_sb.sb_rootino),
@@ -3005,7 +3016,9 @@ process_dir_inode(
if (dirty) {
libxfs_trans_log_inode(tp, ip,
XFS_ILOG_CORE | XFS_ILOG_DDATA);
- libxfs_trans_commit(tp);
+ error = -libxfs_trans_commit(tp);
+ if (error)
+ res_failed(error);
} else {
libxfs_trans_cancel(tp);
}
diff --git a/repair/rmap.c b/repair/rmap.c
index 43eac288..c19513c2 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -1411,7 +1411,9 @@ fix_freelist(
do_error(_("failed to fix AGFL on AG %d, error %d\n"),
agno, error);
}
- libxfs_trans_commit(tp);
+ error = -libxfs_trans_commit(tp);
+ if (error)
+ do_error(_("%s: commit failed, error %d\n"), __func__, error);
}
/*
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-09-19 0:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-18 18:54 [PATCH 0/4] xfsprogs-4.19: transaction cleanups Darrick J. Wong
2018-09-18 18:54 ` [PATCH 1/4] libxfs: port kernel transaction code Darrick J. Wong
2018-09-18 18:55 ` [PATCH 2/4] libxfs: fix libxfs_trans_alloc callsite problems Darrick J. Wong
2018-09-18 18:55 ` [PATCH 3/4] libxfs: fix xfs_trans_alloc reservation abuse Darrick J. Wong
2018-09-18 18:55 ` [PATCH 4/4] libxfs: check libxfs_trans_commit return values Darrick J. Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).