xfs_super.c 54.8 KB
Newer Older
D
Dave Chinner 已提交
1
// SPDX-License-Identifier: GPL-2.0
L
Linus Torvalds 已提交
2
/*
3
 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
4
 * All Rights Reserved.
L
Linus Torvalds 已提交
5
 */
C
Christoph Hellwig 已提交
6

L
Linus Torvalds 已提交
7
#include "xfs.h"
8
#include "xfs_shared.h"
9
#include "xfs_format.h"
10 11
#include "xfs_log_format.h"
#include "xfs_trans_resv.h"
L
Linus Torvalds 已提交
12 13 14
#include "xfs_sb.h"
#include "xfs_mount.h"
#include "xfs_inode.h"
15
#include "xfs_btree.h"
L
Linus Torvalds 已提交
16
#include "xfs_bmap.h"
17
#include "xfs_alloc.h"
C
Christoph Hellwig 已提交
18
#include "xfs_fsops.h"
19
#include "xfs_trans.h"
L
Linus Torvalds 已提交
20
#include "xfs_buf_item.h"
21
#include "xfs_log.h"
22
#include "xfs_log_priv.h"
23
#include "xfs_dir2.h"
24 25 26
#include "xfs_extfree_item.h"
#include "xfs_mru_cache.h"
#include "xfs_inode_item.h"
27
#include "xfs_icache.h"
C
Christoph Hellwig 已提交
28
#include "xfs_trace.h"
D
Dave Chinner 已提交
29
#include "xfs_icreate_item.h"
30 31
#include "xfs_filestream.h"
#include "xfs_quota.h"
32
#include "xfs_sysfs.h"
33
#include "xfs_ondisk.h"
34
#include "xfs_rmap_item.h"
35
#include "xfs_refcount_item.h"
36
#include "xfs_bmap_item.h"
37
#include "xfs_reflink.h"
L
Linus Torvalds 已提交
38

39
#include <linux/magic.h>
40
#include <linux/parser.h>
L
Linus Torvalds 已提交
41

42
static const struct super_operations xfs_super_operations;
43
struct bio_set xfs_ioend_bioset;
44

D
Dave Chinner 已提交
45
static struct kset *xfs_kset;		/* top-level xfs sysfs dir */
46 47 48
#ifdef DEBUG
static struct xfs_kobj xfs_dbg_kobj;	/* global debug sysfs attrs */
#endif
L
Linus Torvalds 已提交
49

50 51 52 53
/*
 * Table driven mount option parser.
 */
enum {
54 55
	Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev, Opt_biosize,
	Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
56
	Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
57 58 59 60
	Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
	Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
	Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
	Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
61 62
	Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
	Opt_discard, Opt_nodiscard, Opt_dax, Opt_err,
63 64
};

65
static const match_table_t tokens = {
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
	{Opt_logbufs,	"logbufs=%u"},	/* number of XFS log buffers */
	{Opt_logbsize,	"logbsize=%s"},	/* size of XFS log buffers */
	{Opt_logdev,	"logdev=%s"},	/* log device */
	{Opt_rtdev,	"rtdev=%s"},	/* realtime I/O device */
	{Opt_biosize,	"biosize=%u"},	/* log2 of preferred buffered io size */
	{Opt_wsync,	"wsync"},	/* safe-mode nfs compatible mount */
	{Opt_noalign,	"noalign"},	/* turn off stripe alignment */
	{Opt_swalloc,	"swalloc"},	/* turn on stripe width allocation */
	{Opt_sunit,	"sunit=%u"},	/* data volume stripe unit */
	{Opt_swidth,	"swidth=%u"},	/* data volume stripe width */
	{Opt_nouuid,	"nouuid"},	/* ignore filesystem UUID */
	{Opt_grpid,	"grpid"},	/* group-ID from parent directory */
	{Opt_nogrpid,	"nogrpid"},	/* group-ID from current process */
	{Opt_bsdgroups,	"bsdgroups"},	/* group-ID from parent directory */
	{Opt_sysvgroups,"sysvgroups"},	/* group-ID from current process */
	{Opt_allocsize,	"allocsize=%s"},/* preferred allocation size */
	{Opt_norecovery,"norecovery"},	/* don't run XFS recovery */
	{Opt_inode64,	"inode64"},	/* inodes can be allocated anywhere */
	{Opt_inode32,   "inode32"},	/* inode allocation limited to
					 * XFS_MAXINUMBER_32 */
	{Opt_ikeep,	"ikeep"},	/* do not free empty inode clusters */
	{Opt_noikeep,	"noikeep"},	/* free empty inode clusters */
	{Opt_largeio,	"largeio"},	/* report large I/O sizes in stat() */
	{Opt_nolargeio,	"nolargeio"},	/* do not report large I/O sizes
					 * in stat(). */
	{Opt_attr2,	"attr2"},	/* do use attr2 attribute format */
	{Opt_noattr2,	"noattr2"},	/* do not use attr2 attribute format */
	{Opt_filestreams,"filestreams"},/* use filestreams allocator */
	{Opt_quota,	"quota"},	/* disk quotas (user) */
	{Opt_noquota,	"noquota"},	/* no quotas */
	{Opt_usrquota,	"usrquota"},	/* user quota enabled */
	{Opt_grpquota,	"grpquota"},	/* group quota enabled */
	{Opt_prjquota,	"prjquota"},	/* project quota enabled */
	{Opt_uquota,	"uquota"},	/* user quota (IRIX variant) */
	{Opt_gquota,	"gquota"},	/* group quota (IRIX variant) */
	{Opt_pquota,	"pquota"},	/* project quota (IRIX variant) */
	{Opt_uqnoenforce,"uqnoenforce"},/* user quota limit enforcement */
	{Opt_gqnoenforce,"gqnoenforce"},/* group quota limit enforcement */
	{Opt_pqnoenforce,"pqnoenforce"},/* project quota limit enforcement */
	{Opt_qnoenforce, "qnoenforce"},	/* same as uqnoenforce */
	{Opt_discard,	"discard"},	/* Discard unused blocks */
	{Opt_nodiscard,	"nodiscard"},	/* Do not discard unused blocks */
	{Opt_dax,	"dax"},		/* Enable direct access to bdev pages */
	{Opt_err,	NULL},
110 111 112
};


113
STATIC int
114
suffix_kstrtoint(const substring_t *s, unsigned int base, int *res)
115
{
116
	int	last, shift_left_factor = 0, _res;
117 118 119 120 121 122
	char	*value;
	int	ret = 0;

	value = match_strdup(s);
	if (!value)
		return -ENOMEM;
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

	last = strlen(value) - 1;
	if (value[last] == 'K' || value[last] == 'k') {
		shift_left_factor = 10;
		value[last] = '\0';
	}
	if (value[last] == 'M' || value[last] == 'm') {
		shift_left_factor = 20;
		value[last] = '\0';
	}
	if (value[last] == 'G' || value[last] == 'g') {
		shift_left_factor = 30;
		value[last] = '\0';
	}

138 139 140
	if (kstrtoint(value, base, &_res))
		ret = -EINVAL;
	kfree(value);
141
	*res = _res << shift_left_factor;
142
	return ret;
143 144
}

145 146 147 148 149 150
/*
 * This function fills in xfs_mount_t fields based on mount args.
 * Note: the superblock has _not_ yet been read in.
 *
 * Note that this function leaks the various device name allocations on
 * failure.  The caller takes care of them.
E
Eric Sandeen 已提交
151 152 153 154
 *
 * *sb is const because this is also used to test options on the remount
 * path, and we don't want this to have any side effects at remount time.
 * Today this function does not change *sb, but just to future-proof...
155
 */
156 157 158
STATIC int
xfs_parseargs(
	struct xfs_mount	*mp,
C
Christoph Hellwig 已提交
159
	char			*options)
160
{
E
Eric Sandeen 已提交
161
	const struct super_block *sb = mp->m_super;
162 163
	char			*p;
	substring_t		args[MAX_OPT_ARGS];
164 165 166
	int			dsunit = 0;
	int			dswidth = 0;
	int			iosize = 0;
167
	uint8_t			iosizelog = 0;
168

169 170 171 172 173 174
	/*
	 * set up the mount name first so all the errors will refer to the
	 * correct device.
	 */
	mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
	if (!mp->m_fsname)
D
Dave Chinner 已提交
175
		return -ENOMEM;
176 177
	mp->m_fsname_len = strlen(mp->m_fsname) + 1;

178 179 180
	/*
	 * Copy binary VFS mount flags we are interested in.
	 */
181
	if (sb_rdonly(sb))
182
		mp->m_flags |= XFS_MOUNT_RDONLY;
183
	if (sb->s_flags & SB_DIRSYNC)
184
		mp->m_flags |= XFS_MOUNT_DIRSYNC;
185
	if (sb->s_flags & SB_SYNCHRONOUS)
186 187 188 189 190 191 192
		mp->m_flags |= XFS_MOUNT_WSYNC;

	/*
	 * Set some default flags that could be cleared by the mount option
	 * parsing.
	 */
	mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
193

194 195 196 197 198
	/*
	 * These can be overridden by the mount option parsing.
	 */
	mp->m_logbufs = -1;
	mp->m_logbsize = -1;
199 200 201 202

	if (!options)
		goto done;

203 204 205 206
	while ((p = strsep(&options, ",")) != NULL) {
		int		token;

		if (!*p)
207 208
			continue;

209 210 211 212
		token = match_token(p, tokens, args);
		switch (token) {
		case Opt_logbufs:
			if (match_int(args, &mp->m_logbufs))
D
Dave Chinner 已提交
213
				return -EINVAL;
214 215 216
			break;
		case Opt_logbsize:
			if (suffix_kstrtoint(args, 10, &mp->m_logbsize))
D
Dave Chinner 已提交
217
				return -EINVAL;
218 219
			break;
		case Opt_logdev:
220
			kfree(mp->m_logname);
221
			mp->m_logname = match_strdup(args);
222
			if (!mp->m_logname)
D
Dave Chinner 已提交
223
				return -ENOMEM;
224 225
			break;
		case Opt_rtdev:
226
			kfree(mp->m_rtname);
227
			mp->m_rtname = match_strdup(args);
228
			if (!mp->m_rtname)
D
Dave Chinner 已提交
229
				return -ENOMEM;
230 231 232 233
			break;
		case Opt_allocsize:
		case Opt_biosize:
			if (suffix_kstrtoint(args, 10, &iosize))
D
Dave Chinner 已提交
234
				return -EINVAL;
235
			iosizelog = ffs(iosize) - 1;
236 237 238
			break;
		case Opt_grpid:
		case Opt_bsdgroups:
239
			mp->m_flags |= XFS_MOUNT_GRPID;
240 241 242
			break;
		case Opt_nogrpid:
		case Opt_sysvgroups:
243
			mp->m_flags &= ~XFS_MOUNT_GRPID;
244 245
			break;
		case Opt_wsync:
246
			mp->m_flags |= XFS_MOUNT_WSYNC;
247 248
			break;
		case Opt_norecovery:
249
			mp->m_flags |= XFS_MOUNT_NORECOVERY;
250 251
			break;
		case Opt_noalign:
252
			mp->m_flags |= XFS_MOUNT_NOALIGN;
253 254
			break;
		case Opt_swalloc:
255
			mp->m_flags |= XFS_MOUNT_SWALLOC;
256 257 258
			break;
		case Opt_sunit:
			if (match_int(args, &dsunit))
D
Dave Chinner 已提交
259
				return -EINVAL;
260 261 262
			break;
		case Opt_swidth:
			if (match_int(args, &dswidth))
D
Dave Chinner 已提交
263
				return -EINVAL;
264 265
			break;
		case Opt_inode32:
266
			mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
267 268
			break;
		case Opt_inode64:
269
			mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
270 271
			break;
		case Opt_nouuid:
272
			mp->m_flags |= XFS_MOUNT_NOUUID;
273 274
			break;
		case Opt_ikeep:
275
			mp->m_flags |= XFS_MOUNT_IKEEP;
276 277
			break;
		case Opt_noikeep:
278
			mp->m_flags &= ~XFS_MOUNT_IKEEP;
279 280
			break;
		case Opt_largeio:
281
			mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
282 283
			break;
		case Opt_nolargeio:
284
			mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
285 286
			break;
		case Opt_attr2:
287
			mp->m_flags |= XFS_MOUNT_ATTR2;
288 289
			break;
		case Opt_noattr2:
290 291
			mp->m_flags &= ~XFS_MOUNT_ATTR2;
			mp->m_flags |= XFS_MOUNT_NOATTR2;
292 293
			break;
		case Opt_filestreams:
294
			mp->m_flags |= XFS_MOUNT_FILESTREAMS;
295 296
			break;
		case Opt_noquota:
297 298 299
			mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
			mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
			mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
300 301 302 303
			break;
		case Opt_quota:
		case Opt_uquota:
		case Opt_usrquota:
304 305
			mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
					 XFS_UQUOTA_ENFD);
306 307 308
			break;
		case Opt_qnoenforce:
		case Opt_uqnoenforce:
309 310
			mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
			mp->m_qflags &= ~XFS_UQUOTA_ENFD;
311 312 313
			break;
		case Opt_pquota:
		case Opt_prjquota:
314
			mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
315
					 XFS_PQUOTA_ENFD);
316 317
			break;
		case Opt_pqnoenforce:
318
			mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
319
			mp->m_qflags &= ~XFS_PQUOTA_ENFD;
320
			break;
321 322
		case Opt_gquota:
		case Opt_grpquota:
323
			mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
324
					 XFS_GQUOTA_ENFD);
