Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'xfs-6.10-fixes-5' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux

Pull xfs fixes from Chandan Babu:

- Always free only post-EOF delayed allocations for files with the
XFS_DIFLAG_PREALLOC or APPEND flags set.

- Do not align cow fork delalloc to cowextsz hint when running low on
space.

- Allow zero-size symlinks and directories as long as the link count is
zero.

- Change XFS_IOC_EXCHANGE_RANGE to be a _IOW only ioctl. This was ioctl
was introduced during v6.10 developement cycle.

- xfs_init_new_inode() now creates an attribute fork on a newly created
inode even if ATTR feature flag is not enabled.

* tag 'xfs-6.10-fixes-5' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux:
xfs: honor init_xattrs in xfs_init_new_inode for !ATTR fs
xfs: fix direction in XFS_IOC_EXCHANGE_RANGE
xfs: allow unlinked symlinks and dirs with zero size
xfs: restrict when we try to align cow fork delalloc to cowextsz hints
xfs: fix freeing speculative preallocations for preallocated files

+95 -53
+27 -4
fs/xfs/libxfs/xfs_bmap.c
··· 4058 4058 xfs_extlen_t indlen; 4059 4059 uint64_t fdblocks; 4060 4060 int error; 4061 - xfs_fileoff_t aoff = off; 4061 + xfs_fileoff_t aoff; 4062 + bool use_cowextszhint = 4063 + whichfork == XFS_COW_FORK && !prealloc; 4062 4064 4065 + retry: 4063 4066 /* 4064 4067 * Cap the alloc length. Keep track of prealloc so we know whether to 4065 4068 * tag the inode before we return. 4066 4069 */ 4070 + aoff = off; 4067 4071 alen = XFS_FILBLKS_MIN(len + prealloc, XFS_MAX_BMBT_EXTLEN); 4068 4072 if (!eof) 4069 4073 alen = XFS_FILBLKS_MIN(alen, got->br_startoff - aoff); 4070 4074 if (prealloc && alen >= len) 4071 4075 prealloc = alen - len; 4072 4076 4073 - /* Figure out the extent size, adjust alen */ 4074 - if (whichfork == XFS_COW_FORK) { 4077 + /* 4078 + * If we're targetting the COW fork but aren't creating a speculative 4079 + * posteof preallocation, try to expand the reservation to align with 4080 + * the COW extent size hint if there's sufficient free space. 4081 + * 4082 + * Unlike the data fork, the CoW cancellation functions will free all 4083 + * the reservations at inactivation, so we don't require that every 4084 + * delalloc reservation have a dirty pagecache. 4085 + */ 4086 + if (use_cowextszhint) { 4075 4087 struct xfs_bmbt_irec prev; 4076 4088 xfs_extlen_t extsz = xfs_get_cowextsz_hint(ip); 4077 4089 ··· 4102 4090 */ 4103 4091 error = xfs_quota_reserve_blkres(ip, alen); 4104 4092 if (error) 4105 - return error; 4093 + goto out; 4106 4094 4107 4095 /* 4108 4096 * Split changing sb for alen and indlen since they could be coming ··· 4152 4140 out_unreserve_quota: 4153 4141 if (XFS_IS_QUOTA_ON(mp)) 4154 4142 xfs_quota_unreserve_blkres(ip, alen); 4143 + out: 4144 + if (error == -ENOSPC || error == -EDQUOT) { 4145 + trace_xfs_delalloc_enospc(ip, off, len); 4146 + 4147 + if (prealloc || use_cowextszhint) { 4148 + /* retry without any preallocation */ 4149 + use_cowextszhint = false; 4150 + prealloc = 0; 4151 + goto retry; 4152 + } 4153 + } 4155 4154 return error; 4156 4155 } 4157 4156
+1 -1
fs/xfs/libxfs/xfs_fs.h
··· 996 996 #define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom) 997 997 #define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req) 998 998 #define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) 999 - #define XFS_IOC_EXCHANGE_RANGE _IOWR('X', 129, struct xfs_exchange_range) 999 + #define XFS_IOC_EXCHANGE_RANGE _IOW ('X', 129, struct xfs_exchange_range) 1000 1000 /* XFS_IOC_GETFSUUID ---------- deprecated 140 */ 1001 1001 1002 1002
+18 -5
fs/xfs/libxfs/xfs_inode_buf.c
··· 379 379 /* 380 380 * A directory small enough to fit in the inode must be stored 381 381 * in local format. The directory sf <-> extents conversion 382 - * code updates the directory size accordingly. 382 + * code updates the directory size accordingly. Directories 383 + * being truncated have zero size and are not subject to this 384 + * check. 383 385 */ 384 386 if (S_ISDIR(mode)) { 385 - if (be64_to_cpu(dip->di_size) <= fork_size && 387 + if (dip->di_size && 388 + be64_to_cpu(dip->di_size) <= fork_size && 386 389 fork_format != XFS_DINODE_FMT_LOCAL) 387 390 return __this_address; 388 391 } ··· 531 528 if (mode && xfs_mode_to_ftype(mode) == XFS_DIR3_FT_UNKNOWN) 532 529 return __this_address; 533 530 534 - /* No zero-length symlinks/dirs. */ 535 - if ((S_ISLNK(mode) || S_ISDIR(mode)) && di_size == 0) 536 - return __this_address; 531 + /* 532 + * No zero-length symlinks/dirs unless they're unlinked and hence being 533 + * inactivated. 534 + */ 535 + if ((S_ISLNK(mode) || S_ISDIR(mode)) && di_size == 0) { 536 + if (dip->di_version > 1) { 537 + if (dip->di_nlink) 538 + return __this_address; 539 + } else { 540 + if (dip->di_onlink) 541 + return __this_address; 542 + } 543 + } 537 544 538 545 fa = xfs_dinode_verify_nrext64(mp, dip); 539 546 if (fa)
+22 -8
fs/xfs/xfs_bmap_util.c
··· 486 486 487 487 /* 488 488 * Test whether it is appropriate to check an inode for and free post EOF 489 - * blocks. The 'force' parameter determines whether we should also consider 490 - * regular files that are marked preallocated or append-only. 489 + * blocks. 491 490 */ 492 491 bool 493 492 xfs_can_free_eofblocks( 494 - struct xfs_inode *ip, 495 - bool force) 493 + struct xfs_inode *ip) 496 494 { 497 495 struct xfs_bmbt_irec imap; 498 496 struct xfs_mount *mp = ip->i_mount; ··· 524 526 return false; 525 527 526 528 /* 527 - * Do not free real preallocated or append-only files unless the file 528 - * has delalloc blocks and we are forced to remove them. 529 + * Only free real extents for inodes with persistent preallocations or 530 + * the append-only flag. 529 531 */ 530 532 if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) 531 - if (!force || ip->i_delayed_blks == 0) 533 + if (ip->i_delayed_blks == 0) 532 534 return false; 533 535 534 536 /* ··· 581 583 582 584 /* Wait on dio to ensure i_size has settled. */ 583 585 inode_dio_wait(VFS_I(ip)); 586 + 587 + /* 588 + * For preallocated files only free delayed allocations. 589 + * 590 + * Note that this means we also leave speculative preallocations in 591 + * place for preallocated files. 592 + */ 593 + if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) { 594 + if (ip->i_delayed_blks) { 595 + xfs_bmap_punch_delalloc_range(ip, 596 + round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize), 597 + LLONG_MAX); 598 + } 599 + xfs_inode_clear_eofblocks_tag(ip); 600 + return 0; 601 + } 584 602 585 603 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); 586 604 if (error) { ··· 905 891 * Trim eofblocks to avoid shifting uninitialized post-eof preallocation 906 892 * into the accessible region of the file. 907 893 */ 908 - if (xfs_can_free_eofblocks(ip, true)) { 894 + if (xfs_can_free_eofblocks(ip)) { 909 895 error = xfs_free_eofblocks(ip); 910 896 if (error) 911 897 return error;
+1 -1
fs/xfs/xfs_bmap_util.h
··· 63 63 xfs_off_t len); 64 64 65 65 /* EOF block manipulation functions */ 66 - bool xfs_can_free_eofblocks(struct xfs_inode *ip, bool force); 66 + bool xfs_can_free_eofblocks(struct xfs_inode *ip); 67 67 int xfs_free_eofblocks(struct xfs_inode *ip); 68 68 69 69 int xfs_swap_extents(struct xfs_inode *ip, struct xfs_inode *tip,
+1 -1
fs/xfs/xfs_icache.c
··· 1155 1155 } 1156 1156 *lockflags |= XFS_IOLOCK_EXCL; 1157 1157 1158 - if (xfs_can_free_eofblocks(ip, false)) 1158 + if (xfs_can_free_eofblocks(ip)) 1159 1159 return xfs_free_eofblocks(ip); 1160 1160 1161 1161 /* inode could be preallocated or append-only */
+13 -11
fs/xfs/xfs_inode.c
··· 42 42 #include "xfs_pnfs.h" 43 43 #include "xfs_parent.h" 44 44 #include "xfs_xattr.h" 45 + #include "xfs_sb.h" 45 46 46 47 struct kmem_cache *xfs_inode_cache; 47 48 ··· 871 870 * this saves us from needing to run a separate transaction to set the 872 871 * fork offset in the immediate future. 873 872 */ 874 - if (init_xattrs && xfs_has_attr(mp)) { 873 + if (init_xattrs) { 875 874 ip->i_forkoff = xfs_default_attroffset(ip) >> 3; 876 875 xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); 876 + 877 + if (!xfs_has_attr(mp)) { 878 + spin_lock(&mp->m_sb_lock); 879 + xfs_add_attr(mp); 880 + spin_unlock(&mp->m_sb_lock); 881 + xfs_log_sb(tp); 882 + } 877 883 } 878 884 879 885 /* ··· 1603 1595 if (!xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) 1604 1596 return 0; 1605 1597 1606 - if (xfs_can_free_eofblocks(ip, false)) { 1598 + if (xfs_can_free_eofblocks(ip)) { 1607 1599 /* 1608 1600 * Check if the inode is being opened, written and closed 1609 1601 * frequently and we have delayed allocation blocks outstanding ··· 1864 1856 1865 1857 /* 1866 1858 * This file isn't being freed, so check if there are post-eof blocks 1867 - * to free. @force is true because we are evicting an inode from the 1868 - * cache. Post-eof blocks must be freed, lest we end up with broken 1869 - * free space accounting. 1859 + * to free. 1870 1860 * 1871 1861 * Note: don't bother with iolock here since lockdep complains about 1872 1862 * acquiring it in reclaim context. We have the only reference to the 1873 1863 * inode at this point anyways. 1874 1864 */ 1875 - return xfs_can_free_eofblocks(ip, true); 1865 + return xfs_can_free_eofblocks(ip); 1876 1866 } 1877 1867 1878 1868 /* ··· 1953 1947 1954 1948 if (VFS_I(ip)->i_nlink != 0) { 1955 1949 /* 1956 - * force is true because we are evicting an inode from the 1957 - * cache. Post-eof blocks must be freed, lest we end up with 1958 - * broken free space accounting. 1959 - * 1960 1950 * Note: don't bother with iolock here since lockdep complains 1961 1951 * about acquiring it in reclaim context. We have the only 1962 1952 * reference to the inode at this point anyways. 1963 1953 */ 1964 - if (xfs_can_free_eofblocks(ip, true)) 1954 + if (xfs_can_free_eofblocks(ip)) 1965 1955 error = xfs_free_eofblocks(ip); 1966 1956 1967 1957 goto out;
+12 -22
fs/xfs/xfs_iomap.c
··· 1148 1148 } 1149 1149 } 1150 1150 1151 - retry: 1152 - error = xfs_bmapi_reserve_delalloc(ip, allocfork, offset_fsb, 1153 - end_fsb - offset_fsb, prealloc_blocks, 1154 - allocfork == XFS_DATA_FORK ? &imap : &cmap, 1155 - allocfork == XFS_DATA_FORK ? &icur : &ccur, 1156 - allocfork == XFS_DATA_FORK ? eof : cow_eof); 1157 - switch (error) { 1158 - case 0: 1159 - break; 1160 - case -ENOSPC: 1161 - case -EDQUOT: 1162 - /* retry without any preallocation */ 1163 - trace_xfs_delalloc_enospc(ip, offset, count); 1164 - if (prealloc_blocks) { 1165 - prealloc_blocks = 0; 1166 - goto retry; 1167 - } 1168 - fallthrough; 1169 - default: 1170 - goto out_unlock; 1171 - } 1172 - 1173 1151 if (allocfork == XFS_COW_FORK) { 1152 + error = xfs_bmapi_reserve_delalloc(ip, allocfork, offset_fsb, 1153 + end_fsb - offset_fsb, prealloc_blocks, &cmap, 1154 + &ccur, cow_eof); 1155 + if (error) 1156 + goto out_unlock; 1157 + 1174 1158 trace_xfs_iomap_alloc(ip, offset, count, allocfork, &cmap); 1175 1159 goto found_cow; 1176 1160 } 1161 + 1162 + error = xfs_bmapi_reserve_delalloc(ip, allocfork, offset_fsb, 1163 + end_fsb - offset_fsb, prealloc_blocks, &imap, &icur, 1164 + eof); 1165 + if (error) 1166 + goto out_unlock; 1177 1167 1178 1168 /* 1179 1169 * Flag newly allocated delalloc blocks with IOMAP_F_NEW so we punch