2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "xfs_types.h"
25 #include "xfs_trans.h"
29 #include "xfs_dmapi.h"
30 #include "xfs_mount.h"
31 #include "xfs_da_btree.h"
32 #include "xfs_bmap_btree.h"
33 #include "xfs_alloc_btree.h"
34 #include "xfs_ialloc_btree.h"
35 #include "xfs_dir2_sf.h"
36 #include "xfs_attr_sf.h"
37 #include "xfs_dinode.h"
38 #include "xfs_inode.h"
39 #include "xfs_inode_item.h"
40 #include "xfs_itable.h"
41 #include "xfs_btree.h"
42 #include "xfs_ialloc.h"
43 #include "xfs_alloc.h"
48 #include "xfs_error.h"
49 #include "xfs_quota.h"
50 #include "xfs_utils.h"
51 #include "xfs_rtalloc.h"
52 #include "xfs_trans_space.h"
53 #include "xfs_log_priv.h"
54 #include "xfs_filestream.h"
55 #include "xfs_vnodeops.h"
56 #include "xfs_trace.h"
64 xfs_mount_t
*mp
= ip
->i_mount
;
65 struct inode
*inode
= VFS_I(ip
);
66 int mask
= iattr
->ia_valid
;
73 struct xfs_dquot
*udqp
, *gdqp
, *olddquot1
, *olddquot2
;
78 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
79 return XFS_ERROR(EROFS
);
81 if (XFS_FORCED_SHUTDOWN(mp
))
82 return XFS_ERROR(EIO
);
84 code
= -inode_change_ok(inode
, iattr
);
88 olddquot1
= olddquot2
= NULL
;
92 * If disk quotas is on, we make sure that the dquots do exist on disk,
93 * before we start any other transactions. Trying to do this later
94 * is messy. We don't care to take a readlock to look at the ids
95 * in inode here, because we can't hold it across the trans_reserve.
96 * If the IDs do change before we take the ilock, we're covered
97 * because the i_*dquot fields will get updated anyway.
99 if (XFS_IS_QUOTA_ON(mp
) && (mask
& (ATTR_UID
|ATTR_GID
))) {
102 if ((mask
& ATTR_UID
) && XFS_IS_UQUOTA_ON(mp
)) {
104 qflags
|= XFS_QMOPT_UQUOTA
;
106 uid
= ip
->i_d
.di_uid
;
108 if ((mask
& ATTR_GID
) && XFS_IS_GQUOTA_ON(mp
)) {
110 qflags
|= XFS_QMOPT_GQUOTA
;
112 gid
= ip
->i_d
.di_gid
;
116 * We take a reference when we initialize udqp and gdqp,
117 * so it is important that we never blindly double trip on
118 * the same variable. See xfs_create() for an example.
120 ASSERT(udqp
== NULL
);
121 ASSERT(gdqp
== NULL
);
122 code
= xfs_qm_vop_dqalloc(ip
, uid
, gid
, ip
->i_d
.di_projid
,
123 qflags
, &udqp
, &gdqp
);
129 * For the other attributes, we acquire the inode lock and
130 * first do an error checking pass.
133 lock_flags
= XFS_ILOCK_EXCL
;
134 if (flags
& XFS_ATTR_NOLOCK
)
136 if (!(mask
& ATTR_SIZE
)) {
137 tp
= xfs_trans_alloc(mp
, XFS_TRANS_SETATTR_NOT_SIZE
);
139 code
= xfs_trans_reserve(tp
, 0, XFS_ICHANGE_LOG_RES(mp
),
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
);
157 lock_flags
|= XFS_IOLOCK_EXCL
;
160 xfs_ilock(ip
, lock_flags
);
163 * Change file ownership. Must be the owner or privileged.
165 if (mask
& (ATTR_UID
|ATTR_GID
)) {
167 * These IDs could have changed since we last looked at them.
168 * But, we're assured that if the ownership did change
169 * while we didn't have the inode locked, inode's dquot(s)
170 * would have changed also.
172 iuid
= ip
->i_d
.di_uid
;
173 igid
= ip
->i_d
.di_gid
;
174 gid
= (mask
& ATTR_GID
) ? iattr
->ia_gid
: igid
;
175 uid
= (mask
& ATTR_UID
) ? iattr
->ia_uid
: iuid
;
178 * Do a quota reservation only if uid/gid is actually
181 if (XFS_IS_QUOTA_RUNNING(mp
) &&
182 ((XFS_IS_UQUOTA_ON(mp
) && iuid
!= uid
) ||
183 (XFS_IS_GQUOTA_ON(mp
) && igid
!= gid
))) {
185 code
= xfs_qm_vop_chown_reserve(tp
, ip
, udqp
, gdqp
,
186 capable(CAP_FOWNER
) ?
187 XFS_QMOPT_FORCE_RES
: 0);
188 if (code
) /* out of quota */
194 * Truncate file. Must have write permission and not be a directory.
196 if (mask
& ATTR_SIZE
) {
197 /* Short circuit the truncate case for zero length files */
198 if (iattr
->ia_size
== 0 &&
199 ip
->i_size
== 0 && ip
->i_d
.di_nextents
== 0) {
200 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
201 lock_flags
&= ~XFS_ILOCK_EXCL
;
202 if (mask
& ATTR_CTIME
)
203 xfs_ichgtime(ip
, XFS_ICHGTIME_MOD
| XFS_ICHGTIME_CHG
);
208 if (S_ISDIR(ip
->i_d
.di_mode
)) {
209 code
= XFS_ERROR(EISDIR
);
211 } else if (!S_ISREG(ip
->i_d
.di_mode
)) {
212 code
= XFS_ERROR(EINVAL
);
217 * Make sure that the dquots are attached to the inode.
219 code
= xfs_qm_dqattach_locked(ip
, 0);
224 * Now we can make the changes. Before we join the inode
225 * to the transaction, if ATTR_SIZE is set then take care of
226 * the part of the truncation that must be done without the
227 * inode lock. This needs to be done before joining the inode
228 * to the transaction, because the inode cannot be unlocked
229 * once it is a part of the transaction.
231 if (iattr
->ia_size
> ip
->i_size
) {
233 * Do the first part of growing a file: zero any data
234 * in the last block that is beyond the old EOF. We
235 * need to do this before the inode is joined to the
236 * transaction to modify the i_size.
238 code
= xfs_zero_eof(ip
, iattr
->ia_size
, ip
->i_size
);
240 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
243 * We are going to log the inode size change in this
244 * transaction so any previous writes that are beyond the on
245 * disk EOF and the new EOF that have not been written out need
246 * to be written here. If we do not write the data out, we
247 * expose ourselves to the null files problem.
249 * Only flush from the on disk size to the smaller of the in
250 * memory file size or the new size as that's the range we
251 * really care about here and prevents waiting for other data
252 * not within the range we care about here.
255 ip
->i_size
!= ip
->i_d
.di_size
&&
256 iattr
->ia_size
> ip
->i_d
.di_size
) {
257 code
= xfs_flush_pages(ip
,
258 ip
->i_d
.di_size
, iattr
->ia_size
,
259 XFS_B_ASYNC
, FI_NONE
);
262 /* wait for all I/O to complete */
266 code
= xfs_itruncate_data(ip
, iattr
->ia_size
);
269 lock_flags
&= ~XFS_ILOCK_EXCL
;
270 ASSERT(lock_flags
== XFS_IOLOCK_EXCL
);
273 tp
= xfs_trans_alloc(mp
, XFS_TRANS_SETATTR_SIZE
);
274 if ((code
= xfs_trans_reserve(tp
, 0,
275 XFS_ITRUNCATE_LOG_RES(mp
), 0,
276 XFS_TRANS_PERM_LOG_RES
,
277 XFS_ITRUNCATE_LOG_COUNT
))) {
278 xfs_trans_cancel(tp
, 0);
280 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
);
283 commit_flags
= XFS_TRANS_RELEASE_LOG_RES
;
284 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
286 xfs_trans_ijoin(tp
, ip
, lock_flags
);
287 xfs_trans_ihold(tp
, ip
);
290 * Only change the c/mtime if we are changing the size
291 * or we are explicitly asked to change it. This handles
292 * the semantic difference between truncate() and ftruncate()
293 * as implemented in the VFS.
295 * The regular truncate() case without ATTR_CTIME and ATTR_MTIME
296 * is a special case where we need to update the times despite
297 * not having these flags set. For all other operations the
298 * VFS set these flags explicitly if it wants a timestamp
301 if (iattr
->ia_size
!= ip
->i_size
&&
302 (!(mask
& (ATTR_CTIME
| ATTR_MTIME
)))) {
303 iattr
->ia_ctime
= iattr
->ia_mtime
=
304 current_fs_time(inode
->i_sb
);
305 mask
|= ATTR_CTIME
| ATTR_MTIME
;
308 if (iattr
->ia_size
> ip
->i_size
) {
309 ip
->i_d
.di_size
= iattr
->ia_size
;
310 ip
->i_size
= iattr
->ia_size
;
311 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
312 } else if (iattr
->ia_size
<= ip
->i_size
||
313 (iattr
->ia_size
== 0 && ip
->i_d
.di_nextents
)) {
315 * signal a sync transaction unless
316 * we're truncating an already unlinked
317 * file on a wsync filesystem
319 code
= xfs_itruncate_finish(&tp
, ip
, iattr
->ia_size
,
321 ((ip
->i_d
.di_nlink
!= 0 ||
322 !(mp
->m_flags
& XFS_MOUNT_WSYNC
))
327 * Truncated "down", so we're removing references
328 * to old data here - if we now delay flushing for
329 * a long time, we expose ourselves unduly to the
330 * notorious NULL files problem. So, we mark this
331 * vnode and flush it when the file is closed, and
332 * do not wait the usual (long) time for writeout.
334 xfs_iflags_set(ip
, XFS_ITRUNCATED
);
337 xfs_trans_ijoin(tp
, ip
, lock_flags
);
338 xfs_trans_ihold(tp
, ip
);
342 * Change file ownership. Must be the owner or privileged.
344 if (mask
& (ATTR_UID
|ATTR_GID
)) {
346 * CAP_FSETID overrides the following restrictions:
348 * The set-user-ID and set-group-ID bits of a file will be
349 * cleared upon successful return from chown()
351 if ((ip
->i_d
.di_mode
& (S_ISUID
|S_ISGID
)) &&
352 !capable(CAP_FSETID
)) {
353 ip
->i_d
.di_mode
&= ~(S_ISUID
|S_ISGID
);
357 * Change the ownerships and register quota modifications
358 * in the transaction.
361 if (XFS_IS_QUOTA_RUNNING(mp
) && XFS_IS_UQUOTA_ON(mp
)) {
362 ASSERT(mask
& ATTR_UID
);
364 olddquot1
= xfs_qm_vop_chown(tp
, ip
,
365 &ip
->i_udquot
, udqp
);
367 ip
->i_d
.di_uid
= uid
;
371 if (XFS_IS_QUOTA_RUNNING(mp
) && XFS_IS_GQUOTA_ON(mp
)) {
372 ASSERT(!XFS_IS_PQUOTA_ON(mp
));
373 ASSERT(mask
& ATTR_GID
);
375 olddquot2
= xfs_qm_vop_chown(tp
, ip
,
376 &ip
->i_gdquot
, gdqp
);
378 ip
->i_d
.di_gid
= gid
;
384 * Change file access modes.
386 if (mask
& ATTR_MODE
) {
387 umode_t mode
= iattr
->ia_mode
;
389 if (!in_group_p(inode
->i_gid
) && !capable(CAP_FSETID
))
392 ip
->i_d
.di_mode
&= S_IFMT
;
393 ip
->i_d
.di_mode
|= mode
& ~S_IFMT
;
395 inode
->i_mode
&= S_IFMT
;
396 inode
->i_mode
|= mode
& ~S_IFMT
;
400 * Change file access or modified times.
402 if (mask
& ATTR_ATIME
) {
403 inode
->i_atime
= iattr
->ia_atime
;
404 ip
->i_d
.di_atime
.t_sec
= iattr
->ia_atime
.tv_sec
;
405 ip
->i_d
.di_atime
.t_nsec
= iattr
->ia_atime
.tv_nsec
;
406 ip
->i_update_core
= 1;
408 if (mask
& ATTR_CTIME
) {
409 inode
->i_ctime
= iattr
->ia_ctime
;
410 ip
->i_d
.di_ctime
.t_sec
= iattr
->ia_ctime
.tv_sec
;
411 ip
->i_d
.di_ctime
.t_nsec
= iattr
->ia_ctime
.tv_nsec
;
412 ip
->i_update_core
= 1;
414 if (mask
& ATTR_MTIME
) {
415 inode
->i_mtime
= iattr
->ia_mtime
;
416 ip
->i_d
.di_mtime
.t_sec
= iattr
->ia_mtime
.tv_sec
;
417 ip
->i_d
.di_mtime
.t_nsec
= iattr
->ia_mtime
.tv_nsec
;
418 ip
->i_update_core
= 1;
422 * And finally, log the inode core if any attribute in it
425 if (mask
& (ATTR_UID
|ATTR_GID
|ATTR_MODE
|
426 ATTR_ATIME
|ATTR_CTIME
|ATTR_MTIME
))
427 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
429 XFS_STATS_INC(xs_ig_attrchg
);
432 * If this is a synchronous mount, make sure that the
433 * transaction goes to disk before returning to the user.
434 * This is slightly sub-optimal in that truncates require
435 * two sync transactions instead of one for wsync filesystems.
436 * One for the truncate and one for the timestamps since we
437 * don't want to change the timestamps unless we're sure the
438 * truncate worked. Truncates are less than 1% of the laddis
439 * mix so this probably isn't worth the trouble to optimize.
442 if (mp
->m_flags
& XFS_MOUNT_WSYNC
)
443 xfs_trans_set_sync(tp
);
445 code
= xfs_trans_commit(tp
, commit_flags
);
447 xfs_iunlock(ip
, lock_flags
);
450 * Release any dquot(s) the inode had kept before chown.
452 xfs_qm_dqrele(olddquot1
);
453 xfs_qm_dqrele(olddquot2
);
461 * XXX(hch): Updating the ACL entries is not atomic vs the i_mode
462 * update. We could avoid this with linked transactions
463 * and passing down the transaction pointer all the way
464 * to attr_set. No previous user of the generic
465 * Posix ACL code seems to care about this issue either.
467 if ((mask
& ATTR_MODE
) && !(flags
& XFS_ATTR_NOACL
)) {
468 code
= -xfs_acl_chmod(inode
);
470 return XFS_ERROR(code
);
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
));
482 commit_flags
|= XFS_TRANS_ABORT
;
488 xfs_trans_cancel(tp
, commit_flags
);
490 if (lock_flags
!= 0) {
491 xfs_iunlock(ip
, lock_flags
);
497 * The maximum pathlen is 1024 bytes. Since the minimum file system
498 * blocksize is 512 bytes, we can get a max of 2 extents back from
501 #define SYMLINK_MAPS 2
508 xfs_mount_t
*mp
= ip
->i_mount
;
509 int pathlen
= ip
->i_d
.di_size
;
510 int nmaps
= SYMLINK_MAPS
;
511 xfs_bmbt_irec_t mval
[SYMLINK_MAPS
];
518 error
= xfs_bmapi(NULL
, ip
, 0, XFS_B_TO_FSB(mp
, pathlen
), 0, NULL
, 0,
519 mval
, &nmaps
, NULL
, NULL
);
523 for (n
= 0; n
< nmaps
; n
++) {
524 d
= XFS_FSB_TO_DADDR(mp
, mval
[n
].br_startblock
);
525 byte_cnt
= XFS_FSB_TO_B(mp
, mval
[n
].br_blockcount
);
527 bp
= xfs_buf_read(mp
->m_ddev_targp
, d
, BTOBB(byte_cnt
),
528 XBF_LOCK
| XBF_MAPPED
| XBF_DONT_BLOCK
);
529 error
= XFS_BUF_GETERROR(bp
);
531 xfs_ioerror_alert("xfs_readlink",
532 ip
->i_mount
, bp
, XFS_BUF_ADDR(bp
));
536 if (pathlen
< byte_cnt
)
540 memcpy(link
, XFS_BUF_PTR(bp
), byte_cnt
);
544 link
[ip
->i_d
.di_size
] = '\0';
556 xfs_mount_t
*mp
= ip
->i_mount
;
560 xfs_itrace_entry(ip
);
562 if (XFS_FORCED_SHUTDOWN(mp
))
563 return XFS_ERROR(EIO
);
565 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
567 ASSERT((ip
->i_d
.di_mode
& S_IFMT
) == S_IFLNK
);
568 ASSERT(ip
->i_d
.di_size
<= MAXPATHLEN
);
570 pathlen
= ip
->i_d
.di_size
;
574 if (ip
->i_df
.if_flags
& XFS_IFINLINE
) {
575 memcpy(link
, ip
->i_df
.if_u1
.if_data
, pathlen
);
576 link
[pathlen
] = '\0';
578 error
= xfs_readlink_bmap(ip
, link
);
582 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
589 * This is called to sync the inode and its data out to disk. We need to hold
590 * the I/O lock while flushing the data, and the inode lock while flushing the
591 * inode. The inode lock CANNOT be held while flushing the data, so acquire
592 * after we're done with that.
600 int log_flushed
= 0, changed
= 1;
602 xfs_itrace_entry(ip
);
604 if (XFS_FORCED_SHUTDOWN(ip
->i_mount
))
605 return XFS_ERROR(EIO
);
608 * We always need to make sure that the required inode state is safe on
609 * disk. The inode might be clean but we still might need to force the
610 * log because of committed transactions that haven't hit the disk yet.
611 * Likewise, there could be unflushed non-transactional changes to the
612 * inode core that have to go to disk and this requires us to issue
613 * a synchronous transaction to capture these changes correctly.
615 * This code relies on the assumption that if the update_* fields
616 * of the inode are clear and the inode is unpinned then it is clean
617 * and no action is required.
619 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
621 if (!ip
->i_update_core
) {
623 * Timestamps/size haven't changed since last inode flush or
624 * inode transaction commit. That means either nothing got
625 * written or a transaction committed which caught the updates.
626 * If the latter happened and the transaction hasn't hit the
627 * disk yet, the inode will be still be pinned. If it is,
631 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
633 if (xfs_ipincount(ip
)) {
634 error
= _xfs_log_force(ip
->i_mount
, (xfs_lsn_t
)0,
635 XFS_LOG_FORCE
| XFS_LOG_SYNC
,
639 * If the inode is not pinned and nothing has changed
640 * we don't need to flush the cache.
646 * Kick off a transaction to log the inode core to get the
647 * updates. The sync transaction will also force the log.
649 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
650 tp
= xfs_trans_alloc(ip
->i_mount
, XFS_TRANS_FSYNC_TS
);
651 error
= xfs_trans_reserve(tp
, 0,
652 XFS_FSYNC_TS_LOG_RES(ip
->i_mount
), 0, 0, 0);
654 xfs_trans_cancel(tp
, 0);
657 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
660 * Note - it's possible that we might have pushed ourselves out
661 * of the way during trans_reserve which would flush the inode.
662 * But there's no guarantee that the inode buffer has actually
663 * gone out yet (it's delwri). Plus the buffer could be pinned
664 * anyway if it's part of an inode in another recent
665 * transaction. So we play it safe and fire off the
666 * transaction anyway.
668 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
669 xfs_trans_ihold(tp
, ip
);
670 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
671 xfs_trans_set_sync(tp
);
672 error
= _xfs_trans_commit(tp
, 0, &log_flushed
);
674 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
677 if ((ip
->i_mount
->m_flags
& XFS_MOUNT_BARRIER
) && changed
) {
679 * If the log write didn't issue an ordered tag we need
680 * to flush the disk cache for the data device now.
683 xfs_blkdev_issue_flush(ip
->i_mount
->m_ddev_targp
);
686 * If this inode is on the RT dev we need to flush that
689 if (XFS_IS_REALTIME_INODE(ip
))
690 xfs_blkdev_issue_flush(ip
->i_mount
->m_rtdev_targp
);
697 * Flags for xfs_free_eofblocks
699 #define XFS_FREE_EOF_TRYLOCK (1<<0)
702 * This is called by xfs_inactive to free any blocks beyond eof
703 * when the link count isn't zero and by xfs_dm_punch_hole() when
704 * punching a hole to EOF.
714 xfs_fileoff_t end_fsb
;
715 xfs_fileoff_t last_fsb
;
716 xfs_filblks_t map_len
;
718 xfs_bmbt_irec_t imap
;
721 * Figure out if there are any blocks beyond the end
722 * of the file. If not, then there is nothing to do.
724 end_fsb
= XFS_B_TO_FSB(mp
, ((xfs_ufsize_t
)ip
->i_size
));
725 last_fsb
= XFS_B_TO_FSB(mp
, (xfs_ufsize_t
)XFS_MAXIOFFSET(mp
));
726 map_len
= last_fsb
- end_fsb
;
731 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
732 error
= xfs_bmapi(NULL
, ip
, end_fsb
, map_len
, 0,
733 NULL
, 0, &imap
, &nimaps
, NULL
, NULL
);
734 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
736 if (!error
&& (nimaps
!= 0) &&
737 (imap
.br_startblock
!= HOLESTARTBLOCK
||
738 ip
->i_delayed_blks
)) {
740 * Attach the dquots to the inode up front.
742 error
= xfs_qm_dqattach(ip
, 0);
747 * There are blocks after the end of file.
748 * Free them up now by truncating the file to
751 tp
= xfs_trans_alloc(mp
, XFS_TRANS_INACTIVE
);
754 * Do the xfs_itruncate_start() call before
755 * reserving any log space because
756 * itruncate_start will call into the buffer
758 * do that within a transaction.
760 if (flags
& XFS_FREE_EOF_TRYLOCK
) {
761 if (!xfs_ilock_nowait(ip
, XFS_IOLOCK_EXCL
)) {
762 xfs_trans_cancel(tp
, 0);
766 xfs_ilock(ip
, XFS_IOLOCK_EXCL
);
768 error
= xfs_itruncate_start(ip
, XFS_ITRUNC_DEFINITE
,
771 xfs_trans_cancel(tp
, 0);
772 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
);
776 error
= xfs_trans_reserve(tp
, 0,
777 XFS_ITRUNCATE_LOG_RES(mp
),
778 0, XFS_TRANS_PERM_LOG_RES
,
779 XFS_ITRUNCATE_LOG_COUNT
);
781 ASSERT(XFS_FORCED_SHUTDOWN(mp
));
782 xfs_trans_cancel(tp
, 0);
783 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
);
787 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
788 xfs_trans_ijoin(tp
, ip
,
791 xfs_trans_ihold(tp
, ip
);
793 error
= xfs_itruncate_finish(&tp
, ip
,
798 * If we get an error at this point we
799 * simply don't bother truncating the file.
803 (XFS_TRANS_RELEASE_LOG_RES
|
806 error
= xfs_trans_commit(tp
,
807 XFS_TRANS_RELEASE_LOG_RES
);
809 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
|XFS_ILOCK_EXCL
);
815 * Free a symlink that has blocks associated with it.
818 xfs_inactive_symlink_rmt(
826 xfs_fsblock_t first_block
;
827 xfs_bmap_free_t free_list
;
830 xfs_bmbt_irec_t mval
[SYMLINK_MAPS
];
838 ASSERT(ip
->i_d
.di_size
> XFS_IFORK_DSIZE(ip
));
840 * We're freeing a symlink that has some
841 * blocks allocated to it. Free the
842 * blocks here. We know that we've got
843 * either 1 or 2 extents and that we can
844 * free them all in one bunmapi call.
846 ASSERT(ip
->i_d
.di_nextents
> 0 && ip
->i_d
.di_nextents
<= 2);
847 if ((error
= xfs_trans_reserve(tp
, 0, XFS_ITRUNCATE_LOG_RES(mp
), 0,
848 XFS_TRANS_PERM_LOG_RES
, XFS_ITRUNCATE_LOG_COUNT
))) {
849 ASSERT(XFS_FORCED_SHUTDOWN(mp
));
850 xfs_trans_cancel(tp
, 0);
855 * Lock the inode, fix the size, and join it to the transaction.
856 * Hold it so in the normal path, we still have it locked for
857 * the second transaction. In the error paths we need it
858 * held so the cancel won't rele it, see below.
860 xfs_ilock(ip
, XFS_IOLOCK_EXCL
| XFS_ILOCK_EXCL
);
861 size
= (int)ip
->i_d
.di_size
;
863 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
| XFS_IOLOCK_EXCL
);
864 xfs_trans_ihold(tp
, ip
);
865 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
867 * Find the block(s) so we can inval and unmap them.
870 xfs_bmap_init(&free_list
, &first_block
);
871 nmaps
= ARRAY_SIZE(mval
);
872 if ((error
= xfs_bmapi(tp
, ip
, 0, XFS_B_TO_FSB(mp
, size
),
873 XFS_BMAPI_METADATA
, &first_block
, 0, mval
, &nmaps
,
877 * Invalidate the block(s).
879 for (i
= 0; i
< nmaps
; i
++) {
880 bp
= xfs_trans_get_buf(tp
, mp
->m_ddev_targp
,
881 XFS_FSB_TO_DADDR(mp
, mval
[i
].br_startblock
),
882 XFS_FSB_TO_BB(mp
, mval
[i
].br_blockcount
), 0);
883 xfs_trans_binval(tp
, bp
);
886 * Unmap the dead block(s) to the free_list.
888 if ((error
= xfs_bunmapi(tp
, ip
, 0, size
, XFS_BMAPI_METADATA
, nmaps
,
889 &first_block
, &free_list
, NULL
, &done
)))
893 * Commit the first transaction. This logs the EFI and the inode.
895 if ((error
= xfs_bmap_finish(&tp
, &free_list
, &committed
)))
898 * The transaction must have been committed, since there were
899 * actually extents freed by xfs_bunmapi. See xfs_bmap_finish.
900 * The new tp has the extent freeing and EFDs.
904 * The first xact was committed, so add the inode to the new one.
905 * Mark it dirty so it will be logged and moved forward in the log as
906 * part of every commit.
908 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
| XFS_IOLOCK_EXCL
);
909 xfs_trans_ihold(tp
, ip
);
910 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
912 * Get a new, empty transaction to return to our caller.
914 ntp
= xfs_trans_dup(tp
);
916 * Commit the transaction containing extent freeing and EFDs.
917 * If we get an error on the commit here or on the reserve below,
918 * we need to unlock the inode since the new transaction doesn't
919 * have the inode attached.
921 error
= xfs_trans_commit(tp
, 0);
924 ASSERT(XFS_FORCED_SHUTDOWN(mp
));
928 * transaction commit worked ok so we can drop the extra ticket
929 * reference that we gained in xfs_trans_dup()
931 xfs_log_ticket_put(tp
->t_ticket
);
934 * Remove the memory for extent descriptions (just bookkeeping).
936 if (ip
->i_df
.if_bytes
)
937 xfs_idata_realloc(ip
, -ip
->i_df
.if_bytes
, XFS_DATA_FORK
);
938 ASSERT(ip
->i_df
.if_bytes
== 0);
940 * Put an itruncate log reservation in the new transaction
943 if ((error
= xfs_trans_reserve(tp
, 0, XFS_ITRUNCATE_LOG_RES(mp
), 0,
944 XFS_TRANS_PERM_LOG_RES
, XFS_ITRUNCATE_LOG_COUNT
))) {
945 ASSERT(XFS_FORCED_SHUTDOWN(mp
));
949 * Return with the inode locked but not joined to the transaction.
955 xfs_bmap_cancel(&free_list
);
958 * Have to come here with the inode locked and either
959 * (held and in the transaction) or (not in the transaction).
960 * If the inode isn't held then cancel would iput it, but
961 * that's wrong since this is inactive and the vnode ref
962 * count is 0 already.
963 * Cancel won't do anything to the inode if held, but it still
964 * needs to be locked until the cancel is done, if it was
965 * joined to the transaction.
967 xfs_trans_cancel(tp
, XFS_TRANS_RELEASE_LOG_RES
| XFS_TRANS_ABORT
);
968 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
| XFS_ILOCK_EXCL
);
975 xfs_inactive_symlink_local(
981 ASSERT(ip
->i_d
.di_size
<= XFS_IFORK_DSIZE(ip
));
983 * We're freeing a symlink which fit into
984 * the inode. Just free the memory used
985 * to hold the old symlink.
987 error
= xfs_trans_reserve(*tpp
, 0,
988 XFS_ITRUNCATE_LOG_RES(ip
->i_mount
),
989 0, XFS_TRANS_PERM_LOG_RES
,
990 XFS_ITRUNCATE_LOG_COUNT
);
993 xfs_trans_cancel(*tpp
, 0);
997 xfs_ilock(ip
, XFS_ILOCK_EXCL
| XFS_IOLOCK_EXCL
);
1000 * Zero length symlinks _can_ exist.
1002 if (ip
->i_df
.if_bytes
> 0) {
1003 xfs_idata_realloc(ip
,
1004 -(ip
->i_df
.if_bytes
),
1006 ASSERT(ip
->i_df
.if_bytes
== 0);
1020 ASSERT(xfs_isilocked(ip
, XFS_IOLOCK_EXCL
));
1023 ASSERT(ip
->i_d
.di_forkoff
!= 0);
1024 error
= xfs_trans_commit(tp
, XFS_TRANS_RELEASE_LOG_RES
);
1025 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1029 error
= xfs_attr_inactive(ip
);
1033 tp
= xfs_trans_alloc(mp
, XFS_TRANS_INACTIVE
);
1034 error
= xfs_trans_reserve(tp
, 0,
1035 XFS_IFREE_LOG_RES(mp
),
1036 0, XFS_TRANS_PERM_LOG_RES
,
1037 XFS_INACTIVE_LOG_COUNT
);
1041 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
1042 xfs_trans_ijoin(tp
, ip
, XFS_IOLOCK_EXCL
| XFS_ILOCK_EXCL
);
1043 xfs_trans_ihold(tp
, ip
);
1044 xfs_idestroy_fork(ip
, XFS_ATTR_FORK
);
1046 ASSERT(ip
->i_d
.di_anextents
== 0);
1052 ASSERT(XFS_FORCED_SHUTDOWN(mp
));
1053 xfs_trans_cancel(tp
, 0);
1056 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
);
1064 xfs_mount_t
*mp
= ip
->i_mount
;
1067 if (!S_ISREG(ip
->i_d
.di_mode
) || (ip
->i_d
.di_mode
== 0))
1070 /* If this is a read-only mount, don't do this (would generate I/O) */
1071 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
1074 if (!XFS_FORCED_SHUTDOWN(mp
)) {
1078 * If we are using filestreams, and we have an unlinked
1079 * file that we are processing the last close on, then nothing
1080 * will be able to reopen and write to this file. Purge this
1081 * inode from the filestreams cache so that it doesn't delay
1082 * teardown of the inode.
1084 if ((ip
->i_d
.di_nlink
== 0) && xfs_inode_is_filestream(ip
))
1085 xfs_filestream_deassociate(ip
);
1088 * If we previously truncated this file and removed old data
1089 * in the process, we want to initiate "early" writeout on
1090 * the last close. This is an attempt to combat the notorious
1091 * NULL files problem which is particularly noticable from a
1092 * truncate down, buffered (re-)write (delalloc), followed by
1093 * a crash. What we are effectively doing here is
1094 * significantly reducing the time window where we'd otherwise
1095 * be exposed to that problem.
1097 truncated
= xfs_iflags_test_and_clear(ip
, XFS_ITRUNCATED
);
1098 if (truncated
&& VN_DIRTY(VFS_I(ip
)) && ip
->i_delayed_blks
> 0)
1099 xfs_flush_pages(ip
, 0, -1, XFS_B_ASYNC
, FI_NONE
);
1102 if (ip
->i_d
.di_nlink
!= 0) {
1103 if ((((ip
->i_d
.di_mode
& S_IFMT
) == S_IFREG
) &&
1104 ((ip
->i_size
> 0) || (VN_CACHED(VFS_I(ip
)) > 0 ||
1105 ip
->i_delayed_blks
> 0)) &&
1106 (ip
->i_df
.if_flags
& XFS_IFEXTENTS
)) &&
1107 (!(ip
->i_d
.di_flags
&
1108 (XFS_DIFLAG_PREALLOC
| XFS_DIFLAG_APPEND
)))) {
1111 * If we can't get the iolock just skip truncating
1112 * the blocks past EOF because we could deadlock
1113 * with the mmap_sem otherwise. We'll get another
1114 * chance to drop them once the last reference to
1115 * the inode is dropped, so we'll never leak blocks
1118 error
= xfs_free_eofblocks(mp
, ip
,
1119 XFS_FREE_EOF_TRYLOCK
);
1131 * This is called when the vnode reference count for the vnode
1132 * goes to zero. If the file has been unlinked, then it must
1133 * now be truncated. Also, we clear all of the read-ahead state
1134 * kept for the inode here since the file is now closed.
1140 xfs_bmap_free_t free_list
;
1141 xfs_fsblock_t first_block
;
1148 xfs_itrace_entry(ip
);
1151 * If the inode is already free, then there can be nothing
1154 if (ip
->i_d
.di_mode
== 0 || is_bad_inode(VFS_I(ip
))) {
1155 ASSERT(ip
->i_df
.if_real_bytes
== 0);
1156 ASSERT(ip
->i_df
.if_broot_bytes
== 0);
1157 return VN_INACTIVE_CACHE
;
1161 * Only do a truncate if it's a regular file with
1162 * some actual space in it. It's OK to look at the
1163 * inode's fields without the lock because we're the
1164 * only one with a reference to the inode.
1166 truncate
= ((ip
->i_d
.di_nlink
== 0) &&
1167 ((ip
->i_d
.di_size
!= 0) || (ip
->i_size
!= 0) ||
1168 (ip
->i_d
.di_nextents
> 0) || (ip
->i_delayed_blks
> 0)) &&
1169 ((ip
->i_d
.di_mode
& S_IFMT
) == S_IFREG
));
1173 if (ip
->i_d
.di_nlink
== 0 && DM_EVENT_ENABLED(ip
, DM_EVENT_DESTROY
))
1174 XFS_SEND_DESTROY(mp
, ip
, DM_RIGHT_NULL
);
1178 /* If this is a read-only mount, don't do this (would generate I/O) */
1179 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
1182 if (ip
->i_d
.di_nlink
!= 0) {
1183 if ((((ip
->i_d
.di_mode
& S_IFMT
) == S_IFREG
) &&
1184 ((ip
->i_size
> 0) || (VN_CACHED(VFS_I(ip
)) > 0 ||
1185 ip
->i_delayed_blks
> 0)) &&
1186 (ip
->i_df
.if_flags
& XFS_IFEXTENTS
) &&
1187 (!(ip
->i_d
.di_flags
&
1188 (XFS_DIFLAG_PREALLOC
| XFS_DIFLAG_APPEND
)) ||
1189 (ip
->i_delayed_blks
!= 0)))) {
1190 error
= xfs_free_eofblocks(mp
, ip
, 0);
1192 return VN_INACTIVE_CACHE
;
1197 ASSERT(ip
->i_d
.di_nlink
== 0);
1199 error
= xfs_qm_dqattach(ip
, 0);
1201 return VN_INACTIVE_CACHE
;
1203 tp
= xfs_trans_alloc(mp
, XFS_TRANS_INACTIVE
);
1206 * Do the xfs_itruncate_start() call before
1207 * reserving any log space because itruncate_start
1208 * will call into the buffer cache and we can't
1209 * do that within a transaction.
1211 xfs_ilock(ip
, XFS_IOLOCK_EXCL
);
1213 error
= xfs_itruncate_start(ip
, XFS_ITRUNC_DEFINITE
, 0);
1215 xfs_trans_cancel(tp
, 0);
1216 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
);
1217 return VN_INACTIVE_CACHE
;
1220 error
= xfs_trans_reserve(tp
, 0,
1221 XFS_ITRUNCATE_LOG_RES(mp
),
1222 0, XFS_TRANS_PERM_LOG_RES
,
1223 XFS_ITRUNCATE_LOG_COUNT
);
1225 /* Don't call itruncate_cleanup */
1226 ASSERT(XFS_FORCED_SHUTDOWN(mp
));
1227 xfs_trans_cancel(tp
, 0);
1228 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
);
1229 return VN_INACTIVE_CACHE
;
1232 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
1233 xfs_trans_ijoin(tp
, ip
, XFS_IOLOCK_EXCL
| XFS_ILOCK_EXCL
);
1234 xfs_trans_ihold(tp
, ip
);
1237 * normally, we have to run xfs_itruncate_finish sync.
1238 * But if filesystem is wsync and we're in the inactive
1239 * path, then we know that nlink == 0, and that the
1240 * xaction that made nlink == 0 is permanently committed
1241 * since xfs_remove runs as a synchronous transaction.
1243 error
= xfs_itruncate_finish(&tp
, ip
, 0, XFS_DATA_FORK
,
1244 (!(mp
->m_flags
& XFS_MOUNT_WSYNC
) ? 1 : 0));
1247 xfs_trans_cancel(tp
,
1248 XFS_TRANS_RELEASE_LOG_RES
| XFS_TRANS_ABORT
);
1249 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
| XFS_ILOCK_EXCL
);
1250 return VN_INACTIVE_CACHE
;
1252 } else if ((ip
->i_d
.di_mode
& S_IFMT
) == S_IFLNK
) {
1255 * If we get an error while cleaning up a
1256 * symlink we bail out.
1258 error
= (ip
->i_d
.di_size
> XFS_IFORK_DSIZE(ip
)) ?
1259 xfs_inactive_symlink_rmt(ip
, &tp
) :
1260 xfs_inactive_symlink_local(ip
, &tp
);
1264 return VN_INACTIVE_CACHE
;
1267 xfs_trans_ijoin(tp
, ip
, XFS_IOLOCK_EXCL
| XFS_ILOCK_EXCL
);
1268 xfs_trans_ihold(tp
, ip
);
1270 error
= xfs_trans_reserve(tp
, 0,
1271 XFS_IFREE_LOG_RES(mp
),
1272 0, XFS_TRANS_PERM_LOG_RES
,
1273 XFS_INACTIVE_LOG_COUNT
);
1275 ASSERT(XFS_FORCED_SHUTDOWN(mp
));
1276 xfs_trans_cancel(tp
, 0);
1277 return VN_INACTIVE_CACHE
;
1280 xfs_ilock(ip
, XFS_ILOCK_EXCL
| XFS_IOLOCK_EXCL
);
1281 xfs_trans_ijoin(tp
, ip
, XFS_IOLOCK_EXCL
| XFS_ILOCK_EXCL
);
1282 xfs_trans_ihold(tp
, ip
);
1286 * If there are attributes associated with the file
1287 * then blow them away now. The code calls a routine
1288 * that recursively deconstructs the attribute fork.
1289 * We need to just commit the current transaction
1290 * because we can't use it for xfs_attr_inactive().
1292 if (ip
->i_d
.di_anextents
> 0) {
1293 error
= xfs_inactive_attrs(ip
, &tp
);
1295 * If we got an error, the transaction is already
1296 * cancelled, and the inode is unlocked. Just get out.
1299 return VN_INACTIVE_CACHE
;
1300 } else if (ip
->i_afp
) {
1301 xfs_idestroy_fork(ip
, XFS_ATTR_FORK
);
1307 xfs_bmap_init(&free_list
, &first_block
);
1308 error
= xfs_ifree(tp
, ip
, &free_list
);
1311 * If we fail to free the inode, shut down. The cancel
1312 * might do that, we need to make sure. Otherwise the
1313 * inode might be lost for a long time or forever.
1315 if (!XFS_FORCED_SHUTDOWN(mp
)) {
1317 "xfs_inactive: xfs_ifree() returned an error = %d on %s",
1318 error
, mp
->m_fsname
);
1319 xfs_force_shutdown(mp
, SHUTDOWN_META_IO_ERROR
);
1321 xfs_trans_cancel(tp
, XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
1324 * Credit the quota account(s). The inode is gone.
1326 xfs_trans_mod_dquot_byino(tp
, ip
, XFS_TRANS_DQ_ICOUNT
, -1);
1329 * Just ignore errors at this point. There is nothing we can
1330 * do except to try to keep going. Make sure it's not a silent
1333 error
= xfs_bmap_finish(&tp
, &free_list
, &committed
);
1335 xfs_fs_cmn_err(CE_NOTE
, mp
, "xfs_inactive: "
1336 "xfs_bmap_finish() returned error %d", error
);
1337 error
= xfs_trans_commit(tp
, XFS_TRANS_RELEASE_LOG_RES
);
1339 xfs_fs_cmn_err(CE_NOTE
, mp
, "xfs_inactive: "
1340 "xfs_trans_commit() returned error %d", error
);
1344 * Release the dquots held by inode, if any.
1346 xfs_qm_dqdetach(ip
);
1347 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
| XFS_ILOCK_EXCL
);
1350 return VN_INACTIVE_CACHE
;
1354 * Lookups up an inode from "name". If ci_name is not NULL, then a CI match
1355 * is allowed, otherwise it has to be an exact match. If a CI match is found,
1356 * ci_name->name will point to a the actual name (caller must free) or
1357 * will be set to NULL if an exact match is found.
1362 struct xfs_name
*name
,
1364 struct xfs_name
*ci_name
)
1370 xfs_itrace_entry(dp
);
1372 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
1373 return XFS_ERROR(EIO
);
1375 lock_mode
= xfs_ilock_map_shared(dp
);
1376 error
= xfs_dir_lookup(NULL
, dp
, name
, &inum
, ci_name
);
1377 xfs_iunlock_map_shared(dp
, lock_mode
);
1382 error
= xfs_iget(dp
->i_mount
, NULL
, inum
, 0, 0, ipp
, 0);
1390 kmem_free(ci_name
->name
);
1399 struct xfs_name
*name
,
1405 int is_dir
= S_ISDIR(mode
);
1406 struct xfs_mount
*mp
= dp
->i_mount
;
1407 struct xfs_inode
*ip
= NULL
;
1408 struct xfs_trans
*tp
= NULL
;
1410 xfs_bmap_free_t free_list
;
1411 xfs_fsblock_t first_block
;
1412 boolean_t unlock_dp_on_error
= B_FALSE
;
1416 struct xfs_dquot
*udqp
= NULL
;
1417 struct xfs_dquot
*gdqp
= NULL
;
1422 xfs_itrace_entry(dp
);
1424 if (XFS_FORCED_SHUTDOWN(mp
))
1425 return XFS_ERROR(EIO
);
1427 if (DM_EVENT_ENABLED(dp
, DM_EVENT_CREATE
)) {
1428 error
= XFS_SEND_NAMESP(mp
, DM_EVENT_CREATE
,
1429 dp
, DM_RIGHT_NULL
, NULL
,
1430 DM_RIGHT_NULL
, name
->name
, NULL
,
1437 if (dp
->i_d
.di_flags
& XFS_DIFLAG_PROJINHERIT
)
1438 prid
= dp
->i_d
.di_projid
;
1443 * Make sure that we have allocated dquot(s) on disk.
1445 error
= xfs_qm_vop_dqalloc(dp
, current_fsuid(), current_fsgid(), prid
,
1446 XFS_QMOPT_QUOTALL
| XFS_QMOPT_INHERIT
, &udqp
, &gdqp
);
1452 resblks
= XFS_MKDIR_SPACE_RES(mp
, name
->len
);
1453 log_res
= XFS_MKDIR_LOG_RES(mp
);
1454 log_count
= XFS_MKDIR_LOG_COUNT
;
1455 tp
= xfs_trans_alloc(mp
, XFS_TRANS_MKDIR
);
1457 resblks
= XFS_CREATE_SPACE_RES(mp
, name
->len
);
1458 log_res
= XFS_CREATE_LOG_RES(mp
);
1459 log_count
= XFS_CREATE_LOG_COUNT
;
1460 tp
= xfs_trans_alloc(mp
, XFS_TRANS_CREATE
);
1463 cancel_flags
= XFS_TRANS_RELEASE_LOG_RES
;
1466 * Initially assume that the file does not exist and
1467 * reserve the resources for that case. If that is not
1468 * the case we'll drop the one we have and get a more
1469 * appropriate transaction later.
1471 error
= xfs_trans_reserve(tp
, resblks
, log_res
, 0,
1472 XFS_TRANS_PERM_LOG_RES
, log_count
);
1473 if (error
== ENOSPC
) {
1474 /* flush outstanding delalloc blocks and retry */
1475 xfs_flush_inodes(dp
);
1476 error
= xfs_trans_reserve(tp
, resblks
, log_res
, 0,
1477 XFS_TRANS_PERM_LOG_RES
, log_count
);
1479 if (error
== ENOSPC
) {
1480 /* No space at all so try a "no-allocation" reservation */
1482 error
= xfs_trans_reserve(tp
, 0, log_res
, 0,
1483 XFS_TRANS_PERM_LOG_RES
, log_count
);
1487 goto out_trans_cancel
;
1490 xfs_ilock(dp
, XFS_ILOCK_EXCL
| XFS_ILOCK_PARENT
);
1491 unlock_dp_on_error
= B_TRUE
;
1494 * Check for directory link count overflow.
1496 if (is_dir
&& dp
->i_d
.di_nlink
>= XFS_MAXLINK
) {
1497 error
= XFS_ERROR(EMLINK
);
1498 goto out_trans_cancel
;
1501 xfs_bmap_init(&free_list
, &first_block
);
1504 * Reserve disk quota and the inode.
1506 error
= xfs_trans_reserve_quota(tp
, mp
, udqp
, gdqp
, resblks
, 1, 0);
1508 goto out_trans_cancel
;
1510 error
= xfs_dir_canenter(tp
, dp
, name
, resblks
);
1512 goto out_trans_cancel
;
1515 * A newly created regular or special file just has one directory
1516 * entry pointing to them, but a directory also the "." entry
1517 * pointing to itself.
1519 error
= xfs_dir_ialloc(&tp
, dp
, mode
, is_dir
? 2 : 1, rdev
, credp
,
1520 prid
, resblks
> 0, &ip
, &committed
);
1522 if (error
== ENOSPC
)
1523 goto out_trans_cancel
;
1524 goto out_trans_abort
;
1528 * At this point, we've gotten a newly allocated inode.
1529 * It is locked (and joined to the transaction).
1531 ASSERT(xfs_isilocked(ip
, XFS_ILOCK_EXCL
));
1534 * Now we join the directory inode to the transaction. We do not do it
1535 * earlier because xfs_dir_ialloc might commit the previous transaction
1536 * (and release all the locks). An error from here on will result in
1537 * the transaction cancel unlocking dp so don't do it explicitly in the
1541 xfs_trans_ijoin(tp
, dp
, XFS_ILOCK_EXCL
);
1542 unlock_dp_on_error
= B_FALSE
;
1544 error
= xfs_dir_createname(tp
, dp
, name
, ip
->i_ino
,
1545 &first_block
, &free_list
, resblks
?
1546 resblks
- XFS_IALLOC_SPACE_RES(mp
) : 0);
1548 ASSERT(error
!= ENOSPC
);
1549 goto out_trans_abort
;
1551 xfs_ichgtime(dp
, XFS_ICHGTIME_MOD
| XFS_ICHGTIME_CHG
);
1552 xfs_trans_log_inode(tp
, dp
, XFS_ILOG_CORE
);
1555 error
= xfs_dir_init(tp
, ip
, dp
);
1557 goto out_bmap_cancel
;
1559 error
= xfs_bumplink(tp
, dp
);
1561 goto out_bmap_cancel
;
1565 * If this is a synchronous mount, make sure that the
1566 * create transaction goes to disk before returning to
1569 if (mp
->m_flags
& (XFS_MOUNT_WSYNC
|XFS_MOUNT_DIRSYNC
))
1570 xfs_trans_set_sync(tp
);
1573 * Attach the dquot(s) to the inodes and modify them incore.
1574 * These ids of the inode couldn't have changed since the new
1575 * inode has been locked ever since it was created.
1577 xfs_qm_vop_create_dqattach(tp
, ip
, udqp
, gdqp
);
1580 * xfs_trans_commit normally decrements the vnode ref count
1581 * when it unlocks the inode. Since we want to return the
1582 * vnode to the caller, we bump the vnode ref count now.
1586 error
= xfs_bmap_finish(&tp
, &free_list
, &committed
);
1588 goto out_abort_rele
;
1590 error
= xfs_trans_commit(tp
, XFS_TRANS_RELEASE_LOG_RES
);
1596 xfs_qm_dqrele(udqp
);
1597 xfs_qm_dqrele(gdqp
);
1601 /* Fallthrough to std_return with error = 0 */
1603 if (DM_EVENT_ENABLED(dp
, DM_EVENT_POSTCREATE
)) {
1604 XFS_SEND_NAMESP(mp
, DM_EVENT_POSTCREATE
, dp
, DM_RIGHT_NULL
,
1605 ip
, DM_RIGHT_NULL
, name
->name
, NULL
, mode
,
1612 xfs_bmap_cancel(&free_list
);
1614 cancel_flags
|= XFS_TRANS_ABORT
;
1616 xfs_trans_cancel(tp
, cancel_flags
);
1618 xfs_qm_dqrele(udqp
);
1619 xfs_qm_dqrele(gdqp
);
1621 if (unlock_dp_on_error
)
1622 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
1628 * Wait until after the current transaction is aborted to
1629 * release the inode. This prevents recursive transactions
1630 * and deadlocks from xfs_inactive.
1632 xfs_bmap_cancel(&free_list
);
1633 cancel_flags
|= XFS_TRANS_ABORT
;
1634 xfs_trans_cancel(tp
, cancel_flags
);
1636 unlock_dp_on_error
= B_FALSE
;
1642 int xfs_small_retries
;
1643 int xfs_middle_retries
;
1644 int xfs_lots_retries
;
1645 int xfs_lock_delays
;
1649 * Bump the subclass so xfs_lock_inodes() acquires each lock with
1653 xfs_lock_inumorder(int lock_mode
, int subclass
)
1655 if (lock_mode
& (XFS_IOLOCK_SHARED
|XFS_IOLOCK_EXCL
))
1656 lock_mode
|= (subclass
+ XFS_LOCK_INUMORDER
) << XFS_IOLOCK_SHIFT
;
1657 if (lock_mode
& (XFS_ILOCK_SHARED
|XFS_ILOCK_EXCL
))
1658 lock_mode
|= (subclass
+ XFS_LOCK_INUMORDER
) << XFS_ILOCK_SHIFT
;
1664 * The following routine will lock n inodes in exclusive mode.
1665 * We assume the caller calls us with the inodes in i_ino order.
1667 * We need to detect deadlock where an inode that we lock
1668 * is in the AIL and we start waiting for another inode that is locked
1669 * by a thread in a long running transaction (such as truncate). This can
1670 * result in deadlock since the long running trans might need to wait
1671 * for the inode we just locked in order to push the tail and free space
1680 int attempts
= 0, i
, j
, try_lock
;
1683 ASSERT(ips
&& (inodes
>= 2)); /* we need at least two */
1689 for (; i
< inodes
; i
++) {
1692 if (i
&& (ips
[i
] == ips
[i
-1])) /* Already locked */
1696 * If try_lock is not set yet, make sure all locked inodes
1697 * are not in the AIL.
1698 * If any are, set try_lock to be used later.
1702 for (j
= (i
- 1); j
>= 0 && !try_lock
; j
--) {
1703 lp
= (xfs_log_item_t
*)ips
[j
]->i_itemp
;
1704 if (lp
&& (lp
->li_flags
& XFS_LI_IN_AIL
)) {
1711 * If any of the previous locks we have locked is in the AIL,
1712 * we must TRY to get the second and subsequent locks. If
1713 * we can't get any, we must release all we have
1718 /* try_lock must be 0 if i is 0. */
1720 * try_lock means we have an inode locked
1721 * that is in the AIL.
1724 if (!xfs_ilock_nowait(ips
[i
], xfs_lock_inumorder(lock_mode
, i
))) {
1728 * Unlock all previous guys and try again.
1729 * xfs_iunlock will try to push the tail
1730 * if the inode is in the AIL.
1733 for(j
= i
- 1; j
>= 0; j
--) {
1736 * Check to see if we've already
1737 * unlocked this one.
1738 * Not the first one going back,
1739 * and the inode ptr is the same.
1741 if ((j
!= (i
- 1)) && ips
[j
] ==
1745 xfs_iunlock(ips
[j
], lock_mode
);
1748 if ((attempts
% 5) == 0) {
1749 delay(1); /* Don't just spin the CPU */
1759 xfs_ilock(ips
[i
], xfs_lock_inumorder(lock_mode
, i
));
1765 if (attempts
< 5) xfs_small_retries
++;
1766 else if (attempts
< 100) xfs_middle_retries
++;
1767 else xfs_lots_retries
++;
1775 * xfs_lock_two_inodes() can only be used to lock one type of lock
1776 * at a time - the iolock or the ilock, but not both at once. If
1777 * we lock both at once, lockdep will report false positives saying
1778 * we have violated locking orders.
1781 xfs_lock_two_inodes(
1790 if (lock_mode
& (XFS_IOLOCK_SHARED
|XFS_IOLOCK_EXCL
))
1791 ASSERT((lock_mode
& (XFS_ILOCK_SHARED
|XFS_ILOCK_EXCL
)) == 0);
1792 ASSERT(ip0
->i_ino
!= ip1
->i_ino
);
1794 if (ip0
->i_ino
> ip1
->i_ino
) {
1801 xfs_ilock(ip0
, xfs_lock_inumorder(lock_mode
, 0));
1804 * If the first lock we have locked is in the AIL, we must TRY to get
1805 * the second lock. If we can't get it, we must release the first one
1808 lp
= (xfs_log_item_t
*)ip0
->i_itemp
;
1809 if (lp
&& (lp
->li_flags
& XFS_LI_IN_AIL
)) {
1810 if (!xfs_ilock_nowait(ip1
, xfs_lock_inumorder(lock_mode
, 1))) {
1811 xfs_iunlock(ip0
, lock_mode
);
1812 if ((++attempts
% 5) == 0)
1813 delay(1); /* Don't just spin the CPU */
1817 xfs_ilock(ip1
, xfs_lock_inumorder(lock_mode
, 1));
1824 struct xfs_name
*name
,
1827 xfs_mount_t
*mp
= dp
->i_mount
;
1828 xfs_trans_t
*tp
= NULL
;
1829 int is_dir
= S_ISDIR(ip
->i_d
.di_mode
);
1831 xfs_bmap_free_t free_list
;
1832 xfs_fsblock_t first_block
;
1839 xfs_itrace_entry(dp
);
1840 xfs_itrace_entry(ip
);
1842 if (XFS_FORCED_SHUTDOWN(mp
))
1843 return XFS_ERROR(EIO
);
1845 if (DM_EVENT_ENABLED(dp
, DM_EVENT_REMOVE
)) {
1846 error
= XFS_SEND_NAMESP(mp
, DM_EVENT_REMOVE
, dp
, DM_RIGHT_NULL
,
1847 NULL
, DM_RIGHT_NULL
, name
->name
, NULL
,
1848 ip
->i_d
.di_mode
, 0, 0);
1853 error
= xfs_qm_dqattach(dp
, 0);
1857 error
= xfs_qm_dqattach(ip
, 0);
1862 tp
= xfs_trans_alloc(mp
, XFS_TRANS_RMDIR
);
1863 log_count
= XFS_DEFAULT_LOG_COUNT
;
1865 tp
= xfs_trans_alloc(mp
, XFS_TRANS_REMOVE
);
1866 log_count
= XFS_REMOVE_LOG_COUNT
;
1868 cancel_flags
= XFS_TRANS_RELEASE_LOG_RES
;
1871 * We try to get the real space reservation first,
1872 * allowing for directory btree deletion(s) implying
1873 * possible bmap insert(s). If we can't get the space
1874 * reservation then we use 0 instead, and avoid the bmap
1875 * btree insert(s) in the directory code by, if the bmap
1876 * insert tries to happen, instead trimming the LAST
1877 * block from the directory.
1879 resblks
= XFS_REMOVE_SPACE_RES(mp
);
1880 error
= xfs_trans_reserve(tp
, resblks
, XFS_REMOVE_LOG_RES(mp
), 0,
1881 XFS_TRANS_PERM_LOG_RES
, log_count
);
1882 if (error
== ENOSPC
) {
1884 error
= xfs_trans_reserve(tp
, 0, XFS_REMOVE_LOG_RES(mp
), 0,
1885 XFS_TRANS_PERM_LOG_RES
, log_count
);
1888 ASSERT(error
!= ENOSPC
);
1890 goto out_trans_cancel
;
1893 xfs_lock_two_inodes(dp
, ip
, XFS_ILOCK_EXCL
);
1896 * At this point, we've gotten both the directory and the entry
1900 xfs_trans_ijoin(tp
, dp
, XFS_ILOCK_EXCL
);
1903 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
1906 * If we're removing a directory perform some additional validation.
1909 ASSERT(ip
->i_d
.di_nlink
>= 2);
1910 if (ip
->i_d
.di_nlink
!= 2) {
1911 error
= XFS_ERROR(ENOTEMPTY
);
1912 goto out_trans_cancel
;
1914 if (!xfs_dir_isempty(ip
)) {
1915 error
= XFS_ERROR(ENOTEMPTY
);
1916 goto out_trans_cancel
;
1920 xfs_bmap_init(&free_list
, &first_block
);
1921 error
= xfs_dir_removename(tp
, dp
, name
, ip
->i_ino
,
1922 &first_block
, &free_list
, resblks
);
1924 ASSERT(error
!= ENOENT
);
1925 goto out_bmap_cancel
;
1927 xfs_ichgtime(dp
, XFS_ICHGTIME_MOD
| XFS_ICHGTIME_CHG
);
1931 * Drop the link from ip's "..".
1933 error
= xfs_droplink(tp
, dp
);
1935 goto out_bmap_cancel
;
1938 * Drop the "." link from ip to self.
1940 error
= xfs_droplink(tp
, ip
);
1942 goto out_bmap_cancel
;
1945 * When removing a non-directory we need to log the parent
1946 * inode here. For a directory this is done implicitly
1947 * by the xfs_droplink call for the ".." entry.
1949 xfs_trans_log_inode(tp
, dp
, XFS_ILOG_CORE
);
1953 * Drop the link from dp to ip.
1955 error
= xfs_droplink(tp
, ip
);
1957 goto out_bmap_cancel
;
1960 * Determine if this is the last link while
1961 * we are in the transaction.
1963 link_zero
= (ip
->i_d
.di_nlink
== 0);
1966 * If this is a synchronous mount, make sure that the
1967 * remove transaction goes to disk before returning to
1970 if (mp
->m_flags
& (XFS_MOUNT_WSYNC
|XFS_MOUNT_DIRSYNC
))
1971 xfs_trans_set_sync(tp
);
1973 error
= xfs_bmap_finish(&tp
, &free_list
, &committed
);
1975 goto out_bmap_cancel
;
1977 error
= xfs_trans_commit(tp
, XFS_TRANS_RELEASE_LOG_RES
);
1982 * If we are using filestreams, kill the stream association.
1983 * If the file is still open it may get a new one but that
1984 * will get killed on last close in xfs_close() so we don't
1985 * have to worry about that.
1987 if (!is_dir
&& link_zero
&& xfs_inode_is_filestream(ip
))
1988 xfs_filestream_deassociate(ip
);
1991 if (DM_EVENT_ENABLED(dp
, DM_EVENT_POSTREMOVE
)) {
1992 XFS_SEND_NAMESP(mp
, DM_EVENT_POSTREMOVE
, dp
, DM_RIGHT_NULL
,
1993 NULL
, DM_RIGHT_NULL
, name
->name
, NULL
,
1994 ip
->i_d
.di_mode
, error
, 0);
2000 xfs_bmap_cancel(&free_list
);
2001 cancel_flags
|= XFS_TRANS_ABORT
;
2003 xfs_trans_cancel(tp
, cancel_flags
);
2011 struct xfs_name
*target_name
)
2013 xfs_mount_t
*mp
= tdp
->i_mount
;
2016 xfs_bmap_free_t free_list
;
2017 xfs_fsblock_t first_block
;
2022 xfs_itrace_entry(tdp
);
2023 xfs_itrace_entry(sip
);
2025 ASSERT(!S_ISDIR(sip
->i_d
.di_mode
));
2027 if (XFS_FORCED_SHUTDOWN(mp
))
2028 return XFS_ERROR(EIO
);
2030 if (DM_EVENT_ENABLED(tdp
, DM_EVENT_LINK
)) {
2031 error
= XFS_SEND_NAMESP(mp
, DM_EVENT_LINK
,
2034 target_name
->name
, NULL
, 0, 0, 0);
2039 /* Return through std_return after this point. */
2041 error
= xfs_qm_dqattach(sip
, 0);
2045 error
= xfs_qm_dqattach(tdp
, 0);
2049 tp
= xfs_trans_alloc(mp
, XFS_TRANS_LINK
);
2050 cancel_flags
= XFS_TRANS_RELEASE_LOG_RES
;
2051 resblks
= XFS_LINK_SPACE_RES(mp
, target_name
->len
);
2052 error
= xfs_trans_reserve(tp
, resblks
, XFS_LINK_LOG_RES(mp
), 0,
2053 XFS_TRANS_PERM_LOG_RES
, XFS_LINK_LOG_COUNT
);
2054 if (error
== ENOSPC
) {
2056 error
= xfs_trans_reserve(tp
, 0, XFS_LINK_LOG_RES(mp
), 0,
2057 XFS_TRANS_PERM_LOG_RES
, XFS_LINK_LOG_COUNT
);
2064 xfs_lock_two_inodes(sip
, tdp
, XFS_ILOCK_EXCL
);
2067 * Increment vnode ref counts since xfs_trans_commit &
2068 * xfs_trans_cancel will both unlock the inodes and
2069 * decrement the associated ref counts.
2073 xfs_trans_ijoin(tp
, sip
, XFS_ILOCK_EXCL
);
2074 xfs_trans_ijoin(tp
, tdp
, XFS_ILOCK_EXCL
);
2077 * If the source has too many links, we can't make any more to it.
2079 if (sip
->i_d
.di_nlink
>= XFS_MAXLINK
) {
2080 error
= XFS_ERROR(EMLINK
);
2085 * If we are using project inheritance, we only allow hard link
2086 * creation in our tree when the project IDs are the same; else
2087 * the tree quota mechanism could be circumvented.
2089 if (unlikely((tdp
->i_d
.di_flags
& XFS_DIFLAG_PROJINHERIT
) &&
2090 (tdp
->i_d
.di_projid
!= sip
->i_d
.di_projid
))) {
2091 error
= XFS_ERROR(EXDEV
);
2095 error
= xfs_dir_canenter(tp
, tdp
, target_name
, resblks
);
2099 xfs_bmap_init(&free_list
, &first_block
);
2101 error
= xfs_dir_createname(tp
, tdp
, target_name
, sip
->i_ino
,
2102 &first_block
, &free_list
, resblks
);
2105 xfs_ichgtime(tdp
, XFS_ICHGTIME_MOD
| XFS_ICHGTIME_CHG
);
2106 xfs_trans_log_inode(tp
, tdp
, XFS_ILOG_CORE
);
2108 error
= xfs_bumplink(tp
, sip
);
2113 * If this is a synchronous mount, make sure that the
2114 * link transaction goes to disk before returning to
2117 if (mp
->m_flags
& (XFS_MOUNT_WSYNC
|XFS_MOUNT_DIRSYNC
)) {
2118 xfs_trans_set_sync(tp
);
2121 error
= xfs_bmap_finish (&tp
, &free_list
, &committed
);
2123 xfs_bmap_cancel(&free_list
);
2127 error
= xfs_trans_commit(tp
, XFS_TRANS_RELEASE_LOG_RES
);
2131 /* Fall through to std_return with error = 0. */
2133 if (DM_EVENT_ENABLED(sip
, DM_EVENT_POSTLINK
)) {
2134 (void) XFS_SEND_NAMESP(mp
, DM_EVENT_POSTLINK
,
2137 target_name
->name
, NULL
, 0, error
, 0);
2142 cancel_flags
|= XFS_TRANS_ABORT
;
2146 xfs_trans_cancel(tp
, cancel_flags
);
2153 struct xfs_name
*link_name
,
2154 const char *target_path
,
2159 xfs_mount_t
*mp
= dp
->i_mount
;
2164 xfs_bmap_free_t free_list
;
2165 xfs_fsblock_t first_block
;
2166 boolean_t unlock_dp_on_error
= B_FALSE
;
2169 xfs_fileoff_t first_fsb
;
2170 xfs_filblks_t fs_blocks
;
2172 xfs_bmbt_irec_t mval
[SYMLINK_MAPS
];
2174 const char *cur_chunk
;
2179 struct xfs_dquot
*udqp
, *gdqp
;
2187 xfs_itrace_entry(dp
);
2189 if (XFS_FORCED_SHUTDOWN(mp
))
2190 return XFS_ERROR(EIO
);
2193 * Check component lengths of the target path name.
2195 pathlen
= strlen(target_path
);
2196 if (pathlen
>= MAXPATHLEN
) /* total string too long */
2197 return XFS_ERROR(ENAMETOOLONG
);
2199 if (DM_EVENT_ENABLED(dp
, DM_EVENT_SYMLINK
)) {
2200 error
= XFS_SEND_NAMESP(mp
, DM_EVENT_SYMLINK
, dp
,
2201 DM_RIGHT_NULL
, NULL
, DM_RIGHT_NULL
,
2202 link_name
->name
, target_path
, 0, 0, 0);
2207 /* Return through std_return after this point. */
2210 if (dp
->i_d
.di_flags
& XFS_DIFLAG_PROJINHERIT
)
2211 prid
= dp
->i_d
.di_projid
;
2213 prid
= (xfs_prid_t
)dfltprid
;
2216 * Make sure that we have allocated dquot(s) on disk.
2218 error
= xfs_qm_vop_dqalloc(dp
, current_fsuid(), current_fsgid(), prid
,
2219 XFS_QMOPT_QUOTALL
| XFS_QMOPT_INHERIT
, &udqp
, &gdqp
);
2223 tp
= xfs_trans_alloc(mp
, XFS_TRANS_SYMLINK
);
2224 cancel_flags
= XFS_TRANS_RELEASE_LOG_RES
;
2226 * The symlink will fit into the inode data fork?
2227 * There can't be any attributes so we get the whole variable part.
2229 if (pathlen
<= XFS_LITINO(mp
))
2232 fs_blocks
= XFS_B_TO_FSB(mp
, pathlen
);
2233 resblks
= XFS_SYMLINK_SPACE_RES(mp
, link_name
->len
, fs_blocks
);
2234 error
= xfs_trans_reserve(tp
, resblks
, XFS_SYMLINK_LOG_RES(mp
), 0,
2235 XFS_TRANS_PERM_LOG_RES
, XFS_SYMLINK_LOG_COUNT
);
2236 if (error
== ENOSPC
&& fs_blocks
== 0) {
2238 error
= xfs_trans_reserve(tp
, 0, XFS_SYMLINK_LOG_RES(mp
), 0,
2239 XFS_TRANS_PERM_LOG_RES
, XFS_SYMLINK_LOG_COUNT
);
2246 xfs_ilock(dp
, XFS_ILOCK_EXCL
| XFS_ILOCK_PARENT
);
2247 unlock_dp_on_error
= B_TRUE
;
2250 * Check whether the directory allows new symlinks or not.
2252 if (dp
->i_d
.di_flags
& XFS_DIFLAG_NOSYMLINKS
) {
2253 error
= XFS_ERROR(EPERM
);
2258 * Reserve disk quota : blocks and inode.
2260 error
= xfs_trans_reserve_quota(tp
, mp
, udqp
, gdqp
, resblks
, 1, 0);
2265 * Check for ability to enter directory entry, if no space reserved.
2267 error
= xfs_dir_canenter(tp
, dp
, link_name
, resblks
);
2271 * Initialize the bmap freelist prior to calling either
2272 * bmapi or the directory create code.
2274 xfs_bmap_init(&free_list
, &first_block
);
2277 * Allocate an inode for the symlink.
2279 error
= xfs_dir_ialloc(&tp
, dp
, S_IFLNK
| (mode
& ~S_IFMT
),
2280 1, 0, credp
, prid
, resblks
> 0, &ip
, NULL
);
2282 if (error
== ENOSPC
)
2288 * An error after we've joined dp to the transaction will result in the
2289 * transaction cancel unlocking dp so don't do it explicitly in the
2293 xfs_trans_ijoin(tp
, dp
, XFS_ILOCK_EXCL
);
2294 unlock_dp_on_error
= B_FALSE
;
2297 * Also attach the dquot(s) to it, if applicable.
2299 xfs_qm_vop_create_dqattach(tp
, ip
, udqp
, gdqp
);
2302 resblks
-= XFS_IALLOC_SPACE_RES(mp
);
2304 * If the symlink will fit into the inode, write it inline.
2306 if (pathlen
<= XFS_IFORK_DSIZE(ip
)) {
2307 xfs_idata_realloc(ip
, pathlen
, XFS_DATA_FORK
);
2308 memcpy(ip
->i_df
.if_u1
.if_data
, target_path
, pathlen
);
2309 ip
->i_d
.di_size
= pathlen
;
2312 * The inode was initially created in extent format.
2314 ip
->i_df
.if_flags
&= ~(XFS_IFEXTENTS
| XFS_IFBROOT
);
2315 ip
->i_df
.if_flags
|= XFS_IFINLINE
;
2317 ip
->i_d
.di_format
= XFS_DINODE_FMT_LOCAL
;
2318 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_DDATA
| XFS_ILOG_CORE
);
2322 nmaps
= SYMLINK_MAPS
;
2324 error
= xfs_bmapi(tp
, ip
, first_fsb
, fs_blocks
,
2325 XFS_BMAPI_WRITE
| XFS_BMAPI_METADATA
,
2326 &first_block
, resblks
, mval
, &nmaps
,
2333 resblks
-= fs_blocks
;
2334 ip
->i_d
.di_size
= pathlen
;
2335 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
2337 cur_chunk
= target_path
;
2338 for (n
= 0; n
< nmaps
; n
++) {
2339 d
= XFS_FSB_TO_DADDR(mp
, mval
[n
].br_startblock
);
2340 byte_cnt
= XFS_FSB_TO_B(mp
, mval
[n
].br_blockcount
);
2341 bp
= xfs_trans_get_buf(tp
, mp
->m_ddev_targp
, d
,
2342 BTOBB(byte_cnt
), 0);
2343 ASSERT(bp
&& !XFS_BUF_GETERROR(bp
));
2344 if (pathlen
< byte_cnt
) {
2347 pathlen
-= byte_cnt
;
2349 memcpy(XFS_BUF_PTR(bp
), cur_chunk
, byte_cnt
);
2350 cur_chunk
+= byte_cnt
;
2352 xfs_trans_log_buf(tp
, bp
, 0, byte_cnt
- 1);
2357 * Create the directory entry for the symlink.
2359 error
= xfs_dir_createname(tp
, dp
, link_name
, ip
->i_ino
,
2360 &first_block
, &free_list
, resblks
);
2363 xfs_ichgtime(dp
, XFS_ICHGTIME_MOD
| XFS_ICHGTIME_CHG
);
2364 xfs_trans_log_inode(tp
, dp
, XFS_ILOG_CORE
);
2367 * If this is a synchronous mount, make sure that the
2368 * symlink transaction goes to disk before returning to
2371 if (mp
->m_flags
& (XFS_MOUNT_WSYNC
|XFS_MOUNT_DIRSYNC
)) {
2372 xfs_trans_set_sync(tp
);
2376 * xfs_trans_commit normally decrements the vnode ref count
2377 * when it unlocks the inode. Since we want to return the
2378 * vnode to the caller, we bump the vnode ref count now.
2382 error
= xfs_bmap_finish(&tp
, &free_list
, &committed
);
2386 error
= xfs_trans_commit(tp
, XFS_TRANS_RELEASE_LOG_RES
);
2387 xfs_qm_dqrele(udqp
);
2388 xfs_qm_dqrele(gdqp
);
2390 /* Fall through to std_return with error = 0 or errno from
2391 * xfs_trans_commit */
2393 if (DM_EVENT_ENABLED(dp
, DM_EVENT_POSTSYMLINK
)) {
2394 (void) XFS_SEND_NAMESP(mp
, DM_EVENT_POSTSYMLINK
,
2397 DM_RIGHT_NULL
, link_name
->name
,
2398 target_path
, 0, error
, 0);
2408 xfs_bmap_cancel(&free_list
);
2409 cancel_flags
|= XFS_TRANS_ABORT
;
2411 xfs_trans_cancel(tp
, cancel_flags
);
2412 xfs_qm_dqrele(udqp
);
2413 xfs_qm_dqrele(gdqp
);
2415 if (unlock_dp_on_error
)
2416 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
2427 xfs_mount_t
*mp
= ip
->i_mount
;
2431 if (!capable(CAP_SYS_ADMIN
))
2432 return XFS_ERROR(EPERM
);
2434 if (XFS_FORCED_SHUTDOWN(mp
))
2435 return XFS_ERROR(EIO
);
2437 tp
= xfs_trans_alloc(mp
, XFS_TRANS_SET_DMATTRS
);
2438 error
= xfs_trans_reserve(tp
, 0, XFS_ICHANGE_LOG_RES (mp
), 0, 0, 0);
2440 xfs_trans_cancel(tp
, 0);
2443 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
2444 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
2446 ip
->i_d
.di_dmevmask
= evmask
;
2447 ip
->i_d
.di_dmstate
= state
;
2449 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
2451 error
= xfs_trans_commit(tp
, 0);
2457 * xfs_alloc_file_space()
2458 * This routine allocates disk space for the given file.
2460 * If alloc_type == 0, this request is for an ALLOCSP type
2461 * request which will change the file size. In this case, no
2462 * DMAPI event will be generated by the call. A TRUNCATE event
2463 * will be generated later by xfs_setattr.
2465 * If alloc_type != 0, this request is for a RESVSP type
2466 * request, and a DMAPI DM_EVENT_WRITE will be generated if the
2467 * lower block boundary byte address is less than the file's
2476 xfs_alloc_file_space(
2483 xfs_mount_t
*mp
= ip
->i_mount
;
2485 xfs_filblks_t allocated_fsb
;
2486 xfs_filblks_t allocatesize_fsb
;
2487 xfs_extlen_t extsz
, temp
;
2488 xfs_fileoff_t startoffset_fsb
;
2489 xfs_fsblock_t firstfsb
;
2495 xfs_bmbt_irec_t imaps
[1], *imapp
;
2496 xfs_bmap_free_t free_list
;
2497 uint qblocks
, resblks
, resrtextents
;
2501 xfs_itrace_entry(ip
);
2503 if (XFS_FORCED_SHUTDOWN(mp
))
2504 return XFS_ERROR(EIO
);
2506 error
= xfs_qm_dqattach(ip
, 0);
2511 return XFS_ERROR(EINVAL
);
2513 rt
= XFS_IS_REALTIME_INODE(ip
);
2514 extsz
= xfs_get_extsz_hint(ip
);
2519 bmapi_flag
= XFS_BMAPI_WRITE
| (alloc_type
? XFS_BMAPI_PREALLOC
: 0);
2520 startoffset_fsb
= XFS_B_TO_FSBT(mp
, offset
);
2521 allocatesize_fsb
= XFS_B_TO_FSB(mp
, count
);
2523 /* Generate a DMAPI event if needed. */
2524 if (alloc_type
!= 0 && offset
< ip
->i_size
&&
2525 (attr_flags
& XFS_ATTR_DMI
) == 0 &&
2526 DM_EVENT_ENABLED(ip
, DM_EVENT_WRITE
)) {
2527 xfs_off_t end_dmi_offset
;
2529 end_dmi_offset
= offset
+len
;
2530 if (end_dmi_offset
> ip
->i_size
)
2531 end_dmi_offset
= ip
->i_size
;
2532 error
= XFS_SEND_DATA(mp
, DM_EVENT_WRITE
, ip
, offset
,
2533 end_dmi_offset
- offset
, 0, NULL
);
2539 * Allocate file space until done or until there is an error
2542 while (allocatesize_fsb
&& !error
) {
2546 * Determine space reservations for data/realtime.
2548 if (unlikely(extsz
)) {
2549 s
= startoffset_fsb
;
2552 e
= startoffset_fsb
+ allocatesize_fsb
;
2553 if ((temp
= do_mod(startoffset_fsb
, extsz
)))
2555 if ((temp
= do_mod(e
, extsz
)))
2559 e
= allocatesize_fsb
;
2563 resrtextents
= qblocks
= (uint
)(e
- s
);
2564 resrtextents
/= mp
->m_sb
.sb_rextsize
;
2565 resblks
= XFS_DIOSTRAT_SPACE_RES(mp
, 0);
2566 quota_flag
= XFS_QMOPT_RES_RTBLKS
;
2569 resblks
= qblocks
= \
2570 XFS_DIOSTRAT_SPACE_RES(mp
, (uint
)(e
- s
));
2571 quota_flag
= XFS_QMOPT_RES_REGBLKS
;
2575 * Allocate and setup the transaction.
2577 tp
= xfs_trans_alloc(mp
, XFS_TRANS_DIOSTRAT
);
2578 error
= xfs_trans_reserve(tp
, resblks
,
2579 XFS_WRITE_LOG_RES(mp
), resrtextents
,
2580 XFS_TRANS_PERM_LOG_RES
,
2581 XFS_WRITE_LOG_COUNT
);
2583 * Check for running out of space
2587 * Free the transaction structure.
2589 ASSERT(error
== ENOSPC
|| XFS_FORCED_SHUTDOWN(mp
));
2590 xfs_trans_cancel(tp
, 0);
2593 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
2594 error
= xfs_trans_reserve_quota_nblks(tp
, ip
, qblocks
,
2599 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
2600 xfs_trans_ihold(tp
, ip
);
2603 * Issue the xfs_bmapi() call to allocate the blocks
2605 xfs_bmap_init(&free_list
, &firstfsb
);
2606 error
= xfs_bmapi(tp
, ip
, startoffset_fsb
,
2607 allocatesize_fsb
, bmapi_flag
,
2608 &firstfsb
, 0, imapp
, &nimaps
,
2615 * Complete the transaction
2617 error
= xfs_bmap_finish(&tp
, &free_list
, &committed
);
2622 error
= xfs_trans_commit(tp
, XFS_TRANS_RELEASE_LOG_RES
);
2623 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
2628 allocated_fsb
= imapp
->br_blockcount
;
2631 error
= XFS_ERROR(ENOSPC
);
2635 startoffset_fsb
+= allocated_fsb
;
2636 allocatesize_fsb
-= allocated_fsb
;
2639 if (error
== ENOSPC
&& (attr_flags
& XFS_ATTR_DMI
) == 0 &&
2640 DM_EVENT_ENABLED(ip
, DM_EVENT_NOSPACE
)) {
2641 error
= XFS_SEND_NAMESP(mp
, DM_EVENT_NOSPACE
,
2644 NULL
, NULL
, 0, 0, 0); /* Delay flag intentionally unused */
2646 goto retry
; /* Maybe DMAPI app. has made space */
2647 /* else fall through with error from XFS_SEND_DATA */
2652 error0
: /* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */
2653 xfs_bmap_cancel(&free_list
);
2654 xfs_trans_unreserve_quota_nblks(tp
, ip
, qblocks
, 0, quota_flag
);
2656 error1
: /* Just cancel transaction */
2657 xfs_trans_cancel(tp
, XFS_TRANS_RELEASE_LOG_RES
| XFS_TRANS_ABORT
);
2658 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
2659 goto dmapi_enospc_check
;
2663 * Zero file bytes between startoff and endoff inclusive.
2664 * The iolock is held exclusive and no blocks are buffered.
2666 * This function is used by xfs_free_file_space() to zero
2667 * partial blocks when the range to free is not block aligned.
2668 * When unreserving space with boundaries that are not block
2669 * aligned we round up the start and round down the end
2670 * boundaries and then use this function to zero the parts of
2671 * the blocks that got dropped during the rounding.
2674 xfs_zero_remaining_bytes(
2679 xfs_bmbt_irec_t imap
;
2680 xfs_fileoff_t offset_fsb
;
2681 xfs_off_t lastoffset
;
2684 xfs_mount_t
*mp
= ip
->i_mount
;
2689 * Avoid doing I/O beyond eof - it's not necessary
2690 * since nothing can read beyond eof. The space will
2691 * be zeroed when the file is extended anyway.
2693 if (startoff
>= ip
->i_size
)
2696 if (endoff
> ip
->i_size
)
2697 endoff
= ip
->i_size
;
2699 bp
= xfs_buf_get_noaddr(mp
->m_sb
.sb_blocksize
,
2700 XFS_IS_REALTIME_INODE(ip
) ?
2701 mp
->m_rtdev_targp
: mp
->m_ddev_targp
);
2703 return XFS_ERROR(ENOMEM
);
2705 for (offset
= startoff
; offset
<= endoff
; offset
= lastoffset
+ 1) {
2706 offset_fsb
= XFS_B_TO_FSBT(mp
, offset
);
2708 error
= xfs_bmapi(NULL
, ip
, offset_fsb
, 1, 0,
2709 NULL
, 0, &imap
, &nimap
, NULL
, NULL
);
2710 if (error
|| nimap
< 1)
2712 ASSERT(imap
.br_blockcount
>= 1);
2713 ASSERT(imap
.br_startoff
== offset_fsb
);
2714 lastoffset
= XFS_FSB_TO_B(mp
, imap
.br_startoff
+ 1) - 1;
2715 if (lastoffset
> endoff
)
2716 lastoffset
= endoff
;
2717 if (imap
.br_startblock
== HOLESTARTBLOCK
)
2719 ASSERT(imap
.br_startblock
!= DELAYSTARTBLOCK
);
2720 if (imap
.br_state
== XFS_EXT_UNWRITTEN
)
2723 XFS_BUF_UNWRITE(bp
);
2725 XFS_BUF_SET_ADDR(bp
, xfs_fsb_to_db(ip
, imap
.br_startblock
));
2727 error
= xfs_iowait(bp
);
2729 xfs_ioerror_alert("xfs_zero_remaining_bytes(read)",
2730 mp
, bp
, XFS_BUF_ADDR(bp
));
2733 memset(XFS_BUF_PTR(bp
) +
2734 (offset
- XFS_FSB_TO_B(mp
, imap
.br_startoff
)),
2735 0, lastoffset
- offset
+ 1);
2740 error
= xfs_iowait(bp
);
2742 xfs_ioerror_alert("xfs_zero_remaining_bytes(write)",
2743 mp
, bp
, XFS_BUF_ADDR(bp
));
2752 * xfs_free_file_space()
2753 * This routine frees disk space for the given file.
2755 * This routine is only called by xfs_change_file_space
2756 * for an UNRESVSP type call.
2764 xfs_free_file_space(
2772 xfs_off_t end_dmi_offset
;
2773 xfs_fileoff_t endoffset_fsb
;
2775 xfs_fsblock_t firstfsb
;
2776 xfs_bmap_free_t free_list
;
2777 xfs_bmbt_irec_t imap
;
2785 xfs_fileoff_t startoffset_fsb
;
2787 int need_iolock
= 1;
2791 xfs_itrace_entry(ip
);
2793 error
= xfs_qm_dqattach(ip
, 0);
2798 if (len
<= 0) /* if nothing being freed */
2800 rt
= XFS_IS_REALTIME_INODE(ip
);
2801 startoffset_fsb
= XFS_B_TO_FSB(mp
, offset
);
2802 end_dmi_offset
= offset
+ len
;
2803 endoffset_fsb
= XFS_B_TO_FSBT(mp
, end_dmi_offset
);
2805 if (offset
< ip
->i_size
&& (attr_flags
& XFS_ATTR_DMI
) == 0 &&
2806 DM_EVENT_ENABLED(ip
, DM_EVENT_WRITE
)) {
2807 if (end_dmi_offset
> ip
->i_size
)
2808 end_dmi_offset
= ip
->i_size
;
2809 error
= XFS_SEND_DATA(mp
, DM_EVENT_WRITE
, ip
,
2810 offset
, end_dmi_offset
- offset
,
2811 AT_DELAY_FLAG(attr_flags
), NULL
);
2816 if (attr_flags
& XFS_ATTR_NOLOCK
)
2819 xfs_ilock(ip
, XFS_IOLOCK_EXCL
);
2820 /* wait for the completion of any pending DIOs */
2824 rounding
= max_t(uint
, 1 << mp
->m_sb
.sb_blocklog
, PAGE_CACHE_SIZE
);
2825 ioffset
= offset
& ~(rounding
- 1);
2827 if (VN_CACHED(VFS_I(ip
)) != 0) {
2828 error
= xfs_flushinval_pages(ip
, ioffset
, -1, FI_REMAPF_LOCKED
);
2830 goto out_unlock_iolock
;
2834 * Need to zero the stuff we're not freeing, on disk.
2835 * If it's a realtime file & can't use unwritten extents then we
2836 * actually need to zero the extent edges. Otherwise xfs_bunmapi
2837 * will take care of it for us.
2839 if (rt
&& !xfs_sb_version_hasextflgbit(&mp
->m_sb
)) {
2841 error
= xfs_bmapi(NULL
, ip
, startoffset_fsb
,
2842 1, 0, NULL
, 0, &imap
, &nimap
, NULL
, NULL
);
2844 goto out_unlock_iolock
;
2845 ASSERT(nimap
== 0 || nimap
== 1);
2846 if (nimap
&& imap
.br_startblock
!= HOLESTARTBLOCK
) {
2849 ASSERT(imap
.br_startblock
!= DELAYSTARTBLOCK
);
2850 block
= imap
.br_startblock
;
2851 mod
= do_div(block
, mp
->m_sb
.sb_rextsize
);
2853 startoffset_fsb
+= mp
->m_sb
.sb_rextsize
- mod
;
2856 error
= xfs_bmapi(NULL
, ip
, endoffset_fsb
- 1,
2857 1, 0, NULL
, 0, &imap
, &nimap
, NULL
, NULL
);
2859 goto out_unlock_iolock
;
2860 ASSERT(nimap
== 0 || nimap
== 1);
2861 if (nimap
&& imap
.br_startblock
!= HOLESTARTBLOCK
) {
2862 ASSERT(imap
.br_startblock
!= DELAYSTARTBLOCK
);
2864 if (mod
&& (mod
!= mp
->m_sb
.sb_rextsize
))
2865 endoffset_fsb
-= mod
;
2868 if ((done
= (endoffset_fsb
<= startoffset_fsb
)))
2870 * One contiguous piece to clear
2872 error
= xfs_zero_remaining_bytes(ip
, offset
, offset
+ len
- 1);
2875 * Some full blocks, possibly two pieces to clear
2877 if (offset
< XFS_FSB_TO_B(mp
, startoffset_fsb
))
2878 error
= xfs_zero_remaining_bytes(ip
, offset
,
2879 XFS_FSB_TO_B(mp
, startoffset_fsb
) - 1);
2881 XFS_FSB_TO_B(mp
, endoffset_fsb
) < offset
+ len
)
2882 error
= xfs_zero_remaining_bytes(ip
,
2883 XFS_FSB_TO_B(mp
, endoffset_fsb
),
2888 * free file space until done or until there is an error
2890 resblks
= XFS_DIOSTRAT_SPACE_RES(mp
, 0);
2891 while (!error
&& !done
) {
2894 * allocate and setup the transaction. Allow this
2895 * transaction to dip into the reserve blocks to ensure
2896 * the freeing of the space succeeds at ENOSPC.
2898 tp
= xfs_trans_alloc(mp
, XFS_TRANS_DIOSTRAT
);
2899 tp
->t_flags
|= XFS_TRANS_RESERVE
;
2900 error
= xfs_trans_reserve(tp
,
2902 XFS_WRITE_LOG_RES(mp
),
2904 XFS_TRANS_PERM_LOG_RES
,
2905 XFS_WRITE_LOG_COUNT
);
2908 * check for running out of space
2912 * Free the transaction structure.
2914 ASSERT(error
== ENOSPC
|| XFS_FORCED_SHUTDOWN(mp
));
2915 xfs_trans_cancel(tp
, 0);
2918 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
2919 error
= xfs_trans_reserve_quota(tp
, mp
,
2920 ip
->i_udquot
, ip
->i_gdquot
,
2921 resblks
, 0, XFS_QMOPT_RES_REGBLKS
);
2925 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
2926 xfs_trans_ihold(tp
, ip
);
2929 * issue the bunmapi() call to free the blocks
2931 xfs_bmap_init(&free_list
, &firstfsb
);
2932 error
= xfs_bunmapi(tp
, ip
, startoffset_fsb
,
2933 endoffset_fsb
- startoffset_fsb
,
2934 0, 2, &firstfsb
, &free_list
, NULL
, &done
);
2940 * complete the transaction
2942 error
= xfs_bmap_finish(&tp
, &free_list
, &committed
);
2947 error
= xfs_trans_commit(tp
, XFS_TRANS_RELEASE_LOG_RES
);
2948 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
2953 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
);
2957 xfs_bmap_cancel(&free_list
);
2959 xfs_trans_cancel(tp
, XFS_TRANS_RELEASE_LOG_RES
| XFS_TRANS_ABORT
);
2960 xfs_iunlock(ip
, need_iolock
? (XFS_ILOCK_EXCL
| XFS_IOLOCK_EXCL
) :
2966 * xfs_change_file_space()
2967 * This routine allocates or frees disk space for the given file.
2968 * The user specified parameters are checked for alignment and size
2977 xfs_change_file_space(
2984 xfs_mount_t
*mp
= ip
->i_mount
;
2989 xfs_off_t startoffset
;
2994 xfs_itrace_entry(ip
);
2996 if (!S_ISREG(ip
->i_d
.di_mode
))
2997 return XFS_ERROR(EINVAL
);
2999 switch (bf
->l_whence
) {
3000 case 0: /*SEEK_SET*/
3002 case 1: /*SEEK_CUR*/
3003 bf
->l_start
+= offset
;
3005 case 2: /*SEEK_END*/
3006 bf
->l_start
+= ip
->i_size
;
3009 return XFS_ERROR(EINVAL
);
3012 llen
= bf
->l_len
> 0 ? bf
->l_len
- 1 : bf
->l_len
;
3014 if ( (bf
->l_start
< 0)
3015 || (bf
->l_start
> XFS_MAXIOFFSET(mp
))
3016 || (bf
->l_start
+ llen
< 0)
3017 || (bf
->l_start
+ llen
> XFS_MAXIOFFSET(mp
)))
3018 return XFS_ERROR(EINVAL
);
3022 startoffset
= bf
->l_start
;
3026 * XFS_IOC_RESVSP and XFS_IOC_UNRESVSP will reserve or unreserve
3028 * These calls do NOT zero the data space allocated to the file,
3029 * nor do they change the file size.
3031 * XFS_IOC_ALLOCSP and XFS_IOC_FREESP will allocate and free file
3033 * These calls cause the new file data to be zeroed and the file
3034 * size to be changed.
3036 setprealloc
= clrprealloc
= 0;
3039 case XFS_IOC_RESVSP
:
3040 case XFS_IOC_RESVSP64
:
3041 error
= xfs_alloc_file_space(ip
, startoffset
, bf
->l_len
,
3048 case XFS_IOC_UNRESVSP
:
3049 case XFS_IOC_UNRESVSP64
:
3050 if ((error
= xfs_free_file_space(ip
, startoffset
, bf
->l_len
,
3055 case XFS_IOC_ALLOCSP
:
3056 case XFS_IOC_ALLOCSP64
:
3057 case XFS_IOC_FREESP
:
3058 case XFS_IOC_FREESP64
:
3059 if (startoffset
> fsize
) {
3060 error
= xfs_alloc_file_space(ip
, fsize
,
3061 startoffset
- fsize
, 0, attr_flags
);
3066 iattr
.ia_valid
= ATTR_SIZE
;
3067 iattr
.ia_size
= startoffset
;
3069 error
= xfs_setattr(ip
, &iattr
, attr_flags
);
3079 return XFS_ERROR(EINVAL
);
3083 * update the inode timestamp, mode, and prealloc flag bits
3085 tp
= xfs_trans_alloc(mp
, XFS_TRANS_WRITEID
);
3087 if ((error
= xfs_trans_reserve(tp
, 0, XFS_WRITEID_LOG_RES(mp
),
3090 xfs_trans_cancel(tp
, 0);
3094 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
3096 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
3097 xfs_trans_ihold(tp
, ip
);
3099 if ((attr_flags
& XFS_ATTR_DMI
) == 0) {
3100 ip
->i_d
.di_mode
&= ~S_ISUID
;
3103 * Note that we don't have to worry about mandatory
3104 * file locking being disabled here because we only
3105 * clear the S_ISGID bit if the Group execute bit is
3106 * on, but if it was on then mandatory locking wouldn't
3107 * have been enabled.
3109 if (ip
->i_d
.di_mode
& S_IXGRP
)
3110 ip
->i_d
.di_mode
&= ~S_ISGID
;
3112 xfs_ichgtime(ip
, XFS_ICHGTIME_MOD
| XFS_ICHGTIME_CHG
);
3115 ip
->i_d
.di_flags
|= XFS_DIFLAG_PREALLOC
;
3116 else if (clrprealloc
)
3117 ip
->i_d
.di_flags
&= ~XFS_DIFLAG_PREALLOC
;
3119 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
3120 xfs_trans_set_sync(tp
);
3122 error
= xfs_trans_commit(tp
, 0);
3124 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);