325 326
			break;
		case Opt_gqnoenforce:
327
			mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
328
			mp->m_qflags &= ~XFS_GQUOTA_ENFD;
329 330
			break;
		case Opt_discard:
331
			mp->m_flags |= XFS_MOUNT_DISCARD;
332 333
			break;
		case Opt_nodiscard:
334
			mp->m_flags &= ~XFS_MOUNT_DISCARD;
335
			break;
D
Dave Chinner 已提交
336
#ifdef CONFIG_FS_DAX
337
		case Opt_dax:
D
Dave Chinner 已提交
338
			mp->m_flags |= XFS_MOUNT_DAX;
339
			break;
D
Dave Chinner 已提交
340
#endif
341 342
		default:
			xfs_warn(mp, "unknown mount option [%s].", p);
D
Dave Chinner 已提交
343
			return -EINVAL;
344 345 346
		}
	}

347 348 349 350 351
	/*
	 * no recovery flag requires a read-only mount
	 */
	if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
	    !(mp->m_flags & XFS_MOUNT_RDONLY)) {
352
		xfs_warn(mp, "no-recovery mounts must be read-only.");
D
Dave Chinner 已提交
353
		return -EINVAL;
354 355
	}

356
	if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
357 358
		xfs_warn(mp,
	"sunit and swidth options incompatible with the noalign option");
D
Dave Chinner 已提交
359
		return -EINVAL;
360 361
	}

C
Christoph Hellwig 已提交
362 363
#ifndef CONFIG_XFS_QUOTA
	if (XFS_IS_QUOTA_RUNNING(mp)) {
364
		xfs_warn(mp, "quota support not available in this kernel.");
D
Dave Chinner 已提交
365
		return -EINVAL;
C
Christoph Hellwig 已提交
366 367 368
	}
#endif

369
	if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
370
		xfs_warn(mp, "sunit and swidth must be specified together");
D
Dave Chinner 已提交
371
		return -EINVAL;
372 373 374
	}

	if (dsunit && (dswidth % dsunit != 0)) {
375 376
		xfs_warn(mp,
	"stripe width (%d) must be a multiple of the stripe unit (%d)",
377
			dswidth, dsunit);
D
Dave Chinner 已提交
378
		return -EINVAL;
379 380
	}

381
done:
J
Jie Liu 已提交
382
	if (dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) {
383 384 385 386 387 388
		/*
		 * At this point the superblock has not been read
		 * in, therefore we do not know the block size.
		 * Before the mount call ends we will convert
		 * these to FSBs.
		 */
J
Jie Liu 已提交
389 390
		mp->m_dalign = dsunit;
		mp->m_swidth = dswidth;
391 392 393 394 395 396
	}

	if (mp->m_logbufs != -1 &&
	    mp->m_logbufs != 0 &&
	    (mp->m_logbufs < XLOG_MIN_ICLOGS ||
	     mp->m_logbufs > XLOG_MAX_ICLOGS)) {
397
		xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
398
			mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
D
Dave Chinner 已提交
399
		return -EINVAL;
400 401 402 403 404 405
	}
	if (mp->m_logbsize != -1 &&
	    mp->m_logbsize !=  0 &&
	    (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
	     mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
	     !is_power_of_2(mp->m_logbsize))) {
406 407
		xfs_warn(mp,
			"invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
408
			mp->m_logbsize);
D
Dave Chinner 已提交
409
		return -EINVAL;
410 411 412 413 414
	}

	if (iosizelog) {
		if (iosizelog > XFS_MAX_IO_LOG ||
		    iosizelog < XFS_MIN_IO_LOG) {
415
			xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
416 417
				iosizelog, XFS_MIN_IO_LOG,
				XFS_MAX_IO_LOG);
D
Dave Chinner 已提交
418
			return -EINVAL;
419 420 421 422 423
		}

		mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
		mp->m_readio_log = iosizelog;
		mp->m_writeio_log = iosizelog;
424 425 426 427 428 429
	}

	return 0;
}

struct proc_xfs_info {
D
Dave Chinner 已提交
430 431
	uint64_t	flag;
	char		*str;
432 433
};

434
STATIC void
435 436 437 438 439 440
xfs_showargs(
	struct xfs_mount	*mp,
	struct seq_file		*m)
{
	static struct proc_xfs_info xfs_info_set[] = {
		/* the few simple ones we can get from the mount struct */
441 442 443 444 445 446 447 448 449 450 451 452
		{ XFS_MOUNT_IKEEP,		",ikeep" },
		{ XFS_MOUNT_WSYNC,		",wsync" },
		{ XFS_MOUNT_NOALIGN,		",noalign" },
		{ XFS_MOUNT_SWALLOC,		",swalloc" },
		{ XFS_MOUNT_NOUUID,		",nouuid" },
		{ XFS_MOUNT_NORECOVERY,		",norecovery" },
		{ XFS_MOUNT_ATTR2,		",attr2" },
		{ XFS_MOUNT_FILESTREAMS,	",filestreams" },
		{ XFS_MOUNT_GRPID,		",grpid" },
		{ XFS_MOUNT_DISCARD,		",discard" },
		{ XFS_MOUNT_SMALL_INUMS,	",inode32" },
		{ XFS_MOUNT_DAX,		",dax" },
453 454 455 456
		{ 0, NULL }
	};
	static struct proc_xfs_info xfs_info_unset[] = {
		/* the few simple ones we can get from the mount struct */
457 458
		{ XFS_MOUNT_COMPAT_IOSIZE,	",largeio" },
		{ XFS_MOUNT_SMALL_INUMS,	",inode64" },
459 460 461 462 463 464 465 466 467 468 469 470 471 472
		{ 0, NULL }
	};
	struct proc_xfs_info	*xfs_infop;

	for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
		if (mp->m_flags & xfs_infop->flag)
			seq_puts(m, xfs_infop->str);
	}
	for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
		if (!(mp->m_flags & xfs_infop->flag))
			seq_puts(m, xfs_infop->str);
	}

	if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
473
		seq_printf(m, ",allocsize=%dk",
474 475 476
				(int)(1 << mp->m_writeio_log) >> 10);

	if (mp->m_logbufs > 0)
477
		seq_printf(m, ",logbufs=%d", mp->m_logbufs);
478
	if (mp->m_logbsize > 0)
479
		seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
480 481

	if (mp->m_logname)
482
		seq_show_option(m, "logdev", mp->m_logname);
483
	if (mp->m_rtname)
484
		seq_show_option(m, "rtdev", mp->m_rtname);
485 486

	if (mp->m_dalign > 0)
487
		seq_printf(m, ",sunit=%d",
488 489
				(int)XFS_FSB_TO_BB(mp, mp->m_dalign));
	if (mp->m_swidth > 0)
490
		seq_printf(m, ",swidth=%d",
491 492 493
				(int)XFS_FSB_TO_BB(mp, mp->m_swidth));

	if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
494
		seq_puts(m, ",usrquota");
495
	else if (mp->m_qflags & XFS_UQUOTA_ACCT)
496
		seq_puts(m, ",uqnoenforce");
497

498
	if (mp->m_qflags & XFS_PQUOTA_ACCT) {
499
		if (mp->m_qflags & XFS_PQUOTA_ENFD)
500
			seq_puts(m, ",prjquota");
501
		else
502
			seq_puts(m, ",pqnoenforce");
503 504
	}
	if (mp->m_qflags & XFS_GQUOTA_ACCT) {
505
		if (mp->m_qflags & XFS_GQUOTA_ENFD)
506
			seq_puts(m, ",grpquota");
507
		else
508
			seq_puts(m, ",gqnoenforce");
509
	}
510 511

	if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
512
		seq_puts(m, ",noquota");
513
}
514

