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