Lines Matching +full:tp +full:- +full:link
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
50 STATIC int xfs_iunlink_remove(struct xfs_trans *tp, struct xfs_perag *pag,
66 if ((ip->i_diflags & XFS_DIFLAG_EXTSIZE) && ip->i_extsize) in xfs_get_extsz_hint()
67 return ip->i_extsize; in xfs_get_extsz_hint()
69 return ip->i_mount->m_sb.sb_rextsize; in xfs_get_extsz_hint()
86 if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) in xfs_get_cowextsz_hint()
87 a = ip->i_cowextsize; in xfs_get_cowextsz_hint()
101 * bringing in of the extents from disk for a file in b-tree format. If the
102 * inode is in b-tree format, then we need to lock the inode exclusively until
117 if (xfs_need_iread_extents(&ip->i_df)) in xfs_ilock_data_map_shared()
129 if (xfs_inode_has_attr_fork(ip) && xfs_need_iread_extents(&ip->i_af)) in xfs_ilock_attr_map_shared()
157 * multi-reader locks: invalidate_lock and the i_lock. This routine allows
165 * i_rwsem -> invalidate_lock -> page_lock -> i_ilock
169 * i_rwsem -> page lock -> mmap_lock
170 * mmap_lock -> invalidate_lock -> page_lock
195 down_write_nested(&VFS_I(ip)->i_rwsem, in xfs_ilock()
198 down_read_nested(&VFS_I(ip)->i_rwsem, in xfs_ilock()
203 down_write_nested(&VFS_I(ip)->i_mapping->invalidate_lock, in xfs_ilock()
206 down_read_nested(&VFS_I(ip)->i_mapping->invalidate_lock, in xfs_ilock()
211 mrupdate_nested(&ip->i_lock, XFS_ILOCK_DEP(lock_flags)); in xfs_ilock()
213 mraccess_nested(&ip->i_lock, XFS_ILOCK_DEP(lock_flags)); in xfs_ilock()
223 * ip -- the inode being locked
224 * lock_flags -- this parameter indicates the inode's locks to be
238 if (!down_write_trylock(&VFS_I(ip)->i_rwsem)) in xfs_ilock_nowait()
241 if (!down_read_trylock(&VFS_I(ip)->i_rwsem)) in xfs_ilock_nowait()
246 if (!down_write_trylock(&VFS_I(ip)->i_mapping->invalidate_lock)) in xfs_ilock_nowait()
249 if (!down_read_trylock(&VFS_I(ip)->i_mapping->invalidate_lock)) in xfs_ilock_nowait()
254 if (!mrtryupdate(&ip->i_lock)) in xfs_ilock_nowait()
257 if (!mrtryaccess(&ip->i_lock)) in xfs_ilock_nowait()
264 up_write(&VFS_I(ip)->i_mapping->invalidate_lock); in xfs_ilock_nowait()
266 up_read(&VFS_I(ip)->i_mapping->invalidate_lock); in xfs_ilock_nowait()
269 up_write(&VFS_I(ip)->i_rwsem); in xfs_ilock_nowait()
271 up_read(&VFS_I(ip)->i_rwsem); in xfs_ilock_nowait()
282 * ip -- the inode being unlocked
283 * lock_flags -- this parameter indicates the inode's locks to be
296 up_write(&VFS_I(ip)->i_rwsem); in xfs_iunlock()
298 up_read(&VFS_I(ip)->i_rwsem); in xfs_iunlock()
301 up_write(&VFS_I(ip)->i_mapping->invalidate_lock); in xfs_iunlock()
303 up_read(&VFS_I(ip)->i_mapping->invalidate_lock); in xfs_iunlock()
306 mrunlock_excl(&ip->i_lock); in xfs_iunlock()
308 mrunlock_shared(&ip->i_lock); in xfs_iunlock()
327 mrdemote(&ip->i_lock); in xfs_ilock_demote()
329 downgrade_write(&VFS_I(ip)->i_mapping->invalidate_lock); in xfs_ilock_demote()
331 downgrade_write(&VFS_I(ip)->i_rwsem); in xfs_ilock_demote()
354 return lockdep_is_held_type(rwsem, -1); in __xfs_rwsem_islocked()
364 return !!ip->i_lock.mr_writer; in xfs_isilocked()
365 return rwsem_is_locked(&ip->i_lock.mr_lock); in xfs_isilocked()
369 return __xfs_rwsem_islocked(&VFS_I(ip)->i_mapping->invalidate_lock, in xfs_isilocked()
374 return __xfs_rwsem_islocked(&VFS_I(ip)->i_rwsem, in xfs_isilocked()
445 * xfs_lock_inodes() can only be used to lock one type of lock at a time -
490 if (i && (ips[i] == ips[i - 1])) /* Already locked */ in xfs_lock_inodes()
498 for (j = (i - 1); j >= 0 && !try_lock; j--) { in xfs_lock_inodes()
499 lp = &ips[j]->i_itemp->ili_item; in xfs_lock_inodes()
500 if (lp && test_bit(XFS_LI_IN_AIL, &lp->li_flags)) in xfs_lock_inodes()
526 for (j = i - 1; j >= 0; j--) { in xfs_lock_inodes()
532 if (j != (i - 1) && ips[j] == ips[j + 1]) in xfs_lock_inodes()
547 * mmaplock must be double-locked separately since we use i_rwsem and
567 ASSERT(ip0->i_ino != ip1->i_ino); in xfs_lock_two_inodes()
569 if (ip0->i_ino > ip1->i_ino) { in xfs_lock_two_inodes()
582 lp = &ip0->i_itemp->ili_item; in xfs_lock_two_inodes()
583 if (lp && test_bit(XFS_LI_IN_AIL, &lp->li_flags)) { in xfs_lock_two_inodes()
601 if (ip->i_diflags & XFS_DIFLAG_ANY) { in xfs_ip2xflags()
602 if (ip->i_diflags & XFS_DIFLAG_REALTIME) in xfs_ip2xflags()
604 if (ip->i_diflags & XFS_DIFLAG_PREALLOC) in xfs_ip2xflags()
606 if (ip->i_diflags & XFS_DIFLAG_IMMUTABLE) in xfs_ip2xflags()
608 if (ip->i_diflags & XFS_DIFLAG_APPEND) in xfs_ip2xflags()
610 if (ip->i_diflags & XFS_DIFLAG_SYNC) in xfs_ip2xflags()
612 if (ip->i_diflags & XFS_DIFLAG_NOATIME) in xfs_ip2xflags()
614 if (ip->i_diflags & XFS_DIFLAG_NODUMP) in xfs_ip2xflags()
616 if (ip->i_diflags & XFS_DIFLAG_RTINHERIT) in xfs_ip2xflags()
618 if (ip->i_diflags & XFS_DIFLAG_PROJINHERIT) in xfs_ip2xflags()
620 if (ip->i_diflags & XFS_DIFLAG_NOSYMLINKS) in xfs_ip2xflags()
622 if (ip->i_diflags & XFS_DIFLAG_EXTSIZE) in xfs_ip2xflags()
624 if (ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) in xfs_ip2xflags()
626 if (ip->i_diflags & XFS_DIFLAG_NODEFRAG) in xfs_ip2xflags()
628 if (ip->i_diflags & XFS_DIFLAG_FILESTREAM) in xfs_ip2xflags()
632 if (ip->i_diflags2 & XFS_DIFLAG2_ANY) { in xfs_ip2xflags()
633 if (ip->i_diflags2 & XFS_DIFLAG2_DAX) in xfs_ip2xflags()
635 if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) in xfs_ip2xflags()
647 * ci_name->name will point to a the actual name (caller must free) or
662 if (xfs_is_shutdown(dp->i_mount)) in xfs_lookup()
663 return -EIO; in xfs_lookup()
669 error = xfs_iget(dp->i_mount, NULL, inum, 0, 0, ipp); in xfs_lookup()
677 kmem_free(ci_name->name); in xfs_lookup()
691 umode_t mode = VFS_I(ip)->i_mode; in xfs_inode_inherit_flags()
694 if (pip->i_diflags & XFS_DIFLAG_RTINHERIT) in xfs_inode_inherit_flags()
696 if (pip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) { in xfs_inode_inherit_flags()
698 ip->i_extsize = pip->i_extsize; in xfs_inode_inherit_flags()
700 if (pip->i_diflags & XFS_DIFLAG_PROJINHERIT) in xfs_inode_inherit_flags()
703 if ((pip->i_diflags & XFS_DIFLAG_RTINHERIT) && in xfs_inode_inherit_flags()
704 xfs_has_realtime(ip->i_mount)) in xfs_inode_inherit_flags()
706 if (pip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) { in xfs_inode_inherit_flags()
708 ip->i_extsize = pip->i_extsize; in xfs_inode_inherit_flags()
711 if ((pip->i_diflags & XFS_DIFLAG_NOATIME) && in xfs_inode_inherit_flags()
714 if ((pip->i_diflags & XFS_DIFLAG_NODUMP) && in xfs_inode_inherit_flags()
717 if ((pip->i_diflags & XFS_DIFLAG_SYNC) && in xfs_inode_inherit_flags()
720 if ((pip->i_diflags & XFS_DIFLAG_NOSYMLINKS) && in xfs_inode_inherit_flags()
723 if ((pip->i_diflags & XFS_DIFLAG_NODEFRAG) && in xfs_inode_inherit_flags()
726 if (pip->i_diflags & XFS_DIFLAG_FILESTREAM) in xfs_inode_inherit_flags()
729 ip->i_diflags |= di_flags; in xfs_inode_inherit_flags()
741 failaddr = xfs_inode_validate_extsize(ip->i_mount, ip->i_extsize, in xfs_inode_inherit_flags()
742 VFS_I(ip)->i_mode, ip->i_diflags); in xfs_inode_inherit_flags()
744 ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE | in xfs_inode_inherit_flags()
746 ip->i_extsize = 0; in xfs_inode_inherit_flags()
758 if (pip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) { in xfs_inode_inherit_flags2()
759 ip->i_diflags2 |= XFS_DIFLAG2_COWEXTSIZE; in xfs_inode_inherit_flags2()
760 ip->i_cowextsize = pip->i_cowextsize; in xfs_inode_inherit_flags2()
762 if (pip->i_diflags2 & XFS_DIFLAG2_DAX) in xfs_inode_inherit_flags2()
763 ip->i_diflags2 |= XFS_DIFLAG2_DAX; in xfs_inode_inherit_flags2()
766 failaddr = xfs_inode_validate_cowextsize(ip->i_mount, ip->i_cowextsize, in xfs_inode_inherit_flags2()
767 VFS_I(ip)->i_mode, ip->i_diflags, ip->i_diflags2); in xfs_inode_inherit_flags2()
769 ip->i_diflags2 &= ~XFS_DIFLAG2_COWEXTSIZE; in xfs_inode_inherit_flags2()
770 ip->i_cowextsize = 0; in xfs_inode_inherit_flags2()
775 * Initialise a newly allocated inode and return the in-core inode to the
781 struct xfs_trans *tp, in xfs_init_new_inode() argument
792 struct xfs_mount *mp = tp->t_mountp; in xfs_init_new_inode()
801 * xfs_iget checks will catch re-allocation of other active in-memory in xfs_init_new_inode()
802 * and on-disk inodes. If we don't catch reallocating the parent inode in xfs_init_new_inode()
806 if ((pip && ino == pip->i_ino) || !xfs_verify_dir_ino(mp, ino)) { in xfs_init_new_inode()
807 xfs_alert(mp, "Allocated a known in-use inode 0x%llx!", ino); in xfs_init_new_inode()
808 return -EFSCORRUPTED; in xfs_init_new_inode()
812 * Get the in-core inode with the lock held exclusively to prevent in xfs_init_new_inode()
815 error = xfs_iget(mp, tp, ino, XFS_IGET_CREATE, XFS_ILOCK_EXCL, &ip); in xfs_init_new_inode()
822 inode->i_rdev = rdev; in xfs_init_new_inode()
823 ip->i_projid = prid; in xfs_init_new_inode()
825 if (dir && !(dir->i_mode & S_ISGID) && xfs_has_grpid(mp)) { in xfs_init_new_inode()
827 inode->i_gid = dir->i_gid; in xfs_init_new_inode()
828 inode->i_mode = mode; in xfs_init_new_inode()
838 if (irix_sgid_inherit && (inode->i_mode & S_ISGID) && in xfs_init_new_inode()
840 inode->i_mode &= ~S_ISGID; in xfs_init_new_inode()
842 ip->i_disk_size = 0; in xfs_init_new_inode()
843 ip->i_df.if_nextents = 0; in xfs_init_new_inode()
844 ASSERT(ip->i_nblocks == 0); in xfs_init_new_inode()
847 inode->i_mtime = tv; in xfs_init_new_inode()
848 inode->i_atime = tv; in xfs_init_new_inode()
850 ip->i_extsize = 0; in xfs_init_new_inode()
851 ip->i_diflags = 0; in xfs_init_new_inode()
855 ip->i_cowextsize = 0; in xfs_init_new_inode()
856 ip->i_crtime = tv; in xfs_init_new_inode()
865 ip->i_df.if_format = XFS_DINODE_FMT_DEV; in xfs_init_new_inode()
870 if (pip && (pip->i_diflags & XFS_DIFLAG_ANY)) in xfs_init_new_inode()
872 if (pip && (pip->i_diflags2 & XFS_DIFLAG2_ANY)) in xfs_init_new_inode()
876 ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS; in xfs_init_new_inode()
877 ip->i_df.if_bytes = 0; in xfs_init_new_inode()
878 ip->i_df.if_u1.if_root = NULL; in xfs_init_new_inode()
894 ip->i_forkoff = xfs_default_attroffset(ip) >> 3; in xfs_init_new_inode()
901 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); in xfs_init_new_inode()
902 xfs_trans_log_inode(tp, ip, flags); in xfs_init_new_inode()
912 * Decrement the link count on an inode & log the change. If this causes the
913 * link count to go to zero, move the inode to AGI unlinked list so that it can
918 xfs_trans_t *tp, in xfs_droplink() argument
921 if (VFS_I(ip)->i_nlink == 0) { in xfs_droplink()
922 xfs_alert(ip->i_mount, in xfs_droplink()
924 __func__, ip->i_ino); in xfs_droplink()
925 return -EFSCORRUPTED; in xfs_droplink()
928 xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); in xfs_droplink()
931 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_droplink()
933 if (VFS_I(ip)->i_nlink) in xfs_droplink()
936 return xfs_iunlink(tp, ip); in xfs_droplink()
940 * Increment the link count on an inode & log the change.
944 xfs_trans_t *tp, in xfs_bumplink() argument
947 xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); in xfs_bumplink()
950 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_bumplink()
964 struct xfs_mount *mp = dp->i_mount; in xfs_create()
966 struct xfs_trans *tp = NULL; in xfs_create() local
980 return -EIO; in xfs_create()
997 resblks = XFS_MKDIR_SPACE_RES(mp, name->len); in xfs_create()
998 tres = &M_RES(mp)->tr_mkdir; in xfs_create()
1000 resblks = XFS_CREATE_SPACE_RES(mp, name->len); in xfs_create()
1001 tres = &M_RES(mp)->tr_create; in xfs_create()
1011 &tp); in xfs_create()
1012 if (error == -ENOSPC) { in xfs_create()
1016 resblks, &tp); in xfs_create()
1029 error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); in xfs_create()
1031 error = xfs_init_new_inode(idmap, tp, dp, ino, mode, in xfs_create()
1043 xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); in xfs_create()
1046 error = xfs_dir_createname(tp, dp, name, ip->i_ino, in xfs_create()
1047 resblks - XFS_IALLOC_SPACE_RES(mp)); in xfs_create()
1049 ASSERT(error != -ENOSPC); in xfs_create()
1052 xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); in xfs_create()
1053 xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); in xfs_create()
1056 error = xfs_dir_init(tp, ip, dp); in xfs_create()
1060 xfs_bumplink(tp, dp); in xfs_create()
1069 xfs_trans_set_sync(tp); in xfs_create()
1076 xfs_qm_vop_create_dqattach(tp, ip, udqp, gdqp, pdqp); in xfs_create()
1078 error = xfs_trans_commit(tp); in xfs_create()
1090 xfs_trans_cancel(tp); in xfs_create()
1118 struct xfs_mount *mp = dp->i_mount; in xfs_create_tmpfile()
1120 struct xfs_trans *tp = NULL; in xfs_create_tmpfile() local
1131 return -EIO; in xfs_create_tmpfile()
1148 tres = &M_RES(mp)->tr_create_tmpfile; in xfs_create_tmpfile()
1151 &tp); in xfs_create_tmpfile()
1155 error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); in xfs_create_tmpfile()
1157 error = xfs_init_new_inode(idmap, tp, dp, ino, mode, in xfs_create_tmpfile()
1163 xfs_trans_set_sync(tp); in xfs_create_tmpfile()
1170 xfs_qm_vop_create_dqattach(tp, ip, udqp, gdqp, pdqp); in xfs_create_tmpfile()
1172 error = xfs_iunlink(tp, ip); in xfs_create_tmpfile()
1176 error = xfs_trans_commit(tp); in xfs_create_tmpfile()
1188 xfs_trans_cancel(tp); in xfs_create_tmpfile()
1213 xfs_mount_t *mp = tdp->i_mount; in xfs_link()
1214 xfs_trans_t *tp; in xfs_link() local
1220 ASSERT(!S_ISDIR(VFS_I(sip)->i_mode)); in xfs_link()
1223 return -EIO; in xfs_link()
1233 resblks = XFS_LINK_SPACE_RES(mp, target_name->len); in xfs_link()
1234 error = xfs_trans_alloc_dir(tdp, &M_RES(mp)->tr_link, sip, &resblks, in xfs_link()
1235 &tp, &nospace_error); in xfs_link()
1240 * If we are using project inheritance, we only allow hard link in xfs_link()
1244 if (unlikely((tdp->i_diflags & XFS_DIFLAG_PROJINHERIT) && in xfs_link()
1245 tdp->i_projid != sip->i_projid)) { in xfs_link()
1250 * to these "project-less" inodes because userspace in xfs_link()
1254 if (!special_file(VFS_I(sip)->i_mode) || in xfs_link()
1255 sip->i_projid != 0) { in xfs_link()
1256 error = -EXDEV; in xfs_link()
1262 error = xfs_dir_canenter(tp, tdp, target_name); in xfs_link()
1268 * Handle initial link state of O_TMPFILE inode in xfs_link()
1270 if (VFS_I(sip)->i_nlink == 0) { in xfs_link()
1273 pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, sip->i_ino)); in xfs_link()
1274 error = xfs_iunlink_remove(tp, pag, sip); in xfs_link()
1280 error = xfs_dir_createname(tp, tdp, target_name, sip->i_ino, in xfs_link()
1284 xfs_trans_ichgtime(tp, tdp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); in xfs_link()
1285 xfs_trans_log_inode(tp, tdp, XFS_ILOG_CORE); in xfs_link()
1287 xfs_bumplink(tp, sip); in xfs_link()
1291 * link transaction goes to disk before returning to in xfs_link()
1295 xfs_trans_set_sync(tp); in xfs_link()
1297 return xfs_trans_commit(tp); in xfs_link()
1300 xfs_trans_cancel(tp); in xfs_link()
1302 if (error == -ENOSPC && nospace_error) in xfs_link()
1319 if (dfork->if_bytes == 0 && cfork->if_bytes == 0) in xfs_itruncate_clear_reflink_flags()
1320 ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_itruncate_clear_reflink_flags()
1321 if (cfork->if_bytes == 0) in xfs_itruncate_clear_reflink_flags()
1354 struct xfs_mount *mp = ip->i_mount; in xfs_itruncate_extents_flags()
1355 struct xfs_trans *tp = *tpp; in xfs_itruncate_extents_flags() local
1361 ASSERT(!atomic_read(&VFS_I(ip)->i_count) || in xfs_itruncate_extents_flags()
1364 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); in xfs_itruncate_extents_flags()
1365 ASSERT(ip->i_itemp != NULL); in xfs_itruncate_extents_flags()
1366 ASSERT(ip->i_itemp->ili_lock_flags == 0); in xfs_itruncate_extents_flags()
1389 unmap_len = XFS_MAX_FILEOFF - first_unmap_block + 1; in xfs_itruncate_extents_flags()
1391 ASSERT(tp->t_highest_agno == NULLAGNUMBER); in xfs_itruncate_extents_flags()
1392 error = __xfs_bunmapi(tp, ip, first_unmap_block, &unmap_len, in xfs_itruncate_extents_flags()
1398 error = xfs_defer_finish(&tp); in xfs_itruncate_extents_flags()
1405 error = xfs_reflink_cancel_cow_blocks(ip, &tp, in xfs_itruncate_extents_flags()
1414 * Always re-log the inode so that our permanent transaction can keep in xfs_itruncate_extents_flags()
1417 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_itruncate_extents_flags()
1422 *tpp = tp; in xfs_itruncate_extents_flags()
1430 xfs_mount_t *mp = ip->i_mount; in xfs_release()
1433 if (!S_ISREG(VFS_I(ip)->i_mode) || (VFS_I(ip)->i_mode == 0)) in xfs_release()
1436 /* If this is a read-only mount, don't do this (would generate I/O) */ in xfs_release()
1448 * truncate down, buffered (re-)write (delalloc), followed by in xfs_release()
1456 if (ip->i_delayed_blks > 0) { in xfs_release()
1457 error = filemap_flush(VFS_I(ip)->i_mapping); in xfs_release()
1464 if (VFS_I(ip)->i_nlink == 0) in xfs_release()
1499 if (ip->i_delayed_blks) in xfs_release()
1517 struct xfs_mount *mp = ip->i_mount; in xfs_inactive_truncate()
1518 struct xfs_trans *tp; in xfs_inactive_truncate() local
1521 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); in xfs_inactive_truncate()
1527 xfs_trans_ijoin(tp, ip, 0); in xfs_inactive_truncate()
1534 ip->i_disk_size = 0; in xfs_inactive_truncate()
1535 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_inactive_truncate()
1537 error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, 0); in xfs_inactive_truncate()
1541 ASSERT(ip->i_df.if_nextents == 0); in xfs_inactive_truncate()
1543 error = xfs_trans_commit(tp); in xfs_inactive_truncate()
1551 xfs_trans_cancel(tp); in xfs_inactive_truncate()
1566 struct xfs_mount *mp = ip->i_mount; in xfs_inactive_ifree()
1567 struct xfs_trans *tp; in xfs_inactive_ifree() local
1571 * We try to use a per-AG reservation for any block needed by the finobt in xfs_inactive_ifree()
1572 * tree, but as the finobt feature predates the per-AG reservation in xfs_inactive_ifree()
1581 if (unlikely(mp->m_finobt_nores)) { in xfs_inactive_ifree()
1582 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ifree, in xfs_inactive_ifree()
1584 &tp); in xfs_inactive_ifree()
1586 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ifree, 0, 0, 0, &tp); in xfs_inactive_ifree()
1589 if (error == -ENOSPC) { in xfs_inactive_ifree()
1610 * operations - we freed the inode and hence reallocation is required in xfs_inactive_ifree()
1620 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); in xfs_inactive_ifree()
1622 error = xfs_ifree(tp, ip); in xfs_inactive_ifree()
1635 xfs_trans_cancel(tp); in xfs_inactive_ifree()
1642 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_ICOUNT, -1); in xfs_inactive_ifree()
1644 return xfs_trans_commit(tp); in xfs_inactive_ifree()
1648 * Returns true if we need to update the on-disk metadata before we can free
1649 * the memory used by this inode. Updates include freeing post-eof
1657 struct xfs_mount *mp = ip->i_mount; in xfs_inode_needs_inactive()
1664 if (VFS_I(ip)->i_mode == 0) in xfs_inode_needs_inactive()
1668 * If this is a read-only mount, don't do this (would generate I/O) in xfs_inode_needs_inactive()
1671 if (xfs_is_readonly(mp) && !xlog_recovery_needed(mp->m_log)) in xfs_inode_needs_inactive()
1683 if (cow_ifp && cow_ifp->if_bytes > 0) in xfs_inode_needs_inactive()
1687 if (VFS_I(ip)->i_nlink == 0) in xfs_inode_needs_inactive()
1691 * This file isn't being freed, so check if there are post-eof blocks in xfs_inode_needs_inactive()
1706 * now be truncated. Also, we clear all of the read-ahead state
1721 if (VFS_I(ip)->i_mode == 0) { in xfs_inactive()
1722 ASSERT(ip->i_df.if_broot_bytes == 0); in xfs_inactive()
1726 mp = ip->i_mount; in xfs_inactive()
1730 * If this is a read-only mount, don't do this (would generate I/O) in xfs_inactive()
1733 if (xfs_is_readonly(mp) && !xlog_recovery_needed(mp->m_log)) in xfs_inactive()
1747 if (VFS_I(ip)->i_nlink != 0) { in xfs_inactive()
1759 if (S_ISREG(VFS_I(ip)->i_mode) && in xfs_inactive()
1760 (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 || in xfs_inactive()
1780 if (S_ISLNK(VFS_I(ip)->i_mode)) in xfs_inactive()
1790 * attribute fork. If also blows away the in-core attribute fork. in xfs_inactive()
1798 ASSERT(ip->i_forkoff == 0); in xfs_inactive()
1815 * In-Core Unlinked List Lookups
1820 * file descriptor but not linked from anywhere in the on-disk directory tree
1822 * maintains links to these inodes so that on-disk metadata are consistent.
1824 * XFS implements a per-AG on-disk hash table of unlinked inodes. The AGI
1827 * singly-linked list causes scaling problems in the iunlink remove function
1831 * Hence we keep an in-memory double linked list to link each inode on an
1861 ip = radix_tree_lookup(&pag->pag_ici_root, agino); in xfs_iunlink_lookup()
1872 if (WARN_ON_ONCE(!ip->i_ino)) { in xfs_iunlink_lookup()
1882 * Update the prev pointer of the next agino. Returns -ENOLINK if the inode
1899 return -ENOLINK; in xfs_iunlink_update_backref()
1901 ip->i_prev_unlinked = prev_agino; in xfs_iunlink_update_backref()
1911 struct xfs_trans *tp, in xfs_iunlink_update_bucket() argument
1917 struct xfs_agi *agi = agibp->b_addr; in xfs_iunlink_update_bucket()
1923 old_value = be32_to_cpu(agi->agi_unlinked[bucket_index]); in xfs_iunlink_update_bucket()
1924 trace_xfs_iunlink_update_bucket(tp->t_mountp, pag->pag_agno, bucket_index, in xfs_iunlink_update_bucket()
1934 return -EFSCORRUPTED; in xfs_iunlink_update_bucket()
1937 agi->agi_unlinked[bucket_index] = cpu_to_be32(new_agino); in xfs_iunlink_update_bucket()
1940 xfs_trans_log_buf(tp, agibp, offset, offset + sizeof(xfs_agino_t) - 1); in xfs_iunlink_update_bucket()
1951 struct xfs_trans *tp, in xfs_iunlink_reload_next() argument
1956 struct xfs_perag *pag = agibp->b_pag; in xfs_iunlink_reload_next()
1957 struct xfs_mount *mp = pag->pag_mount; in xfs_iunlink_reload_next()
1966 next_ip = radix_tree_lookup(&pag->pag_ici_root, next_agino); in xfs_iunlink_reload_next()
1973 next_agino, pag->pag_agno); in xfs_iunlink_reload_next()
1981 ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, next_agino); in xfs_iunlink_reload_next()
1982 error = xfs_iget(mp, tp, ino, XFS_IGET_UNTRUSTED, 0, &next_ip); in xfs_iunlink_reload_next()
1987 if (VFS_I(next_ip)->i_nlink != 0) { in xfs_iunlink_reload_next()
1988 error = -EFSCORRUPTED; in xfs_iunlink_reload_next()
1992 next_ip->i_prev_unlinked = prev_agino; in xfs_iunlink_reload_next()
1995 ASSERT(!(VFS_I(next_ip)->i_state & I_DONTCACHE)); in xfs_iunlink_reload_next()
2004 struct xfs_trans *tp, in xfs_iunlink_insert_inode() argument
2009 struct xfs_mount *mp = tp->t_mountp; in xfs_iunlink_insert_inode()
2010 struct xfs_agi *agi = agibp->b_addr; in xfs_iunlink_insert_inode()
2012 xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ip->i_ino); in xfs_iunlink_insert_inode()
2021 next_agino = be32_to_cpu(agi->agi_unlinked[bucket_index]); in xfs_iunlink_insert_inode()
2025 return -EFSCORRUPTED; in xfs_iunlink_insert_inode()
2033 if (error == -ENOLINK) in xfs_iunlink_insert_inode()
2034 error = xfs_iunlink_reload_next(tp, agibp, agino, next_agino); in xfs_iunlink_insert_inode()
2043 error = xfs_iunlink_log_inode(tp, ip, pag, next_agino); in xfs_iunlink_insert_inode()
2046 ip->i_next_unlinked = next_agino; in xfs_iunlink_insert_inode()
2050 ip->i_prev_unlinked = NULLAGINO; in xfs_iunlink_insert_inode()
2051 return xfs_iunlink_update_bucket(tp, pag, agibp, bucket_index, agino); in xfs_iunlink_insert_inode()
2055 * This is called when the inode's link count has gone to 0 or we are creating
2058 * We place the on-disk inode on a list in the AGI. It will be pulled from this
2063 struct xfs_trans *tp, in xfs_iunlink() argument
2066 struct xfs_mount *mp = tp->t_mountp; in xfs_iunlink()
2071 ASSERT(VFS_I(ip)->i_nlink == 0); in xfs_iunlink()
2072 ASSERT(VFS_I(ip)->i_mode != 0); in xfs_iunlink()
2075 pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino)); in xfs_iunlink()
2078 error = xfs_read_agi(pag, tp, &agibp); in xfs_iunlink()
2082 error = xfs_iunlink_insert_inode(tp, pag, agibp, ip); in xfs_iunlink()
2090 struct xfs_trans *tp, in xfs_iunlink_remove_inode() argument
2095 struct xfs_mount *mp = tp->t_mountp; in xfs_iunlink_remove_inode()
2096 struct xfs_agi *agi = agibp->b_addr; in xfs_iunlink_remove_inode()
2097 xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ip->i_ino); in xfs_iunlink_remove_inode()
2108 head_agino = be32_to_cpu(agi->agi_unlinked[bucket_index]); in xfs_iunlink_remove_inode()
2112 return -EFSCORRUPTED; in xfs_iunlink_remove_inode()
2120 error = xfs_iunlink_log_inode(tp, ip, pag, NULLAGINO); in xfs_iunlink_remove_inode()
2128 error = xfs_iunlink_update_backref(pag, ip->i_prev_unlinked, in xfs_iunlink_remove_inode()
2129 ip->i_next_unlinked); in xfs_iunlink_remove_inode()
2130 if (error == -ENOLINK) in xfs_iunlink_remove_inode()
2131 error = xfs_iunlink_reload_next(tp, agibp, ip->i_prev_unlinked, in xfs_iunlink_remove_inode()
2132 ip->i_next_unlinked); in xfs_iunlink_remove_inode()
2139 prev_ip = xfs_iunlink_lookup(pag, ip->i_prev_unlinked); in xfs_iunlink_remove_inode()
2141 return -EFSCORRUPTED; in xfs_iunlink_remove_inode()
2143 error = xfs_iunlink_log_inode(tp, prev_ip, pag, in xfs_iunlink_remove_inode()
2144 ip->i_next_unlinked); in xfs_iunlink_remove_inode()
2145 prev_ip->i_next_unlinked = ip->i_next_unlinked; in xfs_iunlink_remove_inode()
2148 error = xfs_iunlink_update_bucket(tp, pag, agibp, bucket_index, in xfs_iunlink_remove_inode()
2149 ip->i_next_unlinked); in xfs_iunlink_remove_inode()
2152 ip->i_next_unlinked = NULLAGINO; in xfs_iunlink_remove_inode()
2153 ip->i_prev_unlinked = 0; in xfs_iunlink_remove_inode()
2158 * Pull the on-disk inode from the AGI unlinked list.
2162 struct xfs_trans *tp, in xfs_iunlink_remove() argument
2172 error = xfs_read_agi(pag, tp, &agibp); in xfs_iunlink_remove()
2176 return xfs_iunlink_remove_inode(tp, pag, agibp, ip); in xfs_iunlink_remove()
2190 struct xfs_mount *mp = pag->pag_mount; in xfs_ifree_mark_inode_stale()
2196 ip = radix_tree_lookup(&pag->pag_ici_root, XFS_INO_TO_AGINO(mp, inum)); in xfs_ifree_mark_inode_stale()
2210 spin_lock(&ip->i_flags_lock); in xfs_ifree_mark_inode_stale()
2211 if (ip->i_ino != inum || __xfs_iflags_test(ip, XFS_ISTALE)) in xfs_ifree_mark_inode_stale()
2222 spin_unlock(&ip->i_flags_lock); in xfs_ifree_mark_inode_stale()
2228 ip->i_flags |= XFS_ISTALE; in xfs_ifree_mark_inode_stale()
2235 iip = ip->i_itemp; in xfs_ifree_mark_inode_stale()
2237 ASSERT(!list_empty(&iip->ili_item.li_bio_list)); in xfs_ifree_mark_inode_stale()
2238 ASSERT(iip->ili_last_fields); in xfs_ifree_mark_inode_stale()
2248 if (!iip || list_empty(&iip->ili_item.li_bio_list)) in xfs_ifree_mark_inode_stale()
2252 spin_unlock(&ip->i_flags_lock); in xfs_ifree_mark_inode_stale()
2256 spin_lock(&iip->ili_lock); in xfs_ifree_mark_inode_stale()
2257 iip->ili_last_fields = iip->ili_fields; in xfs_ifree_mark_inode_stale()
2258 iip->ili_fields = 0; in xfs_ifree_mark_inode_stale()
2259 iip->ili_fsync_fields = 0; in xfs_ifree_mark_inode_stale()
2260 spin_unlock(&iip->ili_lock); in xfs_ifree_mark_inode_stale()
2261 ASSERT(iip->ili_last_fields); in xfs_ifree_mark_inode_stale()
2271 spin_unlock(&ip->i_flags_lock); in xfs_ifree_mark_inode_stale()
2277 * inodes that are in memory - they all must be marked stale and attached to
2282 struct xfs_trans *tp, in xfs_ifree_cluster() argument
2287 struct xfs_mount *mp = free_ip->i_mount; in xfs_ifree_cluster()
2291 xfs_ino_t inum = xic->first_ino; in xfs_ifree_cluster()
2297 nbufs = igeo->ialloc_blks / igeo->blocks_per_cluster; in xfs_ifree_cluster()
2299 for (j = 0; j < nbufs; j++, inum += igeo->inodes_per_cluster) { in xfs_ifree_cluster()
2305 ioffset = inum - xic->first_ino; in xfs_ifree_cluster()
2306 if ((xic->alloc & XFS_INOBT_MASK(ioffset)) == 0) { in xfs_ifree_cluster()
2307 ASSERT(ioffset % igeo->inodes_per_cluster == 0); in xfs_ifree_cluster()
2319 * If we scan the in-memory inodes first, then buffer IO can in xfs_ifree_cluster()
2323 error = xfs_trans_get_buf(tp, mp->m_ddev_targp, blkno, in xfs_ifree_cluster()
2324 mp->m_bsize * igeo->blocks_per_cluster, in xfs_ifree_cluster()
2352 bp->b_flags |= XBF_DONE; in xfs_ifree_cluster()
2353 bp->b_ops = &xfs_inode_buf_ops; in xfs_ifree_cluster()
2360 for (i = 0; i < igeo->inodes_per_cluster; i++) in xfs_ifree_cluster()
2363 xfs_trans_stale_inode_buf(tp, bp); in xfs_ifree_cluster()
2364 xfs_trans_binval(tp, bp); in xfs_ifree_cluster()
2374 * The on-disk copy of the inode will have been added to the list of unlinked
2380 struct xfs_trans *tp, in xfs_ifree() argument
2383 struct xfs_mount *mp = ip->i_mount; in xfs_ifree()
2386 struct xfs_inode_log_item *iip = ip->i_itemp; in xfs_ifree()
2390 ASSERT(VFS_I(ip)->i_nlink == 0); in xfs_ifree()
2391 ASSERT(ip->i_df.if_nextents == 0); in xfs_ifree()
2392 ASSERT(ip->i_disk_size == 0 || !S_ISREG(VFS_I(ip)->i_mode)); in xfs_ifree()
2393 ASSERT(ip->i_nblocks == 0); in xfs_ifree()
2395 pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino)); in xfs_ifree()
2400 * makes the AGI lock -> unlinked list modification order the same as in xfs_ifree()
2403 error = xfs_difree(tp, pag, ip->i_ino, &xic); in xfs_ifree()
2407 error = xfs_iunlink_remove(tp, pag, ip); in xfs_ifree()
2412 * Free any local-format data sitting around before we reset the in xfs_ifree()
2416 if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL) { in xfs_ifree()
2417 kmem_free(ip->i_df.if_u1.if_data); in xfs_ifree()
2418 ip->i_df.if_u1.if_data = NULL; in xfs_ifree()
2419 ip->i_df.if_bytes = 0; in xfs_ifree()
2422 VFS_I(ip)->i_mode = 0; /* mark incore inode as free */ in xfs_ifree()
2423 ip->i_diflags = 0; in xfs_ifree()
2424 ip->i_diflags2 = mp->m_ino_geo.new_diflags2; in xfs_ifree()
2425 ip->i_forkoff = 0; /* mark the attr fork not in use */ in xfs_ifree()
2426 ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS; in xfs_ifree()
2431 spin_lock(&iip->ili_lock); in xfs_ifree()
2432 iip->ili_fields &= ~(XFS_ILOG_AOWNER | XFS_ILOG_DOWNER); in xfs_ifree()
2433 spin_unlock(&iip->ili_lock); in xfs_ifree()
2439 VFS_I(ip)->i_generation++; in xfs_ifree()
2440 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_ifree()
2443 error = xfs_ifree_cluster(tp, pag, ip, &xic); in xfs_ifree()
2463 xfs_log_force_seq(ip->i_mount, ip->i_itemp->ili_commit_seq, 0, NULL); in xfs_iunpin()
2471 wait_queue_head_t *wq = bit_waitqueue(&ip->i_flags, __XFS_IPINNED_BIT); in __xfs_iunpin_wait()
2472 DEFINE_WAIT_BIT(wait, &ip->i_flags, __XFS_IPINNED_BIT); in __xfs_iunpin_wait()
2494 * and dropping the link count on the inode. Removing the directory entry can
2495 * result in locking an AGF (directory blocks were freed) and removing a link
2500 * locking - inode allocation locks the AGI, then can allocate a new extent for
2510 * freeing. Therefore we must drop the link counts before we remove the
2513 * This is still safe from a transactional point of view - it is not until we
2516 * entry and drop the link count in the first transaction of the remove
2525 xfs_mount_t *mp = dp->i_mount; in xfs_remove()
2526 xfs_trans_t *tp = NULL; in xfs_remove() local
2527 int is_dir = S_ISDIR(VFS_I(ip)->i_mode); in xfs_remove()
2535 return -EIO; in xfs_remove()
2557 error = xfs_trans_alloc_dir(dp, &M_RES(mp)->tr_remove, ip, &resblks, in xfs_remove()
2558 &tp, &dontcare); in xfs_remove()
2560 ASSERT(error != -ENOSPC); in xfs_remove()
2568 ASSERT(VFS_I(ip)->i_nlink >= 2); in xfs_remove()
2569 if (VFS_I(ip)->i_nlink != 2) { in xfs_remove()
2570 error = -ENOTEMPTY; in xfs_remove()
2574 error = -ENOTEMPTY; in xfs_remove()
2578 /* Drop the link from ip's "..". */ in xfs_remove()
2579 error = xfs_droplink(tp, dp); in xfs_remove()
2583 /* Drop the "." link from ip to self. */ in xfs_remove()
2584 error = xfs_droplink(tp, ip); in xfs_remove()
2590 * directory to eliminate back-references to inodes that may in xfs_remove()
2594 if (dp->i_ino != tp->t_mountp->m_sb.sb_rootino) { in xfs_remove()
2595 error = xfs_dir_replace(tp, ip, &xfs_name_dotdot, in xfs_remove()
2596 tp->t_mountp->m_sb.sb_rootino, 0); in xfs_remove()
2602 * When removing a non-directory we need to log the parent in xfs_remove()
2606 xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); in xfs_remove()
2608 xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); in xfs_remove()
2610 /* Drop the link from dp to ip. */ in xfs_remove()
2611 error = xfs_droplink(tp, ip); in xfs_remove()
2615 error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks); in xfs_remove()
2617 ASSERT(error != -ENOENT); in xfs_remove()
2627 xfs_trans_set_sync(tp); in xfs_remove()
2629 error = xfs_trans_commit(tp); in xfs_remove()
2639 xfs_trans_cancel(tp); in xfs_remove()
2686 if (i_tab[j]->i_ino < i_tab[j-1]->i_ino) { in xfs_sort_for_rename()
2688 i_tab[j] = i_tab[j-1]; in xfs_sort_for_rename()
2689 i_tab[j-1] = temp; in xfs_sort_for_rename()
2697 struct xfs_trans *tp) in xfs_finish_rename() argument
2703 if (xfs_has_wsync(tp->t_mountp) || xfs_has_dirsync(tp->t_mountp)) in xfs_finish_rename()
2704 xfs_trans_set_sync(tp); in xfs_finish_rename()
2706 return xfs_trans_commit(tp); in xfs_finish_rename()
2716 struct xfs_trans *tp, in xfs_cross_rename() argument
2731 error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres); in xfs_cross_rename()
2736 error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres); in xfs_cross_rename()
2742 * update the respective ".." entries (and link counts) to match the new in xfs_cross_rename()
2748 if (S_ISDIR(VFS_I(ip2)->i_mode)) { in xfs_cross_rename()
2749 error = xfs_dir_replace(tp, ip2, &xfs_name_dotdot, in xfs_cross_rename()
2750 dp1->i_ino, spaceres); in xfs_cross_rename()
2755 if (!S_ISDIR(VFS_I(ip1)->i_mode)) { in xfs_cross_rename()
2756 error = xfs_droplink(tp, dp2); in xfs_cross_rename()
2759 xfs_bumplink(tp, dp1); in xfs_cross_rename()
2772 if (S_ISDIR(VFS_I(ip1)->i_mode)) { in xfs_cross_rename()
2773 error = xfs_dir_replace(tp, ip1, &xfs_name_dotdot, in xfs_cross_rename()
2774 dp2->i_ino, spaceres); in xfs_cross_rename()
2779 if (!S_ISDIR(VFS_I(ip2)->i_mode)) { in xfs_cross_rename()
2780 error = xfs_droplink(tp, dp1); in xfs_cross_rename()
2783 xfs_bumplink(tp, dp2); in xfs_cross_rename()
2798 xfs_trans_ichgtime(tp, ip1, ip1_flags); in xfs_cross_rename()
2799 xfs_trans_log_inode(tp, ip1, XFS_ILOG_CORE); in xfs_cross_rename()
2802 xfs_trans_ichgtime(tp, ip2, ip2_flags); in xfs_cross_rename()
2803 xfs_trans_log_inode(tp, ip2, XFS_ILOG_CORE); in xfs_cross_rename()
2806 xfs_trans_ichgtime(tp, dp2, dp2_flags); in xfs_cross_rename()
2807 xfs_trans_log_inode(tp, dp2, XFS_ILOG_CORE); in xfs_cross_rename()
2809 xfs_trans_ichgtime(tp, dp1, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); in xfs_cross_rename()
2810 xfs_trans_log_inode(tp, dp1, XFS_ILOG_CORE); in xfs_cross_rename()
2811 return xfs_finish_rename(tp); in xfs_cross_rename()
2814 xfs_trans_cancel(tp); in xfs_cross_rename()
2842 name.name = src_name->name; in xfs_rename_alloc_whiteout()
2843 name.len = src_name->len; in xfs_rename_alloc_whiteout()
2858 VFS_I(tmpfile)->i_state |= I_LINKABLE; in xfs_rename_alloc_whiteout()
2878 struct xfs_mount *mp = src_dp->i_mount; in xfs_rename()
2879 struct xfs_trans *tp; in xfs_rename() local
2885 bool src_is_directory = S_ISDIR(VFS_I(src_ip)->i_mode); in xfs_rename()
2893 return -EINVAL; in xfs_rename()
2907 src_name->type = XFS_DIR3_FT_CHRDEV; in xfs_rename()
2915 spaceres = XFS_RENAME_SPACE_RES(mp, target_name->len); in xfs_rename()
2916 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, spaceres, 0, 0, &tp); in xfs_rename()
2917 if (error == -ENOSPC) { in xfs_rename()
2920 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, 0, 0, 0, in xfs_rename()
2921 &tp); in xfs_rename()
2946 xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL); in xfs_rename()
2948 xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL); in xfs_rename()
2949 xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL); in xfs_rename()
2951 xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL); in xfs_rename()
2953 xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL); in xfs_rename()
2960 if (unlikely((target_dp->i_diflags & XFS_DIFLAG_PROJINHERIT) && in xfs_rename()
2961 target_dp->i_projid != src_ip->i_projid)) { in xfs_rename()
2962 error = -EXDEV; in xfs_rename()
2968 return xfs_cross_rename(tp, src_dp, src_name, src_ip, in xfs_rename()
2979 error = xfs_trans_reserve_quota_nblks(tp, target_dp, spaceres, in xfs_rename()
2981 if (error == -EDQUOT || error == -ENOSPC) { in xfs_rename()
2983 xfs_trans_cancel(tp); in xfs_rename()
3007 error = xfs_dir_canenter(tp, target_dp, target_name); in xfs_rename()
3016 if (S_ISDIR(VFS_I(target_ip)->i_mode) && in xfs_rename()
3018 (VFS_I(target_ip)->i_nlink > 2))) { in xfs_rename()
3019 error = -EEXIST; in xfs_rename()
3037 (VFS_I(target_ip)->i_nlink == 1 || src_is_directory))) { in xfs_rename()
3042 XFS_INO_TO_AGNO(mp, inodes[i]->i_ino)); in xfs_rename()
3043 error = xfs_read_agi(pag, tp, &bp); in xfs_rename()
3057 * For whiteouts, we need to bump the link count on the whiteout in xfs_rename()
3058 * inode. After this point, we have a real link, clear the tmpfile in xfs_rename()
3065 ASSERT(VFS_I(wip)->i_nlink == 0); in xfs_rename()
3067 pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, wip->i_ino)); in xfs_rename()
3068 error = xfs_iunlink_remove(tp, pag, wip); in xfs_rename()
3073 xfs_bumplink(tp, wip); in xfs_rename()
3074 VFS_I(wip)->i_state &= ~I_LINKABLE; in xfs_rename()
3083 * directories, adjust the target directory link count in xfs_rename()
3086 error = xfs_dir_createname(tp, target_dp, target_name, in xfs_rename()
3087 src_ip->i_ino, spaceres); in xfs_rename()
3091 xfs_trans_ichgtime(tp, target_dp, in xfs_rename()
3095 xfs_bumplink(tp, target_dp); in xfs_rename()
3099 * Link the source inode under the target name. in xfs_rename()
3107 error = xfs_dir_replace(tp, target_dp, target_name, in xfs_rename()
3108 src_ip->i_ino, spaceres); in xfs_rename()
3112 xfs_trans_ichgtime(tp, target_dp, in xfs_rename()
3116 * Decrement the link count on the target since the target in xfs_rename()
3119 error = xfs_droplink(tp, target_ip); in xfs_rename()
3125 * Drop the link from the old "." entry. in xfs_rename()
3127 error = xfs_droplink(tp, target_ip); in xfs_rename()
3141 error = xfs_dir_replace(tp, src_ip, &xfs_name_dotdot, in xfs_rename()
3142 target_dp->i_ino, spaceres); in xfs_rename()
3143 ASSERT(error != -EEXIST); in xfs_rename()
3155 xfs_trans_ichgtime(tp, src_ip, XFS_ICHGTIME_CHG); in xfs_rename()
3156 xfs_trans_log_inode(tp, src_ip, XFS_ILOG_CORE); in xfs_rename()
3159 * Adjust the link count on src_dp. This is necessary when in xfs_rename()
3166 * Decrement link count on src_directory since the in xfs_rename()
3169 error = xfs_droplink(tp, src_dp); in xfs_rename()
3180 error = xfs_dir_replace(tp, src_dp, src_name, wip->i_ino, in xfs_rename()
3183 error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino, in xfs_rename()
3189 xfs_trans_ichgtime(tp, src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); in xfs_rename()
3190 xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE); in xfs_rename()
3192 xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE); in xfs_rename()
3194 error = xfs_finish_rename(tp); in xfs_rename()
3200 xfs_trans_cancel(tp); in xfs_rename()
3204 if (error == -ENOSPC && nospace_error) in xfs_rename()
3214 struct xfs_inode_log_item *iip = ip->i_itemp; in xfs_iflush()
3216 struct xfs_mount *mp = ip->i_mount; in xfs_iflush()
3221 ASSERT(ip->i_df.if_format != XFS_DINODE_FMT_BTREE || in xfs_iflush()
3222 ip->i_df.if_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)); in xfs_iflush()
3223 ASSERT(iip->ili_item.li_buf == bp); in xfs_iflush()
3225 dip = xfs_buf_offset(bp, ip->i_imap.im_boffset); in xfs_iflush()
3233 error = -EFSCORRUPTED; in xfs_iflush()
3234 if (XFS_TEST_ERROR(dip->di_magic != cpu_to_be16(XFS_DINODE_MAGIC), in xfs_iflush()
3238 __func__, ip->i_ino, be16_to_cpu(dip->di_magic), dip); in xfs_iflush()
3241 if (S_ISREG(VFS_I(ip)->i_mode)) { in xfs_iflush()
3243 ip->i_df.if_format != XFS_DINODE_FMT_EXTENTS && in xfs_iflush()
3244 ip->i_df.if_format != XFS_DINODE_FMT_BTREE, in xfs_iflush()
3248 __func__, ip->i_ino, ip); in xfs_iflush()
3251 } else if (S_ISDIR(VFS_I(ip)->i_mode)) { in xfs_iflush()
3253 ip->i_df.if_format != XFS_DINODE_FMT_EXTENTS && in xfs_iflush()
3254 ip->i_df.if_format != XFS_DINODE_FMT_BTREE && in xfs_iflush()
3255 ip->i_df.if_format != XFS_DINODE_FMT_LOCAL, in xfs_iflush()
3259 __func__, ip->i_ino, ip); in xfs_iflush()
3263 if (XFS_TEST_ERROR(ip->i_df.if_nextents + xfs_ifork_nextents(&ip->i_af) > in xfs_iflush()
3264 ip->i_nblocks, mp, XFS_ERRTAG_IFLUSH_5)) { in xfs_iflush()
3268 __func__, ip->i_ino, in xfs_iflush()
3269 ip->i_df.if_nextents + xfs_ifork_nextents(&ip->i_af), in xfs_iflush()
3270 ip->i_nblocks, ip); in xfs_iflush()
3273 if (XFS_TEST_ERROR(ip->i_forkoff > mp->m_sb.sb_inodesize, in xfs_iflush()
3277 __func__, ip->i_ino, ip->i_forkoff, ip); in xfs_iflush()
3290 ip->i_flushiter++; in xfs_iflush()
3296 if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL && in xfs_iflush()
3300 ip->i_af.if_format == XFS_DINODE_FMT_LOCAL && in xfs_iflush()
3305 * Copy the dirty parts of the inode into the on-disk inode. We always in xfs_iflush()
3309 xfs_inode_to_disk(ip, dip, iip->ili_item.li_lsn); in xfs_iflush()
3313 if (ip->i_flushiter == DI_MAX_FLUSH) in xfs_iflush()
3314 ip->i_flushiter = 0; in xfs_iflush()
3327 * after re-logging only part of it, and in the face of a crash we in xfs_iflush()
3339 spin_lock(&iip->ili_lock); in xfs_iflush()
3340 iip->ili_last_fields = iip->ili_fields; in xfs_iflush()
3341 iip->ili_fields = 0; in xfs_iflush()
3342 iip->ili_fsync_fields = 0; in xfs_iflush()
3343 spin_unlock(&iip->ili_lock); in xfs_iflush()
3349 xfs_trans_ail_copy_lsn(mp->m_ail, &iip->ili_flush_lsn, in xfs_iflush()
3350 &iip->ili_item.li_lsn); in xfs_iflush()
3358 * Non-blocking flush of dirty inode metadata into the backing buffer.
3365 * buffer and release it. If no inodes are flushed, -EAGAIN will be returned and
3374 struct xfs_mount *mp = bp->b_mount; in xfs_iflush_cluster()
3385 list_for_each_entry_safe(lip, n, &bp->b_li_list, li_bio_list) { in xfs_iflush_cluster()
3387 ip = iip->ili_inode; in xfs_iflush_cluster()
3404 spin_lock(&ip->i_flags_lock); in xfs_iflush_cluster()
3407 spin_unlock(&ip->i_flags_lock); in xfs_iflush_cluster()
3418 spin_unlock(&ip->i_flags_lock); in xfs_iflush_cluster()
3422 spin_unlock(&ip->i_flags_lock); in xfs_iflush_cluster()
3431 if (xlog_is_shutdown(mp->m_log)) { in xfs_iflush_cluster()
3435 error = -EIO; in xfs_iflush_cluster()
3468 bp->b_flags |= XBF_ASYNC; in xfs_iflush_cluster()
3474 return -EAGAIN; in xfs_iflush_cluster()
3502 seq = ip->i_itemp->ili_commit_seq; in xfs_log_force_inode()
3507 return xfs_log_force_seq(ip->i_mount, seq, XFS_LOG_SYNC, NULL); in xfs_log_force_inode()
3543 if (error == -EWOULDBLOCK) in xfs_iolock_two_inodes_and_break_layout()
3557 if (error == -EWOULDBLOCK) in xfs_iolock_two_inodes_and_break_layout()
3574 if (ip1->i_ino > ip2->i_ino) in xfs_mmaplock_two_inodes_and_break_dax_layout()
3599 page = dax_layout_busy_page(VFS_I(ip2)->i_mapping); in xfs_mmaplock_two_inodes_and_break_dax_layout()
3633 filemap_invalidate_lock_two(VFS_I(ip1)->i_mapping, in xfs_ilock2_io_mmap()
3634 VFS_I(ip2)->i_mapping); in xfs_ilock2_io_mmap()
3650 filemap_invalidate_unlock_two(VFS_I(ip1)->i_mapping, in xfs_iunlock2_io_mmap()
3651 VFS_I(ip2)->i_mapping); in xfs_iunlock2_io_mmap()
3677 * the link count cannot change, either by taking ILOCK_SHARED or otherwise
3682 struct xfs_trans *tp, in xfs_inode_reload_unlinked_bucket() argument
3685 struct xfs_mount *mp = tp->t_mountp; in xfs_inode_reload_unlinked_bucket()
3689 xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, ip->i_ino); in xfs_inode_reload_unlinked_bucket()
3690 xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ip->i_ino); in xfs_inode_reload_unlinked_bucket()
3698 error = xfs_ialloc_read_agi(pag, tp, &agibp); in xfs_inode_reload_unlinked_bucket()
3714 agi = agibp->b_addr; in xfs_inode_reload_unlinked_bucket()
3723 next_agino = be32_to_cpu(agi->agi_unlinked[bucket]); in xfs_inode_reload_unlinked_bucket()
3730 next_ip->i_prev_unlinked = prev_agino; in xfs_inode_reload_unlinked_bucket()
3735 /* Try in-memory lookup first. */ in xfs_inode_reload_unlinked_bucket()
3741 error = xfs_iunlink_reload_next(tp, agibp, prev_agino, in xfs_inode_reload_unlinked_bucket()
3751 error = -EFSCORRUPTED; in xfs_inode_reload_unlinked_bucket()
3757 next_agino = next_ip->i_next_unlinked; in xfs_inode_reload_unlinked_bucket()
3761 xfs_trans_brelse(tp, agibp); in xfs_inode_reload_unlinked_bucket()
3764 error = -EFSCORRUPTED; in xfs_inode_reload_unlinked_bucket()
3773 struct xfs_trans *tp; in xfs_inode_reload_unlinked() local
3776 error = xfs_trans_alloc_empty(ip->i_mount, &tp); in xfs_inode_reload_unlinked()
3782 error = xfs_inode_reload_unlinked_bucket(tp, ip); in xfs_inode_reload_unlinked()
3784 xfs_trans_cancel(tp); in xfs_inode_reload_unlinked()
3797 blocks = ip->i_mount->m_sb.sb_rextsize; in xfs_inode_alloc_unitsize()
3799 return XFS_FSB_TO_B(ip->i_mount, blocks); in xfs_inode_alloc_unitsize()