blob: 967603c469983f2cc734732a72663b3a3b395d94 [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#include <linux/namei.h>
58#include <linux/init.h>
59#include <linux/mount.h>
Christoph Hellwig0829c362005-09-02 16:58:49 +100060#include <linux/mempool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/writeback.h>
Christoph Hellwig4df08c52005-09-05 08:34:18 +100062#include <linux/kthread.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080063#include <linux/freezer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
David Chinner7989cb82007-02-10 18:34:56 +110065static struct quotactl_ops xfs_quotactl_operations;
66static struct super_operations xfs_super_operations;
67static kmem_zone_t *xfs_vnode_zone;
68static kmem_zone_t *xfs_ioend_zone;
Christoph Hellwig0829c362005-09-02 16:58:49 +100069mempool_t *xfs_ioend_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71STATIC struct xfs_mount_args *
72xfs_args_allocate(
Nathan Scott764d1f82006-03-31 13:04:17 +100073 struct super_block *sb,
74 int silent)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 struct xfs_mount_args *args;
77
Christoph Hellwigbdd907b2008-05-20 15:10:44 +100078 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
79 if (!args)
80 return NULL;
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 args->logbufs = args->logbufsize = -1;
83 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
84
85 /* Copy the already-parsed mount(2) flags we're interested in */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 if (sb->s_flags & MS_DIRSYNC)
87 args->flags |= XFSMNT_DIRSYNC;
88 if (sb->s_flags & MS_SYNCHRONOUS)
89 args->flags |= XFSMNT_WSYNC;
Nathan Scott764d1f82006-03-31 13:04:17 +100090 if (silent)
91 args->flags |= XFSMNT_QUIET;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 args->flags |= XFSMNT_32BITINODES;
93
94 return args;
95}
96
David Chinnera67d7c52007-11-23 16:29:32 +110097#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
98#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
99#define MNTOPT_LOGDEV "logdev" /* log device */
100#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
101#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
102#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
103#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
104#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
105#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
106#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
107#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
108#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
109#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
110#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
111#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
112#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
113#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
114#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
115#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
116#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
117 * unwritten extent conversion */
118#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
119#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
120#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
121#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
122#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
123#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
124#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
125 * in stat(). */
126#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
127#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
128#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
129#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
130#define MNTOPT_NOQUOTA "noquota" /* no quotas */
131#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
132#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
133#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
134#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
135#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
136#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
137#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
138#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
139#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
140#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
141#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
142#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
143#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
144
145STATIC unsigned long
146suffix_strtoul(char *s, char **endp, unsigned int base)
147{
148 int last, shift_left_factor = 0;
149 char *value = s;
150
151 last = strlen(value) - 1;
152 if (value[last] == 'K' || value[last] == 'k') {
153 shift_left_factor = 10;
154 value[last] = '\0';
155 }
156 if (value[last] == 'M' || value[last] == 'm') {
157 shift_left_factor = 20;
158 value[last] = '\0';
159 }
160 if (value[last] == 'G' || value[last] == 'g') {
161 shift_left_factor = 30;
162 value[last] = '\0';
163 }
164
165 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
166}
167
168STATIC int
169xfs_parseargs(
170 struct xfs_mount *mp,
171 char *options,
172 struct xfs_mount_args *args,
173 int update)
174{
175 char *this_char, *value, *eov;
176 int dsunit, dswidth, vol_dsunit, vol_dswidth;
177 int iosize;
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100178 int dmapi_implies_ikeep = 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100179
180 args->flags |= XFSMNT_BARRIER;
181 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
182
183 if (!options)
184 goto done;
185
186 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
187
188 while ((this_char = strsep(&options, ",")) != NULL) {
189 if (!*this_char)
190 continue;
191 if ((value = strchr(this_char, '=')) != NULL)
192 *value++ = 0;
193
194 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
195 if (!value || !*value) {
196 cmn_err(CE_WARN,
197 "XFS: %s option requires an argument",
198 this_char);
199 return EINVAL;
200 }
201 args->logbufs = simple_strtoul(value, &eov, 10);
202 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
203 if (!value || !*value) {
204 cmn_err(CE_WARN,
205 "XFS: %s option requires an argument",
206 this_char);
207 return EINVAL;
208 }
209 args->logbufsize = suffix_strtoul(value, &eov, 10);
210 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
211 if (!value || !*value) {
212 cmn_err(CE_WARN,
213 "XFS: %s option requires an argument",
214 this_char);
215 return EINVAL;
216 }
217 strncpy(args->logname, value, MAXNAMELEN);
218 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
219 if (!value || !*value) {
220 cmn_err(CE_WARN,
221 "XFS: %s option requires an argument",
222 this_char);
223 return EINVAL;
224 }
225 strncpy(args->mtpt, value, MAXNAMELEN);
226 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
227 if (!value || !*value) {
228 cmn_err(CE_WARN,
229 "XFS: %s option requires an argument",
230 this_char);
231 return EINVAL;
232 }
233 strncpy(args->rtname, value, MAXNAMELEN);
234 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
235 if (!value || !*value) {
236 cmn_err(CE_WARN,
237 "XFS: %s option requires an argument",
238 this_char);
239 return EINVAL;
240 }
241 iosize = simple_strtoul(value, &eov, 10);
242 args->flags |= XFSMNT_IOSIZE;
243 args->iosizelog = (uint8_t) iosize;
244 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
245 if (!value || !*value) {
246 cmn_err(CE_WARN,
247 "XFS: %s option requires an argument",
248 this_char);
249 return EINVAL;
250 }
251 iosize = suffix_strtoul(value, &eov, 10);
252 args->flags |= XFSMNT_IOSIZE;
253 args->iosizelog = ffs(iosize) - 1;
254 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
255 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
256 mp->m_flags |= XFS_MOUNT_GRPID;
257 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
258 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
259 mp->m_flags &= ~XFS_MOUNT_GRPID;
260 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
261 args->flags |= XFSMNT_WSYNC;
262 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
263 args->flags |= XFSMNT_OSYNCISOSYNC;
264 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
265 args->flags |= XFSMNT_NORECOVERY;
266 } else if (!strcmp(this_char, MNTOPT_INO64)) {
267 args->flags |= XFSMNT_INO64;
268#if !XFS_BIG_INUMS
269 cmn_err(CE_WARN,
270 "XFS: %s option not allowed on this system",
271 this_char);
272 return EINVAL;
273#endif
274 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
275 args->flags |= XFSMNT_NOALIGN;
276 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
277 args->flags |= XFSMNT_SWALLOC;
278 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
279 if (!value || !*value) {
280 cmn_err(CE_WARN,
281 "XFS: %s option requires an argument",
282 this_char);
283 return EINVAL;
284 }
285 dsunit = simple_strtoul(value, &eov, 10);
286 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
287 if (!value || !*value) {
288 cmn_err(CE_WARN,
289 "XFS: %s option requires an argument",
290 this_char);
291 return EINVAL;
292 }
293 dswidth = simple_strtoul(value, &eov, 10);
294 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
295 args->flags &= ~XFSMNT_32BITINODES;
296#if !XFS_BIG_INUMS
297 cmn_err(CE_WARN,
298 "XFS: %s option not allowed on this system",
299 this_char);
300 return EINVAL;
301#endif
302 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
303 args->flags |= XFSMNT_NOUUID;
304 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
305 args->flags |= XFSMNT_BARRIER;
306 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
307 args->flags &= ~XFSMNT_BARRIER;
308 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100309 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100310 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100311 dmapi_implies_ikeep = 0;
312 args->flags &= ~XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100313 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
314 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
315 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
316 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
317 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
318 args->flags |= XFSMNT_ATTR2;
319 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
320 args->flags &= ~XFSMNT_ATTR2;
Tim Shimmin7c12f292008-04-30 18:15:28 +1000321 args->flags |= XFSMNT_NOATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100322 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
323 args->flags2 |= XFSMNT2_FILESTREAMS;
324 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
325 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
326 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
327 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
328 !strcmp(this_char, MNTOPT_UQUOTA) ||
329 !strcmp(this_char, MNTOPT_USRQUOTA)) {
330 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
331 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
332 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
333 args->flags |= XFSMNT_UQUOTA;
334 args->flags &= ~XFSMNT_UQUOTAENF;
335 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
336 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
337 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
338 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
339 args->flags |= XFSMNT_PQUOTA;
340 args->flags &= ~XFSMNT_PQUOTAENF;
341 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
342 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
343 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
344 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
345 args->flags |= XFSMNT_GQUOTA;
346 args->flags &= ~XFSMNT_GQUOTAENF;
347 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
348 args->flags |= XFSMNT_DMAPI;
349 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
350 args->flags |= XFSMNT_DMAPI;
351 } else if (!strcmp(this_char, MNTOPT_DMI)) {
352 args->flags |= XFSMNT_DMAPI;
353 } else if (!strcmp(this_char, "ihashsize")) {
354 cmn_err(CE_WARN,
355 "XFS: ihashsize no longer used, option is deprecated.");
356 } else if (!strcmp(this_char, "osyncisdsync")) {
357 /* no-op, this is now the default */
358 cmn_err(CE_WARN,
359 "XFS: osyncisdsync is now the default, option is deprecated.");
360 } else if (!strcmp(this_char, "irixsgid")) {
361 cmn_err(CE_WARN,
362 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
363 } else {
364 cmn_err(CE_WARN,
365 "XFS: unknown mount option [%s].", this_char);
366 return EINVAL;
367 }
368 }
369
370 if (args->flags & XFSMNT_NORECOVERY) {
371 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
372 cmn_err(CE_WARN,
373 "XFS: no-recovery mounts must be read-only.");
374 return EINVAL;
375 }
376 }
377
378 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
379 cmn_err(CE_WARN,
380 "XFS: sunit and swidth options incompatible with the noalign option");
381 return EINVAL;
382 }
383
384 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
385 cmn_err(CE_WARN,
386 "XFS: cannot mount with both project and group quota");
387 return EINVAL;
388 }
389
390 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
391 printk("XFS: %s option needs the mount point option as well\n",
392 MNTOPT_DMAPI);
393 return EINVAL;
394 }
395
396 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
397 cmn_err(CE_WARN,
398 "XFS: sunit and swidth must be specified together");
399 return EINVAL;
400 }
401
402 if (dsunit && (dswidth % dsunit != 0)) {
403 cmn_err(CE_WARN,
404 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
405 dswidth, dsunit);
406 return EINVAL;
407 }
408
409 /*
410 * Applications using DMI filesystems often expect the
411 * inode generation number to be monotonically increasing.
412 * If we delete inode chunks we break this assumption, so
413 * keep unused inode chunks on disk for DMI filesystems
414 * until we come up with a better solution.
415 * Note that if "ikeep" or "noikeep" mount options are
416 * supplied, then they are honored.
417 */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100418 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
419 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100420
421 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
422 if (dsunit) {
423 args->sunit = dsunit;
424 args->flags |= XFSMNT_RETERR;
425 } else {
426 args->sunit = vol_dsunit;
427 }
428 dswidth ? (args->swidth = dswidth) :
429 (args->swidth = vol_dswidth);
430 } else {
431 args->sunit = args->swidth = 0;
432 }
433
434done:
435 if (args->flags & XFSMNT_32BITINODES)
436 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
437 if (args->flags2)
438 args->flags |= XFSMNT_FLAGS2;
439 return 0;
440}
441
442struct proc_xfs_info {
443 int flag;
444 char *str;
445};
446
447STATIC int
448xfs_showargs(
449 struct xfs_mount *mp,
450 struct seq_file *m)
451{
452 static struct proc_xfs_info xfs_info_set[] = {
453 /* the few simple ones we can get from the mount struct */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100454 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
David Chinnera67d7c52007-11-23 16:29:32 +1100455 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
456 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
457 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
458 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
459 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
460 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
461 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
462 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
463 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
464 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
465 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
466 { 0, NULL }
467 };
468 static struct proc_xfs_info xfs_info_unset[] = {
469 /* the few simple ones we can get from the mount struct */
David Chinnera67d7c52007-11-23 16:29:32 +1100470 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
471 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
472 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
473 { 0, NULL }
474 };
475 struct proc_xfs_info *xfs_infop;
476
477 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
478 if (mp->m_flags & xfs_infop->flag)
479 seq_puts(m, xfs_infop->str);
480 }
481 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
482 if (!(mp->m_flags & xfs_infop->flag))
483 seq_puts(m, xfs_infop->str);
484 }
485
486 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
487 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
488 (int)(1 << mp->m_writeio_log) >> 10);
489
490 if (mp->m_logbufs > 0)
491 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
492 if (mp->m_logbsize > 0)
493 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
494
495 if (mp->m_logname)
496 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
497 if (mp->m_rtname)
498 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
499
500 if (mp->m_dalign > 0)
501 seq_printf(m, "," MNTOPT_SUNIT "=%d",
502 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
503 if (mp->m_swidth > 0)
504 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
505 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
506
507 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
508 seq_puts(m, "," MNTOPT_USRQUOTA);
509 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
510 seq_puts(m, "," MNTOPT_UQUOTANOENF);
511
512 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
513 seq_puts(m, "," MNTOPT_PRJQUOTA);
514 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
515 seq_puts(m, "," MNTOPT_PQUOTANOENF);
516
517 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
518 seq_puts(m, "," MNTOPT_GRPQUOTA);
519 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
520 seq_puts(m, "," MNTOPT_GQUOTANOENF);
521
522 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
523 seq_puts(m, "," MNTOPT_NOQUOTA);
524
525 return 0;
526}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527__uint64_t
528xfs_max_file_offset(
529 unsigned int blockshift)
530{
531 unsigned int pagefactor = 1;
532 unsigned int bitshift = BITS_PER_LONG - 1;
533
534 /* Figure out maximum filesize, on Linux this can depend on
535 * the filesystem blocksize (on 32 bit platforms).
536 * __block_prepare_write does this in an [unsigned] long...
537 * page->index << (PAGE_CACHE_SHIFT - bbits)
538 * So, for page sized blocks (4K on 32 bit platforms),
539 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
540 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
541 * but for smaller blocksizes it is less (bbits = log2 bsize).
542 * Note1: get_block_t takes a long (implicit cast from above)
543 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
544 * can optionally convert the [unsigned] long from above into
545 * an [unsigned] long long.
546 */
547
548#if BITS_PER_LONG == 32
549# if defined(CONFIG_LBD)
550 ASSERT(sizeof(sector_t) == 8);
551 pagefactor = PAGE_CACHE_SIZE;
552 bitshift = BITS_PER_LONG;
553# else
554 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
555# endif
556#endif
557
558 return (((__uint64_t)pagefactor) << bitshift) - 1;
559}
560
David Chinner7989cb82007-02-10 18:34:56 +1100561STATIC_INLINE void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562xfs_set_inodeops(
563 struct inode *inode)
564{
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000565 switch (inode->i_mode & S_IFMT) {
566 case S_IFREG:
Nathan Scott416c6d52006-03-14 14:00:51 +1100567 inode->i_op = &xfs_inode_operations;
Nathan Scott3562fd42006-03-14 14:00:35 +1100568 inode->i_fop = &xfs_file_operations;
Nathan Scotte4c573b2006-03-14 13:54:26 +1100569 inode->i_mapping->a_ops = &xfs_address_space_operations;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000570 break;
571 case S_IFDIR:
Barry Naujok189f4bf2008-05-21 16:58:55 +1000572 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
573 inode->i_op = &xfs_dir_ci_inode_operations;
574 else
575 inode->i_op = &xfs_dir_inode_operations;
Nathan Scott3562fd42006-03-14 14:00:35 +1100576 inode->i_fop = &xfs_dir_file_operations;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000577 break;
578 case S_IFLNK:
Nathan Scott416c6d52006-03-14 14:00:51 +1100579 inode->i_op = &xfs_symlink_inode_operations;
Christoph Hellwig222096a2008-02-05 12:13:46 +1100580 if (!(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE))
Nathan Scotte4c573b2006-03-14 13:54:26 +1100581 inode->i_mapping->a_ops = &xfs_address_space_operations;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000582 break;
583 default:
Nathan Scott416c6d52006-03-14 14:00:51 +1100584 inode->i_op = &xfs_inode_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 init_special_inode(inode, inode->i_mode, inode->i_rdev);
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000586 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588}
589
David Chinner7989cb82007-02-10 18:34:56 +1100590STATIC_INLINE void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591xfs_revalidate_inode(
592 xfs_mount_t *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000593 bhv_vnode_t *vp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 xfs_inode_t *ip)
595{
Nathan Scottec86dc02006-03-17 17:25:36 +1100596 struct inode *inode = vn_to_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000598 inode->i_mode = ip->i_d.di_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 inode->i_nlink = ip->i_d.di_nlink;
600 inode->i_uid = ip->i_d.di_uid;
601 inode->i_gid = ip->i_d.di_gid;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000602
603 switch (inode->i_mode & S_IFMT) {
604 case S_IFBLK:
605 case S_IFCHR:
606 inode->i_rdev =
607 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
608 sysv_minor(ip->i_df.if_u2.if_rdev));
609 break;
610 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 inode->i_rdev = 0;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000612 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 inode->i_generation = ip->i_d.di_gen;
616 i_size_write(inode, ip->i_d.di_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
618 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
619 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
620 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
621 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
622 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
623 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
624 inode->i_flags |= S_IMMUTABLE;
625 else
626 inode->i_flags &= ~S_IMMUTABLE;
627 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
628 inode->i_flags |= S_APPEND;
629 else
630 inode->i_flags &= ~S_APPEND;
631 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
632 inode->i_flags |= S_SYNC;
633 else
634 inode->i_flags &= ~S_SYNC;
635 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
636 inode->i_flags |= S_NOATIME;
637 else
638 inode->i_flags &= ~S_NOATIME;
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +1000639 xfs_iflags_clear(ip, XFS_IMODIFIED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
642void
643xfs_initialize_vnode(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000644 struct xfs_mount *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000645 bhv_vnode_t *vp,
Christoph Hellwig745f6912007-08-30 17:20:39 +1000646 struct xfs_inode *ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647{
Nathan Scottec86dc02006-03-17 17:25:36 +1100648 struct inode *inode = vn_to_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000650 if (!ip->i_vnode) {
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000651 ip->i_vnode = vp;
652 inode->i_private = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 }
654
655 /*
656 * We need to set the ops vectors, and unlock the inode, but if
657 * we have been called during the new inode create process, it is
658 * too early to fill in the Linux inode. We will get called a
659 * second time once the inode is properly set up, and then we can
660 * finish our work.
661 */
Christoph Hellwig745f6912007-08-30 17:20:39 +1000662 if (ip->i_d.di_mode != 0 && (inode->i_state & I_NEW)) {
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000663 xfs_revalidate_inode(mp, vp, ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 xfs_set_inodeops(inode);
Nathan Scottec86dc02006-03-17 17:25:36 +1100665
David Chinner7a18c382006-11-11 18:04:54 +1100666 xfs_iflags_clear(ip, XFS_INEW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 barrier();
668
669 unlock_new_inode(inode);
670 }
671}
672
673int
674xfs_blkdev_get(
675 xfs_mount_t *mp,
676 const char *name,
677 struct block_device **bdevp)
678{
679 int error = 0;
680
681 *bdevp = open_bdev_excl(name, 0, mp);
682 if (IS_ERR(*bdevp)) {
683 error = PTR_ERR(*bdevp);
684 printk("XFS: Invalid device [%s], error=%d\n", name, error);
685 }
686
687 return -error;
688}
689
690void
691xfs_blkdev_put(
692 struct block_device *bdev)
693{
694 if (bdev)
695 close_bdev_excl(bdev);
696}
697
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100698/*
699 * Try to write out the superblock using barriers.
700 */
701STATIC int
702xfs_barrier_test(
703 xfs_mount_t *mp)
704{
705 xfs_buf_t *sbp = xfs_getsb(mp, 0);
706 int error;
707
708 XFS_BUF_UNDONE(sbp);
709 XFS_BUF_UNREAD(sbp);
710 XFS_BUF_UNDELAYWRITE(sbp);
711 XFS_BUF_WRITE(sbp);
712 XFS_BUF_UNASYNC(sbp);
713 XFS_BUF_ORDERED(sbp);
714
715 xfsbdstrat(mp, sbp);
716 error = xfs_iowait(sbp);
717
718 /*
719 * Clear all the flags we set and possible error state in the
720 * buffer. We only did the write to try out whether barriers
721 * worked and shouldn't leave any traces in the superblock
722 * buffer.
723 */
724 XFS_BUF_DONE(sbp);
725 XFS_BUF_ERROR(sbp, 0);
726 XFS_BUF_UNORDERED(sbp);
727
728 xfs_buf_relse(sbp);
729 return error;
730}
731
732void
733xfs_mountfs_check_barriers(xfs_mount_t *mp)
734{
735 int error;
736
737 if (mp->m_logdev_targp != mp->m_ddev_targp) {
738 xfs_fs_cmn_err(CE_NOTE, mp,
739 "Disabling barriers, not supported with external log device");
740 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100741 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100742 }
743
Nathan Scottce8e9222006-01-11 15:39:08 +1100744 if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100745 QUEUE_ORDERED_NONE) {
746 xfs_fs_cmn_err(CE_NOTE, mp,
747 "Disabling barriers, not supported by the underlying device");
748 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100749 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100750 }
751
Nathan Scottb2ea4012006-07-28 17:05:13 +1000752 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
753 xfs_fs_cmn_err(CE_NOTE, mp,
754 "Disabling barriers, underlying device is readonly");
755 mp->m_flags &= ~XFS_MOUNT_BARRIER;
756 return;
757 }
758
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100759 error = xfs_barrier_test(mp);
760 if (error) {
761 xfs_fs_cmn_err(CE_NOTE, mp,
762 "Disabling barriers, trial barrier write failed");
763 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100764 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100765 }
766}
767
768void
769xfs_blkdev_issue_flush(
770 xfs_buftarg_t *buftarg)
771{
Nathan Scottce8e9222006-01-11 15:39:08 +1100772 blkdev_issue_flush(buftarg->bt_bdev, NULL);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100773}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000775STATIC void
776xfs_close_devices(
777 struct xfs_mount *mp)
778{
779 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
780 xfs_free_buftarg(mp->m_logdev_targp);
781 xfs_blkdev_put(mp->m_logdev_targp->bt_bdev);
782 }
783 if (mp->m_rtdev_targp) {
784 xfs_free_buftarg(mp->m_rtdev_targp);
785 xfs_blkdev_put(mp->m_rtdev_targp->bt_bdev);
786 }
787 xfs_free_buftarg(mp->m_ddev_targp);
788}
789
790/*
791 * The file system configurations are:
792 * (1) device (partition) with data and internal log
793 * (2) logical volume with data and log subvolumes.
794 * (3) logical volume with data, log, and realtime subvolumes.
795 *
796 * We only have to handle opening the log and realtime volumes here if
797 * they are present. The data subvolume has already been opened by
798 * get_sb_bdev() and is stored in sb->s_bdev.
799 */
800STATIC int
801xfs_open_devices(
802 struct xfs_mount *mp,
803 struct xfs_mount_args *args)
804{
805 struct block_device *ddev = mp->m_super->s_bdev;
806 struct block_device *logdev = NULL, *rtdev = NULL;
807 int error;
808
809 /*
810 * Open real time and log devices - order is important.
811 */
812 if (args->logname[0]) {
813 error = xfs_blkdev_get(mp, args->logname, &logdev);
814 if (error)
815 goto out;
816 }
817
818 if (args->rtname[0]) {
819 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
820 if (error)
821 goto out_close_logdev;
822
823 if (rtdev == ddev || rtdev == logdev) {
824 cmn_err(CE_WARN,
825 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
826 error = EINVAL;
827 goto out_close_rtdev;
828 }
829 }
830
831 /*
832 * Setup xfs_mount buffer target pointers
833 */
834 error = ENOMEM;
835 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
836 if (!mp->m_ddev_targp)
837 goto out_close_rtdev;
838
839 if (rtdev) {
840 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
841 if (!mp->m_rtdev_targp)
842 goto out_free_ddev_targ;
843 }
844
845 if (logdev && logdev != ddev) {
846 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
847 if (!mp->m_logdev_targp)
848 goto out_free_rtdev_targ;
849 } else {
850 mp->m_logdev_targp = mp->m_ddev_targp;
851 }
852
853 return 0;
854
855 out_free_rtdev_targ:
856 if (mp->m_rtdev_targp)
857 xfs_free_buftarg(mp->m_rtdev_targp);
858 out_free_ddev_targ:
859 xfs_free_buftarg(mp->m_ddev_targp);
860 out_close_rtdev:
861 if (rtdev)
862 xfs_blkdev_put(rtdev);
863 out_close_logdev:
864 if (logdev && logdev != ddev)
865 xfs_blkdev_put(logdev);
866 out:
867 return error;
868}
869
Christoph Hellwige34b5622008-05-20 15:10:36 +1000870/*
871 * Setup xfs_mount buffer target pointers based on superblock
872 */
873STATIC int
874xfs_setup_devices(
875 struct xfs_mount *mp)
876{
877 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000878
Christoph Hellwige34b5622008-05-20 15:10:36 +1000879 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
880 mp->m_sb.sb_sectsize);
881 if (error)
882 return error;
883
884 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
885 unsigned int log_sector_size = BBSIZE;
886
887 if (xfs_sb_version_hassector(&mp->m_sb))
888 log_sector_size = mp->m_sb.sb_logsectsize;
889 error = xfs_setsize_buftarg(mp->m_logdev_targp,
890 mp->m_sb.sb_blocksize,
891 log_sector_size);
892 if (error)
893 return error;
894 }
895 if (mp->m_rtdev_targp) {
896 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
897 mp->m_sb.sb_blocksize,
898 mp->m_sb.sb_sectsize);
899 if (error)
900 return error;
901 }
902
903 return 0;
904}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000905
David Chinner249a8c12008-02-05 12:13:32 +1100906/*
907 * XFS AIL push thread support
908 */
909void
910xfsaild_wakeup(
911 xfs_mount_t *mp,
912 xfs_lsn_t threshold_lsn)
913{
914 mp->m_ail.xa_target = threshold_lsn;
915 wake_up_process(mp->m_ail.xa_task);
916}
917
918int
919xfsaild(
920 void *data)
921{
922 xfs_mount_t *mp = (xfs_mount_t *)data;
923 xfs_lsn_t last_pushed_lsn = 0;
924 long tout = 0;
925
926 while (!kthread_should_stop()) {
927 if (tout)
928 schedule_timeout_interruptible(msecs_to_jiffies(tout));
929 tout = 1000;
930
931 /* swsusp */
932 try_to_freeze();
933
934 ASSERT(mp->m_log);
935 if (XFS_FORCED_SHUTDOWN(mp))
936 continue;
937
938 tout = xfsaild_push(mp, &last_pushed_lsn);
939 }
940
941 return 0;
942} /* xfsaild */
943
944int
945xfsaild_start(
946 xfs_mount_t *mp)
947{
948 mp->m_ail.xa_target = 0;
949 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
950 if (IS_ERR(mp->m_ail.xa_task))
951 return -PTR_ERR(mp->m_ail.xa_task);
952 return 0;
953}
954
955void
956xfsaild_stop(
957 xfs_mount_t *mp)
958{
959 kthread_stop(mp->m_ail.xa_task);
960}
961
962
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100965xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 struct super_block *sb)
967{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000968 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Nathan Scott87582802006-03-14 13:18:19 +1100970 vp = kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
971 if (unlikely(!vp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 return NULL;
Nathan Scottec86dc02006-03-17 17:25:36 +1100973 return vn_to_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
976STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100977xfs_fs_destroy_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 struct inode *inode)
979{
Nathan Scottec86dc02006-03-17 17:25:36 +1100980 kmem_zone_free(xfs_vnode_zone, vn_from_inode(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981}
982
983STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100984xfs_fs_inode_init_once(
Christoph Lameter4ba9b9d2007-10-16 23:25:51 -0700985 void *vnode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986{
Christoph Lametera35afb82007-05-16 22:10:57 -0700987 inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988}
989
Lachlan McIlroyde2eeea2008-02-06 13:37:56 +1100990STATIC int __init
Nathan Scott87582802006-03-14 13:18:19 +1100991xfs_init_zones(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000993 xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
Nathan Scotte0cc2322006-03-14 13:19:55 +1100994 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
995 KM_ZONE_SPREAD,
Nathan Scotta50cd262006-03-14 14:06:18 +1100996 xfs_fs_inode_init_once);
Christoph Hellwig0829c362005-09-02 16:58:49 +1000997 if (!xfs_vnode_zone)
998 goto out;
999
1000 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1001 if (!xfs_ioend_zone)
1002 goto out_destroy_vnode_zone;
1003
Matthew Dobson93d23412006-03-26 01:37:50 -08001004 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1005 xfs_ioend_zone);
Christoph Hellwig0829c362005-09-02 16:58:49 +10001006 if (!xfs_ioend_pool)
1007 goto out_free_ioend_zone;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 return 0;
Christoph Hellwig0829c362005-09-02 16:58:49 +10001009
Christoph Hellwig0829c362005-09-02 16:58:49 +10001010 out_free_ioend_zone:
1011 kmem_zone_destroy(xfs_ioend_zone);
1012 out_destroy_vnode_zone:
1013 kmem_zone_destroy(xfs_vnode_zone);
1014 out:
1015 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016}
1017
1018STATIC void
Nathan Scott87582802006-03-14 13:18:19 +11001019xfs_destroy_zones(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020{
Christoph Hellwig0829c362005-09-02 16:58:49 +10001021 mempool_destroy(xfs_ioend_pool);
1022 kmem_zone_destroy(xfs_vnode_zone);
1023 kmem_zone_destroy(xfs_ioend_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024}
1025
1026/*
1027 * Attempt to flush the inode, this will actually fail
1028 * if the inode is pinned, but we dirty the inode again
1029 * at the point when it is unpinned after a log write,
Nathan Scott87582802006-03-14 13:18:19 +11001030 * since this is when the inode itself becomes flushable.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 */
1032STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001033xfs_fs_write_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 struct inode *inode,
1035 int sync)
1036{
David Chinnera3f74ff2008-03-06 13:43:42 +11001037 int error = 0;
1038 int flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001040 xfs_itrace_entry(XFS_I(inode));
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001041 if (sync) {
1042 filemap_fdatawait(inode->i_mapping);
1043 flags |= FLUSH_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 }
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001045 error = xfs_inode_flush(XFS_I(inode), flags);
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001046 /*
1047 * if we failed to write out the inode then mark
1048 * it dirty again so we'll try again later.
1049 */
1050 if (error)
1051 mark_inode_dirty_sync(inode);
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 return -error;
1054}
1055
1056STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001057xfs_fs_clear_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 struct inode *inode)
1059{
Christoph Hellwig1543d792007-08-29 11:46:47 +10001060 xfs_inode_t *ip = XFS_I(inode);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001061
Christoph Hellwig02ba71d2005-09-05 08:28:02 +10001062 /*
Christoph Hellwig1543d792007-08-29 11:46:47 +10001063 * ip can be null when xfs_iget_core calls xfs_idestroy if we
Christoph Hellwig02ba71d2005-09-05 08:28:02 +10001064 * find an inode with di_mode == 0 but without IGET_CREATE set.
1065 */
Christoph Hellwig1543d792007-08-29 11:46:47 +10001066 if (ip) {
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001067 xfs_itrace_entry(ip);
Christoph Hellwig1543d792007-08-29 11:46:47 +10001068 XFS_STATS_INC(vn_rele);
1069 XFS_STATS_INC(vn_remove);
1070 XFS_STATS_INC(vn_reclaim);
1071 XFS_STATS_DEC(vn_active);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001072
Christoph Hellwig1543d792007-08-29 11:46:47 +10001073 xfs_inactive(ip);
1074 xfs_iflags_clear(ip, XFS_IMODIFIED);
1075 if (xfs_reclaim(ip))
Harvey Harrison34a622b2008-04-10 12:19:21 +10001076 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +10001077 }
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001078
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001079 ASSERT(XFS_I(inode) == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080}
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082/*
1083 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
1084 * Doing this has two advantages:
1085 * - It saves on stack space, which is tight in certain situations
1086 * - It can be used (with care) as a mechanism to avoid deadlocks.
1087 * Flushing while allocating in a full filesystem requires both.
1088 */
1089STATIC void
1090xfs_syncd_queue_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001091 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 void *data,
Christoph Hellwig74394492007-08-30 17:21:22 +10001093 void (*syncer)(struct xfs_mount *, void *))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Nathan Scottb83bd132006-06-09 16:48:30 +10001095 struct bhv_vfs_sync_work *work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
Nathan Scottb83bd132006-06-09 16:48:30 +10001097 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 INIT_LIST_HEAD(&work->w_list);
1099 work->w_syncer = syncer;
1100 work->w_data = data;
Christoph Hellwig74394492007-08-30 17:21:22 +10001101 work->w_mount = mp;
1102 spin_lock(&mp->m_sync_lock);
1103 list_add_tail(&work->w_list, &mp->m_sync_list);
1104 spin_unlock(&mp->m_sync_lock);
1105 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
1108/*
1109 * Flush delayed allocate data, attempting to free up reserved space
1110 * from existing allocations. At this point a new allocation attempt
1111 * has failed with ENOSPC and we are in the process of scratching our
1112 * heads, looking about for more room...
1113 */
1114STATIC void
1115xfs_flush_inode_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001116 struct xfs_mount *mp,
1117 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118{
Christoph Hellwig74394492007-08-30 17:21:22 +10001119 struct inode *inode = arg;
1120 filemap_flush(inode->i_mapping);
1121 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
1124void
1125xfs_flush_inode(
1126 xfs_inode_t *ip)
1127{
Christoph Hellwig74394492007-08-30 17:21:22 +10001128 struct inode *inode = ip->i_vnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 igrab(inode);
Christoph Hellwig74394492007-08-30 17:21:22 +10001131 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001132 delay(msecs_to_jiffies(500));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
1135/*
1136 * This is the "bigger hammer" version of xfs_flush_inode_work...
1137 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1138 */
1139STATIC void
1140xfs_flush_device_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001141 struct xfs_mount *mp,
1142 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143{
Christoph Hellwig74394492007-08-30 17:21:22 +10001144 struct inode *inode = arg;
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001145 sync_blockdev(mp->m_super->s_bdev);
Christoph Hellwig74394492007-08-30 17:21:22 +10001146 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147}
1148
1149void
1150xfs_flush_device(
1151 xfs_inode_t *ip)
1152{
Nathan Scottec86dc02006-03-17 17:25:36 +11001153 struct inode *inode = vn_to_inode(XFS_ITOV(ip));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
1155 igrab(inode);
Christoph Hellwig74394492007-08-30 17:21:22 +10001156 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001157 delay(msecs_to_jiffies(500));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1159}
1160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161STATIC void
Christoph Hellwig74394492007-08-30 17:21:22 +10001162xfs_sync_worker(
1163 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 void *unused)
1165{
1166 int error;
1167
Christoph Hellwig74394492007-08-30 17:21:22 +10001168 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
David Chinner7e206942008-04-17 16:49:55 +10001169 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
Christoph Hellwig74394492007-08-30 17:21:22 +10001170 mp->m_sync_seq++;
1171 wake_up(&mp->m_wait_single_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172}
1173
1174STATIC int
1175xfssyncd(
1176 void *arg)
1177{
Christoph Hellwig74394492007-08-30 17:21:22 +10001178 struct xfs_mount *mp = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 long timeleft;
Nathan Scottb83bd132006-06-09 16:48:30 +10001180 bhv_vfs_sync_work_t *work, *n;
Christoph Hellwig4df08c52005-09-05 08:34:18 +10001181 LIST_HEAD (tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Rafael J. Wysocki83144182007-07-17 04:03:35 -07001183 set_freezable();
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001184 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 for (;;) {
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001186 timeleft = schedule_timeout_interruptible(timeleft);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 /* swsusp */
Christoph Lameter3e1d1d22005-06-24 23:13:50 -07001188 try_to_freeze();
Christoph Hellwig74394492007-08-30 17:21:22 +10001189 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 break;
1191
Christoph Hellwig74394492007-08-30 17:21:22 +10001192 spin_lock(&mp->m_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 /*
1194 * We can get woken by laptop mode, to do a sync -
1195 * that's the (only!) case where the list would be
1196 * empty with time remaining.
1197 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001198 if (!timeleft || list_empty(&mp->m_sync_list)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 if (!timeleft)
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001200 timeleft = xfs_syncd_centisecs *
1201 msecs_to_jiffies(10);
Christoph Hellwig74394492007-08-30 17:21:22 +10001202 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1203 list_add_tail(&mp->m_sync_work.w_list,
1204 &mp->m_sync_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001206 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 list_move(&work->w_list, &tmp);
Christoph Hellwig74394492007-08-30 17:21:22 +10001208 spin_unlock(&mp->m_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
1210 list_for_each_entry_safe(work, n, &tmp, w_list) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001211 (*work->w_syncer)(mp, work->w_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 list_del(&work->w_list);
Christoph Hellwig74394492007-08-30 17:21:22 +10001213 if (work == &mp->m_sync_work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 continue;
Denys Vlasenkof0e2d932008-05-19 16:31:57 +10001215 kmem_free(work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 }
1217 }
1218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 return 0;
1220}
1221
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001223xfs_fs_put_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 struct super_block *sb)
1225{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001226 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001227 struct xfs_inode *rip = mp->m_rootip;
1228 int unmount_event_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 int error;
1230
Christoph Hellwig74394492007-08-30 17:21:22 +10001231 kthread_stop(mp->m_sync_task);
1232
Christoph Hellwig745f6912007-08-30 17:20:39 +10001233 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001234
1235#ifdef HAVE_DMAPI
1236 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1237 unmount_event_flags =
1238 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1239 0 : DM_FLAGS_UNWANTED;
1240 /*
1241 * Ignore error from dmapi here, first unmount is not allowed
1242 * to fail anyway, and second we wouldn't want to fail a
1243 * unmount because of dmapi.
1244 */
1245 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1246 NULL, NULL, 0, 0, unmount_event_flags);
1247 }
1248#endif
1249
1250 /*
1251 * Blow away any referenced inode in the filestreams cache.
1252 * This can and will cause log traffic as inodes go inactive
1253 * here.
1254 */
1255 xfs_filestream_unmount(mp);
1256
1257 XFS_bflush(mp->m_ddev_targp);
1258 error = xfs_unmount_flush(mp, 0);
1259 WARN_ON(error);
1260
1261 IRELE(rip);
1262
1263 /*
1264 * If we're forcing a shutdown, typically because of a media error,
1265 * we want to make sure we invalidate dirty pages that belong to
1266 * referenced vnodes as well.
1267 */
1268 if (XFS_FORCED_SHUTDOWN(mp)) {
1269 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1270 ASSERT(error != EFSCORRUPTED);
1271 }
1272
1273 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1274 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1275 unmount_event_flags);
1276 }
1277
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001278 xfs_unmountfs(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001279 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001280 xfs_close_devices(mp);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001281 xfs_qmops_put(mp);
1282 xfs_dmops_put(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001283 kfree(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284}
1285
1286STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001287xfs_fs_write_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 struct super_block *sb)
1289{
Nathan Scottb83bd132006-06-09 16:48:30 +10001290 if (!(sb->s_flags & MS_RDONLY))
Christoph Hellwig745f6912007-08-30 17:20:39 +10001291 xfs_sync(XFS_M(sb), SYNC_FSDATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 sb->s_dirt = 0;
1293}
1294
1295STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001296xfs_fs_sync_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 struct super_block *sb,
1298 int wait)
1299{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001300 struct xfs_mount *mp = XFS_M(sb);
Nathan Scottb83bd132006-06-09 16:48:30 +10001301 int error;
1302 int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001304 /*
1305 * Treat a sync operation like a freeze. This is to work
1306 * around a race in sync_inodes() which works in two phases
1307 * - an asynchronous flush, which can write out an inode
1308 * without waiting for file size updates to complete, and a
1309 * synchronous flush, which wont do anything because the
1310 * async flush removed the inode's dirty flag. Also
1311 * sync_inodes() will not see any files that just have
1312 * outstanding transactions to be flushed because we don't
1313 * dirty the Linux inode until after the transaction I/O
1314 * completes.
1315 */
1316 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
David Chinner28239452007-02-10 18:36:40 +11001317 /*
1318 * First stage of freeze - no more writers will make progress
1319 * now we are here, so we flush delwri and delalloc buffers
1320 * here, then wait for all I/O to complete. Data is frozen at
1321 * that point. Metadata is not frozen, transactions can still
1322 * occur here so don't bother flushing the buftarg (i.e
1323 * SYNC_QUIESCE) because it'll just get dirty again.
1324 */
David Chinner516b2e72007-06-18 16:50:48 +10001325 flags = SYNC_DATA_QUIESCE;
David Chinner28239452007-02-10 18:36:40 +11001326 } else
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001327 flags = SYNC_FSDATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Christoph Hellwig745f6912007-08-30 17:20:39 +10001329 error = xfs_sync(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 sb->s_dirt = 0;
1331
1332 if (unlikely(laptop_mode)) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001333 int prev_sync_seq = mp->m_sync_seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
1335 /*
1336 * The disk must be active because we're syncing.
1337 * We schedule xfssyncd now (now that the disk is
1338 * active) instead of later (when it might not be).
1339 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001340 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 /*
1342 * We have to wait for the sync iteration to complete.
1343 * If we don't, the disk activity caused by the sync
1344 * will come after the sync is completed, and that
1345 * triggers another sync from laptop mode.
1346 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001347 wait_event(mp->m_wait_single_sync_task,
1348 mp->m_sync_seq != prev_sync_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 }
1350
1351 return -error;
1352}
1353
1354STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001355xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001356 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 struct kstatfs *statp)
1358{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001359 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1360 xfs_sb_t *sbp = &mp->m_sb;
1361 __uint64_t fakeinos, id;
1362 xfs_extlen_t lsize;
1363
1364 statp->f_type = XFS_SB_MAGIC;
1365 statp->f_namelen = MAXNAMELEN - 1;
1366
1367 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1368 statp->f_fsid.val[0] = (u32)id;
1369 statp->f_fsid.val[1] = (u32)(id >> 32);
1370
Christoph Hellwigd4d90b52008-04-22 17:34:37 +10001371 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001372
1373 spin_lock(&mp->m_sb_lock);
1374 statp->f_bsize = sbp->sb_blocksize;
1375 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1376 statp->f_blocks = sbp->sb_dblocks - lsize;
1377 statp->f_bfree = statp->f_bavail =
1378 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1379 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1380#if XFS_BIG_INUMS
1381 fakeinos += mp->m_inoadd;
1382#endif
1383 statp->f_files =
1384 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1385 if (mp->m_maxicount)
1386#if XFS_BIG_INUMS
1387 if (!mp->m_inoadd)
1388#endif
1389 statp->f_files = min_t(typeof(statp->f_files),
1390 statp->f_files,
1391 mp->m_maxicount);
1392 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1393 spin_unlock(&mp->m_sb_lock);
1394
1395 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1396 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397}
1398
1399STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001400xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 struct super_block *sb,
1402 int *flags,
1403 char *options)
1404{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001405 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001406 struct xfs_mount_args *args;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 int error;
1408
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001409 args = xfs_args_allocate(sb, 0);
1410 if (!args)
1411 return -ENOMEM;
1412
Christoph Hellwig745f6912007-08-30 17:20:39 +10001413 error = xfs_parseargs(mp, options, args, 1);
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001414 if (error)
1415 goto out_free_args;
1416
1417 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
1418 if (mp->m_flags & XFS_MOUNT_RDONLY)
1419 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1420 if (args->flags & XFSMNT_BARRIER) {
1421 mp->m_flags |= XFS_MOUNT_BARRIER;
1422 xfs_mountfs_check_barriers(mp);
1423 } else {
1424 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1425 }
1426 } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
1427 xfs_filestream_flush(mp);
1428 xfs_sync(mp, SYNC_DATA_QUIESCE);
1429 xfs_attr_quiesce(mp);
1430 mp->m_flags |= XFS_MOUNT_RDONLY;
1431 }
1432
1433 out_free_args:
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001434 kfree(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 return -error;
1436}
1437
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001438/*
1439 * Second stage of a freeze. The data is already frozen so we only
1440 * need to take care of themetadata. Once that's done write a dummy
1441 * record to dirty the log in case of a crash while frozen.
1442 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001444xfs_fs_lockfs(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 struct super_block *sb)
1446{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001447 struct xfs_mount *mp = XFS_M(sb);
1448
1449 xfs_attr_quiesce(mp);
1450 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451}
1452
1453STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001454xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 struct seq_file *m,
1456 struct vfsmount *mnt)
1457{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001458 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459}
1460
1461STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001462xfs_fs_quotasync(
Nathan Scottee348072005-11-02 10:32:38 +11001463 struct super_block *sb,
1464 int type)
1465{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001466 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
Nathan Scottee348072005-11-02 10:32:38 +11001467}
1468
1469STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001470xfs_fs_getxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 struct super_block *sb,
1472 struct fs_quota_stat *fqs)
1473{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001474 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475}
1476
1477STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001478xfs_fs_setxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 struct super_block *sb,
1480 unsigned int flags,
1481 int op)
1482{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001483 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484}
1485
1486STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001487xfs_fs_getxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 struct super_block *sb,
1489 int type,
1490 qid_t id,
1491 struct fs_disk_quota *fdq)
1492{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001493 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001494 (type == USRQUOTA) ? Q_XGETQUOTA :
1495 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1496 Q_XGETPQUOTA), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497}
1498
1499STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001500xfs_fs_setxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 struct super_block *sb,
1502 int type,
1503 qid_t id,
1504 struct fs_disk_quota *fdq)
1505{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001506 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001507 (type == USRQUOTA) ? Q_XSETQLIM :
1508 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1509 Q_XSETPQLIM), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001512/*
1513 * This function fills in xfs_mount_t fields based on mount args.
1514 * Note: the superblock has _not_ yet been read in.
1515 */
1516STATIC int
1517xfs_start_flags(
1518 struct xfs_mount_args *ap,
1519 struct xfs_mount *mp)
1520{
1521 /* Values are in BBs */
1522 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1523 /*
1524 * At this point the superblock has not been read
1525 * in, therefore we do not know the block size.
1526 * Before the mount call ends we will convert
1527 * these to FSBs.
1528 */
1529 mp->m_dalign = ap->sunit;
1530 mp->m_swidth = ap->swidth;
1531 }
1532
1533 if (ap->logbufs != -1 &&
1534 ap->logbufs != 0 &&
1535 (ap->logbufs < XLOG_MIN_ICLOGS ||
1536 ap->logbufs > XLOG_MAX_ICLOGS)) {
1537 cmn_err(CE_WARN,
1538 "XFS: invalid logbufs value: %d [not %d-%d]",
1539 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1540 return XFS_ERROR(EINVAL);
1541 }
1542 mp->m_logbufs = ap->logbufs;
1543 if (ap->logbufsize != -1 &&
1544 ap->logbufsize != 0 &&
1545 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1546 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1547 !is_power_of_2(ap->logbufsize))) {
1548 cmn_err(CE_WARN,
1549 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1550 ap->logbufsize);
1551 return XFS_ERROR(EINVAL);
1552 }
1553 mp->m_logbsize = ap->logbufsize;
1554 mp->m_fsname_len = strlen(ap->fsname) + 1;
1555 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
1556 strcpy(mp->m_fsname, ap->fsname);
1557 if (ap->rtname[0]) {
1558 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
1559 strcpy(mp->m_rtname, ap->rtname);
1560 }
1561 if (ap->logname[0]) {
1562 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
1563 strcpy(mp->m_logname, ap->logname);
1564 }
1565
1566 if (ap->flags & XFSMNT_WSYNC)
1567 mp->m_flags |= XFS_MOUNT_WSYNC;
1568#if XFS_BIG_INUMS
1569 if (ap->flags & XFSMNT_INO64) {
1570 mp->m_flags |= XFS_MOUNT_INO64;
1571 mp->m_inoadd = XFS_INO64_OFFSET;
1572 }
1573#endif
1574 if (ap->flags & XFSMNT_RETERR)
1575 mp->m_flags |= XFS_MOUNT_RETERR;
1576 if (ap->flags & XFSMNT_NOALIGN)
1577 mp->m_flags |= XFS_MOUNT_NOALIGN;
1578 if (ap->flags & XFSMNT_SWALLOC)
1579 mp->m_flags |= XFS_MOUNT_SWALLOC;
1580 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1581 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1582 if (ap->flags & XFSMNT_32BITINODES)
1583 mp->m_flags |= XFS_MOUNT_32BITINODES;
1584
1585 if (ap->flags & XFSMNT_IOSIZE) {
1586 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1587 ap->iosizelog < XFS_MIN_IO_LOG) {
1588 cmn_err(CE_WARN,
1589 "XFS: invalid log iosize: %d [not %d-%d]",
1590 ap->iosizelog, XFS_MIN_IO_LOG,
1591 XFS_MAX_IO_LOG);
1592 return XFS_ERROR(EINVAL);
1593 }
1594
1595 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1596 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1597 }
1598
1599 if (ap->flags & XFSMNT_IKEEP)
1600 mp->m_flags |= XFS_MOUNT_IKEEP;
1601 if (ap->flags & XFSMNT_DIRSYNC)
1602 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1603 if (ap->flags & XFSMNT_ATTR2)
1604 mp->m_flags |= XFS_MOUNT_ATTR2;
1605 if (ap->flags & XFSMNT_NOATTR2)
1606 mp->m_flags |= XFS_MOUNT_NOATTR2;
1607
1608 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1609 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1610
1611 /*
1612 * no recovery flag requires a read-only mount
1613 */
1614 if (ap->flags & XFSMNT_NORECOVERY) {
1615 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1616 cmn_err(CE_WARN,
1617 "XFS: tried to mount a FS read-write without recovery!");
1618 return XFS_ERROR(EINVAL);
1619 }
1620 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1621 }
1622
1623 if (ap->flags & XFSMNT_NOUUID)
1624 mp->m_flags |= XFS_MOUNT_NOUUID;
1625 if (ap->flags & XFSMNT_BARRIER)
1626 mp->m_flags |= XFS_MOUNT_BARRIER;
1627 else
1628 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1629
1630 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1631 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1632
1633 if (ap->flags & XFSMNT_DMAPI)
1634 mp->m_flags |= XFS_MOUNT_DMAPI;
1635 return 0;
1636}
1637
1638/*
1639 * This function fills in xfs_mount_t fields based on mount args.
1640 * Note: the superblock _has_ now been read in.
1641 */
1642STATIC int
1643xfs_finish_flags(
1644 struct xfs_mount_args *ap,
1645 struct xfs_mount *mp)
1646{
1647 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1648
1649 /* Fail a mount where the logbuf is smaller then the log stripe */
1650 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1651 if ((ap->logbufsize <= 0) &&
1652 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1653 mp->m_logbsize = mp->m_sb.sb_logsunit;
1654 } else if (ap->logbufsize > 0 &&
1655 ap->logbufsize < mp->m_sb.sb_logsunit) {
1656 cmn_err(CE_WARN,
1657 "XFS: logbuf size must be greater than or equal to log stripe size");
1658 return XFS_ERROR(EINVAL);
1659 }
1660 } else {
1661 /* Fail a mount if the logbuf is larger than 32K */
1662 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1663 cmn_err(CE_WARN,
1664 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1665 return XFS_ERROR(EINVAL);
1666 }
1667 }
1668
1669 /*
1670 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1671 * told by noattr2 to turn it off
1672 */
1673 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1674 !(ap->flags & XFSMNT_NOATTR2))
1675 mp->m_flags |= XFS_MOUNT_ATTR2;
1676
1677 /*
1678 * prohibit r/w mounts of read-only filesystems
1679 */
1680 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1681 cmn_err(CE_WARN,
1682 "XFS: cannot mount a read-only filesystem as read-write");
1683 return XFS_ERROR(EROFS);
1684 }
1685
1686 /*
1687 * check for shared mount.
1688 */
1689 if (ap->flags & XFSMNT_SHARED) {
1690 if (!xfs_sb_version_hasshared(&mp->m_sb))
1691 return XFS_ERROR(EINVAL);
1692
1693 /*
1694 * For IRIX 6.5, shared mounts must have the shared
1695 * version bit set, have the persistent readonly
1696 * field set, must be version 0 and can only be mounted
1697 * read-only.
1698 */
1699 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1700 (mp->m_sb.sb_shared_vn != 0))
1701 return XFS_ERROR(EINVAL);
1702
1703 mp->m_flags |= XFS_MOUNT_SHARED;
1704
1705 /*
1706 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1707 */
1708 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1709 return XFS_ERROR(EINVAL);
1710 }
1711
1712 if (ap->flags & XFSMNT_UQUOTA) {
1713 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1714 if (ap->flags & XFSMNT_UQUOTAENF)
1715 mp->m_qflags |= XFS_UQUOTA_ENFD;
1716 }
1717
1718 if (ap->flags & XFSMNT_GQUOTA) {
1719 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1720 if (ap->flags & XFSMNT_GQUOTAENF)
1721 mp->m_qflags |= XFS_OQUOTA_ENFD;
1722 } else if (ap->flags & XFSMNT_PQUOTA) {
1723 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1724 if (ap->flags & XFSMNT_PQUOTAENF)
1725 mp->m_qflags |= XFS_OQUOTA_ENFD;
1726 }
1727
1728 return 0;
1729}
1730
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001732xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 struct super_block *sb,
1734 void *data,
1735 int silent)
1736{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001737 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001738 struct xfs_mount *mp = NULL;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001739 struct xfs_mount_args *args;
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001740 int flags = 0, error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001742 args = xfs_args_allocate(sb, silent);
1743 if (!args)
1744 return -ENOMEM;
1745
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001746 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1747 if (!mp)
1748 goto out_free_args;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001750 spin_lock_init(&mp->m_sb_lock);
1751 mutex_init(&mp->m_ilock);
1752 mutex_init(&mp->m_growlock);
1753 atomic_set(&mp->m_active_trans, 0);
Christoph Hellwig74394492007-08-30 17:21:22 +10001754 INIT_LIST_HEAD(&mp->m_sync_list);
1755 spin_lock_init(&mp->m_sync_lock);
1756 init_waitqueue_head(&mp->m_wait_single_sync_task);
1757
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001758 mp->m_super = sb;
1759 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001761 if (sb->s_flags & MS_RDONLY)
1762 mp->m_flags |= XFS_MOUNT_RDONLY;
1763
Christoph Hellwig745f6912007-08-30 17:20:39 +10001764 error = xfs_parseargs(mp, (char *)data, args, 0);
1765 if (error)
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001766 goto out_free_mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
1768 sb_min_blocksize(sb, BBSIZE);
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001769 sb->s_xattr = xfs_xattr_handlers;
Nathan Scotta50cd262006-03-14 14:06:18 +11001770 sb->s_export_op = &xfs_export_operations;
Nathan Scotta50cd262006-03-14 14:06:18 +11001771 sb->s_qcop = &xfs_quotactl_operations;
1772 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001774 error = xfs_dmops_get(mp, args);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001775 if (error)
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001776 goto out_free_mp;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001777 error = xfs_qmops_get(mp, args);
1778 if (error)
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001779 goto out_put_dmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001780
1781 if (args->flags & XFSMNT_QUIET)
1782 flags |= XFS_MFSI_QUIET;
1783
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001784 error = xfs_open_devices(mp, args);
1785 if (error)
1786 goto out_put_qmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001787
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001788 if (xfs_icsb_init_counters(mp))
1789 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1790
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001791 /*
1792 * Setup flags based on mount(2) options and then the superblock
1793 */
1794 error = xfs_start_flags(args, mp);
1795 if (error)
Christoph Hellwig95db4e22008-05-20 15:10:58 +10001796 goto out_destroy_counters;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001797 error = xfs_readsb(mp, flags);
1798 if (error)
Christoph Hellwig95db4e22008-05-20 15:10:58 +10001799 goto out_destroy_counters;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001800 error = xfs_finish_flags(args, mp);
1801 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001802 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001803
Christoph Hellwige34b5622008-05-20 15:10:36 +10001804 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001805 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001806 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001807
1808 if (mp->m_flags & XFS_MOUNT_BARRIER)
1809 xfs_mountfs_check_barriers(mp);
1810
1811 error = xfs_filestream_mount(mp);
1812 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001813 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001814
1815 error = xfs_mountfs(mp, flags);
1816 if (error)
Christoph Hellwig120226c2008-05-20 15:11:11 +10001817 goto out_filestream_unmount;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001818
1819 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 sb->s_dirt = 1;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001822 sb->s_magic = XFS_SB_MAGIC;
1823 sb->s_blocksize = mp->m_sb.sb_blocksize;
1824 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1826 sb->s_time_gran = 1;
1827 set_posix_acl_flag(sb);
1828
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001829 root = igrab(mp->m_rootip->i_vnode);
1830 if (!root) {
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001831 error = ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 goto fail_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001833 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001834 if (is_bad_inode(root)) {
1835 error = EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 goto fail_vnrele;
1837 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001838 sb->s_root = d_alloc_root(root);
1839 if (!sb->s_root) {
1840 error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 goto fail_vnrele;
1842 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001843
1844 mp->m_sync_work.w_syncer = xfs_sync_worker;
1845 mp->m_sync_work.w_mount = mp;
1846 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1847 if (IS_ERR(mp->m_sync_task)) {
1848 error = -PTR_ERR(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 goto fail_vnrele;
Christoph Hellwig74394492007-08-30 17:21:22 +10001850 }
1851
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001852 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001854 kfree(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 return 0;
1856
Christoph Hellwig120226c2008-05-20 15:11:11 +10001857 out_filestream_unmount:
1858 xfs_filestream_unmount(mp);
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001859 out_free_sb:
1860 xfs_freesb(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001861 out_destroy_counters:
1862 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001863 xfs_close_devices(mp);
1864 out_put_qmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001865 xfs_qmops_put(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001866 out_put_dmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001867 xfs_dmops_put(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001868 out_free_mp:
1869 kfree(mp);
1870 out_free_args:
1871 kfree(args);
1872 return -error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001873
1874 fail_vnrele:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 if (sb->s_root) {
1876 dput(sb->s_root);
1877 sb->s_root = NULL;
1878 } else {
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001879 iput(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 }
1881
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001882 fail_unmount:
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001883 /*
1884 * Blow away any referenced inode in the filestreams cache.
1885 * This can and will cause log traffic as inodes go inactive
1886 * here.
1887 */
1888 xfs_filestream_unmount(mp);
1889
1890 XFS_bflush(mp->m_ddev_targp);
1891 error = xfs_unmount_flush(mp, 0);
1892 WARN_ON(error);
1893
1894 IRELE(mp->m_rootip);
1895
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001896 xfs_unmountfs(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001897 goto out_destroy_counters;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898}
1899
David Howells454e2392006-06-23 02:02:57 -07001900STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001901xfs_fs_get_sb(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 struct file_system_type *fs_type,
1903 int flags,
1904 const char *dev_name,
David Howells454e2392006-06-23 02:02:57 -07001905 void *data,
1906 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907{
David Howells454e2392006-06-23 02:02:57 -07001908 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1909 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910}
1911
David Chinner7989cb82007-02-10 18:34:56 +11001912static struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001913 .alloc_inode = xfs_fs_alloc_inode,
1914 .destroy_inode = xfs_fs_destroy_inode,
1915 .write_inode = xfs_fs_write_inode,
1916 .clear_inode = xfs_fs_clear_inode,
1917 .put_super = xfs_fs_put_super,
1918 .write_super = xfs_fs_write_super,
1919 .sync_fs = xfs_fs_sync_super,
1920 .write_super_lockfs = xfs_fs_lockfs,
1921 .statfs = xfs_fs_statfs,
1922 .remount_fs = xfs_fs_remount,
1923 .show_options = xfs_fs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924};
1925
David Chinner7989cb82007-02-10 18:34:56 +11001926static struct quotactl_ops xfs_quotactl_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001927 .quota_sync = xfs_fs_quotasync,
1928 .get_xstate = xfs_fs_getxstate,
1929 .set_xstate = xfs_fs_setxstate,
1930 .get_xquota = xfs_fs_getxquota,
1931 .set_xquota = xfs_fs_setxquota,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932};
1933
Andrew Morton5085b602007-02-20 13:57:47 -08001934static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 .owner = THIS_MODULE,
1936 .name = "xfs",
Nathan Scotta50cd262006-03-14 14:06:18 +11001937 .get_sb = xfs_fs_get_sb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 .kill_sb = kill_block_super,
1939 .fs_flags = FS_REQUIRES_DEV,
1940};
1941
1942
1943STATIC int __init
1944init_xfs_fs( void )
1945{
1946 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 static char message[] __initdata = KERN_INFO \
1948 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
1949
1950 printk(message);
1951
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 ktrace_init(64);
1953
Nathan Scott87582802006-03-14 13:18:19 +11001954 error = xfs_init_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 if (error < 0)
Christoph Hellwig0829c362005-09-02 16:58:49 +10001956 goto undo_zones;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Nathan Scottce8e9222006-01-11 15:39:08 +11001958 error = xfs_buf_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 if (error < 0)
Nathan Scottce8e9222006-01-11 15:39:08 +11001960 goto undo_buffers;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
1962 vn_init();
1963 xfs_init();
1964 uuid_init();
1965 vfs_initquota();
1966
1967 error = register_filesystem(&xfs_fs_type);
1968 if (error)
1969 goto undo_register;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 return 0;
1971
1972undo_register:
Nathan Scottce8e9222006-01-11 15:39:08 +11001973 xfs_buf_terminate();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974
Nathan Scottce8e9222006-01-11 15:39:08 +11001975undo_buffers:
Nathan Scott87582802006-03-14 13:18:19 +11001976 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Christoph Hellwig0829c362005-09-02 16:58:49 +10001978undo_zones:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 return error;
1980}
1981
1982STATIC void __exit
1983exit_xfs_fs( void )
1984{
1985 vfs_exitquota();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 unregister_filesystem(&xfs_fs_type);
1987 xfs_cleanup();
Nathan Scottce8e9222006-01-11 15:39:08 +11001988 xfs_buf_terminate();
Nathan Scott87582802006-03-14 13:18:19 +11001989 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 ktrace_uninit();
1991}
1992
1993module_init(init_xfs_fs);
1994module_exit(exit_xfs_fs);
1995
1996MODULE_AUTHOR("Silicon Graphics, Inc.");
1997MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1998MODULE_LICENSE("GPL");