Skip to content

Commit c601747

Browse files
committed
Merge tag 'xfs-5.5-fixes-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull xfs fixes from Darrick Wong: "Fix a few bugs that could lead to corrupt files, fsck complaints, and filesystem crashes: - Minor documentation fixes - Fix a file corruption due to read racing with an insert range operation. - Fix log reservation overflows when allocating large rt extents - Fix a buffer log item flags check - Don't allow administrators to mount with sunit= options that will cause later xfs_repair complaints about the root directory being suspicious because the fs geometry appeared inconsistent - Fix a non-static helper that should have been static" * tag 'xfs-5.5-fixes-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: xfs: Make the symbol 'xfs_rtalloc_log_count' static xfs: don't commit sunit/swidth updates to disk if that would cause repair failures xfs: split the sunit parameter update into two parts xfs: refactor agfl length computation function libxfs: resync with the userspace libxfs xfs: use bitops interface for buf log item AIL flag check xfs: fix log reservation overflows when allocating large rt extents xfs: stabilize insert range start boundary to avoid COW writeback race xfs: fix Sphinx documentation warning
2 parents a396560 + 5084bf6 commit c601747

File tree

13 files changed

+341
-104
lines changed

13 files changed

+341
-104
lines changed

Documentation/admin-guide/xfs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ The following sysctls are available for the XFS filesystem:
253253
pool.
254254

255255
fs.xfs.speculative_prealloc_lifetime
256-
(Units: seconds Min: 1 Default: 300 Max: 86400)
256+
(Units: seconds Min: 1 Default: 300 Max: 86400)
257257
The interval at which the background scanning for inodes
258258
with unused speculative preallocation runs. The scan
259259
removes unused preallocation from clean inodes and releases

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,24 +2248,32 @@ xfs_alloc_longest_free_extent(
22482248
return pag->pagf_flcount > 0 || pag->pagf_longest > 0;
22492249
}
22502250

2251+
/*
2252+
* Compute the minimum length of the AGFL in the given AG. If @pag is NULL,
2253+
* return the largest possible minimum length.
2254+
*/
22512255
unsigned int
22522256
xfs_alloc_min_freelist(
22532257
struct xfs_mount *mp,
22542258
struct xfs_perag *pag)
22552259
{
2260+
/* AG btrees have at least 1 level. */
2261+
static const uint8_t fake_levels[XFS_BTNUM_AGF] = {1, 1, 1};
2262+
const uint8_t *levels = pag ? pag->pagf_levels : fake_levels;
22562263
unsigned int min_free;
22572264

2265+
ASSERT(mp->m_ag_maxlevels > 0);
2266+
22582267
/* space needed by-bno freespace btree */
2259-
min_free = min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_BNOi] + 1,
2268+
min_free = min_t(unsigned int, levels[XFS_BTNUM_BNOi] + 1,
22602269
mp->m_ag_maxlevels);
22612270
/* space needed by-size freespace btree */
2262-
min_free += min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_CNTi] + 1,
2271+
min_free += min_t(unsigned int, levels[XFS_BTNUM_CNTi] + 1,
22632272
mp->m_ag_maxlevels);
22642273
/* space needed reverse mapping used space btree */
22652274
if (xfs_sb_version_hasrmapbt(&mp->m_sb))
2266-
min_free += min_t(unsigned int,
2267-
pag->pagf_levels[XFS_BTNUM_RMAPi] + 1,
2268-
mp->m_rmap_maxlevels);
2275+
min_free += min_t(unsigned int, levels[XFS_BTNUM_RMAPi] + 1,
2276+
mp->m_rmap_maxlevels);
22692277

