]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/xfs/xfs_super.c
xfs: reshuffle dir2 definitions around for userspace
[mirror_ubuntu-artful-kernel.git] / fs / xfs / xfs_super.c
CommitLineData
1da177e4 1/*
a805bad5 2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
7b718769 3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
9 * 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.
1da177e4 13 *
7b718769
NS
14 * 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
1da177e4 17 */
0b1b213f 18
1da177e4 19#include "xfs.h"
6ca1c906 20#include "xfs_format.h"
1da177e4 21#include "xfs_log.h"
a844f451 22#include "xfs_inum.h"
1da177e4
LT
23#include "xfs_trans.h"
24#include "xfs_sb.h"
a844f451 25#include "xfs_ag.h"
1da177e4 26#include "xfs_alloc.h"
1da177e4
LT
27#include "xfs_quota.h"
28#include "xfs_mount.h"
1da177e4 29#include "xfs_bmap_btree.h"
a844f451 30#include "xfs_alloc_btree.h"
1da177e4 31#include "xfs_ialloc_btree.h"
1da177e4
LT
32#include "xfs_dinode.h"
33#include "xfs_inode.h"
a844f451
NS
34#include "xfs_btree.h"
35#include "xfs_ialloc.h"
1da177e4 36#include "xfs_bmap.h"
1da177e4
LT
37#include "xfs_rtalloc.h"
38#include "xfs_error.h"
39#include "xfs_itable.h"
9909c4aa 40#include "xfs_fsops.h"
1da177e4
LT
41#include "xfs_attr.h"
42#include "xfs_buf_item.h"
43#include "xfs_utils.h"
739bfb2a 44#include "xfs_vnodeops.h"
a67d7c5f 45#include "xfs_log_priv.h"
249a8c11 46#include "xfs_trans_priv.h"
48b62a1a 47#include "xfs_filestream.h"
9f8868ff 48#include "xfs_da_btree.h"
2b9ab5ab
DC
49#include "xfs_dir2_format.h"
50#include "xfs_dir2.h"
9f8868ff
CH
51#include "xfs_extfree_item.h"
52#include "xfs_mru_cache.h"
53#include "xfs_inode_item.h"
6d8b79cf 54#include "xfs_icache.h"
0b1b213f 55#include "xfs_trace.h"
3ebe7d2d 56#include "xfs_icreate_item.h"
1da177e4
LT
57
58#include <linux/namei.h>
59#include <linux/init.h>
5a0e3ad6 60#include <linux/slab.h>
1da177e4 61#include <linux/mount.h>
0829c360 62#include <linux/mempool.h>
1da177e4 63#include <linux/writeback.h>
4df08c52 64#include <linux/kthread.h>
7dfb7103 65#include <linux/freezer.h>
62a877e3 66#include <linux/parser.h>
1da177e4 67
b87221de 68static const struct super_operations xfs_super_operations;
7989cb8e 69static kmem_zone_t *xfs_ioend_zone;
0829c360 70mempool_t *xfs_ioend_pool;
1da177e4 71
a67d7c5f
DC
72#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
73#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
74#define MNTOPT_LOGDEV "logdev" /* log device */
75#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
76#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
77#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
a67d7c5f
DC
78#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
79#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
80#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
81#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
82#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
83#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
84#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
85#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
86#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
87#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
88#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
89#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
90#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
91 * unwritten extent conversion */
92#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
a67d7c5f 93#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
08bf5404
CM
94#define MNTOPT_32BITINODE "inode32" /* inode allocation limited to
95 * XFS_MAXINUMBER_32 */
a67d7c5f
DC
96#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
97#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
98#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
99#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
100 * in stat(). */
101#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
102#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
103#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
104#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
105#define MNTOPT_NOQUOTA "noquota" /* no quotas */
106#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
107#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
108#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
109#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
110#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
111#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
112#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
113#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
114#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
115#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
e84661aa
CH
116#define MNTOPT_DELAYLOG "delaylog" /* Delayed logging enabled */
117#define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
118#define MNTOPT_DISCARD "discard" /* Discard unused blocks */
119#define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
a67d7c5f 120
62a877e3
CH
121/*
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 {
2ea03929
CM
128 Opt_barrier,
129 Opt_nobarrier,
130 Opt_inode64,
131 Opt_inode32,
132 Opt_err
62a877e3
CH
133};
134
a447c093 135static const match_table_t tokens = {
62a877e3
CH
136 {Opt_barrier, "barrier"},
137 {Opt_nobarrier, "nobarrier"},
c3a58fec 138 {Opt_inode64, "inode64"},
2ea03929 139 {Opt_inode32, "inode32"},
62a877e3
CH
140 {Opt_err, NULL}
141};
142
143
a67d7c5f 144STATIC unsigned long
a17164e5 145suffix_kstrtoint(char *s, unsigned int base, int *res)
a67d7c5f 146{
a17164e5 147 int last, shift_left_factor = 0, _res;
a67d7c5f
DC
148 char *value = s;
149
150 last = strlen(value) - 1;
151 if (value[last] == 'K' || value[last] == 'k') {
152 shift_left_factor = 10;
153 value[last] = '\0';
154 }
155 if (value[last] == 'M' || value[last] == 'm') {
156 shift_left_factor = 20;
157 value[last] = '\0';
158 }
159 if (value[last] == 'G' || value[last] == 'g') {
160 shift_left_factor = 30;
161 value[last] = '\0';
162 }
163
a17164e5
AP
164 if (kstrtoint(s, base, &_res))
165 return -EINVAL;
166 *res = _res << shift_left_factor;
167 return 0;
a67d7c5f
DC
168}
169
9d565ffa
CH
170/*
171 * This function fills in xfs_mount_t fields based on mount args.
172 * Note: the superblock has _not_ yet been read in.
173 *
174 * Note that this function leaks the various device name allocations on
175 * failure. The caller takes care of them.
176 */
a67d7c5f
DC
177STATIC int
178xfs_parseargs(
179 struct xfs_mount *mp,
288699fe 180 char *options)
a67d7c5f 181{
9d565ffa 182 struct super_block *sb = mp->m_super;
a17164e5 183 char *this_char, *value;
9d565ffa
CH
184 int dsunit = 0;
185 int dswidth = 0;
186 int iosize = 0;
a5687787 187 __uint8_t iosizelog = 0;
9d565ffa 188
4f10700a
DC
189 /*
190 * set up the mount name first so all the errors will refer to the
191 * correct device.
192 */
193 mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
194 if (!mp->m_fsname)
195 return ENOMEM;
196 mp->m_fsname_len = strlen(mp->m_fsname) + 1;
197
9d565ffa
CH
198 /*
199 * Copy binary VFS mount flags we are interested in.
200 */
201 if (sb->s_flags & MS_RDONLY)
202 mp->m_flags |= XFS_MOUNT_RDONLY;
203 if (sb->s_flags & MS_DIRSYNC)
204 mp->m_flags |= XFS_MOUNT_DIRSYNC;
205 if (sb->s_flags & MS_SYNCHRONOUS)
206 mp->m_flags |= XFS_MOUNT_WSYNC;
207
208 /*
209 * Set some default flags that could be cleared by the mount option
210 * parsing.
211 */
212 mp->m_flags |= XFS_MOUNT_BARRIER;
213 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
08bf5404 214#if !XFS_BIG_INUMS
9d565ffa 215 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
08bf5404 216#endif
a67d7c5f 217
9d565ffa
CH
218 /*
219 * These can be overridden by the mount option parsing.
220 */
221 mp->m_logbufs = -1;
222 mp->m_logbsize = -1;
a67d7c5f
DC
223
224 if (!options)
225 goto done;
226
a67d7c5f
DC
227 while ((this_char = strsep(&options, ",")) != NULL) {
228 if (!*this_char)
229 continue;
230 if ((value = strchr(this_char, '=')) != NULL)
231 *value++ = 0;
232
233 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
234 if (!value || !*value) {
4f10700a 235 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
236 this_char);
237 return EINVAL;
238 }
a17164e5
AP
239 if (kstrtoint(value, 10, &mp->m_logbufs))
240 return EINVAL;
a67d7c5f
DC
241 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
242 if (!value || !*value) {
4f10700a 243 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
244 this_char);
245 return EINVAL;
246 }
a17164e5
AP
247 if (suffix_kstrtoint(value, 10, &mp->m_logbsize))
248 return EINVAL;
a67d7c5f
DC
249 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
250 if (!value || !*value) {
4f10700a 251 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
252 this_char);
253 return EINVAL;
254 }
9d565ffa
CH
255 mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
256 if (!mp->m_logname)
257 return ENOMEM;
a67d7c5f 258 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
4f10700a 259 xfs_warn(mp, "%s option not allowed on this system",
288699fe
CH
260 this_char);
261 return EINVAL;
a67d7c5f
DC
262 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
263 if (!value || !*value) {
4f10700a 264 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
265 this_char);
266 return EINVAL;
267 }
9d565ffa
CH
268 mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
269 if (!mp->m_rtname)
270 return ENOMEM;
a67d7c5f
DC
271 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
272 if (!value || !*value) {
4f10700a 273 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
274 this_char);
275 return EINVAL;
276 }
a17164e5
AP
277 if (kstrtoint(value, 10, &iosize))
278 return EINVAL;
1ec7944b 279 iosizelog = ffs(iosize) - 1;
a67d7c5f
DC
280 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
281 if (!value || !*value) {
4f10700a 282 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
283 this_char);
284 return EINVAL;
285 }
a17164e5
AP
286 if (suffix_kstrtoint(value, 10, &iosize))
287 return EINVAL;
9d565ffa 288 iosizelog = ffs(iosize) - 1;
a67d7c5f
DC
289 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
290 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
291 mp->m_flags |= XFS_MOUNT_GRPID;
292 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
293 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
294 mp->m_flags &= ~XFS_MOUNT_GRPID;
295 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
9d565ffa 296 mp->m_flags |= XFS_MOUNT_WSYNC;
a67d7c5f 297 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
9d565ffa 298 mp->m_flags |= XFS_MOUNT_NORECOVERY;
a67d7c5f 299 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
9d565ffa 300 mp->m_flags |= XFS_MOUNT_NOALIGN;
a67d7c5f 301 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
9d565ffa 302 mp->m_flags |= XFS_MOUNT_SWALLOC;
a67d7c5f
DC
303 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
304 if (!value || !*value) {
4f10700a 305 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
306 this_char);
307 return EINVAL;
308 }
a17164e5
AP
309 if (kstrtoint(value, 10, &dsunit))
310 return EINVAL;
a67d7c5f
DC
311 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
312 if (!value || !*value) {
4f10700a 313 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
314 this_char);
315 return EINVAL;
316 }
a17164e5
AP
317 if (kstrtoint(value, 10, &dswidth))
318 return EINVAL;
08bf5404
CM
319 } else if (!strcmp(this_char, MNTOPT_32BITINODE)) {
320 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
a67d7c5f 321 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
9d565ffa 322 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
a67d7c5f 323#if !XFS_BIG_INUMS
4f10700a 324 xfs_warn(mp, "%s option not allowed on this system",
a67d7c5f
DC
325 this_char);
326 return EINVAL;
327#endif
328 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
9d565ffa 329 mp->m_flags |= XFS_MOUNT_NOUUID;
a67d7c5f 330 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
9d565ffa 331 mp->m_flags |= XFS_MOUNT_BARRIER;
a67d7c5f 332 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
9d565ffa 333 mp->m_flags &= ~XFS_MOUNT_BARRIER;
a67d7c5f 334 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
9d565ffa 335 mp->m_flags |= XFS_MOUNT_IKEEP;
a67d7c5f 336 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
9d565ffa 337 mp->m_flags &= ~XFS_MOUNT_IKEEP;
a67d7c5f 338 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
9d565ffa 339 mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
a67d7c5f 340 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
9d565ffa 341 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
a67d7c5f 342 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
9d565ffa 343 mp->m_flags |= XFS_MOUNT_ATTR2;
a67d7c5f 344 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
9d565ffa
CH
345 mp->m_flags &= ~XFS_MOUNT_ATTR2;
346 mp->m_flags |= XFS_MOUNT_NOATTR2;
a67d7c5f 347 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
9d565ffa 348 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
a67d7c5f 349 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
4177af3a
CS
350 mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
351 mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
352 mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
a67d7c5f
DC
353 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
354 !strcmp(this_char, MNTOPT_UQUOTA) ||
355 !strcmp(this_char, MNTOPT_USRQUOTA)) {
9d565ffa
CH
356 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
357 XFS_UQUOTA_ENFD);
a67d7c5f
DC
358 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
359 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
9d565ffa
CH
360 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
361 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
a67d7c5f
DC
362 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
363 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
9d565ffa 364 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
83e782e1 365 XFS_PQUOTA_ENFD);
a67d7c5f 366 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
9d565ffa 367 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
83e782e1 368 mp->m_qflags &= ~XFS_PQUOTA_ENFD;
a67d7c5f
DC
369 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
370 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
9d565ffa 371 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
83e782e1 372 XFS_GQUOTA_ENFD);
a67d7c5f 373 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
9d565ffa 374 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
83e782e1 375 mp->m_qflags &= ~XFS_GQUOTA_ENFD;
71e330b5 376 } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) {
93b8a585
CH
377 xfs_warn(mp,
378 "delaylog is the default now, option is deprecated.");
71e330b5 379 } else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) {
242d6219 380 xfs_warn(mp,
93b8a585 381 "nodelaylog support has been removed, option is deprecated.");
e84661aa
CH
382 } else if (!strcmp(this_char, MNTOPT_DISCARD)) {
383 mp->m_flags |= XFS_MOUNT_DISCARD;
384 } else if (!strcmp(this_char, MNTOPT_NODISCARD)) {
385 mp->m_flags &= ~XFS_MOUNT_DISCARD;
a67d7c5f 386 } else if (!strcmp(this_char, "ihashsize")) {
4f10700a
DC
387 xfs_warn(mp,
388 "ihashsize no longer used, option is deprecated.");
a67d7c5f 389 } else if (!strcmp(this_char, "osyncisdsync")) {
4f10700a
DC
390 xfs_warn(mp,
391 "osyncisdsync has no effect, option is deprecated.");
a64afb05 392 } else if (!strcmp(this_char, "osyncisosync")) {
4f10700a
DC
393 xfs_warn(mp,
394 "osyncisosync has no effect, option is deprecated.");
a67d7c5f 395 } else if (!strcmp(this_char, "irixsgid")) {
4f10700a
DC
396 xfs_warn(mp,
397 "irixsgid is now a sysctl(2) variable, option is deprecated.");
a67d7c5f 398 } else {
4f10700a 399 xfs_warn(mp, "unknown mount option [%s].", this_char);
a67d7c5f
DC
400 return EINVAL;
401 }
402 }
403
9d565ffa
CH
404 /*
405 * no recovery flag requires a read-only mount
406 */
407 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
408 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
4f10700a 409 xfs_warn(mp, "no-recovery mounts must be read-only.");
9d565ffa 410 return EINVAL;
a67d7c5f
DC
411 }
412
9d565ffa 413 if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
4f10700a
DC
414 xfs_warn(mp,
415 "sunit and swidth options incompatible with the noalign option");
a67d7c5f
DC
416 return EINVAL;
417 }
418
7d095257
CH
419#ifndef CONFIG_XFS_QUOTA
420 if (XFS_IS_QUOTA_RUNNING(mp)) {
4f10700a 421 xfs_warn(mp, "quota support not available in this kernel.");
7d095257
CH
422 return EINVAL;
423 }
424#endif
425
a67d7c5f 426 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
4f10700a 427 xfs_warn(mp, "sunit and swidth must be specified together");
a67d7c5f
DC
428 return EINVAL;
429 }
430
431 if (dsunit && (dswidth % dsunit != 0)) {
4f10700a
DC
432 xfs_warn(mp,
433 "stripe width (%d) must be a multiple of the stripe unit (%d)",
a67d7c5f
DC
434 dswidth, dsunit);
435 return EINVAL;
436 }
437
9d565ffa 438done:
39a45d84 439 if (dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) {
9d565ffa
CH
440 /*
441 * At this point the superblock has not been read
442 * in, therefore we do not know the block size.
443 * Before the mount call ends we will convert
444 * these to FSBs.
445 */
39a45d84
JL
446 mp->m_dalign = dsunit;
447 mp->m_swidth = dswidth;
9d565ffa
CH
448 }
449
450 if (mp->m_logbufs != -1 &&
451 mp->m_logbufs != 0 &&
452 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
453 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
4f10700a 454 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
9d565ffa
CH
455 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
456 return XFS_ERROR(EINVAL);
457 }
458 if (mp->m_logbsize != -1 &&
459 mp->m_logbsize != 0 &&
460 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
461 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
462 !is_power_of_2(mp->m_logbsize))) {
4f10700a
DC
463 xfs_warn(mp,
464 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
9d565ffa
CH
465 mp->m_logbsize);
466 return XFS_ERROR(EINVAL);
467 }
468
9d565ffa
CH
469 if (iosizelog) {
470 if (iosizelog > XFS_MAX_IO_LOG ||
471 iosizelog < XFS_MIN_IO_LOG) {
4f10700a 472 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
9d565ffa
CH
473 iosizelog, XFS_MIN_IO_LOG,
474 XFS_MAX_IO_LOG);
475 return XFS_ERROR(EINVAL);
476 }
477
478 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
479 mp->m_readio_log = iosizelog;
480 mp->m_writeio_log = iosizelog;
a67d7c5f
DC
481 }
482
a67d7c5f
DC
483 return 0;
484}
485
486struct proc_xfs_info {
487 int flag;
488 char *str;
489};
490
491STATIC int
492xfs_showargs(
493 struct xfs_mount *mp,
494 struct seq_file *m)
495{
496 static struct proc_xfs_info xfs_info_set[] = {
497 /* the few simple ones we can get from the mount struct */
1bd960ee 498 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
a67d7c5f 499 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
a67d7c5f
DC
500 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
501 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
502 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
503 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
a67d7c5f
DC
504 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
505 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
a67d7c5f 506 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
e84661aa 507 { XFS_MOUNT_DISCARD, "," MNTOPT_DISCARD },
08bf5404 508 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_32BITINODE },
a67d7c5f
DC
509 { 0, NULL }
510 };
511 static struct proc_xfs_info xfs_info_unset[] = {
512 /* the few simple ones we can get from the mount struct */
a67d7c5f
DC
513 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
514 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
515 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
516 { 0, NULL }
517 };
518 struct proc_xfs_info *xfs_infop;
519
520 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
521 if (mp->m_flags & xfs_infop->flag)
522 seq_puts(m, xfs_infop->str);
523 }
524 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
525 if (!(mp->m_flags & xfs_infop->flag))
526 seq_puts(m, xfs_infop->str);
527 }
528
529 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
530 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
531 (int)(1 << mp->m_writeio_log) >> 10);
532
533 if (mp->m_logbufs > 0)
534 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
535 if (mp->m_logbsize > 0)
536 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
537
538 if (mp->m_logname)
539 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
540 if (mp->m_rtname)
541 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
542
543 if (mp->m_dalign > 0)
544 seq_printf(m, "," MNTOPT_SUNIT "=%d",
545 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
546 if (mp->m_swidth > 0)
547 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
548 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
549
550 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
551 seq_puts(m, "," MNTOPT_USRQUOTA);
552 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
553 seq_puts(m, "," MNTOPT_UQUOTANOENF);
554
988abe40 555 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
83e782e1 556 if (mp->m_qflags & XFS_PQUOTA_ENFD)
988abe40
AE
557 seq_puts(m, "," MNTOPT_PRJQUOTA);
558 else
559 seq_puts(m, "," MNTOPT_PQUOTANOENF);
d892d586
CS
560 }
561 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
83e782e1 562 if (mp->m_qflags & XFS_GQUOTA_ENFD)
988abe40
AE
563 seq_puts(m, "," MNTOPT_GRPQUOTA);
564 else
565 seq_puts(m, "," MNTOPT_GQUOTANOENF);
566 }
a67d7c5f
DC
567
568 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
569 seq_puts(m, "," MNTOPT_NOQUOTA);
570
571 return 0;
572}
1da177e4
LT
573__uint64_t
574xfs_max_file_offset(
575 unsigned int blockshift)
576{
577 unsigned int pagefactor = 1;
578 unsigned int bitshift = BITS_PER_LONG - 1;
579
580 /* Figure out maximum filesize, on Linux this can depend on
581 * the filesystem blocksize (on 32 bit platforms).
ebdec241 582 * __block_write_begin does this in an [unsigned] long...
1da177e4
LT
583 * page->index << (PAGE_CACHE_SHIFT - bbits)
584 * So, for page sized blocks (4K on 32 bit platforms),
585 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
586 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
587 * but for smaller blocksizes it is less (bbits = log2 bsize).
588 * Note1: get_block_t takes a long (implicit cast from above)
589 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
590 * can optionally convert the [unsigned] long from above into
591 * an [unsigned] long long.
592 */
593
594#if BITS_PER_LONG == 32
90c699a9 595# if defined(CONFIG_LBDAF)
1da177e4
LT
596 ASSERT(sizeof(sector_t) == 8);
597 pagefactor = PAGE_CACHE_SIZE;
598 bitshift = BITS_PER_LONG;
599# else
600 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
601# endif
602#endif
603
604 return (((__uint64_t)pagefactor) << bitshift) - 1;
605}
606
2d2194f6
CM
607xfs_agnumber_t
608xfs_set_inode32(struct xfs_mount *mp)
609{
610 xfs_agnumber_t index = 0;
4056c1d0 611 xfs_agnumber_t maxagi = 0;
2d2194f6
CM
612 xfs_sb_t *sbp = &mp->m_sb;
613 xfs_agnumber_t max_metadata;
614 xfs_agino_t agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks -1, 0);
615 xfs_ino_t ino = XFS_AGINO_TO_INO(mp, sbp->sb_agcount -1, agino);
616 xfs_perag_t *pag;
617
618 /* Calculate how much should be reserved for inodes to meet
619 * the max inode percentage.
620 */
621 if (mp->m_maxicount) {
622 __uint64_t icount;
623
624 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
625 do_div(icount, 100);
626 icount += sbp->sb_agblocks - 1;
627 do_div(icount, sbp->sb_agblocks);
628 max_metadata = icount;
629 } else {
630 max_metadata = sbp->sb_agcount;
631 }
632
633 for (index = 0; index < sbp->sb_agcount; index++) {
634 ino = XFS_AGINO_TO_INO(mp, index, agino);
4056c1d0 635
2d2194f6 636 if (ino > XFS_MAXINUMBER_32) {
4056c1d0
CM
637 pag = xfs_perag_get(mp, index);
638 pag->pagi_inodeok = 0;
639 pag->pagf_metadata = 0;
640 xfs_perag_put(pag);
641 continue;
2d2194f6
CM
642 }
643
644 pag = xfs_perag_get(mp, index);
645 pag->pagi_inodeok = 1;
4056c1d0 646 maxagi++;
2d2194f6
CM
647 if (index < max_metadata)
648 pag->pagf_metadata = 1;
649 xfs_perag_put(pag);
650 }
4056c1d0
CM
651 mp->m_flags |= (XFS_MOUNT_32BITINODES |
652 XFS_MOUNT_SMALL_INUMS);
653
654 return maxagi;
2d2194f6
CM
655}
656
657xfs_agnumber_t
658xfs_set_inode64(struct xfs_mount *mp)
659{
660 xfs_agnumber_t index = 0;
661
662 for (index = 0; index < mp->m_sb.sb_agcount; index++) {
663 struct xfs_perag *pag;
664
665 pag = xfs_perag_get(mp, index);
666 pag->pagi_inodeok = 1;
667 pag->pagf_metadata = 0;
668 xfs_perag_put(pag);
669 }
670
671 /* There is no need for lock protection on m_flags,
672 * the rw_semaphore of the VFS superblock is locked
673 * during mount/umount/remount operations, so this is
674 * enough to avoid concurency on the m_flags field
675 */
676 mp->m_flags &= ~(XFS_MOUNT_32BITINODES |
677 XFS_MOUNT_SMALL_INUMS);
678 return index;
679}
680
3180e66d 681STATIC int
1da177e4
LT
682xfs_blkdev_get(
683 xfs_mount_t *mp,
684 const char *name,
685 struct block_device **bdevp)
686{
687 int error = 0;
688
d4d77629
TH
689 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
690 mp);
1da177e4
LT
691 if (IS_ERR(*bdevp)) {
692 error = PTR_ERR(*bdevp);
4f10700a 693 xfs_warn(mp, "Invalid device [%s], error=%d\n", name, error);
1da177e4
LT
694 }
695
696 return -error;
697}
698
3180e66d 699STATIC void
1da177e4
LT
700xfs_blkdev_put(
701 struct block_device *bdev)
702{
703 if (bdev)
e525fd89 704 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1da177e4
LT
705}
706
f538d4da
CH
707void
708xfs_blkdev_issue_flush(
709 xfs_buftarg_t *buftarg)
710{
7582df51 711 blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
f538d4da 712}
1da177e4 713
19f354d4
CH
714STATIC void
715xfs_close_devices(
716 struct xfs_mount *mp)
717{
718 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
c032bfcf 719 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
b7963133 720 xfs_free_buftarg(mp, mp->m_logdev_targp);
c032bfcf 721 xfs_blkdev_put(logdev);
19f354d4
CH
722 }
723 if (mp->m_rtdev_targp) {
c032bfcf 724 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
b7963133 725 xfs_free_buftarg(mp, mp->m_rtdev_targp);
c032bfcf 726 xfs_blkdev_put(rtdev);
19f354d4 727 }
b7963133 728 xfs_free_buftarg(mp, mp->m_ddev_targp);
19f354d4
CH
729}
730
731/*
732 * The file system configurations are:
733 * (1) device (partition) with data and internal log
734 * (2) logical volume with data and log subvolumes.
735 * (3) logical volume with data, log, and realtime subvolumes.
736 *
737 * We only have to handle opening the log and realtime volumes here if
738 * they are present. The data subvolume has already been opened by
739 * get_sb_bdev() and is stored in sb->s_bdev.
740 */
741STATIC int
742xfs_open_devices(
9d565ffa 743 struct xfs_mount *mp)
19f354d4
CH
744{
745 struct block_device *ddev = mp->m_super->s_bdev;
746 struct block_device *logdev = NULL, *rtdev = NULL;
747 int error;
748
749 /*
750 * Open real time and log devices - order is important.
751 */
9d565ffa
CH
752 if (mp->m_logname) {
753 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
19f354d4
CH
754 if (error)
755 goto out;
756 }
757
9d565ffa
CH
758 if (mp->m_rtname) {
759 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
19f354d4
CH
760 if (error)
761 goto out_close_logdev;
762
763 if (rtdev == ddev || rtdev == logdev) {
4f10700a
DC
764 xfs_warn(mp,
765 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
19f354d4
CH
766 error = EINVAL;
767 goto out_close_rtdev;
768 }
769 }
770
771 /*
772 * Setup xfs_mount buffer target pointers
773 */
774 error = ENOMEM;
ebad861b 775 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, 0, mp->m_fsname);
19f354d4
CH
776 if (!mp->m_ddev_targp)
777 goto out_close_rtdev;
778
779 if (rtdev) {
ebad861b
DC
780 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, 1,
781 mp->m_fsname);
19f354d4
CH
782 if (!mp->m_rtdev_targp)
783 goto out_free_ddev_targ;
784 }
785
786 if (logdev && logdev != ddev) {
ebad861b
DC
787 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, 1,
788 mp->m_fsname);
19f354d4
CH
789 if (!mp->m_logdev_targp)
790 goto out_free_rtdev_targ;
791 } else {
792 mp->m_logdev_targp = mp->m_ddev_targp;
793 }
794
795 return 0;
796
797 out_free_rtdev_targ:
798 if (mp->m_rtdev_targp)
b7963133 799 xfs_free_buftarg(mp, mp->m_rtdev_targp);
19f354d4 800 out_free_ddev_targ:
b7963133 801 xfs_free_buftarg(mp, mp->m_ddev_targp);
19f354d4
CH
802 out_close_rtdev:
803 if (rtdev)
804 xfs_blkdev_put(rtdev);
805 out_close_logdev:
806 if (logdev && logdev != ddev)
807 xfs_blkdev_put(logdev);
808 out:
809 return error;
810}
811
e34b562c
CH
812/*
813 * Setup xfs_mount buffer target pointers based on superblock
814 */
815STATIC int
816xfs_setup_devices(
817 struct xfs_mount *mp)
818{
819 int error;
19f354d4 820
e34b562c
CH
821 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
822 mp->m_sb.sb_sectsize);
823 if (error)
824 return error;
825
826 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
827 unsigned int log_sector_size = BBSIZE;
828
829 if (xfs_sb_version_hassector(&mp->m_sb))
830 log_sector_size = mp->m_sb.sb_logsectsize;
831 error = xfs_setsize_buftarg(mp->m_logdev_targp,
832 mp->m_sb.sb_blocksize,
833 log_sector_size);
834 if (error)
835 return error;
836 }
837 if (mp->m_rtdev_targp) {
838 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
839 mp->m_sb.sb_blocksize,
840 mp->m_sb.sb_sectsize);
841 if (error)
842 return error;
843 }
844
845 return 0;
846}
19f354d4 847
aa6bf01d
CH
848STATIC int
849xfs_init_mount_workqueues(
850 struct xfs_mount *mp)
851{
852 mp->m_data_workqueue = alloc_workqueue("xfs-data/%s",
853 WQ_MEM_RECLAIM, 0, mp->m_fsname);
854 if (!mp->m_data_workqueue)
855 goto out;
856
857 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
858 WQ_MEM_RECLAIM, 0, mp->m_fsname);
859 if (!mp->m_unwritten_workqueue)
860 goto out_destroy_data_iodone_queue;
861
4c2d542f
DC
862 mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
863 WQ_MEM_RECLAIM, 0, mp->m_fsname);
864 if (!mp->m_cil_workqueue)
865 goto out_destroy_unwritten;
5889608d
DC
866
867 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
7a378c9a 868 0, 0, mp->m_fsname);
5889608d
DC
869 if (!mp->m_reclaim_workqueue)
870 goto out_destroy_cil;
871
872 mp->m_log_workqueue = alloc_workqueue("xfs-log/%s",
7a378c9a 873 0, 0, mp->m_fsname);
5889608d
DC
874 if (!mp->m_log_workqueue)
875 goto out_destroy_reclaim;
876
579b62fa 877 mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
7a378c9a 878 0, 0, mp->m_fsname);
579b62fa
BF
879 if (!mp->m_eofblocks_workqueue)
880 goto out_destroy_log;
881
aa6bf01d
CH
882 return 0;
883
579b62fa
BF
884out_destroy_log:
885 destroy_workqueue(mp->m_log_workqueue);
5889608d
DC
886out_destroy_reclaim:
887 destroy_workqueue(mp->m_reclaim_workqueue);
888out_destroy_cil:
889 destroy_workqueue(mp->m_cil_workqueue);
4c2d542f
DC
890out_destroy_unwritten:
891 destroy_workqueue(mp->m_unwritten_workqueue);
aa6bf01d
CH
892out_destroy_data_iodone_queue:
893 destroy_workqueue(mp->m_data_workqueue);
894out:
895 return -ENOMEM;
896}
897
898STATIC void
899xfs_destroy_mount_workqueues(
900 struct xfs_mount *mp)
901{
579b62fa 902 destroy_workqueue(mp->m_eofblocks_workqueue);
5889608d
DC
903 destroy_workqueue(mp->m_log_workqueue);
904 destroy_workqueue(mp->m_reclaim_workqueue);
4c2d542f 905 destroy_workqueue(mp->m_cil_workqueue);
aa6bf01d
CH
906 destroy_workqueue(mp->m_data_workqueue);
907 destroy_workqueue(mp->m_unwritten_workqueue);
908}
909
9aa05000
DC
910/*
911 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
912 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
913 * for IO to complete so that we effectively throttle multiple callers to the
914 * rate at which IO is completing.
915 */
916void
917xfs_flush_inodes(
918 struct xfs_mount *mp)
919{
920 struct super_block *sb = mp->m_super;
921
922 if (down_read_trylock(&sb->s_umount)) {
923 sync_inodes_sb(sb);
924 up_read(&sb->s_umount);
925 }
926}
927
bf904248 928/* Catch misguided souls that try to use this interface on XFS */
1da177e4 929STATIC struct inode *
a50cd269 930xfs_fs_alloc_inode(
1da177e4
LT
931 struct super_block *sb)
932{
bf904248 933 BUG();
493dca61 934 return NULL;
1da177e4
LT
935}
936
bf904248 937/*
99fa8cb3
DC
938 * Now that the generic code is guaranteed not to be accessing
939 * the linux inode, we can reclaim the inode.
bf904248 940 */
1da177e4 941STATIC void
a50cd269 942xfs_fs_destroy_inode(
848ce8f7 943 struct inode *inode)
1da177e4 944{
848ce8f7
CH
945 struct xfs_inode *ip = XFS_I(inode);
946
cca28fb8 947 trace_xfs_destroy_inode(ip);
99fa8cb3
DC
948
949 XFS_STATS_INC(vn_reclaim);
848ce8f7
CH
950
951 /* bad inode, get out here ASAP */
952 if (is_bad_inode(inode))
953 goto out_reclaim;
954
848ce8f7
CH
955 ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
956
957 /*
958 * We should never get here with one of the reclaim flags already set.
959 */
960 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
961 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
962
963 /*
57817c68
DC
964 * We always use background reclaim here because even if the
965 * inode is clean, it still may be under IO and hence we have
966 * to take the flush lock. The background reclaim path handles
967 * this more efficiently than we can here, so simply let background
968 * reclaim tear down all inodes.
848ce8f7 969 */
848ce8f7 970out_reclaim:
57817c68 971 xfs_inode_set_reclaim_tag(ip);
1da177e4
LT
972}
973
07c8f675
DC
974/*
975 * Slab object creation initialisation for the XFS inode.
976 * This covers only the idempotent fields in the XFS inode;
977 * all other fields need to be initialised on allocation
b595076a 978 * from the slab. This avoids the need to repeatedly initialise
07c8f675
DC
979 * fields in the xfs inode that left in the initialise state
980 * when freeing the inode.
981 */
bf904248
DC
982STATIC void
983xfs_fs_inode_init_once(
07c8f675
DC
984 void *inode)
985{
986 struct xfs_inode *ip = inode;
987
988 memset(ip, 0, sizeof(struct xfs_inode));
bf904248
DC
989
990 /* vfs inode */
991 inode_init_once(VFS_I(ip));
992
993 /* xfs inode */
07c8f675
DC
994 atomic_set(&ip->i_pincount, 0);
995 spin_lock_init(&ip->i_flags_lock);
07c8f675
DC
996
997 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
998 "xfsino", ip->i_ino);
07c8f675
DC
999}
1000
1da177e4 1001STATIC void
b57922d9 1002xfs_fs_evict_inode(
1da177e4
LT
1003 struct inode *inode)
1004{
1543d79c 1005 xfs_inode_t *ip = XFS_I(inode);
56d433e4 1006
4f59af75
CH
1007 ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
1008
b57922d9 1009 trace_xfs_evict_inode(ip);
cca28fb8 1010
b57922d9 1011 truncate_inode_pages(&inode->i_data, 0);
dbd5768f 1012 clear_inode(inode);
99fa8cb3
DC
1013 XFS_STATS_INC(vn_rele);
1014 XFS_STATS_INC(vn_remove);
1015 XFS_STATS_DEC(vn_active);
1016
1017 xfs_inactive(ip);
56d433e4 1018}
1da177e4 1019
5132ba8f
DC
1020/*
1021 * We do an unlocked check for XFS_IDONTCACHE here because we are already
1022 * serialised against cache hits here via the inode->i_lock and igrab() in
1023 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
1024 * racing with us, and it avoids needing to grab a spinlock here for every inode
1025 * we drop the final reference on.
1026 */
1027STATIC int
1028xfs_fs_drop_inode(
1029 struct inode *inode)
1030{
1031 struct xfs_inode *ip = XFS_I(inode);
1032
1033 return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
1034}
1035
a738159d
CH
1036STATIC void
1037xfs_free_fsname(
1038 struct xfs_mount *mp)
1039{
1040 kfree(mp->m_fsname);
1041 kfree(mp->m_rtname);
1042 kfree(mp->m_logname);
1043}
1044
1da177e4 1045STATIC void
a50cd269 1046xfs_fs_put_super(
1da177e4
LT
1047 struct super_block *sb)
1048{
745f6919 1049 struct xfs_mount *mp = XFS_M(sb);
1da177e4 1050
7e18530b
DC
1051 xfs_filestream_unmount(mp);
1052 xfs_unmountfs(mp);
1053
6203300e 1054 xfs_freesb(mp);
c962fb79 1055 xfs_icsb_destroy_counters(mp);
aa6bf01d 1056 xfs_destroy_mount_workqueues(mp);
19f354d4 1057 xfs_close_devices(mp);
a738159d 1058 xfs_free_fsname(mp);
c962fb79 1059 kfree(mp);
1da177e4
LT
1060}
1061
1da177e4 1062STATIC int
69961a26 1063xfs_fs_sync_fs(
1da177e4
LT
1064 struct super_block *sb,
1065 int wait)
1066{
745f6919 1067 struct xfs_mount *mp = XFS_M(sb);
1da177e4 1068
e893bffd 1069 /*
34625c66 1070 * Doing anything during the async pass would be counterproductive.
e893bffd 1071 */
34625c66 1072 if (!wait)
69961a26 1073 return 0;
69961a26 1074
34061f5c 1075 xfs_log_force(mp, XFS_LOG_SYNC);
69961a26 1076 if (laptop_mode) {
1da177e4
LT
1077 /*
1078 * The disk must be active because we're syncing.
f661f1e0 1079 * We schedule log work now (now that the disk is
1da177e4
LT
1080 * active) instead of later (when it might not be).
1081 */
f661f1e0 1082 flush_delayed_work(&mp->m_log->l_work);
1da177e4
LT
1083 }
1084
69961a26 1085 return 0;
1da177e4
LT
1086}
1087
1088STATIC int
a50cd269 1089xfs_fs_statfs(
726c3342 1090 struct dentry *dentry,
1da177e4
LT
1091 struct kstatfs *statp)
1092{
4ca488eb
CH
1093 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1094 xfs_sb_t *sbp = &mp->m_sb;
7d095257 1095 struct xfs_inode *ip = XFS_I(dentry->d_inode);
4ca488eb
CH
1096 __uint64_t fakeinos, id;
1097 xfs_extlen_t lsize;
2fe33661 1098 __int64_t ffree;
4ca488eb
CH
1099
1100 statp->f_type = XFS_SB_MAGIC;
1101 statp->f_namelen = MAXNAMELEN - 1;
1102
1103 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1104 statp->f_fsid.val[0] = (u32)id;
1105 statp->f_fsid.val[1] = (u32)(id >> 32);
1106
d4d90b57 1107 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
4ca488eb
CH
1108
1109 spin_lock(&mp->m_sb_lock);
1110 statp->f_bsize = sbp->sb_blocksize;
1111 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1112 statp->f_blocks = sbp->sb_dblocks - lsize;
1113 statp->f_bfree = statp->f_bavail =
1114 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1115 fakeinos = statp->f_bfree << sbp->sb_inopblog;
4ca488eb
CH
1116 statp->f_files =
1117 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1118 if (mp->m_maxicount)
a19d9f88
CH
1119 statp->f_files = min_t(typeof(statp->f_files),
1120 statp->f_files,
1121 mp->m_maxicount);
2fe33661
SB
1122
1123 /* make sure statp->f_ffree does not underflow */
1124 ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1125 statp->f_ffree = max_t(__int64_t, ffree, 0);
1126
4ca488eb
CH
1127 spin_unlock(&mp->m_sb_lock);
1128
da5bf95e 1129 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
83e782e1
CS
1130 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
1131 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
7d095257 1132 xfs_qm_statvfs(ip, statp);
4ca488eb 1133 return 0;
1da177e4
LT
1134}
1135
d5db0f97
ES
1136STATIC void
1137xfs_save_resvblks(struct xfs_mount *mp)
1138{
1139 __uint64_t resblks = 0;
1140
1141 mp->m_resblks_save = mp->m_resblks;
1142 xfs_reserve_blocks(mp, &resblks, NULL);
1143}
1144
1145STATIC void
1146xfs_restore_resvblks(struct xfs_mount *mp)
1147{
1148 __uint64_t resblks;
1149
1150 if (mp->m_resblks_save) {
1151 resblks = mp->m_resblks_save;
1152 mp->m_resblks_save = 0;
1153 } else
1154 resblks = xfs_default_resblks(mp);
1155
1156 xfs_reserve_blocks(mp, &resblks, NULL);
1157}
1158
c7eea6f7
DC
1159/*
1160 * Trigger writeback of all the dirty metadata in the file system.
1161 *
1162 * This ensures that the metadata is written to their location on disk rather
1163 * than just existing in transactions in the log. This means after a quiesce
c75921a7
DC
1164 * there is no log replay required to write the inodes to disk - this is the
1165 * primary difference between a sync and a quiesce.
c7eea6f7 1166 *
c75921a7
DC
1167 * Note: xfs_log_quiesce() stops background log work - the callers must ensure
1168 * it is started again when appropriate.
c7eea6f7
DC
1169 */
1170void
1171xfs_quiesce_attr(
1172 struct xfs_mount *mp)
1173{
1174 int error = 0;
1175
1176 /* wait for all modifications to complete */
1177 while (atomic_read(&mp->m_active_trans) > 0)
1178 delay(100);
1179
1180 /* force the log to unpin objects from the now complete transactions */
1181 xfs_log_force(mp, XFS_LOG_SYNC);
1182
1183 /* reclaim inodes to do any IO before the freeze completes */
1184 xfs_reclaim_inodes(mp, 0);
1185 xfs_reclaim_inodes(mp, SYNC_WAIT);
1186
c7eea6f7
DC
1187 /* Push the superblock and write an unmount record */
1188 error = xfs_log_sbcount(mp);
1189 if (error)
1190 xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
1191 "Frozen image may not be consistent.");
c7eea6f7 1192 /*
c75921a7
DC
1193 * Just warn here till VFS can correctly support
1194 * read-only remount without racing.
c7eea6f7 1195 */
c75921a7 1196 WARN_ON(atomic_read(&mp->m_active_trans) != 0);
c7eea6f7 1197
c75921a7 1198 xfs_log_quiesce(mp);
c7eea6f7
DC
1199}
1200
1da177e4 1201STATIC int
a50cd269 1202xfs_fs_remount(
1da177e4
LT
1203 struct super_block *sb,
1204 int *flags,
1205 char *options)
1206{
745f6919 1207 struct xfs_mount *mp = XFS_M(sb);
62a877e3
CH
1208 substring_t args[MAX_OPT_ARGS];
1209 char *p;
7884bc86 1210 int error;
1da177e4 1211
62a877e3
CH
1212 while ((p = strsep(&options, ",")) != NULL) {
1213 int token;
bdd907ba 1214
62a877e3
CH
1215 if (!*p)
1216 continue;
48b62a1a 1217
62a877e3
CH
1218 token = match_token(p, tokens, args);
1219 switch (token) {
1220 case Opt_barrier:
48b62a1a 1221 mp->m_flags |= XFS_MOUNT_BARRIER;
62a877e3
CH
1222 break;
1223 case Opt_nobarrier:
48b62a1a 1224 mp->m_flags &= ~XFS_MOUNT_BARRIER;
62a877e3 1225 break;
c3a58fec 1226 case Opt_inode64:
4c083722 1227 mp->m_maxagi = xfs_set_inode64(mp);
c3a58fec 1228 break;
2ea03929
CM
1229 case Opt_inode32:
1230 mp->m_maxagi = xfs_set_inode32(mp);
1231 break;
62a877e3 1232 default:
6efdf281
CH
1233 /*
1234 * Logically we would return an error here to prevent
1235 * users from believing they might have changed
1236 * mount options using remount which can't be changed.
1237 *
1238 * But unfortunately mount(8) adds all options from
1239 * mtab and fstab to the mount arguments in some cases
1240 * so we can't blindly reject options, but have to
1241 * check for each specified option if it actually
1242 * differs from the currently set option and only
1243 * reject it if that's the case.
1244 *
1245 * Until that is implemented we return success for
1246 * every remount request, and silently ignore all
1247 * options that we can't actually change.
1248 */
1249#if 0
4f10700a
DC
1250 xfs_info(mp,
1251 "mount option \"%s\" not supported for remount\n", p);
62a877e3 1252 return -EINVAL;
6efdf281 1253#else
6c5e51da 1254 break;
6efdf281 1255#endif
48b62a1a 1256 }
62a877e3
CH
1257 }
1258
7884bc86 1259 /* ro -> rw */
62a877e3
CH
1260 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1261 mp->m_flags &= ~XFS_MOUNT_RDONLY;
7884bc86
CH
1262
1263 /*
1264 * If this is the first remount to writeable state we
1265 * might have some superblock changes to update.
1266 */
1267 if (mp->m_update_flags) {
1268 error = xfs_mount_log_sb(mp, mp->m_update_flags);
1269 if (error) {
4f10700a 1270 xfs_warn(mp, "failed to write sb changes");
7884bc86
CH
1271 return error;
1272 }
1273 mp->m_update_flags = 0;
1274 }
cbe132a8
DC
1275
1276 /*
1277 * Fill out the reserve pool if it is empty. Use the stashed
1278 * value if it is non-zero, otherwise go with the default.
1279 */
d5db0f97 1280 xfs_restore_resvblks(mp);
f661f1e0 1281 xfs_log_work_queue(mp);
62a877e3
CH
1282 }
1283
1284 /* rw -> ro */
1285 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
cbe132a8 1286 /*
34061f5c
DC
1287 * Before we sync the metadata, we need to free up the reserve
1288 * block pool so that the used block count in the superblock on
1289 * disk is correct at the end of the remount. Stash the current
1290 * reserve pool size so that if we get remounted rw, we can
1291 * return it to the same size.
cbe132a8 1292 */
d5db0f97 1293 xfs_save_resvblks(mp);
76bf105c 1294 xfs_quiesce_attr(mp);
48b62a1a
CH
1295 mp->m_flags |= XFS_MOUNT_RDONLY;
1296 }
1297
62a877e3 1298 return 0;
1da177e4
LT
1299}
1300
9909c4aa
CH
1301/*
1302 * Second stage of a freeze. The data is already frozen so we only
76bf105c 1303 * need to take care of the metadata. Once that's done write a dummy
9909c4aa
CH
1304 * record to dirty the log in case of a crash while frozen.
1305 */
c4be0c1d
TS
1306STATIC int
1307xfs_fs_freeze(
1da177e4
LT
1308 struct super_block *sb)
1309{
9909c4aa
CH
1310 struct xfs_mount *mp = XFS_M(sb);
1311
d5db0f97 1312 xfs_save_resvblks(mp);
76bf105c 1313 xfs_quiesce_attr(mp);
c58efdb4 1314 return -xfs_fs_log_dummy(mp);
1da177e4
LT
1315}
1316
d5db0f97
ES
1317STATIC int
1318xfs_fs_unfreeze(
1319 struct super_block *sb)
1320{
1321 struct xfs_mount *mp = XFS_M(sb);
1322
1323 xfs_restore_resvblks(mp);
f661f1e0 1324 xfs_log_work_queue(mp);
d5db0f97
ES
1325 return 0;
1326}
1327
1da177e4 1328STATIC int
a50cd269 1329xfs_fs_show_options(
1da177e4 1330 struct seq_file *m,
34c80b1d 1331 struct dentry *root)
1da177e4 1332{
34c80b1d 1333 return -xfs_showargs(XFS_M(root->d_sb), m);
1da177e4
LT
1334}
1335
f8f15e42
CH
1336/*
1337 * This function fills in xfs_mount_t fields based on mount args.
1338 * Note: the superblock _has_ now been read in.
1339 */
1340STATIC int
1341xfs_finish_flags(
f8f15e42
CH
1342 struct xfs_mount *mp)
1343{
1344 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1345
025dfdaf 1346 /* Fail a mount where the logbuf is smaller than the log stripe */
f8f15e42 1347 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
9d565ffa
CH
1348 if (mp->m_logbsize <= 0 &&
1349 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
f8f15e42 1350 mp->m_logbsize = mp->m_sb.sb_logsunit;
9d565ffa
CH
1351 } else if (mp->m_logbsize > 0 &&
1352 mp->m_logbsize < mp->m_sb.sb_logsunit) {
4f10700a
DC
1353 xfs_warn(mp,
1354 "logbuf size must be greater than or equal to log stripe size");
f8f15e42
CH
1355 return XFS_ERROR(EINVAL);
1356 }
1357 } else {
1358 /* Fail a mount if the logbuf is larger than 32K */
9d565ffa 1359 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
4f10700a
DC
1360 xfs_warn(mp,
1361 "logbuf size for version 1 logs must be 16K or 32K");
f8f15e42
CH
1362 return XFS_ERROR(EINVAL);
1363 }
1364 }
1365
d3eaace8
DC
1366 /*
1367 * V5 filesystems always use attr2 format for attributes.
1368 */
1369 if (xfs_sb_version_hascrc(&mp->m_sb) &&
1370 (mp->m_flags & XFS_MOUNT_NOATTR2)) {
1371 xfs_warn(mp,
1372"Cannot mount a V5 filesystem as %s. %s is always enabled for V5 filesystems.",
1373 MNTOPT_NOATTR2, MNTOPT_ATTR2);
1374 return XFS_ERROR(EINVAL);
1375 }
1376
f8f15e42
CH
1377 /*
1378 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1379 * told by noattr2 to turn it off
1380 */
1381 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
9d565ffa 1382 !(mp->m_flags & XFS_MOUNT_NOATTR2))
f8f15e42
CH
1383 mp->m_flags |= XFS_MOUNT_ATTR2;
1384
1385 /*
1386 * prohibit r/w mounts of read-only filesystems
1387 */
1388 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
4f10700a
DC
1389 xfs_warn(mp,
1390 "cannot mount a read-only filesystem as read-write");
f8f15e42
CH
1391 return XFS_ERROR(EROFS);
1392 }
1393
d892d586
CS
1394 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
1395 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
1396 !xfs_sb_version_has_pquotino(&mp->m_sb)) {
1397 xfs_warn(mp,
1398 "Super block does not support project and group quota together");
1399 return XFS_ERROR(EINVAL);
1400 }
1401
f8f15e42
CH
1402 return 0;
1403}
1404
1da177e4 1405STATIC int
a50cd269 1406xfs_fs_fill_super(
1da177e4
LT
1407 struct super_block *sb,
1408 void *data,
1409 int silent)
1410{
f3dcc13f 1411 struct inode *root;
745f6919 1412 struct xfs_mount *mp = NULL;
c962fb79 1413 int flags = 0, error = ENOMEM;
bdd907ba 1414
c962fb79
CH
1415 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1416 if (!mp)
9d565ffa 1417 goto out;
1da177e4 1418
c962fb79 1419 spin_lock_init(&mp->m_sb_lock);
c962fb79
CH
1420 mutex_init(&mp->m_growlock);
1421 atomic_set(&mp->m_active_trans, 0);
7e18530b 1422 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
579b62fa 1423 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
74394496 1424
b267ce99
CH
1425 mp->m_super = sb;
1426 sb->s_fs_info = mp;
1da177e4 1427
288699fe 1428 error = xfs_parseargs(mp, (char *)data);
745f6919 1429 if (error)
9d565ffa 1430 goto out_free_fsname;
1da177e4
LT
1431
1432 sb_min_blocksize(sb, BBSIZE);
0ec58516 1433 sb->s_xattr = xfs_xattr_handlers;
a50cd269 1434 sb->s_export_op = &xfs_export_operations;
fcafb71b 1435#ifdef CONFIG_XFS_QUOTA
a50cd269 1436 sb->s_qcop = &xfs_quotactl_operations;
fcafb71b 1437#endif
a50cd269 1438 sb->s_op = &xfs_super_operations;
1da177e4 1439
9d565ffa 1440 if (silent)
f8f15e42
CH
1441 flags |= XFS_MFSI_QUIET;
1442
9d565ffa 1443 error = xfs_open_devices(mp);
19f354d4 1444 if (error)
288699fe 1445 goto out_free_fsname;
f8f15e42 1446
aa6bf01d 1447 error = xfs_init_mount_workqueues(mp);
61ba35de
CH
1448 if (error)
1449 goto out_close_devices;
c962fb79 1450
aa6bf01d
CH
1451 error = xfs_icsb_init_counters(mp);
1452 if (error)
1453 goto out_destroy_workqueues;
1454
f8f15e42
CH
1455 error = xfs_readsb(mp, flags);
1456 if (error)
9d565ffa
CH
1457 goto out_destroy_counters;
1458
1459 error = xfs_finish_flags(mp);
f8f15e42 1460 if (error)
effa2eda 1461 goto out_free_sb;
f8f15e42 1462
e34b562c 1463 error = xfs_setup_devices(mp);
19f354d4 1464 if (error)
effa2eda 1465 goto out_free_sb;
f8f15e42 1466
f8f15e42
CH
1467 error = xfs_filestream_mount(mp);
1468 if (error)
effa2eda 1469 goto out_free_sb;
f8f15e42 1470
704b2907
DC
1471 /*
1472 * we must configure the block size in the superblock before we run the
1473 * full mount process as the mount process can lookup and cache inodes.
704b2907 1474 */
4ca488eb
CH
1475 sb->s_magic = XFS_SB_MAGIC;
1476 sb->s_blocksize = mp->m_sb.sb_blocksize;
1477 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1da177e4 1478 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
8de52778 1479 sb->s_max_links = XFS_MAXLINK;
1da177e4
LT
1480 sb->s_time_gran = 1;
1481 set_posix_acl_flag(sb);
1482
dc037ad7
DC
1483 /* version 5 superblocks support inode version counters. */
1484 if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
1485 sb->s_flags |= MS_I_VERSION;
1486
8a00ebe4 1487 error = xfs_mountfs(mp);
2bcf6e97 1488 if (error)
7e18530b 1489 goto out_filestream_unmount;
704b2907 1490
01651646 1491 root = igrab(VFS_I(mp->m_rootip));
f3dcc13f 1492 if (!root) {
cbc89dcf 1493 error = ENOENT;
8a00ebe4 1494 goto out_unmount;
cbc89dcf 1495 }
f3dcc13f
CH
1496 if (is_bad_inode(root)) {
1497 error = EINVAL;
8a00ebe4 1498 goto out_unmount;
1da177e4 1499 }
48fde701 1500 sb->s_root = d_make_root(root);
f3dcc13f
CH
1501 if (!sb->s_root) {
1502 error = ENOMEM;
8a00ebe4 1503 goto out_unmount;
1da177e4 1504 }
74394496 1505
1da177e4 1506 return 0;
33c7a2bc 1507
7e18530b 1508 out_filestream_unmount:
120226c1 1509 xfs_filestream_unmount(mp);
effa2eda
CH
1510 out_free_sb:
1511 xfs_freesb(mp);
9d565ffa 1512 out_destroy_counters:
c962fb79 1513 xfs_icsb_destroy_counters(mp);
aa6bf01d
CH
1514out_destroy_workqueues:
1515 xfs_destroy_mount_workqueues(mp);
61ba35de 1516 out_close_devices:
19f354d4 1517 xfs_close_devices(mp);
9d565ffa
CH
1518 out_free_fsname:
1519 xfs_free_fsname(mp);
c962fb79 1520 kfree(mp);
9d565ffa 1521 out:
c962fb79 1522 return -error;
f8f15e42 1523
2bcf6e97 1524 out_unmount:
e48ad316 1525 xfs_filestream_unmount(mp);
19f354d4 1526 xfs_unmountfs(mp);
6203300e 1527 goto out_free_sb;
1da177e4
LT
1528}
1529
152a0836
AV
1530STATIC struct dentry *
1531xfs_fs_mount(
1da177e4
LT
1532 struct file_system_type *fs_type,
1533 int flags,
1534 const char *dev_name,
152a0836 1535 void *data)
1da177e4 1536{
152a0836 1537 return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
a50cd269
NS
1538}
1539
8daaa831
DC
1540static int
1541xfs_fs_nr_cached_objects(
1542 struct super_block *sb)
1543{
1544 return xfs_reclaim_inodes_count(XFS_M(sb));
1545}
1546
1547static void
1548xfs_fs_free_cached_objects(
1549 struct super_block *sb,
1550 int nr_to_scan)
1551{
1552 xfs_reclaim_inodes_nr(XFS_M(sb), nr_to_scan);
1553}
1554
b87221de 1555static const struct super_operations xfs_super_operations = {
a50cd269
NS
1556 .alloc_inode = xfs_fs_alloc_inode,
1557 .destroy_inode = xfs_fs_destroy_inode,
b57922d9 1558 .evict_inode = xfs_fs_evict_inode,
5132ba8f 1559 .drop_inode = xfs_fs_drop_inode,
a50cd269 1560 .put_super = xfs_fs_put_super,
69961a26 1561 .sync_fs = xfs_fs_sync_fs,
c4be0c1d 1562 .freeze_fs = xfs_fs_freeze,
d5db0f97 1563 .unfreeze_fs = xfs_fs_unfreeze,
a50cd269
NS
1564 .statfs = xfs_fs_statfs,
1565 .remount_fs = xfs_fs_remount,
1566 .show_options = xfs_fs_show_options,
8daaa831
DC
1567 .nr_cached_objects = xfs_fs_nr_cached_objects,
1568 .free_cached_objects = xfs_fs_free_cached_objects,
1da177e4
LT
1569};
1570
5085b607 1571static struct file_system_type xfs_fs_type = {
1da177e4
LT
1572 .owner = THIS_MODULE,
1573 .name = "xfs",
152a0836 1574 .mount = xfs_fs_mount,
1da177e4
LT
1575 .kill_sb = kill_block_super,
1576 .fs_flags = FS_REQUIRES_DEV,
1577};
7f78e035 1578MODULE_ALIAS_FS("xfs");
1da177e4 1579
9f8868ff
CH
1580STATIC int __init
1581xfs_init_zones(void)
1582{
9f8868ff
CH
1583
1584 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1585 if (!xfs_ioend_zone)
bf904248 1586 goto out;
9f8868ff
CH
1587
1588 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1589 xfs_ioend_zone);
1590 if (!xfs_ioend_pool)
1591 goto out_destroy_ioend_zone;
1592
1593 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1594 "xfs_log_ticket");
1595 if (!xfs_log_ticket_zone)
1596 goto out_destroy_ioend_pool;
1597
1598 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1599 "xfs_bmap_free_item");
1600 if (!xfs_bmap_free_item_zone)
1601 goto out_destroy_log_ticket_zone;
bf904248 1602
9f8868ff
CH
1603 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1604 "xfs_btree_cur");
1605 if (!xfs_btree_cur_zone)
1606 goto out_destroy_bmap_free_item_zone;
1607
1608 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1609 "xfs_da_state");
1610 if (!xfs_da_state_zone)
1611 goto out_destroy_btree_cur_zone;
1612
9f8868ff
CH
1613 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1614 if (!xfs_ifork_zone)
1d9025e5 1615 goto out_destroy_da_state_zone;
9f8868ff
CH
1616
1617 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1618 if (!xfs_trans_zone)
1619 goto out_destroy_ifork_zone;
1620
e98c414f
CH
1621 xfs_log_item_desc_zone =
1622 kmem_zone_init(sizeof(struct xfs_log_item_desc),
1623 "xfs_log_item_desc");
1624 if (!xfs_log_item_desc_zone)
1625 goto out_destroy_trans_zone;
1626
9f8868ff
CH
1627 /*
1628 * The size of the zone allocated buf log item is the maximum
1629 * size possible under XFS. This wastes a little bit of memory,
1630 * but it is much faster.
1631 */
77c1a08f
DC
1632 xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
1633 "xfs_buf_item");
9f8868ff 1634 if (!xfs_buf_item_zone)
e98c414f 1635 goto out_destroy_log_item_desc_zone;
9f8868ff
CH
1636
1637 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1638 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1639 sizeof(xfs_extent_t))), "xfs_efd_item");
1640 if (!xfs_efd_zone)
1641 goto out_destroy_buf_item_zone;
1642
1643 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1644 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1645 sizeof(xfs_extent_t))), "xfs_efi_item");
1646 if (!xfs_efi_zone)
1647 goto out_destroy_efd_zone;
1648
1649 xfs_inode_zone =
1650 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
bf904248
DC
1651 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
1652 xfs_fs_inode_init_once);
9f8868ff
CH
1653 if (!xfs_inode_zone)
1654 goto out_destroy_efi_zone;
1655
1656 xfs_ili_zone =
1657 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1658 KM_ZONE_SPREAD, NULL);
1659 if (!xfs_ili_zone)
1660 goto out_destroy_inode_zone;
3ebe7d2d
DC
1661 xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
1662 "xfs_icr");
1663 if (!xfs_icreate_zone)
1664 goto out_destroy_ili_zone;
9f8868ff 1665
9f8868ff
CH
1666 return 0;
1667
3ebe7d2d
DC
1668 out_destroy_ili_zone:
1669 kmem_zone_destroy(xfs_ili_zone);
9f8868ff
CH
1670 out_destroy_inode_zone:
1671 kmem_zone_destroy(xfs_inode_zone);
1672 out_destroy_efi_zone:
1673 kmem_zone_destroy(xfs_efi_zone);
1674 out_destroy_efd_zone:
1675 kmem_zone_destroy(xfs_efd_zone);
1676 out_destroy_buf_item_zone:
1677 kmem_zone_destroy(xfs_buf_item_zone);
e98c414f
CH
1678 out_destroy_log_item_desc_zone:
1679 kmem_zone_destroy(xfs_log_item_desc_zone);
9f8868ff
CH
1680 out_destroy_trans_zone:
1681 kmem_zone_destroy(xfs_trans_zone);
1682 out_destroy_ifork_zone:
1683 kmem_zone_destroy(xfs_ifork_zone);
9f8868ff
CH
1684 out_destroy_da_state_zone:
1685 kmem_zone_destroy(xfs_da_state_zone);
1686 out_destroy_btree_cur_zone:
1687 kmem_zone_destroy(xfs_btree_cur_zone);
1688 out_destroy_bmap_free_item_zone:
1689 kmem_zone_destroy(xfs_bmap_free_item_zone);
1690 out_destroy_log_ticket_zone:
1691 kmem_zone_destroy(xfs_log_ticket_zone);
1692 out_destroy_ioend_pool:
1693 mempool_destroy(xfs_ioend_pool);
1694 out_destroy_ioend_zone:
1695 kmem_zone_destroy(xfs_ioend_zone);
9f8868ff
CH
1696 out:
1697 return -ENOMEM;
1698}
1699
1700STATIC void
1701xfs_destroy_zones(void)
1702{
8c0a8537
KS
1703 /*
1704 * Make sure all delayed rcu free are flushed before we
1705 * destroy caches.
1706 */
1707 rcu_barrier();
3ebe7d2d 1708 kmem_zone_destroy(xfs_icreate_zone);
9f8868ff
CH
1709 kmem_zone_destroy(xfs_ili_zone);
1710 kmem_zone_destroy(xfs_inode_zone);
1711 kmem_zone_destroy(xfs_efi_zone);
1712 kmem_zone_destroy(xfs_efd_zone);
1713 kmem_zone_destroy(xfs_buf_item_zone);
e98c414f 1714 kmem_zone_destroy(xfs_log_item_desc_zone);
9f8868ff
CH
1715 kmem_zone_destroy(xfs_trans_zone);
1716 kmem_zone_destroy(xfs_ifork_zone);
9f8868ff
CH
1717 kmem_zone_destroy(xfs_da_state_zone);
1718 kmem_zone_destroy(xfs_btree_cur_zone);
1719 kmem_zone_destroy(xfs_bmap_free_item_zone);
1720 kmem_zone_destroy(xfs_log_ticket_zone);
1721 mempool_destroy(xfs_ioend_pool);
1722 kmem_zone_destroy(xfs_ioend_zone);
9f8868ff
CH
1723
1724}
1da177e4 1725
0bf6a5bd
DC
1726STATIC int __init
1727xfs_init_workqueues(void)
1728{
c999a223
DC
1729 /*
1730 * The allocation workqueue can be used in memory reclaim situations
1731 * (writepage path), and parallelism is only limited by the number of
1732 * AGs in all the filesystems mounted. Hence use the default large
1733 * max_active value for this workqueue.
1734 */
1735 xfs_alloc_wq = alloc_workqueue("xfsalloc", WQ_MEM_RECLAIM, 0);
1736 if (!xfs_alloc_wq)
5889608d 1737 return -ENOMEM;
c999a223 1738
0bf6a5bd 1739 return 0;
0bf6a5bd
DC
1740}
1741
39411f81 1742STATIC void
0bf6a5bd
DC
1743xfs_destroy_workqueues(void)
1744{
c999a223 1745 destroy_workqueue(xfs_alloc_wq);
0bf6a5bd
DC
1746}
1747
1da177e4 1748STATIC int __init
9f8868ff 1749init_xfs_fs(void)
1da177e4
LT
1750{
1751 int error;
1da177e4 1752
65795910
CH
1753 printk(KERN_INFO XFS_VERSION_STRING " with "
1754 XFS_BUILD_OPTIONS " enabled\n");
1da177e4 1755
9f8868ff 1756 xfs_dir_startup();
1da177e4 1757
8758280f 1758 error = xfs_init_zones();
9f8868ff
CH
1759 if (error)
1760 goto out;
1761
0bf6a5bd 1762 error = xfs_init_workqueues();
9f8868ff 1763 if (error)
0b1b213f 1764 goto out_destroy_zones;
9f8868ff 1765
0bf6a5bd
DC
1766 error = xfs_mru_cache_init();
1767 if (error)
1768 goto out_destroy_wq;
1769
9f8868ff
CH
1770 error = xfs_filestream_init();
1771 if (error)
1772 goto out_mru_cache_uninit;
1da177e4 1773
ce8e922c 1774 error = xfs_buf_init();
9f8868ff
CH
1775 if (error)
1776 goto out_filestream_uninit;
1777
1778 error = xfs_init_procfs();
1779 if (error)
1780 goto out_buf_terminate;
1781
1782 error = xfs_sysctl_register();
1783 if (error)
1784 goto out_cleanup_procfs;
1da177e4 1785
a05931ce
CH
1786 error = xfs_qm_init();
1787 if (error)
1788 goto out_sysctl_unregister;
1da177e4
LT
1789
1790 error = register_filesystem(&xfs_fs_type);
1791 if (error)
a05931ce 1792 goto out_qm_exit;
1da177e4
LT
1793 return 0;
1794
a05931ce
CH
1795 out_qm_exit:
1796 xfs_qm_exit();
9f8868ff
CH
1797 out_sysctl_unregister:
1798 xfs_sysctl_unregister();
1799 out_cleanup_procfs:
1800 xfs_cleanup_procfs();
1801 out_buf_terminate:
ce8e922c 1802 xfs_buf_terminate();
9f8868ff
CH
1803 out_filestream_uninit:
1804 xfs_filestream_uninit();
1805 out_mru_cache_uninit:
1806 xfs_mru_cache_uninit();
0bf6a5bd
DC
1807 out_destroy_wq:
1808 xfs_destroy_workqueues();
9f8868ff 1809 out_destroy_zones:
8758280f 1810 xfs_destroy_zones();
9f8868ff 1811 out:
1da177e4
LT
1812 return error;
1813}
1814
1815STATIC void __exit
9f8868ff 1816exit_xfs_fs(void)
1da177e4 1817{
a05931ce 1818 xfs_qm_exit();
1da177e4 1819 unregister_filesystem(&xfs_fs_type);
9f8868ff
CH
1820 xfs_sysctl_unregister();
1821 xfs_cleanup_procfs();
ce8e922c 1822 xfs_buf_terminate();
9f8868ff
CH
1823 xfs_filestream_uninit();
1824 xfs_mru_cache_uninit();
0bf6a5bd 1825 xfs_destroy_workqueues();
8758280f 1826 xfs_destroy_zones();
1da177e4
LT
1827}
1828
1829module_init(init_xfs_fs);
1830module_exit(exit_xfs_fs);
1831
1832MODULE_AUTHOR("Silicon Graphics, Inc.");
1833MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1834MODULE_LICENSE("GPL");