515
static uint64_t
L
Linus Torvalds 已提交
516 517 518 519 520 521 522 523
xfs_max_file_offset(
	unsigned int		blockshift)
{
	unsigned int		pagefactor = 1;
	unsigned int		bitshift = BITS_PER_LONG - 1;

	/* Figure out maximum filesize, on Linux this can depend on
	 * the filesystem blocksize (on 32 bit platforms).
C
Christoph Hellwig 已提交
524
	 * __block_write_begin does this in an [unsigned] long long...
525
	 *      page->index << (PAGE_SHIFT - bbits)
L
Linus Torvalds 已提交
526 527
	 * So, for page sized blocks (4K on 32 bit platforms),
	 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
528
	 *      (((u64)PAGE_SIZE << (BITS_PER_LONG-1))-1)
L
Linus Torvalds 已提交
529 530 531 532 533
	 * but for smaller blocksizes it is less (bbits = log2 bsize).
	 */

#if BITS_PER_LONG == 32
	ASSERT(sizeof(sector_t) == 8);
534
	pagefactor = PAGE_SIZE;
L
Linus Torvalds 已提交
535 536 537
	bitshift = BITS_PER_LONG;
#endif

538
	return (((uint64_t)pagefactor) << bitshift) - 1;
L
Linus Torvalds 已提交
539 540
}

541
/*
542 543 544 545 546 547 548 549 550 551 552 553 554
 * Set parameters for inode allocation heuristics, taking into account
 * filesystem size and inode32/inode64 mount options; i.e. specifically
 * whether or not XFS_MOUNT_SMALL_INUMS is set.
 *
 * Inode allocation patterns are altered only if inode32 is requested
 * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large.
 * If altered, XFS_MOUNT_32BITINODES is set as well.
 *
 * An agcount independent of that in the mount structure is provided
 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
 * to the potentially higher ag count.
 *
 * Returns the maximum AG index which may contain inodes.
555
 */
556
xfs_agnumber_t
557 558 559
xfs_set_inode_alloc(
	struct xfs_mount *mp,
	xfs_agnumber_t	agcount)
560
{
561
	xfs_agnumber_t	index;
562
	xfs_agnumber_t	maxagi = 0;
563 564
	xfs_sb_t	*sbp = &mp->m_sb;
	xfs_agnumber_t	max_metadata;
E
Eric Sandeen 已提交
565 566
	xfs_agino_t	agino;
	xfs_ino_t	ino;
567

568 569 570
	/*
	 * Calculate how much should be reserved for inodes to meet
	 * the max inode percentage.  Used only for inode32.
571
	 */
D
Darrick J. Wong 已提交
572
	if (M_IGEO(mp)->maxicount) {
573
		uint64_t	icount;
574 575 576 577 578 579 580

		icount = sbp->sb_dblocks * sbp->sb_imax_pct;
		do_div(icount, 100);
		icount += sbp->sb_agblocks - 1;
		do_div(icount, sbp->sb_agblocks);
		max_metadata = icount;
	} else {
581
		max_metadata = agcount;
582 583
	}

584
	/* Get the last possible inode in the filesystem */
585
	agino =	XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
586 587 588 589 590 591 592 593 594 595 596
	ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);

	/*
	 * If user asked for no more than 32-bit inodes, and the fs is
	 * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter
	 * the allocator to accommodate the request.
	 */
	if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32)
		mp->m_flags |= XFS_MOUNT_32BITINODES;
	else
		mp->m_flags &= ~XFS_MOUNT_32BITINODES;
E
Eric Sandeen 已提交
597

598
	for (index = 0; index < agcount; index++) {
599
		struct xfs_perag	*pag;
600

601
		ino = XFS_AGINO_TO_INO(mp, index, agino);
602 603 604

		pag = xfs_perag_get(mp, index);

605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
		if (mp->m_flags & XFS_MOUNT_32BITINODES) {
			if (ino > XFS_MAXINUMBER_32) {
				pag->pagi_inodeok = 0;
				pag->pagf_metadata = 0;
			} else {
				pag->pagi_inodeok = 1;
				maxagi++;
				if (index < max_metadata)
					pag->pagf_metadata = 1;
				else
					pag->pagf_metadata = 0;
			}
		} else {
			pag->pagi_inodeok = 1;
			pag->pagf_metadata = 0;
		}
621 622 623 624

		xfs_perag_put(pag);
	}

625
	return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount;
626 627
}

H
Hannes Eder 已提交
628
STATIC int
L
Linus Torvalds 已提交
629 630 631 632 633 634 635
xfs_blkdev_get(
	xfs_mount_t		*mp,
	const char		*name,
	struct block_device	**bdevp)
{
	int			error = 0;

636 637
	*bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
				    mp);
L
Linus Torvalds 已提交
638 639
	if (IS_ERR(*bdevp)) {
		error = PTR_ERR(*bdevp);
640
		xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
L
Linus Torvalds 已提交
641 642
	}

D
Dave Chinner 已提交
643
	return error;
L
Linus Torvalds 已提交
644 645
}

H
Hannes Eder 已提交
646
STATIC void
L
Linus Torvalds 已提交
647 648 649 650
xfs_blkdev_put(
	struct block_device	*bdev)
{
	if (bdev)
651
		blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
L
Linus Torvalds 已提交
652 653
}

654 655 656 657
void
xfs_blkdev_issue_flush(
	xfs_buftarg_t		*buftarg)
{
658
	blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
659
}
L
Linus Torvalds 已提交
660

661 662 663 664
STATIC void
xfs_close_devices(
	struct xfs_mount	*mp)
{
665 666
	struct dax_device *dax_ddev = mp->m_ddev_targp->bt_daxdev;

667
	if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
668
		struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
669 670
		struct dax_device *dax_logdev = mp->m_logdev_targp->bt_daxdev;

671
		xfs_free_buftarg(mp->m_logdev_targp);
672
		xfs_blkdev_put(logdev);
673
		fs_put_dax(dax_logdev);
674 675
	}
	if (mp->m_rtdev_targp) {
676
		struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
677 678
		struct dax_device *dax_rtdev = mp->m_rtdev_targp->bt_daxdev;

679
		xfs_free_buftarg(mp->m_rtdev_targp);
680
		xfs_blkdev_put(rtdev);
681
		fs_put_dax(dax_rtdev);
682
	}
683
	xfs_free_buftarg(mp->m_ddev_targp);
684
	fs_put_dax(dax_ddev);
685 686 687 688 689 690 691 692 693 694 695 696 697 698
}

/*
 * The file system configurations are:
 *	(1) device (partition) with data and internal log
 *	(2) logical volume with data and log subvolumes.
 *	(3) logical volume with data, log, and realtime subvolumes.
 *
 * We only have to handle opening the log and realtime volumes here if
 * they are present.  The data subvolume has already been opened by
 * get_sb_bdev() and is stored in sb->s_bdev.
 */
STATIC int
xfs_open_devices(
699
	struct xfs_mount	*mp)
700 701
{
	struct block_device	*ddev = mp->m_super->s_bdev;
702 703
	struct dax_device	*dax_ddev = fs_dax_get_by_bdev(ddev);
	struct dax_device	*dax_logdev = NULL, *dax_rtdev = NULL;
704 705 706 707 708 709
	struct block_device	*logdev = NULL, *rtdev = NULL;
	int			error;

	/*
	 * Open real time and log devices - order is important.
	 */
710 711
	if (mp->m_logname) {
		error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
712 713
		if (error)
			goto out;
714
		dax_logdev = fs_dax_get_by_bdev(logdev);
715 716
	}

717 718
	if (mp->m_rtname) {
		error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
719 720 721 722
		if (error)
			goto out_close_logdev;

		if (rtdev == ddev || rtdev == logdev) {
723 724
			xfs_warn(mp,
	"Cannot mount filesystem with identical rtdev and ddev/logdev.");
D
Dave Chinner 已提交
725
			error = -EINVAL;
726 727
			goto out_close_rtdev;
		}
728
		dax_rtdev = fs_dax_get_by_bdev(rtdev);
729 730 731 732 733
	}

	/*
	 * Setup xfs_mount buffer target pointers
	 */
D
Dave Chinner 已提交
734
	error = -ENOMEM;
735
	mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, dax_ddev);
736 737 738 739
	if (!mp->m_ddev_targp)
		goto out_close_rtdev;

	if (rtdev) {
740
		mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, dax_rtdev);
741 742 743 744 745
		if (!mp->m_rtdev_targp)
			goto out_free_ddev_targ;
	}

	if (logdev && logdev != ddev) {
746
		mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, dax_logdev);
747 748 749 750 751 752 753 754 755 756
		if (!mp->m_logdev_targp)
			goto out_free_rtdev_targ;
	} else {
		mp->m_logdev_targp = mp->m_ddev_targp;
	}

	return 0;

 out_free_rtdev_targ:
	if (mp->m_rtdev_targp)
757
		xfs_free_buftarg(mp->m_rtdev_targp);
758
 out_free_ddev_targ:
759
	xfs_free_buftarg(mp->m_ddev_targp);
760
 out_close_rtdev:
761
	xfs_blkdev_put(rtdev);
762
	fs_put_dax(dax_rtdev);
763
 out_close_logdev:
764
	if (logdev && logdev != ddev) {
765
		xfs_blkdev_put(logdev);
766 767
		fs_put_dax(dax_logdev);
	}
768
 out:
769
	fs_put_dax(dax_ddev);
770 771 772
	return error;
}

773 774 775 776 777 778 779 780
/*
 * Setup xfs_mount buffer target pointers based on superblock
 */
STATIC int
xfs_setup_devices(
	struct xfs_mount	*mp)
{
	int			error;
781

782
	error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
	if (error)
		return error;

	if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
		unsigned int	log_sector_size = BBSIZE;

		if (xfs_sb_version_hassector(&mp->m_sb))
			log_sector_size = mp->m_sb.sb_logsectsize;
		error = xfs_setsize_buftarg(mp->m_logdev_targp,
					    log_sector_size);
		if (error)
			return error;
	}
	if (mp->m_rtdev_targp) {
		error = xfs_setsize_buftarg(mp->m_rtdev_targp,
					    mp->m_sb.sb_sectsize);
		if (error)
			return error;
	}

	return 0;
}
805

806 807 808 809
STATIC int
xfs_init_mount_workqueues(
	struct xfs_mount	*mp)
{
810
	mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
811
			WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_fsname);
812 813 814
	if (!mp->m_buf_workqueue)
		goto out;

815
	mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
816
			WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
817
	if (!mp->m_unwritten_workqueue)
818
		goto out_destroy_buf;
819

820
	mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
821
			WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
822 823
	if (!mp->m_cil_workqueue)
		goto out_destroy_unwritten;
D
Dave Chinner 已提交
824 825

	mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
