]>
Commit | Line | Data |
---|---|---|
0b61f8a4 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 | 2 | /* |
a805bad5 | 3 | * Copyright (c) 2000-2006 Silicon Graphics, Inc. |
7b718769 | 4 | * All Rights Reserved. |
1da177e4 | 5 | */ |
0b1b213f | 6 | |
1da177e4 | 7 | #include "xfs.h" |
70a9883c | 8 | #include "xfs_shared.h" |
6ca1c906 | 9 | #include "xfs_format.h" |
239880ef DC |
10 | #include "xfs_log_format.h" |
11 | #include "xfs_trans_resv.h" | |
1da177e4 | 12 | #include "xfs_sb.h" |
1da177e4 | 13 | #include "xfs_mount.h" |
1da177e4 | 14 | #include "xfs_inode.h" |
a844f451 | 15 | #include "xfs_btree.h" |
1da177e4 | 16 | #include "xfs_bmap.h" |
a4fbe6ab | 17 | #include "xfs_alloc.h" |
9909c4aa | 18 | #include "xfs_fsops.h" |
239880ef | 19 | #include "xfs_trans.h" |
1da177e4 | 20 | #include "xfs_buf_item.h" |
239880ef | 21 | #include "xfs_log.h" |
a67d7c5f | 22 | #include "xfs_log_priv.h" |
2b9ab5ab | 23 | #include "xfs_dir2.h" |
9f8868ff CH |
24 | #include "xfs_extfree_item.h" |
25 | #include "xfs_mru_cache.h" | |
26 | #include "xfs_inode_item.h" | |
6d8b79cf | 27 | #include "xfs_icache.h" |
0b1b213f | 28 | #include "xfs_trace.h" |
3ebe7d2d | 29 | #include "xfs_icreate_item.h" |
a4fbe6ab DC |
30 | #include "xfs_filestream.h" |
31 | #include "xfs_quota.h" | |
65b65735 | 32 | #include "xfs_sysfs.h" |
30cbc591 | 33 | #include "xfs_ondisk.h" |
5880f2d7 | 34 | #include "xfs_rmap_item.h" |
baf4bcac | 35 | #include "xfs_refcount_item.h" |
6413a014 | 36 | #include "xfs_bmap_item.h" |
5e7e605c | 37 | #include "xfs_reflink.h" |
894ecacf | 38 | #include "xfs_pwork.h" |
9bbafc71 | 39 | #include "xfs_ag.h" |
1da177e4 | 40 | |
dddde68b | 41 | #include <linux/magic.h> |
73e5fff9 IK |
42 | #include <linux/fs_context.h> |
43 | #include <linux/fs_parser.h> | |
1da177e4 | 44 | |
b87221de | 45 | static const struct super_operations xfs_super_operations; |
65b65735 | 46 | |
e3aed1a0 | 47 | static struct kset *xfs_kset; /* top-level xfs sysfs dir */ |
65b65735 BF |
48 | #ifdef DEBUG |
49 | static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */ | |
50 | #endif | |
1da177e4 | 51 | |
8d6c3446 IW |
52 | enum xfs_dax_mode { |
53 | XFS_DAX_INODE = 0, | |
54 | XFS_DAX_ALWAYS = 1, | |
55 | XFS_DAX_NEVER = 2, | |
56 | }; | |
57 | ||
58 | static void | |
59 | xfs_mount_set_dax_mode( | |
60 | struct xfs_mount *mp, | |
61 | enum xfs_dax_mode mode) | |
62 | { | |
63 | switch (mode) { | |
64 | case XFS_DAX_INODE: | |
65 | mp->m_flags &= ~(XFS_MOUNT_DAX_ALWAYS | XFS_MOUNT_DAX_NEVER); | |
66 | break; | |
67 | case XFS_DAX_ALWAYS: | |
68 | mp->m_flags |= XFS_MOUNT_DAX_ALWAYS; | |
69 | mp->m_flags &= ~XFS_MOUNT_DAX_NEVER; | |
70 | break; | |
71 | case XFS_DAX_NEVER: | |
72 | mp->m_flags |= XFS_MOUNT_DAX_NEVER; | |
73 | mp->m_flags &= ~XFS_MOUNT_DAX_ALWAYS; | |
74 | break; | |
75 | } | |
76 | } | |
77 | ||
78 | static const struct constant_table dax_param_enums[] = { | |
79 | {"inode", XFS_DAX_INODE }, | |
80 | {"always", XFS_DAX_ALWAYS }, | |
81 | {"never", XFS_DAX_NEVER }, | |
82 | {} | |
83 | }; | |
84 | ||
62a877e3 CH |
85 | /* |
86 | * Table driven mount option parser. | |
62a877e3 CH |
87 | */ |
88 | enum { | |
8da57c5c | 89 | Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev, |
2e74af0e | 90 | Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid, |
94079285 | 91 | Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups, |
1c02d502 ES |
92 | Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep, |
93 | Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2, | |
94 | Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota, | |
95 | Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota, | |
2e74af0e | 96 | Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce, |
8d6c3446 | 97 | Opt_discard, Opt_nodiscard, Opt_dax, Opt_dax_enum, |
62a877e3 CH |
98 | }; |
99 | ||
d7167b14 | 100 | static const struct fs_parameter_spec xfs_fs_parameters[] = { |
73e5fff9 IK |
101 | fsparam_u32("logbufs", Opt_logbufs), |
102 | fsparam_string("logbsize", Opt_logbsize), | |
103 | fsparam_string("logdev", Opt_logdev), | |
104 | fsparam_string("rtdev", Opt_rtdev), | |
105 | fsparam_flag("wsync", Opt_wsync), | |
106 | fsparam_flag("noalign", Opt_noalign), | |
107 | fsparam_flag("swalloc", Opt_swalloc), | |
108 | fsparam_u32("sunit", Opt_sunit), | |
109 | fsparam_u32("swidth", Opt_swidth), | |
110 | fsparam_flag("nouuid", Opt_nouuid), | |
111 | fsparam_flag("grpid", Opt_grpid), | |
112 | fsparam_flag("nogrpid", Opt_nogrpid), | |
113 | fsparam_flag("bsdgroups", Opt_bsdgroups), | |
114 | fsparam_flag("sysvgroups", Opt_sysvgroups), | |
115 | fsparam_string("allocsize", Opt_allocsize), | |
116 | fsparam_flag("norecovery", Opt_norecovery), | |
117 | fsparam_flag("inode64", Opt_inode64), | |
118 | fsparam_flag("inode32", Opt_inode32), | |
119 | fsparam_flag("ikeep", Opt_ikeep), | |
120 | fsparam_flag("noikeep", Opt_noikeep), | |
121 | fsparam_flag("largeio", Opt_largeio), | |
122 | fsparam_flag("nolargeio", Opt_nolargeio), | |
123 | fsparam_flag("attr2", Opt_attr2), | |
124 | fsparam_flag("noattr2", Opt_noattr2), | |
125 | fsparam_flag("filestreams", Opt_filestreams), | |
126 | fsparam_flag("quota", Opt_quota), | |
127 | fsparam_flag("noquota", Opt_noquota), | |
128 | fsparam_flag("usrquota", Opt_usrquota), | |
129 | fsparam_flag("grpquota", Opt_grpquota), | |
130 | fsparam_flag("prjquota", Opt_prjquota), | |
131 | fsparam_flag("uquota", Opt_uquota), | |
132 | fsparam_flag("gquota", Opt_gquota), | |
133 | fsparam_flag("pquota", Opt_pquota), | |
134 | fsparam_flag("uqnoenforce", Opt_uqnoenforce), | |
135 | fsparam_flag("gqnoenforce", Opt_gqnoenforce), | |
136 | fsparam_flag("pqnoenforce", Opt_pqnoenforce), | |
137 | fsparam_flag("qnoenforce", Opt_qnoenforce), | |
138 | fsparam_flag("discard", Opt_discard), | |
139 | fsparam_flag("nodiscard", Opt_nodiscard), | |
140 | fsparam_flag("dax", Opt_dax), | |
8d6c3446 | 141 | fsparam_enum("dax", Opt_dax_enum, dax_param_enums), |
73e5fff9 | 142 | {} |
62a877e3 CH |
143 | }; |
144 | ||
a67d7c5f | 145 | struct proc_xfs_info { |
cbe4dab1 DC |
146 | uint64_t flag; |
147 | char *str; | |
a67d7c5f DC |
148 | }; |
149 | ||
21f55993 CH |
150 | static int |
151 | xfs_fs_show_options( | |
152 | struct seq_file *m, | |
153 | struct dentry *root) | |
a67d7c5f DC |
154 | { |
155 | static struct proc_xfs_info xfs_info_set[] = { | |
156 | /* the few simple ones we can get from the mount struct */ | |
2e74af0e ES |
157 | { XFS_MOUNT_IKEEP, ",ikeep" }, |
158 | { XFS_MOUNT_WSYNC, ",wsync" }, | |
159 | { XFS_MOUNT_NOALIGN, ",noalign" }, | |
160 | { XFS_MOUNT_SWALLOC, ",swalloc" }, | |
161 | { XFS_MOUNT_NOUUID, ",nouuid" }, | |
162 | { XFS_MOUNT_NORECOVERY, ",norecovery" }, | |
163 | { XFS_MOUNT_ATTR2, ",attr2" }, | |
164 | { XFS_MOUNT_FILESTREAMS, ",filestreams" }, | |
165 | { XFS_MOUNT_GRPID, ",grpid" }, | |
166 | { XFS_MOUNT_DISCARD, ",discard" }, | |
7c6b94b1 | 167 | { XFS_MOUNT_LARGEIO, ",largeio" }, |
8d6c3446 IW |
168 | { XFS_MOUNT_DAX_ALWAYS, ",dax=always" }, |
169 | { XFS_MOUNT_DAX_NEVER, ",dax=never" }, | |
a67d7c5f DC |
170 | { 0, NULL } |
171 | }; | |
21f55993 | 172 | struct xfs_mount *mp = XFS_M(root->d_sb); |
a67d7c5f DC |
173 | struct proc_xfs_info *xfs_infop; |
174 | ||
175 | for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) { | |
176 | if (mp->m_flags & xfs_infop->flag) | |
177 | seq_puts(m, xfs_infop->str); | |
178 | } | |
1775c506 CH |
179 | |
180 | seq_printf(m, ",inode%d", | |
181 | (mp->m_flags & XFS_MOUNT_SMALL_INUMS) ? 32 : 64); | |
a67d7c5f | 182 | |
3274d008 | 183 | if (mp->m_flags & XFS_MOUNT_ALLOCSIZE) |
2e74af0e | 184 | seq_printf(m, ",allocsize=%dk", |
aa58d445 | 185 | (1 << mp->m_allocsize_log) >> 10); |
a67d7c5f DC |
186 | |
187 | if (mp->m_logbufs > 0) | |
2e74af0e | 188 | seq_printf(m, ",logbufs=%d", mp->m_logbufs); |
a67d7c5f | 189 | if (mp->m_logbsize > 0) |
2e74af0e | 190 | seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10); |
a67d7c5f DC |
191 | |
192 | if (mp->m_logname) | |
2e74af0e | 193 | seq_show_option(m, "logdev", mp->m_logname); |
a67d7c5f | 194 | if (mp->m_rtname) |
2e74af0e | 195 | seq_show_option(m, "rtdev", mp->m_rtname); |
a67d7c5f DC |
196 | |
197 | if (mp->m_dalign > 0) | |
2e74af0e | 198 | seq_printf(m, ",sunit=%d", |
a67d7c5f DC |
199 | (int)XFS_FSB_TO_BB(mp, mp->m_dalign)); |
200 | if (mp->m_swidth > 0) | |
2e74af0e | 201 | seq_printf(m, ",swidth=%d", |
a67d7c5f DC |
202 | (int)XFS_FSB_TO_BB(mp, mp->m_swidth)); |
203 | ||
237d7887 KX |
204 | if (mp->m_qflags & XFS_UQUOTA_ACCT) { |
205 | if (mp->m_qflags & XFS_UQUOTA_ENFD) | |
206 | seq_puts(m, ",usrquota"); | |
207 | else | |
208 | seq_puts(m, ",uqnoenforce"); | |
209 | } | |
a67d7c5f | 210 | |
988abe40 | 211 | if (mp->m_qflags & XFS_PQUOTA_ACCT) { |
83e782e1 | 212 | if (mp->m_qflags & XFS_PQUOTA_ENFD) |
2e74af0e | 213 | seq_puts(m, ",prjquota"); |
988abe40 | 214 | else |
2e74af0e | 215 | seq_puts(m, ",pqnoenforce"); |
d892d586 CS |
216 | } |
217 | if (mp->m_qflags & XFS_GQUOTA_ACCT) { | |
83e782e1 | 218 | if (mp->m_qflags & XFS_GQUOTA_ENFD) |
2e74af0e | 219 | seq_puts(m, ",grpquota"); |
988abe40 | 220 | else |
2e74af0e | 221 | seq_puts(m, ",gqnoenforce"); |
988abe40 | 222 | } |
a67d7c5f DC |
223 | |
224 | if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT)) | |
2e74af0e | 225 | seq_puts(m, ",noquota"); |
21f55993 CH |
226 | |
227 | return 0; | |
a67d7c5f | 228 | } |
91083269 | 229 | |
9de67c3b | 230 | /* |
12c3f05c ES |
231 | * Set parameters for inode allocation heuristics, taking into account |
232 | * filesystem size and inode32/inode64 mount options; i.e. specifically | |
233 | * whether or not XFS_MOUNT_SMALL_INUMS is set. | |
234 | * | |
235 | * Inode allocation patterns are altered only if inode32 is requested | |
236 | * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large. | |
237 | * If altered, XFS_MOUNT_32BITINODES is set as well. | |
238 | * | |
239 | * An agcount independent of that in the mount structure is provided | |
240 | * because in the growfs case, mp->m_sb.sb_agcount is not yet updated | |
241 | * to the potentially higher ag count. | |
242 | * | |
243 | * Returns the maximum AG index which may contain inodes. | |
9de67c3b | 244 | */ |
2d2194f6 | 245 | xfs_agnumber_t |
12c3f05c ES |
246 | xfs_set_inode_alloc( |
247 | struct xfs_mount *mp, | |
248 | xfs_agnumber_t agcount) | |
2d2194f6 | 249 | { |
12c3f05c | 250 | xfs_agnumber_t index; |
4056c1d0 | 251 | xfs_agnumber_t maxagi = 0; |
2d2194f6 CM |
252 | xfs_sb_t *sbp = &mp->m_sb; |
253 | xfs_agnumber_t max_metadata; | |
54aa61f8 ES |
254 | xfs_agino_t agino; |
255 | xfs_ino_t ino; | |
2d2194f6 | 256 | |
12c3f05c ES |
257 | /* |
258 | * Calculate how much should be reserved for inodes to meet | |
259 | * the max inode percentage. Used only for inode32. | |
2d2194f6 | 260 | */ |
ef325959 | 261 | if (M_IGEO(mp)->maxicount) { |
c8ce540d | 262 | uint64_t icount; |
2d2194f6 CM |
263 | |
264 | icount = sbp->sb_dblocks * sbp->sb_imax_pct; | |
265 | do_div(icount, 100); | |
266 | icount += sbp->sb_agblocks - 1; | |
267 | do_div(icount, sbp->sb_agblocks); | |
268 | max_metadata = icount; | |
269 | } else { | |
9de67c3b | 270 | max_metadata = agcount; |
2d2194f6 CM |
271 | } |
272 | ||
12c3f05c | 273 | /* Get the last possible inode in the filesystem */ |
43004b2a | 274 | agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1); |
12c3f05c ES |
275 | ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino); |
276 | ||
277 | /* | |
278 | * If user asked for no more than 32-bit inodes, and the fs is | |
279 | * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter | |
280 | * the allocator to accommodate the request. | |
281 | */ | |
282 | if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32) | |
283 | mp->m_flags |= XFS_MOUNT_32BITINODES; | |
284 | else | |
285 | mp->m_flags &= ~XFS_MOUNT_32BITINODES; | |
54aa61f8 | 286 | |
9de67c3b | 287 | for (index = 0; index < agcount; index++) { |
12c3f05c | 288 | struct xfs_perag *pag; |
4056c1d0 | 289 | |
12c3f05c | 290 | ino = XFS_AGINO_TO_INO(mp, index, agino); |
2d2194f6 CM |
291 | |
292 | pag = xfs_perag_get(mp, index); | |
2d2194f6 | 293 | |
12c3f05c ES |
294 | if (mp->m_flags & XFS_MOUNT_32BITINODES) { |
295 | if (ino > XFS_MAXINUMBER_32) { | |
296 | pag->pagi_inodeok = 0; | |
297 | pag->pagf_metadata = 0; | |
298 | } else { | |
299 | pag->pagi_inodeok = 1; | |
300 | maxagi++; | |
301 | if (index < max_metadata) | |
302 | pag->pagf_metadata = 1; | |
303 | else | |
304 | pag->pagf_metadata = 0; | |
305 | } | |
306 | } else { | |
307 | pag->pagi_inodeok = 1; | |
308 | pag->pagf_metadata = 0; | |
309 | } | |
2d2194f6 | 310 | |
2d2194f6 CM |
311 | xfs_perag_put(pag); |
312 | } | |
313 | ||
12c3f05c | 314 | return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount; |
2d2194f6 CM |
315 | } |
316 | ||
3180e66d | 317 | STATIC int |
1da177e4 LT |
318 | xfs_blkdev_get( |
319 | xfs_mount_t *mp, | |
320 | const char *name, | |
321 | struct block_device **bdevp) | |
322 | { | |
323 | int error = 0; | |
324 | ||
d4d77629 TH |
325 | *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL, |
326 | mp); | |
1da177e4 LT |
327 | if (IS_ERR(*bdevp)) { |
328 | error = PTR_ERR(*bdevp); | |
77af574e | 329 | xfs_warn(mp, "Invalid device [%s], error=%d", name, error); |
1da177e4 LT |
330 | } |
331 | ||
2451337d | 332 | return error; |
1da177e4 LT |
333 | } |
334 | ||
3180e66d | 335 | STATIC void |
1da177e4 LT |
336 | xfs_blkdev_put( |
337 | struct block_device *bdev) | |
338 | { | |
339 | if (bdev) | |
e525fd89 | 340 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); |
1da177e4 LT |
341 | } |
342 | ||
19f354d4 CH |
343 | STATIC void |
344 | xfs_close_devices( | |
345 | struct xfs_mount *mp) | |
346 | { | |
486aff5e DW |
347 | struct dax_device *dax_ddev = mp->m_ddev_targp->bt_daxdev; |
348 | ||
19f354d4 | 349 | if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { |
c032bfcf | 350 | struct block_device *logdev = mp->m_logdev_targp->bt_bdev; |
486aff5e DW |
351 | struct dax_device *dax_logdev = mp->m_logdev_targp->bt_daxdev; |
352 | ||
a1f69417 | 353 | xfs_free_buftarg(mp->m_logdev_targp); |
c032bfcf | 354 | xfs_blkdev_put(logdev); |
486aff5e | 355 | fs_put_dax(dax_logdev); |
19f354d4 CH |
356 | } |
357 | if (mp->m_rtdev_targp) { | |
c032bfcf | 358 | struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev; |
486aff5e DW |
359 | struct dax_device *dax_rtdev = mp->m_rtdev_targp->bt_daxdev; |
360 | ||
a1f69417 | 361 | xfs_free_buftarg(mp->m_rtdev_targp); |
c032bfcf | 362 | xfs_blkdev_put(rtdev); |
486aff5e | 363 | fs_put_dax(dax_rtdev); |
19f354d4 | 364 | } |
a1f69417 | 365 | xfs_free_buftarg(mp->m_ddev_targp); |
486aff5e | 366 | fs_put_dax(dax_ddev); |
19f354d4 CH |
367 | } |
368 | ||
369 | /* | |
370 | * The file system configurations are: | |
371 | * (1) device (partition) with data and internal log | |
372 | * (2) logical volume with data and log subvolumes. | |
373 | * (3) logical volume with data, log, and realtime subvolumes. | |
374 | * | |
375 | * We only have to handle opening the log and realtime volumes here if | |
376 | * they are present. The data subvolume has already been opened by | |
377 | * get_sb_bdev() and is stored in sb->s_bdev. | |
378 | */ | |
379 | STATIC int | |
380 | xfs_open_devices( | |
9d565ffa | 381 | struct xfs_mount *mp) |
19f354d4 CH |
382 | { |
383 | struct block_device *ddev = mp->m_super->s_bdev; | |
486aff5e DW |
384 | struct dax_device *dax_ddev = fs_dax_get_by_bdev(ddev); |
385 | struct dax_device *dax_logdev = NULL, *dax_rtdev = NULL; | |
19f354d4 CH |
386 | struct block_device *logdev = NULL, *rtdev = NULL; |
387 | int error; | |
388 | ||
389 | /* | |
390 | * Open real time and log devices - order is important. | |
391 | */ | |
9d565ffa CH |
392 | if (mp->m_logname) { |
393 | error = xfs_blkdev_get(mp, mp->m_logname, &logdev); | |
19f354d4 CH |
394 | if (error) |
395 | goto out; | |
486aff5e | 396 | dax_logdev = fs_dax_get_by_bdev(logdev); |
19f354d4 CH |
397 | } |
398 | ||
9d565ffa CH |
399 | if (mp->m_rtname) { |
400 | error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev); | |
19f354d4 CH |
401 | if (error) |
402 | goto out_close_logdev; | |
403 | ||
404 | if (rtdev == ddev || rtdev == logdev) { | |
4f10700a DC |
405 | xfs_warn(mp, |
406 | "Cannot mount filesystem with identical rtdev and ddev/logdev."); | |
2451337d | 407 | error = -EINVAL; |
19f354d4 CH |
408 | goto out_close_rtdev; |
409 | } | |
486aff5e | 410 | dax_rtdev = fs_dax_get_by_bdev(rtdev); |
19f354d4 CH |
411 | } |
412 | ||
413 | /* | |
414 | * Setup xfs_mount buffer target pointers | |
415 | */ | |
2451337d | 416 | error = -ENOMEM; |
486aff5e | 417 | mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, dax_ddev); |
19f354d4 CH |
418 | if (!mp->m_ddev_targp) |
419 | goto out_close_rtdev; | |
420 | ||
421 | if (rtdev) { | |
486aff5e | 422 | mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, dax_rtdev); |
19f354d4 CH |
423 | if (!mp->m_rtdev_targp) |
424 | goto out_free_ddev_targ; | |
425 | } | |
426 | ||
427 | if (logdev && logdev != ddev) { | |
486aff5e | 428 | mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, dax_logdev); |
19f354d4 CH |
429 | if (!mp->m_logdev_targp) |
430 | goto out_free_rtdev_targ; | |
431 | } else { | |
432 | mp->m_logdev_targp = mp->m_ddev_targp; | |
433 | } | |
434 | ||
435 | return 0; | |
436 | ||
437 | out_free_rtdev_targ: | |
438 | if (mp->m_rtdev_targp) | |
a1f69417 | 439 | xfs_free_buftarg(mp->m_rtdev_targp); |
19f354d4 | 440 | out_free_ddev_targ: |
a1f69417 | 441 | xfs_free_buftarg(mp->m_ddev_targp); |
19f354d4 | 442 | out_close_rtdev: |
d2a5e3c6 | 443 | xfs_blkdev_put(rtdev); |
486aff5e | 444 | fs_put_dax(dax_rtdev); |
19f354d4 | 445 | out_close_logdev: |
486aff5e | 446 | if (logdev && logdev != ddev) { |
19f354d4 | 447 | xfs_blkdev_put(logdev); |
486aff5e DW |
448 | fs_put_dax(dax_logdev); |
449 | } | |
19f354d4 | 450 | out: |
486aff5e | 451 | fs_put_dax(dax_ddev); |
19f354d4 CH |
452 | return error; |
453 | } | |
454 | ||
e34b562c CH |
455 | /* |
456 | * Setup xfs_mount buffer target pointers based on superblock | |
457 | */ | |
458 | STATIC int | |
459 | xfs_setup_devices( | |
460 | struct xfs_mount *mp) | |
461 | { | |
462 | int error; | |
19f354d4 | 463 | |
a96c4151 | 464 | error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize); |
e34b562c CH |
465 | if (error) |
466 | return error; | |
467 | ||
468 | if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { | |
469 | unsigned int log_sector_size = BBSIZE; | |
470 | ||
471 | if (xfs_sb_version_hassector(&mp->m_sb)) | |
472 | log_sector_size = mp->m_sb.sb_logsectsize; | |
473 | error = xfs_setsize_buftarg(mp->m_logdev_targp, | |
e34b562c CH |
474 | log_sector_size); |
475 | if (error) | |
476 | return error; | |
477 | } | |
478 | if (mp->m_rtdev_targp) { | |
479 | error = xfs_setsize_buftarg(mp->m_rtdev_targp, | |
e34b562c CH |
480 | mp->m_sb.sb_sectsize); |
481 | if (error) | |
482 | return error; | |
483 | } | |
484 | ||
485 | return 0; | |
486 | } | |
19f354d4 | 487 | |
aa6bf01d CH |
488 | STATIC int |
489 | xfs_init_mount_workqueues( | |
490 | struct xfs_mount *mp) | |
491 | { | |
78c931b8 | 492 | mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s", |
05a302a1 DW |
493 | XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM), |
494 | 1, mp->m_super->s_id); | |
78c931b8 BF |
495 | if (!mp->m_buf_workqueue) |
496 | goto out; | |
497 | ||
aa6bf01d | 498 | mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s", |
05a302a1 DW |
499 | XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM), |
500 | 0, mp->m_super->s_id); | |
aa6bf01d | 501 | if (!mp->m_unwritten_workqueue) |
28408243 | 502 | goto out_destroy_buf; |
aa6bf01d | 503 | |
4c2d542f | 504 | mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s", |
05a302a1 | 505 | XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM | WQ_UNBOUND), |
e1d3d218 | 506 | 0, mp->m_super->s_id); |
4c2d542f DC |
507 | if (!mp->m_cil_workqueue) |
508 | goto out_destroy_unwritten; | |
5889608d DC |
509 | |
510 | mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s", | |
05a302a1 DW |
511 | XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM), |
512 | 0, mp->m_super->s_id); | |
5889608d DC |
513 | if (!mp->m_reclaim_workqueue) |
514 | goto out_destroy_cil; | |
515 | ||
3fef46fc | 516 | mp->m_gc_workqueue = alloc_workqueue("xfs-gc/%s", |
47bd6d34 | 517 | WQ_SYSFS | WQ_UNBOUND | WQ_FREEZABLE | WQ_MEM_RECLAIM, |
05a302a1 | 518 | 0, mp->m_super->s_id); |
3fef46fc | 519 | if (!mp->m_gc_workqueue) |
1058d0f5 | 520 | goto out_destroy_reclaim; |
579b62fa | 521 | |
05a302a1 DW |
522 | mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", |
523 | XFS_WQFLAGS(WQ_FREEZABLE), 0, mp->m_super->s_id); | |
696a5620 BF |
524 | if (!mp->m_sync_workqueue) |
525 | goto out_destroy_eofb; | |
526 | ||
aa6bf01d CH |
527 | return 0; |
528 | ||
696a5620 | 529 | out_destroy_eofb: |
3fef46fc | 530 | destroy_workqueue(mp->m_gc_workqueue); |
5889608d DC |
531 | out_destroy_reclaim: |
532 | destroy_workqueue(mp->m_reclaim_workqueue); | |
533 | out_destroy_cil: | |
534 | destroy_workqueue(mp->m_cil_workqueue); | |
4c2d542f DC |
535 | out_destroy_unwritten: |
536 | destroy_workqueue(mp->m_unwritten_workqueue); | |
78c931b8 BF |
537 | out_destroy_buf: |
538 | destroy_workqueue(mp->m_buf_workqueue); | |
aa6bf01d CH |
539 | out: |
540 | return -ENOMEM; | |
541 | } | |
542 | ||
543 | STATIC void | |
544 | xfs_destroy_mount_workqueues( | |
545 | struct xfs_mount *mp) | |
546 | { | |
696a5620 | 547 | destroy_workqueue(mp->m_sync_workqueue); |
3fef46fc | 548 | destroy_workqueue(mp->m_gc_workqueue); |
5889608d | 549 | destroy_workqueue(mp->m_reclaim_workqueue); |
4c2d542f | 550 | destroy_workqueue(mp->m_cil_workqueue); |
aa6bf01d | 551 | destroy_workqueue(mp->m_unwritten_workqueue); |
78c931b8 | 552 | destroy_workqueue(mp->m_buf_workqueue); |
aa6bf01d CH |
553 | } |
554 | ||
f0f7a674 DW |
555 | static void |
556 | xfs_flush_inodes_worker( | |
557 | struct work_struct *work) | |
558 | { | |
559 | struct xfs_mount *mp = container_of(work, struct xfs_mount, | |
560 | m_flush_inodes_work); | |
561 | struct super_block *sb = mp->m_super; | |
562 | ||
563 | if (down_read_trylock(&sb->s_umount)) { | |
564 | sync_inodes_sb(sb); | |
565 | up_read(&sb->s_umount); | |
566 | } | |
567 | } | |
568 | ||
9aa05000 DC |
569 | /* |
570 | * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK | |
571 | * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting | |
572 | * for IO to complete so that we effectively throttle multiple callers to the | |
573 | * rate at which IO is completing. | |
574 | */ | |
575 | void | |
576 | xfs_flush_inodes( | |
577 | struct xfs_mount *mp) | |
578 | { | |
f0f7a674 DW |
579 | /* |
580 | * If flush_work() returns true then that means we waited for a flush | |
581 | * which was already in progress. Don't bother running another scan. | |
582 | */ | |
583 | if (flush_work(&mp->m_flush_inodes_work)) | |
c6425702 DW |
584 | return; |
585 | ||
f0f7a674 DW |
586 | queue_work(mp->m_sync_workqueue, &mp->m_flush_inodes_work); |
587 | flush_work(&mp->m_flush_inodes_work); | |
9aa05000 DC |
588 | } |
589 | ||
bf904248 | 590 | /* Catch misguided souls that try to use this interface on XFS */ |
1da177e4 | 591 | STATIC struct inode * |
a50cd269 | 592 | xfs_fs_alloc_inode( |
1da177e4 LT |
593 | struct super_block *sb) |
594 | { | |
bf904248 | 595 | BUG(); |
493dca61 | 596 | return NULL; |
1da177e4 LT |
597 | } |
598 | ||
4831822f CH |
599 | #ifdef DEBUG |
600 | static void | |
601 | xfs_check_delalloc( | |
602 | struct xfs_inode *ip, | |
603 | int whichfork) | |
604 | { | |
605 | struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); | |
606 | struct xfs_bmbt_irec got; | |
607 | struct xfs_iext_cursor icur; | |
608 | ||
609 | if (!ifp || !xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got)) | |
610 | return; | |
611 | do { | |
612 | if (isnullstartblock(got.br_startblock)) { | |
613 | xfs_warn(ip->i_mount, | |
614 | "ino %llx %s fork has delalloc extent at [0x%llx:0x%llx]", | |
615 | ip->i_ino, | |
616 | whichfork == XFS_DATA_FORK ? "data" : "cow", | |
617 | got.br_startoff, got.br_blockcount); | |
618 | } | |
619 | } while (xfs_iext_next_extent(ifp, &icur, &got)); | |
620 | } | |
621 | #else | |
622 | #define xfs_check_delalloc(ip, whichfork) do { } while (0) | |
623 | #endif | |
624 | ||
bf904248 | 625 | /* |
99fa8cb3 | 626 | * Now that the generic code is guaranteed not to be accessing |
8179c036 | 627 | * the linux inode, we can inactivate and reclaim the inode. |
bf904248 | 628 | */ |
1da177e4 | 629 | STATIC void |
a50cd269 | 630 | xfs_fs_destroy_inode( |
848ce8f7 | 631 | struct inode *inode) |
1da177e4 | 632 | { |
848ce8f7 CH |
633 | struct xfs_inode *ip = XFS_I(inode); |
634 | ||
cca28fb8 | 635 | trace_xfs_destroy_inode(ip); |
99fa8cb3 | 636 | |
65523218 | 637 | ASSERT(!rwsem_is_locked(&inode->i_rwsem)); |
8179c036 DC |
638 | XFS_STATS_INC(ip->i_mount, vn_rele); |
639 | XFS_STATS_INC(ip->i_mount, vn_remove); | |
640 | ||
641 | xfs_inactive(ip); | |
848ce8f7 | 642 | |
4831822f CH |
643 | if (!XFS_FORCED_SHUTDOWN(ip->i_mount) && ip->i_delayed_blks) { |
644 | xfs_check_delalloc(ip, XFS_DATA_FORK); | |
645 | xfs_check_delalloc(ip, XFS_COW_FORK); | |
646 | ASSERT(0); | |
647 | } | |
648 | ||
8179c036 | 649 | XFS_STATS_INC(ip->i_mount, vn_reclaim); |
848ce8f7 CH |
650 | |
651 | /* | |
652 | * We should never get here with one of the reclaim flags already set. | |
653 | */ | |
654 | ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE)); | |
655 | ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM)); | |
656 | ||
657 | /* | |
718ecc50 DC |
658 | * We always use background reclaim here because even if the inode is |
659 | * clean, it still may be under IO and hence we have wait for IO | |
660 | * completion to occur before we can reclaim the inode. The background | |
661 | * reclaim path handles this more efficiently than we can here, so | |
662 | * simply let background reclaim tear down all inodes. | |
848ce8f7 | 663 | */ |
c076ae7a | 664 | xfs_inode_mark_reclaimable(ip); |
1da177e4 LT |
665 | } |
666 | ||
c3b1b131 CH |
667 | static void |
668 | xfs_fs_dirty_inode( | |
669 | struct inode *inode, | |
670 | int flag) | |
671 | { | |
672 | struct xfs_inode *ip = XFS_I(inode); | |
673 | struct xfs_mount *mp = ip->i_mount; | |
674 | struct xfs_trans *tp; | |
675 | ||
676 | if (!(inode->i_sb->s_flags & SB_LAZYTIME)) | |
677 | return; | |
678 | if (flag != I_DIRTY_SYNC || !(inode->i_state & I_DIRTY_TIME)) | |
679 | return; | |
680 | ||
681 | if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp)) | |
682 | return; | |
683 | xfs_ilock(ip, XFS_ILOCK_EXCL); | |
684 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); | |
685 | xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP); | |
686 | xfs_trans_commit(tp); | |
687 | } | |
688 | ||
07c8f675 DC |
689 | /* |
690 | * Slab object creation initialisation for the XFS inode. | |
691 | * This covers only the idempotent fields in the XFS inode; | |
692 | * all other fields need to be initialised on allocation | |
b595076a | 693 | * from the slab. This avoids the need to repeatedly initialise |
07c8f675 DC |
694 | * fields in the xfs inode that left in the initialise state |
695 | * when freeing the inode. | |
696 | */ | |
bf904248 DC |
697 | STATIC void |
698 | xfs_fs_inode_init_once( | |
07c8f675 DC |
699 | void *inode) |
700 | { | |
701 | struct xfs_inode *ip = inode; | |
702 | ||
703 | memset(ip, 0, sizeof(struct xfs_inode)); | |
bf904248 DC |
704 | |
705 | /* vfs inode */ | |
706 | inode_init_once(VFS_I(ip)); | |
707 | ||
708 | /* xfs inode */ | |
07c8f675 DC |
709 | atomic_set(&ip->i_pincount, 0); |
710 | spin_lock_init(&ip->i_flags_lock); | |
07c8f675 | 711 | |
653c60b6 DC |
712 | mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER, |
713 | "xfsino", ip->i_ino); | |
07c8f675 DC |
714 | mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER, |
715 | "xfsino", ip->i_ino); | |
07c8f675 DC |
716 | } |
717 | ||
5132ba8f DC |
718 | /* |
719 | * We do an unlocked check for XFS_IDONTCACHE here because we are already | |
720 | * serialised against cache hits here via the inode->i_lock and igrab() in | |
721 | * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be | |
722 | * racing with us, and it avoids needing to grab a spinlock here for every inode | |
723 | * we drop the final reference on. | |
724 | */ | |
725 | STATIC int | |
726 | xfs_fs_drop_inode( | |
727 | struct inode *inode) | |
728 | { | |
729 | struct xfs_inode *ip = XFS_I(inode); | |
730 | ||
17c12bcd DW |
731 | /* |
732 | * If this unlinked inode is in the middle of recovery, don't | |
733 | * drop the inode just yet; log recovery will take care of | |
734 | * that. See the comment for this inode flag. | |
735 | */ | |
736 | if (ip->i_flags & XFS_IRECOVERY) { | |
737 | ASSERT(ip->i_mount->m_log->l_flags & XLOG_RECOVERY_NEEDED); | |
738 | return 0; | |
739 | } | |
740 | ||
dae2f8ed | 741 | return generic_drop_inode(inode); |
5132ba8f DC |
742 | } |
743 | ||
a943f372 IK |
744 | static void |
745 | xfs_mount_free( | |
a738159d CH |
746 | struct xfs_mount *mp) |
747 | { | |
a738159d CH |
748 | kfree(mp->m_rtname); |
749 | kfree(mp->m_logname); | |
a943f372 | 750 | kmem_free(mp); |
a738159d CH |
751 | } |
752 | ||
1da177e4 | 753 | STATIC int |
69961a26 | 754 | xfs_fs_sync_fs( |
1da177e4 LT |
755 | struct super_block *sb, |
756 | int wait) | |
757 | { | |
745f6919 | 758 | struct xfs_mount *mp = XFS_M(sb); |
1da177e4 | 759 | |
e893bffd | 760 | /* |
34625c66 | 761 | * Doing anything during the async pass would be counterproductive. |
e893bffd | 762 | */ |
34625c66 | 763 | if (!wait) |
69961a26 | 764 | return 0; |
69961a26 | 765 | |
34061f5c | 766 | xfs_log_force(mp, XFS_LOG_SYNC); |
69961a26 | 767 | if (laptop_mode) { |
1da177e4 LT |
768 | /* |
769 | * The disk must be active because we're syncing. | |
f661f1e0 | 770 | * We schedule log work now (now that the disk is |
1da177e4 LT |
771 | * active) instead of later (when it might not be). |
772 | */ | |
f661f1e0 | 773 | flush_delayed_work(&mp->m_log->l_work); |
1da177e4 LT |
774 | } |
775 | ||
69961a26 | 776 | return 0; |
1da177e4 LT |
777 | } |
778 | ||
779 | STATIC int | |
a50cd269 | 780 | xfs_fs_statfs( |
726c3342 | 781 | struct dentry *dentry, |
1da177e4 LT |
782 | struct kstatfs *statp) |
783 | { | |
4ca488eb CH |
784 | struct xfs_mount *mp = XFS_M(dentry->d_sb); |
785 | xfs_sb_t *sbp = &mp->m_sb; | |
2b0143b5 | 786 | struct xfs_inode *ip = XFS_I(d_inode(dentry)); |
c8ce540d DW |
787 | uint64_t fakeinos, id; |
788 | uint64_t icount; | |
789 | uint64_t ifree; | |
790 | uint64_t fdblocks; | |
4ca488eb | 791 | xfs_extlen_t lsize; |
c8ce540d | 792 | int64_t ffree; |
4ca488eb | 793 | |
dddde68b | 794 | statp->f_type = XFS_SUPER_MAGIC; |
4ca488eb CH |
795 | statp->f_namelen = MAXNAMELEN - 1; |
796 | ||
797 | id = huge_encode_dev(mp->m_ddev_targp->bt_dev); | |
6d1349c7 | 798 | statp->f_fsid = u64_to_fsid(id); |
4ca488eb | 799 | |
501ab323 | 800 | icount = percpu_counter_sum(&mp->m_icount); |
e88b64ea | 801 | ifree = percpu_counter_sum(&mp->m_ifree); |
0d485ada | 802 | fdblocks = percpu_counter_sum(&mp->m_fdblocks); |
4ca488eb CH |
803 | |
804 | spin_lock(&mp->m_sb_lock); | |
805 | statp->f_bsize = sbp->sb_blocksize; | |
806 | lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0; | |
807 | statp->f_blocks = sbp->sb_dblocks - lsize; | |
0d485ada DC |
808 | spin_unlock(&mp->m_sb_lock); |
809 | ||
237aac46 ZB |
810 | /* make sure statp->f_bfree does not underflow */ |
811 | statp->f_bfree = max_t(int64_t, fdblocks - mp->m_alloc_set_aside, 0); | |
0d485ada DC |
812 | statp->f_bavail = statp->f_bfree; |
813 | ||
43004b2a | 814 | fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree); |
9bb54cb5 | 815 | statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER); |
ef325959 | 816 | if (M_IGEO(mp)->maxicount) |
a19d9f88 CH |
817 | statp->f_files = min_t(typeof(statp->f_files), |
818 | statp->f_files, | |
ef325959 | 819 | M_IGEO(mp)->maxicount); |
2fe33661 | 820 | |
01f9882e ES |
821 | /* If sb_icount overshot maxicount, report actual allocation */ |
822 | statp->f_files = max_t(typeof(statp->f_files), | |
823 | statp->f_files, | |
824 | sbp->sb_icount); | |
825 | ||
2fe33661 | 826 | /* make sure statp->f_ffree does not underflow */ |
e88b64ea | 827 | ffree = statp->f_files - (icount - ifree); |
c8ce540d | 828 | statp->f_ffree = max_t(int64_t, ffree, 0); |
2fe33661 | 829 | |
4ca488eb | 830 | |
db07349d | 831 | if ((ip->i_diflags & XFS_DIFLAG_PROJINHERIT) && |
83e782e1 CS |
832 | ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) == |
833 | (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD)) | |
7d095257 | 834 | xfs_qm_statvfs(ip, statp); |
a0158315 RW |
835 | |
836 | if (XFS_IS_REALTIME_MOUNT(mp) && | |
db07349d | 837 | (ip->i_diflags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) { |
a0158315 RW |
838 | statp->f_blocks = sbp->sb_rblocks; |
839 | statp->f_bavail = statp->f_bfree = | |
840 | sbp->sb_frextents * sbp->sb_rextsize; | |
841 | } | |
842 | ||
4ca488eb | 843 | return 0; |
1da177e4 LT |
844 | } |
845 | ||
d5db0f97 ES |
846 | STATIC void |
847 | xfs_save_resvblks(struct xfs_mount *mp) | |
848 | { | |
c8ce540d | 849 | uint64_t resblks = 0; |
d5db0f97 ES |
850 | |
851 | mp->m_resblks_save = mp->m_resblks; | |
852 | xfs_reserve_blocks(mp, &resblks, NULL); | |
853 | } | |
854 | ||
855 | STATIC void | |
856 | xfs_restore_resvblks(struct xfs_mount *mp) | |
857 | { | |
c8ce540d | 858 | uint64_t resblks; |
d5db0f97 ES |
859 | |
860 | if (mp->m_resblks_save) { | |
861 | resblks = mp->m_resblks_save; | |
862 | mp->m_resblks_save = 0; | |
863 | } else | |
864 | resblks = xfs_default_resblks(mp); | |
865 | ||
866 | xfs_reserve_blocks(mp, &resblks, NULL); | |
867 | } | |
868 | ||
8757c38f IK |
869 | /* |
870 | * Second stage of a freeze. The data is already frozen so we only | |
871 | * need to take care of the metadata. Once that's done sync the superblock | |
872 | * to the log to dirty it in case of a crash while frozen. This ensures that we | |
873 | * will recover the unlinked inode lists on the next mount. | |
874 | */ | |
875 | STATIC int | |
876 | xfs_fs_freeze( | |
877 | struct super_block *sb) | |
878 | { | |
879 | struct xfs_mount *mp = XFS_M(sb); | |
c3f2375b WL |
880 | unsigned int flags; |
881 | int ret; | |
8757c38f | 882 | |
c3f2375b WL |
883 | /* |
884 | * The filesystem is now frozen far enough that memory reclaim | |
885 | * cannot safely operate on the filesystem. Hence we need to | |
886 | * set a GFP_NOFS context here to avoid recursion deadlocks. | |
887 | */ | |
888 | flags = memalloc_nofs_save(); | |
c9a6526f | 889 | xfs_blockgc_stop(mp); |
8757c38f | 890 | xfs_save_resvblks(mp); |
5b0ad7c2 | 891 | ret = xfs_log_quiesce(mp); |
c3f2375b WL |
892 | memalloc_nofs_restore(flags); |
893 | return ret; | |
8757c38f IK |
894 | } |
895 | ||
896 | STATIC int | |
897 | xfs_fs_unfreeze( | |
898 | struct super_block *sb) | |
899 | { | |
900 | struct xfs_mount *mp = XFS_M(sb); | |
901 | ||
902 | xfs_restore_resvblks(mp); | |
903 | xfs_log_work_queue(mp); | |
c9a6526f | 904 | xfs_blockgc_start(mp); |
8757c38f IK |
905 | return 0; |
906 | } | |
907 | ||
908 | /* | |
909 | * This function fills in xfs_mount_t fields based on mount args. | |
910 | * Note: the superblock _has_ now been read in. | |
911 | */ | |
912 | STATIC int | |
913 | xfs_finish_flags( | |
914 | struct xfs_mount *mp) | |
915 | { | |
916 | int ronly = (mp->m_flags & XFS_MOUNT_RDONLY); | |
917 | ||
918 | /* Fail a mount where the logbuf is smaller than the log stripe */ | |
919 | if (xfs_sb_version_haslogv2(&mp->m_sb)) { | |
920 | if (mp->m_logbsize <= 0 && | |
921 | mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) { | |
922 | mp->m_logbsize = mp->m_sb.sb_logsunit; | |
923 | } else if (mp->m_logbsize > 0 && | |
924 | mp->m_logbsize < mp->m_sb.sb_logsunit) { | |
925 | xfs_warn(mp, | |
926 | "logbuf size must be greater than or equal to log stripe size"); | |
927 | return -EINVAL; | |
928 | } | |
929 | } else { | |
930 | /* Fail a mount if the logbuf is larger than 32K */ | |
931 | if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) { | |
932 | xfs_warn(mp, | |
933 | "logbuf size for version 1 logs must be 16K or 32K"); | |
934 | return -EINVAL; | |
935 | } | |
936 | } | |
937 | ||
938 | /* | |
939 | * V5 filesystems always use attr2 format for attributes. | |
940 | */ | |
941 | if (xfs_sb_version_hascrc(&mp->m_sb) && | |
942 | (mp->m_flags & XFS_MOUNT_NOATTR2)) { | |
943 | xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. " | |
944 | "attr2 is always enabled for V5 filesystems."); | |
945 | return -EINVAL; | |
946 | } | |
947 | ||
948 | /* | |
949 | * mkfs'ed attr2 will turn on attr2 mount unless explicitly | |
950 | * told by noattr2 to turn it off | |
951 | */ | |
952 | if (xfs_sb_version_hasattr2(&mp->m_sb) && | |
953 | !(mp->m_flags & XFS_MOUNT_NOATTR2)) | |
954 | mp->m_flags |= XFS_MOUNT_ATTR2; | |
955 | ||
956 | /* | |
957 | * prohibit r/w mounts of read-only filesystems | |
958 | */ | |
959 | if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) { | |
960 | xfs_warn(mp, | |
961 | "cannot mount a read-only filesystem as read-write"); | |
962 | return -EROFS; | |
963 | } | |
964 | ||
965 | if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) && | |
966 | (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) && | |
967 | !xfs_sb_version_has_pquotino(&mp->m_sb)) { | |
968 | xfs_warn(mp, | |
969 | "Super block does not support project and group quota together"); | |
970 | return -EINVAL; | |
971 | } | |
972 | ||
973 | return 0; | |
974 | } | |
975 | ||
976 | static int | |
977 | xfs_init_percpu_counters( | |
978 | struct xfs_mount *mp) | |
979 | { | |
980 | int error; | |
981 | ||
982 | error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL); | |
983 | if (error) | |
984 | return -ENOMEM; | |
985 | ||
986 | error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL); | |
987 | if (error) | |
988 | goto free_icount; | |
989 | ||
990 | error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL); | |
991 | if (error) | |
992 | goto free_ifree; | |
993 | ||
994 | error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL); | |
995 | if (error) | |
996 | goto free_fdblocks; | |
997 | ||
998 | return 0; | |
999 | ||
1000 | free_fdblocks: | |
1001 | percpu_counter_destroy(&mp->m_fdblocks); | |
1002 | free_ifree: | |
1003 | percpu_counter_destroy(&mp->m_ifree); | |
1004 | free_icount: | |
1005 | percpu_counter_destroy(&mp->m_icount); | |
1006 | return -ENOMEM; | |
1007 | } | |
1008 | ||
1009 | void | |
1010 | xfs_reinit_percpu_counters( | |
1011 | struct xfs_mount *mp) | |
1012 | { | |
1013 | percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount); | |
1014 | percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree); | |
1015 | percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks); | |
1016 | } | |
1017 | ||
1018 | static void | |
1019 | xfs_destroy_percpu_counters( | |
1020 | struct xfs_mount *mp) | |
1021 | { | |
1022 | percpu_counter_destroy(&mp->m_icount); | |
1023 | percpu_counter_destroy(&mp->m_ifree); | |
1024 | percpu_counter_destroy(&mp->m_fdblocks); | |
1025 | ASSERT(XFS_FORCED_SHUTDOWN(mp) || | |
1026 | percpu_counter_sum(&mp->m_delalloc_blks) == 0); | |
1027 | percpu_counter_destroy(&mp->m_delalloc_blks); | |
1028 | } | |
1029 | ||
1030 | static void | |
1031 | xfs_fs_put_super( | |
1032 | struct super_block *sb) | |
1033 | { | |
1034 | struct xfs_mount *mp = XFS_M(sb); | |
1035 | ||
1036 | /* if ->fill_super failed, we have no mount to tear down */ | |
1037 | if (!sb->s_fs_info) | |
1038 | return; | |
1039 | ||
1040 | xfs_notice(mp, "Unmounting Filesystem"); | |
1041 | xfs_filestream_unmount(mp); | |
1042 | xfs_unmountfs(mp); | |
1043 | ||
1044 | xfs_freesb(mp); | |
1045 | free_percpu(mp->m_stats.xs_stats); | |
1046 | xfs_destroy_percpu_counters(mp); | |
1047 | xfs_destroy_mount_workqueues(mp); | |
1048 | xfs_close_devices(mp); | |
1049 | ||
1050 | sb->s_fs_info = NULL; | |
1051 | xfs_mount_free(mp); | |
1052 | } | |
1053 | ||
1054 | static long | |
1055 | xfs_fs_nr_cached_objects( | |
1056 | struct super_block *sb, | |
1057 | struct shrink_control *sc) | |
1058 | { | |
1059 | /* Paranoia: catch incorrect calls during mount setup or teardown */ | |
1060 | if (WARN_ON_ONCE(!sb->s_fs_info)) | |
1061 | return 0; | |
1062 | return xfs_reclaim_inodes_count(XFS_M(sb)); | |
1063 | } | |
1064 | ||
1065 | static long | |
1066 | xfs_fs_free_cached_objects( | |
1067 | struct super_block *sb, | |
1068 | struct shrink_control *sc) | |
c7eea6f7 | 1069 | { |
8757c38f IK |
1070 | return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan); |
1071 | } | |
c7eea6f7 | 1072 | |
8757c38f IK |
1073 | static const struct super_operations xfs_super_operations = { |
1074 | .alloc_inode = xfs_fs_alloc_inode, | |
1075 | .destroy_inode = xfs_fs_destroy_inode, | |
1076 | .dirty_inode = xfs_fs_dirty_inode, | |
1077 | .drop_inode = xfs_fs_drop_inode, | |
1078 | .put_super = xfs_fs_put_super, | |
1079 | .sync_fs = xfs_fs_sync_fs, | |
1080 | .freeze_fs = xfs_fs_freeze, | |
1081 | .unfreeze_fs = xfs_fs_unfreeze, | |
1082 | .statfs = xfs_fs_statfs, | |
1083 | .show_options = xfs_fs_show_options, | |
1084 | .nr_cached_objects = xfs_fs_nr_cached_objects, | |
1085 | .free_cached_objects = xfs_fs_free_cached_objects, | |
1086 | }; | |
c7eea6f7 | 1087 | |
8757c38f IK |
1088 | static int |
1089 | suffix_kstrtoint( | |
1090 | const char *s, | |
1091 | unsigned int base, | |
1092 | int *res) | |
1093 | { | |
1094 | int last, shift_left_factor = 0, _res; | |
1095 | char *value; | |
1096 | int ret = 0; | |
1097 | ||
1098 | value = kstrdup(s, GFP_KERNEL); | |
1099 | if (!value) | |
1100 | return -ENOMEM; | |
1101 | ||
1102 | last = strlen(value) - 1; | |
1103 | if (value[last] == 'K' || value[last] == 'k') { | |
1104 | shift_left_factor = 10; | |
1105 | value[last] = '\0'; | |
1106 | } | |
1107 | if (value[last] == 'M' || value[last] == 'm') { | |
1108 | shift_left_factor = 20; | |
1109 | value[last] = '\0'; | |
1110 | } | |
1111 | if (value[last] == 'G' || value[last] == 'g') { | |
1112 | shift_left_factor = 30; | |
1113 | value[last] = '\0'; | |
1114 | } | |
1115 | ||
1116 | if (kstrtoint(value, base, &_res)) | |
1117 | ret = -EINVAL; | |
1118 | kfree(value); | |
1119 | *res = _res << shift_left_factor; | |
1120 | return ret; | |
c7eea6f7 DC |
1121 | } |
1122 | ||
92cf7d36 PR |
1123 | static inline void |
1124 | xfs_fs_warn_deprecated( | |
1125 | struct fs_context *fc, | |
1126 | struct fs_parameter *param, | |
1127 | uint64_t flag, | |
1128 | bool value) | |
1129 | { | |
1130 | /* Don't print the warning if reconfiguring and current mount point | |
1131 | * already had the flag set | |
1132 | */ | |
1133 | if ((fc->purpose & FS_CONTEXT_FOR_RECONFIGURE) && | |
1134 | !!(XFS_M(fc->root->d_sb)->m_flags & flag) == value) | |
1135 | return; | |
1136 | xfs_warn(fc->s_fs_info, "%s mount option is deprecated.", param->key); | |
1137 | } | |
1138 | ||
9909c4aa | 1139 | /* |
8757c38f IK |
1140 | * Set mount state from a mount option. |
1141 | * | |
1142 | * NOTE: mp->m_super is NULL here! | |
9909c4aa | 1143 | */ |
8757c38f | 1144 | static int |
1e5c39df | 1145 | xfs_fs_parse_param( |
8757c38f IK |
1146 | struct fs_context *fc, |
1147 | struct fs_parameter *param) | |
1da177e4 | 1148 | { |
0f98b4ec | 1149 | struct xfs_mount *parsing_mp = fc->s_fs_info; |
8757c38f IK |
1150 | struct fs_parse_result result; |
1151 | int size = 0; | |
1152 | int opt; | |
9909c4aa | 1153 | |
d7167b14 | 1154 | opt = fs_parse(fc, xfs_fs_parameters, param, &result); |
8757c38f IK |
1155 | if (opt < 0) |
1156 | return opt; | |
1da177e4 | 1157 | |
8757c38f IK |
1158 | switch (opt) { |
1159 | case Opt_logbufs: | |
0f98b4ec | 1160 | parsing_mp->m_logbufs = result.uint_32; |
8757c38f IK |
1161 | return 0; |
1162 | case Opt_logbsize: | |
0f98b4ec | 1163 | if (suffix_kstrtoint(param->string, 10, &parsing_mp->m_logbsize)) |
8757c38f IK |
1164 | return -EINVAL; |
1165 | return 0; | |
1166 | case Opt_logdev: | |
0f98b4ec PR |
1167 | kfree(parsing_mp->m_logname); |
1168 | parsing_mp->m_logname = kstrdup(param->string, GFP_KERNEL); | |
1169 | if (!parsing_mp->m_logname) | |
8757c38f IK |
1170 | return -ENOMEM; |
1171 | return 0; | |
1172 | case Opt_rtdev: | |
0f98b4ec PR |
1173 | kfree(parsing_mp->m_rtname); |
1174 | parsing_mp->m_rtname = kstrdup(param->string, GFP_KERNEL); | |
1175 | if (!parsing_mp->m_rtname) | |
8757c38f IK |
1176 | return -ENOMEM; |
1177 | return 0; | |
1178 | case Opt_allocsize: | |
1179 | if (suffix_kstrtoint(param->string, 10, &size)) | |
1180 | return -EINVAL; | |
0f98b4ec PR |
1181 | parsing_mp->m_allocsize_log = ffs(size) - 1; |
1182 | parsing_mp->m_flags |= XFS_MOUNT_ALLOCSIZE; | |
8757c38f IK |
1183 | return 0; |
1184 | case Opt_grpid: | |
1185 | case Opt_bsdgroups: | |
0f98b4ec | 1186 | parsing_mp->m_flags |= XFS_MOUNT_GRPID; |
8757c38f IK |
1187 | return 0; |
1188 | case Opt_nogrpid: | |
1189 | case Opt_sysvgroups: | |
0f98b4ec | 1190 | parsing_mp->m_flags &= ~XFS_MOUNT_GRPID; |
8757c38f IK |
1191 | return 0; |
1192 | case Opt_wsync: | |
0f98b4ec | 1193 | parsing_mp->m_flags |= XFS_MOUNT_WSYNC; |
8757c38f IK |
1194 | return 0; |
1195 | case Opt_norecovery: | |
0f98b4ec | 1196 | parsing_mp->m_flags |= XFS_MOUNT_NORECOVERY; |
8757c38f IK |
1197 | return 0; |
1198 | case Opt_noalign: | |
0f98b4ec | 1199 | parsing_mp->m_flags |= XFS_MOUNT_NOALIGN; |
8757c38f IK |
1200 | return 0; |
1201 | case Opt_swalloc: | |
0f98b4ec | 1202 | parsing_mp->m_flags |= XFS_MOUNT_SWALLOC; |
8757c38f IK |
1203 | return 0; |
1204 | case Opt_sunit: | |
0f98b4ec | 1205 | parsing_mp->m_dalign = result.uint_32; |
8757c38f IK |
1206 | return 0; |
1207 | case Opt_swidth: | |
0f98b4ec | 1208 | parsing_mp->m_swidth = result.uint_32; |
8757c38f IK |
1209 | return 0; |
1210 | case Opt_inode32: | |
0f98b4ec | 1211 | parsing_mp->m_flags |= XFS_MOUNT_SMALL_INUMS; |
8757c38f IK |
1212 | return 0; |
1213 | case Opt_inode64: | |
0f98b4ec | 1214 | parsing_mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS; |
8757c38f IK |
1215 | return 0; |
1216 | case Opt_nouuid: | |
0f98b4ec | 1217 | parsing_mp->m_flags |= XFS_MOUNT_NOUUID; |
8757c38f | 1218 | return 0; |
8757c38f | 1219 | case Opt_largeio: |
0f98b4ec | 1220 | parsing_mp->m_flags |= XFS_MOUNT_LARGEIO; |
8757c38f IK |
1221 | return 0; |
1222 | case Opt_nolargeio: | |
0f98b4ec | 1223 | parsing_mp->m_flags &= ~XFS_MOUNT_LARGEIO; |
8757c38f | 1224 | return 0; |
8757c38f | 1225 | case Opt_filestreams: |
0f98b4ec | 1226 | parsing_mp->m_flags |= XFS_MOUNT_FILESTREAMS; |
8757c38f IK |
1227 | return 0; |
1228 | case Opt_noquota: | |
0f98b4ec PR |
1229 | parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT; |
1230 | parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD; | |
1231 | parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE; | |
8757c38f IK |
1232 | return 0; |
1233 | case Opt_quota: | |
1234 | case Opt_uquota: | |
1235 | case Opt_usrquota: | |
0f98b4ec | 1236 | parsing_mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE | |
8757c38f IK |
1237 | XFS_UQUOTA_ENFD); |
1238 | return 0; | |
1239 | case Opt_qnoenforce: | |
1240 | case Opt_uqnoenforce: | |
0f98b4ec PR |
1241 | parsing_mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE); |
1242 | parsing_mp->m_qflags &= ~XFS_UQUOTA_ENFD; | |
8757c38f IK |
1243 | return 0; |
1244 | case Opt_pquota: | |
1245 | case Opt_prjquota: | |
0f98b4ec | 1246 | parsing_mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE | |
8757c38f IK |
1247 | XFS_PQUOTA_ENFD); |
1248 | return 0; | |
1249 | case Opt_pqnoenforce: | |
0f98b4ec PR |
1250 | parsing_mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE); |
1251 | parsing_mp->m_qflags &= ~XFS_PQUOTA_ENFD; | |
8757c38f IK |
1252 | return 0; |
1253 | case Opt_gquota: | |
1254 | case Opt_grpquota: | |
0f98b4ec | 1255 | parsing_mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE | |
8757c38f IK |
1256 | XFS_GQUOTA_ENFD); |
1257 | return 0; | |
1258 | case Opt_gqnoenforce: | |
0f98b4ec PR |
1259 | parsing_mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE); |
1260 | parsing_mp->m_qflags &= ~XFS_GQUOTA_ENFD; | |
8757c38f IK |
1261 | return 0; |
1262 | case Opt_discard: | |
0f98b4ec | 1263 | parsing_mp->m_flags |= XFS_MOUNT_DISCARD; |
8757c38f IK |
1264 | return 0; |
1265 | case Opt_nodiscard: | |
0f98b4ec | 1266 | parsing_mp->m_flags &= ~XFS_MOUNT_DISCARD; |
8757c38f IK |
1267 | return 0; |
1268 | #ifdef CONFIG_FS_DAX | |
1269 | case Opt_dax: | |
0f98b4ec | 1270 | xfs_mount_set_dax_mode(parsing_mp, XFS_DAX_ALWAYS); |
8d6c3446 IW |
1271 | return 0; |
1272 | case Opt_dax_enum: | |
0f98b4ec | 1273 | xfs_mount_set_dax_mode(parsing_mp, result.uint_32); |
8757c38f IK |
1274 | return 0; |
1275 | #endif | |
c23c393e PR |
1276 | /* Following mount options will be removed in September 2025 */ |
1277 | case Opt_ikeep: | |
92cf7d36 | 1278 | xfs_fs_warn_deprecated(fc, param, XFS_MOUNT_IKEEP, true); |
0f98b4ec | 1279 | parsing_mp->m_flags |= XFS_MOUNT_IKEEP; |
c23c393e PR |
1280 | return 0; |
1281 | case Opt_noikeep: | |
92cf7d36 | 1282 | xfs_fs_warn_deprecated(fc, param, XFS_MOUNT_IKEEP, false); |
0f98b4ec | 1283 | parsing_mp->m_flags &= ~XFS_MOUNT_IKEEP; |
c23c393e PR |
1284 | return 0; |
1285 | case Opt_attr2: | |
92cf7d36 | 1286 | xfs_fs_warn_deprecated(fc, param, XFS_MOUNT_ATTR2, true); |
0f98b4ec | 1287 | parsing_mp->m_flags |= XFS_MOUNT_ATTR2; |
c23c393e PR |
1288 | return 0; |
1289 | case Opt_noattr2: | |
92cf7d36 | 1290 | xfs_fs_warn_deprecated(fc, param, XFS_MOUNT_NOATTR2, true); |
0f98b4ec PR |
1291 | parsing_mp->m_flags &= ~XFS_MOUNT_ATTR2; |
1292 | parsing_mp->m_flags |= XFS_MOUNT_NOATTR2; | |
c23c393e | 1293 | return 0; |
8757c38f | 1294 | default: |
0f98b4ec | 1295 | xfs_warn(parsing_mp, "unknown mount option [%s].", param->key); |
8757c38f IK |
1296 | return -EINVAL; |
1297 | } | |
d5db0f97 | 1298 | |
d5db0f97 ES |
1299 | return 0; |
1300 | } | |
1301 | ||
8757c38f | 1302 | static int |
1e5c39df | 1303 | xfs_fs_validate_params( |
f8f15e42 CH |
1304 | struct xfs_mount *mp) |
1305 | { | |
d3eaace8 | 1306 | /* |
8757c38f | 1307 | * no recovery flag requires a read-only mount |
d3eaace8 | 1308 | */ |
8757c38f IK |
1309 | if ((mp->m_flags & XFS_MOUNT_NORECOVERY) && |
1310 | !(mp->m_flags & XFS_MOUNT_RDONLY)) { | |
1311 | xfs_warn(mp, "no-recovery mounts must be read-only."); | |
2451337d | 1312 | return -EINVAL; |
d3eaace8 DC |
1313 | } |
1314 | ||
8757c38f IK |
1315 | if ((mp->m_flags & XFS_MOUNT_NOALIGN) && |
1316 | (mp->m_dalign || mp->m_swidth)) { | |
4f10700a | 1317 | xfs_warn(mp, |
8757c38f IK |
1318 | "sunit and swidth options incompatible with the noalign option"); |
1319 | return -EINVAL; | |
f8f15e42 CH |
1320 | } |
1321 | ||
8757c38f IK |
1322 | if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) { |
1323 | xfs_warn(mp, "quota support not available in this kernel."); | |
2451337d | 1324 | return -EINVAL; |
d892d586 CS |
1325 | } |
1326 | ||
8757c38f IK |
1327 | if ((mp->m_dalign && !mp->m_swidth) || |
1328 | (!mp->m_dalign && mp->m_swidth)) { | |
1329 | xfs_warn(mp, "sunit and swidth must be specified together"); | |
1330 | return -EINVAL; | |
1331 | } | |
5681ca40 | 1332 | |
8757c38f IK |
1333 | if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) { |
1334 | xfs_warn(mp, | |
1335 | "stripe width (%d) must be a multiple of the stripe unit (%d)", | |
1336 | mp->m_swidth, mp->m_dalign); | |
1337 | return -EINVAL; | |
1338 | } | |
5681ca40 | 1339 | |
8757c38f IK |
1340 | if (mp->m_logbufs != -1 && |
1341 | mp->m_logbufs != 0 && | |
1342 | (mp->m_logbufs < XLOG_MIN_ICLOGS || | |
1343 | mp->m_logbufs > XLOG_MAX_ICLOGS)) { | |
1344 | xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]", | |
1345 | mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS); | |
1346 | return -EINVAL; | |
1347 | } | |
5681ca40 | 1348 | |
8757c38f IK |
1349 | if (mp->m_logbsize != -1 && |
1350 | mp->m_logbsize != 0 && | |
1351 | (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE || | |
1352 | mp->m_logbsize > XLOG_MAX_RECORD_BSIZE || | |
1353 | !is_power_of_2(mp->m_logbsize))) { | |
1354 | xfs_warn(mp, | |
1355 | "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]", | |
1356 | mp->m_logbsize); | |
1357 | return -EINVAL; | |
1358 | } | |
5681ca40 | 1359 | |
8757c38f IK |
1360 | if ((mp->m_flags & XFS_MOUNT_ALLOCSIZE) && |
1361 | (mp->m_allocsize_log > XFS_MAX_IO_LOG || | |
1362 | mp->m_allocsize_log < XFS_MIN_IO_LOG)) { | |
1363 | xfs_warn(mp, "invalid log iosize: %d [not %d-%d]", | |
1364 | mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG); | |
1365 | return -EINVAL; | |
1366 | } | |
9fe82b8c | 1367 | |
5681ca40 | 1368 | return 0; |
72c44e35 | 1369 | } |
74394496 | 1370 | |
73e5fff9 | 1371 | static int |
1e5c39df | 1372 | xfs_fs_fill_super( |
72c44e35 | 1373 | struct super_block *sb, |
73e5fff9 | 1374 | struct fs_context *fc) |
72c44e35 | 1375 | { |
73e5fff9 | 1376 | struct xfs_mount *mp = sb->s_fs_info; |
72c44e35 | 1377 | struct inode *root; |
0279c71f | 1378 | int flags = 0, error; |
72c44e35 | 1379 | |
7c89fcb2 | 1380 | mp->m_super = sb; |
1da177e4 | 1381 | |
1e5c39df | 1382 | error = xfs_fs_validate_params(mp); |
745f6919 | 1383 | if (error) |
e1d3d218 | 1384 | goto out_free_names; |
1da177e4 LT |
1385 | |
1386 | sb_min_blocksize(sb, BBSIZE); | |
0ec58516 | 1387 | sb->s_xattr = xfs_xattr_handlers; |
a50cd269 | 1388 | sb->s_export_op = &xfs_export_operations; |
fcafb71b | 1389 | #ifdef CONFIG_XFS_QUOTA |
a50cd269 | 1390 | sb->s_qcop = &xfs_quotactl_operations; |
17ef4fdd | 1391 | sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ; |
fcafb71b | 1392 | #endif |
a50cd269 | 1393 | sb->s_op = &xfs_super_operations; |
1da177e4 | 1394 | |
dae5cd81 DC |
1395 | /* |
1396 | * Delay mount work if the debug hook is set. This is debug | |
1397 | * instrumention to coordinate simulation of xfs mount failures with | |
1398 | * VFS superblock operations | |
1399 | */ | |
1400 | if (xfs_globals.mount_delay) { | |
1401 | xfs_notice(mp, "Delaying mount for %d seconds.", | |
1402 | xfs_globals.mount_delay); | |
1403 | msleep(xfs_globals.mount_delay * 1000); | |
1404 | } | |
1405 | ||
73e5fff9 | 1406 | if (fc->sb_flags & SB_SILENT) |
f8f15e42 CH |
1407 | flags |= XFS_MFSI_QUIET; |
1408 | ||
9d565ffa | 1409 | error = xfs_open_devices(mp); |
19f354d4 | 1410 | if (error) |
e1d3d218 | 1411 | goto out_free_names; |
f8f15e42 | 1412 | |
2451337d | 1413 | error = xfs_init_mount_workqueues(mp); |
61ba35de CH |
1414 | if (error) |
1415 | goto out_close_devices; | |
c962fb79 | 1416 | |
5681ca40 | 1417 | error = xfs_init_percpu_counters(mp); |
aa6bf01d CH |
1418 | if (error) |
1419 | goto out_destroy_workqueues; | |
1420 | ||
225e4635 BD |
1421 | /* Allocate stats memory before we do operations that might use it */ |
1422 | mp->m_stats.xs_stats = alloc_percpu(struct xfsstats); | |
1423 | if (!mp->m_stats.xs_stats) { | |
f9d460b3 | 1424 | error = -ENOMEM; |
225e4635 BD |
1425 | goto out_destroy_counters; |
1426 | } | |
1427 | ||
f8f15e42 CH |
1428 | error = xfs_readsb(mp, flags); |
1429 | if (error) | |
225e4635 | 1430 | goto out_free_stats; |
9d565ffa CH |
1431 | |
1432 | error = xfs_finish_flags(mp); | |
f8f15e42 | 1433 | if (error) |
effa2eda | 1434 | goto out_free_sb; |
f8f15e42 | 1435 | |
e34b562c | 1436 | error = xfs_setup_devices(mp); |
19f354d4 | 1437 | if (error) |
effa2eda | 1438 | goto out_free_sb; |
f8f15e42 | 1439 | |
b96cb835 DW |
1440 | /* V4 support is undergoing deprecation. */ |
1441 | if (!xfs_sb_version_hascrc(&mp->m_sb)) { | |
1442 | #ifdef CONFIG_XFS_SUPPORT_V4 | |
1443 | xfs_warn_once(mp, | |
1444 | "Deprecated V4 format (crc=0) will not be supported after September 2030."); | |
1445 | #else | |
1446 | xfs_warn(mp, | |
1447 | "Deprecated V4 format (crc=0) not supported by kernel."); | |
1448 | error = -EINVAL; | |
1449 | goto out_free_sb; | |
1450 | #endif | |
1451 | } | |
1452 | ||
80c720b8 DW |
1453 | /* Filesystem claims it needs repair, so refuse the mount. */ |
1454 | if (xfs_sb_version_needsrepair(&mp->m_sb)) { | |
1455 | xfs_warn(mp, "Filesystem needs repair. Please run xfs_repair."); | |
1456 | error = -EFSCORRUPTED; | |
1457 | goto out_free_sb; | |
1458 | } | |
1459 | ||
3945ae03 DW |
1460 | /* |
1461 | * Don't touch the filesystem if a user tool thinks it owns the primary | |
1462 | * superblock. mkfs doesn't clear the flag from secondary supers, so | |
1463 | * we don't check them at all. | |
1464 | */ | |
1465 | if (mp->m_sb.sb_inprogress) { | |
1466 | xfs_warn(mp, "Offline file system operation in progress!"); | |
1467 | error = -EFSCORRUPTED; | |
1468 | goto out_free_sb; | |
1469 | } | |
1470 | ||
1471 | /* | |
1472 | * Until this is fixed only page-sized or smaller data blocks work. | |
1473 | */ | |
1474 | if (mp->m_sb.sb_blocksize > PAGE_SIZE) { | |
1475 | xfs_warn(mp, | |
1476 | "File system with blocksize %d bytes. " | |
1477 | "Only pagesize (%ld) or less will currently work.", | |
1478 | mp->m_sb.sb_blocksize, PAGE_SIZE); | |
1479 | error = -ENOSYS; | |
1480 | goto out_free_sb; | |
1481 | } | |
1482 | ||
1483 | /* Ensure this filesystem fits in the page cache limits */ | |
1484 | if (xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_dblocks) || | |
1485 | xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_rblocks)) { | |
1486 | xfs_warn(mp, | |
1487 | "file system too large to be mounted on this system."); | |
1488 | error = -EFBIG; | |
1489 | goto out_free_sb; | |
1490 | } | |
1491 | ||
932befe3 DW |
1492 | /* |
1493 | * XFS block mappings use 54 bits to store the logical block offset. | |
1494 | * This should suffice to handle the maximum file size that the VFS | |
1495 | * supports (currently 2^63 bytes on 64-bit and ULONG_MAX << PAGE_SHIFT | |
1496 | * bytes on 32-bit), but as XFS and VFS have gotten the s_maxbytes | |
1497 | * calculation wrong on 32-bit kernels in the past, we'll add a WARN_ON | |
1498 | * to check this assertion. | |
1499 | * | |
1500 | * Avoid integer overflow by comparing the maximum bmbt offset to the | |
1501 | * maximum pagecache offset in units of fs blocks. | |
1502 | */ | |
33005fd0 | 1503 | if (!xfs_verify_fileoff(mp, XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE))) { |
932befe3 DW |
1504 | xfs_warn(mp, |
1505 | "MAX_LFS_FILESIZE block offset (%llu) exceeds extent map maximum (%llu)!", | |
1506 | XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE), | |
1507 | XFS_MAX_FILEOFF); | |
1508 | error = -EINVAL; | |
1509 | goto out_free_sb; | |
1510 | } | |
1511 | ||
f8f15e42 CH |
1512 | error = xfs_filestream_mount(mp); |
1513 | if (error) | |
effa2eda | 1514 | goto out_free_sb; |
f8f15e42 | 1515 | |
704b2907 DC |
1516 | /* |
1517 | * we must configure the block size in the superblock before we run the | |
1518 | * full mount process as the mount process can lookup and cache inodes. | |
704b2907 | 1519 | */ |
dddde68b | 1520 | sb->s_magic = XFS_SUPER_MAGIC; |
4ca488eb CH |
1521 | sb->s_blocksize = mp->m_sb.sb_blocksize; |
1522 | sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1; | |
932befe3 | 1523 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
8de52778 | 1524 | sb->s_max_links = XFS_MAXLINK; |
1da177e4 | 1525 | sb->s_time_gran = 1; |
f93e5436 DW |
1526 | if (xfs_sb_version_hasbigtime(&mp->m_sb)) { |
1527 | sb->s_time_min = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MIN); | |
1528 | sb->s_time_max = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MAX); | |
1529 | } else { | |
1530 | sb->s_time_min = XFS_LEGACY_TIME_MIN; | |
1531 | sb->s_time_max = XFS_LEGACY_TIME_MAX; | |
1532 | } | |
06dbf82b | 1533 | trace_xfs_inode_timestamp_range(mp, sb->s_time_min, sb->s_time_max); |
adfb5fb4 CH |
1534 | sb->s_iflags |= SB_I_CGROUPWB; |
1535 | ||
1da177e4 LT |
1536 | set_posix_acl_flag(sb); |
1537 | ||
dc037ad7 DC |
1538 | /* version 5 superblocks support inode version counters. */ |
1539 | if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5) | |
357fdad0 | 1540 | sb->s_flags |= SB_I_VERSION; |
dc037ad7 | 1541 | |
f93e5436 DW |
1542 | if (xfs_sb_version_hasbigtime(&mp->m_sb)) |
1543 | xfs_warn(mp, | |
1544 | "EXPERIMENTAL big timestamp feature in use. Use at your own risk!"); | |
1545 | ||
606723d9 | 1546 | if (mp->m_flags & XFS_MOUNT_DAX_ALWAYS) { |
80660f20 | 1547 | bool rtdev_is_dax = false, datadev_is_dax; |
ba23cba9 | 1548 | |
cbe4dab1 | 1549 | xfs_warn(mp, |
1e937cdd TK |
1550 | "DAX enabled. Warning: EXPERIMENTAL, use at your own risk"); |
1551 | ||
80660f20 DJ |
1552 | datadev_is_dax = bdev_dax_supported(mp->m_ddev_targp->bt_bdev, |
1553 | sb->s_blocksize); | |
ba23cba9 | 1554 | if (mp->m_rtdev_targp) |
80660f20 DJ |
1555 | rtdev_is_dax = bdev_dax_supported( |
1556 | mp->m_rtdev_targp->bt_bdev, sb->s_blocksize); | |
1557 | if (!rtdev_is_dax && !datadev_is_dax) { | |
cbe4dab1 | 1558 | xfs_alert(mp, |
1e937cdd | 1559 | "DAX unsupported by block device. Turning off DAX."); |
8d6c3446 | 1560 | xfs_mount_set_dax_mode(mp, XFS_DAX_NEVER); |
cbe4dab1 | 1561 | } |
b6e03c10 | 1562 | if (xfs_sb_version_hasreflink(&mp->m_sb)) { |
e54b5bf9 | 1563 | xfs_alert(mp, |
1e369b0e | 1564 | "DAX and reflink cannot be used together!"); |
b6e03c10 DW |
1565 | error = -EINVAL; |
1566 | goto out_filestream_unmount; | |
1567 | } | |
cbe4dab1 DC |
1568 | } |
1569 | ||
1e6fa688 KN |
1570 | if (mp->m_flags & XFS_MOUNT_DISCARD) { |
1571 | struct request_queue *q = bdev_get_queue(sb->s_bdev); | |
1572 | ||
1573 | if (!blk_queue_discard(q)) { | |
1574 | xfs_warn(mp, "mounting with \"discard\" option, but " | |
1575 | "the device does not support discard"); | |
1576 | mp->m_flags &= ~XFS_MOUNT_DISCARD; | |
1577 | } | |
1578 | } | |
1579 | ||
66ae56a5 CH |
1580 | if (xfs_sb_version_hasreflink(&mp->m_sb)) { |
1581 | if (mp->m_sb.sb_rblocks) { | |
1582 | xfs_alert(mp, | |
c14632dd | 1583 | "reflink not compatible with realtime device!"); |
66ae56a5 CH |
1584 | error = -EINVAL; |
1585 | goto out_filestream_unmount; | |
1586 | } | |
1587 | ||
1588 | if (xfs_globals.always_cow) { | |
1589 | xfs_info(mp, "using DEBUG-only always_cow mode."); | |
1590 | mp->m_always_cow = true; | |
1591 | } | |
c14632dd DW |
1592 | } |
1593 | ||
76883f79 | 1594 | if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks) { |
1c0607ac | 1595 | xfs_alert(mp, |
76883f79 DW |
1596 | "reverse mapping btree not compatible with realtime device!"); |
1597 | error = -EINVAL; | |
1598 | goto out_filestream_unmount; | |
738f57c1 | 1599 | } |
1c0607ac | 1600 | |
2a39946c DW |
1601 | if (xfs_sb_version_hasinobtcounts(&mp->m_sb)) |
1602 | xfs_warn(mp, | |
1603 | "EXPERIMENTAL inode btree counters feature in use. Use at your own risk!"); | |
1604 | ||
8a00ebe4 | 1605 | error = xfs_mountfs(mp); |
2bcf6e97 | 1606 | if (error) |
7e18530b | 1607 | goto out_filestream_unmount; |
704b2907 | 1608 | |
01651646 | 1609 | root = igrab(VFS_I(mp->m_rootip)); |
f3dcc13f | 1610 | if (!root) { |
2451337d | 1611 | error = -ENOENT; |
8a00ebe4 | 1612 | goto out_unmount; |
cbc89dcf | 1613 | } |
48fde701 | 1614 | sb->s_root = d_make_root(root); |
f3dcc13f | 1615 | if (!sb->s_root) { |
2451337d | 1616 | error = -ENOMEM; |
8a00ebe4 | 1617 | goto out_unmount; |
1da177e4 | 1618 | } |
74394496 | 1619 | |
1da177e4 | 1620 | return 0; |
33c7a2bc | 1621 | |
7e18530b | 1622 | out_filestream_unmount: |
120226c1 | 1623 | xfs_filestream_unmount(mp); |
effa2eda CH |
1624 | out_free_sb: |
1625 | xfs_freesb(mp); | |
225e4635 BD |
1626 | out_free_stats: |
1627 | free_percpu(mp->m_stats.xs_stats); | |
9d565ffa | 1628 | out_destroy_counters: |
5681ca40 | 1629 | xfs_destroy_percpu_counters(mp); |
225e4635 | 1630 | out_destroy_workqueues: |
aa6bf01d | 1631 | xfs_destroy_mount_workqueues(mp); |
61ba35de | 1632 | out_close_devices: |
19f354d4 | 1633 | xfs_close_devices(mp); |
e1d3d218 | 1634 | out_free_names: |
c9fbd7bb | 1635 | sb->s_fs_info = NULL; |
a943f372 | 1636 | xfs_mount_free(mp); |
2451337d | 1637 | return error; |
f8f15e42 | 1638 | |
2bcf6e97 | 1639 | out_unmount: |
e48ad316 | 1640 | xfs_filestream_unmount(mp); |
19f354d4 | 1641 | xfs_unmountfs(mp); |
6203300e | 1642 | goto out_free_sb; |
1da177e4 LT |
1643 | } |
1644 | ||
73e5fff9 | 1645 | static int |
1e5c39df | 1646 | xfs_fs_get_tree( |
73e5fff9 IK |
1647 | struct fs_context *fc) |
1648 | { | |
1e5c39df | 1649 | return get_tree_bdev(fc, xfs_fs_fill_super); |
73e5fff9 IK |
1650 | } |
1651 | ||
63cd1e9b IK |
1652 | static int |
1653 | xfs_remount_rw( | |
1654 | struct xfs_mount *mp) | |
1655 | { | |
1656 | struct xfs_sb *sbp = &mp->m_sb; | |
1657 | int error; | |
1658 | ||
1659 | if (mp->m_flags & XFS_MOUNT_NORECOVERY) { | |
1660 | xfs_warn(mp, | |
1661 | "ro->rw transition prohibited on norecovery mount"); | |
1662 | return -EINVAL; | |
1663 | } | |
1664 | ||
1665 | if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 && | |
1666 | xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) { | |
1667 | xfs_warn(mp, | |
1668 | "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem", | |
1669 | (sbp->sb_features_ro_compat & | |
1670 | XFS_SB_FEAT_RO_COMPAT_UNKNOWN)); | |
1671 | return -EINVAL; | |
1672 | } | |
1673 | ||
1674 | mp->m_flags &= ~XFS_MOUNT_RDONLY; | |
1675 | ||
1676 | /* | |
1677 | * If this is the first remount to writeable state we might have some | |
1678 | * superblock changes to update. | |
1679 | */ | |
1680 | if (mp->m_update_sb) { | |
1681 | error = xfs_sync_sb(mp, false); | |
1682 | if (error) { | |
1683 | xfs_warn(mp, "failed to write sb changes"); | |
1684 | return error; | |
1685 | } | |
1686 | mp->m_update_sb = false; | |
1687 | } | |
1688 | ||
1689 | /* | |
1690 | * Fill out the reserve pool if it is empty. Use the stashed value if | |
1691 | * it is non-zero, otherwise go with the default. | |
1692 | */ | |
1693 | xfs_restore_resvblks(mp); | |
1694 | xfs_log_work_queue(mp); | |
1695 | ||
1696 | /* Recover any CoW blocks that never got remapped. */ | |
1697 | error = xfs_reflink_recover_cow(mp); | |
1698 | if (error) { | |
1699 | xfs_err(mp, | |
1700 | "Error %d recovering leftover CoW allocations.", error); | |
7f6bcf7c | 1701 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); |
63cd1e9b IK |
1702 | return error; |
1703 | } | |
c9a6526f | 1704 | xfs_blockgc_start(mp); |
63cd1e9b IK |
1705 | |
1706 | /* Create the per-AG metadata reservation pool .*/ | |
1707 | error = xfs_fs_reserve_ag_blocks(mp); | |
1708 | if (error && error != -ENOSPC) | |
1709 | return error; | |
1710 | ||
1711 | return 0; | |
1712 | } | |
1713 | ||
1714 | static int | |
1715 | xfs_remount_ro( | |
1716 | struct xfs_mount *mp) | |
1717 | { | |
1718 | int error; | |
1719 | ||
1720 | /* | |
1721 | * Cancel background eofb scanning so it cannot race with the final | |
1722 | * log force+buftarg wait and deadlock the remount. | |
1723 | */ | |
c9a6526f | 1724 | xfs_blockgc_stop(mp); |
63cd1e9b IK |
1725 | |
1726 | /* Get rid of any leftover CoW reservations... */ | |
b943c0cd | 1727 | error = xfs_blockgc_free_space(mp, NULL); |
63cd1e9b IK |
1728 | if (error) { |
1729 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); | |
1730 | return error; | |
1731 | } | |
1732 | ||
1733 | /* Free the per-AG metadata reservation pool. */ | |
1734 | error = xfs_fs_unreserve_ag_blocks(mp); | |
1735 | if (error) { | |
1736 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); | |
1737 | return error; | |
1738 | } | |
1739 | ||
1740 | /* | |
1741 | * Before we sync the metadata, we need to free up the reserve block | |
1742 | * pool so that the used block count in the superblock on disk is | |
1743 | * correct at the end of the remount. Stash the current* reserve pool | |
1744 | * size so that if we get remounted rw, we can return it to the same | |
1745 | * size. | |
1746 | */ | |
1747 | xfs_save_resvblks(mp); | |
1748 | ||
ea2064da | 1749 | xfs_log_clean(mp); |
63cd1e9b IK |
1750 | mp->m_flags |= XFS_MOUNT_RDONLY; |
1751 | ||
1752 | return 0; | |
1753 | } | |
1754 | ||
1755 | /* | |
1756 | * Logically we would return an error here to prevent users from believing | |
1757 | * they might have changed mount options using remount which can't be changed. | |
1758 | * | |
1759 | * But unfortunately mount(8) adds all options from mtab and fstab to the mount | |
1760 | * arguments in some cases so we can't blindly reject options, but have to | |
1761 | * check for each specified option if it actually differs from the currently | |
1762 | * set option and only reject it if that's the case. | |
1763 | * | |
1764 | * Until that is implemented we return success for every remount request, and | |
1765 | * silently ignore all options that we can't actually change. | |
1766 | */ | |
1767 | static int | |
1e5c39df | 1768 | xfs_fs_reconfigure( |
63cd1e9b IK |
1769 | struct fs_context *fc) |
1770 | { | |
1771 | struct xfs_mount *mp = XFS_M(fc->root->d_sb); | |
1772 | struct xfs_mount *new_mp = fc->s_fs_info; | |
1773 | xfs_sb_t *sbp = &mp->m_sb; | |
1774 | int flags = fc->sb_flags; | |
1775 | int error; | |
1776 | ||
4750a171 ES |
1777 | /* version 5 superblocks always support version counters. */ |
1778 | if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5) | |
1779 | fc->sb_flags |= SB_I_VERSION; | |
1780 | ||
1e5c39df | 1781 | error = xfs_fs_validate_params(new_mp); |
63cd1e9b IK |
1782 | if (error) |
1783 | return error; | |
1784 | ||
1785 | sync_filesystem(mp->m_super); | |
1786 | ||
1787 | /* inode32 -> inode64 */ | |
1788 | if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && | |
1789 | !(new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) { | |
1790 | mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS; | |
1791 | mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount); | |
1792 | } | |
1793 | ||
1794 | /* inode64 -> inode32 */ | |
1795 | if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS) && | |
1796 | (new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) { | |
1797 | mp->m_flags |= XFS_MOUNT_SMALL_INUMS; | |
1798 | mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount); | |
1799 | } | |
1800 | ||
1801 | /* ro -> rw */ | |
1802 | if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(flags & SB_RDONLY)) { | |
1803 | error = xfs_remount_rw(mp); | |
1804 | if (error) | |
1805 | return error; | |
1806 | } | |
1807 | ||
1808 | /* rw -> ro */ | |
1809 | if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (flags & SB_RDONLY)) { | |
1810 | error = xfs_remount_ro(mp); | |
1811 | if (error) | |
1812 | return error; | |
1813 | } | |
1814 | ||
1815 | return 0; | |
1816 | } | |
1817 | ||
1e5c39df | 1818 | static void xfs_fs_free( |
73e5fff9 IK |
1819 | struct fs_context *fc) |
1820 | { | |
1821 | struct xfs_mount *mp = fc->s_fs_info; | |
1822 | ||
1823 | /* | |
1824 | * mp is stored in the fs_context when it is initialized. | |
1825 | * mp is transferred to the superblock on a successful mount, | |
1826 | * but if an error occurs before the transfer we have to free | |
1827 | * it here. | |
1828 | */ | |
1829 | if (mp) | |
1830 | xfs_mount_free(mp); | |
1831 | } | |
1832 | ||
1833 | static const struct fs_context_operations xfs_context_ops = { | |
1e5c39df DW |
1834 | .parse_param = xfs_fs_parse_param, |
1835 | .get_tree = xfs_fs_get_tree, | |
1836 | .reconfigure = xfs_fs_reconfigure, | |
1837 | .free = xfs_fs_free, | |
73e5fff9 IK |
1838 | }; |
1839 | ||
1840 | static int xfs_init_fs_context( | |
1841 | struct fs_context *fc) | |
1842 | { | |
1843 | struct xfs_mount *mp; | |
1844 | ||
50f83009 | 1845 | mp = kmem_alloc(sizeof(struct xfs_mount), KM_ZERO); |
73e5fff9 IK |
1846 | if (!mp) |
1847 | return -ENOMEM; | |
1848 | ||
50f83009 IK |
1849 | spin_lock_init(&mp->m_sb_lock); |
1850 | spin_lock_init(&mp->m_agirotor_lock); | |
1851 | INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC); | |
1852 | spin_lock_init(&mp->m_perag_lock); | |
1853 | mutex_init(&mp->m_growlock); | |
f0f7a674 | 1854 | INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker); |
50f83009 | 1855 | INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker); |
50f83009 IK |
1856 | mp->m_kobj.kobject.kset = xfs_kset; |
1857 | /* | |
1858 | * We don't create the finobt per-ag space reservation until after log | |
1859 | * recovery, so we must set this to true so that an ifree transaction | |
1860 | * started during log recovery will not depend on space reservations | |
1861 | * for finobt expansion. | |
1862 | */ | |
1863 | mp->m_finobt_nores = true; | |
1864 | ||
73e5fff9 IK |
1865 | /* |
1866 | * These can be overridden by the mount option parsing. | |
1867 | */ | |
1868 | mp->m_logbufs = -1; | |
1869 | mp->m_logbsize = -1; | |
1870 | mp->m_allocsize_log = 16; /* 64k */ | |
1871 | ||
1872 | /* | |
1873 | * Copy binary VFS mount flags we are interested in. | |
1874 | */ | |
1875 | if (fc->sb_flags & SB_RDONLY) | |
1876 | mp->m_flags |= XFS_MOUNT_RDONLY; | |
1877 | if (fc->sb_flags & SB_DIRSYNC) | |
1878 | mp->m_flags |= XFS_MOUNT_DIRSYNC; | |
1879 | if (fc->sb_flags & SB_SYNCHRONOUS) | |
1880 | mp->m_flags |= XFS_MOUNT_WSYNC; | |
1881 | ||
1882 | fc->s_fs_info = mp; | |
1883 | fc->ops = &xfs_context_ops; | |
1884 | ||
1885 | return 0; | |
1886 | } | |
1887 | ||
5085b607 | 1888 | static struct file_system_type xfs_fs_type = { |
1da177e4 LT |
1889 | .owner = THIS_MODULE, |
1890 | .name = "xfs", | |
73e5fff9 | 1891 | .init_fs_context = xfs_init_fs_context, |
d7167b14 | 1892 | .parameters = xfs_fs_parameters, |
1da177e4 | 1893 | .kill_sb = kill_block_super, |
f736d93d | 1894 | .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, |
1da177e4 | 1895 | }; |
7f78e035 | 1896 | MODULE_ALIAS_FS("xfs"); |
1da177e4 | 1897 | |
9f8868ff CH |
1898 | STATIC int __init |
1899 | xfs_init_zones(void) | |
1900 | { | |
b1231760 CM |
1901 | xfs_log_ticket_zone = kmem_cache_create("xfs_log_ticket", |
1902 | sizeof(struct xlog_ticket), | |
1903 | 0, 0, NULL); | |
9f8868ff | 1904 | if (!xfs_log_ticket_zone) |
598ecfba | 1905 | goto out; |
9f8868ff | 1906 | |
b1231760 CM |
1907 | xfs_bmap_free_item_zone = kmem_cache_create("xfs_bmap_free_item", |
1908 | sizeof(struct xfs_extent_free_item), | |
1909 | 0, 0, NULL); | |
9f8868ff CH |
1910 | if (!xfs_bmap_free_item_zone) |
1911 | goto out_destroy_log_ticket_zone; | |
bf904248 | 1912 | |
b1231760 CM |
1913 | xfs_btree_cur_zone = kmem_cache_create("xfs_btree_cur", |
1914 | sizeof(struct xfs_btree_cur), | |
1915 | 0, 0, NULL); | |
9f8868ff CH |
1916 | if (!xfs_btree_cur_zone) |
1917 | goto out_destroy_bmap_free_item_zone; | |
1918 | ||
b1231760 CM |
1919 | xfs_da_state_zone = kmem_cache_create("xfs_da_state", |
1920 | sizeof(struct xfs_da_state), | |
1921 | 0, 0, NULL); | |
9f8868ff CH |
1922 | if (!xfs_da_state_zone) |
1923 | goto out_destroy_btree_cur_zone; | |
1924 | ||
b1231760 CM |
1925 | xfs_ifork_zone = kmem_cache_create("xfs_ifork", |
1926 | sizeof(struct xfs_ifork), | |
1927 | 0, 0, NULL); | |
9f8868ff | 1928 | if (!xfs_ifork_zone) |
1d9025e5 | 1929 | goto out_destroy_da_state_zone; |
9f8868ff | 1930 | |
25dfa65f | 1931 | xfs_trans_zone = kmem_cache_create("xfs_trans", |
b1231760 CM |
1932 | sizeof(struct xfs_trans), |
1933 | 0, 0, NULL); | |
9f8868ff CH |
1934 | if (!xfs_trans_zone) |
1935 | goto out_destroy_ifork_zone; | |
1936 | ||
e98c414f | 1937 | |
9f8868ff CH |
1938 | /* |
1939 | * The size of the zone allocated buf log item is the maximum | |
1940 | * size possible under XFS. This wastes a little bit of memory, | |
1941 | * but it is much faster. | |
1942 | */ | |
b1231760 CM |
1943 | xfs_buf_item_zone = kmem_cache_create("xfs_buf_item", |
1944 | sizeof(struct xfs_buf_log_item), | |
1945 | 0, 0, NULL); | |
9f8868ff | 1946 | if (!xfs_buf_item_zone) |
e6631f85 | 1947 | goto out_destroy_trans_zone; |
9f8868ff | 1948 | |
b1231760 CM |
1949 | xfs_efd_zone = kmem_cache_create("xfs_efd_item", |
1950 | (sizeof(struct xfs_efd_log_item) + | |
1951 | (XFS_EFD_MAX_FAST_EXTENTS - 1) * | |
1952 | sizeof(struct xfs_extent)), | |
1953 | 0, 0, NULL); | |
9f8868ff CH |
1954 | if (!xfs_efd_zone) |
1955 | goto out_destroy_buf_item_zone; | |
1956 | ||
b1231760 CM |
1957 | xfs_efi_zone = kmem_cache_create("xfs_efi_item", |
1958 | (sizeof(struct xfs_efi_log_item) + | |
1959 | (XFS_EFI_MAX_FAST_EXTENTS - 1) * | |
1960 | sizeof(struct xfs_extent)), | |
1961 | 0, 0, NULL); | |
9f8868ff CH |
1962 | if (!xfs_efi_zone) |
1963 | goto out_destroy_efd_zone; | |
1964 | ||
b1231760 CM |
1965 | xfs_inode_zone = kmem_cache_create("xfs_inode", |
1966 | sizeof(struct xfs_inode), 0, | |
1967 | (SLAB_HWCACHE_ALIGN | | |
1968 | SLAB_RECLAIM_ACCOUNT | | |
1969 | SLAB_MEM_SPREAD | SLAB_ACCOUNT), | |
1970 | xfs_fs_inode_init_once); | |
9f8868ff CH |
1971 | if (!xfs_inode_zone) |
1972 | goto out_destroy_efi_zone; | |
1973 | ||
b1231760 CM |
1974 | xfs_ili_zone = kmem_cache_create("xfs_ili", |
1975 | sizeof(struct xfs_inode_log_item), 0, | |
d59eadae DC |
1976 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, |
1977 | NULL); | |
9f8868ff CH |
1978 | if (!xfs_ili_zone) |
1979 | goto out_destroy_inode_zone; | |
b1231760 CM |
1980 | |
1981 | xfs_icreate_zone = kmem_cache_create("xfs_icr", | |
1982 | sizeof(struct xfs_icreate_item), | |
1983 | 0, 0, NULL); | |
3ebe7d2d DC |
1984 | if (!xfs_icreate_zone) |
1985 | goto out_destroy_ili_zone; | |
9f8868ff | 1986 | |
b1231760 CM |
1987 | xfs_rud_zone = kmem_cache_create("xfs_rud_item", |
1988 | sizeof(struct xfs_rud_log_item), | |
1989 | 0, 0, NULL); | |
5880f2d7 DW |
1990 | if (!xfs_rud_zone) |
1991 | goto out_destroy_icreate_zone; | |
1992 | ||
b1231760 | 1993 | xfs_rui_zone = kmem_cache_create("xfs_rui_item", |
cd00158c | 1994 | xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS), |
b1231760 | 1995 | 0, 0, NULL); |
5880f2d7 DW |
1996 | if (!xfs_rui_zone) |
1997 | goto out_destroy_rud_zone; | |
1998 | ||
b1231760 CM |
1999 | xfs_cud_zone = kmem_cache_create("xfs_cud_item", |
2000 | sizeof(struct xfs_cud_log_item), | |
2001 | 0, 0, NULL); | |
baf4bcac DW |
2002 | if (!xfs_cud_zone) |
2003 | goto out_destroy_rui_zone; | |
2004 | ||
b1231760 | 2005 | xfs_cui_zone = kmem_cache_create("xfs_cui_item", |
baf4bcac | 2006 | xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS), |
b1231760 | 2007 | 0, 0, NULL); |
baf4bcac DW |
2008 | if (!xfs_cui_zone) |
2009 | goto out_destroy_cud_zone; | |
2010 | ||
b1231760 CM |
2011 | xfs_bud_zone = kmem_cache_create("xfs_bud_item", |
2012 | sizeof(struct xfs_bud_log_item), | |
2013 | 0, 0, NULL); | |
6413a014 DW |
2014 | if (!xfs_bud_zone) |
2015 | goto out_destroy_cui_zone; | |
2016 | ||
b1231760 | 2017 | xfs_bui_zone = kmem_cache_create("xfs_bui_item", |
6413a014 | 2018 | xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS), |
b1231760 | 2019 | 0, 0, NULL); |
6413a014 DW |
2020 | if (!xfs_bui_zone) |
2021 | goto out_destroy_bud_zone; | |
2022 | ||
9f8868ff CH |
2023 | return 0; |
2024 | ||
6413a014 | 2025 | out_destroy_bud_zone: |
aaf54eb8 | 2026 | kmem_cache_destroy(xfs_bud_zone); |
6413a014 | 2027 | out_destroy_cui_zone: |
aaf54eb8 | 2028 | kmem_cache_destroy(xfs_cui_zone); |
baf4bcac | 2029 | out_destroy_cud_zone: |
aaf54eb8 | 2030 | kmem_cache_destroy(xfs_cud_zone); |
baf4bcac | 2031 | out_destroy_rui_zone: |
aaf54eb8 | 2032 | kmem_cache_destroy(xfs_rui_zone); |
5880f2d7 | 2033 | out_destroy_rud_zone: |
aaf54eb8 | 2034 | kmem_cache_destroy(xfs_rud_zone); |
5880f2d7 | 2035 | out_destroy_icreate_zone: |
aaf54eb8 | 2036 | kmem_cache_destroy(xfs_icreate_zone); |
3ebe7d2d | 2037 | out_destroy_ili_zone: |
aaf54eb8 | 2038 | kmem_cache_destroy(xfs_ili_zone); |
9f8868ff | 2039 | out_destroy_inode_zone: |
aaf54eb8 | 2040 | kmem_cache_destroy(xfs_inode_zone); |
9f8868ff | 2041 | out_destroy_efi_zone: |
aaf54eb8 | 2042 | kmem_cache_destroy(xfs_efi_zone); |
9f8868ff | 2043 | out_destroy_efd_zone: |
aaf54eb8 | 2044 | kmem_cache_destroy(xfs_efd_zone); |
9f8868ff | 2045 | out_destroy_buf_item_zone: |
aaf54eb8 | 2046 | kmem_cache_destroy(xfs_buf_item_zone); |
9f8868ff | 2047 | out_destroy_trans_zone: |
aaf54eb8 | 2048 | kmem_cache_destroy(xfs_trans_zone); |
9f8868ff | 2049 | out_destroy_ifork_zone: |
aaf54eb8 | 2050 | kmem_cache_destroy(xfs_ifork_zone); |
9f8868ff | 2051 | out_destroy_da_state_zone: |
aaf54eb8 | 2052 | kmem_cache_destroy(xfs_da_state_zone); |
9f8868ff | 2053 | out_destroy_btree_cur_zone: |
aaf54eb8 | 2054 | kmem_cache_destroy(xfs_btree_cur_zone); |
9f8868ff | 2055 | out_destroy_bmap_free_item_zone: |
aaf54eb8 | 2056 | kmem_cache_destroy(xfs_bmap_free_item_zone); |
9f8868ff | 2057 | out_destroy_log_ticket_zone: |
aaf54eb8 | 2058 | kmem_cache_destroy(xfs_log_ticket_zone); |
9f8868ff CH |
2059 | out: |
2060 | return -ENOMEM; | |
2061 | } | |
2062 | ||
2063 | STATIC void | |
2064 | xfs_destroy_zones(void) | |
2065 | { | |
8c0a8537 KS |
2066 | /* |
2067 | * Make sure all delayed rcu free are flushed before we | |
2068 | * destroy caches. | |
2069 | */ | |
2070 | rcu_barrier(); | |
aaf54eb8 CM |
2071 | kmem_cache_destroy(xfs_bui_zone); |
2072 | kmem_cache_destroy(xfs_bud_zone); | |
2073 | kmem_cache_destroy(xfs_cui_zone); | |
2074 | kmem_cache_destroy(xfs_cud_zone); | |
2075 | kmem_cache_destroy(xfs_rui_zone); | |
2076 | kmem_cache_destroy(xfs_rud_zone); | |
2077 | kmem_cache_destroy(xfs_icreate_zone); | |
2078 | kmem_cache_destroy(xfs_ili_zone); | |
2079 | kmem_cache_destroy(xfs_inode_zone); | |
2080 | kmem_cache_destroy(xfs_efi_zone); | |
2081 | kmem_cache_destroy(xfs_efd_zone); | |
2082 | kmem_cache_destroy(xfs_buf_item_zone); | |
2083 | kmem_cache_destroy(xfs_trans_zone); | |
2084 | kmem_cache_destroy(xfs_ifork_zone); | |
2085 | kmem_cache_destroy(xfs_da_state_zone); | |
2086 | kmem_cache_destroy(xfs_btree_cur_zone); | |
2087 | kmem_cache_destroy(xfs_bmap_free_item_zone); | |
2088 | kmem_cache_destroy(xfs_log_ticket_zone); | |
9f8868ff | 2089 | } |
1da177e4 | 2090 | |
0bf6a5bd DC |
2091 | STATIC int __init |
2092 | xfs_init_workqueues(void) | |
2093 | { | |
c999a223 DC |
2094 | /* |
2095 | * The allocation workqueue can be used in memory reclaim situations | |
2096 | * (writepage path), and parallelism is only limited by the number of | |
2097 | * AGs in all the filesystems mounted. Hence use the default large | |
2098 | * max_active value for this workqueue. | |
2099 | */ | |
8018ec08 | 2100 | xfs_alloc_wq = alloc_workqueue("xfsalloc", |
05a302a1 | 2101 | XFS_WQFLAGS(WQ_MEM_RECLAIM | WQ_FREEZABLE), 0); |
c999a223 | 2102 | if (!xfs_alloc_wq) |
5889608d | 2103 | return -ENOMEM; |
c999a223 | 2104 | |
05a302a1 DW |
2105 | xfs_discard_wq = alloc_workqueue("xfsdiscard", XFS_WQFLAGS(WQ_UNBOUND), |
2106 | 0); | |
4560e78f CH |
2107 | if (!xfs_discard_wq) |
2108 | goto out_free_alloc_wq; | |
2109 | ||
0bf6a5bd | 2110 | return 0; |
4560e78f CH |
2111 | out_free_alloc_wq: |
2112 | destroy_workqueue(xfs_alloc_wq); | |
2113 | return -ENOMEM; | |
0bf6a5bd DC |
2114 | } |
2115 | ||
39411f81 | 2116 | STATIC void |
0bf6a5bd DC |
2117 | xfs_destroy_workqueues(void) |
2118 | { | |
4560e78f | 2119 | destroy_workqueue(xfs_discard_wq); |
c999a223 | 2120 | destroy_workqueue(xfs_alloc_wq); |
0bf6a5bd DC |
2121 | } |
2122 | ||
1da177e4 | 2123 | STATIC int __init |
9f8868ff | 2124 | init_xfs_fs(void) |
1da177e4 LT |
2125 | { |
2126 | int error; | |
1da177e4 | 2127 | |
30cbc591 DW |
2128 | xfs_check_ondisk_structs(); |
2129 | ||
65795910 CH |
2130 | printk(KERN_INFO XFS_VERSION_STRING " with " |
2131 | XFS_BUILD_OPTIONS " enabled\n"); | |
1da177e4 | 2132 | |
9f8868ff | 2133 | xfs_dir_startup(); |
1da177e4 | 2134 | |
8758280f | 2135 | error = xfs_init_zones(); |
9f8868ff CH |
2136 | if (error) |
2137 | goto out; | |
2138 | ||
0bf6a5bd | 2139 | error = xfs_init_workqueues(); |
9f8868ff | 2140 | if (error) |
0b1b213f | 2141 | goto out_destroy_zones; |
9f8868ff | 2142 | |
0bf6a5bd DC |
2143 | error = xfs_mru_cache_init(); |
2144 | if (error) | |
2145 | goto out_destroy_wq; | |
2146 | ||
ce8e922c | 2147 | error = xfs_buf_init(); |
9f8868ff | 2148 | if (error) |
1919adda | 2149 | goto out_mru_cache_uninit; |
9f8868ff CH |
2150 | |
2151 | error = xfs_init_procfs(); | |
2152 | if (error) | |
2153 | goto out_buf_terminate; | |
2154 | ||
2155 | error = xfs_sysctl_register(); | |
2156 | if (error) | |
2157 | goto out_cleanup_procfs; | |
1da177e4 | 2158 | |
3d871226 BF |
2159 | xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj); |
2160 | if (!xfs_kset) { | |
2161 | error = -ENOMEM; | |
bb230c12 | 2162 | goto out_sysctl_unregister; |
3d871226 BF |
2163 | } |
2164 | ||
80529c45 BD |
2165 | xfsstats.xs_kobj.kobject.kset = xfs_kset; |
2166 | ||
2167 | xfsstats.xs_stats = alloc_percpu(struct xfsstats); | |
2168 | if (!xfsstats.xs_stats) { | |
2169 | error = -ENOMEM; | |
2170 | goto out_kset_unregister; | |
2171 | } | |
2172 | ||
2173 | error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL, | |
bb230c12 BD |
2174 | "stats"); |
2175 | if (error) | |
80529c45 | 2176 | goto out_free_stats; |
bb230c12 | 2177 | |
65b65735 BF |
2178 | #ifdef DEBUG |
2179 | xfs_dbg_kobj.kobject.kset = xfs_kset; | |
2180 | error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug"); | |
a05931ce | 2181 | if (error) |
bb230c12 | 2182 | goto out_remove_stats_kobj; |
65b65735 BF |
2183 | #endif |
2184 | ||
2185 | error = xfs_qm_init(); | |
2186 | if (error) | |
bb230c12 | 2187 | goto out_remove_dbg_kobj; |
1da177e4 LT |
2188 | |
2189 | error = register_filesystem(&xfs_fs_type); | |
2190 | if (error) | |
a05931ce | 2191 | goto out_qm_exit; |
1da177e4 LT |
2192 | return 0; |
2193 | ||
a05931ce CH |
2194 | out_qm_exit: |
2195 | xfs_qm_exit(); | |
bb230c12 | 2196 | out_remove_dbg_kobj: |
65b65735 BF |
2197 | #ifdef DEBUG |
2198 | xfs_sysfs_del(&xfs_dbg_kobj); | |
bb230c12 | 2199 | out_remove_stats_kobj: |
65b65735 | 2200 | #endif |
80529c45 BD |
2201 | xfs_sysfs_del(&xfsstats.xs_kobj); |
2202 | out_free_stats: | |
2203 | free_percpu(xfsstats.xs_stats); | |
bb230c12 | 2204 | out_kset_unregister: |
3d871226 | 2205 | kset_unregister(xfs_kset); |
9f8868ff CH |
2206 | out_sysctl_unregister: |
2207 | xfs_sysctl_unregister(); | |
2208 | out_cleanup_procfs: | |
2209 | xfs_cleanup_procfs(); | |
2210 | out_buf_terminate: | |
ce8e922c | 2211 | xfs_buf_terminate(); |
9f8868ff CH |
2212 | out_mru_cache_uninit: |
2213 | xfs_mru_cache_uninit(); | |
0bf6a5bd DC |
2214 | out_destroy_wq: |
2215 | xfs_destroy_workqueues(); | |
9f8868ff | 2216 | out_destroy_zones: |
8758280f | 2217 | xfs_destroy_zones(); |
9f8868ff | 2218 | out: |
1da177e4 LT |
2219 | return error; |
2220 | } | |
2221 | ||
2222 | STATIC void __exit | |
9f8868ff | 2223 | exit_xfs_fs(void) |
1da177e4 | 2224 | { |
a05931ce | 2225 | xfs_qm_exit(); |
1da177e4 | 2226 | unregister_filesystem(&xfs_fs_type); |
65b65735 BF |
2227 | #ifdef DEBUG |
2228 | xfs_sysfs_del(&xfs_dbg_kobj); | |
2229 | #endif | |
80529c45 BD |
2230 | xfs_sysfs_del(&xfsstats.xs_kobj); |
2231 | free_percpu(xfsstats.xs_stats); | |
3d871226 | 2232 | kset_unregister(xfs_kset); |
9f8868ff CH |
2233 | xfs_sysctl_unregister(); |
2234 | xfs_cleanup_procfs(); | |
ce8e922c | 2235 | xfs_buf_terminate(); |
9f8868ff | 2236 | xfs_mru_cache_uninit(); |
0bf6a5bd | 2237 | xfs_destroy_workqueues(); |
8758280f | 2238 | xfs_destroy_zones(); |
af3b6382 | 2239 | xfs_uuid_table_free(); |
1da177e4 LT |
2240 | } |
2241 | ||
2242 | module_init(init_xfs_fs); | |
2243 | module_exit(exit_xfs_fs); | |
2244 | ||
2245 | MODULE_AUTHOR("Silicon Graphics, Inc."); | |
2246 | MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled"); | |
2247 | MODULE_LICENSE("GPL"); |