xfs_inode.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. * Copyright (c) 2000-2003,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_INODE_H__
  19. #define __XFS_INODE_H__
  20. #include "xfs_inode_buf.h"
  21. #include "xfs_inode_fork.h"
  22. /*
  23. * Kernel only inode definitions
  24. */
  25. struct xfs_dinode;
  26. struct xfs_inode;
  27. struct xfs_buf;
  28. struct xfs_bmap_free;
  29. struct xfs_bmbt_irec;
  30. struct xfs_inode_log_item;
  31. struct xfs_mount;
  32. struct xfs_trans;
  33. struct xfs_dquot;
  34. typedef struct xfs_inode {
  35. /* Inode linking and identification information. */
  36. struct xfs_mount *i_mount; /* fs mount struct ptr */
  37. struct xfs_dquot *i_udquot; /* user dquot */
  38. struct xfs_dquot *i_gdquot; /* group dquot */
  39. struct xfs_dquot *i_pdquot; /* project dquot */
  40. /* Inode location stuff */
  41. xfs_ino_t i_ino; /* inode number (agno/agino)*/
  42. struct xfs_imap i_imap; /* location for xfs_imap() */
  43. /* Extent information. */
  44. xfs_ifork_t *i_afp; /* attribute fork pointer */
  45. xfs_ifork_t i_df; /* data fork */
  46. /* operations vectors */
  47. const struct xfs_dir_ops *d_ops; /* directory ops vector */
  48. /* Transaction and locking information. */
  49. struct xfs_inode_log_item *i_itemp; /* logging information */
  50. mrlock_t i_lock; /* inode lock */
  51. mrlock_t i_iolock; /* inode IO lock */
  52. atomic_t i_pincount; /* inode pin count */
  53. spinlock_t i_flags_lock; /* inode i_flags lock */
  54. /* Miscellaneous state. */
  55. unsigned long i_flags; /* see defined flags below */
  56. unsigned int i_delayed_blks; /* count of delay alloc blks */
  57. xfs_icdinode_t i_d; /* most of ondisk inode */
  58. /* VFS inode */
  59. struct inode i_vnode; /* embedded VFS inode */
  60. } xfs_inode_t;
  61. /* Convert from vfs inode to xfs inode */
  62. static inline struct xfs_inode *XFS_I(struct inode *inode)
  63. {
  64. return container_of(inode, struct xfs_inode, i_vnode);
  65. }
  66. /* convert from xfs inode to vfs inode */
  67. static inline struct inode *VFS_I(struct xfs_inode *ip)
  68. {
  69. return &ip->i_vnode;
  70. }
  71. /*
  72. * For regular files we only update the on-disk filesize when actually
  73. * writing data back to disk. Until then only the copy in the VFS inode
  74. * is uptodate.
  75. */
  76. static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
  77. {
  78. if (S_ISREG(ip->i_d.di_mode))
  79. return i_size_read(VFS_I(ip));
  80. return ip->i_d.di_size;
  81. }
  82. /*
  83. * If this I/O goes past the on-disk inode size update it unless it would
  84. * be past the current in-core inode size.
  85. */
  86. static inline xfs_fsize_t
  87. xfs_new_eof(struct xfs_inode *ip, xfs_fsize_t new_size)
  88. {
  89. xfs_fsize_t i_size = i_size_read(VFS_I(ip));
  90. if (new_size > i_size)
  91. new_size = i_size;
  92. return new_size > ip->i_d.di_size ? new_size : 0;
  93. }
  94. /*
  95. * i_flags helper functions
  96. */
  97. static inline void
  98. __xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
  99. {
  100. ip->i_flags |= flags;
  101. }
  102. static inline void
  103. xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
  104. {
  105. spin_lock(&ip->i_flags_lock);
  106. __xfs_iflags_set(ip, flags);
  107. spin_unlock(&ip->i_flags_lock);
  108. }
  109. static inline void
  110. xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
  111. {
  112. spin_lock(&ip->i_flags_lock);
  113. ip->i_flags &= ~flags;
  114. spin_unlock(&ip->i_flags_lock);
  115. }
  116. static inline int
  117. __xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
  118. {
  119. return (ip->i_flags & flags);
  120. }
  121. static inline int
  122. xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
  123. {
  124. int ret;
  125. spin_lock(&ip->i_flags_lock);
  126. ret = __xfs_iflags_test(ip, flags);
  127. spin_unlock(&ip->i_flags_lock);
  128. return ret;
  129. }
  130. static inline int
  131. xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
  132. {
  133. int ret;
  134. spin_lock(&ip->i_flags_lock);
  135. ret = ip->i_flags & flags;
  136. if (ret)
  137. ip->i_flags &= ~flags;
  138. spin_unlock(&ip->i_flags_lock);
  139. return ret;
  140. }
  141. static inline int
  142. xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
  143. {
  144. int ret;
  145. spin_lock(&ip->i_flags_lock);
  146. ret = ip->i_flags & flags;
  147. if (!ret)
  148. ip->i_flags |= flags;
  149. spin_unlock(&ip->i_flags_lock);
  150. return ret;
  151. }
  152. /*
  153. * Project quota id helpers (previously projid was 16bit only
  154. * and using two 16bit values to hold new 32bit projid was chosen
  155. * to retain compatibility with "old" filesystems).
  156. */
  157. static inline prid_t
  158. xfs_get_projid(struct xfs_inode *ip)
  159. {
  160. return (prid_t)ip->i_d.di_projid_hi << 16 | ip->i_d.di_projid_lo;
  161. }
  162. static inline void
  163. xfs_set_projid(struct xfs_inode *ip,
  164. prid_t projid)
  165. {
  166. ip->i_d.di_projid_hi = (__uint16_t) (projid >> 16);
  167. ip->i_d.di_projid_lo = (__uint16_t) (projid & 0xffff);
  168. }
  169. /*
  170. * In-core inode flags.
  171. */
  172. #define XFS_IRECLAIM (1 << 0) /* started reclaiming this inode */
  173. #define XFS_ISTALE (1 << 1) /* inode has been staled */
  174. #define XFS_IRECLAIMABLE (1 << 2) /* inode can be reclaimed */
  175. #define XFS_INEW (1 << 3) /* inode has just been allocated */
  176. #define XFS_IFILESTREAM (1 << 4) /* inode is in a filestream dir. */
  177. #define XFS_ITRUNCATED (1 << 5) /* truncated down so flush-on-close */
  178. #define XFS_IDIRTY_RELEASE (1 << 6) /* dirty release already seen */
  179. #define __XFS_IFLOCK_BIT 7 /* inode is being flushed right now */
  180. #define XFS_IFLOCK (1 << __XFS_IFLOCK_BIT)
  181. #define __XFS_IPINNED_BIT 8 /* wakeup key for zero pin count */
  182. #define XFS_IPINNED (1 << __XFS_IPINNED_BIT)
  183. #define XFS_IDONTCACHE (1 << 9) /* don't cache the inode long term */
  184. /*
  185. * Per-lifetime flags need to be reset when re-using a reclaimable inode during
  186. * inode lookup. This prevents unintended behaviour on the new inode from
  187. * ocurring.
  188. */
  189. #define XFS_IRECLAIM_RESET_FLAGS \
  190. (XFS_IRECLAIMABLE | XFS_IRECLAIM | \
  191. XFS_IDIRTY_RELEASE | XFS_ITRUNCATED | \
  192. XFS_IFILESTREAM);
  193. /*
  194. * Synchronize processes attempting to flush the in-core inode back to disk.
  195. */
  196. extern void __xfs_iflock(struct xfs_inode *ip);
  197. static inline int xfs_iflock_nowait(struct xfs_inode *ip)
  198. {
  199. return !xfs_iflags_test_and_set(ip, XFS_IFLOCK);
  200. }
  201. static inline void xfs_iflock(struct xfs_inode *ip)
  202. {
  203. if (!xfs_iflock_nowait(ip))
  204. __xfs_iflock(ip);
  205. }
  206. static inline void xfs_ifunlock(struct xfs_inode *ip)
  207. {
  208. xfs_iflags_clear(ip, XFS_IFLOCK);
  209. smp_mb();
  210. wake_up_bit(&ip->i_flags, __XFS_IFLOCK_BIT);
  211. }
  212. static inline int xfs_isiflocked(struct xfs_inode *ip)
  213. {
  214. return xfs_iflags_test(ip, XFS_IFLOCK);
  215. }
  216. /*
  217. * Flags for inode locking.
  218. * Bit ranges: 1<<1 - 1<<16-1 -- iolock/ilock modes (bitfield)
  219. * 1<<16 - 1<<32-1 -- lockdep annotation (integers)
  220. */
  221. #define XFS_IOLOCK_EXCL (1<<0)
  222. #define XFS_IOLOCK_SHARED (1<<1)
  223. #define XFS_ILOCK_EXCL (1<<2)
  224. #define XFS_ILOCK_SHARED (1<<3)
  225. #define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
  226. | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED)
  227. #define XFS_LOCK_FLAGS \
  228. { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
  229. { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
  230. { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
  231. { XFS_ILOCK_SHARED, "ILOCK_SHARED" }
  232. /*
  233. * Flags for lockdep annotations.
  234. *
  235. * XFS_LOCK_PARENT - for directory operations that require locking a
  236. * parent directory inode and a child entry inode. The parent gets locked
  237. * with this flag so it gets a lockdep subclass of 1 and the child entry
  238. * lock will have a lockdep subclass of 0.
  239. *
  240. * XFS_LOCK_RTBITMAP/XFS_LOCK_RTSUM - the realtime device bitmap and summary
  241. * inodes do not participate in the normal lock order, and thus have their
  242. * own subclasses.
  243. *
  244. * XFS_LOCK_INUMORDER - for locking several inodes at the some time
  245. * with xfs_lock_inodes(). This flag is used as the starting subclass
  246. * and each subsequent lock acquired will increment the subclass by one.
  247. * So the first lock acquired will have a lockdep subclass of 4, the
  248. * second lock will have a lockdep subclass of 5, and so on. It is
  249. * the responsibility of the class builder to shift this to the correct
  250. * portion of the lock_mode lockdep mask.
  251. */
  252. #define XFS_LOCK_PARENT 1
  253. #define XFS_LOCK_RTBITMAP 2
  254. #define XFS_LOCK_RTSUM 3
  255. #define XFS_LOCK_INUMORDER 4
  256. #define XFS_IOLOCK_SHIFT 16
  257. #define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT)
  258. #define XFS_ILOCK_SHIFT 24
  259. #define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT)
  260. #define XFS_ILOCK_RTBITMAP (XFS_LOCK_RTBITMAP << XFS_ILOCK_SHIFT)
  261. #define XFS_ILOCK_RTSUM (XFS_LOCK_RTSUM << XFS_ILOCK_SHIFT)
  262. #define XFS_IOLOCK_DEP_MASK 0x00ff0000
  263. #define XFS_ILOCK_DEP_MASK 0xff000000
  264. #define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | XFS_ILOCK_DEP_MASK)
  265. #define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) >> XFS_IOLOCK_SHIFT)
  266. #define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) >> XFS_ILOCK_SHIFT)
  267. /*
  268. * For multiple groups support: if S_ISGID bit is set in the parent
  269. * directory, group of new file is set to that of the parent, and
  270. * new subdirectory gets S_ISGID bit from parent.
  271. */
  272. #define XFS_INHERIT_GID(pip) \
  273. (((pip)->i_mount->m_flags & XFS_MOUNT_GRPID) || \
  274. ((pip)->i_d.di_mode & S_ISGID))
  275. int xfs_release(struct xfs_inode *ip);
  276. void xfs_inactive(struct xfs_inode *ip);
  277. int xfs_lookup(struct xfs_inode *dp, struct xfs_name *name,
  278. struct xfs_inode **ipp, struct xfs_name *ci_name);
  279. int xfs_create(struct xfs_inode *dp, struct xfs_name *name,
  280. umode_t mode, xfs_dev_t rdev, struct xfs_inode **ipp);
  281. int xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
  282. struct xfs_inode *ip);
  283. int xfs_link(struct xfs_inode *tdp, struct xfs_inode *sip,
  284. struct xfs_name *target_name);
  285. int xfs_rename(struct xfs_inode *src_dp, struct xfs_name *src_name,
  286. struct xfs_inode *src_ip, struct xfs_inode *target_dp,
  287. struct xfs_name *target_name,
  288. struct xfs_inode *target_ip);
  289. void xfs_ilock(xfs_inode_t *, uint);
  290. int xfs_ilock_nowait(xfs_inode_t *, uint);
  291. void xfs_iunlock(xfs_inode_t *, uint);
  292. void xfs_ilock_demote(xfs_inode_t *, uint);
  293. int xfs_isilocked(xfs_inode_t *, uint);
  294. uint xfs_ilock_map_shared(xfs_inode_t *);
  295. void xfs_iunlock_map_shared(xfs_inode_t *, uint);
  296. int xfs_ialloc(struct xfs_trans *, xfs_inode_t *, umode_t,
  297. xfs_nlink_t, xfs_dev_t, prid_t, int,
  298. struct xfs_buf **, xfs_inode_t **);
  299. uint xfs_ip2xflags(struct xfs_inode *);
  300. uint xfs_dic2xflags(struct xfs_dinode *);
  301. int xfs_ifree(struct xfs_trans *, xfs_inode_t *,
  302. struct xfs_bmap_free *);
  303. int xfs_itruncate_extents(struct xfs_trans **, struct xfs_inode *,
  304. int, xfs_fsize_t);
  305. int xfs_iunlink(struct xfs_trans *, xfs_inode_t *);
  306. void xfs_iext_realloc(xfs_inode_t *, int, int);
  307. void xfs_iunpin_wait(xfs_inode_t *);
  308. #define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
  309. int xfs_iflush(struct xfs_inode *, struct xfs_buf **);
  310. void xfs_lock_inodes(xfs_inode_t **, int, uint);
  311. void xfs_lock_two_inodes(xfs_inode_t *, xfs_inode_t *, uint);
  312. xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);
  313. int xfs_dir_ialloc(struct xfs_trans **, struct xfs_inode *, umode_t,
  314. xfs_nlink_t, xfs_dev_t, prid_t, int,
  315. struct xfs_inode **, int *);
  316. int xfs_droplink(struct xfs_trans *, struct xfs_inode *);
  317. int xfs_bumplink(struct xfs_trans *, struct xfs_inode *);
  318. void xfs_bump_ino_vers2(struct xfs_trans *, struct xfs_inode *);
  319. /* from xfs_file.c */
  320. int xfs_zero_eof(struct xfs_inode *, xfs_off_t, xfs_fsize_t);
  321. int xfs_iozero(struct xfs_inode *, loff_t, size_t);
  322. #define IHOLD(ip) \
  323. do { \
  324. ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \
  325. ihold(VFS_I(ip)); \
  326. trace_xfs_ihold(ip, _THIS_IP_); \
  327. } while (0)
  328. #define IRELE(ip) \
  329. do { \
  330. trace_xfs_irele(ip, _THIS_IP_); \
  331. iput(VFS_I(ip)); \
  332. } while (0)
  333. extern struct kmem_zone *xfs_inode_zone;
  334. #endif /* __XFS_INODE_H__ */