blob: cc5e07e3e7a1fed4ad49c055ea0d63cd18789efa [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"
Christoph Hellwig745f6912007-08-30 17:20:39 +100051#include "xfs_vfsops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include "xfs_version.h"
David Chinnera67d7c52007-11-23 16:29:32 +110053#include "xfs_log_priv.h"
David Chinner249a8c12008-02-05 12:13:32 +110054#include "xfs_trans_priv.h"
Christoph Hellwig48b62a12008-05-20 11:30:39 +100055#include "xfs_filestream.h"
Christoph Hellwig9f8868f2008-07-18 17:11:46 +100056#include "xfs_da_btree.h"
57#include "xfs_dir2_trace.h"
58#include "xfs_extfree_item.h"
59#include "xfs_mru_cache.h"
60#include "xfs_inode_item.h"
David Chinnerfe4fa4b2008-10-30 17:06:08 +110061#include "xfs_sync.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#include <linux/namei.h>
64#include <linux/init.h>
65#include <linux/mount.h>
Christoph Hellwig0829c362005-09-02 16:58:49 +100066#include <linux/mempool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#include <linux/writeback.h>
Christoph Hellwig4df08c52005-09-05 08:34:18 +100068#include <linux/kthread.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080069#include <linux/freezer.h>
Christoph Hellwig62a877e2008-07-18 17:12:36 +100070#include <linux/parser.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
David Chinner7989cb82007-02-10 18:34:56 +110072static struct quotactl_ops xfs_quotactl_operations;
73static struct super_operations xfs_super_operations;
David Chinner7989cb82007-02-10 18:34:56 +110074static kmem_zone_t *xfs_ioend_zone;
Christoph Hellwig0829c362005-09-02 16:58:49 +100075mempool_t *xfs_ioend_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
David Chinnera67d7c52007-11-23 16:29:32 +110077#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
78#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
79#define MNTOPT_LOGDEV "logdev" /* log device */
80#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
81#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
82#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
83#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
84#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
85#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
86#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
87#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
88#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
89#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
90#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
91#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
92#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
93#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
94#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
95#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
96#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
97 * unwritten extent conversion */
98#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
99#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
100#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
101#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
102#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
103#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
104#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
105 * in stat(). */
106#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
107#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
108#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
109#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
110#define MNTOPT_NOQUOTA "noquota" /* no quotas */
111#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
112#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
113#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
114#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
115#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
116#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
117#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
118#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
119#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
120#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
121#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
122#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
123#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
124
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000125/*
126 * Table driven mount option parser.
127 *
128 * Currently only used for remount, but it will be used for mount
129 * in the future, too.
130 */
131enum {
132 Opt_barrier, Opt_nobarrier, Opt_err
133};
134
Steven Whitehousea447c092008-10-13 10:46:57 +0100135static const match_table_t tokens = {
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000136 {Opt_barrier, "barrier"},
137 {Opt_nobarrier, "nobarrier"},
138 {Opt_err, NULL}
139};
140
141
David Chinnera67d7c52007-11-23 16:29:32 +1100142STATIC unsigned long
143suffix_strtoul(char *s, char **endp, unsigned int base)
144{
145 int last, shift_left_factor = 0;
146 char *value = s;
147
148 last = strlen(value) - 1;
149 if (value[last] == 'K' || value[last] == 'k') {
150 shift_left_factor = 10;
151 value[last] = '\0';
152 }
153 if (value[last] == 'M' || value[last] == 'm') {
154 shift_left_factor = 20;
155 value[last] = '\0';
156 }
157 if (value[last] == 'G' || value[last] == 'g') {
158 shift_left_factor = 30;
159 value[last] = '\0';
160 }
161
162 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
163}
164
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100165/*
166 * This function fills in xfs_mount_t fields based on mount args.
167 * Note: the superblock has _not_ yet been read in.
168 *
169 * Note that this function leaks the various device name allocations on
170 * failure. The caller takes care of them.
171 */
David Chinnera67d7c52007-11-23 16:29:32 +1100172STATIC int
173xfs_parseargs(
174 struct xfs_mount *mp,
175 char *options,
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100176 char **mtpt)
David Chinnera67d7c52007-11-23 16:29:32 +1100177{
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100178 struct super_block *sb = mp->m_super;
David Chinnera67d7c52007-11-23 16:29:32 +1100179 char *this_char, *value, *eov;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100180 int dsunit = 0;
181 int dswidth = 0;
182 int iosize = 0;
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100183 int dmapi_implies_ikeep = 1;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100184 uchar_t iosizelog = 0;
David Chinnera67d7c52007-11-23 16:29:32 +1100185
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100186 /*
187 * Copy binary VFS mount flags we are interested in.
188 */
189 if (sb->s_flags & MS_RDONLY)
190 mp->m_flags |= XFS_MOUNT_RDONLY;
191 if (sb->s_flags & MS_DIRSYNC)
192 mp->m_flags |= XFS_MOUNT_DIRSYNC;
193 if (sb->s_flags & MS_SYNCHRONOUS)
194 mp->m_flags |= XFS_MOUNT_WSYNC;
195
196 /*
197 * Set some default flags that could be cleared by the mount option
198 * parsing.
199 */
200 mp->m_flags |= XFS_MOUNT_BARRIER;
201 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
202 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
203
204 /*
205 * These can be overridden by the mount option parsing.
206 */
207 mp->m_logbufs = -1;
208 mp->m_logbsize = -1;
David Chinnera67d7c52007-11-23 16:29:32 +1100209
210 if (!options)
211 goto done;
212
David Chinnera67d7c52007-11-23 16:29:32 +1100213 while ((this_char = strsep(&options, ",")) != NULL) {
214 if (!*this_char)
215 continue;
216 if ((value = strchr(this_char, '=')) != NULL)
217 *value++ = 0;
218
219 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
220 if (!value || !*value) {
221 cmn_err(CE_WARN,
222 "XFS: %s option requires an argument",
223 this_char);
224 return EINVAL;
225 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100226 mp->m_logbufs = simple_strtoul(value, &eov, 10);
David Chinnera67d7c52007-11-23 16:29:32 +1100227 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
228 if (!value || !*value) {
229 cmn_err(CE_WARN,
230 "XFS: %s option requires an argument",
231 this_char);
232 return EINVAL;
233 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100234 mp->m_logbsize = suffix_strtoul(value, &eov, 10);
David Chinnera67d7c52007-11-23 16:29:32 +1100235 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
236 if (!value || !*value) {
237 cmn_err(CE_WARN,
238 "XFS: %s option requires an argument",
239 this_char);
240 return EINVAL;
241 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100242 mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
243 if (!mp->m_logname)
244 return ENOMEM;
David Chinnera67d7c52007-11-23 16:29:32 +1100245 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
246 if (!value || !*value) {
247 cmn_err(CE_WARN,
248 "XFS: %s option requires an argument",
249 this_char);
250 return EINVAL;
251 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100252 *mtpt = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
253 if (!*mtpt)
254 return ENOMEM;
David Chinnera67d7c52007-11-23 16:29:32 +1100255 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
256 if (!value || !*value) {
257 cmn_err(CE_WARN,
258 "XFS: %s option requires an argument",
259 this_char);
260 return EINVAL;
261 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100262 mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
263 if (!mp->m_rtname)
264 return ENOMEM;
David Chinnera67d7c52007-11-23 16:29:32 +1100265 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
266 if (!value || !*value) {
267 cmn_err(CE_WARN,
268 "XFS: %s option requires an argument",
269 this_char);
270 return EINVAL;
271 }
272 iosize = simple_strtoul(value, &eov, 10);
Christoph Hellwig1ec79442008-10-30 17:55:08 +1100273 iosizelog = ffs(iosize) - 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100274 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
275 if (!value || !*value) {
276 cmn_err(CE_WARN,
277 "XFS: %s option requires an argument",
278 this_char);
279 return EINVAL;
280 }
281 iosize = suffix_strtoul(value, &eov, 10);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100282 iosizelog = ffs(iosize) - 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100283 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
284 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
285 mp->m_flags |= XFS_MOUNT_GRPID;
286 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
287 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
288 mp->m_flags &= ~XFS_MOUNT_GRPID;
289 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100290 mp->m_flags |= XFS_MOUNT_WSYNC;
David Chinnera67d7c52007-11-23 16:29:32 +1100291 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100292 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
David Chinnera67d7c52007-11-23 16:29:32 +1100293 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100294 mp->m_flags |= XFS_MOUNT_NORECOVERY;
David Chinnera67d7c52007-11-23 16:29:32 +1100295 } else if (!strcmp(this_char, MNTOPT_INO64)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100296#if XFS_BIG_INUMS
297 mp->m_flags |= XFS_MOUNT_INO64;
298 mp->m_inoadd = XFS_INO64_OFFSET;
299#else
David Chinnera67d7c52007-11-23 16:29:32 +1100300 cmn_err(CE_WARN,
301 "XFS: %s option not allowed on this system",
302 this_char);
303 return EINVAL;
304#endif
305 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100306 mp->m_flags |= XFS_MOUNT_NOALIGN;
David Chinnera67d7c52007-11-23 16:29:32 +1100307 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100308 mp->m_flags |= XFS_MOUNT_SWALLOC;
David Chinnera67d7c52007-11-23 16:29:32 +1100309 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
310 if (!value || !*value) {
311 cmn_err(CE_WARN,
312 "XFS: %s option requires an argument",
313 this_char);
314 return EINVAL;
315 }
316 dsunit = simple_strtoul(value, &eov, 10);
317 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
318 if (!value || !*value) {
319 cmn_err(CE_WARN,
320 "XFS: %s option requires an argument",
321 this_char);
322 return EINVAL;
323 }
324 dswidth = simple_strtoul(value, &eov, 10);
325 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100326 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
David Chinnera67d7c52007-11-23 16:29:32 +1100327#if !XFS_BIG_INUMS
328 cmn_err(CE_WARN,
329 "XFS: %s option not allowed on this system",
330 this_char);
331 return EINVAL;
332#endif
333 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100334 mp->m_flags |= XFS_MOUNT_NOUUID;
David Chinnera67d7c52007-11-23 16:29:32 +1100335 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100336 mp->m_flags |= XFS_MOUNT_BARRIER;
David Chinnera67d7c52007-11-23 16:29:32 +1100337 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100338 mp->m_flags &= ~XFS_MOUNT_BARRIER;
David Chinnera67d7c52007-11-23 16:29:32 +1100339 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100340 mp->m_flags |= XFS_MOUNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100341 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100342 dmapi_implies_ikeep = 0;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100343 mp->m_flags &= ~XFS_MOUNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100344 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100345 mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
David Chinnera67d7c52007-11-23 16:29:32 +1100346 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100347 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
David Chinnera67d7c52007-11-23 16:29:32 +1100348 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100349 mp->m_flags |= XFS_MOUNT_ATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100350 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100351 mp->m_flags &= ~XFS_MOUNT_ATTR2;
352 mp->m_flags |= XFS_MOUNT_NOATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100353 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100354 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
David Chinnera67d7c52007-11-23 16:29:32 +1100355 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100356 mp->m_qflags &= ~(XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
357 XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
Christoph Hellwig469fc232008-10-30 17:54:57 +1100358 XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100359 XFS_UQUOTA_ENFD | XFS_OQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100360 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
361 !strcmp(this_char, MNTOPT_UQUOTA) ||
362 !strcmp(this_char, MNTOPT_USRQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100363 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
364 XFS_UQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100365 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
366 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100367 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
368 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
David Chinnera67d7c52007-11-23 16:29:32 +1100369 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
370 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100371 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
372 XFS_OQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100373 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100374 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
375 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
David Chinnera67d7c52007-11-23 16:29:32 +1100376 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
377 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100378 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
379 XFS_OQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100380 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100381 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
382 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
David Chinnera67d7c52007-11-23 16:29:32 +1100383 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100384 mp->m_flags |= XFS_MOUNT_DMAPI;
David Chinnera67d7c52007-11-23 16:29:32 +1100385 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100386 mp->m_flags |= XFS_MOUNT_DMAPI;
David Chinnera67d7c52007-11-23 16:29:32 +1100387 } else if (!strcmp(this_char, MNTOPT_DMI)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100388 mp->m_flags |= XFS_MOUNT_DMAPI;
David Chinnera67d7c52007-11-23 16:29:32 +1100389 } else if (!strcmp(this_char, "ihashsize")) {
390 cmn_err(CE_WARN,
391 "XFS: ihashsize no longer used, option is deprecated.");
392 } else if (!strcmp(this_char, "osyncisdsync")) {
393 /* no-op, this is now the default */
394 cmn_err(CE_WARN,
395 "XFS: osyncisdsync is now the default, option is deprecated.");
396 } else if (!strcmp(this_char, "irixsgid")) {
397 cmn_err(CE_WARN,
398 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
399 } else {
400 cmn_err(CE_WARN,
401 "XFS: unknown mount option [%s].", this_char);
402 return EINVAL;
403 }
404 }
405
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100406 /*
407 * no recovery flag requires a read-only mount
408 */
409 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
410 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
411 cmn_err(CE_WARN, "XFS: no-recovery mounts must be read-only.");
412 return EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100413 }
414
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100415 if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
David Chinnera67d7c52007-11-23 16:29:32 +1100416 cmn_err(CE_WARN,
417 "XFS: sunit and swidth options incompatible with the noalign option");
418 return EINVAL;
419 }
420
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100421 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
422 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE))) {
David Chinnera67d7c52007-11-23 16:29:32 +1100423 cmn_err(CE_WARN,
424 "XFS: cannot mount with both project and group quota");
425 return EINVAL;
426 }
427
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100428 if ((mp->m_flags & XFS_MOUNT_DMAPI) && (!*mtpt || *mtpt[0] == '\0')) {
David Chinnera67d7c52007-11-23 16:29:32 +1100429 printk("XFS: %s option needs the mount point option as well\n",
430 MNTOPT_DMAPI);
431 return EINVAL;
432 }
433
434 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
435 cmn_err(CE_WARN,
436 "XFS: sunit and swidth must be specified together");
437 return EINVAL;
438 }
439
440 if (dsunit && (dswidth % dsunit != 0)) {
441 cmn_err(CE_WARN,
442 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
443 dswidth, dsunit);
444 return EINVAL;
445 }
446
447 /*
448 * Applications using DMI filesystems often expect the
449 * inode generation number to be monotonically increasing.
450 * If we delete inode chunks we break this assumption, so
451 * keep unused inode chunks on disk for DMI filesystems
452 * until we come up with a better solution.
453 * Note that if "ikeep" or "noikeep" mount options are
454 * supplied, then they are honored.
455 */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100456 if ((mp->m_flags & XFS_MOUNT_DMAPI) && dmapi_implies_ikeep)
457 mp->m_flags |= XFS_MOUNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100458
459done:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100460 if (!(mp->m_flags & XFS_MOUNT_NOALIGN)) {
461 /*
462 * At this point the superblock has not been read
463 * in, therefore we do not know the block size.
464 * Before the mount call ends we will convert
465 * these to FSBs.
466 */
467 if (dsunit) {
468 mp->m_dalign = dsunit;
469 mp->m_flags |= XFS_MOUNT_RETERR;
470 }
471
472 if (dswidth)
473 mp->m_swidth = dswidth;
474 }
475
476 if (mp->m_logbufs != -1 &&
477 mp->m_logbufs != 0 &&
478 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
479 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
480 cmn_err(CE_WARN,
481 "XFS: invalid logbufs value: %d [not %d-%d]",
482 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
483 return XFS_ERROR(EINVAL);
484 }
485 if (mp->m_logbsize != -1 &&
486 mp->m_logbsize != 0 &&
487 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
488 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
489 !is_power_of_2(mp->m_logbsize))) {
490 cmn_err(CE_WARN,
491 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
492 mp->m_logbsize);
493 return XFS_ERROR(EINVAL);
494 }
495
496 mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
497 if (!mp->m_fsname)
498 return ENOMEM;
499 mp->m_fsname_len = strlen(mp->m_fsname) + 1;
500
501 if (iosizelog) {
502 if (iosizelog > XFS_MAX_IO_LOG ||
503 iosizelog < XFS_MIN_IO_LOG) {
504 cmn_err(CE_WARN,
505 "XFS: invalid log iosize: %d [not %d-%d]",
506 iosizelog, XFS_MIN_IO_LOG,
507 XFS_MAX_IO_LOG);
508 return XFS_ERROR(EINVAL);
509 }
510
511 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
512 mp->m_readio_log = iosizelog;
513 mp->m_writeio_log = iosizelog;
514 }
515
David Chinnera67d7c52007-11-23 16:29:32 +1100516 return 0;
517}
518
519struct proc_xfs_info {
520 int flag;
521 char *str;
522};
523
524STATIC int
525xfs_showargs(
526 struct xfs_mount *mp,
527 struct seq_file *m)
528{
529 static struct proc_xfs_info xfs_info_set[] = {
530 /* the few simple ones we can get from the mount struct */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100531 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
David Chinnera67d7c52007-11-23 16:29:32 +1100532 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
533 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
534 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
535 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
536 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
537 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
538 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
539 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
540 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
541 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
542 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
543 { 0, NULL }
544 };
545 static struct proc_xfs_info xfs_info_unset[] = {
546 /* the few simple ones we can get from the mount struct */
David Chinnera67d7c52007-11-23 16:29:32 +1100547 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
548 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
549 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
550 { 0, NULL }
551 };
552 struct proc_xfs_info *xfs_infop;
553
554 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
555 if (mp->m_flags & xfs_infop->flag)
556 seq_puts(m, xfs_infop->str);
557 }
558 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
559 if (!(mp->m_flags & xfs_infop->flag))
560 seq_puts(m, xfs_infop->str);
561 }
562
563 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
564 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
565 (int)(1 << mp->m_writeio_log) >> 10);
566
567 if (mp->m_logbufs > 0)
568 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
569 if (mp->m_logbsize > 0)
570 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
571
572 if (mp->m_logname)
573 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
574 if (mp->m_rtname)
575 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
576
577 if (mp->m_dalign > 0)
578 seq_printf(m, "," MNTOPT_SUNIT "=%d",
579 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
580 if (mp->m_swidth > 0)
581 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
582 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
583
584 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
585 seq_puts(m, "," MNTOPT_USRQUOTA);
586 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
587 seq_puts(m, "," MNTOPT_UQUOTANOENF);
588
589 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
590 seq_puts(m, "," MNTOPT_PRJQUOTA);
591 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
592 seq_puts(m, "," MNTOPT_PQUOTANOENF);
593
594 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
595 seq_puts(m, "," MNTOPT_GRPQUOTA);
596 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
597 seq_puts(m, "," MNTOPT_GQUOTANOENF);
598
599 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
600 seq_puts(m, "," MNTOPT_NOQUOTA);
601
602 return 0;
603}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604__uint64_t
605xfs_max_file_offset(
606 unsigned int blockshift)
607{
608 unsigned int pagefactor = 1;
609 unsigned int bitshift = BITS_PER_LONG - 1;
610
611 /* Figure out maximum filesize, on Linux this can depend on
612 * the filesystem blocksize (on 32 bit platforms).
613 * __block_prepare_write does this in an [unsigned] long...
614 * page->index << (PAGE_CACHE_SHIFT - bbits)
615 * So, for page sized blocks (4K on 32 bit platforms),
616 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
617 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
618 * but for smaller blocksizes it is less (bbits = log2 bsize).
619 * Note1: get_block_t takes a long (implicit cast from above)
620 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
621 * can optionally convert the [unsigned] long from above into
622 * an [unsigned] long long.
623 */
624
625#if BITS_PER_LONG == 32
626# if defined(CONFIG_LBD)
627 ASSERT(sizeof(sector_t) == 8);
628 pagefactor = PAGE_CACHE_SIZE;
629 bitshift = BITS_PER_LONG;
630# else
631 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
632# endif
633#endif
634
635 return (((__uint64_t)pagefactor) << bitshift) - 1;
636}
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638int
639xfs_blkdev_get(
640 xfs_mount_t *mp,
641 const char *name,
642 struct block_device **bdevp)
643{
644 int error = 0;
645
Al Viro30c40d22008-02-22 19:50:45 -0500646 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (IS_ERR(*bdevp)) {
648 error = PTR_ERR(*bdevp);
649 printk("XFS: Invalid device [%s], error=%d\n", name, error);
650 }
651
652 return -error;
653}
654
655void
656xfs_blkdev_put(
657 struct block_device *bdev)
658{
659 if (bdev)
Al Viro30c40d22008-02-22 19:50:45 -0500660 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
662
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100663/*
664 * Try to write out the superblock using barriers.
665 */
666STATIC int
667xfs_barrier_test(
668 xfs_mount_t *mp)
669{
670 xfs_buf_t *sbp = xfs_getsb(mp, 0);
671 int error;
672
673 XFS_BUF_UNDONE(sbp);
674 XFS_BUF_UNREAD(sbp);
675 XFS_BUF_UNDELAYWRITE(sbp);
676 XFS_BUF_WRITE(sbp);
677 XFS_BUF_UNASYNC(sbp);
678 XFS_BUF_ORDERED(sbp);
679
680 xfsbdstrat(mp, sbp);
681 error = xfs_iowait(sbp);
682
683 /*
684 * Clear all the flags we set and possible error state in the
685 * buffer. We only did the write to try out whether barriers
686 * worked and shouldn't leave any traces in the superblock
687 * buffer.
688 */
689 XFS_BUF_DONE(sbp);
690 XFS_BUF_ERROR(sbp, 0);
691 XFS_BUF_UNORDERED(sbp);
692
693 xfs_buf_relse(sbp);
694 return error;
695}
696
697void
698xfs_mountfs_check_barriers(xfs_mount_t *mp)
699{
700 int error;
701
702 if (mp->m_logdev_targp != mp->m_ddev_targp) {
703 xfs_fs_cmn_err(CE_NOTE, mp,
704 "Disabling barriers, not supported with external log device");
705 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100706 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100707 }
708
Nathan Scottb2ea4012006-07-28 17:05:13 +1000709 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
710 xfs_fs_cmn_err(CE_NOTE, mp,
711 "Disabling barriers, underlying device is readonly");
712 mp->m_flags &= ~XFS_MOUNT_BARRIER;
713 return;
714 }
715
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100716 error = xfs_barrier_test(mp);
717 if (error) {
718 xfs_fs_cmn_err(CE_NOTE, mp,
719 "Disabling barriers, trial barrier write failed");
720 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100721 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100722 }
723}
724
725void
726xfs_blkdev_issue_flush(
727 xfs_buftarg_t *buftarg)
728{
Nathan Scottce8e9222006-01-11 15:39:08 +1100729 blkdev_issue_flush(buftarg->bt_bdev, NULL);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100730}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000732STATIC void
733xfs_close_devices(
734 struct xfs_mount *mp)
735{
736 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000737 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000738 xfs_free_buftarg(mp->m_logdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000739 xfs_blkdev_put(logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000740 }
741 if (mp->m_rtdev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000742 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000743 xfs_free_buftarg(mp->m_rtdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000744 xfs_blkdev_put(rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000745 }
746 xfs_free_buftarg(mp->m_ddev_targp);
747}
748
749/*
750 * The file system configurations are:
751 * (1) device (partition) with data and internal log
752 * (2) logical volume with data and log subvolumes.
753 * (3) logical volume with data, log, and realtime subvolumes.
754 *
755 * We only have to handle opening the log and realtime volumes here if
756 * they are present. The data subvolume has already been opened by
757 * get_sb_bdev() and is stored in sb->s_bdev.
758 */
759STATIC int
760xfs_open_devices(
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100761 struct xfs_mount *mp)
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000762{
763 struct block_device *ddev = mp->m_super->s_bdev;
764 struct block_device *logdev = NULL, *rtdev = NULL;
765 int error;
766
767 /*
768 * Open real time and log devices - order is important.
769 */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100770 if (mp->m_logname) {
771 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000772 if (error)
773 goto out;
774 }
775
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100776 if (mp->m_rtname) {
777 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000778 if (error)
779 goto out_close_logdev;
780
781 if (rtdev == ddev || rtdev == logdev) {
782 cmn_err(CE_WARN,
783 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
784 error = EINVAL;
785 goto out_close_rtdev;
786 }
787 }
788
789 /*
790 * Setup xfs_mount buffer target pointers
791 */
792 error = ENOMEM;
793 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
794 if (!mp->m_ddev_targp)
795 goto out_close_rtdev;
796
797 if (rtdev) {
798 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
799 if (!mp->m_rtdev_targp)
800 goto out_free_ddev_targ;
801 }
802
803 if (logdev && logdev != ddev) {
804 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
805 if (!mp->m_logdev_targp)
806 goto out_free_rtdev_targ;
807 } else {
808 mp->m_logdev_targp = mp->m_ddev_targp;
809 }
810
811 return 0;
812
813 out_free_rtdev_targ:
814 if (mp->m_rtdev_targp)
815 xfs_free_buftarg(mp->m_rtdev_targp);
816 out_free_ddev_targ:
817 xfs_free_buftarg(mp->m_ddev_targp);
818 out_close_rtdev:
819 if (rtdev)
820 xfs_blkdev_put(rtdev);
821 out_close_logdev:
822 if (logdev && logdev != ddev)
823 xfs_blkdev_put(logdev);
824 out:
825 return error;
826}
827
Christoph Hellwige34b5622008-05-20 15:10:36 +1000828/*
829 * Setup xfs_mount buffer target pointers based on superblock
830 */
831STATIC int
832xfs_setup_devices(
833 struct xfs_mount *mp)
834{
835 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000836
Christoph Hellwige34b5622008-05-20 15:10:36 +1000837 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
838 mp->m_sb.sb_sectsize);
839 if (error)
840 return error;
841
842 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
843 unsigned int log_sector_size = BBSIZE;
844
845 if (xfs_sb_version_hassector(&mp->m_sb))
846 log_sector_size = mp->m_sb.sb_logsectsize;
847 error = xfs_setsize_buftarg(mp->m_logdev_targp,
848 mp->m_sb.sb_blocksize,
849 log_sector_size);
850 if (error)
851 return error;
852 }
853 if (mp->m_rtdev_targp) {
854 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
855 mp->m_sb.sb_blocksize,
856 mp->m_sb.sb_sectsize);
857 if (error)
858 return error;
859 }
860
861 return 0;
862}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000863
David Chinner249a8c12008-02-05 12:13:32 +1100864/*
865 * XFS AIL push thread support
866 */
867void
868xfsaild_wakeup(
David Chinner82fa9012008-10-30 17:38:26 +1100869 struct xfs_ail *ailp,
David Chinner249a8c12008-02-05 12:13:32 +1100870 xfs_lsn_t threshold_lsn)
871{
David Chinner82fa9012008-10-30 17:38:26 +1100872 ailp->xa_target = threshold_lsn;
873 wake_up_process(ailp->xa_task);
David Chinner249a8c12008-02-05 12:13:32 +1100874}
875
876int
877xfsaild(
878 void *data)
879{
David Chinner82fa9012008-10-30 17:38:26 +1100880 struct xfs_ail *ailp = data;
David Chinner249a8c12008-02-05 12:13:32 +1100881 xfs_lsn_t last_pushed_lsn = 0;
882 long tout = 0;
883
884 while (!kthread_should_stop()) {
885 if (tout)
886 schedule_timeout_interruptible(msecs_to_jiffies(tout));
887 tout = 1000;
888
889 /* swsusp */
890 try_to_freeze();
891
David Chinner82fa9012008-10-30 17:38:26 +1100892 ASSERT(ailp->xa_mount->m_log);
893 if (XFS_FORCED_SHUTDOWN(ailp->xa_mount))
David Chinner249a8c12008-02-05 12:13:32 +1100894 continue;
895
David Chinner82fa9012008-10-30 17:38:26 +1100896 tout = xfsaild_push(ailp, &last_pushed_lsn);
David Chinner249a8c12008-02-05 12:13:32 +1100897 }
898
899 return 0;
900} /* xfsaild */
901
902int
903xfsaild_start(
David Chinner82fa9012008-10-30 17:38:26 +1100904 struct xfs_ail *ailp)
David Chinner249a8c12008-02-05 12:13:32 +1100905{
David Chinner82fa9012008-10-30 17:38:26 +1100906 ailp->xa_target = 0;
907 ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild");
908 if (IS_ERR(ailp->xa_task))
909 return -PTR_ERR(ailp->xa_task);
David Chinner249a8c12008-02-05 12:13:32 +1100910 return 0;
911}
912
913void
914xfsaild_stop(
David Chinner82fa9012008-10-30 17:38:26 +1100915 struct xfs_ail *ailp)
David Chinner249a8c12008-02-05 12:13:32 +1100916{
David Chinner82fa9012008-10-30 17:38:26 +1100917 kthread_stop(ailp->xa_task);
David Chinner249a8c12008-02-05 12:13:32 +1100918}
919
920
David Chinnerbf904242008-10-30 17:36:14 +1100921/* Catch misguided souls that try to use this interface on XFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100923xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 struct super_block *sb)
925{
David Chinnerbf904242008-10-30 17:36:14 +1100926 BUG();
Lachlan McIlroy493dca62008-10-30 17:36:52 +1100927 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928}
929
David Chinnerbf904242008-10-30 17:36:14 +1100930/*
David Chinner99fa8cb2008-10-30 17:36:40 +1100931 * Now that the generic code is guaranteed not to be accessing
932 * the linux inode, we can reclaim the inode.
David Chinnerbf904242008-10-30 17:36:14 +1100933 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100935xfs_fs_destroy_inode(
David Chinnerbf904242008-10-30 17:36:14 +1100936 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937{
David Chinner99fa8cb2008-10-30 17:36:40 +1100938 xfs_inode_t *ip = XFS_I(inode);
939
940 XFS_STATS_INC(vn_reclaim);
941 if (xfs_reclaim(ip))
942 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943}
944
David Chinner07c8f672008-10-30 16:11:59 +1100945/*
946 * Slab object creation initialisation for the XFS inode.
947 * This covers only the idempotent fields in the XFS inode;
948 * all other fields need to be initialised on allocation
949 * from the slab. This avoids the need to repeatedly intialise
950 * fields in the xfs inode that left in the initialise state
951 * when freeing the inode.
952 */
David Chinnerbf904242008-10-30 17:36:14 +1100953STATIC void
954xfs_fs_inode_init_once(
David Chinner07c8f672008-10-30 16:11:59 +1100955 void *inode)
956{
957 struct xfs_inode *ip = inode;
958
959 memset(ip, 0, sizeof(struct xfs_inode));
David Chinnerbf904242008-10-30 17:36:14 +1100960
961 /* vfs inode */
962 inode_init_once(VFS_I(ip));
963
964 /* xfs inode */
David Chinner07c8f672008-10-30 16:11:59 +1100965 atomic_set(&ip->i_iocount, 0);
966 atomic_set(&ip->i_pincount, 0);
967 spin_lock_init(&ip->i_flags_lock);
David Chinner07c8f672008-10-30 16:11:59 +1100968 init_waitqueue_head(&ip->i_ipin_wait);
969 /*
970 * Because we want to use a counting completion, complete
971 * the flush completion once to allow a single access to
972 * the flush completion without blocking.
973 */
974 init_completion(&ip->i_flush);
975 complete(&ip->i_flush);
976
977 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
978 "xfsino", ip->i_ino);
979 mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
980}
981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982/*
983 * Attempt to flush the inode, this will actually fail
984 * if the inode is pinned, but we dirty the inode again
985 * at the point when it is unpinned after a log write,
Nathan Scott87582802006-03-14 13:18:19 +1100986 * since this is when the inode itself becomes flushable.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 */
988STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +1100989xfs_fs_write_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 struct inode *inode,
991 int sync)
992{
David Chinnera3f74ff2008-03-06 13:43:42 +1100993 int error = 0;
994 int flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100996 xfs_itrace_entry(XFS_I(inode));
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000997 if (sync) {
998 filemap_fdatawait(inode->i_mapping);
999 flags |= FLUSH_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 }
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001001 error = xfs_inode_flush(XFS_I(inode), flags);
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001002 /*
1003 * if we failed to write out the inode then mark
1004 * it dirty again so we'll try again later.
1005 */
1006 if (error)
David Chinner94b97e32008-10-30 17:21:30 +11001007 xfs_mark_inode_dirty_sync(XFS_I(inode));
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001008
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 return -error;
1010}
1011
1012STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001013xfs_fs_clear_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 struct inode *inode)
1015{
Christoph Hellwig1543d792007-08-29 11:46:47 +10001016 xfs_inode_t *ip = XFS_I(inode);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001017
David Chinner99fa8cb2008-10-30 17:36:40 +11001018 xfs_itrace_entry(ip);
1019 XFS_STATS_INC(vn_rele);
1020 XFS_STATS_INC(vn_remove);
1021 XFS_STATS_DEC(vn_active);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001022
David Chinner99fa8cb2008-10-30 17:36:40 +11001023 xfs_inactive(ip);
1024 xfs_iflags_clear(ip, XFS_IMODIFIED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025}
1026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027STATIC void
Christoph Hellwiga7381592008-08-13 16:04:05 +10001028xfs_free_fsname(
1029 struct xfs_mount *mp)
1030{
1031 kfree(mp->m_fsname);
1032 kfree(mp->m_rtname);
1033 kfree(mp->m_logname);
1034}
1035
1036STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001037xfs_fs_put_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 struct super_block *sb)
1039{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001040 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001041 struct xfs_inode *rip = mp->m_rootip;
1042 int unmount_event_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 int error;
1044
David Chinnera167b172008-10-30 17:06:18 +11001045 xfs_syncd_stop(mp);
David Chinnerbe97d9d2008-10-30 17:15:38 +11001046 xfs_sync_inodes(mp, SYNC_ATTR|SYNC_DELWRI);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001047
1048#ifdef HAVE_DMAPI
1049 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1050 unmount_event_flags =
1051 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1052 0 : DM_FLAGS_UNWANTED;
1053 /*
1054 * Ignore error from dmapi here, first unmount is not allowed
1055 * to fail anyway, and second we wouldn't want to fail a
1056 * unmount because of dmapi.
1057 */
1058 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1059 NULL, NULL, 0, 0, unmount_event_flags);
1060 }
1061#endif
1062
1063 /*
1064 * Blow away any referenced inode in the filestreams cache.
1065 * This can and will cause log traffic as inodes go inactive
1066 * here.
1067 */
1068 xfs_filestream_unmount(mp);
1069
1070 XFS_bflush(mp->m_ddev_targp);
1071 error = xfs_unmount_flush(mp, 0);
1072 WARN_ON(error);
1073
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001074 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1075 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1076 unmount_event_flags);
1077 }
1078
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001079 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001080 xfs_freesb(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001081 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001082 xfs_close_devices(mp);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001083 xfs_qmops_put(mp);
1084 xfs_dmops_put(mp);
Christoph Hellwiga7381592008-08-13 16:04:05 +10001085 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001086 kfree(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087}
1088
1089STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001090xfs_fs_write_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 struct super_block *sb)
1092{
Nathan Scottb83bd132006-06-09 16:48:30 +10001093 if (!(sb->s_flags & MS_RDONLY))
David Chinnere9f1c6e2008-10-30 17:15:50 +11001094 xfs_sync_fsdata(XFS_M(sb), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 sb->s_dirt = 0;
1096}
1097
1098STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001099xfs_fs_sync_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 struct super_block *sb,
1101 int wait)
1102{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001103 struct xfs_mount *mp = XFS_M(sb);
Nathan Scottb83bd132006-06-09 16:48:30 +10001104 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001106 /*
1107 * Treat a sync operation like a freeze. This is to work
1108 * around a race in sync_inodes() which works in two phases
1109 * - an asynchronous flush, which can write out an inode
1110 * without waiting for file size updates to complete, and a
1111 * synchronous flush, which wont do anything because the
1112 * async flush removed the inode's dirty flag. Also
1113 * sync_inodes() will not see any files that just have
1114 * outstanding transactions to be flushed because we don't
1115 * dirty the Linux inode until after the transaction I/O
1116 * completes.
1117 */
David Chinnere9f1c6e2008-10-30 17:15:50 +11001118 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE))
1119 error = xfs_quiesce_data(mp);
1120 else
1121 error = xfs_sync_fsdata(mp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 sb->s_dirt = 0;
1123
1124 if (unlikely(laptop_mode)) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001125 int prev_sync_seq = mp->m_sync_seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
1127 /*
1128 * The disk must be active because we're syncing.
1129 * We schedule xfssyncd now (now that the disk is
1130 * active) instead of later (when it might not be).
1131 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001132 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 /*
1134 * We have to wait for the sync iteration to complete.
1135 * If we don't, the disk activity caused by the sync
1136 * will come after the sync is completed, and that
1137 * triggers another sync from laptop mode.
1138 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001139 wait_event(mp->m_wait_single_sync_task,
1140 mp->m_sync_seq != prev_sync_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 }
1142
1143 return -error;
1144}
1145
1146STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001147xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001148 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 struct kstatfs *statp)
1150{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001151 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1152 xfs_sb_t *sbp = &mp->m_sb;
1153 __uint64_t fakeinos, id;
1154 xfs_extlen_t lsize;
1155
1156 statp->f_type = XFS_SB_MAGIC;
1157 statp->f_namelen = MAXNAMELEN - 1;
1158
1159 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1160 statp->f_fsid.val[0] = (u32)id;
1161 statp->f_fsid.val[1] = (u32)(id >> 32);
1162
Christoph Hellwigd4d90b52008-04-22 17:34:37 +10001163 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001164
1165 spin_lock(&mp->m_sb_lock);
1166 statp->f_bsize = sbp->sb_blocksize;
1167 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1168 statp->f_blocks = sbp->sb_dblocks - lsize;
1169 statp->f_bfree = statp->f_bavail =
1170 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1171 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1172#if XFS_BIG_INUMS
1173 fakeinos += mp->m_inoadd;
1174#endif
1175 statp->f_files =
1176 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1177 if (mp->m_maxicount)
1178#if XFS_BIG_INUMS
1179 if (!mp->m_inoadd)
1180#endif
1181 statp->f_files = min_t(typeof(statp->f_files),
1182 statp->f_files,
1183 mp->m_maxicount);
1184 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1185 spin_unlock(&mp->m_sb_lock);
1186
1187 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1188 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
1191STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001192xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 struct super_block *sb,
1194 int *flags,
1195 char *options)
1196{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001197 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001198 substring_t args[MAX_OPT_ARGS];
1199 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001201 while ((p = strsep(&options, ",")) != NULL) {
1202 int token;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001203
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001204 if (!*p)
1205 continue;
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001206
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001207 token = match_token(p, tokens, args);
1208 switch (token) {
1209 case Opt_barrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001210 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001211
1212 /*
1213 * Test if barriers are actually working if we can,
1214 * else delay this check until the filesystem is
1215 * marked writeable.
1216 */
1217 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1218 xfs_mountfs_check_barriers(mp);
1219 break;
1220 case Opt_nobarrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001221 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001222 break;
1223 default:
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001224 /*
1225 * Logically we would return an error here to prevent
1226 * users from believing they might have changed
1227 * mount options using remount which can't be changed.
1228 *
1229 * But unfortunately mount(8) adds all options from
1230 * mtab and fstab to the mount arguments in some cases
1231 * so we can't blindly reject options, but have to
1232 * check for each specified option if it actually
1233 * differs from the currently set option and only
1234 * reject it if that's the case.
1235 *
1236 * Until that is implemented we return success for
1237 * every remount request, and silently ignore all
1238 * options that we can't actually change.
1239 */
1240#if 0
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001241 printk(KERN_INFO
1242 "XFS: mount option \"%s\" not supported for remount\n", p);
1243 return -EINVAL;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001244#else
Christoph Hellwig6c5e51d2008-10-12 14:30:44 +02001245 break;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001246#endif
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001247 }
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001248 }
1249
1250 /* rw/ro -> rw */
1251 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1252 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1253 if (mp->m_flags & XFS_MOUNT_BARRIER)
1254 xfs_mountfs_check_barriers(mp);
1255 }
1256
1257 /* rw -> ro */
1258 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
David Chinnere9f1c6e2008-10-30 17:15:50 +11001259 xfs_quiesce_data(mp);
David Chinner76bf1052008-10-30 17:16:21 +11001260 xfs_quiesce_attr(mp);
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001261 mp->m_flags |= XFS_MOUNT_RDONLY;
1262 }
1263
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001264 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001267/*
1268 * Second stage of a freeze. The data is already frozen so we only
David Chinner76bf1052008-10-30 17:16:21 +11001269 * need to take care of the metadata. Once that's done write a dummy
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001270 * record to dirty the log in case of a crash while frozen.
1271 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001273xfs_fs_lockfs(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 struct super_block *sb)
1275{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001276 struct xfs_mount *mp = XFS_M(sb);
1277
David Chinner76bf1052008-10-30 17:16:21 +11001278 xfs_quiesce_attr(mp);
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001279 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280}
1281
1282STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001283xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 struct seq_file *m,
1285 struct vfsmount *mnt)
1286{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001287 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288}
1289
1290STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001291xfs_fs_quotasync(
Nathan Scottee348072005-11-02 10:32:38 +11001292 struct super_block *sb,
1293 int type)
1294{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001295 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
Nathan Scottee348072005-11-02 10:32:38 +11001296}
1297
1298STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001299xfs_fs_getxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 struct super_block *sb,
1301 struct fs_quota_stat *fqs)
1302{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001303 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304}
1305
1306STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001307xfs_fs_setxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 struct super_block *sb,
1309 unsigned int flags,
1310 int op)
1311{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001312 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313}
1314
1315STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001316xfs_fs_getxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 struct super_block *sb,
1318 int type,
1319 qid_t id,
1320 struct fs_disk_quota *fdq)
1321{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001322 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001323 (type == USRQUOTA) ? Q_XGETQUOTA :
1324 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1325 Q_XGETPQUOTA), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
1328STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001329xfs_fs_setxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 struct super_block *sb,
1331 int type,
1332 qid_t id,
1333 struct fs_disk_quota *fdq)
1334{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001335 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001336 (type == USRQUOTA) ? Q_XSETQLIM :
1337 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1338 Q_XSETPQLIM), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339}
1340
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001341/*
1342 * This function fills in xfs_mount_t fields based on mount args.
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001343 * Note: the superblock _has_ now been read in.
1344 */
1345STATIC int
1346xfs_finish_flags(
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001347 struct xfs_mount *mp)
1348{
1349 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1350
1351 /* Fail a mount where the logbuf is smaller then the log stripe */
1352 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001353 if (mp->m_logbsize <= 0 &&
1354 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001355 mp->m_logbsize = mp->m_sb.sb_logsunit;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001356 } else if (mp->m_logbsize > 0 &&
1357 mp->m_logbsize < mp->m_sb.sb_logsunit) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001358 cmn_err(CE_WARN,
1359 "XFS: logbuf size must be greater than or equal to log stripe size");
1360 return XFS_ERROR(EINVAL);
1361 }
1362 } else {
1363 /* Fail a mount if the logbuf is larger than 32K */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001364 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001365 cmn_err(CE_WARN,
1366 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1367 return XFS_ERROR(EINVAL);
1368 }
1369 }
1370
1371 /*
1372 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1373 * told by noattr2 to turn it off
1374 */
1375 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001376 !(mp->m_flags & XFS_MOUNT_NOATTR2))
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001377 mp->m_flags |= XFS_MOUNT_ATTR2;
1378
1379 /*
1380 * prohibit r/w mounts of read-only filesystems
1381 */
1382 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1383 cmn_err(CE_WARN,
1384 "XFS: cannot mount a read-only filesystem as read-write");
1385 return XFS_ERROR(EROFS);
1386 }
1387
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001388#if 0 /* shared mounts were never supported on Linux */
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001389 /*
1390 * check for shared mount.
1391 */
1392 if (ap->flags & XFSMNT_SHARED) {
1393 if (!xfs_sb_version_hasshared(&mp->m_sb))
1394 return XFS_ERROR(EINVAL);
1395
1396 /*
1397 * For IRIX 6.5, shared mounts must have the shared
1398 * version bit set, have the persistent readonly
1399 * field set, must be version 0 and can only be mounted
1400 * read-only.
1401 */
1402 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1403 (mp->m_sb.sb_shared_vn != 0))
1404 return XFS_ERROR(EINVAL);
1405
1406 mp->m_flags |= XFS_MOUNT_SHARED;
1407
1408 /*
1409 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1410 */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001411 if (mp->m_sb.sb_shared_vn == 0 &&
1412 (mp->m_flags & XFS_MOUNT_DMAPI))
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001413 return XFS_ERROR(EINVAL);
1414 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001415#endif
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001416
1417 return 0;
1418}
1419
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001421xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 struct super_block *sb,
1423 void *data,
1424 int silent)
1425{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001426 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001427 struct xfs_mount *mp = NULL;
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001428 int flags = 0, error = ENOMEM;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001429 char *mtpt = NULL;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001430
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001431 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1432 if (!mp)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001433 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001435 spin_lock_init(&mp->m_sb_lock);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001436 mutex_init(&mp->m_growlock);
1437 atomic_set(&mp->m_active_trans, 0);
Christoph Hellwig74394492007-08-30 17:21:22 +10001438 INIT_LIST_HEAD(&mp->m_sync_list);
1439 spin_lock_init(&mp->m_sync_lock);
1440 init_waitqueue_head(&mp->m_wait_single_sync_task);
1441
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001442 mp->m_super = sb;
1443 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001445 error = xfs_parseargs(mp, (char *)data, &mtpt);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001446 if (error)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001447 goto out_free_fsname;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
1449 sb_min_blocksize(sb, BBSIZE);
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001450 sb->s_xattr = xfs_xattr_handlers;
Nathan Scotta50cd262006-03-14 14:06:18 +11001451 sb->s_export_op = &xfs_export_operations;
Nathan Scotta50cd262006-03-14 14:06:18 +11001452 sb->s_qcop = &xfs_quotactl_operations;
1453 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001455 error = xfs_dmops_get(mp);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001456 if (error)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001457 goto out_free_fsname;
1458 error = xfs_qmops_get(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001459 if (error)
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001460 goto out_put_dmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001461
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001462 if (silent)
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001463 flags |= XFS_MFSI_QUIET;
1464
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001465 error = xfs_open_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001466 if (error)
1467 goto out_put_qmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001468
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001469 if (xfs_icsb_init_counters(mp))
1470 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1471
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001472 error = xfs_readsb(mp, flags);
1473 if (error)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001474 goto out_destroy_counters;
1475
1476 error = xfs_finish_flags(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001477 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001478 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001479
Christoph Hellwige34b5622008-05-20 15:10:36 +10001480 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001481 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001482 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001483
1484 if (mp->m_flags & XFS_MOUNT_BARRIER)
1485 xfs_mountfs_check_barriers(mp);
1486
1487 error = xfs_filestream_mount(mp);
1488 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001489 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001490
Christoph Hellwig42490232008-08-13 16:49:32 +10001491 error = xfs_mountfs(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001492 if (error)
Christoph Hellwig120226c2008-05-20 15:11:11 +10001493 goto out_filestream_unmount;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001494
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001495 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 sb->s_dirt = 1;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001498 sb->s_magic = XFS_SB_MAGIC;
1499 sb->s_blocksize = mp->m_sb.sb_blocksize;
1500 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1502 sb->s_time_gran = 1;
1503 set_posix_acl_flag(sb);
1504
David Chinner01651642008-08-13 15:45:15 +10001505 root = igrab(VFS_I(mp->m_rootip));
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001506 if (!root) {
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001507 error = ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 goto fail_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001509 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001510 if (is_bad_inode(root)) {
1511 error = EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 goto fail_vnrele;
1513 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001514 sb->s_root = d_alloc_root(root);
1515 if (!sb->s_root) {
1516 error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 goto fail_vnrele;
1518 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001519
David Chinnera167b172008-10-30 17:06:18 +11001520 error = xfs_syncd_init(mp);
1521 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 goto fail_vnrele;
Christoph Hellwig74394492007-08-30 17:21:22 +10001523
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001524 kfree(mtpt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001526 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 return 0;
1528
Christoph Hellwig120226c2008-05-20 15:11:11 +10001529 out_filestream_unmount:
1530 xfs_filestream_unmount(mp);
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001531 out_free_sb:
1532 xfs_freesb(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001533 out_destroy_counters:
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001534 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001535 xfs_close_devices(mp);
1536 out_put_qmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001537 xfs_qmops_put(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001538 out_put_dmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001539 xfs_dmops_put(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001540 out_free_fsname:
1541 xfs_free_fsname(mp);
1542 kfree(mtpt);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001543 kfree(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001544 out:
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001545 return -error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001546
1547 fail_vnrele:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 if (sb->s_root) {
1549 dput(sb->s_root);
1550 sb->s_root = NULL;
1551 } else {
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001552 iput(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 }
1554
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001555 fail_unmount:
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001556 /*
1557 * Blow away any referenced inode in the filestreams cache.
1558 * This can and will cause log traffic as inodes go inactive
1559 * here.
1560 */
1561 xfs_filestream_unmount(mp);
1562
1563 XFS_bflush(mp->m_ddev_targp);
1564 error = xfs_unmount_flush(mp, 0);
1565 WARN_ON(error);
1566
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001567 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001568 goto out_free_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569}
1570
David Howells454e2392006-06-23 02:02:57 -07001571STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001572xfs_fs_get_sb(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 struct file_system_type *fs_type,
1574 int flags,
1575 const char *dev_name,
David Howells454e2392006-06-23 02:02:57 -07001576 void *data,
1577 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578{
David Howells454e2392006-06-23 02:02:57 -07001579 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1580 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581}
1582
David Chinner7989cb82007-02-10 18:34:56 +11001583static struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001584 .alloc_inode = xfs_fs_alloc_inode,
1585 .destroy_inode = xfs_fs_destroy_inode,
1586 .write_inode = xfs_fs_write_inode,
1587 .clear_inode = xfs_fs_clear_inode,
1588 .put_super = xfs_fs_put_super,
1589 .write_super = xfs_fs_write_super,
1590 .sync_fs = xfs_fs_sync_super,
1591 .write_super_lockfs = xfs_fs_lockfs,
1592 .statfs = xfs_fs_statfs,
1593 .remount_fs = xfs_fs_remount,
1594 .show_options = xfs_fs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595};
1596
David Chinner7989cb82007-02-10 18:34:56 +11001597static struct quotactl_ops xfs_quotactl_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001598 .quota_sync = xfs_fs_quotasync,
1599 .get_xstate = xfs_fs_getxstate,
1600 .set_xstate = xfs_fs_setxstate,
1601 .get_xquota = xfs_fs_getxquota,
1602 .set_xquota = xfs_fs_setxquota,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603};
1604
Andrew Morton5085b602007-02-20 13:57:47 -08001605static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 .owner = THIS_MODULE,
1607 .name = "xfs",
Nathan Scotta50cd262006-03-14 14:06:18 +11001608 .get_sb = xfs_fs_get_sb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 .kill_sb = kill_block_super,
1610 .fs_flags = FS_REQUIRES_DEV,
1611};
1612
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001613STATIC int __init
1614xfs_alloc_trace_bufs(void)
1615{
1616#ifdef XFS_ALLOC_TRACE
1617 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1618 if (!xfs_alloc_trace_buf)
1619 goto out;
1620#endif
1621#ifdef XFS_BMAP_TRACE
1622 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1623 if (!xfs_bmap_trace_buf)
1624 goto out_free_alloc_trace;
1625#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001626#ifdef XFS_BTREE_TRACE
1627 xfs_allocbt_trace_buf = ktrace_alloc(XFS_ALLOCBT_TRACE_SIZE,
1628 KM_MAYFAIL);
1629 if (!xfs_allocbt_trace_buf)
1630 goto out_free_bmap_trace;
1631
1632 xfs_inobt_trace_buf = ktrace_alloc(XFS_INOBT_TRACE_SIZE, KM_MAYFAIL);
1633 if (!xfs_inobt_trace_buf)
1634 goto out_free_allocbt_trace;
1635
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001636 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1637 if (!xfs_bmbt_trace_buf)
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001638 goto out_free_inobt_trace;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001639#endif
1640#ifdef XFS_ATTR_TRACE
1641 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1642 if (!xfs_attr_trace_buf)
1643 goto out_free_bmbt_trace;
1644#endif
1645#ifdef XFS_DIR2_TRACE
1646 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1647 if (!xfs_dir2_trace_buf)
1648 goto out_free_attr_trace;
1649#endif
1650
1651 return 0;
1652
1653#ifdef XFS_DIR2_TRACE
1654 out_free_attr_trace:
1655#endif
1656#ifdef XFS_ATTR_TRACE
1657 ktrace_free(xfs_attr_trace_buf);
1658 out_free_bmbt_trace:
1659#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001660#ifdef XFS_BTREE_TRACE
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001661 ktrace_free(xfs_bmbt_trace_buf);
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001662 out_free_inobt_trace:
1663 ktrace_free(xfs_inobt_trace_buf);
1664 out_free_allocbt_trace:
1665 ktrace_free(xfs_allocbt_trace_buf);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001666 out_free_bmap_trace:
1667#endif
1668#ifdef XFS_BMAP_TRACE
1669 ktrace_free(xfs_bmap_trace_buf);
1670 out_free_alloc_trace:
1671#endif
1672#ifdef XFS_ALLOC_TRACE
1673 ktrace_free(xfs_alloc_trace_buf);
1674 out:
1675#endif
1676 return -ENOMEM;
1677}
1678
1679STATIC void
1680xfs_free_trace_bufs(void)
1681{
1682#ifdef XFS_DIR2_TRACE
1683 ktrace_free(xfs_dir2_trace_buf);
1684#endif
1685#ifdef XFS_ATTR_TRACE
1686 ktrace_free(xfs_attr_trace_buf);
1687#endif
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001688#ifdef XFS_BTREE_TRACE
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001689 ktrace_free(xfs_bmbt_trace_buf);
Christoph Hellwig8c4ed632008-10-30 16:55:13 +11001690 ktrace_free(xfs_inobt_trace_buf);
1691 ktrace_free(xfs_allocbt_trace_buf);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001692#endif
1693#ifdef XFS_BMAP_TRACE
1694 ktrace_free(xfs_bmap_trace_buf);
1695#endif
1696#ifdef XFS_ALLOC_TRACE
1697 ktrace_free(xfs_alloc_trace_buf);
1698#endif
1699}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
1701STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001702xfs_init_zones(void)
1703{
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001704
1705 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1706 if (!xfs_ioend_zone)
David Chinnerbf904242008-10-30 17:36:14 +11001707 goto out;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001708
1709 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1710 xfs_ioend_zone);
1711 if (!xfs_ioend_pool)
1712 goto out_destroy_ioend_zone;
1713
1714 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1715 "xfs_log_ticket");
1716 if (!xfs_log_ticket_zone)
1717 goto out_destroy_ioend_pool;
1718
1719 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1720 "xfs_bmap_free_item");
1721 if (!xfs_bmap_free_item_zone)
1722 goto out_destroy_log_ticket_zone;
David Chinnerbf904242008-10-30 17:36:14 +11001723
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001724 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1725 "xfs_btree_cur");
1726 if (!xfs_btree_cur_zone)
1727 goto out_destroy_bmap_free_item_zone;
1728
1729 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1730 "xfs_da_state");
1731 if (!xfs_da_state_zone)
1732 goto out_destroy_btree_cur_zone;
1733
1734 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
1735 if (!xfs_dabuf_zone)
1736 goto out_destroy_da_state_zone;
1737
1738 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1739 if (!xfs_ifork_zone)
1740 goto out_destroy_dabuf_zone;
1741
1742 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1743 if (!xfs_trans_zone)
1744 goto out_destroy_ifork_zone;
1745
1746 /*
1747 * The size of the zone allocated buf log item is the maximum
1748 * size possible under XFS. This wastes a little bit of memory,
1749 * but it is much faster.
1750 */
1751 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
1752 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
1753 NBWORD) * sizeof(int))), "xfs_buf_item");
1754 if (!xfs_buf_item_zone)
1755 goto out_destroy_trans_zone;
1756
1757 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1758 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1759 sizeof(xfs_extent_t))), "xfs_efd_item");
1760 if (!xfs_efd_zone)
1761 goto out_destroy_buf_item_zone;
1762
1763 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1764 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1765 sizeof(xfs_extent_t))), "xfs_efi_item");
1766 if (!xfs_efi_zone)
1767 goto out_destroy_efd_zone;
1768
1769 xfs_inode_zone =
1770 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
David Chinnerbf904242008-10-30 17:36:14 +11001771 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
1772 xfs_fs_inode_init_once);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001773 if (!xfs_inode_zone)
1774 goto out_destroy_efi_zone;
1775
1776 xfs_ili_zone =
1777 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1778 KM_ZONE_SPREAD, NULL);
1779 if (!xfs_ili_zone)
1780 goto out_destroy_inode_zone;
1781
1782#ifdef CONFIG_XFS_POSIX_ACL
1783 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
1784 if (!xfs_acl_zone)
1785 goto out_destroy_ili_zone;
1786#endif
1787
1788 return 0;
1789
1790#ifdef CONFIG_XFS_POSIX_ACL
1791 out_destroy_ili_zone:
1792#endif
1793 kmem_zone_destroy(xfs_ili_zone);
1794 out_destroy_inode_zone:
1795 kmem_zone_destroy(xfs_inode_zone);
1796 out_destroy_efi_zone:
1797 kmem_zone_destroy(xfs_efi_zone);
1798 out_destroy_efd_zone:
1799 kmem_zone_destroy(xfs_efd_zone);
1800 out_destroy_buf_item_zone:
1801 kmem_zone_destroy(xfs_buf_item_zone);
1802 out_destroy_trans_zone:
1803 kmem_zone_destroy(xfs_trans_zone);
1804 out_destroy_ifork_zone:
1805 kmem_zone_destroy(xfs_ifork_zone);
1806 out_destroy_dabuf_zone:
1807 kmem_zone_destroy(xfs_dabuf_zone);
1808 out_destroy_da_state_zone:
1809 kmem_zone_destroy(xfs_da_state_zone);
1810 out_destroy_btree_cur_zone:
1811 kmem_zone_destroy(xfs_btree_cur_zone);
1812 out_destroy_bmap_free_item_zone:
1813 kmem_zone_destroy(xfs_bmap_free_item_zone);
1814 out_destroy_log_ticket_zone:
1815 kmem_zone_destroy(xfs_log_ticket_zone);
1816 out_destroy_ioend_pool:
1817 mempool_destroy(xfs_ioend_pool);
1818 out_destroy_ioend_zone:
1819 kmem_zone_destroy(xfs_ioend_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001820 out:
1821 return -ENOMEM;
1822}
1823
1824STATIC void
1825xfs_destroy_zones(void)
1826{
1827#ifdef CONFIG_XFS_POSIX_ACL
1828 kmem_zone_destroy(xfs_acl_zone);
1829#endif
1830 kmem_zone_destroy(xfs_ili_zone);
1831 kmem_zone_destroy(xfs_inode_zone);
1832 kmem_zone_destroy(xfs_efi_zone);
1833 kmem_zone_destroy(xfs_efd_zone);
1834 kmem_zone_destroy(xfs_buf_item_zone);
1835 kmem_zone_destroy(xfs_trans_zone);
1836 kmem_zone_destroy(xfs_ifork_zone);
1837 kmem_zone_destroy(xfs_dabuf_zone);
1838 kmem_zone_destroy(xfs_da_state_zone);
1839 kmem_zone_destroy(xfs_btree_cur_zone);
1840 kmem_zone_destroy(xfs_bmap_free_item_zone);
1841 kmem_zone_destroy(xfs_log_ticket_zone);
1842 mempool_destroy(xfs_ioend_pool);
1843 kmem_zone_destroy(xfs_ioend_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001844
1845}
1846
1847STATIC int __init
1848init_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849{
1850 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
Christoph Hellwig65795912008-11-28 14:23:33 +11001852 printk(KERN_INFO XFS_VERSION_STRING " with "
1853 XFS_BUILD_OPTIONS " enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 ktrace_init(64);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001856 vn_init();
1857 xfs_dir_startup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
Nathan Scott87582802006-03-14 13:18:19 +11001859 error = xfs_init_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001860 if (error)
1861 goto out;
1862
1863 error = xfs_alloc_trace_bufs();
1864 if (error)
1865 goto out_destroy_zones;
1866
1867 error = xfs_mru_cache_init();
1868 if (error)
1869 goto out_free_trace_buffers;
1870
1871 error = xfs_filestream_init();
1872 if (error)
1873 goto out_mru_cache_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
Nathan Scottce8e9222006-01-11 15:39:08 +11001875 error = xfs_buf_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001876 if (error)
1877 goto out_filestream_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001879 error = xfs_init_procfs();
1880 if (error)
1881 goto out_buf_terminate;
1882
1883 error = xfs_sysctl_register();
1884 if (error)
1885 goto out_cleanup_procfs;
1886
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 vfs_initquota();
1888
1889 error = register_filesystem(&xfs_fs_type);
1890 if (error)
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001891 goto out_sysctl_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 return 0;
1893
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001894 out_sysctl_unregister:
1895 xfs_sysctl_unregister();
1896 out_cleanup_procfs:
1897 xfs_cleanup_procfs();
1898 out_buf_terminate:
Nathan Scottce8e9222006-01-11 15:39:08 +11001899 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001900 out_filestream_uninit:
1901 xfs_filestream_uninit();
1902 out_mru_cache_uninit:
1903 xfs_mru_cache_uninit();
1904 out_free_trace_buffers:
1905 xfs_free_trace_bufs();
1906 out_destroy_zones:
Nathan Scott87582802006-03-14 13:18:19 +11001907 xfs_destroy_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001908 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 return error;
1910}
1911
1912STATIC void __exit
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001913exit_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914{
1915 vfs_exitquota();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 unregister_filesystem(&xfs_fs_type);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001917 xfs_sysctl_unregister();
1918 xfs_cleanup_procfs();
Nathan Scottce8e9222006-01-11 15:39:08 +11001919 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001920 xfs_filestream_uninit();
1921 xfs_mru_cache_uninit();
1922 xfs_free_trace_bufs();
Nathan Scott87582802006-03-14 13:18:19 +11001923 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 ktrace_uninit();
1925}
1926
1927module_init(init_xfs_fs);
1928module_exit(exit_xfs_fs);
1929
1930MODULE_AUTHOR("Silicon Graphics, Inc.");
1931MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1932MODULE_LICENSE("GPL");