blob: 7c621dfee73d907de901e9a28e9c24fcfa444ee5 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
David Chinner7989cb82007-02-10 18:34:56 +110070static struct quotactl_ops xfs_quotactl_operations;
71static struct super_operations xfs_super_operations;
72static kmem_zone_t *xfs_vnode_zone;
73static kmem_zone_t *xfs_ioend_zone;
Christoph Hellwig0829c362005-09-02 16:58:49 +100074mempool_t *xfs_ioend_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76STATIC struct xfs_mount_args *
77xfs_args_allocate(
Nathan Scott764d1f82006-03-31 13:04:17 +100078 struct super_block *sb,
79 int silent)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 struct xfs_mount_args *args;
82
Christoph Hellwigbdd907b2008-05-20 15:10:44 +100083 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
84 if (!args)
85 return NULL;
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 args->logbufs = args->logbufsize = -1;
88 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
89
90 /* Copy the already-parsed mount(2) flags we're interested in */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 if (sb->s_flags & MS_DIRSYNC)
92 args->flags |= XFSMNT_DIRSYNC;
93 if (sb->s_flags & MS_SYNCHRONOUS)
94 args->flags |= XFSMNT_WSYNC;
Nathan Scott764d1f82006-03-31 13:04:17 +100095 if (silent)
96 args->flags |= XFSMNT_QUIET;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 args->flags |= XFSMNT_32BITINODES;
98
99 return args;
100}
101
David Chinnera67d7c52007-11-23 16:29:32 +1100102#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
103#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
104#define MNTOPT_LOGDEV "logdev" /* log device */
105#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
106#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
107#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
108#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
109#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
110#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
111#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
112#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
113#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
114#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
115#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
116#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
117#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
118#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
119#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
120#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
121#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
122 * unwritten extent conversion */
123#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
124#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
125#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
126#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
127#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
128#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
129#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
130 * in stat(). */
131#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
132#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
133#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
134#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
135#define MNTOPT_NOQUOTA "noquota" /* no quotas */
136#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
137#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
138#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
139#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
140#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
141#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
142#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
143#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
144#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
145#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
146#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
147#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
148#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
149
150STATIC unsigned long
151suffix_strtoul(char *s, char **endp, unsigned int base)
152{
153 int last, shift_left_factor = 0;
154 char *value = s;
155
156 last = strlen(value) - 1;
157 if (value[last] == 'K' || value[last] == 'k') {
158 shift_left_factor = 10;
159 value[last] = '\0';
160 }
161 if (value[last] == 'M' || value[last] == 'm') {
162 shift_left_factor = 20;
163 value[last] = '\0';
164 }
165 if (value[last] == 'G' || value[last] == 'g') {
166 shift_left_factor = 30;
167 value[last] = '\0';
168 }
169
170 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
171}
172
173STATIC int
174xfs_parseargs(
175 struct xfs_mount *mp,
176 char *options,
177 struct xfs_mount_args *args,
178 int update)
179{
180 char *this_char, *value, *eov;
181 int dsunit, dswidth, vol_dsunit, vol_dswidth;
182 int iosize;
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100183 int dmapi_implies_ikeep = 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100184
185 args->flags |= XFSMNT_BARRIER;
186 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
187
188 if (!options)
189 goto done;
190
191 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
192
193 while ((this_char = strsep(&options, ",")) != NULL) {
194 if (!*this_char)
195 continue;
196 if ((value = strchr(this_char, '=')) != NULL)
197 *value++ = 0;
198
199 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
200 if (!value || !*value) {
201 cmn_err(CE_WARN,
202 "XFS: %s option requires an argument",
203 this_char);
204 return EINVAL;
205 }
206 args->logbufs = simple_strtoul(value, &eov, 10);
207 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
208 if (!value || !*value) {
209 cmn_err(CE_WARN,
210 "XFS: %s option requires an argument",
211 this_char);
212 return EINVAL;
213 }
214 args->logbufsize = suffix_strtoul(value, &eov, 10);
215 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
216 if (!value || !*value) {
217 cmn_err(CE_WARN,
218 "XFS: %s option requires an argument",
219 this_char);
220 return EINVAL;
221 }
222 strncpy(args->logname, value, MAXNAMELEN);
223 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
224 if (!value || !*value) {
225 cmn_err(CE_WARN,
226 "XFS: %s option requires an argument",
227 this_char);
228 return EINVAL;
229 }
230 strncpy(args->mtpt, value, MAXNAMELEN);
231 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
232 if (!value || !*value) {
233 cmn_err(CE_WARN,
234 "XFS: %s option requires an argument",
235 this_char);
236 return EINVAL;
237 }
238 strncpy(args->rtname, value, MAXNAMELEN);
239 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
240 if (!value || !*value) {
241 cmn_err(CE_WARN,
242 "XFS: %s option requires an argument",
243 this_char);
244 return EINVAL;
245 }
246 iosize = simple_strtoul(value, &eov, 10);
247 args->flags |= XFSMNT_IOSIZE;
248 args->iosizelog = (uint8_t) iosize;
249 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
250 if (!value || !*value) {
251 cmn_err(CE_WARN,
252 "XFS: %s option requires an argument",
253 this_char);
254 return EINVAL;
255 }
256 iosize = suffix_strtoul(value, &eov, 10);
257 args->flags |= XFSMNT_IOSIZE;
258 args->iosizelog = ffs(iosize) - 1;
259 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
260 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
261 mp->m_flags |= XFS_MOUNT_GRPID;
262 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
263 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
264 mp->m_flags &= ~XFS_MOUNT_GRPID;
265 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
266 args->flags |= XFSMNT_WSYNC;
267 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
268 args->flags |= XFSMNT_OSYNCISOSYNC;
269 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
270 args->flags |= XFSMNT_NORECOVERY;
271 } else if (!strcmp(this_char, MNTOPT_INO64)) {
272 args->flags |= XFSMNT_INO64;
273#if !XFS_BIG_INUMS
274 cmn_err(CE_WARN,
275 "XFS: %s option not allowed on this system",
276 this_char);
277 return EINVAL;
278#endif
279 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
280 args->flags |= XFSMNT_NOALIGN;
281 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
282 args->flags |= XFSMNT_SWALLOC;
283 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
284 if (!value || !*value) {
285 cmn_err(CE_WARN,
286 "XFS: %s option requires an argument",
287 this_char);
288 return EINVAL;
289 }
290 dsunit = simple_strtoul(value, &eov, 10);
291 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
292 if (!value || !*value) {
293 cmn_err(CE_WARN,
294 "XFS: %s option requires an argument",
295 this_char);
296 return EINVAL;
297 }
298 dswidth = simple_strtoul(value, &eov, 10);
299 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
300 args->flags &= ~XFSMNT_32BITINODES;
301#if !XFS_BIG_INUMS
302 cmn_err(CE_WARN,
303 "XFS: %s option not allowed on this system",
304 this_char);
305 return EINVAL;
306#endif
307 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
308 args->flags |= XFSMNT_NOUUID;
309 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
310 args->flags |= XFSMNT_BARRIER;
311 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
312 args->flags &= ~XFSMNT_BARRIER;
313 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100314 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100315 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100316 dmapi_implies_ikeep = 0;
317 args->flags &= ~XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100318 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
319 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
320 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
321 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
322 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
323 args->flags |= XFSMNT_ATTR2;
324 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
325 args->flags &= ~XFSMNT_ATTR2;
Tim Shimmin7c12f292008-04-30 18:15:28 +1000326 args->flags |= XFSMNT_NOATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100327 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
328 args->flags2 |= XFSMNT2_FILESTREAMS;
329 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
330 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
331 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
332 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
333 !strcmp(this_char, MNTOPT_UQUOTA) ||
334 !strcmp(this_char, MNTOPT_USRQUOTA)) {
335 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
336 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
337 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
338 args->flags |= XFSMNT_UQUOTA;
339 args->flags &= ~XFSMNT_UQUOTAENF;
340 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
341 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
342 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
343 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
344 args->flags |= XFSMNT_PQUOTA;
345 args->flags &= ~XFSMNT_PQUOTAENF;
346 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
347 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
348 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
349 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
350 args->flags |= XFSMNT_GQUOTA;
351 args->flags &= ~XFSMNT_GQUOTAENF;
352 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
353 args->flags |= XFSMNT_DMAPI;
354 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
355 args->flags |= XFSMNT_DMAPI;
356 } else if (!strcmp(this_char, MNTOPT_DMI)) {
357 args->flags |= XFSMNT_DMAPI;
358 } else if (!strcmp(this_char, "ihashsize")) {
359 cmn_err(CE_WARN,
360 "XFS: ihashsize no longer used, option is deprecated.");
361 } else if (!strcmp(this_char, "osyncisdsync")) {
362 /* no-op, this is now the default */
363 cmn_err(CE_WARN,
364 "XFS: osyncisdsync is now the default, option is deprecated.");
365 } else if (!strcmp(this_char, "irixsgid")) {
366 cmn_err(CE_WARN,
367 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
368 } else {
369 cmn_err(CE_WARN,
370 "XFS: unknown mount option [%s].", this_char);
371 return EINVAL;
372 }
373 }
374
375 if (args->flags & XFSMNT_NORECOVERY) {
376 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
377 cmn_err(CE_WARN,
378 "XFS: no-recovery mounts must be read-only.");
379 return EINVAL;
380 }
381 }
382
383 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
384 cmn_err(CE_WARN,
385 "XFS: sunit and swidth options incompatible with the noalign option");
386 return EINVAL;
387 }
388
389 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
390 cmn_err(CE_WARN,
391 "XFS: cannot mount with both project and group quota");
392 return EINVAL;
393 }
394
395 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
396 printk("XFS: %s option needs the mount point option as well\n",
397 MNTOPT_DMAPI);
398 return EINVAL;
399 }
400
401 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
402 cmn_err(CE_WARN,
403 "XFS: sunit and swidth must be specified together");
404 return EINVAL;
405 }
406
407 if (dsunit && (dswidth % dsunit != 0)) {
408 cmn_err(CE_WARN,
409 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
410 dswidth, dsunit);
411 return EINVAL;
412 }
413
414 /*
415 * Applications using DMI filesystems often expect the
416 * inode generation number to be monotonically increasing.
417 * If we delete inode chunks we break this assumption, so
418 * keep unused inode chunks on disk for DMI filesystems
419 * until we come up with a better solution.
420 * Note that if "ikeep" or "noikeep" mount options are
421 * supplied, then they are honored.
422 */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100423 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
424 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100425
426 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
427 if (dsunit) {
428 args->sunit = dsunit;
429 args->flags |= XFSMNT_RETERR;
430 } else {
431 args->sunit = vol_dsunit;
432 }
433 dswidth ? (args->swidth = dswidth) :
434 (args->swidth = vol_dswidth);
435 } else {
436 args->sunit = args->swidth = 0;
437 }
438
439done:
440 if (args->flags & XFSMNT_32BITINODES)
441 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
442 if (args->flags2)
443 args->flags |= XFSMNT_FLAGS2;
444 return 0;
445}
446
447struct proc_xfs_info {
448 int flag;
449 char *str;
450};
451
452STATIC int
453xfs_showargs(
454 struct xfs_mount *mp,
455 struct seq_file *m)
456{
457 static struct proc_xfs_info xfs_info_set[] = {
458 /* the few simple ones we can get from the mount struct */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100459 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
David Chinnera67d7c52007-11-23 16:29:32 +1100460 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
461 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
462 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
463 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
464 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
465 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
466 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
467 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
468 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
469 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
470 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
471 { 0, NULL }
472 };
473 static struct proc_xfs_info xfs_info_unset[] = {
474 /* the few simple ones we can get from the mount struct */
David Chinnera67d7c52007-11-23 16:29:32 +1100475 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
476 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
477 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
478 { 0, NULL }
479 };
480 struct proc_xfs_info *xfs_infop;
481
482 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
483 if (mp->m_flags & xfs_infop->flag)
484 seq_puts(m, xfs_infop->str);
485 }
486 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
487 if (!(mp->m_flags & xfs_infop->flag))
488 seq_puts(m, xfs_infop->str);
489 }
490
491 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
492 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
493 (int)(1 << mp->m_writeio_log) >> 10);
494
495 if (mp->m_logbufs > 0)
496 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
497 if (mp->m_logbsize > 0)
498 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
499
500 if (mp->m_logname)
501 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
502 if (mp->m_rtname)
503 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
504
505 if (mp->m_dalign > 0)
506 seq_printf(m, "," MNTOPT_SUNIT "=%d",
507 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
508 if (mp->m_swidth > 0)
509 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
510 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
511
512 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
513 seq_puts(m, "," MNTOPT_USRQUOTA);
514 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
515 seq_puts(m, "," MNTOPT_UQUOTANOENF);
516
517 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
518 seq_puts(m, "," MNTOPT_PRJQUOTA);
519 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
520 seq_puts(m, "," MNTOPT_PQUOTANOENF);
521
522 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
523 seq_puts(m, "," MNTOPT_GRPQUOTA);
524 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
525 seq_puts(m, "," MNTOPT_GQUOTANOENF);
526
527 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
528 seq_puts(m, "," MNTOPT_NOQUOTA);
529
530 return 0;
531}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532__uint64_t
533xfs_max_file_offset(
534 unsigned int blockshift)
535{
536 unsigned int pagefactor = 1;
537 unsigned int bitshift = BITS_PER_LONG - 1;
538
539 /* Figure out maximum filesize, on Linux this can depend on
540 * the filesystem blocksize (on 32 bit platforms).
541 * __block_prepare_write does this in an [unsigned] long...
542 * page->index << (PAGE_CACHE_SHIFT - bbits)
543 * So, for page sized blocks (4K on 32 bit platforms),
544 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
545 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
546 * but for smaller blocksizes it is less (bbits = log2 bsize).
547 * Note1: get_block_t takes a long (implicit cast from above)
548 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
549 * can optionally convert the [unsigned] long from above into
550 * an [unsigned] long long.
551 */
552
553#if BITS_PER_LONG == 32
554# if defined(CONFIG_LBD)
555 ASSERT(sizeof(sector_t) == 8);
556 pagefactor = PAGE_CACHE_SIZE;
557 bitshift = BITS_PER_LONG;
558# else
559 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
560# endif
561#endif
562
563 return (((__uint64_t)pagefactor) << bitshift) - 1;
564}
565
David Chinner7989cb82007-02-10 18:34:56 +1100566STATIC_INLINE void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567xfs_set_inodeops(
568 struct inode *inode)
569{
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000570 switch (inode->i_mode & S_IFMT) {
571 case S_IFREG:
Nathan Scott416c6d52006-03-14 14:00:51 +1100572 inode->i_op = &xfs_inode_operations;
Nathan Scott3562fd42006-03-14 14:00:35 +1100573 inode->i_fop = &xfs_file_operations;
Nathan Scotte4c573b2006-03-14 13:54:26 +1100574 inode->i_mapping->a_ops = &xfs_address_space_operations;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000575 break;
576 case S_IFDIR:
Barry Naujok189f4bf2008-05-21 16:58:55 +1000577 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
578 inode->i_op = &xfs_dir_ci_inode_operations;
579 else
580 inode->i_op = &xfs_dir_inode_operations;
Nathan Scott3562fd42006-03-14 14:00:35 +1100581 inode->i_fop = &xfs_dir_file_operations;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000582 break;
583 case S_IFLNK:
Nathan Scott416c6d52006-03-14 14:00:51 +1100584 inode->i_op = &xfs_symlink_inode_operations;
Christoph Hellwig222096a2008-02-05 12:13:46 +1100585 if (!(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE))
Nathan Scotte4c573b2006-03-14 13:54:26 +1100586 inode->i_mapping->a_ops = &xfs_address_space_operations;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000587 break;
588 default:
Nathan Scott416c6d52006-03-14 14:00:51 +1100589 inode->i_op = &xfs_inode_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 init_special_inode(inode, inode->i_mode, inode->i_rdev);
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000591 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
593}
594
David Chinner7989cb82007-02-10 18:34:56 +1100595STATIC_INLINE void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596xfs_revalidate_inode(
597 xfs_mount_t *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000598 bhv_vnode_t *vp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 xfs_inode_t *ip)
600{
Nathan Scottec86dc02006-03-17 17:25:36 +1100601 struct inode *inode = vn_to_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000603 inode->i_mode = ip->i_d.di_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 inode->i_nlink = ip->i_d.di_nlink;
605 inode->i_uid = ip->i_d.di_uid;
606 inode->i_gid = ip->i_d.di_gid;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000607
608 switch (inode->i_mode & S_IFMT) {
609 case S_IFBLK:
610 case S_IFCHR:
611 inode->i_rdev =
612 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
613 sysv_minor(ip->i_df.if_u2.if_rdev));
614 break;
615 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 inode->i_rdev = 0;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000617 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 }
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 inode->i_generation = ip->i_d.di_gen;
621 i_size_write(inode, ip->i_d.di_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
623 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
624 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
625 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
626 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
627 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
628 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
629 inode->i_flags |= S_IMMUTABLE;
630 else
631 inode->i_flags &= ~S_IMMUTABLE;
632 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
633 inode->i_flags |= S_APPEND;
634 else
635 inode->i_flags &= ~S_APPEND;
636 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
637 inode->i_flags |= S_SYNC;
638 else
639 inode->i_flags &= ~S_SYNC;
640 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
641 inode->i_flags |= S_NOATIME;
642 else
643 inode->i_flags &= ~S_NOATIME;
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +1000644 xfs_iflags_clear(ip, XFS_IMODIFIED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645}
646
647void
648xfs_initialize_vnode(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000649 struct xfs_mount *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000650 bhv_vnode_t *vp,
Christoph Hellwig745f6912007-08-30 17:20:39 +1000651 struct xfs_inode *ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Nathan Scottec86dc02006-03-17 17:25:36 +1100653 struct inode *inode = vn_to_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000655 if (!ip->i_vnode) {
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000656 ip->i_vnode = vp;
657 inode->i_private = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
659
660 /*
661 * We need to set the ops vectors, and unlock the inode, but if
662 * we have been called during the new inode create process, it is
663 * too early to fill in the Linux inode. We will get called a
664 * second time once the inode is properly set up, and then we can
665 * finish our work.
666 */
Christoph Hellwig745f6912007-08-30 17:20:39 +1000667 if (ip->i_d.di_mode != 0 && (inode->i_state & I_NEW)) {
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000668 xfs_revalidate_inode(mp, vp, ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 xfs_set_inodeops(inode);
Nathan Scottec86dc02006-03-17 17:25:36 +1100670
David Chinner7a18c382006-11-11 18:04:54 +1100671 xfs_iflags_clear(ip, XFS_INEW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 barrier();
673
674 unlock_new_inode(inode);
675 }
676}
677
678int
679xfs_blkdev_get(
680 xfs_mount_t *mp,
681 const char *name,
682 struct block_device **bdevp)
683{
684 int error = 0;
685
686 *bdevp = open_bdev_excl(name, 0, mp);
687 if (IS_ERR(*bdevp)) {
688 error = PTR_ERR(*bdevp);
689 printk("XFS: Invalid device [%s], error=%d\n", name, error);
690 }
691
692 return -error;
693}
694
695void
696xfs_blkdev_put(
697 struct block_device *bdev)
698{
699 if (bdev)
700 close_bdev_excl(bdev);
701}
702
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100703/*
704 * Try to write out the superblock using barriers.
705 */
706STATIC int
707xfs_barrier_test(
708 xfs_mount_t *mp)
709{
710 xfs_buf_t *sbp = xfs_getsb(mp, 0);
711 int error;
712
713 XFS_BUF_UNDONE(sbp);
714 XFS_BUF_UNREAD(sbp);
715 XFS_BUF_UNDELAYWRITE(sbp);
716 XFS_BUF_WRITE(sbp);
717 XFS_BUF_UNASYNC(sbp);
718 XFS_BUF_ORDERED(sbp);
719
720 xfsbdstrat(mp, sbp);
721 error = xfs_iowait(sbp);
722
723 /*
724 * Clear all the flags we set and possible error state in the
725 * buffer. We only did the write to try out whether barriers
726 * worked and shouldn't leave any traces in the superblock
727 * buffer.
728 */
729 XFS_BUF_DONE(sbp);
730 XFS_BUF_ERROR(sbp, 0);
731 XFS_BUF_UNORDERED(sbp);
732
733 xfs_buf_relse(sbp);
734 return error;
735}
736
737void
738xfs_mountfs_check_barriers(xfs_mount_t *mp)
739{
740 int error;
741
742 if (mp->m_logdev_targp != mp->m_ddev_targp) {
743 xfs_fs_cmn_err(CE_NOTE, mp,
744 "Disabling barriers, not supported with external log device");
745 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100746 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100747 }
748
Nathan Scottce8e9222006-01-11 15:39:08 +1100749 if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100750 QUEUE_ORDERED_NONE) {
751 xfs_fs_cmn_err(CE_NOTE, mp,
752 "Disabling barriers, not supported by the underlying device");
753 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100754 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100755 }
756
Nathan Scottb2ea4012006-07-28 17:05:13 +1000757 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
758 xfs_fs_cmn_err(CE_NOTE, mp,
759 "Disabling barriers, underlying device is readonly");
760 mp->m_flags &= ~XFS_MOUNT_BARRIER;
761 return;
762 }
763
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100764 error = xfs_barrier_test(mp);
765 if (error) {
766 xfs_fs_cmn_err(CE_NOTE, mp,
767 "Disabling barriers, trial barrier write failed");
768 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100769 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100770 }
771}
772
773void
774xfs_blkdev_issue_flush(
775 xfs_buftarg_t *buftarg)
776{
Nathan Scottce8e9222006-01-11 15:39:08 +1100777 blkdev_issue_flush(buftarg->bt_bdev, NULL);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100778}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000780STATIC void
781xfs_close_devices(
782 struct xfs_mount *mp)
783{
784 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
785 xfs_free_buftarg(mp->m_logdev_targp);
786 xfs_blkdev_put(mp->m_logdev_targp->bt_bdev);
787 }
788 if (mp->m_rtdev_targp) {
789 xfs_free_buftarg(mp->m_rtdev_targp);
790 xfs_blkdev_put(mp->m_rtdev_targp->bt_bdev);
791 }
792 xfs_free_buftarg(mp->m_ddev_targp);
793}
794
795/*
796 * The file system configurations are:
797 * (1) device (partition) with data and internal log
798 * (2) logical volume with data and log subvolumes.
799 * (3) logical volume with data, log, and realtime subvolumes.
800 *
801 * We only have to handle opening the log and realtime volumes here if
802 * they are present. The data subvolume has already been opened by
803 * get_sb_bdev() and is stored in sb->s_bdev.
804 */
805STATIC int
806xfs_open_devices(
807 struct xfs_mount *mp,
808 struct xfs_mount_args *args)
809{
810 struct block_device *ddev = mp->m_super->s_bdev;
811 struct block_device *logdev = NULL, *rtdev = NULL;
812 int error;
813
814 /*
815 * Open real time and log devices - order is important.
816 */
817 if (args->logname[0]) {
818 error = xfs_blkdev_get(mp, args->logname, &logdev);
819 if (error)
820 goto out;
821 }
822
823 if (args->rtname[0]) {
824 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
825 if (error)
826 goto out_close_logdev;
827
828 if (rtdev == ddev || rtdev == logdev) {
829 cmn_err(CE_WARN,
830 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
831 error = EINVAL;
832 goto out_close_rtdev;
833 }
834 }
835
836 /*
837 * Setup xfs_mount buffer target pointers
838 */
839 error = ENOMEM;
840 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
841 if (!mp->m_ddev_targp)
842 goto out_close_rtdev;
843
844 if (rtdev) {
845 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
846 if (!mp->m_rtdev_targp)
847 goto out_free_ddev_targ;
848 }
849
850 if (logdev && logdev != ddev) {
851 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
852 if (!mp->m_logdev_targp)
853 goto out_free_rtdev_targ;
854 } else {
855 mp->m_logdev_targp = mp->m_ddev_targp;
856 }
857
858 return 0;
859
860 out_free_rtdev_targ:
861 if (mp->m_rtdev_targp)
862 xfs_free_buftarg(mp->m_rtdev_targp);
863 out_free_ddev_targ:
864 xfs_free_buftarg(mp->m_ddev_targp);
865 out_close_rtdev:
866 if (rtdev)
867 xfs_blkdev_put(rtdev);
868 out_close_logdev:
869 if (logdev && logdev != ddev)
870 xfs_blkdev_put(logdev);
871 out:
872 return error;
873}
874
Christoph Hellwige34b5622008-05-20 15:10:36 +1000875/*
876 * Setup xfs_mount buffer target pointers based on superblock
877 */
878STATIC int
879xfs_setup_devices(
880 struct xfs_mount *mp)
881{
882 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000883
Christoph Hellwige34b5622008-05-20 15:10:36 +1000884 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
885 mp->m_sb.sb_sectsize);
886 if (error)
887 return error;
888
889 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
890 unsigned int log_sector_size = BBSIZE;
891
892 if (xfs_sb_version_hassector(&mp->m_sb))
893 log_sector_size = mp->m_sb.sb_logsectsize;
894 error = xfs_setsize_buftarg(mp->m_logdev_targp,
895 mp->m_sb.sb_blocksize,
896 log_sector_size);
897 if (error)
898 return error;
899 }
900 if (mp->m_rtdev_targp) {
901 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
902 mp->m_sb.sb_blocksize,
903 mp->m_sb.sb_sectsize);
904 if (error)
905 return error;
906 }
907
908 return 0;
909}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000910
David Chinner249a8c12008-02-05 12:13:32 +1100911/*
912 * XFS AIL push thread support
913 */
914void
915xfsaild_wakeup(
916 xfs_mount_t *mp,
917 xfs_lsn_t threshold_lsn)
918{
919 mp->m_ail.xa_target = threshold_lsn;
920 wake_up_process(mp->m_ail.xa_task);
921}
922
923int
924xfsaild(
925 void *data)
926{
927 xfs_mount_t *mp = (xfs_mount_t *)data;
928 xfs_lsn_t last_pushed_lsn = 0;
929 long tout = 0;
930
931 while (!kthread_should_stop()) {
932 if (tout)
933 schedule_timeout_interruptible(msecs_to_jiffies(tout));
934 tout = 1000;
935
936 /* swsusp */
937 try_to_freeze();
938
939 ASSERT(mp->m_log);
940 if (XFS_FORCED_SHUTDOWN(mp))
941 continue;
942
943 tout = xfsaild_push(mp, &last_pushed_lsn);
944 }
945
946 return 0;
947} /* xfsaild */
948
949int
950xfsaild_start(
951 xfs_mount_t *mp)
952{
953 mp->m_ail.xa_target = 0;
954 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
955 if (IS_ERR(mp->m_ail.xa_task))
956 return -PTR_ERR(mp->m_ail.xa_task);
957 return 0;
958}
959
960void
961xfsaild_stop(
962 xfs_mount_t *mp)
963{
964 kthread_stop(mp->m_ail.xa_task);
965}
966
967
968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100970xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 struct super_block *sb)
972{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000973 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Nathan Scott87582802006-03-14 13:18:19 +1100975 vp = kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
976 if (unlikely(!vp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 return NULL;
Nathan Scottec86dc02006-03-17 17:25:36 +1100978 return vn_to_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
981STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100982xfs_fs_destroy_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 struct inode *inode)
984{
Nathan Scottec86dc02006-03-17 17:25:36 +1100985 kmem_zone_free(xfs_vnode_zone, vn_from_inode(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
988STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100989xfs_fs_inode_init_once(
Christoph Lameter4ba9b9d2007-10-16 23:25:51 -0700990 void *vnode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991{
Christoph Lametera35afb82007-05-16 22:10:57 -0700992 inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993}
994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995/*
996 * Attempt to flush the inode, this will actually fail
997 * if the inode is pinned, but we dirty the inode again
998 * at the point when it is unpinned after a log write,
Nathan Scott87582802006-03-14 13:18:19 +1100999 * since this is when the inode itself becomes flushable.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 */
1001STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001002xfs_fs_write_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 struct inode *inode,
1004 int sync)
1005{
David Chinnera3f74ff2008-03-06 13:43:42 +11001006 int error = 0;
1007 int flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001009 xfs_itrace_entry(XFS_I(inode));
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001010 if (sync) {
1011 filemap_fdatawait(inode->i_mapping);
1012 flags |= FLUSH_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 }
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001014 error = xfs_inode_flush(XFS_I(inode), flags);
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001015 /*
1016 * if we failed to write out the inode then mark
1017 * it dirty again so we'll try again later.
1018 */
1019 if (error)
1020 mark_inode_dirty_sync(inode);
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 return -error;
1023}
1024
1025STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001026xfs_fs_clear_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 struct inode *inode)
1028{
Christoph Hellwig1543d792007-08-29 11:46:47 +10001029 xfs_inode_t *ip = XFS_I(inode);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001030
Christoph Hellwig02ba71d2005-09-05 08:28:02 +10001031 /*
Christoph Hellwig1543d792007-08-29 11:46:47 +10001032 * ip can be null when xfs_iget_core calls xfs_idestroy if we
Christoph Hellwig02ba71d2005-09-05 08:28:02 +10001033 * find an inode with di_mode == 0 but without IGET_CREATE set.
1034 */
Christoph Hellwig1543d792007-08-29 11:46:47 +10001035 if (ip) {
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001036 xfs_itrace_entry(ip);
Christoph Hellwig1543d792007-08-29 11:46:47 +10001037 XFS_STATS_INC(vn_rele);
1038 XFS_STATS_INC(vn_remove);
1039 XFS_STATS_INC(vn_reclaim);
1040 XFS_STATS_DEC(vn_active);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001041
Christoph Hellwig1543d792007-08-29 11:46:47 +10001042 xfs_inactive(ip);
1043 xfs_iflags_clear(ip, XFS_IMODIFIED);
1044 if (xfs_reclaim(ip))
Harvey Harrison34a622b2008-04-10 12:19:21 +10001045 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +10001046 }
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001047
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001048 ASSERT(XFS_I(inode) == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051/*
1052 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
1053 * Doing this has two advantages:
1054 * - It saves on stack space, which is tight in certain situations
1055 * - It can be used (with care) as a mechanism to avoid deadlocks.
1056 * Flushing while allocating in a full filesystem requires both.
1057 */
1058STATIC void
1059xfs_syncd_queue_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001060 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 void *data,
Christoph Hellwig74394492007-08-30 17:21:22 +10001062 void (*syncer)(struct xfs_mount *, void *))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
Nathan Scottb83bd132006-06-09 16:48:30 +10001064 struct bhv_vfs_sync_work *work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Nathan Scottb83bd132006-06-09 16:48:30 +10001066 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 INIT_LIST_HEAD(&work->w_list);
1068 work->w_syncer = syncer;
1069 work->w_data = data;
Christoph Hellwig74394492007-08-30 17:21:22 +10001070 work->w_mount = mp;
1071 spin_lock(&mp->m_sync_lock);
1072 list_add_tail(&work->w_list, &mp->m_sync_list);
1073 spin_unlock(&mp->m_sync_lock);
1074 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075}
1076
1077/*
1078 * Flush delayed allocate data, attempting to free up reserved space
1079 * from existing allocations. At this point a new allocation attempt
1080 * has failed with ENOSPC and we are in the process of scratching our
1081 * heads, looking about for more room...
1082 */
1083STATIC void
1084xfs_flush_inode_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001085 struct xfs_mount *mp,
1086 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
Christoph Hellwig74394492007-08-30 17:21:22 +10001088 struct inode *inode = arg;
1089 filemap_flush(inode->i_mapping);
1090 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
1093void
1094xfs_flush_inode(
1095 xfs_inode_t *ip)
1096{
Christoph Hellwig74394492007-08-30 17:21:22 +10001097 struct inode *inode = ip->i_vnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 igrab(inode);
Christoph Hellwig74394492007-08-30 17:21:22 +10001100 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001101 delay(msecs_to_jiffies(500));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
1104/*
1105 * This is the "bigger hammer" version of xfs_flush_inode_work...
1106 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1107 */
1108STATIC void
1109xfs_flush_device_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001110 struct xfs_mount *mp,
1111 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112{
Christoph Hellwig74394492007-08-30 17:21:22 +10001113 struct inode *inode = arg;
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001114 sync_blockdev(mp->m_super->s_bdev);
Christoph Hellwig74394492007-08-30 17:21:22 +10001115 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
1118void
1119xfs_flush_device(
1120 xfs_inode_t *ip)
1121{
Nathan Scottec86dc02006-03-17 17:25:36 +11001122 struct inode *inode = vn_to_inode(XFS_ITOV(ip));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 igrab(inode);
Christoph Hellwig74394492007-08-30 17:21:22 +10001125 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001126 delay(msecs_to_jiffies(500));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1128}
1129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130STATIC void
Christoph Hellwig74394492007-08-30 17:21:22 +10001131xfs_sync_worker(
1132 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 void *unused)
1134{
1135 int error;
1136
Christoph Hellwig74394492007-08-30 17:21:22 +10001137 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
David Chinner7e206942008-04-17 16:49:55 +10001138 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
Christoph Hellwig74394492007-08-30 17:21:22 +10001139 mp->m_sync_seq++;
1140 wake_up(&mp->m_wait_single_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
1143STATIC int
1144xfssyncd(
1145 void *arg)
1146{
Christoph Hellwig74394492007-08-30 17:21:22 +10001147 struct xfs_mount *mp = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 long timeleft;
Nathan Scottb83bd132006-06-09 16:48:30 +10001149 bhv_vfs_sync_work_t *work, *n;
Christoph Hellwig4df08c52005-09-05 08:34:18 +10001150 LIST_HEAD (tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Rafael J. Wysocki83144182007-07-17 04:03:35 -07001152 set_freezable();
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001153 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 for (;;) {
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001155 timeleft = schedule_timeout_interruptible(timeleft);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 /* swsusp */
Christoph Lameter3e1d1d22005-06-24 23:13:50 -07001157 try_to_freeze();
Christoph Hellwig74394492007-08-30 17:21:22 +10001158 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 break;
1160
Christoph Hellwig74394492007-08-30 17:21:22 +10001161 spin_lock(&mp->m_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 /*
1163 * We can get woken by laptop mode, to do a sync -
1164 * that's the (only!) case where the list would be
1165 * empty with time remaining.
1166 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001167 if (!timeleft || list_empty(&mp->m_sync_list)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 if (!timeleft)
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001169 timeleft = xfs_syncd_centisecs *
1170 msecs_to_jiffies(10);
Christoph Hellwig74394492007-08-30 17:21:22 +10001171 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1172 list_add_tail(&mp->m_sync_work.w_list,
1173 &mp->m_sync_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001175 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 list_move(&work->w_list, &tmp);
Christoph Hellwig74394492007-08-30 17:21:22 +10001177 spin_unlock(&mp->m_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
1179 list_for_each_entry_safe(work, n, &tmp, w_list) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001180 (*work->w_syncer)(mp, work->w_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 list_del(&work->w_list);
Christoph Hellwig74394492007-08-30 17:21:22 +10001182 if (work == &mp->m_sync_work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 continue;
Denys Vlasenkof0e2d932008-05-19 16:31:57 +10001184 kmem_free(work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 }
1186 }
1187
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 return 0;
1189}
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001192xfs_fs_put_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 struct super_block *sb)
1194{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001195 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001196 struct xfs_inode *rip = mp->m_rootip;
1197 int unmount_event_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 int error;
1199
Christoph Hellwig74394492007-08-30 17:21:22 +10001200 kthread_stop(mp->m_sync_task);
1201
Christoph Hellwig745f6912007-08-30 17:20:39 +10001202 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001203
1204#ifdef HAVE_DMAPI
1205 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1206 unmount_event_flags =
1207 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1208 0 : DM_FLAGS_UNWANTED;
1209 /*
1210 * Ignore error from dmapi here, first unmount is not allowed
1211 * to fail anyway, and second we wouldn't want to fail a
1212 * unmount because of dmapi.
1213 */
1214 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1215 NULL, NULL, 0, 0, unmount_event_flags);
1216 }
1217#endif
1218
1219 /*
1220 * Blow away any referenced inode in the filestreams cache.
1221 * This can and will cause log traffic as inodes go inactive
1222 * here.
1223 */
1224 xfs_filestream_unmount(mp);
1225
1226 XFS_bflush(mp->m_ddev_targp);
1227 error = xfs_unmount_flush(mp, 0);
1228 WARN_ON(error);
1229
1230 IRELE(rip);
1231
1232 /*
1233 * If we're forcing a shutdown, typically because of a media error,
1234 * we want to make sure we invalidate dirty pages that belong to
1235 * referenced vnodes as well.
1236 */
1237 if (XFS_FORCED_SHUTDOWN(mp)) {
1238 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1239 ASSERT(error != EFSCORRUPTED);
1240 }
1241
1242 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1243 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1244 unmount_event_flags);
1245 }
1246
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001247 xfs_unmountfs(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001248 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001249 xfs_close_devices(mp);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001250 xfs_qmops_put(mp);
1251 xfs_dmops_put(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001252 kfree(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253}
1254
1255STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001256xfs_fs_write_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 struct super_block *sb)
1258{
Nathan Scottb83bd132006-06-09 16:48:30 +10001259 if (!(sb->s_flags & MS_RDONLY))
Christoph Hellwig745f6912007-08-30 17:20:39 +10001260 xfs_sync(XFS_M(sb), SYNC_FSDATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 sb->s_dirt = 0;
1262}
1263
1264STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001265xfs_fs_sync_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 struct super_block *sb,
1267 int wait)
1268{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001269 struct xfs_mount *mp = XFS_M(sb);
Nathan Scottb83bd132006-06-09 16:48:30 +10001270 int error;
1271 int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001273 /*
1274 * Treat a sync operation like a freeze. This is to work
1275 * around a race in sync_inodes() which works in two phases
1276 * - an asynchronous flush, which can write out an inode
1277 * without waiting for file size updates to complete, and a
1278 * synchronous flush, which wont do anything because the
1279 * async flush removed the inode's dirty flag. Also
1280 * sync_inodes() will not see any files that just have
1281 * outstanding transactions to be flushed because we don't
1282 * dirty the Linux inode until after the transaction I/O
1283 * completes.
1284 */
1285 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
David Chinner28239452007-02-10 18:36:40 +11001286 /*
1287 * First stage of freeze - no more writers will make progress
1288 * now we are here, so we flush delwri and delalloc buffers
1289 * here, then wait for all I/O to complete. Data is frozen at
1290 * that point. Metadata is not frozen, transactions can still
1291 * occur here so don't bother flushing the buftarg (i.e
1292 * SYNC_QUIESCE) because it'll just get dirty again.
1293 */
David Chinner516b2e72007-06-18 16:50:48 +10001294 flags = SYNC_DATA_QUIESCE;
David Chinner28239452007-02-10 18:36:40 +11001295 } else
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001296 flags = SYNC_FSDATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Christoph Hellwig745f6912007-08-30 17:20:39 +10001298 error = xfs_sync(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 sb->s_dirt = 0;
1300
1301 if (unlikely(laptop_mode)) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001302 int prev_sync_seq = mp->m_sync_seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
1304 /*
1305 * The disk must be active because we're syncing.
1306 * We schedule xfssyncd now (now that the disk is
1307 * active) instead of later (when it might not be).
1308 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001309 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 /*
1311 * We have to wait for the sync iteration to complete.
1312 * If we don't, the disk activity caused by the sync
1313 * will come after the sync is completed, and that
1314 * triggers another sync from laptop mode.
1315 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001316 wait_event(mp->m_wait_single_sync_task,
1317 mp->m_sync_seq != prev_sync_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 }
1319
1320 return -error;
1321}
1322
1323STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001324xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001325 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 struct kstatfs *statp)
1327{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001328 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1329 xfs_sb_t *sbp = &mp->m_sb;
1330 __uint64_t fakeinos, id;
1331 xfs_extlen_t lsize;
1332
1333 statp->f_type = XFS_SB_MAGIC;
1334 statp->f_namelen = MAXNAMELEN - 1;
1335
1336 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1337 statp->f_fsid.val[0] = (u32)id;
1338 statp->f_fsid.val[1] = (u32)(id >> 32);
1339
Christoph Hellwigd4d90b52008-04-22 17:34:37 +10001340 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001341
1342 spin_lock(&mp->m_sb_lock);
1343 statp->f_bsize = sbp->sb_blocksize;
1344 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1345 statp->f_blocks = sbp->sb_dblocks - lsize;
1346 statp->f_bfree = statp->f_bavail =
1347 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1348 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1349#if XFS_BIG_INUMS
1350 fakeinos += mp->m_inoadd;
1351#endif
1352 statp->f_files =
1353 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1354 if (mp->m_maxicount)
1355#if XFS_BIG_INUMS
1356 if (!mp->m_inoadd)
1357#endif
1358 statp->f_files = min_t(typeof(statp->f_files),
1359 statp->f_files,
1360 mp->m_maxicount);
1361 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1362 spin_unlock(&mp->m_sb_lock);
1363
1364 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1365 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366}
1367
1368STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001369xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 struct super_block *sb,
1371 int *flags,
1372 char *options)
1373{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001374 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001375 struct xfs_mount_args *args;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 int error;
1377
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001378 args = xfs_args_allocate(sb, 0);
1379 if (!args)
1380 return -ENOMEM;
1381
Christoph Hellwig745f6912007-08-30 17:20:39 +10001382 error = xfs_parseargs(mp, options, args, 1);
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001383 if (error)
1384 goto out_free_args;
1385
1386 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
1387 if (mp->m_flags & XFS_MOUNT_RDONLY)
1388 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1389 if (args->flags & XFSMNT_BARRIER) {
1390 mp->m_flags |= XFS_MOUNT_BARRIER;
1391 xfs_mountfs_check_barriers(mp);
1392 } else {
1393 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1394 }
1395 } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
1396 xfs_filestream_flush(mp);
1397 xfs_sync(mp, SYNC_DATA_QUIESCE);
1398 xfs_attr_quiesce(mp);
1399 mp->m_flags |= XFS_MOUNT_RDONLY;
1400 }
1401
1402 out_free_args:
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001403 kfree(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 return -error;
1405}
1406
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001407/*
1408 * Second stage of a freeze. The data is already frozen so we only
1409 * need to take care of themetadata. Once that's done write a dummy
1410 * record to dirty the log in case of a crash while frozen.
1411 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001413xfs_fs_lockfs(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 struct super_block *sb)
1415{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001416 struct xfs_mount *mp = XFS_M(sb);
1417
1418 xfs_attr_quiesce(mp);
1419 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420}
1421
1422STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001423xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 struct seq_file *m,
1425 struct vfsmount *mnt)
1426{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001427 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428}
1429
1430STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001431xfs_fs_quotasync(
Nathan Scottee348072005-11-02 10:32:38 +11001432 struct super_block *sb,
1433 int type)
1434{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001435 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
Nathan Scottee348072005-11-02 10:32:38 +11001436}
1437
1438STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001439xfs_fs_getxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 struct super_block *sb,
1441 struct fs_quota_stat *fqs)
1442{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001443 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444}
1445
1446STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001447xfs_fs_setxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 struct super_block *sb,
1449 unsigned int flags,
1450 int op)
1451{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001452 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453}
1454
1455STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001456xfs_fs_getxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 struct super_block *sb,
1458 int type,
1459 qid_t id,
1460 struct fs_disk_quota *fdq)
1461{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001462 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001463 (type == USRQUOTA) ? Q_XGETQUOTA :
1464 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1465 Q_XGETPQUOTA), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466}
1467
1468STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001469xfs_fs_setxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 struct super_block *sb,
1471 int type,
1472 qid_t id,
1473 struct fs_disk_quota *fdq)
1474{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001475 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001476 (type == USRQUOTA) ? Q_XSETQLIM :
1477 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1478 Q_XSETPQLIM), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001481/*
1482 * This function fills in xfs_mount_t fields based on mount args.
1483 * Note: the superblock has _not_ yet been read in.
1484 */
1485STATIC int
1486xfs_start_flags(
1487 struct xfs_mount_args *ap,
1488 struct xfs_mount *mp)
1489{
1490 /* Values are in BBs */
1491 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1492 /*
1493 * At this point the superblock has not been read
1494 * in, therefore we do not know the block size.
1495 * Before the mount call ends we will convert
1496 * these to FSBs.
1497 */
1498 mp->m_dalign = ap->sunit;
1499 mp->m_swidth = ap->swidth;
1500 }
1501
1502 if (ap->logbufs != -1 &&
1503 ap->logbufs != 0 &&
1504 (ap->logbufs < XLOG_MIN_ICLOGS ||
1505 ap->logbufs > XLOG_MAX_ICLOGS)) {
1506 cmn_err(CE_WARN,
1507 "XFS: invalid logbufs value: %d [not %d-%d]",
1508 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1509 return XFS_ERROR(EINVAL);
1510 }
1511 mp->m_logbufs = ap->logbufs;
1512 if (ap->logbufsize != -1 &&
1513 ap->logbufsize != 0 &&
1514 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1515 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1516 !is_power_of_2(ap->logbufsize))) {
1517 cmn_err(CE_WARN,
1518 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1519 ap->logbufsize);
1520 return XFS_ERROR(EINVAL);
1521 }
1522 mp->m_logbsize = ap->logbufsize;
1523 mp->m_fsname_len = strlen(ap->fsname) + 1;
1524 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
1525 strcpy(mp->m_fsname, ap->fsname);
1526 if (ap->rtname[0]) {
1527 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
1528 strcpy(mp->m_rtname, ap->rtname);
1529 }
1530 if (ap->logname[0]) {
1531 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
1532 strcpy(mp->m_logname, ap->logname);
1533 }
1534
1535 if (ap->flags & XFSMNT_WSYNC)
1536 mp->m_flags |= XFS_MOUNT_WSYNC;
1537#if XFS_BIG_INUMS
1538 if (ap->flags & XFSMNT_INO64) {
1539 mp->m_flags |= XFS_MOUNT_INO64;
1540 mp->m_inoadd = XFS_INO64_OFFSET;
1541 }
1542#endif
1543 if (ap->flags & XFSMNT_RETERR)
1544 mp->m_flags |= XFS_MOUNT_RETERR;
1545 if (ap->flags & XFSMNT_NOALIGN)
1546 mp->m_flags |= XFS_MOUNT_NOALIGN;
1547 if (ap->flags & XFSMNT_SWALLOC)
1548 mp->m_flags |= XFS_MOUNT_SWALLOC;
1549 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1550 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1551 if (ap->flags & XFSMNT_32BITINODES)
1552 mp->m_flags |= XFS_MOUNT_32BITINODES;
1553
1554 if (ap->flags & XFSMNT_IOSIZE) {
1555 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1556 ap->iosizelog < XFS_MIN_IO_LOG) {
1557 cmn_err(CE_WARN,
1558 "XFS: invalid log iosize: %d [not %d-%d]",
1559 ap->iosizelog, XFS_MIN_IO_LOG,
1560 XFS_MAX_IO_LOG);
1561 return XFS_ERROR(EINVAL);
1562 }
1563
1564 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1565 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1566 }
1567
1568 if (ap->flags & XFSMNT_IKEEP)
1569 mp->m_flags |= XFS_MOUNT_IKEEP;
1570 if (ap->flags & XFSMNT_DIRSYNC)
1571 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1572 if (ap->flags & XFSMNT_ATTR2)
1573 mp->m_flags |= XFS_MOUNT_ATTR2;
1574 if (ap->flags & XFSMNT_NOATTR2)
1575 mp->m_flags |= XFS_MOUNT_NOATTR2;
1576
1577 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1578 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1579
1580 /*
1581 * no recovery flag requires a read-only mount
1582 */
1583 if (ap->flags & XFSMNT_NORECOVERY) {
1584 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1585 cmn_err(CE_WARN,
1586 "XFS: tried to mount a FS read-write without recovery!");
1587 return XFS_ERROR(EINVAL);
1588 }
1589 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1590 }
1591
1592 if (ap->flags & XFSMNT_NOUUID)
1593 mp->m_flags |= XFS_MOUNT_NOUUID;
1594 if (ap->flags & XFSMNT_BARRIER)
1595 mp->m_flags |= XFS_MOUNT_BARRIER;
1596 else
1597 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1598
1599 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1600 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1601
1602 if (ap->flags & XFSMNT_DMAPI)
1603 mp->m_flags |= XFS_MOUNT_DMAPI;
1604 return 0;
1605}
1606
1607/*
1608 * This function fills in xfs_mount_t fields based on mount args.
1609 * Note: the superblock _has_ now been read in.
1610 */
1611STATIC int
1612xfs_finish_flags(
1613 struct xfs_mount_args *ap,
1614 struct xfs_mount *mp)
1615{
1616 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1617
1618 /* Fail a mount where the logbuf is smaller then the log stripe */
1619 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1620 if ((ap->logbufsize <= 0) &&
1621 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1622 mp->m_logbsize = mp->m_sb.sb_logsunit;
1623 } else if (ap->logbufsize > 0 &&
1624 ap->logbufsize < mp->m_sb.sb_logsunit) {
1625 cmn_err(CE_WARN,
1626 "XFS: logbuf size must be greater than or equal to log stripe size");
1627 return XFS_ERROR(EINVAL);
1628 }
1629 } else {
1630 /* Fail a mount if the logbuf is larger than 32K */
1631 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1632 cmn_err(CE_WARN,
1633 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1634 return XFS_ERROR(EINVAL);
1635 }
1636 }
1637
1638 /*
1639 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1640 * told by noattr2 to turn it off
1641 */
1642 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1643 !(ap->flags & XFSMNT_NOATTR2))
1644 mp->m_flags |= XFS_MOUNT_ATTR2;
1645
1646 /*
1647 * prohibit r/w mounts of read-only filesystems
1648 */
1649 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1650 cmn_err(CE_WARN,
1651 "XFS: cannot mount a read-only filesystem as read-write");
1652 return XFS_ERROR(EROFS);
1653 }
1654
1655 /*
1656 * check for shared mount.
1657 */
1658 if (ap->flags & XFSMNT_SHARED) {
1659 if (!xfs_sb_version_hasshared(&mp->m_sb))
1660 return XFS_ERROR(EINVAL);
1661
1662 /*
1663 * For IRIX 6.5, shared mounts must have the shared
1664 * version bit set, have the persistent readonly
1665 * field set, must be version 0 and can only be mounted
1666 * read-only.
1667 */
1668 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1669 (mp->m_sb.sb_shared_vn != 0))
1670 return XFS_ERROR(EINVAL);
1671
1672 mp->m_flags |= XFS_MOUNT_SHARED;
1673
1674 /*
1675 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1676 */
1677 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1678 return XFS_ERROR(EINVAL);
1679 }
1680
1681 if (ap->flags & XFSMNT_UQUOTA) {
1682 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1683 if (ap->flags & XFSMNT_UQUOTAENF)
1684 mp->m_qflags |= XFS_UQUOTA_ENFD;
1685 }
1686
1687 if (ap->flags & XFSMNT_GQUOTA) {
1688 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1689 if (ap->flags & XFSMNT_GQUOTAENF)
1690 mp->m_qflags |= XFS_OQUOTA_ENFD;
1691 } else if (ap->flags & XFSMNT_PQUOTA) {
1692 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1693 if (ap->flags & XFSMNT_PQUOTAENF)
1694 mp->m_qflags |= XFS_OQUOTA_ENFD;
1695 }
1696
1697 return 0;
1698}
1699
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001701xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 struct super_block *sb,
1703 void *data,
1704 int silent)
1705{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001706 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001707 struct xfs_mount *mp = NULL;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001708 struct xfs_mount_args *args;
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001709 int flags = 0, error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001711 args = xfs_args_allocate(sb, silent);
1712 if (!args)
1713 return -ENOMEM;
1714
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001715 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1716 if (!mp)
1717 goto out_free_args;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001719 spin_lock_init(&mp->m_sb_lock);
1720 mutex_init(&mp->m_ilock);
1721 mutex_init(&mp->m_growlock);
1722 atomic_set(&mp->m_active_trans, 0);
Christoph Hellwig74394492007-08-30 17:21:22 +10001723 INIT_LIST_HEAD(&mp->m_sync_list);
1724 spin_lock_init(&mp->m_sync_lock);
1725 init_waitqueue_head(&mp->m_wait_single_sync_task);
1726
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001727 mp->m_super = sb;
1728 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001730 if (sb->s_flags & MS_RDONLY)
1731 mp->m_flags |= XFS_MOUNT_RDONLY;
1732
Christoph Hellwig745f6912007-08-30 17:20:39 +10001733 error = xfs_parseargs(mp, (char *)data, args, 0);
1734 if (error)
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001735 goto out_free_mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 sb_min_blocksize(sb, BBSIZE);
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001738 sb->s_xattr = xfs_xattr_handlers;
Nathan Scotta50cd262006-03-14 14:06:18 +11001739 sb->s_export_op = &xfs_export_operations;
Nathan Scotta50cd262006-03-14 14:06:18 +11001740 sb->s_qcop = &xfs_quotactl_operations;
1741 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001743 error = xfs_dmops_get(mp, args);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001744 if (error)
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001745 goto out_free_mp;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001746 error = xfs_qmops_get(mp, args);
1747 if (error)
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001748 goto out_put_dmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001749
1750 if (args->flags & XFSMNT_QUIET)
1751 flags |= XFS_MFSI_QUIET;
1752
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001753 error = xfs_open_devices(mp, args);
1754 if (error)
1755 goto out_put_qmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001756
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001757 if (xfs_icsb_init_counters(mp))
1758 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1759
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001760 /*
1761 * Setup flags based on mount(2) options and then the superblock
1762 */
1763 error = xfs_start_flags(args, mp);
1764 if (error)
Christoph Hellwig95db4e22008-05-20 15:10:58 +10001765 goto out_destroy_counters;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001766 error = xfs_readsb(mp, flags);
1767 if (error)
Christoph Hellwig95db4e22008-05-20 15:10:58 +10001768 goto out_destroy_counters;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001769 error = xfs_finish_flags(args, mp);
1770 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001771 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001772
Christoph Hellwige34b5622008-05-20 15:10:36 +10001773 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001774 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001775 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001776
1777 if (mp->m_flags & XFS_MOUNT_BARRIER)
1778 xfs_mountfs_check_barriers(mp);
1779
1780 error = xfs_filestream_mount(mp);
1781 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001782 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001783
1784 error = xfs_mountfs(mp, flags);
1785 if (error)
Christoph Hellwig120226c2008-05-20 15:11:11 +10001786 goto out_filestream_unmount;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001787
1788 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 sb->s_dirt = 1;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001791 sb->s_magic = XFS_SB_MAGIC;
1792 sb->s_blocksize = mp->m_sb.sb_blocksize;
1793 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1795 sb->s_time_gran = 1;
1796 set_posix_acl_flag(sb);
1797
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001798 root = igrab(mp->m_rootip->i_vnode);
1799 if (!root) {
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001800 error = ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 goto fail_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001802 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001803 if (is_bad_inode(root)) {
1804 error = EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 goto fail_vnrele;
1806 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001807 sb->s_root = d_alloc_root(root);
1808 if (!sb->s_root) {
1809 error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 goto fail_vnrele;
1811 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001812
1813 mp->m_sync_work.w_syncer = xfs_sync_worker;
1814 mp->m_sync_work.w_mount = mp;
1815 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1816 if (IS_ERR(mp->m_sync_task)) {
1817 error = -PTR_ERR(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 goto fail_vnrele;
Christoph Hellwig74394492007-08-30 17:21:22 +10001819 }
1820
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001821 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001823 kfree(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 return 0;
1825
Christoph Hellwig120226c2008-05-20 15:11:11 +10001826 out_filestream_unmount:
1827 xfs_filestream_unmount(mp);
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001828 out_free_sb:
1829 xfs_freesb(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001830 out_destroy_counters:
1831 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001832 xfs_close_devices(mp);
1833 out_put_qmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001834 xfs_qmops_put(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001835 out_put_dmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001836 xfs_dmops_put(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001837 out_free_mp:
1838 kfree(mp);
1839 out_free_args:
1840 kfree(args);
1841 return -error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001842
1843 fail_vnrele:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 if (sb->s_root) {
1845 dput(sb->s_root);
1846 sb->s_root = NULL;
1847 } else {
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001848 iput(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 }
1850
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001851 fail_unmount:
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001852 /*
1853 * Blow away any referenced inode in the filestreams cache.
1854 * This can and will cause log traffic as inodes go inactive
1855 * here.
1856 */
1857 xfs_filestream_unmount(mp);
1858
1859 XFS_bflush(mp->m_ddev_targp);
1860 error = xfs_unmount_flush(mp, 0);
1861 WARN_ON(error);
1862
1863 IRELE(mp->m_rootip);
1864
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001865 xfs_unmountfs(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001866 goto out_destroy_counters;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867}
1868
David Howells454e2392006-06-23 02:02:57 -07001869STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001870xfs_fs_get_sb(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 struct file_system_type *fs_type,
1872 int flags,
1873 const char *dev_name,
David Howells454e2392006-06-23 02:02:57 -07001874 void *data,
1875 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876{
David Howells454e2392006-06-23 02:02:57 -07001877 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1878 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879}
1880
David Chinner7989cb82007-02-10 18:34:56 +11001881static struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001882 .alloc_inode = xfs_fs_alloc_inode,
1883 .destroy_inode = xfs_fs_destroy_inode,
1884 .write_inode = xfs_fs_write_inode,
1885 .clear_inode = xfs_fs_clear_inode,
1886 .put_super = xfs_fs_put_super,
1887 .write_super = xfs_fs_write_super,
1888 .sync_fs = xfs_fs_sync_super,
1889 .write_super_lockfs = xfs_fs_lockfs,
1890 .statfs = xfs_fs_statfs,
1891 .remount_fs = xfs_fs_remount,
1892 .show_options = xfs_fs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893};
1894
David Chinner7989cb82007-02-10 18:34:56 +11001895static struct quotactl_ops xfs_quotactl_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001896 .quota_sync = xfs_fs_quotasync,
1897 .get_xstate = xfs_fs_getxstate,
1898 .set_xstate = xfs_fs_setxstate,
1899 .get_xquota = xfs_fs_getxquota,
1900 .set_xquota = xfs_fs_setxquota,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901};
1902
Andrew Morton5085b602007-02-20 13:57:47 -08001903static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 .owner = THIS_MODULE,
1905 .name = "xfs",
Nathan Scotta50cd262006-03-14 14:06:18 +11001906 .get_sb = xfs_fs_get_sb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 .kill_sb = kill_block_super,
1908 .fs_flags = FS_REQUIRES_DEV,
1909};
1910
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001911STATIC int __init
1912xfs_alloc_trace_bufs(void)
1913{
1914#ifdef XFS_ALLOC_TRACE
1915 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1916 if (!xfs_alloc_trace_buf)
1917 goto out;
1918#endif
1919#ifdef XFS_BMAP_TRACE
1920 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1921 if (!xfs_bmap_trace_buf)
1922 goto out_free_alloc_trace;
1923#endif
1924#ifdef XFS_BMBT_TRACE
1925 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1926 if (!xfs_bmbt_trace_buf)
1927 goto out_free_bmap_trace;
1928#endif
1929#ifdef XFS_ATTR_TRACE
1930 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1931 if (!xfs_attr_trace_buf)
1932 goto out_free_bmbt_trace;
1933#endif
1934#ifdef XFS_DIR2_TRACE
1935 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1936 if (!xfs_dir2_trace_buf)
1937 goto out_free_attr_trace;
1938#endif
1939
1940 return 0;
1941
1942#ifdef XFS_DIR2_TRACE
1943 out_free_attr_trace:
1944#endif
1945#ifdef XFS_ATTR_TRACE
1946 ktrace_free(xfs_attr_trace_buf);
1947 out_free_bmbt_trace:
1948#endif
1949#ifdef XFS_BMBT_TRACE
1950 ktrace_free(xfs_bmbt_trace_buf);
1951 out_free_bmap_trace:
1952#endif
1953#ifdef XFS_BMAP_TRACE
1954 ktrace_free(xfs_bmap_trace_buf);
1955 out_free_alloc_trace:
1956#endif
1957#ifdef XFS_ALLOC_TRACE
1958 ktrace_free(xfs_alloc_trace_buf);
1959 out:
1960#endif
1961 return -ENOMEM;
1962}
1963
1964STATIC void
1965xfs_free_trace_bufs(void)
1966{
1967#ifdef XFS_DIR2_TRACE
1968 ktrace_free(xfs_dir2_trace_buf);
1969#endif
1970#ifdef XFS_ATTR_TRACE
1971 ktrace_free(xfs_attr_trace_buf);
1972#endif
1973#ifdef XFS_BMBT_TRACE
1974 ktrace_free(xfs_bmbt_trace_buf);
1975#endif
1976#ifdef XFS_BMAP_TRACE
1977 ktrace_free(xfs_bmap_trace_buf);
1978#endif
1979#ifdef XFS_ALLOC_TRACE
1980 ktrace_free(xfs_alloc_trace_buf);
1981#endif
1982}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
1984STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001985xfs_init_zones(void)
1986{
1987 xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
1988 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
1989 KM_ZONE_SPREAD,
1990 xfs_fs_inode_init_once);
1991 if (!xfs_vnode_zone)
1992 goto out;
1993
1994 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1995 if (!xfs_ioend_zone)
1996 goto out_destroy_vnode_zone;
1997
1998 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1999 xfs_ioend_zone);
2000 if (!xfs_ioend_pool)
2001 goto out_destroy_ioend_zone;
2002
2003 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
2004 "xfs_log_ticket");
2005 if (!xfs_log_ticket_zone)
2006 goto out_destroy_ioend_pool;
2007
2008 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
2009 "xfs_bmap_free_item");
2010 if (!xfs_bmap_free_item_zone)
2011 goto out_destroy_log_ticket_zone;
2012 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
2013 "xfs_btree_cur");
2014 if (!xfs_btree_cur_zone)
2015 goto out_destroy_bmap_free_item_zone;
2016
2017 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
2018 "xfs_da_state");
2019 if (!xfs_da_state_zone)
2020 goto out_destroy_btree_cur_zone;
2021
2022 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
2023 if (!xfs_dabuf_zone)
2024 goto out_destroy_da_state_zone;
2025
2026 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
2027 if (!xfs_ifork_zone)
2028 goto out_destroy_dabuf_zone;
2029
2030 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
2031 if (!xfs_trans_zone)
2032 goto out_destroy_ifork_zone;
2033
2034 /*
2035 * The size of the zone allocated buf log item is the maximum
2036 * size possible under XFS. This wastes a little bit of memory,
2037 * but it is much faster.
2038 */
2039 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
2040 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
2041 NBWORD) * sizeof(int))), "xfs_buf_item");
2042 if (!xfs_buf_item_zone)
2043 goto out_destroy_trans_zone;
2044
2045 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
2046 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
2047 sizeof(xfs_extent_t))), "xfs_efd_item");
2048 if (!xfs_efd_zone)
2049 goto out_destroy_buf_item_zone;
2050
2051 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
2052 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
2053 sizeof(xfs_extent_t))), "xfs_efi_item");
2054 if (!xfs_efi_zone)
2055 goto out_destroy_efd_zone;
2056
2057 xfs_inode_zone =
2058 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
2059 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
2060 KM_ZONE_SPREAD, NULL);
2061 if (!xfs_inode_zone)
2062 goto out_destroy_efi_zone;
2063
2064 xfs_ili_zone =
2065 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
2066 KM_ZONE_SPREAD, NULL);
2067 if (!xfs_ili_zone)
2068 goto out_destroy_inode_zone;
2069
2070#ifdef CONFIG_XFS_POSIX_ACL
2071 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
2072 if (!xfs_acl_zone)
2073 goto out_destroy_ili_zone;
2074#endif
2075
2076 return 0;
2077
2078#ifdef CONFIG_XFS_POSIX_ACL
2079 out_destroy_ili_zone:
2080#endif
2081 kmem_zone_destroy(xfs_ili_zone);
2082 out_destroy_inode_zone:
2083 kmem_zone_destroy(xfs_inode_zone);
2084 out_destroy_efi_zone:
2085 kmem_zone_destroy(xfs_efi_zone);
2086 out_destroy_efd_zone:
2087 kmem_zone_destroy(xfs_efd_zone);
2088 out_destroy_buf_item_zone:
2089 kmem_zone_destroy(xfs_buf_item_zone);
2090 out_destroy_trans_zone:
2091 kmem_zone_destroy(xfs_trans_zone);
2092 out_destroy_ifork_zone:
2093 kmem_zone_destroy(xfs_ifork_zone);
2094 out_destroy_dabuf_zone:
2095 kmem_zone_destroy(xfs_dabuf_zone);
2096 out_destroy_da_state_zone:
2097 kmem_zone_destroy(xfs_da_state_zone);
2098 out_destroy_btree_cur_zone:
2099 kmem_zone_destroy(xfs_btree_cur_zone);
2100 out_destroy_bmap_free_item_zone:
2101 kmem_zone_destroy(xfs_bmap_free_item_zone);
2102 out_destroy_log_ticket_zone:
2103 kmem_zone_destroy(xfs_log_ticket_zone);
2104 out_destroy_ioend_pool:
2105 mempool_destroy(xfs_ioend_pool);
2106 out_destroy_ioend_zone:
2107 kmem_zone_destroy(xfs_ioend_zone);
2108 out_destroy_vnode_zone:
2109 kmem_zone_destroy(xfs_vnode_zone);
2110 out:
2111 return -ENOMEM;
2112}
2113
2114STATIC void
2115xfs_destroy_zones(void)
2116{
2117#ifdef CONFIG_XFS_POSIX_ACL
2118 kmem_zone_destroy(xfs_acl_zone);
2119#endif
2120 kmem_zone_destroy(xfs_ili_zone);
2121 kmem_zone_destroy(xfs_inode_zone);
2122 kmem_zone_destroy(xfs_efi_zone);
2123 kmem_zone_destroy(xfs_efd_zone);
2124 kmem_zone_destroy(xfs_buf_item_zone);
2125 kmem_zone_destroy(xfs_trans_zone);
2126 kmem_zone_destroy(xfs_ifork_zone);
2127 kmem_zone_destroy(xfs_dabuf_zone);
2128 kmem_zone_destroy(xfs_da_state_zone);
2129 kmem_zone_destroy(xfs_btree_cur_zone);
2130 kmem_zone_destroy(xfs_bmap_free_item_zone);
2131 kmem_zone_destroy(xfs_log_ticket_zone);
2132 mempool_destroy(xfs_ioend_pool);
2133 kmem_zone_destroy(xfs_ioend_zone);
2134 kmem_zone_destroy(xfs_vnode_zone);
2135
2136}
2137
2138STATIC int __init
2139init_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140{
2141 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 static char message[] __initdata = KERN_INFO \
2143 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
2144
2145 printk(message);
2146
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 ktrace_init(64);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002148 vn_init();
2149 xfs_dir_startup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
Nathan Scott87582802006-03-14 13:18:19 +11002151 error = xfs_init_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002152 if (error)
2153 goto out;
2154
2155 error = xfs_alloc_trace_bufs();
2156 if (error)
2157 goto out_destroy_zones;
2158
2159 error = xfs_mru_cache_init();
2160 if (error)
2161 goto out_free_trace_buffers;
2162
2163 error = xfs_filestream_init();
2164 if (error)
2165 goto out_mru_cache_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Nathan Scottce8e9222006-01-11 15:39:08 +11002167 error = xfs_buf_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002168 if (error)
2169 goto out_filestream_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002171 error = xfs_init_procfs();
2172 if (error)
2173 goto out_buf_terminate;
2174
2175 error = xfs_sysctl_register();
2176 if (error)
2177 goto out_cleanup_procfs;
2178
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 vfs_initquota();
2180
2181 error = register_filesystem(&xfs_fs_type);
2182 if (error)
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002183 goto out_sysctl_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 return 0;
2185
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002186 out_sysctl_unregister:
2187 xfs_sysctl_unregister();
2188 out_cleanup_procfs:
2189 xfs_cleanup_procfs();
2190 out_buf_terminate:
Nathan Scottce8e9222006-01-11 15:39:08 +11002191 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002192 out_filestream_uninit:
2193 xfs_filestream_uninit();
2194 out_mru_cache_uninit:
2195 xfs_mru_cache_uninit();
2196 out_free_trace_buffers:
2197 xfs_free_trace_bufs();
2198 out_destroy_zones:
Nathan Scott87582802006-03-14 13:18:19 +11002199 xfs_destroy_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002200 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 return error;
2202}
2203
2204STATIC void __exit
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002205exit_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206{
2207 vfs_exitquota();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 unregister_filesystem(&xfs_fs_type);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002209 xfs_sysctl_unregister();
2210 xfs_cleanup_procfs();
Nathan Scottce8e9222006-01-11 15:39:08 +11002211 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002212 xfs_filestream_uninit();
2213 xfs_mru_cache_uninit();
2214 xfs_free_trace_bufs();
Nathan Scott87582802006-03-14 13:18:19 +11002215 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 ktrace_uninit();
2217}
2218
2219module_init(init_xfs_fs);
2220module_exit(exit_xfs_fs);
2221
2222MODULE_AUTHOR("Silicon Graphics, Inc.");
2223MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2224MODULE_LICENSE("GPL");