xfs_vnode.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef __XFS_VNODE_H__
  19. #define __XFS_VNODE_H__
  20. struct file;
  21. struct bhv_vattr;
  22. struct xfs_iomap;
  23. struct attrlist_cursor_kern;
  24. typedef struct inode bhv_vnode_t;
  25. /*
  26. * Vnode to Linux inode mapping.
  27. */
  28. static inline bhv_vnode_t *vn_from_inode(struct inode *inode)
  29. {
  30. return inode;
  31. }
  32. static inline struct inode *vn_to_inode(bhv_vnode_t *vnode)
  33. {
  34. return vnode;
  35. }
  36. /*
  37. * Return values for xfs_inactive. A return value of
  38. * VN_INACTIVE_NOCACHE implies that the file system behavior
  39. * has disassociated its state and bhv_desc_t from the vnode.
  40. */
  41. #define VN_INACTIVE_CACHE 0
  42. #define VN_INACTIVE_NOCACHE 1
  43. /*
  44. * Flags for read/write calls - same values as IRIX
  45. */
  46. #define IO_ISAIO 0x00001 /* don't wait for completion */
  47. #define IO_ISDIRECT 0x00004 /* bypass page cache */
  48. #define IO_INVIS 0x00020 /* don't update inode timestamps */
  49. /*
  50. * Flags for xfs_inode_flush
  51. */
  52. #define FLUSH_SYNC 1 /* wait for flush to complete */
  53. /*
  54. * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
  55. */
  56. #define FI_NONE 0 /* none */
  57. #define FI_REMAPF 1 /* Do a remapf prior to the operation */
  58. #define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
  59. Prevent VM access to the pages until
  60. the operation completes. */
  61. /*
  62. * Vnode attributes. va_mask indicates those attributes the caller
  63. * wants to set or extract.
  64. */
  65. typedef struct bhv_vattr {
  66. int va_mask; /* bit-mask of attributes present */
  67. mode_t va_mode; /* file access mode and type */
  68. xfs_nlink_t va_nlink; /* number of references to file */
  69. uid_t va_uid; /* owner user id */
  70. gid_t va_gid; /* owner group id */
  71. xfs_ino_t va_nodeid; /* file id */
  72. xfs_off_t va_size; /* file size in bytes */
  73. u_long va_blocksize; /* blocksize preferred for i/o */
  74. struct timespec va_atime; /* time of last access */
  75. struct timespec va_mtime; /* time of last modification */
  76. struct timespec va_ctime; /* time file changed */
  77. u_int va_gen; /* generation number of file */
  78. xfs_dev_t va_rdev; /* device the special file represents */
  79. __int64_t va_nblocks; /* number of blocks allocated */
  80. u_long va_xflags; /* random extended file flags */
  81. u_long va_extsize; /* file extent size */
  82. u_long va_nextents; /* number of extents in file */
  83. u_long va_anextents; /* number of attr extents in file */
  84. prid_t va_projid; /* project id */
  85. } bhv_vattr_t;
  86. /*
  87. * setattr or getattr attributes
  88. */
  89. #define XFS_AT_TYPE 0x00000001
  90. #define XFS_AT_MODE 0x00000002
  91. #define XFS_AT_UID 0x00000004
  92. #define XFS_AT_GID 0x00000008
  93. #define XFS_AT_FSID 0x00000010
  94. #define XFS_AT_NODEID 0x00000020
  95. #define XFS_AT_NLINK 0x00000040
  96. #define XFS_AT_SIZE 0x00000080
  97. #define XFS_AT_ATIME 0x00000100
  98. #define XFS_AT_MTIME 0x00000200
  99. #define XFS_AT_CTIME 0x00000400
  100. #define XFS_AT_RDEV 0x00000800
  101. #define XFS_AT_BLKSIZE 0x00001000
  102. #define XFS_AT_NBLOCKS 0x00002000
  103. #define XFS_AT_VCODE 0x00004000
  104. #define XFS_AT_MAC 0x00008000
  105. #define XFS_AT_UPDATIME 0x00010000
  106. #define XFS_AT_UPDMTIME 0x00020000
  107. #define XFS_AT_UPDCTIME 0x00040000
  108. #define XFS_AT_ACL 0x00080000
  109. #define XFS_AT_CAP 0x00100000
  110. #define XFS_AT_INF 0x00200000
  111. #define XFS_AT_NEXTENTS 0x01000000
  112. #define XFS_AT_ANEXTENTS 0x02000000
  113. #define XFS_AT_SIZE_NOPERM 0x08000000
  114. #define XFS_AT_GENCOUNT 0x10000000
  115. #define XFS_AT_TIMES (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
  116. #define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
  117. #define XFS_AT_NOSET (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
  118. XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
  119. XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
  120. extern void vn_init(void);
  121. extern int vn_revalidate(bhv_vnode_t *);
  122. /*
  123. * Yeah, these don't take vnode anymore at all, all this should be
  124. * cleaned up at some point.
  125. */
  126. extern void vn_iowait(struct xfs_inode *ip);
  127. extern void vn_iowake(struct xfs_inode *ip);
  128. extern void vn_ioerror(struct xfs_inode *ip, int error, char *f, int l);
  129. static inline int vn_count(bhv_vnode_t *vp)
  130. {
  131. return atomic_read(&vn_to_inode(vp)->i_count);
  132. }
  133. /*
  134. * Vnode reference counting functions (and macros for compatibility).
  135. */
  136. extern bhv_vnode_t *vn_hold(bhv_vnode_t *);
  137. #if defined(XFS_INODE_TRACE)
  138. #define VN_HOLD(vp) \
  139. ((void)vn_hold(vp), \
  140. xfs_itrace_hold(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address))
  141. #define VN_RELE(vp) \
  142. (xfs_itrace_rele(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address), \
  143. iput(vn_to_inode(vp)))
  144. #else
  145. #define VN_HOLD(vp) ((void)vn_hold(vp))
  146. #define VN_RELE(vp) (iput(vn_to_inode(vp)))
  147. #endif
  148. static inline bhv_vnode_t *vn_grab(bhv_vnode_t *vp)
  149. {
  150. struct inode *inode = igrab(vn_to_inode(vp));
  151. return inode ? vn_from_inode(inode) : NULL;
  152. }
  153. /*
  154. * Dealing with bad inodes
  155. */
  156. static inline int VN_BAD(bhv_vnode_t *vp)
  157. {
  158. return is_bad_inode(vn_to_inode(vp));
  159. }
  160. /*
  161. * Extracting atime values in various formats
  162. */
  163. static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
  164. {
  165. bs_atime->tv_sec = vp->i_atime.tv_sec;
  166. bs_atime->tv_nsec = vp->i_atime.tv_nsec;
  167. }
  168. static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
  169. {
  170. *ts = vp->i_atime;
  171. }
  172. static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
  173. {
  174. *tt = vp->i_atime.tv_sec;
  175. }
  176. /*
  177. * Some useful predicates.
  178. */
  179. #define VN_MAPPED(vp) mapping_mapped(vn_to_inode(vp)->i_mapping)
  180. #define VN_CACHED(vp) (vn_to_inode(vp)->i_mapping->nrpages)
  181. #define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \
  182. PAGECACHE_TAG_DIRTY)
  183. /*
  184. * Flags to vop_setattr/getattr.
  185. */
  186. #define ATTR_UTIME 0x01 /* non-default utime(2) request */
  187. #define ATTR_DMI 0x08 /* invocation from a DMI function */
  188. #define ATTR_LAZY 0x80 /* set/get attributes lazily */
  189. #define ATTR_NONBLOCK 0x100 /* return EAGAIN if operation would block */
  190. #define ATTR_NOLOCK 0x200 /* Don't grab any conflicting locks */
  191. #define ATTR_NOSIZETOK 0x400 /* Don't get the SIZE token */
  192. /*
  193. * Tracking vnode activity.
  194. */
  195. #if defined(XFS_INODE_TRACE)
  196. #define INODE_TRACE_SIZE 16 /* number of trace entries */
  197. #define INODE_KTRACE_ENTRY 1
  198. #define INODE_KTRACE_EXIT 2
  199. #define INODE_KTRACE_HOLD 3
  200. #define INODE_KTRACE_REF 4
  201. #define INODE_KTRACE_RELE 5
  202. extern void _xfs_itrace_entry(struct xfs_inode *, const char *, inst_t *);
  203. extern void _xfs_itrace_exit(struct xfs_inode *, const char *, inst_t *);
  204. extern void xfs_itrace_hold(struct xfs_inode *, char *, int, inst_t *);
  205. extern void _xfs_itrace_ref(struct xfs_inode *, char *, int, inst_t *);
  206. extern void xfs_itrace_rele(struct xfs_inode *, char *, int, inst_t *);
  207. #define xfs_itrace_entry(ip) \
  208. _xfs_itrace_entry(ip, __func__, (inst_t *)__return_address)
  209. #define xfs_itrace_exit(ip) \
  210. _xfs_itrace_exit(ip, __func__, (inst_t *)__return_address)
  211. #define xfs_itrace_exit_tag(ip, tag) \
  212. _xfs_itrace_exit(ip, tag, (inst_t *)__return_address)
  213. #define xfs_itrace_ref(ip) \
  214. _xfs_itrace_ref(ip, __FILE__, __LINE__, (inst_t *)__return_address)
  215. #else
  216. #define xfs_itrace_entry(a)
  217. #define xfs_itrace_exit(a)
  218. #define xfs_itrace_exit_tag(a, b)
  219. #define xfs_itrace_hold(a, b, c, d)
  220. #define xfs_itrace_ref(a)
  221. #define xfs_itrace_rele(a, b, c, d)
  222. #endif
  223. #endif /* __XFS_VNODE_H__ */