xfs_vnode.h 11 KB

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