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 | */ |
1da177e4 | 18 | #include "xfs.h" |
a844f451 | 19 | #include "xfs_bit.h" |
1da177e4 LT |
20 | #include "xfs_log.h" |
21 | #include "xfs_clnt.h" | |
a844f451 | 22 | #include "xfs_inum.h" |
1da177e4 LT |
23 | #include "xfs_trans.h" |
24 | #include "xfs_sb.h" | |
a844f451 | 25 | #include "xfs_ag.h" |
1da177e4 LT |
26 | #include "xfs_dir2.h" |
27 | #include "xfs_alloc.h" | |
28 | #include "xfs_dmapi.h" | |
29 | #include "xfs_quota.h" | |
30 | #include "xfs_mount.h" | |
1da177e4 | 31 | #include "xfs_bmap_btree.h" |
a844f451 | 32 | #include "xfs_alloc_btree.h" |
1da177e4 | 33 | #include "xfs_ialloc_btree.h" |
1da177e4 | 34 | #include "xfs_dir2_sf.h" |
a844f451 | 35 | #include "xfs_attr_sf.h" |
1da177e4 LT |
36 | #include "xfs_dinode.h" |
37 | #include "xfs_inode.h" | |
a844f451 NS |
38 | #include "xfs_btree.h" |
39 | #include "xfs_ialloc.h" | |
1da177e4 | 40 | #include "xfs_bmap.h" |
1da177e4 LT |
41 | #include "xfs_rtalloc.h" |
42 | #include "xfs_error.h" | |
43 | #include "xfs_itable.h" | |
9909c4aa | 44 | #include "xfs_fsops.h" |
1da177e4 LT |
45 | #include "xfs_rw.h" |
46 | #include "xfs_acl.h" | |
1da177e4 LT |
47 | #include "xfs_attr.h" |
48 | #include "xfs_buf_item.h" | |
49 | #include "xfs_utils.h" | |
739bfb2a | 50 | #include "xfs_vnodeops.h" |
745f6919 | 51 | #include "xfs_vfsops.h" |
1da177e4 | 52 | #include "xfs_version.h" |
a67d7c5f | 53 | #include "xfs_log_priv.h" |
249a8c11 | 54 | #include "xfs_trans_priv.h" |
48b62a1a | 55 | #include "xfs_filestream.h" |
9f8868ff CH |
56 | #include "xfs_da_btree.h" |
57 | #include "xfs_dir2_trace.h" | |
58 | #include "xfs_extfree_item.h" | |
59 | #include "xfs_mru_cache.h" | |
60 | #include "xfs_inode_item.h" | |
1da177e4 LT |
61 | |
62 | #include <linux/namei.h> | |
63 | #include <linux/init.h> | |
64 | #include <linux/mount.h> | |
0829c360 | 65 | #include <linux/mempool.h> |
1da177e4 | 66 | #include <linux/writeback.h> |
4df08c52 | 67 | #include <linux/kthread.h> |
7dfb7103 | 68 | #include <linux/freezer.h> |
62a877e3 | 69 | #include <linux/parser.h> |
1da177e4 | 70 | |
7989cb8e DC |
71 | static struct quotactl_ops xfs_quotactl_operations; |
72 | static struct super_operations xfs_super_operations; | |
73 | static kmem_zone_t *xfs_vnode_zone; | |
74 | static kmem_zone_t *xfs_ioend_zone; | |
0829c360 | 75 | mempool_t *xfs_ioend_pool; |
1da177e4 LT |
76 | |
77 | STATIC struct xfs_mount_args * | |
78 | xfs_args_allocate( | |
764d1f89 NS |
79 | struct super_block *sb, |
80 | int silent) | |
1da177e4 LT |
81 | { |
82 | struct xfs_mount_args *args; | |
83 | ||
bdd907ba CH |
84 | args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL); |
85 | if (!args) | |
86 | return NULL; | |
87 | ||
1da177e4 LT |
88 | args->logbufs = args->logbufsize = -1; |
89 | strncpy(args->fsname, sb->s_id, MAXNAMELEN); | |
90 | ||
91 | /* Copy the already-parsed mount(2) flags we're interested in */ | |
1da177e4 LT |
92 | if (sb->s_flags & MS_DIRSYNC) |
93 | args->flags |= XFSMNT_DIRSYNC; | |
94 | if (sb->s_flags & MS_SYNCHRONOUS) | |
95 | args->flags |= XFSMNT_WSYNC; | |
764d1f89 NS |
96 | if (silent) |
97 | args->flags |= XFSMNT_QUIET; | |
1da177e4 LT |
98 | args->flags |= XFSMNT_32BITINODES; |
99 | ||
100 | return args; | |
101 | } | |
102 | ||
a67d7c5f DC |
103 | #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */ |
104 | #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */ | |
105 | #define MNTOPT_LOGDEV "logdev" /* log device */ | |
106 | #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */ | |
107 | #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */ | |
108 | #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */ | |
109 | #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */ | |
110 | #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */ | |
111 | #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */ | |
112 | #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */ | |
113 | #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */ | |
114 | #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */ | |
115 | #define MNTOPT_MTPT "mtpt" /* filesystem mount point */ | |
116 | #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */ | |
117 | #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */ | |
118 | #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */ | |
119 | #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */ | |
120 | #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */ | |
121 | #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */ | |
122 | #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and | |
123 | * unwritten extent conversion */ | |
124 | #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */ | |
125 | #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */ | |
126 | #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */ | |
127 | #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */ | |
128 | #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */ | |
129 | #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */ | |
130 | #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes | |
131 | * in stat(). */ | |
132 | #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */ | |
133 | #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */ | |
134 | #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */ | |
135 | #define MNTOPT_QUOTA "quota" /* disk quotas (user) */ | |
136 | #define MNTOPT_NOQUOTA "noquota" /* no quotas */ | |
137 | #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */ | |
138 | #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */ | |
139 | #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */ | |
140 | #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */ | |
141 | #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */ | |
142 | #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */ | |
143 | #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */ | |
144 | #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */ | |
145 | #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */ | |
146 | #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */ | |
147 | #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */ | |
148 | #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */ | |
149 | #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */ | |
150 | ||
62a877e3 CH |
151 | /* |
152 | * Table driven mount option parser. | |
153 | * | |
154 | * Currently only used for remount, but it will be used for mount | |
155 | * in the future, too. | |
156 | */ | |
157 | enum { | |
158 | Opt_barrier, Opt_nobarrier, Opt_err | |
159 | }; | |
160 | ||
161 | static match_table_t tokens = { | |
162 | {Opt_barrier, "barrier"}, | |
163 | {Opt_nobarrier, "nobarrier"}, | |
164 | {Opt_err, NULL} | |
165 | }; | |
166 | ||
167 | ||
a67d7c5f DC |
168 | STATIC unsigned long |
169 | suffix_strtoul(char *s, char **endp, unsigned int base) | |
170 | { | |
171 | int last, shift_left_factor = 0; | |
172 | char *value = s; | |
173 | ||
174 | last = strlen(value) - 1; | |
175 | if (value[last] == 'K' || value[last] == 'k') { | |
176 | shift_left_factor = 10; | |
177 | value[last] = '\0'; | |
178 | } | |
179 | if (value[last] == 'M' || value[last] == 'm') { | |
180 | shift_left_factor = 20; | |
181 | value[last] = '\0'; | |
182 | } | |
183 | if (value[last] == 'G' || value[last] == 'g') { | |
184 | shift_left_factor = 30; | |
185 | value[last] = '\0'; | |
186 | } | |
187 | ||
188 | return simple_strtoul((const char *)s, endp, base) << shift_left_factor; | |
189 | } | |
190 | ||
191 | STATIC int | |
192 | xfs_parseargs( | |
193 | struct xfs_mount *mp, | |
194 | char *options, | |
195 | struct xfs_mount_args *args, | |
196 | int update) | |
197 | { | |
198 | char *this_char, *value, *eov; | |
199 | int dsunit, dswidth, vol_dsunit, vol_dswidth; | |
200 | int iosize; | |
1bd960ee | 201 | int dmapi_implies_ikeep = 1; |
a67d7c5f DC |
202 | |
203 | args->flags |= XFSMNT_BARRIER; | |
204 | args->flags2 |= XFSMNT2_COMPAT_IOSIZE; | |
205 | ||
206 | if (!options) | |
207 | goto done; | |
208 | ||
209 | iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0; | |
210 | ||
211 | while ((this_char = strsep(&options, ",")) != NULL) { | |
212 | if (!*this_char) | |
213 | continue; | |
214 | if ((value = strchr(this_char, '=')) != NULL) | |
215 | *value++ = 0; | |
216 | ||
217 | if (!strcmp(this_char, MNTOPT_LOGBUFS)) { | |
218 | if (!value || !*value) { | |
219 | cmn_err(CE_WARN, | |
220 | "XFS: %s option requires an argument", | |
221 | this_char); | |
222 | return EINVAL; | |
223 | } | |
224 | args->logbufs = simple_strtoul(value, &eov, 10); | |
225 | } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) { | |
226 | if (!value || !*value) { | |
227 | cmn_err(CE_WARN, | |
228 | "XFS: %s option requires an argument", | |
229 | this_char); | |
230 | return EINVAL; | |
231 | } | |
232 | args->logbufsize = suffix_strtoul(value, &eov, 10); | |
233 | } else if (!strcmp(this_char, MNTOPT_LOGDEV)) { | |
234 | if (!value || !*value) { | |
235 | cmn_err(CE_WARN, | |
236 | "XFS: %s option requires an argument", | |
237 | this_char); | |
238 | return EINVAL; | |
239 | } | |
240 | strncpy(args->logname, value, MAXNAMELEN); | |
241 | } else if (!strcmp(this_char, MNTOPT_MTPT)) { | |
242 | if (!value || !*value) { | |
243 | cmn_err(CE_WARN, | |
244 | "XFS: %s option requires an argument", | |
245 | this_char); | |
246 | return EINVAL; | |
247 | } | |
248 | strncpy(args->mtpt, value, MAXNAMELEN); | |
249 | } else if (!strcmp(this_char, MNTOPT_RTDEV)) { | |
250 | if (!value || !*value) { | |
251 | cmn_err(CE_WARN, | |
252 | "XFS: %s option requires an argument", | |
253 | this_char); | |
254 | return EINVAL; | |
255 | } | |
256 | strncpy(args->rtname, value, MAXNAMELEN); | |
257 | } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) { | |
258 | if (!value || !*value) { | |
259 | cmn_err(CE_WARN, | |
260 | "XFS: %s option requires an argument", | |
261 | this_char); | |
262 | return EINVAL; | |
263 | } | |
264 | iosize = simple_strtoul(value, &eov, 10); | |
265 | args->flags |= XFSMNT_IOSIZE; | |
266 | args->iosizelog = (uint8_t) iosize; | |
267 | } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) { | |
268 | if (!value || !*value) { | |
269 | cmn_err(CE_WARN, | |
270 | "XFS: %s option requires an argument", | |
271 | this_char); | |
272 | return EINVAL; | |
273 | } | |
274 | iosize = suffix_strtoul(value, &eov, 10); | |
275 | args->flags |= XFSMNT_IOSIZE; | |
276 | args->iosizelog = ffs(iosize) - 1; | |
277 | } else if (!strcmp(this_char, MNTOPT_GRPID) || | |
278 | !strcmp(this_char, MNTOPT_BSDGROUPS)) { | |
279 | mp->m_flags |= XFS_MOUNT_GRPID; | |
280 | } else if (!strcmp(this_char, MNTOPT_NOGRPID) || | |
281 | !strcmp(this_char, MNTOPT_SYSVGROUPS)) { | |
282 | mp->m_flags &= ~XFS_MOUNT_GRPID; | |
283 | } else if (!strcmp(this_char, MNTOPT_WSYNC)) { | |
284 | args->flags |= XFSMNT_WSYNC; | |
285 | } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) { | |
286 | args->flags |= XFSMNT_OSYNCISOSYNC; | |
287 | } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) { | |
288 | args->flags |= XFSMNT_NORECOVERY; | |
289 | } else if (!strcmp(this_char, MNTOPT_INO64)) { | |
290 | args->flags |= XFSMNT_INO64; | |
291 | #if !XFS_BIG_INUMS | |
292 | cmn_err(CE_WARN, | |
293 | "XFS: %s option not allowed on this system", | |
294 | this_char); | |
295 | return EINVAL; | |
296 | #endif | |
297 | } else if (!strcmp(this_char, MNTOPT_NOALIGN)) { | |
298 | args->flags |= XFSMNT_NOALIGN; | |
299 | } else if (!strcmp(this_char, MNTOPT_SWALLOC)) { | |
300 | args->flags |= XFSMNT_SWALLOC; | |
301 | } else if (!strcmp(this_char, MNTOPT_SUNIT)) { | |
302 | if (!value || !*value) { | |
303 | cmn_err(CE_WARN, | |
304 | "XFS: %s option requires an argument", | |
305 | this_char); | |
306 | return EINVAL; | |
307 | } | |
308 | dsunit = simple_strtoul(value, &eov, 10); | |
309 | } else if (!strcmp(this_char, MNTOPT_SWIDTH)) { | |
310 | if (!value || !*value) { | |
311 | cmn_err(CE_WARN, | |
312 | "XFS: %s option requires an argument", | |
313 | this_char); | |
314 | return EINVAL; | |
315 | } | |
316 | dswidth = simple_strtoul(value, &eov, 10); | |
317 | } else if (!strcmp(this_char, MNTOPT_64BITINODE)) { | |
318 | args->flags &= ~XFSMNT_32BITINODES; | |
319 | #if !XFS_BIG_INUMS | |
320 | cmn_err(CE_WARN, | |
321 | "XFS: %s option not allowed on this system", | |
322 | this_char); | |
323 | return EINVAL; | |
324 | #endif | |
325 | } else if (!strcmp(this_char, MNTOPT_NOUUID)) { | |
326 | args->flags |= XFSMNT_NOUUID; | |
327 | } else if (!strcmp(this_char, MNTOPT_BARRIER)) { | |
328 | args->flags |= XFSMNT_BARRIER; | |
329 | } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) { | |
330 | args->flags &= ~XFSMNT_BARRIER; | |
331 | } else if (!strcmp(this_char, MNTOPT_IKEEP)) { | |
1bd960ee | 332 | args->flags |= XFSMNT_IKEEP; |
a67d7c5f | 333 | } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) { |
1bd960ee JJS |
334 | dmapi_implies_ikeep = 0; |
335 | args->flags &= ~XFSMNT_IKEEP; | |
a67d7c5f DC |
336 | } else if (!strcmp(this_char, MNTOPT_LARGEIO)) { |
337 | args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE; | |
338 | } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) { | |
339 | args->flags2 |= XFSMNT2_COMPAT_IOSIZE; | |
340 | } else if (!strcmp(this_char, MNTOPT_ATTR2)) { | |
341 | args->flags |= XFSMNT_ATTR2; | |
342 | } else if (!strcmp(this_char, MNTOPT_NOATTR2)) { | |
343 | args->flags &= ~XFSMNT_ATTR2; | |
7c12f296 | 344 | args->flags |= XFSMNT_NOATTR2; |
a67d7c5f DC |
345 | } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) { |
346 | args->flags2 |= XFSMNT2_FILESTREAMS; | |
347 | } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) { | |
348 | args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA); | |
349 | args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA); | |
350 | } else if (!strcmp(this_char, MNTOPT_QUOTA) || | |
351 | !strcmp(this_char, MNTOPT_UQUOTA) || | |
352 | !strcmp(this_char, MNTOPT_USRQUOTA)) { | |
353 | args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF; | |
354 | } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) || | |
355 | !strcmp(this_char, MNTOPT_UQUOTANOENF)) { | |
356 | args->flags |= XFSMNT_UQUOTA; | |
357 | args->flags &= ~XFSMNT_UQUOTAENF; | |
358 | } else if (!strcmp(this_char, MNTOPT_PQUOTA) || | |
359 | !strcmp(this_char, MNTOPT_PRJQUOTA)) { | |
360 | args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF; | |
361 | } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) { | |
362 | args->flags |= XFSMNT_PQUOTA; | |
363 | args->flags &= ~XFSMNT_PQUOTAENF; | |
364 | } else if (!strcmp(this_char, MNTOPT_GQUOTA) || | |
365 | !strcmp(this_char, MNTOPT_GRPQUOTA)) { | |
366 | args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF; | |
367 | } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) { | |
368 | args->flags |= XFSMNT_GQUOTA; | |
369 | args->flags &= ~XFSMNT_GQUOTAENF; | |
370 | } else if (!strcmp(this_char, MNTOPT_DMAPI)) { | |
371 | args->flags |= XFSMNT_DMAPI; | |
372 | } else if (!strcmp(this_char, MNTOPT_XDSM)) { | |
373 | args->flags |= XFSMNT_DMAPI; | |
374 | } else if (!strcmp(this_char, MNTOPT_DMI)) { | |
375 | args->flags |= XFSMNT_DMAPI; | |
376 | } else if (!strcmp(this_char, "ihashsize")) { | |
377 | cmn_err(CE_WARN, | |
378 | "XFS: ihashsize no longer used, option is deprecated."); | |
379 | } else if (!strcmp(this_char, "osyncisdsync")) { | |
380 | /* no-op, this is now the default */ | |
381 | cmn_err(CE_WARN, | |
382 | "XFS: osyncisdsync is now the default, option is deprecated."); | |
383 | } else if (!strcmp(this_char, "irixsgid")) { | |
384 | cmn_err(CE_WARN, | |
385 | "XFS: irixsgid is now a sysctl(2) variable, option is deprecated."); | |
386 | } else { | |
387 | cmn_err(CE_WARN, | |
388 | "XFS: unknown mount option [%s].", this_char); | |
389 | return EINVAL; | |
390 | } | |
391 | } | |
392 | ||
393 | if (args->flags & XFSMNT_NORECOVERY) { | |
394 | if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) { | |
395 | cmn_err(CE_WARN, | |
396 | "XFS: no-recovery mounts must be read-only."); | |
397 | return EINVAL; | |
398 | } | |
399 | } | |
400 | ||
401 | if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) { | |
402 | cmn_err(CE_WARN, | |
403 | "XFS: sunit and swidth options incompatible with the noalign option"); | |
404 | return EINVAL; | |
405 | } | |
406 | ||
407 | if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) { | |
408 | cmn_err(CE_WARN, | |
409 | "XFS: cannot mount with both project and group quota"); | |
410 | return EINVAL; | |
411 | } | |
412 | ||
413 | if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') { | |
414 | printk("XFS: %s option needs the mount point option as well\n", | |
415 | MNTOPT_DMAPI); | |
416 | return EINVAL; | |
417 | } | |
418 | ||
419 | if ((dsunit && !dswidth) || (!dsunit && dswidth)) { | |
420 | cmn_err(CE_WARN, | |
421 | "XFS: sunit and swidth must be specified together"); | |
422 | return EINVAL; | |
423 | } | |
424 | ||
425 | if (dsunit && (dswidth % dsunit != 0)) { | |
426 | cmn_err(CE_WARN, | |
427 | "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)", | |
428 | dswidth, dsunit); | |
429 | return EINVAL; | |
430 | } | |
431 | ||
432 | /* | |
433 | * Applications using DMI filesystems often expect the | |
434 | * inode generation number to be monotonically increasing. | |
435 | * If we delete inode chunks we break this assumption, so | |
436 | * keep unused inode chunks on disk for DMI filesystems | |
437 | * until we come up with a better solution. | |
438 | * Note that if "ikeep" or "noikeep" mount options are | |
439 | * supplied, then they are honored. | |
440 | */ | |
1bd960ee JJS |
441 | if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep) |
442 | args->flags |= XFSMNT_IKEEP; | |
a67d7c5f DC |
443 | |
444 | if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { | |
445 | if (dsunit) { | |
446 | args->sunit = dsunit; | |
447 | args->flags |= XFSMNT_RETERR; | |
448 | } else { | |
449 | args->sunit = vol_dsunit; | |
450 | } | |
451 | dswidth ? (args->swidth = dswidth) : | |
452 | (args->swidth = vol_dswidth); | |
453 | } else { | |
454 | args->sunit = args->swidth = 0; | |
455 | } | |
456 | ||
457 | done: | |
458 | if (args->flags & XFSMNT_32BITINODES) | |
459 | mp->m_flags |= XFS_MOUNT_SMALL_INUMS; | |
460 | if (args->flags2) | |
461 | args->flags |= XFSMNT_FLAGS2; | |
462 | return 0; | |
463 | } | |
464 | ||
465 | struct proc_xfs_info { | |
466 | int flag; | |
467 | char *str; | |
468 | }; | |
469 | ||
470 | STATIC int | |
471 | xfs_showargs( | |
472 | struct xfs_mount *mp, | |
473 | struct seq_file *m) | |
474 | { | |
475 | static struct proc_xfs_info xfs_info_set[] = { | |
476 | /* the few simple ones we can get from the mount struct */ | |
1bd960ee | 477 | { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP }, |
a67d7c5f DC |
478 | { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC }, |
479 | { XFS_MOUNT_INO64, "," MNTOPT_INO64 }, | |
480 | { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN }, | |
481 | { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC }, | |
482 | { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID }, | |
483 | { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY }, | |
484 | { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC }, | |
485 | { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 }, | |
486 | { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM }, | |
487 | { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI }, | |
488 | { XFS_MOUNT_GRPID, "," MNTOPT_GRPID }, | |
489 | { 0, NULL } | |
490 | }; | |
491 | static struct proc_xfs_info xfs_info_unset[] = { | |
492 | /* the few simple ones we can get from the mount struct */ | |
a67d7c5f DC |
493 | { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO }, |
494 | { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER }, | |
495 | { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE }, | |
496 | { 0, NULL } | |
497 | }; | |
498 | struct proc_xfs_info *xfs_infop; | |
499 | ||
500 | for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) { | |
501 | if (mp->m_flags & xfs_infop->flag) | |
502 | seq_puts(m, xfs_infop->str); | |
503 | } | |
504 | for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) { | |
505 | if (!(mp->m_flags & xfs_infop->flag)) | |
506 | seq_puts(m, xfs_infop->str); | |
507 | } | |
508 | ||
509 | if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE) | |
510 | seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk", | |
511 | (int)(1 << mp->m_writeio_log) >> 10); | |
512 | ||
513 | if (mp->m_logbufs > 0) | |
514 | seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs); | |
515 | if (mp->m_logbsize > 0) | |
516 | seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10); | |
517 | ||
518 | if (mp->m_logname) | |
519 | seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname); | |
520 | if (mp->m_rtname) | |
521 | seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname); | |
522 | ||
523 | if (mp->m_dalign > 0) | |
524 | seq_printf(m, "," MNTOPT_SUNIT "=%d", | |
525 | (int)XFS_FSB_TO_BB(mp, mp->m_dalign)); | |
526 | if (mp->m_swidth > 0) | |
527 | seq_printf(m, "," MNTOPT_SWIDTH "=%d", | |
528 | (int)XFS_FSB_TO_BB(mp, mp->m_swidth)); | |
529 | ||
530 | if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD)) | |
531 | seq_puts(m, "," MNTOPT_USRQUOTA); | |
532 | else if (mp->m_qflags & XFS_UQUOTA_ACCT) | |
533 | seq_puts(m, "," MNTOPT_UQUOTANOENF); | |
534 | ||
535 | if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD)) | |
536 | seq_puts(m, "," MNTOPT_PRJQUOTA); | |
537 | else if (mp->m_qflags & XFS_PQUOTA_ACCT) | |
538 | seq_puts(m, "," MNTOPT_PQUOTANOENF); | |
539 | ||
540 | if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD)) | |
541 | seq_puts(m, "," MNTOPT_GRPQUOTA); | |
542 | else if (mp->m_qflags & XFS_GQUOTA_ACCT) | |
543 | seq_puts(m, "," MNTOPT_GQUOTANOENF); | |
544 | ||
545 | if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT)) | |
546 | seq_puts(m, "," MNTOPT_NOQUOTA); | |
547 | ||
548 | return 0; | |
549 | } | |
1da177e4 LT |
550 | __uint64_t |
551 | xfs_max_file_offset( | |
552 | unsigned int blockshift) | |
553 | { | |
554 | unsigned int pagefactor = 1; | |
555 | unsigned int bitshift = BITS_PER_LONG - 1; | |
556 | ||
557 | /* Figure out maximum filesize, on Linux this can depend on | |
558 | * the filesystem blocksize (on 32 bit platforms). | |
559 | * __block_prepare_write does this in an [unsigned] long... | |
560 | * page->index << (PAGE_CACHE_SHIFT - bbits) | |
561 | * So, for page sized blocks (4K on 32 bit platforms), | |
562 | * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is | |
563 | * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) | |
564 | * but for smaller blocksizes it is less (bbits = log2 bsize). | |
565 | * Note1: get_block_t takes a long (implicit cast from above) | |
566 | * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch | |
567 | * can optionally convert the [unsigned] long from above into | |
568 | * an [unsigned] long long. | |
569 | */ | |
570 | ||
571 | #if BITS_PER_LONG == 32 | |
572 | # if defined(CONFIG_LBD) | |
573 | ASSERT(sizeof(sector_t) == 8); | |
574 | pagefactor = PAGE_CACHE_SIZE; | |
575 | bitshift = BITS_PER_LONG; | |
576 | # else | |
577 | pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift); | |
578 | # endif | |
579 | #endif | |
580 | ||
581 | return (((__uint64_t)pagefactor) << bitshift) - 1; | |
582 | } | |
583 | ||
1da177e4 LT |
584 | int |
585 | xfs_blkdev_get( | |
586 | xfs_mount_t *mp, | |
587 | const char *name, | |
588 | struct block_device **bdevp) | |
589 | { | |
590 | int error = 0; | |
591 | ||
592 | *bdevp = open_bdev_excl(name, 0, mp); | |
593 | if (IS_ERR(*bdevp)) { | |
594 | error = PTR_ERR(*bdevp); | |
595 | printk("XFS: Invalid device [%s], error=%d\n", name, error); | |
596 | } | |
597 | ||
598 | return -error; | |
599 | } | |
600 | ||
601 | void | |
602 | xfs_blkdev_put( | |
603 | struct block_device *bdev) | |
604 | { | |
605 | if (bdev) | |
606 | close_bdev_excl(bdev); | |
607 | } | |
608 | ||
f538d4da CH |
609 | /* |
610 | * Try to write out the superblock using barriers. | |
611 | */ | |
612 | STATIC int | |
613 | xfs_barrier_test( | |
614 | xfs_mount_t *mp) | |
615 | { | |
616 | xfs_buf_t *sbp = xfs_getsb(mp, 0); | |
617 | int error; | |
618 | ||
619 | XFS_BUF_UNDONE(sbp); | |
620 | XFS_BUF_UNREAD(sbp); | |
621 | XFS_BUF_UNDELAYWRITE(sbp); | |
622 | XFS_BUF_WRITE(sbp); | |
623 | XFS_BUF_UNASYNC(sbp); | |
624 | XFS_BUF_ORDERED(sbp); | |
625 | ||
626 | xfsbdstrat(mp, sbp); | |
627 | error = xfs_iowait(sbp); | |
628 | ||
629 | /* | |
630 | * Clear all the flags we set and possible error state in the | |
631 | * buffer. We only did the write to try out whether barriers | |
632 | * worked and shouldn't leave any traces in the superblock | |
633 | * buffer. | |
634 | */ | |
635 | XFS_BUF_DONE(sbp); | |
636 | XFS_BUF_ERROR(sbp, 0); | |
637 | XFS_BUF_UNORDERED(sbp); | |
638 | ||
639 | xfs_buf_relse(sbp); | |
640 | return error; | |
641 | } | |
642 | ||
643 | void | |
644 | xfs_mountfs_check_barriers(xfs_mount_t *mp) | |
645 | { | |
646 | int error; | |
647 | ||
648 | if (mp->m_logdev_targp != mp->m_ddev_targp) { | |
649 | xfs_fs_cmn_err(CE_NOTE, mp, | |
650 | "Disabling barriers, not supported with external log device"); | |
651 | mp->m_flags &= ~XFS_MOUNT_BARRIER; | |
4ef19ddd | 652 | return; |
f538d4da CH |
653 | } |
654 | ||
b2ea401b NS |
655 | if (xfs_readonly_buftarg(mp->m_ddev_targp)) { |
656 | xfs_fs_cmn_err(CE_NOTE, mp, | |
657 | "Disabling barriers, underlying device is readonly"); | |
658 | mp->m_flags &= ~XFS_MOUNT_BARRIER; | |
659 | return; | |
660 | } | |
661 | ||
f538d4da CH |
662 | error = xfs_barrier_test(mp); |
663 | if (error) { | |
664 | xfs_fs_cmn_err(CE_NOTE, mp, | |
665 | "Disabling barriers, trial barrier write failed"); | |
666 | mp->m_flags &= ~XFS_MOUNT_BARRIER; | |
4ef19ddd | 667 | return; |
f538d4da CH |
668 | } |
669 | } | |
670 | ||
671 | void | |
672 | xfs_blkdev_issue_flush( | |
673 | xfs_buftarg_t *buftarg) | |
674 | { | |
ce8e922c | 675 | blkdev_issue_flush(buftarg->bt_bdev, NULL); |
f538d4da | 676 | } |
1da177e4 | 677 | |
19f354d4 CH |
678 | STATIC void |
679 | xfs_close_devices( | |
680 | struct xfs_mount *mp) | |
681 | { | |
682 | if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { | |
c032bfcf | 683 | struct block_device *logdev = mp->m_logdev_targp->bt_bdev; |
19f354d4 | 684 | xfs_free_buftarg(mp->m_logdev_targp); |
c032bfcf | 685 | xfs_blkdev_put(logdev); |
19f354d4 CH |
686 | } |
687 | if (mp->m_rtdev_targp) { | |
c032bfcf | 688 | struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev; |
19f354d4 | 689 | xfs_free_buftarg(mp->m_rtdev_targp); |
c032bfcf | 690 | xfs_blkdev_put(rtdev); |
19f354d4 CH |
691 | } |
692 | xfs_free_buftarg(mp->m_ddev_targp); | |
693 | } | |
694 | ||
695 | /* | |
696 | * The file system configurations are: | |
697 | * (1) device (partition) with data and internal log | |
698 | * (2) logical volume with data and log subvolumes. | |
699 | * (3) logical volume with data, log, and realtime subvolumes. | |
700 | * | |
701 | * We only have to handle opening the log and realtime volumes here if | |
702 | * they are present. The data subvolume has already been opened by | |
703 | * get_sb_bdev() and is stored in sb->s_bdev. | |
704 | */ | |
705 | STATIC int | |
706 | xfs_open_devices( | |
707 | struct xfs_mount *mp, | |
708 | struct xfs_mount_args *args) | |
709 | { | |
710 | struct block_device *ddev = mp->m_super->s_bdev; | |
711 | struct block_device *logdev = NULL, *rtdev = NULL; | |
712 | int error; | |
713 | ||
714 | /* | |
715 | * Open real time and log devices - order is important. | |
716 | */ | |
717 | if (args->logname[0]) { | |
718 | error = xfs_blkdev_get(mp, args->logname, &logdev); | |
719 | if (error) | |
720 | goto out; | |
721 | } | |
722 | ||
723 | if (args->rtname[0]) { | |
724 | error = xfs_blkdev_get(mp, args->rtname, &rtdev); | |
725 | if (error) | |
726 | goto out_close_logdev; | |
727 | ||
728 | if (rtdev == ddev || rtdev == logdev) { | |
729 | cmn_err(CE_WARN, | |
730 | "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev."); | |
731 | error = EINVAL; | |
732 | goto out_close_rtdev; | |
733 | } | |
734 | } | |
735 | ||
736 | /* | |
737 | * Setup xfs_mount buffer target pointers | |
738 | */ | |
739 | error = ENOMEM; | |
740 | mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0); | |
741 | if (!mp->m_ddev_targp) | |
742 | goto out_close_rtdev; | |
743 | ||
744 | if (rtdev) { | |
745 | mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1); | |
746 | if (!mp->m_rtdev_targp) | |
747 | goto out_free_ddev_targ; | |
748 | } | |
749 | ||
750 | if (logdev && logdev != ddev) { | |
751 | mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1); | |
752 | if (!mp->m_logdev_targp) | |
753 | goto out_free_rtdev_targ; | |
754 | } else { | |
755 | mp->m_logdev_targp = mp->m_ddev_targp; | |
756 | } | |
757 | ||
758 | return 0; | |
759 | ||
760 | out_free_rtdev_targ: | |
761 | if (mp->m_rtdev_targp) | |
762 | xfs_free_buftarg(mp->m_rtdev_targp); | |
763 | out_free_ddev_targ: | |
764 | xfs_free_buftarg(mp->m_ddev_targp); | |
765 | out_close_rtdev: | |
766 | if (rtdev) | |
767 | xfs_blkdev_put(rtdev); | |
768 | out_close_logdev: | |
769 | if (logdev && logdev != ddev) | |
770 | xfs_blkdev_put(logdev); | |
771 | out: | |
772 | return error; | |
773 | } | |
774 | ||
e34b562c CH |
775 | /* |
776 | * Setup xfs_mount buffer target pointers based on superblock | |
777 | */ | |
778 | STATIC int | |
779 | xfs_setup_devices( | |
780 | struct xfs_mount *mp) | |
781 | { | |
782 | int error; | |
19f354d4 | 783 | |
e34b562c CH |
784 | error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize, |
785 | mp->m_sb.sb_sectsize); | |
786 | if (error) | |
787 | return error; | |
788 | ||
789 | if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { | |
790 | unsigned int log_sector_size = BBSIZE; | |
791 | ||
792 | if (xfs_sb_version_hassector(&mp->m_sb)) | |
793 | log_sector_size = mp->m_sb.sb_logsectsize; | |
794 | error = xfs_setsize_buftarg(mp->m_logdev_targp, | |
795 | mp->m_sb.sb_blocksize, | |
796 | log_sector_size); | |
797 | if (error) | |
798 | return error; | |
799 | } | |
800 | if (mp->m_rtdev_targp) { | |
801 | error = xfs_setsize_buftarg(mp->m_rtdev_targp, | |
802 | mp->m_sb.sb_blocksize, | |
803 | mp->m_sb.sb_sectsize); | |
804 | if (error) | |
805 | return error; | |
806 | } | |
807 | ||
808 | return 0; | |
809 | } | |
19f354d4 | 810 | |
249a8c11 DC |
811 | /* |
812 | * XFS AIL push thread support | |
813 | */ | |
814 | void | |
815 | xfsaild_wakeup( | |
816 | xfs_mount_t *mp, | |
817 | xfs_lsn_t threshold_lsn) | |
818 | { | |
819 | mp->m_ail.xa_target = threshold_lsn; | |
820 | wake_up_process(mp->m_ail.xa_task); | |
821 | } | |
822 | ||
823 | int | |
824 | xfsaild( | |
825 | void *data) | |
826 | { | |
827 | xfs_mount_t *mp = (xfs_mount_t *)data; | |
828 | xfs_lsn_t last_pushed_lsn = 0; | |
829 | long tout = 0; | |
830 | ||
831 | while (!kthread_should_stop()) { | |
832 | if (tout) | |
833 | schedule_timeout_interruptible(msecs_to_jiffies(tout)); | |
834 | tout = 1000; | |
835 | ||
836 | /* swsusp */ | |
837 | try_to_freeze(); | |
838 | ||
839 | ASSERT(mp->m_log); | |
840 | if (XFS_FORCED_SHUTDOWN(mp)) | |
841 | continue; | |
842 | ||
843 | tout = xfsaild_push(mp, &last_pushed_lsn); | |
844 | } | |
845 | ||
846 | return 0; | |
847 | } /* xfsaild */ | |
848 | ||
849 | int | |
850 | xfsaild_start( | |
851 | xfs_mount_t *mp) | |
852 | { | |
853 | mp->m_ail.xa_target = 0; | |
854 | mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild"); | |
855 | if (IS_ERR(mp->m_ail.xa_task)) | |
856 | return -PTR_ERR(mp->m_ail.xa_task); | |
857 | return 0; | |
858 | } | |
859 | ||
860 | void | |
861 | xfsaild_stop( | |
862 | xfs_mount_t *mp) | |
863 | { | |
864 | kthread_stop(mp->m_ail.xa_task); | |
865 | } | |
866 | ||
867 | ||
868 | ||
1da177e4 | 869 | STATIC struct inode * |
a50cd269 | 870 | xfs_fs_alloc_inode( |
1da177e4 LT |
871 | struct super_block *sb) |
872 | { | |
df80c933 | 873 | return kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP); |
1da177e4 LT |
874 | } |
875 | ||
876 | STATIC void | |
a50cd269 | 877 | xfs_fs_destroy_inode( |
1da177e4 LT |
878 | struct inode *inode) |
879 | { | |
a19d033c | 880 | kmem_zone_free(xfs_vnode_zone, inode); |
1da177e4 LT |
881 | } |
882 | ||
883 | STATIC void | |
a50cd269 | 884 | xfs_fs_inode_init_once( |
4ba9b9d0 | 885 | void *vnode) |
1da177e4 | 886 | { |
863890cd | 887 | inode_init_once((struct inode *)vnode); |
1da177e4 LT |
888 | } |
889 | ||
1da177e4 LT |
890 | /* |
891 | * Attempt to flush the inode, this will actually fail | |
892 | * if the inode is pinned, but we dirty the inode again | |
893 | * at the point when it is unpinned after a log write, | |
8758280f | 894 | * since this is when the inode itself becomes flushable. |
1da177e4 LT |
895 | */ |
896 | STATIC int | |
a50cd269 | 897 | xfs_fs_write_inode( |
1da177e4 LT |
898 | struct inode *inode, |
899 | int sync) | |
900 | { | |
a3f74ffb DC |
901 | int error = 0; |
902 | int flags = 0; | |
1da177e4 | 903 | |
cf441eeb | 904 | xfs_itrace_entry(XFS_I(inode)); |
739bfb2a CH |
905 | if (sync) { |
906 | filemap_fdatawait(inode->i_mapping); | |
907 | flags |= FLUSH_SYNC; | |
1da177e4 | 908 | } |
739bfb2a | 909 | error = xfs_inode_flush(XFS_I(inode), flags); |
e893bffd LM |
910 | /* |
911 | * if we failed to write out the inode then mark | |
912 | * it dirty again so we'll try again later. | |
913 | */ | |
914 | if (error) | |
915 | mark_inode_dirty_sync(inode); | |
739bfb2a | 916 | |
1da177e4 LT |
917 | return -error; |
918 | } | |
919 | ||
920 | STATIC void | |
a50cd269 | 921 | xfs_fs_clear_inode( |
1da177e4 LT |
922 | struct inode *inode) |
923 | { | |
1543d79c | 924 | xfs_inode_t *ip = XFS_I(inode); |
56d433e4 | 925 | |
02ba71de | 926 | /* |
1543d79c | 927 | * ip can be null when xfs_iget_core calls xfs_idestroy if we |
02ba71de CH |
928 | * find an inode with di_mode == 0 but without IGET_CREATE set. |
929 | */ | |
1543d79c | 930 | if (ip) { |
cf441eeb | 931 | xfs_itrace_entry(ip); |
1543d79c CH |
932 | XFS_STATS_INC(vn_rele); |
933 | XFS_STATS_INC(vn_remove); | |
934 | XFS_STATS_INC(vn_reclaim); | |
935 | XFS_STATS_DEC(vn_active); | |
936 | ||
937 | xfs_inactive(ip); | |
938 | xfs_iflags_clear(ip, XFS_IMODIFIED); | |
939 | if (xfs_reclaim(ip)) | |
34a622b2 | 940 | panic("%s: cannot reclaim 0x%p\n", __func__, inode); |
b3aea4ed | 941 | } |
56d433e4 | 942 | |
739bfb2a | 943 | ASSERT(XFS_I(inode) == NULL); |
56d433e4 | 944 | } |
1da177e4 LT |
945 | |
946 | /* | |
947 | * Enqueue a work item to be picked up by the vfs xfssyncd thread. | |
948 | * Doing this has two advantages: | |
949 | * - It saves on stack space, which is tight in certain situations | |
950 | * - It can be used (with care) as a mechanism to avoid deadlocks. | |
951 | * Flushing while allocating in a full filesystem requires both. | |
952 | */ | |
953 | STATIC void | |
954 | xfs_syncd_queue_work( | |
74394496 | 955 | struct xfs_mount *mp, |
1da177e4 | 956 | void *data, |
74394496 | 957 | void (*syncer)(struct xfs_mount *, void *)) |
1da177e4 | 958 | { |
b83bd138 | 959 | struct bhv_vfs_sync_work *work; |
1da177e4 | 960 | |
b83bd138 | 961 | work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP); |
1da177e4 LT |
962 | INIT_LIST_HEAD(&work->w_list); |
963 | work->w_syncer = syncer; | |
964 | work->w_data = data; | |
74394496 CH |
965 | work->w_mount = mp; |
966 | spin_lock(&mp->m_sync_lock); | |
967 | list_add_tail(&work->w_list, &mp->m_sync_list); | |
968 | spin_unlock(&mp->m_sync_lock); | |
969 | wake_up_process(mp->m_sync_task); | |
1da177e4 LT |
970 | } |
971 | ||
972 | /* | |
973 | * Flush delayed allocate data, attempting to free up reserved space | |
974 | * from existing allocations. At this point a new allocation attempt | |
975 | * has failed with ENOSPC and we are in the process of scratching our | |
976 | * heads, looking about for more room... | |
977 | */ | |
978 | STATIC void | |
979 | xfs_flush_inode_work( | |
74394496 CH |
980 | struct xfs_mount *mp, |
981 | void *arg) | |
1da177e4 | 982 | { |
74394496 CH |
983 | struct inode *inode = arg; |
984 | filemap_flush(inode->i_mapping); | |
985 | iput(inode); | |
1da177e4 LT |
986 | } |
987 | ||
988 | void | |
989 | xfs_flush_inode( | |
990 | xfs_inode_t *ip) | |
991 | { | |
01651646 | 992 | struct inode *inode = VFS_I(ip); |
1da177e4 LT |
993 | |
994 | igrab(inode); | |
74394496 | 995 | xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work); |
041e0e3b | 996 | delay(msecs_to_jiffies(500)); |
1da177e4 LT |
997 | } |
998 | ||
999 | /* | |
1000 | * This is the "bigger hammer" version of xfs_flush_inode_work... | |
1001 | * (IOW, "If at first you don't succeed, use a Bigger Hammer"). | |
1002 | */ | |
1003 | STATIC void | |
1004 | xfs_flush_device_work( | |
74394496 CH |
1005 | struct xfs_mount *mp, |
1006 | void *arg) | |
1da177e4 | 1007 | { |
74394496 | 1008 | struct inode *inode = arg; |
b267ce99 | 1009 | sync_blockdev(mp->m_super->s_bdev); |
74394496 | 1010 | iput(inode); |
1da177e4 LT |
1011 | } |
1012 | ||
1013 | void | |
1014 | xfs_flush_device( | |
1015 | xfs_inode_t *ip) | |
1016 | { | |
e4f75291 | 1017 | struct inode *inode = VFS_I(ip); |
1da177e4 LT |
1018 | |
1019 | igrab(inode); | |
74394496 | 1020 | xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work); |
041e0e3b | 1021 | delay(msecs_to_jiffies(500)); |
1da177e4 LT |
1022 | xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC); |
1023 | } | |
1024 | ||
1da177e4 | 1025 | STATIC void |
74394496 CH |
1026 | xfs_sync_worker( |
1027 | struct xfs_mount *mp, | |
1da177e4 LT |
1028 | void *unused) |
1029 | { | |
1030 | int error; | |
1031 | ||
74394496 | 1032 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) |
7e20694d | 1033 | error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR); |
74394496 CH |
1034 | mp->m_sync_seq++; |
1035 | wake_up(&mp->m_wait_single_sync_task); | |
1da177e4 LT |
1036 | } |
1037 | ||
1038 | STATIC int | |
1039 | xfssyncd( | |
1040 | void *arg) | |
1041 | { | |
74394496 | 1042 | struct xfs_mount *mp = arg; |
1da177e4 | 1043 | long timeleft; |
b83bd138 | 1044 | bhv_vfs_sync_work_t *work, *n; |
4df08c52 | 1045 | LIST_HEAD (tmp); |
1da177e4 | 1046 | |
83144186 | 1047 | set_freezable(); |
041e0e3b | 1048 | timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10); |
1da177e4 | 1049 | for (;;) { |
041e0e3b | 1050 | timeleft = schedule_timeout_interruptible(timeleft); |
1da177e4 | 1051 | /* swsusp */ |
3e1d1d28 | 1052 | try_to_freeze(); |
74394496 | 1053 | if (kthread_should_stop() && list_empty(&mp->m_sync_list)) |
1da177e4 LT |
1054 | break; |
1055 | ||
74394496 | 1056 | spin_lock(&mp->m_sync_lock); |
1da177e4 LT |
1057 | /* |
1058 | * We can get woken by laptop mode, to do a sync - | |
1059 | * that's the (only!) case where the list would be | |
1060 | * empty with time remaining. | |
1061 | */ | |
74394496 | 1062 | if (!timeleft || list_empty(&mp->m_sync_list)) { |
1da177e4 | 1063 | if (!timeleft) |
041e0e3b NA |
1064 | timeleft = xfs_syncd_centisecs * |
1065 | msecs_to_jiffies(10); | |
74394496 CH |
1066 | INIT_LIST_HEAD(&mp->m_sync_work.w_list); |
1067 | list_add_tail(&mp->m_sync_work.w_list, | |
1068 | &mp->m_sync_list); | |
1da177e4 | 1069 | } |
74394496 | 1070 | list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list) |
1da177e4 | 1071 | list_move(&work->w_list, &tmp); |
74394496 | 1072 | spin_unlock(&mp->m_sync_lock); |
1da177e4 LT |
1073 | |
1074 | list_for_each_entry_safe(work, n, &tmp, w_list) { | |
74394496 | 1075 | (*work->w_syncer)(mp, work->w_data); |
1da177e4 | 1076 | list_del(&work->w_list); |
74394496 | 1077 | if (work == &mp->m_sync_work) |
1da177e4 | 1078 | continue; |
f0e2d93c | 1079 | kmem_free(work); |
1da177e4 LT |
1080 | } |
1081 | } | |
1082 | ||
1da177e4 LT |
1083 | return 0; |
1084 | } | |
1085 | ||
a738159d CH |
1086 | STATIC void |
1087 | xfs_free_fsname( | |
1088 | struct xfs_mount *mp) | |
1089 | { | |
1090 | kfree(mp->m_fsname); | |
1091 | kfree(mp->m_rtname); | |
1092 | kfree(mp->m_logname); | |
1093 | } | |
1094 | ||
1da177e4 | 1095 | STATIC void |
a50cd269 | 1096 | xfs_fs_put_super( |
1da177e4 LT |
1097 | struct super_block *sb) |
1098 | { | |
745f6919 | 1099 | struct xfs_mount *mp = XFS_M(sb); |
e48ad316 CH |
1100 | struct xfs_inode *rip = mp->m_rootip; |
1101 | int unmount_event_flags = 0; | |
1da177e4 LT |
1102 | int error; |
1103 | ||
74394496 CH |
1104 | kthread_stop(mp->m_sync_task); |
1105 | ||
745f6919 | 1106 | xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI); |
e48ad316 CH |
1107 | |
1108 | #ifdef HAVE_DMAPI | |
1109 | if (mp->m_flags & XFS_MOUNT_DMAPI) { | |
1110 | unmount_event_flags = | |
1111 | (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ? | |
1112 | 0 : DM_FLAGS_UNWANTED; | |
1113 | /* | |
1114 | * Ignore error from dmapi here, first unmount is not allowed | |
1115 | * to fail anyway, and second we wouldn't want to fail a | |
1116 | * unmount because of dmapi. | |
1117 | */ | |
1118 | XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL, | |
1119 | NULL, NULL, 0, 0, unmount_event_flags); | |
1120 | } | |
1121 | #endif | |
1122 | ||
1123 | /* | |
1124 | * Blow away any referenced inode in the filestreams cache. | |
1125 | * This can and will cause log traffic as inodes go inactive | |
1126 | * here. | |
1127 | */ | |
1128 | xfs_filestream_unmount(mp); | |
1129 | ||
1130 | XFS_bflush(mp->m_ddev_targp); | |
1131 | error = xfs_unmount_flush(mp, 0); | |
1132 | WARN_ON(error); | |
1133 | ||
e48ad316 CH |
1134 | /* |
1135 | * If we're forcing a shutdown, typically because of a media error, | |
1136 | * we want to make sure we invalidate dirty pages that belong to | |
1137 | * referenced vnodes as well. | |
1138 | */ | |
1139 | if (XFS_FORCED_SHUTDOWN(mp)) { | |
1140 | error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE); | |
1141 | ASSERT(error != EFSCORRUPTED); | |
1142 | } | |
1143 | ||
1144 | if (mp->m_flags & XFS_MOUNT_DMAPI) { | |
1145 | XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0, | |
1146 | unmount_event_flags); | |
1147 | } | |
1148 | ||
19f354d4 | 1149 | xfs_unmountfs(mp); |
6203300e | 1150 | xfs_freesb(mp); |
c962fb79 | 1151 | xfs_icsb_destroy_counters(mp); |
19f354d4 | 1152 | xfs_close_devices(mp); |
e48ad316 CH |
1153 | xfs_qmops_put(mp); |
1154 | xfs_dmops_put(mp); | |
a738159d | 1155 | xfs_free_fsname(mp); |
c962fb79 | 1156 | kfree(mp); |
1da177e4 LT |
1157 | } |
1158 | ||
1159 | STATIC void | |
a50cd269 | 1160 | xfs_fs_write_super( |
1da177e4 LT |
1161 | struct super_block *sb) |
1162 | { | |
b83bd138 | 1163 | if (!(sb->s_flags & MS_RDONLY)) |
745f6919 | 1164 | xfs_sync(XFS_M(sb), SYNC_FSDATA); |
1da177e4 LT |
1165 | sb->s_dirt = 0; |
1166 | } | |
1167 | ||
1168 | STATIC int | |
a50cd269 | 1169 | xfs_fs_sync_super( |
1da177e4 LT |
1170 | struct super_block *sb, |
1171 | int wait) | |
1172 | { | |
745f6919 | 1173 | struct xfs_mount *mp = XFS_M(sb); |
b83bd138 NS |
1174 | int error; |
1175 | int flags; | |
1da177e4 | 1176 | |
e893bffd LM |
1177 | /* |
1178 | * Treat a sync operation like a freeze. This is to work | |
1179 | * around a race in sync_inodes() which works in two phases | |
1180 | * - an asynchronous flush, which can write out an inode | |
1181 | * without waiting for file size updates to complete, and a | |
1182 | * synchronous flush, which wont do anything because the | |
1183 | * async flush removed the inode's dirty flag. Also | |
1184 | * sync_inodes() will not see any files that just have | |
1185 | * outstanding transactions to be flushed because we don't | |
1186 | * dirty the Linux inode until after the transaction I/O | |
1187 | * completes. | |
1188 | */ | |
1189 | if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) { | |
2823945f DC |
1190 | /* |
1191 | * First stage of freeze - no more writers will make progress | |
1192 | * now we are here, so we flush delwri and delalloc buffers | |
1193 | * here, then wait for all I/O to complete. Data is frozen at | |
1194 | * that point. Metadata is not frozen, transactions can still | |
1195 | * occur here so don't bother flushing the buftarg (i.e | |
1196 | * SYNC_QUIESCE) because it'll just get dirty again. | |
1197 | */ | |
516b2e7c | 1198 | flags = SYNC_DATA_QUIESCE; |
2823945f | 1199 | } else |
e893bffd | 1200 | flags = SYNC_FSDATA; |
1da177e4 | 1201 | |
745f6919 | 1202 | error = xfs_sync(mp, flags); |
1da177e4 LT |
1203 | sb->s_dirt = 0; |
1204 | ||
1205 | if (unlikely(laptop_mode)) { | |
74394496 | 1206 | int prev_sync_seq = mp->m_sync_seq; |
1da177e4 LT |
1207 | |
1208 | /* | |
1209 | * The disk must be active because we're syncing. | |
1210 | * We schedule xfssyncd now (now that the disk is | |
1211 | * active) instead of later (when it might not be). | |
1212 | */ | |
74394496 | 1213 | wake_up_process(mp->m_sync_task); |
1da177e4 LT |
1214 | /* |
1215 | * We have to wait for the sync iteration to complete. | |
1216 | * If we don't, the disk activity caused by the sync | |
1217 | * will come after the sync is completed, and that | |
1218 | * triggers another sync from laptop mode. | |
1219 | */ | |
74394496 CH |
1220 | wait_event(mp->m_wait_single_sync_task, |
1221 | mp->m_sync_seq != prev_sync_seq); | |
1da177e4 LT |
1222 | } |
1223 | ||
1224 | return -error; | |
1225 | } | |
1226 | ||
1227 | STATIC int | |
a50cd269 | 1228 | xfs_fs_statfs( |
726c3342 | 1229 | struct dentry *dentry, |
1da177e4 LT |
1230 | struct kstatfs *statp) |
1231 | { | |
4ca488eb CH |
1232 | struct xfs_mount *mp = XFS_M(dentry->d_sb); |
1233 | xfs_sb_t *sbp = &mp->m_sb; | |
1234 | __uint64_t fakeinos, id; | |
1235 | xfs_extlen_t lsize; | |
1236 | ||
1237 | statp->f_type = XFS_SB_MAGIC; | |
1238 | statp->f_namelen = MAXNAMELEN - 1; | |
1239 | ||
1240 | id = huge_encode_dev(mp->m_ddev_targp->bt_dev); | |
1241 | statp->f_fsid.val[0] = (u32)id; | |
1242 | statp->f_fsid.val[1] = (u32)(id >> 32); | |
1243 | ||
d4d90b57 | 1244 | xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT); |
4ca488eb CH |
1245 | |
1246 | spin_lock(&mp->m_sb_lock); | |
1247 | statp->f_bsize = sbp->sb_blocksize; | |
1248 | lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0; | |
1249 | statp->f_blocks = sbp->sb_dblocks - lsize; | |
1250 | statp->f_bfree = statp->f_bavail = | |
1251 | sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); | |
1252 | fakeinos = statp->f_bfree << sbp->sb_inopblog; | |
1253 | #if XFS_BIG_INUMS | |
1254 | fakeinos += mp->m_inoadd; | |
1255 | #endif | |
1256 | statp->f_files = | |
1257 | MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER); | |
1258 | if (mp->m_maxicount) | |
1259 | #if XFS_BIG_INUMS | |
1260 | if (!mp->m_inoadd) | |
1261 | #endif | |
1262 | statp->f_files = min_t(typeof(statp->f_files), | |
1263 | statp->f_files, | |
1264 | mp->m_maxicount); | |
1265 | statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree); | |
1266 | spin_unlock(&mp->m_sb_lock); | |
1267 | ||
1268 | XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp); | |
1269 | return 0; | |
1da177e4 LT |
1270 | } |
1271 | ||
1272 | STATIC int | |
a50cd269 | 1273 | xfs_fs_remount( |
1da177e4 LT |
1274 | struct super_block *sb, |
1275 | int *flags, | |
1276 | char *options) | |
1277 | { | |
745f6919 | 1278 | struct xfs_mount *mp = XFS_M(sb); |
62a877e3 CH |
1279 | substring_t args[MAX_OPT_ARGS]; |
1280 | char *p; | |
1da177e4 | 1281 | |
62a877e3 CH |
1282 | while ((p = strsep(&options, ",")) != NULL) { |
1283 | int token; | |
bdd907ba | 1284 | |
62a877e3 CH |
1285 | if (!*p) |
1286 | continue; | |
48b62a1a | 1287 | |
62a877e3 CH |
1288 | token = match_token(p, tokens, args); |
1289 | switch (token) { | |
1290 | case Opt_barrier: | |
48b62a1a | 1291 | mp->m_flags |= XFS_MOUNT_BARRIER; |
62a877e3 CH |
1292 | |
1293 | /* | |
1294 | * Test if barriers are actually working if we can, | |
1295 | * else delay this check until the filesystem is | |
1296 | * marked writeable. | |
1297 | */ | |
1298 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) | |
1299 | xfs_mountfs_check_barriers(mp); | |
1300 | break; | |
1301 | case Opt_nobarrier: | |
48b62a1a | 1302 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
62a877e3 CH |
1303 | break; |
1304 | default: | |
1305 | printk(KERN_INFO | |
1306 | "XFS: mount option \"%s\" not supported for remount\n", p); | |
1307 | return -EINVAL; | |
48b62a1a | 1308 | } |
62a877e3 CH |
1309 | } |
1310 | ||
1311 | /* rw/ro -> rw */ | |
1312 | if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) { | |
1313 | mp->m_flags &= ~XFS_MOUNT_RDONLY; | |
1314 | if (mp->m_flags & XFS_MOUNT_BARRIER) | |
1315 | xfs_mountfs_check_barriers(mp); | |
1316 | } | |
1317 | ||
1318 | /* rw -> ro */ | |
1319 | if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) { | |
48b62a1a CH |
1320 | xfs_filestream_flush(mp); |
1321 | xfs_sync(mp, SYNC_DATA_QUIESCE); | |
1322 | xfs_attr_quiesce(mp); | |
1323 | mp->m_flags |= XFS_MOUNT_RDONLY; | |
1324 | } | |
1325 | ||
62a877e3 | 1326 | return 0; |
1da177e4 LT |
1327 | } |
1328 | ||
9909c4aa CH |
1329 | /* |
1330 | * Second stage of a freeze. The data is already frozen so we only | |
1331 | * need to take care of themetadata. Once that's done write a dummy | |
1332 | * record to dirty the log in case of a crash while frozen. | |
1333 | */ | |
1da177e4 | 1334 | STATIC void |
a50cd269 | 1335 | xfs_fs_lockfs( |
1da177e4 LT |
1336 | struct super_block *sb) |
1337 | { | |
9909c4aa CH |
1338 | struct xfs_mount *mp = XFS_M(sb); |
1339 | ||
1340 | xfs_attr_quiesce(mp); | |
1341 | xfs_fs_log_dummy(mp); | |
1da177e4 LT |
1342 | } |
1343 | ||
1344 | STATIC int | |
a50cd269 | 1345 | xfs_fs_show_options( |
1da177e4 LT |
1346 | struct seq_file *m, |
1347 | struct vfsmount *mnt) | |
1348 | { | |
745f6919 | 1349 | return -xfs_showargs(XFS_M(mnt->mnt_sb), m); |
1da177e4 LT |
1350 | } |
1351 | ||
ee34807a | 1352 | STATIC int |
a50cd269 | 1353 | xfs_fs_quotasync( |
ee34807a NS |
1354 | struct super_block *sb, |
1355 | int type) | |
1356 | { | |
b09cc771 | 1357 | return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL); |
ee34807a NS |
1358 | } |
1359 | ||
1da177e4 | 1360 | STATIC int |
a50cd269 | 1361 | xfs_fs_getxstate( |
1da177e4 LT |
1362 | struct super_block *sb, |
1363 | struct fs_quota_stat *fqs) | |
1364 | { | |
b09cc771 | 1365 | return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs); |
1da177e4 LT |
1366 | } |
1367 | ||
1368 | STATIC int | |
a50cd269 | 1369 | xfs_fs_setxstate( |
1da177e4 LT |
1370 | struct super_block *sb, |
1371 | unsigned int flags, | |
1372 | int op) | |
1373 | { | |
b09cc771 | 1374 | return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags); |
1da177e4 LT |
1375 | } |
1376 | ||
1377 | STATIC int | |
a50cd269 | 1378 | xfs_fs_getxquota( |
1da177e4 LT |
1379 | struct super_block *sb, |
1380 | int type, | |
1381 | qid_t id, | |
1382 | struct fs_disk_quota *fdq) | |
1383 | { | |
b09cc771 | 1384 | return -XFS_QM_QUOTACTL(XFS_M(sb), |
b83bd138 NS |
1385 | (type == USRQUOTA) ? Q_XGETQUOTA : |
1386 | ((type == GRPQUOTA) ? Q_XGETGQUOTA : | |
1387 | Q_XGETPQUOTA), id, (caddr_t)fdq); | |
1da177e4 LT |
1388 | } |
1389 | ||
1390 | STATIC int | |
a50cd269 | 1391 | xfs_fs_setxquota( |
1da177e4 LT |
1392 | struct super_block *sb, |
1393 | int type, | |
1394 | qid_t id, | |
1395 | struct fs_disk_quota *fdq) | |
1396 | { | |
b09cc771 | 1397 | return -XFS_QM_QUOTACTL(XFS_M(sb), |
b83bd138 NS |
1398 | (type == USRQUOTA) ? Q_XSETQLIM : |
1399 | ((type == GRPQUOTA) ? Q_XSETGQLIM : | |
1400 | Q_XSETPQLIM), id, (caddr_t)fdq); | |
1da177e4 LT |
1401 | } |
1402 | ||
f8f15e42 CH |
1403 | /* |
1404 | * This function fills in xfs_mount_t fields based on mount args. | |
1405 | * Note: the superblock has _not_ yet been read in. | |
1406 | */ | |
1407 | STATIC int | |
1408 | xfs_start_flags( | |
1409 | struct xfs_mount_args *ap, | |
1410 | struct xfs_mount *mp) | |
1411 | { | |
a738159d CH |
1412 | int error; |
1413 | ||
f8f15e42 CH |
1414 | /* Values are in BBs */ |
1415 | if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { | |
1416 | /* | |
1417 | * At this point the superblock has not been read | |
1418 | * in, therefore we do not know the block size. | |
1419 | * Before the mount call ends we will convert | |
1420 | * these to FSBs. | |
1421 | */ | |
1422 | mp->m_dalign = ap->sunit; | |
1423 | mp->m_swidth = ap->swidth; | |
1424 | } | |
1425 | ||
1426 | if (ap->logbufs != -1 && | |
1427 | ap->logbufs != 0 && | |
1428 | (ap->logbufs < XLOG_MIN_ICLOGS || | |
1429 | ap->logbufs > XLOG_MAX_ICLOGS)) { | |
1430 | cmn_err(CE_WARN, | |
1431 | "XFS: invalid logbufs value: %d [not %d-%d]", | |
1432 | ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS); | |
1433 | return XFS_ERROR(EINVAL); | |
1434 | } | |
1435 | mp->m_logbufs = ap->logbufs; | |
1436 | if (ap->logbufsize != -1 && | |
1437 | ap->logbufsize != 0 && | |
1438 | (ap->logbufsize < XLOG_MIN_RECORD_BSIZE || | |
1439 | ap->logbufsize > XLOG_MAX_RECORD_BSIZE || | |
1440 | !is_power_of_2(ap->logbufsize))) { | |
1441 | cmn_err(CE_WARN, | |
1442 | "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]", | |
1443 | ap->logbufsize); | |
1444 | return XFS_ERROR(EINVAL); | |
1445 | } | |
a738159d CH |
1446 | |
1447 | error = ENOMEM; | |
1448 | ||
f8f15e42 CH |
1449 | mp->m_logbsize = ap->logbufsize; |
1450 | mp->m_fsname_len = strlen(ap->fsname) + 1; | |
a738159d CH |
1451 | |
1452 | mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL); | |
1453 | if (!mp->m_fsname) | |
1454 | goto out; | |
1455 | ||
f8f15e42 | 1456 | if (ap->rtname[0]) { |
a738159d CH |
1457 | mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL); |
1458 | if (!mp->m_rtname) | |
1459 | goto out_free_fsname; | |
1460 | ||
f8f15e42 | 1461 | } |
a738159d | 1462 | |
f8f15e42 | 1463 | if (ap->logname[0]) { |
a738159d CH |
1464 | mp->m_logname = kstrdup(ap->logname, GFP_KERNEL); |
1465 | if (!mp->m_logname) | |
1466 | goto out_free_rtname; | |
f8f15e42 CH |
1467 | } |
1468 | ||
1469 | if (ap->flags & XFSMNT_WSYNC) | |
1470 | mp->m_flags |= XFS_MOUNT_WSYNC; | |
1471 | #if XFS_BIG_INUMS | |
1472 | if (ap->flags & XFSMNT_INO64) { | |
1473 | mp->m_flags |= XFS_MOUNT_INO64; | |
1474 | mp->m_inoadd = XFS_INO64_OFFSET; | |
1475 | } | |
1476 | #endif | |
1477 | if (ap->flags & XFSMNT_RETERR) | |
1478 | mp->m_flags |= XFS_MOUNT_RETERR; | |
1479 | if (ap->flags & XFSMNT_NOALIGN) | |
1480 | mp->m_flags |= XFS_MOUNT_NOALIGN; | |
1481 | if (ap->flags & XFSMNT_SWALLOC) | |
1482 | mp->m_flags |= XFS_MOUNT_SWALLOC; | |
1483 | if (ap->flags & XFSMNT_OSYNCISOSYNC) | |
1484 | mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC; | |
1485 | if (ap->flags & XFSMNT_32BITINODES) | |
1486 | mp->m_flags |= XFS_MOUNT_32BITINODES; | |
1487 | ||
1488 | if (ap->flags & XFSMNT_IOSIZE) { | |
1489 | if (ap->iosizelog > XFS_MAX_IO_LOG || | |
1490 | ap->iosizelog < XFS_MIN_IO_LOG) { | |
1491 | cmn_err(CE_WARN, | |
1492 | "XFS: invalid log iosize: %d [not %d-%d]", | |
1493 | ap->iosizelog, XFS_MIN_IO_LOG, | |
1494 | XFS_MAX_IO_LOG); | |
1495 | return XFS_ERROR(EINVAL); | |
1496 | } | |
1497 | ||
1498 | mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE; | |
1499 | mp->m_readio_log = mp->m_writeio_log = ap->iosizelog; | |
1500 | } | |
1501 | ||
1502 | if (ap->flags & XFSMNT_IKEEP) | |
1503 | mp->m_flags |= XFS_MOUNT_IKEEP; | |
1504 | if (ap->flags & XFSMNT_DIRSYNC) | |
1505 | mp->m_flags |= XFS_MOUNT_DIRSYNC; | |
1506 | if (ap->flags & XFSMNT_ATTR2) | |
1507 | mp->m_flags |= XFS_MOUNT_ATTR2; | |
1508 | if (ap->flags & XFSMNT_NOATTR2) | |
1509 | mp->m_flags |= XFS_MOUNT_NOATTR2; | |
1510 | ||
1511 | if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE) | |
1512 | mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE; | |
1513 | ||
1514 | /* | |
1515 | * no recovery flag requires a read-only mount | |
1516 | */ | |
1517 | if (ap->flags & XFSMNT_NORECOVERY) { | |
1518 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { | |
1519 | cmn_err(CE_WARN, | |
1520 | "XFS: tried to mount a FS read-write without recovery!"); | |
1521 | return XFS_ERROR(EINVAL); | |
1522 | } | |
1523 | mp->m_flags |= XFS_MOUNT_NORECOVERY; | |
1524 | } | |
1525 | ||
1526 | if (ap->flags & XFSMNT_NOUUID) | |
1527 | mp->m_flags |= XFS_MOUNT_NOUUID; | |
1528 | if (ap->flags & XFSMNT_BARRIER) | |
1529 | mp->m_flags |= XFS_MOUNT_BARRIER; | |
1530 | else | |
1531 | mp->m_flags &= ~XFS_MOUNT_BARRIER; | |
1532 | ||
1533 | if (ap->flags2 & XFSMNT2_FILESTREAMS) | |
1534 | mp->m_flags |= XFS_MOUNT_FILESTREAMS; | |
1535 | ||
1536 | if (ap->flags & XFSMNT_DMAPI) | |
1537 | mp->m_flags |= XFS_MOUNT_DMAPI; | |
1538 | return 0; | |
a738159d CH |
1539 | |
1540 | ||
1541 | out_free_rtname: | |
1542 | kfree(mp->m_rtname); | |
1543 | out_free_fsname: | |
1544 | kfree(mp->m_fsname); | |
1545 | out: | |
1546 | return error; | |
f8f15e42 CH |
1547 | } |
1548 | ||
1549 | /* | |
1550 | * This function fills in xfs_mount_t fields based on mount args. | |
1551 | * Note: the superblock _has_ now been read in. | |
1552 | */ | |
1553 | STATIC int | |
1554 | xfs_finish_flags( | |
1555 | struct xfs_mount_args *ap, | |
1556 | struct xfs_mount *mp) | |
1557 | { | |
1558 | int ronly = (mp->m_flags & XFS_MOUNT_RDONLY); | |
1559 | ||
1560 | /* Fail a mount where the logbuf is smaller then the log stripe */ | |
1561 | if (xfs_sb_version_haslogv2(&mp->m_sb)) { | |
1562 | if ((ap->logbufsize <= 0) && | |
1563 | (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) { | |
1564 | mp->m_logbsize = mp->m_sb.sb_logsunit; | |
1565 | } else if (ap->logbufsize > 0 && | |
1566 | ap->logbufsize < mp->m_sb.sb_logsunit) { | |
1567 | cmn_err(CE_WARN, | |
1568 | "XFS: logbuf size must be greater than or equal to log stripe size"); | |
1569 | return XFS_ERROR(EINVAL); | |
1570 | } | |
1571 | } else { | |
1572 | /* Fail a mount if the logbuf is larger than 32K */ | |
1573 | if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) { | |
1574 | cmn_err(CE_WARN, | |
1575 | "XFS: logbuf size for version 1 logs must be 16K or 32K"); | |
1576 | return XFS_ERROR(EINVAL); | |
1577 | } | |
1578 | } | |
1579 | ||
1580 | /* | |
1581 | * mkfs'ed attr2 will turn on attr2 mount unless explicitly | |
1582 | * told by noattr2 to turn it off | |
1583 | */ | |
1584 | if (xfs_sb_version_hasattr2(&mp->m_sb) && | |
1585 | !(ap->flags & XFSMNT_NOATTR2)) | |
1586 | mp->m_flags |= XFS_MOUNT_ATTR2; | |
1587 | ||
1588 | /* | |
1589 | * prohibit r/w mounts of read-only filesystems | |
1590 | */ | |
1591 | if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) { | |
1592 | cmn_err(CE_WARN, | |
1593 | "XFS: cannot mount a read-only filesystem as read-write"); | |
1594 | return XFS_ERROR(EROFS); | |
1595 | } | |
1596 | ||
1597 | /* | |
1598 | * check for shared mount. | |
1599 | */ | |
1600 | if (ap->flags & XFSMNT_SHARED) { | |
1601 | if (!xfs_sb_version_hasshared(&mp->m_sb)) | |
1602 | return XFS_ERROR(EINVAL); | |
1603 | ||
1604 | /* | |
1605 | * For IRIX 6.5, shared mounts must have the shared | |
1606 | * version bit set, have the persistent readonly | |
1607 | * field set, must be version 0 and can only be mounted | |
1608 | * read-only. | |
1609 | */ | |
1610 | if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) || | |
1611 | (mp->m_sb.sb_shared_vn != 0)) | |
1612 | return XFS_ERROR(EINVAL); | |
1613 | ||
1614 | mp->m_flags |= XFS_MOUNT_SHARED; | |
1615 | ||
1616 | /* | |
1617 | * Shared XFS V0 can't deal with DMI. Return EINVAL. | |
1618 | */ | |
1619 | if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI)) | |
1620 | return XFS_ERROR(EINVAL); | |
1621 | } | |
1622 | ||
1623 | if (ap->flags & XFSMNT_UQUOTA) { | |
1624 | mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE); | |
1625 | if (ap->flags & XFSMNT_UQUOTAENF) | |
1626 | mp->m_qflags |= XFS_UQUOTA_ENFD; | |
1627 | } | |
1628 | ||
1629 | if (ap->flags & XFSMNT_GQUOTA) { | |
1630 | mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE); | |
1631 | if (ap->flags & XFSMNT_GQUOTAENF) | |
1632 | mp->m_qflags |= XFS_OQUOTA_ENFD; | |
1633 | } else if (ap->flags & XFSMNT_PQUOTA) { | |
1634 | mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE); | |
1635 | if (ap->flags & XFSMNT_PQUOTAENF) | |
1636 | mp->m_qflags |= XFS_OQUOTA_ENFD; | |
1637 | } | |
1638 | ||
1639 | return 0; | |
1640 | } | |
1641 | ||
1da177e4 | 1642 | STATIC int |
a50cd269 | 1643 | xfs_fs_fill_super( |
1da177e4 LT |
1644 | struct super_block *sb, |
1645 | void *data, | |
1646 | int silent) | |
1647 | { | |
f3dcc13f | 1648 | struct inode *root; |
745f6919 | 1649 | struct xfs_mount *mp = NULL; |
bdd907ba | 1650 | struct xfs_mount_args *args; |
c962fb79 | 1651 | int flags = 0, error = ENOMEM; |
1da177e4 | 1652 | |
bdd907ba CH |
1653 | args = xfs_args_allocate(sb, silent); |
1654 | if (!args) | |
1655 | return -ENOMEM; | |
1656 | ||
c962fb79 CH |
1657 | mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL); |
1658 | if (!mp) | |
1659 | goto out_free_args; | |
1da177e4 | 1660 | |
c962fb79 CH |
1661 | spin_lock_init(&mp->m_sb_lock); |
1662 | mutex_init(&mp->m_ilock); | |
1663 | mutex_init(&mp->m_growlock); | |
1664 | atomic_set(&mp->m_active_trans, 0); | |
74394496 CH |
1665 | INIT_LIST_HEAD(&mp->m_sync_list); |
1666 | spin_lock_init(&mp->m_sync_lock); | |
1667 | init_waitqueue_head(&mp->m_wait_single_sync_task); | |
1668 | ||
b267ce99 CH |
1669 | mp->m_super = sb; |
1670 | sb->s_fs_info = mp; | |
1da177e4 | 1671 | |
bd186aa9 CH |
1672 | if (sb->s_flags & MS_RDONLY) |
1673 | mp->m_flags |= XFS_MOUNT_RDONLY; | |
1674 | ||
745f6919 CH |
1675 | error = xfs_parseargs(mp, (char *)data, args, 0); |
1676 | if (error) | |
c962fb79 | 1677 | goto out_free_mp; |
1da177e4 LT |
1678 | |
1679 | sb_min_blocksize(sb, BBSIZE); | |
0ec58516 | 1680 | sb->s_xattr = xfs_xattr_handlers; |
a50cd269 | 1681 | sb->s_export_op = &xfs_export_operations; |
a50cd269 NS |
1682 | sb->s_qcop = &xfs_quotactl_operations; |
1683 | sb->s_op = &xfs_super_operations; | |
1da177e4 | 1684 | |
f8f15e42 CH |
1685 | error = xfs_dmops_get(mp, args); |
1686 | if (error) | |
c962fb79 | 1687 | goto out_free_mp; |
f8f15e42 | 1688 | error = xfs_qmops_get(mp, args); |
745f6919 | 1689 | if (error) |
19f354d4 | 1690 | goto out_put_dmops; |
1da177e4 | 1691 | |
f8f15e42 CH |
1692 | if (args->flags & XFSMNT_QUIET) |
1693 | flags |= XFS_MFSI_QUIET; | |
1694 | ||
19f354d4 CH |
1695 | error = xfs_open_devices(mp, args); |
1696 | if (error) | |
1697 | goto out_put_qmops; | |
f8f15e42 | 1698 | |
c962fb79 CH |
1699 | if (xfs_icsb_init_counters(mp)) |
1700 | mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB; | |
1701 | ||
f8f15e42 CH |
1702 | /* |
1703 | * Setup flags based on mount(2) options and then the superblock | |
1704 | */ | |
1705 | error = xfs_start_flags(args, mp); | |
1706 | if (error) | |
a738159d | 1707 | goto out_free_fsname; |
f8f15e42 CH |
1708 | error = xfs_readsb(mp, flags); |
1709 | if (error) | |
a738159d | 1710 | goto out_free_fsname; |
f8f15e42 CH |
1711 | error = xfs_finish_flags(args, mp); |
1712 | if (error) | |
effa2eda | 1713 | goto out_free_sb; |
f8f15e42 | 1714 | |
e34b562c | 1715 | error = xfs_setup_devices(mp); |
19f354d4 | 1716 | if (error) |
effa2eda | 1717 | goto out_free_sb; |
f8f15e42 CH |
1718 | |
1719 | if (mp->m_flags & XFS_MOUNT_BARRIER) | |
1720 | xfs_mountfs_check_barriers(mp); | |
1721 | ||
1722 | error = xfs_filestream_mount(mp); | |
1723 | if (error) | |
effa2eda | 1724 | goto out_free_sb; |
f8f15e42 | 1725 | |
4249023a | 1726 | error = xfs_mountfs(mp); |
f8f15e42 | 1727 | if (error) |
120226c1 | 1728 | goto out_filestream_unmount; |
f8f15e42 CH |
1729 | |
1730 | XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname); | |
1731 | ||
1da177e4 | 1732 | sb->s_dirt = 1; |
4ca488eb CH |
1733 | sb->s_magic = XFS_SB_MAGIC; |
1734 | sb->s_blocksize = mp->m_sb.sb_blocksize; | |
1735 | sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1; | |
1da177e4 LT |
1736 | sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits); |
1737 | sb->s_time_gran = 1; | |
1738 | set_posix_acl_flag(sb); | |
1739 | ||
01651646 | 1740 | root = igrab(VFS_I(mp->m_rootip)); |
f3dcc13f | 1741 | if (!root) { |
cbc89dcf | 1742 | error = ENOENT; |
1da177e4 | 1743 | goto fail_unmount; |
cbc89dcf | 1744 | } |
f3dcc13f CH |
1745 | if (is_bad_inode(root)) { |
1746 | error = EINVAL; | |
1da177e4 LT |
1747 | goto fail_vnrele; |
1748 | } | |
f3dcc13f CH |
1749 | sb->s_root = d_alloc_root(root); |
1750 | if (!sb->s_root) { | |
1751 | error = ENOMEM; | |
1da177e4 LT |
1752 | goto fail_vnrele; |
1753 | } | |
74394496 CH |
1754 | |
1755 | mp->m_sync_work.w_syncer = xfs_sync_worker; | |
1756 | mp->m_sync_work.w_mount = mp; | |
1757 | mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd"); | |
1758 | if (IS_ERR(mp->m_sync_task)) { | |
1759 | error = -PTR_ERR(mp->m_sync_task); | |
1da177e4 | 1760 | goto fail_vnrele; |
74394496 CH |
1761 | } |
1762 | ||
cf441eeb | 1763 | xfs_itrace_exit(XFS_I(sb->s_root->d_inode)); |
1da177e4 | 1764 | |
bdd907ba | 1765 | kfree(args); |
1da177e4 LT |
1766 | return 0; |
1767 | ||
120226c1 CH |
1768 | out_filestream_unmount: |
1769 | xfs_filestream_unmount(mp); | |
effa2eda CH |
1770 | out_free_sb: |
1771 | xfs_freesb(mp); | |
a738159d CH |
1772 | out_free_fsname: |
1773 | xfs_free_fsname(mp); | |
c962fb79 | 1774 | xfs_icsb_destroy_counters(mp); |
19f354d4 CH |
1775 | xfs_close_devices(mp); |
1776 | out_put_qmops: | |
f8f15e42 | 1777 | xfs_qmops_put(mp); |
19f354d4 | 1778 | out_put_dmops: |
f8f15e42 | 1779 | xfs_dmops_put(mp); |
c962fb79 CH |
1780 | out_free_mp: |
1781 | kfree(mp); | |
1782 | out_free_args: | |
1783 | kfree(args); | |
1784 | return -error; | |
f8f15e42 CH |
1785 | |
1786 | fail_vnrele: | |
1da177e4 LT |
1787 | if (sb->s_root) { |
1788 | dput(sb->s_root); | |
1789 | sb->s_root = NULL; | |
1790 | } else { | |
f3dcc13f | 1791 | iput(root); |
1da177e4 LT |
1792 | } |
1793 | ||
f8f15e42 | 1794 | fail_unmount: |
e48ad316 CH |
1795 | /* |
1796 | * Blow away any referenced inode in the filestreams cache. | |
1797 | * This can and will cause log traffic as inodes go inactive | |
1798 | * here. | |
1799 | */ | |
1800 | xfs_filestream_unmount(mp); | |
1801 | ||
1802 | XFS_bflush(mp->m_ddev_targp); | |
1803 | error = xfs_unmount_flush(mp, 0); | |
1804 | WARN_ON(error); | |
1805 | ||
19f354d4 | 1806 | xfs_unmountfs(mp); |
6203300e | 1807 | goto out_free_sb; |
1da177e4 LT |
1808 | } |
1809 | ||
454e2398 | 1810 | STATIC int |
a50cd269 | 1811 | xfs_fs_get_sb( |
1da177e4 LT |
1812 | struct file_system_type *fs_type, |
1813 | int flags, | |
1814 | const char *dev_name, | |
454e2398 DH |
1815 | void *data, |
1816 | struct vfsmount *mnt) | |
1da177e4 | 1817 | { |
454e2398 DH |
1818 | return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super, |
1819 | mnt); | |
a50cd269 NS |
1820 | } |
1821 | ||
7989cb8e | 1822 | static struct super_operations xfs_super_operations = { |
a50cd269 NS |
1823 | .alloc_inode = xfs_fs_alloc_inode, |
1824 | .destroy_inode = xfs_fs_destroy_inode, | |
1825 | .write_inode = xfs_fs_write_inode, | |
1826 | .clear_inode = xfs_fs_clear_inode, | |
1827 | .put_super = xfs_fs_put_super, | |
1828 | .write_super = xfs_fs_write_super, | |
1829 | .sync_fs = xfs_fs_sync_super, | |
1830 | .write_super_lockfs = xfs_fs_lockfs, | |
1831 | .statfs = xfs_fs_statfs, | |
1832 | .remount_fs = xfs_fs_remount, | |
1833 | .show_options = xfs_fs_show_options, | |
1da177e4 LT |
1834 | }; |
1835 | ||
7989cb8e | 1836 | static struct quotactl_ops xfs_quotactl_operations = { |
a50cd269 NS |
1837 | .quota_sync = xfs_fs_quotasync, |
1838 | .get_xstate = xfs_fs_getxstate, | |
1839 | .set_xstate = xfs_fs_setxstate, | |
1840 | .get_xquota = xfs_fs_getxquota, | |
1841 | .set_xquota = xfs_fs_setxquota, | |
1da177e4 LT |
1842 | }; |
1843 | ||
5085b607 | 1844 | static struct file_system_type xfs_fs_type = { |
1da177e4 LT |
1845 | .owner = THIS_MODULE, |
1846 | .name = "xfs", | |
a50cd269 | 1847 | .get_sb = xfs_fs_get_sb, |
1da177e4 LT |
1848 | .kill_sb = kill_block_super, |
1849 | .fs_flags = FS_REQUIRES_DEV, | |
1850 | }; | |
1851 | ||
9f8868ff CH |
1852 | STATIC int __init |
1853 | xfs_alloc_trace_bufs(void) | |
1854 | { | |
1855 | #ifdef XFS_ALLOC_TRACE | |
1856 | xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL); | |
1857 | if (!xfs_alloc_trace_buf) | |
1858 | goto out; | |
1859 | #endif | |
1860 | #ifdef XFS_BMAP_TRACE | |
1861 | xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL); | |
1862 | if (!xfs_bmap_trace_buf) | |
1863 | goto out_free_alloc_trace; | |
1864 | #endif | |
1865 | #ifdef XFS_BMBT_TRACE | |
1866 | xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL); | |
1867 | if (!xfs_bmbt_trace_buf) | |
1868 | goto out_free_bmap_trace; | |
1869 | #endif | |
1870 | #ifdef XFS_ATTR_TRACE | |
1871 | xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL); | |
1872 | if (!xfs_attr_trace_buf) | |
1873 | goto out_free_bmbt_trace; | |
1874 | #endif | |
1875 | #ifdef XFS_DIR2_TRACE | |
1876 | xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL); | |
1877 | if (!xfs_dir2_trace_buf) | |
1878 | goto out_free_attr_trace; | |
1879 | #endif | |
1880 | ||
1881 | return 0; | |
1882 | ||
1883 | #ifdef XFS_DIR2_TRACE | |
1884 | out_free_attr_trace: | |
1885 | #endif | |
1886 | #ifdef XFS_ATTR_TRACE | |
1887 | ktrace_free(xfs_attr_trace_buf); | |
1888 | out_free_bmbt_trace: | |
1889 | #endif | |
1890 | #ifdef XFS_BMBT_TRACE | |
1891 | ktrace_free(xfs_bmbt_trace_buf); | |
1892 | out_free_bmap_trace: | |
1893 | #endif | |
1894 | #ifdef XFS_BMAP_TRACE | |
1895 | ktrace_free(xfs_bmap_trace_buf); | |
1896 | out_free_alloc_trace: | |
1897 | #endif | |
1898 | #ifdef XFS_ALLOC_TRACE | |
1899 | ktrace_free(xfs_alloc_trace_buf); | |
1900 | out: | |
1901 | #endif | |
1902 | return -ENOMEM; | |
1903 | } | |
1904 | ||
1905 | STATIC void | |
1906 | xfs_free_trace_bufs(void) | |
1907 | { | |
1908 | #ifdef XFS_DIR2_TRACE | |
1909 | ktrace_free(xfs_dir2_trace_buf); | |
1910 | #endif | |
1911 | #ifdef XFS_ATTR_TRACE | |
1912 | ktrace_free(xfs_attr_trace_buf); | |
1913 | #endif | |
1914 | #ifdef XFS_BMBT_TRACE | |
1915 | ktrace_free(xfs_bmbt_trace_buf); | |
1916 | #endif | |
1917 | #ifdef XFS_BMAP_TRACE | |
1918 | ktrace_free(xfs_bmap_trace_buf); | |
1919 | #endif | |
1920 | #ifdef XFS_ALLOC_TRACE | |
1921 | ktrace_free(xfs_alloc_trace_buf); | |
1922 | #endif | |
1923 | } | |
1924 | ||
1925 | STATIC int __init | |
1926 | xfs_init_zones(void) | |
1927 | { | |
5ec7f8c7 | 1928 | xfs_vnode_zone = kmem_zone_init_flags(sizeof(struct inode), "xfs_vnode", |
9f8868ff CH |
1929 | KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | |
1930 | KM_ZONE_SPREAD, | |
1931 | xfs_fs_inode_init_once); | |
1932 | if (!xfs_vnode_zone) | |
1933 | goto out; | |
1934 | ||
1935 | xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend"); | |
1936 | if (!xfs_ioend_zone) | |
1937 | goto out_destroy_vnode_zone; | |
1938 | ||
1939 | xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE, | |
1940 | xfs_ioend_zone); | |
1941 | if (!xfs_ioend_pool) | |
1942 | goto out_destroy_ioend_zone; | |
1943 | ||
1944 | xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t), | |
1945 | "xfs_log_ticket"); | |
1946 | if (!xfs_log_ticket_zone) | |
1947 | goto out_destroy_ioend_pool; | |
1948 | ||
1949 | xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t), | |
1950 | "xfs_bmap_free_item"); | |
1951 | if (!xfs_bmap_free_item_zone) | |
1952 | goto out_destroy_log_ticket_zone; | |
1953 | xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t), | |
1954 | "xfs_btree_cur"); | |
1955 | if (!xfs_btree_cur_zone) | |
1956 | goto out_destroy_bmap_free_item_zone; | |
1957 | ||
1958 | xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t), | |
1959 | "xfs_da_state"); | |
1960 | if (!xfs_da_state_zone) | |
1961 | goto out_destroy_btree_cur_zone; | |
1962 | ||
1963 | xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf"); | |
1964 | if (!xfs_dabuf_zone) | |
1965 | goto out_destroy_da_state_zone; | |
1966 | ||
1967 | xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork"); | |
1968 | if (!xfs_ifork_zone) | |
1969 | goto out_destroy_dabuf_zone; | |
1970 | ||
1971 | xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans"); | |
1972 | if (!xfs_trans_zone) | |
1973 | goto out_destroy_ifork_zone; | |
1974 | ||
1975 | /* | |
1976 | * The size of the zone allocated buf log item is the maximum | |
1977 | * size possible under XFS. This wastes a little bit of memory, | |
1978 | * but it is much faster. | |
1979 | */ | |
1980 | xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) + | |
1981 | (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) / | |
1982 | NBWORD) * sizeof(int))), "xfs_buf_item"); | |
1983 | if (!xfs_buf_item_zone) | |
1984 | goto out_destroy_trans_zone; | |
1985 | ||
1986 | xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) + | |
1987 | ((XFS_EFD_MAX_FAST_EXTENTS - 1) * | |
1988 | sizeof(xfs_extent_t))), "xfs_efd_item"); | |
1989 | if (!xfs_efd_zone) | |
1990 | goto out_destroy_buf_item_zone; | |
1991 | ||
1992 | xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) + | |
1993 | ((XFS_EFI_MAX_FAST_EXTENTS - 1) * | |
1994 | sizeof(xfs_extent_t))), "xfs_efi_item"); | |
1995 | if (!xfs_efi_zone) | |
1996 | goto out_destroy_efd_zone; | |
1997 | ||
1998 | xfs_inode_zone = | |
1999 | kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode", | |
2000 | KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | | |
2001 | KM_ZONE_SPREAD, NULL); | |
2002 | if (!xfs_inode_zone) | |
2003 | goto out_destroy_efi_zone; | |
2004 | ||
2005 | xfs_ili_zone = | |
2006 | kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili", | |
2007 | KM_ZONE_SPREAD, NULL); | |
2008 | if (!xfs_ili_zone) | |
2009 | goto out_destroy_inode_zone; | |
2010 | ||
2011 | #ifdef CONFIG_XFS_POSIX_ACL | |
2012 | xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl"); | |
2013 | if (!xfs_acl_zone) | |
2014 | goto out_destroy_ili_zone; | |
2015 | #endif | |
2016 | ||
2017 | return 0; | |
2018 | ||
2019 | #ifdef CONFIG_XFS_POSIX_ACL | |
2020 | out_destroy_ili_zone: | |
2021 | #endif | |
2022 | kmem_zone_destroy(xfs_ili_zone); | |
2023 | out_destroy_inode_zone: | |
2024 | kmem_zone_destroy(xfs_inode_zone); | |
2025 | out_destroy_efi_zone: | |
2026 | kmem_zone_destroy(xfs_efi_zone); | |
2027 | out_destroy_efd_zone: | |
2028 | kmem_zone_destroy(xfs_efd_zone); | |
2029 | out_destroy_buf_item_zone: | |
2030 | kmem_zone_destroy(xfs_buf_item_zone); | |
2031 | out_destroy_trans_zone: | |
2032 | kmem_zone_destroy(xfs_trans_zone); | |
2033 | out_destroy_ifork_zone: | |
2034 | kmem_zone_destroy(xfs_ifork_zone); | |
2035 | out_destroy_dabuf_zone: | |
2036 | kmem_zone_destroy(xfs_dabuf_zone); | |
2037 | out_destroy_da_state_zone: | |
2038 | kmem_zone_destroy(xfs_da_state_zone); | |
2039 | out_destroy_btree_cur_zone: | |
2040 | kmem_zone_destroy(xfs_btree_cur_zone); | |
2041 | out_destroy_bmap_free_item_zone: | |
2042 | kmem_zone_destroy(xfs_bmap_free_item_zone); | |
2043 | out_destroy_log_ticket_zone: | |
2044 | kmem_zone_destroy(xfs_log_ticket_zone); | |
2045 | out_destroy_ioend_pool: | |
2046 | mempool_destroy(xfs_ioend_pool); | |
2047 | out_destroy_ioend_zone: | |
2048 | kmem_zone_destroy(xfs_ioend_zone); | |
2049 | out_destroy_vnode_zone: | |
2050 | kmem_zone_destroy(xfs_vnode_zone); | |
2051 | out: | |
2052 | return -ENOMEM; | |
2053 | } | |
2054 | ||
2055 | STATIC void | |
2056 | xfs_destroy_zones(void) | |
2057 | { | |
2058 | #ifdef CONFIG_XFS_POSIX_ACL | |
2059 | kmem_zone_destroy(xfs_acl_zone); | |
2060 | #endif | |
2061 | kmem_zone_destroy(xfs_ili_zone); | |
2062 | kmem_zone_destroy(xfs_inode_zone); | |
2063 | kmem_zone_destroy(xfs_efi_zone); | |
2064 | kmem_zone_destroy(xfs_efd_zone); | |
2065 | kmem_zone_destroy(xfs_buf_item_zone); | |
2066 | kmem_zone_destroy(xfs_trans_zone); | |
2067 | kmem_zone_destroy(xfs_ifork_zone); | |
2068 | kmem_zone_destroy(xfs_dabuf_zone); | |
2069 | kmem_zone_destroy(xfs_da_state_zone); | |
2070 | kmem_zone_destroy(xfs_btree_cur_zone); | |
2071 | kmem_zone_destroy(xfs_bmap_free_item_zone); | |
2072 | kmem_zone_destroy(xfs_log_ticket_zone); | |
2073 | mempool_destroy(xfs_ioend_pool); | |
2074 | kmem_zone_destroy(xfs_ioend_zone); | |
2075 | kmem_zone_destroy(xfs_vnode_zone); | |
2076 | ||
2077 | } | |
1da177e4 LT |
2078 | |
2079 | STATIC int __init | |
9f8868ff | 2080 | init_xfs_fs(void) |
1da177e4 LT |
2081 | { |
2082 | int error; | |
1da177e4 LT |
2083 | static char message[] __initdata = KERN_INFO \ |
2084 | XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n"; | |
2085 | ||
2086 | printk(message); | |
2087 | ||
1da177e4 | 2088 | ktrace_init(64); |
9f8868ff CH |
2089 | vn_init(); |
2090 | xfs_dir_startup(); | |
1da177e4 | 2091 | |
8758280f | 2092 | error = xfs_init_zones(); |
9f8868ff CH |
2093 | if (error) |
2094 | goto out; | |
2095 | ||
2096 | error = xfs_alloc_trace_bufs(); | |
2097 | if (error) | |
2098 | goto out_destroy_zones; | |
2099 | ||
2100 | error = xfs_mru_cache_init(); | |
2101 | if (error) | |
2102 | goto out_free_trace_buffers; | |
2103 | ||
2104 | error = xfs_filestream_init(); | |
2105 | if (error) | |
2106 | goto out_mru_cache_uninit; | |
1da177e4 | 2107 | |
ce8e922c | 2108 | error = xfs_buf_init(); |
9f8868ff CH |
2109 | if (error) |
2110 | goto out_filestream_uninit; | |
2111 | ||
2112 | error = xfs_init_procfs(); | |
2113 | if (error) | |
2114 | goto out_buf_terminate; | |
2115 | ||
2116 | error = xfs_sysctl_register(); | |
2117 | if (error) | |
2118 | goto out_cleanup_procfs; | |
1da177e4 | 2119 | |
1da177e4 LT |
2120 | vfs_initquota(); |
2121 | ||
2122 | error = register_filesystem(&xfs_fs_type); | |
2123 | if (error) | |
9f8868ff | 2124 | goto out_sysctl_unregister; |
1da177e4 LT |
2125 | return 0; |
2126 | ||
9f8868ff CH |
2127 | out_sysctl_unregister: |
2128 | xfs_sysctl_unregister(); | |
2129 | out_cleanup_procfs: | |
2130 | xfs_cleanup_procfs(); | |
2131 | out_buf_terminate: | |
ce8e922c | 2132 | xfs_buf_terminate(); |
9f8868ff CH |
2133 | out_filestream_uninit: |
2134 | xfs_filestream_uninit(); | |
2135 | out_mru_cache_uninit: | |
2136 | xfs_mru_cache_uninit(); | |
2137 | out_free_trace_buffers: | |
2138 | xfs_free_trace_bufs(); | |
2139 | out_destroy_zones: | |
8758280f | 2140 | xfs_destroy_zones(); |
9f8868ff | 2141 | out: |
1da177e4 LT |
2142 | return error; |
2143 | } | |
2144 | ||
2145 | STATIC void __exit | |
9f8868ff | 2146 | exit_xfs_fs(void) |
1da177e4 LT |
2147 | { |
2148 | vfs_exitquota(); | |
1da177e4 | 2149 | unregister_filesystem(&xfs_fs_type); |
9f8868ff CH |
2150 | xfs_sysctl_unregister(); |
2151 | xfs_cleanup_procfs(); | |
ce8e922c | 2152 | xfs_buf_terminate(); |
9f8868ff CH |
2153 | xfs_filestream_uninit(); |
2154 | xfs_mru_cache_uninit(); | |
2155 | xfs_free_trace_bufs(); | |
8758280f | 2156 | xfs_destroy_zones(); |
1da177e4 LT |
2157 | ktrace_uninit(); |
2158 | } | |
2159 | ||
2160 | module_init(init_xfs_fs); | |
2161 | module_exit(exit_xfs_fs); | |
2162 | ||
2163 | MODULE_AUTHOR("Silicon Graphics, Inc."); | |
2164 | MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled"); | |
2165 | MODULE_LICENSE("GPL"); |