826
			WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
D
Dave Chinner 已提交
827 828 829
	if (!mp->m_reclaim_workqueue)
		goto out_destroy_cil;

830
	mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
831
			WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
832
	if (!mp->m_eofblocks_workqueue)
833
		goto out_destroy_reclaim;
834

835 836 837 838 839
	mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", WQ_FREEZABLE, 0,
					       mp->m_fsname);
	if (!mp->m_sync_workqueue)
		goto out_destroy_eofb;

840 841
	return 0;

842 843
out_destroy_eofb:
	destroy_workqueue(mp->m_eofblocks_workqueue);
D
Dave Chinner 已提交
844 845 846 847
out_destroy_reclaim:
	destroy_workqueue(mp->m_reclaim_workqueue);
out_destroy_cil:
	destroy_workqueue(mp->m_cil_workqueue);
848 849
out_destroy_unwritten:
	destroy_workqueue(mp->m_unwritten_workqueue);
850 851
out_destroy_buf:
	destroy_workqueue(mp->m_buf_workqueue);
852 853 854 855 856 857 858 859
out:
	return -ENOMEM;
}

STATIC void
xfs_destroy_mount_workqueues(
	struct xfs_mount	*mp)
{
860
	destroy_workqueue(mp->m_sync_workqueue);
861
	destroy_workqueue(mp->m_eofblocks_workqueue);
D
Dave Chinner 已提交
862
	destroy_workqueue(mp->m_reclaim_workqueue);
863
	destroy_workqueue(mp->m_cil_workqueue);
864
	destroy_workqueue(mp->m_unwritten_workqueue);
865
	destroy_workqueue(mp->m_buf_workqueue);
866 867
}

D
Dave Chinner 已提交
868 869 870 871 872 873 874 875 876 877 878 879 880
/*
 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
 * for IO to complete so that we effectively throttle multiple callers to the
 * rate at which IO is completing.
 */
void
xfs_flush_inodes(
	struct xfs_mount	*mp)
{
	struct super_block	*sb = mp->m_super;

	if (down_read_trylock(&sb->s_umount)) {
881
		sync_inodes_sb(sb);
D
Dave Chinner 已提交
882 883 884 885
		up_read(&sb->s_umount);
	}
}

886
/* Catch misguided souls that try to use this interface on XFS */
L
Linus Torvalds 已提交
887
STATIC struct inode *
888
xfs_fs_alloc_inode(
L
Linus Torvalds 已提交
889 890
	struct super_block	*sb)
{
891
	BUG();
892
	return NULL;
L
Linus Torvalds 已提交
893 894
}

895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
#ifdef DEBUG
static void
xfs_check_delalloc(
	struct xfs_inode	*ip,
	int			whichfork)
{
	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, whichfork);
	struct xfs_bmbt_irec	got;
	struct xfs_iext_cursor	icur;

	if (!ifp || !xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got))
		return;
	do {
		if (isnullstartblock(got.br_startblock)) {
			xfs_warn(ip->i_mount,
	"ino %llx %s fork has delalloc extent at [0x%llx:0x%llx]",
				ip->i_ino,
				whichfork == XFS_DATA_FORK ? "data" : "cow",
				got.br_startoff, got.br_blockcount);
		}
	} while (xfs_iext_next_extent(ifp, &icur, &got));
}
#else
#define xfs_check_delalloc(ip, whichfork)	do { } while (0)
#endif

921
/*
922
 * Now that the generic code is guaranteed not to be accessing
D
Dave Chinner 已提交
923
 * the linux inode, we can inactivate and reclaim the inode.
924
 */
L
Linus Torvalds 已提交
925
STATIC void
926
xfs_fs_destroy_inode(
C
Christoph Hellwig 已提交
927
	struct inode		*inode)
L
Linus Torvalds 已提交
928
{
C
Christoph Hellwig 已提交
929 930
	struct xfs_inode	*ip = XFS_I(inode);

C
Christoph Hellwig 已提交
931
	trace_xfs_destroy_inode(ip);
932

933
	ASSERT(!rwsem_is_locked(&inode->i_rwsem));
D
Dave Chinner 已提交
934 935 936 937
	XFS_STATS_INC(ip->i_mount, vn_rele);
	XFS_STATS_INC(ip->i_mount, vn_remove);

	xfs_inactive(ip);
C
Christoph Hellwig 已提交
938

939 940 941 942 943 944
	if (!XFS_FORCED_SHUTDOWN(ip->i_mount) && ip->i_delayed_blks) {
		xfs_check_delalloc(ip, XFS_DATA_FORK);
		xfs_check_delalloc(ip, XFS_COW_FORK);
		ASSERT(0);
	}

D
Dave Chinner 已提交
945
	XFS_STATS_INC(ip->i_mount, vn_reclaim);
C
Christoph Hellwig 已提交
946 947 948 949 950 951 952 953

	/*
	 * We should never get here with one of the reclaim flags already set.
	 */
	ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
	ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));

	/*
954 955 956 957 958
	 * We always use background reclaim here because even if the
	 * inode is clean, it still may be under IO and hence we have
	 * to take the flush lock. The background reclaim path handles
	 * this more efficiently than we can here, so simply let background
	 * reclaim tear down all inodes.
C
Christoph Hellwig 已提交
959
	 */
960
	xfs_inode_set_reclaim_tag(ip);
L
Linus Torvalds 已提交
961 962
}

963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
static void
xfs_fs_dirty_inode(
	struct inode			*inode,
	int				flag)
{
	struct xfs_inode		*ip = XFS_I(inode);
	struct xfs_mount		*mp = ip->i_mount;
	struct xfs_trans		*tp;

	if (!(inode->i_sb->s_flags & SB_LAZYTIME))
		return;
	if (flag != I_DIRTY_SYNC || !(inode->i_state & I_DIRTY_TIME))
		return;

	if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
		return;
	xfs_ilock(ip, XFS_ILOCK_EXCL);
	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
	xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
	xfs_trans_commit(tp);
}

985 986 987 988
/*
 * Slab object creation initialisation for the XFS inode.
 * This covers only the idempotent fields in the XFS inode;
 * all other fields need to be initialised on allocation
989
 * from the slab. This avoids the need to repeatedly initialise
990 991 992
 * fields in the xfs inode that left in the initialise state
 * when freeing the inode.
 */
993 994
STATIC void
xfs_fs_inode_init_once(
995 996 997 998 999
	void			*inode)
{
	struct xfs_inode	*ip = inode;

	memset(ip, 0, sizeof(struct xfs_inode));
1000 1001 1002 1003 1004

	/* vfs inode */
	inode_init_once(VFS_I(ip));

	/* xfs inode */
1005 1006 1007
	atomic_set(&ip->i_pincount, 0);
	spin_lock_init(&ip->i_flags_lock);

D
Dave Chinner 已提交
1008 1009
	mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
		     "xfsino", ip->i_ino);
1010 1011 1012 1013
	mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
		     "xfsino", ip->i_ino);
}

1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
/*
 * We do an unlocked check for XFS_IDONTCACHE here because we are already
 * serialised against cache hits here via the inode->i_lock and igrab() in
 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
 * racing with us, and it avoids needing to grab a spinlock here for every inode
 * we drop the final reference on.
 */
STATIC int
xfs_fs_drop_inode(
	struct inode		*inode)
{
	struct xfs_inode	*ip = XFS_I(inode);

1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
	/*
	 * If this unlinked inode is in the middle of recovery, don't
	 * drop the inode just yet; log recovery will take care of
	 * that.  See the comment for this inode flag.
	 */
	if (ip->i_flags & XFS_IRECOVERY) {
		ASSERT(ip->i_mount->m_log->l_flags & XLOG_RECOVERY_NEEDED);
		return 0;
	}

1037 1038 1039
	return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
}

1040 1041 1042 1043 1044 1045 1046 1047 1048
STATIC void
xfs_free_fsname(
	struct xfs_mount	*mp)
{
	kfree(mp->m_fsname);
	kfree(mp->m_rtname);
	kfree(mp->m_logname);
}

L
Linus Torvalds 已提交
1049
STATIC int
C
Christoph Hellwig 已提交
1050
xfs_fs_sync_fs(
L
Linus Torvalds 已提交
1051 1052 1053
	struct super_block	*sb,
	int			wait)
{
1054
	struct xfs_mount	*mp = XFS_M(sb);
L
Linus Torvalds 已提交
1055

1056
	/*
C
Christoph Hellwig 已提交
1057
	 * Doing anything during the async pass would be counterproductive.
1058
	 */
C
Christoph Hellwig 已提交
1059
	if (!wait)
C
Christoph Hellwig 已提交
1060 1061
		return 0;

D
Dave Chinner 已提交
1062
	xfs_log_force(mp, XFS_LOG_SYNC);
C
Christoph Hellwig 已提交
1063
	if (laptop_mode) {
L
Linus Torvalds 已提交
1064 1065
		/*
		 * The disk must be active because we're syncing.
1066
		 * We schedule log work now (now that the disk is
L
Linus Torvalds 已提交
1067 1068
		 * active) instead of later (when it might not be).
		 */
1069
		flush_delayed_work(&mp->m_log->l_work);
L
Linus Torvalds 已提交
1070 1071
	}

C
Christoph Hellwig 已提交
1072
	return 0;
L
Linus Torvalds 已提交
1073 1074 1075
}

STATIC int
1076
xfs_fs_statfs(
1077
	struct dentry		*dentry,
L
Linus Torvalds 已提交
1078 1079
	struct kstatfs		*statp)
{
C
Christoph Hellwig 已提交
1080 1081
	struct xfs_mount	*mp = XFS_M(dentry->d_sb);
	xfs_sb_t		*sbp = &mp->m_sb;
1082
	struct xfs_inode	*ip = XFS_I(d_inode(dentry));
1083 1084 1085 1086
	uint64_t		fakeinos, id;
	uint64_t		icount;
	uint64_t		ifree;
	uint64_t		fdblocks;
C
Christoph Hellwig 已提交
1087
	xfs_extlen_t		lsize;
1088
	int64_t			ffree;
C
Christoph Hellwig 已提交
1089

1090
	statp->f_type = XFS_SUPER_MAGIC;
C
Christoph Hellwig 已提交
1091 1092 1093 1094 1095 1096
	statp->f_namelen = MAXNAMELEN - 1;

	id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
	statp->f_fsid.val[0] = (u32)id;
	statp->f_fsid.val[1] = (u32)(id >> 32);

1097
	icount = percpu_counter_sum(&mp->m_icount);
1098
	ifree = percpu_counter_sum(&mp->m_ifree);
1099
	fdblocks = percpu_counter_sum(&mp->m_fdblocks);
C
Christoph Hellwig 已提交
1100 1101 1102 1103 1104