22702278
return min_free;
22712279
}

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,7 +4561,7 @@ xfs_bmapi_convert_delalloc(
45614561
struct xfs_mount *mp = ip->i_mount;
45624562
xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
45634563
struct xfs_bmalloca bma = { NULL };
4564-
u16 flags = 0;
4564+
uint16_t flags = 0;
45654565
struct xfs_trans *tp;
45664566
int error;
45674567

@@ -5972,8 +5972,7 @@ xfs_bmap_insert_extents(
59725972
goto del_cursor;
59735973
}
59745974

5975-
if (XFS_IS_CORRUPT(mp,
5976-
stop_fsb >= got.br_startoff + got.br_blockcount)) {
5975+
if (XFS_IS_CORRUPT(mp, stop_fsb > got.br_startoff)) {
59775976
error = -EFSCORRUPTED;
59785977
goto del_cursor;
59795978
}

fs/xfs/libxfs/xfs_dir2.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,3 +724,24 @@ xfs_dir2_namecheck(
724724
/* There shouldn't be any slashes or nulls here */
725725
return !memchr(name, '/', length) && !memchr(name, 0, length);
726726
}
727+
728+
xfs_dahash_t
729+
xfs_dir2_hashname(
730+
struct xfs_mount *mp,
731+
struct xfs_name *name)
732+
{
733+
if (unlikely(xfs_sb_version_hasasciici(&mp->m_sb)))
734+
return xfs_ascii_ci_hashname(name);
735+
return xfs_da_hashname(name->name, name->len);
736+
}
737+
738+
enum xfs_dacmp
739+
xfs_dir2_compname(
740+
struct xfs_da_args *args,
741+
const unsigned char *name,
742+
int len)
743+
{
744+
if (unlikely(xfs_sb_version_hasasciici(&args->dp->i_mount->m_sb)))
745+
return xfs_ascii_ci_compname(args, name, len);
746+
return xfs_da_compname(args, name, len);
747+
}

fs/xfs/libxfs/xfs_dir2_priv.h

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ extern int xfs_dir2_sf_lookup(struct xfs_da_args *args);
175175
extern int xfs_dir2_sf_removename(struct xfs_da_args *args);
176176
extern int xfs_dir2_sf_replace(struct xfs_da_args *args);
177177
extern xfs_failaddr_t xfs_dir2_sf_verify(struct xfs_inode *ip);
178+
int xfs_dir2_sf_entsize(struct xfs_mount *mp,
179+
struct xfs_dir2_sf_hdr *hdr, int len);
180+
void xfs_dir2_sf_put_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr,
181+
struct xfs_dir2_sf_entry *sfep, xfs_ino_t ino);
182+
void xfs_dir2_sf_put_ftype(struct xfs_mount *mp,
183+
struct xfs_dir2_sf_entry *sfep, uint8_t ftype);
178184

179185
/* xfs_dir2_readdir.c */
180186
extern int xfs_readdir(struct xfs_trans *tp, struct xfs_inode *dp,
@@ -194,25 +200,8 @@ xfs_dir2_data_entsize(
194200
return round_up(len, XFS_DIR2_DATA_ALIGN);
195201
}
196202

197-
static inline xfs_dahash_t
198-
xfs_dir2_hashname(
199-
struct xfs_mount *mp,
200-
struct xfs_name *name)
201-
{
202-
if (unlikely(xfs_sb_version_hasasciici(&mp->m_sb)))
203-
return xfs_ascii_ci_hashname(name);
204-
return xfs_da_hashname(name->name, name->len);
205-
}
206-
207-
static inline enum xfs_dacmp
208-
xfs_dir2_compname(
209-
struct xfs_da_args *args,
210-
const unsigned char *name,
211-
int len)
212-
{
213-
if (unlikely(xfs_sb_version_hasasciici(&args->dp->i_mount->m_sb)))
214-
return xfs_ascii_ci_compname(args, name, len);
215-
return xfs_da_compname(args, name, len);
216-
}
203+
xfs_dahash_t xfs_dir2_hashname(struct xfs_mount *mp, struct xfs_name *name);
204+
enum xfs_dacmp xfs_dir2_compname(struct xfs_da_args *args,
205+
const unsigned char *name, int len);
217206

218207
#endif /* __XFS_DIR2_PRIV_H__ */

fs/xfs/libxfs/xfs_dir2_sf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void xfs_dir2_sf_check(xfs_da_args_t *args);
3737
static void xfs_dir2_sf_toino4(xfs_da_args_t *args);
3838
static void xfs_dir2_sf_toino8(xfs_da_args_t *args);
3939

40-
static int
40+
int
4141
xfs_dir2_sf_entsize(
4242
struct xfs_mount *mp,
4343
struct xfs_dir2_sf_hdr *hdr,
@@ -84,7 +84,7 @@ xfs_dir2_sf_get_ino(
8484
return get_unaligned_be64(from) & XFS_MAXINUMBER;
8585
}
8686

87-
static void
87+
void
8888
xfs_dir2_sf_put_ino(
8989
struct xfs_mount *mp,
9090
struct xfs_dir2_sf_hdr *hdr,
@@ -145,7 +145,7 @@ xfs_dir2_sf_get_ftype(
145145
return XFS_DIR3_FT_UNKNOWN;
146146
}
147147

148-
static void
148+
void
149149
xfs_dir2_sf_put_ftype(
150150
struct xfs_mount *mp,
151151
struct xfs_dir2_sf_entry *sfep,

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,3 +2909,67 @@ xfs_ialloc_setup_geometry(
29092909
else
29102910
igeo->ialloc_align = 0;
29112911
}
2912+
2913+
/* Compute the location of the root directory inode that is laid out by mkfs. */
2914+
xfs_ino_t
2915+
xfs_ialloc_calc_rootino(
2916+
struct xfs_mount *mp,
2917+
int sunit)
2918+
{
2919+
struct xfs_ino_geometry *igeo = M_IGEO(mp);
2920+
xfs_agblock_t first_bno;
2921+
2922+
/*
2923+
* Pre-calculate the geometry of AG 0. We know what it looks like
2924+
* because libxfs knows how to create allocation groups now.
2925+
*
2926+
* first_bno is the first block in which mkfs could possibly have
2927+
* allocated the root directory inode, once we factor in the metadata
2928+
* that mkfs formats before it. Namely, the four AG headers...
2929+
*/
2930+
first_bno = howmany(4 * mp->m_sb.sb_sectsize, mp->m_sb.sb_blocksize);
2931+
2932+
/* ...the two free space btree roots... */
2933+
first_bno += 2;
2934+
2935+
/* ...the inode btree root... */
2936+
first_bno += 1;
2937+
2938+
/* ...the initial AGFL... */
2939+
first_bno += xfs_alloc_min_freelist(mp, NULL);
2940+
2941+
/* ...the free inode btree root... */
2942+
if (xfs_sb_version_hasfinobt(&mp->m_sb))
2943+
first_bno++;
2944+
2945+
/* ...the reverse mapping btree root... */
2946+
if (xfs_sb_version_hasrmapbt(&mp->m_sb))
2947+
first_bno++;
2948+
2949+
/* ...the reference count btree... */
2950+
if (xfs_sb_version_hasreflink(&mp->m_sb))
2951+
first_bno++;
2952+
2953+
/*
2954+
* ...and the log, if it is allocated in the first allocation group.
2955+
*
2956+
* This can happen with filesystems that only have a single
2957+
* allocation group, or very odd geometries created by old mkfs
2958+
* versions on very small filesystems.
2959+
*/
2960+
if (mp->m_sb.sb_logstart &&
2961+
XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart) == 0)
2962+
first_bno += mp->m_sb.sb_logblocks;
2963+
2964+
/*
2965+
* Now round first_bno up to whatever allocation alignment is given
2966+
* by the filesystem or was passed in.
2967+
*/
2968+
if (xfs_sb_version_hasdalign(&mp->m_sb) && igeo->ialloc_align > 0)
2969+
first_bno = roundup(first_bno, sunit);
2970+
else if (xfs_sb_version_hasalign(&mp->m_sb) &&
2971+
mp->m_sb.sb_inoalignmt > 1)
2972+
first_bno = roundup(first_bno, mp->m_sb.sb_inoalignmt);
2973+
2974+
return XFS_AGINO_TO_INO(mp, 0, XFS_AGB_TO_AGINO(mp, first_bno));
2975+
}

fs/xfs/libxfs/xfs_ialloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,6 @@ int xfs_inobt_insert_rec(struct xfs_btree_cur *cur, uint16_t holemask,
152152

153153
int xfs_ialloc_cluster_alignment(struct xfs_mount *mp);
154154
void xfs_ialloc_setup_geometry(struct xfs_mount *mp);
155+
xfs_ino_t xfs_ialloc_calc_rootino(struct xfs_mount *mp, int sunit);
155156

156157
#endif /* __XFS_IALLOC_H__ */

fs/xfs/libxfs/xfs_trans_resv.c

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ xfs_calc_inode_chunk_res(
196196
return res;
197197
}
198198

199+
/*
200+
* Per-extent log reservation for the btree changes involved in freeing or
201+
* allocating a realtime extent. We have to be able to log as many rtbitmap
202+
* blocks as needed to mark inuse MAXEXTLEN blocks' worth of realtime extents,
203+
* as well as the realtime summary block.
204+
*/
205+
static unsigned int
206+
xfs_rtalloc_log_count(
207+
struct xfs_mount *mp,
208+
unsigned int num_ops)
209+
{
210+
unsigned int blksz = XFS_FSB_TO_B(mp, 1);
211+
unsigned int rtbmp_bytes;
212+
213+
rtbmp_bytes = (MAXEXTLEN / mp->m_sb.sb_rextsize) / NBBY;
214+
return (howmany(rtbmp_bytes, blksz) + 1) * num_ops;
215+
}
216+
199217
/*
200218
* Various log reservation values.
201219
*
@@ -218,13 +236,21 @@ xfs_calc_inode_chunk_res(
218236

219237
/*
220238
* In a write transaction we can allocate a maximum of 2
221-
* extents. This gives:
239+
* extents. This gives (t1):
222240
* the inode getting the new extents: inode size
223241
* the inode's bmap btree: max depth * block size
224242
* the agfs of the ags from which the extents are allocated: 2 * sector
225243
* the superblock free block counter: sector size
226244
* the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
227-
* And the bmap_finish transaction can free bmap blocks in a join:
245+
* Or, if we're writing to a realtime file (t2):
246+
* the inode getting the new extents: inode size
247+
* the inode's bmap btree: max depth * block size
248+
* the agfs of the ags from which the extents are allocated: 2 * sector
249+
* the superblock free block counter: sector size
250+
* the realtime bitmap: ((MAXEXTLEN / rtextsize) / NBBY) bytes
251+
* the realtime summary: 1 block
252+
* the allocation btrees: 2 trees * (2 * max depth - 1) * block size
253+
* And the bmap_finish transaction can free bmap blocks in a join (t3):
228254
* the agfs of the ags containing the blocks: 2 * sector size
229255
* the agfls of the ags containing the blocks: 2 * sector size
230256
* the super block free block counter: sector size
@@ -234,40 +260,72 @@ STATIC uint
234260
xfs_calc_write_reservation(
235261
struct xfs_mount *mp)
236262
{
237-
return XFS_DQUOT_LOGRES(mp) +
238-
max((xfs_calc_inode_res(mp, 1) +
263+
unsigned int t1, t2, t3;
264+
unsigned int blksz = XFS_FSB_TO_B(mp, 1);
265+
266+
t1 = xfs_calc_inode_res(mp, 1) +
267+
xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), blksz) +
268+
xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
269+
xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2), blksz);
270+
271+
if (xfs_sb_version_hasrealtime(&mp->m_sb)) {
272+
t2 = xfs_calc_inode_res(mp, 1) +
239273
xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
240-
XFS_FSB_TO_B(mp, 1)) +
274+
blksz) +
241275
xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
242-
xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2),
243-
XFS_FSB_TO_B(mp, 1))),
244-
(xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
245-
xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2),
246-
XFS_FSB_TO_B(mp, 1))));
276+
xfs_calc_buf_res(xfs_rtalloc_log_count(mp, 1), blksz) +
277+
xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1), blksz);
278+
} else {
279+
t2 = 0;
280+
}
281+
282+
t3 = xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
283+
xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2), blksz);
284+
285+
return XFS_DQUOT_LOGRES(mp) + max3(t1, t2, t3);
247286
}
248287

249288
/*
250-
* In truncating a file we free up to two extents at once. We can modify:
289+
* In truncating a file we free up to two extents at once. We can modify (t1):
251290
* the inode being truncated: inode size
252291
* the inode's bmap btree: (max depth + 1) * block size
253-
* And the bmap_finish transaction can free the blocks and bmap blocks:
292+
* And the bmap_finish transaction can free the blocks and bmap blocks (t2):
254293
* the agf for each of the ags: 4 * sector size
255294
* the agfl for each of the ags: 4 * sector size
256295
* the super block to reflect the freed blocks: sector size
257296
* worst case split in allocation btrees per extent assuming 4 extents:
258297
* 4 exts * 2 trees * (2 * max depth - 1) * block size
298+
* Or, if it's a realtime file (t3):
299+
* the agf for each of the ags: 2 * sector size
300+
* the agfl for each of the ags: 2 * sector size
301+
* the super block to reflect the freed blocks: sector size
302+
* the realtime bitmap: 2 exts * ((MAXEXTLEN / rtextsize) / NBBY) bytes
303+
* the realtime summary: 2 exts * 1 block
304+
* worst case split in allocation btrees per extent assuming 2 extents:
305+
* 2 exts * 2 trees * (2 * max depth - 1) * block size
259306
*/
260307
STATIC uint
261308
xfs_calc_itruncate_reservation(
262309
struct xfs_mount *mp)
263310
{
264-
return XFS_DQUOT_LOGRES(mp) +
265-
max((xfs_calc_inode_res(mp, 1) +
266-
xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1,
267-
XFS_FSB_TO_B(mp, 1))),
268-
(xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
269-
xfs_calc_buf_res(xfs_allocfree_log_count(mp, 4),
270-
XFS_FSB_TO_B(mp, 1))));
311+
unsigned int t1, t2, t3;
312+
unsigned int blksz = XFS_FSB_TO_B(mp, 1);
313+
314+
t1 = xfs_calc_inode_res(mp, 1) +
315+
xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1, blksz);
316+
317+
t2 = xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
318+
xfs_calc_buf_res(xfs_allocfree_log_count(mp, 4), blksz);
319+
320+
if (xfs_sb_version_hasrealtime(&mp->m_sb)) {
321+
t3 = xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
322+
xfs_calc_buf_res(xfs_rtalloc_log_count(mp, 2), blksz) +
323+
xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2), blksz);
324+
} else {
325+
t3 = 0;
326+
}
327+
328+
return XFS_DQUOT_LOGRES(mp) + max3(t1, t2, t3);
271329
}
272330

273331
/*

fs/xfs/xfs_bmap_util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ xfs_prepare_shift(
992992
struct xfs_inode *ip,
993993
loff_t offset)
994994
{
995+
struct xfs_mount *mp = ip->i_mount;
995996
int error;
996997

997998
/*
@@ -1004,6 +1005,17 @@ xfs_prepare_shift(
10041005
return error;
10051006
}
10061007

1008+
/*
1009+
* Shift operations must stabilize the start block offset boundary along
1010+
* with the full range of the operation. If we don't, a COW writeback
1011+
* completion could race with an insert, front merge with the start
1012+
* extent (after split) during the shift and corrupt the file. Start
1013+
* with the block just prior to the start to stabilize the boundary.
1014+
*/
1015+
offset = round_down(offset, 1 << mp->m_sb.sb_blocklog);
1016+
if (offset)
1017+
offset -= (1 << mp->m_sb.sb_blocklog);
1018+
10071019
/*
10081020
* Writeback and invalidate cache for the remainder of the file as we're
10091021
* about to shift down every extent from offset to EOF.

0 commit comments

Comments
 (0)