blob: 727d0e47e80f1a67c8acafebc29b5a9380fdcb14 [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;
75static kmem_zone_t *xfs_vnode_zone;
76static kmem_zone_t *xfs_ioend_zone;
Christoph Hellwig0829c362005-09-02 16:58:49 +100077mempool_t *xfs_ioend_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79STATIC struct xfs_mount_args *
80xfs_args_allocate(
Nathan Scott764d1f82006-03-31 13:04:17 +100081 struct super_block *sb,
82 int silent)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 struct xfs_mount_args *args;
85
Christoph Hellwigbdd907b2008-05-20 15:10:44 +100086 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
87 if (!args)
88 return NULL;
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 args->logbufs = args->logbufsize = -1;
91 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
92
93 /* Copy the already-parsed mount(2) flags we're interested in */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 if (sb->s_flags & MS_DIRSYNC)
95 args->flags |= XFSMNT_DIRSYNC;
96 if (sb->s_flags & MS_SYNCHRONOUS)
97 args->flags |= XFSMNT_WSYNC;
Nathan Scott764d1f82006-03-31 13:04:17 +100098 if (silent)
99 args->flags |= XFSMNT_QUIET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 args->flags |= XFSMNT_32BITINODES;
101
102 return args;
103}
104
David Chinnera67d7c52007-11-23 16:29:32 +1100105#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
106#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
107#define MNTOPT_LOGDEV "logdev" /* log device */
108#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
109#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
110#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
111#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
112#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
113#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
114#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
115#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
116#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
117#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
118#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
119#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
120#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
121#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
122#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
123#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
124#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
125 * unwritten extent conversion */
126#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
127#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
128#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
129#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
130#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
131#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
132#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
133 * in stat(). */
134#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
135#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
136#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
137#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
138#define MNTOPT_NOQUOTA "noquota" /* no quotas */
139#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
140#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
141#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
142#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
143#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
144#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
145#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
146#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
147#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
148#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
149#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
150#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
151#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
152
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000153/*
154 * Table driven mount option parser.
155 *
156 * Currently only used for remount, but it will be used for mount
157 * in the future, too.
158 */
159enum {
160 Opt_barrier, Opt_nobarrier, Opt_err
161};
162
Steven Whitehousea447c092008-10-13 10:46:57 +0100163static const match_table_t tokens = {
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000164 {Opt_barrier, "barrier"},
165 {Opt_nobarrier, "nobarrier"},
166 {Opt_err, NULL}
167};
168
169
David Chinnera67d7c52007-11-23 16:29:32 +1100170STATIC unsigned long
171suffix_strtoul(char *s, char **endp, unsigned int base)
172{
173 int last, shift_left_factor = 0;
174 char *value = s;
175
176 last = strlen(value) - 1;
177 if (value[last] == 'K' || value[last] == 'k') {
178 shift_left_factor = 10;
179 value[last] = '\0';
180 }
181 if (value[last] == 'M' || value[last] == 'm') {
182 shift_left_factor = 20;
183 value[last] = '\0';
184 }
185 if (value[last] == 'G' || value[last] == 'g') {
186 shift_left_factor = 30;
187 value[last] = '\0';
188 }
189
190 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
191}
192
193STATIC int
194xfs_parseargs(
195 struct xfs_mount *mp,
196 char *options,
197 struct xfs_mount_args *args,
198 int update)
199{
200 char *this_char, *value, *eov;
201 int dsunit, dswidth, vol_dsunit, vol_dswidth;
202 int iosize;
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100203 int dmapi_implies_ikeep = 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100204
205 args->flags |= XFSMNT_BARRIER;
206 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
207
208 if (!options)
209 goto done;
210
211 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
212
213 while ((this_char = strsep(&options, ",")) != NULL) {
214 if (!*this_char)
215 continue;
216 if ((value = strchr(this_char, '=')) != NULL)
217 *value++ = 0;
218
219 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
220 if (!value || !*value) {
221 cmn_err(CE_WARN,
222 "XFS: %s option requires an argument",
223 this_char);
224 return EINVAL;
225 }
226 args->logbufs = simple_strtoul(value, &eov, 10);
227 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
228 if (!value || !*value) {
229 cmn_err(CE_WARN,
230 "XFS: %s option requires an argument",
231 this_char);
232 return EINVAL;
233 }
234 args->logbufsize = suffix_strtoul(value, &eov, 10);
235 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
236 if (!value || !*value) {
237 cmn_err(CE_WARN,
238 "XFS: %s option requires an argument",
239 this_char);
240 return EINVAL;
241 }
242 strncpy(args->logname, value, MAXNAMELEN);
243 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
244 if (!value || !*value) {
245 cmn_err(CE_WARN,
246 "XFS: %s option requires an argument",
247 this_char);
248 return EINVAL;
249 }
250 strncpy(args->mtpt, value, MAXNAMELEN);
251 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
252 if (!value || !*value) {
253 cmn_err(CE_WARN,
254 "XFS: %s option requires an argument",
255 this_char);
256 return EINVAL;
257 }
258 strncpy(args->rtname, value, MAXNAMELEN);
259 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
260 if (!value || !*value) {
261 cmn_err(CE_WARN,
262 "XFS: %s option requires an argument",
263 this_char);
264 return EINVAL;
265 }
266 iosize = simple_strtoul(value, &eov, 10);
267 args->flags |= XFSMNT_IOSIZE;
268 args->iosizelog = (uint8_t) iosize;
269 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
270 if (!value || !*value) {
271 cmn_err(CE_WARN,
272 "XFS: %s option requires an argument",
273 this_char);
274 return EINVAL;
275 }
276 iosize = suffix_strtoul(value, &eov, 10);
277 args->flags |= XFSMNT_IOSIZE;
278 args->iosizelog = ffs(iosize) - 1;
279 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
280 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
281 mp->m_flags |= XFS_MOUNT_GRPID;
282 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
283 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
284 mp->m_flags &= ~XFS_MOUNT_GRPID;
285 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
286 args->flags |= XFSMNT_WSYNC;
287 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
288 args->flags |= XFSMNT_OSYNCISOSYNC;
289 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
290 args->flags |= XFSMNT_NORECOVERY;
291 } else if (!strcmp(this_char, MNTOPT_INO64)) {
292 args->flags |= XFSMNT_INO64;
293#if !XFS_BIG_INUMS
294 cmn_err(CE_WARN,
295 "XFS: %s option not allowed on this system",
296 this_char);
297 return EINVAL;
298#endif
299 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
300 args->flags |= XFSMNT_NOALIGN;
301 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
302 args->flags |= XFSMNT_SWALLOC;
303 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
304 if (!value || !*value) {
305 cmn_err(CE_WARN,
306 "XFS: %s option requires an argument",
307 this_char);
308 return EINVAL;
309 }
310 dsunit = simple_strtoul(value, &eov, 10);
311 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
312 if (!value || !*value) {
313 cmn_err(CE_WARN,
314 "XFS: %s option requires an argument",
315 this_char);
316 return EINVAL;
317 }
318 dswidth = simple_strtoul(value, &eov, 10);
319 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
320 args->flags &= ~XFSMNT_32BITINODES;
321#if !XFS_BIG_INUMS
322 cmn_err(CE_WARN,
323 "XFS: %s option not allowed on this system",
324 this_char);
325 return EINVAL;
326#endif
327 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
328 args->flags |= XFSMNT_NOUUID;
329 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
330 args->flags |= XFSMNT_BARRIER;
331 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
332 args->flags &= ~XFSMNT_BARRIER;
333 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100334 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100335 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100336 dmapi_implies_ikeep = 0;
337 args->flags &= ~XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100338 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
339 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
340 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
341 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
342 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
343 args->flags |= XFSMNT_ATTR2;
344 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
345 args->flags &= ~XFSMNT_ATTR2;
Tim Shimmin7c12f292008-04-30 18:15:28 +1000346 args->flags |= XFSMNT_NOATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100347 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
348 args->flags2 |= XFSMNT2_FILESTREAMS;
349 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
350 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
351 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
352 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
353 !strcmp(this_char, MNTOPT_UQUOTA) ||
354 !strcmp(this_char, MNTOPT_USRQUOTA)) {
355 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
356 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
357 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
358 args->flags |= XFSMNT_UQUOTA;
359 args->flags &= ~XFSMNT_UQUOTAENF;
360 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
361 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
362 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
363 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
364 args->flags |= XFSMNT_PQUOTA;
365 args->flags &= ~XFSMNT_PQUOTAENF;
366 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
367 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
368 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
369 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
370 args->flags |= XFSMNT_GQUOTA;
371 args->flags &= ~XFSMNT_GQUOTAENF;
372 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
373 args->flags |= XFSMNT_DMAPI;
374 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
375 args->flags |= XFSMNT_DMAPI;
376 } else if (!strcmp(this_char, MNTOPT_DMI)) {
377 args->flags |= XFSMNT_DMAPI;
378 } else if (!strcmp(this_char, "ihashsize")) {
379 cmn_err(CE_WARN,
380 "XFS: ihashsize no longer used, option is deprecated.");
381 } else if (!strcmp(this_char, "osyncisdsync")) {
382 /* no-op, this is now the default */
383 cmn_err(CE_WARN,
384 "XFS: osyncisdsync is now the default, option is deprecated.");
385 } else if (!strcmp(this_char, "irixsgid")) {
386 cmn_err(CE_WARN,
387 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
388 } else {
389 cmn_err(CE_WARN,
390 "XFS: unknown mount option [%s].", this_char);
391 return EINVAL;
392 }
393 }
394
395 if (args->flags & XFSMNT_NORECOVERY) {
396 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
397 cmn_err(CE_WARN,
398 "XFS: no-recovery mounts must be read-only.");
399 return EINVAL;
400 }
401 }
402
403 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
404 cmn_err(CE_WARN,
405 "XFS: sunit and swidth options incompatible with the noalign option");
406 return EINVAL;
407 }
408
409 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
410 cmn_err(CE_WARN,
411 "XFS: cannot mount with both project and group quota");
412 return EINVAL;
413 }
414
415 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
416 printk("XFS: %s option needs the mount point option as well\n",
417 MNTOPT_DMAPI);
418 return EINVAL;
419 }
420
421 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
422 cmn_err(CE_WARN,
423 "XFS: sunit and swidth must be specified together");
424 return EINVAL;
425 }
426
427 if (dsunit && (dswidth % dsunit != 0)) {
428 cmn_err(CE_WARN,
429 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
430 dswidth, dsunit);
431 return EINVAL;
432 }
433
434 /*
435 * Applications using DMI filesystems often expect the
436 * inode generation number to be monotonically increasing.
437 * If we delete inode chunks we break this assumption, so
438 * keep unused inode chunks on disk for DMI filesystems
439 * until we come up with a better solution.
440 * Note that if "ikeep" or "noikeep" mount options are
441 * supplied, then they are honored.
442 */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100443 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
444 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100445
446 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
447 if (dsunit) {
448 args->sunit = dsunit;
449 args->flags |= XFSMNT_RETERR;
450 } else {
451 args->sunit = vol_dsunit;
452 }
453 dswidth ? (args->swidth = dswidth) :
454 (args->swidth = vol_dswidth);
455 } else {
456 args->sunit = args->swidth = 0;
457 }
458
459done:
460 if (args->flags & XFSMNT_32BITINODES)
461 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
462 if (args->flags2)
463 args->flags |= XFSMNT_FLAGS2;
464 return 0;
465}
466
467struct proc_xfs_info {
468 int flag;
469 char *str;
470};
471
472STATIC int
473xfs_showargs(
474 struct xfs_mount *mp,
475 struct seq_file *m)
476{
477 static struct proc_xfs_info xfs_info_set[] = {
478 /* the few simple ones we can get from the mount struct */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100479 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
David Chinnera67d7c52007-11-23 16:29:32 +1100480 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
481 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
482 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
483 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
484 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
485 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
486 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
487 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
488 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
489 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
490 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
491 { 0, NULL }
492 };
493 static struct proc_xfs_info xfs_info_unset[] = {
494 /* the few simple ones we can get from the mount struct */
David Chinnera67d7c52007-11-23 16:29:32 +1100495 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
496 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
497 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
498 { 0, NULL }
499 };
500 struct proc_xfs_info *xfs_infop;
501
502 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
503 if (mp->m_flags & xfs_infop->flag)
504 seq_puts(m, xfs_infop->str);
505 }
506 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
507 if (!(mp->m_flags & xfs_infop->flag))
508 seq_puts(m, xfs_infop->str);
509 }
510
511 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
512 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
513 (int)(1 << mp->m_writeio_log) >> 10);
514
515 if (mp->m_logbufs > 0)
516 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
517 if (mp->m_logbsize > 0)
518 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
519
520 if (mp->m_logname)
521 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
522 if (mp->m_rtname)
523 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
524
525 if (mp->m_dalign > 0)
526 seq_printf(m, "," MNTOPT_SUNIT "=%d",
527 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
528 if (mp->m_swidth > 0)
529 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
530 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
531
532 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
533 seq_puts(m, "," MNTOPT_USRQUOTA);
534 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
535 seq_puts(m, "," MNTOPT_UQUOTANOENF);
536
537 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
538 seq_puts(m, "," MNTOPT_PRJQUOTA);
539 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
540 seq_puts(m, "," MNTOPT_PQUOTANOENF);
541
542 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
543 seq_puts(m, "," MNTOPT_GRPQUOTA);
544 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
545 seq_puts(m, "," MNTOPT_GQUOTANOENF);
546
547 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
548 seq_puts(m, "," MNTOPT_NOQUOTA);
549
550 return 0;
551}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552__uint64_t
553xfs_max_file_offset(
554 unsigned int blockshift)
555{
556 unsigned int pagefactor = 1;
557 unsigned int bitshift = BITS_PER_LONG - 1;
558
559 /* Figure out maximum filesize, on Linux this can depend on
560 * the filesystem blocksize (on 32 bit platforms).
561 * __block_prepare_write does this in an [unsigned] long...
562 * page->index << (PAGE_CACHE_SHIFT - bbits)
563 * So, for page sized blocks (4K on 32 bit platforms),
564 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
565 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
566 * but for smaller blocksizes it is less (bbits = log2 bsize).
567 * Note1: get_block_t takes a long (implicit cast from above)
568 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
569 * can optionally convert the [unsigned] long from above into
570 * an [unsigned] long long.
571 */
572
573#if BITS_PER_LONG == 32
574# if defined(CONFIG_LBD)
575 ASSERT(sizeof(sector_t) == 8);
576 pagefactor = PAGE_CACHE_SIZE;
577 bitshift = BITS_PER_LONG;
578# else
579 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
580# endif
581#endif
582
583 return (((__uint64_t)pagefactor) << bitshift) - 1;
584}
585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586int
587xfs_blkdev_get(
588 xfs_mount_t *mp,
589 const char *name,
590 struct block_device **bdevp)
591{
592 int error = 0;
593
Al Viro30c40d22008-02-22 19:50:45 -0500594 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 if (IS_ERR(*bdevp)) {
596 error = PTR_ERR(*bdevp);
597 printk("XFS: Invalid device [%s], error=%d\n", name, error);
598 }
599
600 return -error;
601}
602
603void
604xfs_blkdev_put(
605 struct block_device *bdev)
606{
607 if (bdev)
Al Viro30c40d22008-02-22 19:50:45 -0500608 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
610
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100611/*
612 * Try to write out the superblock using barriers.
613 */
614STATIC int
615xfs_barrier_test(
616 xfs_mount_t *mp)
617{
618 xfs_buf_t *sbp = xfs_getsb(mp, 0);
619 int error;
620
621 XFS_BUF_UNDONE(sbp);
622 XFS_BUF_UNREAD(sbp);
623 XFS_BUF_UNDELAYWRITE(sbp);
624 XFS_BUF_WRITE(sbp);
625 XFS_BUF_UNASYNC(sbp);
626 XFS_BUF_ORDERED(sbp);
627
628 xfsbdstrat(mp, sbp);
629 error = xfs_iowait(sbp);
630
631 /*
632 * Clear all the flags we set and possible error state in the
633 * buffer. We only did the write to try out whether barriers
634 * worked and shouldn't leave any traces in the superblock
635 * buffer.
636 */
637 XFS_BUF_DONE(sbp);
638 XFS_BUF_ERROR(sbp, 0);
639 XFS_BUF_UNORDERED(sbp);
640
641 xfs_buf_relse(sbp);
642 return error;
643}
644
645void
646xfs_mountfs_check_barriers(xfs_mount_t *mp)
647{
648 int error;
649
650 if (mp->m_logdev_targp != mp->m_ddev_targp) {
651 xfs_fs_cmn_err(CE_NOTE, mp,
652 "Disabling barriers, not supported with external log device");
653 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100654 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100655 }
656
Nathan Scottb2ea4012006-07-28 17:05:13 +1000657 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
658 xfs_fs_cmn_err(CE_NOTE, mp,
659 "Disabling barriers, underlying device is readonly");
660 mp->m_flags &= ~XFS_MOUNT_BARRIER;
661 return;
662 }
663
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100664 error = xfs_barrier_test(mp);
665 if (error) {
666 xfs_fs_cmn_err(CE_NOTE, mp,
667 "Disabling barriers, trial barrier write failed");
668 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100669 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100670 }
671}
672
673void
674xfs_blkdev_issue_flush(
675 xfs_buftarg_t *buftarg)
676{
Nathan Scottce8e9222006-01-11 15:39:08 +1100677 blkdev_issue_flush(buftarg->bt_bdev, NULL);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100678}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000680STATIC void
681xfs_close_devices(
682 struct xfs_mount *mp)
683{
684 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000685 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000686 xfs_free_buftarg(mp->m_logdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000687 xfs_blkdev_put(logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000688 }
689 if (mp->m_rtdev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000690 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000691 xfs_free_buftarg(mp->m_rtdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000692 xfs_blkdev_put(rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000693 }
694 xfs_free_buftarg(mp->m_ddev_targp);
695}
696
697/*
698 * The file system configurations are:
699 * (1) device (partition) with data and internal log
700 * (2) logical volume with data and log subvolumes.
701 * (3) logical volume with data, log, and realtime subvolumes.
702 *
703 * We only have to handle opening the log and realtime volumes here if
704 * they are present. The data subvolume has already been opened by
705 * get_sb_bdev() and is stored in sb->s_bdev.
706 */
707STATIC int
708xfs_open_devices(
709 struct xfs_mount *mp,
710 struct xfs_mount_args *args)
711{
712 struct block_device *ddev = mp->m_super->s_bdev;
713 struct block_device *logdev = NULL, *rtdev = NULL;
714 int error;
715
716 /*
717 * Open real time and log devices - order is important.
718 */
719 if (args->logname[0]) {
720 error = xfs_blkdev_get(mp, args->logname, &logdev);
721 if (error)
722 goto out;
723 }
724
725 if (args->rtname[0]) {
726 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
727 if (error)
728 goto out_close_logdev;
729
730 if (rtdev == ddev || rtdev == logdev) {
731 cmn_err(CE_WARN,
732 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
733 error = EINVAL;
734 goto out_close_rtdev;
735 }
736 }
737
738 /*
739 * Setup xfs_mount buffer target pointers
740 */
741 error = ENOMEM;
742 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
743 if (!mp->m_ddev_targp)
744 goto out_close_rtdev;
745
746 if (rtdev) {
747 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
748 if (!mp->m_rtdev_targp)
749 goto out_free_ddev_targ;
750 }
751
752 if (logdev && logdev != ddev) {
753 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
754 if (!mp->m_logdev_targp)
755 goto out_free_rtdev_targ;
756 } else {
757 mp->m_logdev_targp = mp->m_ddev_targp;
758 }
759
760 return 0;
761
762 out_free_rtdev_targ:
763 if (mp->m_rtdev_targp)
764 xfs_free_buftarg(mp->m_rtdev_targp);
765 out_free_ddev_targ:
766 xfs_free_buftarg(mp->m_ddev_targp);
767 out_close_rtdev:
768 if (rtdev)
769 xfs_blkdev_put(rtdev);
770 out_close_logdev:
771 if (logdev && logdev != ddev)
772 xfs_blkdev_put(logdev);
773 out:
774 return error;
775}
776
Christoph Hellwige34b5622008-05-20 15:10:36 +1000777/*
778 * Setup xfs_mount buffer target pointers based on superblock
779 */
780STATIC int
781xfs_setup_devices(
782 struct xfs_mount *mp)
783{
784 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000785
Christoph Hellwige34b5622008-05-20 15:10:36 +1000786 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
787 mp->m_sb.sb_sectsize);
788 if (error)
789 return error;
790
791 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
792 unsigned int log_sector_size = BBSIZE;
793
794 if (xfs_sb_version_hassector(&mp->m_sb))
795 log_sector_size = mp->m_sb.sb_logsectsize;
796 error = xfs_setsize_buftarg(mp->m_logdev_targp,
797 mp->m_sb.sb_blocksize,
798 log_sector_size);
799 if (error)
800 return error;
801 }
802 if (mp->m_rtdev_targp) {
803 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
804 mp->m_sb.sb_blocksize,
805 mp->m_sb.sb_sectsize);
806 if (error)
807 return error;
808 }
809
810 return 0;
811}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000812
David Chinner249a8c12008-02-05 12:13:32 +1100813/*
814 * XFS AIL push thread support
815 */
816void
817xfsaild_wakeup(
818 xfs_mount_t *mp,
819 xfs_lsn_t threshold_lsn)
820{
821 mp->m_ail.xa_target = threshold_lsn;
822 wake_up_process(mp->m_ail.xa_task);
823}
824
825int
826xfsaild(
827 void *data)
828{
829 xfs_mount_t *mp = (xfs_mount_t *)data;
830 xfs_lsn_t last_pushed_lsn = 0;
831 long tout = 0;
832
833 while (!kthread_should_stop()) {
834 if (tout)
835 schedule_timeout_interruptible(msecs_to_jiffies(tout));
836 tout = 1000;
837
838 /* swsusp */
839 try_to_freeze();
840
841 ASSERT(mp->m_log);
842 if (XFS_FORCED_SHUTDOWN(mp))
843 continue;
844
845 tout = xfsaild_push(mp, &last_pushed_lsn);
846 }
847
848 return 0;
849} /* xfsaild */
850
851int
852xfsaild_start(
853 xfs_mount_t *mp)
854{
855 mp->m_ail.xa_target = 0;
856 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
857 if (IS_ERR(mp->m_ail.xa_task))
858 return -PTR_ERR(mp->m_ail.xa_task);
859 return 0;
860}
861
862void
863xfsaild_stop(
864 xfs_mount_t *mp)
865{
866 kthread_stop(mp->m_ail.xa_task);
867}
868
869
870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100872xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 struct super_block *sb)
874{
Christoph Hellwigdf80c932008-08-13 16:22:09 +1000875 return kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876}
877
878STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100879xfs_fs_destroy_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 struct inode *inode)
881{
Christoph Hellwiga19d0332008-08-13 16:11:26 +1000882 kmem_zone_free(xfs_vnode_zone, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883}
884
885STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100886xfs_fs_inode_init_once(
Christoph Lameter4ba9b9d2007-10-16 23:25:51 -0700887 void *vnode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
Christoph Hellwig863890c2008-08-13 16:12:05 +1000889 inode_init_once((struct inode *)vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
891
David Chinner07c8f672008-10-30 16:11:59 +1100892
893/*
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 */
901void
902xfs_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));
908 atomic_set(&ip->i_iocount, 0);
909 atomic_set(&ip->i_pincount, 0);
910 spin_lock_init(&ip->i_flags_lock);
911 INIT_LIST_HEAD(&ip->i_reclaim);
912 init_waitqueue_head(&ip->i_ipin_wait);
913 /*
914 * Because we want to use a counting completion, complete
915 * the flush completion once to allow a single access to
916 * the flush completion without blocking.
917 */
918 init_completion(&ip->i_flush);
919 complete(&ip->i_flush);
920
921 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
922 "xfsino", ip->i_ino);
923 mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
924}
925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926/*
927 * Attempt to flush the inode, this will actually fail
928 * if the inode is pinned, but we dirty the inode again
929 * at the point when it is unpinned after a log write,
Nathan Scott87582802006-03-14 13:18:19 +1100930 * since this is when the inode itself becomes flushable.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 */
932STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +1100933xfs_fs_write_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 struct inode *inode,
935 int sync)
936{
David Chinnera3f74ff2008-03-06 13:43:42 +1100937 int error = 0;
938 int flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100940 xfs_itrace_entry(XFS_I(inode));
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000941 if (sync) {
942 filemap_fdatawait(inode->i_mapping);
943 flags |= FLUSH_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 }
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000945 error = xfs_inode_flush(XFS_I(inode), flags);
Lachlan McIlroye893bff2007-10-12 11:13:35 +1000946 /*
947 * if we failed to write out the inode then mark
948 * it dirty again so we'll try again later.
949 */
950 if (error)
951 mark_inode_dirty_sync(inode);
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 return -error;
954}
955
956STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100957xfs_fs_clear_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 struct inode *inode)
959{
Christoph Hellwig1543d792007-08-29 11:46:47 +1000960 xfs_inode_t *ip = XFS_I(inode);
Christoph Hellwig56d433e2005-09-05 08:23:54 +1000961
Christoph Hellwig02ba71d2005-09-05 08:28:02 +1000962 /*
Christoph Hellwig1543d792007-08-29 11:46:47 +1000963 * ip can be null when xfs_iget_core calls xfs_idestroy if we
Christoph Hellwig02ba71d2005-09-05 08:28:02 +1000964 * find an inode with di_mode == 0 but without IGET_CREATE set.
965 */
Christoph Hellwig1543d792007-08-29 11:46:47 +1000966 if (ip) {
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100967 xfs_itrace_entry(ip);
Christoph Hellwig1543d792007-08-29 11:46:47 +1000968 XFS_STATS_INC(vn_rele);
969 XFS_STATS_INC(vn_remove);
970 XFS_STATS_INC(vn_reclaim);
971 XFS_STATS_DEC(vn_active);
Christoph Hellwig56d433e2005-09-05 08:23:54 +1000972
Christoph Hellwig1543d792007-08-29 11:46:47 +1000973 xfs_inactive(ip);
974 xfs_iflags_clear(ip, XFS_IMODIFIED);
975 if (xfs_reclaim(ip))
Harvey Harrison34a622b2008-04-10 12:19:21 +1000976 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +1000977 }
Christoph Hellwig56d433e2005-09-05 08:23:54 +1000978
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000979 ASSERT(XFS_I(inode) == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980}
981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982/*
983 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
984 * Doing this has two advantages:
985 * - It saves on stack space, which is tight in certain situations
986 * - It can be used (with care) as a mechanism to avoid deadlocks.
987 * Flushing while allocating in a full filesystem requires both.
988 */
989STATIC void
990xfs_syncd_queue_work(
Christoph Hellwig74394492007-08-30 17:21:22 +1000991 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 void *data,
Christoph Hellwig74394492007-08-30 17:21:22 +1000993 void (*syncer)(struct xfs_mount *, void *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
Nathan Scottb83bd132006-06-09 16:48:30 +1000995 struct bhv_vfs_sync_work *work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Nathan Scottb83bd132006-06-09 16:48:30 +1000997 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 INIT_LIST_HEAD(&work->w_list);
999 work->w_syncer = syncer;
1000 work->w_data = data;
Christoph Hellwig74394492007-08-30 17:21:22 +10001001 work->w_mount = mp;
1002 spin_lock(&mp->m_sync_lock);
1003 list_add_tail(&work->w_list, &mp->m_sync_list);
1004 spin_unlock(&mp->m_sync_lock);
1005 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006}
1007
1008/*
1009 * Flush delayed allocate data, attempting to free up reserved space
1010 * from existing allocations. At this point a new allocation attempt
1011 * has failed with ENOSPC and we are in the process of scratching our
1012 * heads, looking about for more room...
1013 */
1014STATIC void
1015xfs_flush_inode_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001016 struct xfs_mount *mp,
1017 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
Christoph Hellwig74394492007-08-30 17:21:22 +10001019 struct inode *inode = arg;
1020 filemap_flush(inode->i_mapping);
1021 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022}
1023
1024void
1025xfs_flush_inode(
1026 xfs_inode_t *ip)
1027{
David Chinner01651642008-08-13 15:45:15 +10001028 struct inode *inode = VFS_I(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 igrab(inode);
Christoph Hellwig74394492007-08-30 17:21:22 +10001031 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001032 delay(msecs_to_jiffies(500));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033}
1034
1035/*
1036 * This is the "bigger hammer" version of xfs_flush_inode_work...
1037 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1038 */
1039STATIC void
1040xfs_flush_device_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001041 struct xfs_mount *mp,
1042 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043{
Christoph Hellwig74394492007-08-30 17:21:22 +10001044 struct inode *inode = arg;
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001045 sync_blockdev(mp->m_super->s_bdev);
Christoph Hellwig74394492007-08-30 17:21:22 +10001046 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
1049void
1050xfs_flush_device(
1051 xfs_inode_t *ip)
1052{
David Chinnere4f75292008-08-13 16:00:45 +10001053 struct inode *inode = VFS_I(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055 igrab(inode);
Christoph Hellwig74394492007-08-30 17:21:22 +10001056 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001057 delay(msecs_to_jiffies(500));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1059}
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061STATIC void
Christoph Hellwig74394492007-08-30 17:21:22 +10001062xfs_sync_worker(
1063 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 void *unused)
1065{
1066 int error;
1067
Christoph Hellwig74394492007-08-30 17:21:22 +10001068 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
David Chinner7e206942008-04-17 16:49:55 +10001069 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
Christoph Hellwig74394492007-08-30 17:21:22 +10001070 mp->m_sync_seq++;
1071 wake_up(&mp->m_wait_single_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072}
1073
1074STATIC int
1075xfssyncd(
1076 void *arg)
1077{
Christoph Hellwig74394492007-08-30 17:21:22 +10001078 struct xfs_mount *mp = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 long timeleft;
Nathan Scottb83bd132006-06-09 16:48:30 +10001080 bhv_vfs_sync_work_t *work, *n;
Christoph Hellwig4df08c52005-09-05 08:34:18 +10001081 LIST_HEAD (tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Rafael J. Wysocki83144182007-07-17 04:03:35 -07001083 set_freezable();
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001084 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 for (;;) {
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001086 timeleft = schedule_timeout_interruptible(timeleft);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 /* swsusp */
Christoph Lameter3e1d1d22005-06-24 23:13:50 -07001088 try_to_freeze();
Christoph Hellwig74394492007-08-30 17:21:22 +10001089 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 break;
1091
Christoph Hellwig74394492007-08-30 17:21:22 +10001092 spin_lock(&mp->m_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 /*
1094 * We can get woken by laptop mode, to do a sync -
1095 * that's the (only!) case where the list would be
1096 * empty with time remaining.
1097 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001098 if (!timeleft || list_empty(&mp->m_sync_list)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 if (!timeleft)
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001100 timeleft = xfs_syncd_centisecs *
1101 msecs_to_jiffies(10);
Christoph Hellwig74394492007-08-30 17:21:22 +10001102 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1103 list_add_tail(&mp->m_sync_work.w_list,
1104 &mp->m_sync_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001106 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 list_move(&work->w_list, &tmp);
Christoph Hellwig74394492007-08-30 17:21:22 +10001108 spin_unlock(&mp->m_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
1110 list_for_each_entry_safe(work, n, &tmp, w_list) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001111 (*work->w_syncer)(mp, work->w_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 list_del(&work->w_list);
Christoph Hellwig74394492007-08-30 17:21:22 +10001113 if (work == &mp->m_sync_work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 continue;
Denys Vlasenkof0e2d932008-05-19 16:31:57 +10001115 kmem_free(work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 }
1117 }
1118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 return 0;
1120}
1121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122STATIC void
Christoph Hellwiga7381592008-08-13 16:04:05 +10001123xfs_free_fsname(
1124 struct xfs_mount *mp)
1125{
1126 kfree(mp->m_fsname);
1127 kfree(mp->m_rtname);
1128 kfree(mp->m_logname);
1129}
1130
1131STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001132xfs_fs_put_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 struct super_block *sb)
1134{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001135 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001136 struct xfs_inode *rip = mp->m_rootip;
1137 int unmount_event_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 int error;
1139
Christoph Hellwig74394492007-08-30 17:21:22 +10001140 kthread_stop(mp->m_sync_task);
1141
Christoph Hellwig745f6912007-08-30 17:20:39 +10001142 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001143
1144#ifdef HAVE_DMAPI
1145 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1146 unmount_event_flags =
1147 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1148 0 : DM_FLAGS_UNWANTED;
1149 /*
1150 * Ignore error from dmapi here, first unmount is not allowed
1151 * to fail anyway, and second we wouldn't want to fail a
1152 * unmount because of dmapi.
1153 */
1154 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1155 NULL, NULL, 0, 0, unmount_event_flags);
1156 }
1157#endif
1158
1159 /*
1160 * Blow away any referenced inode in the filestreams cache.
1161 * This can and will cause log traffic as inodes go inactive
1162 * here.
1163 */
1164 xfs_filestream_unmount(mp);
1165
1166 XFS_bflush(mp->m_ddev_targp);
1167 error = xfs_unmount_flush(mp, 0);
1168 WARN_ON(error);
1169
Christoph Hellwige48ad312008-05-20 11:30:52 +10001170 /*
1171 * If we're forcing a shutdown, typically because of a media error,
1172 * we want to make sure we invalidate dirty pages that belong to
1173 * referenced vnodes as well.
1174 */
1175 if (XFS_FORCED_SHUTDOWN(mp)) {
1176 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1177 ASSERT(error != EFSCORRUPTED);
1178 }
1179
1180 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1181 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1182 unmount_event_flags);
1183 }
1184
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001185 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001186 xfs_freesb(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001187 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001188 xfs_close_devices(mp);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001189 xfs_qmops_put(mp);
1190 xfs_dmops_put(mp);
Christoph Hellwiga7381592008-08-13 16:04:05 +10001191 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001192 kfree(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
1194
1195STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001196xfs_fs_write_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 struct super_block *sb)
1198{
Nathan Scottb83bd132006-06-09 16:48:30 +10001199 if (!(sb->s_flags & MS_RDONLY))
Christoph Hellwig745f6912007-08-30 17:20:39 +10001200 xfs_sync(XFS_M(sb), SYNC_FSDATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 sb->s_dirt = 0;
1202}
1203
1204STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001205xfs_fs_sync_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 struct super_block *sb,
1207 int wait)
1208{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001209 struct xfs_mount *mp = XFS_M(sb);
Nathan Scottb83bd132006-06-09 16:48:30 +10001210 int error;
1211 int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001213 /*
1214 * Treat a sync operation like a freeze. This is to work
1215 * around a race in sync_inodes() which works in two phases
1216 * - an asynchronous flush, which can write out an inode
1217 * without waiting for file size updates to complete, and a
1218 * synchronous flush, which wont do anything because the
1219 * async flush removed the inode's dirty flag. Also
1220 * sync_inodes() will not see any files that just have
1221 * outstanding transactions to be flushed because we don't
1222 * dirty the Linux inode until after the transaction I/O
1223 * completes.
1224 */
1225 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
David Chinner28239452007-02-10 18:36:40 +11001226 /*
1227 * First stage of freeze - no more writers will make progress
1228 * now we are here, so we flush delwri and delalloc buffers
1229 * here, then wait for all I/O to complete. Data is frozen at
1230 * that point. Metadata is not frozen, transactions can still
1231 * occur here so don't bother flushing the buftarg (i.e
1232 * SYNC_QUIESCE) because it'll just get dirty again.
1233 */
David Chinner516b2e72007-06-18 16:50:48 +10001234 flags = SYNC_DATA_QUIESCE;
David Chinner28239452007-02-10 18:36:40 +11001235 } else
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001236 flags = SYNC_FSDATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Christoph Hellwig745f6912007-08-30 17:20:39 +10001238 error = xfs_sync(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 sb->s_dirt = 0;
1240
1241 if (unlikely(laptop_mode)) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001242 int prev_sync_seq = mp->m_sync_seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 /*
1245 * The disk must be active because we're syncing.
1246 * We schedule xfssyncd now (now that the disk is
1247 * active) instead of later (when it might not be).
1248 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001249 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 /*
1251 * We have to wait for the sync iteration to complete.
1252 * If we don't, the disk activity caused by the sync
1253 * will come after the sync is completed, and that
1254 * triggers another sync from laptop mode.
1255 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001256 wait_event(mp->m_wait_single_sync_task,
1257 mp->m_sync_seq != prev_sync_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 }
1259
1260 return -error;
1261}
1262
1263STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001264xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001265 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 struct kstatfs *statp)
1267{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001268 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1269 xfs_sb_t *sbp = &mp->m_sb;
1270 __uint64_t fakeinos, id;
1271 xfs_extlen_t lsize;
1272
1273 statp->f_type = XFS_SB_MAGIC;
1274 statp->f_namelen = MAXNAMELEN - 1;
1275
1276 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1277 statp->f_fsid.val[0] = (u32)id;
1278 statp->f_fsid.val[1] = (u32)(id >> 32);
1279
Christoph Hellwigd4d90b52008-04-22 17:34:37 +10001280 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001281
1282 spin_lock(&mp->m_sb_lock);
1283 statp->f_bsize = sbp->sb_blocksize;
1284 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1285 statp->f_blocks = sbp->sb_dblocks - lsize;
1286 statp->f_bfree = statp->f_bavail =
1287 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1288 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1289#if XFS_BIG_INUMS
1290 fakeinos += mp->m_inoadd;
1291#endif
1292 statp->f_files =
1293 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1294 if (mp->m_maxicount)
1295#if XFS_BIG_INUMS
1296 if (!mp->m_inoadd)
1297#endif
1298 statp->f_files = min_t(typeof(statp->f_files),
1299 statp->f_files,
1300 mp->m_maxicount);
1301 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1302 spin_unlock(&mp->m_sb_lock);
1303
1304 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1305 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306}
1307
1308STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001309xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 struct super_block *sb,
1311 int *flags,
1312 char *options)
1313{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001314 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001315 substring_t args[MAX_OPT_ARGS];
1316 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001318 while ((p = strsep(&options, ",")) != NULL) {
1319 int token;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001320
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001321 if (!*p)
1322 continue;
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001323
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001324 token = match_token(p, tokens, args);
1325 switch (token) {
1326 case Opt_barrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001327 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001328
1329 /*
1330 * Test if barriers are actually working if we can,
1331 * else delay this check until the filesystem is
1332 * marked writeable.
1333 */
1334 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1335 xfs_mountfs_check_barriers(mp);
1336 break;
1337 case Opt_nobarrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001338 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001339 break;
1340 default:
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001341 /*
1342 * Logically we would return an error here to prevent
1343 * users from believing they might have changed
1344 * mount options using remount which can't be changed.
1345 *
1346 * But unfortunately mount(8) adds all options from
1347 * mtab and fstab to the mount arguments in some cases
1348 * so we can't blindly reject options, but have to
1349 * check for each specified option if it actually
1350 * differs from the currently set option and only
1351 * reject it if that's the case.
1352 *
1353 * Until that is implemented we return success for
1354 * every remount request, and silently ignore all
1355 * options that we can't actually change.
1356 */
1357#if 0
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001358 printk(KERN_INFO
1359 "XFS: mount option \"%s\" not supported for remount\n", p);
1360 return -EINVAL;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001361#else
Christoph Hellwig6c5e51d2008-10-12 14:30:44 +02001362 break;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001363#endif
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001364 }
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001365 }
1366
1367 /* rw/ro -> rw */
1368 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1369 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1370 if (mp->m_flags & XFS_MOUNT_BARRIER)
1371 xfs_mountfs_check_barriers(mp);
1372 }
1373
1374 /* rw -> ro */
1375 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001376 xfs_filestream_flush(mp);
1377 xfs_sync(mp, SYNC_DATA_QUIESCE);
1378 xfs_attr_quiesce(mp);
1379 mp->m_flags |= XFS_MOUNT_RDONLY;
1380 }
1381
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001382 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
1384
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001385/*
1386 * Second stage of a freeze. The data is already frozen so we only
1387 * need to take care of themetadata. Once that's done write a dummy
1388 * record to dirty the log in case of a crash while frozen.
1389 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001391xfs_fs_lockfs(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 struct super_block *sb)
1393{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001394 struct xfs_mount *mp = XFS_M(sb);
1395
1396 xfs_attr_quiesce(mp);
1397 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398}
1399
1400STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001401xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 struct seq_file *m,
1403 struct vfsmount *mnt)
1404{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001405 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406}
1407
1408STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001409xfs_fs_quotasync(
Nathan Scottee348072005-11-02 10:32:38 +11001410 struct super_block *sb,
1411 int type)
1412{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001413 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
Nathan Scottee348072005-11-02 10:32:38 +11001414}
1415
1416STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001417xfs_fs_getxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 struct super_block *sb,
1419 struct fs_quota_stat *fqs)
1420{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001421 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422}
1423
1424STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001425xfs_fs_setxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 struct super_block *sb,
1427 unsigned int flags,
1428 int op)
1429{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001430 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431}
1432
1433STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001434xfs_fs_getxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 struct super_block *sb,
1436 int type,
1437 qid_t id,
1438 struct fs_disk_quota *fdq)
1439{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001440 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001441 (type == USRQUOTA) ? Q_XGETQUOTA :
1442 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1443 Q_XGETPQUOTA), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444}
1445
1446STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001447xfs_fs_setxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 struct super_block *sb,
1449 int type,
1450 qid_t id,
1451 struct fs_disk_quota *fdq)
1452{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001453 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001454 (type == USRQUOTA) ? Q_XSETQLIM :
1455 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1456 Q_XSETPQLIM), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457}
1458
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001459/*
1460 * This function fills in xfs_mount_t fields based on mount args.
1461 * Note: the superblock has _not_ yet been read in.
1462 */
1463STATIC int
1464xfs_start_flags(
1465 struct xfs_mount_args *ap,
1466 struct xfs_mount *mp)
1467{
Christoph Hellwiga7381592008-08-13 16:04:05 +10001468 int error;
1469
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001470 /* Values are in BBs */
1471 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1472 /*
1473 * At this point the superblock has not been read
1474 * in, therefore we do not know the block size.
1475 * Before the mount call ends we will convert
1476 * these to FSBs.
1477 */
1478 mp->m_dalign = ap->sunit;
1479 mp->m_swidth = ap->swidth;
1480 }
1481
1482 if (ap->logbufs != -1 &&
1483 ap->logbufs != 0 &&
1484 (ap->logbufs < XLOG_MIN_ICLOGS ||
1485 ap->logbufs > XLOG_MAX_ICLOGS)) {
1486 cmn_err(CE_WARN,
1487 "XFS: invalid logbufs value: %d [not %d-%d]",
1488 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1489 return XFS_ERROR(EINVAL);
1490 }
1491 mp->m_logbufs = ap->logbufs;
1492 if (ap->logbufsize != -1 &&
1493 ap->logbufsize != 0 &&
1494 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1495 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1496 !is_power_of_2(ap->logbufsize))) {
1497 cmn_err(CE_WARN,
1498 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1499 ap->logbufsize);
1500 return XFS_ERROR(EINVAL);
1501 }
Christoph Hellwiga7381592008-08-13 16:04:05 +10001502
1503 error = ENOMEM;
1504
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001505 mp->m_logbsize = ap->logbufsize;
1506 mp->m_fsname_len = strlen(ap->fsname) + 1;
Christoph Hellwiga7381592008-08-13 16:04:05 +10001507
1508 mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL);
1509 if (!mp->m_fsname)
1510 goto out;
1511
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001512 if (ap->rtname[0]) {
Christoph Hellwiga7381592008-08-13 16:04:05 +10001513 mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL);
1514 if (!mp->m_rtname)
1515 goto out_free_fsname;
1516
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001517 }
Christoph Hellwiga7381592008-08-13 16:04:05 +10001518
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001519 if (ap->logname[0]) {
Christoph Hellwiga7381592008-08-13 16:04:05 +10001520 mp->m_logname = kstrdup(ap->logname, GFP_KERNEL);
1521 if (!mp->m_logname)
1522 goto out_free_rtname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001523 }
1524
1525 if (ap->flags & XFSMNT_WSYNC)
1526 mp->m_flags |= XFS_MOUNT_WSYNC;
1527#if XFS_BIG_INUMS
1528 if (ap->flags & XFSMNT_INO64) {
1529 mp->m_flags |= XFS_MOUNT_INO64;
1530 mp->m_inoadd = XFS_INO64_OFFSET;
1531 }
1532#endif
1533 if (ap->flags & XFSMNT_RETERR)
1534 mp->m_flags |= XFS_MOUNT_RETERR;
1535 if (ap->flags & XFSMNT_NOALIGN)
1536 mp->m_flags |= XFS_MOUNT_NOALIGN;
1537 if (ap->flags & XFSMNT_SWALLOC)
1538 mp->m_flags |= XFS_MOUNT_SWALLOC;
1539 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1540 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1541 if (ap->flags & XFSMNT_32BITINODES)
1542 mp->m_flags |= XFS_MOUNT_32BITINODES;
1543
1544 if (ap->flags & XFSMNT_IOSIZE) {
1545 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1546 ap->iosizelog < XFS_MIN_IO_LOG) {
1547 cmn_err(CE_WARN,
1548 "XFS: invalid log iosize: %d [not %d-%d]",
1549 ap->iosizelog, XFS_MIN_IO_LOG,
1550 XFS_MAX_IO_LOG);
1551 return XFS_ERROR(EINVAL);
1552 }
1553
1554 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1555 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1556 }
1557
1558 if (ap->flags & XFSMNT_IKEEP)
1559 mp->m_flags |= XFS_MOUNT_IKEEP;
1560 if (ap->flags & XFSMNT_DIRSYNC)
1561 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1562 if (ap->flags & XFSMNT_ATTR2)
1563 mp->m_flags |= XFS_MOUNT_ATTR2;
1564 if (ap->flags & XFSMNT_NOATTR2)
1565 mp->m_flags |= XFS_MOUNT_NOATTR2;
1566
1567 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1568 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1569
1570 /*
1571 * no recovery flag requires a read-only mount
1572 */
1573 if (ap->flags & XFSMNT_NORECOVERY) {
1574 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1575 cmn_err(CE_WARN,
1576 "XFS: tried to mount a FS read-write without recovery!");
1577 return XFS_ERROR(EINVAL);
1578 }
1579 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1580 }
1581
1582 if (ap->flags & XFSMNT_NOUUID)
1583 mp->m_flags |= XFS_MOUNT_NOUUID;
1584 if (ap->flags & XFSMNT_BARRIER)
1585 mp->m_flags |= XFS_MOUNT_BARRIER;
1586 else
1587 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1588
1589 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1590 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1591
1592 if (ap->flags & XFSMNT_DMAPI)
1593 mp->m_flags |= XFS_MOUNT_DMAPI;
1594 return 0;
Christoph Hellwiga7381592008-08-13 16:04:05 +10001595
1596
1597 out_free_rtname:
1598 kfree(mp->m_rtname);
1599 out_free_fsname:
1600 kfree(mp->m_fsname);
1601 out:
1602 return error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001603}
1604
1605/*
1606 * This function fills in xfs_mount_t fields based on mount args.
1607 * Note: the superblock _has_ now been read in.
1608 */
1609STATIC int
1610xfs_finish_flags(
1611 struct xfs_mount_args *ap,
1612 struct xfs_mount *mp)
1613{
1614 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1615
1616 /* Fail a mount where the logbuf is smaller then the log stripe */
1617 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1618 if ((ap->logbufsize <= 0) &&
1619 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1620 mp->m_logbsize = mp->m_sb.sb_logsunit;
1621 } else if (ap->logbufsize > 0 &&
1622 ap->logbufsize < mp->m_sb.sb_logsunit) {
1623 cmn_err(CE_WARN,
1624 "XFS: logbuf size must be greater than or equal to log stripe size");
1625 return XFS_ERROR(EINVAL);
1626 }
1627 } else {
1628 /* Fail a mount if the logbuf is larger than 32K */
1629 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1630 cmn_err(CE_WARN,
1631 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1632 return XFS_ERROR(EINVAL);
1633 }
1634 }
1635
1636 /*
1637 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1638 * told by noattr2 to turn it off
1639 */
1640 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1641 !(ap->flags & XFSMNT_NOATTR2))
1642 mp->m_flags |= XFS_MOUNT_ATTR2;
1643
1644 /*
1645 * prohibit r/w mounts of read-only filesystems
1646 */
1647 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1648 cmn_err(CE_WARN,
1649 "XFS: cannot mount a read-only filesystem as read-write");
1650 return XFS_ERROR(EROFS);
1651 }
1652
1653 /*
1654 * check for shared mount.
1655 */
1656 if (ap->flags & XFSMNT_SHARED) {
1657 if (!xfs_sb_version_hasshared(&mp->m_sb))
1658 return XFS_ERROR(EINVAL);
1659
1660 /*
1661 * For IRIX 6.5, shared mounts must have the shared
1662 * version bit set, have the persistent readonly
1663 * field set, must be version 0 and can only be mounted
1664 * read-only.
1665 */
1666 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1667 (mp->m_sb.sb_shared_vn != 0))
1668 return XFS_ERROR(EINVAL);
1669
1670 mp->m_flags |= XFS_MOUNT_SHARED;
1671
1672 /*
1673 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1674 */
1675 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1676 return XFS_ERROR(EINVAL);
1677 }
1678
1679 if (ap->flags & XFSMNT_UQUOTA) {
1680 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1681 if (ap->flags & XFSMNT_UQUOTAENF)
1682 mp->m_qflags |= XFS_UQUOTA_ENFD;
1683 }
1684
1685 if (ap->flags & XFSMNT_GQUOTA) {
1686 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1687 if (ap->flags & XFSMNT_GQUOTAENF)
1688 mp->m_qflags |= XFS_OQUOTA_ENFD;
1689 } else if (ap->flags & XFSMNT_PQUOTA) {
1690 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1691 if (ap->flags & XFSMNT_PQUOTAENF)
1692 mp->m_qflags |= XFS_OQUOTA_ENFD;
1693 }
1694
1695 return 0;
1696}
1697
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001699xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 struct super_block *sb,
1701 void *data,
1702 int silent)
1703{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001704 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001705 struct xfs_mount *mp = NULL;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001706 struct xfs_mount_args *args;
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001707 int flags = 0, error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001709 args = xfs_args_allocate(sb, silent);
1710 if (!args)
1711 return -ENOMEM;
1712
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001713 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1714 if (!mp)
1715 goto out_free_args;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001717 spin_lock_init(&mp->m_sb_lock);
1718 mutex_init(&mp->m_ilock);
1719 mutex_init(&mp->m_growlock);
1720 atomic_set(&mp->m_active_trans, 0);
Christoph Hellwig74394492007-08-30 17:21:22 +10001721 INIT_LIST_HEAD(&mp->m_sync_list);
1722 spin_lock_init(&mp->m_sync_lock);
1723 init_waitqueue_head(&mp->m_wait_single_sync_task);
1724
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001725 mp->m_super = sb;
1726 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001728 if (sb->s_flags & MS_RDONLY)
1729 mp->m_flags |= XFS_MOUNT_RDONLY;
1730
Christoph Hellwig745f6912007-08-30 17:20:39 +10001731 error = xfs_parseargs(mp, (char *)data, args, 0);
1732 if (error)
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001733 goto out_free_mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 sb_min_blocksize(sb, BBSIZE);
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001736 sb->s_xattr = xfs_xattr_handlers;
Nathan Scotta50cd262006-03-14 14:06:18 +11001737 sb->s_export_op = &xfs_export_operations;
Nathan Scotta50cd262006-03-14 14:06:18 +11001738 sb->s_qcop = &xfs_quotactl_operations;
1739 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001741 error = xfs_dmops_get(mp, args);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001742 if (error)
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001743 goto out_free_mp;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001744 error = xfs_qmops_get(mp, args);
1745 if (error)
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001746 goto out_put_dmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001747
1748 if (args->flags & XFSMNT_QUIET)
1749 flags |= XFS_MFSI_QUIET;
1750
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001751 error = xfs_open_devices(mp, args);
1752 if (error)
1753 goto out_put_qmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001754
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001755 if (xfs_icsb_init_counters(mp))
1756 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1757
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001758 /*
1759 * Setup flags based on mount(2) options and then the superblock
1760 */
1761 error = xfs_start_flags(args, mp);
1762 if (error)
Christoph Hellwiga7381592008-08-13 16:04:05 +10001763 goto out_free_fsname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001764 error = xfs_readsb(mp, flags);
1765 if (error)
Christoph Hellwiga7381592008-08-13 16:04:05 +10001766 goto out_free_fsname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001767 error = xfs_finish_flags(args, mp);
1768 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001769 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001770
Christoph Hellwige34b5622008-05-20 15:10:36 +10001771 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001772 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001773 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001774
1775 if (mp->m_flags & XFS_MOUNT_BARRIER)
1776 xfs_mountfs_check_barriers(mp);
1777
1778 error = xfs_filestream_mount(mp);
1779 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001780 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001781
Christoph Hellwig42490232008-08-13 16:49:32 +10001782 error = xfs_mountfs(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001783 if (error)
Christoph Hellwig120226c2008-05-20 15:11:11 +10001784 goto out_filestream_unmount;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001785
1786 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 sb->s_dirt = 1;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001789 sb->s_magic = XFS_SB_MAGIC;
1790 sb->s_blocksize = mp->m_sb.sb_blocksize;
1791 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1793 sb->s_time_gran = 1;
1794 set_posix_acl_flag(sb);
1795
David Chinner01651642008-08-13 15:45:15 +10001796 root = igrab(VFS_I(mp->m_rootip));
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001797 if (!root) {
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001798 error = ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 goto fail_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001800 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001801 if (is_bad_inode(root)) {
1802 error = EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 goto fail_vnrele;
1804 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001805 sb->s_root = d_alloc_root(root);
1806 if (!sb->s_root) {
1807 error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 goto fail_vnrele;
1809 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001810
1811 mp->m_sync_work.w_syncer = xfs_sync_worker;
1812 mp->m_sync_work.w_mount = mp;
1813 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1814 if (IS_ERR(mp->m_sync_task)) {
1815 error = -PTR_ERR(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 goto fail_vnrele;
Christoph Hellwig74394492007-08-30 17:21:22 +10001817 }
1818
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001819 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001821 kfree(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 return 0;
1823
Christoph Hellwig120226c2008-05-20 15:11:11 +10001824 out_filestream_unmount:
1825 xfs_filestream_unmount(mp);
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001826 out_free_sb:
1827 xfs_freesb(mp);
Christoph Hellwiga7381592008-08-13 16:04:05 +10001828 out_free_fsname:
1829 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001830 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001831 xfs_close_devices(mp);
1832 out_put_qmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001833 xfs_qmops_put(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001834 out_put_dmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001835 xfs_dmops_put(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001836 out_free_mp:
1837 kfree(mp);
1838 out_free_args:
1839 kfree(args);
1840 return -error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001841
1842 fail_vnrele:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 if (sb->s_root) {
1844 dput(sb->s_root);
1845 sb->s_root = NULL;
1846 } else {
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001847 iput(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 }
1849
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001850 fail_unmount:
Christoph Hellwige48ad312008-05-20 11:30:52 +10001851 /*
1852 * Blow away any referenced inode in the filestreams cache.
1853 * This can and will cause log traffic as inodes go inactive
1854 * here.
1855 */
1856 xfs_filestream_unmount(mp);
1857
1858 XFS_bflush(mp->m_ddev_targp);
1859 error = xfs_unmount_flush(mp, 0);
1860 WARN_ON(error);
1861
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001862 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001863 goto out_free_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864}
1865
David Howells454e2392006-06-23 02:02:57 -07001866STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001867xfs_fs_get_sb(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 struct file_system_type *fs_type,
1869 int flags,
1870 const char *dev_name,
David Howells454e2392006-06-23 02:02:57 -07001871 void *data,
1872 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873{
David Howells454e2392006-06-23 02:02:57 -07001874 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1875 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876}
1877
David Chinner7989cb82007-02-10 18:34:56 +11001878static struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001879 .alloc_inode = xfs_fs_alloc_inode,
1880 .destroy_inode = xfs_fs_destroy_inode,
1881 .write_inode = xfs_fs_write_inode,
1882 .clear_inode = xfs_fs_clear_inode,
1883 .put_super = xfs_fs_put_super,
1884 .write_super = xfs_fs_write_super,
1885 .sync_fs = xfs_fs_sync_super,
1886 .write_super_lockfs = xfs_fs_lockfs,
1887 .statfs = xfs_fs_statfs,
1888 .remount_fs = xfs_fs_remount,
1889 .show_options = xfs_fs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890};
1891
David Chinner7989cb82007-02-10 18:34:56 +11001892static struct quotactl_ops xfs_quotactl_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001893 .quota_sync = xfs_fs_quotasync,
1894 .get_xstate = xfs_fs_getxstate,
1895 .set_xstate = xfs_fs_setxstate,
1896 .get_xquota = xfs_fs_getxquota,
1897 .set_xquota = xfs_fs_setxquota,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898};
1899
Andrew Morton5085b602007-02-20 13:57:47 -08001900static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 .owner = THIS_MODULE,
1902 .name = "xfs",
Nathan Scotta50cd262006-03-14 14:06:18 +11001903 .get_sb = xfs_fs_get_sb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 .kill_sb = kill_block_super,
1905 .fs_flags = FS_REQUIRES_DEV,
1906};
1907
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001908STATIC int __init
1909xfs_alloc_trace_bufs(void)
1910{
1911#ifdef XFS_ALLOC_TRACE
1912 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1913 if (!xfs_alloc_trace_buf)
1914 goto out;
1915#endif
1916#ifdef XFS_BMAP_TRACE
1917 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1918 if (!xfs_bmap_trace_buf)
1919 goto out_free_alloc_trace;
1920#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001921#ifdef XFS_BTREE_TRACE
1922 xfs_allocbt_trace_buf = ktrace_alloc(XFS_ALLOCBT_TRACE_SIZE,
1923 KM_MAYFAIL);
1924 if (!xfs_allocbt_trace_buf)
1925 goto out_free_bmap_trace;
1926
1927 xfs_inobt_trace_buf = ktrace_alloc(XFS_INOBT_TRACE_SIZE, KM_MAYFAIL);
1928 if (!xfs_inobt_trace_buf)
1929 goto out_free_allocbt_trace;
1930
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001931 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1932 if (!xfs_bmbt_trace_buf)
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001933 goto out_free_inobt_trace;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001934#endif
1935#ifdef XFS_ATTR_TRACE
1936 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1937 if (!xfs_attr_trace_buf)
1938 goto out_free_bmbt_trace;
1939#endif
1940#ifdef XFS_DIR2_TRACE
1941 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1942 if (!xfs_dir2_trace_buf)
1943 goto out_free_attr_trace;
1944#endif
1945
1946 return 0;
1947
1948#ifdef XFS_DIR2_TRACE
1949 out_free_attr_trace:
1950#endif
1951#ifdef XFS_ATTR_TRACE
1952 ktrace_free(xfs_attr_trace_buf);
1953 out_free_bmbt_trace:
1954#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001955#ifdef XFS_BTREE_TRACE
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001956 ktrace_free(xfs_bmbt_trace_buf);
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001957 out_free_inobt_trace:
1958 ktrace_free(xfs_inobt_trace_buf);
1959 out_free_allocbt_trace:
1960 ktrace_free(xfs_allocbt_trace_buf);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001961 out_free_bmap_trace:
1962#endif
1963#ifdef XFS_BMAP_TRACE
1964 ktrace_free(xfs_bmap_trace_buf);
1965 out_free_alloc_trace:
1966#endif
1967#ifdef XFS_ALLOC_TRACE
1968 ktrace_free(xfs_alloc_trace_buf);
1969 out:
1970#endif
1971 return -ENOMEM;
1972}
1973
1974STATIC void
1975xfs_free_trace_bufs(void)
1976{
1977#ifdef XFS_DIR2_TRACE
1978 ktrace_free(xfs_dir2_trace_buf);
1979#endif
1980#ifdef XFS_ATTR_TRACE
1981 ktrace_free(xfs_attr_trace_buf);
1982#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001983#ifdef XFS_BTREE_TRACE
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001984 ktrace_free(xfs_bmbt_trace_buf);
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001985 ktrace_free(xfs_inobt_trace_buf);
1986 ktrace_free(xfs_allocbt_trace_buf);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001987#endif
1988#ifdef XFS_BMAP_TRACE
1989 ktrace_free(xfs_bmap_trace_buf);
1990#endif
1991#ifdef XFS_ALLOC_TRACE
1992 ktrace_free(xfs_alloc_trace_buf);
1993#endif
1994}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
1996STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001997xfs_init_zones(void)
1998{
Christoph Hellwig5ec7f8c2008-08-13 16:22:40 +10001999 xfs_vnode_zone = kmem_zone_init_flags(sizeof(struct inode), "xfs_vnode",
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002000 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
2001 KM_ZONE_SPREAD,
2002 xfs_fs_inode_init_once);
2003 if (!xfs_vnode_zone)
2004 goto out;
2005
2006 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
2007 if (!xfs_ioend_zone)
2008 goto out_destroy_vnode_zone;
2009
2010 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
2011 xfs_ioend_zone);
2012 if (!xfs_ioend_pool)
2013 goto out_destroy_ioend_zone;
2014
2015 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
2016 "xfs_log_ticket");
2017 if (!xfs_log_ticket_zone)
2018 goto out_destroy_ioend_pool;
2019
2020 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
2021 "xfs_bmap_free_item");
2022 if (!xfs_bmap_free_item_zone)
2023 goto out_destroy_log_ticket_zone;
2024 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
2025 "xfs_btree_cur");
2026 if (!xfs_btree_cur_zone)
2027 goto out_destroy_bmap_free_item_zone;
2028
2029 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
2030 "xfs_da_state");
2031 if (!xfs_da_state_zone)
2032 goto out_destroy_btree_cur_zone;
2033
2034 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
2035 if (!xfs_dabuf_zone)
2036 goto out_destroy_da_state_zone;
2037
2038 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
2039 if (!xfs_ifork_zone)
2040 goto out_destroy_dabuf_zone;
2041
2042 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
2043 if (!xfs_trans_zone)
2044 goto out_destroy_ifork_zone;
2045
2046 /*
2047 * The size of the zone allocated buf log item is the maximum
2048 * size possible under XFS. This wastes a little bit of memory,
2049 * but it is much faster.
2050 */
2051 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
2052 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
2053 NBWORD) * sizeof(int))), "xfs_buf_item");
2054 if (!xfs_buf_item_zone)
2055 goto out_destroy_trans_zone;
2056
2057 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
2058 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
2059 sizeof(xfs_extent_t))), "xfs_efd_item");
2060 if (!xfs_efd_zone)
2061 goto out_destroy_buf_item_zone;
2062
2063 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
2064 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
2065 sizeof(xfs_extent_t))), "xfs_efi_item");
2066 if (!xfs_efi_zone)
2067 goto out_destroy_efd_zone;
2068
2069 xfs_inode_zone =
2070 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
2071 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
David Chinner07c8f672008-10-30 16:11:59 +11002072 KM_ZONE_SPREAD, xfs_inode_init_once);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002073 if (!xfs_inode_zone)
2074 goto out_destroy_efi_zone;
2075
2076 xfs_ili_zone =
2077 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
2078 KM_ZONE_SPREAD, NULL);
2079 if (!xfs_ili_zone)
2080 goto out_destroy_inode_zone;
2081
2082#ifdef CONFIG_XFS_POSIX_ACL
2083 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
2084 if (!xfs_acl_zone)
2085 goto out_destroy_ili_zone;
2086#endif
2087
2088 return 0;
2089
2090#ifdef CONFIG_XFS_POSIX_ACL
2091 out_destroy_ili_zone:
2092#endif
2093 kmem_zone_destroy(xfs_ili_zone);
2094 out_destroy_inode_zone:
2095 kmem_zone_destroy(xfs_inode_zone);
2096 out_destroy_efi_zone:
2097 kmem_zone_destroy(xfs_efi_zone);
2098 out_destroy_efd_zone:
2099 kmem_zone_destroy(xfs_efd_zone);
2100 out_destroy_buf_item_zone:
2101 kmem_zone_destroy(xfs_buf_item_zone);
2102 out_destroy_trans_zone:
2103 kmem_zone_destroy(xfs_trans_zone);
2104 out_destroy_ifork_zone:
2105 kmem_zone_destroy(xfs_ifork_zone);
2106 out_destroy_dabuf_zone:
2107 kmem_zone_destroy(xfs_dabuf_zone);
2108 out_destroy_da_state_zone:
2109 kmem_zone_destroy(xfs_da_state_zone);
2110 out_destroy_btree_cur_zone:
2111 kmem_zone_destroy(xfs_btree_cur_zone);
2112 out_destroy_bmap_free_item_zone:
2113 kmem_zone_destroy(xfs_bmap_free_item_zone);
2114 out_destroy_log_ticket_zone:
2115 kmem_zone_destroy(xfs_log_ticket_zone);
2116 out_destroy_ioend_pool:
2117 mempool_destroy(xfs_ioend_pool);
2118 out_destroy_ioend_zone:
2119 kmem_zone_destroy(xfs_ioend_zone);
2120 out_destroy_vnode_zone:
2121 kmem_zone_destroy(xfs_vnode_zone);
2122 out:
2123 return -ENOMEM;
2124}
2125
2126STATIC void
2127xfs_destroy_zones(void)
2128{
2129#ifdef CONFIG_XFS_POSIX_ACL
2130 kmem_zone_destroy(xfs_acl_zone);
2131#endif
2132 kmem_zone_destroy(xfs_ili_zone);
2133 kmem_zone_destroy(xfs_inode_zone);
2134 kmem_zone_destroy(xfs_efi_zone);
2135 kmem_zone_destroy(xfs_efd_zone);
2136 kmem_zone_destroy(xfs_buf_item_zone);
2137 kmem_zone_destroy(xfs_trans_zone);
2138 kmem_zone_destroy(xfs_ifork_zone);
2139 kmem_zone_destroy(xfs_dabuf_zone);
2140 kmem_zone_destroy(xfs_da_state_zone);
2141 kmem_zone_destroy(xfs_btree_cur_zone);
2142 kmem_zone_destroy(xfs_bmap_free_item_zone);
2143 kmem_zone_destroy(xfs_log_ticket_zone);
2144 mempool_destroy(xfs_ioend_pool);
2145 kmem_zone_destroy(xfs_ioend_zone);
2146 kmem_zone_destroy(xfs_vnode_zone);
2147
2148}
2149
2150STATIC int __init
2151init_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152{
2153 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 static char message[] __initdata = KERN_INFO \
2155 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
2156
2157 printk(message);
2158
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 ktrace_init(64);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002160 vn_init();
2161 xfs_dir_startup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Nathan Scott87582802006-03-14 13:18:19 +11002163 error = xfs_init_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002164 if (error)
2165 goto out;
2166
2167 error = xfs_alloc_trace_bufs();
2168 if (error)
2169 goto out_destroy_zones;
2170
2171 error = xfs_mru_cache_init();
2172 if (error)
2173 goto out_free_trace_buffers;
2174
2175 error = xfs_filestream_init();
2176 if (error)
2177 goto out_mru_cache_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Nathan Scottce8e9222006-01-11 15:39:08 +11002179 error = xfs_buf_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002180 if (error)
2181 goto out_filestream_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002183 error = xfs_init_procfs();
2184 if (error)
2185 goto out_buf_terminate;
2186
2187 error = xfs_sysctl_register();
2188 if (error)
2189 goto out_cleanup_procfs;
2190
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 vfs_initquota();
2192
2193 error = register_filesystem(&xfs_fs_type);
2194 if (error)
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002195 goto out_sysctl_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 return 0;
2197
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002198 out_sysctl_unregister:
2199 xfs_sysctl_unregister();
2200 out_cleanup_procfs:
2201 xfs_cleanup_procfs();
2202 out_buf_terminate:
Nathan Scottce8e9222006-01-11 15:39:08 +11002203 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002204 out_filestream_uninit:
2205 xfs_filestream_uninit();
2206 out_mru_cache_uninit:
2207 xfs_mru_cache_uninit();
2208 out_free_trace_buffers:
2209 xfs_free_trace_bufs();
2210 out_destroy_zones:
Nathan Scott87582802006-03-14 13:18:19 +11002211 xfs_destroy_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002212 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 return error;
2214}
2215
2216STATIC void __exit
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002217exit_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218{
2219 vfs_exitquota();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 unregister_filesystem(&xfs_fs_type);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002221 xfs_sysctl_unregister();
2222 xfs_cleanup_procfs();
Nathan Scottce8e9222006-01-11 15:39:08 +11002223 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002224 xfs_filestream_uninit();
2225 xfs_mru_cache_uninit();
2226 xfs_free_trace_bufs();
Nathan Scott87582802006-03-14 13:18:19 +11002227 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 ktrace_uninit();
2229}
2230
2231module_init(init_xfs_fs);
2232module_exit(exit_xfs_fs);
2233
2234MODULE_AUTHOR("Silicon Graphics, Inc.");
2235MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2236MODULE_LICENSE("GPL");