aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_vnodeops.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_vnodeops.c')
-rw-r--r--fs/xfs/xfs_vnodeops.c409
1 files changed, 121 insertions, 288 deletions
diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
index c1646838898f..8e4a63c4151a 100644
--- a/fs/xfs/xfs_vnodeops.c
+++ b/fs/xfs/xfs_vnodeops.c
@@ -26,19 +26,14 @@
26#include "xfs_sb.h" 26#include "xfs_sb.h"
27#include "xfs_ag.h" 27#include "xfs_ag.h"
28#include "xfs_dir2.h" 28#include "xfs_dir2.h"
29#include "xfs_dmapi.h"
30#include "xfs_mount.h" 29#include "xfs_mount.h"
31#include "xfs_da_btree.h" 30#include "xfs_da_btree.h"
32#include "xfs_bmap_btree.h" 31#include "xfs_bmap_btree.h"
33#include "xfs_alloc_btree.h"
34#include "xfs_ialloc_btree.h" 32#include "xfs_ialloc_btree.h"
35#include "xfs_dir2_sf.h"
36#include "xfs_attr_sf.h"
37#include "xfs_dinode.h" 33#include "xfs_dinode.h"
38#include "xfs_inode.h" 34#include "xfs_inode.h"
39#include "xfs_inode_item.h" 35#include "xfs_inode_item.h"
40#include "xfs_itable.h" 36#include "xfs_itable.h"
41#include "xfs_btree.h"
42#include "xfs_ialloc.h" 37#include "xfs_ialloc.h"
43#include "xfs_alloc.h" 38#include "xfs_alloc.h"
44#include "xfs_bmap.h" 39#include "xfs_bmap.h"
@@ -73,7 +68,7 @@ xfs_setattr(
73 struct xfs_dquot *udqp, *gdqp, *olddquot1, *olddquot2; 68 struct xfs_dquot *udqp, *gdqp, *olddquot1, *olddquot2;
74 int need_iolock = 1; 69 int need_iolock = 1;
75 70
76 xfs_itrace_entry(ip); 71 trace_xfs_setattr(ip);
77 72
78 if (mp->m_flags & XFS_MOUNT_RDONLY) 73 if (mp->m_flags & XFS_MOUNT_RDONLY)
79 return XFS_ERROR(EROFS); 74 return XFS_ERROR(EROFS);
@@ -119,7 +114,7 @@ xfs_setattr(
119 */ 114 */
120 ASSERT(udqp == NULL); 115 ASSERT(udqp == NULL);
121 ASSERT(gdqp == NULL); 116 ASSERT(gdqp == NULL);
122 code = xfs_qm_vop_dqalloc(ip, uid, gid, ip->i_d.di_projid, 117 code = xfs_qm_vop_dqalloc(ip, uid, gid, xfs_get_projid(ip),
123 qflags, &udqp, &gdqp); 118 qflags, &udqp, &gdqp);
124 if (code) 119 if (code)
125 return code; 120 return code;
@@ -143,16 +138,6 @@ xfs_setattr(
143 goto error_return; 138 goto error_return;
144 } 139 }
145 } else { 140 } else {
146 if (DM_EVENT_ENABLED(ip, DM_EVENT_TRUNCATE) &&
147 !(flags & XFS_ATTR_DMI)) {
148 int dmflags = AT_DELAY_FLAG(flags) | DM_SEM_FLAG_WR;
149 code = XFS_SEND_DATA(mp, DM_EVENT_TRUNCATE, ip,
150 iattr->ia_size, 0, dmflags, NULL);
151 if (code) {
152 lock_flags = 0;
153 goto error_return;
154 }
155 }
156 if (need_iolock) 141 if (need_iolock)
157 lock_flags |= XFS_IOLOCK_EXCL; 142 lock_flags |= XFS_IOLOCK_EXCL;
158 } 143 }
@@ -199,8 +184,11 @@ xfs_setattr(
199 ip->i_size == 0 && ip->i_d.di_nextents == 0) { 184 ip->i_size == 0 && ip->i_d.di_nextents == 0) {
200 xfs_iunlock(ip, XFS_ILOCK_EXCL); 185 xfs_iunlock(ip, XFS_ILOCK_EXCL);
201 lock_flags &= ~XFS_ILOCK_EXCL; 186 lock_flags &= ~XFS_ILOCK_EXCL;
202 if (mask & ATTR_CTIME) 187 if (mask & ATTR_CTIME) {
203 xfs_ichgtime(ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); 188 inode->i_mtime = inode->i_ctime =
189 current_fs_time(inode->i_sb);
190 xfs_mark_inode_dirty_sync(ip);
191 }
204 code = 0; 192 code = 0;
205 goto error_return; 193 goto error_return;
206 } 194 }
@@ -236,8 +224,11 @@ xfs_setattr(
236 * transaction to modify the i_size. 224 * transaction to modify the i_size.
237 */ 225 */
238 code = xfs_zero_eof(ip, iattr->ia_size, ip->i_size); 226 code = xfs_zero_eof(ip, iattr->ia_size, ip->i_size);
227 if (code)
228 goto error_return;
239 } 229 }
240 xfs_iunlock(ip, XFS_ILOCK_EXCL); 230 xfs_iunlock(ip, XFS_ILOCK_EXCL);
231 lock_flags &= ~XFS_ILOCK_EXCL;
241 232
242 /* 233 /*
243 * We are going to log the inode size change in this 234 * We are going to log the inode size change in this
@@ -251,40 +242,38 @@ xfs_setattr(
251 * really care about here and prevents waiting for other data 242 * really care about here and prevents waiting for other data
252 * not within the range we care about here. 243 * not within the range we care about here.
253 */ 244 */
254 if (!code && 245 if (ip->i_size != ip->i_d.di_size &&
255 ip->i_size != ip->i_d.di_size &&
256 iattr->ia_size > ip->i_d.di_size) { 246 iattr->ia_size > ip->i_d.di_size) {
257 code = xfs_flush_pages(ip, 247 code = xfs_flush_pages(ip,
258 ip->i_d.di_size, iattr->ia_size, 248 ip->i_d.di_size, iattr->ia_size,
259 XBF_ASYNC, FI_NONE); 249 XBF_ASYNC, FI_NONE);
250 if (code)
251 goto error_return;
260 } 252 }
261 253
262 /* wait for all I/O to complete */ 254 /* wait for all I/O to complete */
263 xfs_ioend_wait(ip); 255 xfs_ioend_wait(ip);
264 256
265 if (!code) 257 code = -block_truncate_page(inode->i_mapping, iattr->ia_size,
266 code = xfs_itruncate_data(ip, iattr->ia_size); 258 xfs_get_blocks);
267 if (code) { 259 if (code)
268 ASSERT(tp == NULL);
269 lock_flags &= ~XFS_ILOCK_EXCL;
270 ASSERT(lock_flags == XFS_IOLOCK_EXCL || !need_iolock);
271 goto error_return; 260 goto error_return;
272 } 261
273 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_SIZE); 262 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_SIZE);
274 if ((code = xfs_trans_reserve(tp, 0, 263 code = xfs_trans_reserve(tp, 0, XFS_ITRUNCATE_LOG_RES(mp), 0,
275 XFS_ITRUNCATE_LOG_RES(mp), 0, 264 XFS_TRANS_PERM_LOG_RES,
276 XFS_TRANS_PERM_LOG_RES, 265 XFS_ITRUNCATE_LOG_COUNT);
277 XFS_ITRUNCATE_LOG_COUNT))) { 266 if (code)
278 xfs_trans_cancel(tp, 0); 267 goto error_return;
279 if (need_iolock) 268
280 xfs_iunlock(ip, XFS_IOLOCK_EXCL); 269 truncate_setsize(inode, iattr->ia_size);
281 return code; 270
282 }
283 commit_flags = XFS_TRANS_RELEASE_LOG_RES; 271 commit_flags = XFS_TRANS_RELEASE_LOG_RES;
272 lock_flags |= XFS_ILOCK_EXCL;
273
284 xfs_ilock(ip, XFS_ILOCK_EXCL); 274 xfs_ilock(ip, XFS_ILOCK_EXCL);
285 275
286 xfs_trans_ijoin(tp, ip, lock_flags); 276 xfs_trans_ijoin(tp, ip);
287 xfs_trans_ihold(tp, ip);
288 277
289 /* 278 /*
290 * Only change the c/mtime if we are changing the size 279 * Only change the c/mtime if we are changing the size
@@ -334,8 +323,7 @@ xfs_setattr(
334 xfs_iflags_set(ip, XFS_ITRUNCATED); 323 xfs_iflags_set(ip, XFS_ITRUNCATED);
335 } 324 }
336 } else if (tp) { 325 } else if (tp) {
337 xfs_trans_ijoin(tp, ip, lock_flags); 326 xfs_trans_ijoin(tp, ip);
338 xfs_trans_ihold(tp, ip);
339 } 327 }
340 328
341 /* 329 /*
@@ -470,17 +458,10 @@ xfs_setattr(
470 return XFS_ERROR(code); 458 return XFS_ERROR(code);
471 } 459 }
472 460
473 if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE) &&
474 !(flags & XFS_ATTR_DMI)) {
475 (void) XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, ip, DM_RIGHT_NULL,
476 NULL, DM_RIGHT_NULL, NULL, NULL,
477 0, 0, AT_DELAY_FLAG(flags));
478 }
479 return 0; 461 return 0;
480 462
481 abort_return: 463 abort_return:
482 commit_flags |= XFS_TRANS_ABORT; 464 commit_flags |= XFS_TRANS_ABORT;
483 /* FALLTHROUGH */
484 error_return: 465 error_return:
485 xfs_qm_dqrele(udqp); 466 xfs_qm_dqrele(udqp);
486 xfs_qm_dqrele(gdqp); 467 xfs_qm_dqrele(gdqp);
@@ -516,7 +497,7 @@ xfs_readlink_bmap(
516 int error = 0; 497 int error = 0;
517 498
518 error = xfs_bmapi(NULL, ip, 0, XFS_B_TO_FSB(mp, pathlen), 0, NULL, 0, 499 error = xfs_bmapi(NULL, ip, 0, XFS_B_TO_FSB(mp, pathlen), 0, NULL, 0,
519 mval, &nmaps, NULL, NULL); 500 mval, &nmaps, NULL);
520 if (error) 501 if (error)
521 goto out; 502 goto out;
522 503
@@ -557,7 +538,7 @@ xfs_readlink(
557 int pathlen; 538 int pathlen;
558 int error = 0; 539 int error = 0;
559 540
560 xfs_itrace_entry(ip); 541 trace_xfs_readlink(ip);
561 542
562 if (XFS_FORCED_SHUTDOWN(mp)) 543 if (XFS_FORCED_SHUTDOWN(mp))
563 return XFS_ERROR(EIO); 544 return XFS_ERROR(EIO);
@@ -613,14 +594,14 @@ xfs_free_eofblocks(
613 */ 594 */
614 end_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)ip->i_size)); 595 end_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)ip->i_size));
615 last_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp)); 596 last_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp));
616 map_len = last_fsb - end_fsb; 597 if (last_fsb <= end_fsb)
617 if (map_len <= 0)
618 return 0; 598 return 0;
599 map_len = last_fsb - end_fsb;
619 600
620 nimaps = 1; 601 nimaps = 1;
621 xfs_ilock(ip, XFS_ILOCK_SHARED); 602 xfs_ilock(ip, XFS_ILOCK_SHARED);
622 error = xfs_bmapi(NULL, ip, end_fsb, map_len, 0, 603 error = xfs_bmapi(NULL, ip, end_fsb, map_len, 0,
623 NULL, 0, &imap, &nimaps, NULL, NULL); 604 NULL, 0, &imap, &nimaps, NULL);
624 xfs_iunlock(ip, XFS_ILOCK_SHARED); 605 xfs_iunlock(ip, XFS_ILOCK_SHARED);
625 606
626 if (!error && (nimaps != 0) && 607 if (!error && (nimaps != 0) &&
@@ -675,10 +656,7 @@ xfs_free_eofblocks(
675 } 656 }
676 657
677 xfs_ilock(ip, XFS_ILOCK_EXCL); 658 xfs_ilock(ip, XFS_ILOCK_EXCL);
678 xfs_trans_ijoin(tp, ip, 659 xfs_trans_ijoin(tp, ip);
679 XFS_IOLOCK_EXCL |
680 XFS_ILOCK_EXCL);
681 xfs_trans_ihold(tp, ip);
682 660
683 error = xfs_itruncate_finish(&tp, ip, 661 error = xfs_itruncate_finish(&tp, ip,
684 ip->i_size, 662 ip->i_size,
@@ -750,8 +728,7 @@ xfs_inactive_symlink_rmt(
750 xfs_ilock(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL); 728 xfs_ilock(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
751 size = (int)ip->i_d.di_size; 729 size = (int)ip->i_d.di_size;
752 ip->i_d.di_size = 0; 730 ip->i_d.di_size = 0;
753 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); 731 xfs_trans_ijoin(tp, ip);
754 xfs_trans_ihold(tp, ip);
755 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); 732 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
756 /* 733 /*
757 * Find the block(s) so we can inval and unmap them. 734 * Find the block(s) so we can inval and unmap them.
@@ -761,7 +738,7 @@ xfs_inactive_symlink_rmt(
761 nmaps = ARRAY_SIZE(mval); 738 nmaps = ARRAY_SIZE(mval);
762 if ((error = xfs_bmapi(tp, ip, 0, XFS_B_TO_FSB(mp, size), 739 if ((error = xfs_bmapi(tp, ip, 0, XFS_B_TO_FSB(mp, size),
763 XFS_BMAPI_METADATA, &first_block, 0, mval, &nmaps, 740 XFS_BMAPI_METADATA, &first_block, 0, mval, &nmaps,
764 &free_list, NULL))) 741 &free_list)))
765 goto error0; 742 goto error0;
766 /* 743 /*
767 * Invalidate the block(s). 744 * Invalidate the block(s).
@@ -776,7 +753,7 @@ xfs_inactive_symlink_rmt(
776 * Unmap the dead block(s) to the free_list. 753 * Unmap the dead block(s) to the free_list.
777 */ 754 */
778 if ((error = xfs_bunmapi(tp, ip, 0, size, XFS_BMAPI_METADATA, nmaps, 755 if ((error = xfs_bunmapi(tp, ip, 0, size, XFS_BMAPI_METADATA, nmaps,
779 &first_block, &free_list, NULL, &done))) 756 &first_block, &free_list, &done)))
780 goto error1; 757 goto error1;
781 ASSERT(done); 758 ASSERT(done);
782 /* 759 /*
@@ -795,8 +772,7 @@ xfs_inactive_symlink_rmt(
795 * Mark it dirty so it will be logged and moved forward in the log as 772 * Mark it dirty so it will be logged and moved forward in the log as
796 * part of every commit. 773 * part of every commit.
797 */ 774 */
798 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); 775 xfs_trans_ijoin(tp, ip);
799 xfs_trans_ihold(tp, ip);
800 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); 776 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
801 /* 777 /*
802 * Get a new, empty transaction to return to our caller. 778 * Get a new, empty transaction to return to our caller.
@@ -929,8 +905,7 @@ xfs_inactive_attrs(
929 goto error_cancel; 905 goto error_cancel;
930 906
931 xfs_ilock(ip, XFS_ILOCK_EXCL); 907 xfs_ilock(ip, XFS_ILOCK_EXCL);
932 xfs_trans_ijoin(tp, ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL); 908 xfs_trans_ijoin(tp, ip);
933 xfs_trans_ihold(tp, ip);
934 xfs_idestroy_fork(ip, XFS_ATTR_FORK); 909 xfs_idestroy_fork(ip, XFS_ATTR_FORK);
935 910
936 ASSERT(ip->i_d.di_anextents == 0); 911 ASSERT(ip->i_d.di_anextents == 0);
@@ -1035,8 +1010,6 @@ xfs_inactive(
1035 int error; 1010 int error;
1036 int truncate; 1011 int truncate;
1037 1012
1038 xfs_itrace_entry(ip);
1039
1040 /* 1013 /*
1041 * If the inode is already free, then there can be nothing 1014 * If the inode is already free, then there can be nothing
1042 * to clean up here. 1015 * to clean up here.
@@ -1060,9 +1033,6 @@ xfs_inactive(
1060 1033
1061 mp = ip->i_mount; 1034 mp = ip->i_mount;
1062 1035
1063 if (ip->i_d.di_nlink == 0 && DM_EVENT_ENABLED(ip, DM_EVENT_DESTROY))
1064 XFS_SEND_DESTROY(mp, ip, DM_RIGHT_NULL);
1065
1066 error = 0; 1036 error = 0;
1067 1037
1068 /* If this is a read-only mount, don't do this (would generate I/O) */ 1038 /* If this is a read-only mount, don't do this (would generate I/O) */
@@ -1120,8 +1090,7 @@ xfs_inactive(
1120 } 1090 }
1121 1091
1122 xfs_ilock(ip, XFS_ILOCK_EXCL); 1092 xfs_ilock(ip, XFS_ILOCK_EXCL);
1123 xfs_trans_ijoin(tp, ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL); 1093 xfs_trans_ijoin(tp, ip);
1124 xfs_trans_ihold(tp, ip);
1125 1094
1126 /* 1095 /*
1127 * normally, we have to run xfs_itruncate_finish sync. 1096 * normally, we have to run xfs_itruncate_finish sync.
@@ -1154,8 +1123,7 @@ xfs_inactive(
1154 return VN_INACTIVE_CACHE; 1123 return VN_INACTIVE_CACHE;
1155 } 1124 }
1156 1125
1157 xfs_trans_ijoin(tp, ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL); 1126 xfs_trans_ijoin(tp, ip);
1158 xfs_trans_ihold(tp, ip);
1159 } else { 1127 } else {
1160 error = xfs_trans_reserve(tp, 0, 1128 error = xfs_trans_reserve(tp, 0,
1161 XFS_IFREE_LOG_RES(mp), 1129 XFS_IFREE_LOG_RES(mp),
@@ -1168,8 +1136,7 @@ xfs_inactive(
1168 } 1136 }
1169 1137
1170 xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); 1138 xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
1171 xfs_trans_ijoin(tp, ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL); 1139 xfs_trans_ijoin(tp, ip);
1172 xfs_trans_ihold(tp, ip);
1173 } 1140 }
1174 1141
1175 /* 1142 /*
@@ -1257,7 +1224,7 @@ xfs_lookup(
1257 int error; 1224 int error;
1258 uint lock_mode; 1225 uint lock_mode;
1259 1226
1260 xfs_itrace_entry(dp); 1227 trace_xfs_lookup(dp, name);
1261 1228
1262 if (XFS_FORCED_SHUTDOWN(dp->i_mount)) 1229 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
1263 return XFS_ERROR(EIO); 1230 return XFS_ERROR(EIO);
@@ -1289,8 +1256,7 @@ xfs_create(
1289 struct xfs_name *name, 1256 struct xfs_name *name,
1290 mode_t mode, 1257 mode_t mode,
1291 xfs_dev_t rdev, 1258 xfs_dev_t rdev,
1292 xfs_inode_t **ipp, 1259 xfs_inode_t **ipp)
1293 cred_t *credp)
1294{ 1260{
1295 int is_dir = S_ISDIR(mode); 1261 int is_dir = S_ISDIR(mode);
1296 struct xfs_mount *mp = dp->i_mount; 1262 struct xfs_mount *mp = dp->i_mount;
@@ -1302,32 +1268,22 @@ xfs_create(
1302 boolean_t unlock_dp_on_error = B_FALSE; 1268 boolean_t unlock_dp_on_error = B_FALSE;
1303 uint cancel_flags; 1269 uint cancel_flags;
1304 int committed; 1270 int committed;
1305 xfs_prid_t prid; 1271 prid_t prid;
1306 struct xfs_dquot *udqp = NULL; 1272 struct xfs_dquot *udqp = NULL;
1307 struct xfs_dquot *gdqp = NULL; 1273 struct xfs_dquot *gdqp = NULL;
1308 uint resblks; 1274 uint resblks;
1309 uint log_res; 1275 uint log_res;
1310 uint log_count; 1276 uint log_count;
1311 1277
1312 xfs_itrace_entry(dp); 1278 trace_xfs_create(dp, name);
1313 1279
1314 if (XFS_FORCED_SHUTDOWN(mp)) 1280 if (XFS_FORCED_SHUTDOWN(mp))
1315 return XFS_ERROR(EIO); 1281 return XFS_ERROR(EIO);
1316 1282
1317 if (DM_EVENT_ENABLED(dp, DM_EVENT_CREATE)) {
1318 error = XFS_SEND_NAMESP(mp, DM_EVENT_CREATE,
1319 dp, DM_RIGHT_NULL, NULL,
1320 DM_RIGHT_NULL, name->name, NULL,
1321 mode, 0, 0);
1322
1323 if (error)
1324 return error;
1325 }
1326
1327 if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) 1283 if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)
1328 prid = dp->i_d.di_projid; 1284 prid = xfs_get_projid(dp);
1329 else 1285 else
1330 prid = dfltprid; 1286 prid = XFS_PROJID_DEFAULT;
1331 1287
1332 /* 1288 /*
1333 * Make sure that we have allocated dquot(s) on disk. 1289 * Make sure that we have allocated dquot(s) on disk.
@@ -1406,7 +1362,7 @@ xfs_create(
1406 * entry pointing to them, but a directory also the "." entry 1362 * entry pointing to them, but a directory also the "." entry
1407 * pointing to itself. 1363 * pointing to itself.
1408 */ 1364 */
1409 error = xfs_dir_ialloc(&tp, dp, mode, is_dir ? 2 : 1, rdev, credp, 1365 error = xfs_dir_ialloc(&tp, dp, mode, is_dir ? 2 : 1, rdev,
1410 prid, resblks > 0, &ip, &committed); 1366 prid, resblks > 0, &ip, &committed);
1411 if (error) { 1367 if (error) {
1412 if (error == ENOSPC) 1368 if (error == ENOSPC)
@@ -1427,8 +1383,7 @@ xfs_create(
1427 * the transaction cancel unlocking dp so don't do it explicitly in the 1383 * the transaction cancel unlocking dp so don't do it explicitly in the
1428 * error path. 1384 * error path.
1429 */ 1385 */
1430 IHOLD(dp); 1386 xfs_trans_ijoin_ref(tp, dp, XFS_ILOCK_EXCL);
1431 xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
1432 unlock_dp_on_error = B_FALSE; 1387 unlock_dp_on_error = B_FALSE;
1433 1388
1434 error = xfs_dir_createname(tp, dp, name, ip->i_ino, 1389 error = xfs_dir_createname(tp, dp, name, ip->i_ino,
@@ -1438,7 +1393,7 @@ xfs_create(
1438 ASSERT(error != ENOSPC); 1393 ASSERT(error != ENOSPC);
1439 goto out_trans_abort; 1394 goto out_trans_abort;
1440 } 1395 }
1441 xfs_ichgtime(dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); 1396 xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
1442 xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); 1397 xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);
1443 1398
1444 if (is_dir) { 1399 if (is_dir) {
@@ -1487,16 +1442,7 @@ xfs_create(
1487 xfs_qm_dqrele(gdqp); 1442 xfs_qm_dqrele(gdqp);
1488 1443
1489 *ipp = ip; 1444 *ipp = ip;
1490 1445 return 0;
1491 /* Fallthrough to std_return with error = 0 */
1492 std_return:
1493 if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTCREATE)) {
1494 XFS_SEND_NAMESP(mp, DM_EVENT_POSTCREATE, dp, DM_RIGHT_NULL,
1495 ip, DM_RIGHT_NULL, name->name, NULL, mode,
1496 error, 0);
1497 }
1498
1499 return error;
1500 1446
1501 out_bmap_cancel: 1447 out_bmap_cancel:
1502 xfs_bmap_cancel(&free_list); 1448 xfs_bmap_cancel(&free_list);
@@ -1510,8 +1456,8 @@ xfs_create(
1510 1456
1511 if (unlock_dp_on_error) 1457 if (unlock_dp_on_error)
1512 xfs_iunlock(dp, XFS_ILOCK_EXCL); 1458 xfs_iunlock(dp, XFS_ILOCK_EXCL);
1513 1459 std_return:
1514 goto std_return; 1460 return error;
1515 1461
1516 out_abort_rele: 1462 out_abort_rele:
1517 /* 1463 /*
@@ -1726,20 +1672,11 @@ xfs_remove(
1726 uint resblks; 1672 uint resblks;
1727 uint log_count; 1673 uint log_count;
1728 1674
1729 xfs_itrace_entry(dp); 1675 trace_xfs_remove(dp, name);
1730 xfs_itrace_entry(ip);
1731 1676
1732 if (XFS_FORCED_SHUTDOWN(mp)) 1677 if (XFS_FORCED_SHUTDOWN(mp))
1733 return XFS_ERROR(EIO); 1678 return XFS_ERROR(EIO);
1734 1679
1735 if (DM_EVENT_ENABLED(dp, DM_EVENT_REMOVE)) {
1736 error = XFS_SEND_NAMESP(mp, DM_EVENT_REMOVE, dp, DM_RIGHT_NULL,
1737 NULL, DM_RIGHT_NULL, name->name, NULL,
1738 ip->i_d.di_mode, 0, 0);
1739 if (error)
1740 return error;
1741 }
1742
1743 error = xfs_qm_dqattach(dp, 0); 1680 error = xfs_qm_dqattach(dp, 0);
1744 if (error) 1681 if (error)
1745 goto std_return; 1682 goto std_return;
@@ -1782,15 +1719,8 @@ xfs_remove(
1782 1719
1783 xfs_lock_two_inodes(dp, ip, XFS_ILOCK_EXCL); 1720 xfs_lock_two_inodes(dp, ip, XFS_ILOCK_EXCL);
1784 1721
1785 /* 1722 xfs_trans_ijoin_ref(tp, dp, XFS_ILOCK_EXCL);
1786 * At this point, we've gotten both the directory and the entry 1723 xfs_trans_ijoin_ref(tp, ip, XFS_ILOCK_EXCL);
1787 * inodes locked.
1788 */
1789 IHOLD(ip);
1790 xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
1791
1792 IHOLD(dp);
1793 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1794 1724
1795 /* 1725 /*
1796 * If we're removing a directory perform some additional validation. 1726 * If we're removing a directory perform some additional validation.
@@ -1814,7 +1744,7 @@ xfs_remove(
1814 ASSERT(error != ENOENT); 1744 ASSERT(error != ENOENT);
1815 goto out_bmap_cancel; 1745 goto out_bmap_cancel;
1816 } 1746 }
1817 xfs_ichgtime(dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); 1747 xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
1818 1748
1819 if (is_dir) { 1749 if (is_dir) {
1820 /* 1750 /*
@@ -1877,21 +1807,15 @@ xfs_remove(
1877 if (!is_dir && link_zero && xfs_inode_is_filestream(ip)) 1807 if (!is_dir && link_zero && xfs_inode_is_filestream(ip))
1878 xfs_filestream_deassociate(ip); 1808 xfs_filestream_deassociate(ip);
1879 1809
1880 std_return: 1810 return 0;
1881 if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTREMOVE)) {
1882 XFS_SEND_NAMESP(mp, DM_EVENT_POSTREMOVE, dp, DM_RIGHT_NULL,
1883 NULL, DM_RIGHT_NULL, name->name, NULL,
1884 ip->i_d.di_mode, error, 0);
1885 }
1886
1887 return error;
1888 1811
1889 out_bmap_cancel: 1812 out_bmap_cancel:
1890 xfs_bmap_cancel(&free_list); 1813 xfs_bmap_cancel(&free_list);
1891 cancel_flags |= XFS_TRANS_ABORT; 1814 cancel_flags |= XFS_TRANS_ABORT;
1892 out_trans_cancel: 1815 out_trans_cancel:
1893 xfs_trans_cancel(tp, cancel_flags); 1816 xfs_trans_cancel(tp, cancel_flags);
1894 goto std_return; 1817 std_return:
1818 return error;
1895} 1819}
1896 1820
1897int 1821int
@@ -1909,25 +1833,13 @@ xfs_link(
1909 int committed; 1833 int committed;
1910 int resblks; 1834 int resblks;
1911 1835
1912 xfs_itrace_entry(tdp); 1836 trace_xfs_link(tdp, target_name);
1913 xfs_itrace_entry(sip);
1914 1837
1915 ASSERT(!S_ISDIR(sip->i_d.di_mode)); 1838 ASSERT(!S_ISDIR(sip->i_d.di_mode));
1916 1839
1917 if (XFS_FORCED_SHUTDOWN(mp)) 1840 if (XFS_FORCED_SHUTDOWN(mp))
1918 return XFS_ERROR(EIO); 1841 return XFS_ERROR(EIO);
1919 1842
1920 if (DM_EVENT_ENABLED(tdp, DM_EVENT_LINK)) {
1921 error = XFS_SEND_NAMESP(mp, DM_EVENT_LINK,
1922 tdp, DM_RIGHT_NULL,
1923 sip, DM_RIGHT_NULL,
1924 target_name->name, NULL, 0, 0, 0);
1925 if (error)
1926 return error;
1927 }
1928
1929 /* Return through std_return after this point. */
1930
1931 error = xfs_qm_dqattach(sip, 0); 1843 error = xfs_qm_dqattach(sip, 0);
1932 if (error) 1844 if (error)
1933 goto std_return; 1845 goto std_return;
@@ -1953,15 +1865,8 @@ xfs_link(
1953 1865
1954 xfs_lock_two_inodes(sip, tdp, XFS_ILOCK_EXCL); 1866 xfs_lock_two_inodes(sip, tdp, XFS_ILOCK_EXCL);
1955 1867
1956 /* 1868 xfs_trans_ijoin_ref(tp, sip, XFS_ILOCK_EXCL);
1957 * Increment vnode ref counts since xfs_trans_commit & 1869 xfs_trans_ijoin_ref(tp, tdp, XFS_ILOCK_EXCL);
1958 * xfs_trans_cancel will both unlock the inodes and
1959 * decrement the associated ref counts.
1960 */
1961 IHOLD(sip);
1962 IHOLD(tdp);
1963 xfs_trans_ijoin(tp, sip, XFS_ILOCK_EXCL);
1964 xfs_trans_ijoin(tp, tdp, XFS_ILOCK_EXCL);
1965 1870
1966 /* 1871 /*
1967 * If the source has too many links, we can't make any more to it. 1872 * If the source has too many links, we can't make any more to it.
@@ -1977,7 +1882,7 @@ xfs_link(
1977 * the tree quota mechanism could be circumvented. 1882 * the tree quota mechanism could be circumvented.
1978 */ 1883 */
1979 if (unlikely((tdp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) && 1884 if (unlikely((tdp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
1980 (tdp->i_d.di_projid != sip->i_d.di_projid))) { 1885 (xfs_get_projid(tdp) != xfs_get_projid(sip)))) {
1981 error = XFS_ERROR(EXDEV); 1886 error = XFS_ERROR(EXDEV);
1982 goto error_return; 1887 goto error_return;
1983 } 1888 }
@@ -1992,7 +1897,7 @@ xfs_link(
1992 &first_block, &free_list, resblks); 1897 &first_block, &free_list, resblks);
1993 if (error) 1898 if (error)
1994 goto abort_return; 1899 goto abort_return;
1995 xfs_ichgtime(tdp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); 1900 xfs_trans_ichgtime(tp, tdp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
1996 xfs_trans_log_inode(tp, tdp, XFS_ILOG_CORE); 1901 xfs_trans_log_inode(tp, tdp, XFS_ILOG_CORE);
1997 1902
1998 error = xfs_bumplink(tp, sip); 1903 error = xfs_bumplink(tp, sip);
@@ -2014,27 +1919,14 @@ xfs_link(
2014 goto abort_return; 1919 goto abort_return;
2015 } 1920 }
2016 1921
2017 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); 1922 return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
2018 if (error)
2019 goto std_return;
2020
2021 /* Fall through to std_return with error = 0. */
2022std_return:
2023 if (DM_EVENT_ENABLED(sip, DM_EVENT_POSTLINK)) {
2024 (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTLINK,
2025 tdp, DM_RIGHT_NULL,
2026 sip, DM_RIGHT_NULL,
2027 target_name->name, NULL, 0, error, 0);
2028 }
2029 return error;
2030 1923
2031 abort_return: 1924 abort_return:
2032 cancel_flags |= XFS_TRANS_ABORT; 1925 cancel_flags |= XFS_TRANS_ABORT;
2033 /* FALLTHROUGH */
2034
2035 error_return: 1926 error_return:
2036 xfs_trans_cancel(tp, cancel_flags); 1927 xfs_trans_cancel(tp, cancel_flags);
2037 goto std_return; 1928 std_return:
1929 return error;
2038} 1930}
2039 1931
2040int 1932int
@@ -2043,8 +1935,7 @@ xfs_symlink(
2043 struct xfs_name *link_name, 1935 struct xfs_name *link_name,
2044 const char *target_path, 1936 const char *target_path,
2045 mode_t mode, 1937 mode_t mode,
2046 xfs_inode_t **ipp, 1938 xfs_inode_t **ipp)
2047 cred_t *credp)
2048{ 1939{
2049 xfs_mount_t *mp = dp->i_mount; 1940 xfs_mount_t *mp = dp->i_mount;
2050 xfs_trans_t *tp; 1941 xfs_trans_t *tp;
@@ -2065,7 +1956,7 @@ xfs_symlink(
2065 int byte_cnt; 1956 int byte_cnt;
2066 int n; 1957 int n;
2067 xfs_buf_t *bp; 1958 xfs_buf_t *bp;
2068 xfs_prid_t prid; 1959 prid_t prid;
2069 struct xfs_dquot *udqp, *gdqp; 1960 struct xfs_dquot *udqp, *gdqp;
2070 uint resblks; 1961 uint resblks;
2071 1962
@@ -2074,7 +1965,7 @@ xfs_symlink(
2074 ip = NULL; 1965 ip = NULL;
2075 tp = NULL; 1966 tp = NULL;
2076 1967
2077 xfs_itrace_entry(dp); 1968 trace_xfs_symlink(dp, link_name);
2078 1969
2079 if (XFS_FORCED_SHUTDOWN(mp)) 1970 if (XFS_FORCED_SHUTDOWN(mp))
2080 return XFS_ERROR(EIO); 1971 return XFS_ERROR(EIO);
@@ -2086,22 +1977,11 @@ xfs_symlink(
2086 if (pathlen >= MAXPATHLEN) /* total string too long */ 1977 if (pathlen >= MAXPATHLEN) /* total string too long */
2087 return XFS_ERROR(ENAMETOOLONG); 1978 return XFS_ERROR(ENAMETOOLONG);
2088 1979
2089 if (DM_EVENT_ENABLED(dp, DM_EVENT_SYMLINK)) {
2090 error = XFS_SEND_NAMESP(mp, DM_EVENT_SYMLINK, dp,
2091 DM_RIGHT_NULL, NULL, DM_RIGHT_NULL,
2092 link_name->name,
2093 (unsigned char *)target_path, 0, 0, 0);
2094 if (error)
2095 return error;
2096 }
2097
2098 /* Return through std_return after this point. */
2099
2100 udqp = gdqp = NULL; 1980 udqp = gdqp = NULL;
2101 if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) 1981 if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)
2102 prid = dp->i_d.di_projid; 1982 prid = xfs_get_projid(dp);
2103 else 1983 else
2104 prid = (xfs_prid_t)dfltprid; 1984 prid = XFS_PROJID_DEFAULT;
2105 1985
2106 /* 1986 /*
2107 * Make sure that we have allocated dquot(s) on disk. 1987 * Make sure that we have allocated dquot(s) on disk.
@@ -2167,8 +2047,8 @@ xfs_symlink(
2167 /* 2047 /*
2168 * Allocate an inode for the symlink. 2048 * Allocate an inode for the symlink.
2169 */ 2049 */
2170 error = xfs_dir_ialloc(&tp, dp, S_IFLNK | (mode & ~S_IFMT), 2050 error = xfs_dir_ialloc(&tp, dp, S_IFLNK | (mode & ~S_IFMT), 1, 0,
2171 1, 0, credp, prid, resblks > 0, &ip, NULL); 2051 prid, resblks > 0, &ip, NULL);
2172 if (error) { 2052 if (error) {
2173 if (error == ENOSPC) 2053 if (error == ENOSPC)
2174 goto error_return; 2054 goto error_return;
@@ -2180,8 +2060,7 @@ xfs_symlink(
2180 * transaction cancel unlocking dp so don't do it explicitly in the 2060 * transaction cancel unlocking dp so don't do it explicitly in the
2181 * error path. 2061 * error path.
2182 */ 2062 */
2183 IHOLD(dp); 2063 xfs_trans_ijoin_ref(tp, dp, XFS_ILOCK_EXCL);
2184 xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
2185 unlock_dp_on_error = B_FALSE; 2064 unlock_dp_on_error = B_FALSE;
2186 2065
2187 /* 2066 /*
@@ -2215,7 +2094,7 @@ xfs_symlink(
2215 error = xfs_bmapi(tp, ip, first_fsb, fs_blocks, 2094 error = xfs_bmapi(tp, ip, first_fsb, fs_blocks,
2216 XFS_BMAPI_WRITE | XFS_BMAPI_METADATA, 2095 XFS_BMAPI_WRITE | XFS_BMAPI_METADATA,
2217 &first_block, resblks, mval, &nmaps, 2096 &first_block, resblks, mval, &nmaps,
2218 &free_list, NULL); 2097 &free_list);
2219 if (error) { 2098 if (error) {
2220 goto error1; 2099 goto error1;
2221 } 2100 }
@@ -2251,7 +2130,7 @@ xfs_symlink(
2251 &first_block, &free_list, resblks); 2130 &first_block, &free_list, resblks);
2252 if (error) 2131 if (error)
2253 goto error1; 2132 goto error1;
2254 xfs_ichgtime(dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); 2133 xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
2255 xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); 2134 xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);
2256 2135
2257 /* 2136 /*
@@ -2278,21 +2157,8 @@ xfs_symlink(
2278 xfs_qm_dqrele(udqp); 2157 xfs_qm_dqrele(udqp);
2279 xfs_qm_dqrele(gdqp); 2158 xfs_qm_dqrele(gdqp);
2280 2159
2281 /* Fall through to std_return with error = 0 or errno from 2160 *ipp = ip;
2282 * xfs_trans_commit */ 2161 return 0;
2283std_return:
2284 if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTSYMLINK)) {
2285 (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTSYMLINK,
2286 dp, DM_RIGHT_NULL,
2287 error ? NULL : ip,
2288 DM_RIGHT_NULL, link_name->name,
2289 (unsigned char *)target_path,
2290 0, error, 0);
2291 }
2292
2293 if (!error)
2294 *ipp = ip;
2295 return error;
2296 2162
2297 error2: 2163 error2:
2298 IRELE(ip); 2164 IRELE(ip);
@@ -2306,8 +2172,8 @@ std_return:
2306 2172
2307 if (unlock_dp_on_error) 2173 if (unlock_dp_on_error)
2308 xfs_iunlock(dp, XFS_ILOCK_EXCL); 2174 xfs_iunlock(dp, XFS_ILOCK_EXCL);
2309 2175 std_return:
2310 goto std_return; 2176 return error;
2311} 2177}
2312 2178
2313int 2179int
@@ -2333,13 +2199,12 @@ xfs_set_dmattrs(
2333 return error; 2199 return error;
2334 } 2200 }
2335 xfs_ilock(ip, XFS_ILOCK_EXCL); 2201 xfs_ilock(ip, XFS_ILOCK_EXCL);
2336 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 2202 xfs_trans_ijoin_ref(tp, ip, XFS_ILOCK_EXCL);
2337 2203
2338 ip->i_d.di_dmevmask = evmask; 2204 ip->i_d.di_dmevmask = evmask;
2339 ip->i_d.di_dmstate = state; 2205 ip->i_d.di_dmstate = state;
2340 2206
2341 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); 2207 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
2342 IHOLD(ip);
2343 error = xfs_trans_commit(tp, 0); 2208 error = xfs_trans_commit(tp, 0);
2344 2209
2345 return error; 2210 return error;
@@ -2390,7 +2255,7 @@ xfs_alloc_file_space(
2390 int committed; 2255 int committed;
2391 int error; 2256 int error;
2392 2257
2393 xfs_itrace_entry(ip); 2258 trace_xfs_alloc_file_space(ip);
2394 2259
2395 if (XFS_FORCED_SHUTDOWN(mp)) 2260 if (XFS_FORCED_SHUTDOWN(mp))
2396 return XFS_ERROR(EIO); 2261 return XFS_ERROR(EIO);
@@ -2408,29 +2273,13 @@ xfs_alloc_file_space(
2408 count = len; 2273 count = len;
2409 imapp = &imaps[0]; 2274 imapp = &imaps[0];
2410 nimaps = 1; 2275 nimaps = 1;
2411 bmapi_flag = XFS_BMAPI_WRITE | (alloc_type ? XFS_BMAPI_PREALLOC : 0); 2276 bmapi_flag = XFS_BMAPI_WRITE | alloc_type;
2412 startoffset_fsb = XFS_B_TO_FSBT(mp, offset); 2277 startoffset_fsb = XFS_B_TO_FSBT(mp, offset);
2413 allocatesize_fsb = XFS_B_TO_FSB(mp, count); 2278 allocatesize_fsb = XFS_B_TO_FSB(mp, count);
2414 2279
2415 /* Generate a DMAPI event if needed. */
2416 if (alloc_type != 0 && offset < ip->i_size &&
2417 (attr_flags & XFS_ATTR_DMI) == 0 &&
2418 DM_EVENT_ENABLED(ip, DM_EVENT_WRITE)) {
2419 xfs_off_t end_dmi_offset;
2420
2421 end_dmi_offset = offset+len;
2422 if (end_dmi_offset > ip->i_size)
2423 end_dmi_offset = ip->i_size;
2424 error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, ip, offset,
2425 end_dmi_offset - offset, 0, NULL);
2426 if (error)
2427 return error;
2428 }
2429
2430 /* 2280 /*
2431 * Allocate file space until done or until there is an error 2281 * Allocate file space until done or until there is an error
2432 */ 2282 */
2433retry:
2434 while (allocatesize_fsb && !error) { 2283 while (allocatesize_fsb && !error) {
2435 xfs_fileoff_t s, e; 2284 xfs_fileoff_t s, e;
2436 2285
@@ -2451,15 +2300,22 @@ retry:
2451 e = allocatesize_fsb; 2300 e = allocatesize_fsb;
2452 } 2301 }
2453 2302
2303 /*
2304 * The transaction reservation is limited to a 32-bit block
2305 * count, hence we need to limit the number of blocks we are
2306 * trying to reserve to avoid an overflow. We can't allocate
2307 * more than @nimaps extents, and an extent is limited on disk
2308 * to MAXEXTLEN (21 bits), so use that to enforce the limit.
2309 */
2310 resblks = min_t(xfs_fileoff_t, (e - s), (MAXEXTLEN * nimaps));
2454 if (unlikely(rt)) { 2311 if (unlikely(rt)) {
2455 resrtextents = qblocks = (uint)(e - s); 2312 resrtextents = qblocks = resblks;
2456 resrtextents /= mp->m_sb.sb_rextsize; 2313 resrtextents /= mp->m_sb.sb_rextsize;
2457 resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0); 2314 resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
2458 quota_flag = XFS_QMOPT_RES_RTBLKS; 2315 quota_flag = XFS_QMOPT_RES_RTBLKS;
2459 } else { 2316 } else {
2460 resrtextents = 0; 2317 resrtextents = 0;
2461 resblks = qblocks = \ 2318 resblks = qblocks = XFS_DIOSTRAT_SPACE_RES(mp, resblks);
2462 XFS_DIOSTRAT_SPACE_RES(mp, (uint)(e - s));
2463 quota_flag = XFS_QMOPT_RES_REGBLKS; 2319 quota_flag = XFS_QMOPT_RES_REGBLKS;
2464 } 2320 }
2465 2321
@@ -2488,8 +2344,7 @@ retry:
2488 if (error) 2344 if (error)
2489 goto error1; 2345 goto error1;
2490 2346
2491 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 2347 xfs_trans_ijoin(tp, ip);
2492 xfs_trans_ihold(tp, ip);
2493 2348
2494 /* 2349 /*
2495 * Issue the xfs_bmapi() call to allocate the blocks 2350 * Issue the xfs_bmapi() call to allocate the blocks
@@ -2498,7 +2353,7 @@ retry:
2498 error = xfs_bmapi(tp, ip, startoffset_fsb, 2353 error = xfs_bmapi(tp, ip, startoffset_fsb,
2499 allocatesize_fsb, bmapi_flag, 2354 allocatesize_fsb, bmapi_flag,
2500 &firstfsb, 0, imapp, &nimaps, 2355 &firstfsb, 0, imapp, &nimaps,
2501 &free_list, NULL); 2356 &free_list);
2502 if (error) { 2357 if (error) {
2503 goto error0; 2358 goto error0;
2504 } 2359 }
@@ -2527,17 +2382,6 @@ retry:
2527 startoffset_fsb += allocated_fsb; 2382 startoffset_fsb += allocated_fsb;
2528 allocatesize_fsb -= allocated_fsb; 2383 allocatesize_fsb -= allocated_fsb;
2529 } 2384 }
2530dmapi_enospc_check:
2531 if (error == ENOSPC && (attr_flags & XFS_ATTR_DMI) == 0 &&
2532 DM_EVENT_ENABLED(ip, DM_EVENT_NOSPACE)) {
2533 error = XFS_SEND_NAMESP(mp, DM_EVENT_NOSPACE,
2534 ip, DM_RIGHT_NULL,
2535 ip, DM_RIGHT_NULL,
2536 NULL, NULL, 0, 0, 0); /* Delay flag intentionally unused */
2537 if (error == 0)
2538 goto retry; /* Maybe DMAPI app. has made space */
2539 /* else fall through with error from XFS_SEND_DATA */
2540 }
2541 2385
2542 return error; 2386 return error;
2543 2387
@@ -2548,7 +2392,7 @@ error0: /* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */
2548error1: /* Just cancel transaction */ 2392error1: /* Just cancel transaction */
2549 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT); 2393 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
2550 xfs_iunlock(ip, XFS_ILOCK_EXCL); 2394 xfs_iunlock(ip, XFS_ILOCK_EXCL);
2551 goto dmapi_enospc_check; 2395 return error;
2552} 2396}
2553 2397
2554/* 2398/*
@@ -2588,9 +2432,9 @@ xfs_zero_remaining_bytes(
2588 if (endoff > ip->i_size) 2432 if (endoff > ip->i_size)
2589 endoff = ip->i_size; 2433 endoff = ip->i_size;
2590 2434
2591 bp = xfs_buf_get_noaddr(mp->m_sb.sb_blocksize, 2435 bp = xfs_buf_get_uncached(XFS_IS_REALTIME_INODE(ip) ?
2592 XFS_IS_REALTIME_INODE(ip) ? 2436 mp->m_rtdev_targp : mp->m_ddev_targp,
2593 mp->m_rtdev_targp : mp->m_ddev_targp); 2437 mp->m_sb.sb_blocksize, XBF_DONT_BLOCK);
2594 if (!bp) 2438 if (!bp)
2595 return XFS_ERROR(ENOMEM); 2439 return XFS_ERROR(ENOMEM);
2596 2440
@@ -2598,7 +2442,7 @@ xfs_zero_remaining_bytes(
2598 offset_fsb = XFS_B_TO_FSBT(mp, offset); 2442 offset_fsb = XFS_B_TO_FSBT(mp, offset);
2599 nimap = 1; 2443 nimap = 1;
2600 error = xfs_bmapi(NULL, ip, offset_fsb, 1, 0, 2444 error = xfs_bmapi(NULL, ip, offset_fsb, 1, 0,
2601 NULL, 0, &imap, &nimap, NULL, NULL); 2445 NULL, 0, &imap, &nimap, NULL);
2602 if (error || nimap < 1) 2446 if (error || nimap < 1)
2603 break; 2447 break;
2604 ASSERT(imap.br_blockcount >= 1); 2448 ASSERT(imap.br_blockcount >= 1);
@@ -2616,7 +2460,7 @@ xfs_zero_remaining_bytes(
2616 XFS_BUF_READ(bp); 2460 XFS_BUF_READ(bp);
2617 XFS_BUF_SET_ADDR(bp, xfs_fsb_to_db(ip, imap.br_startblock)); 2461 XFS_BUF_SET_ADDR(bp, xfs_fsb_to_db(ip, imap.br_startblock));
2618 xfsbdstrat(mp, bp); 2462 xfsbdstrat(mp, bp);
2619 error = xfs_iowait(bp); 2463 error = xfs_buf_iowait(bp);
2620 if (error) { 2464 if (error) {
2621 xfs_ioerror_alert("xfs_zero_remaining_bytes(read)", 2465 xfs_ioerror_alert("xfs_zero_remaining_bytes(read)",
2622 mp, bp, XFS_BUF_ADDR(bp)); 2466 mp, bp, XFS_BUF_ADDR(bp));
@@ -2629,7 +2473,7 @@ xfs_zero_remaining_bytes(
2629 XFS_BUF_UNREAD(bp); 2473 XFS_BUF_UNREAD(bp);
2630 XFS_BUF_WRITE(bp); 2474 XFS_BUF_WRITE(bp);
2631 xfsbdstrat(mp, bp); 2475 xfsbdstrat(mp, bp);
2632 error = xfs_iowait(bp); 2476 error = xfs_buf_iowait(bp);
2633 if (error) { 2477 if (error) {
2634 xfs_ioerror_alert("xfs_zero_remaining_bytes(write)", 2478 xfs_ioerror_alert("xfs_zero_remaining_bytes(write)",
2635 mp, bp, XFS_BUF_ADDR(bp)); 2479 mp, bp, XFS_BUF_ADDR(bp));
@@ -2661,7 +2505,6 @@ xfs_free_file_space(
2661{ 2505{
2662 int committed; 2506 int committed;
2663 int done; 2507 int done;
2664 xfs_off_t end_dmi_offset;
2665 xfs_fileoff_t endoffset_fsb; 2508 xfs_fileoff_t endoffset_fsb;
2666 int error; 2509 int error;
2667 xfs_fsblock_t firstfsb; 2510 xfs_fsblock_t firstfsb;
@@ -2680,7 +2523,7 @@ xfs_free_file_space(
2680 2523
2681 mp = ip->i_mount; 2524 mp = ip->i_mount;
2682 2525
2683 xfs_itrace_entry(ip); 2526 trace_xfs_free_file_space(ip);
2684 2527
2685 error = xfs_qm_dqattach(ip, 0); 2528 error = xfs_qm_dqattach(ip, 0);
2686 if (error) 2529 if (error)
@@ -2691,19 +2534,7 @@ xfs_free_file_space(
2691 return error; 2534 return error;
2692 rt = XFS_IS_REALTIME_INODE(ip); 2535 rt = XFS_IS_REALTIME_INODE(ip);
2693 startoffset_fsb = XFS_B_TO_FSB(mp, offset); 2536 startoffset_fsb = XFS_B_TO_FSB(mp, offset);
2694 end_dmi_offset = offset + len; 2537 endoffset_fsb = XFS_B_TO_FSBT(mp, offset + len);
2695 endoffset_fsb = XFS_B_TO_FSBT(mp, end_dmi_offset);
2696
2697 if (offset < ip->i_size && (attr_flags & XFS_ATTR_DMI) == 0 &&
2698 DM_EVENT_ENABLED(ip, DM_EVENT_WRITE)) {
2699 if (end_dmi_offset > ip->i_size)
2700 end_dmi_offset = ip->i_size;
2701 error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, ip,
2702 offset, end_dmi_offset - offset,
2703 AT_DELAY_FLAG(attr_flags), NULL);
2704 if (error)
2705 return error;
2706 }
2707 2538
2708 if (attr_flags & XFS_ATTR_NOLOCK) 2539 if (attr_flags & XFS_ATTR_NOLOCK)
2709 need_iolock = 0; 2540 need_iolock = 0;
@@ -2731,7 +2562,7 @@ xfs_free_file_space(
2731 if (rt && !xfs_sb_version_hasextflgbit(&mp->m_sb)) { 2562 if (rt && !xfs_sb_version_hasextflgbit(&mp->m_sb)) {
2732 nimap = 1; 2563 nimap = 1;
2733 error = xfs_bmapi(NULL, ip, startoffset_fsb, 2564 error = xfs_bmapi(NULL, ip, startoffset_fsb,
2734 1, 0, NULL, 0, &imap, &nimap, NULL, NULL); 2565 1, 0, NULL, 0, &imap, &nimap, NULL);
2735 if (error) 2566 if (error)
2736 goto out_unlock_iolock; 2567 goto out_unlock_iolock;
2737 ASSERT(nimap == 0 || nimap == 1); 2568 ASSERT(nimap == 0 || nimap == 1);
@@ -2746,7 +2577,7 @@ xfs_free_file_space(
2746 } 2577 }
2747 nimap = 1; 2578 nimap = 1;
2748 error = xfs_bmapi(NULL, ip, endoffset_fsb - 1, 2579 error = xfs_bmapi(NULL, ip, endoffset_fsb - 1,
2749 1, 0, NULL, 0, &imap, &nimap, NULL, NULL); 2580 1, 0, NULL, 0, &imap, &nimap, NULL);
2750 if (error) 2581 if (error)
2751 goto out_unlock_iolock; 2582 goto out_unlock_iolock;
2752 ASSERT(nimap == 0 || nimap == 1); 2583 ASSERT(nimap == 0 || nimap == 1);
@@ -2814,8 +2645,7 @@ xfs_free_file_space(
2814 if (error) 2645 if (error)
2815 goto error1; 2646 goto error1;
2816 2647
2817 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 2648 xfs_trans_ijoin(tp, ip);
2818 xfs_trans_ihold(tp, ip);
2819 2649
2820 /* 2650 /*
2821 * issue the bunmapi() call to free the blocks 2651 * issue the bunmapi() call to free the blocks
@@ -2823,7 +2653,7 @@ xfs_free_file_space(
2823 xfs_bmap_init(&free_list, &firstfsb); 2653 xfs_bmap_init(&free_list, &firstfsb);
2824 error = xfs_bunmapi(tp, ip, startoffset_fsb, 2654 error = xfs_bunmapi(tp, ip, startoffset_fsb,
2825 endoffset_fsb - startoffset_fsb, 2655 endoffset_fsb - startoffset_fsb,
2826 0, 2, &firstfsb, &free_list, NULL, &done); 2656 0, 2, &firstfsb, &free_list, &done);
2827 if (error) { 2657 if (error) {
2828 goto error0; 2658 goto error0;
2829 } 2659 }
@@ -2882,8 +2712,7 @@ xfs_change_file_space(
2882 xfs_off_t llen; 2712 xfs_off_t llen;
2883 xfs_trans_t *tp; 2713 xfs_trans_t *tp;
2884 struct iattr iattr; 2714 struct iattr iattr;
2885 2715 int prealloc_type;
2886 xfs_itrace_entry(ip);
2887 2716
2888 if (!S_ISREG(ip->i_d.di_mode)) 2717 if (!S_ISREG(ip->i_d.di_mode))
2889 return XFS_ERROR(EINVAL); 2718 return XFS_ERROR(EINVAL);
@@ -2926,12 +2755,17 @@ xfs_change_file_space(
2926 * size to be changed. 2755 * size to be changed.
2927 */ 2756 */
2928 setprealloc = clrprealloc = 0; 2757 setprealloc = clrprealloc = 0;
2758 prealloc_type = XFS_BMAPI_PREALLOC;
2929 2759
2930 switch (cmd) { 2760 switch (cmd) {
2761 case XFS_IOC_ZERO_RANGE:
2762 prealloc_type |= XFS_BMAPI_CONVERT;
2763 xfs_tosspages(ip, startoffset, startoffset + bf->l_len, 0);
2764 /* FALLTHRU */
2931 case XFS_IOC_RESVSP: 2765 case XFS_IOC_RESVSP:
2932 case XFS_IOC_RESVSP64: 2766 case XFS_IOC_RESVSP64:
2933 error = xfs_alloc_file_space(ip, startoffset, bf->l_len, 2767 error = xfs_alloc_file_space(ip, startoffset, bf->l_len,
2934 1, attr_flags); 2768 prealloc_type, attr_flags);
2935 if (error) 2769 if (error)
2936 return error; 2770 return error;
2937 setprealloc = 1; 2771 setprealloc = 1;
@@ -2985,8 +2819,7 @@ xfs_change_file_space(
2985 2819
2986 xfs_ilock(ip, XFS_ILOCK_EXCL); 2820 xfs_ilock(ip, XFS_ILOCK_EXCL);
2987 2821
2988 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 2822 xfs_trans_ijoin(tp, ip);
2989 xfs_trans_ihold(tp, ip);
2990 2823
2991 if ((attr_flags & XFS_ATTR_DMI) == 0) { 2824 if ((attr_flags & XFS_ATTR_DMI) == 0) {
2992 ip->i_d.di_mode &= ~S_ISUID; 2825 ip->i_d.di_mode &= ~S_ISUID;
@@ -3001,7 +2834,7 @@ xfs_change_file_space(
3001 if (ip->i_d.di_mode & S_IXGRP) 2834 if (ip->i_d.di_mode & S_IXGRP)
3002 ip->i_d.di_mode &= ~S_ISGID; 2835 ip->i_d.di_mode &= ~S_ISGID;
3003 2836
3004 xfs_ichgtime(ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); 2837 xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
3005 } 2838 }
3006 if (setprealloc) 2839 if (setprealloc)
3007 ip->i_d.di_flags |= XFS_DIFLAG_PREALLOC; 2840 ip->i_d.di_flags |= XFS_DIFLAG_PREALLOC;