xfs_vnode.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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_vfs;
  22. struct bhv_vattr;
  23. struct xfs_iomap;
  24. struct attrlist_cursor_kern;
  25. typedef struct dentry bhv_vname_t;
  26. typedef __u64 bhv_vnumber_t;
  27. typedef struct inode bhv_vnode_t;
  28. #define VN_ISLNK(vp) S_ISLNK((vp)->i_mode)
  29. #define VN_ISREG(vp) S_ISREG((vp)->i_mode)
  30. #define VN_ISDIR(vp) S_ISDIR((vp)->i_mode)
  31. #define VN_ISCHR(vp) S_ISCHR((vp)->i_mode)
  32. #define VN_ISBLK(vp) S_ISBLK((vp)->i_mode)
  33. /*
  34. * Vnode to Linux inode mapping.
  35. */
  36. static inline bhv_vnode_t *vn_from_inode(struct inode *inode)
  37. {
  38. return inode;
  39. }
  40. static inline struct inode *vn_to_inode(bhv_vnode_t *vnode)
  41. {
  42. return vnode;
  43. }
  44. /*
  45. * Values for the vop_rwlock/rwunlock flags parameter.
  46. */
  47. typedef enum bhv_vrwlock {
  48. VRWLOCK_NONE,
  49. VRWLOCK_READ,
  50. VRWLOCK_WRITE,
  51. VRWLOCK_WRITE_DIRECT,
  52. VRWLOCK_TRY_READ,
  53. VRWLOCK_TRY_WRITE
  54. } bhv_vrwlock_t;
  55. /*
  56. * Return values for xfs_inactive. A return value of
  57. * VN_INACTIVE_NOCACHE implies that the file system behavior
  58. * has disassociated its state and bhv_desc_t from the vnode.
  59. */
  60. #define VN_INACTIVE_CACHE 0
  61. #define VN_INACTIVE_NOCACHE 1
  62. /*
  63. * Flags for read/write calls - same values as IRIX
  64. */
  65. #define IO_ISAIO 0x00001 /* don't wait for completion */
  66. #define IO_ISDIRECT 0x00004 /* bypass page cache */
  67. #define IO_INVIS 0x00020 /* don't update inode timestamps */
  68. /*
  69. * Flags for vop_iflush call
  70. */
  71. #define FLUSH_SYNC 1 /* wait for flush to complete */
  72. #define FLUSH_INODE 2 /* flush the inode itself */
  73. #define FLUSH_LOG 4 /* force the last log entry for
  74. * this inode out to disk */
  75. /*
  76. * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
  77. */
  78. #define FI_NONE 0 /* none */
  79. #define FI_REMAPF 1 /* Do a remapf prior to the operation */
  80. #define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
  81. Prevent VM access to the pages until
  82. the operation completes. */
  83. /*
  84. * Vnode attributes. va_mask indicates those attributes the caller
  85. * wants to set or extract.
  86. */
  87. typedef struct bhv_vattr {
  88. int va_mask; /* bit-mask of attributes present */
  89. mode_t va_mode; /* file access mode and type */
  90. xfs_nlink_t va_nlink; /* number of references to file */
  91. uid_t va_uid; /* owner user id */
  92. gid_t va_gid; /* owner group id */
  93. xfs_ino_t va_nodeid; /* file id */
  94. xfs_off_t va_size; /* file size in bytes */
  95. u_long va_blocksize; /* blocksize preferred for i/o */
  96. struct timespec va_atime; /* time of last access */
  97. struct timespec va_mtime; /* time of last modification */
  98. struct timespec va_ctime; /* time file changed */
  99. u_int va_gen; /* generation number of file */
  100. xfs_dev_t va_rdev; /* device the special file represents */
  101. __int64_t va_nblocks; /* number of blocks allocated */
  102. u_long va_xflags; /* random extended file flags */
  103. u_long va_extsize; /* file extent size */
  104. u_long va_nextents; /* number of extents in file */
  105. u_long va_anextents; /* number of attr extents in file */
  106. prid_t va_projid; /* project id */
  107. } bhv_vattr_t;
  108. /*
  109. * setattr or getattr attributes
  110. */
  111. #define XFS_AT_TYPE 0x00000001
  112. #define XFS_AT_MODE 0x00000002
  113. #define XFS_AT_UID 0x00000004
  114. #define XFS_AT_GID 0x00000008
  115. #define XFS_AT_FSID 0x00000010
  116. #define XFS_AT_NODEID 0x00000020
  117. #define XFS_AT_NLINK 0x00000040
  118. #define XFS_AT_SIZE 0x00000080
  119. #define XFS_AT_ATIME 0x00000100
  120. #define XFS_AT_MTIME 0x00000200
  121. #define XFS_AT_CTIME 0x00000400
  122. #define XFS_AT_RDEV 0x00000800
  123. #define XFS_AT_BLKSIZE 0x00001000
  124. #define XFS_AT_NBLOCKS 0x00002000
  125. #define XFS_AT_VCODE 0x00004000
  126. #define XFS_AT_MAC 0x00008000
  127. #define XFS_AT_UPDATIME 0x00010000
  128. #define XFS_AT_UPDMTIME 0x00020000
  129. #define XFS_AT_UPDCTIME 0x00040000
  130. #define XFS_AT_ACL 0x00080000
  131. #define XFS_AT_CAP 0x00100000
  132. #define XFS_AT_INF 0x00200000
  133. #define XFS_AT_XFLAGS 0x00400000
  134. #define XFS_AT_EXTSIZE 0x00800000
  135. #define XFS_AT_NEXTENTS 0x01000000
  136. #define XFS_AT_ANEXTENTS 0x02000000
  137. #define XFS_AT_PROJID 0x04000000
  138. #define XFS_AT_SIZE_NOPERM 0x08000000
  139. #define XFS_AT_GENCOUNT 0x10000000
  140. #define XFS_AT_ALL (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
  141. XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
  142. XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
  143. XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
  144. XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
  145. XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
  146. #define XFS_AT_STAT (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
  147. XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
  148. XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
  149. XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
  150. #define XFS_AT_TIMES (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
  151. #define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
  152. #define XFS_AT_NOSET (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
  153. XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
  154. XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
  155. /*
  156. * Modes.
  157. */
  158. #define VSUID S_ISUID /* set user id on execution */
  159. #define VSGID S_ISGID /* set group id on execution */
  160. #define VSVTX S_ISVTX /* save swapped text even after use */
  161. #define VREAD S_IRUSR /* read, write, execute permissions */
  162. #define VWRITE S_IWUSR
  163. #define VEXEC S_IXUSR
  164. #define MODEMASK S_IALLUGO /* mode bits plus permission bits */
  165. /*
  166. * Check whether mandatory file locking is enabled.
  167. */
  168. #define MANDLOCK(vp, mode) \
  169. (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
  170. extern void vn_init(void);
  171. extern bhv_vnode_t *vn_initialize(struct inode *);
  172. extern int vn_revalidate(bhv_vnode_t *);
  173. extern int __vn_revalidate(bhv_vnode_t *, bhv_vattr_t *);
  174. extern void vn_revalidate_core(bhv_vnode_t *, bhv_vattr_t *);
  175. /*
  176. * Yeah, these don't take vnode anymore at all, all this should be
  177. * cleaned up at some point.
  178. */
  179. extern void vn_iowait(struct xfs_inode *ip);
  180. extern void vn_iowake(struct xfs_inode *ip);
  181. extern void vn_ioerror(struct xfs_inode *ip, int error, char *f, int l);
  182. static inline int vn_count(bhv_vnode_t *vp)
  183. {
  184. return atomic_read(&vn_to_inode(vp)->i_count);
  185. }
  186. /*
  187. * Vnode reference counting functions (and macros for compatibility).
  188. */
  189. extern bhv_vnode_t *vn_hold(bhv_vnode_t *);
  190. #if defined(XFS_VNODE_TRACE)
  191. #define VN_HOLD(vp) \
  192. ((void)vn_hold(vp), \
  193. vn_trace_hold(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address))
  194. #define VN_RELE(vp) \
  195. (vn_trace_rele(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address), \
  196. iput(vn_to_inode(vp)))
  197. #else
  198. #define VN_HOLD(vp) ((void)vn_hold(vp))
  199. #define VN_RELE(vp) (iput(vn_to_inode(vp)))
  200. #endif
  201. static inline bhv_vnode_t *vn_grab(bhv_vnode_t *vp)
  202. {
  203. struct inode *inode = igrab(vn_to_inode(vp));
  204. return inode ? vn_from_inode(inode) : NULL;
  205. }
  206. /*
  207. * Vname handling macros.
  208. */
  209. #define VNAME(dentry) ((char *) (dentry)->d_name.name)
  210. #define VNAMELEN(dentry) ((dentry)->d_name.len)
  211. #define VNAME_TO_VNODE(dentry) (vn_from_inode((dentry)->d_inode))
  212. /*
  213. * Dealing with bad inodes
  214. */
  215. static inline void vn_mark_bad(bhv_vnode_t *vp)
  216. {
  217. make_bad_inode(vn_to_inode(vp));
  218. }
  219. static inline int VN_BAD(bhv_vnode_t *vp)
  220. {
  221. return is_bad_inode(vn_to_inode(vp));
  222. }
  223. /*
  224. * Extracting atime values in various formats
  225. */
  226. static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
  227. {
  228. bs_atime->tv_sec = vp->i_atime.tv_sec;
  229. bs_atime->tv_nsec = vp->i_atime.tv_nsec;
  230. }
  231. static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
  232. {
  233. *ts = vp->i_atime;
  234. }
  235. static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
  236. {
  237. *tt = vp->i_atime.tv_sec;
  238. }
  239. /*
  240. * Some useful predicates.
  241. */
  242. #define VN_MAPPED(vp) mapping_mapped(vn_to_inode(vp)->i_mapping)
  243. #define VN_CACHED(vp) (vn_to_inode(vp)->i_mapping->nrpages)
  244. #define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \
  245. PAGECACHE_TAG_DIRTY)
  246. /*
  247. * Flags to vop_setattr/getattr.
  248. */
  249. #define ATTR_UTIME 0x01 /* non-default utime(2) request */
  250. #define ATTR_DMI 0x08 /* invocation from a DMI function */
  251. #define ATTR_LAZY 0x80 /* set/get attributes lazily */
  252. #define ATTR_NONBLOCK 0x100 /* return EAGAIN if operation would block */
  253. #define ATTR_NOLOCK 0x200 /* Don't grab any conflicting locks */
  254. #define ATTR_NOSIZETOK 0x400 /* Don't get the SIZE token */
  255. /*
  256. * Flags to vop_fsync/reclaim.
  257. */
  258. #define FSYNC_NOWAIT 0 /* asynchronous flush */
  259. #define FSYNC_WAIT 0x1 /* synchronous fsync or forced reclaim */
  260. #define FSYNC_INVAL 0x2 /* flush and invalidate cached data */
  261. #define FSYNC_DATA 0x4 /* synchronous fsync of data only */
  262. /*
  263. * Tracking vnode activity.
  264. */
  265. #if defined(XFS_VNODE_TRACE)
  266. #define VNODE_TRACE_SIZE 16 /* number of trace entries */
  267. #define VNODE_KTRACE_ENTRY 1
  268. #define VNODE_KTRACE_EXIT 2
  269. #define VNODE_KTRACE_HOLD 3
  270. #define VNODE_KTRACE_REF 4
  271. #define VNODE_KTRACE_RELE 5
  272. extern void vn_trace_entry(struct xfs_inode *, const char *, inst_t *);
  273. extern void vn_trace_exit(struct xfs_inode *, const char *, inst_t *);
  274. extern void vn_trace_hold(struct xfs_inode *, char *, int, inst_t *);
  275. extern void vn_trace_ref(struct xfs_inode *, char *, int, inst_t *);
  276. extern void vn_trace_rele(struct xfs_inode *, char *, int, inst_t *);
  277. #else
  278. #define vn_trace_entry(a,b,c)
  279. #define vn_trace_exit(a,b,c)
  280. #define vn_trace_hold(a,b,c,d)
  281. #define vn_trace_ref(a,b,c,d)
  282. #define vn_trace_rele(a,b,c,d)
  283. #endif
  284. #endif /* __XFS_VNODE_H__ */