xfs_linux.h 6.5 KB
Newer Older
D
Dave Chinner 已提交
1
// SPDX-License-Identifier: GPL-2.0
L
Linus Torvalds 已提交
2
/*
3 4
 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
 * All Rights Reserved.
L
Linus Torvalds 已提交
5 6 7 8 9
 */
#ifndef __XFS_LINUX__
#define __XFS_LINUX__

#include <linux/types.h>
10
#include <linux/uuid.h>
L
Linus Torvalds 已提交
11

12 13 14 15 16 17 18 19 20 21
/*
 * Kernel specific type declarations for XFS
 */

typedef __s64			xfs_off_t;	/* <file offset> type */
typedef unsigned long long	xfs_ino_t;	/* <inode> type */
typedef __s64			xfs_daddr_t;	/* <disk address> type */
typedef __u32			xfs_dev_t;
typedef __u32			xfs_nlink_t;

22
#include "xfs_types.h"
L
Linus Torvalds 已提交
23

24 25
#include "kmem.h"
#include "mrlock.h"
L
Linus Torvalds 已提交
26

27
#include <linux/semaphore.h>
L
Linus Torvalds 已提交
28
#include <linux/mm.h>
29
#include <linux/sched/mm.h>
L
Linus Torvalds 已提交
30 31 32
#include <linux/kernel.h>
#include <linux/blkdev.h>
#include <linux/slab.h>
C
Christoph Hellwig 已提交
33
#include <linux/crc32c.h>
L
Linus Torvalds 已提交
34
#include <linux/module.h>
C
Christoph Hellwig 已提交
35
#include <linux/mutex.h>
L
Linus Torvalds 已提交
36 37 38
#include <linux/file.h>
#include <linux/swap.h>
#include <linux/errno.h>
39
#include <linux/sched/signal.h>
L
Linus Torvalds 已提交
40 41 42 43 44 45 46 47 48
#include <linux/bitops.h>
#include <linux/major.h>
#include <linux/pagemap.h>
#include <linux/vfs.h>
#include <linux/seq_file.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/proc_fs.h>
#include <linux/sort.h>
49 50
#include <linux/cpu.h>
#include <linux/notifier.h>
51
#include <linux/delay.h>
52
#include <linux/log2.h>
E
Eric Sandeen 已提交
53
#include <linux/spinlock.h>
54
#include <linux/random.h>
55
#include <linux/ctype.h>
56
#include <linux/writeback.h>
C
Christoph Hellwig 已提交
57
#include <linux/capability.h>
58 59
#include <linux/kthread.h>
#include <linux/freezer.h>
60
#include <linux/list_sort.h>
61
#include <linux/ratelimit.h>
62
#include <linux/rhashtable.h>
63
#include <linux/xattr.h>
L
Linus Torvalds 已提交
64 65 66 67

#include <asm/page.h>
#include <asm/div64.h>
#include <asm/param.h>
68
#include <linux/uaccess.h>
L
Linus Torvalds 已提交
69 70 71
#include <asm/byteorder.h>
#include <asm/unaligned.h>

D
Dave Chinner 已提交
72
#include "xfs_fs.h"
73 74 75 76 77
#include "xfs_stats.h"
#include "xfs_sysctl.h"
#include "xfs_iops.h"
#include "xfs_aops.h"
#include "xfs_super.h"
78
#include "xfs_cksum.h"
79 80
#include "xfs_buf.h"
#include "xfs_message.h"
L
Linus Torvalds 已提交
81

82 83 84 85 86 87
#ifdef __BIG_ENDIAN
#define XFS_NATIVE_HOST 1
#else
#undef XFS_NATIVE_HOST
#endif

L
Linus Torvalds 已提交
88 89 90 91 92 93 94 95 96 97 98
#define irix_sgid_inherit	xfs_params.sgid_inherit.val
#define irix_symlink_mode	xfs_params.symlink_mode.val
#define xfs_panic_mask		xfs_params.panic_mask.val
#define xfs_error_level		xfs_params.error_level.val
#define xfs_syncd_centisecs	xfs_params.syncd_timer.val
#define xfs_stats_clear		xfs_params.stats_clear.val
#define xfs_inherit_sync	xfs_params.inherit_sync.val
#define xfs_inherit_nodump	xfs_params.inherit_nodump.val
#define xfs_inherit_noatime	xfs_params.inherit_noatim.val
#define xfs_inherit_nosymlinks	xfs_params.inherit_nosym.val
#define xfs_rotorstep		xfs_params.rotorstep.val
99
#define xfs_inherit_nodefrag	xfs_params.inherit_nodfrg.val
100
#define xfs_fstrm_centisecs	xfs_params.fstrm_timer.val
101
#define xfs_eofb_secs		xfs_params.eofb_timer.val
102
#define xfs_cowb_secs		xfs_params.cowb_timer.val
L
Linus Torvalds 已提交
103

104 105 106 107 108
#define current_cpu()		(raw_smp_processor_id())
#define current_set_flags_nested(sp, f)		\
		(*(sp) = current->flags, current->flags |= (f))
