blob: 712fa29508757fb6ab24bdbc1af0c029e111f9e7 [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"
Nathan Scotta844f452005-11-02 14:38:42 +110021#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_trans.h"
23#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110024#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "xfs_dir2.h"
26#include "xfs_alloc.h"
27#include "xfs_dmapi.h"
28#include "xfs_quota.h"
29#include "xfs_mount.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include "xfs_bmap_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110031#include "xfs_alloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include "xfs_ialloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "xfs_dir2_sf.h"
Nathan Scotta844f452005-11-02 14:38:42 +110034#include "xfs_attr_sf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "xfs_dinode.h"
36#include "xfs_inode.h"
Nathan Scotta844f452005-11-02 14:38:42 +110037#include "xfs_btree.h"
Christoph Hellwig8c4ed632008-10-30 16:55:13 +110038#include "xfs_btree_trace.h"
Nathan Scotta844f452005-11-02 14:38:42 +110039#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include "xfs_version.h"
David Chinnera67d7c52007-11-23 16:29:32 +110052#include "xfs_log_priv.h"
David Chinner249a8c12008-02-05 12:13:32 +110053#include "xfs_trans_priv.h"
Christoph Hellwig48b62a12008-05-20 11:30:39 +100054#include "xfs_filestream.h"
Christoph Hellwig9f8868f2008-07-18 17:11:46 +100055#include "xfs_da_btree.h"
56#include "xfs_dir2_trace.h"
57#include "xfs_extfree_item.h"
58#include "xfs_mru_cache.h"
59#include "xfs_inode_item.h"
David Chinnerfe4fa4b2008-10-30 17:06:08 +110060#include "xfs_sync.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#include <linux/namei.h>
63#include <linux/init.h>
64#include <linux/mount.h>
Christoph Hellwig0829c362005-09-02 16:58:49 +100065#include <linux/mempool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#include <linux/writeback.h>
Christoph Hellwig4df08c52005-09-05 08:34:18 +100067#include <linux/kthread.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080068#include <linux/freezer.h>
Christoph Hellwig62a877e2008-07-18 17:12:36 +100069#include <linux/parser.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
David Chinner7989cb82007-02-10 18:34:56 +110071static struct quotactl_ops xfs_quotactl_operations;
72static struct super_operations xfs_super_operations;
David Chinner7989cb82007-02-10 18:34:56 +110073static 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
David Chinnera67d7c52007-11-23 16:29:32 +110076#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
77#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
78#define MNTOPT_LOGDEV "logdev" /* log device */
79#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
80#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
81#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
82#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
83#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
84#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
85#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
86#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
87#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
88#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
89#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
90#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
91#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
92#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
93#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
94#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
95#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
96 * unwritten extent conversion */
97#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
98#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
99#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
100#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
101#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
102#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
103#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
104 * in stat(). */
105#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
106#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
107#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
108#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
109#define MNTOPT_NOQUOTA "noquota" /* no quotas */
110#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
111#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
112#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
113#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
114#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
115#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
116#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
117#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
118#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
119#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
120#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
121#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
122#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
123
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000124/*
125 * Table driven mount option parser.
126 *
127 * Currently only used for remount, but it will be used for mount
128 * in the future, too.
129 */
130enum {
131 Opt_barrier, Opt_nobarrier, Opt_err
132};
133
Steven Whitehousea447c092008-10-13 10:46:57 +0100134static const match_table_t tokens = {
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000135 {Opt_barrier, "barrier"},
136 {Opt_nobarrier, "nobarrier"},
137 {Opt_err, NULL}
138};
139
140
David Chinnera67d7c52007-11-23 16:29:32 +1100141STATIC unsigned long
142suffix_strtoul(char *s, char **endp, unsigned int base)
143{
144 int last, shift_left_factor = 0;
145 char *value = s;
146
147 last = strlen(value) - 1;
148 if (value[last] == 'K' || value[last] == 'k') {
149 shift_left_factor = 10;
150 value[last] = '\0';
151 }
152 if (value[last] == 'M' || value[last] == 'm') {
153 shift_left_factor = 20;
154 value[last] = '\0';
155 }
156 if (value[last] == 'G' || value[last] == 'g') {
157 shift_left_factor = 30;
158 value[last] = '\0';
159 }
160
161 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
162}
163
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100164/*
165 * This function fills in xfs_mount_t fields based on mount args.
166 * Note: the superblock has _not_ yet been read in.
167 *
168 * Note that this function leaks the various device name allocations on
169 * failure. The caller takes care of them.
170 */
David Chinnera67d7c52007-11-23 16:29:32 +1100171STATIC int
172xfs_parseargs(
173 struct xfs_mount *mp,
174 char *options,
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100175 char **mtpt)
David Chinnera67d7c52007-11-23 16:29:32 +1100176{
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100177 struct super_block *sb = mp->m_super;
David Chinnera67d7c52007-11-23 16:29:32 +1100178 char *this_char, *value, *eov;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100179 int dsunit = 0;
180 int dswidth = 0;
181 int iosize = 0;
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100182 int dmapi_implies_ikeep = 1;
Christoph Hellwiga5687782009-02-09 08:37:39 +0100183 __uint8_t iosizelog = 0;
David Chinnera67d7c52007-11-23 16:29:32 +1100184
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100185 /*
186 * Copy binary VFS mount flags we are interested in.
187 */
188 if (sb->s_flags & MS_RDONLY)
189 mp->m_flags |= XFS_MOUNT_RDONLY;
190 if (sb->s_flags & MS_DIRSYNC)
191 mp->m_flags |= XFS_MOUNT_DIRSYNC;
192 if (sb->s_flags & MS_SYNCHRONOUS)
193 mp->m_flags |= XFS_MOUNT_WSYNC;
194
195 /*
196 * Set some default flags that could be cleared by the mount option
197 * parsing.
198 */
199 mp->m_flags |= XFS_MOUNT_BARRIER;
200 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
201 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
202
203 /*
204 * These can be overridden by the mount option parsing.
205 */
206 mp->m_logbufs = -1;
207 mp->m_logbsize = -1;
David Chinnera67d7c52007-11-23 16:29:32 +1100208
209 if (!options)
210 goto done;
211
David Chinnera67d7c52007-11-23 16:29:32 +1100212 while ((this_char = strsep(&options, ",")) != NULL) {
213 if (!*this_char)
214 continue;
215 if ((value = strchr(this_char, '=')) != NULL)
216 *value++ = 0;
217
218 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
219 if (!value || !*value) {
220 cmn_err(CE_WARN,
221 "XFS: %s option requires an argument",
222 this_char);
223 return EINVAL;
224 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100225 mp->m_logbufs = simple_strtoul(value, &eov, 10);
David Chinnera67d7c52007-11-23 16:29:32 +1100226 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
227 if (!value || !*value) {
228 cmn_err(CE_WARN,
229 "XFS: %s option requires an argument",
230 this_char);
231 return EINVAL;
232 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100233 mp->m_logbsize = suffix_strtoul(value, &eov, 10);
David Chinnera67d7c52007-11-23 16:29:32 +1100234 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
235 if (!value || !*value) {
236 cmn_err(CE_WARN,
237 "XFS: %s option requires an argument",
238 this_char);
239 return EINVAL;
240 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100241 mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
242 if (!mp->m_logname)
243 return ENOMEM;
David Chinnera67d7c52007-11-23 16:29:32 +1100244 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
245 if (!value || !*value) {
246 cmn_err(CE_WARN,
247 "XFS: %s option requires an argument",
248 this_char);
249 return EINVAL;
250 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100251 *mtpt = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
252 if (!*mtpt)
253 return ENOMEM;
David Chinnera67d7c52007-11-23 16:29:32 +1100254 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
255 if (!value || !*value) {
256 cmn_err(CE_WARN,
257 "XFS: %s option requires an argument",
258 this_char);
259 return EINVAL;
260 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100261 mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
262 if (!mp->m_rtname)
263 return ENOMEM;
David Chinnera67d7c52007-11-23 16:29:32 +1100264 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
265 if (!value || !*value) {
266 cmn_err(CE_WARN,
267 "XFS: %s option requires an argument",
268 this_char);
269 return EINVAL;
270 }
271 iosize = simple_strtoul(value, &eov, 10);
Christoph Hellwig1ec79442008-10-30 17:55:08 +1100272 iosizelog = ffs(iosize) - 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100273 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
274 if (!value || !*value) {
275 cmn_err(CE_WARN,
276 "XFS: %s option requires an argument",
277 this_char);
278 return EINVAL;
279 }
280 iosize = suffix_strtoul(value, &eov, 10);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100281 iosizelog = ffs(iosize) - 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100282 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
283 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
284 mp->m_flags |= XFS_MOUNT_GRPID;
285 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
286 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
287 mp->m_flags &= ~XFS_MOUNT_GRPID;
288 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100289 mp->m_flags |= XFS_MOUNT_WSYNC;
David Chinnera67d7c52007-11-23 16:29:32 +1100290 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100291 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
David Chinnera67d7c52007-11-23 16:29:32 +1100292 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100293 mp->m_flags |= XFS_MOUNT_NORECOVERY;
David Chinnera67d7c52007-11-23 16:29:32 +1100294 } else if (!strcmp(this_char, MNTOPT_INO64)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100295#if XFS_BIG_INUMS
296 mp->m_flags |= XFS_MOUNT_INO64;
297 mp->m_inoadd = XFS_INO64_OFFSET;
298#else
David Chinnera67d7c52007-11-23 16:29:32 +1100299 cmn_err(CE_WARN,
300 "XFS: %s option not allowed on this system",
301 this_char);
302 return EINVAL;
303#endif
304 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100305 mp->m_flags |= XFS_MOUNT_NOALIGN;
David Chinnera67d7c52007-11-23 16:29:32 +1100306 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100307 mp->m_flags |= XFS_MOUNT_SWALLOC;
David Chinnera67d7c52007-11-23 16:29:32 +1100308 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
309 if (!value || !*value) {
310 cmn_err(CE_WARN,
311 "XFS: %s option requires an argument",
312 this_char);
313 return EINVAL;
314 }
315 dsunit = simple_strtoul(value, &eov, 10);
316 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
317 if (!value || !*value) {
318 cmn_err(CE_WARN,
319 "XFS: %s option requires an argument",
320 this_char);
321 return EINVAL;
322 }
323 dswidth = simple_strtoul(value, &eov, 10);
324 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100325 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
David Chinnera67d7c52007-11-23 16:29:32 +1100326#if !XFS_BIG_INUMS
327 cmn_err(CE_WARN,
328 "XFS: %s option not allowed on this system",
329 this_char);
330 return EINVAL;
331#endif
332 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100333 mp->m_flags |= XFS_MOUNT_NOUUID;
David Chinnera67d7c52007-11-23 16:29:32 +1100334 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100335 mp->m_flags |= XFS_MOUNT_BARRIER;
David Chinnera67d7c52007-11-23 16:29:32 +1100336 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100337 mp->m_flags &= ~XFS_MOUNT_BARRIER;
David Chinnera67d7c52007-11-23 16:29:32 +1100338 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100339 mp->m_flags |= XFS_MOUNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100340 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100341 dmapi_implies_ikeep = 0;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100342 mp->m_flags &= ~XFS_MOUNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100343 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100344 mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
David Chinnera67d7c52007-11-23 16:29:32 +1100345 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100346 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
David Chinnera67d7c52007-11-23 16:29:32 +1100347 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100348 mp->m_flags |= XFS_MOUNT_ATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100349 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100350 mp->m_flags &= ~XFS_MOUNT_ATTR2;
351 mp->m_flags |= XFS_MOUNT_NOATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100352 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100353 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
David Chinnera67d7c52007-11-23 16:29:32 +1100354 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100355 mp->m_qflags &= ~(XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
356 XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
Christoph Hellwig469fc232008-10-30 17:54:57 +1100357 XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100358 XFS_UQUOTA_ENFD | XFS_OQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100359 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
360 !strcmp(this_char, MNTOPT_UQUOTA) ||
361 !strcmp(this_char, MNTOPT_USRQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100362 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
363 XFS_UQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100364 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
365 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100366 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
367 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
David Chinnera67d7c52007-11-23 16:29:32 +1100368 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
369 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100370 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
371 XFS_OQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100372 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100373 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
374 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
David Chinnera67d7c52007-11-23 16:29:32 +1100375 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
376 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100377 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
378 XFS_OQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100379 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100380 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
381 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
David Chinnera67d7c52007-11-23 16:29:32 +1100382 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100383 mp->m_flags |= XFS_MOUNT_DMAPI;
David Chinnera67d7c52007-11-23 16:29:32 +1100384 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100385 mp->m_flags |= XFS_MOUNT_DMAPI;
David Chinnera67d7c52007-11-23 16:29:32 +1100386 } else if (!strcmp(this_char, MNTOPT_DMI)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100387 mp->m_flags |= XFS_MOUNT_DMAPI;
David Chinnera67d7c52007-11-23 16:29:32 +1100388 } else if (!strcmp(this_char, "ihashsize")) {
389 cmn_err(CE_WARN,
390 "XFS: ihashsize no longer used, option is deprecated.");
391 } else if (!strcmp(this_char, "osyncisdsync")) {
392 /* no-op, this is now the default */
393 cmn_err(CE_WARN,
394 "XFS: osyncisdsync is now the default, option is deprecated.");
395 } else if (!strcmp(this_char, "irixsgid")) {
396 cmn_err(CE_WARN,
397 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
398 } else {
399 cmn_err(CE_WARN,
400 "XFS: unknown mount option [%s].", this_char);
401 return EINVAL;
402 }
403 }
404
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100405 /*
406 * no recovery flag requires a read-only mount
407 */
408 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
409 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
410 cmn_err(CE_WARN, "XFS: no-recovery mounts must be read-only.");
411 return EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100412 }
413
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100414 if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
David Chinnera67d7c52007-11-23 16:29:32 +1100415 cmn_err(CE_WARN,
416 "XFS: sunit and swidth options incompatible with the noalign option");
417 return EINVAL;
418 }
419
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100420 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
421 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE))) {
David Chinnera67d7c52007-11-23 16:29:32 +1100422 cmn_err(CE_WARN,
423 "XFS: cannot mount with both project and group quota");
424 return EINVAL;
425 }
426
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100427 if ((mp->m_flags & XFS_MOUNT_DMAPI) && (!*mtpt || *mtpt[0] == '\0')) {
David Chinnera67d7c52007-11-23 16:29:32 +1100428 printk("XFS: %s option needs the mount point option as well\n",
429 MNTOPT_DMAPI);
430 return EINVAL;
431 }
432
433 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
434 cmn_err(CE_WARN,
435 "XFS: sunit and swidth must be specified together");
436 return EINVAL;
437 }
438
439 if (dsunit && (dswidth % dsunit != 0)) {
440 cmn_err(CE_WARN,
441 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
442 dswidth, dsunit);
443 return EINVAL;
444 }
445
446 /*
447 * Applications using DMI filesystems often expect the
448 * inode generation number to be monotonically increasing.
449 * If we delete inode chunks we break this assumption, so
450 * keep unused inode chunks on disk for DMI filesystems
451 * until we come up with a better solution.
452 * Note that if "ikeep" or "noikeep" mount options are
453 * supplied, then they are honored.
454 */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100455 if ((mp->m_flags & XFS_MOUNT_DMAPI) && dmapi_implies_ikeep)
456 mp->m_flags |= XFS_MOUNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100457
458done:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100459 if (!(mp->m_flags & XFS_MOUNT_NOALIGN)) {
460 /*
461 * At this point the superblock has not been read
462 * in, therefore we do not know the block size.
463 * Before the mount call ends we will convert
464 * these to FSBs.
465 */
466 if (dsunit) {
467 mp->m_dalign = dsunit;
468 mp->m_flags |= XFS_MOUNT_RETERR;
469 }
470
471 if (dswidth)
472 mp->m_swidth = dswidth;
473 }
474
475 if (mp->m_logbufs != -1 &&
476 mp->m_logbufs != 0 &&
477 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
478 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
479 cmn_err(CE_WARN,
480 "XFS: invalid logbufs value: %d [not %d-%d]",
481 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
482 return XFS_ERROR(EINVAL);
483 }
484 if (mp->m_logbsize != -1 &&
485 mp->m_logbsize != 0 &&
486 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
487 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
488 !is_power_of_2(mp->m_logbsize))) {
489 cmn_err(CE_WARN,
490 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
491 mp->m_logbsize);
492 return XFS_ERROR(EINVAL);
493 }
494
495 mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
496 if (!mp->m_fsname)
497 return ENOMEM;
498 mp->m_fsname_len = strlen(mp->m_fsname) + 1;
499
500 if (iosizelog) {
501 if (iosizelog > XFS_MAX_IO_LOG ||
502 iosizelog < XFS_MIN_IO_LOG) {
503 cmn_err(CE_WARN,
504 "XFS: invalid log iosize: %d [not %d-%d]",
505 iosizelog, XFS_MIN_IO_LOG,
506 XFS_MAX_IO_LOG);
507 return XFS_ERROR(EINVAL);
508 }
509
510 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
511 mp->m_readio_log = iosizelog;
512 mp->m_writeio_log = iosizelog;
513 }
514
David Chinnera67d7c52007-11-23 16:29:32 +1100515 return 0;
516}
517
518struct proc_xfs_info {
519 int flag;
520 char *str;
521};
522
523STATIC int
524xfs_showargs(
525 struct xfs_mount *mp,
526 struct seq_file *m)
527{
528 static struct proc_xfs_info xfs_info_set[] = {
529 /* the few simple ones we can get from the mount struct */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100530 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
David Chinnera67d7c52007-11-23 16:29:32 +1100531 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
532 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
533 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
534 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
535 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
536 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
537 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
538 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
539 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
540 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
541 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
542 { 0, NULL }
543 };
544 static struct proc_xfs_info xfs_info_unset[] = {
545 /* the few simple ones we can get from the mount struct */
David Chinnera67d7c52007-11-23 16:29:32 +1100546 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
547 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
548 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
549 { 0, NULL }
550 };
551 struct proc_xfs_info *xfs_infop;
552
553 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
554 if (mp->m_flags & xfs_infop->flag)
555 seq_puts(m, xfs_infop->str);
556 }
557 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
558 if (!(mp->m_flags & xfs_infop->flag))
559 seq_puts(m, xfs_infop->str);
560 }
561
562 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
563 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
564 (int)(1 << mp->m_writeio_log) >> 10);
565
566 if (mp->m_logbufs > 0)
567 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
568 if (mp->m_logbsize > 0)
569 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
570
571 if (mp->m_logname)
572 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
573 if (mp->m_rtname)
574 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
575
576 if (mp->m_dalign > 0)
577 seq_printf(m, "," MNTOPT_SUNIT "=%d",
578 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
579 if (mp->m_swidth > 0)
580 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
581 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
582
583 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
584 seq_puts(m, "," MNTOPT_USRQUOTA);
585 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
586 seq_puts(m, "," MNTOPT_UQUOTANOENF);
587
588 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
589 seq_puts(m, "," MNTOPT_PRJQUOTA);
590 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
591 seq_puts(m, "," MNTOPT_PQUOTANOENF);
592
593 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
594 seq_puts(m, "," MNTOPT_GRPQUOTA);
595 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
596 seq_puts(m, "," MNTOPT_GQUOTANOENF);
597
598 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
599 seq_puts(m, "," MNTOPT_NOQUOTA);
600
601 return 0;
602}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603__uint64_t
604xfs_max_file_offset(
605 unsigned int blockshift)
606{
607 unsigned int pagefactor = 1;
608 unsigned int bitshift = BITS_PER_LONG - 1;
609
610 /* Figure out maximum filesize, on Linux this can depend on
611 * the filesystem blocksize (on 32 bit platforms).
612 * __block_prepare_write does this in an [unsigned] long...
613 * page->index << (PAGE_CACHE_SHIFT - bbits)
614 * So, for page sized blocks (4K on 32 bit platforms),
615 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
616 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
617 * but for smaller blocksizes it is less (bbits = log2 bsize).
618 * Note1: get_block_t takes a long (implicit cast from above)
619 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
620 * can optionally convert the [unsigned] long from above into
621 * an [unsigned] long long.
622 */
623
624#if BITS_PER_LONG == 32
625# if defined(CONFIG_LBD)
626 ASSERT(sizeof(sector_t) == 8);
627 pagefactor = PAGE_CACHE_SIZE;
628 bitshift = BITS_PER_LONG;
629# else
630 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
631# endif
632#endif
633
634 return (((__uint64_t)pagefactor) << bitshift) - 1;
635}
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637int
638xfs_blkdev_get(
639 xfs_mount_t *mp,
640 const char *name,
641 struct block_device **bdevp)
642{
643 int error = 0;
644
Al Viro30c40d22008-02-22 19:50:45 -0500645 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (IS_ERR(*bdevp)) {
647 error = PTR_ERR(*bdevp);
648 printk("XFS: Invalid device [%s], error=%d\n", name, error);
649 }
650
651 return -error;
652}
653
654void
655xfs_blkdev_put(
656 struct block_device *bdev)
657{
658 if (bdev)
Al Viro30c40d22008-02-22 19:50:45 -0500659 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
661
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100662/*
663 * Try to write out the superblock using barriers.
664 */
665STATIC int
666xfs_barrier_test(
667 xfs_mount_t *mp)
668{
669 xfs_buf_t *sbp = xfs_getsb(mp, 0);
670 int error;
671
672 XFS_BUF_UNDONE(sbp);
673 XFS_BUF_UNREAD(sbp);
674 XFS_BUF_UNDELAYWRITE(sbp);
675 XFS_BUF_WRITE(sbp);
676 XFS_BUF_UNASYNC(sbp);
677 XFS_BUF_ORDERED(sbp);
678
679 xfsbdstrat(mp, sbp);
680 error = xfs_iowait(sbp);
681
682 /*
683 * Clear all the flags we set and possible error state in the
684 * buffer. We only did the write to try out whether barriers
685 * worked and shouldn't leave any traces in the superblock
686 * buffer.
687 */
688 XFS_BUF_DONE(sbp);
689 XFS_BUF_ERROR(sbp, 0);
690 XFS_BUF_UNORDERED(sbp);
691
692 xfs_buf_relse(sbp);
693 return error;
694}
695
696void
697xfs_mountfs_check_barriers(xfs_mount_t *mp)
698{
699 int error;
700
701 if (mp->m_logdev_targp != mp->m_ddev_targp) {
702 xfs_fs_cmn_err(CE_NOTE, mp,
703 "Disabling barriers, not supported with external log device");
704 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100705 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100706 }
707
Nathan Scottb2ea4012006-07-28 17:05:13 +1000708 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
709 xfs_fs_cmn_err(CE_NOTE, mp,
710 "Disabling barriers, underlying device is readonly");
711 mp->m_flags &= ~XFS_MOUNT_BARRIER;
712 return;
713 }
714
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100715 error = xfs_barrier_test(mp);
716 if (error) {
717 xfs_fs_cmn_err(CE_NOTE, mp,
718 "Disabling barriers, trial barrier write failed");
719 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100720 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100721 }
722}
723
724void
725xfs_blkdev_issue_flush(
726 xfs_buftarg_t *buftarg)
727{
Nathan Scottce8e9222006-01-11 15:39:08 +1100728 blkdev_issue_flush(buftarg->bt_bdev, NULL);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100729}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000731STATIC void
732xfs_close_devices(
733 struct xfs_mount *mp)
734{
735 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000736 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000737 xfs_free_buftarg(mp->m_logdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000738 xfs_blkdev_put(logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000739 }
740 if (mp->m_rtdev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000741 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000742 xfs_free_buftarg(mp->m_rtdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000743 xfs_blkdev_put(rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000744 }
745 xfs_free_buftarg(mp->m_ddev_targp);
746}
747
748/*
749 * The file system configurations are:
750 * (1) device (partition) with data and internal log
751 * (2) logical volume with data and log subvolumes.
752 * (3) logical volume with data, log, and realtime subvolumes.
753 *
754 * We only have to handle opening the log and realtime volumes here if
755 * they are present. The data subvolume has already been opened by
756 * get_sb_bdev() and is stored in sb->s_bdev.
757 */
758STATIC int
759xfs_open_devices(
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100760 struct xfs_mount *mp)
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000761{
762 struct block_device *ddev = mp->m_super->s_bdev;
763 struct block_device *logdev = NULL, *rtdev = NULL;
764 int error;
765
766 /*
767 * Open real time and log devices - order is important.
768 */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100769 if (mp->m_logname) {
770 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000771 if (error)
772 goto out;
773 }
774
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100775 if (mp->m_rtname) {
776 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000777 if (error)
778 goto out_close_logdev;
779
780 if (rtdev == ddev || rtdev == logdev) {
781 cmn_err(CE_WARN,
782 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
783 error = EINVAL;
784 goto out_close_rtdev;
785 }
786 }
787
788 /*
789 * Setup xfs_mount buffer target pointers
790 */
791 error = ENOMEM;
792 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
793 if (!mp->m_ddev_targp)
794 goto out_close_rtdev;
795
796 if (rtdev) {
797 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
798 if (!mp->m_rtdev_targp)
799 goto out_free_ddev_targ;
800 }
801
802 if (logdev && logdev != ddev) {
803 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
804 if (!mp->m_logdev_targp)
805 goto out_free_rtdev_targ;
806 } else {
807 mp->m_logdev_targp = mp->m_ddev_targp;
808 }
809
810 return 0;
811
812 out_free_rtdev_targ:
813 if (mp->m_rtdev_targp)
814 xfs_free_buftarg(mp->m_rtdev_targp);
815 out_free_ddev_targ:
816 xfs_free_buftarg(mp->m_ddev_targp);
817 out_close_rtdev:
818 if (rtdev)
819 xfs_blkdev_put(rtdev);
820 out_close_logdev:
821 if (logdev && logdev != ddev)
822 xfs_blkdev_put(logdev);
823 out:
824 return error;
825}
826
Christoph Hellwige34b5622008-05-20 15:10:36 +1000827/*
828 * Setup xfs_mount buffer target pointers based on superblock
829 */
830STATIC int
831xfs_setup_devices(
832 struct xfs_mount *mp)
833{
834 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000835
Christoph Hellwige34b5622008-05-20 15:10:36 +1000836 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
837 mp->m_sb.sb_sectsize);
838 if (error)
839 return error;
840
841 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
842 unsigned int log_sector_size = BBSIZE;
843
844 if (xfs_sb_version_hassector(&mp->m_sb))
845 log_sector_size = mp->m_sb.sb_logsectsize;
846 error = xfs_setsize_buftarg(mp->m_logdev_targp,
847 mp->m_sb.sb_blocksize,
848 log_sector_size);
849 if (error)
850 return error;
851 }
852 if (mp->m_rtdev_targp) {
853 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
854 mp->m_sb.sb_blocksize,
855 mp->m_sb.sb_sectsize);
856 if (error)
857 return error;
858 }
859
860 return 0;
861}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000862
David Chinner249a8c12008-02-05 12:13:32 +1100863/*
864 * XFS AIL push thread support
865 */
866void
867xfsaild_wakeup(
David Chinner82fa9012008-10-30 17:38:26 +1100868 struct xfs_ail *ailp,
David Chinner249a8c12008-02-05 12:13:32 +1100869 xfs_lsn_t threshold_lsn)
870{
David Chinner82fa9012008-10-30 17:38:26 +1100871 ailp->xa_target = threshold_lsn;
872 wake_up_process(ailp->xa_task);
David Chinner249a8c12008-02-05 12:13:32 +1100873}
874
875int
876xfsaild(
877 void *data)
878{
David Chinner82fa9012008-10-30 17:38:26 +1100879 struct xfs_ail *ailp = data;
David Chinner249a8c12008-02-05 12:13:32 +1100880 xfs_lsn_t last_pushed_lsn = 0;
881 long tout = 0;
882
883 while (!kthread_should_stop()) {
884 if (tout)
885 schedule_timeout_interruptible(msecs_to_jiffies(tout));
886 tout = 1000;
887
888 /* swsusp */
889 try_to_freeze();
890
David Chinner82fa9012008-10-30 17:38:26 +1100891 ASSERT(ailp->xa_mount->m_log);
892 if (XFS_FORCED_SHUTDOWN(ailp->xa_mount))
David Chinner249a8c12008-02-05 12:13:32 +1100893 continue;
894
David Chinner82fa9012008-10-30 17:38:26 +1100895 tout = xfsaild_push(ailp, &last_pushed_lsn);
David Chinner249a8c12008-02-05 12:13:32 +1100896 }
897
898 return 0;
899} /* xfsaild */
900
901int
902xfsaild_start(
David Chinner82fa9012008-10-30 17:38:26 +1100903 struct xfs_ail *ailp)
David Chinner249a8c12008-02-05 12:13:32 +1100904{
David Chinner82fa9012008-10-30 17:38:26 +1100905 ailp->xa_target = 0;
906 ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild");
907 if (IS_ERR(ailp->xa_task))
908 return -PTR_ERR(ailp->xa_task);
David Chinner249a8c12008-02-05 12:13:32 +1100909 return 0;
910}
911
912void
913xfsaild_stop(
David Chinner82fa9012008-10-30 17:38:26 +1100914 struct xfs_ail *ailp)
David Chinner249a8c12008-02-05 12:13:32 +1100915{
David Chinner82fa9012008-10-30 17:38:26 +1100916 kthread_stop(ailp->xa_task);
David Chinner249a8c12008-02-05 12:13:32 +1100917}
918
919
David Chinnerbf904242008-10-30 17:36:14 +1100920/* Catch misguided souls that try to use this interface on XFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100922xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 struct super_block *sb)
924{
David Chinnerbf904242008-10-30 17:36:14 +1100925 BUG();
Lachlan McIlroy493dca62008-10-30 17:36:52 +1100926 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927}
928
David Chinnerbf904242008-10-30 17:36:14 +1100929/*
David Chinner99fa8cb2008-10-30 17:36:40 +1100930 * Now that the generic code is guaranteed not to be accessing
931 * the linux inode, we can reclaim the inode.
David Chinnerbf904242008-10-30 17:36:14 +1100932 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100934xfs_fs_destroy_inode(
David Chinnerbf904242008-10-30 17:36:14 +1100935 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
David Chinner99fa8cb2008-10-30 17:36:40 +1100937 xfs_inode_t *ip = XFS_I(inode);
938
939 XFS_STATS_INC(vn_reclaim);
940 if (xfs_reclaim(ip))
941 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
943
David Chinner07c8f672008-10-30 16:11:59 +1100944/*
945 * Slab object creation initialisation for the XFS inode.
946 * This covers only the idempotent fields in the XFS inode;
947 * all other fields need to be initialised on allocation
948 * from the slab. This avoids the need to repeatedly intialise
949 * fields in the xfs inode that left in the initialise state
950 * when freeing the inode.
951 */
David Chinnerbf904242008-10-30 17:36:14 +1100952STATIC void
953xfs_fs_inode_init_once(
David Chinner07c8f672008-10-30 16:11:59 +1100954 void *inode)
955{
956 struct xfs_inode *ip = inode;
957
958 memset(ip, 0, sizeof(struct xfs_inode));
David Chinnerbf904242008-10-30 17:36:14 +1100959
960 /* vfs inode */
961 inode_init_once(VFS_I(ip));
962
963 /* xfs inode */
David Chinner07c8f672008-10-30 16:11:59 +1100964 atomic_set(&ip->i_iocount, 0);
965 atomic_set(&ip->i_pincount, 0);
966 spin_lock_init(&ip->i_flags_lock);
David Chinner07c8f672008-10-30 16:11:59 +1100967 init_waitqueue_head(&ip->i_ipin_wait);
968 /*
969 * Because we want to use a counting completion, complete
970 * the flush completion once to allow a single access to
971 * the flush completion without blocking.
972 */
973 init_completion(&ip->i_flush);
974 complete(&ip->i_flush);
975
976 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
977 "xfsino", ip->i_ino);
978 mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
979}
980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981/*
982 * Attempt to flush the inode, this will actually fail
983 * if the inode is pinned, but we dirty the inode again
984 * at the point when it is unpinned after a log write,
Nathan Scott87582802006-03-14 13:18:19 +1100985 * since this is when the inode itself becomes flushable.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 */
987STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +1100988xfs_fs_write_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 struct inode *inode,
990 int sync)
991{
Dave Chinner2e656092008-11-28 14:23:33 +1100992 struct xfs_inode *ip = XFS_I(inode);
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +0100993 struct xfs_mount *mp = ip->i_mount;
David Chinnera3f74ff2008-03-06 13:43:42 +1100994 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Dave Chinner2e656092008-11-28 14:23:33 +1100996 xfs_itrace_entry(ip);
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +0100997
998 if (XFS_FORCED_SHUTDOWN(mp))
999 return XFS_ERROR(EIO);
1000
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001001 if (sync) {
Dave Chinner2e656092008-11-28 14:23:33 +11001002 error = xfs_wait_on_pages(ip, 0, -1);
1003 if (error)
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +01001004 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 }
Dave Chinner2e656092008-11-28 14:23:33 +11001006
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +01001007 /*
1008 * Bypass inodes which have already been cleaned by
1009 * the inode flush clustering code inside xfs_iflush
1010 */
1011 if (xfs_inode_clean(ip))
1012 goto out;
1013
1014 /*
1015 * We make this non-blocking if the inode is contended, return
1016 * EAGAIN to indicate to the caller that they did not succeed.
1017 * This prevents the flush path from blocking on inodes inside
1018 * another operation right now, they get caught later by xfs_sync.
1019 */
1020 if (sync) {
1021 xfs_ilock(ip, XFS_ILOCK_SHARED);
1022 xfs_iflock(ip);
1023
1024 error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
1025 } else {
1026 error = EAGAIN;
1027 if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED))
1028 goto out;
1029 if (xfs_ipincount(ip) || !xfs_iflock_nowait(ip))
1030 goto out_unlock;
1031
1032 error = xfs_iflush(ip, XFS_IFLUSH_ASYNC_NOBLOCK);
1033 }
1034
1035 out_unlock:
1036 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1037 out:
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001038 /*
1039 * if we failed to write out the inode then mark
1040 * it dirty again so we'll try again later.
1041 */
1042 if (error)
Dave Chinner2e656092008-11-28 14:23:33 +11001043 xfs_mark_inode_dirty_sync(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 return -error;
1045}
1046
1047STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001048xfs_fs_clear_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 struct inode *inode)
1050{
Christoph Hellwig1543d792007-08-29 11:46:47 +10001051 xfs_inode_t *ip = XFS_I(inode);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001052
David Chinner99fa8cb2008-10-30 17:36:40 +11001053 xfs_itrace_entry(ip);
1054 XFS_STATS_INC(vn_rele);
1055 XFS_STATS_INC(vn_remove);
1056 XFS_STATS_DEC(vn_active);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001057
David Chinner99fa8cb2008-10-30 17:36:40 +11001058 xfs_inactive(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059}
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061STATIC void
Christoph Hellwiga7381592008-08-13 16:04:05 +10001062xfs_free_fsname(
1063 struct xfs_mount *mp)
1064{
1065 kfree(mp->m_fsname);
1066 kfree(mp->m_rtname);
1067 kfree(mp->m_logname);
1068}
1069
1070STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001071xfs_fs_put_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 struct super_block *sb)
1073{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001074 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001075 struct xfs_inode *rip = mp->m_rootip;
1076 int unmount_event_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
David Chinnera167b172008-10-30 17:06:18 +11001078 xfs_syncd_stop(mp);
David Chinnerbe97d9d2008-10-30 17:15:38 +11001079 xfs_sync_inodes(mp, SYNC_ATTR|SYNC_DELWRI);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001080
1081#ifdef HAVE_DMAPI
1082 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1083 unmount_event_flags =
1084 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1085 0 : DM_FLAGS_UNWANTED;
1086 /*
1087 * Ignore error from dmapi here, first unmount is not allowed
1088 * to fail anyway, and second we wouldn't want to fail a
1089 * unmount because of dmapi.
1090 */
1091 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1092 NULL, NULL, 0, 0, unmount_event_flags);
1093 }
1094#endif
1095
1096 /*
1097 * Blow away any referenced inode in the filestreams cache.
1098 * This can and will cause log traffic as inodes go inactive
1099 * here.
1100 */
1101 xfs_filestream_unmount(mp);
1102
1103 XFS_bflush(mp->m_ddev_targp);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001104
Christoph Hellwige48ad312008-05-20 11:30:52 +10001105 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1106 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1107 unmount_event_flags);
1108 }
1109
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001110 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001111 xfs_freesb(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001112 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001113 xfs_close_devices(mp);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001114 xfs_qmops_put(mp);
1115 xfs_dmops_put(mp);
Christoph Hellwiga7381592008-08-13 16:04:05 +10001116 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001117 kfree(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
1120STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001121xfs_fs_write_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 struct super_block *sb)
1123{
Nathan Scottb83bd132006-06-09 16:48:30 +10001124 if (!(sb->s_flags & MS_RDONLY))
David Chinnere9f1c6e2008-10-30 17:15:50 +11001125 xfs_sync_fsdata(XFS_M(sb), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 sb->s_dirt = 0;
1127}
1128
1129STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001130xfs_fs_sync_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 struct super_block *sb,
1132 int wait)
1133{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001134 struct xfs_mount *mp = XFS_M(sb);
Nathan Scottb83bd132006-06-09 16:48:30 +10001135 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001137 /*
1138 * Treat a sync operation like a freeze. This is to work
1139 * around a race in sync_inodes() which works in two phases
1140 * - an asynchronous flush, which can write out an inode
1141 * without waiting for file size updates to complete, and a
1142 * synchronous flush, which wont do anything because the
1143 * async flush removed the inode's dirty flag. Also
1144 * sync_inodes() will not see any files that just have
1145 * outstanding transactions to be flushed because we don't
1146 * dirty the Linux inode until after the transaction I/O
1147 * completes.
1148 */
David Chinnere9f1c6e2008-10-30 17:15:50 +11001149 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE))
1150 error = xfs_quiesce_data(mp);
1151 else
1152 error = xfs_sync_fsdata(mp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 sb->s_dirt = 0;
1154
1155 if (unlikely(laptop_mode)) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001156 int prev_sync_seq = mp->m_sync_seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 /*
1159 * The disk must be active because we're syncing.
1160 * We schedule xfssyncd now (now that the disk is
1161 * active) instead of later (when it might not be).
1162 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001163 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 /*
1165 * We have to wait for the sync iteration to complete.
1166 * If we don't, the disk activity caused by the sync
1167 * will come after the sync is completed, and that
1168 * triggers another sync from laptop mode.
1169 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001170 wait_event(mp->m_wait_single_sync_task,
1171 mp->m_sync_seq != prev_sync_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 }
1173
1174 return -error;
1175}
1176
1177STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001178xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001179 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 struct kstatfs *statp)
1181{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001182 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1183 xfs_sb_t *sbp = &mp->m_sb;
1184 __uint64_t fakeinos, id;
1185 xfs_extlen_t lsize;
1186
1187 statp->f_type = XFS_SB_MAGIC;
1188 statp->f_namelen = MAXNAMELEN - 1;
1189
1190 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1191 statp->f_fsid.val[0] = (u32)id;
1192 statp->f_fsid.val[1] = (u32)(id >> 32);
1193
Christoph Hellwigd4d90b52008-04-22 17:34:37 +10001194 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001195
1196 spin_lock(&mp->m_sb_lock);
1197 statp->f_bsize = sbp->sb_blocksize;
1198 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1199 statp->f_blocks = sbp->sb_dblocks - lsize;
1200 statp->f_bfree = statp->f_bavail =
1201 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1202 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1203#if XFS_BIG_INUMS
1204 fakeinos += mp->m_inoadd;
1205#endif
1206 statp->f_files =
1207 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1208 if (mp->m_maxicount)
1209#if XFS_BIG_INUMS
1210 if (!mp->m_inoadd)
1211#endif
1212 statp->f_files = min_t(typeof(statp->f_files),
1213 statp->f_files,
1214 mp->m_maxicount);
1215 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1216 spin_unlock(&mp->m_sb_lock);
1217
1218 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1219 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
1222STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001223xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 struct super_block *sb,
1225 int *flags,
1226 char *options)
1227{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001228 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001229 substring_t args[MAX_OPT_ARGS];
1230 char *p;
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001231 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001233 while ((p = strsep(&options, ",")) != NULL) {
1234 int token;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001235
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001236 if (!*p)
1237 continue;
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001238
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001239 token = match_token(p, tokens, args);
1240 switch (token) {
1241 case Opt_barrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001242 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001243
1244 /*
1245 * Test if barriers are actually working if we can,
1246 * else delay this check until the filesystem is
1247 * marked writeable.
1248 */
1249 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1250 xfs_mountfs_check_barriers(mp);
1251 break;
1252 case Opt_nobarrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001253 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001254 break;
1255 default:
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001256 /*
1257 * Logically we would return an error here to prevent
1258 * users from believing they might have changed
1259 * mount options using remount which can't be changed.
1260 *
1261 * But unfortunately mount(8) adds all options from
1262 * mtab and fstab to the mount arguments in some cases
1263 * so we can't blindly reject options, but have to
1264 * check for each specified option if it actually
1265 * differs from the currently set option and only
1266 * reject it if that's the case.
1267 *
1268 * Until that is implemented we return success for
1269 * every remount request, and silently ignore all
1270 * options that we can't actually change.
1271 */
1272#if 0
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001273 printk(KERN_INFO
1274 "XFS: mount option \"%s\" not supported for remount\n", p);
1275 return -EINVAL;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001276#else
Christoph Hellwig6c5e51d2008-10-12 14:30:44 +02001277 break;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001278#endif
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001279 }
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001280 }
1281
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001282 /* ro -> rw */
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001283 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1284 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1285 if (mp->m_flags & XFS_MOUNT_BARRIER)
1286 xfs_mountfs_check_barriers(mp);
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001287
1288 /*
1289 * If this is the first remount to writeable state we
1290 * might have some superblock changes to update.
1291 */
1292 if (mp->m_update_flags) {
1293 error = xfs_mount_log_sb(mp, mp->m_update_flags);
1294 if (error) {
1295 cmn_err(CE_WARN,
1296 "XFS: failed to write sb changes");
1297 return error;
1298 }
1299 mp->m_update_flags = 0;
1300 }
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001301 }
1302
1303 /* rw -> ro */
1304 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
David Chinnere9f1c6e2008-10-30 17:15:50 +11001305 xfs_quiesce_data(mp);
David Chinner76bf1052008-10-30 17:16:21 +11001306 xfs_quiesce_attr(mp);
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001307 mp->m_flags |= XFS_MOUNT_RDONLY;
1308 }
1309
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001310 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311}
1312
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001313/*
1314 * Second stage of a freeze. The data is already frozen so we only
David Chinner76bf1052008-10-30 17:16:21 +11001315 * need to take care of the metadata. Once that's done write a dummy
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001316 * record to dirty the log in case of a crash while frozen.
1317 */
Takashi Satoc4be0c12009-01-09 16:40:58 -08001318STATIC int
1319xfs_fs_freeze(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 struct super_block *sb)
1321{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001322 struct xfs_mount *mp = XFS_M(sb);
1323
David Chinner76bf1052008-10-30 17:16:21 +11001324 xfs_quiesce_attr(mp);
Takashi Satoc4be0c12009-01-09 16:40:58 -08001325 return -xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
1328STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001329xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 struct seq_file *m,
1331 struct vfsmount *mnt)
1332{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001333 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334}
1335
1336STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001337xfs_fs_quotasync(
Nathan Scottee348072005-11-02 10:32:38 +11001338 struct super_block *sb,
1339 int type)
1340{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001341 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
Nathan Scottee348072005-11-02 10:32:38 +11001342}
1343
1344STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001345xfs_fs_getxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 struct super_block *sb,
1347 struct fs_quota_stat *fqs)
1348{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001349 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350}
1351
1352STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001353xfs_fs_setxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 struct super_block *sb,
1355 unsigned int flags,
1356 int op)
1357{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001358 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359}
1360
1361STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001362xfs_fs_getxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 struct super_block *sb,
1364 int type,
1365 qid_t id,
1366 struct fs_disk_quota *fdq)
1367{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001368 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001369 (type == USRQUOTA) ? Q_XGETQUOTA :
1370 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1371 Q_XGETPQUOTA), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372}
1373
1374STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001375xfs_fs_setxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 struct super_block *sb,
1377 int type,
1378 qid_t id,
1379 struct fs_disk_quota *fdq)
1380{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001381 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001382 (type == USRQUOTA) ? Q_XSETQLIM :
1383 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1384 Q_XSETPQLIM), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385}
1386
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001387/*
1388 * This function fills in xfs_mount_t fields based on mount args.
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001389 * Note: the superblock _has_ now been read in.
1390 */
1391STATIC int
1392xfs_finish_flags(
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001393 struct xfs_mount *mp)
1394{
1395 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1396
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02001397 /* Fail a mount where the logbuf is smaller than the log stripe */
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001398 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001399 if (mp->m_logbsize <= 0 &&
1400 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001401 mp->m_logbsize = mp->m_sb.sb_logsunit;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001402 } else if (mp->m_logbsize > 0 &&
1403 mp->m_logbsize < mp->m_sb.sb_logsunit) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001404 cmn_err(CE_WARN,
1405 "XFS: logbuf size must be greater than or equal to log stripe size");
1406 return XFS_ERROR(EINVAL);
1407 }
1408 } else {
1409 /* Fail a mount if the logbuf is larger than 32K */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001410 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001411 cmn_err(CE_WARN,
1412 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1413 return XFS_ERROR(EINVAL);
1414 }
1415 }
1416
1417 /*
1418 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1419 * told by noattr2 to turn it off
1420 */
1421 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001422 !(mp->m_flags & XFS_MOUNT_NOATTR2))
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001423 mp->m_flags |= XFS_MOUNT_ATTR2;
1424
1425 /*
1426 * prohibit r/w mounts of read-only filesystems
1427 */
1428 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1429 cmn_err(CE_WARN,
1430 "XFS: cannot mount a read-only filesystem as read-write");
1431 return XFS_ERROR(EROFS);
1432 }
1433
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001434 return 0;
1435}
1436
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001438xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 struct super_block *sb,
1440 void *data,
1441 int silent)
1442{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001443 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001444 struct xfs_mount *mp = NULL;
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001445 int flags = 0, error = ENOMEM;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001446 char *mtpt = NULL;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001447
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001448 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1449 if (!mp)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001450 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001452 spin_lock_init(&mp->m_sb_lock);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001453 mutex_init(&mp->m_growlock);
1454 atomic_set(&mp->m_active_trans, 0);
Christoph Hellwig74394492007-08-30 17:21:22 +10001455 INIT_LIST_HEAD(&mp->m_sync_list);
1456 spin_lock_init(&mp->m_sync_lock);
1457 init_waitqueue_head(&mp->m_wait_single_sync_task);
1458
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001459 mp->m_super = sb;
1460 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001462 error = xfs_parseargs(mp, (char *)data, &mtpt);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001463 if (error)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001464 goto out_free_fsname;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
1466 sb_min_blocksize(sb, BBSIZE);
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001467 sb->s_xattr = xfs_xattr_handlers;
Nathan Scotta50cd262006-03-14 14:06:18 +11001468 sb->s_export_op = &xfs_export_operations;
Nathan Scotta50cd262006-03-14 14:06:18 +11001469 sb->s_qcop = &xfs_quotactl_operations;
1470 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001472 error = xfs_dmops_get(mp);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001473 if (error)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001474 goto out_free_fsname;
1475 error = xfs_qmops_get(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001476 if (error)
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001477 goto out_put_dmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001478
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001479 if (silent)
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001480 flags |= XFS_MFSI_QUIET;
1481
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001482 error = xfs_open_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001483 if (error)
1484 goto out_put_qmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001485
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001486 if (xfs_icsb_init_counters(mp))
1487 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1488
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001489 error = xfs_readsb(mp, flags);
1490 if (error)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001491 goto out_destroy_counters;
1492
1493 error = xfs_finish_flags(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001494 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001495 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001496
Christoph Hellwige34b5622008-05-20 15:10:36 +10001497 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001498 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001499 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001500
1501 if (mp->m_flags & XFS_MOUNT_BARRIER)
1502 xfs_mountfs_check_barriers(mp);
1503
1504 error = xfs_filestream_mount(mp);
1505 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001506 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001507
Christoph Hellwig42490232008-08-13 16:49:32 +10001508 error = xfs_mountfs(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001509 if (error)
Christoph Hellwig120226c2008-05-20 15:11:11 +10001510 goto out_filestream_unmount;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001511
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001512 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 sb->s_dirt = 1;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001515 sb->s_magic = XFS_SB_MAGIC;
1516 sb->s_blocksize = mp->m_sb.sb_blocksize;
1517 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1519 sb->s_time_gran = 1;
1520 set_posix_acl_flag(sb);
1521
David Chinner01651642008-08-13 15:45:15 +10001522 root = igrab(VFS_I(mp->m_rootip));
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001523 if (!root) {
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001524 error = ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 goto fail_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001526 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001527 if (is_bad_inode(root)) {
1528 error = EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 goto fail_vnrele;
1530 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001531 sb->s_root = d_alloc_root(root);
1532 if (!sb->s_root) {
1533 error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 goto fail_vnrele;
1535 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001536
David Chinnera167b172008-10-30 17:06:18 +11001537 error = xfs_syncd_init(mp);
1538 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 goto fail_vnrele;
Christoph Hellwig74394492007-08-30 17:21:22 +10001540
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001541 kfree(mtpt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001543 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 return 0;
1545
Christoph Hellwig120226c2008-05-20 15:11:11 +10001546 out_filestream_unmount:
1547 xfs_filestream_unmount(mp);
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001548 out_free_sb:
1549 xfs_freesb(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001550 out_destroy_counters:
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001551 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001552 xfs_close_devices(mp);
1553 out_put_qmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001554 xfs_qmops_put(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001555 out_put_dmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001556 xfs_dmops_put(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001557 out_free_fsname:
1558 xfs_free_fsname(mp);
1559 kfree(mtpt);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001560 kfree(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001561 out:
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001562 return -error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001563
1564 fail_vnrele:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 if (sb->s_root) {
1566 dput(sb->s_root);
1567 sb->s_root = NULL;
1568 } else {
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001569 iput(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 }
1571
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001572 fail_unmount:
Christoph Hellwige48ad312008-05-20 11:30:52 +10001573 /*
1574 * Blow away any referenced inode in the filestreams cache.
1575 * This can and will cause log traffic as inodes go inactive
1576 * here.
1577 */
1578 xfs_filestream_unmount(mp);
1579
1580 XFS_bflush(mp->m_ddev_targp);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001581
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001582 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001583 goto out_free_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584}
1585
David Howells454e2392006-06-23 02:02:57 -07001586STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001587xfs_fs_get_sb(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 struct file_system_type *fs_type,
1589 int flags,
1590 const char *dev_name,
David Howells454e2392006-06-23 02:02:57 -07001591 void *data,
1592 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593{
David Howells454e2392006-06-23 02:02:57 -07001594 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1595 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
1597
David Chinner7989cb82007-02-10 18:34:56 +11001598static struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001599 .alloc_inode = xfs_fs_alloc_inode,
1600 .destroy_inode = xfs_fs_destroy_inode,
1601 .write_inode = xfs_fs_write_inode,
1602 .clear_inode = xfs_fs_clear_inode,
1603 .put_super = xfs_fs_put_super,
1604 .write_super = xfs_fs_write_super,
1605 .sync_fs = xfs_fs_sync_super,
Takashi Satoc4be0c12009-01-09 16:40:58 -08001606 .freeze_fs = xfs_fs_freeze,
Nathan Scotta50cd262006-03-14 14:06:18 +11001607 .statfs = xfs_fs_statfs,
1608 .remount_fs = xfs_fs_remount,
1609 .show_options = xfs_fs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610};
1611
David Chinner7989cb82007-02-10 18:34:56 +11001612static struct quotactl_ops xfs_quotactl_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001613 .quota_sync = xfs_fs_quotasync,
1614 .get_xstate = xfs_fs_getxstate,
1615 .set_xstate = xfs_fs_setxstate,
1616 .get_xquota = xfs_fs_getxquota,
1617 .set_xquota = xfs_fs_setxquota,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618};
1619
Andrew Morton5085b602007-02-20 13:57:47 -08001620static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 .owner = THIS_MODULE,
1622 .name = "xfs",
Nathan Scotta50cd262006-03-14 14:06:18 +11001623 .get_sb = xfs_fs_get_sb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 .kill_sb = kill_block_super,
1625 .fs_flags = FS_REQUIRES_DEV,
1626};
1627
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001628STATIC int __init
1629xfs_alloc_trace_bufs(void)
1630{
1631#ifdef XFS_ALLOC_TRACE
1632 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1633 if (!xfs_alloc_trace_buf)
1634 goto out;
1635#endif
1636#ifdef XFS_BMAP_TRACE
1637 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1638 if (!xfs_bmap_trace_buf)
1639 goto out_free_alloc_trace;
1640#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001641#ifdef XFS_BTREE_TRACE
1642 xfs_allocbt_trace_buf = ktrace_alloc(XFS_ALLOCBT_TRACE_SIZE,
1643 KM_MAYFAIL);
1644 if (!xfs_allocbt_trace_buf)
1645 goto out_free_bmap_trace;
1646
1647 xfs_inobt_trace_buf = ktrace_alloc(XFS_INOBT_TRACE_SIZE, KM_MAYFAIL);
1648 if (!xfs_inobt_trace_buf)
1649 goto out_free_allocbt_trace;
1650
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001651 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1652 if (!xfs_bmbt_trace_buf)
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001653 goto out_free_inobt_trace;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001654#endif
1655#ifdef XFS_ATTR_TRACE
1656 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1657 if (!xfs_attr_trace_buf)
1658 goto out_free_bmbt_trace;
1659#endif
1660#ifdef XFS_DIR2_TRACE
1661 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1662 if (!xfs_dir2_trace_buf)
1663 goto out_free_attr_trace;
1664#endif
1665
1666 return 0;
1667
1668#ifdef XFS_DIR2_TRACE
1669 out_free_attr_trace:
1670#endif
1671#ifdef XFS_ATTR_TRACE
1672 ktrace_free(xfs_attr_trace_buf);
1673 out_free_bmbt_trace:
1674#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001675#ifdef XFS_BTREE_TRACE
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001676 ktrace_free(xfs_bmbt_trace_buf);
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001677 out_free_inobt_trace:
1678 ktrace_free(xfs_inobt_trace_buf);
1679 out_free_allocbt_trace:
1680 ktrace_free(xfs_allocbt_trace_buf);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001681 out_free_bmap_trace:
1682#endif
1683#ifdef XFS_BMAP_TRACE
1684 ktrace_free(xfs_bmap_trace_buf);
1685 out_free_alloc_trace:
1686#endif
1687#ifdef XFS_ALLOC_TRACE
1688 ktrace_free(xfs_alloc_trace_buf);
1689 out:
1690#endif
1691 return -ENOMEM;
1692}
1693
1694STATIC void
1695xfs_free_trace_bufs(void)
1696{
1697#ifdef XFS_DIR2_TRACE
1698 ktrace_free(xfs_dir2_trace_buf);
1699#endif
1700#ifdef XFS_ATTR_TRACE
1701 ktrace_free(xfs_attr_trace_buf);
1702#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001703#ifdef XFS_BTREE_TRACE
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001704 ktrace_free(xfs_bmbt_trace_buf);
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001705 ktrace_free(xfs_inobt_trace_buf);
1706 ktrace_free(xfs_allocbt_trace_buf);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001707#endif
1708#ifdef XFS_BMAP_TRACE
1709 ktrace_free(xfs_bmap_trace_buf);
1710#endif
1711#ifdef XFS_ALLOC_TRACE
1712 ktrace_free(xfs_alloc_trace_buf);
1713#endif
1714}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
1716STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001717xfs_init_zones(void)
1718{
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001719
1720 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1721 if (!xfs_ioend_zone)
David Chinnerbf904242008-10-30 17:36:14 +11001722 goto out;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001723
1724 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1725 xfs_ioend_zone);
1726 if (!xfs_ioend_pool)
1727 goto out_destroy_ioend_zone;
1728
1729 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1730 "xfs_log_ticket");
1731 if (!xfs_log_ticket_zone)
1732 goto out_destroy_ioend_pool;
1733
1734 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1735 "xfs_bmap_free_item");
1736 if (!xfs_bmap_free_item_zone)
1737 goto out_destroy_log_ticket_zone;
David Chinnerbf904242008-10-30 17:36:14 +11001738
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001739 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1740 "xfs_btree_cur");
1741 if (!xfs_btree_cur_zone)
1742 goto out_destroy_bmap_free_item_zone;
1743
1744 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1745 "xfs_da_state");
1746 if (!xfs_da_state_zone)
1747 goto out_destroy_btree_cur_zone;
1748
1749 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
1750 if (!xfs_dabuf_zone)
1751 goto out_destroy_da_state_zone;
1752
1753 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1754 if (!xfs_ifork_zone)
1755 goto out_destroy_dabuf_zone;
1756
1757 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1758 if (!xfs_trans_zone)
1759 goto out_destroy_ifork_zone;
1760
1761 /*
1762 * The size of the zone allocated buf log item is the maximum
1763 * size possible under XFS. This wastes a little bit of memory,
1764 * but it is much faster.
1765 */
1766 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
1767 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
1768 NBWORD) * sizeof(int))), "xfs_buf_item");
1769 if (!xfs_buf_item_zone)
1770 goto out_destroy_trans_zone;
1771
1772 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1773 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1774 sizeof(xfs_extent_t))), "xfs_efd_item");
1775 if (!xfs_efd_zone)
1776 goto out_destroy_buf_item_zone;
1777
1778 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1779 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1780 sizeof(xfs_extent_t))), "xfs_efi_item");
1781 if (!xfs_efi_zone)
1782 goto out_destroy_efd_zone;
1783
1784 xfs_inode_zone =
1785 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
David Chinnerbf904242008-10-30 17:36:14 +11001786 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
1787 xfs_fs_inode_init_once);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001788 if (!xfs_inode_zone)
1789 goto out_destroy_efi_zone;
1790
1791 xfs_ili_zone =
1792 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1793 KM_ZONE_SPREAD, NULL);
1794 if (!xfs_ili_zone)
1795 goto out_destroy_inode_zone;
1796
1797#ifdef CONFIG_XFS_POSIX_ACL
1798 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
1799 if (!xfs_acl_zone)
1800 goto out_destroy_ili_zone;
1801#endif
1802
1803 return 0;
1804
1805#ifdef CONFIG_XFS_POSIX_ACL
1806 out_destroy_ili_zone:
1807#endif
1808 kmem_zone_destroy(xfs_ili_zone);
1809 out_destroy_inode_zone:
1810 kmem_zone_destroy(xfs_inode_zone);
1811 out_destroy_efi_zone:
1812 kmem_zone_destroy(xfs_efi_zone);
1813 out_destroy_efd_zone:
1814 kmem_zone_destroy(xfs_efd_zone);
1815 out_destroy_buf_item_zone:
1816 kmem_zone_destroy(xfs_buf_item_zone);
1817 out_destroy_trans_zone:
1818 kmem_zone_destroy(xfs_trans_zone);
1819 out_destroy_ifork_zone:
1820 kmem_zone_destroy(xfs_ifork_zone);
1821 out_destroy_dabuf_zone:
1822 kmem_zone_destroy(xfs_dabuf_zone);
1823 out_destroy_da_state_zone:
1824 kmem_zone_destroy(xfs_da_state_zone);
1825 out_destroy_btree_cur_zone:
1826 kmem_zone_destroy(xfs_btree_cur_zone);
1827 out_destroy_bmap_free_item_zone:
1828 kmem_zone_destroy(xfs_bmap_free_item_zone);
1829 out_destroy_log_ticket_zone:
1830 kmem_zone_destroy(xfs_log_ticket_zone);
1831 out_destroy_ioend_pool:
1832 mempool_destroy(xfs_ioend_pool);
1833 out_destroy_ioend_zone:
1834 kmem_zone_destroy(xfs_ioend_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001835 out:
1836 return -ENOMEM;
1837}
1838
1839STATIC void
1840xfs_destroy_zones(void)
1841{
1842#ifdef CONFIG_XFS_POSIX_ACL
1843 kmem_zone_destroy(xfs_acl_zone);
1844#endif
1845 kmem_zone_destroy(xfs_ili_zone);
1846 kmem_zone_destroy(xfs_inode_zone);
1847 kmem_zone_destroy(xfs_efi_zone);
1848 kmem_zone_destroy(xfs_efd_zone);
1849 kmem_zone_destroy(xfs_buf_item_zone);
1850 kmem_zone_destroy(xfs_trans_zone);
1851 kmem_zone_destroy(xfs_ifork_zone);
1852 kmem_zone_destroy(xfs_dabuf_zone);
1853 kmem_zone_destroy(xfs_da_state_zone);
1854 kmem_zone_destroy(xfs_btree_cur_zone);
1855 kmem_zone_destroy(xfs_bmap_free_item_zone);
1856 kmem_zone_destroy(xfs_log_ticket_zone);
1857 mempool_destroy(xfs_ioend_pool);
1858 kmem_zone_destroy(xfs_ioend_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001859
1860}
1861
1862STATIC int __init
1863init_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864{
1865 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
Christoph Hellwig65795912008-11-28 14:23:33 +11001867 printk(KERN_INFO XFS_VERSION_STRING " with "
1868 XFS_BUILD_OPTIONS " enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 ktrace_init(64);
Christoph Hellwig25e41b32008-12-03 12:20:39 +01001871 xfs_ioend_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001872 xfs_dir_startup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873
Nathan Scott87582802006-03-14 13:18:19 +11001874 error = xfs_init_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001875 if (error)
1876 goto out;
1877
1878 error = xfs_alloc_trace_bufs();
1879 if (error)
1880 goto out_destroy_zones;
1881
1882 error = xfs_mru_cache_init();
1883 if (error)
1884 goto out_free_trace_buffers;
1885
1886 error = xfs_filestream_init();
1887 if (error)
1888 goto out_mru_cache_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
Nathan Scottce8e9222006-01-11 15:39:08 +11001890 error = xfs_buf_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001891 if (error)
1892 goto out_filestream_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001894 error = xfs_init_procfs();
1895 if (error)
1896 goto out_buf_terminate;
1897
1898 error = xfs_sysctl_register();
1899 if (error)
1900 goto out_cleanup_procfs;
1901
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 vfs_initquota();
1903
1904 error = register_filesystem(&xfs_fs_type);
1905 if (error)
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001906 goto out_sysctl_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 return 0;
1908
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001909 out_sysctl_unregister:
1910 xfs_sysctl_unregister();
1911 out_cleanup_procfs:
1912 xfs_cleanup_procfs();
1913 out_buf_terminate:
Nathan Scottce8e9222006-01-11 15:39:08 +11001914 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001915 out_filestream_uninit:
1916 xfs_filestream_uninit();
1917 out_mru_cache_uninit:
1918 xfs_mru_cache_uninit();
1919 out_free_trace_buffers:
1920 xfs_free_trace_bufs();
1921 out_destroy_zones:
Nathan Scott87582802006-03-14 13:18:19 +11001922 xfs_destroy_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001923 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 return error;
1925}
1926
1927STATIC void __exit
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001928exit_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929{
1930 vfs_exitquota();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 unregister_filesystem(&xfs_fs_type);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001932 xfs_sysctl_unregister();
1933 xfs_cleanup_procfs();
Nathan Scottce8e9222006-01-11 15:39:08 +11001934 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001935 xfs_filestream_uninit();
1936 xfs_mru_cache_uninit();
1937 xfs_free_trace_bufs();
Nathan Scott87582802006-03-14 13:18:19 +11001938 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 ktrace_uninit();
1940}
1941
1942module_init(init_xfs_fs);
1943module_exit(exit_xfs_fs);
1944
1945MODULE_AUTHOR("Silicon Graphics, Inc.");
1946MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1947MODULE_LICENSE("GPL");