	spin_lock(&mp->m_sb_lock);
	statp->f_bsize = sbp->sb_blocksize;
	lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
	statp->f_blocks = sbp->sb_dblocks - lsize;
1105 1106
	spin_unlock(&mp->m_sb_lock);

1107
	statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
1108 1109
	statp->f_bavail = statp->f_bfree;

1110
	fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
D
Dave Chinner 已提交
1111
	statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
D
Darrick J. Wong 已提交
1112
	if (M_IGEO(mp)->maxicount)
C
Christoph Hellwig 已提交
1113 1114
		statp->f_files = min_t(typeof(statp->f_files),
					statp->f_files,
D
Darrick J. Wong 已提交
1115
					M_IGEO(mp)->maxicount);
1116

1117 1118 1119 1120 1121
	/* If sb_icount overshot maxicount, report actual allocation */
	statp->f_files = max_t(typeof(statp->f_files),
					statp->f_files,
					sbp->sb_icount);

1122
	/* make sure statp->f_ffree does not underflow */
1123
	ffree = statp->f_files - (icount - ifree);
1124
	statp->f_ffree = max_t(int64_t, ffree, 0);
1125

C
Christoph Hellwig 已提交
1126

1127
	if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
1128 1129
	    ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
			      (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
C
Christoph Hellwig 已提交
1130
		xfs_qm_statvfs(ip, statp);
1131 1132 1133 1134 1135 1136 1137 1138

	if (XFS_IS_REALTIME_MOUNT(mp) &&
	    (ip->i_d.di_flags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
		statp->f_blocks = sbp->sb_rblocks;
		statp->f_bavail = statp->f_bfree =
			sbp->sb_frextents * sbp->sb_rextsize;
	}

C
Christoph Hellwig 已提交
1139
	return 0;
L
Linus Torvalds 已提交
1140 1141
}

E
Eric Sandeen 已提交
1142 1143 1144
STATIC void
xfs_save_resvblks(struct xfs_mount *mp)
{
1145
	uint64_t resblks = 0;
E
Eric Sandeen 已提交
1146 1147 1148 1149 1150 1151 1152 1153

	mp->m_resblks_save = mp->m_resblks;
	xfs_reserve_blocks(mp, &resblks, NULL);
}

STATIC void
xfs_restore_resvblks(struct xfs_mount *mp)
{
1154
	uint64_t resblks;
E
Eric Sandeen 已提交
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164

	if (mp->m_resblks_save) {
		resblks = mp->m_resblks_save;
		mp->m_resblks_save = 0;
	} else
		resblks = xfs_default_resblks(mp);

	xfs_reserve_blocks(mp, &resblks, NULL);
}

1165 1166 1167 1168 1169
/*
 * Trigger writeback of all the dirty metadata in the file system.
 *
 * This ensures that the metadata is written to their location on disk rather
 * than just existing in transactions in the log. This means after a quiesce
1170 1171
 * there is no log replay required to write the inodes to disk - this is the
 * primary difference between a sync and a quiesce.
1172
 *
1173 1174
 * Note: xfs_log_quiesce() stops background log work - the callers must ensure
 * it is started again when appropriate.
1175
 */
1176
void
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
xfs_quiesce_attr(
	struct xfs_mount	*mp)
{
	int	error = 0;

	/* wait for all modifications to complete */
	while (atomic_read(&mp->m_active_trans) > 0)
		delay(100);

	/* force the log to unpin objects from the now complete transactions */
	xfs_log_force(mp, XFS_LOG_SYNC);

	/* reclaim inodes to do any IO before the freeze completes */
	xfs_reclaim_inodes(mp, 0);
	xfs_reclaim_inodes(mp, SYNC_WAIT);

	/* Push the superblock and write an unmount record */
	error = xfs_log_sbcount(mp);
	if (error)
		xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
				"Frozen image may not be consistent.");
	/*
1199 1200
	 * Just warn here till VFS can correctly support
	 * read-only remount without racing.
1201
	 */
1202
	WARN_ON(atomic_read(&mp->m_active_trans) != 0);
1203

1204
	xfs_log_quiesce(mp);
1205 1206
}

E
Eric Sandeen 已提交
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
STATIC int
xfs_test_remount_options(
	struct super_block	*sb,
	char			*options)
{
	int			error = 0;
	struct xfs_mount	*tmp_mp;

	tmp_mp = kmem_zalloc(sizeof(*tmp_mp), KM_MAYFAIL);
	if (!tmp_mp)
		return -ENOMEM;

	tmp_mp->m_super = sb;
	error = xfs_parseargs(tmp_mp, options);
	xfs_free_fsname(tmp_mp);
1222
	kmem_free(tmp_mp);
E
Eric Sandeen 已提交
1223 1224 1225 1226

	return error;
}

L
Linus Torvalds 已提交
1227
STATIC int
1228
xfs_fs_remount(
L
Linus Torvalds 已提交
1229 1230 1231 1232
	struct super_block	*sb,
	int			*flags,
	char			*options)
{
1233
	struct xfs_mount	*mp = XFS_M(sb);
1234
	xfs_sb_t		*sbp = &mp->m_sb;
1235 1236
	substring_t		args[MAX_OPT_ARGS];
	char			*p;
1237
	int			error;
L
Linus Torvalds 已提交
1238

E
Eric Sandeen 已提交
1239
	/* First, check for complete junk; i.e. invalid options */
1240
	error = xfs_test_remount_options(sb, options);
E
Eric Sandeen 已提交
1241 1242 1243
	if (error)
		return error;

1244
	sync_filesystem(sb);
1245 1246
	while ((p = strsep(&options, ",")) != NULL) {
		int token;
1247

1248 1249
		if (!*p)
			continue;
1250

1251 1252
		token = match_token(p, tokens, args);
		switch (token) {
1253
		case Opt_inode64:
1254 1255
			mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
			mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1256
			break;
1257
		case Opt_inode32:
1258 1259
			mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
			mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1260
			break;
1261
		default:
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
			/*
			 * Logically we would return an error here to prevent
			 * users from believing they might have changed
			 * mount options using remount which can't be changed.
			 *
			 * But unfortunately mount(8) adds all options from
			 * mtab and fstab to the mount arguments in some cases
			 * so we can't blindly reject options, but have to
			 * check for each specified option if it actually
			 * differs from the currently set option and only
			 * reject it if that's the case.
			 *
			 * Until that is implemented we return success for
			 * every remount request, and silently ignore all
			 * options that we can't actually change.
			 */
#if 0
1279
			xfs_info(mp,
1280
		"mount option \"%s\" not supported for remount", p);
1281
			return -EINVAL;
1282
#else
1283
			break;
1284
#endif
1285
		}
1286 1287
	}

1288
	/* ro -> rw */
1289
	if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & SB_RDONLY)) {
1290 1291 1292 1293 1294 1295
		if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
			xfs_warn(mp,
		"ro->rw transition prohibited on norecovery mount");
			return -EINVAL;
		}

1296 1297 1298 1299 1300 1301 1302 1303 1304 1305
		if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
		    xfs_sb_has_ro_compat_feature(sbp,
					XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
			xfs_warn(mp,
"ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
				(sbp->sb_features_ro_compat &
					XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
			return -EINVAL;
		}

1306
		mp->m_flags &= ~XFS_MOUNT_RDONLY;
1307 1308 1309 1310 1311

		/*
		 * If this is the first remount to writeable state we
		 * might have some superblock changes to update.
		 */
1312 1313
		if (mp->m_update_sb) {
			error = xfs_sync_sb(mp, false);
1314
			if (error) {
1315
				xfs_warn(mp, "failed to write sb changes");
1316 1317
				return error;
			}
1318
			mp->m_update_sb = false;
1319
		}
1320 1321 1322 1323 1324

		/*
		 * Fill out the reserve pool if it is empty. Use the stashed
		 * value if it is non-zero, otherwise go with the default.
		 */
E
Eric Sandeen 已提交
1325
		xfs_restore_resvblks(mp);
1326
		xfs_log_work_queue(mp);
1327 1328 1329 1330 1331 1332 1333 1334 1335

		/* Recover any CoW blocks that never got remapped. */
		error = xfs_reflink_recover_cow(mp);
		if (error) {
			xfs_err(mp,
	"Error %d recovering leftover CoW allocations.", error);
			xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
			return error;
		}
1336
		xfs_start_block_reaping(mp);
1337 1338 1339 1340 1341

		/* Create the per-AG metadata reservation pool .*/
		error = xfs_fs_reserve_ag_blocks(mp);
		if (error && error != -ENOSPC)
			return error;
1342 1343 1344
	}

	/* rw -> ro */
1345
	if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & SB_RDONLY)) {
1346 1347 1348 1349
		/*
		 * Cancel background eofb scanning so it cannot race with the
		 * final log force+buftarg wait and deadlock the remount.
		 */
1350
		xfs_stop_block_reaping(mp);
1351

1352 1353 1354 1355 1356 1357 1358
		/* Get rid of any leftover CoW reservations... */
		error = xfs_icache_free_cowblocks(mp, NULL);
		if (error) {
			xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
			return error;
		}

1359 1360 1361 1362 1363 1364 1365
		/* Free the per-AG metadata reservation pool. */
		error = xfs_fs_unreserve_ag_blocks(mp);
		if (error) {
			xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
			return error;
		}

1366
		/*
D
Dave Chinner 已提交
1367 1368 1369 1370 1371
		 * Before we sync the metadata, we need to free up the reserve
		 * block pool so that the used block count in the superblock on
		 * disk is correct at the end of the remount. Stash the current
		 * reserve pool size so that if we get remounted rw, we can
		 * return it to the same size.
1372
		 */
E
Eric Sandeen 已提交
1373
		xfs_save_resvblks(mp);
1374

D
David Chinner 已提交
1375
		xfs_quiesce_attr(mp);
1376 1377 1378
		mp->m_flags |= XFS_MOUNT_RDONLY;
	}

1379
	return 0;
L
Linus Torvalds 已提交
1380 1381
}

C
Christoph Hellwig 已提交
1382 1383
/*
 * Second stage of a freeze. The data is already frozen so we only
1384 1385 1386
 * need to take care of the metadata. Once that's done sync the superblock
 * to the log to dirty it in case of a crash while frozen. This ensures that we
 * will recover the unlinked inode lists on the next mount.
C
Christoph Hellwig 已提交
1387
 */