#define current_restore_flags_nested(sp, f)	\
		(current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
L
Linus Torvalds 已提交
109 110 111 112 113 114 115

#define NBBY		8		/* number of bits per byte */

/*
 * Size of block device i/o is parameterized here.
 * Currently the system supports page-sized i/o.
 */
116
#define	BLKDEV_IOSHIFT		PAGE_SHIFT
L
Linus Torvalds 已提交
117 118 119 120 121
#define	BLKDEV_IOSIZE		(1<<BLKDEV_IOSHIFT)
/* number of BB's per block device block */
#define	BLKDEV_BB		BTOBB(BLKDEV_IOSIZE)

#define ENOATTR		ENODATA		/* Attribute not found */
122 123
#define EWRONGFS	EINVAL		/* Mount with wrong filesystem type */
#define EFSCORRUPTED	EUCLEAN		/* Filesystem is corrupted */
E
Eric Sandeen 已提交
124
#define EFSBADCRC	EBADMSG		/* Bad CRC detected */
L
Linus Torvalds 已提交
125 126 127 128

#define SYNCHRONIZE()	barrier()
#define __return_address __builtin_return_address(0)

129 130 131 132 133 134 135
/*
 * Return the address of a label.  Use barrier() so that the optimizer
 * won't reorder code to refactor the error jumpouts into a single
 * return, which throws off the reported address.
 */
#define __this_address	({ __label__ __here; __here: barrier(); &&__here; })

136
#define XFS_PROJID_DEFAULT	0
L
Linus Torvalds 已提交
137 138 139

#define howmany(x, y)	(((x)+((y)-1))/(y))

D
Dave Chinner 已提交
140 141 142 143 144
static inline void delay(long ticks)
{
	schedule_timeout_uninterruptible(ticks);
}

B
Brian Foster 已提交
145 146 147 148 149 150 151 152 153 154 155
/*
 * XFS wrapper structure for sysfs support. It depends on external data
 * structures and is embedded in various internal data structures to implement
 * the XFS sysfs object heirarchy. Define it here for broad access throughout
 * the codebase.
 */
struct xfs_kobj {
	struct kobject		kobject;
	struct completion	complete;
};

156 157 158 159 160 161 162
struct xstats {
	struct xfsstats __percpu	*xs_stats;
	struct xfs_kobj			xs_kobj;
};

extern struct xstats xfsstats;

163 164 165 166 167 168 169 170 171 172
static inline dev_t xfs_to_linux_dev_t(xfs_dev_t dev)
{
	return MKDEV(sysv_major(dev) & 0x1ff, sysv_minor(dev));
}

static inline xfs_dev_t linux_to_xfs_dev_t(dev_t dev)
{
	return sysv_encode_dev(dev);
}

173 174 175
/*
 * Various platform dependent calls that don't fit anywhere else
 */
176
#define xfs_sort(a,n,s,fn)	sort(a,n,s,fn,NULL)
L
Linus Torvalds 已提交
177 178
#define xfs_stack_trace()	dump_stack()

179
static inline uint64_t roundup_64(uint64_t x, uint32_t y)
L
Linus Torvalds 已提交
180 181 182
{
	x += y - 1;
	do_div(x, y);
E
Eric Sandeen 已提交
183
	return x * y;
L
Linus Torvalds 已提交
184 185
}

186
static inline uint64_t howmany_64(uint64_t x, uint32_t y)
187 188 189 190 191 192
{
	x += y - 1;
	do_div(x, y);
	return x;
}

193 194 195
int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
		char *data, unsigned int op);

D
Dave Chinner 已提交
196
#define ASSERT_ALWAYS(expr)	\
197
	(likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__))
D
Dave Chinner 已提交
198

D
Dave Chinner 已提交
199 200
#ifdef DEBUG
#define ASSERT(expr)	\
201
	(likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__))
D
Dave Chinner 已提交
202

D
Dave Chinner 已提交
203 204 205
#else	/* !DEBUG */

#ifdef XFS_WARN
D
Dave Chinner 已提交
206 207

#define ASSERT(expr)	\
208
	(likely(expr) ? (void)0 : asswarn(NULL, #expr, __FILE__, __LINE__))
D
Dave Chinner 已提交
209

D
Dave Chinner 已提交
210 211
#else	/* !DEBUG && !XFS_WARN */

D
Darrick J. Wong 已提交
212
#define ASSERT(expr)		((void)0)
D
Dave Chinner 已提交
213 214

#endif /* XFS_WARN */
D
Dave Chinner 已提交
215 216
#endif /* DEBUG */

217 218 219 220 221 222
#define XFS_IS_CORRUPT(mp, expr)	\
	(unlikely(expr) ? xfs_corruption_error(#expr, XFS_ERRLEVEL_LOW, (mp), \
					       NULL, 0, __FILE__, __LINE__, \
					       __this_address), \
			  true : false)

223 224
#define STATIC static noinline

225
#ifdef CONFIG_XFS_RT
226 227 228 229 230 231 232 233

/*
 * make sure we ignore the inode flag if the filesystem doesn't have a
 * configured realtime device.
 */
#define XFS_IS_REALTIME_INODE(ip)			\
	(((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME) &&	\
	 (ip)->i_mount->m_rtdev_targp)
234
#define XFS_IS_REALTIME_MOUNT(mp) ((mp)->m_rtdev_targp ? 1 : 0)
235 236
#else
#define XFS_IS_REALTIME_INODE(ip) (0)
237
#define XFS_IS_REALTIME_MOUNT(mp) (0)
238 239
#endif

240 241 242 243 244 245 246 247 248 249 250 251
/*
 * Starting in Linux 4.15, the %p (raw pointer value) printk modifier
 * prints a hashed version of the pointer to avoid leaking kernel
 * pointers into dmesg.  If we're trying to debug the kernel we want the
 * raw values, so override this behavior as best we can.
 */
#ifdef DEBUG
# define PTR_FMT "%px"
#else
# define PTR_FMT "%p"
#endif

L
Linus Torvalds 已提交
252
#endif /* __XFS_LINUX__ */