1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2000-2005 Silicon Graphics, Inc. 4 * All Rights Reserved. 5 */ 6 #ifndef _XFS_PLATFORM_H 7 #define _XFS_PLATFORM_H 8 9 #include <linux/types.h> 10 #include <linux/uuid.h> 11 #include <linux/semaphore.h> 12 #include <linux/mm.h> 13 #include <linux/sched/mm.h> 14 #include <linux/kernel.h> 15 #include <linux/blkdev.h> 16 #include <linux/slab.h> 17 #include <linux/vmalloc.h> 18 #include <linux/crc32c.h> 19 #include <linux/module.h> 20 #include <linux/mutex.h> 21 #include <linux/file.h> 22 #include <linux/filelock.h> 23 #include <linux/swap.h> 24 #include <linux/errno.h> 25 #include <linux/sched/signal.h> 26 #include <linux/bitops.h> 27 #include <linux/major.h> 28 #include <linux/pagemap.h> 29 #include <linux/vfs.h> 30 #include <linux/seq_file.h> 31 #include <linux/init.h> 32 #include <linux/list.h> 33 #include <linux/proc_fs.h> 34 #include <linux/sort.h> 35 #include <linux/cpu.h> 36 #include <linux/notifier.h> 37 #include <linux/delay.h> 38 #include <linux/log2.h> 39 #include <linux/rwsem.h> 40 #include <linux/spinlock.h> 41 #include <linux/random.h> 42 #include <linux/ctype.h> 43 #include <linux/writeback.h> 44 #include <linux/capability.h> 45 #include <linux/kthread.h> 46 #include <linux/freezer.h> 47 #include <linux/list_sort.h> 48 #include <linux/ratelimit.h> 49 #include <linux/rhashtable.h> 50 #include <linux/xattr.h> 51 #include <linux/mnt_idmapping.h> 52 #include <linux/debugfs.h> 53 #include <linux/iversion.h> 54 #include <asm/page.h> 55 #include <asm/div64.h> 56 #include <asm/param.h> 57 #include <linux/uaccess.h> 58 #include <asm/byteorder.h> 59 #include <linux/unaligned.h> 60 61 #ifdef CONFIG_XFS_DEBUG 62 #define DEBUG 1 63 #endif 64 65 #ifdef CONFIG_XFS_DEBUG_EXPENSIVE 66 #define DEBUG_EXPENSIVE 1 67 #endif 68 69 #ifdef CONFIG_XFS_ASSERT_FATAL 70 #define XFS_ASSERT_FATAL 1 71 #endif 72 73 #ifdef CONFIG_XFS_WARN 74 #define XFS_WARN 1 75 #endif 76 77 /* 78 * Kernel specific type declarations for XFS 79 */ 80 typedef __s64 xfs_off_t; /* <file offset> type */ 81 typedef unsigned long long xfs_ino_t; /* <inode> type */ 82 typedef __s64 xfs_daddr_t; /* <disk address> type */ 83 typedef __u32 xfs_dev_t; 84 typedef __u32 xfs_nlink_t; 85 86 #include "xfs_types.h" 87 #include "xfs_fs.h" 88 #include "xfs_stats.h" 89 #include "xfs_sysctl.h" 90 #include "xfs_iops.h" 91 #include "xfs_aops.h" 92 #include "xfs_super.h" 93 #include "xfs_cksum.h" 94 #include "xfs_buf.h" 95 #include "xfs_message.h" 96 #include "xfs_drain.h" 97 #include "xfs_hooks.h" 98 99 #ifdef __BIG_ENDIAN 100 #define XFS_NATIVE_HOST 1 101 #else 102 #undef XFS_NATIVE_HOST 103 #endif 104 105 #define xfs_panic_mask xfs_params.panic_mask.val 106 #define xfs_error_level xfs_params.error_level.val 107 #define xfs_syncd_centisecs xfs_params.syncd_timer.val 108 #define xfs_stats_clear xfs_params.stats_clear.val 109 #define xfs_inherit_sync xfs_params.inherit_sync.val 110 #define xfs_inherit_nodump xfs_params.inherit_nodump.val 111 #define xfs_inherit_noatime xfs_params.inherit_noatim.val 112 #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val 113 #define xfs_rotorstep xfs_params.rotorstep.val 114 #define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val 115 #define xfs_fstrm_centisecs xfs_params.fstrm_timer.val 116 #define xfs_blockgc_secs xfs_params.blockgc_timer.val 117 118 #define current_cpu() (raw_smp_processor_id()) 119 120 #define NBBY 8 /* number of bits per byte */ 121 122 /* 123 * Size of block device i/o is parameterized here. 124 * Currently the system supports page-sized i/o. 125 */ 126 #define BLKDEV_IOSHIFT PAGE_SHIFT 127 #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT) 128 /* number of BB's per block device block */ 129 #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE) 130 131 #define ENOATTR ENODATA /* Attribute not found */ 132 #define EWRONGFS EINVAL /* Mount with wrong filesystem type */ 133 134 #define __return_address __builtin_return_address(0) 135 136 /* 137 * Return the address of a label. Use barrier() so that the optimizer 138 * won't reorder code to refactor the error jumpouts into a single 139 * return, which throws off the reported address. 140 */ 141 #define __this_address ({ __label__ __here; __here: barrier(); &&__here; }) 142 143 #define howmany(x, y) (((x)+((y)-1))/(y)) 144 145 static inline void delay(long ticks) 146 { 147 schedule_timeout_uninterruptible(ticks); 148 } 149 150 /* 151 * XFS wrapper structure for sysfs support. It depends on external data 152 * structures and is embedded in various internal data structures to implement 153 * the XFS sysfs object hierarchy. Define it here for broad access throughout 154 * the codebase. 155 */ 156 struct xfs_kobj { 157 struct kobject kobject; 158 struct completion complete; 159 }; 160 161 struct xstats { 162 struct xfsstats __percpu *xs_stats; 163 struct xfs_kobj xs_kobj; 164 }; 165 166 extern struct xstats xfsstats; 167 168 static inline dev_t xfs_to_linux_dev_t(xfs_dev_t dev) 169 { 170 return MKDEV(sysv_major(dev) & 0x1ff, sysv_minor(dev)); 171 } 172 173 static inline xfs_dev_t linux_to_xfs_dev_t(dev_t dev) 174 { 175 return sysv_encode_dev(dev); 176 } 177 178 /* 179 * Various platform dependent calls that don't fit anywhere else 180 */ 181 #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL) 182 #define xfs_stack_trace() dump_stack() 183 184 static inline uint64_t rounddown_64(uint64_t x, uint32_t y) 185 { 186 do_div(x, y); 187 return x * y; 188 } 189 190 static inline uint64_t roundup_64(uint64_t x, uint32_t y) 191 { 192 x += y - 1; 193 do_div(x, y); 194 return x * y; 195 } 196 197 static inline uint64_t howmany_64(uint64_t x, uint32_t y) 198 { 199 x += y - 1; 200 do_div(x, y); 201 return x; 202 } 203 204 static inline bool isaligned_64(uint64_t x, uint32_t y) 205 { 206 return do_div(x, y) == 0; 207 } 208 209 /* If @b is a power of 2, return log2(b). Else return -1. */ 210 static inline int8_t log2_if_power2(unsigned long b) 211 { 212 return is_power_of_2(b) ? ilog2(b) : -1; 213 } 214 215 /* If @b is a power of 2, return a mask of the lower bits, else return zero. */ 216 static inline unsigned long long mask64_if_power2(unsigned long b) 217 { 218 return is_power_of_2(b) ? b - 1 : 0; 219 } 220 221 int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count, 222 char *data, enum req_op op); 223 224 #define ASSERT_ALWAYS(expr) \ 225 (likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__)) 226 227 #ifdef DEBUG 228 #define ASSERT(expr) \ 229 (likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__)) 230 231 #else /* !DEBUG */ 232 233 #ifdef XFS_WARN 234 235 /* 236 * Please note that this ASSERT doesn't kill the kernel. It will if the kernel 237 * has panic_on_warn set. 238 */ 239 #define ASSERT(expr) \ 240 (likely(expr) ? (void)0 : asswarn(NULL, #expr, __FILE__, __LINE__)) 241 242 #else /* !DEBUG && !XFS_WARN */ 243 244 #define ASSERT(expr) ((void)0) 245 246 #endif /* XFS_WARN */ 247 #endif /* DEBUG */ 248 249 /* 250 * Use this to catch metadata corruptions that are not caught by block or 251 * structure verifiers. The reason is that the verifiers check corruptions only 252 * within the scope of the object being verified. 253 */ 254 #define XFS_IS_CORRUPT(mp, expr) \ 255 (unlikely(expr) ? xfs_corruption_error(#expr, XFS_ERRLEVEL_LOW, (mp), \ 256 NULL, 0, __FILE__, __LINE__, \ 257 __this_address), \ 258 true : false) 259 260 #define STATIC static noinline 261 262 #ifdef CONFIG_XFS_RT 263 264 /* 265 * make sure we ignore the inode flag if the filesystem doesn't have a 266 * configured realtime device. 267 */ 268 #define XFS_IS_REALTIME_INODE(ip) \ 269 (((ip)->i_diflags & XFS_DIFLAG_REALTIME) && \ 270 (ip)->i_mount->m_rtdev_targp) 271 #define XFS_IS_REALTIME_MOUNT(mp) ((mp)->m_rtdev_targp ? 1 : 0) 272 #else 273 #define XFS_IS_REALTIME_INODE(ip) (0) 274 #define XFS_IS_REALTIME_MOUNT(mp) (0) 275 #endif 276 277 /* 278 * Starting in Linux 4.15, the %p (raw pointer value) printk modifier 279 * prints a hashed version of the pointer to avoid leaking kernel 280 * pointers into dmesg. If we're trying to debug the kernel we want the 281 * raw values, so override this behavior as best we can. 282 */ 283 #ifdef DEBUG 284 # define PTR_FMT "%px" 285 #else 286 # define PTR_FMT "%p" 287 #endif 288 289 #endif /* _XFS_PLATFORM_H */ 290