1388 1389
STATIC int
xfs_fs_freeze(
L
Linus Torvalds 已提交
1390 1391
	struct super_block	*sb)
{
C
Christoph Hellwig 已提交
1392 1393
	struct xfs_mount	*mp = XFS_M(sb);

1394
	xfs_stop_block_reaping(mp);
E
Eric Sandeen 已提交
1395
	xfs_save_resvblks(mp);
D
David Chinner 已提交
1396
	xfs_quiesce_attr(mp);
1397
	return xfs_sync_sb(mp, true);
L
Linus Torvalds 已提交
1398 1399
}

E
Eric Sandeen 已提交
1400 1401 1402 1403 1404 1405 1406
STATIC int
xfs_fs_unfreeze(
	struct super_block	*sb)
{
	struct xfs_mount	*mp = XFS_M(sb);

	xfs_restore_resvblks(mp);
1407
	xfs_log_work_queue(mp);
1408
	xfs_start_block_reaping(mp);
E
Eric Sandeen 已提交
1409 1410 1411
	return 0;
}

L
Linus Torvalds 已提交
1412
STATIC int
1413
xfs_fs_show_options(
L
Linus Torvalds 已提交
1414
	struct seq_file		*m,
1415
	struct dentry		*root)
L
Linus Torvalds 已提交
1416
{
1417 1418
	xfs_showargs(XFS_M(root->d_sb), m);
	return 0;
L
Linus Torvalds 已提交
1419 1420
}

1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
/*
 * This function fills in xfs_mount_t fields based on mount args.
 * Note: the superblock _has_ now been read in.
 */
STATIC int
xfs_finish_flags(
	struct xfs_mount	*mp)
{
	int			ronly = (mp->m_flags & XFS_MOUNT_RDONLY);

1431
	/* Fail a mount where the logbuf is smaller than the log stripe */
1432
	if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1433 1434
		if (mp->m_logbsize <= 0 &&
		    mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
1435
			mp->m_logbsize = mp->m_sb.sb_logsunit;
1436 1437
		} else if (mp->m_logbsize > 0 &&
			   mp->m_logbsize < mp->m_sb.sb_logsunit) {
1438 1439
			xfs_warn(mp,
		"logbuf size must be greater than or equal to log stripe size");
D
Dave Chinner 已提交
1440
			return -EINVAL;
1441 1442 1443
		}
	} else {
		/* Fail a mount if the logbuf is larger than 32K */
1444
		if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
1445 1446
			xfs_warn(mp,
		"logbuf size for version 1 logs must be 16K or 32K");
D
Dave Chinner 已提交
1447
			return -EINVAL;
1448 1449 1450
		}
	}

1451 1452 1453 1454 1455
	/*
	 * V5 filesystems always use attr2 format for attributes.
	 */
	if (xfs_sb_version_hascrc(&mp->m_sb) &&
	    (mp->m_flags & XFS_MOUNT_NOATTR2)) {
1456 1457
		xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
			     "attr2 is always enabled for V5 filesystems.");
D
Dave Chinner 已提交
1458
		return -EINVAL;
1459 1460
	}

1461 1462 1463 1464 1465
	/*
	 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
	 * told by noattr2 to turn it off
	 */
	if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1466
	    !(mp->m_flags & XFS_MOUNT_NOATTR2))
1467 1468 1469 1470 1471 1472
		mp->m_flags |= XFS_MOUNT_ATTR2;

	/*
	 * prohibit r/w mounts of read-only filesystems
	 */
	if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1473 1474
		xfs_warn(mp,
			"cannot mount a read-only filesystem as read-write");
D
Dave Chinner 已提交
1475
		return -EROFS;
1476 1477
	}

1478 1479 1480 1481 1482
	if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
	    (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
	    !xfs_sb_version_has_pquotino(&mp->m_sb)) {
		xfs_warn(mp,
		  "Super block does not support project and group quota together");
D
Dave Chinner 已提交
1483
		return -EINVAL;
1484 1485
	}

1486 1487 1488
	return 0;
}

D
Dave Chinner 已提交
1489 1490 1491 1492 1493 1494 1495 1496
static int
xfs_init_percpu_counters(
	struct xfs_mount	*mp)
{
	int		error;

	error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
	if (error)
1497
		return -ENOMEM;
D
Dave Chinner 已提交
1498 1499 1500 1501 1502 1503 1504 1505 1506

	error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
	if (error)
		goto free_icount;

	error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
	if (error)
		goto free_ifree;

1507 1508 1509 1510
	error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
	if (error)
		goto free_fdblocks;

D
Dave Chinner 已提交
1511 1512
	return 0;

1513 1514
free_fdblocks:
	percpu_counter_destroy(&mp->m_fdblocks);
D
Dave Chinner 已提交
1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
free_ifree:
	percpu_counter_destroy(&mp->m_ifree);
free_icount:
	percpu_counter_destroy(&mp->m_icount);
	return -ENOMEM;
}

void
xfs_reinit_percpu_counters(
	struct xfs_mount	*mp)
{
	percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
	percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
	percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
}

static void
xfs_destroy_percpu_counters(
	struct xfs_mount	*mp)
{
	percpu_counter_destroy(&mp->m_icount);
	percpu_counter_destroy(&mp->m_ifree);
	percpu_counter_destroy(&mp->m_fdblocks);
1538 1539 1540
	ASSERT(XFS_FORCED_SHUTDOWN(mp) ||
	       percpu_counter_sum(&mp->m_delalloc_blks) == 0);
	percpu_counter_destroy(&mp->m_delalloc_blks);
D
Dave Chinner 已提交
1541 1542
}

1543 1544 1545
static struct xfs_mount *
xfs_mount_alloc(
	struct super_block	*sb)
L
Linus Torvalds 已提交
1546
{
1547
	struct xfs_mount	*mp;
1548

C
Christoph Hellwig 已提交
1549 1550
	mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
	if (!mp)
1551
		return NULL;
L
Linus Torvalds 已提交
1552

1553
	mp->m_super = sb;
C
Christoph Hellwig 已提交
1554
	spin_lock_init(&mp->m_sb_lock);
1555 1556 1557
	spin_lock_init(&mp->m_agirotor_lock);
	INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
	spin_lock_init(&mp->m_perag_lock);
C
Christoph Hellwig 已提交
1558 1559
	mutex_init(&mp->m_growlock);
	atomic_set(&mp->m_active_trans, 0);
D
Dave Chinner 已提交
1560
	INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
1561
	INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
1562
	INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker);
D
Dave Chinner 已提交
1563
	mp->m_kobj.kobject.kset = xfs_kset;
1564 1565 1566 1567 1568 1569 1570
	/*
	 * We don't create the finobt per-ag space reservation until after log
	 * recovery, so we must set this to true so that an ifree transaction
	 * started during log recovery will not depend on space reservations
	 * for finobt expansion.
	 */
	mp->m_finobt_nores = true;
1571 1572
	return mp;
}
1573

1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591

STATIC int
xfs_fs_fill_super(
	struct super_block	*sb,
	void			*data,
	int			silent)
{
	struct inode		*root;
	struct xfs_mount	*mp = NULL;
	int			flags = 0, error = -ENOMEM;

	/*
	 * allocate mp and do all low-level struct initializations before we
	 * attach it to the super
	 */
	mp = xfs_mount_alloc(sb);
	if (!mp)
		goto out;
C
Christoph Hellwig 已提交
1592
	sb->s_fs_info = mp;
L
Linus Torvalds 已提交
1593

C
Christoph Hellwig 已提交
1594
	error = xfs_parseargs(mp, (char *)data);
1595
	if (error)
1596
		goto out_free_fsname;
L
Linus Torvalds 已提交
1597 1598

	sb_min_blocksize(sb, BBSIZE);
1599
	sb->s_xattr = xfs_xattr_handlers;
1600
	sb->s_export_op = &xfs_export_operations;
1601
#ifdef CONFIG_XFS_QUOTA
1602
	sb->s_qcop = &xfs_quotactl_operations;
J
Jan Kara 已提交
1603
	sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
1604
#endif
1605
	sb->s_op = &xfs_super_operations;
L
Linus Torvalds 已提交
1606

D
Dave Chinner 已提交
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617
	/*
	 * Delay mount work if the debug hook is set. This is debug
	 * instrumention to coordinate simulation of xfs mount failures with
	 * VFS superblock operations
	 */
	if (xfs_globals.mount_delay) {
		xfs_notice(mp, "Delaying mount for %d seconds.",
			xfs_globals.mount_delay);
		msleep(xfs_globals.mount_delay * 1000);
	}

1618
	if (silent)
1619 1620
		flags |= XFS_MFSI_QUIET;

1621
	error = xfs_open_devices(mp);
1622
	if (error)
C
Christoph Hellwig 已提交
1623
		goto out_free_fsname;
1624

D
Dave Chinner 已提交
1625
	error = xfs_init_mount_workqueues(mp);
1626 1627
	if (error)
		goto out_close_devices;
C
Christoph Hellwig 已提交
1628

D
Dave Chinner 已提交
1629
	error = xfs_init_percpu_counters(mp);
1630 1631 1632
	if (error)
		goto out_destroy_workqueues;

1633 1634 1635
	/* Allocate stats memory before we do operations that might use it */
	mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
	if (!mp->m_stats.xs_stats) {
1636
		error = -ENOMEM;
1637 1638 1639
		goto out_destroy_counters;
	}

1640 1641
	error = xfs_readsb(mp, flags);
	if (error)
1642
		goto out_free_stats;
1643 1644

	error = xfs_finish_flags(mp);
1645
	if (error)
1646
		goto out_free_sb;
1647

1648
	error = xfs_setup_devices(mp);
1649
	if (error)
1650
		goto out_free_sb;
1651 1652 1653

	error = xfs_filestream_mount(mp);
	if (error)
1654
		goto out_free_sb;
1655

1656 1657 1658 1659
	/*
	 * we must configure the block size in the superblock before we run the
	 * full mount process as the mount process can lookup and cache inodes.
	 */
1660
	sb->s_magic = XFS_SUPER_MAGIC;
C
Christoph Hellwig 已提交
1661 1662
	sb->s_blocksize = mp->m_sb.sb_blocksize;
	sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
L
Linus Torvalds 已提交
1663
	sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1664
	sb->s_max_links = XFS_MAXLINK;
L
Linus Torvalds 已提交
1665
	sb->s_time_gran = 1;
1666 1667
	sb->s_iflags |= SB_I_CGROUPWB;

L
Linus Torvalds 已提交
1668 1669
	set_posix_acl_flag(sb);

D
Dave Chinner 已提交
1670 1671
	/* version 5 superblocks support inode version counters. */
	if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
M
Matthew Garrett 已提交
1672
		sb->s_flags |= SB_I_VERSION;
D
Dave Chinner 已提交
1673

D
Dave Chinner 已提交
1674
	if (mp->m_flags & XFS_MOUNT_DAX) {
1675
		bool rtdev_is_dax = false, datadev_is_dax;
1676

D
Dave Chinner 已提交
1677
		xfs_warn(mp,
1678 1679
		"DAX enabled. Warning: EXPERIMENTAL, use at your own risk");

1680 1681
		datadev_is_dax = bdev_dax_supported(mp->m_ddev_targp->bt_bdev,
			sb->s_blocksize);
1682
		if (mp->m_rtdev_targp)
1683 1684 1685
			rtdev_is_dax = bdev_dax_supported(
				mp->m_rtdev_targp->bt_bdev, sb->s_blocksize);
		if (!rtdev_is_dax && !datadev_is_dax) {
D
Dave Chinner 已提交
1686
			xfs_alert(mp,
1687
			"DAX unsupported by block device. Turning off DAX.");
D
Dave Chinner 已提交
1688 1689
			mp->m_flags &= ~XFS_MOUNT_DAX;
		}
1690
		if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1691
			xfs_alert(mp,
1692
		"DAX and reflink cannot be used together!");
1693 1694 1695
			error = -EINVAL;
			goto out_filestream_unmount;
		}
D
Dave Chinner 已提交
1696 1697
	}

