blob: 1d67d7f92a4658855ff2666ae7e14a0931c83897 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scotta805bad2006-06-19 08:40:27 +10002 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
Nathan Scott7b718762005-11-02 14:58:39 +11003 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_log.h"
21#include "xfs_clnt.h"
Nathan Scotta844f452005-11-02 14:38:42 +110022#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_trans.h"
24#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110025#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_dir2.h"
27#include "xfs_alloc.h"
28#include "xfs_dmapi.h"
29#include "xfs_quota.h"
30#include "xfs_mount.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_bmap_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110032#include "xfs_alloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "xfs_ialloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_dir2_sf.h"
Nathan Scotta844f452005-11-02 14:38:42 +110035#include "xfs_attr_sf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "xfs_dinode.h"
37#include "xfs_inode.h"
Nathan Scotta844f452005-11-02 14:38:42 +110038#include "xfs_btree.h"
Christoph Hellwig8c4ed632008-10-30 16:55:13 +110039#include "xfs_btree_trace.h"
Nathan Scotta844f452005-11-02 14:38:42 +110040#include "xfs_ialloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "xfs_bmap.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include "xfs_rtalloc.h"
43#include "xfs_error.h"
44#include "xfs_itable.h"
Christoph Hellwig9909c4a2007-10-11 18:11:14 +100045#include "xfs_fsops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include "xfs_rw.h"
47#include "xfs_acl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include "xfs_attr.h"
49#include "xfs_buf_item.h"
50#include "xfs_utils.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100051#include "xfs_vnodeops.h"
Christoph Hellwig745f6912007-08-30 17:20:39 +100052#include "xfs_vfsops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include "xfs_version.h"
David Chinnera67d7c52007-11-23 16:29:32 +110054#include "xfs_log_priv.h"
David Chinner249a8c12008-02-05 12:13:32 +110055#include "xfs_trans_priv.h"
Christoph Hellwig48b62a12008-05-20 11:30:39 +100056#include "xfs_filestream.h"
Christoph Hellwig9f8868f2008-07-18 17:11:46 +100057#include "xfs_da_btree.h"
58#include "xfs_dir2_trace.h"
59#include "xfs_extfree_item.h"
60#include "xfs_mru_cache.h"
61#include "xfs_inode_item.h"
David Chinnerfe4fa4b2008-10-30 17:06:08 +110062#include "xfs_sync.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#include <linux/namei.h>
65#include <linux/init.h>
66#include <linux/mount.h>
Christoph Hellwig0829c362005-09-02 16:58:49 +100067#include <linux/mempool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#include <linux/writeback.h>
Christoph Hellwig4df08c52005-09-05 08:34:18 +100069#include <linux/kthread.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080070#include <linux/freezer.h>
Christoph Hellwig62a877e2008-07-18 17:12:36 +100071#include <linux/parser.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
David Chinner7989cb82007-02-10 18:34:56 +110073static struct quotactl_ops xfs_quotactl_operations;
74static struct super_operations xfs_super_operations;
David Chinner7989cb82007-02-10 18:34:56 +110075static kmem_zone_t *xfs_ioend_zone;
Christoph Hellwig0829c362005-09-02 16:58:49 +100076mempool_t *xfs_ioend_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78STATIC struct xfs_mount_args *
79xfs_args_allocate(
Nathan Scott764d1f82006-03-31 13:04:17 +100080 struct super_block *sb,
81 int silent)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
83 struct xfs_mount_args *args;
84
Christoph Hellwigbdd907b2008-05-20 15:10:44 +100085 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
86 if (!args)
87 return NULL;
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 args->logbufs = args->logbufsize = -1;
90 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
91
92 /* Copy the already-parsed mount(2) flags we're interested in */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (sb->s_flags & MS_DIRSYNC)
94 args->flags |= XFSMNT_DIRSYNC;
95 if (sb->s_flags & MS_SYNCHRONOUS)
96 args->flags |= XFSMNT_WSYNC;
Nathan Scott764d1f82006-03-31 13:04:17 +100097 if (silent)
98 args->flags |= XFSMNT_QUIET;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 args->flags |= XFSMNT_32BITINODES;
100
101 return args;
102}
103
David Chinnera67d7c52007-11-23 16:29:32 +1100104#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
105#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
106#define MNTOPT_LOGDEV "logdev" /* log device */
107#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
108#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
109#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
110#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
111#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
112#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
113#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
114#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
115#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
116#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
117#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
118#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
119#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
120#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
121#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
122#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
123#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
124 * unwritten extent conversion */
125#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
126#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
127#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
128#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
129#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
130#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
131#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
132 * in stat(). */
133#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
134#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
135#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
136#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
137#define MNTOPT_NOQUOTA "noquota" /* no quotas */
138#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
139#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
140#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
141#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
142#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
143#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
144#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
145#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
146#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
147#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
148#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
149#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
150#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
151
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000152/*
153 * Table driven mount option parser.
154 *
155 * Currently only used for remount, but it will be used for mount
156 * in the future, too.
157 */
158enum {
159 Opt_barrier, Opt_nobarrier, Opt_err
160};
161
Steven Whitehousea447c092008-10-13 10:46:57 +0100162static const match_table_t tokens = {
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000163 {Opt_barrier, "barrier"},
164 {Opt_nobarrier, "nobarrier"},
165 {Opt_err, NULL}
166};
167
168
David Chinnera67d7c52007-11-23 16:29:32 +1100169STATIC unsigned long
170suffix_strtoul(char *s, char **endp, unsigned int base)
171{
172 int last, shift_left_factor = 0;
173 char *value = s;
174
175 last = strlen(value) - 1;
176 if (value[last] == 'K' || value[last] == 'k') {
177 shift_left_factor = 10;
178 value[last] = '\0';
179 }
180 if (value[last] == 'M' || value[last] == 'm') {
181 shift_left_factor = 20;
182 value[last] = '\0';
183 }
184 if (value[last] == 'G' || value[last] == 'g') {
185 shift_left_factor = 30;
186 value[last] = '\0';
187 }
188
189 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
190}
191
192STATIC int
193xfs_parseargs(
194 struct xfs_mount *mp,
195 char *options,
196 struct xfs_mount_args *args,
197 int update)
198{
199 char *this_char, *value, *eov;
200 int dsunit, dswidth, vol_dsunit, vol_dswidth;
201 int iosize;
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100202 int dmapi_implies_ikeep = 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100203
204 args->flags |= XFSMNT_BARRIER;
205 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
206
207 if (!options)
208 goto done;
209
210 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
211
212 while ((this_char = strsep(&options, ",")) != NULL) {
213 if (!*this_char)
214 continue;
215 if ((value = strchr(this_char, '=')) != NULL)
216 *value++ = 0;
217
218 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
219 if (!value || !*value) {
220 cmn_err(CE_WARN,
221 "XFS: %s option requires an argument",
222 this_char);
223 return EINVAL;
224 }
225 args->logbufs = simple_strtoul(value, &eov, 10);
226 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
227 if (!value || !*value) {
228 cmn_err(CE_WARN,
229 "XFS: %s option requires an argument",
230 this_char);
231 return EINVAL;
232 }
233 args->logbufsize = suffix_strtoul(value, &eov, 10);
234 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
235 if (!value || !*value) {
236 cmn_err(CE_WARN,
237 "XFS: %s option requires an argument",
238 this_char);
239 return EINVAL;
240 }
241 strncpy(args->logname, value, MAXNAMELEN);
242 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
243 if (!value || !*value) {
244 cmn_err(CE_WARN,
245 "XFS: %s option requires an argument",
246 this_char);
247 return EINVAL;
248 }
249 strncpy(args->mtpt, value, MAXNAMELEN);
250 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
251 if (!value || !*value) {
252 cmn_err(CE_WARN,
253 "XFS: %s option requires an argument",
254 this_char);
255 return EINVAL;
256 }
257 strncpy(args->rtname, value, MAXNAMELEN);
258 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
259 if (!value || !*value) {
260 cmn_err(CE_WARN,
261 "XFS: %s option requires an argument",
262 this_char);
263 return EINVAL;
264 }
265 iosize = simple_strtoul(value, &eov, 10);
266 args->flags |= XFSMNT_IOSIZE;
267 args->iosizelog = (uint8_t) iosize;
268 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
269 if (!value || !*value) {
270 cmn_err(CE_WARN,
271 "XFS: %s option requires an argument",
272 this_char);
273 return EINVAL;
274 }
275 iosize = suffix_strtoul(value, &eov, 10);
276 args->flags |= XFSMNT_IOSIZE;
277 args->iosizelog = ffs(iosize) - 1;
278 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
279 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
280 mp->m_flags |= XFS_MOUNT_GRPID;
281 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
282 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
283 mp->m_flags &= ~XFS_MOUNT_GRPID;
284 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
285 args->flags |= XFSMNT_WSYNC;
286 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
287 args->flags |= XFSMNT_OSYNCISOSYNC;
288 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
289 args->flags |= XFSMNT_NORECOVERY;
290 } else if (!strcmp(this_char, MNTOPT_INO64)) {
291 args->flags |= XFSMNT_INO64;
292#if !XFS_BIG_INUMS
293 cmn_err(CE_WARN,
294 "XFS: %s option not allowed on this system",
295 this_char);
296 return EINVAL;
297#endif
298 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
299 args->flags |= XFSMNT_NOALIGN;
300 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
301 args->flags |= XFSMNT_SWALLOC;
302 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
303 if (!value || !*value) {
304 cmn_err(CE_WARN,
305 "XFS: %s option requires an argument",
306 this_char);
307 return EINVAL;
308 }
309 dsunit = simple_strtoul(value, &eov, 10);
310 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
311 if (!value || !*value) {
312 cmn_err(CE_WARN,
313 "XFS: %s option requires an argument",
314 this_char);
315 return EINVAL;
316 }
317 dswidth = simple_strtoul(value, &eov, 10);
318 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
319 args->flags &= ~XFSMNT_32BITINODES;
320#if !XFS_BIG_INUMS
321 cmn_err(CE_WARN,
322 "XFS: %s option not allowed on this system",
323 this_char);
324 return EINVAL;
325#endif
326 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
327 args->flags |= XFSMNT_NOUUID;
328 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
329 args->flags |= XFSMNT_BARRIER;
330 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
331 args->flags &= ~XFSMNT_BARRIER;
332 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100333 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100334 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100335 dmapi_implies_ikeep = 0;
336 args->flags &= ~XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100337 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
338 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
339 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
340 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
341 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
342 args->flags |= XFSMNT_ATTR2;
343 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
344 args->flags &= ~XFSMNT_ATTR2;
Tim Shimmin7c12f292008-04-30 18:15:28 +1000345 args->flags |= XFSMNT_NOATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100346 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
347 args->flags2 |= XFSMNT2_FILESTREAMS;
348 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
349 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
350 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
351 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
352 !strcmp(this_char, MNTOPT_UQUOTA) ||
353 !strcmp(this_char, MNTOPT_USRQUOTA)) {
354 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
355 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
356 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
357 args->flags |= XFSMNT_UQUOTA;
358 args->flags &= ~XFSMNT_UQUOTAENF;
359 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
360 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
361 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
362 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
363 args->flags |= XFSMNT_PQUOTA;
364 args->flags &= ~XFSMNT_PQUOTAENF;
365 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
366 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
367 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
368 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
369 args->flags |= XFSMNT_GQUOTA;
370 args->flags &= ~XFSMNT_GQUOTAENF;
371 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
372 args->flags |= XFSMNT_DMAPI;
373 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
374 args->flags |= XFSMNT_DMAPI;
375 } else if (!strcmp(this_char, MNTOPT_DMI)) {
376 args->flags |= XFSMNT_DMAPI;
377 } else if (!strcmp(this_char, "ihashsize")) {
378 cmn_err(CE_WARN,
379 "XFS: ihashsize no longer used, option is deprecated.");
380 } else if (!strcmp(this_char, "osyncisdsync")) {
381 /* no-op, this is now the default */
382 cmn_err(CE_WARN,
383 "XFS: osyncisdsync is now the default, option is deprecated.");
384 } else if (!strcmp(this_char, "irixsgid")) {
385 cmn_err(CE_WARN,
386 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
387 } else {
388 cmn_err(CE_WARN,
389 "XFS: unknown mount option [%s].", this_char);
390 return EINVAL;
391 }
392 }
393
394 if (args->flags & XFSMNT_NORECOVERY) {
395 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
396 cmn_err(CE_WARN,
397 "XFS: no-recovery mounts must be read-only.");
398 return EINVAL;
399 }
400 }
401
402 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
403 cmn_err(CE_WARN,
404 "XFS: sunit and swidth options incompatible with the noalign option");
405 return EINVAL;
406 }
407
408 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
409 cmn_err(CE_WARN,
410 "XFS: cannot mount with both project and group quota");
411 return EINVAL;
412 }
413
414 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
415 printk("XFS: %s option needs the mount point option as well\n",
416 MNTOPT_DMAPI);
417 return EINVAL;
418 }
419
420 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
421 cmn_err(CE_WARN,
422 "XFS: sunit and swidth must be specified together");
423 return EINVAL;
424 }
425
426 if (dsunit && (dswidth % dsunit != 0)) {
427 cmn_err(CE_WARN,
428 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
429 dswidth, dsunit);
430 return EINVAL;
431 }
432
433 /*
434 * Applications using DMI filesystems often expect the
435 * inode generation number to be monotonically increasing.
436 * If we delete inode chunks we break this assumption, so
437 * keep unused inode chunks on disk for DMI filesystems
438 * until we come up with a better solution.
439 * Note that if "ikeep" or "noikeep" mount options are
440 * supplied, then they are honored.
441 */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100442 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
443 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100444
445 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
446 if (dsunit) {
447 args->sunit = dsunit;
448 args->flags |= XFSMNT_RETERR;
449 } else {
450 args->sunit = vol_dsunit;
451 }
452 dswidth ? (args->swidth = dswidth) :
453 (args->swidth = vol_dswidth);
454 } else {
455 args->sunit = args->swidth = 0;
456 }
457
458done:
459 if (args->flags & XFSMNT_32BITINODES)
460 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
461 if (args->flags2)
462 args->flags |= XFSMNT_FLAGS2;
463 return 0;
464}
465
466struct proc_xfs_info {
467 int flag;
468 char *str;
469};
470
471STATIC int
472xfs_showargs(
473 struct xfs_mount *mp,
474 struct seq_file *m)
475{
476 static struct proc_xfs_info xfs_info_set[] = {
477 /* the few simple ones we can get from the mount struct */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100478 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
David Chinnera67d7c52007-11-23 16:29:32 +1100479 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
480 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
481 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
482 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
483 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
484 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
485 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
486 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
487 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
488 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
489 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
490 { 0, NULL }
491 };
492 static struct proc_xfs_info xfs_info_unset[] = {
493 /* the few simple ones we can get from the mount struct */
David Chinnera67d7c52007-11-23 16:29:32 +1100494 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
495 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
496 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
497 { 0, NULL }
498 };
499 struct proc_xfs_info *xfs_infop;
500
501 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
502 if (mp->m_flags & xfs_infop->flag)
503 seq_puts(m, xfs_infop->str);
504 }
505 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
506 if (!(mp->m_flags & xfs_infop->flag))
507 seq_puts(m, xfs_infop->str);
508 }
509
510 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
511 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
512 (int)(1 << mp->m_writeio_log) >> 10);
513
514 if (mp->m_logbufs > 0)
515 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
516 if (mp->m_logbsize > 0)
517 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
518
519 if (mp->m_logname)
520 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
521 if (mp->m_rtname)
522 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
523
524 if (mp->m_dalign > 0)
525 seq_printf(m, "," MNTOPT_SUNIT "=%d",
526 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
527 if (mp->m_swidth > 0)
528 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
529 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
530
531 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
532 seq_puts(m, "," MNTOPT_USRQUOTA);
533 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
534 seq_puts(m, "," MNTOPT_UQUOTANOENF);
535
536 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
537 seq_puts(m, "," MNTOPT_PRJQUOTA);
538 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
539 seq_puts(m, "," MNTOPT_PQUOTANOENF);
540
541 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
542 seq_puts(m, "," MNTOPT_GRPQUOTA);
543 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
544 seq_puts(m, "," MNTOPT_GQUOTANOENF);
545
546 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
547 seq_puts(m, "," MNTOPT_NOQUOTA);
548
549 return 0;
550}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551__uint64_t
552xfs_max_file_offset(
553 unsigned int blockshift)
554{
555 unsigned int pagefactor = 1;
556 unsigned int bitshift = BITS_PER_LONG - 1;
557
558 /* Figure out maximum filesize, on Linux this can depend on
559 * the filesystem blocksize (on 32 bit platforms).
560 * __block_prepare_write does this in an [unsigned] long...
561 * page->index << (PAGE_CACHE_SHIFT - bbits)
562 * So, for page sized blocks (4K on 32 bit platforms),
563 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
564 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
565 * but for smaller blocksizes it is less (bbits = log2 bsize).
566 * Note1: get_block_t takes a long (implicit cast from above)
567 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
568 * can optionally convert the [unsigned] long from above into
569 * an [unsigned] long long.
570 */
571
572#if BITS_PER_LONG == 32
573# if defined(CONFIG_LBD)
574 ASSERT(sizeof(sector_t) == 8);
575 pagefactor = PAGE_CACHE_SIZE;
576 bitshift = BITS_PER_LONG;
577# else
578 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
579# endif
580#endif
581
582 return (((__uint64_t)pagefactor) << bitshift) - 1;
583}
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585int
586xfs_blkdev_get(
587 xfs_mount_t *mp,
588 const char *name,
589 struct block_device **bdevp)
590{
591 int error = 0;
592
Al Viro30c40d22008-02-22 19:50:45 -0500593 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 if (IS_ERR(*bdevp)) {
595 error = PTR_ERR(*bdevp);
596 printk("XFS: Invalid device [%s], error=%d\n", name, error);
597 }
598
599 return -error;
600}
601
602void
603xfs_blkdev_put(
604 struct block_device *bdev)
605{
606 if (bdev)
Al Viro30c40d22008-02-22 19:50:45 -0500607 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608}
609
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100610/*
611 * Try to write out the superblock using barriers.
612 */
613STATIC int
614xfs_barrier_test(
615 xfs_mount_t *mp)
616{
617 xfs_buf_t *sbp = xfs_getsb(mp, 0);
618 int error;
619
620 XFS_BUF_UNDONE(sbp);
621 XFS_BUF_UNREAD(sbp);
622 XFS_BUF_UNDELAYWRITE(sbp);
623 XFS_BUF_WRITE(sbp);
624 XFS_BUF_UNASYNC(sbp);
625 XFS_BUF_ORDERED(sbp);
626
627 xfsbdstrat(mp, sbp);
628 error = xfs_iowait(sbp);
629
630 /*
631 * Clear all the flags we set and possible error state in the
632 * buffer. We only did the write to try out whether barriers
633 * worked and shouldn't leave any traces in the superblock
634 * buffer.
635 */
636 XFS_BUF_DONE(sbp);
637 XFS_BUF_ERROR(sbp, 0);
638 XFS_BUF_UNORDERED(sbp);
639
640 xfs_buf_relse(sbp);
641 return error;
642}
643
644void
645xfs_mountfs_check_barriers(xfs_mount_t *mp)
646{
647 int error;
648
649 if (mp->m_logdev_targp != mp->m_ddev_targp) {
650 xfs_fs_cmn_err(CE_NOTE, mp,
651 "Disabling barriers, not supported with external log device");
652 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100653 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100654 }
655
Nathan Scottb2ea4012006-07-28 17:05:13 +1000656 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
657 xfs_fs_cmn_err(CE_NOTE, mp,
658 "Disabling barriers, underlying device is readonly");
659 mp->m_flags &= ~XFS_MOUNT_BARRIER;
660 return;
661 }
662
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100663 error = xfs_barrier_test(mp);
664 if (error) {
665 xfs_fs_cmn_err(CE_NOTE, mp,
666 "Disabling barriers, trial barrier write failed");
667 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100668 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100669 }
670}
671
672void
673xfs_blkdev_issue_flush(
674 xfs_buftarg_t *buftarg)
675{
Nathan Scottce8e9222006-01-11 15:39:08 +1100676 blkdev_issue_flush(buftarg->bt_bdev, NULL);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100677}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000679STATIC void
680xfs_close_devices(
681 struct xfs_mount *mp)
682{
683 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000684 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000685 xfs_free_buftarg(mp->m_logdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000686 xfs_blkdev_put(logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000687 }
688 if (mp->m_rtdev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000689 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000690 xfs_free_buftarg(mp->m_rtdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000691 xfs_blkdev_put(rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000692 }
693 xfs_free_buftarg(mp->m_ddev_targp);
694}
695
696/*
697 * The file system configurations are:
698 * (1) device (partition) with data and internal log
699 * (2) logical volume with data and log subvolumes.
700 * (3) logical volume with data, log, and realtime subvolumes.
701 *
702 * We only have to handle opening the log and realtime volumes here if
703 * they are present. The data subvolume has already been opened by
704 * get_sb_bdev() and is stored in sb->s_bdev.
705 */
706STATIC int
707xfs_open_devices(
708 struct xfs_mount *mp,
709 struct xfs_mount_args *args)
710{
711 struct block_device *ddev = mp->m_super->s_bdev;
712 struct block_device *logdev = NULL, *rtdev = NULL;
713 int error;
714
715 /*
716 * Open real time and log devices - order is important.
717 */
718 if (args->logname[0]) {
719 error = xfs_blkdev_get(mp, args->logname, &logdev);
720 if (error)
721 goto out;
722 }
723
724 if (args->rtname[0]) {
725 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
726 if (error)
727 goto out_close_logdev;
728
729 if (rtdev == ddev || rtdev == logdev) {
730 cmn_err(CE_WARN,
731 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
732 error = EINVAL;
733 goto out_close_rtdev;
734 }
735 }
736
737 /*
738 * Setup xfs_mount buffer target pointers
739 */
740 error = ENOMEM;
741 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
742 if (!mp->m_ddev_targp)
743 goto out_close_rtdev;
744
745 if (rtdev) {
746 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
747 if (!mp->m_rtdev_targp)
748 goto out_free_ddev_targ;
749 }
750
751 if (logdev && logdev != ddev) {
752 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
753 if (!mp->m_logdev_targp)
754 goto out_free_rtdev_targ;
755 } else {
756 mp->m_logdev_targp = mp->m_ddev_targp;
757 }
758
759 return 0;
760
761 out_free_rtdev_targ:
762 if (mp->m_rtdev_targp)
763 xfs_free_buftarg(mp->m_rtdev_targp);
764 out_free_ddev_targ:
765 xfs_free_buftarg(mp->m_ddev_targp);
766 out_close_rtdev:
767 if (rtdev)
768 xfs_blkdev_put(rtdev);
769 out_close_logdev:
770 if (logdev && logdev != ddev)
771 xfs_blkdev_put(logdev);
772 out:
773 return error;
774}
775
Christoph Hellwige34b5622008-05-20 15:10:36 +1000776/*
777 * Setup xfs_mount buffer target pointers based on superblock
778 */
779STATIC int
780xfs_setup_devices(
781 struct xfs_mount *mp)
782{
783 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000784
Christoph Hellwige34b5622008-05-20 15:10:36 +1000785 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
786 mp->m_sb.sb_sectsize);
787 if (error)
788 return error;
789
790 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
791 unsigned int log_sector_size = BBSIZE;
792
793 if (xfs_sb_version_hassector(&mp->m_sb))
794 log_sector_size = mp->m_sb.sb_logsectsize;
795 error = xfs_setsize_buftarg(mp->m_logdev_targp,
796 mp->m_sb.sb_blocksize,
797 log_sector_size);
798 if (error)
799 return error;
800 }
801 if (mp->m_rtdev_targp) {
802 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
803 mp->m_sb.sb_blocksize,
804 mp->m_sb.sb_sectsize);
805 if (error)
806 return error;
807 }
808
809 return 0;
810}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000811
David Chinner249a8c12008-02-05 12:13:32 +1100812/*
813 * XFS AIL push thread support
814 */
815void
816xfsaild_wakeup(
817 xfs_mount_t *mp,
818 xfs_lsn_t threshold_lsn)
819{
820 mp->m_ail.xa_target = threshold_lsn;
821 wake_up_process(mp->m_ail.xa_task);
822}
823
824int
825xfsaild(
826 void *data)
827{
828 xfs_mount_t *mp = (xfs_mount_t *)data;
829 xfs_lsn_t last_pushed_lsn = 0;
830 long tout = 0;
831
832 while (!kthread_should_stop()) {
833 if (tout)
834 schedule_timeout_interruptible(msecs_to_jiffies(tout));
835 tout = 1000;
836
837 /* swsusp */
838 try_to_freeze();
839
840 ASSERT(mp->m_log);
841 if (XFS_FORCED_SHUTDOWN(mp))
842 continue;
843
844 tout = xfsaild_push(mp, &last_pushed_lsn);
845 }
846
847 return 0;
848} /* xfsaild */
849
850int
851xfsaild_start(
852 xfs_mount_t *mp)
853{
854 mp->m_ail.xa_target = 0;
855 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
856 if (IS_ERR(mp->m_ail.xa_task))
857 return -PTR_ERR(mp->m_ail.xa_task);
858 return 0;
859}
860
861void
862xfsaild_stop(
863 xfs_mount_t *mp)
864{
865 kthread_stop(mp->m_ail.xa_task);
866}
867
868
David Chinnerbf904242008-10-30 17:36:14 +1100869/* Catch misguided souls that try to use this interface on XFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100871xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 struct super_block *sb)
873{
David Chinnerbf904242008-10-30 17:36:14 +1100874 BUG();
Lachlan McIlroy493dca62008-10-30 17:36:52 +1100875 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876}
877
David Chinnerbf904242008-10-30 17:36:14 +1100878/*
David Chinner99fa8cb2008-10-30 17:36:40 +1100879 * Now that the generic code is guaranteed not to be accessing
880 * the linux inode, we can reclaim the inode.
David Chinnerbf904242008-10-30 17:36:14 +1100881 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100883xfs_fs_destroy_inode(
David Chinnerbf904242008-10-30 17:36:14 +1100884 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
David Chinner99fa8cb2008-10-30 17:36:40 +1100886 xfs_inode_t *ip = XFS_I(inode);
887
888 XFS_STATS_INC(vn_reclaim);
889 if (xfs_reclaim(ip))
890 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891}
892
David Chinner07c8f672008-10-30 16:11:59 +1100893/*
894 * Slab object creation initialisation for the XFS inode.
895 * This covers only the idempotent fields in the XFS inode;
896 * all other fields need to be initialised on allocation
897 * from the slab. This avoids the need to repeatedly intialise
898 * fields in the xfs inode that left in the initialise state
899 * when freeing the inode.
900 */
David Chinnerbf904242008-10-30 17:36:14 +1100901STATIC void
902xfs_fs_inode_init_once(
David Chinner07c8f672008-10-30 16:11:59 +1100903 void *inode)
904{
905 struct xfs_inode *ip = inode;
906
907 memset(ip, 0, sizeof(struct xfs_inode));
David Chinnerbf904242008-10-30 17:36:14 +1100908
909 /* vfs inode */
910 inode_init_once(VFS_I(ip));
911
912 /* xfs inode */
David Chinner07c8f672008-10-30 16:11:59 +1100913 atomic_set(&ip->i_iocount, 0);
914 atomic_set(&ip->i_pincount, 0);
915 spin_lock_init(&ip->i_flags_lock);
916 INIT_LIST_HEAD(&ip->i_reclaim);
917 init_waitqueue_head(&ip->i_ipin_wait);
918 /*
919 * Because we want to use a counting completion, complete
920 * the flush completion once to allow a single access to
921 * the flush completion without blocking.
922 */
923 init_completion(&ip->i_flush);
924 complete(&ip->i_flush);
925
926 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
927 "xfsino", ip->i_ino);
928 mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
929}
930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931/*
932 * Attempt to flush the inode, this will actually fail
933 * if the inode is pinned, but we dirty the inode again
934 * at the point when it is unpinned after a log write,
Nathan Scott87582802006-03-14 13:18:19 +1100935 * since this is when the inode itself becomes flushable.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 */
937STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +1100938xfs_fs_write_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 struct inode *inode,
940 int sync)
941{
David Chinnera3f74ff2008-03-06 13:43:42 +1100942 int error = 0;
943 int flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100945 xfs_itrace_entry(XFS_I(inode));
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000946 if (sync) {
947 filemap_fdatawait(inode->i_mapping);
948 flags |= FLUSH_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000950 error = xfs_inode_flush(XFS_I(inode), flags);
Lachlan McIlroye893bff2007-10-12 11:13:35 +1000951 /*
952 * if we failed to write out the inode then mark
953 * it dirty again so we'll try again later.
954 */
955 if (error)
David Chinner94b97e32008-10-30 17:21:30 +1100956 xfs_mark_inode_dirty_sync(XFS_I(inode));
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 return -error;
959}
960
961STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100962xfs_fs_clear_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 struct inode *inode)
964{
Christoph Hellwig1543d792007-08-29 11:46:47 +1000965 xfs_inode_t *ip = XFS_I(inode);
Christoph Hellwig56d433e2005-09-05 08:23:54 +1000966
David Chinner99fa8cb2008-10-30 17:36:40 +1100967 xfs_itrace_entry(ip);
968 XFS_STATS_INC(vn_rele);
969 XFS_STATS_INC(vn_remove);
970 XFS_STATS_DEC(vn_active);
Christoph Hellwig56d433e2005-09-05 08:23:54 +1000971
David Chinner99fa8cb2008-10-30 17:36:40 +1100972 xfs_inactive(ip);
973 xfs_iflags_clear(ip, XFS_IMODIFIED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976STATIC void
Christoph Hellwiga7381592008-08-13 16:04:05 +1000977xfs_free_fsname(
978 struct xfs_mount *mp)
979{
980 kfree(mp->m_fsname);
981 kfree(mp->m_rtname);
982 kfree(mp->m_logname);
983}
984
985STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100986xfs_fs_put_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 struct super_block *sb)
988{
Christoph Hellwig745f6912007-08-30 17:20:39 +1000989 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwige48ad312008-05-20 11:30:52 +1000990 struct xfs_inode *rip = mp->m_rootip;
991 int unmount_event_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 int error;
993
David Chinnera167b172008-10-30 17:06:18 +1100994 xfs_syncd_stop(mp);
David Chinnerbe97d9d2008-10-30 17:15:38 +1100995 xfs_sync_inodes(mp, SYNC_ATTR|SYNC_DELWRI);
Christoph Hellwige48ad312008-05-20 11:30:52 +1000996
997#ifdef HAVE_DMAPI
998 if (mp->m_flags & XFS_MOUNT_DMAPI) {
999 unmount_event_flags =
1000 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1001 0 : DM_FLAGS_UNWANTED;
1002 /*
1003 * Ignore error from dmapi here, first unmount is not allowed
1004 * to fail anyway, and second we wouldn't want to fail a
1005 * unmount because of dmapi.
1006 */
1007 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1008 NULL, NULL, 0, 0, unmount_event_flags);
1009 }
1010#endif
1011
1012 /*
1013 * Blow away any referenced inode in the filestreams cache.
1014 * This can and will cause log traffic as inodes go inactive
1015 * here.
1016 */
1017 xfs_filestream_unmount(mp);
1018
1019 XFS_bflush(mp->m_ddev_targp);
1020 error = xfs_unmount_flush(mp, 0);
1021 WARN_ON(error);
1022
Christoph Hellwige48ad312008-05-20 11:30:52 +10001023 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1024 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1025 unmount_event_flags);
1026 }
1027
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001028 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001029 xfs_freesb(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001030 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001031 xfs_close_devices(mp);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001032 xfs_qmops_put(mp);
1033 xfs_dmops_put(mp);
Christoph Hellwiga7381592008-08-13 16:04:05 +10001034 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001035 kfree(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036}
1037
1038STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001039xfs_fs_write_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 struct super_block *sb)
1041{
Nathan Scottb83bd132006-06-09 16:48:30 +10001042 if (!(sb->s_flags & MS_RDONLY))
David Chinnere9f1c6e2008-10-30 17:15:50 +11001043 xfs_sync_fsdata(XFS_M(sb), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 sb->s_dirt = 0;
1045}
1046
1047STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001048xfs_fs_sync_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 struct super_block *sb,
1050 int wait)
1051{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001052 struct xfs_mount *mp = XFS_M(sb);
Nathan Scottb83bd132006-06-09 16:48:30 +10001053 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001055 /*
1056 * Treat a sync operation like a freeze. This is to work
1057 * around a race in sync_inodes() which works in two phases
1058 * - an asynchronous flush, which can write out an inode
1059 * without waiting for file size updates to complete, and a
1060 * synchronous flush, which wont do anything because the
1061 * async flush removed the inode's dirty flag. Also
1062 * sync_inodes() will not see any files that just have
1063 * outstanding transactions to be flushed because we don't
1064 * dirty the Linux inode until after the transaction I/O
1065 * completes.
1066 */
David Chinnere9f1c6e2008-10-30 17:15:50 +11001067 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE))
1068 error = xfs_quiesce_data(mp);
1069 else
1070 error = xfs_sync_fsdata(mp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 sb->s_dirt = 0;
1072
1073 if (unlikely(laptop_mode)) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001074 int prev_sync_seq = mp->m_sync_seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
1076 /*
1077 * The disk must be active because we're syncing.
1078 * We schedule xfssyncd now (now that the disk is
1079 * active) instead of later (when it might not be).
1080 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001081 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 /*
1083 * We have to wait for the sync iteration to complete.
1084 * If we don't, the disk activity caused by the sync
1085 * will come after the sync is completed, and that
1086 * triggers another sync from laptop mode.
1087 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001088 wait_event(mp->m_wait_single_sync_task,
1089 mp->m_sync_seq != prev_sync_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091
1092 return -error;
1093}
1094
1095STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001096xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001097 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 struct kstatfs *statp)
1099{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001100 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1101 xfs_sb_t *sbp = &mp->m_sb;
1102 __uint64_t fakeinos, id;
1103 xfs_extlen_t lsize;
1104
1105 statp->f_type = XFS_SB_MAGIC;
1106 statp->f_namelen = MAXNAMELEN - 1;
1107
1108 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1109 statp->f_fsid.val[0] = (u32)id;
1110 statp->f_fsid.val[1] = (u32)(id >> 32);
1111
Christoph Hellwigd4d90b52008-04-22 17:34:37 +10001112 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001113
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;
1118 statp->f_bfree = statp->f_bavail =
1119 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1120 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1121#if XFS_BIG_INUMS
1122 fakeinos += mp->m_inoadd;
1123#endif
1124 statp->f_files =
1125 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1126 if (mp->m_maxicount)
1127#if XFS_BIG_INUMS
1128 if (!mp->m_inoadd)
1129#endif
1130 statp->f_files = min_t(typeof(statp->f_files),
1131 statp->f_files,
1132 mp->m_maxicount);
1133 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1134 spin_unlock(&mp->m_sb_lock);
1135
1136 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1137 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138}
1139
1140STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001141xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 struct super_block *sb,
1143 int *flags,
1144 char *options)
1145{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001146 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001147 substring_t args[MAX_OPT_ARGS];
1148 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001150 while ((p = strsep(&options, ",")) != NULL) {
1151 int token;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001152
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001153 if (!*p)
1154 continue;
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001155
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001156 token = match_token(p, tokens, args);
1157 switch (token) {
1158 case Opt_barrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001159 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001160
1161 /*
1162 * Test if barriers are actually working if we can,
1163 * else delay this check until the filesystem is
1164 * marked writeable.
1165 */
1166 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1167 xfs_mountfs_check_barriers(mp);
1168 break;
1169 case Opt_nobarrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001170 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001171 break;
1172 default:
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001173 /*
1174 * Logically we would return an error here to prevent
1175 * users from believing they might have changed
1176 * mount options using remount which can't be changed.
1177 *
1178 * But unfortunately mount(8) adds all options from
1179 * mtab and fstab to the mount arguments in some cases
1180 * so we can't blindly reject options, but have to
1181 * check for each specified option if it actually
1182 * differs from the currently set option and only
1183 * reject it if that's the case.
1184 *
1185 * Until that is implemented we return success for
1186 * every remount request, and silently ignore all
1187 * options that we can't actually change.
1188 */
1189#if 0
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001190 printk(KERN_INFO
1191 "XFS: mount option \"%s\" not supported for remount\n", p);
1192 return -EINVAL;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001193#else
Christoph Hellwig6c5e51d2008-10-12 14:30:44 +02001194 break;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001195#endif
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001196 }
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001197 }
1198
1199 /* rw/ro -> rw */
1200 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1201 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1202 if (mp->m_flags & XFS_MOUNT_BARRIER)
1203 xfs_mountfs_check_barriers(mp);
1204 }
1205
1206 /* rw -> ro */
1207 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
David Chinnere9f1c6e2008-10-30 17:15:50 +11001208 xfs_quiesce_data(mp);
David Chinner76bf1052008-10-30 17:16:21 +11001209 xfs_quiesce_attr(mp);
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001210 mp->m_flags |= XFS_MOUNT_RDONLY;
1211 }
1212
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001213 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214}
1215
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001216/*
1217 * Second stage of a freeze. The data is already frozen so we only
David Chinner76bf1052008-10-30 17:16:21 +11001218 * need to take care of the metadata. Once that's done write a dummy
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001219 * record to dirty the log in case of a crash while frozen.
1220 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001222xfs_fs_lockfs(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 struct super_block *sb)
1224{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001225 struct xfs_mount *mp = XFS_M(sb);
1226
David Chinner76bf1052008-10-30 17:16:21 +11001227 xfs_quiesce_attr(mp);
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001228 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229}
1230
1231STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001232xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 struct seq_file *m,
1234 struct vfsmount *mnt)
1235{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001236 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237}
1238
1239STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001240xfs_fs_quotasync(
Nathan Scottee348072005-11-02 10:32:38 +11001241 struct super_block *sb,
1242 int type)
1243{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001244 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
Nathan Scottee348072005-11-02 10:32:38 +11001245}
1246
1247STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001248xfs_fs_getxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 struct super_block *sb,
1250 struct fs_quota_stat *fqs)
1251{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001252 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253}
1254
1255STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001256xfs_fs_setxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 struct super_block *sb,
1258 unsigned int flags,
1259 int op)
1260{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001261 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262}
1263
1264STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001265xfs_fs_getxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 struct super_block *sb,
1267 int type,
1268 qid_t id,
1269 struct fs_disk_quota *fdq)
1270{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001271 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001272 (type == USRQUOTA) ? Q_XGETQUOTA :
1273 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1274 Q_XGETPQUOTA), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275}
1276
1277STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001278xfs_fs_setxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 struct super_block *sb,
1280 int type,
1281 qid_t id,
1282 struct fs_disk_quota *fdq)
1283{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001284 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001285 (type == USRQUOTA) ? Q_XSETQLIM :
1286 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1287 Q_XSETPQLIM), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288}
1289
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001290/*
1291 * This function fills in xfs_mount_t fields based on mount args.
1292 * Note: the superblock has _not_ yet been read in.
1293 */
1294STATIC int
1295xfs_start_flags(
1296 struct xfs_mount_args *ap,
1297 struct xfs_mount *mp)
1298{
Christoph Hellwiga7381592008-08-13 16:04:05 +10001299 int error;
1300
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001301 /* Values are in BBs */
1302 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1303 /*
1304 * At this point the superblock has not been read
1305 * in, therefore we do not know the block size.
1306 * Before the mount call ends we will convert
1307 * these to FSBs.
1308 */
1309 mp->m_dalign = ap->sunit;
1310 mp->m_swidth = ap->swidth;
1311 }
1312
1313 if (ap->logbufs != -1 &&
1314 ap->logbufs != 0 &&
1315 (ap->logbufs < XLOG_MIN_ICLOGS ||
1316 ap->logbufs > XLOG_MAX_ICLOGS)) {
1317 cmn_err(CE_WARN,
1318 "XFS: invalid logbufs value: %d [not %d-%d]",
1319 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1320 return XFS_ERROR(EINVAL);
1321 }
1322 mp->m_logbufs = ap->logbufs;
1323 if (ap->logbufsize != -1 &&
1324 ap->logbufsize != 0 &&
1325 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1326 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1327 !is_power_of_2(ap->logbufsize))) {
1328 cmn_err(CE_WARN,
1329 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1330 ap->logbufsize);
1331 return XFS_ERROR(EINVAL);
1332 }
Christoph Hellwiga7381592008-08-13 16:04:05 +10001333
1334 error = ENOMEM;
1335
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001336 mp->m_logbsize = ap->logbufsize;
1337 mp->m_fsname_len = strlen(ap->fsname) + 1;
Christoph Hellwiga7381592008-08-13 16:04:05 +10001338
1339 mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL);
1340 if (!mp->m_fsname)
1341 goto out;
1342
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001343 if (ap->rtname[0]) {
Christoph Hellwiga7381592008-08-13 16:04:05 +10001344 mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL);
1345 if (!mp->m_rtname)
1346 goto out_free_fsname;
1347
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001348 }
Christoph Hellwiga7381592008-08-13 16:04:05 +10001349
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001350 if (ap->logname[0]) {
Christoph Hellwiga7381592008-08-13 16:04:05 +10001351 mp->m_logname = kstrdup(ap->logname, GFP_KERNEL);
1352 if (!mp->m_logname)
1353 goto out_free_rtname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001354 }
1355
1356 if (ap->flags & XFSMNT_WSYNC)
1357 mp->m_flags |= XFS_MOUNT_WSYNC;
1358#if XFS_BIG_INUMS
1359 if (ap->flags & XFSMNT_INO64) {
1360 mp->m_flags |= XFS_MOUNT_INO64;
1361 mp->m_inoadd = XFS_INO64_OFFSET;
1362 }
1363#endif
1364 if (ap->flags & XFSMNT_RETERR)
1365 mp->m_flags |= XFS_MOUNT_RETERR;
1366 if (ap->flags & XFSMNT_NOALIGN)
1367 mp->m_flags |= XFS_MOUNT_NOALIGN;
1368 if (ap->flags & XFSMNT_SWALLOC)
1369 mp->m_flags |= XFS_MOUNT_SWALLOC;
1370 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1371 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1372 if (ap->flags & XFSMNT_32BITINODES)
1373 mp->m_flags |= XFS_MOUNT_32BITINODES;
1374
1375 if (ap->flags & XFSMNT_IOSIZE) {
1376 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1377 ap->iosizelog < XFS_MIN_IO_LOG) {
1378 cmn_err(CE_WARN,
1379 "XFS: invalid log iosize: %d [not %d-%d]",
1380 ap->iosizelog, XFS_MIN_IO_LOG,
1381 XFS_MAX_IO_LOG);
1382 return XFS_ERROR(EINVAL);
1383 }
1384
1385 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1386 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1387 }
1388
1389 if (ap->flags & XFSMNT_IKEEP)
1390 mp->m_flags |= XFS_MOUNT_IKEEP;
1391 if (ap->flags & XFSMNT_DIRSYNC)
1392 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1393 if (ap->flags & XFSMNT_ATTR2)
1394 mp->m_flags |= XFS_MOUNT_ATTR2;
1395 if (ap->flags & XFSMNT_NOATTR2)
1396 mp->m_flags |= XFS_MOUNT_NOATTR2;
1397
1398 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1399 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1400
1401 /*
1402 * no recovery flag requires a read-only mount
1403 */
1404 if (ap->flags & XFSMNT_NORECOVERY) {
1405 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1406 cmn_err(CE_WARN,
1407 "XFS: tried to mount a FS read-write without recovery!");
1408 return XFS_ERROR(EINVAL);
1409 }
1410 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1411 }
1412
1413 if (ap->flags & XFSMNT_NOUUID)
1414 mp->m_flags |= XFS_MOUNT_NOUUID;
1415 if (ap->flags & XFSMNT_BARRIER)
1416 mp->m_flags |= XFS_MOUNT_BARRIER;
1417 else
1418 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1419
1420 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1421 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1422
1423 if (ap->flags & XFSMNT_DMAPI)
1424 mp->m_flags |= XFS_MOUNT_DMAPI;
1425 return 0;
Christoph Hellwiga7381592008-08-13 16:04:05 +10001426
1427
1428 out_free_rtname:
1429 kfree(mp->m_rtname);
1430 out_free_fsname:
1431 kfree(mp->m_fsname);
1432 out:
1433 return error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001434}
1435
1436/*
1437 * This function fills in xfs_mount_t fields based on mount args.
1438 * Note: the superblock _has_ now been read in.
1439 */
1440STATIC int
1441xfs_finish_flags(
1442 struct xfs_mount_args *ap,
1443 struct xfs_mount *mp)
1444{
1445 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1446
1447 /* Fail a mount where the logbuf is smaller then the log stripe */
1448 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1449 if ((ap->logbufsize <= 0) &&
1450 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1451 mp->m_logbsize = mp->m_sb.sb_logsunit;
1452 } else if (ap->logbufsize > 0 &&
1453 ap->logbufsize < mp->m_sb.sb_logsunit) {
1454 cmn_err(CE_WARN,
1455 "XFS: logbuf size must be greater than or equal to log stripe size");
1456 return XFS_ERROR(EINVAL);
1457 }
1458 } else {
1459 /* Fail a mount if the logbuf is larger than 32K */
1460 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1461 cmn_err(CE_WARN,
1462 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1463 return XFS_ERROR(EINVAL);
1464 }
1465 }
1466
1467 /*
1468 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1469 * told by noattr2 to turn it off
1470 */
1471 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1472 !(ap->flags & XFSMNT_NOATTR2))
1473 mp->m_flags |= XFS_MOUNT_ATTR2;
1474
1475 /*
1476 * prohibit r/w mounts of read-only filesystems
1477 */
1478 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1479 cmn_err(CE_WARN,
1480 "XFS: cannot mount a read-only filesystem as read-write");
1481 return XFS_ERROR(EROFS);
1482 }
1483
1484 /*
1485 * check for shared mount.
1486 */
1487 if (ap->flags & XFSMNT_SHARED) {
1488 if (!xfs_sb_version_hasshared(&mp->m_sb))
1489 return XFS_ERROR(EINVAL);
1490
1491 /*
1492 * For IRIX 6.5, shared mounts must have the shared
1493 * version bit set, have the persistent readonly
1494 * field set, must be version 0 and can only be mounted
1495 * read-only.
1496 */
1497 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1498 (mp->m_sb.sb_shared_vn != 0))
1499 return XFS_ERROR(EINVAL);
1500
1501 mp->m_flags |= XFS_MOUNT_SHARED;
1502
1503 /*
1504 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1505 */
1506 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1507 return XFS_ERROR(EINVAL);
1508 }
1509
1510 if (ap->flags & XFSMNT_UQUOTA) {
1511 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1512 if (ap->flags & XFSMNT_UQUOTAENF)
1513 mp->m_qflags |= XFS_UQUOTA_ENFD;
1514 }
1515
1516 if (ap->flags & XFSMNT_GQUOTA) {
1517 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1518 if (ap->flags & XFSMNT_GQUOTAENF)
1519 mp->m_qflags |= XFS_OQUOTA_ENFD;
1520 } else if (ap->flags & XFSMNT_PQUOTA) {
1521 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1522 if (ap->flags & XFSMNT_PQUOTAENF)
1523 mp->m_qflags |= XFS_OQUOTA_ENFD;
1524 }
1525
1526 return 0;
1527}
1528
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001530xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 struct super_block *sb,
1532 void *data,
1533 int silent)
1534{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001535 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001536 struct xfs_mount *mp = NULL;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001537 struct xfs_mount_args *args;
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001538 int flags = 0, error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001540 args = xfs_args_allocate(sb, silent);
1541 if (!args)
1542 return -ENOMEM;
1543
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001544 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1545 if (!mp)
1546 goto out_free_args;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001548 spin_lock_init(&mp->m_sb_lock);
1549 mutex_init(&mp->m_ilock);
1550 mutex_init(&mp->m_growlock);
1551 atomic_set(&mp->m_active_trans, 0);
Christoph Hellwig74394492007-08-30 17:21:22 +10001552 INIT_LIST_HEAD(&mp->m_sync_list);
1553 spin_lock_init(&mp->m_sync_lock);
1554 init_waitqueue_head(&mp->m_wait_single_sync_task);
1555
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001556 mp->m_super = sb;
1557 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001559 if (sb->s_flags & MS_RDONLY)
1560 mp->m_flags |= XFS_MOUNT_RDONLY;
1561
Christoph Hellwig745f6912007-08-30 17:20:39 +10001562 error = xfs_parseargs(mp, (char *)data, args, 0);
1563 if (error)
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001564 goto out_free_mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 sb_min_blocksize(sb, BBSIZE);
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001567 sb->s_xattr = xfs_xattr_handlers;
Nathan Scotta50cd262006-03-14 14:06:18 +11001568 sb->s_export_op = &xfs_export_operations;
Nathan Scotta50cd262006-03-14 14:06:18 +11001569 sb->s_qcop = &xfs_quotactl_operations;
1570 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001572 error = xfs_dmops_get(mp, args);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001573 if (error)
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001574 goto out_free_mp;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001575 error = xfs_qmops_get(mp, args);
1576 if (error)
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001577 goto out_put_dmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001578
1579 if (args->flags & XFSMNT_QUIET)
1580 flags |= XFS_MFSI_QUIET;
1581
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001582 error = xfs_open_devices(mp, args);
1583 if (error)
1584 goto out_put_qmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001585
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001586 if (xfs_icsb_init_counters(mp))
1587 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1588
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001589 /*
1590 * Setup flags based on mount(2) options and then the superblock
1591 */
1592 error = xfs_start_flags(args, mp);
1593 if (error)
Christoph Hellwiga7381592008-08-13 16:04:05 +10001594 goto out_free_fsname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001595 error = xfs_readsb(mp, flags);
1596 if (error)
Christoph Hellwiga7381592008-08-13 16:04:05 +10001597 goto out_free_fsname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001598 error = xfs_finish_flags(args, mp);
1599 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001600 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001601
Christoph Hellwige34b5622008-05-20 15:10:36 +10001602 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001603 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001604 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001605
1606 if (mp->m_flags & XFS_MOUNT_BARRIER)
1607 xfs_mountfs_check_barriers(mp);
1608
1609 error = xfs_filestream_mount(mp);
1610 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001611 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001612
Christoph Hellwig42490232008-08-13 16:49:32 +10001613 error = xfs_mountfs(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001614 if (error)
Christoph Hellwig120226c2008-05-20 15:11:11 +10001615 goto out_filestream_unmount;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001616
1617 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 sb->s_dirt = 1;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001620 sb->s_magic = XFS_SB_MAGIC;
1621 sb->s_blocksize = mp->m_sb.sb_blocksize;
1622 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1624 sb->s_time_gran = 1;
1625 set_posix_acl_flag(sb);
1626
David Chinner01651642008-08-13 15:45:15 +10001627 root = igrab(VFS_I(mp->m_rootip));
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001628 if (!root) {
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001629 error = ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 goto fail_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001631 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001632 if (is_bad_inode(root)) {
1633 error = EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 goto fail_vnrele;
1635 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001636 sb->s_root = d_alloc_root(root);
1637 if (!sb->s_root) {
1638 error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 goto fail_vnrele;
1640 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001641
David Chinnera167b172008-10-30 17:06:18 +11001642 error = xfs_syncd_init(mp);
1643 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 goto fail_vnrele;
Christoph Hellwig74394492007-08-30 17:21:22 +10001645
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001646 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001648 kfree(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 return 0;
1650
Christoph Hellwig120226c2008-05-20 15:11:11 +10001651 out_filestream_unmount:
1652 xfs_filestream_unmount(mp);
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001653 out_free_sb:
1654 xfs_freesb(mp);
Christoph Hellwiga7381592008-08-13 16:04:05 +10001655 out_free_fsname:
1656 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001657 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001658 xfs_close_devices(mp);
1659 out_put_qmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001660 xfs_qmops_put(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001661 out_put_dmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001662 xfs_dmops_put(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001663 out_free_mp:
1664 kfree(mp);
1665 out_free_args:
1666 kfree(args);
1667 return -error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001668
1669 fail_vnrele:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 if (sb->s_root) {
1671 dput(sb->s_root);
1672 sb->s_root = NULL;
1673 } else {
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001674 iput(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 }
1676
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001677 fail_unmount:
Christoph Hellwige48ad312008-05-20 11:30:52 +10001678 /*
1679 * Blow away any referenced inode in the filestreams cache.
1680 * This can and will cause log traffic as inodes go inactive
1681 * here.
1682 */
1683 xfs_filestream_unmount(mp);
1684
1685 XFS_bflush(mp->m_ddev_targp);
1686 error = xfs_unmount_flush(mp, 0);
1687 WARN_ON(error);
1688
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001689 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001690 goto out_free_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691}
1692
David Howells454e2392006-06-23 02:02:57 -07001693STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001694xfs_fs_get_sb(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 struct file_system_type *fs_type,
1696 int flags,
1697 const char *dev_name,
David Howells454e2392006-06-23 02:02:57 -07001698 void *data,
1699 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700{
David Howells454e2392006-06-23 02:02:57 -07001701 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1702 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
David Chinner7989cb82007-02-10 18:34:56 +11001705static struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001706 .alloc_inode = xfs_fs_alloc_inode,
1707 .destroy_inode = xfs_fs_destroy_inode,
1708 .write_inode = xfs_fs_write_inode,
1709 .clear_inode = xfs_fs_clear_inode,
1710 .put_super = xfs_fs_put_super,
1711 .write_super = xfs_fs_write_super,
1712 .sync_fs = xfs_fs_sync_super,
1713 .write_super_lockfs = xfs_fs_lockfs,
1714 .statfs = xfs_fs_statfs,
1715 .remount_fs = xfs_fs_remount,
1716 .show_options = xfs_fs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717};
1718
David Chinner7989cb82007-02-10 18:34:56 +11001719static struct quotactl_ops xfs_quotactl_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001720 .quota_sync = xfs_fs_quotasync,
1721 .get_xstate = xfs_fs_getxstate,
1722 .set_xstate = xfs_fs_setxstate,
1723 .get_xquota = xfs_fs_getxquota,
1724 .set_xquota = xfs_fs_setxquota,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725};
1726
Andrew Morton5085b602007-02-20 13:57:47 -08001727static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 .owner = THIS_MODULE,
1729 .name = "xfs",
Nathan Scotta50cd262006-03-14 14:06:18 +11001730 .get_sb = xfs_fs_get_sb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 .kill_sb = kill_block_super,
1732 .fs_flags = FS_REQUIRES_DEV,
1733};
1734
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001735STATIC int __init
1736xfs_alloc_trace_bufs(void)
1737{
1738#ifdef XFS_ALLOC_TRACE
1739 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1740 if (!xfs_alloc_trace_buf)
1741 goto out;
1742#endif
1743#ifdef XFS_BMAP_TRACE
1744 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1745 if (!xfs_bmap_trace_buf)
1746 goto out_free_alloc_trace;
1747#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001748#ifdef XFS_BTREE_TRACE
1749 xfs_allocbt_trace_buf = ktrace_alloc(XFS_ALLOCBT_TRACE_SIZE,
1750 KM_MAYFAIL);
1751 if (!xfs_allocbt_trace_buf)
1752 goto out_free_bmap_trace;
1753
1754 xfs_inobt_trace_buf = ktrace_alloc(XFS_INOBT_TRACE_SIZE, KM_MAYFAIL);
1755 if (!xfs_inobt_trace_buf)
1756 goto out_free_allocbt_trace;
1757
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001758 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1759 if (!xfs_bmbt_trace_buf)
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001760 goto out_free_inobt_trace;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001761#endif
1762#ifdef XFS_ATTR_TRACE
1763 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1764 if (!xfs_attr_trace_buf)
1765 goto out_free_bmbt_trace;
1766#endif
1767#ifdef XFS_DIR2_TRACE
1768 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1769 if (!xfs_dir2_trace_buf)
1770 goto out_free_attr_trace;
1771#endif
1772
1773 return 0;
1774
1775#ifdef XFS_DIR2_TRACE
1776 out_free_attr_trace:
1777#endif
1778#ifdef XFS_ATTR_TRACE
1779 ktrace_free(xfs_attr_trace_buf);
1780 out_free_bmbt_trace:
1781#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001782#ifdef XFS_BTREE_TRACE
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001783 ktrace_free(xfs_bmbt_trace_buf);
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001784 out_free_inobt_trace:
1785 ktrace_free(xfs_inobt_trace_buf);
1786 out_free_allocbt_trace:
1787 ktrace_free(xfs_allocbt_trace_buf);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001788 out_free_bmap_trace:
1789#endif
1790#ifdef XFS_BMAP_TRACE
1791 ktrace_free(xfs_bmap_trace_buf);
1792 out_free_alloc_trace:
1793#endif
1794#ifdef XFS_ALLOC_TRACE
1795 ktrace_free(xfs_alloc_trace_buf);
1796 out:
1797#endif
1798 return -ENOMEM;
1799}
1800
1801STATIC void
1802xfs_free_trace_bufs(void)
1803{
1804#ifdef XFS_DIR2_TRACE
1805 ktrace_free(xfs_dir2_trace_buf);
1806#endif
1807#ifdef XFS_ATTR_TRACE
1808 ktrace_free(xfs_attr_trace_buf);
1809#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001810#ifdef XFS_BTREE_TRACE
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001811 ktrace_free(xfs_bmbt_trace_buf);
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001812 ktrace_free(xfs_inobt_trace_buf);
1813 ktrace_free(xfs_allocbt_trace_buf);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001814#endif
1815#ifdef XFS_BMAP_TRACE
1816 ktrace_free(xfs_bmap_trace_buf);
1817#endif
1818#ifdef XFS_ALLOC_TRACE
1819 ktrace_free(xfs_alloc_trace_buf);
1820#endif
1821}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001824xfs_init_zones(void)
1825{
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001826
1827 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1828 if (!xfs_ioend_zone)
David Chinnerbf904242008-10-30 17:36:14 +11001829 goto out;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001830
1831 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1832 xfs_ioend_zone);
1833 if (!xfs_ioend_pool)
1834 goto out_destroy_ioend_zone;
1835
1836 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1837 "xfs_log_ticket");
1838 if (!xfs_log_ticket_zone)
1839 goto out_destroy_ioend_pool;
1840
1841 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1842 "xfs_bmap_free_item");
1843 if (!xfs_bmap_free_item_zone)
1844 goto out_destroy_log_ticket_zone;
David Chinnerbf904242008-10-30 17:36:14 +11001845
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001846 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1847 "xfs_btree_cur");
1848 if (!xfs_btree_cur_zone)
1849 goto out_destroy_bmap_free_item_zone;
1850
1851 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1852 "xfs_da_state");
1853 if (!xfs_da_state_zone)
1854 goto out_destroy_btree_cur_zone;
1855
1856 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
1857 if (!xfs_dabuf_zone)
1858 goto out_destroy_da_state_zone;
1859
1860 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1861 if (!xfs_ifork_zone)
1862 goto out_destroy_dabuf_zone;
1863
1864 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1865 if (!xfs_trans_zone)
1866 goto out_destroy_ifork_zone;
1867
1868 /*
1869 * The size of the zone allocated buf log item is the maximum
1870 * size possible under XFS. This wastes a little bit of memory,
1871 * but it is much faster.
1872 */
1873 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
1874 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
1875 NBWORD) * sizeof(int))), "xfs_buf_item");
1876 if (!xfs_buf_item_zone)
1877 goto out_destroy_trans_zone;
1878
1879 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1880 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1881 sizeof(xfs_extent_t))), "xfs_efd_item");
1882 if (!xfs_efd_zone)
1883 goto out_destroy_buf_item_zone;
1884
1885 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1886 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1887 sizeof(xfs_extent_t))), "xfs_efi_item");
1888 if (!xfs_efi_zone)
1889 goto out_destroy_efd_zone;
1890
1891 xfs_inode_zone =
1892 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
David Chinnerbf904242008-10-30 17:36:14 +11001893 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
1894 xfs_fs_inode_init_once);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001895 if (!xfs_inode_zone)
1896 goto out_destroy_efi_zone;
1897
1898 xfs_ili_zone =
1899 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1900 KM_ZONE_SPREAD, NULL);
1901 if (!xfs_ili_zone)
1902 goto out_destroy_inode_zone;
1903
1904#ifdef CONFIG_XFS_POSIX_ACL
1905 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
1906 if (!xfs_acl_zone)
1907 goto out_destroy_ili_zone;
1908#endif
1909
1910 return 0;
1911
1912#ifdef CONFIG_XFS_POSIX_ACL
1913 out_destroy_ili_zone:
1914#endif
1915 kmem_zone_destroy(xfs_ili_zone);
1916 out_destroy_inode_zone:
1917 kmem_zone_destroy(xfs_inode_zone);
1918 out_destroy_efi_zone:
1919 kmem_zone_destroy(xfs_efi_zone);
1920 out_destroy_efd_zone:
1921 kmem_zone_destroy(xfs_efd_zone);
1922 out_destroy_buf_item_zone:
1923 kmem_zone_destroy(xfs_buf_item_zone);
1924 out_destroy_trans_zone:
1925 kmem_zone_destroy(xfs_trans_zone);
1926 out_destroy_ifork_zone:
1927 kmem_zone_destroy(xfs_ifork_zone);
1928 out_destroy_dabuf_zone:
1929 kmem_zone_destroy(xfs_dabuf_zone);
1930 out_destroy_da_state_zone:
1931 kmem_zone_destroy(xfs_da_state_zone);
1932 out_destroy_btree_cur_zone:
1933 kmem_zone_destroy(xfs_btree_cur_zone);
1934 out_destroy_bmap_free_item_zone:
1935 kmem_zone_destroy(xfs_bmap_free_item_zone);
1936 out_destroy_log_ticket_zone:
1937 kmem_zone_destroy(xfs_log_ticket_zone);
1938 out_destroy_ioend_pool:
1939 mempool_destroy(xfs_ioend_pool);
1940 out_destroy_ioend_zone:
1941 kmem_zone_destroy(xfs_ioend_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001942 out:
1943 return -ENOMEM;
1944}
1945
1946STATIC void
1947xfs_destroy_zones(void)
1948{
1949#ifdef CONFIG_XFS_POSIX_ACL
1950 kmem_zone_destroy(xfs_acl_zone);
1951#endif
1952 kmem_zone_destroy(xfs_ili_zone);
1953 kmem_zone_destroy(xfs_inode_zone);
1954 kmem_zone_destroy(xfs_efi_zone);
1955 kmem_zone_destroy(xfs_efd_zone);
1956 kmem_zone_destroy(xfs_buf_item_zone);
1957 kmem_zone_destroy(xfs_trans_zone);
1958 kmem_zone_destroy(xfs_ifork_zone);
1959 kmem_zone_destroy(xfs_dabuf_zone);
1960 kmem_zone_destroy(xfs_da_state_zone);
1961 kmem_zone_destroy(xfs_btree_cur_zone);
1962 kmem_zone_destroy(xfs_bmap_free_item_zone);
1963 kmem_zone_destroy(xfs_log_ticket_zone);
1964 mempool_destroy(xfs_ioend_pool);
1965 kmem_zone_destroy(xfs_ioend_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001966
1967}
1968
1969STATIC int __init
1970init_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971{
1972 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 static char message[] __initdata = KERN_INFO \
1974 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
1975
1976 printk(message);
1977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 ktrace_init(64);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001979 vn_init();
1980 xfs_dir_startup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
Nathan Scott87582802006-03-14 13:18:19 +11001982 error = xfs_init_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001983 if (error)
1984 goto out;
1985
1986 error = xfs_alloc_trace_bufs();
1987 if (error)
1988 goto out_destroy_zones;
1989
1990 error = xfs_mru_cache_init();
1991 if (error)
1992 goto out_free_trace_buffers;
1993
1994 error = xfs_filestream_init();
1995 if (error)
1996 goto out_mru_cache_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
Nathan Scottce8e9222006-01-11 15:39:08 +11001998 error = xfs_buf_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001999 if (error)
2000 goto out_filestream_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002002 error = xfs_init_procfs();
2003 if (error)
2004 goto out_buf_terminate;
2005
2006 error = xfs_sysctl_register();
2007 if (error)
2008 goto out_cleanup_procfs;
2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 vfs_initquota();
2011
2012 error = register_filesystem(&xfs_fs_type);
2013 if (error)
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002014 goto out_sysctl_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 return 0;
2016
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002017 out_sysctl_unregister:
2018 xfs_sysctl_unregister();
2019 out_cleanup_procfs:
2020 xfs_cleanup_procfs();
2021 out_buf_terminate:
Nathan Scottce8e9222006-01-11 15:39:08 +11002022 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002023 out_filestream_uninit:
2024 xfs_filestream_uninit();
2025 out_mru_cache_uninit:
2026 xfs_mru_cache_uninit();
2027 out_free_trace_buffers:
2028 xfs_free_trace_bufs();
2029 out_destroy_zones:
Nathan Scott87582802006-03-14 13:18:19 +11002030 xfs_destroy_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002031 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 return error;
2033}
2034
2035STATIC void __exit
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002036exit_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037{
2038 vfs_exitquota();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 unregister_filesystem(&xfs_fs_type);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002040 xfs_sysctl_unregister();
2041 xfs_cleanup_procfs();
Nathan Scottce8e9222006-01-11 15:39:08 +11002042 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002043 xfs_filestream_uninit();
2044 xfs_mru_cache_uninit();
2045 xfs_free_trace_bufs();
Nathan Scott87582802006-03-14 13:18:19 +11002046 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 ktrace_uninit();
2048}
2049
2050module_init(init_xfs_fs);
2051module_exit(exit_xfs_fs);
2052
2053MODULE_AUTHOR("Silicon Graphics, Inc.");
2054MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2055MODULE_LICENSE("GPL");