Lines Matching +full:ip +full:- +full:block
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
35 * Convert the given file system block to a disk block. We have to treat it
40 xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb) in xfs_fsb_to_db() argument
42 if (XFS_IS_REALTIME_INODE(ip)) in xfs_fsb_to_db()
43 return XFS_FSB_TO_BB(ip->i_mount, fsb); in xfs_fsb_to_db()
44 return XFS_FSB_TO_DADDR(ip->i_mount, fsb); in xfs_fsb_to_db()
50 * The VFS functions take a linearised filesystem block offset, so we have to
56 struct xfs_inode *ip, in xfs_zero_extent() argument
60 struct xfs_mount *mp = ip->i_mount; in xfs_zero_extent()
61 struct xfs_buftarg *target = xfs_inode_buftarg(ip); in xfs_zero_extent()
62 xfs_daddr_t sector = xfs_fsb_to_db(ip, start_fsb); in xfs_zero_extent()
63 sector_t block = XFS_BB_TO_FSBT(mp, sector); in xfs_zero_extent() local
65 return blkdev_issue_zeroout(target->bt_bdev, in xfs_zero_extent()
66 block << (mp->m_super->s_blocksize_bits - 9), in xfs_zero_extent()
67 count_fsb << (mp->m_super->s_blocksize_bits - 9), in xfs_zero_extent()
84 mp = ap->ip->i_mount; in xfs_bmap_rtalloc()
85 align = xfs_get_extsz_hint(ap->ip); in xfs_bmap_rtalloc()
86 prod = align / mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
87 error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, in xfs_bmap_rtalloc()
88 align, 1, ap->eof, 0, in xfs_bmap_rtalloc()
89 ap->conv, &ap->offset, &ap->length); in xfs_bmap_rtalloc()
92 ASSERT(ap->length); in xfs_bmap_rtalloc()
93 ASSERT(ap->length % mp->m_sb.sb_rextsize == 0); in xfs_bmap_rtalloc()
99 div_u64_rem(ap->offset, align, &mod); in xfs_bmap_rtalloc()
100 if (mod || ap->length % align) in xfs_bmap_rtalloc()
105 ralen = ap->length / mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
113 if (ralen * mp->m_sb.sb_rextsize >= MAXEXTLEN) in xfs_bmap_rtalloc()
114 ralen = MAXEXTLEN / mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
119 xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP); in xfs_bmap_rtalloc()
120 xfs_trans_ijoin(ap->tp, mp->m_rbmip, XFS_ILOCK_EXCL); in xfs_bmap_rtalloc()
121 xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM); in xfs_bmap_rtalloc()
122 xfs_trans_ijoin(ap->tp, mp->m_rsumip, XFS_ILOCK_EXCL); in xfs_bmap_rtalloc()
128 if (ap->eof && ap->offset == 0) { in xfs_bmap_rtalloc()
131 error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx); in xfs_bmap_rtalloc()
134 ap->blkno = rtx * mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
136 ap->blkno = 0; in xfs_bmap_rtalloc()
144 do_div(ap->blkno, mp->m_sb.sb_rextsize); in xfs_bmap_rtalloc()
145 rtb = ap->blkno; in xfs_bmap_rtalloc()
146 ap->length = ralen; in xfs_bmap_rtalloc()
147 error = xfs_rtallocate_extent(ap->tp, ap->blkno, 1, ap->length, in xfs_bmap_rtalloc()
148 &ralen, ap->wasdel, prod, &rtb); in xfs_bmap_rtalloc()
152 ap->blkno = rtb; in xfs_bmap_rtalloc()
153 if (ap->blkno != NULLFSBLOCK) { in xfs_bmap_rtalloc()
154 ap->blkno *= mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
155 ralen *= mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
156 ap->length = ralen; in xfs_bmap_rtalloc()
157 ap->ip->i_d.di_nblocks += ralen; in xfs_bmap_rtalloc()
158 xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE); in xfs_bmap_rtalloc()
159 if (ap->wasdel) in xfs_bmap_rtalloc()
160 ap->ip->i_delayed_blks -= ralen; in xfs_bmap_rtalloc()
165 xfs_trans_mod_dquot_byino(ap->tp, ap->ip, in xfs_bmap_rtalloc()
166 ap->wasdel ? XFS_TRANS_DQ_DELRTBCOUNT : in xfs_bmap_rtalloc()
169 ap->length = 0; in xfs_bmap_rtalloc()
176 * Extent tree block counting routines.
209 struct xfs_inode *ip, in xfs_bmap_count_blocks() argument
214 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_count_blocks()
215 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); in xfs_bmap_count_blocks()
226 switch (ifp->if_format) { in xfs_bmap_count_blocks()
228 if (!(ifp->if_flags & XFS_IFEXTENTS)) { in xfs_bmap_count_blocks()
229 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_count_blocks()
234 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in xfs_bmap_count_blocks()
241 * xfs_btree_count_blocks includes the root block contained in in xfs_bmap_count_blocks()
245 *count += btblocks - 1; in xfs_bmap_count_blocks()
258 struct xfs_inode *ip, in xfs_getbmap_report_one() argument
264 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_one()
268 error = xfs_reflink_trim_around_shared(ip, got, &shared); in xfs_getbmap_report_one()
272 if (isnullstartblock(got->br_startblock) || in xfs_getbmap_report_one()
273 got->br_startblock == DELAYSTARTBLOCK) { in xfs_getbmap_report_one()
282 if (got->br_startoff < XFS_B_TO_FSB(ip->i_mount, XFS_ISIZE(ip))) in xfs_getbmap_report_one()
283 ASSERT((bmv->bmv_iflags & BMV_IF_DELALLOC) != 0); in xfs_getbmap_report_one()
285 p->bmv_oflags |= BMV_OF_DELALLOC; in xfs_getbmap_report_one()
286 p->bmv_block = -2; in xfs_getbmap_report_one()
288 p->bmv_block = xfs_fsb_to_db(ip, got->br_startblock); in xfs_getbmap_report_one()
291 if (got->br_state == XFS_EXT_UNWRITTEN && in xfs_getbmap_report_one()
292 (bmv->bmv_iflags & BMV_IF_PREALLOC)) in xfs_getbmap_report_one()
293 p->bmv_oflags |= BMV_OF_PREALLOC; in xfs_getbmap_report_one()
296 p->bmv_oflags |= BMV_OF_SHARED; in xfs_getbmap_report_one()
298 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, got->br_startoff); in xfs_getbmap_report_one()
299 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, got->br_blockcount); in xfs_getbmap_report_one()
301 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_one()
302 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_one()
303 bmv->bmv_entries++; in xfs_getbmap_report_one()
309 struct xfs_inode *ip, in xfs_getbmap_report_hole() argument
316 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_hole()
318 if (bmv->bmv_iflags & BMV_IF_NO_HOLES) in xfs_getbmap_report_hole()
321 p->bmv_block = -1; in xfs_getbmap_report_hole()
322 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, bno); in xfs_getbmap_report_hole()
323 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, end - bno); in xfs_getbmap_report_hole()
325 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_hole()
326 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_hole()
327 bmv->bmv_entries++; in xfs_getbmap_report_hole()
334 return bmv->bmv_length == 0 || bmv->bmv_entries >= bmv->bmv_count - 1; in xfs_getbmap_full()
342 xfs_fileoff_t end = rec->br_startoff + rec->br_blockcount; in xfs_getbmap_next_rec()
347 rec->br_startoff += rec->br_blockcount; in xfs_getbmap_next_rec()
348 if (!isnullstartblock(rec->br_startblock) && in xfs_getbmap_next_rec()
349 rec->br_startblock != DELAYSTARTBLOCK) in xfs_getbmap_next_rec()
350 rec->br_startblock += rec->br_blockcount; in xfs_getbmap_next_rec()
351 rec->br_blockcount = total_end - end; in xfs_getbmap_next_rec()
358 * are mapped, until the passed-in bmv->bmv_count slots have
359 * been filled, or until the formatter short-circuits the loop,
360 * if it is tracking filled-in extents on its own.
364 struct xfs_inode *ip, in xfs_getbmap() argument
368 struct xfs_mount *mp = ip->i_mount; in xfs_getbmap()
369 int iflags = bmv->bmv_iflags; in xfs_getbmap()
378 if (bmv->bmv_iflags & ~BMV_IF_VALID) in xfs_getbmap()
379 return -EINVAL; in xfs_getbmap()
383 return -EINVAL; in xfs_getbmap()
386 return -EINVAL; in xfs_getbmap()
388 if (bmv->bmv_length < -1) in xfs_getbmap()
389 return -EINVAL; in xfs_getbmap()
390 bmv->bmv_entries = 0; in xfs_getbmap()
391 if (bmv->bmv_length == 0) in xfs_getbmap()
400 ifp = XFS_IFORK_PTR(ip, whichfork); in xfs_getbmap()
402 xfs_ilock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
405 if (!XFS_IFORK_Q(ip)) in xfs_getbmap()
409 lock = xfs_ilock_attr_map_shared(ip); in xfs_getbmap()
416 if (xfs_get_cowextsz_hint(ip)) in xfs_getbmap()
417 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
419 max_len = XFS_ISIZE(ip); in xfs_getbmap()
422 xfs_ilock(ip, lock); in xfs_getbmap()
426 (ip->i_delayed_blks || XFS_ISIZE(ip) > ip->i_d.di_size)) { in xfs_getbmap()
427 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_getbmap()
437 * ip->i_delayed_blks == 0. in xfs_getbmap()
441 if (xfs_get_extsz_hint(ip) || in xfs_getbmap()
442 (ip->i_d.di_flags & in xfs_getbmap()
444 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
446 max_len = XFS_ISIZE(ip); in xfs_getbmap()
448 lock = xfs_ilock_data_map_shared(ip); in xfs_getbmap()
452 switch (ifp->if_format) { in xfs_getbmap()
460 error = -EINVAL; in xfs_getbmap()
464 if (bmv->bmv_length == -1) { in xfs_getbmap()
466 bmv->bmv_length = max(0LL, max_len - bmv->bmv_offset); in xfs_getbmap()
469 bmv_end = bmv->bmv_offset + bmv->bmv_length; in xfs_getbmap()
471 first_bno = bno = XFS_BB_TO_FSBT(mp, bmv->bmv_offset); in xfs_getbmap()
472 len = XFS_BB_TO_FSB(mp, bmv->bmv_length); in xfs_getbmap()
474 if (!(ifp->if_flags & XFS_IFEXTENTS)) { in xfs_getbmap()
475 error = xfs_iread_extents(NULL, ip, whichfork); in xfs_getbmap()
480 if (!xfs_iext_lookup_extent(ip, ifp, bno, &icur, &got)) { in xfs_getbmap()
482 * Report a whole-file hole if the delalloc flag is set to in xfs_getbmap()
486 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
487 XFS_B_TO_FSB(mp, XFS_ISIZE(ip))); in xfs_getbmap()
499 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
513 error = xfs_getbmap_report_one(ip, bmv, out, bmv_end, in xfs_getbmap()
520 xfs_fileoff_t end = XFS_B_TO_FSB(mp, XFS_ISIZE(ip)); in xfs_getbmap()
522 out[bmv->bmv_entries - 1].bmv_oflags |= BMV_OF_LAST; in xfs_getbmap()
526 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, in xfs_getbmap()
537 xfs_iunlock(ip, lock); in xfs_getbmap()
539 xfs_iunlock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
551 struct xfs_inode *ip, in xfs_bmap_punch_delalloc_range() argument
555 struct xfs_ifork *ifp = &ip->i_df; in xfs_bmap_punch_delalloc_range()
561 ASSERT(ifp->if_flags & XFS_IFEXTENTS); in xfs_bmap_punch_delalloc_range()
563 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
564 if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got)) in xfs_bmap_punch_delalloc_range()
573 * previous extent on non-delalloc or extents outside the in xfs_bmap_punch_delalloc_range()
583 error = xfs_bmap_del_extent_delay(ip, XFS_DATA_FORK, &icur, in xfs_bmap_punch_delalloc_range()
590 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
597 * regular files that are marked preallocated or append-only.
600 xfs_can_free_eofblocks(struct xfs_inode *ip, bool force) in xfs_can_free_eofblocks() argument
603 if (!S_ISREG(VFS_I(ip)->i_mode)) in xfs_can_free_eofblocks()
610 if (VFS_I(ip)->i_size == 0 && in xfs_can_free_eofblocks()
611 VFS_I(ip)->i_mapping->nrpages == 0 && in xfs_can_free_eofblocks()
612 ip->i_delayed_blks == 0) in xfs_can_free_eofblocks()
616 if (!(ip->i_df.if_flags & XFS_IFEXTENTS)) in xfs_can_free_eofblocks()
620 * Do not free real preallocated or append-only files unless the file in xfs_can_free_eofblocks()
623 if (ip->i_d.di_flags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) in xfs_can_free_eofblocks()
624 if (!force || ip->i_delayed_blks == 0) in xfs_can_free_eofblocks()
637 struct xfs_inode *ip) in xfs_free_eofblocks() argument
646 struct xfs_mount *mp = ip->i_mount; in xfs_free_eofblocks()
652 end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip)); in xfs_free_eofblocks()
653 last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); in xfs_free_eofblocks()
656 map_len = last_fsb - end_fsb; in xfs_free_eofblocks()
659 xfs_ilock(ip, XFS_ILOCK_SHARED); in xfs_free_eofblocks()
660 error = xfs_bmapi_read(ip, end_fsb, map_len, &imap, &nimaps, 0); in xfs_free_eofblocks()
661 xfs_iunlock(ip, XFS_ILOCK_SHARED); in xfs_free_eofblocks()
669 ip->i_delayed_blks)) { in xfs_free_eofblocks()
673 error = xfs_qm_dqattach(ip); in xfs_free_eofblocks()
678 inode_dio_wait(VFS_I(ip)); in xfs_free_eofblocks()
680 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, in xfs_free_eofblocks()
687 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
688 xfs_trans_ijoin(tp, ip, 0); in xfs_free_eofblocks()
691 * Do not update the on-disk file size. If we update the in xfs_free_eofblocks()
692 * on-disk file size and then the system crashes before the in xfs_free_eofblocks()
696 error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK, in xfs_free_eofblocks()
697 XFS_ISIZE(ip), XFS_BMAPI_NODISCARD); in xfs_free_eofblocks()
707 xfs_inode_clear_eofblocks_tag(ip); in xfs_free_eofblocks()
710 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
717 struct xfs_inode *ip, in xfs_alloc_file_space() argument
722 xfs_mount_t *mp = ip->i_mount; in xfs_alloc_file_space()
737 trace_xfs_alloc_file_space(ip); in xfs_alloc_file_space()
740 return -EIO; in xfs_alloc_file_space()
742 error = xfs_qm_dqattach(ip); in xfs_alloc_file_space()
747 return -EINVAL; in xfs_alloc_file_space()
749 rt = XFS_IS_REALTIME_INODE(ip); in xfs_alloc_file_space()
750 extsz = xfs_get_extsz_hint(ip); in xfs_alloc_file_space()
757 allocatesize_fsb = endoffset_fsb - startoffset_fsb; in xfs_alloc_file_space()
778 e += extsz - temp; in xfs_alloc_file_space()
785 * The transaction reservation is limited to a 32-bit block in xfs_alloc_file_space()
791 resblks = min_t(xfs_fileoff_t, (e - s), (MAXEXTLEN * nimaps)); in xfs_alloc_file_space()
794 resrtextents /= mp->m_sb.sb_rextsize; in xfs_alloc_file_space()
806 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, in xfs_alloc_file_space()
816 ASSERT(error == -ENOSPC || XFS_FORCED_SHUTDOWN(mp)); in xfs_alloc_file_space()
819 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
820 error = xfs_trans_reserve_quota_nblks(tp, ip, qblocks, in xfs_alloc_file_space()
825 xfs_trans_ijoin(tp, ip, 0); in xfs_alloc_file_space()
827 error = xfs_bmapi_write(tp, ip, startoffset_fsb, in xfs_alloc_file_space()
837 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
841 allocated_fsb = imapp->br_blockcount; in xfs_alloc_file_space()
844 error = -ENOSPC; in xfs_alloc_file_space()
849 allocatesize_fsb -= allocated_fsb; in xfs_alloc_file_space()
855 xfs_trans_unreserve_quota_nblks(tp, ip, (long)qblocks, 0, quota_flag); in xfs_alloc_file_space()
859 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
865 struct xfs_inode *ip, in xfs_unmap_extent() argument
870 struct xfs_mount *mp = ip->i_mount; in xfs_unmap_extent()
875 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, 0, &tp); in xfs_unmap_extent()
877 ASSERT(error == -ENOSPC || XFS_FORCED_SHUTDOWN(mp)); in xfs_unmap_extent()
881 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_unmap_extent()
882 error = xfs_trans_reserve_quota(tp, mp, ip->i_udquot, ip->i_gdquot, in xfs_unmap_extent()
883 ip->i_pdquot, resblks, 0, XFS_QMOPT_RES_REGBLKS); in xfs_unmap_extent()
887 xfs_trans_ijoin(tp, ip, 0); in xfs_unmap_extent()
889 error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done); in xfs_unmap_extent()
895 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_unmap_extent()
906 struct xfs_inode *ip, in xfs_flush_unmap_range() argument
910 struct xfs_mount *mp = ip->i_mount; in xfs_flush_unmap_range()
911 struct inode *inode = VFS_I(ip); in xfs_flush_unmap_range()
915 rounding = max_t(xfs_off_t, 1 << mp->m_sb.sb_blocklog, PAGE_SIZE); in xfs_flush_unmap_range()
917 end = round_up(offset + len, rounding) - 1; in xfs_flush_unmap_range()
919 error = filemap_write_and_wait_range(inode->i_mapping, start, end); in xfs_flush_unmap_range()
928 struct xfs_inode *ip, in xfs_free_file_space() argument
932 struct xfs_mount *mp = ip->i_mount; in xfs_free_file_space()
937 trace_xfs_free_file_space(ip); in xfs_free_file_space()
939 error = xfs_qm_dqattach(ip); in xfs_free_file_space()
950 if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1) { in xfs_free_file_space()
952 mp->m_sb.sb_rextsize); in xfs_free_file_space()
954 mp->m_sb.sb_rextsize); in xfs_free_file_space()
962 error = xfs_unmap_extent(ip, startoffset_fsb, in xfs_free_file_space()
963 endoffset_fsb - startoffset_fsb, &done); in xfs_free_file_space()
971 * partial block at the beginning and/or end. iomap_zero_range is smart in xfs_free_file_space()
975 if (offset >= XFS_ISIZE(ip)) in xfs_free_file_space()
977 if (offset + len > XFS_ISIZE(ip)) in xfs_free_file_space()
978 len = XFS_ISIZE(ip) - offset; in xfs_free_file_space()
979 error = iomap_zero_range(VFS_I(ip), offset, len, NULL, in xfs_free_file_space()
986 * must make sure that the post-EOF area is also zeroed because the in xfs_free_file_space()
990 if (offset + len >= XFS_ISIZE(ip) && offset_in_page(offset + len) > 0) { in xfs_free_file_space()
991 error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, in xfs_free_file_space()
1000 struct xfs_inode *ip, in xfs_prepare_shift() argument
1003 struct xfs_mount *mp = ip->i_mount; in xfs_prepare_shift()
1007 * Trim eofblocks to avoid shifting uninitialized post-eof preallocation in xfs_prepare_shift()
1010 if (xfs_can_free_eofblocks(ip, true)) { in xfs_prepare_shift()
1011 error = xfs_free_eofblocks(ip); in xfs_prepare_shift()
1017 * Shift operations must stabilize the start block offset boundary along in xfs_prepare_shift()
1021 * with the block just prior to the start to stabilize the boundary. in xfs_prepare_shift()
1023 offset = round_down(offset, 1 << mp->m_sb.sb_blocklog); in xfs_prepare_shift()
1025 offset -= (1 << mp->m_sb.sb_blocklog); in xfs_prepare_shift()
1031 error = xfs_flush_unmap_range(ip, offset, XFS_ISIZE(ip)); in xfs_prepare_shift()
1040 if (xfs_inode_has_cow_data(ip)) { in xfs_prepare_shift()
1041 error = xfs_reflink_cancel_cow_range(ip, offset, NULLFILEOFF, in xfs_prepare_shift()
1064 struct xfs_inode *ip, in xfs_collapse_file_space() argument
1068 struct xfs_mount *mp = ip->i_mount; in xfs_collapse_file_space()
1075 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); in xfs_collapse_file_space()
1076 ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL)); in xfs_collapse_file_space()
1078 trace_xfs_collapse_file_space(ip); in xfs_collapse_file_space()
1080 error = xfs_free_file_space(ip, offset, len); in xfs_collapse_file_space()
1084 error = xfs_prepare_shift(ip, offset); in xfs_collapse_file_space()
1088 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, 0, &tp); in xfs_collapse_file_space()
1092 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1093 xfs_trans_ijoin(tp, ip, 0); in xfs_collapse_file_space()
1096 error = xfs_bmap_collapse_extents(tp, ip, &next_fsb, shift_fsb, in xfs_collapse_file_space()
1110 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1115 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1133 struct xfs_inode *ip, in xfs_insert_file_space() argument
1137 struct xfs_mount *mp = ip->i_mount; in xfs_insert_file_space()
1145 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); in xfs_insert_file_space()
1146 ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL)); in xfs_insert_file_space()
1148 trace_xfs_insert_file_space(ip); in xfs_insert_file_space()
1150 error = xfs_bmap_can_insert_extents(ip, stop_fsb, shift_fsb); in xfs_insert_file_space()
1154 error = xfs_prepare_shift(ip, offset); in xfs_insert_file_space()
1158 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, in xfs_insert_file_space()
1163 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1164 xfs_trans_ijoin(tp, ip, 0); in xfs_insert_file_space()
1168 * is not the starting block of extent, we need to split the extent at in xfs_insert_file_space()
1171 error = xfs_bmap_split_extent(tp, ip, stop_fsb); in xfs_insert_file_space()
1180 error = xfs_bmap_insert_extents(tp, ip, &next_fsb, shift_fsb, in xfs_insert_file_space()
1187 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1192 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1218 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents_check_format() argument
1221 struct xfs_ifork *ifp = &ip->i_df; in xfs_swap_extents_check_format()
1222 struct xfs_ifork *tifp = &tip->i_df; in xfs_swap_extents_check_format()
1225 if (XFS_IS_QUOTA_ON(ip->i_mount) && in xfs_swap_extents_check_format()
1226 (!uid_eq(VFS_I(ip)->i_uid, VFS_I(tip)->i_uid) || in xfs_swap_extents_check_format()
1227 !gid_eq(VFS_I(ip)->i_gid, VFS_I(tip)->i_gid) || in xfs_swap_extents_check_format()
1228 ip->i_d.di_projid != tip->i_d.di_projid)) in xfs_swap_extents_check_format()
1229 return -EINVAL; in xfs_swap_extents_check_format()
1232 if (ifp->if_format == XFS_DINODE_FMT_LOCAL || in xfs_swap_extents_check_format()
1233 tifp->if_format == XFS_DINODE_FMT_LOCAL) in xfs_swap_extents_check_format()
1234 return -EINVAL; in xfs_swap_extents_check_format()
1240 if (ifp->if_nextents < tifp->if_nextents) in xfs_swap_extents_check_format()
1241 return -EINVAL; in xfs_swap_extents_check_format()
1247 if (xfs_sb_version_hasrmapbt(&ip->i_mount->m_sb)) in xfs_swap_extents_check_format()
1255 if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1256 tifp->if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extents_check_format()
1257 return -EINVAL; in xfs_swap_extents_check_format()
1260 if (tifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1261 tifp->if_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1262 return -EINVAL; in xfs_swap_extents_check_format()
1265 if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1266 ifp->if_nextents > XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1267 return -EINVAL; in xfs_swap_extents_check_format()
1270 * If we are in a btree format, check that the temp root block will fit in xfs_swap_extents_check_format()
1274 * Note that we have to be careful to allow btree->extent conversions in xfs_swap_extents_check_format()
1278 if (tifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1279 if (XFS_IFORK_Q(ip) && in xfs_swap_extents_check_format()
1280 XFS_BMAP_BMDR_SPACE(tifp->if_broot) > XFS_IFORK_BOFF(ip)) in xfs_swap_extents_check_format()
1281 return -EINVAL; in xfs_swap_extents_check_format()
1282 if (tifp->if_nextents <= XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1283 return -EINVAL; in xfs_swap_extents_check_format()
1286 /* Reciprocal target->temp btree format checks */ in xfs_swap_extents_check_format()
1287 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1289 XFS_BMAP_BMDR_SPACE(ip->i_df.if_broot) > XFS_IFORK_BOFF(tip)) in xfs_swap_extents_check_format()
1290 return -EINVAL; in xfs_swap_extents_check_format()
1291 if (ifp->if_nextents <= XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1292 return -EINVAL; in xfs_swap_extents_check_format()
1300 struct xfs_inode *ip) in xfs_swap_extent_flush() argument
1304 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_swap_extent_flush()
1307 truncate_pagecache_range(VFS_I(ip), 0, -1); in xfs_swap_extent_flush()
1310 if (VFS_I(ip)->i_mapping->nrpages) in xfs_swap_extent_flush()
1311 return -EINVAL; in xfs_swap_extent_flush()
1321 struct xfs_inode *ip, in xfs_swap_extent_rmap() argument
1339 * file as having shared blocks so that we get the shared-block in xfs_swap_extent_rmap()
1343 tip_flags2 = tip->i_d.di_flags2; in xfs_swap_extent_rmap()
1344 if (ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK) in xfs_swap_extent_rmap()
1345 tip->i_d.di_flags2 |= XFS_DIFLAG2_REFLINK; in xfs_swap_extent_rmap()
1348 end_fsb = XFS_B_TO_FSB(ip->i_mount, i_size_read(VFS_I(ip))); in xfs_swap_extent_rmap()
1349 count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb); in xfs_swap_extent_rmap()
1366 ASSERT(tp->t_firstblock == NULLFSBLOCK); in xfs_swap_extent_rmap()
1371 error = xfs_bmapi_read(ip, tirec.br_startoff, in xfs_swap_extent_rmap()
1378 trace_xfs_swap_extent_rmap_remap_piece(ip, &irec); in xfs_swap_extent_rmap()
1391 xfs_bmap_unmap_extent(tp, ip, &irec); in xfs_swap_extent_rmap()
1394 xfs_bmap_map_extent(tp, ip, &uirec); in xfs_swap_extent_rmap()
1408 tirec.br_blockcount -= rlen; in xfs_swap_extent_rmap()
1412 count_fsb -= ilen; in xfs_swap_extent_rmap()
1416 tip->i_d.di_flags2 = tip_flags2; in xfs_swap_extent_rmap()
1420 trace_xfs_swap_extent_rmap_error(ip, error, _RET_IP_); in xfs_swap_extent_rmap()
1421 tip->i_d.di_flags2 = tip_flags2; in xfs_swap_extent_rmap()
1429 struct xfs_inode *ip, in xfs_swap_extent_forks() argument
1443 if (XFS_IFORK_Q(ip) && ip->i_afp->if_nextents > 0 && in xfs_swap_extent_forks()
1444 ip->i_afp->if_format != XFS_DINODE_FMT_LOCAL) { in xfs_swap_extent_forks()
1445 error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &junk, in xfs_swap_extent_forks()
1450 if (XFS_IFORK_Q(tip) && tip->i_afp->if_nextents > 0 && in xfs_swap_extent_forks()
1451 tip->i_afp->if_format != XFS_DINODE_FMT_LOCAL) { in xfs_swap_extent_forks()
1460 * block headers. We can't start changing the bmbt blocks until the in xfs_swap_extent_forks()
1465 if (xfs_sb_version_has_v3inode(&ip->i_mount->m_sb)) { in xfs_swap_extent_forks()
1466 if (ip->i_df.if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1468 if (tip->i_df.if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1475 swap(ip->i_df, tip->i_df); in xfs_swap_extent_forks()
1478 * Fix the on-disk inode values in xfs_swap_extent_forks()
1480 tmp = (uint64_t)ip->i_d.di_nblocks; in xfs_swap_extent_forks()
1481 ip->i_d.di_nblocks = tip->i_d.di_nblocks - taforkblks + aforkblks; in xfs_swap_extent_forks()
1482 tip->i_d.di_nblocks = tmp + taforkblks - aforkblks; in xfs_swap_extent_forks()
1493 ASSERT(tip->i_delayed_blks == 0); in xfs_swap_extent_forks()
1494 tip->i_delayed_blks = ip->i_delayed_blks; in xfs_swap_extent_forks()
1495 ip->i_delayed_blks = 0; in xfs_swap_extent_forks()
1497 switch (ip->i_df.if_format) { in xfs_swap_extent_forks()
1502 ASSERT(!xfs_sb_version_has_v3inode(&ip->i_mount->m_sb) || in xfs_swap_extent_forks()
1508 switch (tip->i_df.if_format) { in xfs_swap_extent_forks()
1514 ASSERT(!xfs_sb_version_has_v3inode(&ip->i_mount->m_sb) || in xfs_swap_extent_forks()
1526 * physically logged as a fallback and the scan returns -EAGAIN. We must roll
1533 struct xfs_inode *ip, in xfs_swap_change_owner() argument
1540 error = xfs_bmbt_change_owner(tp, ip, XFS_DATA_FORK, ip->i_ino, in xfs_swap_change_owner()
1543 if (error != -EAGAIN) in xfs_swap_change_owner()
1555 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_change_owner()
1557 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_swap_change_owner()
1566 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents() argument
1570 struct xfs_mount *mp = ip->i_mount; in xfs_swap_extents()
1572 struct xfs_bstat *sbp = &sxp->sx_stat; in xfs_swap_extents()
1586 lock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()
1588 xfs_lock_two_inodes(ip, XFS_MMAPLOCK_EXCL, tip, XFS_MMAPLOCK_EXCL); in xfs_swap_extents()
1591 if ((VFS_I(ip)->i_mode & S_IFMT) != (VFS_I(tip)->i_mode & S_IFMT)) { in xfs_swap_extents()
1592 error = -EINVAL; in xfs_swap_extents()
1596 /* Verify both files are either real-time or non-realtime */ in xfs_swap_extents()
1597 if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) { in xfs_swap_extents()
1598 error = -EINVAL; in xfs_swap_extents()
1602 error = xfs_qm_dqattach(ip); in xfs_swap_extents()
1610 error = xfs_swap_extent_flush(ip); in xfs_swap_extents()
1625 * a block reservation because it's really just a remap operation in xfs_swap_extents()
1628 if (xfs_sb_version_hasrmapbt(&mp->m_sb)) { in xfs_swap_extents()
1630 uint32_t ipnext = ip->i_df.if_nextents; in xfs_swap_extents()
1631 uint32_t tipnext = tip->i_df.if_nextents; in xfs_swap_extents()
1642 * If either inode straddles a bmapbt block allocation boundary, in xfs_swap_extents()
1644 * extents are remapped. This can exhaust the block reservation in xfs_swap_extents()
1650 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, flags, in xfs_swap_extents()
1659 xfs_lock_two_inodes(ip, XFS_ILOCK_EXCL, tip, XFS_ILOCK_EXCL); in xfs_swap_extents()
1661 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_extents()
1666 if (sxp->sx_offset != 0 || in xfs_swap_extents()
1667 sxp->sx_length != ip->i_d.di_size || in xfs_swap_extents()
1668 sxp->sx_length != tip->i_d.di_size) { in xfs_swap_extents()
1669 error = -EFAULT; in xfs_swap_extents()
1673 trace_xfs_swap_extent_before(ip, 0); in xfs_swap_extents()
1677 error = xfs_swap_extents_check_format(ip, tip); in xfs_swap_extents()
1681 __func__, ip->i_ino); in xfs_swap_extents()
1692 if ((sbp->bs_ctime.tv_sec != VFS_I(ip)->i_ctime.tv_sec) || in xfs_swap_extents()
1693 (sbp->bs_ctime.tv_nsec != VFS_I(ip)->i_ctime.tv_nsec) || in xfs_swap_extents()
1694 (sbp->bs_mtime.tv_sec != VFS_I(ip)->i_mtime.tv_sec) || in xfs_swap_extents()
1695 (sbp->bs_mtime.tv_nsec != VFS_I(ip)->i_mtime.tv_nsec)) { in xfs_swap_extents()
1696 error = -EBUSY; in xfs_swap_extents()
1701 * Note the trickiness in setting the log flags - we set the owner log in xfs_swap_extents()
1705 * not the pre-swapped inodes. in xfs_swap_extents()
1710 if (xfs_sb_version_hasrmapbt(&mp->m_sb)) in xfs_swap_extents()
1711 error = xfs_swap_extent_rmap(&tp, ip, tip); in xfs_swap_extents()
1713 error = xfs_swap_extent_forks(tp, ip, tip, &src_log_flags, in xfs_swap_extents()
1719 if ((ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK) ^ in xfs_swap_extents()
1720 (tip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK)) { in xfs_swap_extents()
1721 f = ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1722 ip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1723 ip->i_d.di_flags2 |= tip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1724 tip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1725 tip->i_d.di_flags2 |= f & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1729 if (xfs_sb_version_hasreflink(&mp->m_sb)) { in xfs_swap_extents()
1730 ASSERT(!ip->i_cowfp || in xfs_swap_extents()
1731 ip->i_cowfp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1732 ASSERT(!tip->i_cowfp || in xfs_swap_extents()
1733 tip->i_cowfp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1735 swap(ip->i_cowfp, tip->i_cowfp); in xfs_swap_extents()
1737 if (ip->i_cowfp && ip->i_cowfp->if_bytes) in xfs_swap_extents()
1738 xfs_inode_set_cowblocks_tag(ip); in xfs_swap_extents()
1740 xfs_inode_clear_cowblocks_tag(ip); in xfs_swap_extents()
1741 if (tip->i_cowfp && tip->i_cowfp->if_bytes) in xfs_swap_extents()
1747 xfs_trans_log_inode(tp, ip, src_log_flags); in xfs_swap_extents()
1757 error = xfs_swap_change_owner(&tp, ip, tip); in xfs_swap_extents()
1762 error = xfs_swap_change_owner(&tp, tip, ip); in xfs_swap_extents()
1771 if (mp->m_flags & XFS_MOUNT_WSYNC) in xfs_swap_extents()
1776 trace_xfs_swap_extent_after(ip, 0); in xfs_swap_extents()
1780 xfs_iunlock(ip, lock_flags); in xfs_swap_extents()
1782 unlock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()