1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
	if (mp->m_flags & XFS_MOUNT_DISCARD) {
		struct request_queue *q = bdev_get_queue(sb->s_bdev);

		if (!blk_queue_discard(q)) {
			xfs_warn(mp, "mounting with \"discard\" option, but "
					"the device does not support discard");
			mp->m_flags &= ~XFS_MOUNT_DISCARD;
		}
	}

1708 1709 1710
	if (xfs_sb_version_hasreflink(&mp->m_sb)) {
		if (mp->m_sb.sb_rblocks) {
			xfs_alert(mp,
1711
	"reflink not compatible with realtime device!");
1712 1713 1714 1715 1716 1717 1718 1719
			error = -EINVAL;
			goto out_filestream_unmount;
		}

		if (xfs_globals.always_cow) {
			xfs_info(mp, "using DEBUG-only always_cow mode.");
			mp->m_always_cow = true;
		}
1720 1721
	}

1722
	if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks) {
1723
		xfs_alert(mp,
1724 1725 1726
	"reverse mapping btree not compatible with realtime device!");
		error = -EINVAL;
		goto out_filestream_unmount;
1727
	}
1728

1729
	error = xfs_mountfs(mp);
1730
	if (error)
D
Dave Chinner 已提交
1731
		goto out_filestream_unmount;
1732

1733
	root = igrab(VFS_I(mp->m_rootip));
1734
	if (!root) {
D
Dave Chinner 已提交
1735
		error = -ENOENT;
1736
		goto out_unmount;
C
Christoph Hellwig 已提交
1737
	}
1738
	sb->s_root = d_make_root(root);
1739
	if (!sb->s_root) {
D
Dave Chinner 已提交
1740
		error = -ENOMEM;
1741
		goto out_unmount;
L
Linus Torvalds 已提交
1742
	}
1743

L
Linus Torvalds 已提交
1744
	return 0;
D
Dave Chinner 已提交
1745

D
Dave Chinner 已提交
1746
 out_filestream_unmount:
1747
	xfs_filestream_unmount(mp);
1748 1749
 out_free_sb:
	xfs_freesb(mp);
1750 1751
 out_free_stats:
	free_percpu(mp->m_stats.xs_stats);
1752
 out_destroy_counters:
D
Dave Chinner 已提交
1753
	xfs_destroy_percpu_counters(mp);
1754
 out_destroy_workqueues:
1755
	xfs_destroy_mount_workqueues(mp);
1756
 out_close_devices:
1757
	xfs_close_devices(mp);
1758
 out_free_fsname:
1759
	sb->s_fs_info = NULL;
1760
	xfs_free_fsname(mp);
C
Christoph Hellwig 已提交
1761
	kfree(mp);
1762
 out:
D
Dave Chinner 已提交
1763
	return error;
1764

1765
 out_unmount:
1766
	xfs_filestream_unmount(mp);
1767
	xfs_unmountfs(mp);
1768
	goto out_free_sb;
L
Linus Torvalds 已提交
1769 1770
}

D
Dave Chinner 已提交
1771 1772 1773 1774 1775 1776
STATIC void
xfs_fs_put_super(
	struct super_block	*sb)
{
	struct xfs_mount	*mp = XFS_M(sb);

1777 1778 1779 1780
	/* if ->fill_super failed, we have no mount to tear down */
	if (!sb->s_fs_info)
		return;

1781
	xfs_notice(mp, "Unmounting Filesystem");
D
Dave Chinner 已提交
1782 1783 1784 1785
	xfs_filestream_unmount(mp);
	xfs_unmountfs(mp);

	xfs_freesb(mp);
1786
	free_percpu(mp->m_stats.xs_stats);
D
Dave Chinner 已提交
1787 1788 1789
	xfs_destroy_percpu_counters(mp);
	xfs_destroy_mount_workqueues(mp);
	xfs_close_devices(mp);
1790 1791

	sb->s_fs_info = NULL;
D
Dave Chinner 已提交
1792 1793 1794 1795
	xfs_free_fsname(mp);
	kfree(mp);
}

A
Al Viro 已提交
1796 1797
STATIC struct dentry *
xfs_fs_mount(
L
Linus Torvalds 已提交
1798 1799 1800
	struct file_system_type	*fs_type,
	int			flags,
	const char		*dev_name,
A
Al Viro 已提交
1801
	void			*data)
L
Linus Torvalds 已提交
1802
{
A
Al Viro 已提交
1803
	return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
1804 1805
}

1806
static long
1807
xfs_fs_nr_cached_objects(
1808
	struct super_block	*sb,
1809
	struct shrink_control	*sc)
1810
{
1811 1812 1813
	/* Paranoia: catch incorrect calls during mount setup or teardown */
	if (WARN_ON_ONCE(!sb->s_fs_info))
		return 0;
1814 1815 1816
	return xfs_reclaim_inodes_count(XFS_M(sb));
}

1817
static long
1818 1819
xfs_fs_free_cached_objects(
	struct super_block	*sb,
1820
	struct shrink_control	*sc)
1821
{
1822
	return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
1823 1824
}

1825
static const struct super_operations xfs_super_operations = {
1826 1827
	.alloc_inode		= xfs_fs_alloc_inode,
	.destroy_inode		= xfs_fs_destroy_inode,
1828
	.dirty_inode		= xfs_fs_dirty_inode,
1829
	.drop_inode		= xfs_fs_drop_inode,
1830
	.put_super		= xfs_fs_put_super,
C
Christoph Hellwig 已提交
1831
	.sync_fs		= xfs_fs_sync_fs,
1832
	.freeze_fs		= xfs_fs_freeze,
E
Eric Sandeen 已提交
1833
	.unfreeze_fs		= xfs_fs_unfreeze,
1834 1835 1836
	.statfs			= xfs_fs_statfs,
	.remount_fs		= xfs_fs_remount,
	.show_options		= xfs_fs_show_options,
1837 1838
	.nr_cached_objects	= xfs_fs_nr_cached_objects,
	.free_cached_objects	= xfs_fs_free_cached_objects,
L
Linus Torvalds 已提交
1839 1840
};

A
Andrew Morton 已提交
1841
static struct file_system_type xfs_fs_type = {
L
Linus Torvalds 已提交
1842 1843
	.owner			= THIS_MODULE,
	.name			= "xfs",
A
Al Viro 已提交
1844
	.mount			= xfs_fs_mount,
L
Linus Torvalds 已提交
1845 1846 1847
	.kill_sb		= kill_block_super,
	.fs_flags		= FS_REQUIRES_DEV,
};
1848
MODULE_ALIAS_FS("xfs");
L
Linus Torvalds 已提交
1849

1850 1851 1852
STATIC int __init
xfs_init_zones(void)
{
1853
	if (bioset_init(&xfs_ioend_bioset, 4 * (PAGE_SIZE / SECTOR_SIZE),
1854
			offsetof(struct xfs_ioend, io_inline_bio),
1855
			BIOSET_NEED_BVECS))
1856
		goto out;
1857 1858 1859 1860

	xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
						"xfs_log_ticket");
	if (!xfs_log_ticket_zone)
1861
		goto out_free_ioend_bioset;
1862

1863
	xfs_bmap_free_item_zone = kmem_zone_init(
1864
			sizeof(struct xfs_extent_free_item),
1865
			"xfs_bmap_free_item");
1866 1867
	if (!xfs_bmap_free_item_zone)
		goto out_destroy_log_ticket_zone;
1868

1869 1870 1871 1872 1873 1874 1875 1876 1877 1878
	xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
						"xfs_btree_cur");
	if (!xfs_btree_cur_zone)
		goto out_destroy_bmap_free_item_zone;

	xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
						"xfs_da_state");
	if (!xfs_da_state_zone)
		goto out_destroy_btree_cur_zone;

1879
	xfs_ifork_zone = kmem_zone_init(sizeof(struct xfs_ifork), "xfs_ifork");
1880
	if (!xfs_ifork_zone)
1881
		goto out_destroy_da_state_zone;
1882 1883 1884 1885 1886

	xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
	if (!xfs_trans_zone)
		goto out_destroy_ifork_zone;

1887

1888 1889 1890 1891 1892
	/*
	 * The size of the zone allocated buf log item is the maximum
	 * size possible under XFS.  This wastes a little bit of memory,
	 * but it is much faster.
	 */
1893 1894
	xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
					   "xfs_buf_item");
1895
	if (!xfs_buf_item_zone)
1896
		goto out_destroy_trans_zone;
1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911

	xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
			((XFS_EFD_MAX_FAST_EXTENTS - 1) *
				 sizeof(xfs_extent_t))), "xfs_efd_item");
	if (!xfs_efd_zone)
		goto out_destroy_buf_item_zone;

	xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
			((XFS_EFI_MAX_FAST_EXTENTS - 1) *
				sizeof(xfs_extent_t))), "xfs_efi_item");
	if (!xfs_efi_zone)
		goto out_destroy_efd_zone;

	xfs_inode_zone =
		kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
1912 1913
			KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD |
			KM_ZONE_ACCOUNT, xfs_fs_inode_init_once);
1914 1915 1916 1917 1918 1919 1920 1921
	if (!xfs_inode_zone)
		goto out_destroy_efi_zone;

	xfs_ili_zone =
		kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
					KM_ZONE_SPREAD, NULL);
	if (!xfs_ili_zone)
		goto out_destroy_inode_zone;
D
Dave Chinner 已提交
1922 1923 1924 1925
	xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
					"xfs_icr");
	if (!xfs_icreate_zone)
		goto out_destroy_ili_zone;
