xfs_linux.h 7.3 KB

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