]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
5e656dbb | 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
da23017d | 3 | * All Rights Reserved. |
2bd0ea18 | 4 | * |
da23017d NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
2bd0ea18 NS |
7 | * published by the Free Software Foundation. |
8 | * | |
da23017d NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
2bd0ea18 | 13 | * |
da23017d NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2bd0ea18 | 17 | */ |
9c799827 | 18 | #include "libxfs_priv.h" |
b626fb59 DC |
19 | #include "xfs_fs.h" |
20 | #include "xfs_shared.h" | |
21 | #include "xfs_format.h" | |
22 | #include "xfs_log_format.h" | |
23 | #include "xfs_trans_resv.h" | |
24 | #include "xfs_bit.h" | |
25 | #include "xfs_sb.h" | |
26 | #include "xfs_mount.h" | |
f944d3d0 | 27 | #include "xfs_defer.h" |
b626fb59 DC |
28 | #include "xfs_inode.h" |
29 | #include "xfs_ialloc.h" | |
30 | #include "xfs_alloc.h" | |
31 | #include "xfs_trace.h" | |
32 | #include "xfs_cksum.h" | |
33 | #include "xfs_trans.h" | |
34 | #include "xfs_bmap_btree.h" | |
35 | #include "xfs_alloc_btree.h" | |
36 | #include "xfs_ialloc_btree.h" | |
b3a96b46 | 37 | #include "xfs_rmap_btree.h" |
d8079fe0 DW |
38 | #include "xfs_bmap.h" |
39 | #include "xfs_refcount_btree.h" | |
a2a52384 DW |
40 | #include "xfs_da_format.h" |
41 | #include "xfs_da_btree.h" | |
2bd0ea18 | 42 | |
4896e6c8 DC |
43 | /* |
44 | * Physical superblock buffer manipulations. Shared with libxfs in userspace. | |
45 | */ | |
46 | ||
56b2de80 DC |
47 | /* |
48 | * Reference counting access wrappers to the perag structures. | |
49 | * Because we never free per-ag structures, the only thing we | |
50 | * have to protect against changes is the tree structure itself. | |
51 | */ | |
52 | struct xfs_perag * | |
4896e6c8 DC |
53 | xfs_perag_get( |
54 | struct xfs_mount *mp, | |
55 | xfs_agnumber_t agno) | |
a33a9e62 | 56 | { |
56b2de80 DC |
57 | struct xfs_perag *pag; |
58 | int ref = 0; | |
59 | ||
60 | rcu_read_lock(); | |
61 | pag = radix_tree_lookup(&mp->m_perag_tree, agno); | |
62 | if (pag) { | |
63 | ASSERT(atomic_read(&pag->pag_ref) >= 0); | |
64 | ref = atomic_inc_return(&pag->pag_ref); | |
a33a9e62 | 65 | } |
56b2de80 | 66 | rcu_read_unlock(); |
a2ceac1f | 67 | trace_xfs_perag_get(mp, agno, ref, _RET_IP_); |
56b2de80 DC |
68 | return pag; |
69 | } | |
a33a9e62 | 70 | |
4896e6c8 DC |
71 | /* |
72 | * search from @first to find the next perag with the given tag set. | |
73 | */ | |
74 | struct xfs_perag * | |
75 | xfs_perag_get_tag( | |
76 | struct xfs_mount *mp, | |
77 | xfs_agnumber_t first, | |
78 | int tag) | |
79 | { | |
80 | struct xfs_perag *pag; | |
81 | int found; | |
82 | int ref; | |
83 | ||
84 | rcu_read_lock(); | |
85 | found = radix_tree_gang_lookup_tag(&mp->m_perag_tree, | |
86 | (void **)&pag, first, 1, tag); | |
87 | if (found <= 0) { | |
88 | rcu_read_unlock(); | |
89 | return NULL; | |
90 | } | |
91 | ref = atomic_inc_return(&pag->pag_ref); | |
92 | rcu_read_unlock(); | |
93 | trace_xfs_perag_get_tag(mp, pag->pag_agno, ref, _RET_IP_); | |
94 | return pag; | |
95 | } | |
96 | ||
56b2de80 | 97 | void |
4896e6c8 DC |
98 | xfs_perag_put( |
99 | struct xfs_perag *pag) | |
56b2de80 DC |
100 | { |
101 | int ref; | |
a33a9e62 | 102 | |
56b2de80 DC |
103 | ASSERT(atomic_read(&pag->pag_ref) > 0); |
104 | ref = atomic_dec_return(&pag->pag_ref); | |
105 | trace_xfs_perag_put(pag->pag_mount, pag->pag_agno, ref, _RET_IP_); | |
a33a9e62 | 106 | } |
cdded3d8 | 107 | |
a2ceac1f DC |
108 | /* |
109 | * Check the validity of the SB found. | |
110 | */ | |
111 | STATIC int | |
112 | xfs_mount_validate_sb( | |
113 | xfs_mount_t *mp, | |
114 | xfs_sb_t *sbp, | |
5629f836 DC |
115 | bool check_inprogress, |
116 | bool check_version) | |
a2ceac1f | 117 | { |
e91df844 DW |
118 | uint32_t agcount = 0; |
119 | uint32_t rem; | |
120 | ||
a2ceac1f DC |
121 | if (sbp->sb_magicnum != XFS_SB_MAGIC) { |
122 | xfs_warn(mp, "bad magic number"); | |
12b53197 | 123 | return -EWRONGFS; |
a2ceac1f DC |
124 | } |
125 | ||
5565d79a | 126 | |
a2ceac1f DC |
127 | if (!xfs_sb_good_version(sbp)) { |
128 | xfs_warn(mp, "bad version"); | |
12b53197 | 129 | return -EWRONGFS; |
a2ceac1f DC |
130 | } |
131 | ||
5565d79a | 132 | /* |
6567f1f9 | 133 | * Version 5 superblock feature mask validation. Reject combinations the |
4896e6c8 DC |
134 | * kernel cannot support up front before checking anything else. For |
135 | * write validation, we don't need to check feature masks. | |
5565d79a | 136 | */ |
5629f836 | 137 | if (check_version && XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) { |
6567f1f9 DC |
138 | if (xfs_sb_has_compat_feature(sbp, |
139 | XFS_SB_FEAT_COMPAT_UNKNOWN)) { | |
140 | xfs_warn(mp, | |
2c2ec8ff | 141 | "Superblock has unknown compatible features (0x%x) enabled.", |
6567f1f9 DC |
142 | (sbp->sb_features_compat & |
143 | XFS_SB_FEAT_COMPAT_UNKNOWN)); | |
2c2ec8ff JP |
144 | xfs_warn(mp, |
145 | "Using a more recent kernel is recommended."); | |
6567f1f9 DC |
146 | } |
147 | ||
148 | if (xfs_sb_has_ro_compat_feature(sbp, | |
149 | XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) { | |
ff105f75 DC |
150 | xfs_alert(mp, |
151 | "Superblock has unknown read-only compatible features (0x%x) enabled.", | |
6567f1f9 DC |
152 | (sbp->sb_features_ro_compat & |
153 | XFS_SB_FEAT_RO_COMPAT_UNKNOWN)); | |
ff105f75 DC |
154 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { |
155 | xfs_warn(mp, | |
2c2ec8ff JP |
156 | "Attempted to mount read-only compatible filesystem read-write."); |
157 | xfs_warn(mp, | |
ff105f75 | 158 | "Filesystem can only be safely mounted read only."); |
2c2ec8ff | 159 | |
12b53197 | 160 | return -EINVAL; |
ff105f75 | 161 | } |
6567f1f9 DC |
162 | } |
163 | if (xfs_sb_has_incompat_feature(sbp, | |
164 | XFS_SB_FEAT_INCOMPAT_UNKNOWN)) { | |
165 | xfs_warn(mp, | |
2c2ec8ff | 166 | "Superblock has unknown incompatible features (0x%x) enabled.", |
6567f1f9 DC |
167 | (sbp->sb_features_incompat & |
168 | XFS_SB_FEAT_INCOMPAT_UNKNOWN)); | |
2c2ec8ff JP |
169 | xfs_warn(mp, |
170 | "Filesystem can not be safely mounted by this kernel."); | |
12b53197 | 171 | return -EINVAL; |
6567f1f9 | 172 | } |
a65d8d29 BF |
173 | } else if (xfs_sb_version_hascrc(sbp)) { |
174 | /* | |
175 | * We can't read verify the sb LSN because the read verifier is | |
176 | * called before the log is allocated and processed. We know the | |
177 | * log is set up before write verifier (!check_version) calls, | |
178 | * so just check it here. | |
179 | */ | |
180 | if (!xfs_log_check_lsn(mp, sbp->sb_lsn)) | |
181 | return -EFSCORRUPTED; | |
5565d79a DC |
182 | } |
183 | ||
4896e6c8 DC |
184 | if (xfs_sb_version_has_pquotino(sbp)) { |
185 | if (sbp->sb_qflags & (XFS_OQUOTA_ENFD | XFS_OQUOTA_CHKD)) { | |
186 | xfs_notice(mp, | |
12864fd9 | 187 | "Version 5 of Super block has XFS_OQUOTA bits."); |
12b53197 | 188 | return -EFSCORRUPTED; |
4896e6c8 DC |
189 | } |
190 | } else if (sbp->sb_qflags & (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD | | |
191 | XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD)) { | |
192 | xfs_notice(mp, | |
12864fd9 | 193 | "Superblock earlier than Version 5 has XFS_[PQ]UOTA_{ENFD|CHKD} bits."); |
12b53197 | 194 | return -EFSCORRUPTED; |
342aef1e CS |
195 | } |
196 | ||
7f5cd45d BF |
197 | /* |
198 | * Full inode chunks must be aligned to inode chunk size when | |
199 | * sparse inodes are enabled to support the sparse chunk | |
200 | * allocation algorithm and prevent overlapping inode records. | |
201 | */ | |
202 | if (xfs_sb_version_hassparseinodes(sbp)) { | |
203 | uint32_t align; | |
204 | ||
7f5cd45d BF |
205 | align = XFS_INODES_PER_CHUNK * sbp->sb_inodesize |
206 | >> sbp->sb_blocklog; | |
207 | if (sbp->sb_inoalignmt != align) { | |
208 | xfs_warn(mp, | |
209 | "Inode block alignment (%u) must match chunk size (%u) for sparse inodes.", | |
210 | sbp->sb_inoalignmt, align); | |
211 | return -EINVAL; | |
212 | } | |
213 | } | |
214 | ||
a2ceac1f | 215 | if (unlikely( |
6567f1f9 | 216 | sbp->sb_logstart == 0 && mp->m_logdev_targp == mp->m_ddev_targp)) { |
a2ceac1f DC |
217 | xfs_warn(mp, |
218 | "filesystem is marked as having an external log; " | |
219 | "specify logdev on the mount command line."); | |
12b53197 | 220 | return -EINVAL; |
a2ceac1f DC |
221 | } |
222 | ||
223 | if (unlikely( | |
6567f1f9 | 224 | sbp->sb_logstart != 0 && mp->m_logdev_targp != mp->m_ddev_targp)) { |
a2ceac1f DC |
225 | xfs_warn(mp, |
226 | "filesystem is marked as having an internal log; " | |
227 | "do not specify logdev on the mount command line."); | |
12b53197 | 228 | return -EINVAL; |
a2ceac1f DC |
229 | } |
230 | ||
e91df844 DW |
231 | /* Compute agcount for this number of dblocks and agblocks */ |
232 | if (sbp->sb_agblocks) { | |
233 | agcount = div_u64_rem(sbp->sb_dblocks, sbp->sb_agblocks, &rem); | |
234 | if (rem) | |
235 | agcount++; | |
236 | } | |
237 | ||
a2ceac1f DC |
238 | /* |
239 | * More sanity checking. Most of these were stolen directly from | |
240 | * xfs_repair. | |
241 | */ | |
242 | if (unlikely( | |
243 | sbp->sb_agcount <= 0 || | |
244 | sbp->sb_sectsize < XFS_MIN_SECTORSIZE || | |
245 | sbp->sb_sectsize > XFS_MAX_SECTORSIZE || | |
246 | sbp->sb_sectlog < XFS_MIN_SECTORSIZE_LOG || | |
247 | sbp->sb_sectlog > XFS_MAX_SECTORSIZE_LOG || | |
248 | sbp->sb_sectsize != (1 << sbp->sb_sectlog) || | |
249 | sbp->sb_blocksize < XFS_MIN_BLOCKSIZE || | |
250 | sbp->sb_blocksize > XFS_MAX_BLOCKSIZE || | |
251 | sbp->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG || | |
252 | sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG || | |
253 | sbp->sb_blocksize != (1 << sbp->sb_blocklog) || | |
2e6fca28 | 254 | sbp->sb_dirblklog + sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG || |
a2ceac1f DC |
255 | sbp->sb_inodesize < XFS_DINODE_MIN_SIZE || |
256 | sbp->sb_inodesize > XFS_DINODE_MAX_SIZE || | |
257 | sbp->sb_inodelog < XFS_DINODE_MIN_LOG || | |
258 | sbp->sb_inodelog > XFS_DINODE_MAX_LOG || | |
259 | sbp->sb_inodesize != (1 << sbp->sb_inodelog) || | |
5a35bf2c | 260 | sbp->sb_logsunit > XLOG_MAX_RECORD_BSIZE || |
4b0c789d | 261 | sbp->sb_inopblock != howmany(sbp->sb_blocksize,sbp->sb_inodesize) || |
e91df844 DW |
262 | XFS_FSB_TO_B(mp, sbp->sb_agblocks) < XFS_MIN_AG_BYTES || |
263 | XFS_FSB_TO_B(mp, sbp->sb_agblocks) > XFS_MAX_AG_BYTES || | |
264 | sbp->sb_agblklog != xfs_highbit32(sbp->sb_agblocks - 1) + 1 || | |
265 | agcount == 0 || agcount != sbp->sb_agcount || | |
a2ceac1f DC |
266 | (sbp->sb_blocklog - sbp->sb_inodelog != sbp->sb_inopblog) || |
267 | (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE) || | |
268 | (sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE) || | |
269 | (sbp->sb_imax_pct > 100 /* zero sb_imax_pct is valid */) || | |
270 | sbp->sb_dblocks == 0 || | |
271 | sbp->sb_dblocks > XFS_MAX_DBLOCKS(sbp) || | |
ff105f75 DC |
272 | sbp->sb_dblocks < XFS_MIN_DBLOCKS(sbp) || |
273 | sbp->sb_shared_vn != 0)) { | |
ba5027e0 | 274 | xfs_notice(mp, "SB sanity check failed"); |
12b53197 | 275 | return -EFSCORRUPTED; |
a2ceac1f DC |
276 | } |
277 | ||
342ec632 DW |
278 | if (xfs_sb_version_hascrc(&mp->m_sb) && |
279 | sbp->sb_blocksize < XFS_MIN_CRC_BLOCKSIZE) { | |
280 | xfs_notice(mp, "v5 SB sanity check failed"); | |
281 | return -EFSCORRUPTED; | |
282 | } | |
283 | ||
a2ceac1f DC |
284 | /* |
285 | * Currently only very few inode sizes are supported. | |
286 | */ | |
287 | switch (sbp->sb_inodesize) { | |
288 | case 256: | |
289 | case 512: | |
290 | case 1024: | |
291 | case 2048: | |
292 | break; | |
293 | default: | |
294 | xfs_warn(mp, "inode size of %d bytes not supported", | |
295 | sbp->sb_inodesize); | |
12b53197 | 296 | return -ENOSYS; |
a2ceac1f DC |
297 | } |
298 | ||
4896e6c8 DC |
299 | if (xfs_sb_validate_fsb_count(sbp, sbp->sb_dblocks) || |
300 | xfs_sb_validate_fsb_count(sbp, sbp->sb_rblocks)) { | |
301 | xfs_warn(mp, | |
302 | "file system too large to be mounted on this system."); | |
12b53197 | 303 | return -EFBIG; |
4896e6c8 DC |
304 | } |
305 | ||
a2ceac1f DC |
306 | return 0; |
307 | } | |
308 | ||
4896e6c8 DC |
309 | void |
310 | xfs_sb_quota_from_disk(struct xfs_sb *sbp) | |
311 | { | |
312 | /* | |
313 | * older mkfs doesn't initialize quota inodes to NULLFSINO. This | |
314 | * leads to in-core values having two different values for a quota | |
315 | * inode to be invalid: 0 and NULLFSINO. Change it to a single value | |
316 | * NULLFSINO. | |
317 | * | |
318 | * Note that this change affect only the in-core values. These | |
319 | * values are not written back to disk unless any quota information | |
320 | * is written to the disk. Even in that case, sb_pquotino field is | |
321 | * not written to disk unless the superblock supports pquotino. | |
322 | */ | |
323 | if (sbp->sb_uquotino == 0) | |
324 | sbp->sb_uquotino = NULLFSINO; | |
325 | if (sbp->sb_gquotino == 0) | |
326 | sbp->sb_gquotino = NULLFSINO; | |
327 | if (sbp->sb_pquotino == 0) | |
328 | sbp->sb_pquotino = NULLFSINO; | |
329 | ||
330 | /* | |
331 | * We need to do these manipilations only if we are working | |
332 | * with an older version of on-disk superblock. | |
333 | */ | |
334 | if (xfs_sb_version_has_pquotino(sbp)) | |
335 | return; | |
336 | ||
337 | if (sbp->sb_qflags & XFS_OQUOTA_ENFD) | |
338 | sbp->sb_qflags |= (sbp->sb_qflags & XFS_PQUOTA_ACCT) ? | |
339 | XFS_PQUOTA_ENFD : XFS_GQUOTA_ENFD; | |
340 | if (sbp->sb_qflags & XFS_OQUOTA_CHKD) | |
341 | sbp->sb_qflags |= (sbp->sb_qflags & XFS_PQUOTA_ACCT) ? | |
342 | XFS_PQUOTA_CHKD : XFS_GQUOTA_CHKD; | |
343 | sbp->sb_qflags &= ~(XFS_OQUOTA_ENFD | XFS_OQUOTA_CHKD); | |
344 | ||
ee375425 ES |
345 | if (sbp->sb_qflags & XFS_PQUOTA_ACCT && |
346 | sbp->sb_gquotino != NULLFSINO) { | |
4896e6c8 DC |
347 | /* |
348 | * In older version of superblock, on-disk superblock only | |
349 | * has sb_gquotino, and in-core superblock has both sb_gquotino | |
350 | * and sb_pquotino. But, only one of them is supported at any | |
351 | * point of time. So, if PQUOTA is set in disk superblock, | |
ee375425 ES |
352 | * copy over sb_gquotino to sb_pquotino. The NULLFSINO test |
353 | * above is to make sure we don't do this twice and wipe them | |
354 | * both out! | |
4896e6c8 DC |
355 | */ |
356 | sbp->sb_pquotino = sbp->sb_gquotino; | |
357 | sbp->sb_gquotino = NULLFSINO; | |
358 | } | |
359 | } | |
360 | ||
5a35bf2c DC |
361 | static void |
362 | __xfs_sb_from_disk( | |
4896e6c8 | 363 | struct xfs_sb *to, |
5a35bf2c DC |
364 | xfs_dsb_t *from, |
365 | bool convert_xquota) | |
5e656dbb BN |
366 | { |
367 | to->sb_magicnum = be32_to_cpu(from->sb_magicnum); | |
368 | to->sb_blocksize = be32_to_cpu(from->sb_blocksize); | |
369 | to->sb_dblocks = be64_to_cpu(from->sb_dblocks); | |
370 | to->sb_rblocks = be64_to_cpu(from->sb_rblocks); | |
371 | to->sb_rextents = be64_to_cpu(from->sb_rextents); | |
372 | memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid)); | |
373 | to->sb_logstart = be64_to_cpu(from->sb_logstart); | |
374 | to->sb_rootino = be64_to_cpu(from->sb_rootino); | |
375 | to->sb_rbmino = be64_to_cpu(from->sb_rbmino); | |
376 | to->sb_rsumino = be64_to_cpu(from->sb_rsumino); | |
377 | to->sb_rextsize = be32_to_cpu(from->sb_rextsize); | |
378 | to->sb_agblocks = be32_to_cpu(from->sb_agblocks); | |
379 | to->sb_agcount = be32_to_cpu(from->sb_agcount); | |
380 | to->sb_rbmblocks = be32_to_cpu(from->sb_rbmblocks); | |
381 | to->sb_logblocks = be32_to_cpu(from->sb_logblocks); | |
382 | to->sb_versionnum = be16_to_cpu(from->sb_versionnum); | |
383 | to->sb_sectsize = be16_to_cpu(from->sb_sectsize); | |
384 | to->sb_inodesize = be16_to_cpu(from->sb_inodesize); | |
385 | to->sb_inopblock = be16_to_cpu(from->sb_inopblock); | |
386 | memcpy(&to->sb_fname, &from->sb_fname, sizeof(to->sb_fname)); | |
387 | to->sb_blocklog = from->sb_blocklog; | |
388 | to->sb_sectlog = from->sb_sectlog; | |
389 | to->sb_inodelog = from->sb_inodelog; | |
390 | to->sb_inopblog = from->sb_inopblog; | |
391 | to->sb_agblklog = from->sb_agblklog; | |
392 | to->sb_rextslog = from->sb_rextslog; | |
393 | to->sb_inprogress = from->sb_inprogress; | |
394 | to->sb_imax_pct = from->sb_imax_pct; | |
395 | to->sb_icount = be64_to_cpu(from->sb_icount); | |
396 | to->sb_ifree = be64_to_cpu(from->sb_ifree); | |
397 | to->sb_fdblocks = be64_to_cpu(from->sb_fdblocks); | |
398 | to->sb_frextents = be64_to_cpu(from->sb_frextents); | |
399 | to->sb_uquotino = be64_to_cpu(from->sb_uquotino); | |
400 | to->sb_gquotino = be64_to_cpu(from->sb_gquotino); | |
401 | to->sb_qflags = be16_to_cpu(from->sb_qflags); | |
402 | to->sb_flags = from->sb_flags; | |
403 | to->sb_shared_vn = from->sb_shared_vn; | |
404 | to->sb_inoalignmt = be32_to_cpu(from->sb_inoalignmt); | |
405 | to->sb_unit = be32_to_cpu(from->sb_unit); | |
406 | to->sb_width = be32_to_cpu(from->sb_width); | |
407 | to->sb_dirblklog = from->sb_dirblklog; | |
408 | to->sb_logsectlog = from->sb_logsectlog; | |
409 | to->sb_logsectsize = be16_to_cpu(from->sb_logsectsize); | |
410 | to->sb_logsunit = be32_to_cpu(from->sb_logsunit); | |
411 | to->sb_features2 = be32_to_cpu(from->sb_features2); | |
412 | to->sb_bad_features2 = be32_to_cpu(from->sb_bad_features2); | |
5565d79a DC |
413 | to->sb_features_compat = be32_to_cpu(from->sb_features_compat); |
414 | to->sb_features_ro_compat = be32_to_cpu(from->sb_features_ro_compat); | |
415 | to->sb_features_incompat = be32_to_cpu(from->sb_features_incompat); | |
6567f1f9 DC |
416 | to->sb_features_log_incompat = |
417 | be32_to_cpu(from->sb_features_log_incompat); | |
5a35bf2c DC |
418 | /* crc is only used on disk, not in memory; just init to 0 here. */ |
419 | to->sb_crc = 0; | |
6bd8b7e1 | 420 | to->sb_spino_align = be32_to_cpu(from->sb_spino_align); |
5565d79a DC |
421 | to->sb_pquotino = be64_to_cpu(from->sb_pquotino); |
422 | to->sb_lsn = be64_to_cpu(from->sb_lsn); | |
9c4e12fb ES |
423 | /* |
424 | * sb_meta_uuid is only on disk if it differs from sb_uuid and the | |
425 | * feature flag is set; if not set we keep it only in memory. | |
426 | */ | |
427 | if (xfs_sb_version_hasmetauuid(to)) | |
428 | uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid); | |
429 | else | |
430 | uuid_copy(&to->sb_meta_uuid, &from->sb_uuid); | |
5a35bf2c DC |
431 | /* Convert on-disk flags to in-memory flags? */ |
432 | if (convert_xquota) | |
433 | xfs_sb_quota_from_disk(to); | |
434 | } | |
435 | ||
436 | void | |
437 | xfs_sb_from_disk( | |
438 | struct xfs_sb *to, | |
439 | xfs_dsb_t *from) | |
440 | { | |
441 | __xfs_sb_from_disk(to, from, true); | |
5e656dbb BN |
442 | } |
443 | ||
19ebedcf | 444 | static void |
342aef1e | 445 | xfs_sb_quota_to_disk( |
19ebedcf DC |
446 | struct xfs_dsb *to, |
447 | struct xfs_sb *from) | |
342aef1e | 448 | { |
4a492e72 | 449 | uint16_t qflags = from->sb_qflags; |
342aef1e | 450 | |
19ebedcf DC |
451 | to->sb_uquotino = cpu_to_be64(from->sb_uquotino); |
452 | if (xfs_sb_version_has_pquotino(from)) { | |
453 | to->sb_qflags = cpu_to_be16(from->sb_qflags); | |
454 | to->sb_gquotino = cpu_to_be64(from->sb_gquotino); | |
455 | to->sb_pquotino = cpu_to_be64(from->sb_pquotino); | |
456 | return; | |
457 | } | |
458 | ||
0340d706 | 459 | /* |
19ebedcf DC |
460 | * The in-core version of sb_qflags do not have XFS_OQUOTA_* |
461 | * flags, whereas the on-disk version does. So, convert incore | |
462 | * XFS_{PG}QUOTA_* flags to on-disk XFS_OQUOTA_* flags. | |
0340d706 | 463 | */ |
19ebedcf DC |
464 | qflags &= ~(XFS_PQUOTA_ENFD | XFS_PQUOTA_CHKD | |
465 | XFS_GQUOTA_ENFD | XFS_GQUOTA_CHKD); | |
0340d706 | 466 | |
19ebedcf DC |
467 | if (from->sb_qflags & |
468 | (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD)) | |
469 | qflags |= XFS_OQUOTA_ENFD; | |
470 | if (from->sb_qflags & | |
471 | (XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD)) | |
472 | qflags |= XFS_OQUOTA_CHKD; | |
473 | to->sb_qflags = cpu_to_be16(qflags); | |
0340d706 CS |
474 | |
475 | /* | |
19ebedcf DC |
476 | * GQUOTINO and PQUOTINO cannot be used together in versions |
477 | * of superblock that do not have pquotino. from->sb_flags | |
478 | * tells us which quota is active and should be copied to | |
479 | * disk. If neither are active, we should NULL the inode. | |
ff105f75 | 480 | * |
19ebedcf DC |
481 | * In all cases, the separate pquotino must remain 0 because it |
482 | * it beyond the "end" of the valid non-pquotino superblock. | |
0340d706 | 483 | */ |
19ebedcf | 484 | if (from->sb_qflags & XFS_GQUOTA_ACCT) |
0340d706 | 485 | to->sb_gquotino = cpu_to_be64(from->sb_gquotino); |
19ebedcf | 486 | else if (from->sb_qflags & XFS_PQUOTA_ACCT) |
0340d706 | 487 | to->sb_gquotino = cpu_to_be64(from->sb_pquotino); |
ff105f75 DC |
488 | else { |
489 | /* | |
490 | * We can't rely on just the fields being logged to tell us | |
491 | * that it is safe to write NULLFSINO - we should only do that | |
492 | * if quotas are not actually enabled. Hence only write | |
493 | * NULLFSINO if both in-core quota inodes are NULL. | |
494 | */ | |
495 | if (from->sb_gquotino == NULLFSINO && | |
496 | from->sb_pquotino == NULLFSINO) | |
497 | to->sb_gquotino = cpu_to_be64(NULLFSINO); | |
498 | } | |
0340d706 | 499 | |
19ebedcf | 500 | to->sb_pquotino = 0; |
342aef1e CS |
501 | } |
502 | ||
5e656dbb BN |
503 | void |
504 | xfs_sb_to_disk( | |
19ebedcf DC |
505 | struct xfs_dsb *to, |
506 | struct xfs_sb *from) | |
5e656dbb | 507 | { |
19ebedcf | 508 | xfs_sb_quota_to_disk(to, from); |
5e656dbb | 509 | |
19ebedcf DC |
510 | to->sb_magicnum = cpu_to_be32(from->sb_magicnum); |
511 | to->sb_blocksize = cpu_to_be32(from->sb_blocksize); | |
512 | to->sb_dblocks = cpu_to_be64(from->sb_dblocks); | |
513 | to->sb_rblocks = cpu_to_be64(from->sb_rblocks); | |
514 | to->sb_rextents = cpu_to_be64(from->sb_rextents); | |
515 | memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid)); | |
516 | to->sb_logstart = cpu_to_be64(from->sb_logstart); | |
517 | to->sb_rootino = cpu_to_be64(from->sb_rootino); | |
518 | to->sb_rbmino = cpu_to_be64(from->sb_rbmino); | |
519 | to->sb_rsumino = cpu_to_be64(from->sb_rsumino); | |
520 | to->sb_rextsize = cpu_to_be32(from->sb_rextsize); | |
521 | to->sb_agblocks = cpu_to_be32(from->sb_agblocks); | |
522 | to->sb_agcount = cpu_to_be32(from->sb_agcount); | |
523 | to->sb_rbmblocks = cpu_to_be32(from->sb_rbmblocks); | |
524 | to->sb_logblocks = cpu_to_be32(from->sb_logblocks); | |
525 | to->sb_versionnum = cpu_to_be16(from->sb_versionnum); | |
526 | to->sb_sectsize = cpu_to_be16(from->sb_sectsize); | |
527 | to->sb_inodesize = cpu_to_be16(from->sb_inodesize); | |
528 | to->sb_inopblock = cpu_to_be16(from->sb_inopblock); | |
529 | memcpy(&to->sb_fname, &from->sb_fname, sizeof(to->sb_fname)); | |
530 | to->sb_blocklog = from->sb_blocklog; | |
531 | to->sb_sectlog = from->sb_sectlog; | |
532 | to->sb_inodelog = from->sb_inodelog; | |
533 | to->sb_inopblog = from->sb_inopblog; | |
534 | to->sb_agblklog = from->sb_agblklog; | |
535 | to->sb_rextslog = from->sb_rextslog; | |
536 | to->sb_inprogress = from->sb_inprogress; | |
537 | to->sb_imax_pct = from->sb_imax_pct; | |
538 | to->sb_icount = cpu_to_be64(from->sb_icount); | |
539 | to->sb_ifree = cpu_to_be64(from->sb_ifree); | |
540 | to->sb_fdblocks = cpu_to_be64(from->sb_fdblocks); | |
541 | to->sb_frextents = cpu_to_be64(from->sb_frextents); | |
542 | ||
543 | to->sb_flags = from->sb_flags; | |
544 | to->sb_shared_vn = from->sb_shared_vn; | |
545 | to->sb_inoalignmt = cpu_to_be32(from->sb_inoalignmt); | |
546 | to->sb_unit = cpu_to_be32(from->sb_unit); | |
547 | to->sb_width = cpu_to_be32(from->sb_width); | |
548 | to->sb_dirblklog = from->sb_dirblklog; | |
549 | to->sb_logsectlog = from->sb_logsectlog; | |
550 | to->sb_logsectsize = cpu_to_be16(from->sb_logsectsize); | |
551 | to->sb_logsunit = cpu_to_be32(from->sb_logsunit); | |
5e656dbb | 552 | |
19ebedcf DC |
553 | /* |
554 | * We need to ensure that bad_features2 always matches features2. | |
555 | * Hence we enforce that here rather than having to remember to do it | |
556 | * everywhere else that updates features2. | |
557 | */ | |
558 | from->sb_bad_features2 = from->sb_features2; | |
559 | to->sb_features2 = cpu_to_be32(from->sb_features2); | |
560 | to->sb_bad_features2 = cpu_to_be32(from->sb_bad_features2); | |
561 | ||
562 | if (xfs_sb_version_hascrc(from)) { | |
563 | to->sb_features_compat = cpu_to_be32(from->sb_features_compat); | |
564 | to->sb_features_ro_compat = | |
565 | cpu_to_be32(from->sb_features_ro_compat); | |
566 | to->sb_features_incompat = | |
567 | cpu_to_be32(from->sb_features_incompat); | |
568 | to->sb_features_log_incompat = | |
569 | cpu_to_be32(from->sb_features_log_incompat); | |
6bd8b7e1 | 570 | to->sb_spino_align = cpu_to_be32(from->sb_spino_align); |
19ebedcf | 571 | to->sb_lsn = cpu_to_be64(from->sb_lsn); |
9c4e12fb ES |
572 | if (xfs_sb_version_hasmetauuid(from)) |
573 | uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid); | |
5e656dbb BN |
574 | } |
575 | } | |
576 | ||
5565d79a | 577 | static int |
a2ceac1f | 578 | xfs_sb_verify( |
f7b80291 | 579 | struct xfs_buf *bp, |
5629f836 | 580 | bool check_version) |
a2ceac1f DC |
581 | { |
582 | struct xfs_mount *mp = bp->b_target->bt_mount; | |
583 | struct xfs_sb sb; | |
a2ceac1f | 584 | |
5a35bf2c DC |
585 | /* |
586 | * Use call variant which doesn't convert quota flags from disk | |
587 | * format, because xfs_mount_validate_sb checks the on-disk flags. | |
588 | */ | |
589 | __xfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp), false); | |
a2ceac1f DC |
590 | |
591 | /* | |
592 | * Only check the in progress field for the primary superblock as | |
593 | * mkfs.xfs doesn't clear it from secondary superblocks. | |
594 | */ | |
85428dd2 DC |
595 | return xfs_mount_validate_sb(mp, &sb, |
596 | bp->b_maps[0].bm_bn == XFS_SB_DADDR, | |
5629f836 | 597 | check_version); |
a2ceac1f DC |
598 | } |
599 | ||
5565d79a DC |
600 | /* |
601 | * If the superblock has the CRC feature bit set or the CRC field is non-null, | |
602 | * check that the CRC is valid. We check the CRC field is non-null because a | |
603 | * single bit error could clear the feature bit and unused parts of the | |
604 | * superblock are supposed to be zero. Hence a non-null crc field indicates that | |
605 | * we've potentially lost a feature bit and we should check it anyway. | |
46ea3a62 DC |
606 | * |
607 | * However, past bugs (i.e. in growfs) left non-zeroed regions beyond the | |
608 | * last field in V4 secondary superblocks. So for secondary superblocks, | |
609 | * we are more forgiving, and ignore CRC failures if the primary doesn't | |
610 | * indicate that the fs version is V5. | |
5565d79a | 611 | */ |
a2ceac1f DC |
612 | static void |
613 | xfs_sb_read_verify( | |
614 | struct xfs_buf *bp) | |
615 | { | |
5565d79a DC |
616 | struct xfs_mount *mp = bp->b_target->bt_mount; |
617 | struct xfs_dsb *dsb = XFS_BUF_TO_SBP(bp); | |
618 | int error; | |
619 | ||
620 | /* | |
621 | * open code the version check to avoid needing to convert the entire | |
622 | * superblock from disk order just to check the version number | |
623 | */ | |
624 | if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC) && | |
625 | (((be16_to_cpu(dsb->sb_versionnum) & XFS_SB_VERSION_NUMBITS) == | |
626 | XFS_SB_VERSION_5) || | |
627 | dsb->sb_crc != 0)) { | |
628 | ||
d21ca64d | 629 | if (!xfs_buf_verify_cksum(bp, XFS_SB_CRC_OFF)) { |
46ea3a62 | 630 | /* Only fail bad secondaries on a known V5 filesystem */ |
f3cddd91 | 631 | if (bp->b_bn == XFS_SB_DADDR || |
46ea3a62 | 632 | xfs_sb_version_hascrc(&mp->m_sb)) { |
12b53197 | 633 | error = -EFSBADCRC; |
46ea3a62 DC |
634 | goto out_error; |
635 | } | |
5565d79a DC |
636 | } |
637 | } | |
f7b80291 | 638 | error = xfs_sb_verify(bp, true); |
5565d79a DC |
639 | |
640 | out_error: | |
7e6c95f1 | 641 | if (error == -EFSCORRUPTED || error == -EFSBADCRC) |
1e697959 | 642 | xfs_verifier_error(bp, error, __this_address); |
7e6c95f1 | 643 | else if (error) |
5565d79a | 644 | xfs_buf_ioerror(bp, error); |
a2ceac1f DC |
645 | } |
646 | ||
647 | /* | |
648 | * We may be probed for a filesystem match, so we may not want to emit | |
649 | * messages when the superblock buffer is not actually an XFS superblock. | |
4896e6c8 | 650 | * If we find an XFS superblock, then run a normal, noisy mount because we are |
a2ceac1f DC |
651 | * really going to mount it and want to know about errors. |
652 | */ | |
653 | static void | |
654 | xfs_sb_quiet_read_verify( | |
655 | struct xfs_buf *bp) | |
656 | { | |
5565d79a | 657 | struct xfs_dsb *dsb = XFS_BUF_TO_SBP(bp); |
a2ceac1f | 658 | |
5565d79a | 659 | if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC)) { |
a2ceac1f DC |
660 | /* XFS filesystem, verify noisily! */ |
661 | xfs_sb_read_verify(bp); | |
662 | return; | |
663 | } | |
664 | /* quietly fail */ | |
12b53197 | 665 | xfs_buf_ioerror(bp, -EWRONGFS); |
a2ceac1f DC |
666 | } |
667 | ||
668 | static void | |
669 | xfs_sb_write_verify( | |
5565d79a | 670 | struct xfs_buf *bp) |
a2ceac1f | 671 | { |
5565d79a | 672 | struct xfs_mount *mp = bp->b_target->bt_mount; |
37d086ca | 673 | struct xfs_buf_log_item *bip = bp->b_log_item; |
5565d79a DC |
674 | int error; |
675 | ||
f7b80291 | 676 | error = xfs_sb_verify(bp, false); |
5565d79a | 677 | if (error) { |
1e697959 | 678 | xfs_verifier_error(bp, error, __this_address); |
5565d79a DC |
679 | return; |
680 | } | |
681 | ||
682 | if (!xfs_sb_version_hascrc(&mp->m_sb)) | |
683 | return; | |
684 | ||
685 | if (bip) | |
686 | XFS_BUF_TO_SBP(bp)->sb_lsn = cpu_to_be64(bip->bli_item.li_lsn); | |
687 | ||
43b5aeed | 688 | xfs_buf_update_cksum(bp, XFS_SB_CRC_OFF); |
a2ceac1f DC |
689 | } |
690 | ||
691 | const struct xfs_buf_ops xfs_sb_buf_ops = { | |
a3fac935 | 692 | .name = "xfs_sb", |
a2ceac1f DC |
693 | .verify_read = xfs_sb_read_verify, |
694 | .verify_write = xfs_sb_write_verify, | |
695 | }; | |
696 | ||
4896e6c8 | 697 | const struct xfs_buf_ops xfs_sb_quiet_buf_ops = { |
a3fac935 | 698 | .name = "xfs_sb_quiet", |
a2ceac1f DC |
699 | .verify_read = xfs_sb_quiet_read_verify, |
700 | .verify_write = xfs_sb_write_verify, | |
701 | }; | |
702 | ||
5e656dbb BN |
703 | /* |
704 | * xfs_mount_common | |
705 | * | |
706 | * Mount initialization code establishing various mount | |
707 | * fields from the superblock associated with the given | |
708 | * mount structure | |
5e656dbb BN |
709 | */ |
710 | void | |
4896e6c8 DC |
711 | xfs_sb_mount_common( |
712 | struct xfs_mount *mp, | |
713 | struct xfs_sb *sbp) | |
5e656dbb | 714 | { |
5e656dbb BN |
715 | mp->m_agfrotor = mp->m_agirotor = 0; |
716 | spin_lock_init(&mp->m_agirotor_lock); | |
717 | mp->m_maxagi = mp->m_sb.sb_agcount; | |
718 | mp->m_blkbit_log = sbp->sb_blocklog + XFS_NBBYLOG; | |
719 | mp->m_blkbb_log = sbp->sb_blocklog - BBSHIFT; | |
720 | mp->m_sectbb_log = sbp->sb_sectlog - BBSHIFT; | |
721 | mp->m_agno_log = xfs_highbit32(sbp->sb_agcount - 1) + 1; | |
722 | mp->m_agino_log = sbp->sb_inopblog + sbp->sb_agblklog; | |
5e656dbb BN |
723 | mp->m_blockmask = sbp->sb_blocksize - 1; |
724 | mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG; | |
725 | mp->m_blockwmask = mp->m_blockwsize - 1; | |
5e656dbb | 726 | |
b3563c19 BN |
727 | mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1); |
728 | mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0); | |
729 | mp->m_alloc_mnr[0] = mp->m_alloc_mxr[0] / 2; | |
730 | mp->m_alloc_mnr[1] = mp->m_alloc_mxr[1] / 2; | |
731 | ||
732 | mp->m_inobt_mxr[0] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, 1); | |
733 | mp->m_inobt_mxr[1] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, 0); | |
734 | mp->m_inobt_mnr[0] = mp->m_inobt_mxr[0] / 2; | |
735 | mp->m_inobt_mnr[1] = mp->m_inobt_mxr[1] / 2; | |
736 | ||
737 | mp->m_bmap_dmxr[0] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 1); | |
738 | mp->m_bmap_dmxr[1] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 0); | |
739 | mp->m_bmap_dmnr[0] = mp->m_bmap_dmxr[0] / 2; | |
740 | mp->m_bmap_dmnr[1] = mp->m_bmap_dmxr[1] / 2; | |
5e656dbb | 741 | |
b3a96b46 DW |
742 | mp->m_rmap_mxr[0] = xfs_rmapbt_maxrecs(mp, sbp->sb_blocksize, 1); |
743 | mp->m_rmap_mxr[1] = xfs_rmapbt_maxrecs(mp, sbp->sb_blocksize, 0); | |
744 | mp->m_rmap_mnr[0] = mp->m_rmap_mxr[0] / 2; | |
745 | mp->m_rmap_mnr[1] = mp->m_rmap_mxr[1] / 2; | |
746 | ||
d8079fe0 DW |
747 | mp->m_refc_mxr[0] = xfs_refcountbt_maxrecs(mp, sbp->sb_blocksize, |
748 | true); | |
749 | mp->m_refc_mxr[1] = xfs_refcountbt_maxrecs(mp, sbp->sb_blocksize, | |
750 | false); | |
751 | mp->m_refc_mnr[0] = mp->m_refc_mxr[0] / 2; | |
752 | mp->m_refc_mnr[1] = mp->m_refc_mxr[1] / 2; | |
753 | ||
5e656dbb | 754 | mp->m_bsize = XFS_FSB_TO_BB(mp, 1); |
4a492e72 | 755 | mp->m_ialloc_inos = (int)MAX((uint16_t)XFS_INODES_PER_CHUNK, |
5e656dbb BN |
756 | sbp->sb_inopblock); |
757 | mp->m_ialloc_blks = mp->m_ialloc_inos >> sbp->sb_inopblog; | |
62dc6cdb BF |
758 | |
759 | if (sbp->sb_spino_align) | |
760 | mp->m_ialloc_min_blks = sbp->sb_spino_align; | |
761 | else | |
762 | mp->m_ialloc_min_blks = mp->m_ialloc_blks; | |
b8a8d6e5 DW |
763 | mp->m_alloc_set_aside = xfs_alloc_set_aside(mp); |
764 | mp->m_ag_max_usable = xfs_alloc_ag_max_usable(mp); | |
5e656dbb BN |
765 | } |
766 | ||
cdded3d8 DC |
767 | /* |
768 | * xfs_initialize_perag_data | |
769 | * | |
770 | * Read in each per-ag structure so we can count up the number of | |
771 | * allocated inodes, free inodes and used filesystem blocks as this | |
772 | * information is no longer persistent in the superblock. Once we have | |
773 | * this information, write it into the in-core superblock structure. | |
774 | */ | |
5e656dbb | 775 | int |
4896e6c8 DC |
776 | xfs_initialize_perag_data( |
777 | struct xfs_mount *mp, | |
778 | xfs_agnumber_t agcount) | |
cdded3d8 DC |
779 | { |
780 | xfs_agnumber_t index; | |
781 | xfs_perag_t *pag; | |
782 | xfs_sb_t *sbp = &mp->m_sb; | |
5e656dbb BN |
783 | uint64_t ifree = 0; |
784 | uint64_t ialloc = 0; | |
785 | uint64_t bfree = 0; | |
786 | uint64_t bfreelst = 0; | |
787 | uint64_t btree = 0; | |
cdded3d8 | 788 | int error; |
cdded3d8 DC |
789 | |
790 | for (index = 0; index < agcount; index++) { | |
791 | /* | |
792 | * read the agf, then the agi. This gets us | |
56b2de80 | 793 | * all the information we need and populates the |
cdded3d8 DC |
794 | * per-ag structures for us. |
795 | */ | |
796 | error = xfs_alloc_pagf_init(mp, NULL, index, 0); | |
797 | if (error) | |
798 | return error; | |
799 | ||
800 | error = xfs_ialloc_pagi_init(mp, NULL, index); | |
801 | if (error) | |
802 | return error; | |
56b2de80 | 803 | pag = xfs_perag_get(mp, index); |
cdded3d8 DC |
804 | ifree += pag->pagi_freecount; |
805 | ialloc += pag->pagi_count; | |
806 | bfree += pag->pagf_freeblks; | |
807 | bfreelst += pag->pagf_flcount; | |
808 | btree += pag->pagf_btreeblks; | |
56b2de80 | 809 | xfs_perag_put(pag); |
cdded3d8 | 810 | } |
19ebedcf DC |
811 | |
812 | /* Overwrite incore superblock counters with just-read data */ | |
5e656dbb | 813 | spin_lock(&mp->m_sb_lock); |
cdded3d8 DC |
814 | sbp->sb_ifree = ifree; |
815 | sbp->sb_icount = ialloc; | |
816 | sbp->sb_fdblocks = bfree + bfreelst + btree; | |
5e656dbb BN |
817 | spin_unlock(&mp->m_sb_lock); |
818 | ||
19ebedcf | 819 | xfs_reinit_percpu_counters(mp); |
5e656dbb | 820 | |
cdded3d8 DC |
821 | return 0; |
822 | } | |
5e656dbb BN |
823 | |
824 | /* | |
19ebedcf DC |
825 | * xfs_log_sb() can be used to copy arbitrary changes to the in-core superblock |
826 | * into the superblock buffer to be logged. It does not provide the higher | |
827 | * level of locking that is needed to protect the in-core superblock from | |
828 | * concurrent access. | |
5e656dbb BN |
829 | */ |
830 | void | |
19ebedcf DC |
831 | xfs_log_sb( |
832 | struct xfs_trans *tp) | |
5e656dbb | 833 | { |
19ebedcf DC |
834 | struct xfs_mount *mp = tp->t_mountp; |
835 | struct xfs_buf *bp = xfs_trans_getsb(tp, mp, 0); | |
5e656dbb | 836 | |
19ebedcf DC |
837 | mp->m_sb.sb_icount = percpu_counter_sum(&mp->m_icount); |
838 | mp->m_sb.sb_ifree = percpu_counter_sum(&mp->m_ifree); | |
839 | mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks); | |
4896e6c8 | 840 | |
19ebedcf DC |
841 | xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb); |
842 | xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF); | |
843 | xfs_trans_log_buf(tp, bp, 0, sizeof(struct xfs_dsb)); | |
844 | } | |
5e656dbb | 845 | |
19ebedcf DC |
846 | /* |
847 | * xfs_sync_sb | |
848 | * | |
849 | * Sync the superblock to disk. | |
850 | * | |
851 | * Note that the caller is responsible for checking the frozen state of the | |
852 | * filesystem. This procedure uses the non-blocking transaction allocator and | |
853 | * thus will allow modifications to a frozen fs. This is required because this | |
854 | * code can be called during the process of freezing where use of the high-level | |
855 | * allocator would deadlock. | |
856 | */ | |
857 | int | |
858 | xfs_sync_sb( | |
859 | struct xfs_mount *mp, | |
860 | bool wait) | |
861 | { | |
862 | struct xfs_trans *tp; | |
863 | int error; | |
5e656dbb | 864 | |
9074815c CH |
865 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, |
866 | XFS_TRANS_NO_WRITECOUNT, &tp); | |
867 | if (error) | |
19ebedcf | 868 | return error; |
5e656dbb | 869 | |
19ebedcf DC |
870 | xfs_log_sb(tp); |
871 | if (wait) | |
872 | xfs_trans_set_sync(tp); | |
de5a3f46 | 873 | return xfs_trans_commit(tp); |
5e656dbb | 874 | } |
a2a52384 DW |
875 | |
876 | int | |
877 | xfs_fs_geometry( | |
fdef0e8b DW |
878 | struct xfs_sb *sbp, |
879 | struct xfs_fsop_geom *geo, | |
880 | int struct_version) | |
a2a52384 | 881 | { |
fdef0e8b DW |
882 | memset(geo, 0, sizeof(struct xfs_fsop_geom)); |
883 | ||
884 | geo->blocksize = sbp->sb_blocksize; | |
885 | geo->rtextsize = sbp->sb_rextsize; | |
886 | geo->agblocks = sbp->sb_agblocks; | |
887 | geo->agcount = sbp->sb_agcount; | |
888 | geo->logblocks = sbp->sb_logblocks; | |
889 | geo->sectsize = sbp->sb_sectsize; | |
890 | geo->inodesize = sbp->sb_inodesize; | |
891 | geo->imaxpct = sbp->sb_imax_pct; | |
892 | geo->datablocks = sbp->sb_dblocks; | |
893 | geo->rtblocks = sbp->sb_rblocks; | |
894 | geo->rtextents = sbp->sb_rextents; | |
895 | geo->logstart = sbp->sb_logstart; | |
896 | BUILD_BUG_ON(sizeof(geo->uuid) != sizeof(sbp->sb_uuid)); | |
897 | memcpy(geo->uuid, &sbp->sb_uuid, sizeof(sbp->sb_uuid)); | |
898 | ||
899 | if (struct_version < 2) | |
900 | return 0; | |
901 | ||
902 | geo->sunit = sbp->sb_unit; | |
903 | geo->swidth = sbp->sb_width; | |
904 | ||
905 | if (struct_version < 3) | |
906 | return 0; | |
907 | ||
908 | geo->version = XFS_FSOP_GEOM_VERSION; | |
909 | geo->flags = XFS_FSOP_GEOM_FLAGS_NLINK | | |
910 | XFS_FSOP_GEOM_FLAGS_DIRV2; | |
911 | if (xfs_sb_version_hasattr(sbp)) | |
912 | geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR; | |
913 | if (xfs_sb_version_hasquota(sbp)) | |
914 | geo->flags |= XFS_FSOP_GEOM_FLAGS_QUOTA; | |
915 | if (xfs_sb_version_hasalign(sbp)) | |
916 | geo->flags |= XFS_FSOP_GEOM_FLAGS_IALIGN; | |
917 | if (xfs_sb_version_hasdalign(sbp)) | |
918 | geo->flags |= XFS_FSOP_GEOM_FLAGS_DALIGN; | |
919 | if (xfs_sb_version_hasextflgbit(sbp)) | |
920 | geo->flags |= XFS_FSOP_GEOM_FLAGS_EXTFLG; | |
921 | if (xfs_sb_version_hassector(sbp)) | |
922 | geo->flags |= XFS_FSOP_GEOM_FLAGS_SECTOR; | |
923 | if (xfs_sb_version_hasasciici(sbp)) | |
924 | geo->flags |= XFS_FSOP_GEOM_FLAGS_DIRV2CI; | |
925 | if (xfs_sb_version_haslazysbcount(sbp)) | |
926 | geo->flags |= XFS_FSOP_GEOM_FLAGS_LAZYSB; | |
927 | if (xfs_sb_version_hasattr2(sbp)) | |
928 | geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR2; | |
929 | if (xfs_sb_version_hasprojid32bit(sbp)) | |
930 | geo->flags |= XFS_FSOP_GEOM_FLAGS_PROJID32; | |
931 | if (xfs_sb_version_hascrc(sbp)) | |
932 | geo->flags |= XFS_FSOP_GEOM_FLAGS_V5SB; | |
933 | if (xfs_sb_version_hasftype(sbp)) | |
934 | geo->flags |= XFS_FSOP_GEOM_FLAGS_FTYPE; | |
935 | if (xfs_sb_version_hasfinobt(sbp)) | |
936 | geo->flags |= XFS_FSOP_GEOM_FLAGS_FINOBT; | |
937 | if (xfs_sb_version_hassparseinodes(sbp)) | |
938 | geo->flags |= XFS_FSOP_GEOM_FLAGS_SPINODES; | |
939 | if (xfs_sb_version_hasrmapbt(sbp)) | |
940 | geo->flags |= XFS_FSOP_GEOM_FLAGS_RMAPBT; | |
941 | if (xfs_sb_version_hasreflink(sbp)) | |
942 | geo->flags |= XFS_FSOP_GEOM_FLAGS_REFLINK; | |
943 | if (xfs_sb_version_hassector(sbp)) | |
944 | geo->logsectsize = sbp->sb_logsectsize; | |
945 | else | |
946 | geo->logsectsize = BBSIZE; | |
947 | geo->rtsectsize = sbp->sb_blocksize; | |
948 | geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp); | |
949 | ||
dfcfc5f1 | 950 | if (struct_version < 4) |
fdef0e8b DW |
951 | return 0; |
952 | ||
953 | if (xfs_sb_version_haslogv2(sbp)) | |
954 | geo->flags |= XFS_FSOP_GEOM_FLAGS_LOGV2; | |
955 | ||
956 | geo->logsunit = sbp->sb_logsunit; | |
a2a52384 | 957 | |
a2a52384 DW |
958 | return 0; |
959 | } |