1926

1927
	xfs_rud_zone = kmem_zone_init(sizeof(struct xfs_rud_log_item),
1928 1929 1930 1931
			"xfs_rud_item");
	if (!xfs_rud_zone)
		goto out_destroy_icreate_zone;

1932 1933
	xfs_rui_zone = kmem_zone_init(
			xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
1934 1935 1936 1937
			"xfs_rui_item");
	if (!xfs_rui_zone)
		goto out_destroy_rud_zone;

1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948
	xfs_cud_zone = kmem_zone_init(sizeof(struct xfs_cud_log_item),
			"xfs_cud_item");
	if (!xfs_cud_zone)
		goto out_destroy_rui_zone;

	xfs_cui_zone = kmem_zone_init(
			xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
			"xfs_cui_item");
	if (!xfs_cui_zone)
		goto out_destroy_cud_zone;

1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959
	xfs_bud_zone = kmem_zone_init(sizeof(struct xfs_bud_log_item),
			"xfs_bud_item");
	if (!xfs_bud_zone)
		goto out_destroy_cui_zone;

	xfs_bui_zone = kmem_zone_init(
			xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
			"xfs_bui_item");
	if (!xfs_bui_zone)
		goto out_destroy_bud_zone;

1960 1961
	return 0;

1962 1963 1964 1965
 out_destroy_bud_zone:
	kmem_zone_destroy(xfs_bud_zone);
 out_destroy_cui_zone:
	kmem_zone_destroy(xfs_cui_zone);
1966 1967 1968 1969
 out_destroy_cud_zone:
	kmem_zone_destroy(xfs_cud_zone);
 out_destroy_rui_zone:
	kmem_zone_destroy(xfs_rui_zone);
1970 1971 1972 1973
 out_destroy_rud_zone:
	kmem_zone_destroy(xfs_rud_zone);
 out_destroy_icreate_zone:
	kmem_zone_destroy(xfs_icreate_zone);
D
Dave Chinner 已提交
1974 1975
 out_destroy_ili_zone:
	kmem_zone_destroy(xfs_ili_zone);
1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995
 out_destroy_inode_zone:
	kmem_zone_destroy(xfs_inode_zone);
 out_destroy_efi_zone:
	kmem_zone_destroy(xfs_efi_zone);
 out_destroy_efd_zone:
	kmem_zone_destroy(xfs_efd_zone);
 out_destroy_buf_item_zone:
	kmem_zone_destroy(xfs_buf_item_zone);
 out_destroy_trans_zone:
	kmem_zone_destroy(xfs_trans_zone);
 out_destroy_ifork_zone:
	kmem_zone_destroy(xfs_ifork_zone);
 out_destroy_da_state_zone:
	kmem_zone_destroy(xfs_da_state_zone);
 out_destroy_btree_cur_zone:
	kmem_zone_destroy(xfs_btree_cur_zone);
 out_destroy_bmap_free_item_zone:
	kmem_zone_destroy(xfs_bmap_free_item_zone);
 out_destroy_log_ticket_zone:
	kmem_zone_destroy(xfs_log_ticket_zone);
1996
 out_free_ioend_bioset:
1997
	bioset_exit(&xfs_ioend_bioset);
1998 1999 2000 2001 2002 2003 2004
 out:
	return -ENOMEM;
}

STATIC void
xfs_destroy_zones(void)
{
2005 2006 2007 2008 2009
	/*
	 * Make sure all delayed rcu free are flushed before we
	 * destroy caches.
	 */
	rcu_barrier();
2010 2011
	kmem_zone_destroy(xfs_bui_zone);
	kmem_zone_destroy(xfs_bud_zone);
2012 2013
	kmem_zone_destroy(xfs_cui_zone);
	kmem_zone_destroy(xfs_cud_zone);
2014 2015
	kmem_zone_destroy(xfs_rui_zone);
	kmem_zone_destroy(xfs_rud_zone);
D
Dave Chinner 已提交
2016
	kmem_zone_destroy(xfs_icreate_zone);
2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027
	kmem_zone_destroy(xfs_ili_zone);
	kmem_zone_destroy(xfs_inode_zone);
	kmem_zone_destroy(xfs_efi_zone);
	kmem_zone_destroy(xfs_efd_zone);
	kmem_zone_destroy(xfs_buf_item_zone);
	kmem_zone_destroy(xfs_trans_zone);
	kmem_zone_destroy(xfs_ifork_zone);
	kmem_zone_destroy(xfs_da_state_zone);
	kmem_zone_destroy(xfs_btree_cur_zone);
	kmem_zone_destroy(xfs_bmap_free_item_zone);
	kmem_zone_destroy(xfs_log_ticket_zone);
2028
	bioset_exit(&xfs_ioend_bioset);
2029
}
L
Linus Torvalds 已提交
2030

2031 2032 2033
STATIC int __init
xfs_init_workqueues(void)
{
2034 2035 2036 2037 2038 2039
	/*
	 * The allocation workqueue can be used in memory reclaim situations
	 * (writepage path), and parallelism is only limited by the number of
	 * AGs in all the filesystems mounted. Hence use the default large
	 * max_active value for this workqueue.
	 */
2040 2041
	xfs_alloc_wq = alloc_workqueue("xfsalloc",
			WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
2042
	if (!xfs_alloc_wq)
D
Dave Chinner 已提交
2043
		return -ENOMEM;
2044

2045 2046 2047 2048
	xfs_discard_wq = alloc_workqueue("xfsdiscard", WQ_UNBOUND, 0);
	if (!xfs_discard_wq)
		goto out_free_alloc_wq;

2049
	return 0;
2050 2051 2052
out_free_alloc_wq:
	destroy_workqueue(xfs_alloc_wq);
	return -ENOMEM;
2053 2054
}

2055
STATIC void
2056 2057
xfs_destroy_workqueues(void)
{
2058
	destroy_workqueue(xfs_discard_wq);
2059
	destroy_workqueue(xfs_alloc_wq);
2060 2061
}

L
Linus Torvalds 已提交
2062
STATIC int __init
2063
init_xfs_fs(void)
L
Linus Torvalds 已提交
2064 2065 2066
{
	int			error;

2067 2068
	xfs_check_ondisk_structs();

2069 2070
	printk(KERN_INFO XFS_VERSION_STRING " with "
			 XFS_BUILD_OPTIONS " enabled\n");
L
Linus Torvalds 已提交
2071

2072
	xfs_dir_startup();
L
Linus Torvalds 已提交
2073

2074
	error = xfs_init_zones();
2075 2076 2077
	if (error)
		goto out;

2078
	error = xfs_init_workqueues();
2079
	if (error)
C
Christoph Hellwig 已提交
2080
		goto out_destroy_zones;
2081

2082 2083 2084 2085
	error = xfs_mru_cache_init();
	if (error)
		goto out_destroy_wq;

2086
	error = xfs_buf_init();
2087
	if (error)
2088
		goto out_mru_cache_uninit;
2089 2090 2091 2092 2093 2094 2095 2096

	error = xfs_init_procfs();
	if (error)
		goto out_buf_terminate;

	error = xfs_sysctl_register();
	if (error)
		goto out_cleanup_procfs;
L
Linus Torvalds 已提交
2097

B
Brian Foster 已提交
2098 2099 2100
	xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
	if (!xfs_kset) {
		error = -ENOMEM;
2101
		goto out_sysctl_unregister;
B
Brian Foster 已提交
2102 2103
	}

2104 2105 2106 2107 2108 2109 2110 2111 2112
	xfsstats.xs_kobj.kobject.kset = xfs_kset;

	xfsstats.xs_stats = alloc_percpu(struct xfsstats);
	if (!xfsstats.xs_stats) {
		error = -ENOMEM;
		goto out_kset_unregister;
	}

	error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
2113 2114
			       "stats");
	if (error)
2115
		goto out_free_stats;
2116

2117 2118 2119
#ifdef DEBUG
	xfs_dbg_kobj.kobject.kset = xfs_kset;
	error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
2120
	if (error)
2121
		goto out_remove_stats_kobj;
2122 2123 2124 2125
#endif

	error = xfs_qm_init();
	if (error)
2126
		goto out_remove_dbg_kobj;
L
Linus Torvalds 已提交
2127 2128 2129

	error = register_filesystem(&xfs_fs_type);
	if (error)
2130
		goto out_qm_exit;
L
Linus Torvalds 已提交
2131 2132
	return 0;

2133 2134
 out_qm_exit:
	xfs_qm_exit();
2135
 out_remove_dbg_kobj:
2136 2137
#ifdef DEBUG
	xfs_sysfs_del(&xfs_dbg_kobj);
2138
 out_remove_stats_kobj:
2139
#endif
2140 2141 2142
	xfs_sysfs_del(&xfsstats.xs_kobj);
 out_free_stats:
	free_percpu(xfsstats.xs_stats);
2143
 out_kset_unregister:
B
Brian Foster 已提交
2144
	kset_unregister(xfs_kset);
2145 2146 2147 2148 2149
 out_sysctl_unregister:
	xfs_sysctl_unregister();
 out_cleanup_procfs:
	xfs_cleanup_procfs();
 out_buf_terminate:
2150
	xfs_buf_terminate();
2151 2152
 out_mru_cache_uninit:
	xfs_mru_cache_uninit();
2153 2154
 out_destroy_wq:
	xfs_destroy_workqueues();
2155
 out_destroy_zones:
2156
	xfs_destroy_zones();
2157
 out:
L
Linus Torvalds 已提交
2158 2159 2160 2161
	return error;
}

STATIC void __exit
2162
exit_xfs_fs(void)
L
Linus Torvalds 已提交
2163
{
2164
	xfs_qm_exit();
L
Linus Torvalds 已提交
2165
	unregister_filesystem(&xfs_fs_type);
2166 2167 2168
#ifdef DEBUG
	xfs_sysfs_del(&xfs_dbg_kobj);
#endif
2169 2170
	xfs_sysfs_del(&xfsstats.xs_kobj);
	free_percpu(xfsstats.xs_stats);
B
Brian Foster 已提交
2171
	kset_unregister(xfs_kset);
2172 2173
	xfs_sysctl_unregister();
	xfs_cleanup_procfs();
2174
	xfs_buf_terminate();
2175
	xfs_mru_cache_uninit();
2176
	xfs_destroy_workqueues();
2177
	xfs_destroy_zones();
2178
	xfs_uuid_table_free();
L
Linus Torvalds 已提交
2179 2180 2181 2182 2183 2184 2185 2186
}

module_init(init_xfs_fs);
module_exit(exit_xfs_fs);

MODULE_AUTHOR("Silicon Graphics, Inc.");
MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
MODULE_LICENSE("GPL");