aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Chinner <david@fromorbit.com>2016-05-19 20:31:52 -0400
committerDave Chinner <david@fromorbit.com>2016-05-19 20:31:52 -0400
commitd6bd9615abdf89b147eb200ea4f63156af8a279e (patch)
treec9f1bcd755fe58aa61bcd8f440a6b0350fd80cd4
parent8b7a242e53e20dc3f2a071ff4d3d8dfa063174dd (diff)
parent710b1e2c2948c1e5d0499def5273ecbc6472342d (diff)
Merge branch 'xfs-4.7-trans-type-cleanup' into for-next
-rw-r--r--fs/xfs/libxfs/xfs_attr.c58
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c22
-rw-r--r--fs/xfs/libxfs/xfs_log_format.h5
-rw-r--r--fs/xfs/libxfs/xfs_sb.c8
-rw-r--r--fs/xfs/libxfs/xfs_shared.h102
-rw-r--r--fs/xfs/xfs_aops.c19
-rw-r--r--fs/xfs/xfs_attr_inactive.c16
-rw-r--r--fs/xfs/xfs_bmap_util.c45
-rw-r--r--fs/xfs/xfs_dquot.c7
-rw-r--r--fs/xfs/xfs_file.c8
-rw-r--r--fs/xfs/xfs_fsops.c10
-rw-r--r--fs/xfs/xfs_inode.c60
-rw-r--r--fs/xfs/xfs_ioctl.c13
-rw-r--r--fs/xfs/xfs_iomap.c53
-rw-r--r--fs/xfs/xfs_iops.c29
-rw-r--r--fs/xfs/xfs_log.c58
-rw-r--r--fs/xfs/xfs_log.h3
-rw-r--r--fs/xfs/xfs_log_cil.c1
-rw-r--r--fs/xfs/xfs_log_priv.h1
-rw-r--r--fs/xfs/xfs_log_recover.c10
-rw-r--r--fs/xfs/xfs_pnfs.c7
-rw-r--r--fs/xfs/xfs_qm.c9
-rw-r--r--fs/xfs/xfs_qm_syscalls.c26
-rw-r--r--fs/xfs/xfs_rtalloc.c21
-rw-r--r--fs/xfs/xfs_symlink.c16
-rw-r--r--fs/xfs/xfs_trace.h5
-rw-r--r--fs/xfs/xfs_trans.c88
-rw-r--r--fs/xfs/xfs_trans.h8
28 files changed, 200 insertions, 508 deletions
diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
index fa3b948ef9c2..4e126f41a0aa 100644
--- a/fs/xfs/libxfs/xfs_attr.c
+++ b/fs/xfs/libxfs/xfs_attr.c
@@ -242,37 +242,21 @@ xfs_attr_set(
242 return error; 242 return error;
243 } 243 }
244 244
245 /* 245 tres.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres +
246 * Start our first transaction of the day. 246 M_RES(mp)->tr_attrsetrt.tr_logres * args.total;
247 * 247 tres.tr_logcount = XFS_ATTRSET_LOG_COUNT;
248 * All future transactions during this code must be "chained" off 248 tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
249 * this one via the trans_dup() call. All transactions will contain
250 * the inode, and the inode will always be marked with trans_ihold().
251 * Since the inode will be locked in all transactions, we must log
252 * the inode in every transaction to let it float upward through
253 * the log.
254 */
255 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET);
256 249
257 /* 250 /*
258 * Root fork attributes can use reserved data blocks for this 251 * Root fork attributes can use reserved data blocks for this
259 * operation if necessary 252 * operation if necessary
260 */ 253 */
261 254 error = xfs_trans_alloc(mp, &tres, args.total, 0,
262 if (rsvd) 255 rsvd ? XFS_TRANS_RESERVE : 0, &args.trans);
263 args.trans->t_flags |= XFS_TRANS_RESERVE; 256 if (error)
264
265 tres.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres +
266 M_RES(mp)->tr_attrsetrt.tr_logres * args.total;
267 tres.tr_logcount = XFS_ATTRSET_LOG_COUNT;
268 tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
269 error = xfs_trans_reserve(args.trans, &tres, args.total, 0);
270 if (error) {
271 xfs_trans_cancel(args.trans);
272 return error; 257 return error;
273 }
274 xfs_ilock(dp, XFS_ILOCK_EXCL);
275 258
259 xfs_ilock(dp, XFS_ILOCK_EXCL);
276 error = xfs_trans_reserve_quota_nblks(args.trans, dp, args.total, 0, 260 error = xfs_trans_reserve_quota_nblks(args.trans, dp, args.total, 0,
277 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES : 261 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
278 XFS_QMOPT_RES_REGBLKS); 262 XFS_QMOPT_RES_REGBLKS);
@@ -429,31 +413,15 @@ xfs_attr_remove(
429 return error; 413 return error;
430 414
431 /* 415 /*
432 * Start our first transaction of the day.
433 *
434 * All future transactions during this code must be "chained" off
435 * this one via the trans_dup() call. All transactions will contain
436 * the inode, and the inode will always be marked with trans_ihold().
437 * Since the inode will be locked in all transactions, we must log
438 * the inode in every transaction to let it float upward through
439 * the log.
440 */
441 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM);
442
443 /*
444 * Root fork attributes can use reserved data blocks for this 416 * Root fork attributes can use reserved data blocks for this
445 * operation if necessary 417 * operation if necessary
446 */ 418 */
447 419 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrrm,
448 if (flags & ATTR_ROOT) 420 XFS_ATTRRM_SPACE_RES(mp), 0,
449 args.trans->t_flags |= XFS_TRANS_RESERVE; 421 (flags & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
450 422 &args.trans);
451 error = xfs_trans_reserve(args.trans, &M_RES(mp)->tr_attrrm, 423 if (error)
452 XFS_ATTRRM_SPACE_RES(mp), 0);
453 if (error) {
454 xfs_trans_cancel(args.trans);
455 return error; 424 return error;
456 }
457 425
458 xfs_ilock(dp, XFS_ILOCK_EXCL); 426 xfs_ilock(dp, XFS_ILOCK_EXCL);
459 /* 427 /*
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 041b6948aecc..e7ec8ccd3d64 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -1121,15 +1121,14 @@ xfs_bmap_add_attrfork(
1121 1121
1122 mp = ip->i_mount; 1122 mp = ip->i_mount;
1123 ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); 1123 ASSERT(!XFS_NOT_DQATTACHED(mp, ip));
1124 tp = xfs_trans_alloc(mp, XFS_TRANS_ADDAFORK); 1124
1125 blks = XFS_ADDAFORK_SPACE_RES(mp); 1125 blks = XFS_ADDAFORK_SPACE_RES(mp);
1126 if (rsvd) 1126
1127 tp->t_flags |= XFS_TRANS_RESERVE; 1127 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_addafork, blks, 0,
1128 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_addafork, blks, 0); 1128 rsvd ? XFS_TRANS_RESERVE : 0, &tp);
1129 if (error) { 1129 if (error)
1130 xfs_trans_cancel(tp);
1131 return error; 1130 return error;
1132 } 1131
1133 xfs_ilock(ip, XFS_ILOCK_EXCL); 1132 xfs_ilock(ip, XFS_ILOCK_EXCL);
1134 error = xfs_trans_reserve_quota_nblks(tp, ip, blks, 0, rsvd ? 1133 error = xfs_trans_reserve_quota_nblks(tp, ip, blks, 0, rsvd ?
1135 XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES : 1134 XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
@@ -6026,13 +6025,10 @@ xfs_bmap_split_extent(
6026 xfs_fsblock_t firstfsb; 6025 xfs_fsblock_t firstfsb;
6027 int error; 6026 int error;
6028 6027
6029 tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT); 6028 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write,
6030 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write, 6029 XFS_DIOSTRAT_SPACE_RES(mp, 0), 0, 0, &tp);
6031 XFS_DIOSTRAT_SPACE_RES(mp, 0), 0); 6030 if (error)
6032 if (error) {
6033 xfs_trans_cancel(tp);
6034 return error; 6031 return error;
6035 }
6036 6032
6037 xfs_ilock(ip, XFS_ILOCK_EXCL); 6033 xfs_ilock(ip, XFS_ILOCK_EXCL);
6038 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 6034 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h
index d54a8018b079..e8f49c029ff0 100644
--- a/fs/xfs/libxfs/xfs_log_format.h
+++ b/fs/xfs/libxfs/xfs_log_format.h
@@ -212,6 +212,11 @@ typedef struct xfs_trans_header {
212#define XFS_TRANS_HEADER_MAGIC 0x5452414e /* TRAN */ 212#define XFS_TRANS_HEADER_MAGIC 0x5452414e /* TRAN */
213 213
214/* 214/*
215 * The only type valid for th_type in CIL-enabled file system logs:
216 */
217#define XFS_TRANS_CHECKPOINT 40
218
219/*
215 * Log item types. 220 * Log item types.
216 */ 221 */
217#define XFS_LI_EFI 0x1236 222#define XFS_LI_EFI 0x1236
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index 8a53eaa349f4..12ca86778e02 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -838,12 +838,10 @@ xfs_sync_sb(
838 struct xfs_trans *tp; 838 struct xfs_trans *tp;
839 int error; 839 int error;
840 840
841 tp = _xfs_trans_alloc(mp, XFS_TRANS_SB_CHANGE, KM_SLEEP); 841 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0,
842 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_sb, 0, 0); 842 XFS_TRANS_NO_WRITECOUNT, &tp);
843 if (error) { 843 if (error)
844 xfs_trans_cancel(tp);
845 return error; 844 return error;
846 }
847 845
848 xfs_log_sb(tp); 846 xfs_log_sb(tp);
849 if (wait) 847 if (wait)
diff --git a/fs/xfs/libxfs/xfs_shared.h b/fs/xfs/libxfs/xfs_shared.h
index 81ac870834da..16002b5ec4eb 100644
--- a/fs/xfs/libxfs/xfs_shared.h
+++ b/fs/xfs/libxfs/xfs_shared.h
@@ -56,103 +56,6 @@ extern const struct xfs_buf_ops xfs_symlink_buf_ops;
56extern const struct xfs_buf_ops xfs_rtbuf_ops; 56extern const struct xfs_buf_ops xfs_rtbuf_ops;
57 57
58/* 58/*
59 * Transaction types. Used to distinguish types of buffers. These never reach
60 * the log.
61 */
62#define XFS_TRANS_SETATTR_NOT_SIZE 1
63#define XFS_TRANS_SETATTR_SIZE 2
64#define XFS_TRANS_INACTIVE 3
65#define XFS_TRANS_CREATE 4
66#define XFS_TRANS_CREATE_TRUNC 5
67#define XFS_TRANS_TRUNCATE_FILE 6
68#define XFS_TRANS_REMOVE 7
69#define XFS_TRANS_LINK 8
70#define XFS_TRANS_RENAME 9
71#define XFS_TRANS_MKDIR 10
72#define XFS_TRANS_RMDIR 11
73#define XFS_TRANS_SYMLINK 12
74#define XFS_TRANS_SET_DMATTRS 13
75#define XFS_TRANS_GROWFS 14
76#define XFS_TRANS_STRAT_WRITE 15
77#define XFS_TRANS_DIOSTRAT 16
78/* 17 was XFS_TRANS_WRITE_SYNC */
79#define XFS_TRANS_WRITEID 18
80#define XFS_TRANS_ADDAFORK 19
81#define XFS_TRANS_ATTRINVAL 20
82#define XFS_TRANS_ATRUNCATE 21
83#define XFS_TRANS_ATTR_SET 22
84#define XFS_TRANS_ATTR_RM 23
85#define XFS_TRANS_ATTR_FLAG 24
86#define XFS_TRANS_CLEAR_AGI_BUCKET 25
87#define XFS_TRANS_SB_CHANGE 26
88/*
89 * Dummy entries since we use the transaction type to index into the
90 * trans_type[] in xlog_recover_print_trans_head()
91 */
92#define XFS_TRANS_DUMMY1 27
93#define XFS_TRANS_DUMMY2 28
94#define XFS_TRANS_QM_QUOTAOFF 29
95#define XFS_TRANS_QM_DQALLOC 30
96#define XFS_TRANS_QM_SETQLIM 31
97#define XFS_TRANS_QM_DQCLUSTER 32
98#define XFS_TRANS_QM_QINOCREATE 33
99#define XFS_TRANS_QM_QUOTAOFF_END 34
100#define XFS_TRANS_FSYNC_TS 35
101#define XFS_TRANS_GROWFSRT_ALLOC 36
102#define XFS_TRANS_GROWFSRT_ZERO 37
103#define XFS_TRANS_GROWFSRT_FREE 38
104#define XFS_TRANS_SWAPEXT 39
105#define XFS_TRANS_CHECKPOINT 40
106#define XFS_TRANS_ICREATE 41
107#define XFS_TRANS_CREATE_TMPFILE 42
108#define XFS_TRANS_TYPE_MAX 43
109/* new transaction types need to be reflected in xfs_logprint(8) */
110
111#define XFS_TRANS_TYPES \
112 { XFS_TRANS_SETATTR_NOT_SIZE, "SETATTR_NOT_SIZE" }, \
113 { XFS_TRANS_SETATTR_SIZE, "SETATTR_SIZE" }, \
114 { XFS_TRANS_INACTIVE, "INACTIVE" }, \
115 { XFS_TRANS_CREATE, "CREATE" }, \
116 { XFS_TRANS_CREATE_TRUNC, "CREATE_TRUNC" }, \
117 { XFS_TRANS_TRUNCATE_FILE, "TRUNCATE_FILE" }, \
118 { XFS_TRANS_REMOVE, "REMOVE" }, \
119 { XFS_TRANS_LINK, "LINK" }, \
120 { XFS_TRANS_RENAME, "RENAME" }, \
121 { XFS_TRANS_MKDIR, "MKDIR" }, \
122 { XFS_TRANS_RMDIR, "RMDIR" }, \
123 { XFS_TRANS_SYMLINK, "SYMLINK" }, \
124 { XFS_TRANS_SET_DMATTRS, "SET_DMATTRS" }, \
125 { XFS_TRANS_GROWFS, "GROWFS" }, \
126 { XFS_TRANS_STRAT_WRITE, "STRAT_WRITE" }, \
127 { XFS_TRANS_DIOSTRAT, "DIOSTRAT" }, \
128 { XFS_TRANS_WRITEID, "WRITEID" }, \
129 { XFS_TRANS_ADDAFORK, "ADDAFORK" }, \
130 { XFS_TRANS_ATTRINVAL, "ATTRINVAL" }, \
131 { XFS_TRANS_ATRUNCATE, "ATRUNCATE" }, \
132 { XFS_TRANS_ATTR_SET, "ATTR_SET" }, \
133 { XFS_TRANS_ATTR_RM, "ATTR_RM" }, \
134 { XFS_TRANS_ATTR_FLAG, "ATTR_FLAG" }, \
135 { XFS_TRANS_CLEAR_AGI_BUCKET, "CLEAR_AGI_BUCKET" }, \
136 { XFS_TRANS_SB_CHANGE, "SBCHANGE" }, \
137 { XFS_TRANS_DUMMY1, "DUMMY1" }, \
138 { XFS_TRANS_DUMMY2, "DUMMY2" }, \
139 { XFS_TRANS_QM_QUOTAOFF, "QM_QUOTAOFF" }, \
140 { XFS_TRANS_QM_DQALLOC, "QM_DQALLOC" }, \
141 { XFS_TRANS_QM_SETQLIM, "QM_SETQLIM" }, \
142 { XFS_TRANS_QM_DQCLUSTER, "QM_DQCLUSTER" }, \
143 { XFS_TRANS_QM_QINOCREATE, "QM_QINOCREATE" }, \
144 { XFS_TRANS_QM_QUOTAOFF_END, "QM_QOFF_END" }, \
145 { XFS_TRANS_FSYNC_TS, "FSYNC_TS" }, \
146 { XFS_TRANS_GROWFSRT_ALLOC, "GROWFSRT_ALLOC" }, \
147 { XFS_TRANS_GROWFSRT_ZERO, "GROWFSRT_ZERO" }, \
148 { XFS_TRANS_GROWFSRT_FREE, "GROWFSRT_FREE" }, \
149 { XFS_TRANS_SWAPEXT, "SWAPEXT" }, \
150 { XFS_TRANS_CHECKPOINT, "CHECKPOINT" }, \
151 { XFS_TRANS_ICREATE, "ICREATE" }, \
152 { XFS_TRANS_CREATE_TMPFILE, "CREATE_TMPFILE" }, \
153 { XLOG_UNMOUNT_REC_TYPE, "UNMOUNT" }
154
155/*
156 * This structure is used to track log items associated with 59 * This structure is used to track log items associated with
157 * a transaction. It points to the log item and keeps some 60 * a transaction. It points to the log item and keeps some
158 * flags to track the state of the log item. It also tracks 61 * flags to track the state of the log item. It also tracks
@@ -181,8 +84,9 @@ int xfs_log_calc_minimum_size(struct xfs_mount *);
181#define XFS_TRANS_SYNC 0x08 /* make commit synchronous */ 84#define XFS_TRANS_SYNC 0x08 /* make commit synchronous */
182#define XFS_TRANS_DQ_DIRTY 0x10 /* at least one dquot in trx dirty */ 85#define XFS_TRANS_DQ_DIRTY 0x10 /* at least one dquot in trx dirty */
183#define XFS_TRANS_RESERVE 0x20 /* OK to use reserved data blocks */ 86#define XFS_TRANS_RESERVE 0x20 /* OK to use reserved data blocks */
184#define XFS_TRANS_FREEZE_PROT 0x40 /* Transaction has elevated writer 87#define XFS_TRANS_NO_WRITECOUNT 0x40 /* do not elevate SB writecount */
185 count in superblock */ 88#define XFS_TRANS_NOFS 0x80 /* pass KM_NOFS to kmem_alloc */
89
186/* 90/*
187 * Field values for xfs_trans_mod_sb. 91 * Field values for xfs_trans_mod_sb.
188 */ 92 */
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 736461a861b1..1d6eca54f016 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -168,13 +168,9 @@ xfs_setfilesize_trans_alloc(
168 struct xfs_trans *tp; 168 struct xfs_trans *tp;
169 int error; 169 int error;
170 170
171 tp = xfs_trans_alloc(mp, XFS_TRANS_FSYNC_TS); 171 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp);
172 172 if (error)
173 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_fsyncts, 0, 0);
174 if (error) {
175 xfs_trans_cancel(tp);
176 return error; 173 return error;
177 }
178 174
179 ioend->io_append_trans = tp; 175 ioend->io_append_trans = tp;
180 176
@@ -1397,13 +1393,10 @@ xfs_end_io_direct_write(
1397 1393
1398 trace_xfs_end_io_direct_write_append(ip, offset, size); 1394 trace_xfs_end_io_direct_write_append(ip, offset, size);
1399 1395
1400 tp = xfs_trans_alloc(mp, XFS_TRANS_FSYNC_TS); 1396 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0,
1401 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_fsyncts, 0, 0); 1397 &tp);
1402 if (error) { 1398 if (!error)
1403 xfs_trans_cancel(tp); 1399 error = xfs_setfilesize(ip, tp, offset, size);
1404 return error;
1405 }
1406 error = xfs_setfilesize(ip, tp, offset, size);
1407 } 1400 }
1408 1401
1409 return error; 1402 return error;
diff --git a/fs/xfs/xfs_attr_inactive.c b/fs/xfs/xfs_attr_inactive.c
index 2bb959ada45b..55d214981ed2 100644
--- a/fs/xfs/xfs_attr_inactive.c
+++ b/fs/xfs/xfs_attr_inactive.c
@@ -405,21 +405,11 @@ xfs_attr_inactive(
405 goto out_destroy_fork; 405 goto out_destroy_fork;
406 xfs_iunlock(dp, lock_mode); 406 xfs_iunlock(dp, lock_mode);
407 407
408 /*
409 * Start our first transaction of the day.
410 *
411 * All future transactions during this code must be "chained" off
412 * this one via the trans_dup() call. All transactions will contain
413 * the inode, and the inode will always be marked with trans_ihold().
414 * Since the inode will be locked in all transactions, we must log
415 * the inode in every transaction to let it float upward through
416 * the log.
417 */
418 lock_mode = 0; 408 lock_mode = 0;
419 trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL); 409
420 error = xfs_trans_reserve(trans, &M_RES(mp)->tr_attrinval, 0, 0); 410 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrinval, 0, 0, 0, &trans);
421 if (error) 411 if (error)
422 goto out_cancel; 412 goto out_destroy_fork;
423 413
424 lock_mode = XFS_ILOCK_EXCL; 414 lock_mode = XFS_ILOCK_EXCL;
425 xfs_ilock(dp, lock_mode); 415 xfs_ilock(dp, lock_mode);
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index a32c1dcae2ff..3246ebc7cbd0 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -900,19 +900,15 @@ xfs_free_eofblocks(
900 * Free them up now by truncating the file to 900 * Free them up now by truncating the file to
901 * its current size. 901 * its current size.
902 */ 902 */
903 tp = xfs_trans_alloc(mp, XFS_TRANS_INACTIVE);
904
905 if (need_iolock) { 903 if (need_iolock) {
906 if (!xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) { 904 if (!xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL))
907 xfs_trans_cancel(tp);
908 return -EAGAIN; 905 return -EAGAIN;
909 }
910 } 906 }
911 907
912 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_itruncate, 0, 0); 908 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0,
909 &tp);
913 if (error) { 910 if (error) {
914 ASSERT(XFS_FORCED_SHUTDOWN(mp)); 911 ASSERT(XFS_FORCED_SHUTDOWN(mp));
915 xfs_trans_cancel(tp);
916 if (need_iolock) 912 if (need_iolock)
917 xfs_iunlock(ip, XFS_IOLOCK_EXCL); 913 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
918 return error; 914 return error;
@@ -1037,9 +1033,9 @@ xfs_alloc_file_space(
1037 /* 1033 /*
1038 * Allocate and setup the transaction. 1034 * Allocate and setup the transaction.
1039 */ 1035 */
1040 tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT); 1036 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks,
1041 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write, 1037 resrtextents, 0, &tp);
1042 resblks, resrtextents); 1038
1043 /* 1039 /*
1044 * Check for running out of space 1040 * Check for running out of space
1045 */ 1041 */
@@ -1048,7 +1044,6 @@ xfs_alloc_file_space(
1048 * Free the transaction structure. 1044 * Free the transaction structure.
1049 */ 1045 */
1050 ASSERT(error == -ENOSPC || XFS_FORCED_SHUTDOWN(mp)); 1046 ASSERT(error == -ENOSPC || XFS_FORCED_SHUTDOWN(mp));
1051 xfs_trans_cancel(tp);
1052 break; 1047 break;
1053 } 1048 }
1054 xfs_ilock(ip, XFS_ILOCK_EXCL); 1049 xfs_ilock(ip, XFS_ILOCK_EXCL);
@@ -1311,18 +1306,10 @@ xfs_free_file_space(
1311 * transaction to dip into the reserve blocks to ensure 1306 * transaction to dip into the reserve blocks to ensure
1312 * the freeing of the space succeeds at ENOSPC. 1307 * the freeing of the space succeeds at ENOSPC.
1313 */ 1308 */
1314 tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT); 1309 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, 0,
1315 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write, resblks, 0); 1310 &tp);
1316
1317 /*
1318 * check for running out of space
1319 */
1320 if (error) { 1311 if (error) {
1321 /*
1322 * Free the transaction structure.
1323 */
1324 ASSERT(error == -ENOSPC || XFS_FORCED_SHUTDOWN(mp)); 1312 ASSERT(error == -ENOSPC || XFS_FORCED_SHUTDOWN(mp));
1325 xfs_trans_cancel(tp);
1326 break; 1313 break;
1327 } 1314 }
1328 xfs_ilock(ip, XFS_ILOCK_EXCL); 1315 xfs_ilock(ip, XFS_ILOCK_EXCL);
@@ -1482,19 +1469,16 @@ xfs_shift_file_space(
1482 } 1469 }
1483 1470
1484 while (!error && !done) { 1471 while (!error && !done) {
1485 tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT);
1486 /* 1472 /*
1487 * We would need to reserve permanent block for transaction. 1473 * We would need to reserve permanent block for transaction.
1488 * This will come into picture when after shifting extent into 1474 * This will come into picture when after shifting extent into
1489 * hole we found that adjacent extents can be merged which 1475 * hole we found that adjacent extents can be merged which
1490 * may lead to freeing of a block during record update. 1476 * may lead to freeing of a block during record update.
1491 */ 1477 */
1492 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write, 1478 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write,
1493 XFS_DIOSTRAT_SPACE_RES(mp, 0), 0); 1479 XFS_DIOSTRAT_SPACE_RES(mp, 0), 0, 0, &tp);
1494 if (error) { 1480 if (error)
1495 xfs_trans_cancel(tp);
1496 break; 1481 break;
1497 }
1498 1482
1499 xfs_ilock(ip, XFS_ILOCK_EXCL); 1483 xfs_ilock(ip, XFS_ILOCK_EXCL);
1500 error = xfs_trans_reserve_quota(tp, mp, ip->i_udquot, 1484 error = xfs_trans_reserve_quota(tp, mp, ip->i_udquot,
@@ -1747,12 +1731,9 @@ xfs_swap_extents(
1747 if (error) 1731 if (error)
1748 goto out_unlock; 1732 goto out_unlock;
1749 1733
1750 tp = xfs_trans_alloc(mp, XFS_TRANS_SWAPEXT); 1734 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp);
1751 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0); 1735 if (error)
1752 if (error) {
1753 xfs_trans_cancel(tp);
1754 goto out_unlock; 1736 goto out_unlock;
1755 }
1756 1737
1757 /* 1738 /*
1758 * Lock and join the inodes to the tansaction so that transaction commit 1739 * Lock and join the inodes to the tansaction so that transaction commit
diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
index 316b2a1bdba5..23e24329b132 100644
--- a/fs/xfs/xfs_dquot.c
+++ b/fs/xfs/xfs_dquot.c
@@ -614,11 +614,10 @@ xfs_qm_dqread(
614 trace_xfs_dqread(dqp); 614 trace_xfs_dqread(dqp);
615 615
616 if (flags & XFS_QMOPT_DQALLOC) { 616 if (flags & XFS_QMOPT_DQALLOC) {
617 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_DQALLOC); 617 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_qm_dqalloc,
618 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_qm_dqalloc, 618 XFS_QM_DQALLOC_SPACE_RES(mp), 0, 0, &tp);
619 XFS_QM_DQALLOC_SPACE_RES(mp), 0);
620 if (error) 619 if (error)
621 goto error1; 620 goto error0;
622 } 621 }
623 622
624 /* 623 /*
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index ac0fd32de31e..98bbd8f84c76 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -145,12 +145,10 @@ xfs_update_prealloc_flags(
145 struct xfs_trans *tp; 145 struct xfs_trans *tp;
146 int error; 146 int error;
147 147
148 tp = xfs_trans_alloc(ip->i_mount, XFS_TRANS_WRITEID); 148 error = xfs_trans_alloc(ip->i_mount, &M_RES(ip->i_mount)->tr_writeid,
149 error = xfs_trans_reserve(tp, &M_RES(ip->i_mount)->tr_writeid, 0, 0); 149 0, 0, 0, &tp);
150 if (error) { 150 if (error)
151 xfs_trans_cancel(tp);
152 return error; 151 return error;
153 }
154 152
155 xfs_ilock(ip, XFS_ILOCK_EXCL); 153 xfs_ilock(ip, XFS_ILOCK_EXCL);
156 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 154 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index ca0d3eb44925..b4d75825ae37 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -198,14 +198,10 @@ xfs_growfs_data_private(
198 return error; 198 return error;
199 } 199 }
200 200
201 tp = xfs_trans_alloc(mp, XFS_TRANS_GROWFS); 201 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata,
202 tp->t_flags |= XFS_TRANS_RESERVE; 202 XFS_GROWFS_SPACE_RES(mp), 0, XFS_TRANS_RESERVE, &tp);
203 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_growdata, 203 if (error)
204 XFS_GROWFS_SPACE_RES(mp), 0);
205 if (error) {
206 xfs_trans_cancel(tp);
207 return error; 204 return error;
208 }
209 205
210 /* 206 /*
211 * Write new AG headers to disk. Non-transactional, but written 207 * Write new AG headers to disk. Non-transactional, but written
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index 96f606deee31..b82c729634f6 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1161,11 +1161,9 @@ xfs_create(
1161 rdev = 0; 1161 rdev = 0;
1162 resblks = XFS_MKDIR_SPACE_RES(mp, name->len); 1162 resblks = XFS_MKDIR_SPACE_RES(mp, name->len);
1163 tres = &M_RES(mp)->tr_mkdir; 1163 tres = &M_RES(mp)->tr_mkdir;
1164 tp = xfs_trans_alloc(mp, XFS_TRANS_MKDIR);
1165 } else { 1164 } else {
1166 resblks = XFS_CREATE_SPACE_RES(mp, name->len); 1165 resblks = XFS_CREATE_SPACE_RES(mp, name->len);
1167 tres = &M_RES(mp)->tr_create; 1166 tres = &M_RES(mp)->tr_create;
1168 tp = xfs_trans_alloc(mp, XFS_TRANS_CREATE);
1169 } 1167 }
1170 1168
1171 /* 1169 /*
@@ -1174,20 +1172,19 @@ xfs_create(
1174 * the case we'll drop the one we have and get a more 1172 * the case we'll drop the one we have and get a more
1175 * appropriate transaction later. 1173 * appropriate transaction later.
1176 */ 1174 */
1177 error = xfs_trans_reserve(tp, tres, resblks, 0); 1175 error = xfs_trans_alloc(mp, tres, resblks, 0, 0, &tp);
1178 if (error == -ENOSPC) { 1176 if (error == -ENOSPC) {
1179 /* flush outstanding delalloc blocks and retry */ 1177 /* flush outstanding delalloc blocks and retry */
1180 xfs_flush_inodes(mp); 1178 xfs_flush_inodes(mp);
1181 error = xfs_trans_reserve(tp, tres, resblks, 0); 1179 error = xfs_trans_alloc(mp, tres, resblks, 0, 0, &tp);
1182 } 1180 }
1183 if (error == -ENOSPC) { 1181 if (error == -ENOSPC) {
1184 /* No space at all so try a "no-allocation" reservation */ 1182 /* No space at all so try a "no-allocation" reservation */
1185 resblks = 0; 1183 resblks = 0;
1186 error = xfs_trans_reserve(tp, tres, 0, 0); 1184 error = xfs_trans_alloc(mp, tres, 0, 0, 0, &tp);
1187 } 1185 }
1188 if (error) 1186 if (error)
1189 goto out_trans_cancel; 1187 goto out_release_inode;
1190
1191 1188
1192 xfs_ilock(dp, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL | 1189 xfs_ilock(dp, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL |
1193 XFS_IOLOCK_PARENT | XFS_ILOCK_PARENT); 1190 XFS_IOLOCK_PARENT | XFS_ILOCK_PARENT);
@@ -1337,17 +1334,16 @@ xfs_create_tmpfile(
1337 return error; 1334 return error;
1338 1335
1339 resblks = XFS_IALLOC_SPACE_RES(mp); 1336 resblks = XFS_IALLOC_SPACE_RES(mp);
1340 tp = xfs_trans_alloc(mp, XFS_TRANS_CREATE_TMPFILE);
1341
1342 tres = &M_RES(mp)->tr_create_tmpfile; 1337 tres = &M_RES(mp)->tr_create_tmpfile;
1343 error = xfs_trans_reserve(tp, tres, resblks, 0); 1338
1339 error = xfs_trans_alloc(mp, tres, resblks, 0, 0, &tp);
1344 if (error == -ENOSPC) { 1340 if (error == -ENOSPC) {
1345 /* No space at all so try a "no-allocation" reservation */ 1341 /* No space at all so try a "no-allocation" reservation */
1346 resblks = 0; 1342 resblks = 0;
1347 error = xfs_trans_reserve(tp, tres, 0, 0); 1343 error = xfs_trans_alloc(mp, tres, 0, 0, 0, &tp);
1348 } 1344 }
1349 if (error) 1345 if (error)
1350 goto out_trans_cancel; 1346 goto out_release_inode;
1351 1347
1352 error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp, 1348 error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp,
1353 pdqp, resblks, 1, 0); 1349 pdqp, resblks, 1, 0);
@@ -1432,15 +1428,14 @@ xfs_link(
1432 if (error) 1428 if (error)
1433 goto std_return; 1429 goto std_return;
1434 1430
1435 tp = xfs_trans_alloc(mp, XFS_TRANS_LINK);
1436 resblks = XFS_LINK_SPACE_RES(mp, target_name->len); 1431 resblks = XFS_LINK_SPACE_RES(mp, target_name->len);
1437 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_link, resblks, 0); 1432 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_link, resblks, 0, 0, &tp);
1438 if (error == -ENOSPC) { 1433 if (error == -ENOSPC) {
1439 resblks = 0; 1434 resblks = 0;
1440 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_link, 0, 0); 1435 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_link, 0, 0, 0, &tp);
1441 } 1436 }
1442 if (error) 1437 if (error)
1443 goto error_return; 1438 goto std_return;
1444 1439
1445 xfs_ilock(tdp, XFS_IOLOCK_EXCL | XFS_IOLOCK_PARENT); 1440 xfs_ilock(tdp, XFS_IOLOCK_EXCL | XFS_IOLOCK_PARENT);
1446 xfs_lock_two_inodes(sip, tdp, XFS_ILOCK_EXCL); 1441 xfs_lock_two_inodes(sip, tdp, XFS_ILOCK_EXCL);
@@ -1710,11 +1705,9 @@ xfs_inactive_truncate(
1710 struct xfs_trans *tp; 1705 struct xfs_trans *tp;
1711 int error; 1706 int error;
1712 1707
1713 tp = xfs_trans_alloc(mp, XFS_TRANS_INACTIVE); 1708 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
1714 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_itruncate, 0, 0);
1715 if (error) { 1709 if (error) {
1716 ASSERT(XFS_FORCED_SHUTDOWN(mp)); 1710 ASSERT(XFS_FORCED_SHUTDOWN(mp));
1717 xfs_trans_cancel(tp);
1718 return error; 1711 return error;
1719 } 1712 }
1720 1713
@@ -1764,8 +1757,6 @@ xfs_inactive_ifree(
1764 struct xfs_trans *tp; 1757 struct xfs_trans *tp;
1765 int error; 1758 int error;
1766 1759
1767 tp = xfs_trans_alloc(mp, XFS_TRANS_INACTIVE);
1768
1769 /* 1760 /*
1770 * The ifree transaction might need to allocate blocks for record 1761 * The ifree transaction might need to allocate blocks for record
1771 * insertion to the finobt. We don't want to fail here at ENOSPC, so 1762 * insertion to the finobt. We don't want to fail here at ENOSPC, so
@@ -1781,9 +1772,8 @@ xfs_inactive_ifree(
1781 * now remains allocated and sits on the unlinked list until the fs is 1772 * now remains allocated and sits on the unlinked list until the fs is
1782 * repaired. 1773 * repaired.
1783 */ 1774 */
1784 tp->t_flags |= XFS_TRANS_RESERVE; 1775 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ifree,
1785 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ifree, 1776 XFS_IFREE_SPACE_RES(mp), 0, XFS_TRANS_RESERVE, &tp);
1786 XFS_IFREE_SPACE_RES(mp), 0);
1787 if (error) { 1777 if (error) {
1788 if (error == -ENOSPC) { 1778 if (error == -ENOSPC) {
1789 xfs_warn_ratelimited(mp, 1779 xfs_warn_ratelimited(mp,
@@ -1792,7 +1782,6 @@ xfs_inactive_ifree(
1792 } else { 1782 } else {
1793 ASSERT(XFS_FORCED_SHUTDOWN(mp)); 1783 ASSERT(XFS_FORCED_SHUTDOWN(mp));
1794 } 1784 }
1795 xfs_trans_cancel(tp);
1796 return error; 1785 return error;
1797 } 1786 }
1798 1787
@@ -2525,11 +2514,6 @@ xfs_remove(
2525 if (error) 2514 if (error)
2526 goto std_return; 2515 goto std_return;
2527 2516
2528 if (is_dir)
2529 tp = xfs_trans_alloc(mp, XFS_TRANS_RMDIR);
2530 else
2531 tp = xfs_trans_alloc(mp, XFS_TRANS_REMOVE);
2532
2533 /* 2517 /*
2534 * We try to get the real space reservation first, 2518 * We try to get the real space reservation first,
2535 * allowing for directory btree deletion(s) implying 2519 * allowing for directory btree deletion(s) implying
@@ -2540,14 +2524,15 @@ xfs_remove(
2540 * block from the directory. 2524 * block from the directory.
2541 */ 2525 */
2542 resblks = XFS_REMOVE_SPACE_RES(mp); 2526 resblks = XFS_REMOVE_SPACE_RES(mp);
2543 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_remove, resblks, 0); 2527 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_remove, resblks, 0, 0, &tp);
2544 if (error == -ENOSPC) { 2528 if (error == -ENOSPC) {
2545 resblks = 0; 2529 resblks = 0;
2546 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_remove, 0, 0); 2530 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_remove, 0, 0, 0,
2531 &tp);
2547 } 2532 }
2548 if (error) { 2533 if (error) {
2549 ASSERT(error != -ENOSPC); 2534 ASSERT(error != -ENOSPC);
2550 goto out_trans_cancel; 2535 goto std_return;
2551 } 2536 }
2552 2537
2553 xfs_ilock(dp, XFS_IOLOCK_EXCL | XFS_IOLOCK_PARENT); 2538 xfs_ilock(dp, XFS_IOLOCK_EXCL | XFS_IOLOCK_PARENT);
@@ -2910,15 +2895,15 @@ xfs_rename(
2910 xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, wip, 2895 xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, wip,
2911 inodes, &num_inodes); 2896 inodes, &num_inodes);
2912 2897
2913 tp = xfs_trans_alloc(mp, XFS_TRANS_RENAME);
2914 spaceres = XFS_RENAME_SPACE_RES(mp, target_name->len); 2898 spaceres = XFS_RENAME_SPACE_RES(mp, target_name->len);
2915 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_rename, spaceres, 0); 2899 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, spaceres, 0, 0, &tp);
2916 if (error == -ENOSPC) { 2900 if (error == -ENOSPC) {
2917 spaceres = 0; 2901 spaceres = 0;
2918 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_rename, 0, 0); 2902 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, 0, 0, 0,
2903 &tp);
2919 } 2904 }
2920 if (error) 2905 if (error)
2921 goto out_trans_cancel; 2906 goto out_release_wip;
2922 2907
2923 /* 2908 /*
2924 * Attach the dquots to the inodes 2909 * Attach the dquots to the inodes
@@ -3155,6 +3140,7 @@ out_bmap_cancel:
3155 xfs_bmap_cancel(&free_list); 3140 xfs_bmap_cancel(&free_list);
3156out_trans_cancel: 3141out_trans_cancel:
3157 xfs_trans_cancel(tp); 3142 xfs_trans_cancel(tp);
3143out_release_wip:
3158 if (wip) 3144 if (wip)
3159 IRELE(wip); 3145 IRELE(wip);
3160 return error; 3146 return error;
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index bcb6c19ce3ea..6f82187ee297 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -334,12 +334,10 @@ xfs_set_dmattrs(
334 if (XFS_FORCED_SHUTDOWN(mp)) 334 if (XFS_FORCED_SHUTDOWN(mp))
335 return -EIO; 335 return -EIO;
336 336
337 tp = xfs_trans_alloc(mp, XFS_TRANS_SET_DMATTRS); 337 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp);
338 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0); 338 if (error)
339 if (error) {
340 xfs_trans_cancel(tp);
341 return error; 339 return error;
342 } 340
343 xfs_ilock(ip, XFS_ILOCK_EXCL); 341 xfs_ilock(ip, XFS_ILOCK_EXCL);
344 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 342 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
345 343
@@ -1141,10 +1139,9 @@ xfs_ioctl_setattr_get_trans(
1141 if (XFS_FORCED_SHUTDOWN(mp)) 1139 if (XFS_FORCED_SHUTDOWN(mp))
1142 goto out_unlock; 1140 goto out_unlock;
1143 1141
1144 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE); 1142 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp);
1145 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0);
1146 if (error) 1143 if (error)
1147 goto out_cancel; 1144 return ERR_PTR(error);
1148 1145
1149 xfs_ilock(ip, XFS_ILOCK_EXCL); 1146 xfs_ilock(ip, XFS_ILOCK_EXCL);
1150 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | join_flags); 1147 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | join_flags);
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index d81bdc080370..58391355a44d 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -132,6 +132,7 @@ xfs_iomap_write_direct(
132 int error; 132 int error;
133 int lockmode; 133 int lockmode;
134 int bmapi_flags = XFS_BMAPI_PREALLOC; 134 int bmapi_flags = XFS_BMAPI_PREALLOC;
135 uint tflags = 0;
135 136
136 rt = XFS_IS_REALTIME_INODE(ip); 137 rt = XFS_IS_REALTIME_INODE(ip);
137 extsz = xfs_get_extsz_hint(ip); 138 extsz = xfs_get_extsz_hint(ip);
@@ -192,11 +193,6 @@ xfs_iomap_write_direct(
192 return error; 193 return error;
193 194
194 /* 195 /*
195 * Allocate and setup the transaction
196 */
197 tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT);
198
199 /*
200 * For DAX, we do not allocate unwritten extents, but instead we zero 196 * For DAX, we do not allocate unwritten extents, but instead we zero
201 * the block before we commit the transaction. Ideally we'd like to do 197 * the block before we commit the transaction. Ideally we'd like to do
202 * this outside the transaction context, but if we commit and then crash 198 * this outside the transaction context, but if we commit and then crash
@@ -209,23 +205,17 @@ xfs_iomap_write_direct(
209 * the reserve block pool for bmbt block allocation if there is no space 205 * the reserve block pool for bmbt block allocation if there is no space
210 * left but we need to do unwritten extent conversion. 206 * left but we need to do unwritten extent conversion.
211 */ 207 */
212
213 if (IS_DAX(VFS_I(ip))) { 208 if (IS_DAX(VFS_I(ip))) {
214 bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO; 209 bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;
215 if (ISUNWRITTEN(imap)) { 210 if (ISUNWRITTEN(imap)) {
216 tp->t_flags |= XFS_TRANS_RESERVE; 211 tflags |= XFS_TRANS_RESERVE;
217 resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1; 212 resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
218 } 213 }
219 } 214 }
220 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write, 215 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, resrtextents,
221 resblks, resrtextents); 216 tflags, &tp);
222 /* 217 if (error)
223 * Check for running out of space, note: need lock to return
224 */
225 if (error) {
226 xfs_trans_cancel(tp);
227 return error; 218 return error;
228 }
229 219
230 lockmode = XFS_ILOCK_EXCL; 220 lockmode = XFS_ILOCK_EXCL;
231 xfs_ilock(ip, lockmode); 221 xfs_ilock(ip, lockmode);
@@ -726,15 +716,13 @@ xfs_iomap_write_allocate(
726 716
727 nimaps = 0; 717 nimaps = 0;
728 while (nimaps == 0) { 718 while (nimaps == 0) {
729 tp = xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE);
730 tp->t_flags |= XFS_TRANS_RESERVE;
731 nres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK); 719 nres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK);
732 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write, 720
733 nres, 0); 721 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, nres,
734 if (error) { 722 0, XFS_TRANS_RESERVE, &tp);
735 xfs_trans_cancel(tp); 723 if (error)
736 return error; 724 return error;
737 } 725
738 xfs_ilock(ip, XFS_ILOCK_EXCL); 726 xfs_ilock(ip, XFS_ILOCK_EXCL);
739 xfs_trans_ijoin(tp, ip, 0); 727 xfs_trans_ijoin(tp, ip, 0);
740 728
@@ -878,25 +866,18 @@ xfs_iomap_write_unwritten(
878 866
879 do { 867 do {
880 /* 868 /*
881 * set up a transaction to convert the range of extents 869 * Set up a transaction to convert the range of extents
882 * from unwritten to real. Do allocations in a loop until 870 * from unwritten to real. Do allocations in a loop until
883 * we have covered the range passed in. 871 * we have covered the range passed in.
884 * 872 *
885 * Note that we open code the transaction allocation here 873 * Note that we can't risk to recursing back into the filesystem
886 * to pass KM_NOFS--we can't risk to recursing back into 874 * here as we might be asked to write out the same inode that we
887 * the filesystem here as we might be asked to write out 875 * complete here and might deadlock on the iolock.
888 * the same inode that we complete here and might deadlock
889 * on the iolock.
890 */ 876 */
891 sb_start_intwrite(mp->m_super); 877 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0,
892 tp = _xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE, KM_NOFS); 878 XFS_TRANS_RESERVE | XFS_TRANS_NOFS, &tp);
893 tp->t_flags |= XFS_TRANS_RESERVE | XFS_TRANS_FREEZE_PROT; 879 if (error)
894 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write,
895 resblks, 0);
896 if (error) {
897 xfs_trans_cancel(tp);
898 return error; 880 return error;
899 }
900 881
901 xfs_ilock(ip, XFS_ILOCK_EXCL); 882 xfs_ilock(ip, XFS_ILOCK_EXCL);
902 xfs_trans_ijoin(tp, ip, 0); 883 xfs_trans_ijoin(tp, ip, 0);
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index fb7dc61f4a29..fc7766164dc9 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -599,12 +599,12 @@ xfs_setattr_nonsize(
599 return error; 599 return error;
600 } 600 }
601 601
602 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE); 602 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp);
603 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0);
604 if (error) 603 if (error)
605 goto out_trans_cancel; 604 goto out_dqrele;
606 605
607 xfs_ilock(ip, XFS_ILOCK_EXCL); 606 xfs_ilock(ip, XFS_ILOCK_EXCL);
607 xfs_trans_ijoin(tp, ip, 0);
608 608
609 /* 609 /*
610 * Change file ownership. Must be the owner or privileged. 610 * Change file ownership. Must be the owner or privileged.
@@ -633,12 +633,10 @@ xfs_setattr_nonsize(
633 NULL, capable(CAP_FOWNER) ? 633 NULL, capable(CAP_FOWNER) ?
634 XFS_QMOPT_FORCE_RES : 0); 634 XFS_QMOPT_FORCE_RES : 0);
635 if (error) /* out of quota */ 635 if (error) /* out of quota */
636 goto out_unlock; 636 goto out_cancel;
637 } 637 }
638 } 638 }
639 639
640 xfs_trans_ijoin(tp, ip, 0);
641
642 /* 640 /*
643 * Change file ownership. Must be the owner or privileged. 641 * Change file ownership. Must be the owner or privileged.
644 */ 642 */
@@ -722,10 +720,9 @@ xfs_setattr_nonsize(
722 720
723 return 0; 721 return 0;
724 722
725out_unlock: 723out_cancel:
726 xfs_iunlock(ip, XFS_ILOCK_EXCL);
727out_trans_cancel:
728 xfs_trans_cancel(tp); 724 xfs_trans_cancel(tp);
725out_dqrele:
729 xfs_qm_dqrele(udqp); 726 xfs_qm_dqrele(udqp);
730 xfs_qm_dqrele(gdqp); 727 xfs_qm_dqrele(gdqp);
731 return error; 728 return error;
@@ -834,7 +831,7 @@ xfs_setattr_size(
834 * We have to do all the page cache truncate work outside the 831 * We have to do all the page cache truncate work outside the
835 * transaction context as the "lock" order is page lock->log space 832 * transaction context as the "lock" order is page lock->log space
836 * reservation as defined by extent allocation in the writeback path. 833 * reservation as defined by extent allocation in the writeback path.
837 * Hence a truncate can fail with ENOMEM from xfs_trans_reserve(), but 834 * Hence a truncate can fail with ENOMEM from xfs_trans_alloc(), but
838 * having already truncated the in-memory version of the file (i.e. made 835 * having already truncated the in-memory version of the file (i.e. made
839 * user visible changes). There's not much we can do about this, except 836 * user visible changes). There's not much we can do about this, except
840 * to hope that the caller sees ENOMEM and retries the truncate 837 * to hope that the caller sees ENOMEM and retries the truncate
@@ -849,10 +846,9 @@ xfs_setattr_size(
849 return error; 846 return error;
850 truncate_setsize(inode, newsize); 847 truncate_setsize(inode, newsize);
851 848
852 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_SIZE); 849 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
853 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_itruncate, 0, 0);
854 if (error) 850 if (error)
855 goto out_trans_cancel; 851 return error;
856 852
857 lock_flags |= XFS_ILOCK_EXCL; 853 lock_flags |= XFS_ILOCK_EXCL;
858 xfs_ilock(ip, XFS_ILOCK_EXCL); 854 xfs_ilock(ip, XFS_ILOCK_EXCL);
@@ -971,12 +967,9 @@ xfs_vn_update_time(
971 967
972 trace_xfs_update_time(ip); 968 trace_xfs_update_time(ip);
973 969
974 tp = xfs_trans_alloc(mp, XFS_TRANS_FSYNC_TS); 970 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp);
975 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_fsyncts, 0, 0); 971 if (error)
976 if (error) {
977 xfs_trans_cancel(tp);
978 return error; 972 return error;
979 }
980 973
981 xfs_ilock(ip, XFS_ILOCK_EXCL); 974 xfs_ilock(ip, XFS_ILOCK_EXCL);
982 if (flags & S_CTIME) 975 if (flags & S_CTIME)
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index b49ccf5c1d75..268f7d65cfd4 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -435,8 +435,7 @@ xfs_log_reserve(
435 int cnt, 435 int cnt,
436 struct xlog_ticket **ticp, 436 struct xlog_ticket **ticp,
437 __uint8_t client, 437 __uint8_t client,
438 bool permanent, 438 bool permanent)
439 uint t_type)
440{ 439{
441 struct xlog *log = mp->m_log; 440 struct xlog *log = mp->m_log;
442 struct xlog_ticket *tic; 441 struct xlog_ticket *tic;
@@ -456,7 +455,6 @@ xfs_log_reserve(
456 if (!tic) 455 if (!tic)
457 return -ENOMEM; 456 return -ENOMEM;
458 457
459 tic->t_trans_type = t_type;
460 *ticp = tic; 458 *ticp = tic;
461 459
462 xlog_grant_push_ail(log, tic->t_cnt ? tic->t_unit_res * tic->t_cnt 460 xlog_grant_push_ail(log, tic->t_cnt ? tic->t_unit_res * tic->t_cnt
@@ -823,8 +821,7 @@ xfs_log_unmount_write(xfs_mount_t *mp)
823 } while (iclog != first_iclog); 821 } while (iclog != first_iclog);
824#endif 822#endif
825 if (! (XLOG_FORCED_SHUTDOWN(log))) { 823 if (! (XLOG_FORCED_SHUTDOWN(log))) {
826 error = xfs_log_reserve(mp, 600, 1, &tic, 824 error = xfs_log_reserve(mp, 600, 1, &tic, XFS_LOG, 0);
827 XFS_LOG, 0, XLOG_UNMOUNT_REC_TYPE);
828 if (!error) { 825 if (!error) {
829 /* the data section must be 32 bit size aligned */ 826 /* the data section must be 32 bit size aligned */
830 struct { 827 struct {
@@ -2032,58 +2029,8 @@ xlog_print_tic_res(
2032 REG_TYPE_STR(ICREATE, "inode create") 2029 REG_TYPE_STR(ICREATE, "inode create")
2033 }; 2030 };
2034#undef REG_TYPE_STR 2031#undef REG_TYPE_STR
2035#define TRANS_TYPE_STR(type) [XFS_TRANS_##type] = #type
2036 static char *trans_type_str[XFS_TRANS_TYPE_MAX] = {
2037 TRANS_TYPE_STR(SETATTR_NOT_SIZE),
2038 TRANS_TYPE_STR(SETATTR_SIZE),
2039 TRANS_TYPE_STR(INACTIVE),
2040 TRANS_TYPE_STR(CREATE),
2041 TRANS_TYPE_STR(CREATE_TRUNC),
2042 TRANS_TYPE_STR(TRUNCATE_FILE),
2043 TRANS_TYPE_STR(REMOVE),
2044 TRANS_TYPE_STR(LINK),
2045 TRANS_TYPE_STR(RENAME),
2046 TRANS_TYPE_STR(MKDIR),
2047 TRANS_TYPE_STR(RMDIR),
2048 TRANS_TYPE_STR(SYMLINK),
2049 TRANS_TYPE_STR(SET_DMATTRS),
2050 TRANS_TYPE_STR(GROWFS),
2051 TRANS_TYPE_STR(STRAT_WRITE),
2052 TRANS_TYPE_STR(DIOSTRAT),
2053 TRANS_TYPE_STR(WRITEID),
2054 TRANS_TYPE_STR(ADDAFORK),
2055 TRANS_TYPE_STR(ATTRINVAL),
2056 TRANS_TYPE_STR(ATRUNCATE),
2057 TRANS_TYPE_STR(ATTR_SET),
2058 TRANS_TYPE_STR(ATTR_RM),
2059 TRANS_TYPE_STR(ATTR_FLAG),
2060 TRANS_TYPE_STR(CLEAR_AGI_BUCKET),
2061 TRANS_TYPE_STR(SB_CHANGE),
2062 TRANS_TYPE_STR(DUMMY1),
2063 TRANS_TYPE_STR(DUMMY2),
2064 TRANS_TYPE_STR(QM_QUOTAOFF),
2065 TRANS_TYPE_STR(QM_DQALLOC),
2066 TRANS_TYPE_STR(QM_SETQLIM),
2067 TRANS_TYPE_STR(QM_DQCLUSTER),
2068 TRANS_TYPE_STR(QM_QINOCREATE),
2069 TRANS_TYPE_STR(QM_QUOTAOFF_END),
2070 TRANS_TYPE_STR(FSYNC_TS),
2071 TRANS_TYPE_STR(GROWFSRT_ALLOC),
2072 TRANS_TYPE_STR(GROWFSRT_ZERO),
2073 TRANS_TYPE_STR(GROWFSRT_FREE),
2074 TRANS_TYPE_STR(SWAPEXT),
2075 TRANS_TYPE_STR(CHECKPOINT),
2076 TRANS_TYPE_STR(ICREATE),
2077 TRANS_TYPE_STR(CREATE_TMPFILE)
2078 };
2079#undef TRANS_TYPE_STR
2080 2032
2081 xfs_warn(mp, "xlog_write: reservation summary:"); 2033 xfs_warn(mp, "xlog_write: reservation summary:");
2082 xfs_warn(mp, " trans type = %s (%u)",
2083 ((ticket->t_trans_type <= 0 ||
2084 ticket->t_trans_type > XFS_TRANS_TYPE_MAX) ?
2085 "bad-trans-type" : trans_type_str[ticket->t_trans_type]),
2086 ticket->t_trans_type);
2087 xfs_warn(mp, " unit res = %d bytes", 2034 xfs_warn(mp, " unit res = %d bytes",
2088 ticket->t_unit_res); 2035 ticket->t_unit_res);
2089 xfs_warn(mp, " current res = %d bytes", 2036 xfs_warn(mp, " current res = %d bytes",
@@ -3709,7 +3656,6 @@ xlog_ticket_alloc(
3709 tic->t_tid = prandom_u32(); 3656 tic->t_tid = prandom_u32();
3710 tic->t_clientid = client; 3657 tic->t_clientid = client;
3711 tic->t_flags = XLOG_TIC_INITED; 3658 tic->t_flags = XLOG_TIC_INITED;
3712 tic->t_trans_type = 0;
3713 if (permanent) 3659 if (permanent)
3714 tic->t_flags |= XLOG_TIC_PERM_RESERV; 3660 tic->t_flags |= XLOG_TIC_PERM_RESERV;
3715 3661
diff --git a/fs/xfs/xfs_log.h b/fs/xfs/xfs_log.h
index aa533a7d50f2..80ba0c047090 100644
--- a/fs/xfs/xfs_log.h
+++ b/fs/xfs/xfs_log.h
@@ -161,8 +161,7 @@ int xfs_log_reserve(struct xfs_mount *mp,
161 int count, 161 int count,
162 struct xlog_ticket **ticket, 162 struct xlog_ticket **ticket,
163 __uint8_t clientid, 163 __uint8_t clientid,
164 bool permanent, 164 bool permanent);
165 uint t_type);
166int xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic); 165int xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic);
167int xfs_log_unmount_write(struct xfs_mount *mp); 166int xfs_log_unmount_write(struct xfs_mount *mp);
168void xfs_log_unmount(struct xfs_mount *mp); 167void xfs_log_unmount(struct xfs_mount *mp);
diff --git a/fs/xfs/xfs_log_cil.c b/fs/xfs/xfs_log_cil.c
index 4e7649351f5a..5e54e7955ea6 100644
--- a/fs/xfs/xfs_log_cil.c
+++ b/fs/xfs/xfs_log_cil.c
@@ -51,7 +51,6 @@ xlog_cil_ticket_alloc(
51 51
52 tic = xlog_ticket_alloc(log, 0, 1, XFS_TRANSACTION, 0, 52 tic = xlog_ticket_alloc(log, 0, 1, XFS_TRANSACTION, 0,
53 KM_SLEEP|KM_NOFS); 53 KM_SLEEP|KM_NOFS);
54 tic->t_trans_type = XFS_TRANS_CHECKPOINT;
55 54
56 /* 55 /*
57 * set the current reservation to zero so we know to steal the basic 56 * set the current reservation to zero so we know to steal the basic
diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h
index ed8896310c00..765f084759b5 100644
--- a/fs/xfs/xfs_log_priv.h
+++ b/fs/xfs/xfs_log_priv.h
@@ -175,7 +175,6 @@ typedef struct xlog_ticket {
175 char t_cnt; /* current count : 1 */ 175 char t_cnt; /* current count : 1 */
176 char t_clientid; /* who does this belong to; : 1 */ 176 char t_clientid; /* who does this belong to; : 1 */
177 char t_flags; /* properties of reservation : 1 */ 177 char t_flags; /* properties of reservation : 1 */
178 uint t_trans_type; /* transaction type : 4 */
179 178
180 /* reservation array fields */ 179 /* reservation array fields */
181 uint t_res_num; /* num in array : 4 */ 180 uint t_res_num; /* num in array : 4 */
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index 396565f43247..558f3d1d91ad 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -4205,10 +4205,9 @@ xlog_recover_process_efi(
4205 } 4205 }
4206 } 4206 }
4207 4207
4208 tp = xfs_trans_alloc(mp, 0); 4208 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
4209 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_itruncate, 0, 0);
4210 if (error) 4209 if (error)
4211 goto abort_error; 4210 return error;
4212 efdp = xfs_trans_get_efd(tp, efip, efip->efi_format.efi_nextents); 4211 efdp = xfs_trans_get_efd(tp, efip, efip->efi_format.efi_nextents);
4213 4212
4214 for (i = 0; i < efip->efi_format.efi_nextents; i++) { 4213 for (i = 0; i < efip->efi_format.efi_nextents; i++) {
@@ -4355,10 +4354,9 @@ xlog_recover_clear_agi_bucket(
4355 int offset; 4354 int offset;
4356 int error; 4355 int error;
4357 4356
4358 tp = xfs_trans_alloc(mp, XFS_TRANS_CLEAR_AGI_BUCKET); 4357 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_clearagi, 0, 0, 0, &tp);
4359 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_clearagi, 0, 0);
4360 if (error) 4358 if (error)
4361 goto out_abort; 4359 goto out_error;
4362 4360
4363 error = xfs_read_agi(mp, tp, agno, &agibp); 4361 error = xfs_read_agi(mp, tp, agno, &agibp);
4364 if (error) 4362 if (error)
diff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c
index ade236e90bb3..3332baeac582 100644
--- a/fs/xfs/xfs_pnfs.c
+++ b/fs/xfs/xfs_pnfs.c
@@ -308,12 +308,9 @@ xfs_fs_commit_blocks(
308 goto out_drop_iolock; 308 goto out_drop_iolock;
309 } 309 }
310 310
311 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE); 311 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp);
312 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0); 312 if (error)
313 if (error) {
314 xfs_trans_cancel(tp);
315 goto out_drop_iolock; 313 goto out_drop_iolock;
316 }
317 314
318 xfs_ilock(ip, XFS_ILOCK_EXCL); 315 xfs_ilock(ip, XFS_ILOCK_EXCL);
319 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 316 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
index be125e1758c1..a60d9e2739d1 100644
--- a/fs/xfs/xfs_qm.c
+++ b/fs/xfs/xfs_qm.c
@@ -783,13 +783,10 @@ xfs_qm_qino_alloc(
783 } 783 }
784 } 784 }
785 785
786 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QINOCREATE); 786 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_create,
787 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_create, 787 XFS_QM_QINOCREATE_SPACE_RES(mp), 0, 0, &tp);
788 XFS_QM_QINOCREATE_SPACE_RES(mp), 0); 788 if (error)
789 if (error) {
790 xfs_trans_cancel(tp);
791 return error; 789 return error;
792 }
793 790
794 if (need_alloc) { 791 if (need_alloc) {
795 error = xfs_dir_ialloc(&tp, NULL, S_IFREG, 1, 0, 0, 1, ip, 792 error = xfs_dir_ialloc(&tp, NULL, S_IFREG, 1, 0, 0, 1, ip,
diff --git a/fs/xfs/xfs_qm_syscalls.c b/fs/xfs/xfs_qm_syscalls.c
index f4d0e0a8f517..475a3882a81f 100644
--- a/fs/xfs/xfs_qm_syscalls.c
+++ b/fs/xfs/xfs_qm_syscalls.c
@@ -236,10 +236,8 @@ xfs_qm_scall_trunc_qfile(
236 236
237 xfs_ilock(ip, XFS_IOLOCK_EXCL); 237 xfs_ilock(ip, XFS_IOLOCK_EXCL);
238 238
239 tp = xfs_trans_alloc(mp, XFS_TRANS_TRUNCATE_FILE); 239 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
240 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_itruncate, 0, 0);
241 if (error) { 240 if (error) {
242 xfs_trans_cancel(tp);
243 xfs_iunlock(ip, XFS_IOLOCK_EXCL); 241 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
244 goto out_put; 242 goto out_put;
245 } 243 }
@@ -436,12 +434,9 @@ xfs_qm_scall_setqlim(
436 defq = xfs_get_defquota(dqp, q); 434 defq = xfs_get_defquota(dqp, q);
437 xfs_dqunlock(dqp); 435 xfs_dqunlock(dqp);
438 436
439 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_SETQLIM); 437 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_qm_setqlim, 0, 0, 0, &tp);
440 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_qm_setqlim, 0, 0); 438 if (error)
441 if (error) {
442 xfs_trans_cancel(tp);
443 goto out_rele; 439 goto out_rele;
444 }
445 440
446 xfs_dqlock(dqp); 441 xfs_dqlock(dqp);
447 xfs_trans_dqjoin(tp, dqp); 442 xfs_trans_dqjoin(tp, dqp);
@@ -569,13 +564,9 @@ xfs_qm_log_quotaoff_end(
569 int error; 564 int error;
570 xfs_qoff_logitem_t *qoffi; 565 xfs_qoff_logitem_t *qoffi;
571 566
572 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF_END); 567 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_qm_equotaoff, 0, 0, 0, &tp);
573 568 if (error)
574 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_qm_equotaoff, 0, 0);
575 if (error) {
576 xfs_trans_cancel(tp);
577 return error; 569 return error;
578 }
579 570
580 qoffi = xfs_trans_get_qoff_item(tp, startqoff, 571 qoffi = xfs_trans_get_qoff_item(tp, startqoff,
581 flags & XFS_ALL_QUOTA_ACCT); 572 flags & XFS_ALL_QUOTA_ACCT);
@@ -603,12 +594,9 @@ xfs_qm_log_quotaoff(
603 594
604 *qoffstartp = NULL; 595 *qoffstartp = NULL;
605 596
606 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF); 597 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_qm_quotaoff, 0, 0, 0, &tp);
607 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_qm_quotaoff, 0, 0); 598 if (error)
608 if (error) {
609 xfs_trans_cancel(tp);
610 goto out; 599 goto out;
611 }
612 600
613 qoffi = xfs_trans_get_qoff_item(tp, NULL, flags & XFS_ALL_QUOTA_ACCT); 601 qoffi = xfs_trans_get_qoff_item(tp, NULL, flags & XFS_ALL_QUOTA_ACCT);
614 xfs_trans_log_quotaoff_item(tp, qoffi); 602 xfs_trans_log_quotaoff_item(tp, qoffi);
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index abf44435d04a..3938b37d1043 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -780,15 +780,14 @@ xfs_growfs_rt_alloc(
780 * Allocate space to the file, as necessary. 780 * Allocate space to the file, as necessary.
781 */ 781 */
782 while (oblocks < nblocks) { 782 while (oblocks < nblocks) {
783 tp = xfs_trans_alloc(mp, XFS_TRANS_GROWFSRT_ALLOC);
784 resblks = XFS_GROWFSRT_SPACE_RES(mp, nblocks - oblocks); 783 resblks = XFS_GROWFSRT_SPACE_RES(mp, nblocks - oblocks);
785 /* 784 /*
786 * Reserve space & log for one extent added to the file. 785 * Reserve space & log for one extent added to the file.
787 */ 786 */
788 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_growrtalloc, 787 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtalloc, resblks,
789 resblks, 0); 788 0, 0, &tp);
790 if (error) 789 if (error)
791 goto out_trans_cancel; 790 return error;
792 /* 791 /*
793 * Lock the inode. 792 * Lock the inode.
794 */ 793 */
@@ -823,14 +822,13 @@ xfs_growfs_rt_alloc(
823 for (bno = map.br_startoff, fsbno = map.br_startblock; 822 for (bno = map.br_startoff, fsbno = map.br_startblock;
824 bno < map.br_startoff + map.br_blockcount; 823 bno < map.br_startoff + map.br_blockcount;
825 bno++, fsbno++) { 824 bno++, fsbno++) {
826 tp = xfs_trans_alloc(mp, XFS_TRANS_GROWFSRT_ZERO);
827 /* 825 /*
828 * Reserve log for one block zeroing. 826 * Reserve log for one block zeroing.
829 */ 827 */
830 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_growrtzero, 828 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtzero,
831 0, 0); 829 0, 0, 0, &tp);
832 if (error) 830 if (error)
833 goto out_trans_cancel; 831 return error;
834 /* 832 /*
835 * Lock the bitmap inode. 833 * Lock the bitmap inode.
836 */ 834 */
@@ -994,11 +992,10 @@ xfs_growfs_rt(
994 /* 992 /*
995 * Start a transaction, get the log reservation. 993 * Start a transaction, get the log reservation.
996 */ 994 */
997 tp = xfs_trans_alloc(mp, XFS_TRANS_GROWFSRT_FREE); 995 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtfree, 0, 0, 0,
998 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_growrtfree, 996 &tp);
999 0, 0);
1000 if (error) 997 if (error)
1001 goto error_cancel; 998 break;
1002 /* 999 /*
1003 * Lock out other callers by grabbing the bitmap inode lock. 1000 * Lock out other callers by grabbing the bitmap inode lock.
1004 */ 1001 */
diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c
index b44284c1adda..c3aeaa884478 100644
--- a/fs/xfs/xfs_symlink.c
+++ b/fs/xfs/xfs_symlink.c
@@ -221,7 +221,6 @@ xfs_symlink(
221 if (error) 221 if (error)
222 return error; 222 return error;
223 223
224 tp = xfs_trans_alloc(mp, XFS_TRANS_SYMLINK);
225 /* 224 /*
226 * The symlink will fit into the inode data fork? 225 * The symlink will fit into the inode data fork?
227 * There can't be any attributes so we get the whole variable part. 226 * There can't be any attributes so we get the whole variable part.
@@ -231,13 +230,15 @@ xfs_symlink(
231 else 230 else
232 fs_blocks = xfs_symlink_blocks(mp, pathlen); 231 fs_blocks = xfs_symlink_blocks(mp, pathlen);
233 resblks = XFS_SYMLINK_SPACE_RES(mp, link_name->len, fs_blocks); 232 resblks = XFS_SYMLINK_SPACE_RES(mp, link_name->len, fs_blocks);
234 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_symlink, resblks, 0); 233
234 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_symlink, resblks, 0, 0, &tp);
235 if (error == -ENOSPC && fs_blocks == 0) { 235 if (error == -ENOSPC && fs_blocks == 0) {
236 resblks = 0; 236 resblks = 0;
237 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_symlink, 0, 0); 237 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_symlink, 0, 0, 0,
238 &tp);
238 } 239 }
239 if (error) 240 if (error)
240 goto out_trans_cancel; 241 goto out_release_inode;
241 242
242 xfs_ilock(dp, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL | 243 xfs_ilock(dp, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL |
243 XFS_IOLOCK_PARENT | XFS_ILOCK_PARENT); 244 XFS_IOLOCK_PARENT | XFS_ILOCK_PARENT);
@@ -455,12 +456,9 @@ xfs_inactive_symlink_rmt(
455 */ 456 */
456 ASSERT(ip->i_d.di_nextents > 0 && ip->i_d.di_nextents <= 2); 457 ASSERT(ip->i_d.di_nextents > 0 && ip->i_d.di_nextents <= 2);
457 458
458 tp = xfs_trans_alloc(mp, XFS_TRANS_INACTIVE); 459 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
459 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_itruncate, 0, 0); 460 if (error)
460 if (error) {
461 xfs_trans_cancel(tp);
462 return error; 461 return error;
463 }
464 462
465 xfs_ilock(ip, XFS_ILOCK_EXCL); 463 xfs_ilock(ip, XFS_ILOCK_EXCL);
466 xfs_trans_ijoin(tp, ip, 0); 464 xfs_trans_ijoin(tp, ip, 0);
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
index c8d58426008e..f08129444280 100644
--- a/fs/xfs/xfs_trace.h
+++ b/fs/xfs/xfs_trace.h
@@ -944,7 +944,6 @@ DECLARE_EVENT_CLASS(xfs_loggrant_class,
944 TP_ARGS(log, tic), 944 TP_ARGS(log, tic),
945 TP_STRUCT__entry( 945 TP_STRUCT__entry(
946 __field(dev_t, dev) 946 __field(dev_t, dev)
947 __field(unsigned, trans_type)
948 __field(char, ocnt) 947 __field(char, ocnt)
949 __field(char, cnt) 948 __field(char, cnt)
950 __field(int, curr_res) 949 __field(int, curr_res)
@@ -962,7 +961,6 @@ DECLARE_EVENT_CLASS(xfs_loggrant_class,
962 ), 961 ),
963 TP_fast_assign( 962 TP_fast_assign(
964 __entry->dev = log->l_mp->m_super->s_dev; 963 __entry->dev = log->l_mp->m_super->s_dev;
965 __entry->trans_type = tic->t_trans_type;
966 __entry->ocnt = tic->t_ocnt; 964 __entry->ocnt = tic->t_ocnt;
967 __entry->cnt = tic->t_cnt; 965 __entry->cnt = tic->t_cnt;
968 __entry->curr_res = tic->t_curr_res; 966 __entry->curr_res = tic->t_curr_res;
@@ -980,14 +978,13 @@ DECLARE_EVENT_CLASS(xfs_loggrant_class,
980 __entry->curr_block = log->l_curr_block; 978 __entry->curr_block = log->l_curr_block;
981 __entry->tail_lsn = atomic64_read(&log->l_tail_lsn); 979 __entry->tail_lsn = atomic64_read(&log->l_tail_lsn);
982 ), 980 ),
983 TP_printk("dev %d:%d type %s t_ocnt %u t_cnt %u t_curr_res %u " 981 TP_printk("dev %d:%d t_ocnt %u t_cnt %u t_curr_res %u "
984 "t_unit_res %u t_flags %s reserveq %s " 982 "t_unit_res %u t_flags %s reserveq %s "
985 "writeq %s grant_reserve_cycle %d " 983 "writeq %s grant_reserve_cycle %d "
986 "grant_reserve_bytes %d grant_write_cycle %d " 984 "grant_reserve_bytes %d grant_write_cycle %d "
987 "grant_write_bytes %d curr_cycle %d curr_block %d " 985 "grant_write_bytes %d curr_cycle %d curr_block %d "
988 "tail_cycle %d tail_block %d", 986 "tail_cycle %d tail_block %d",
989 MAJOR(__entry->dev), MINOR(__entry->dev), 987 MAJOR(__entry->dev), MINOR(__entry->dev),
990 __print_symbolic(__entry->trans_type, XFS_TRANS_TYPES),
991 __entry->ocnt, 988 __entry->ocnt,
992 __entry->cnt, 989 __entry->cnt,
993 __entry->curr_res, 990 __entry->curr_res,
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index 20c53666cb4b..5f3d33d16e67 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -47,47 +47,6 @@ xfs_trans_init(
47} 47}
48 48
49/* 49/*
50 * This routine is called to allocate a transaction structure.
51 * The type parameter indicates the type of the transaction. These
52 * are enumerated in xfs_trans.h.
53 *
54 * Dynamically allocate the transaction structure from the transaction
55 * zone, initialize it, and return it to the caller.
56 */
57xfs_trans_t *
58xfs_trans_alloc(
59 xfs_mount_t *mp,
60 uint type)
61{
62 xfs_trans_t *tp;
63
64 sb_start_intwrite(mp->m_super);
65 tp = _xfs_trans_alloc(mp, type, KM_SLEEP);
66 tp->t_flags |= XFS_TRANS_FREEZE_PROT;
67 return tp;
68}
69
70xfs_trans_t *
71_xfs_trans_alloc(
72 xfs_mount_t *mp,
73 uint type,
74 xfs_km_flags_t memflags)
75{
76 xfs_trans_t *tp;
77
78 WARN_ON(mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE);
79 atomic_inc(&mp->m_active_trans);
80
81 tp = kmem_zone_zalloc(xfs_trans_zone, memflags);
82 tp->t_magic = XFS_TRANS_HEADER_MAGIC;
83 tp->t_type = type;
84 tp->t_mountp = mp;
85 INIT_LIST_HEAD(&tp->t_items);
86 INIT_LIST_HEAD(&tp->t_busy);
87 return tp;
88}
89
90/*
91 * Free the transaction structure. If there is more clean up 50 * Free the transaction structure. If there is more clean up
92 * to do when the structure is freed, add it here. 51 * to do when the structure is freed, add it here.
93 */ 52 */
@@ -99,7 +58,7 @@ xfs_trans_free(
99 xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false); 58 xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false);
100 59
101 atomic_dec(&tp->t_mountp->m_active_trans); 60 atomic_dec(&tp->t_mountp->m_active_trans);
102 if (tp->t_flags & XFS_TRANS_FREEZE_PROT) 61 if (!(tp->t_flags & XFS_TRANS_NO_WRITECOUNT))
103 sb_end_intwrite(tp->t_mountp->m_super); 62 sb_end_intwrite(tp->t_mountp->m_super);
104 xfs_trans_free_dqinfo(tp); 63 xfs_trans_free_dqinfo(tp);
105 kmem_zone_free(xfs_trans_zone, tp); 64 kmem_zone_free(xfs_trans_zone, tp);
@@ -125,7 +84,6 @@ xfs_trans_dup(
125 * Initialize the new transaction structure. 84 * Initialize the new transaction structure.
126 */ 85 */
127 ntp->t_magic = XFS_TRANS_HEADER_MAGIC; 86 ntp->t_magic = XFS_TRANS_HEADER_MAGIC;
128 ntp->t_type = tp->t_type;
129 ntp->t_mountp = tp->t_mountp; 87 ntp->t_mountp = tp->t_mountp;
130 INIT_LIST_HEAD(&ntp->t_items); 88 INIT_LIST_HEAD(&ntp->t_items);
131 INIT_LIST_HEAD(&ntp->t_busy); 89 INIT_LIST_HEAD(&ntp->t_busy);
@@ -135,9 +93,9 @@ xfs_trans_dup(
135 93
136 ntp->t_flags = XFS_TRANS_PERM_LOG_RES | 94 ntp->t_flags = XFS_TRANS_PERM_LOG_RES |
137 (tp->t_flags & XFS_TRANS_RESERVE) | 95 (tp->t_flags & XFS_TRANS_RESERVE) |
138 (tp->t_flags & XFS_TRANS_FREEZE_PROT); 96 (tp->t_flags & XFS_TRANS_NO_WRITECOUNT);
139 /* We gave our writer reference to the new transaction */ 97 /* We gave our writer reference to the new transaction */
140 tp->t_flags &= ~XFS_TRANS_FREEZE_PROT; 98 tp->t_flags |= XFS_TRANS_NO_WRITECOUNT;
141 ntp->t_ticket = xfs_log_ticket_get(tp->t_ticket); 99 ntp->t_ticket = xfs_log_ticket_get(tp->t_ticket);
142 ntp->t_blk_res = tp->t_blk_res - tp->t_blk_res_used; 100 ntp->t_blk_res = tp->t_blk_res - tp->t_blk_res_used;
143 tp->t_blk_res = tp->t_blk_res_used; 101 tp->t_blk_res = tp->t_blk_res_used;
@@ -165,7 +123,7 @@ xfs_trans_dup(
165 * This does not do quota reservations. That typically is done by the 123 * This does not do quota reservations. That typically is done by the
166 * caller afterwards. 124 * caller afterwards.
167 */ 125 */
168int 126static int
169xfs_trans_reserve( 127xfs_trans_reserve(
170 struct xfs_trans *tp, 128 struct xfs_trans *tp,
171 struct xfs_trans_res *resp, 129 struct xfs_trans_res *resp,
@@ -219,7 +177,7 @@ xfs_trans_reserve(
219 resp->tr_logres, 177 resp->tr_logres,
220 resp->tr_logcount, 178 resp->tr_logcount,
221 &tp->t_ticket, XFS_TRANSACTION, 179 &tp->t_ticket, XFS_TRANSACTION,
222 permanent, tp->t_type); 180 permanent);
223 } 181 }
224 182
225 if (error) 183 if (error)
@@ -268,6 +226,42 @@ undo_blocks:
268 return error; 226 return error;
269} 227}
270 228
229int
230xfs_trans_alloc(
231 struct xfs_mount *mp,
232 struct xfs_trans_res *resp,
233 uint blocks,
234 uint rtextents,
235 uint flags,
236 struct xfs_trans **tpp)
237{
238 struct xfs_trans *tp;
239 int error;
240
241 if (!(flags & XFS_TRANS_NO_WRITECOUNT))
242 sb_start_intwrite(mp->m_super);
243
244 WARN_ON(mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE);
245 atomic_inc(&mp->m_active_trans);
246
247 tp = kmem_zone_zalloc(xfs_trans_zone,
248 (flags & XFS_TRANS_NOFS) ? KM_NOFS : KM_SLEEP);
249 tp->t_magic = XFS_TRANS_HEADER_MAGIC;
250 tp->t_flags = flags;
251 tp->t_mountp = mp;
252 INIT_LIST_HEAD(&tp->t_items);
253 INIT_LIST_HEAD(&tp->t_busy);
254
255 error = xfs_trans_reserve(tp, resp, blocks, rtextents);
256 if (error) {
257 xfs_trans_cancel(tp);
258 return error;
259 }
260
261 *tpp = tp;
262 return 0;
263}
264
271/* 265/*
272 * Record the indicated change to the given field for application 266 * Record the indicated change to the given field for application
273 * to the file system's superblock when the transaction commits. 267 * to the file system's superblock when the transaction commits.
diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h
index e7c49cf43fbc..9a462e892e4f 100644
--- a/fs/xfs/xfs_trans.h
+++ b/fs/xfs/xfs_trans.h
@@ -90,7 +90,6 @@ void xfs_log_item_init(struct xfs_mount *mp, struct xfs_log_item *item,
90 */ 90 */
91typedef struct xfs_trans { 91typedef struct xfs_trans {
92 unsigned int t_magic; /* magic number */ 92 unsigned int t_magic; /* magic number */
93 unsigned int t_type; /* transaction type */
94 unsigned int t_log_res; /* amt of log space resvd */ 93 unsigned int t_log_res; /* amt of log space resvd */
95 unsigned int t_log_count; /* count for perm log res */ 94 unsigned int t_log_count; /* count for perm log res */
96 unsigned int t_blk_res; /* # of blocks resvd */ 95 unsigned int t_blk_res; /* # of blocks resvd */
@@ -148,10 +147,9 @@ typedef struct xfs_trans {
148/* 147/*
149 * XFS transaction mechanism exported interfaces. 148 * XFS transaction mechanism exported interfaces.
150 */ 149 */
151xfs_trans_t *xfs_trans_alloc(struct xfs_mount *, uint); 150int xfs_trans_alloc(struct xfs_mount *mp, struct xfs_trans_res *resp,
152xfs_trans_t *_xfs_trans_alloc(struct xfs_mount *, uint, xfs_km_flags_t); 151 uint blocks, uint rtextents, uint flags,
153int xfs_trans_reserve(struct xfs_trans *, struct xfs_trans_res *, 152 struct xfs_trans **tpp);
154 uint, uint);
155void xfs_trans_mod_sb(xfs_trans_t *, uint, int64_t); 153void xfs_trans_mod_sb(xfs_trans_t *, uint, int64_t);
156 154
157struct xfs_buf *xfs_trans_get_buf_map(struct xfs_trans *tp, 155struct xfs_buf *xfs_trans_get_buf_map(struct xfs_trans *tp,