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