Lines Matching +full:ip +full:- +full:blocks
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2018-2024 Oracle. All Rights Reserved.
47 struct xfs_inode *ip, in xfs_metafile_set_iflag() argument
50 VFS_I(ip)->i_mode &= ~0777; in xfs_metafile_set_iflag()
51 VFS_I(ip)->i_uid = GLOBAL_ROOT_UID; in xfs_metafile_set_iflag()
52 VFS_I(ip)->i_gid = GLOBAL_ROOT_GID; in xfs_metafile_set_iflag()
53 if (S_ISDIR(VFS_I(ip)->i_mode)) in xfs_metafile_set_iflag()
54 ip->i_diflags |= XFS_METADIR_DIFLAGS; in xfs_metafile_set_iflag()
56 ip->i_diflags |= XFS_METAFILE_DIFLAGS; in xfs_metafile_set_iflag()
57 ip->i_diflags2 &= ~XFS_DIFLAG2_DAX; in xfs_metafile_set_iflag()
58 ip->i_diflags2 |= XFS_DIFLAG2_METADATA; in xfs_metafile_set_iflag()
59 ip->i_metatype = metafile_type; in xfs_metafile_set_iflag()
60 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_metafile_set_iflag()
67 struct xfs_inode *ip) in xfs_metafile_clear_iflag() argument
69 ASSERT(xfs_is_metadir_inode(ip)); in xfs_metafile_clear_iflag()
70 ASSERT(VFS_I(ip)->i_nlink == 0); in xfs_metafile_clear_iflag()
72 ip->i_diflags2 &= ~XFS_DIFLAG2_METADATA; in xfs_metafile_clear_iflag()
73 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_metafile_clear_iflag()
82 struct xfs_inode *ip, in xfs_metafile_resv_can_cover() argument
89 * touching the per-cpu counter. in xfs_metafile_resv_can_cover()
91 if (ip->i_delayed_blks >= rhs) in xfs_metafile_resv_can_cover()
95 * There aren't enough blocks left in the inode's reservation, but it in xfs_metafile_resv_can_cover()
98 return __percpu_counter_compare(&ip->i_mount->m_fdblocks, in xfs_metafile_resv_can_cover()
99 rhs - ip->i_delayed_blks, 2048) >= 0; in xfs_metafile_resv_can_cover()
103 * Is this metadata file critically low on blocks? For now we'll define that
104 * as the number of blocks we can get our hands on being less than 10% of what
109 struct xfs_inode *ip) in xfs_metafile_resv_critical() argument
113 if (!ip) in xfs_metafile_resv_critical()
116 ASSERT(xfs_is_metadir_inode(ip)); in xfs_metafile_resv_critical()
117 trace_xfs_metafile_resv_critical(ip, 0); in xfs_metafile_resv_critical()
119 if (!xfs_metafile_resv_can_cover(ip, ip->i_mount->m_rtbtree_maxlevels)) in xfs_metafile_resv_critical()
122 asked_low_water = div_u64(ip->i_meta_resv_asked, 10); in xfs_metafile_resv_critical()
123 if (!xfs_metafile_resv_can_cover(ip, asked_low_water)) in xfs_metafile_resv_critical()
126 return XFS_TEST_ERROR(false, ip->i_mount, in xfs_metafile_resv_critical()
133 struct xfs_inode *ip, in xfs_metafile_resv_alloc_space() argument
136 int64_t len = args->len; in xfs_metafile_resv_alloc_space()
138 ASSERT(xfs_is_metadir_inode(ip)); in xfs_metafile_resv_alloc_space()
139 ASSERT(args->resv == XFS_AG_RESV_METAFILE); in xfs_metafile_resv_alloc_space()
141 trace_xfs_metafile_resv_alloc_space(ip, args->len); in xfs_metafile_resv_alloc_space()
144 * Allocate the blocks from the metadata inode's block reservation in xfs_metafile_resv_alloc_space()
147 if (ip->i_delayed_blks > 0) { in xfs_metafile_resv_alloc_space()
150 from_resv = min_t(int64_t, len, ip->i_delayed_blks); in xfs_metafile_resv_alloc_space()
151 ip->i_delayed_blks -= from_resv; in xfs_metafile_resv_alloc_space()
152 xfs_mod_delalloc(ip, 0, -from_resv); in xfs_metafile_resv_alloc_space()
153 xfs_trans_mod_sb(args->tp, XFS_TRANS_SB_RES_FDBLOCKS, in xfs_metafile_resv_alloc_space()
154 -from_resv); in xfs_metafile_resv_alloc_space()
155 len -= from_resv; in xfs_metafile_resv_alloc_space()
159 * Any allocation in excess of the reservation requires in-core and in xfs_metafile_resv_alloc_space()
160 * on-disk fdblocks updates. If we can grab @len blocks from the in xfs_metafile_resv_alloc_space()
161 * in-core fdblocks then all we need to do is update the on-disk in xfs_metafile_resv_alloc_space()
169 error = xfs_dec_fdblocks(ip->i_mount, len, true); in xfs_metafile_resv_alloc_space()
175 xfs_trans_mod_sb(args->tp, field, -len); in xfs_metafile_resv_alloc_space()
178 ip->i_nblocks += args->len; in xfs_metafile_resv_alloc_space()
179 xfs_trans_log_inode(args->tp, ip, XFS_ILOG_CORE); in xfs_metafile_resv_alloc_space()
185 struct xfs_inode *ip, in xfs_metafile_resv_free_space() argument
191 ASSERT(xfs_is_metadir_inode(ip)); in xfs_metafile_resv_free_space()
192 trace_xfs_metafile_resv_free_space(ip, len); in xfs_metafile_resv_free_space()
194 ip->i_nblocks -= len; in xfs_metafile_resv_free_space()
195 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_metafile_resv_free_space()
198 * Add the freed blocks back into the inode's delalloc reservation in xfs_metafile_resv_free_space()
201 to_resv = ip->i_meta_resv_asked - (ip->i_nblocks + ip->i_delayed_blks); in xfs_metafile_resv_free_space()
204 ip->i_delayed_blks += to_resv; in xfs_metafile_resv_free_space()
205 xfs_mod_delalloc(ip, 0, to_resv); in xfs_metafile_resv_free_space()
207 len -= to_resv; in xfs_metafile_resv_free_space()
211 * Everything else goes back to the filesystem, so update the in-core in xfs_metafile_resv_free_space()
212 * and on-disk counters. in xfs_metafile_resv_free_space()
221 struct xfs_inode *ip) in xfs_metafile_resv_free() argument
223 /* Non-btree metadata inodes don't need space reservations. */ in xfs_metafile_resv_free()
224 if (!ip || !ip->i_meta_resv_asked) in xfs_metafile_resv_free()
227 ASSERT(xfs_is_metadir_inode(ip)); in xfs_metafile_resv_free()
228 trace_xfs_metafile_resv_free(ip, 0); in xfs_metafile_resv_free()
230 if (ip->i_delayed_blks) { in xfs_metafile_resv_free()
231 xfs_mod_delalloc(ip, 0, -ip->i_delayed_blks); in xfs_metafile_resv_free()
232 xfs_add_fdblocks(ip->i_mount, ip->i_delayed_blks); in xfs_metafile_resv_free()
233 ip->i_delayed_blks = 0; in xfs_metafile_resv_free()
235 ip->i_meta_resv_asked = 0; in xfs_metafile_resv_free()
241 struct xfs_inode *ip, in xfs_metafile_resv_init() argument
248 if (!ip || ip->i_meta_resv_asked > 0) in xfs_metafile_resv_init()
251 ASSERT(xfs_is_metadir_inode(ip)); in xfs_metafile_resv_init()
254 * Space taken by all other metadata btrees are accounted on-disk as in xfs_metafile_resv_init()
258 used = ip->i_nblocks; in xfs_metafile_resv_init()
261 hidden_space = ask - used; in xfs_metafile_resv_init()
263 error = xfs_dec_fdblocks(ip->i_mount, hidden_space, true); in xfs_metafile_resv_init()
265 trace_xfs_metafile_resv_init_error(ip, error, _RET_IP_); in xfs_metafile_resv_init()
269 xfs_mod_delalloc(ip, 0, hidden_space); in xfs_metafile_resv_init()
270 ip->i_delayed_blks = hidden_space; in xfs_metafile_resv_init()
271 ip->i_meta_resv_asked = ask; in xfs_metafile_resv_init()
273 trace_xfs_metafile_resv_init(ip, ask); in xfs_metafile_resv_init()