]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
a805bad5 | 2 | * Copyright (c) 2000-2006 Silicon Graphics, Inc. |
7b718769 | 3 | * All Rights Reserved. |
1da177e4 | 4 | * |
7b718769 NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
1da177e4 | 13 | * |
7b718769 NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1da177e4 | 17 | */ |
0b1b213f | 18 | |
1da177e4 | 19 | #include "xfs.h" |
70a9883c | 20 | #include "xfs_shared.h" |
6ca1c906 | 21 | #include "xfs_format.h" |
239880ef DC |
22 | #include "xfs_log_format.h" |
23 | #include "xfs_trans_resv.h" | |
1da177e4 | 24 | #include "xfs_sb.h" |
1da177e4 | 25 | #include "xfs_mount.h" |
57062787 | 26 | #include "xfs_da_format.h" |
1da177e4 | 27 | #include "xfs_inode.h" |
a844f451 | 28 | #include "xfs_btree.h" |
1da177e4 | 29 | #include "xfs_bmap.h" |
a4fbe6ab | 30 | #include "xfs_alloc.h" |
1da177e4 | 31 | #include "xfs_error.h" |
9909c4aa | 32 | #include "xfs_fsops.h" |
239880ef | 33 | #include "xfs_trans.h" |
1da177e4 | 34 | #include "xfs_buf_item.h" |
239880ef | 35 | #include "xfs_log.h" |
a67d7c5f | 36 | #include "xfs_log_priv.h" |
9f8868ff | 37 | #include "xfs_da_btree.h" |
2b9ab5ab | 38 | #include "xfs_dir2.h" |
9f8868ff CH |
39 | #include "xfs_extfree_item.h" |
40 | #include "xfs_mru_cache.h" | |
41 | #include "xfs_inode_item.h" | |
6d8b79cf | 42 | #include "xfs_icache.h" |
0b1b213f | 43 | #include "xfs_trace.h" |
3ebe7d2d | 44 | #include "xfs_icreate_item.h" |
a4fbe6ab DC |
45 | #include "xfs_filestream.h" |
46 | #include "xfs_quota.h" | |
65b65735 | 47 | #include "xfs_sysfs.h" |
30cbc591 | 48 | #include "xfs_ondisk.h" |
5880f2d7 | 49 | #include "xfs_rmap_item.h" |
baf4bcac | 50 | #include "xfs_refcount_item.h" |
1da177e4 LT |
51 | |
52 | #include <linux/namei.h> | |
53 | #include <linux/init.h> | |
5a0e3ad6 | 54 | #include <linux/slab.h> |
1da177e4 | 55 | #include <linux/mount.h> |
0829c360 | 56 | #include <linux/mempool.h> |
1da177e4 | 57 | #include <linux/writeback.h> |
4df08c52 | 58 | #include <linux/kthread.h> |
7dfb7103 | 59 | #include <linux/freezer.h> |
62a877e3 | 60 | #include <linux/parser.h> |
1da177e4 | 61 | |
b87221de | 62 | static const struct super_operations xfs_super_operations; |
0e51a8e1 | 63 | struct bio_set *xfs_ioend_bioset; |
65b65735 | 64 | |
e3aed1a0 | 65 | static struct kset *xfs_kset; /* top-level xfs sysfs dir */ |
65b65735 BF |
66 | #ifdef DEBUG |
67 | static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */ | |
68 | #endif | |
1da177e4 | 69 | |
62a877e3 CH |
70 | /* |
71 | * Table driven mount option parser. | |
62a877e3 CH |
72 | */ |
73 | enum { | |
2e74af0e ES |
74 | Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev, Opt_biosize, |
75 | Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid, | |
76 | Opt_mtpt, Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups, | |
77 | Opt_allocsize, Opt_norecovery, Opt_barrier, Opt_nobarrier, | |
78 | Opt_inode64, Opt_inode32, Opt_ikeep, Opt_noikeep, | |
79 | Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2, Opt_filestreams, | |
80 | Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota, Opt_prjquota, | |
81 | Opt_uquota, Opt_gquota, Opt_pquota, | |
82 | Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce, | |
83 | Opt_discard, Opt_nodiscard, Opt_dax, Opt_err, | |
62a877e3 CH |
84 | }; |
85 | ||
a447c093 | 86 | static const match_table_t tokens = { |
2e74af0e ES |
87 | {Opt_logbufs, "logbufs=%u"}, /* number of XFS log buffers */ |
88 | {Opt_logbsize, "logbsize=%s"}, /* size of XFS log buffers */ | |
89 | {Opt_logdev, "logdev=%s"}, /* log device */ | |
90 | {Opt_rtdev, "rtdev=%s"}, /* realtime I/O device */ | |
91 | {Opt_biosize, "biosize=%u"}, /* log2 of preferred buffered io size */ | |
92 | {Opt_wsync, "wsync"}, /* safe-mode nfs compatible mount */ | |
93 | {Opt_noalign, "noalign"}, /* turn off stripe alignment */ | |
94 | {Opt_swalloc, "swalloc"}, /* turn on stripe width allocation */ | |
95 | {Opt_sunit, "sunit=%u"}, /* data volume stripe unit */ | |
96 | {Opt_swidth, "swidth=%u"}, /* data volume stripe width */ | |
97 | {Opt_nouuid, "nouuid"}, /* ignore filesystem UUID */ | |
98 | {Opt_mtpt, "mtpt"}, /* filesystem mount point */ | |
99 | {Opt_grpid, "grpid"}, /* group-ID from parent directory */ | |
100 | {Opt_nogrpid, "nogrpid"}, /* group-ID from current process */ | |
101 | {Opt_bsdgroups, "bsdgroups"}, /* group-ID from parent directory */ | |
102 | {Opt_sysvgroups,"sysvgroups"}, /* group-ID from current process */ | |
103 | {Opt_allocsize, "allocsize=%s"},/* preferred allocation size */ | |
104 | {Opt_norecovery,"norecovery"}, /* don't run XFS recovery */ | |
105 | {Opt_barrier, "barrier"}, /* use writer barriers for log write and | |
106 | * unwritten extent conversion */ | |
107 | {Opt_nobarrier, "nobarrier"}, /* .. disable */ | |
108 | {Opt_inode64, "inode64"}, /* inodes can be allocated anywhere */ | |
109 | {Opt_inode32, "inode32"}, /* inode allocation limited to | |
110 | * XFS_MAXINUMBER_32 */ | |
111 | {Opt_ikeep, "ikeep"}, /* do not free empty inode clusters */ | |
112 | {Opt_noikeep, "noikeep"}, /* free empty inode clusters */ | |
113 | {Opt_largeio, "largeio"}, /* report large I/O sizes in stat() */ | |
114 | {Opt_nolargeio, "nolargeio"}, /* do not report large I/O sizes | |
115 | * in stat(). */ | |
116 | {Opt_attr2, "attr2"}, /* do use attr2 attribute format */ | |
117 | {Opt_noattr2, "noattr2"}, /* do not use attr2 attribute format */ | |
118 | {Opt_filestreams,"filestreams"},/* use filestreams allocator */ | |
119 | {Opt_quota, "quota"}, /* disk quotas (user) */ | |
120 | {Opt_noquota, "noquota"}, /* no quotas */ | |
121 | {Opt_usrquota, "usrquota"}, /* user quota enabled */ | |
122 | {Opt_grpquota, "grpquota"}, /* group quota enabled */ | |
123 | {Opt_prjquota, "prjquota"}, /* project quota enabled */ | |
124 | {Opt_uquota, "uquota"}, /* user quota (IRIX variant) */ | |
125 | {Opt_gquota, "gquota"}, /* group quota (IRIX variant) */ | |
126 | {Opt_pquota, "pquota"}, /* project quota (IRIX variant) */ | |
127 | {Opt_uqnoenforce,"uqnoenforce"},/* user quota limit enforcement */ | |
128 | {Opt_gqnoenforce,"gqnoenforce"},/* group quota limit enforcement */ | |
129 | {Opt_pqnoenforce,"pqnoenforce"},/* project quota limit enforcement */ | |
130 | {Opt_qnoenforce, "qnoenforce"}, /* same as uqnoenforce */ | |
131 | {Opt_discard, "discard"}, /* Discard unused blocks */ | |
132 | {Opt_nodiscard, "nodiscard"}, /* Do not discard unused blocks */ | |
133 | ||
134 | {Opt_dax, "dax"}, /* Enable direct access to bdev pages */ | |
135 | {Opt_err, NULL}, | |
62a877e3 CH |
136 | }; |
137 | ||
138 | ||
a841b64d | 139 | STATIC int |
2e74af0e | 140 | suffix_kstrtoint(const substring_t *s, unsigned int base, int *res) |
a67d7c5f | 141 | { |
a17164e5 | 142 | int last, shift_left_factor = 0, _res; |
2e74af0e ES |
143 | char *value; |
144 | int ret = 0; | |
145 | ||
146 | value = match_strdup(s); | |
147 | if (!value) | |
148 | return -ENOMEM; | |
a67d7c5f DC |
149 | |
150 | last = strlen(value) - 1; | |
151 | if (value[last] == 'K' || value[last] == 'k') { | |
152 | shift_left_factor = 10; | |
153 | value[last] = '\0'; | |
154 | } | |
155 | if (value[last] == 'M' || value[last] == 'm') { | |
156 | shift_left_factor = 20; | |
157 | value[last] = '\0'; | |
158 | } | |
159 | if (value[last] == 'G' || value[last] == 'g') { | |
160 | shift_left_factor = 30; | |
161 | value[last] = '\0'; | |
162 | } | |
163 | ||
2e74af0e ES |
164 | if (kstrtoint(value, base, &_res)) |
165 | ret = -EINVAL; | |
166 | kfree(value); | |
a17164e5 | 167 | *res = _res << shift_left_factor; |
2e74af0e | 168 | return ret; |
a67d7c5f DC |
169 | } |
170 | ||
9d565ffa CH |
171 | /* |
172 | * This function fills in xfs_mount_t fields based on mount args. | |
173 | * Note: the superblock has _not_ yet been read in. | |
174 | * | |
175 | * Note that this function leaks the various device name allocations on | |
176 | * failure. The caller takes care of them. | |
a08ee40a ES |
177 | * |
178 | * *sb is const because this is also used to test options on the remount | |
179 | * path, and we don't want this to have any side effects at remount time. | |
180 | * Today this function does not change *sb, but just to future-proof... | |
9d565ffa | 181 | */ |
a67d7c5f DC |
182 | STATIC int |
183 | xfs_parseargs( | |
184 | struct xfs_mount *mp, | |
288699fe | 185 | char *options) |
a67d7c5f | 186 | { |
a08ee40a | 187 | const struct super_block *sb = mp->m_super; |
2e74af0e ES |
188 | char *p; |
189 | substring_t args[MAX_OPT_ARGS]; | |
9d565ffa CH |
190 | int dsunit = 0; |
191 | int dswidth = 0; | |
192 | int iosize = 0; | |
a5687787 | 193 | __uint8_t iosizelog = 0; |
9d565ffa | 194 | |
4f10700a DC |
195 | /* |
196 | * set up the mount name first so all the errors will refer to the | |
197 | * correct device. | |
198 | */ | |
199 | mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL); | |
200 | if (!mp->m_fsname) | |
2451337d | 201 | return -ENOMEM; |
4f10700a DC |
202 | mp->m_fsname_len = strlen(mp->m_fsname) + 1; |
203 | ||
9d565ffa CH |
204 | /* |
205 | * Copy binary VFS mount flags we are interested in. | |
206 | */ | |
207 | if (sb->s_flags & MS_RDONLY) | |
208 | mp->m_flags |= XFS_MOUNT_RDONLY; | |
209 | if (sb->s_flags & MS_DIRSYNC) | |
210 | mp->m_flags |= XFS_MOUNT_DIRSYNC; | |
211 | if (sb->s_flags & MS_SYNCHRONOUS) | |
212 | mp->m_flags |= XFS_MOUNT_WSYNC; | |
213 | ||
214 | /* | |
215 | * Set some default flags that could be cleared by the mount option | |
216 | * parsing. | |
217 | */ | |
218 | mp->m_flags |= XFS_MOUNT_BARRIER; | |
219 | mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE; | |
a67d7c5f | 220 | |
9d565ffa CH |
221 | /* |
222 | * These can be overridden by the mount option parsing. | |
223 | */ | |
224 | mp->m_logbufs = -1; | |
225 | mp->m_logbsize = -1; | |
a67d7c5f DC |
226 | |
227 | if (!options) | |
228 | goto done; | |
229 | ||
2e74af0e ES |
230 | while ((p = strsep(&options, ",")) != NULL) { |
231 | int token; | |
232 | ||
233 | if (!*p) | |
a67d7c5f | 234 | continue; |
a67d7c5f | 235 | |
2e74af0e ES |
236 | token = match_token(p, tokens, args); |
237 | switch (token) { | |
238 | case Opt_logbufs: | |
239 | if (match_int(args, &mp->m_logbufs)) | |
2451337d | 240 | return -EINVAL; |
2e74af0e ES |
241 | break; |
242 | case Opt_logbsize: | |
243 | if (suffix_kstrtoint(args, 10, &mp->m_logbsize)) | |
2451337d | 244 | return -EINVAL; |
2e74af0e ES |
245 | break; |
246 | case Opt_logdev: | |
247 | mp->m_logname = match_strdup(args); | |
9d565ffa | 248 | if (!mp->m_logname) |
2451337d | 249 | return -ENOMEM; |
2e74af0e ES |
250 | break; |
251 | case Opt_mtpt: | |
252 | xfs_warn(mp, "%s option not allowed on this system", p); | |
2451337d | 253 | return -EINVAL; |
2e74af0e ES |
254 | case Opt_rtdev: |
255 | mp->m_rtname = match_strdup(args); | |
9d565ffa | 256 | if (!mp->m_rtname) |
2451337d | 257 | return -ENOMEM; |
2e74af0e ES |
258 | break; |
259 | case Opt_allocsize: | |
260 | case Opt_biosize: | |
261 | if (suffix_kstrtoint(args, 10, &iosize)) | |
2451337d | 262 | return -EINVAL; |
9d565ffa | 263 | iosizelog = ffs(iosize) - 1; |
2e74af0e ES |
264 | break; |
265 | case Opt_grpid: | |
266 | case Opt_bsdgroups: | |
a67d7c5f | 267 | mp->m_flags |= XFS_MOUNT_GRPID; |
2e74af0e ES |
268 | break; |
269 | case Opt_nogrpid: | |
270 | case Opt_sysvgroups: | |
a67d7c5f | 271 | mp->m_flags &= ~XFS_MOUNT_GRPID; |
2e74af0e ES |
272 | break; |
273 | case Opt_wsync: | |
9d565ffa | 274 | mp->m_flags |= XFS_MOUNT_WSYNC; |
2e74af0e ES |
275 | break; |
276 | case Opt_norecovery: | |
9d565ffa | 277 | mp->m_flags |= XFS_MOUNT_NORECOVERY; |
2e74af0e ES |
278 | break; |
279 | case Opt_noalign: | |
9d565ffa | 280 | mp->m_flags |= XFS_MOUNT_NOALIGN; |
2e74af0e ES |
281 | break; |
282 | case Opt_swalloc: | |
9d565ffa | 283 | mp->m_flags |= XFS_MOUNT_SWALLOC; |
2e74af0e ES |
284 | break; |
285 | case Opt_sunit: | |
286 | if (match_int(args, &dsunit)) | |
2451337d | 287 | return -EINVAL; |
2e74af0e ES |
288 | break; |
289 | case Opt_swidth: | |
290 | if (match_int(args, &dswidth)) | |
2451337d | 291 | return -EINVAL; |
2e74af0e ES |
292 | break; |
293 | case Opt_inode32: | |
08bf5404 | 294 | mp->m_flags |= XFS_MOUNT_SMALL_INUMS; |
2e74af0e ES |
295 | break; |
296 | case Opt_inode64: | |
9d565ffa | 297 | mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS; |
2e74af0e ES |
298 | break; |
299 | case Opt_nouuid: | |
9d565ffa | 300 | mp->m_flags |= XFS_MOUNT_NOUUID; |
2e74af0e ES |
301 | break; |
302 | case Opt_barrier: | |
9d565ffa | 303 | mp->m_flags |= XFS_MOUNT_BARRIER; |
2e74af0e ES |
304 | break; |
305 | case Opt_nobarrier: | |
9d565ffa | 306 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
2e74af0e ES |
307 | break; |
308 | case Opt_ikeep: | |
9d565ffa | 309 | mp->m_flags |= XFS_MOUNT_IKEEP; |
2e74af0e ES |
310 | break; |
311 | case Opt_noikeep: | |
9d565ffa | 312 | mp->m_flags &= ~XFS_MOUNT_IKEEP; |
2e74af0e ES |
313 | break; |
314 | case Opt_largeio: | |
9d565ffa | 315 | mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE; |
2e74af0e ES |
316 | break; |
317 | case Opt_nolargeio: | |
9d565ffa | 318 | mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE; |
2e74af0e ES |
319 | break; |
320 | case Opt_attr2: | |
9d565ffa | 321 | mp->m_flags |= XFS_MOUNT_ATTR2; |
2e74af0e ES |
322 | break; |
323 | case Opt_noattr2: | |
9d565ffa CH |
324 | mp->m_flags &= ~XFS_MOUNT_ATTR2; |
325 | mp->m_flags |= XFS_MOUNT_NOATTR2; | |
2e74af0e ES |
326 | break; |
327 | case Opt_filestreams: | |
9d565ffa | 328 | mp->m_flags |= XFS_MOUNT_FILESTREAMS; |
2e74af0e ES |
329 | break; |
330 | case Opt_noquota: | |
4177af3a CS |
331 | mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT; |
332 | mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD; | |
333 | mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE; | |
2e74af0e ES |
334 | break; |
335 | case Opt_quota: | |
336 | case Opt_uquota: | |
337 | case Opt_usrquota: | |
9d565ffa CH |
338 | mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE | |
339 | XFS_UQUOTA_ENFD); | |
2e74af0e ES |
340 | break; |
341 | case Opt_qnoenforce: | |
342 | case Opt_uqnoenforce: | |
9d565ffa CH |
343 | mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE); |
344 | mp->m_qflags &= ~XFS_UQUOTA_ENFD; | |
2e74af0e ES |
345 | break; |
346 | case Opt_pquota: | |
347 | case Opt_prjquota: | |
9d565ffa | 348 | mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE | |
83e782e1 | 349 | XFS_PQUOTA_ENFD); |
2e74af0e ES |
350 | break; |
351 | case Opt_pqnoenforce: | |
9d565ffa | 352 | mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE); |
83e782e1 | 353 | mp->m_qflags &= ~XFS_PQUOTA_ENFD; |
ce5c767d | 354 | break; |
2e74af0e ES |
355 | case Opt_gquota: |
356 | case Opt_grpquota: | |
9d565ffa | 357 | mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE | |
83e782e1 | 358 | XFS_GQUOTA_ENFD); |
2e74af0e ES |
359 | break; |
360 | case Opt_gqnoenforce: | |
9d565ffa | 361 | mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE); |
83e782e1 | 362 | mp->m_qflags &= ~XFS_GQUOTA_ENFD; |
2e74af0e ES |
363 | break; |
364 | case Opt_discard: | |
e84661aa | 365 | mp->m_flags |= XFS_MOUNT_DISCARD; |
2e74af0e ES |
366 | break; |
367 | case Opt_nodiscard: | |
e84661aa | 368 | mp->m_flags &= ~XFS_MOUNT_DISCARD; |
2e74af0e | 369 | break; |
cbe4dab1 | 370 | #ifdef CONFIG_FS_DAX |
2e74af0e | 371 | case Opt_dax: |
cbe4dab1 | 372 | mp->m_flags |= XFS_MOUNT_DAX; |
2e74af0e | 373 | break; |
cbe4dab1 | 374 | #endif |
2e74af0e ES |
375 | default: |
376 | xfs_warn(mp, "unknown mount option [%s].", p); | |
2451337d | 377 | return -EINVAL; |
a67d7c5f DC |
378 | } |
379 | } | |
380 | ||
9d565ffa CH |
381 | /* |
382 | * no recovery flag requires a read-only mount | |
383 | */ | |
384 | if ((mp->m_flags & XFS_MOUNT_NORECOVERY) && | |
385 | !(mp->m_flags & XFS_MOUNT_RDONLY)) { | |
4f10700a | 386 | xfs_warn(mp, "no-recovery mounts must be read-only."); |
2451337d | 387 | return -EINVAL; |
a67d7c5f DC |
388 | } |
389 | ||
9d565ffa | 390 | if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) { |
4f10700a DC |
391 | xfs_warn(mp, |
392 | "sunit and swidth options incompatible with the noalign option"); | |
2451337d | 393 | return -EINVAL; |
a67d7c5f DC |
394 | } |
395 | ||
7d095257 CH |
396 | #ifndef CONFIG_XFS_QUOTA |
397 | if (XFS_IS_QUOTA_RUNNING(mp)) { | |
4f10700a | 398 | xfs_warn(mp, "quota support not available in this kernel."); |
2451337d | 399 | return -EINVAL; |
7d095257 CH |
400 | } |
401 | #endif | |
402 | ||
a67d7c5f | 403 | if ((dsunit && !dswidth) || (!dsunit && dswidth)) { |
4f10700a | 404 | xfs_warn(mp, "sunit and swidth must be specified together"); |
2451337d | 405 | return -EINVAL; |
a67d7c5f DC |
406 | } |
407 | ||
408 | if (dsunit && (dswidth % dsunit != 0)) { | |
4f10700a DC |
409 | xfs_warn(mp, |
410 | "stripe width (%d) must be a multiple of the stripe unit (%d)", | |
a67d7c5f | 411 | dswidth, dsunit); |
2451337d | 412 | return -EINVAL; |
a67d7c5f DC |
413 | } |
414 | ||
9d565ffa | 415 | done: |
39a45d84 | 416 | if (dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) { |
9d565ffa CH |
417 | /* |
418 | * At this point the superblock has not been read | |
419 | * in, therefore we do not know the block size. | |
420 | * Before the mount call ends we will convert | |
421 | * these to FSBs. | |
422 | */ | |
39a45d84 JL |
423 | mp->m_dalign = dsunit; |
424 | mp->m_swidth = dswidth; | |
9d565ffa CH |
425 | } |
426 | ||
427 | if (mp->m_logbufs != -1 && | |
428 | mp->m_logbufs != 0 && | |
429 | (mp->m_logbufs < XLOG_MIN_ICLOGS || | |
430 | mp->m_logbufs > XLOG_MAX_ICLOGS)) { | |
4f10700a | 431 | xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]", |
9d565ffa | 432 | mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS); |
2451337d | 433 | return -EINVAL; |
9d565ffa CH |
434 | } |
435 | if (mp->m_logbsize != -1 && | |
436 | mp->m_logbsize != 0 && | |
437 | (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE || | |
438 | mp->m_logbsize > XLOG_MAX_RECORD_BSIZE || | |
439 | !is_power_of_2(mp->m_logbsize))) { | |
4f10700a DC |
440 | xfs_warn(mp, |
441 | "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]", | |
9d565ffa | 442 | mp->m_logbsize); |
2451337d | 443 | return -EINVAL; |
9d565ffa CH |
444 | } |
445 | ||
9d565ffa CH |
446 | if (iosizelog) { |
447 | if (iosizelog > XFS_MAX_IO_LOG || | |
448 | iosizelog < XFS_MIN_IO_LOG) { | |
4f10700a | 449 | xfs_warn(mp, "invalid log iosize: %d [not %d-%d]", |
9d565ffa CH |
450 | iosizelog, XFS_MIN_IO_LOG, |
451 | XFS_MAX_IO_LOG); | |
2451337d | 452 | return -EINVAL; |
9d565ffa CH |
453 | } |
454 | ||
455 | mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE; | |
456 | mp->m_readio_log = iosizelog; | |
457 | mp->m_writeio_log = iosizelog; | |
a67d7c5f DC |
458 | } |
459 | ||
a67d7c5f DC |
460 | return 0; |
461 | } | |
462 | ||
463 | struct proc_xfs_info { | |
cbe4dab1 DC |
464 | uint64_t flag; |
465 | char *str; | |
a67d7c5f DC |
466 | }; |
467 | ||
468 | STATIC int | |
469 | xfs_showargs( | |
470 | struct xfs_mount *mp, | |
471 | struct seq_file *m) | |
472 | { | |
473 | static struct proc_xfs_info xfs_info_set[] = { | |
474 | /* the few simple ones we can get from the mount struct */ | |
2e74af0e ES |
475 | { XFS_MOUNT_IKEEP, ",ikeep" }, |
476 | { XFS_MOUNT_WSYNC, ",wsync" }, | |
477 | { XFS_MOUNT_NOALIGN, ",noalign" }, | |
478 | { XFS_MOUNT_SWALLOC, ",swalloc" }, | |
479 | { XFS_MOUNT_NOUUID, ",nouuid" }, | |
480 | { XFS_MOUNT_NORECOVERY, ",norecovery" }, | |
481 | { XFS_MOUNT_ATTR2, ",attr2" }, | |
482 | { XFS_MOUNT_FILESTREAMS, ",filestreams" }, | |
483 | { XFS_MOUNT_GRPID, ",grpid" }, | |
484 | { XFS_MOUNT_DISCARD, ",discard" }, | |
485 | { XFS_MOUNT_SMALL_INUMS, ",inode32" }, | |
486 | { XFS_MOUNT_DAX, ",dax" }, | |
a67d7c5f DC |
487 | { 0, NULL } |
488 | }; | |
489 | static struct proc_xfs_info xfs_info_unset[] = { | |
490 | /* the few simple ones we can get from the mount struct */ | |
2e74af0e ES |
491 | { XFS_MOUNT_COMPAT_IOSIZE, ",largeio" }, |
492 | { XFS_MOUNT_BARRIER, ",nobarrier" }, | |
493 | { XFS_MOUNT_SMALL_INUMS, ",inode64" }, | |
a67d7c5f DC |
494 | { 0, NULL } |
495 | }; | |
496 | struct proc_xfs_info *xfs_infop; | |
497 | ||
498 | for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) { | |
499 | if (mp->m_flags & xfs_infop->flag) | |
500 | seq_puts(m, xfs_infop->str); | |
501 | } | |
502 | for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) { | |
503 | if (!(mp->m_flags & xfs_infop->flag)) | |
504 | seq_puts(m, xfs_infop->str); | |
505 | } | |
506 | ||
507 | if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE) | |
2e74af0e | 508 | seq_printf(m, ",allocsize=%dk", |
a67d7c5f DC |
509 | (int)(1 << mp->m_writeio_log) >> 10); |
510 | ||
511 | if (mp->m_logbufs > 0) | |
2e74af0e | 512 | seq_printf(m, ",logbufs=%d", mp->m_logbufs); |
a67d7c5f | 513 | if (mp->m_logbsize > 0) |
2e74af0e | 514 | seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10); |
a67d7c5f DC |
515 | |
516 | if (mp->m_logname) | |
2e74af0e | 517 | seq_show_option(m, "logdev", mp->m_logname); |
a67d7c5f | 518 | if (mp->m_rtname) |
2e74af0e | 519 | seq_show_option(m, "rtdev", mp->m_rtname); |
a67d7c5f DC |
520 | |
521 | if (mp->m_dalign > 0) | |
2e74af0e | 522 | seq_printf(m, ",sunit=%d", |
a67d7c5f DC |
523 | (int)XFS_FSB_TO_BB(mp, mp->m_dalign)); |
524 | if (mp->m_swidth > 0) | |
2e74af0e | 525 | seq_printf(m, ",swidth=%d", |
a67d7c5f DC |
526 | (int)XFS_FSB_TO_BB(mp, mp->m_swidth)); |
527 | ||
528 | if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD)) | |
2e74af0e | 529 | seq_puts(m, ",usrquota"); |
a67d7c5f | 530 | else if (mp->m_qflags & XFS_UQUOTA_ACCT) |
2e74af0e | 531 | seq_puts(m, ",uqnoenforce"); |
a67d7c5f | 532 | |
988abe40 | 533 | if (mp->m_qflags & XFS_PQUOTA_ACCT) { |
83e782e1 | 534 | if (mp->m_qflags & XFS_PQUOTA_ENFD) |
2e74af0e | 535 | seq_puts(m, ",prjquota"); |
988abe40 | 536 | else |
2e74af0e | 537 | seq_puts(m, ",pqnoenforce"); |
d892d586 CS |
538 | } |
539 | if (mp->m_qflags & XFS_GQUOTA_ACCT) { | |
83e782e1 | 540 | if (mp->m_qflags & XFS_GQUOTA_ENFD) |
2e74af0e | 541 | seq_puts(m, ",grpquota"); |
988abe40 | 542 | else |
2e74af0e | 543 | seq_puts(m, ",gqnoenforce"); |
988abe40 | 544 | } |
a67d7c5f DC |
545 | |
546 | if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT)) | |
2e74af0e | 547 | seq_puts(m, ",noquota"); |
a67d7c5f DC |
548 | |
549 | return 0; | |
550 | } | |
0d5a75e9 | 551 | static __uint64_t |
1da177e4 LT |
552 | xfs_max_file_offset( |
553 | unsigned int blockshift) | |
554 | { | |
555 | unsigned int pagefactor = 1; | |
556 | unsigned int bitshift = BITS_PER_LONG - 1; | |
557 | ||
558 | /* Figure out maximum filesize, on Linux this can depend on | |
559 | * the filesystem blocksize (on 32 bit platforms). | |
ebdec241 | 560 | * __block_write_begin does this in an [unsigned] long... |
ea1754a0 | 561 | * page->index << (PAGE_SHIFT - bbits) |
1da177e4 LT |
562 | * So, for page sized blocks (4K on 32 bit platforms), |
563 | * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is | |
ea1754a0 | 564 | * (((u64)PAGE_SIZE << (BITS_PER_LONG-1))-1) |
1da177e4 LT |
565 | * but for smaller blocksizes it is less (bbits = log2 bsize). |
566 | * Note1: get_block_t takes a long (implicit cast from above) | |
567 | * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch | |
568 | * can optionally convert the [unsigned] long from above into | |
569 | * an [unsigned] long long. | |
570 | */ | |
571 | ||
572 | #if BITS_PER_LONG == 32 | |
90c699a9 | 573 | # if defined(CONFIG_LBDAF) |
1da177e4 | 574 | ASSERT(sizeof(sector_t) == 8); |
09cbfeaf | 575 | pagefactor = PAGE_SIZE; |
1da177e4 LT |
576 | bitshift = BITS_PER_LONG; |
577 | # else | |
09cbfeaf | 578 | pagefactor = PAGE_SIZE >> (PAGE_SHIFT - blockshift); |
1da177e4 LT |
579 | # endif |
580 | #endif | |
581 | ||
582 | return (((__uint64_t)pagefactor) << bitshift) - 1; | |
583 | } | |
584 | ||
9de67c3b | 585 | /* |
12c3f05c ES |
586 | * Set parameters for inode allocation heuristics, taking into account |
587 | * filesystem size and inode32/inode64 mount options; i.e. specifically | |
588 | * whether or not XFS_MOUNT_SMALL_INUMS is set. | |
589 | * | |
590 | * Inode allocation patterns are altered only if inode32 is requested | |
591 | * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large. | |
592 | * If altered, XFS_MOUNT_32BITINODES is set as well. | |
593 | * | |
594 | * An agcount independent of that in the mount structure is provided | |
595 | * because in the growfs case, mp->m_sb.sb_agcount is not yet updated | |
596 | * to the potentially higher ag count. | |
597 | * | |
598 | * Returns the maximum AG index which may contain inodes. | |
9de67c3b | 599 | */ |
2d2194f6 | 600 | xfs_agnumber_t |
12c3f05c ES |
601 | xfs_set_inode_alloc( |
602 | struct xfs_mount *mp, | |
603 | xfs_agnumber_t agcount) | |
2d2194f6 | 604 | { |
12c3f05c | 605 | xfs_agnumber_t index; |
4056c1d0 | 606 | xfs_agnumber_t maxagi = 0; |
2d2194f6 CM |
607 | xfs_sb_t *sbp = &mp->m_sb; |
608 | xfs_agnumber_t max_metadata; | |
54aa61f8 ES |
609 | xfs_agino_t agino; |
610 | xfs_ino_t ino; | |
2d2194f6 | 611 | |
12c3f05c ES |
612 | /* |
613 | * Calculate how much should be reserved for inodes to meet | |
614 | * the max inode percentage. Used only for inode32. | |
2d2194f6 CM |
615 | */ |
616 | if (mp->m_maxicount) { | |
617 | __uint64_t icount; | |
618 | ||
619 | icount = sbp->sb_dblocks * sbp->sb_imax_pct; | |
620 | do_div(icount, 100); | |
621 | icount += sbp->sb_agblocks - 1; | |
622 | do_div(icount, sbp->sb_agblocks); | |
623 | max_metadata = icount; | |
624 | } else { | |
9de67c3b | 625 | max_metadata = agcount; |
2d2194f6 CM |
626 | } |
627 | ||
12c3f05c | 628 | /* Get the last possible inode in the filesystem */ |
54aa61f8 | 629 | agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks - 1, 0); |
12c3f05c ES |
630 | ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino); |
631 | ||
632 | /* | |
633 | * If user asked for no more than 32-bit inodes, and the fs is | |
634 | * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter | |
635 | * the allocator to accommodate the request. | |
636 | */ | |
637 | if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32) | |
638 | mp->m_flags |= XFS_MOUNT_32BITINODES; | |
639 | else | |
640 | mp->m_flags &= ~XFS_MOUNT_32BITINODES; | |
54aa61f8 | 641 | |
9de67c3b | 642 | for (index = 0; index < agcount; index++) { |
12c3f05c | 643 | struct xfs_perag *pag; |
4056c1d0 | 644 | |
12c3f05c | 645 | ino = XFS_AGINO_TO_INO(mp, index, agino); |
2d2194f6 CM |
646 | |
647 | pag = xfs_perag_get(mp, index); | |
2d2194f6 | 648 | |
12c3f05c ES |
649 | if (mp->m_flags & XFS_MOUNT_32BITINODES) { |
650 | if (ino > XFS_MAXINUMBER_32) { | |
651 | pag->pagi_inodeok = 0; | |
652 | pag->pagf_metadata = 0; | |
653 | } else { | |
654 | pag->pagi_inodeok = 1; | |
655 | maxagi++; | |
656 | if (index < max_metadata) | |
657 | pag->pagf_metadata = 1; | |
658 | else | |
659 | pag->pagf_metadata = 0; | |
660 | } | |
661 | } else { | |
662 | pag->pagi_inodeok = 1; | |
663 | pag->pagf_metadata = 0; | |
664 | } | |
2d2194f6 | 665 | |
2d2194f6 CM |
666 | xfs_perag_put(pag); |
667 | } | |
668 | ||
12c3f05c | 669 | return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount; |
2d2194f6 CM |
670 | } |
671 | ||
3180e66d | 672 | STATIC int |
1da177e4 LT |
673 | xfs_blkdev_get( |
674 | xfs_mount_t *mp, | |
675 | const char *name, | |
676 | struct block_device **bdevp) | |
677 | { | |
678 | int error = 0; | |
679 | ||
d4d77629 TH |
680 | *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL, |
681 | mp); | |
1da177e4 LT |
682 | if (IS_ERR(*bdevp)) { |
683 | error = PTR_ERR(*bdevp); | |
77af574e | 684 | xfs_warn(mp, "Invalid device [%s], error=%d", name, error); |
1da177e4 LT |
685 | } |
686 | ||
2451337d | 687 | return error; |
1da177e4 LT |
688 | } |
689 | ||
3180e66d | 690 | STATIC void |
1da177e4 LT |
691 | xfs_blkdev_put( |
692 | struct block_device *bdev) | |
693 | { | |
694 | if (bdev) | |
e525fd89 | 695 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); |
1da177e4 LT |
696 | } |
697 | ||
f538d4da CH |
698 | void |
699 | xfs_blkdev_issue_flush( | |
700 | xfs_buftarg_t *buftarg) | |
701 | { | |
7582df51 | 702 | blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL); |
f538d4da | 703 | } |
1da177e4 | 704 | |
19f354d4 CH |
705 | STATIC void |
706 | xfs_close_devices( | |
707 | struct xfs_mount *mp) | |
708 | { | |
709 | if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { | |
c032bfcf | 710 | struct block_device *logdev = mp->m_logdev_targp->bt_bdev; |
b7963133 | 711 | xfs_free_buftarg(mp, mp->m_logdev_targp); |
c032bfcf | 712 | xfs_blkdev_put(logdev); |
19f354d4 CH |
713 | } |
714 | if (mp->m_rtdev_targp) { | |
c032bfcf | 715 | struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev; |
b7963133 | 716 | xfs_free_buftarg(mp, mp->m_rtdev_targp); |
c032bfcf | 717 | xfs_blkdev_put(rtdev); |
19f354d4 | 718 | } |
b7963133 | 719 | xfs_free_buftarg(mp, mp->m_ddev_targp); |
19f354d4 CH |
720 | } |
721 | ||
722 | /* | |
723 | * The file system configurations are: | |
724 | * (1) device (partition) with data and internal log | |
725 | * (2) logical volume with data and log subvolumes. | |
726 | * (3) logical volume with data, log, and realtime subvolumes. | |
727 | * | |
728 | * We only have to handle opening the log and realtime volumes here if | |
729 | * they are present. The data subvolume has already been opened by | |
730 | * get_sb_bdev() and is stored in sb->s_bdev. | |
731 | */ | |
732 | STATIC int | |
733 | xfs_open_devices( | |
9d565ffa | 734 | struct xfs_mount *mp) |
19f354d4 CH |
735 | { |
736 | struct block_device *ddev = mp->m_super->s_bdev; | |
737 | struct block_device *logdev = NULL, *rtdev = NULL; | |
738 | int error; | |
739 | ||
740 | /* | |
741 | * Open real time and log devices - order is important. | |
742 | */ | |
9d565ffa CH |
743 | if (mp->m_logname) { |
744 | error = xfs_blkdev_get(mp, mp->m_logname, &logdev); | |
19f354d4 CH |
745 | if (error) |
746 | goto out; | |
747 | } | |
748 | ||
9d565ffa CH |
749 | if (mp->m_rtname) { |
750 | error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev); | |
19f354d4 CH |
751 | if (error) |
752 | goto out_close_logdev; | |
753 | ||
754 | if (rtdev == ddev || rtdev == logdev) { | |
4f10700a DC |
755 | xfs_warn(mp, |
756 | "Cannot mount filesystem with identical rtdev and ddev/logdev."); | |
2451337d | 757 | error = -EINVAL; |
19f354d4 CH |
758 | goto out_close_rtdev; |
759 | } | |
760 | } | |
761 | ||
762 | /* | |
763 | * Setup xfs_mount buffer target pointers | |
764 | */ | |
2451337d | 765 | error = -ENOMEM; |
34dcefd7 | 766 | mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev); |
19f354d4 CH |
767 | if (!mp->m_ddev_targp) |
768 | goto out_close_rtdev; | |
769 | ||
770 | if (rtdev) { | |
34dcefd7 | 771 | mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev); |
19f354d4 CH |
772 | if (!mp->m_rtdev_targp) |
773 | goto out_free_ddev_targ; | |
774 | } | |
775 | ||
776 | if (logdev && logdev != ddev) { | |
34dcefd7 | 777 | mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev); |
19f354d4 CH |
778 | if (!mp->m_logdev_targp) |
779 | goto out_free_rtdev_targ; | |
780 | } else { | |
781 | mp->m_logdev_targp = mp->m_ddev_targp; | |
782 | } | |
783 | ||
784 | return 0; | |
785 | ||
786 | out_free_rtdev_targ: | |
787 | if (mp->m_rtdev_targp) | |
b7963133 | 788 | xfs_free_buftarg(mp, mp->m_rtdev_targp); |
19f354d4 | 789 | out_free_ddev_targ: |
b7963133 | 790 | xfs_free_buftarg(mp, mp->m_ddev_targp); |
19f354d4 | 791 | out_close_rtdev: |
d2a5e3c6 | 792 | xfs_blkdev_put(rtdev); |
19f354d4 CH |
793 | out_close_logdev: |
794 | if (logdev && logdev != ddev) | |
795 | xfs_blkdev_put(logdev); | |
796 | out: | |
797 | return error; | |
798 | } | |
799 | ||
e34b562c CH |
800 | /* |
801 | * Setup xfs_mount buffer target pointers based on superblock | |
802 | */ | |
803 | STATIC int | |
804 | xfs_setup_devices( | |
805 | struct xfs_mount *mp) | |
806 | { | |
807 | int error; | |
19f354d4 | 808 | |
a96c4151 | 809 | error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize); |
e34b562c CH |
810 | if (error) |
811 | return error; | |
812 | ||
813 | if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { | |
814 | unsigned int log_sector_size = BBSIZE; | |
815 | ||
816 | if (xfs_sb_version_hassector(&mp->m_sb)) | |
817 | log_sector_size = mp->m_sb.sb_logsectsize; | |
818 | error = xfs_setsize_buftarg(mp->m_logdev_targp, | |
e34b562c CH |
819 | log_sector_size); |
820 | if (error) | |
821 | return error; | |
822 | } | |
823 | if (mp->m_rtdev_targp) { | |
824 | error = xfs_setsize_buftarg(mp->m_rtdev_targp, | |
e34b562c CH |
825 | mp->m_sb.sb_sectsize); |
826 | if (error) | |
827 | return error; | |
828 | } | |
829 | ||
830 | return 0; | |
831 | } | |
19f354d4 | 832 | |
aa6bf01d CH |
833 | STATIC int |
834 | xfs_init_mount_workqueues( | |
835 | struct xfs_mount *mp) | |
836 | { | |
78c931b8 | 837 | mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s", |
b29c70f5 | 838 | WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_fsname); |
78c931b8 BF |
839 | if (!mp->m_buf_workqueue) |
840 | goto out; | |
841 | ||
aa6bf01d | 842 | mp->m_data_workqueue = alloc_workqueue("xfs-data/%s", |
8018ec08 | 843 | WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname); |
aa6bf01d | 844 | if (!mp->m_data_workqueue) |
78c931b8 | 845 | goto out_destroy_buf; |
aa6bf01d CH |
846 | |
847 | mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s", | |
8018ec08 | 848 | WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname); |
aa6bf01d CH |
849 | if (!mp->m_unwritten_workqueue) |
850 | goto out_destroy_data_iodone_queue; | |
851 | ||
4c2d542f | 852 | mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s", |
8018ec08 | 853 | WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname); |
4c2d542f DC |
854 | if (!mp->m_cil_workqueue) |
855 | goto out_destroy_unwritten; | |
5889608d DC |
856 | |
857 | mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s", | |
7a29ac47 | 858 | WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname); |
5889608d DC |
859 | if (!mp->m_reclaim_workqueue) |
860 | goto out_destroy_cil; | |
861 | ||
862 | mp->m_log_workqueue = alloc_workqueue("xfs-log/%s", | |
7a29ac47 CM |
863 | WQ_MEM_RECLAIM|WQ_FREEZABLE|WQ_HIGHPRI, 0, |
864 | mp->m_fsname); | |
5889608d DC |
865 | if (!mp->m_log_workqueue) |
866 | goto out_destroy_reclaim; | |
867 | ||
579b62fa | 868 | mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s", |
7a29ac47 | 869 | WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname); |
579b62fa BF |
870 | if (!mp->m_eofblocks_workqueue) |
871 | goto out_destroy_log; | |
872 | ||
aa6bf01d CH |
873 | return 0; |
874 | ||
579b62fa BF |
875 | out_destroy_log: |
876 | destroy_workqueue(mp->m_log_workqueue); | |
5889608d DC |
877 | out_destroy_reclaim: |
878 | destroy_workqueue(mp->m_reclaim_workqueue); | |
879 | out_destroy_cil: | |
880 | destroy_workqueue(mp->m_cil_workqueue); | |
4c2d542f DC |
881 | out_destroy_unwritten: |
882 | destroy_workqueue(mp->m_unwritten_workqueue); | |
aa6bf01d CH |
883 | out_destroy_data_iodone_queue: |
884 | destroy_workqueue(mp->m_data_workqueue); | |
78c931b8 BF |
885 | out_destroy_buf: |
886 | destroy_workqueue(mp->m_buf_workqueue); | |
aa6bf01d CH |
887 | out: |
888 | return -ENOMEM; | |
889 | } | |
890 | ||
891 | STATIC void | |
892 | xfs_destroy_mount_workqueues( | |
893 | struct xfs_mount *mp) | |
894 | { | |
579b62fa | 895 | destroy_workqueue(mp->m_eofblocks_workqueue); |
5889608d DC |
896 | destroy_workqueue(mp->m_log_workqueue); |
897 | destroy_workqueue(mp->m_reclaim_workqueue); | |
4c2d542f | 898 | destroy_workqueue(mp->m_cil_workqueue); |
aa6bf01d CH |
899 | destroy_workqueue(mp->m_data_workqueue); |
900 | destroy_workqueue(mp->m_unwritten_workqueue); | |
78c931b8 | 901 | destroy_workqueue(mp->m_buf_workqueue); |
aa6bf01d CH |
902 | } |
903 | ||
9aa05000 DC |
904 | /* |
905 | * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK | |
906 | * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting | |
907 | * for IO to complete so that we effectively throttle multiple callers to the | |
908 | * rate at which IO is completing. | |
909 | */ | |
910 | void | |
911 | xfs_flush_inodes( | |
912 | struct xfs_mount *mp) | |
913 | { | |
914 | struct super_block *sb = mp->m_super; | |
915 | ||
916 | if (down_read_trylock(&sb->s_umount)) { | |
0dc83bd3 | 917 | sync_inodes_sb(sb); |
9aa05000 DC |
918 | up_read(&sb->s_umount); |
919 | } | |
920 | } | |
921 | ||
bf904248 | 922 | /* Catch misguided souls that try to use this interface on XFS */ |
1da177e4 | 923 | STATIC struct inode * |
a50cd269 | 924 | xfs_fs_alloc_inode( |
1da177e4 LT |
925 | struct super_block *sb) |
926 | { | |
bf904248 | 927 | BUG(); |
493dca61 | 928 | return NULL; |
1da177e4 LT |
929 | } |
930 | ||
bf904248 | 931 | /* |
99fa8cb3 | 932 | * Now that the generic code is guaranteed not to be accessing |
8179c036 | 933 | * the linux inode, we can inactivate and reclaim the inode. |
bf904248 | 934 | */ |
1da177e4 | 935 | STATIC void |
a50cd269 | 936 | xfs_fs_destroy_inode( |
848ce8f7 | 937 | struct inode *inode) |
1da177e4 | 938 | { |
848ce8f7 CH |
939 | struct xfs_inode *ip = XFS_I(inode); |
940 | ||
cca28fb8 | 941 | trace_xfs_destroy_inode(ip); |
99fa8cb3 | 942 | |
8179c036 DC |
943 | ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock)); |
944 | XFS_STATS_INC(ip->i_mount, vn_rele); | |
945 | XFS_STATS_INC(ip->i_mount, vn_remove); | |
946 | ||
947 | xfs_inactive(ip); | |
848ce8f7 | 948 | |
848ce8f7 | 949 | ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0); |
8179c036 | 950 | XFS_STATS_INC(ip->i_mount, vn_reclaim); |
848ce8f7 CH |
951 | |
952 | /* | |
953 | * We should never get here with one of the reclaim flags already set. | |
954 | */ | |
955 | ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE)); | |
956 | ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM)); | |
957 | ||
958 | /* | |
57817c68 DC |
959 | * We always use background reclaim here because even if the |
960 | * inode is clean, it still may be under IO and hence we have | |
961 | * to take the flush lock. The background reclaim path handles | |
962 | * this more efficiently than we can here, so simply let background | |
963 | * reclaim tear down all inodes. | |
848ce8f7 | 964 | */ |
57817c68 | 965 | xfs_inode_set_reclaim_tag(ip); |
1da177e4 LT |
966 | } |
967 | ||
07c8f675 DC |
968 | /* |
969 | * Slab object creation initialisation for the XFS inode. | |
970 | * This covers only the idempotent fields in the XFS inode; | |
971 | * all other fields need to be initialised on allocation | |
b595076a | 972 | * from the slab. This avoids the need to repeatedly initialise |
07c8f675 DC |
973 | * fields in the xfs inode that left in the initialise state |
974 | * when freeing the inode. | |
975 | */ | |
bf904248 DC |
976 | STATIC void |
977 | xfs_fs_inode_init_once( | |
07c8f675 DC |
978 | void *inode) |
979 | { | |
980 | struct xfs_inode *ip = inode; | |
981 | ||
982 | memset(ip, 0, sizeof(struct xfs_inode)); | |
bf904248 DC |
983 | |
984 | /* vfs inode */ | |
985 | inode_init_once(VFS_I(ip)); | |
986 | ||
987 | /* xfs inode */ | |
07c8f675 DC |
988 | atomic_set(&ip->i_pincount, 0); |
989 | spin_lock_init(&ip->i_flags_lock); | |
07c8f675 | 990 | |
653c60b6 DC |
991 | mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER, |
992 | "xfsino", ip->i_ino); | |
07c8f675 DC |
993 | mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER, |
994 | "xfsino", ip->i_ino); | |
07c8f675 DC |
995 | } |
996 | ||
5132ba8f DC |
997 | /* |
998 | * We do an unlocked check for XFS_IDONTCACHE here because we are already | |
999 | * serialised against cache hits here via the inode->i_lock and igrab() in | |
1000 | * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be | |
1001 | * racing with us, and it avoids needing to grab a spinlock here for every inode | |
1002 | * we drop the final reference on. | |
1003 | */ | |
1004 | STATIC int | |
1005 | xfs_fs_drop_inode( | |
1006 | struct inode *inode) | |
1007 | { | |
1008 | struct xfs_inode *ip = XFS_I(inode); | |
1009 | ||
1010 | return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE); | |
1011 | } | |
1012 | ||
a738159d CH |
1013 | STATIC void |
1014 | xfs_free_fsname( | |
1015 | struct xfs_mount *mp) | |
1016 | { | |
1017 | kfree(mp->m_fsname); | |
1018 | kfree(mp->m_rtname); | |
1019 | kfree(mp->m_logname); | |
1020 | } | |
1021 | ||
1da177e4 | 1022 | STATIC int |
69961a26 | 1023 | xfs_fs_sync_fs( |
1da177e4 LT |
1024 | struct super_block *sb, |
1025 | int wait) | |
1026 | { | |
745f6919 | 1027 | struct xfs_mount *mp = XFS_M(sb); |
1da177e4 | 1028 | |
e893bffd | 1029 | /* |
34625c66 | 1030 | * Doing anything during the async pass would be counterproductive. |
e893bffd | 1031 | */ |
34625c66 | 1032 | if (!wait) |
69961a26 | 1033 | return 0; |
69961a26 | 1034 | |
34061f5c | 1035 | xfs_log_force(mp, XFS_LOG_SYNC); |
69961a26 | 1036 | if (laptop_mode) { |
1da177e4 LT |
1037 | /* |
1038 | * The disk must be active because we're syncing. | |
f661f1e0 | 1039 | * We schedule log work now (now that the disk is |
1da177e4 LT |
1040 | * active) instead of later (when it might not be). |
1041 | */ | |
f661f1e0 | 1042 | flush_delayed_work(&mp->m_log->l_work); |
1da177e4 LT |
1043 | } |
1044 | ||
69961a26 | 1045 | return 0; |
1da177e4 LT |
1046 | } |
1047 | ||
1048 | STATIC int | |
a50cd269 | 1049 | xfs_fs_statfs( |
726c3342 | 1050 | struct dentry *dentry, |
1da177e4 LT |
1051 | struct kstatfs *statp) |
1052 | { | |
4ca488eb CH |
1053 | struct xfs_mount *mp = XFS_M(dentry->d_sb); |
1054 | xfs_sb_t *sbp = &mp->m_sb; | |
2b0143b5 | 1055 | struct xfs_inode *ip = XFS_I(d_inode(dentry)); |
4ca488eb | 1056 | __uint64_t fakeinos, id; |
501ab323 | 1057 | __uint64_t icount; |
e88b64ea | 1058 | __uint64_t ifree; |
0d485ada | 1059 | __uint64_t fdblocks; |
4ca488eb | 1060 | xfs_extlen_t lsize; |
2fe33661 | 1061 | __int64_t ffree; |
4ca488eb CH |
1062 | |
1063 | statp->f_type = XFS_SB_MAGIC; | |
1064 | statp->f_namelen = MAXNAMELEN - 1; | |
1065 | ||
1066 | id = huge_encode_dev(mp->m_ddev_targp->bt_dev); | |
1067 | statp->f_fsid.val[0] = (u32)id; | |
1068 | statp->f_fsid.val[1] = (u32)(id >> 32); | |
1069 | ||
501ab323 | 1070 | icount = percpu_counter_sum(&mp->m_icount); |
e88b64ea | 1071 | ifree = percpu_counter_sum(&mp->m_ifree); |
0d485ada | 1072 | fdblocks = percpu_counter_sum(&mp->m_fdblocks); |
4ca488eb CH |
1073 | |
1074 | spin_lock(&mp->m_sb_lock); | |
1075 | statp->f_bsize = sbp->sb_blocksize; | |
1076 | lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0; | |
1077 | statp->f_blocks = sbp->sb_dblocks - lsize; | |
0d485ada DC |
1078 | spin_unlock(&mp->m_sb_lock); |
1079 | ||
52548852 | 1080 | statp->f_bfree = fdblocks - mp->m_alloc_set_aside; |
0d485ada DC |
1081 | statp->f_bavail = statp->f_bfree; |
1082 | ||
4ca488eb | 1083 | fakeinos = statp->f_bfree << sbp->sb_inopblog; |
501ab323 | 1084 | statp->f_files = MIN(icount + fakeinos, (__uint64_t)XFS_MAXINUMBER); |
4ca488eb | 1085 | if (mp->m_maxicount) |
a19d9f88 CH |
1086 | statp->f_files = min_t(typeof(statp->f_files), |
1087 | statp->f_files, | |
1088 | mp->m_maxicount); | |
2fe33661 | 1089 | |
01f9882e ES |
1090 | /* If sb_icount overshot maxicount, report actual allocation */ |
1091 | statp->f_files = max_t(typeof(statp->f_files), | |
1092 | statp->f_files, | |
1093 | sbp->sb_icount); | |
1094 | ||
2fe33661 | 1095 | /* make sure statp->f_ffree does not underflow */ |
e88b64ea | 1096 | ffree = statp->f_files - (icount - ifree); |
2fe33661 SB |
1097 | statp->f_ffree = max_t(__int64_t, ffree, 0); |
1098 | ||
4ca488eb | 1099 | |
da5bf95e | 1100 | if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) && |
83e782e1 CS |
1101 | ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) == |
1102 | (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD)) | |
7d095257 | 1103 | xfs_qm_statvfs(ip, statp); |
4ca488eb | 1104 | return 0; |
1da177e4 LT |
1105 | } |
1106 | ||
d5db0f97 ES |
1107 | STATIC void |
1108 | xfs_save_resvblks(struct xfs_mount *mp) | |
1109 | { | |
1110 | __uint64_t resblks = 0; | |
1111 | ||
1112 | mp->m_resblks_save = mp->m_resblks; | |
1113 | xfs_reserve_blocks(mp, &resblks, NULL); | |
1114 | } | |
1115 | ||
1116 | STATIC void | |
1117 | xfs_restore_resvblks(struct xfs_mount *mp) | |
1118 | { | |
1119 | __uint64_t resblks; | |
1120 | ||
1121 | if (mp->m_resblks_save) { | |
1122 | resblks = mp->m_resblks_save; | |
1123 | mp->m_resblks_save = 0; | |
1124 | } else | |
1125 | resblks = xfs_default_resblks(mp); | |
1126 | ||
1127 | xfs_reserve_blocks(mp, &resblks, NULL); | |
1128 | } | |
1129 | ||
c7eea6f7 DC |
1130 | /* |
1131 | * Trigger writeback of all the dirty metadata in the file system. | |
1132 | * | |
1133 | * This ensures that the metadata is written to their location on disk rather | |
1134 | * than just existing in transactions in the log. This means after a quiesce | |
c75921a7 DC |
1135 | * there is no log replay required to write the inodes to disk - this is the |
1136 | * primary difference between a sync and a quiesce. | |
c7eea6f7 | 1137 | * |
c75921a7 DC |
1138 | * Note: xfs_log_quiesce() stops background log work - the callers must ensure |
1139 | * it is started again when appropriate. | |
c7eea6f7 | 1140 | */ |
ddeb14f4 | 1141 | void |
c7eea6f7 DC |
1142 | xfs_quiesce_attr( |
1143 | struct xfs_mount *mp) | |
1144 | { | |
1145 | int error = 0; | |
1146 | ||
1147 | /* wait for all modifications to complete */ | |
1148 | while (atomic_read(&mp->m_active_trans) > 0) | |
1149 | delay(100); | |
1150 | ||
1151 | /* force the log to unpin objects from the now complete transactions */ | |
1152 | xfs_log_force(mp, XFS_LOG_SYNC); | |
1153 | ||
1154 | /* reclaim inodes to do any IO before the freeze completes */ | |
1155 | xfs_reclaim_inodes(mp, 0); | |
1156 | xfs_reclaim_inodes(mp, SYNC_WAIT); | |
1157 | ||
c7eea6f7 DC |
1158 | /* Push the superblock and write an unmount record */ |
1159 | error = xfs_log_sbcount(mp); | |
1160 | if (error) | |
1161 | xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. " | |
1162 | "Frozen image may not be consistent."); | |
c7eea6f7 | 1163 | /* |
c75921a7 DC |
1164 | * Just warn here till VFS can correctly support |
1165 | * read-only remount without racing. | |
c7eea6f7 | 1166 | */ |
c75921a7 | 1167 | WARN_ON(atomic_read(&mp->m_active_trans) != 0); |
c7eea6f7 | 1168 | |
c75921a7 | 1169 | xfs_log_quiesce(mp); |
c7eea6f7 DC |
1170 | } |
1171 | ||
a08ee40a ES |
1172 | STATIC int |
1173 | xfs_test_remount_options( | |
1174 | struct super_block *sb, | |
1175 | struct xfs_mount *mp, | |
1176 | char *options) | |
1177 | { | |
1178 | int error = 0; | |
1179 | struct xfs_mount *tmp_mp; | |
1180 | ||
1181 | tmp_mp = kmem_zalloc(sizeof(*tmp_mp), KM_MAYFAIL); | |
1182 | if (!tmp_mp) | |
1183 | return -ENOMEM; | |
1184 | ||
1185 | tmp_mp->m_super = sb; | |
1186 | error = xfs_parseargs(tmp_mp, options); | |
1187 | xfs_free_fsname(tmp_mp); | |
1188 | kfree(tmp_mp); | |
1189 | ||
1190 | return error; | |
1191 | } | |
1192 | ||
1da177e4 | 1193 | STATIC int |
a50cd269 | 1194 | xfs_fs_remount( |
1da177e4 LT |
1195 | struct super_block *sb, |
1196 | int *flags, | |
1197 | char *options) | |
1198 | { | |
745f6919 | 1199 | struct xfs_mount *mp = XFS_M(sb); |
9de67c3b | 1200 | xfs_sb_t *sbp = &mp->m_sb; |
62a877e3 CH |
1201 | substring_t args[MAX_OPT_ARGS]; |
1202 | char *p; | |
7884bc86 | 1203 | int error; |
1da177e4 | 1204 | |
a08ee40a ES |
1205 | /* First, check for complete junk; i.e. invalid options */ |
1206 | error = xfs_test_remount_options(sb, mp, options); | |
1207 | if (error) | |
1208 | return error; | |
1209 | ||
02b9984d | 1210 | sync_filesystem(sb); |
62a877e3 CH |
1211 | while ((p = strsep(&options, ",")) != NULL) { |
1212 | int token; | |
bdd907ba | 1213 | |
62a877e3 CH |
1214 | if (!*p) |
1215 | continue; | |
48b62a1a | 1216 | |
62a877e3 CH |
1217 | token = match_token(p, tokens, args); |
1218 | switch (token) { | |
1219 | case Opt_barrier: | |
48b62a1a | 1220 | mp->m_flags |= XFS_MOUNT_BARRIER; |
62a877e3 CH |
1221 | break; |
1222 | case Opt_nobarrier: | |
48b62a1a | 1223 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
62a877e3 | 1224 | break; |
c3a58fec | 1225 | case Opt_inode64: |
12c3f05c ES |
1226 | mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS; |
1227 | mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount); | |
c3a58fec | 1228 | break; |
2ea03929 | 1229 | case Opt_inode32: |
12c3f05c ES |
1230 | mp->m_flags |= XFS_MOUNT_SMALL_INUMS; |
1231 | mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount); | |
2ea03929 | 1232 | break; |
62a877e3 | 1233 | default: |
6efdf281 CH |
1234 | /* |
1235 | * Logically we would return an error here to prevent | |
1236 | * users from believing they might have changed | |
1237 | * mount options using remount which can't be changed. | |
1238 | * | |
1239 | * But unfortunately mount(8) adds all options from | |
1240 | * mtab and fstab to the mount arguments in some cases | |
1241 | * so we can't blindly reject options, but have to | |
1242 | * check for each specified option if it actually | |
1243 | * differs from the currently set option and only | |
1244 | * reject it if that's the case. | |
1245 | * | |
1246 | * Until that is implemented we return success for | |
1247 | * every remount request, and silently ignore all | |
1248 | * options that we can't actually change. | |
1249 | */ | |
1250 | #if 0 | |
4f10700a | 1251 | xfs_info(mp, |
08e96e1a | 1252 | "mount option \"%s\" not supported for remount", p); |
62a877e3 | 1253 | return -EINVAL; |
6efdf281 | 1254 | #else |
6c5e51da | 1255 | break; |
6efdf281 | 1256 | #endif |
48b62a1a | 1257 | } |
62a877e3 CH |
1258 | } |
1259 | ||
7884bc86 | 1260 | /* ro -> rw */ |
62a877e3 | 1261 | if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) { |
bbe051c8 ES |
1262 | if (mp->m_flags & XFS_MOUNT_NORECOVERY) { |
1263 | xfs_warn(mp, | |
1264 | "ro->rw transition prohibited on norecovery mount"); | |
1265 | return -EINVAL; | |
1266 | } | |
1267 | ||
d0a58e83 ES |
1268 | if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 && |
1269 | xfs_sb_has_ro_compat_feature(sbp, | |
1270 | XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) { | |
1271 | xfs_warn(mp, | |
1272 | "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem", | |
1273 | (sbp->sb_features_ro_compat & | |
1274 | XFS_SB_FEAT_RO_COMPAT_UNKNOWN)); | |
1275 | return -EINVAL; | |
1276 | } | |
1277 | ||
62a877e3 | 1278 | mp->m_flags &= ~XFS_MOUNT_RDONLY; |
7884bc86 CH |
1279 | |
1280 | /* | |
1281 | * If this is the first remount to writeable state we | |
1282 | * might have some superblock changes to update. | |
1283 | */ | |
61e63ecb DC |
1284 | if (mp->m_update_sb) { |
1285 | error = xfs_sync_sb(mp, false); | |
7884bc86 | 1286 | if (error) { |
4f10700a | 1287 | xfs_warn(mp, "failed to write sb changes"); |
7884bc86 CH |
1288 | return error; |
1289 | } | |
61e63ecb | 1290 | mp->m_update_sb = false; |
7884bc86 | 1291 | } |
cbe132a8 DC |
1292 | |
1293 | /* | |
1294 | * Fill out the reserve pool if it is empty. Use the stashed | |
1295 | * value if it is non-zero, otherwise go with the default. | |
1296 | */ | |
d5db0f97 | 1297 | xfs_restore_resvblks(mp); |
f661f1e0 | 1298 | xfs_log_work_queue(mp); |
fa5a4f57 | 1299 | xfs_queue_eofblocks(mp); |
62a877e3 CH |
1300 | } |
1301 | ||
1302 | /* rw -> ro */ | |
1303 | if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) { | |
cbe132a8 | 1304 | /* |
34061f5c DC |
1305 | * Before we sync the metadata, we need to free up the reserve |
1306 | * block pool so that the used block count in the superblock on | |
1307 | * disk is correct at the end of the remount. Stash the current | |
1308 | * reserve pool size so that if we get remounted rw, we can | |
1309 | * return it to the same size. | |
cbe132a8 | 1310 | */ |
d5db0f97 | 1311 | xfs_save_resvblks(mp); |
fa5a4f57 BF |
1312 | |
1313 | /* | |
1314 | * Cancel background eofb scanning so it cannot race with the | |
1315 | * final log force+buftarg wait and deadlock the remount. | |
1316 | */ | |
1317 | cancel_delayed_work_sync(&mp->m_eofblocks_work); | |
1318 | ||
76bf105c | 1319 | xfs_quiesce_attr(mp); |
48b62a1a CH |
1320 | mp->m_flags |= XFS_MOUNT_RDONLY; |
1321 | } | |
1322 | ||
62a877e3 | 1323 | return 0; |
1da177e4 LT |
1324 | } |
1325 | ||
9909c4aa CH |
1326 | /* |
1327 | * Second stage of a freeze. The data is already frozen so we only | |
61e63ecb DC |
1328 | * need to take care of the metadata. Once that's done sync the superblock |
1329 | * to the log to dirty it in case of a crash while frozen. This ensures that we | |
1330 | * will recover the unlinked inode lists on the next mount. | |
9909c4aa | 1331 | */ |
c4be0c1d TS |
1332 | STATIC int |
1333 | xfs_fs_freeze( | |
1da177e4 LT |
1334 | struct super_block *sb) |
1335 | { | |
9909c4aa CH |
1336 | struct xfs_mount *mp = XFS_M(sb); |
1337 | ||
d5db0f97 | 1338 | xfs_save_resvblks(mp); |
76bf105c | 1339 | xfs_quiesce_attr(mp); |
61e63ecb | 1340 | return xfs_sync_sb(mp, true); |
1da177e4 LT |
1341 | } |
1342 | ||
d5db0f97 ES |
1343 | STATIC int |
1344 | xfs_fs_unfreeze( | |
1345 | struct super_block *sb) | |
1346 | { | |
1347 | struct xfs_mount *mp = XFS_M(sb); | |
1348 | ||
1349 | xfs_restore_resvblks(mp); | |
f661f1e0 | 1350 | xfs_log_work_queue(mp); |
d5db0f97 ES |
1351 | return 0; |
1352 | } | |
1353 | ||
1da177e4 | 1354 | STATIC int |
a50cd269 | 1355 | xfs_fs_show_options( |
1da177e4 | 1356 | struct seq_file *m, |
34c80b1d | 1357 | struct dentry *root) |
1da177e4 | 1358 | { |
2451337d | 1359 | return xfs_showargs(XFS_M(root->d_sb), m); |
1da177e4 LT |
1360 | } |
1361 | ||
f8f15e42 CH |
1362 | /* |
1363 | * This function fills in xfs_mount_t fields based on mount args. | |
1364 | * Note: the superblock _has_ now been read in. | |
1365 | */ | |
1366 | STATIC int | |
1367 | xfs_finish_flags( | |
f8f15e42 CH |
1368 | struct xfs_mount *mp) |
1369 | { | |
1370 | int ronly = (mp->m_flags & XFS_MOUNT_RDONLY); | |
1371 | ||
025dfdaf | 1372 | /* Fail a mount where the logbuf is smaller than the log stripe */ |
f8f15e42 | 1373 | if (xfs_sb_version_haslogv2(&mp->m_sb)) { |
9d565ffa CH |
1374 | if (mp->m_logbsize <= 0 && |
1375 | mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) { | |
f8f15e42 | 1376 | mp->m_logbsize = mp->m_sb.sb_logsunit; |
9d565ffa CH |
1377 | } else if (mp->m_logbsize > 0 && |
1378 | mp->m_logbsize < mp->m_sb.sb_logsunit) { | |
4f10700a DC |
1379 | xfs_warn(mp, |
1380 | "logbuf size must be greater than or equal to log stripe size"); | |
2451337d | 1381 | return -EINVAL; |
f8f15e42 CH |
1382 | } |
1383 | } else { | |
1384 | /* Fail a mount if the logbuf is larger than 32K */ | |
9d565ffa | 1385 | if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) { |
4f10700a DC |
1386 | xfs_warn(mp, |
1387 | "logbuf size for version 1 logs must be 16K or 32K"); | |
2451337d | 1388 | return -EINVAL; |
f8f15e42 CH |
1389 | } |
1390 | } | |
1391 | ||
d3eaace8 DC |
1392 | /* |
1393 | * V5 filesystems always use attr2 format for attributes. | |
1394 | */ | |
1395 | if (xfs_sb_version_hascrc(&mp->m_sb) && | |
1396 | (mp->m_flags & XFS_MOUNT_NOATTR2)) { | |
2e74af0e ES |
1397 | xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. " |
1398 | "attr2 is always enabled for V5 filesystems."); | |
2451337d | 1399 | return -EINVAL; |
d3eaace8 DC |
1400 | } |
1401 | ||
f8f15e42 CH |
1402 | /* |
1403 | * mkfs'ed attr2 will turn on attr2 mount unless explicitly | |
1404 | * told by noattr2 to turn it off | |
1405 | */ | |
1406 | if (xfs_sb_version_hasattr2(&mp->m_sb) && | |
9d565ffa | 1407 | !(mp->m_flags & XFS_MOUNT_NOATTR2)) |
f8f15e42 CH |
1408 | mp->m_flags |= XFS_MOUNT_ATTR2; |
1409 | ||
1410 | /* | |
1411 | * prohibit r/w mounts of read-only filesystems | |
1412 | */ | |
1413 | if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) { | |
4f10700a DC |
1414 | xfs_warn(mp, |
1415 | "cannot mount a read-only filesystem as read-write"); | |
2451337d | 1416 | return -EROFS; |
f8f15e42 CH |
1417 | } |
1418 | ||
d892d586 CS |
1419 | if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) && |
1420 | (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) && | |
1421 | !xfs_sb_version_has_pquotino(&mp->m_sb)) { | |
1422 | xfs_warn(mp, | |
1423 | "Super block does not support project and group quota together"); | |
2451337d | 1424 | return -EINVAL; |
d892d586 CS |
1425 | } |
1426 | ||
f8f15e42 CH |
1427 | return 0; |
1428 | } | |
1429 | ||
5681ca40 DC |
1430 | static int |
1431 | xfs_init_percpu_counters( | |
1432 | struct xfs_mount *mp) | |
1433 | { | |
1434 | int error; | |
1435 | ||
1436 | error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL); | |
1437 | if (error) | |
5e9383f9 | 1438 | return -ENOMEM; |
5681ca40 DC |
1439 | |
1440 | error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL); | |
1441 | if (error) | |
1442 | goto free_icount; | |
1443 | ||
1444 | error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL); | |
1445 | if (error) | |
1446 | goto free_ifree; | |
1447 | ||
1448 | return 0; | |
1449 | ||
1450 | free_ifree: | |
1451 | percpu_counter_destroy(&mp->m_ifree); | |
1452 | free_icount: | |
1453 | percpu_counter_destroy(&mp->m_icount); | |
1454 | return -ENOMEM; | |
1455 | } | |
1456 | ||
1457 | void | |
1458 | xfs_reinit_percpu_counters( | |
1459 | struct xfs_mount *mp) | |
1460 | { | |
1461 | percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount); | |
1462 | percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree); | |
1463 | percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks); | |
1464 | } | |
1465 | ||
1466 | static void | |
1467 | xfs_destroy_percpu_counters( | |
1468 | struct xfs_mount *mp) | |
1469 | { | |
1470 | percpu_counter_destroy(&mp->m_icount); | |
1471 | percpu_counter_destroy(&mp->m_ifree); | |
1472 | percpu_counter_destroy(&mp->m_fdblocks); | |
1473 | } | |
1474 | ||
1da177e4 | 1475 | STATIC int |
a50cd269 | 1476 | xfs_fs_fill_super( |
1da177e4 LT |
1477 | struct super_block *sb, |
1478 | void *data, | |
1479 | int silent) | |
1480 | { | |
f3dcc13f | 1481 | struct inode *root; |
745f6919 | 1482 | struct xfs_mount *mp = NULL; |
2451337d | 1483 | int flags = 0, error = -ENOMEM; |
bdd907ba | 1484 | |
c962fb79 CH |
1485 | mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL); |
1486 | if (!mp) | |
9d565ffa | 1487 | goto out; |
1da177e4 | 1488 | |
c962fb79 | 1489 | spin_lock_init(&mp->m_sb_lock); |
c962fb79 CH |
1490 | mutex_init(&mp->m_growlock); |
1491 | atomic_set(&mp->m_active_trans, 0); | |
7e18530b | 1492 | INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker); |
579b62fa | 1493 | INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker); |
e3aed1a0 | 1494 | mp->m_kobj.kobject.kset = xfs_kset; |
74394496 | 1495 | |
b267ce99 CH |
1496 | mp->m_super = sb; |
1497 | sb->s_fs_info = mp; | |
1da177e4 | 1498 | |
288699fe | 1499 | error = xfs_parseargs(mp, (char *)data); |
745f6919 | 1500 | if (error) |
9d565ffa | 1501 | goto out_free_fsname; |
1da177e4 LT |
1502 | |
1503 | sb_min_blocksize(sb, BBSIZE); | |
0ec58516 | 1504 | sb->s_xattr = xfs_xattr_handlers; |
a50cd269 | 1505 | sb->s_export_op = &xfs_export_operations; |
fcafb71b | 1506 | #ifdef CONFIG_XFS_QUOTA |
a50cd269 | 1507 | sb->s_qcop = &xfs_quotactl_operations; |
17ef4fdd | 1508 | sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ; |
fcafb71b | 1509 | #endif |
a50cd269 | 1510 | sb->s_op = &xfs_super_operations; |
1da177e4 | 1511 | |
9d565ffa | 1512 | if (silent) |
f8f15e42 CH |
1513 | flags |= XFS_MFSI_QUIET; |
1514 | ||
9d565ffa | 1515 | error = xfs_open_devices(mp); |
19f354d4 | 1516 | if (error) |
288699fe | 1517 | goto out_free_fsname; |
f8f15e42 | 1518 | |
2451337d | 1519 | error = xfs_init_mount_workqueues(mp); |
61ba35de CH |
1520 | if (error) |
1521 | goto out_close_devices; | |
c962fb79 | 1522 | |
5681ca40 | 1523 | error = xfs_init_percpu_counters(mp); |
aa6bf01d CH |
1524 | if (error) |
1525 | goto out_destroy_workqueues; | |
1526 | ||
225e4635 BD |
1527 | /* Allocate stats memory before we do operations that might use it */ |
1528 | mp->m_stats.xs_stats = alloc_percpu(struct xfsstats); | |
1529 | if (!mp->m_stats.xs_stats) { | |
f9d460b3 | 1530 | error = -ENOMEM; |
225e4635 BD |
1531 | goto out_destroy_counters; |
1532 | } | |
1533 | ||
f8f15e42 CH |
1534 | error = xfs_readsb(mp, flags); |
1535 | if (error) | |
225e4635 | 1536 | goto out_free_stats; |
9d565ffa CH |
1537 | |
1538 | error = xfs_finish_flags(mp); | |
f8f15e42 | 1539 | if (error) |
effa2eda | 1540 | goto out_free_sb; |
f8f15e42 | 1541 | |
e34b562c | 1542 | error = xfs_setup_devices(mp); |
19f354d4 | 1543 | if (error) |
effa2eda | 1544 | goto out_free_sb; |
f8f15e42 | 1545 | |
f8f15e42 CH |
1546 | error = xfs_filestream_mount(mp); |
1547 | if (error) | |
effa2eda | 1548 | goto out_free_sb; |
f8f15e42 | 1549 | |
704b2907 DC |
1550 | /* |
1551 | * we must configure the block size in the superblock before we run the | |
1552 | * full mount process as the mount process can lookup and cache inodes. | |
704b2907 | 1553 | */ |
4ca488eb CH |
1554 | sb->s_magic = XFS_SB_MAGIC; |
1555 | sb->s_blocksize = mp->m_sb.sb_blocksize; | |
1556 | sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1; | |
1da177e4 | 1557 | sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits); |
8de52778 | 1558 | sb->s_max_links = XFS_MAXLINK; |
1da177e4 LT |
1559 | sb->s_time_gran = 1; |
1560 | set_posix_acl_flag(sb); | |
1561 | ||
dc037ad7 DC |
1562 | /* version 5 superblocks support inode version counters. */ |
1563 | if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5) | |
1564 | sb->s_flags |= MS_I_VERSION; | |
1565 | ||
cbe4dab1 DC |
1566 | if (mp->m_flags & XFS_MOUNT_DAX) { |
1567 | xfs_warn(mp, | |
1e937cdd TK |
1568 | "DAX enabled. Warning: EXPERIMENTAL, use at your own risk"); |
1569 | ||
1570 | error = bdev_dax_supported(sb, sb->s_blocksize); | |
1571 | if (error) { | |
cbe4dab1 | 1572 | xfs_alert(mp, |
1e937cdd | 1573 | "DAX unsupported by block device. Turning off DAX."); |
cbe4dab1 DC |
1574 | mp->m_flags &= ~XFS_MOUNT_DAX; |
1575 | } | |
1576 | } | |
1577 | ||
738f57c1 DW |
1578 | if (xfs_sb_version_hasrmapbt(&mp->m_sb)) { |
1579 | if (mp->m_sb.sb_rblocks) { | |
1580 | xfs_alert(mp, | |
1581 | "EXPERIMENTAL reverse mapping btree not compatible with realtime device!"); | |
1582 | error = -EINVAL; | |
1583 | goto out_filestream_unmount; | |
1584 | } | |
1c0607ac DW |
1585 | xfs_alert(mp, |
1586 | "EXPERIMENTAL reverse mapping btree feature enabled. Use at your own risk!"); | |
738f57c1 | 1587 | } |
1c0607ac | 1588 | |
8a00ebe4 | 1589 | error = xfs_mountfs(mp); |
2bcf6e97 | 1590 | if (error) |
7e18530b | 1591 | goto out_filestream_unmount; |
704b2907 | 1592 | |
01651646 | 1593 | root = igrab(VFS_I(mp->m_rootip)); |
f3dcc13f | 1594 | if (!root) { |
2451337d | 1595 | error = -ENOENT; |
8a00ebe4 | 1596 | goto out_unmount; |
cbc89dcf | 1597 | } |
48fde701 | 1598 | sb->s_root = d_make_root(root); |
f3dcc13f | 1599 | if (!sb->s_root) { |
2451337d | 1600 | error = -ENOMEM; |
8a00ebe4 | 1601 | goto out_unmount; |
1da177e4 | 1602 | } |
74394496 | 1603 | |
1da177e4 | 1604 | return 0; |
33c7a2bc | 1605 | |
7e18530b | 1606 | out_filestream_unmount: |
120226c1 | 1607 | xfs_filestream_unmount(mp); |
effa2eda CH |
1608 | out_free_sb: |
1609 | xfs_freesb(mp); | |
225e4635 BD |
1610 | out_free_stats: |
1611 | free_percpu(mp->m_stats.xs_stats); | |
9d565ffa | 1612 | out_destroy_counters: |
5681ca40 | 1613 | xfs_destroy_percpu_counters(mp); |
225e4635 | 1614 | out_destroy_workqueues: |
aa6bf01d | 1615 | xfs_destroy_mount_workqueues(mp); |
61ba35de | 1616 | out_close_devices: |
19f354d4 | 1617 | xfs_close_devices(mp); |
9d565ffa CH |
1618 | out_free_fsname: |
1619 | xfs_free_fsname(mp); | |
c962fb79 | 1620 | kfree(mp); |
9d565ffa | 1621 | out: |
2451337d | 1622 | return error; |
f8f15e42 | 1623 | |
2bcf6e97 | 1624 | out_unmount: |
e48ad316 | 1625 | xfs_filestream_unmount(mp); |
19f354d4 | 1626 | xfs_unmountfs(mp); |
6203300e | 1627 | goto out_free_sb; |
1da177e4 LT |
1628 | } |
1629 | ||
5681ca40 DC |
1630 | STATIC void |
1631 | xfs_fs_put_super( | |
1632 | struct super_block *sb) | |
1633 | { | |
1634 | struct xfs_mount *mp = XFS_M(sb); | |
1635 | ||
4225441a | 1636 | xfs_notice(mp, "Unmounting Filesystem"); |
5681ca40 DC |
1637 | xfs_filestream_unmount(mp); |
1638 | xfs_unmountfs(mp); | |
1639 | ||
1640 | xfs_freesb(mp); | |
225e4635 | 1641 | free_percpu(mp->m_stats.xs_stats); |
5681ca40 DC |
1642 | xfs_destroy_percpu_counters(mp); |
1643 | xfs_destroy_mount_workqueues(mp); | |
1644 | xfs_close_devices(mp); | |
1645 | xfs_free_fsname(mp); | |
1646 | kfree(mp); | |
1647 | } | |
1648 | ||
152a0836 AV |
1649 | STATIC struct dentry * |
1650 | xfs_fs_mount( | |
1da177e4 LT |
1651 | struct file_system_type *fs_type, |
1652 | int flags, | |
1653 | const char *dev_name, | |
152a0836 | 1654 | void *data) |
1da177e4 | 1655 | { |
152a0836 | 1656 | return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super); |
a50cd269 NS |
1657 | } |
1658 | ||
0a234c6d | 1659 | static long |
8daaa831 | 1660 | xfs_fs_nr_cached_objects( |
9b17c623 | 1661 | struct super_block *sb, |
4101b624 | 1662 | struct shrink_control *sc) |
8daaa831 DC |
1663 | { |
1664 | return xfs_reclaim_inodes_count(XFS_M(sb)); | |
1665 | } | |
1666 | ||
0a234c6d | 1667 | static long |
8daaa831 DC |
1668 | xfs_fs_free_cached_objects( |
1669 | struct super_block *sb, | |
4101b624 | 1670 | struct shrink_control *sc) |
8daaa831 | 1671 | { |
4101b624 | 1672 | return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan); |
8daaa831 DC |
1673 | } |
1674 | ||
b87221de | 1675 | static const struct super_operations xfs_super_operations = { |
a50cd269 NS |
1676 | .alloc_inode = xfs_fs_alloc_inode, |
1677 | .destroy_inode = xfs_fs_destroy_inode, | |
5132ba8f | 1678 | .drop_inode = xfs_fs_drop_inode, |
a50cd269 | 1679 | .put_super = xfs_fs_put_super, |
69961a26 | 1680 | .sync_fs = xfs_fs_sync_fs, |
c4be0c1d | 1681 | .freeze_fs = xfs_fs_freeze, |
d5db0f97 | 1682 | .unfreeze_fs = xfs_fs_unfreeze, |
a50cd269 NS |
1683 | .statfs = xfs_fs_statfs, |
1684 | .remount_fs = xfs_fs_remount, | |
1685 | .show_options = xfs_fs_show_options, | |
8daaa831 DC |
1686 | .nr_cached_objects = xfs_fs_nr_cached_objects, |
1687 | .free_cached_objects = xfs_fs_free_cached_objects, | |
1da177e4 LT |
1688 | }; |
1689 | ||
5085b607 | 1690 | static struct file_system_type xfs_fs_type = { |
1da177e4 LT |
1691 | .owner = THIS_MODULE, |
1692 | .name = "xfs", | |
152a0836 | 1693 | .mount = xfs_fs_mount, |
1da177e4 LT |
1694 | .kill_sb = kill_block_super, |
1695 | .fs_flags = FS_REQUIRES_DEV, | |
1696 | }; | |
7f78e035 | 1697 | MODULE_ALIAS_FS("xfs"); |
1da177e4 | 1698 | |
9f8868ff CH |
1699 | STATIC int __init |
1700 | xfs_init_zones(void) | |
1701 | { | |
0e51a8e1 CH |
1702 | xfs_ioend_bioset = bioset_create(4 * MAX_BUF_PER_PAGE, |
1703 | offsetof(struct xfs_ioend, io_inline_bio)); | |
1704 | if (!xfs_ioend_bioset) | |
bf904248 | 1705 | goto out; |
9f8868ff | 1706 | |
9f8868ff CH |
1707 | xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t), |
1708 | "xfs_log_ticket"); | |
1709 | if (!xfs_log_ticket_zone) | |
0e51a8e1 | 1710 | goto out_free_ioend_bioset; |
9f8868ff | 1711 | |
e66a4c67 | 1712 | xfs_bmap_free_item_zone = kmem_zone_init( |
310a75a3 | 1713 | sizeof(struct xfs_extent_free_item), |
e66a4c67 | 1714 | "xfs_bmap_free_item"); |
9f8868ff CH |
1715 | if (!xfs_bmap_free_item_zone) |
1716 | goto out_destroy_log_ticket_zone; | |
bf904248 | 1717 | |
9f8868ff CH |
1718 | xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t), |
1719 | "xfs_btree_cur"); | |
1720 | if (!xfs_btree_cur_zone) | |
1721 | goto out_destroy_bmap_free_item_zone; | |
1722 | ||
1723 | xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t), | |
1724 | "xfs_da_state"); | |
1725 | if (!xfs_da_state_zone) | |
1726 | goto out_destroy_btree_cur_zone; | |
1727 | ||
9f8868ff CH |
1728 | xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork"); |
1729 | if (!xfs_ifork_zone) | |
1d9025e5 | 1730 | goto out_destroy_da_state_zone; |
9f8868ff CH |
1731 | |
1732 | xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans"); | |
1733 | if (!xfs_trans_zone) | |
1734 | goto out_destroy_ifork_zone; | |
1735 | ||
e98c414f CH |
1736 | xfs_log_item_desc_zone = |
1737 | kmem_zone_init(sizeof(struct xfs_log_item_desc), | |
1738 | "xfs_log_item_desc"); | |
1739 | if (!xfs_log_item_desc_zone) | |
1740 | goto out_destroy_trans_zone; | |
1741 | ||
9f8868ff CH |
1742 | /* |
1743 | * The size of the zone allocated buf log item is the maximum | |
1744 | * size possible under XFS. This wastes a little bit of memory, | |
1745 | * but it is much faster. | |
1746 | */ | |
77c1a08f DC |
1747 | xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item), |
1748 | "xfs_buf_item"); | |
9f8868ff | 1749 | if (!xfs_buf_item_zone) |
e98c414f | 1750 | goto out_destroy_log_item_desc_zone; |
9f8868ff CH |
1751 | |
1752 | xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) + | |
1753 | ((XFS_EFD_MAX_FAST_EXTENTS - 1) * | |
1754 | sizeof(xfs_extent_t))), "xfs_efd_item"); | |
1755 | if (!xfs_efd_zone) | |
1756 | goto out_destroy_buf_item_zone; | |
1757 | ||
1758 | xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) + | |
1759 | ((XFS_EFI_MAX_FAST_EXTENTS - 1) * | |
1760 | sizeof(xfs_extent_t))), "xfs_efi_item"); | |
1761 | if (!xfs_efi_zone) | |
1762 | goto out_destroy_efd_zone; | |
1763 | ||
1764 | xfs_inode_zone = | |
1765 | kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode", | |
5d097056 VD |
1766 | KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD | |
1767 | KM_ZONE_ACCOUNT, xfs_fs_inode_init_once); | |
9f8868ff CH |
1768 | if (!xfs_inode_zone) |
1769 | goto out_destroy_efi_zone; | |
1770 | ||
1771 | xfs_ili_zone = | |
1772 | kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili", | |
1773 | KM_ZONE_SPREAD, NULL); | |
1774 | if (!xfs_ili_zone) | |
1775 | goto out_destroy_inode_zone; | |
3ebe7d2d DC |
1776 | xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item), |
1777 | "xfs_icr"); | |
1778 | if (!xfs_icreate_zone) | |
1779 | goto out_destroy_ili_zone; | |
9f8868ff | 1780 | |
722e2517 | 1781 | xfs_rud_zone = kmem_zone_init(sizeof(struct xfs_rud_log_item), |
5880f2d7 DW |
1782 | "xfs_rud_item"); |
1783 | if (!xfs_rud_zone) | |
1784 | goto out_destroy_icreate_zone; | |
1785 | ||
cd00158c DW |
1786 | xfs_rui_zone = kmem_zone_init( |
1787 | xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS), | |
5880f2d7 DW |
1788 | "xfs_rui_item"); |
1789 | if (!xfs_rui_zone) | |
1790 | goto out_destroy_rud_zone; | |
1791 | ||
baf4bcac DW |
1792 | xfs_cud_zone = kmem_zone_init(sizeof(struct xfs_cud_log_item), |
1793 | "xfs_cud_item"); | |
1794 | if (!xfs_cud_zone) | |
1795 | goto out_destroy_rui_zone; | |
1796 | ||
1797 | xfs_cui_zone = kmem_zone_init( | |
1798 | xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS), | |
1799 | "xfs_cui_item"); | |
1800 | if (!xfs_cui_zone) | |
1801 | goto out_destroy_cud_zone; | |
1802 | ||
9f8868ff CH |
1803 | return 0; |
1804 | ||
baf4bcac DW |
1805 | out_destroy_cud_zone: |
1806 | kmem_zone_destroy(xfs_cud_zone); | |
1807 | out_destroy_rui_zone: | |
1808 | kmem_zone_destroy(xfs_rui_zone); | |
5880f2d7 DW |
1809 | out_destroy_rud_zone: |
1810 | kmem_zone_destroy(xfs_rud_zone); | |
1811 | out_destroy_icreate_zone: | |
1812 | kmem_zone_destroy(xfs_icreate_zone); | |
3ebe7d2d DC |
1813 | out_destroy_ili_zone: |
1814 | kmem_zone_destroy(xfs_ili_zone); | |
9f8868ff CH |
1815 | out_destroy_inode_zone: |
1816 | kmem_zone_destroy(xfs_inode_zone); | |
1817 | out_destroy_efi_zone: | |
1818 | kmem_zone_destroy(xfs_efi_zone); | |
1819 | out_destroy_efd_zone: | |
1820 | kmem_zone_destroy(xfs_efd_zone); | |
1821 | out_destroy_buf_item_zone: | |
1822 | kmem_zone_destroy(xfs_buf_item_zone); | |
e98c414f CH |
1823 | out_destroy_log_item_desc_zone: |
1824 | kmem_zone_destroy(xfs_log_item_desc_zone); | |
9f8868ff CH |
1825 | out_destroy_trans_zone: |
1826 | kmem_zone_destroy(xfs_trans_zone); | |
1827 | out_destroy_ifork_zone: | |
1828 | kmem_zone_destroy(xfs_ifork_zone); | |
9f8868ff CH |
1829 | out_destroy_da_state_zone: |
1830 | kmem_zone_destroy(xfs_da_state_zone); | |
1831 | out_destroy_btree_cur_zone: | |
1832 | kmem_zone_destroy(xfs_btree_cur_zone); | |
1833 | out_destroy_bmap_free_item_zone: | |
1834 | kmem_zone_destroy(xfs_bmap_free_item_zone); | |
1835 | out_destroy_log_ticket_zone: | |
1836 | kmem_zone_destroy(xfs_log_ticket_zone); | |
0e51a8e1 CH |
1837 | out_free_ioend_bioset: |
1838 | bioset_free(xfs_ioend_bioset); | |
9f8868ff CH |
1839 | out: |
1840 | return -ENOMEM; | |
1841 | } | |
1842 | ||
1843 | STATIC void | |
1844 | xfs_destroy_zones(void) | |
1845 | { | |
8c0a8537 KS |
1846 | /* |
1847 | * Make sure all delayed rcu free are flushed before we | |
1848 | * destroy caches. | |
1849 | */ | |
1850 | rcu_barrier(); | |
baf4bcac DW |
1851 | kmem_zone_destroy(xfs_cui_zone); |
1852 | kmem_zone_destroy(xfs_cud_zone); | |
5880f2d7 DW |
1853 | kmem_zone_destroy(xfs_rui_zone); |
1854 | kmem_zone_destroy(xfs_rud_zone); | |
3ebe7d2d | 1855 | kmem_zone_destroy(xfs_icreate_zone); |
9f8868ff CH |
1856 | kmem_zone_destroy(xfs_ili_zone); |
1857 | kmem_zone_destroy(xfs_inode_zone); | |
1858 | kmem_zone_destroy(xfs_efi_zone); | |
1859 | kmem_zone_destroy(xfs_efd_zone); | |
1860 | kmem_zone_destroy(xfs_buf_item_zone); | |
e98c414f | 1861 | kmem_zone_destroy(xfs_log_item_desc_zone); |
9f8868ff CH |
1862 | kmem_zone_destroy(xfs_trans_zone); |
1863 | kmem_zone_destroy(xfs_ifork_zone); | |
9f8868ff CH |
1864 | kmem_zone_destroy(xfs_da_state_zone); |
1865 | kmem_zone_destroy(xfs_btree_cur_zone); | |
1866 | kmem_zone_destroy(xfs_bmap_free_item_zone); | |
1867 | kmem_zone_destroy(xfs_log_ticket_zone); | |
0e51a8e1 | 1868 | bioset_free(xfs_ioend_bioset); |
9f8868ff | 1869 | } |
1da177e4 | 1870 | |
0bf6a5bd DC |
1871 | STATIC int __init |
1872 | xfs_init_workqueues(void) | |
1873 | { | |
c999a223 DC |
1874 | /* |
1875 | * The allocation workqueue can be used in memory reclaim situations | |
1876 | * (writepage path), and parallelism is only limited by the number of | |
1877 | * AGs in all the filesystems mounted. Hence use the default large | |
1878 | * max_active value for this workqueue. | |
1879 | */ | |
8018ec08 BF |
1880 | xfs_alloc_wq = alloc_workqueue("xfsalloc", |
1881 | WQ_MEM_RECLAIM|WQ_FREEZABLE, 0); | |
c999a223 | 1882 | if (!xfs_alloc_wq) |
5889608d | 1883 | return -ENOMEM; |
c999a223 | 1884 | |
0bf6a5bd | 1885 | return 0; |
0bf6a5bd DC |
1886 | } |
1887 | ||
39411f81 | 1888 | STATIC void |
0bf6a5bd DC |
1889 | xfs_destroy_workqueues(void) |
1890 | { | |
c999a223 | 1891 | destroy_workqueue(xfs_alloc_wq); |
0bf6a5bd DC |
1892 | } |
1893 | ||
1da177e4 | 1894 | STATIC int __init |
9f8868ff | 1895 | init_xfs_fs(void) |
1da177e4 LT |
1896 | { |
1897 | int error; | |
1da177e4 | 1898 | |
30cbc591 DW |
1899 | xfs_check_ondisk_structs(); |
1900 | ||
65795910 CH |
1901 | printk(KERN_INFO XFS_VERSION_STRING " with " |
1902 | XFS_BUILD_OPTIONS " enabled\n"); | |
1da177e4 | 1903 | |
9749fee8 | 1904 | xfs_extent_free_init_defer_op(); |
f8dbebef | 1905 | xfs_rmap_update_init_defer_op(); |
33ba6129 | 1906 | xfs_refcount_update_init_defer_op(); |
9749fee8 | 1907 | |
9f8868ff | 1908 | xfs_dir_startup(); |
1da177e4 | 1909 | |
8758280f | 1910 | error = xfs_init_zones(); |
9f8868ff CH |
1911 | if (error) |
1912 | goto out; | |
1913 | ||
0bf6a5bd | 1914 | error = xfs_init_workqueues(); |
9f8868ff | 1915 | if (error) |
0b1b213f | 1916 | goto out_destroy_zones; |
9f8868ff | 1917 | |
0bf6a5bd DC |
1918 | error = xfs_mru_cache_init(); |
1919 | if (error) | |
1920 | goto out_destroy_wq; | |
1921 | ||
ce8e922c | 1922 | error = xfs_buf_init(); |
9f8868ff | 1923 | if (error) |
1919adda | 1924 | goto out_mru_cache_uninit; |
9f8868ff CH |
1925 | |
1926 | error = xfs_init_procfs(); | |
1927 | if (error) | |
1928 | goto out_buf_terminate; | |
1929 | ||
1930 | error = xfs_sysctl_register(); | |
1931 | if (error) | |
1932 | goto out_cleanup_procfs; | |
1da177e4 | 1933 | |
3d871226 BF |
1934 | xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj); |
1935 | if (!xfs_kset) { | |
1936 | error = -ENOMEM; | |
bb230c12 | 1937 | goto out_sysctl_unregister; |
3d871226 BF |
1938 | } |
1939 | ||
80529c45 BD |
1940 | xfsstats.xs_kobj.kobject.kset = xfs_kset; |
1941 | ||
1942 | xfsstats.xs_stats = alloc_percpu(struct xfsstats); | |
1943 | if (!xfsstats.xs_stats) { | |
1944 | error = -ENOMEM; | |
1945 | goto out_kset_unregister; | |
1946 | } | |
1947 | ||
1948 | error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL, | |
bb230c12 BD |
1949 | "stats"); |
1950 | if (error) | |
80529c45 | 1951 | goto out_free_stats; |
bb230c12 | 1952 | |
65b65735 BF |
1953 | #ifdef DEBUG |
1954 | xfs_dbg_kobj.kobject.kset = xfs_kset; | |
1955 | error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug"); | |
a05931ce | 1956 | if (error) |
bb230c12 | 1957 | goto out_remove_stats_kobj; |
65b65735 BF |
1958 | #endif |
1959 | ||
1960 | error = xfs_qm_init(); | |
1961 | if (error) | |
bb230c12 | 1962 | goto out_remove_dbg_kobj; |
1da177e4 LT |
1963 | |
1964 | error = register_filesystem(&xfs_fs_type); | |
1965 | if (error) | |
a05931ce | 1966 | goto out_qm_exit; |
1da177e4 LT |
1967 | return 0; |
1968 | ||
a05931ce CH |
1969 | out_qm_exit: |
1970 | xfs_qm_exit(); | |
bb230c12 | 1971 | out_remove_dbg_kobj: |
65b65735 BF |
1972 | #ifdef DEBUG |
1973 | xfs_sysfs_del(&xfs_dbg_kobj); | |
bb230c12 | 1974 | out_remove_stats_kobj: |
65b65735 | 1975 | #endif |
80529c45 BD |
1976 | xfs_sysfs_del(&xfsstats.xs_kobj); |
1977 | out_free_stats: | |
1978 | free_percpu(xfsstats.xs_stats); | |
bb230c12 | 1979 | out_kset_unregister: |
3d871226 | 1980 | kset_unregister(xfs_kset); |
9f8868ff CH |
1981 | out_sysctl_unregister: |
1982 | xfs_sysctl_unregister(); | |
1983 | out_cleanup_procfs: | |
1984 | xfs_cleanup_procfs(); | |
1985 | out_buf_terminate: | |
ce8e922c | 1986 | xfs_buf_terminate(); |
9f8868ff CH |
1987 | out_mru_cache_uninit: |
1988 | xfs_mru_cache_uninit(); | |
0bf6a5bd DC |
1989 | out_destroy_wq: |
1990 | xfs_destroy_workqueues(); | |
9f8868ff | 1991 | out_destroy_zones: |
8758280f | 1992 | xfs_destroy_zones(); |
9f8868ff | 1993 | out: |
1da177e4 LT |
1994 | return error; |
1995 | } | |
1996 | ||
1997 | STATIC void __exit | |
9f8868ff | 1998 | exit_xfs_fs(void) |
1da177e4 | 1999 | { |
a05931ce | 2000 | xfs_qm_exit(); |
1da177e4 | 2001 | unregister_filesystem(&xfs_fs_type); |
65b65735 BF |
2002 | #ifdef DEBUG |
2003 | xfs_sysfs_del(&xfs_dbg_kobj); | |
2004 | #endif | |
80529c45 BD |
2005 | xfs_sysfs_del(&xfsstats.xs_kobj); |
2006 | free_percpu(xfsstats.xs_stats); | |
3d871226 | 2007 | kset_unregister(xfs_kset); |
9f8868ff CH |
2008 | xfs_sysctl_unregister(); |
2009 | xfs_cleanup_procfs(); | |
ce8e922c | 2010 | xfs_buf_terminate(); |
9f8868ff | 2011 | xfs_mru_cache_uninit(); |
0bf6a5bd | 2012 | xfs_destroy_workqueues(); |
8758280f | 2013 | xfs_destroy_zones(); |
af3b6382 | 2014 | xfs_uuid_table_free(); |
1da177e4 LT |
2015 | } |
2016 | ||
2017 | module_init(init_xfs_fs); | |
2018 | module_exit(exit_xfs_fs); | |
2019 | ||
2020 | MODULE_AUTHOR("Silicon Graphics, Inc."); | |
2021 | MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled"); | |
2022 | MODULE_LICENSE("GPL"); |