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