blob: 4c7b8f9f4deb4bdff563d94ebb9184ee12ae666e [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 */
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000018
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110020#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110022#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_trans.h"
24#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110025#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_dir2.h"
27#include "xfs_alloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include "xfs_attr.h"
47#include "xfs_buf_item.h"
48#include "xfs_utils.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100049#include "xfs_vnodeops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include "xfs_version.h"
David Chinnera67d7c52007-11-23 16:29:32 +110051#include "xfs_log_priv.h"
David Chinner249a8c12008-02-05 12:13:32 +110052#include "xfs_trans_priv.h"
Christoph Hellwig48b62a12008-05-20 11:30:39 +100053#include "xfs_filestream.h"
Christoph Hellwig9f8868f2008-07-18 17:11:46 +100054#include "xfs_da_btree.h"
Christoph Hellwig9f8868f2008-07-18 17:11:46 +100055#include "xfs_extfree_item.h"
56#include "xfs_mru_cache.h"
57#include "xfs_inode_item.h"
David Chinnerfe4fa4b2008-10-30 17:06:08 +110058#include "xfs_sync.h"
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000059#include "xfs_trace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61#include <linux/namei.h>
62#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090063#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#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
Alexey Dobriyanb87221d2009-09-21 17:01:09 -070071static const struct super_operations xfs_super_operations;
David Chinner7989cb82007-02-10 18:34:56 +110072static kmem_zone_t *xfs_ioend_zone;
Christoph Hellwig0829c362005-09-02 16:58:49 +100073mempool_t *xfs_ioend_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
David Chinnera67d7c52007-11-23 16:29:32 +110075#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
76#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
77#define MNTOPT_LOGDEV "logdev" /* log device */
78#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
79#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
80#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
David Chinnera67d7c52007-11-23 16:29:32 +110081#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
82#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
83#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
84#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
85#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
86#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
87#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
88#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
89#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
90#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
91#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
92#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
93#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
94 * unwritten extent conversion */
95#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
96#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
97#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
98#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
99#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
100#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
101#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
102 * in stat(). */
103#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
104#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
105#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
106#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
107#define MNTOPT_NOQUOTA "noquota" /* no quotas */
108#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
109#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
110#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
111#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
112#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
113#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
114#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
115#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
116#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
117#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
Dave Chinner71e330b2010-05-21 14:37:18 +1000118#define MNTOPT_DELAYLOG "delaylog" /* Delayed loging enabled */
119#define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
David Chinnera67d7c52007-11-23 16:29:32 +1100120
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000121/*
122 * Table driven mount option parser.
123 *
124 * Currently only used for remount, but it will be used for mount
125 * in the future, too.
126 */
127enum {
128 Opt_barrier, Opt_nobarrier, Opt_err
129};
130
Steven Whitehousea447c092008-10-13 10:46:57 +0100131static const match_table_t tokens = {
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000132 {Opt_barrier, "barrier"},
133 {Opt_nobarrier, "nobarrier"},
134 {Opt_err, NULL}
135};
136
137
David Chinnera67d7c52007-11-23 16:29:32 +1100138STATIC unsigned long
139suffix_strtoul(char *s, char **endp, unsigned int base)
140{
141 int last, shift_left_factor = 0;
142 char *value = s;
143
144 last = strlen(value) - 1;
145 if (value[last] == 'K' || value[last] == 'k') {
146 shift_left_factor = 10;
147 value[last] = '\0';
148 }
149 if (value[last] == 'M' || value[last] == 'm') {
150 shift_left_factor = 20;
151 value[last] = '\0';
152 }
153 if (value[last] == 'G' || value[last] == 'g') {
154 shift_left_factor = 30;
155 value[last] = '\0';
156 }
157
158 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
159}
160
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100161/*
162 * This function fills in xfs_mount_t fields based on mount args.
163 * Note: the superblock has _not_ yet been read in.
164 *
165 * Note that this function leaks the various device name allocations on
166 * failure. The caller takes care of them.
167 */
David Chinnera67d7c52007-11-23 16:29:32 +1100168STATIC int
169xfs_parseargs(
170 struct xfs_mount *mp,
Christoph Hellwig288699f2010-06-23 18:11:15 +1000171 char *options)
David Chinnera67d7c52007-11-23 16:29:32 +1100172{
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100173 struct super_block *sb = mp->m_super;
David Chinnera67d7c52007-11-23 16:29:32 +1100174 char *this_char, *value, *eov;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100175 int dsunit = 0;
176 int dswidth = 0;
177 int iosize = 0;
Christoph Hellwiga5687782009-02-09 08:37:39 +0100178 __uint8_t iosizelog = 0;
David Chinnera67d7c52007-11-23 16:29:32 +1100179
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100180 /*
181 * Copy binary VFS mount flags we are interested in.
182 */
183 if (sb->s_flags & MS_RDONLY)
184 mp->m_flags |= XFS_MOUNT_RDONLY;
185 if (sb->s_flags & MS_DIRSYNC)
186 mp->m_flags |= XFS_MOUNT_DIRSYNC;
187 if (sb->s_flags & MS_SYNCHRONOUS)
188 mp->m_flags |= XFS_MOUNT_WSYNC;
189
190 /*
191 * Set some default flags that could be cleared by the mount option
192 * parsing.
193 */
194 mp->m_flags |= XFS_MOUNT_BARRIER;
195 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
196 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
197
198 /*
199 * These can be overridden by the mount option parsing.
200 */
201 mp->m_logbufs = -1;
202 mp->m_logbsize = -1;
David Chinnera67d7c52007-11-23 16:29:32 +1100203
204 if (!options)
205 goto done;
206
David Chinnera67d7c52007-11-23 16:29:32 +1100207 while ((this_char = strsep(&options, ",")) != NULL) {
208 if (!*this_char)
209 continue;
210 if ((value = strchr(this_char, '=')) != NULL)
211 *value++ = 0;
212
213 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
214 if (!value || !*value) {
215 cmn_err(CE_WARN,
216 "XFS: %s option requires an argument",
217 this_char);
218 return EINVAL;
219 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100220 mp->m_logbufs = simple_strtoul(value, &eov, 10);
David Chinnera67d7c52007-11-23 16:29:32 +1100221 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
222 if (!value || !*value) {
223 cmn_err(CE_WARN,
224 "XFS: %s option requires an argument",
225 this_char);
226 return EINVAL;
227 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100228 mp->m_logbsize = suffix_strtoul(value, &eov, 10);
David Chinnera67d7c52007-11-23 16:29:32 +1100229 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
230 if (!value || !*value) {
231 cmn_err(CE_WARN,
232 "XFS: %s option requires an argument",
233 this_char);
234 return EINVAL;
235 }
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100236 mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
237 if (!mp->m_logname)
238 return ENOMEM;
David Chinnera67d7c52007-11-23 16:29:32 +1100239 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
Christoph Hellwig288699f2010-06-23 18:11:15 +1000240 cmn_err(CE_WARN,
241 "XFS: %s option not allowed on this system",
242 this_char);
243 return EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100244 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
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 mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
252 if (!mp->m_rtname)
253 return ENOMEM;
David Chinnera67d7c52007-11-23 16:29:32 +1100254 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
255 if (!value || !*value) {
256 cmn_err(CE_WARN,
257 "XFS: %s option requires an argument",
258 this_char);
259 return EINVAL;
260 }
261 iosize = simple_strtoul(value, &eov, 10);
Christoph Hellwig1ec79442008-10-30 17:55:08 +1100262 iosizelog = ffs(iosize) - 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100263 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
264 if (!value || !*value) {
265 cmn_err(CE_WARN,
266 "XFS: %s option requires an argument",
267 this_char);
268 return EINVAL;
269 }
270 iosize = suffix_strtoul(value, &eov, 10);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100271 iosizelog = ffs(iosize) - 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100272 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
273 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
274 mp->m_flags |= XFS_MOUNT_GRPID;
275 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
276 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
277 mp->m_flags &= ~XFS_MOUNT_GRPID;
278 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100279 mp->m_flags |= XFS_MOUNT_WSYNC;
David Chinnera67d7c52007-11-23 16:29:32 +1100280 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100281 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
David Chinnera67d7c52007-11-23 16:29:32 +1100282 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100283 mp->m_flags |= XFS_MOUNT_NORECOVERY;
David Chinnera67d7c52007-11-23 16:29:32 +1100284 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100285 mp->m_flags |= XFS_MOUNT_NOALIGN;
David Chinnera67d7c52007-11-23 16:29:32 +1100286 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100287 mp->m_flags |= XFS_MOUNT_SWALLOC;
David Chinnera67d7c52007-11-23 16:29:32 +1100288 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
289 if (!value || !*value) {
290 cmn_err(CE_WARN,
291 "XFS: %s option requires an argument",
292 this_char);
293 return EINVAL;
294 }
295 dsunit = simple_strtoul(value, &eov, 10);
296 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
297 if (!value || !*value) {
298 cmn_err(CE_WARN,
299 "XFS: %s option requires an argument",
300 this_char);
301 return EINVAL;
302 }
303 dswidth = simple_strtoul(value, &eov, 10);
304 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100305 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
David Chinnera67d7c52007-11-23 16:29:32 +1100306#if !XFS_BIG_INUMS
307 cmn_err(CE_WARN,
308 "XFS: %s option not allowed on this system",
309 this_char);
310 return EINVAL;
311#endif
312 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100313 mp->m_flags |= XFS_MOUNT_NOUUID;
David Chinnera67d7c52007-11-23 16:29:32 +1100314 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100315 mp->m_flags |= XFS_MOUNT_BARRIER;
David Chinnera67d7c52007-11-23 16:29:32 +1100316 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100317 mp->m_flags &= ~XFS_MOUNT_BARRIER;
David Chinnera67d7c52007-11-23 16:29:32 +1100318 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100319 mp->m_flags |= XFS_MOUNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100320 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100321 mp->m_flags &= ~XFS_MOUNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100322 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100323 mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
David Chinnera67d7c52007-11-23 16:29:32 +1100324 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100325 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
David Chinnera67d7c52007-11-23 16:29:32 +1100326 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100327 mp->m_flags |= XFS_MOUNT_ATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100328 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100329 mp->m_flags &= ~XFS_MOUNT_ATTR2;
330 mp->m_flags |= XFS_MOUNT_NOATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100331 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100332 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
David Chinnera67d7c52007-11-23 16:29:32 +1100333 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100334 mp->m_qflags &= ~(XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
335 XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
Christoph Hellwig469fc232008-10-30 17:54:57 +1100336 XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100337 XFS_UQUOTA_ENFD | XFS_OQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100338 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
339 !strcmp(this_char, MNTOPT_UQUOTA) ||
340 !strcmp(this_char, MNTOPT_USRQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100341 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
342 XFS_UQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100343 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
344 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100345 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
346 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
David Chinnera67d7c52007-11-23 16:29:32 +1100347 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
348 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100349 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
350 XFS_OQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100351 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100352 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
353 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
David Chinnera67d7c52007-11-23 16:29:32 +1100354 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
355 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100356 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
357 XFS_OQUOTA_ENFD);
David Chinnera67d7c52007-11-23 16:29:32 +1100358 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100359 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
360 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
Dave Chinner71e330b2010-05-21 14:37:18 +1000361 } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) {
362 mp->m_flags |= XFS_MOUNT_DELAYLOG;
363 cmn_err(CE_WARN,
364 "Enabling EXPERIMENTAL delayed logging feature "
365 "- use at your own risk.\n");
366 } else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) {
367 mp->m_flags &= ~XFS_MOUNT_DELAYLOG;
David Chinnera67d7c52007-11-23 16:29:32 +1100368 } else if (!strcmp(this_char, "ihashsize")) {
369 cmn_err(CE_WARN,
370 "XFS: ihashsize no longer used, option is deprecated.");
371 } else if (!strcmp(this_char, "osyncisdsync")) {
372 /* no-op, this is now the default */
373 cmn_err(CE_WARN,
374 "XFS: osyncisdsync is now the default, option is deprecated.");
375 } else if (!strcmp(this_char, "irixsgid")) {
376 cmn_err(CE_WARN,
377 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
378 } else {
379 cmn_err(CE_WARN,
380 "XFS: unknown mount option [%s].", this_char);
381 return EINVAL;
382 }
383 }
384
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100385 /*
386 * no recovery flag requires a read-only mount
387 */
388 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
389 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
390 cmn_err(CE_WARN, "XFS: no-recovery mounts must be read-only.");
391 return EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100392 }
393
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100394 if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
David Chinnera67d7c52007-11-23 16:29:32 +1100395 cmn_err(CE_WARN,
396 "XFS: sunit and swidth options incompatible with the noalign option");
397 return EINVAL;
398 }
399
Christoph Hellwig7d095252009-06-08 15:33:32 +0200400#ifndef CONFIG_XFS_QUOTA
401 if (XFS_IS_QUOTA_RUNNING(mp)) {
402 cmn_err(CE_WARN,
403 "XFS: quota support not available in this kernel.");
404 return EINVAL;
405 }
406#endif
407
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100408 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
409 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE))) {
David Chinnera67d7c52007-11-23 16:29:32 +1100410 cmn_err(CE_WARN,
411 "XFS: cannot mount with both project and group quota");
412 return EINVAL;
413 }
414
David Chinnera67d7c52007-11-23 16:29:32 +1100415 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
416 cmn_err(CE_WARN,
417 "XFS: sunit and swidth must be specified together");
418 return EINVAL;
419 }
420
421 if (dsunit && (dswidth % dsunit != 0)) {
422 cmn_err(CE_WARN,
423 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
424 dswidth, dsunit);
425 return EINVAL;
426 }
427
David Chinnera67d7c52007-11-23 16:29:32 +1100428done:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100429 if (!(mp->m_flags & XFS_MOUNT_NOALIGN)) {
430 /*
431 * At this point the superblock has not been read
432 * in, therefore we do not know the block size.
433 * Before the mount call ends we will convert
434 * these to FSBs.
435 */
436 if (dsunit) {
437 mp->m_dalign = dsunit;
438 mp->m_flags |= XFS_MOUNT_RETERR;
439 }
440
441 if (dswidth)
442 mp->m_swidth = dswidth;
443 }
444
445 if (mp->m_logbufs != -1 &&
446 mp->m_logbufs != 0 &&
447 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
448 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
449 cmn_err(CE_WARN,
450 "XFS: invalid logbufs value: %d [not %d-%d]",
451 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
452 return XFS_ERROR(EINVAL);
453 }
454 if (mp->m_logbsize != -1 &&
455 mp->m_logbsize != 0 &&
456 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
457 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
458 !is_power_of_2(mp->m_logbsize))) {
459 cmn_err(CE_WARN,
460 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
461 mp->m_logbsize);
462 return XFS_ERROR(EINVAL);
463 }
464
465 mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
466 if (!mp->m_fsname)
467 return ENOMEM;
468 mp->m_fsname_len = strlen(mp->m_fsname) + 1;
469
470 if (iosizelog) {
471 if (iosizelog > XFS_MAX_IO_LOG ||
472 iosizelog < XFS_MIN_IO_LOG) {
473 cmn_err(CE_WARN,
474 "XFS: invalid log iosize: %d [not %d-%d]",
475 iosizelog, XFS_MIN_IO_LOG,
476 XFS_MAX_IO_LOG);
477 return XFS_ERROR(EINVAL);
478 }
479
480 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
481 mp->m_readio_log = iosizelog;
482 mp->m_writeio_log = iosizelog;
483 }
484
David Chinnera67d7c52007-11-23 16:29:32 +1100485 return 0;
486}
487
488struct proc_xfs_info {
489 int flag;
490 char *str;
491};
492
493STATIC int
494xfs_showargs(
495 struct xfs_mount *mp,
496 struct seq_file *m)
497{
498 static struct proc_xfs_info xfs_info_set[] = {
499 /* the few simple ones we can get from the mount struct */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100500 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
David Chinnera67d7c52007-11-23 16:29:32 +1100501 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
David Chinnera67d7c52007-11-23 16:29:32 +1100502 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
503 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
504 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
505 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
506 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
507 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
508 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
David Chinnera67d7c52007-11-23 16:29:32 +1100509 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
Dave Chinner71e330b2010-05-21 14:37:18 +1000510 { XFS_MOUNT_DELAYLOG, "," MNTOPT_DELAYLOG },
David Chinnera67d7c52007-11-23 16:29:32 +1100511 { 0, NULL }
512 };
513 static struct proc_xfs_info xfs_info_unset[] = {
514 /* the few simple ones we can get from the mount struct */
David Chinnera67d7c52007-11-23 16:29:32 +1100515 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
516 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
517 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
518 { 0, NULL }
519 };
520 struct proc_xfs_info *xfs_infop;
521
522 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
523 if (mp->m_flags & xfs_infop->flag)
524 seq_puts(m, xfs_infop->str);
525 }
526 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
527 if (!(mp->m_flags & xfs_infop->flag))
528 seq_puts(m, xfs_infop->str);
529 }
530
531 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
532 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
533 (int)(1 << mp->m_writeio_log) >> 10);
534
535 if (mp->m_logbufs > 0)
536 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
537 if (mp->m_logbsize > 0)
538 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
539
540 if (mp->m_logname)
541 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
542 if (mp->m_rtname)
543 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
544
545 if (mp->m_dalign > 0)
546 seq_printf(m, "," MNTOPT_SUNIT "=%d",
547 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
548 if (mp->m_swidth > 0)
549 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
550 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
551
552 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
553 seq_puts(m, "," MNTOPT_USRQUOTA);
554 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
555 seq_puts(m, "," MNTOPT_UQUOTANOENF);
556
Alex Elder988abe42009-09-02 17:02:24 -0500557 /* Either project or group quotas can be active, not both */
David Chinnera67d7c52007-11-23 16:29:32 +1100558
Alex Elder988abe42009-09-02 17:02:24 -0500559 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
560 if (mp->m_qflags & XFS_OQUOTA_ENFD)
561 seq_puts(m, "," MNTOPT_PRJQUOTA);
562 else
563 seq_puts(m, "," MNTOPT_PQUOTANOENF);
564 } else if (mp->m_qflags & XFS_GQUOTA_ACCT) {
565 if (mp->m_qflags & XFS_OQUOTA_ENFD)
566 seq_puts(m, "," MNTOPT_GRPQUOTA);
567 else
568 seq_puts(m, "," MNTOPT_GQUOTANOENF);
569 }
David Chinnera67d7c52007-11-23 16:29:32 +1100570
571 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
572 seq_puts(m, "," MNTOPT_NOQUOTA);
573
574 return 0;
575}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576__uint64_t
577xfs_max_file_offset(
578 unsigned int blockshift)
579{
580 unsigned int pagefactor = 1;
581 unsigned int bitshift = BITS_PER_LONG - 1;
582
583 /* Figure out maximum filesize, on Linux this can depend on
584 * the filesystem blocksize (on 32 bit platforms).
585 * __block_prepare_write does this in an [unsigned] long...
586 * page->index << (PAGE_CACHE_SHIFT - bbits)
587 * So, for page sized blocks (4K on 32 bit platforms),
588 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
589 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
590 * but for smaller blocksizes it is less (bbits = log2 bsize).
591 * Note1: get_block_t takes a long (implicit cast from above)
592 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
593 * can optionally convert the [unsigned] long from above into
594 * an [unsigned] long long.
595 */
596
597#if BITS_PER_LONG == 32
Bartlomiej Zolnierkiewicz90c699a2009-06-19 08:08:50 +0200598# if defined(CONFIG_LBDAF)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 ASSERT(sizeof(sector_t) == 8);
600 pagefactor = PAGE_CACHE_SIZE;
601 bitshift = BITS_PER_LONG;
602# else
603 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
604# endif
605#endif
606
607 return (((__uint64_t)pagefactor) << bitshift) - 1;
608}
609
Hannes Eder3180e662009-03-04 19:34:10 +0100610STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611xfs_blkdev_get(
612 xfs_mount_t *mp,
613 const char *name,
614 struct block_device **bdevp)
615{
616 int error = 0;
617
Al Viro30c40d22008-02-22 19:50:45 -0500618 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 if (IS_ERR(*bdevp)) {
620 error = PTR_ERR(*bdevp);
621 printk("XFS: Invalid device [%s], error=%d\n", name, error);
622 }
623
624 return -error;
625}
626
Hannes Eder3180e662009-03-04 19:34:10 +0100627STATIC void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628xfs_blkdev_put(
629 struct block_device *bdev)
630{
631 if (bdev)
Al Viro30c40d22008-02-22 19:50:45 -0500632 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633}
634
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100635/*
636 * Try to write out the superblock using barriers.
637 */
638STATIC int
639xfs_barrier_test(
640 xfs_mount_t *mp)
641{
642 xfs_buf_t *sbp = xfs_getsb(mp, 0);
643 int error;
644
645 XFS_BUF_UNDONE(sbp);
646 XFS_BUF_UNREAD(sbp);
647 XFS_BUF_UNDELAYWRITE(sbp);
648 XFS_BUF_WRITE(sbp);
649 XFS_BUF_UNASYNC(sbp);
650 XFS_BUF_ORDERED(sbp);
651
652 xfsbdstrat(mp, sbp);
653 error = xfs_iowait(sbp);
654
655 /*
656 * Clear all the flags we set and possible error state in the
657 * buffer. We only did the write to try out whether barriers
658 * worked and shouldn't leave any traces in the superblock
659 * buffer.
660 */
661 XFS_BUF_DONE(sbp);
662 XFS_BUF_ERROR(sbp, 0);
663 XFS_BUF_UNORDERED(sbp);
664
665 xfs_buf_relse(sbp);
666 return error;
667}
668
Eric Sandeend96f8f82009-07-02 00:09:33 -0500669STATIC void
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100670xfs_mountfs_check_barriers(xfs_mount_t *mp)
671{
672 int error;
673
674 if (mp->m_logdev_targp != mp->m_ddev_targp) {
675 xfs_fs_cmn_err(CE_NOTE, mp,
676 "Disabling barriers, not supported with external log device");
677 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100678 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100679 }
680
Nathan Scottb2ea4012006-07-28 17:05:13 +1000681 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
682 xfs_fs_cmn_err(CE_NOTE, mp,
683 "Disabling barriers, underlying device is readonly");
684 mp->m_flags &= ~XFS_MOUNT_BARRIER;
685 return;
686 }
687
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100688 error = xfs_barrier_test(mp);
689 if (error) {
690 xfs_fs_cmn_err(CE_NOTE, mp,
691 "Disabling barriers, trial barrier write failed");
692 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100693 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100694 }
695}
696
697void
698xfs_blkdev_issue_flush(
699 xfs_buftarg_t *buftarg)
700{
Dmitry Monakhovfbd9b092010-04-28 17:55:06 +0400701 blkdev_issue_flush(buftarg->bt_bdev, GFP_KERNEL, NULL,
702 BLKDEV_IFL_WAIT);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100703}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000705STATIC void
706xfs_close_devices(
707 struct xfs_mount *mp)
708{
709 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000710 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
Christoph Hellwigb7963132009-03-03 14:48:37 -0500711 xfs_free_buftarg(mp, mp->m_logdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000712 xfs_blkdev_put(logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000713 }
714 if (mp->m_rtdev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000715 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
Christoph Hellwigb7963132009-03-03 14:48:37 -0500716 xfs_free_buftarg(mp, mp->m_rtdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000717 xfs_blkdev_put(rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000718 }
Christoph Hellwigb7963132009-03-03 14:48:37 -0500719 xfs_free_buftarg(mp, mp->m_ddev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000720}
721
722/*
723 * The file system configurations are:
724 * (1) device (partition) with data and internal log
725 * (2) logical volume with data and log subvolumes.
726 * (3) logical volume with data, log, and realtime subvolumes.
727 *
728 * We only have to handle opening the log and realtime volumes here if
729 * they are present. The data subvolume has already been opened by
730 * get_sb_bdev() and is stored in sb->s_bdev.
731 */
732STATIC int
733xfs_open_devices(
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100734 struct xfs_mount *mp)
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000735{
736 struct block_device *ddev = mp->m_super->s_bdev;
737 struct block_device *logdev = NULL, *rtdev = NULL;
738 int error;
739
740 /*
741 * Open real time and log devices - order is important.
742 */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100743 if (mp->m_logname) {
744 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000745 if (error)
746 goto out;
747 }
748
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100749 if (mp->m_rtname) {
750 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000751 if (error)
752 goto out_close_logdev;
753
754 if (rtdev == ddev || rtdev == logdev) {
755 cmn_err(CE_WARN,
756 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
757 error = EINVAL;
758 goto out_close_rtdev;
759 }
760 }
761
762 /*
763 * Setup xfs_mount buffer target pointers
764 */
765 error = ENOMEM;
Jan Engelhardte2a07812010-03-23 09:52:55 +1100766 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0, mp->m_fsname);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000767 if (!mp->m_ddev_targp)
768 goto out_close_rtdev;
769
770 if (rtdev) {
Jan Engelhardte2a07812010-03-23 09:52:55 +1100771 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1, mp->m_fsname);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000772 if (!mp->m_rtdev_targp)
773 goto out_free_ddev_targ;
774 }
775
776 if (logdev && logdev != ddev) {
Jan Engelhardte2a07812010-03-23 09:52:55 +1100777 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1, mp->m_fsname);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000778 if (!mp->m_logdev_targp)
779 goto out_free_rtdev_targ;
780 } else {
781 mp->m_logdev_targp = mp->m_ddev_targp;
782 }
783
784 return 0;
785
786 out_free_rtdev_targ:
787 if (mp->m_rtdev_targp)
Christoph Hellwigb7963132009-03-03 14:48:37 -0500788 xfs_free_buftarg(mp, mp->m_rtdev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000789 out_free_ddev_targ:
Christoph Hellwigb7963132009-03-03 14:48:37 -0500790 xfs_free_buftarg(mp, mp->m_ddev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000791 out_close_rtdev:
792 if (rtdev)
793 xfs_blkdev_put(rtdev);
794 out_close_logdev:
795 if (logdev && logdev != ddev)
796 xfs_blkdev_put(logdev);
797 out:
798 return error;
799}
800
Christoph Hellwige34b5622008-05-20 15:10:36 +1000801/*
802 * Setup xfs_mount buffer target pointers based on superblock
803 */
804STATIC int
805xfs_setup_devices(
806 struct xfs_mount *mp)
807{
808 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000809
Christoph Hellwige34b5622008-05-20 15:10:36 +1000810 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
811 mp->m_sb.sb_sectsize);
812 if (error)
813 return error;
814
815 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
816 unsigned int log_sector_size = BBSIZE;
817
818 if (xfs_sb_version_hassector(&mp->m_sb))
819 log_sector_size = mp->m_sb.sb_logsectsize;
820 error = xfs_setsize_buftarg(mp->m_logdev_targp,
821 mp->m_sb.sb_blocksize,
822 log_sector_size);
823 if (error)
824 return error;
825 }
826 if (mp->m_rtdev_targp) {
827 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
828 mp->m_sb.sb_blocksize,
829 mp->m_sb.sb_sectsize);
830 if (error)
831 return error;
832 }
833
834 return 0;
835}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000836
David Chinner249a8c12008-02-05 12:13:32 +1100837/*
838 * XFS AIL push thread support
839 */
840void
841xfsaild_wakeup(
David Chinner82fa9012008-10-30 17:38:26 +1100842 struct xfs_ail *ailp,
David Chinner249a8c12008-02-05 12:13:32 +1100843 xfs_lsn_t threshold_lsn)
844{
David Chinner82fa9012008-10-30 17:38:26 +1100845 ailp->xa_target = threshold_lsn;
846 wake_up_process(ailp->xa_task);
David Chinner249a8c12008-02-05 12:13:32 +1100847}
848
Hannes Eder3180e662009-03-04 19:34:10 +0100849STATIC int
David Chinner249a8c12008-02-05 12:13:32 +1100850xfsaild(
851 void *data)
852{
David Chinner82fa9012008-10-30 17:38:26 +1100853 struct xfs_ail *ailp = data;
David Chinner249a8c12008-02-05 12:13:32 +1100854 xfs_lsn_t last_pushed_lsn = 0;
Dave Chinner453eac82010-01-11 11:49:58 +0000855 long tout = 0; /* milliseconds */
David Chinner249a8c12008-02-05 12:13:32 +1100856
857 while (!kthread_should_stop()) {
Dave Chinner453eac82010-01-11 11:49:58 +0000858 schedule_timeout_interruptible(tout ?
859 msecs_to_jiffies(tout) : MAX_SCHEDULE_TIMEOUT);
David Chinner249a8c12008-02-05 12:13:32 +1100860
861 /* swsusp */
862 try_to_freeze();
863
David Chinner82fa9012008-10-30 17:38:26 +1100864 ASSERT(ailp->xa_mount->m_log);
865 if (XFS_FORCED_SHUTDOWN(ailp->xa_mount))
David Chinner249a8c12008-02-05 12:13:32 +1100866 continue;
867
David Chinner82fa9012008-10-30 17:38:26 +1100868 tout = xfsaild_push(ailp, &last_pushed_lsn);
David Chinner249a8c12008-02-05 12:13:32 +1100869 }
870
871 return 0;
872} /* xfsaild */
873
874int
875xfsaild_start(
David Chinner82fa9012008-10-30 17:38:26 +1100876 struct xfs_ail *ailp)
David Chinner249a8c12008-02-05 12:13:32 +1100877{
David Chinner82fa9012008-10-30 17:38:26 +1100878 ailp->xa_target = 0;
Jan Engelhardte2a07812010-03-23 09:52:55 +1100879 ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild/%s",
880 ailp->xa_mount->m_fsname);
David Chinner82fa9012008-10-30 17:38:26 +1100881 if (IS_ERR(ailp->xa_task))
882 return -PTR_ERR(ailp->xa_task);
David Chinner249a8c12008-02-05 12:13:32 +1100883 return 0;
884}
885
886void
887xfsaild_stop(
David Chinner82fa9012008-10-30 17:38:26 +1100888 struct xfs_ail *ailp)
David Chinner249a8c12008-02-05 12:13:32 +1100889{
David Chinner82fa9012008-10-30 17:38:26 +1100890 kthread_stop(ailp->xa_task);
David Chinner249a8c12008-02-05 12:13:32 +1100891}
892
893
David Chinnerbf904242008-10-30 17:36:14 +1100894/* Catch misguided souls that try to use this interface on XFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100896xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 struct super_block *sb)
898{
David Chinnerbf904242008-10-30 17:36:14 +1100899 BUG();
Lachlan McIlroy493dca62008-10-30 17:36:52 +1100900 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
David Chinnerbf904242008-10-30 17:36:14 +1100903/*
David Chinner99fa8cb2008-10-30 17:36:40 +1100904 * Now that the generic code is guaranteed not to be accessing
905 * the linux inode, we can reclaim the inode.
David Chinnerbf904242008-10-30 17:36:14 +1100906 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100908xfs_fs_destroy_inode(
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000909 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000911 struct xfs_inode *ip = XFS_I(inode);
912
913 xfs_itrace_entry(ip);
David Chinner99fa8cb2008-10-30 17:36:40 +1100914
915 XFS_STATS_INC(vn_reclaim);
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000916
917 /* bad inode, get out here ASAP */
918 if (is_bad_inode(inode))
919 goto out_reclaim;
920
921 xfs_ioend_wait(ip);
922
923 ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
924
925 /*
926 * We should never get here with one of the reclaim flags already set.
927 */
928 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
929 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
930
931 /*
Dave Chinner57817c62010-01-10 23:51:47 +0000932 * We always use background reclaim here because even if the
933 * inode is clean, it still may be under IO and hence we have
934 * to take the flush lock. The background reclaim path handles
935 * this more efficiently than we can here, so simply let background
936 * reclaim tear down all inodes.
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000937 */
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000938out_reclaim:
Dave Chinner57817c62010-01-10 23:51:47 +0000939 xfs_inode_set_reclaim_tag(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940}
941
David Chinner07c8f672008-10-30 16:11:59 +1100942/*
943 * Slab object creation initialisation for the XFS inode.
944 * This covers only the idempotent fields in the XFS inode;
945 * all other fields need to be initialised on allocation
946 * from the slab. This avoids the need to repeatedly intialise
947 * fields in the xfs inode that left in the initialise state
948 * when freeing the inode.
949 */
David Chinnerbf904242008-10-30 17:36:14 +1100950STATIC void
951xfs_fs_inode_init_once(
David Chinner07c8f672008-10-30 16:11:59 +1100952 void *inode)
953{
954 struct xfs_inode *ip = inode;
955
956 memset(ip, 0, sizeof(struct xfs_inode));
David Chinnerbf904242008-10-30 17:36:14 +1100957
958 /* vfs inode */
959 inode_init_once(VFS_I(ip));
960
961 /* xfs inode */
David Chinner07c8f672008-10-30 16:11:59 +1100962 atomic_set(&ip->i_iocount, 0);
963 atomic_set(&ip->i_pincount, 0);
964 spin_lock_init(&ip->i_flags_lock);
David Chinner07c8f672008-10-30 16:11:59 +1100965 init_waitqueue_head(&ip->i_ipin_wait);
966 /*
967 * Because we want to use a counting completion, complete
968 * the flush completion once to allow a single access to
969 * the flush completion without blocking.
970 */
971 init_completion(&ip->i_flush);
972 complete(&ip->i_flush);
973
974 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
975 "xfsino", ip->i_ino);
David Chinner07c8f672008-10-30 16:11:59 +1100976}
977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978/*
Christoph Hellwigf9581b12009-10-06 20:29:26 +0000979 * Dirty the XFS inode when mark_inode_dirty_sync() is called so that
980 * we catch unlogged VFS level updates to the inode. Care must be taken
981 * here - the transaction code calls mark_inode_dirty_sync() to mark the
982 * VFS inode dirty in a transaction and clears the i_update_core field;
983 * it must clear the field after calling mark_inode_dirty_sync() to
984 * correctly indicate that the dirty state has been propagated into the
985 * inode log item.
986 *
987 * We need the barrier() to maintain correct ordering between unlogged
988 * updates and the transaction commit code that clears the i_update_core
989 * field. This requires all updates to be completed before marking the
990 * inode dirty.
991 */
992STATIC void
993xfs_fs_dirty_inode(
994 struct inode *inode)
995{
996 barrier();
997 XFS_I(inode)->i_update_core = 1;
998}
999
Christoph Hellwig07fec732010-02-09 11:43:49 +11001000STATIC int
1001xfs_log_inode(
1002 struct xfs_inode *ip)
1003{
1004 struct xfs_mount *mp = ip->i_mount;
1005 struct xfs_trans *tp;
1006 int error;
1007
1008 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1009 tp = xfs_trans_alloc(mp, XFS_TRANS_FSYNC_TS);
1010 error = xfs_trans_reserve(tp, 0, XFS_FSYNC_TS_LOG_RES(mp), 0, 0, 0);
1011
1012 if (error) {
1013 xfs_trans_cancel(tp, 0);
1014 /* we need to return with the lock hold shared */
1015 xfs_ilock(ip, XFS_ILOCK_SHARED);
1016 return error;
1017 }
1018
1019 xfs_ilock(ip, XFS_ILOCK_EXCL);
1020
1021 /*
1022 * Note - it's possible that we might have pushed ourselves out of the
1023 * way during trans_reserve which would flush the inode. But there's
1024 * no guarantee that the inode buffer has actually gone out yet (it's
1025 * delwri). Plus the buffer could be pinned anyway if it's part of
1026 * an inode in another recent transaction. So we play it safe and
1027 * fire off the transaction anyway.
1028 */
1029 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1030 xfs_trans_ihold(tp, ip);
1031 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1032 xfs_trans_set_sync(tp);
1033 error = xfs_trans_commit(tp, 0);
1034 xfs_ilock_demote(ip, XFS_ILOCK_EXCL);
1035
1036 return error;
1037}
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001040xfs_fs_write_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 struct inode *inode,
Christoph Hellwiga9185b42010-03-05 09:21:37 +01001042 struct writeback_control *wbc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043{
Dave Chinner2e656092008-11-28 14:23:33 +11001044 struct xfs_inode *ip = XFS_I(inode);
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +01001045 struct xfs_mount *mp = ip->i_mount;
Christoph Hellwig07fec732010-02-09 11:43:49 +11001046 int error = EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Dave Chinner2e656092008-11-28 14:23:33 +11001048 xfs_itrace_entry(ip);
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +01001049
1050 if (XFS_FORCED_SHUTDOWN(mp))
1051 return XFS_ERROR(EIO);
1052
Christoph Hellwiga9185b42010-03-05 09:21:37 +01001053 if (wbc->sync_mode == WB_SYNC_ALL) {
Christoph Hellwig07fec732010-02-09 11:43:49 +11001054 /*
1055 * Make sure the inode has hit stable storage. By using the
1056 * log and the fsync transactions we reduce the IOs we have
1057 * to do here from two (log and inode) to just the log.
1058 *
1059 * Note: We still need to do a delwri write of the inode after
1060 * this to flush it to the backing buffer so that bulkstat
1061 * works properly if this is the first time the inode has been
1062 * written. Because we hold the ilock atomically over the
1063 * transaction commit and the inode flush we are guaranteed
1064 * that the inode is not pinned when it returns. If the flush
1065 * lock is already held, then the inode has already been
1066 * flushed once and we don't need to flush it again. Hence
1067 * the code will only flush the inode if it isn't already
1068 * being flushed.
1069 */
Christoph Hellwig37bc5742010-04-20 17:00:59 +10001070 xfs_ioend_wait(ip);
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +01001071 xfs_ilock(ip, XFS_ILOCK_SHARED);
Christoph Hellwig07fec732010-02-09 11:43:49 +11001072 if (ip->i_update_core) {
1073 error = xfs_log_inode(ip);
1074 if (error)
1075 goto out_unlock;
1076 }
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +01001077 } else {
Christoph Hellwig07fec732010-02-09 11:43:49 +11001078 /*
1079 * We make this non-blocking if the inode is contended, return
1080 * EAGAIN to indicate to the caller that they did not succeed.
1081 * This prevents the flush path from blocking on inodes inside
1082 * another operation right now, they get caught later by xfs_sync.
1083 */
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +01001084 if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED))
1085 goto out;
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +01001086 }
1087
Christoph Hellwig07fec732010-02-09 11:43:49 +11001088 if (xfs_ipincount(ip) || !xfs_iflock_nowait(ip))
1089 goto out_unlock;
1090
1091 /*
1092 * Now we have the flush lock and the inode is not pinned, we can check
1093 * if the inode is really clean as we know that there are no pending
1094 * transaction completions, it is not waiting on the delayed write
1095 * queue and there is no IO in progress.
1096 */
1097 if (xfs_inode_clean(ip)) {
1098 xfs_ifunlock(ip);
1099 error = 0;
1100 goto out_unlock;
1101 }
1102 error = xfs_iflush(ip, 0);
1103
Christoph Hellwigd4bb6d02009-02-04 09:36:19 +01001104 out_unlock:
1105 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1106 out:
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001107 /*
1108 * if we failed to write out the inode then mark
1109 * it dirty again so we'll try again later.
1110 */
1111 if (error)
Dave Chinner2e656092008-11-28 14:23:33 +11001112 xfs_mark_inode_dirty_sync(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 return -error;
1114}
1115
1116STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001117xfs_fs_clear_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 struct inode *inode)
1119{
Christoph Hellwig1543d792007-08-29 11:46:47 +10001120 xfs_inode_t *ip = XFS_I(inode);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001121
David Chinner99fa8cb2008-10-30 17:36:40 +11001122 xfs_itrace_entry(ip);
1123 XFS_STATS_INC(vn_rele);
1124 XFS_STATS_INC(vn_remove);
1125 XFS_STATS_DEC(vn_active);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001126
Christoph Hellwig033da482009-10-19 04:05:26 +00001127 /*
1128 * The iolock is used by the file system to coordinate reads,
1129 * writes, and block truncates. Up to this point the lock
1130 * protected concurrent accesses by users of the inode. But
1131 * from here forward we're doing some final processing of the
1132 * inode because we're done with it, and although we reuse the
1133 * iolock for protection it is really a distinct lock class
1134 * (in the lockdep sense) from before. To keep lockdep happy
1135 * (and basically indicate what we are doing), we explicitly
1136 * re-init the iolock here.
1137 */
1138 ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
1139 mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
1140
David Chinner99fa8cb2008-10-30 17:36:40 +11001141 xfs_inactive(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144STATIC void
Christoph Hellwiga7381592008-08-13 16:04:05 +10001145xfs_free_fsname(
1146 struct xfs_mount *mp)
1147{
1148 kfree(mp->m_fsname);
1149 kfree(mp->m_rtname);
1150 kfree(mp->m_logname);
1151}
1152
1153STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001154xfs_fs_put_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 struct super_block *sb)
1156{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001157 struct xfs_mount *mp = XFS_M(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
David Chinnera167b172008-10-30 17:06:18 +11001159 xfs_syncd_stop(mp);
Christoph Hellwig075fe102009-06-08 15:35:48 +02001160
1161 if (!(sb->s_flags & MS_RDONLY)) {
1162 /*
1163 * XXX(hch): this should be SYNC_WAIT.
1164 *
1165 * Or more likely not needed at all because the VFS is already
1166 * calling ->sync_fs after shutting down all filestem
1167 * operations and just before calling ->put_super.
1168 */
1169 xfs_sync_data(mp, 0);
1170 xfs_sync_attr(mp, 0);
1171 }
Christoph Hellwige48ad312008-05-20 11:30:52 +10001172
Christoph Hellwige48ad312008-05-20 11:30:52 +10001173 /*
1174 * Blow away any referenced inode in the filestreams cache.
1175 * This can and will cause log traffic as inodes go inactive
1176 * here.
1177 */
1178 xfs_filestream_unmount(mp);
1179
1180 XFS_bflush(mp->m_ddev_targp);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001181
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001182 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001183 xfs_freesb(mp);
Dave Chinner9bf729c2010-04-29 09:55:50 +10001184 xfs_inode_shrinker_unregister(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001185 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001186 xfs_close_devices(mp);
Christoph Hellwiga7381592008-08-13 16:04:05 +10001187 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001188 kfree(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191STATIC int
Christoph Hellwig69961a22009-10-06 20:29:28 +00001192xfs_fs_sync_fs(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 struct super_block *sb,
1194 int wait)
1195{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001196 struct xfs_mount *mp = XFS_M(sb);
Nathan Scottb83bd132006-06-09 16:48:30 +10001197 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001199 /*
Christoph Hellwig69961a22009-10-06 20:29:28 +00001200 * Not much we can do for the first async pass. Writing out the
1201 * superblock would be counter-productive as we are going to redirty
1202 * when writing out other data and metadata (and writing out a single
1203 * block is quite fast anyway).
1204 *
1205 * Try to asynchronously kick off quota syncing at least.
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001206 */
Christoph Hellwig69961a22009-10-06 20:29:28 +00001207 if (!wait) {
1208 xfs_qm_sync(mp, SYNC_TRYLOCK);
1209 return 0;
1210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Christoph Hellwig69961a22009-10-06 20:29:28 +00001212 error = xfs_quiesce_data(mp);
1213 if (error)
1214 return -error;
1215
1216 if (laptop_mode) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001217 int prev_sync_seq = mp->m_sync_seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219 /*
1220 * The disk must be active because we're syncing.
1221 * We schedule xfssyncd now (now that the disk is
1222 * active) instead of later (when it might not be).
1223 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001224 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 /*
1226 * We have to wait for the sync iteration to complete.
1227 * If we don't, the disk activity caused by the sync
1228 * will come after the sync is completed, and that
1229 * triggers another sync from laptop mode.
1230 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001231 wait_event(mp->m_wait_single_sync_task,
1232 mp->m_sync_seq != prev_sync_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 }
1234
Christoph Hellwig69961a22009-10-06 20:29:28 +00001235 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236}
1237
1238STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001239xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001240 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 struct kstatfs *statp)
1242{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001243 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1244 xfs_sb_t *sbp = &mp->m_sb;
Christoph Hellwig7d095252009-06-08 15:33:32 +02001245 struct xfs_inode *ip = XFS_I(dentry->d_inode);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001246 __uint64_t fakeinos, id;
1247 xfs_extlen_t lsize;
1248
1249 statp->f_type = XFS_SB_MAGIC;
1250 statp->f_namelen = MAXNAMELEN - 1;
1251
1252 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1253 statp->f_fsid.val[0] = (u32)id;
1254 statp->f_fsid.val[1] = (u32)(id >> 32);
1255
Christoph Hellwigd4d90b52008-04-22 17:34:37 +10001256 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001257
1258 spin_lock(&mp->m_sb_lock);
1259 statp->f_bsize = sbp->sb_blocksize;
1260 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1261 statp->f_blocks = sbp->sb_dblocks - lsize;
1262 statp->f_bfree = statp->f_bavail =
1263 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1264 fakeinos = statp->f_bfree << sbp->sb_inopblog;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001265 statp->f_files =
1266 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1267 if (mp->m_maxicount)
Christoph Hellwiga19d9f82009-03-29 09:51:08 +02001268 statp->f_files = min_t(typeof(statp->f_files),
1269 statp->f_files,
1270 mp->m_maxicount);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001271 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1272 spin_unlock(&mp->m_sb_lock);
1273
Christoph Hellwig7d095252009-06-08 15:33:32 +02001274 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) ||
1275 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))) ==
1276 (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
1277 xfs_qm_statvfs(ip, statp);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001278 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279}
1280
Eric Sandeend5db0f92010-02-05 22:59:53 +00001281STATIC void
1282xfs_save_resvblks(struct xfs_mount *mp)
1283{
1284 __uint64_t resblks = 0;
1285
1286 mp->m_resblks_save = mp->m_resblks;
1287 xfs_reserve_blocks(mp, &resblks, NULL);
1288}
1289
1290STATIC void
1291xfs_restore_resvblks(struct xfs_mount *mp)
1292{
1293 __uint64_t resblks;
1294
1295 if (mp->m_resblks_save) {
1296 resblks = mp->m_resblks_save;
1297 mp->m_resblks_save = 0;
1298 } else
1299 resblks = xfs_default_resblks(mp);
1300
1301 xfs_reserve_blocks(mp, &resblks, NULL);
1302}
1303
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001305xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 struct super_block *sb,
1307 int *flags,
1308 char *options)
1309{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001310 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001311 substring_t args[MAX_OPT_ARGS];
1312 char *p;
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001313 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001315 while ((p = strsep(&options, ",")) != NULL) {
1316 int token;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001317
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001318 if (!*p)
1319 continue;
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001320
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001321 token = match_token(p, tokens, args);
1322 switch (token) {
1323 case Opt_barrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001324 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001325
1326 /*
1327 * Test if barriers are actually working if we can,
1328 * else delay this check until the filesystem is
1329 * marked writeable.
1330 */
1331 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1332 xfs_mountfs_check_barriers(mp);
1333 break;
1334 case Opt_nobarrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001335 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001336 break;
1337 default:
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001338 /*
1339 * Logically we would return an error here to prevent
1340 * users from believing they might have changed
1341 * mount options using remount which can't be changed.
1342 *
1343 * But unfortunately mount(8) adds all options from
1344 * mtab and fstab to the mount arguments in some cases
1345 * so we can't blindly reject options, but have to
1346 * check for each specified option if it actually
1347 * differs from the currently set option and only
1348 * reject it if that's the case.
1349 *
1350 * Until that is implemented we return success for
1351 * every remount request, and silently ignore all
1352 * options that we can't actually change.
1353 */
1354#if 0
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001355 printk(KERN_INFO
1356 "XFS: mount option \"%s\" not supported for remount\n", p);
1357 return -EINVAL;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001358#else
Christoph Hellwig6c5e51d2008-10-12 14:30:44 +02001359 break;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001360#endif
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001361 }
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001362 }
1363
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001364 /* ro -> rw */
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001365 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1366 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1367 if (mp->m_flags & XFS_MOUNT_BARRIER)
1368 xfs_mountfs_check_barriers(mp);
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001369
1370 /*
1371 * If this is the first remount to writeable state we
1372 * might have some superblock changes to update.
1373 */
1374 if (mp->m_update_flags) {
1375 error = xfs_mount_log_sb(mp, mp->m_update_flags);
1376 if (error) {
1377 cmn_err(CE_WARN,
1378 "XFS: failed to write sb changes");
1379 return error;
1380 }
1381 mp->m_update_flags = 0;
1382 }
Dave Chinnercbe132a2010-01-26 15:08:49 +11001383
1384 /*
1385 * Fill out the reserve pool if it is empty. Use the stashed
1386 * value if it is non-zero, otherwise go with the default.
1387 */
Eric Sandeend5db0f92010-02-05 22:59:53 +00001388 xfs_restore_resvblks(mp);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001389 }
1390
1391 /* rw -> ro */
1392 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
Dave Chinnercbe132a2010-01-26 15:08:49 +11001393 /*
1394 * After we have synced the data but before we sync the
1395 * metadata, we need to free up the reserve block pool so that
1396 * the used block count in the superblock on disk is correct at
1397 * the end of the remount. Stash the current reserve pool size
1398 * so that if we get remounted rw, we can return it to the same
1399 * size.
1400 */
Dave Chinnercbe132a2010-01-26 15:08:49 +11001401
David Chinnere9f1c6e2008-10-30 17:15:50 +11001402 xfs_quiesce_data(mp);
Eric Sandeend5db0f92010-02-05 22:59:53 +00001403 xfs_save_resvblks(mp);
David Chinner76bf1052008-10-30 17:16:21 +11001404 xfs_quiesce_attr(mp);
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001405 mp->m_flags |= XFS_MOUNT_RDONLY;
1406 }
1407
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001408 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409}
1410
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001411/*
1412 * Second stage of a freeze. The data is already frozen so we only
David Chinner76bf1052008-10-30 17:16:21 +11001413 * need to take care of the metadata. Once that's done write a dummy
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001414 * record to dirty the log in case of a crash while frozen.
1415 */
Takashi Satoc4be0c12009-01-09 16:40:58 -08001416STATIC int
1417xfs_fs_freeze(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 struct super_block *sb)
1419{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001420 struct xfs_mount *mp = XFS_M(sb);
1421
Eric Sandeend5db0f92010-02-05 22:59:53 +00001422 xfs_save_resvblks(mp);
David Chinner76bf1052008-10-30 17:16:21 +11001423 xfs_quiesce_attr(mp);
Takashi Satoc4be0c12009-01-09 16:40:58 -08001424 return -xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425}
1426
1427STATIC int
Eric Sandeend5db0f92010-02-05 22:59:53 +00001428xfs_fs_unfreeze(
1429 struct super_block *sb)
1430{
1431 struct xfs_mount *mp = XFS_M(sb);
1432
1433 xfs_restore_resvblks(mp);
1434 return 0;
1435}
1436
1437STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001438xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 struct seq_file *m,
1440 struct vfsmount *mnt)
1441{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001442 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443}
1444
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001445/*
1446 * This function fills in xfs_mount_t fields based on mount args.
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001447 * Note: the superblock _has_ now been read in.
1448 */
1449STATIC int
1450xfs_finish_flags(
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001451 struct xfs_mount *mp)
1452{
1453 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1454
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02001455 /* Fail a mount where the logbuf is smaller than the log stripe */
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001456 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001457 if (mp->m_logbsize <= 0 &&
1458 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001459 mp->m_logbsize = mp->m_sb.sb_logsunit;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001460 } else if (mp->m_logbsize > 0 &&
1461 mp->m_logbsize < mp->m_sb.sb_logsunit) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001462 cmn_err(CE_WARN,
1463 "XFS: logbuf size must be greater than or equal to log stripe size");
1464 return XFS_ERROR(EINVAL);
1465 }
1466 } else {
1467 /* Fail a mount if the logbuf is larger than 32K */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001468 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001469 cmn_err(CE_WARN,
1470 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1471 return XFS_ERROR(EINVAL);
1472 }
1473 }
1474
1475 /*
1476 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1477 * told by noattr2 to turn it off
1478 */
1479 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001480 !(mp->m_flags & XFS_MOUNT_NOATTR2))
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001481 mp->m_flags |= XFS_MOUNT_ATTR2;
1482
1483 /*
1484 * prohibit r/w mounts of read-only filesystems
1485 */
1486 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1487 cmn_err(CE_WARN,
1488 "XFS: cannot mount a read-only filesystem as read-write");
1489 return XFS_ERROR(EROFS);
1490 }
1491
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001492 return 0;
1493}
1494
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001496xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 struct super_block *sb,
1498 void *data,
1499 int silent)
1500{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001501 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001502 struct xfs_mount *mp = NULL;
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001503 int flags = 0, error = ENOMEM;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001504
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001505 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1506 if (!mp)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001507 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001509 spin_lock_init(&mp->m_sb_lock);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001510 mutex_init(&mp->m_growlock);
1511 atomic_set(&mp->m_active_trans, 0);
Christoph Hellwig74394492007-08-30 17:21:22 +10001512 INIT_LIST_HEAD(&mp->m_sync_list);
1513 spin_lock_init(&mp->m_sync_lock);
1514 init_waitqueue_head(&mp->m_wait_single_sync_task);
1515
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001516 mp->m_super = sb;
1517 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Christoph Hellwig288699f2010-06-23 18:11:15 +10001519 error = xfs_parseargs(mp, (char *)data);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001520 if (error)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001521 goto out_free_fsname;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
1523 sb_min_blocksize(sb, BBSIZE);
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001524 sb->s_xattr = xfs_xattr_handlers;
Nathan Scotta50cd262006-03-14 14:06:18 +11001525 sb->s_export_op = &xfs_export_operations;
Christoph Hellwigfcafb712009-02-09 08:47:34 +01001526#ifdef CONFIG_XFS_QUOTA
Nathan Scotta50cd262006-03-14 14:06:18 +11001527 sb->s_qcop = &xfs_quotactl_operations;
Christoph Hellwigfcafb712009-02-09 08:47:34 +01001528#endif
Nathan Scotta50cd262006-03-14 14:06:18 +11001529 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001531 if (silent)
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001532 flags |= XFS_MFSI_QUIET;
1533
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001534 error = xfs_open_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001535 if (error)
Christoph Hellwig288699f2010-06-23 18:11:15 +10001536 goto out_free_fsname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001537
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001538 if (xfs_icsb_init_counters(mp))
1539 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1540
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001541 error = xfs_readsb(mp, flags);
1542 if (error)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001543 goto out_destroy_counters;
1544
1545 error = xfs_finish_flags(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001546 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001547 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001548
Christoph Hellwige34b5622008-05-20 15:10:36 +10001549 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001550 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001551 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001552
1553 if (mp->m_flags & XFS_MOUNT_BARRIER)
1554 xfs_mountfs_check_barriers(mp);
1555
1556 error = xfs_filestream_mount(mp);
1557 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001558 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001559
Christoph Hellwig42490232008-08-13 16:49:32 +10001560 error = xfs_mountfs(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001561 if (error)
Christoph Hellwig120226c2008-05-20 15:11:11 +10001562 goto out_filestream_unmount;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001563
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001564 sb->s_magic = XFS_SB_MAGIC;
1565 sb->s_blocksize = mp->m_sb.sb_blocksize;
1566 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1568 sb->s_time_gran = 1;
1569 set_posix_acl_flag(sb);
1570
David Chinner01651642008-08-13 15:45:15 +10001571 root = igrab(VFS_I(mp->m_rootip));
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001572 if (!root) {
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001573 error = ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 goto fail_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001575 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001576 if (is_bad_inode(root)) {
1577 error = EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 goto fail_vnrele;
1579 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001580 sb->s_root = d_alloc_root(root);
1581 if (!sb->s_root) {
1582 error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 goto fail_vnrele;
1584 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001585
David Chinnera167b172008-10-30 17:06:18 +11001586 error = xfs_syncd_init(mp);
1587 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 goto fail_vnrele;
Christoph Hellwig74394492007-08-30 17:21:22 +10001589
Dave Chinner9bf729c2010-04-29 09:55:50 +10001590 xfs_inode_shrinker_register(mp);
1591
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 return 0;
1593
Christoph Hellwig120226c2008-05-20 15:11:11 +10001594 out_filestream_unmount:
1595 xfs_filestream_unmount(mp);
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001596 out_free_sb:
1597 xfs_freesb(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001598 out_destroy_counters:
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001599 xfs_icsb_destroy_counters(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001600 xfs_close_devices(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001601 out_free_fsname:
1602 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001603 kfree(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001604 out:
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001605 return -error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001606
1607 fail_vnrele:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 if (sb->s_root) {
1609 dput(sb->s_root);
1610 sb->s_root = NULL;
1611 } else {
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001612 iput(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 }
1614
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001615 fail_unmount:
Christoph Hellwige48ad312008-05-20 11:30:52 +10001616 /*
1617 * Blow away any referenced inode in the filestreams cache.
1618 * This can and will cause log traffic as inodes go inactive
1619 * here.
1620 */
1621 xfs_filestream_unmount(mp);
1622
1623 XFS_bflush(mp->m_ddev_targp);
Christoph Hellwige48ad312008-05-20 11:30:52 +10001624
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001625 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001626 goto out_free_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
David Howells454e2392006-06-23 02:02:57 -07001629STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001630xfs_fs_get_sb(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 struct file_system_type *fs_type,
1632 int flags,
1633 const char *dev_name,
David Howells454e2392006-06-23 02:02:57 -07001634 void *data,
1635 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
David Howells454e2392006-06-23 02:02:57 -07001637 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1638 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639}
1640
Alexey Dobriyanb87221d2009-09-21 17:01:09 -07001641static const struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001642 .alloc_inode = xfs_fs_alloc_inode,
1643 .destroy_inode = xfs_fs_destroy_inode,
Christoph Hellwigf9581b12009-10-06 20:29:26 +00001644 .dirty_inode = xfs_fs_dirty_inode,
Nathan Scotta50cd262006-03-14 14:06:18 +11001645 .write_inode = xfs_fs_write_inode,
1646 .clear_inode = xfs_fs_clear_inode,
1647 .put_super = xfs_fs_put_super,
Christoph Hellwig69961a22009-10-06 20:29:28 +00001648 .sync_fs = xfs_fs_sync_fs,
Takashi Satoc4be0c12009-01-09 16:40:58 -08001649 .freeze_fs = xfs_fs_freeze,
Eric Sandeend5db0f92010-02-05 22:59:53 +00001650 .unfreeze_fs = xfs_fs_unfreeze,
Nathan Scotta50cd262006-03-14 14:06:18 +11001651 .statfs = xfs_fs_statfs,
1652 .remount_fs = xfs_fs_remount,
1653 .show_options = xfs_fs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654};
1655
Andrew Morton5085b602007-02-20 13:57:47 -08001656static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 .owner = THIS_MODULE,
1658 .name = "xfs",
Nathan Scotta50cd262006-03-14 14:06:18 +11001659 .get_sb = xfs_fs_get_sb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 .kill_sb = kill_block_super,
1661 .fs_flags = FS_REQUIRES_DEV,
1662};
1663
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001664STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001665xfs_init_zones(void)
1666{
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001667
1668 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1669 if (!xfs_ioend_zone)
David Chinnerbf904242008-10-30 17:36:14 +11001670 goto out;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001671
1672 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1673 xfs_ioend_zone);
1674 if (!xfs_ioend_pool)
1675 goto out_destroy_ioend_zone;
1676
1677 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1678 "xfs_log_ticket");
1679 if (!xfs_log_ticket_zone)
1680 goto out_destroy_ioend_pool;
1681
1682 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1683 "xfs_bmap_free_item");
1684 if (!xfs_bmap_free_item_zone)
1685 goto out_destroy_log_ticket_zone;
David Chinnerbf904242008-10-30 17:36:14 +11001686
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001687 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1688 "xfs_btree_cur");
1689 if (!xfs_btree_cur_zone)
1690 goto out_destroy_bmap_free_item_zone;
1691
1692 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1693 "xfs_da_state");
1694 if (!xfs_da_state_zone)
1695 goto out_destroy_btree_cur_zone;
1696
1697 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
1698 if (!xfs_dabuf_zone)
1699 goto out_destroy_da_state_zone;
1700
1701 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1702 if (!xfs_ifork_zone)
1703 goto out_destroy_dabuf_zone;
1704
1705 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1706 if (!xfs_trans_zone)
1707 goto out_destroy_ifork_zone;
1708
1709 /*
1710 * The size of the zone allocated buf log item is the maximum
1711 * size possible under XFS. This wastes a little bit of memory,
1712 * but it is much faster.
1713 */
1714 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
Dave Chinnerc1155412010-05-07 11:05:19 +10001715 (((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) /
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001716 NBWORD) * sizeof(int))), "xfs_buf_item");
1717 if (!xfs_buf_item_zone)
1718 goto out_destroy_trans_zone;
1719
1720 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1721 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1722 sizeof(xfs_extent_t))), "xfs_efd_item");
1723 if (!xfs_efd_zone)
1724 goto out_destroy_buf_item_zone;
1725
1726 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1727 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1728 sizeof(xfs_extent_t))), "xfs_efi_item");
1729 if (!xfs_efi_zone)
1730 goto out_destroy_efd_zone;
1731
1732 xfs_inode_zone =
1733 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
David Chinnerbf904242008-10-30 17:36:14 +11001734 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
1735 xfs_fs_inode_init_once);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001736 if (!xfs_inode_zone)
1737 goto out_destroy_efi_zone;
1738
1739 xfs_ili_zone =
1740 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1741 KM_ZONE_SPREAD, NULL);
1742 if (!xfs_ili_zone)
1743 goto out_destroy_inode_zone;
1744
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001745 return 0;
1746
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001747 out_destroy_inode_zone:
1748 kmem_zone_destroy(xfs_inode_zone);
1749 out_destroy_efi_zone:
1750 kmem_zone_destroy(xfs_efi_zone);
1751 out_destroy_efd_zone:
1752 kmem_zone_destroy(xfs_efd_zone);
1753 out_destroy_buf_item_zone:
1754 kmem_zone_destroy(xfs_buf_item_zone);
1755 out_destroy_trans_zone:
1756 kmem_zone_destroy(xfs_trans_zone);
1757 out_destroy_ifork_zone:
1758 kmem_zone_destroy(xfs_ifork_zone);
1759 out_destroy_dabuf_zone:
1760 kmem_zone_destroy(xfs_dabuf_zone);
1761 out_destroy_da_state_zone:
1762 kmem_zone_destroy(xfs_da_state_zone);
1763 out_destroy_btree_cur_zone:
1764 kmem_zone_destroy(xfs_btree_cur_zone);
1765 out_destroy_bmap_free_item_zone:
1766 kmem_zone_destroy(xfs_bmap_free_item_zone);
1767 out_destroy_log_ticket_zone:
1768 kmem_zone_destroy(xfs_log_ticket_zone);
1769 out_destroy_ioend_pool:
1770 mempool_destroy(xfs_ioend_pool);
1771 out_destroy_ioend_zone:
1772 kmem_zone_destroy(xfs_ioend_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001773 out:
1774 return -ENOMEM;
1775}
1776
1777STATIC void
1778xfs_destroy_zones(void)
1779{
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001780 kmem_zone_destroy(xfs_ili_zone);
1781 kmem_zone_destroy(xfs_inode_zone);
1782 kmem_zone_destroy(xfs_efi_zone);
1783 kmem_zone_destroy(xfs_efd_zone);
1784 kmem_zone_destroy(xfs_buf_item_zone);
1785 kmem_zone_destroy(xfs_trans_zone);
1786 kmem_zone_destroy(xfs_ifork_zone);
1787 kmem_zone_destroy(xfs_dabuf_zone);
1788 kmem_zone_destroy(xfs_da_state_zone);
1789 kmem_zone_destroy(xfs_btree_cur_zone);
1790 kmem_zone_destroy(xfs_bmap_free_item_zone);
1791 kmem_zone_destroy(xfs_log_ticket_zone);
1792 mempool_destroy(xfs_ioend_pool);
1793 kmem_zone_destroy(xfs_ioend_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001794
1795}
1796
1797STATIC int __init
1798init_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799{
1800 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
Christoph Hellwig65795912008-11-28 14:23:33 +11001802 printk(KERN_INFO XFS_VERSION_STRING " with "
1803 XFS_BUILD_OPTIONS " enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
Christoph Hellwig25e41b32008-12-03 12:20:39 +01001805 xfs_ioend_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001806 xfs_dir_startup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
Nathan Scott87582802006-03-14 13:18:19 +11001808 error = xfs_init_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001809 if (error)
1810 goto out;
1811
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001812 error = xfs_mru_cache_init();
1813 if (error)
Christoph Hellwig0b1b2132009-12-14 23:14:59 +00001814 goto out_destroy_zones;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001815
1816 error = xfs_filestream_init();
1817 if (error)
1818 goto out_mru_cache_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Nathan Scottce8e9222006-01-11 15:39:08 +11001820 error = xfs_buf_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001821 if (error)
1822 goto out_filestream_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001824 error = xfs_init_procfs();
1825 if (error)
1826 goto out_buf_terminate;
1827
1828 error = xfs_sysctl_register();
1829 if (error)
1830 goto out_cleanup_procfs;
1831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 vfs_initquota();
1833
1834 error = register_filesystem(&xfs_fs_type);
1835 if (error)
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001836 goto out_sysctl_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 return 0;
1838
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001839 out_sysctl_unregister:
1840 xfs_sysctl_unregister();
1841 out_cleanup_procfs:
1842 xfs_cleanup_procfs();
1843 out_buf_terminate:
Nathan Scottce8e9222006-01-11 15:39:08 +11001844 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001845 out_filestream_uninit:
1846 xfs_filestream_uninit();
1847 out_mru_cache_uninit:
1848 xfs_mru_cache_uninit();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001849 out_destroy_zones:
Nathan Scott87582802006-03-14 13:18:19 +11001850 xfs_destroy_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001851 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 return error;
1853}
1854
1855STATIC void __exit
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001856exit_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857{
1858 vfs_exitquota();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 unregister_filesystem(&xfs_fs_type);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001860 xfs_sysctl_unregister();
1861 xfs_cleanup_procfs();
Nathan Scottce8e9222006-01-11 15:39:08 +11001862 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001863 xfs_filestream_uninit();
1864 xfs_mru_cache_uninit();
Nathan Scott87582802006-03-14 13:18:19 +11001865 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866}
1867
1868module_init(init_xfs_fs);
1869module_exit(exit_xfs_fs);
1870
1871MODULE_AUTHOR("Silicon Graphics, Inc.");
1872MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1873MODULE_LICENSE("GPL");