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