xfs_inode.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. struct posix_acl;
  21. struct xfs_dinode;
  22. struct xfs_inode;
  23. #include "xfs_inode_fork.h"
  24. /*
  25. * Inode location information. Stored in the inode and passed to
  26. * xfs_imap_to_bp() to get a buffer and dinode for a given inode.
  27. */
  28. struct xfs_imap {
  29. xfs_daddr_t im_blkno; /* starting BB of inode chunk */
  30. ushort im_len; /* length in BBs of inode chunk */
  31. ushort im_boffset; /* inode offset in block in bytes */
  32. };
  33. /*
  34. * This is the xfs in-core inode structure.
  35. * Most of the on-disk inode is embedded in the i_d field.
  36. *
  37. * The extent pointers/inline file space, however, are managed
  38. * separately. The memory for this information is pointed to by
  39. * the if_u1 unions depending on the type of the data.
  40. * This is used to linearize the array of extents for fast in-core
  41. * access. This is used until the file's number of extents
  42. * surpasses XFS_MAX_INCORE_EXTENTS, at which point all extent pointers
  43. * are accessed through the buffer cache.
  44. *
  45. * Other state kept in the in-core inode is used for identification,
  46. * locking, transactional updating, etc of the inode.
  47. *
  48. * Generally, we do not want to hold the i_rlock while holding the
  49. * i_ilock. Hierarchy is i_iolock followed by i_rlock.
  50. *
  51. * xfs_iptr_t contains all the inode fields up to and including the
  52. * i_mnext and i_mprev fields, it is used as a marker in the inode
  53. * chain off the mount structure by xfs_sync calls.
  54. */
  55. /*
  56. * Flags for xfs_ichgtime().
  57. */
  58. #define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */
  59. #define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */
  60. #define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */
  61. #ifdef __KERNEL__
  62. struct xfs_buf;
  63. struct xfs_bmap_free;
  64. struct xfs_bmbt_irec;
  65. struct xfs_inode_log_item;
  66. struct xfs_mount;
  67. struct xfs_trans;
  68. struct xfs_dquot;
  69. typedef struct xfs_inode {
  70. /* Inode linking and identification information. */
  71. struct xfs_mount *i_mount; /* fs mount struct ptr */
  72. struct xfs_dquot *i_udquot; /* user dquot */
  73. struct xfs_dquot *i_gdquot; /* group dquot */
  74. struct xfs_dquot *i_pdquot; /* project dquot */
  75. /* Inode location stuff */
  76. xfs_ino_t i_ino; /* inode number (agno/agino)*/
  77. struct xfs_imap i_imap; /* location for xfs_imap() */
  78. /* Extent information. */
  79. xfs_ifork_t *i_afp; /* attribute fork pointer */
  80. xfs_ifork_t i_df; /* data fork */
  81. /* Transaction and locking information. */
  82. struct xfs_inode_log_item *i_itemp; /* logging information */
  83. mrlock_t i_lock; /* inode lock */
  84. mrlock_t i_iolock; /* inode IO lock */
  85. atomic_t i_pincount; /* inode pin count */
  86. spinlock_t i_flags_lock; /* inode i_flags lock */
  87. /* Miscellaneous state. */
  88. unsigned long i_flags; /* see defined flags below */
  89. unsigned int i_delayed_blks; /* count of delay alloc blks */
  90. xfs_icdinode_t i_d; /* most of ondisk inode */
  91. /* VFS inode */
  92. struct inode i_vnode; /* embedded VFS inode */
  93. } xfs_inode_t;
  94. /* Convert from vfs inode to xfs inode */
  95. static inline struct xfs_inode *XFS_I(struct inode *inode)
  96. {
  97. return container_of(inode, struct xfs_inode, i_vnode);
  98. }
  99. /* convert from xfs inode to vfs inode */
  100. static inline struct inode *VFS_I(struct xfs_inode *ip)
  101. {
  102. return &ip->i_vnode;
  103. }
  104. /*
  105. * For regular files we only update the on-disk filesize when actually
  106. * writing data back to disk. Until then only the copy in the VFS inode
  107. * is uptodate.
  108. */
  109. static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
  110. {
  111. if (S_ISREG(ip->i_d.di_mode))
  112. return i_size_read(VFS_I(ip));
  113. return ip->i_d.di_size;
  114. }
  115. /*
  116. * If this I/O goes past the on-disk inode size update it unless it would
  117. * be past the current in-core inode size.
  118. */
  119. static inline xfs_fsize_t
  120. xfs_new_eof(struct xfs_inode *ip, xfs_fsize_t new_size)
  121. {
  122. xfs_fsize_t i_size = i_size_read(VFS_I(ip));
  123. if (new_size > i_size)
  124. new_size = i_size;
  125. return new_size > ip->i_d.di_size ? new_size : 0;
  126. }
  127. /*
  128. * i_flags helper functions
  129. */
  130. static inline void
  131. __xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
  132. {
  133. ip->i_flags |= flags;
  134. }
  135. static inline void
  136. xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
  137. {
  138. spin_lock(&ip->i_flags_lock);
  139. __xfs_iflags_set(ip, flags);
  140. spin_unlock(&ip->i_flags_lock);
  141. }
  142. static inline void
  143. xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
  144. {
  145. spin_lock(&ip->i_flags_lock);
  146. ip->i_flags &= ~flags;
  147. spin_unlock(&ip->i_flags_lock);
  148. }
  149. static inline int
  150. __xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
  151. {
  152. return (ip->i_flags & flags);
  153. }
  154. static inline int
  155. xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
  156. {
  157. int ret;
  158. spin_lock(&ip->i_flags_lock);
  159. ret = __xfs_iflags_test(ip, flags);
  160. spin_unlock(&ip->i_flags_lock);
  161. return ret;
  162. }
  163. static inline int
  164. xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
  165. {
  166. int ret;
  167. spin_lock(&ip->i_flags_lock);
  168. ret = ip->i_flags & flags;
  169. if (ret)
  170. ip->i_flags &= ~flags;
  171. spin_unlock(&ip->i_flags_lock);
  172. return ret;
  173. }
  174. static inline int
  175. xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
  176. {
  177. int ret;
  178. spin_lock(&ip->i_flags_lock);
  179. ret = ip->i_flags & flags;
  180. if (!ret)
  181. ip->i_flags |= flags;
  182. spin_unlock(&ip->i_flags_lock);
  183. return ret;
  184. }
  185. /*
  186. * Project quota id helpers (previously projid was 16bit only
  187. * and using two 16bit values to hold new 32bit projid was chosen
  188. * to retain compatibility with "old" filesystems).
  189. */
  190. static inline prid_t
  191. xfs_get_projid(struct xfs_inode *ip)
  192. {
  193. return (prid_t)ip->i_d.di_projid_hi << 16 | ip->i_d.di_projid_lo;
  194. }
  195. static inline void
  196. xfs_set_projid(struct xfs_inode *ip,
  197. prid_t projid)
  198. {
  199. ip->i_d.di_projid_hi = (__uint16_t) (projid >> 16);
  200. ip->i_d.di_projid_lo = (__uint16_t) (projid & 0xffff);
  201. }
  202. /*
  203. * In-core inode flags.
  204. */
  205. #define XFS_IRECLAIM (1 << 0) /* started reclaiming this inode */
  206. #define XFS_ISTALE (1 << 1) /* inode has been staled */
  207. #define XFS_IRECLAIMABLE (1 << 2) /* inode can be reclaimed */
  208. #define XFS_INEW (1 << 3) /* inode has just been allocated */
  209. #define XFS_IFILESTREAM (1 << 4) /* inode is in a filestream dir. */
  210. #define XFS_ITRUNCATED (1 << 5) /* truncated down so flush-on-close */
  211. #define XFS_IDIRTY_RELEASE (1 << 6) /* dirty release already seen */
  212. #define __XFS_IFLOCK_BIT 7 /* inode is being flushed right now */
  213. #define XFS_IFLOCK (1 << __XFS_IFLOCK_BIT)
  214. #define __XFS_IPINNED_BIT 8 /* wakeup key for zero pin count */
  215. #define XFS_IPINNED (1 << __XFS_IPINNED_BIT)
  216. #define XFS_IDONTCACHE (1 << 9) /* don't cache the inode long term */
  217. /*
  218. * Per-lifetime flags need to be reset when re-using a reclaimable inode during
  219. * inode lookup. This prevents unintended behaviour on the new inode from
  220. * ocurring.
  221. */
  222. #define XFS_IRECLAIM_RESET_FLAGS \
  223. (XFS_IRECLAIMABLE | XFS_IRECLAIM | \
  224. XFS_IDIRTY_RELEASE | XFS_ITRUNCATED | \
  225. XFS_IFILESTREAM);
  226. /*
  227. * Synchronize processes attempting to flush the in-core inode back to disk.
  228. */
  229. extern void __xfs_iflock(struct xfs_inode *ip);
  230. static inline int xfs_iflock_nowait(struct xfs_inode *ip)
  231. {
  232. return !xfs_iflags_test_and_set(ip, XFS_IFLOCK);
  233. }
  234. static inline void xfs_iflock(struct xfs_inode *ip)
  235. {
  236. if (!xfs_iflock_nowait(ip))
  237. __xfs_iflock(ip);
  238. }
  239. static inline void xfs_ifunlock(struct xfs_inode *ip)
  240. {
  241. xfs_iflags_clear(ip, XFS_IFLOCK);
  242. smp_mb();
  243. wake_up_bit(&ip->i_flags, __XFS_IFLOCK_BIT);
  244. }
  245. static inline int xfs_isiflocked(struct xfs_inode *ip)
  246. {
  247. return xfs_iflags_test(ip, XFS_IFLOCK);
  248. }
  249. /*
  250. * Flags for inode locking.
  251. * Bit ranges: 1<<1 - 1<<16-1 -- iolock/ilock modes (bitfield)
  252. * 1<<16 - 1<<32-1 -- lockdep annotation (integers)
  253. */
  254. #define XFS_IOLOCK_EXCL (1<<0)
  255. #define XFS_IOLOCK_SHARED (1<<1)
  256. #define XFS_ILOCK_EXCL (1<<2)
  257. #define XFS_ILOCK_SHARED (1<<3)
  258. #define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
  259. | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED)
  260. #define XFS_LOCK_FLAGS \
  261. { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
  262. { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
  263. { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
  264. { XFS_ILOCK_SHARED, "ILOCK_SHARED" }
  265. /*
  266. * Flags for lockdep annotations.
  267. *
  268. * XFS_LOCK_PARENT - for directory operations that require locking a
  269. * parent directory inode and a child entry inode. The parent gets locked
  270. * with this flag so it gets a lockdep subclass of 1 and the child entry
  271. * lock will have a lockdep subclass of 0.
  272. *
  273. * XFS_LOCK_RTBITMAP/XFS_LOCK_RTSUM - the realtime device bitmap and summary
  274. * inodes do not participate in the normal lock order, and thus have their
  275. * own subclasses.
  276. *
  277. * XFS_LOCK_INUMORDER - for locking several inodes at the some time
  278. * with xfs_lock_inodes(). This flag is used as the starting subclass
  279. * and each subsequent lock acquired will increment the subclass by one.
  280. * So the first lock acquired will have a lockdep subclass of 4, the
  281. * second lock will have a lockdep subclass of 5, and so on. It is
  282. * the responsibility of the class builder to shift this to the correct
  283. * portion of the lock_mode lockdep mask.
  284. */
  285. #define XFS_LOCK_PARENT 1
  286. #define XFS_LOCK_RTBITMAP 2
  287. #define XFS_LOCK_RTSUM 3
  288. #define XFS_LOCK_INUMORDER 4
  289. #define XFS_IOLOCK_SHIFT 16
  290. #define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT)
  291. #define XFS_ILOCK_SHIFT 24
  292. #define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT)
  293. #define XFS_ILOCK_RTBITMAP (XFS_LOCK_RTBITMAP << XFS_ILOCK_SHIFT)
  294. #define XFS_ILOCK_RTSUM (XFS_LOCK_RTSUM << XFS_ILOCK_SHIFT)
  295. #define XFS_IOLOCK_DEP_MASK 0x00ff0000
  296. #define XFS_ILOCK_DEP_MASK 0xff000000
  297. #define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | XFS_ILOCK_DEP_MASK)
  298. #define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) >> XFS_IOLOCK_SHIFT)
  299. #define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) >> XFS_ILOCK_SHIFT)
  300. /*
  301. * For multiple groups support: if S_ISGID bit is set in the parent
  302. * directory, group of new file is set to that of the parent, and
  303. * new subdirectory gets S_ISGID bit from parent.
  304. */
  305. #define XFS_INHERIT_GID(pip) \
  306. (((pip)->i_mount->m_flags & XFS_MOUNT_GRPID) || \
  307. ((pip)->i_d.di_mode & S_ISGID))
  308. /*
  309. * xfs_inode.c prototypes.
  310. */
  311. void xfs_ilock(xfs_inode_t *, uint);
  312. int xfs_ilock_nowait(xfs_inode_t *, uint);
  313. void xfs_iunlock(xfs_inode_t *, uint);
  314. void xfs_ilock_demote(xfs_inode_t *, uint);
  315. int xfs_isilocked(xfs_inode_t *, uint);
  316. uint xfs_ilock_map_shared(xfs_inode_t *);
  317. void xfs_iunlock_map_shared(xfs_inode_t *, uint);
  318. int xfs_ialloc(struct xfs_trans *, xfs_inode_t *, umode_t,
  319. xfs_nlink_t, xfs_dev_t, prid_t, int,
  320. struct xfs_buf **, xfs_inode_t **);
  321. uint xfs_ip2xflags(struct xfs_inode *);
  322. uint xfs_dic2xflags(struct xfs_dinode *);
  323. int xfs_ifree(struct xfs_trans *, xfs_inode_t *,
  324. struct xfs_bmap_free *);
  325. int xfs_itruncate_extents(struct xfs_trans **, struct xfs_inode *,
  326. int, xfs_fsize_t);
  327. int xfs_iunlink(struct xfs_trans *, xfs_inode_t *);
  328. void xfs_iext_realloc(xfs_inode_t *, int, int);
  329. void xfs_iunpin_wait(xfs_inode_t *);
  330. int xfs_iflush(struct xfs_inode *, struct xfs_buf **);
  331. void xfs_lock_inodes(xfs_inode_t **, int, uint);
  332. void xfs_lock_two_inodes(xfs_inode_t *, xfs_inode_t *, uint);
  333. xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);
  334. #define IHOLD(ip) \
  335. do { \
  336. ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \
  337. ihold(VFS_I(ip)); \
  338. trace_xfs_ihold(ip, _THIS_IP_); \
  339. } while (0)
  340. #define IRELE(ip) \
  341. do { \
  342. trace_xfs_irele(ip, _THIS_IP_); \
  343. iput(VFS_I(ip)); \
  344. } while (0)
  345. #endif /* __KERNEL__ */
  346. /*
  347. * Flags for xfs_iget()
  348. */
  349. #define XFS_IGET_CREATE 0x1
  350. #define XFS_IGET_UNTRUSTED 0x2
  351. #define XFS_IGET_DONTCACHE 0x4
  352. int xfs_imap_to_bp(struct xfs_mount *, struct xfs_trans *,
  353. struct xfs_imap *, struct xfs_dinode **,
  354. struct xfs_buf **, uint, uint);
  355. int xfs_iread(struct xfs_mount *, struct xfs_trans *,
  356. struct xfs_inode *, uint);
  357. void xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);
  358. void xfs_dinode_to_disk(struct xfs_dinode *,
  359. struct xfs_icdinode *);
  360. bool xfs_can_free_eofblocks(struct xfs_inode *, bool);
  361. #define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
  362. #if defined(DEBUG)
  363. void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *);
  364. #else
  365. #define xfs_inobp_check(mp, bp)
  366. #endif /* DEBUG */
  367. extern struct kmem_zone *xfs_inode_zone;
  368. extern const struct xfs_buf_ops xfs_inode_buf_ops;
  369. #endif /* __XFS_INODE_H__ */