blob: 9bfb26066a84308ccf5abd816a1a4af5b9aabdcc [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"
39#include "xfs_ialloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include "xfs_bmap.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "xfs_rtalloc.h"
42#include "xfs_error.h"
43#include "xfs_itable.h"
Christoph Hellwig9909c4a2007-10-11 18:11:14 +100044#include "xfs_fsops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include "xfs_rw.h"
46#include "xfs_acl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include "xfs_attr.h"
48#include "xfs_buf_item.h"
49#include "xfs_utils.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100050#include "xfs_vnodeops.h"
Christoph Hellwig745f6912007-08-30 17:20:39 +100051#include "xfs_vfsops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include "xfs_version.h"
David Chinnera67d7c52007-11-23 16:29:32 +110053#include "xfs_log_priv.h"
David Chinner249a8c12008-02-05 12:13:32 +110054#include "xfs_trans_priv.h"
Christoph Hellwig48b62a12008-05-20 11:30:39 +100055#include "xfs_filestream.h"
Christoph Hellwig9f8868f2008-07-18 17:11:46 +100056#include "xfs_da_btree.h"
57#include "xfs_dir2_trace.h"
58#include "xfs_extfree_item.h"
59#include "xfs_mru_cache.h"
60#include "xfs_inode_item.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#include <linux/namei.h>
63#include <linux/init.h>
64#include <linux/mount.h>
Christoph Hellwig0829c362005-09-02 16:58:49 +100065#include <linux/mempool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#include <linux/writeback.h>
Christoph Hellwig4df08c52005-09-05 08:34:18 +100067#include <linux/kthread.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080068#include <linux/freezer.h>
Christoph Hellwig62a877e2008-07-18 17:12:36 +100069#include <linux/parser.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
David Chinner7989cb82007-02-10 18:34:56 +110071static struct quotactl_ops xfs_quotactl_operations;
72static struct super_operations xfs_super_operations;
73static kmem_zone_t *xfs_vnode_zone;
74static kmem_zone_t *xfs_ioend_zone;
Christoph Hellwig0829c362005-09-02 16:58:49 +100075mempool_t *xfs_ioend_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77STATIC struct xfs_mount_args *
78xfs_args_allocate(
Nathan Scott764d1f82006-03-31 13:04:17 +100079 struct super_block *sb,
80 int silent)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 struct xfs_mount_args *args;
83
Christoph Hellwigbdd907b2008-05-20 15:10:44 +100084 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
85 if (!args)
86 return NULL;
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 args->logbufs = args->logbufsize = -1;
89 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
90
91 /* Copy the already-parsed mount(2) flags we're interested in */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 if (sb->s_flags & MS_DIRSYNC)
93 args->flags |= XFSMNT_DIRSYNC;
94 if (sb->s_flags & MS_SYNCHRONOUS)
95 args->flags |= XFSMNT_WSYNC;
Nathan Scott764d1f82006-03-31 13:04:17 +100096 if (silent)
97 args->flags |= XFSMNT_QUIET;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 args->flags |= XFSMNT_32BITINODES;
99
100 return args;
101}
102
David Chinnera67d7c52007-11-23 16:29:32 +1100103#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
104#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
105#define MNTOPT_LOGDEV "logdev" /* log device */
106#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
107#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
108#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
109#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
110#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
111#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
112#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
113#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
114#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
115#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
116#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
117#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
118#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
119#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
120#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
121#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
122#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
123 * unwritten extent conversion */
124#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
125#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
126#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
127#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
128#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
129#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
130#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
131 * in stat(). */
132#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
133#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
134#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
135#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
136#define MNTOPT_NOQUOTA "noquota" /* no quotas */
137#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
138#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
139#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
140#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
141#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
142#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
143#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
144#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
145#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
146#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
147#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
148#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
149#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
150
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000151/*
152 * Table driven mount option parser.
153 *
154 * Currently only used for remount, but it will be used for mount
155 * in the future, too.
156 */
157enum {
158 Opt_barrier, Opt_nobarrier, Opt_err
159};
160
Steven Whitehousea447c092008-10-13 10:46:57 +0100161static const match_table_t tokens = {
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000162 {Opt_barrier, "barrier"},
163 {Opt_nobarrier, "nobarrier"},
164 {Opt_err, NULL}
165};
166
167
David Chinnera67d7c52007-11-23 16:29:32 +1100168STATIC unsigned long
169suffix_strtoul(char *s, char **endp, unsigned int base)
170{
171 int last, shift_left_factor = 0;
172 char *value = s;
173
174 last = strlen(value) - 1;
175 if (value[last] == 'K' || value[last] == 'k') {
176 shift_left_factor = 10;
177 value[last] = '\0';
178 }
179 if (value[last] == 'M' || value[last] == 'm') {
180 shift_left_factor = 20;
181 value[last] = '\0';
182 }
183 if (value[last] == 'G' || value[last] == 'g') {
184 shift_left_factor = 30;
185 value[last] = '\0';
186 }
187
188 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
189}
190
191STATIC int
192xfs_parseargs(
193 struct xfs_mount *mp,
194 char *options,
195 struct xfs_mount_args *args,
196 int update)
197{
198 char *this_char, *value, *eov;
199 int dsunit, dswidth, vol_dsunit, vol_dswidth;
200 int iosize;
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100201 int dmapi_implies_ikeep = 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100202
203 args->flags |= XFSMNT_BARRIER;
204 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
205
206 if (!options)
207 goto done;
208
209 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
210
211 while ((this_char = strsep(&options, ",")) != NULL) {
212 if (!*this_char)
213 continue;
214 if ((value = strchr(this_char, '=')) != NULL)
215 *value++ = 0;
216
217 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
218 if (!value || !*value) {
219 cmn_err(CE_WARN,
220 "XFS: %s option requires an argument",
221 this_char);
222 return EINVAL;
223 }
224 args->logbufs = simple_strtoul(value, &eov, 10);
225 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
226 if (!value || !*value) {
227 cmn_err(CE_WARN,
228 "XFS: %s option requires an argument",
229 this_char);
230 return EINVAL;
231 }
232 args->logbufsize = suffix_strtoul(value, &eov, 10);
233 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
234 if (!value || !*value) {
235 cmn_err(CE_WARN,
236 "XFS: %s option requires an argument",
237 this_char);
238 return EINVAL;
239 }
240 strncpy(args->logname, value, MAXNAMELEN);
241 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
242 if (!value || !*value) {
243 cmn_err(CE_WARN,
244 "XFS: %s option requires an argument",
245 this_char);
246 return EINVAL;
247 }
248 strncpy(args->mtpt, value, MAXNAMELEN);
249 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
250 if (!value || !*value) {
251 cmn_err(CE_WARN,
252 "XFS: %s option requires an argument",
253 this_char);
254 return EINVAL;
255 }
256 strncpy(args->rtname, value, MAXNAMELEN);
257 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
258 if (!value || !*value) {
259 cmn_err(CE_WARN,
260 "XFS: %s option requires an argument",
261 this_char);
262 return EINVAL;
263 }
264 iosize = simple_strtoul(value, &eov, 10);
265 args->flags |= XFSMNT_IOSIZE;
266 args->iosizelog = (uint8_t) iosize;
267 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
268 if (!value || !*value) {
269 cmn_err(CE_WARN,
270 "XFS: %s option requires an argument",
271 this_char);
272 return EINVAL;
273 }
274 iosize = suffix_strtoul(value, &eov, 10);
275 args->flags |= XFSMNT_IOSIZE;
276 args->iosizelog = ffs(iosize) - 1;
277 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
278 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
279 mp->m_flags |= XFS_MOUNT_GRPID;
280 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
281 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
282 mp->m_flags &= ~XFS_MOUNT_GRPID;
283 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
284 args->flags |= XFSMNT_WSYNC;
285 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
286 args->flags |= XFSMNT_OSYNCISOSYNC;
287 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
288 args->flags |= XFSMNT_NORECOVERY;
289 } else if (!strcmp(this_char, MNTOPT_INO64)) {
290 args->flags |= XFSMNT_INO64;
291#if !XFS_BIG_INUMS
292 cmn_err(CE_WARN,
293 "XFS: %s option not allowed on this system",
294 this_char);
295 return EINVAL;
296#endif
297 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
298 args->flags |= XFSMNT_NOALIGN;
299 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
300 args->flags |= XFSMNT_SWALLOC;
301 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
302 if (!value || !*value) {
303 cmn_err(CE_WARN,
304 "XFS: %s option requires an argument",
305 this_char);
306 return EINVAL;
307 }
308 dsunit = simple_strtoul(value, &eov, 10);
309 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
310 if (!value || !*value) {
311 cmn_err(CE_WARN,
312 "XFS: %s option requires an argument",
313 this_char);
314 return EINVAL;
315 }
316 dswidth = simple_strtoul(value, &eov, 10);
317 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
318 args->flags &= ~XFSMNT_32BITINODES;
319#if !XFS_BIG_INUMS
320 cmn_err(CE_WARN,
321 "XFS: %s option not allowed on this system",
322 this_char);
323 return EINVAL;
324#endif
325 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
326 args->flags |= XFSMNT_NOUUID;
327 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
328 args->flags |= XFSMNT_BARRIER;
329 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
330 args->flags &= ~XFSMNT_BARRIER;
331 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100332 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100333 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100334 dmapi_implies_ikeep = 0;
335 args->flags &= ~XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100336 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
337 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
338 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
339 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
340 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
341 args->flags |= XFSMNT_ATTR2;
342 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
343 args->flags &= ~XFSMNT_ATTR2;
Tim Shimmin7c12f292008-04-30 18:15:28 +1000344 args->flags |= XFSMNT_NOATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100345 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
346 args->flags2 |= XFSMNT2_FILESTREAMS;
347 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
348 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
349 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
350 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
351 !strcmp(this_char, MNTOPT_UQUOTA) ||
352 !strcmp(this_char, MNTOPT_USRQUOTA)) {
353 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
354 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
355 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
356 args->flags |= XFSMNT_UQUOTA;
357 args->flags &= ~XFSMNT_UQUOTAENF;
358 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
359 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
360 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
361 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
362 args->flags |= XFSMNT_PQUOTA;
363 args->flags &= ~XFSMNT_PQUOTAENF;
364 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
365 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
366 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
367 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
368 args->flags |= XFSMNT_GQUOTA;
369 args->flags &= ~XFSMNT_GQUOTAENF;
370 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
371 args->flags |= XFSMNT_DMAPI;
372 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
373 args->flags |= XFSMNT_DMAPI;
374 } else if (!strcmp(this_char, MNTOPT_DMI)) {
375 args->flags |= XFSMNT_DMAPI;
376 } else if (!strcmp(this_char, "ihashsize")) {
377 cmn_err(CE_WARN,
378 "XFS: ihashsize no longer used, option is deprecated.");
379 } else if (!strcmp(this_char, "osyncisdsync")) {
380 /* no-op, this is now the default */
381 cmn_err(CE_WARN,
382 "XFS: osyncisdsync is now the default, option is deprecated.");
383 } else if (!strcmp(this_char, "irixsgid")) {
384 cmn_err(CE_WARN,
385 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
386 } else {
387 cmn_err(CE_WARN,
388 "XFS: unknown mount option [%s].", this_char);
389 return EINVAL;
390 }
391 }
392
393 if (args->flags & XFSMNT_NORECOVERY) {
394 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
395 cmn_err(CE_WARN,
396 "XFS: no-recovery mounts must be read-only.");
397 return EINVAL;
398 }
399 }
400
401 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
402 cmn_err(CE_WARN,
403 "XFS: sunit and swidth options incompatible with the noalign option");
404 return EINVAL;
405 }
406
407 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
408 cmn_err(CE_WARN,
409 "XFS: cannot mount with both project and group quota");
410 return EINVAL;
411 }
412
413 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
414 printk("XFS: %s option needs the mount point option as well\n",
415 MNTOPT_DMAPI);
416 return EINVAL;
417 }
418
419 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
420 cmn_err(CE_WARN,
421 "XFS: sunit and swidth must be specified together");
422 return EINVAL;
423 }
424
425 if (dsunit && (dswidth % dsunit != 0)) {
426 cmn_err(CE_WARN,
427 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
428 dswidth, dsunit);
429 return EINVAL;
430 }
431
432 /*
433 * Applications using DMI filesystems often expect the
434 * inode generation number to be monotonically increasing.
435 * If we delete inode chunks we break this assumption, so
436 * keep unused inode chunks on disk for DMI filesystems
437 * until we come up with a better solution.
438 * Note that if "ikeep" or "noikeep" mount options are
439 * supplied, then they are honored.
440 */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100441 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
442 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100443
444 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
445 if (dsunit) {
446 args->sunit = dsunit;
447 args->flags |= XFSMNT_RETERR;
448 } else {
449 args->sunit = vol_dsunit;
450 }
451 dswidth ? (args->swidth = dswidth) :
452 (args->swidth = vol_dswidth);
453 } else {
454 args->sunit = args->swidth = 0;
455 }
456
457done:
458 if (args->flags & XFSMNT_32BITINODES)
459 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
460 if (args->flags2)
461 args->flags |= XFSMNT_FLAGS2;
462 return 0;
463}
464
465struct proc_xfs_info {
466 int flag;
467 char *str;
468};
469
470STATIC int
471xfs_showargs(
472 struct xfs_mount *mp,
473 struct seq_file *m)
474{
475 static struct proc_xfs_info xfs_info_set[] = {
476 /* the few simple ones we can get from the mount struct */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100477 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
David Chinnera67d7c52007-11-23 16:29:32 +1100478 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
479 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
480 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
481 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
482 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
483 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
484 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
485 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
486 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
487 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
488 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
489 { 0, NULL }
490 };
491 static struct proc_xfs_info xfs_info_unset[] = {
492 /* the few simple ones we can get from the mount struct */
David Chinnera67d7c52007-11-23 16:29:32 +1100493 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
494 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
495 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
496 { 0, NULL }
497 };
498 struct proc_xfs_info *xfs_infop;
499
500 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
501 if (mp->m_flags & xfs_infop->flag)
502 seq_puts(m, xfs_infop->str);
503 }
504 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
505 if (!(mp->m_flags & xfs_infop->flag))
506 seq_puts(m, xfs_infop->str);
507 }
508
509 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
510 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
511 (int)(1 << mp->m_writeio_log) >> 10);
512
513 if (mp->m_logbufs > 0)
514 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
515 if (mp->m_logbsize > 0)
516 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
517
518 if (mp->m_logname)
519 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
520 if (mp->m_rtname)
521 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
522
523 if (mp->m_dalign > 0)
524 seq_printf(m, "," MNTOPT_SUNIT "=%d",
525 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
526 if (mp->m_swidth > 0)
527 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
528 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
529
530 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
531 seq_puts(m, "," MNTOPT_USRQUOTA);
532 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
533 seq_puts(m, "," MNTOPT_UQUOTANOENF);
534
535 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
536 seq_puts(m, "," MNTOPT_PRJQUOTA);
537 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
538 seq_puts(m, "," MNTOPT_PQUOTANOENF);
539
540 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
541 seq_puts(m, "," MNTOPT_GRPQUOTA);
542 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
543 seq_puts(m, "," MNTOPT_GQUOTANOENF);
544
545 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
546 seq_puts(m, "," MNTOPT_NOQUOTA);
547
548 return 0;
549}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550__uint64_t
551xfs_max_file_offset(
552 unsigned int blockshift)
553{
554 unsigned int pagefactor = 1;
555 unsigned int bitshift = BITS_PER_LONG - 1;
556
557 /* Figure out maximum filesize, on Linux this can depend on
558 * the filesystem blocksize (on 32 bit platforms).
559 * __block_prepare_write does this in an [unsigned] long...
560 * page->index << (PAGE_CACHE_SHIFT - bbits)
561 * So, for page sized blocks (4K on 32 bit platforms),
562 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
563 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
564 * but for smaller blocksizes it is less (bbits = log2 bsize).
565 * Note1: get_block_t takes a long (implicit cast from above)
566 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
567 * can optionally convert the [unsigned] long from above into
568 * an [unsigned] long long.
569 */
570
571#if BITS_PER_LONG == 32
572# if defined(CONFIG_LBD)
573 ASSERT(sizeof(sector_t) == 8);
574 pagefactor = PAGE_CACHE_SIZE;
575 bitshift = BITS_PER_LONG;
576# else
577 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
578# endif
579#endif
580
581 return (((__uint64_t)pagefactor) << bitshift) - 1;
582}
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584int
585xfs_blkdev_get(
586 xfs_mount_t *mp,
587 const char *name,
588 struct block_device **bdevp)
589{
590 int error = 0;
591
Al Viro30c40d22008-02-22 19:50:45 -0500592 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (IS_ERR(*bdevp)) {
594 error = PTR_ERR(*bdevp);
595 printk("XFS: Invalid device [%s], error=%d\n", name, error);
596 }
597
598 return -error;
599}
600
601void
602xfs_blkdev_put(
603 struct block_device *bdev)
604{
605 if (bdev)
Al Viro30c40d22008-02-22 19:50:45 -0500606 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607}
608
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100609/*
610 * Try to write out the superblock using barriers.
611 */
612STATIC int
613xfs_barrier_test(
614 xfs_mount_t *mp)
615{
616 xfs_buf_t *sbp = xfs_getsb(mp, 0);
617 int error;
618
619 XFS_BUF_UNDONE(sbp);
620 XFS_BUF_UNREAD(sbp);
621 XFS_BUF_UNDELAYWRITE(sbp);
622 XFS_BUF_WRITE(sbp);
623 XFS_BUF_UNASYNC(sbp);
624 XFS_BUF_ORDERED(sbp);
625
626 xfsbdstrat(mp, sbp);
627 error = xfs_iowait(sbp);
628
629 /*
630 * Clear all the flags we set and possible error state in the
631 * buffer. We only did the write to try out whether barriers
632 * worked and shouldn't leave any traces in the superblock
633 * buffer.
634 */
635 XFS_BUF_DONE(sbp);
636 XFS_BUF_ERROR(sbp, 0);
637 XFS_BUF_UNORDERED(sbp);
638
639 xfs_buf_relse(sbp);
640 return error;
641}
642
643void
644xfs_mountfs_check_barriers(xfs_mount_t *mp)
645{
646 int error;
647
648 if (mp->m_logdev_targp != mp->m_ddev_targp) {
649 xfs_fs_cmn_err(CE_NOTE, mp,
650 "Disabling barriers, not supported with external log device");
651 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100652 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100653 }
654
Nathan Scottb2ea4012006-07-28 17:05:13 +1000655 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
656 xfs_fs_cmn_err(CE_NOTE, mp,
657 "Disabling barriers, underlying device is readonly");
658 mp->m_flags &= ~XFS_MOUNT_BARRIER;
659 return;
660 }
661
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100662 error = xfs_barrier_test(mp);
663 if (error) {
664 xfs_fs_cmn_err(CE_NOTE, mp,
665 "Disabling barriers, trial barrier write failed");
666 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100667 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100668 }
669}
670
671void
672xfs_blkdev_issue_flush(
673 xfs_buftarg_t *buftarg)
674{
Nathan Scottce8e9222006-01-11 15:39:08 +1100675 blkdev_issue_flush(buftarg->bt_bdev, NULL);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100676}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000678STATIC void
679xfs_close_devices(
680 struct xfs_mount *mp)
681{
682 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000683 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000684 xfs_free_buftarg(mp->m_logdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000685 xfs_blkdev_put(logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000686 }
687 if (mp->m_rtdev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000688 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000689 xfs_free_buftarg(mp->m_rtdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000690 xfs_blkdev_put(rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000691 }
692 xfs_free_buftarg(mp->m_ddev_targp);
693}
694
695/*
696 * The file system configurations are:
697 * (1) device (partition) with data and internal log
698 * (2) logical volume with data and log subvolumes.
699 * (3) logical volume with data, log, and realtime subvolumes.
700 *
701 * We only have to handle opening the log and realtime volumes here if
702 * they are present. The data subvolume has already been opened by
703 * get_sb_bdev() and is stored in sb->s_bdev.
704 */
705STATIC int
706xfs_open_devices(
707 struct xfs_mount *mp,
708 struct xfs_mount_args *args)
709{
710 struct block_device *ddev = mp->m_super->s_bdev;
711 struct block_device *logdev = NULL, *rtdev = NULL;
712 int error;
713
714 /*
715 * Open real time and log devices - order is important.
716 */
717 if (args->logname[0]) {
718 error = xfs_blkdev_get(mp, args->logname, &logdev);
719 if (error)
720 goto out;
721 }
722
723 if (args->rtname[0]) {
724 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
725 if (error)
726 goto out_close_logdev;
727
728 if (rtdev == ddev || rtdev == logdev) {
729 cmn_err(CE_WARN,
730 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
731 error = EINVAL;
732 goto out_close_rtdev;
733 }
734 }
735
736 /*
737 * Setup xfs_mount buffer target pointers
738 */
739 error = ENOMEM;
740 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
741 if (!mp->m_ddev_targp)
742 goto out_close_rtdev;
743
744 if (rtdev) {
745 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
746 if (!mp->m_rtdev_targp)
747 goto out_free_ddev_targ;
748 }
749
750 if (logdev && logdev != ddev) {
751 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
752 if (!mp->m_logdev_targp)
753 goto out_free_rtdev_targ;
754 } else {
755 mp->m_logdev_targp = mp->m_ddev_targp;
756 }
757
758 return 0;
759
760 out_free_rtdev_targ:
761 if (mp->m_rtdev_targp)
762 xfs_free_buftarg(mp->m_rtdev_targp);
763 out_free_ddev_targ:
764 xfs_free_buftarg(mp->m_ddev_targp);
765 out_close_rtdev:
766 if (rtdev)
767 xfs_blkdev_put(rtdev);
768 out_close_logdev:
769 if (logdev && logdev != ddev)
770 xfs_blkdev_put(logdev);
771 out:
772 return error;
773}
774
Christoph Hellwige34b5622008-05-20 15:10:36 +1000775/*
776 * Setup xfs_mount buffer target pointers based on superblock
777 */
778STATIC int
779xfs_setup_devices(
780 struct xfs_mount *mp)
781{
782 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000783
Christoph Hellwige34b5622008-05-20 15:10:36 +1000784 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
785 mp->m_sb.sb_sectsize);
786 if (error)
787 return error;
788
789 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
790 unsigned int log_sector_size = BBSIZE;
791
792 if (xfs_sb_version_hassector(&mp->m_sb))
793 log_sector_size = mp->m_sb.sb_logsectsize;
794 error = xfs_setsize_buftarg(mp->m_logdev_targp,
795 mp->m_sb.sb_blocksize,
796 log_sector_size);
797 if (error)
798 return error;
799 }
800 if (mp->m_rtdev_targp) {
801 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
802 mp->m_sb.sb_blocksize,
803 mp->m_sb.sb_sectsize);
804 if (error)
805 return error;
806 }
807
808 return 0;
809}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000810
David Chinner249a8c12008-02-05 12:13:32 +1100811/*
812 * XFS AIL push thread support
813 */
814void
815xfsaild_wakeup(
816 xfs_mount_t *mp,
817 xfs_lsn_t threshold_lsn)
818{
819 mp->m_ail.xa_target = threshold_lsn;
820 wake_up_process(mp->m_ail.xa_task);
821}
822
823int
824xfsaild(
825 void *data)
826{
827 xfs_mount_t *mp = (xfs_mount_t *)data;
828 xfs_lsn_t last_pushed_lsn = 0;
829 long tout = 0;
830
831 while (!kthread_should_stop()) {
832 if (tout)
833 schedule_timeout_interruptible(msecs_to_jiffies(tout));
834 tout = 1000;
835
836 /* swsusp */
837 try_to_freeze();
838
839 ASSERT(mp->m_log);
840 if (XFS_FORCED_SHUTDOWN(mp))
841 continue;
842
843 tout = xfsaild_push(mp, &last_pushed_lsn);
844 }
845
846 return 0;
847} /* xfsaild */
848
849int
850xfsaild_start(
851 xfs_mount_t *mp)
852{
853 mp->m_ail.xa_target = 0;
854 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
855 if (IS_ERR(mp->m_ail.xa_task))
856 return -PTR_ERR(mp->m_ail.xa_task);
857 return 0;
858}
859
860void
861xfsaild_stop(
862 xfs_mount_t *mp)
863{
864 kthread_stop(mp->m_ail.xa_task);
865}
866
867
868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100870xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 struct super_block *sb)
872{
Christoph Hellwigdf80c932008-08-13 16:22:09 +1000873 return kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
875
876STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100877xfs_fs_destroy_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 struct inode *inode)
879{
Christoph Hellwiga19d0332008-08-13 16:11:26 +1000880 kmem_zone_free(xfs_vnode_zone, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
882
883STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100884xfs_fs_inode_init_once(
Christoph Lameter4ba9b9d2007-10-16 23:25:51 -0700885 void *vnode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886{
Christoph Hellwig863890c2008-08-13 16:12:05 +1000887 inode_init_once((struct inode *)vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888}
889
David Chinner07c8f672008-10-30 16:11:59 +1100890
891/*
892 * Slab object creation initialisation for the XFS inode.
893 * This covers only the idempotent fields in the XFS inode;
894 * all other fields need to be initialised on allocation
895 * from the slab. This avoids the need to repeatedly intialise
896 * fields in the xfs inode that left in the initialise state
897 * when freeing the inode.
898 */
899void
900xfs_inode_init_once(
David Chinner07c8f672008-10-30 16:11:59 +1100901 void *inode)
902{
903 struct xfs_inode *ip = inode;
904
905 memset(ip, 0, sizeof(struct xfs_inode));
906 atomic_set(&ip->i_iocount, 0);
907 atomic_set(&ip->i_pincount, 0);
908 spin_lock_init(&ip->i_flags_lock);
909 INIT_LIST_HEAD(&ip->i_reclaim);
910 init_waitqueue_head(&ip->i_ipin_wait);
911 /*
912 * Because we want to use a counting completion, complete
913 * the flush completion once to allow a single access to
914 * the flush completion without blocking.
915 */
916 init_completion(&ip->i_flush);
917 complete(&ip->i_flush);
918
919 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
920 "xfsino", ip->i_ino);
921 mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
922}
923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924/*
925 * Attempt to flush the inode, this will actually fail
926 * if the inode is pinned, but we dirty the inode again
927 * at the point when it is unpinned after a log write,
Nathan Scott87582802006-03-14 13:18:19 +1100928 * since this is when the inode itself becomes flushable.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 */
930STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +1100931xfs_fs_write_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 struct inode *inode,
933 int sync)
934{
David Chinnera3f74ff2008-03-06 13:43:42 +1100935 int error = 0;
936 int flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100938 xfs_itrace_entry(XFS_I(inode));
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000939 if (sync) {
940 filemap_fdatawait(inode->i_mapping);
941 flags |= FLUSH_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 }
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000943 error = xfs_inode_flush(XFS_I(inode), flags);
Lachlan McIlroye893bff2007-10-12 11:13:35 +1000944 /*
945 * if we failed to write out the inode then mark
946 * it dirty again so we'll try again later.
947 */
948 if (error)
949 mark_inode_dirty_sync(inode);
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 return -error;
952}
953
954STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100955xfs_fs_clear_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 struct inode *inode)
957{
Christoph Hellwig1543d792007-08-29 11:46:47 +1000958 xfs_inode_t *ip = XFS_I(inode);
Christoph Hellwig56d433e2005-09-05 08:23:54 +1000959
Christoph Hellwig02ba71d2005-09-05 08:28:02 +1000960 /*
Christoph Hellwig1543d792007-08-29 11:46:47 +1000961 * ip can be null when xfs_iget_core calls xfs_idestroy if we
Christoph Hellwig02ba71d2005-09-05 08:28:02 +1000962 * find an inode with di_mode == 0 but without IGET_CREATE set.
963 */
Christoph Hellwig1543d792007-08-29 11:46:47 +1000964 if (ip) {
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100965 xfs_itrace_entry(ip);
Christoph Hellwig1543d792007-08-29 11:46:47 +1000966 XFS_STATS_INC(vn_rele);
967 XFS_STATS_INC(vn_remove);
968 XFS_STATS_INC(vn_reclaim);
969 XFS_STATS_DEC(vn_active);
Christoph Hellwig56d433e2005-09-05 08:23:54 +1000970
Christoph Hellwig1543d792007-08-29 11:46:47 +1000971 xfs_inactive(ip);
972 xfs_iflags_clear(ip, XFS_IMODIFIED);
973 if (xfs_reclaim(ip))
Harvey Harrison34a622b2008-04-10 12:19:21 +1000974 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +1000975 }
Christoph Hellwig56d433e2005-09-05 08:23:54 +1000976
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000977 ASSERT(XFS_I(inode) == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978}
979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980/*
981 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
982 * Doing this has two advantages:
983 * - It saves on stack space, which is tight in certain situations
984 * - It can be used (with care) as a mechanism to avoid deadlocks.
985 * Flushing while allocating in a full filesystem requires both.
986 */
987STATIC void
988xfs_syncd_queue_work(
Christoph Hellwig74394492007-08-30 17:21:22 +1000989 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 void *data,
Christoph Hellwig74394492007-08-30 17:21:22 +1000991 void (*syncer)(struct xfs_mount *, void *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992{
Nathan Scottb83bd132006-06-09 16:48:30 +1000993 struct bhv_vfs_sync_work *work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Nathan Scottb83bd132006-06-09 16:48:30 +1000995 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 INIT_LIST_HEAD(&work->w_list);
997 work->w_syncer = syncer;
998 work->w_data = data;
Christoph Hellwig74394492007-08-30 17:21:22 +1000999 work->w_mount = mp;
1000 spin_lock(&mp->m_sync_lock);
1001 list_add_tail(&work->w_list, &mp->m_sync_list);
1002 spin_unlock(&mp->m_sync_lock);
1003 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004}
1005
1006/*
1007 * Flush delayed allocate data, attempting to free up reserved space
1008 * from existing allocations. At this point a new allocation attempt
1009 * has failed with ENOSPC and we are in the process of scratching our
1010 * heads, looking about for more room...
1011 */
1012STATIC void
1013xfs_flush_inode_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001014 struct xfs_mount *mp,
1015 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
Christoph Hellwig74394492007-08-30 17:21:22 +10001017 struct inode *inode = arg;
1018 filemap_flush(inode->i_mapping);
1019 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020}
1021
1022void
1023xfs_flush_inode(
1024 xfs_inode_t *ip)
1025{
David Chinner01651642008-08-13 15:45:15 +10001026 struct inode *inode = VFS_I(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
1028 igrab(inode);
Christoph Hellwig74394492007-08-30 17:21:22 +10001029 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001030 delay(msecs_to_jiffies(500));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031}
1032
1033/*
1034 * This is the "bigger hammer" version of xfs_flush_inode_work...
1035 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1036 */
1037STATIC void
1038xfs_flush_device_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001039 struct xfs_mount *mp,
1040 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
Christoph Hellwig74394492007-08-30 17:21:22 +10001042 struct inode *inode = arg;
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001043 sync_blockdev(mp->m_super->s_bdev);
Christoph Hellwig74394492007-08-30 17:21:22 +10001044 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045}
1046
1047void
1048xfs_flush_device(
1049 xfs_inode_t *ip)
1050{
David Chinnere4f75292008-08-13 16:00:45 +10001051 struct inode *inode = VFS_I(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
1053 igrab(inode);
Christoph Hellwig74394492007-08-30 17:21:22 +10001054 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001055 delay(msecs_to_jiffies(500));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1057}
1058
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059STATIC void
Christoph Hellwig74394492007-08-30 17:21:22 +10001060xfs_sync_worker(
1061 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 void *unused)
1063{
1064 int error;
1065
Christoph Hellwig74394492007-08-30 17:21:22 +10001066 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
David Chinner7e206942008-04-17 16:49:55 +10001067 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
Christoph Hellwig74394492007-08-30 17:21:22 +10001068 mp->m_sync_seq++;
1069 wake_up(&mp->m_wait_single_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070}
1071
1072STATIC int
1073xfssyncd(
1074 void *arg)
1075{
Christoph Hellwig74394492007-08-30 17:21:22 +10001076 struct xfs_mount *mp = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 long timeleft;
Nathan Scottb83bd132006-06-09 16:48:30 +10001078 bhv_vfs_sync_work_t *work, *n;
Christoph Hellwig4df08c52005-09-05 08:34:18 +10001079 LIST_HEAD (tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Rafael J. Wysocki83144182007-07-17 04:03:35 -07001081 set_freezable();
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001082 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 for (;;) {
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001084 timeleft = schedule_timeout_interruptible(timeleft);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 /* swsusp */
Christoph Lameter3e1d1d22005-06-24 23:13:50 -07001086 try_to_freeze();
Christoph Hellwig74394492007-08-30 17:21:22 +10001087 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 break;
1089
Christoph Hellwig74394492007-08-30 17:21:22 +10001090 spin_lock(&mp->m_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 /*
1092 * We can get woken by laptop mode, to do a sync -
1093 * that's the (only!) case where the list would be
1094 * empty with time remaining.
1095 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001096 if (!timeleft || list_empty(&mp->m_sync_list)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 if (!timeleft)
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001098 timeleft = xfs_syncd_centisecs *
1099 msecs_to_jiffies(10);
Christoph Hellwig74394492007-08-30 17:21:22 +10001100 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1101 list_add_tail(&mp->m_sync_work.w_list,
1102 &mp->m_sync_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001104 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 list_move(&work->w_list, &tmp);
Christoph Hellwig74394492007-08-30 17:21:22 +10001106 spin_unlock(&mp->m_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
1108 list_for_each_entry_safe(work, n, &tmp, w_list) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001109 (*work->w_syncer)(mp, work->w_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 list_del(&work->w_list);
Christoph Hellwig74394492007-08-30 17:21:22 +10001111 if (work == &mp->m_sync_work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 continue;
Denys Vlasenkof0e2d932008-05-19 16:31:57 +10001113 kmem_free(work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 }
1115 }
1116
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 return 0;
1118}
1119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120STATIC void
Christoph Hellwiga7381592008-08-13 16:04:05 +10001121xfs_free_fsname(
1122 struct xfs_mount *mp)
1123{
1124 kfree(mp->m_fsname);
1125 kfree(mp->m_rtname);
1126 kfree(mp->m_logname);
1127}
1128
1129STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001130xfs_fs_put_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 struct super_block *sb)
1132{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001133 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001134 struct xfs_inode *rip = mp->m_rootip;
1135 int unmount_event_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 int error;
1137
Christoph Hellwig74394492007-08-30 17:21:22 +10001138 kthread_stop(mp->m_sync_task);
1139
Christoph Hellwig745f6912007-08-30 17:20:39 +10001140 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001141
1142#ifdef HAVE_DMAPI
1143 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1144 unmount_event_flags =
1145 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1146 0 : DM_FLAGS_UNWANTED;
1147 /*
1148 * Ignore error from dmapi here, first unmount is not allowed
1149 * to fail anyway, and second we wouldn't want to fail a
1150 * unmount because of dmapi.
1151 */
1152 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1153 NULL, NULL, 0, 0, unmount_event_flags);
1154 }
1155#endif
1156
1157 /*
1158 * Blow away any referenced inode in the filestreams cache.
1159 * This can and will cause log traffic as inodes go inactive
1160 * here.
1161 */
1162 xfs_filestream_unmount(mp);
1163
1164 XFS_bflush(mp->m_ddev_targp);
1165 error = xfs_unmount_flush(mp, 0);
1166 WARN_ON(error);
1167
Christoph Hellwige48ad312008-05-20 11:30:52 +10001168 /*
1169 * If we're forcing a shutdown, typically because of a media error,
1170 * we want to make sure we invalidate dirty pages that belong to
1171 * referenced vnodes as well.
1172 */
1173 if (XFS_FORCED_SHUTDOWN(mp)) {
1174 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1175 ASSERT(error != EFSCORRUPTED);
1176 }
1177
1178 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1179 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1180 unmount_event_flags);
1181 }
1182
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001183 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001184 xfs_freesb(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001185 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001186 xfs_close_devices(mp);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001187 xfs_qmops_put(mp);
1188 xfs_dmops_put(mp);
Christoph Hellwiga7381592008-08-13 16:04:05 +10001189 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001190 kfree(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}
1192
1193STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001194xfs_fs_write_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 struct super_block *sb)
1196{
Nathan Scottb83bd132006-06-09 16:48:30 +10001197 if (!(sb->s_flags & MS_RDONLY))
Christoph Hellwig745f6912007-08-30 17:20:39 +10001198 xfs_sync(XFS_M(sb), SYNC_FSDATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 sb->s_dirt = 0;
1200}
1201
1202STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001203xfs_fs_sync_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 struct super_block *sb,
1205 int wait)
1206{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001207 struct xfs_mount *mp = XFS_M(sb);
Nathan Scottb83bd132006-06-09 16:48:30 +10001208 int error;
1209 int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001211 /*
1212 * Treat a sync operation like a freeze. This is to work
1213 * around a race in sync_inodes() which works in two phases
1214 * - an asynchronous flush, which can write out an inode
1215 * without waiting for file size updates to complete, and a
1216 * synchronous flush, which wont do anything because the
1217 * async flush removed the inode's dirty flag. Also
1218 * sync_inodes() will not see any files that just have
1219 * outstanding transactions to be flushed because we don't
1220 * dirty the Linux inode until after the transaction I/O
1221 * completes.
1222 */
1223 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
David Chinner28239452007-02-10 18:36:40 +11001224 /*
1225 * First stage of freeze - no more writers will make progress
1226 * now we are here, so we flush delwri and delalloc buffers
1227 * here, then wait for all I/O to complete. Data is frozen at
1228 * that point. Metadata is not frozen, transactions can still
1229 * occur here so don't bother flushing the buftarg (i.e
1230 * SYNC_QUIESCE) because it'll just get dirty again.
1231 */
David Chinner516b2e72007-06-18 16:50:48 +10001232 flags = SYNC_DATA_QUIESCE;
David Chinner28239452007-02-10 18:36:40 +11001233 } else
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001234 flags = SYNC_FSDATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
Christoph Hellwig745f6912007-08-30 17:20:39 +10001236 error = xfs_sync(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 sb->s_dirt = 0;
1238
1239 if (unlikely(laptop_mode)) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001240 int prev_sync_seq = mp->m_sync_seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
1242 /*
1243 * The disk must be active because we're syncing.
1244 * We schedule xfssyncd now (now that the disk is
1245 * active) instead of later (when it might not be).
1246 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001247 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 /*
1249 * We have to wait for the sync iteration to complete.
1250 * If we don't, the disk activity caused by the sync
1251 * will come after the sync is completed, and that
1252 * triggers another sync from laptop mode.
1253 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001254 wait_event(mp->m_wait_single_sync_task,
1255 mp->m_sync_seq != prev_sync_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 }
1257
1258 return -error;
1259}
1260
1261STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001262xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001263 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 struct kstatfs *statp)
1265{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001266 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1267 xfs_sb_t *sbp = &mp->m_sb;
1268 __uint64_t fakeinos, id;
1269 xfs_extlen_t lsize;
1270
1271 statp->f_type = XFS_SB_MAGIC;
1272 statp->f_namelen = MAXNAMELEN - 1;
1273
1274 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1275 statp->f_fsid.val[0] = (u32)id;
1276 statp->f_fsid.val[1] = (u32)(id >> 32);
1277
Christoph Hellwigd4d90b52008-04-22 17:34:37 +10001278 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001279
1280 spin_lock(&mp->m_sb_lock);
1281 statp->f_bsize = sbp->sb_blocksize;
1282 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1283 statp->f_blocks = sbp->sb_dblocks - lsize;
1284 statp->f_bfree = statp->f_bavail =
1285 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1286 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1287#if XFS_BIG_INUMS
1288 fakeinos += mp->m_inoadd;
1289#endif
1290 statp->f_files =
1291 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1292 if (mp->m_maxicount)
1293#if XFS_BIG_INUMS
1294 if (!mp->m_inoadd)
1295#endif
1296 statp->f_files = min_t(typeof(statp->f_files),
1297 statp->f_files,
1298 mp->m_maxicount);
1299 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1300 spin_unlock(&mp->m_sb_lock);
1301
1302 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1303 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304}
1305
1306STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001307xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 struct super_block *sb,
1309 int *flags,
1310 char *options)
1311{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001312 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001313 substring_t args[MAX_OPT_ARGS];
1314 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001316 while ((p = strsep(&options, ",")) != NULL) {
1317 int token;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001318
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001319 if (!*p)
1320 continue;
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001321
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001322 token = match_token(p, tokens, args);
1323 switch (token) {
1324 case Opt_barrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001325 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001326
1327 /*
1328 * Test if barriers are actually working if we can,
1329 * else delay this check until the filesystem is
1330 * marked writeable.
1331 */
1332 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1333 xfs_mountfs_check_barriers(mp);
1334 break;
1335 case Opt_nobarrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001336 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001337 break;
1338 default:
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001339 /*
1340 * Logically we would return an error here to prevent
1341 * users from believing they might have changed
1342 * mount options using remount which can't be changed.
1343 *
1344 * But unfortunately mount(8) adds all options from
1345 * mtab and fstab to the mount arguments in some cases
1346 * so we can't blindly reject options, but have to
1347 * check for each specified option if it actually
1348 * differs from the currently set option and only
1349 * reject it if that's the case.
1350 *
1351 * Until that is implemented we return success for
1352 * every remount request, and silently ignore all
1353 * options that we can't actually change.
1354 */
1355#if 0
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001356 printk(KERN_INFO
1357 "XFS: mount option \"%s\" not supported for remount\n", p);
1358 return -EINVAL;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001359#else
Christoph Hellwig6c5e51d2008-10-12 14:30:44 +02001360 break;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001361#endif
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001362 }
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001363 }
1364
1365 /* rw/ro -> rw */
1366 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1367 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1368 if (mp->m_flags & XFS_MOUNT_BARRIER)
1369 xfs_mountfs_check_barriers(mp);
1370 }
1371
1372 /* rw -> ro */
1373 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001374 xfs_filestream_flush(mp);
1375 xfs_sync(mp, SYNC_DATA_QUIESCE);
1376 xfs_attr_quiesce(mp);
1377 mp->m_flags |= XFS_MOUNT_RDONLY;
1378 }
1379
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001380 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381}
1382
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001383/*
1384 * Second stage of a freeze. The data is already frozen so we only
1385 * need to take care of themetadata. Once that's done write a dummy
1386 * record to dirty the log in case of a crash while frozen.
1387 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001389xfs_fs_lockfs(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 struct super_block *sb)
1391{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001392 struct xfs_mount *mp = XFS_M(sb);
1393
1394 xfs_attr_quiesce(mp);
1395 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
1398STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001399xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 struct seq_file *m,
1401 struct vfsmount *mnt)
1402{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001403 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404}
1405
1406STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001407xfs_fs_quotasync(
Nathan Scottee348072005-11-02 10:32:38 +11001408 struct super_block *sb,
1409 int type)
1410{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001411 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
Nathan Scottee348072005-11-02 10:32:38 +11001412}
1413
1414STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001415xfs_fs_getxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 struct super_block *sb,
1417 struct fs_quota_stat *fqs)
1418{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001419 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420}
1421
1422STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001423xfs_fs_setxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 struct super_block *sb,
1425 unsigned int flags,
1426 int op)
1427{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001428 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429}
1430
1431STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001432xfs_fs_getxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 struct super_block *sb,
1434 int type,
1435 qid_t id,
1436 struct fs_disk_quota *fdq)
1437{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001438 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001439 (type == USRQUOTA) ? Q_XGETQUOTA :
1440 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1441 Q_XGETPQUOTA), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442}
1443
1444STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001445xfs_fs_setxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 struct super_block *sb,
1447 int type,
1448 qid_t id,
1449 struct fs_disk_quota *fdq)
1450{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001451 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001452 (type == USRQUOTA) ? Q_XSETQLIM :
1453 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1454 Q_XSETPQLIM), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455}
1456
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001457/*
1458 * This function fills in xfs_mount_t fields based on mount args.
1459 * Note: the superblock has _not_ yet been read in.
1460 */
1461STATIC int
1462xfs_start_flags(
1463 struct xfs_mount_args *ap,
1464 struct xfs_mount *mp)
1465{
Christoph Hellwiga7381592008-08-13 16:04:05 +10001466 int error;
1467
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001468 /* Values are in BBs */
1469 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1470 /*
1471 * At this point the superblock has not been read
1472 * in, therefore we do not know the block size.
1473 * Before the mount call ends we will convert
1474 * these to FSBs.
1475 */
1476 mp->m_dalign = ap->sunit;
1477 mp->m_swidth = ap->swidth;
1478 }
1479
1480 if (ap->logbufs != -1 &&
1481 ap->logbufs != 0 &&
1482 (ap->logbufs < XLOG_MIN_ICLOGS ||
1483 ap->logbufs > XLOG_MAX_ICLOGS)) {
1484 cmn_err(CE_WARN,
1485 "XFS: invalid logbufs value: %d [not %d-%d]",
1486 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1487 return XFS_ERROR(EINVAL);
1488 }
1489 mp->m_logbufs = ap->logbufs;
1490 if (ap->logbufsize != -1 &&
1491 ap->logbufsize != 0 &&
1492 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1493 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1494 !is_power_of_2(ap->logbufsize))) {
1495 cmn_err(CE_WARN,
1496 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1497 ap->logbufsize);
1498 return XFS_ERROR(EINVAL);
1499 }
Christoph Hellwiga7381592008-08-13 16:04:05 +10001500
1501 error = ENOMEM;
1502
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001503 mp->m_logbsize = ap->logbufsize;
1504 mp->m_fsname_len = strlen(ap->fsname) + 1;
Christoph Hellwiga7381592008-08-13 16:04:05 +10001505
1506 mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL);
1507 if (!mp->m_fsname)
1508 goto out;
1509
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001510 if (ap->rtname[0]) {
Christoph Hellwiga7381592008-08-13 16:04:05 +10001511 mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL);
1512 if (!mp->m_rtname)
1513 goto out_free_fsname;
1514
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001515 }
Christoph Hellwiga7381592008-08-13 16:04:05 +10001516
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001517 if (ap->logname[0]) {
Christoph Hellwiga7381592008-08-13 16:04:05 +10001518 mp->m_logname = kstrdup(ap->logname, GFP_KERNEL);
1519 if (!mp->m_logname)
1520 goto out_free_rtname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001521 }
1522
1523 if (ap->flags & XFSMNT_WSYNC)
1524 mp->m_flags |= XFS_MOUNT_WSYNC;
1525#if XFS_BIG_INUMS
1526 if (ap->flags & XFSMNT_INO64) {
1527 mp->m_flags |= XFS_MOUNT_INO64;
1528 mp->m_inoadd = XFS_INO64_OFFSET;
1529 }
1530#endif
1531 if (ap->flags & XFSMNT_RETERR)
1532 mp->m_flags |= XFS_MOUNT_RETERR;
1533 if (ap->flags & XFSMNT_NOALIGN)
1534 mp->m_flags |= XFS_MOUNT_NOALIGN;
1535 if (ap->flags & XFSMNT_SWALLOC)
1536 mp->m_flags |= XFS_MOUNT_SWALLOC;
1537 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1538 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1539 if (ap->flags & XFSMNT_32BITINODES)
1540 mp->m_flags |= XFS_MOUNT_32BITINODES;
1541
1542 if (ap->flags & XFSMNT_IOSIZE) {
1543 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1544 ap->iosizelog < XFS_MIN_IO_LOG) {
1545 cmn_err(CE_WARN,
1546 "XFS: invalid log iosize: %d [not %d-%d]",
1547 ap->iosizelog, XFS_MIN_IO_LOG,
1548 XFS_MAX_IO_LOG);
1549 return XFS_ERROR(EINVAL);
1550 }
1551
1552 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1553 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1554 }
1555
1556 if (ap->flags & XFSMNT_IKEEP)
1557 mp->m_flags |= XFS_MOUNT_IKEEP;
1558 if (ap->flags & XFSMNT_DIRSYNC)
1559 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1560 if (ap->flags & XFSMNT_ATTR2)
1561 mp->m_flags |= XFS_MOUNT_ATTR2;
1562 if (ap->flags & XFSMNT_NOATTR2)
1563 mp->m_flags |= XFS_MOUNT_NOATTR2;
1564
1565 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1566 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1567
1568 /*
1569 * no recovery flag requires a read-only mount
1570 */
1571 if (ap->flags & XFSMNT_NORECOVERY) {
1572 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1573 cmn_err(CE_WARN,
1574 "XFS: tried to mount a FS read-write without recovery!");
1575 return XFS_ERROR(EINVAL);
1576 }
1577 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1578 }
1579
1580 if (ap->flags & XFSMNT_NOUUID)
1581 mp->m_flags |= XFS_MOUNT_NOUUID;
1582 if (ap->flags & XFSMNT_BARRIER)
1583 mp->m_flags |= XFS_MOUNT_BARRIER;
1584 else
1585 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1586
1587 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1588 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1589
1590 if (ap->flags & XFSMNT_DMAPI)
1591 mp->m_flags |= XFS_MOUNT_DMAPI;
1592 return 0;
Christoph Hellwiga7381592008-08-13 16:04:05 +10001593
1594
1595 out_free_rtname:
1596 kfree(mp->m_rtname);
1597 out_free_fsname:
1598 kfree(mp->m_fsname);
1599 out:
1600 return error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001601}
1602
1603/*
1604 * This function fills in xfs_mount_t fields based on mount args.
1605 * Note: the superblock _has_ now been read in.
1606 */
1607STATIC int
1608xfs_finish_flags(
1609 struct xfs_mount_args *ap,
1610 struct xfs_mount *mp)
1611{
1612 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1613
1614 /* Fail a mount where the logbuf is smaller then the log stripe */
1615 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1616 if ((ap->logbufsize <= 0) &&
1617 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1618 mp->m_logbsize = mp->m_sb.sb_logsunit;
1619 } else if (ap->logbufsize > 0 &&
1620 ap->logbufsize < mp->m_sb.sb_logsunit) {
1621 cmn_err(CE_WARN,
1622 "XFS: logbuf size must be greater than or equal to log stripe size");
1623 return XFS_ERROR(EINVAL);
1624 }
1625 } else {
1626 /* Fail a mount if the logbuf is larger than 32K */
1627 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1628 cmn_err(CE_WARN,
1629 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1630 return XFS_ERROR(EINVAL);
1631 }
1632 }
1633
1634 /*
1635 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1636 * told by noattr2 to turn it off
1637 */
1638 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1639 !(ap->flags & XFSMNT_NOATTR2))
1640 mp->m_flags |= XFS_MOUNT_ATTR2;
1641
1642 /*
1643 * prohibit r/w mounts of read-only filesystems
1644 */
1645 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1646 cmn_err(CE_WARN,
1647 "XFS: cannot mount a read-only filesystem as read-write");
1648 return XFS_ERROR(EROFS);
1649 }
1650
1651 /*
1652 * check for shared mount.
1653 */
1654 if (ap->flags & XFSMNT_SHARED) {
1655 if (!xfs_sb_version_hasshared(&mp->m_sb))
1656 return XFS_ERROR(EINVAL);
1657
1658 /*
1659 * For IRIX 6.5, shared mounts must have the shared
1660 * version bit set, have the persistent readonly
1661 * field set, must be version 0 and can only be mounted
1662 * read-only.
1663 */
1664 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1665 (mp->m_sb.sb_shared_vn != 0))
1666 return XFS_ERROR(EINVAL);
1667
1668 mp->m_flags |= XFS_MOUNT_SHARED;
1669
1670 /*
1671 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1672 */
1673 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1674 return XFS_ERROR(EINVAL);
1675 }
1676
1677 if (ap->flags & XFSMNT_UQUOTA) {
1678 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1679 if (ap->flags & XFSMNT_UQUOTAENF)
1680 mp->m_qflags |= XFS_UQUOTA_ENFD;
1681 }
1682
1683 if (ap->flags & XFSMNT_GQUOTA) {
1684 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1685 if (ap->flags & XFSMNT_GQUOTAENF)
1686 mp->m_qflags |= XFS_OQUOTA_ENFD;
1687 } else if (ap->flags & XFSMNT_PQUOTA) {
1688 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1689 if (ap->flags & XFSMNT_PQUOTAENF)
1690 mp->m_qflags |= XFS_OQUOTA_ENFD;
1691 }
1692
1693 return 0;
1694}
1695
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001697xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 struct super_block *sb,
1699 void *data,
1700 int silent)
1701{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001702 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001703 struct xfs_mount *mp = NULL;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001704 struct xfs_mount_args *args;
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001705 int flags = 0, error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001707 args = xfs_args_allocate(sb, silent);
1708 if (!args)
1709 return -ENOMEM;
1710
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001711 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1712 if (!mp)
1713 goto out_free_args;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001715 spin_lock_init(&mp->m_sb_lock);
1716 mutex_init(&mp->m_ilock);
1717 mutex_init(&mp->m_growlock);
1718 atomic_set(&mp->m_active_trans, 0);
Christoph Hellwig74394492007-08-30 17:21:22 +10001719 INIT_LIST_HEAD(&mp->m_sync_list);
1720 spin_lock_init(&mp->m_sync_lock);
1721 init_waitqueue_head(&mp->m_wait_single_sync_task);
1722
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001723 mp->m_super = sb;
1724 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001726 if (sb->s_flags & MS_RDONLY)
1727 mp->m_flags |= XFS_MOUNT_RDONLY;
1728
Christoph Hellwig745f6912007-08-30 17:20:39 +10001729 error = xfs_parseargs(mp, (char *)data, args, 0);
1730 if (error)
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001731 goto out_free_mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
1733 sb_min_blocksize(sb, BBSIZE);
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001734 sb->s_xattr = xfs_xattr_handlers;
Nathan Scotta50cd262006-03-14 14:06:18 +11001735 sb->s_export_op = &xfs_export_operations;
Nathan Scotta50cd262006-03-14 14:06:18 +11001736 sb->s_qcop = &xfs_quotactl_operations;
1737 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001739 error = xfs_dmops_get(mp, args);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001740 if (error)
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001741 goto out_free_mp;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001742 error = xfs_qmops_get(mp, args);
1743 if (error)
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001744 goto out_put_dmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001745
1746 if (args->flags & XFSMNT_QUIET)
1747 flags |= XFS_MFSI_QUIET;
1748
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001749 error = xfs_open_devices(mp, args);
1750 if (error)
1751 goto out_put_qmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001752
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001753 if (xfs_icsb_init_counters(mp))
1754 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1755
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001756 /*
1757 * Setup flags based on mount(2) options and then the superblock
1758 */
1759 error = xfs_start_flags(args, mp);
1760 if (error)
Christoph Hellwiga7381592008-08-13 16:04:05 +10001761 goto out_free_fsname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001762 error = xfs_readsb(mp, flags);
1763 if (error)
Christoph Hellwiga7381592008-08-13 16:04:05 +10001764 goto out_free_fsname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001765 error = xfs_finish_flags(args, mp);
1766 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001767 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001768
Christoph Hellwige34b5622008-05-20 15:10:36 +10001769 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001770 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001771 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001772
1773 if (mp->m_flags & XFS_MOUNT_BARRIER)
1774 xfs_mountfs_check_barriers(mp);
1775
1776 error = xfs_filestream_mount(mp);
1777 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001778 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001779
Christoph Hellwig42490232008-08-13 16:49:32 +10001780 error = xfs_mountfs(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001781 if (error)
Christoph Hellwig120226c2008-05-20 15:11:11 +10001782 goto out_filestream_unmount;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001783
1784 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 sb->s_dirt = 1;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001787 sb->s_magic = XFS_SB_MAGIC;
1788 sb->s_blocksize = mp->m_sb.sb_blocksize;
1789 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1791 sb->s_time_gran = 1;
1792 set_posix_acl_flag(sb);
1793
David Chinner01651642008-08-13 15:45:15 +10001794 root = igrab(VFS_I(mp->m_rootip));
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001795 if (!root) {
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001796 error = ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 goto fail_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001798 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001799 if (is_bad_inode(root)) {
1800 error = EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 goto fail_vnrele;
1802 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001803 sb->s_root = d_alloc_root(root);
1804 if (!sb->s_root) {
1805 error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 goto fail_vnrele;
1807 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001808
1809 mp->m_sync_work.w_syncer = xfs_sync_worker;
1810 mp->m_sync_work.w_mount = mp;
1811 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1812 if (IS_ERR(mp->m_sync_task)) {
1813 error = -PTR_ERR(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 goto fail_vnrele;
Christoph Hellwig74394492007-08-30 17:21:22 +10001815 }
1816
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001817 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001819 kfree(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 return 0;
1821
Christoph Hellwig120226c2008-05-20 15:11:11 +10001822 out_filestream_unmount:
1823 xfs_filestream_unmount(mp);
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001824 out_free_sb:
1825 xfs_freesb(mp);
Christoph Hellwiga7381592008-08-13 16:04:05 +10001826 out_free_fsname:
1827 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001828 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001829 xfs_close_devices(mp);
1830 out_put_qmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001831 xfs_qmops_put(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001832 out_put_dmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001833 xfs_dmops_put(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001834 out_free_mp:
1835 kfree(mp);
1836 out_free_args:
1837 kfree(args);
1838 return -error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001839
1840 fail_vnrele:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 if (sb->s_root) {
1842 dput(sb->s_root);
1843 sb->s_root = NULL;
1844 } else {
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001845 iput(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 }
1847
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001848 fail_unmount:
Christoph Hellwige48ad312008-05-20 11:30:52 +10001849 /*
1850 * Blow away any referenced inode in the filestreams cache.
1851 * This can and will cause log traffic as inodes go inactive
1852 * here.
1853 */
1854 xfs_filestream_unmount(mp);
1855
1856 XFS_bflush(mp->m_ddev_targp);
1857 error = xfs_unmount_flush(mp, 0);
1858 WARN_ON(error);
1859
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001860 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001861 goto out_free_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862}
1863
David Howells454e2392006-06-23 02:02:57 -07001864STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001865xfs_fs_get_sb(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 struct file_system_type *fs_type,
1867 int flags,
1868 const char *dev_name,
David Howells454e2392006-06-23 02:02:57 -07001869 void *data,
1870 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871{
David Howells454e2392006-06-23 02:02:57 -07001872 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1873 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874}
1875
David Chinner7989cb82007-02-10 18:34:56 +11001876static struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001877 .alloc_inode = xfs_fs_alloc_inode,
1878 .destroy_inode = xfs_fs_destroy_inode,
1879 .write_inode = xfs_fs_write_inode,
1880 .clear_inode = xfs_fs_clear_inode,
1881 .put_super = xfs_fs_put_super,
1882 .write_super = xfs_fs_write_super,
1883 .sync_fs = xfs_fs_sync_super,
1884 .write_super_lockfs = xfs_fs_lockfs,
1885 .statfs = xfs_fs_statfs,
1886 .remount_fs = xfs_fs_remount,
1887 .show_options = xfs_fs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888};
1889
David Chinner7989cb82007-02-10 18:34:56 +11001890static struct quotactl_ops xfs_quotactl_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001891 .quota_sync = xfs_fs_quotasync,
1892 .get_xstate = xfs_fs_getxstate,
1893 .set_xstate = xfs_fs_setxstate,
1894 .get_xquota = xfs_fs_getxquota,
1895 .set_xquota = xfs_fs_setxquota,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896};
1897
Andrew Morton5085b602007-02-20 13:57:47 -08001898static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 .owner = THIS_MODULE,
1900 .name = "xfs",
Nathan Scotta50cd262006-03-14 14:06:18 +11001901 .get_sb = xfs_fs_get_sb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 .kill_sb = kill_block_super,
1903 .fs_flags = FS_REQUIRES_DEV,
1904};
1905
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001906STATIC int __init
1907xfs_alloc_trace_bufs(void)
1908{
1909#ifdef XFS_ALLOC_TRACE
1910 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1911 if (!xfs_alloc_trace_buf)
1912 goto out;
1913#endif
1914#ifdef XFS_BMAP_TRACE
1915 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1916 if (!xfs_bmap_trace_buf)
1917 goto out_free_alloc_trace;
1918#endif
1919#ifdef XFS_BMBT_TRACE
1920 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1921 if (!xfs_bmbt_trace_buf)
1922 goto out_free_bmap_trace;
1923#endif
1924#ifdef XFS_ATTR_TRACE
1925 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1926 if (!xfs_attr_trace_buf)
1927 goto out_free_bmbt_trace;
1928#endif
1929#ifdef XFS_DIR2_TRACE
1930 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1931 if (!xfs_dir2_trace_buf)
1932 goto out_free_attr_trace;
1933#endif
1934
1935 return 0;
1936
1937#ifdef XFS_DIR2_TRACE
1938 out_free_attr_trace:
1939#endif
1940#ifdef XFS_ATTR_TRACE
1941 ktrace_free(xfs_attr_trace_buf);
1942 out_free_bmbt_trace:
1943#endif
1944#ifdef XFS_BMBT_TRACE
1945 ktrace_free(xfs_bmbt_trace_buf);
1946 out_free_bmap_trace:
1947#endif
1948#ifdef XFS_BMAP_TRACE
1949 ktrace_free(xfs_bmap_trace_buf);
1950 out_free_alloc_trace:
1951#endif
1952#ifdef XFS_ALLOC_TRACE
1953 ktrace_free(xfs_alloc_trace_buf);
1954 out:
1955#endif
1956 return -ENOMEM;
1957}
1958
1959STATIC void
1960xfs_free_trace_bufs(void)
1961{
1962#ifdef XFS_DIR2_TRACE
1963 ktrace_free(xfs_dir2_trace_buf);
1964#endif
1965#ifdef XFS_ATTR_TRACE
1966 ktrace_free(xfs_attr_trace_buf);
1967#endif
1968#ifdef XFS_BMBT_TRACE
1969 ktrace_free(xfs_bmbt_trace_buf);
1970#endif
1971#ifdef XFS_BMAP_TRACE
1972 ktrace_free(xfs_bmap_trace_buf);
1973#endif
1974#ifdef XFS_ALLOC_TRACE
1975 ktrace_free(xfs_alloc_trace_buf);
1976#endif
1977}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
1979STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001980xfs_init_zones(void)
1981{
Christoph Hellwig5ec7f8c2008-08-13 16:22:40 +10001982 xfs_vnode_zone = kmem_zone_init_flags(sizeof(struct inode), "xfs_vnode",
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001983 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
1984 KM_ZONE_SPREAD,
1985 xfs_fs_inode_init_once);
1986 if (!xfs_vnode_zone)
1987 goto out;
1988
1989 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1990 if (!xfs_ioend_zone)
1991 goto out_destroy_vnode_zone;
1992
1993 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1994 xfs_ioend_zone);
1995 if (!xfs_ioend_pool)
1996 goto out_destroy_ioend_zone;
1997
1998 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1999 "xfs_log_ticket");
2000 if (!xfs_log_ticket_zone)
2001 goto out_destroy_ioend_pool;
2002
2003 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
2004 "xfs_bmap_free_item");
2005 if (!xfs_bmap_free_item_zone)
2006 goto out_destroy_log_ticket_zone;
2007 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
2008 "xfs_btree_cur");
2009 if (!xfs_btree_cur_zone)
2010 goto out_destroy_bmap_free_item_zone;
2011
2012 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
2013 "xfs_da_state");
2014 if (!xfs_da_state_zone)
2015 goto out_destroy_btree_cur_zone;
2016
2017 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
2018 if (!xfs_dabuf_zone)
2019 goto out_destroy_da_state_zone;
2020
2021 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
2022 if (!xfs_ifork_zone)
2023 goto out_destroy_dabuf_zone;
2024
2025 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
2026 if (!xfs_trans_zone)
2027 goto out_destroy_ifork_zone;
2028
2029 /*
2030 * The size of the zone allocated buf log item is the maximum
2031 * size possible under XFS. This wastes a little bit of memory,
2032 * but it is much faster.
2033 */
2034 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
2035 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
2036 NBWORD) * sizeof(int))), "xfs_buf_item");
2037 if (!xfs_buf_item_zone)
2038 goto out_destroy_trans_zone;
2039
2040 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
2041 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
2042 sizeof(xfs_extent_t))), "xfs_efd_item");
2043 if (!xfs_efd_zone)
2044 goto out_destroy_buf_item_zone;
2045
2046 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
2047 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
2048 sizeof(xfs_extent_t))), "xfs_efi_item");
2049 if (!xfs_efi_zone)
2050 goto out_destroy_efd_zone;
2051
2052 xfs_inode_zone =
2053 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
2054 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
David Chinner07c8f672008-10-30 16:11:59 +11002055 KM_ZONE_SPREAD, xfs_inode_init_once);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002056 if (!xfs_inode_zone)
2057 goto out_destroy_efi_zone;
2058
2059 xfs_ili_zone =
2060 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
2061 KM_ZONE_SPREAD, NULL);
2062 if (!xfs_ili_zone)
2063 goto out_destroy_inode_zone;
2064
2065#ifdef CONFIG_XFS_POSIX_ACL
2066 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
2067 if (!xfs_acl_zone)
2068 goto out_destroy_ili_zone;
2069#endif
2070
2071 return 0;
2072
2073#ifdef CONFIG_XFS_POSIX_ACL
2074 out_destroy_ili_zone:
2075#endif
2076 kmem_zone_destroy(xfs_ili_zone);
2077 out_destroy_inode_zone:
2078 kmem_zone_destroy(xfs_inode_zone);
2079 out_destroy_efi_zone:
2080 kmem_zone_destroy(xfs_efi_zone);
2081 out_destroy_efd_zone:
2082 kmem_zone_destroy(xfs_efd_zone);
2083 out_destroy_buf_item_zone:
2084 kmem_zone_destroy(xfs_buf_item_zone);
2085 out_destroy_trans_zone:
2086 kmem_zone_destroy(xfs_trans_zone);
2087 out_destroy_ifork_zone:
2088 kmem_zone_destroy(xfs_ifork_zone);
2089 out_destroy_dabuf_zone:
2090 kmem_zone_destroy(xfs_dabuf_zone);
2091 out_destroy_da_state_zone:
2092 kmem_zone_destroy(xfs_da_state_zone);
2093 out_destroy_btree_cur_zone:
2094 kmem_zone_destroy(xfs_btree_cur_zone);
2095 out_destroy_bmap_free_item_zone:
2096 kmem_zone_destroy(xfs_bmap_free_item_zone);
2097 out_destroy_log_ticket_zone:
2098 kmem_zone_destroy(xfs_log_ticket_zone);
2099 out_destroy_ioend_pool:
2100 mempool_destroy(xfs_ioend_pool);
2101 out_destroy_ioend_zone:
2102 kmem_zone_destroy(xfs_ioend_zone);
2103 out_destroy_vnode_zone:
2104 kmem_zone_destroy(xfs_vnode_zone);
2105 out:
2106 return -ENOMEM;
2107}
2108
2109STATIC void
2110xfs_destroy_zones(void)
2111{
2112#ifdef CONFIG_XFS_POSIX_ACL
2113 kmem_zone_destroy(xfs_acl_zone);
2114#endif
2115 kmem_zone_destroy(xfs_ili_zone);
2116 kmem_zone_destroy(xfs_inode_zone);
2117 kmem_zone_destroy(xfs_efi_zone);
2118 kmem_zone_destroy(xfs_efd_zone);
2119 kmem_zone_destroy(xfs_buf_item_zone);
2120 kmem_zone_destroy(xfs_trans_zone);
2121 kmem_zone_destroy(xfs_ifork_zone);
2122 kmem_zone_destroy(xfs_dabuf_zone);
2123 kmem_zone_destroy(xfs_da_state_zone);
2124 kmem_zone_destroy(xfs_btree_cur_zone);
2125 kmem_zone_destroy(xfs_bmap_free_item_zone);
2126 kmem_zone_destroy(xfs_log_ticket_zone);
2127 mempool_destroy(xfs_ioend_pool);
2128 kmem_zone_destroy(xfs_ioend_zone);
2129 kmem_zone_destroy(xfs_vnode_zone);
2130
2131}
2132
2133STATIC int __init
2134init_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135{
2136 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 static char message[] __initdata = KERN_INFO \
2138 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
2139
2140 printk(message);
2141
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 ktrace_init(64);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002143 vn_init();
2144 xfs_dir_startup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
Nathan Scott87582802006-03-14 13:18:19 +11002146 error = xfs_init_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002147 if (error)
2148 goto out;
2149
2150 error = xfs_alloc_trace_bufs();
2151 if (error)
2152 goto out_destroy_zones;
2153
2154 error = xfs_mru_cache_init();
2155 if (error)
2156 goto out_free_trace_buffers;
2157
2158 error = xfs_filestream_init();
2159 if (error)
2160 goto out_mru_cache_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
Nathan Scottce8e9222006-01-11 15:39:08 +11002162 error = xfs_buf_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002163 if (error)
2164 goto out_filestream_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002166 error = xfs_init_procfs();
2167 if (error)
2168 goto out_buf_terminate;
2169
2170 error = xfs_sysctl_register();
2171 if (error)
2172 goto out_cleanup_procfs;
2173
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 vfs_initquota();
2175
2176 error = register_filesystem(&xfs_fs_type);
2177 if (error)
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002178 goto out_sysctl_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 return 0;
2180
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002181 out_sysctl_unregister:
2182 xfs_sysctl_unregister();
2183 out_cleanup_procfs:
2184 xfs_cleanup_procfs();
2185 out_buf_terminate:
Nathan Scottce8e9222006-01-11 15:39:08 +11002186 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002187 out_filestream_uninit:
2188 xfs_filestream_uninit();
2189 out_mru_cache_uninit:
2190 xfs_mru_cache_uninit();
2191 out_free_trace_buffers:
2192 xfs_free_trace_bufs();
2193 out_destroy_zones:
Nathan Scott87582802006-03-14 13:18:19 +11002194 xfs_destroy_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002195 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 return error;
2197}
2198
2199STATIC void __exit
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002200exit_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201{
2202 vfs_exitquota();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 unregister_filesystem(&xfs_fs_type);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002204 xfs_sysctl_unregister();
2205 xfs_cleanup_procfs();
Nathan Scottce8e9222006-01-11 15:39:08 +11002206 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002207 xfs_filestream_uninit();
2208 xfs_mru_cache_uninit();
2209 xfs_free_trace_bufs();
Nathan Scott87582802006-03-14 13:18:19 +11002210 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 ktrace_uninit();
2212}
2213
2214module_init(init_xfs_fs);
2215module_exit(exit_xfs_fs);
2216
2217MODULE_AUTHOR("Silicon Graphics, Inc.");
2218MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2219MODULE_LICENSE("GPL");