xfs_inode.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. mrlock_t i_mmaplock; /* inode mmap IO lock */
  53. atomic_t i_pincount; /* inode pin count */
  54. spinlock_t i_flags_lock; /* inode i_flags lock */
  55. /* Miscellaneous state. */
  56. unsigned long i_flags; /* see defined flags below */
  57. unsigned int i_delayed_blks; /* count of delay alloc blks */
  58. xfs_icdinode_t i_d; /* most of ondisk inode */
  59. /* VFS inode */
  60. struct inode i_vnode; /* embedded VFS inode */
  61. } xfs_inode_t;
  62. /* Convert from vfs inode to xfs inode */
  63. static inline struct xfs_inode *XFS_I(struct inode *inode)
  64. {
  65. return container_of(inode, struct xfs_inode, i_vnode);
  66. }
  67. /* convert from xfs inode to vfs inode */
  68. static inline struct inode *VFS_I(struct xfs_inode *ip)
  69. {
  70. return &ip->i_vnode;
  71. }
  72. /*
  73. * For regular files we only update the on-disk filesize when actually
  74. * writing data back to disk. Until then only the copy in the VFS inode
  75. * is uptodate.
  76. */
  77. static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
  78. {
  79. if (S_ISREG(ip->i_d.di_mode))
  80. return i_size_read(VFS_I(ip));
  81. return ip->i_d.di_size;
  82. }
  83. /*
  84. * If this I/O goes past the on-disk inode size update it unless it would
  85. * be past the current in-core inode size.
  86. */
  87. static inline xfs_fsize_t
  88. xfs_new_eof(struct xfs_inode *ip, xfs_fsize_t new_size)
  89. {
  90. xfs_fsize_t i_size = i_size_read(VFS_I(ip));
  91. if (new_size > i_size || new_size < 0)
  92. new_size = i_size;
  93. return new_size > ip->i_d.di_size ? new_size : 0;
  94. }
  95. /*
  96. * i_flags helper functions
  97. */
  98. static inline void
  99. __xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
  100. {
  101. ip->i_flags |= flags;
  102. }
  103. static inline void
  104. xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
  105. {
  106. spin_lock(&ip->i_flags_lock);
  107. __xfs_iflags_set(ip, flags);
  108. spin_unlock(&ip->i_flags_lock);
  109. }
  110. static inline void
  111. xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
  112. {
  113. spin_lock(&ip->i_flags_lock);
  114. ip->i_flags &= ~flags;
  115. spin_unlock(&ip->i_flags_lock);
  116. }
  117. static inline int
  118. __xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
  119. {
  120. return (ip->i_flags & flags);
  121. }
  122. static inline int
  123. xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
  124. {
  125. int ret;
  126. spin_lock(&ip->i_flags_lock);
  127. ret = __xfs_iflags_test(ip, flags);
  128. spin_unlock(&ip->i_flags_lock);
  129. return ret;
  130. }
  131. static inline int
  132. xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
  133. {
  134. int ret;
  135. spin_lock(&ip->i_flags_lock);
  136. ret = ip->i_flags & flags;
  137. if (ret)
  138. ip->i_flags &= ~flags;
  139. spin_unlock(&ip->i_flags_lock);
  140. return ret;
  141. }
  142. static inline int
  143. xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
  144. {
  145. int ret;
  146. spin_lock(&ip->i_flags_lock);
  147. ret = ip->i_flags & flags;
  148. if (!ret)
  149. ip->i_flags |= flags;
  150. spin_unlock(&ip->i_flags_lock);
  151. return ret;
  152. }
  153. /*
  154. * Project quota id helpers (previously projid was 16bit only
  155. * and using two 16bit values to hold new 32bit projid was chosen
  156. * to retain compatibility with "old" filesystems).
  157. */
  158. static inline prid_t
  159. xfs_get_projid(struct xfs_inode *ip)
  160. {
  161. return (prid_t)ip->i_d.di_projid_hi << 16 | ip->i_d.di_projid_lo;
  162. }
  163. static inline void
  164. xfs_set_projid(struct xfs_inode *ip,
  165. prid_t projid)
  166. {
  167. ip->i_d.di_projid_hi = (__uint16_t) (projid >> 16);
  168. ip->i_d.di_projid_lo = (__uint16_t) (projid & 0xffff);
  169. }
  170. static inline prid_t
  171. xfs_get_initial_prid(struct xfs_inode *dp)
  172. {
  173. if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)
  174. return xfs_get_projid(dp);
  175. return XFS_PROJID_DEFAULT;
  176. }
  177. /*
  178. * In-core inode flags.
  179. */
  180. #define XFS_IRECLAIM (1 << 0) /* started reclaiming this inode */
  181. #define XFS_ISTALE (1 << 1) /* inode has been staled */
  182. #define XFS_IRECLAIMABLE (1 << 2) /* inode can be reclaimed */
  183. #define XFS_INEW (1 << 3) /* inode has just been allocated */
  184. #define XFS_ITRUNCATED (1 << 5) /* truncated down so flush-on-close */
  185. #define XFS_IDIRTY_RELEASE (1 << 6) /* dirty release already seen */
  186. #define __XFS_IFLOCK_BIT 7 /* inode is being flushed right now */
  187. #define XFS_IFLOCK (1 << __XFS_IFLOCK_BIT)
  188. #define __XFS_IPINNED_BIT 8 /* wakeup key for zero pin count */
  189. #define XFS_IPINNED (1 << __XFS_IPINNED_BIT)
  190. #define XFS_IDONTCACHE (1 << 9) /* don't cache the inode long term */
  191. /*
  192. * Per-lifetime flags need to be reset when re-using a reclaimable inode during
  193. * inode lookup. This prevents unintended behaviour on the new inode from
  194. * ocurring.
  195. */
  196. #define XFS_IRECLAIM_RESET_FLAGS \
  197. (XFS_IRECLAIMABLE | XFS_IRECLAIM | \
  198. XFS_IDIRTY_RELEASE | XFS_ITRUNCATED)
  199. /*
  200. * Synchronize processes attempting to flush the in-core inode back to disk.
  201. */
  202. extern void __xfs_iflock(struct xfs_inode *ip);
  203. static inline int xfs_iflock_nowait(struct xfs_inode *ip)
  204. {
  205. return !xfs_iflags_test_and_set(ip, XFS_IFLOCK);
  206. }
  207. static inline void xfs_iflock(struct xfs_inode *ip)
  208. {
  209. if (!xfs_iflock_nowait(ip))
  210. __xfs_iflock(ip);
  211. }
  212. static inline void xfs_ifunlock(struct xfs_inode *ip)
  213. {
  214. xfs_iflags_clear(ip, XFS_IFLOCK);
  215. smp_mb();
  216. wake_up_bit(&ip->i_flags, __XFS_IFLOCK_BIT);
  217. }
  218. static inline int xfs_isiflocked(struct xfs_inode *ip)
  219. {
  220. return xfs_iflags_test(ip, XFS_IFLOCK);
  221. }
  222. /*
  223. * Flags for inode locking.
  224. * Bit ranges: 1<<1 - 1<<16-1 -- iolock/ilock modes (bitfield)
  225. * 1<<16 - 1<<32-1 -- lockdep annotation (integers)
  226. */
  227. #define XFS_IOLOCK_EXCL (1<<0)
  228. #define XFS_IOLOCK_SHARED (1<<1)
  229. #define XFS_ILOCK_EXCL (1<<2)
  230. #define XFS_ILOCK_SHARED (1<<3)
  231. #define XFS_MMAPLOCK_EXCL (1<<4)
  232. #define XFS_MMAPLOCK_SHARED (1<<5)
  233. #define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
  234. | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \
  235. | XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED)
  236. #define XFS_LOCK_FLAGS \
  237. { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
  238. { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
  239. { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
  240. { XFS_ILOCK_SHARED, "ILOCK_SHARED" }, \
  241. { XFS_MMAPLOCK_EXCL, "MMAPLOCK_EXCL" }, \
  242. { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" }
  243. /*
  244. * Flags for lockdep annotations.
  245. *
  246. * XFS_LOCK_PARENT - for directory operations that require locking a
  247. * parent directory inode and a child entry inode. The parent gets locked
  248. * with this flag so it gets a lockdep subclass of 1 and the child entry
  249. * lock will have a lockdep subclass of 0.
  250. *
  251. * XFS_LOCK_RTBITMAP/XFS_LOCK_RTSUM - the realtime device bitmap and summary
  252. * inodes do not participate in the normal lock order, and thus have their
  253. * own subclasses.
  254. *
  255. * XFS_LOCK_INUMORDER - for locking several inodes at the some time
  256. * with xfs_lock_inodes(). This flag is used as the starting subclass
  257. * and each subsequent lock acquired will increment the subclass by one.
  258. * So the first lock acquired will have a lockdep subclass of 4, the
  259. * second lock will have a lockdep subclass of 5, and so on. It is
  260. * the responsibility of the class builder to shift this to the correct
  261. * portion of the lock_mode lockdep mask.
  262. */
  263. #define XFS_LOCK_PARENT 1
  264. #define XFS_LOCK_RTBITMAP 2
  265. #define XFS_LOCK_RTSUM 3
  266. #define XFS_LOCK_INUMORDER 4
  267. #define XFS_IOLOCK_SHIFT 16
  268. #define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT)
  269. #define XFS_MMAPLOCK_SHIFT 20
  270. #define XFS_ILOCK_SHIFT 24
  271. #define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT)
  272. #define XFS_ILOCK_RTBITMAP (XFS_LOCK_RTBITMAP << XFS_ILOCK_SHIFT)
  273. #define XFS_ILOCK_RTSUM (XFS_LOCK_RTSUM << XFS_ILOCK_SHIFT)
  274. #define XFS_IOLOCK_DEP_MASK 0x000f0000
  275. #define XFS_MMAPLOCK_DEP_MASK 0x00f00000
  276. #define XFS_ILOCK_DEP_MASK 0xff000000
  277. #define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | \
  278. XFS_MMAPLOCK_DEP_MASK | \
  279. XFS_ILOCK_DEP_MASK)
  280. #define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) \
  281. >> XFS_IOLOCK_SHIFT)
  282. #define XFS_MMAPLOCK_DEP(flags) (((flags) & XFS_MMAPLOCK_DEP_MASK) \
  283. >> XFS_MMAPLOCK_SHIFT)
  284. #define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) \
  285. >> XFS_ILOCK_SHIFT)
  286. /*
  287. * For multiple groups support: if S_ISGID bit is set in the parent
  288. * directory, group of new file is set to that of the parent, and
  289. * new subdirectory gets S_ISGID bit from parent.
  290. */
  291. #define XFS_INHERIT_GID(pip) \
  292. (((pip)->i_mount->m_flags & XFS_MOUNT_GRPID) || \
  293. ((pip)->i_d.di_mode & S_ISGID))
  294. int xfs_release(struct xfs_inode *ip);
  295. void xfs_inactive(struct xfs_inode *ip);
  296. int xfs_lookup(struct xfs_inode *dp, struct xfs_name *name,
  297. struct xfs_inode **ipp, struct xfs_name *ci_name);
  298. int xfs_create(struct xfs_inode *dp, struct xfs_name *name,
  299. umode_t mode, xfs_dev_t rdev, struct xfs_inode **ipp);
  300. int xfs_create_tmpfile(struct xfs_inode *dp, struct dentry *dentry,
  301. umode_t mode, struct xfs_inode **ipp);
  302. int xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
  303. struct xfs_inode *ip);
  304. int xfs_link(struct xfs_inode *tdp, struct xfs_inode *sip,
  305. struct xfs_name *target_name);
  306. int xfs_rename(struct xfs_inode *src_dp, struct xfs_name *src_name,
  307. struct xfs_inode *src_ip, struct xfs_inode *target_dp,
  308. struct xfs_name *target_name,
  309. struct xfs_inode *target_ip, unsigned int flags);
  310. void xfs_ilock(xfs_inode_t *, uint);
  311. int xfs_ilock_nowait(xfs_inode_t *, uint);
  312. void xfs_iunlock(xfs_inode_t *, uint);
  313. void xfs_ilock_demote(xfs_inode_t *, uint);
  314. int xfs_isilocked(xfs_inode_t *, uint);
  315. uint xfs_ilock_data_map_shared(struct xfs_inode *);
  316. uint xfs_ilock_attr_map_shared(struct xfs_inode *);
  317. int xfs_ialloc(struct xfs_trans *, xfs_inode_t *, umode_t,
  318. xfs_nlink_t, xfs_dev_t, prid_t, int,
  319. struct xfs_buf **, xfs_inode_t **);
  320. uint xfs_ip2xflags(struct xfs_inode *);
  321. uint xfs_dic2xflags(struct xfs_dinode *);
  322. int xfs_ifree(struct xfs_trans *, xfs_inode_t *,
  323. struct xfs_bmap_free *);
  324. int xfs_itruncate_extents(struct xfs_trans **, struct xfs_inode *,
  325. int, xfs_fsize_t);
  326. int xfs_iunlink(struct xfs_trans *, xfs_inode_t *);
  327. void xfs_iext_realloc(xfs_inode_t *, int, int);
  328. void xfs_iunpin_wait(xfs_inode_t *);
  329. #define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
  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. int xfs_dir_ialloc(struct xfs_trans **, struct xfs_inode *, umode_t,
  335. xfs_nlink_t, xfs_dev_t, prid_t, int,
  336. struct xfs_inode **, int *);
  337. int xfs_droplink(struct xfs_trans *, struct xfs_inode *);
  338. int xfs_bumplink(struct xfs_trans *, struct xfs_inode *);
  339. /* from xfs_file.c */
  340. enum xfs_prealloc_flags {
  341. XFS_PREALLOC_SET = (1 << 1),
  342. XFS_PREALLOC_CLEAR = (1 << 2),
  343. XFS_PREALLOC_SYNC = (1 << 3),
  344. XFS_PREALLOC_INVISIBLE = (1 << 4),
  345. };
  346. int xfs_update_prealloc_flags(struct xfs_inode *ip,
  347. enum xfs_prealloc_flags flags);
  348. int xfs_zero_eof(struct xfs_inode *ip, xfs_off_t offset,
  349. xfs_fsize_t isize, bool *did_zeroing);
  350. int xfs_iozero(struct xfs_inode *ip, loff_t pos, size_t count);
  351. /* from xfs_iops.c */
  352. /*
  353. * When setting up a newly allocated inode, we need to call
  354. * xfs_finish_inode_setup() once the inode is fully instantiated at
  355. * the VFS level to prevent the rest of the world seeing the inode
  356. * before we've completed instantiation. Otherwise we can do it
  357. * the moment the inode lookup is complete.
  358. */
  359. extern void xfs_setup_inode(struct xfs_inode *ip);
  360. static inline void xfs_finish_inode_setup(struct xfs_inode *ip)
  361. {
  362. xfs_iflags_clear(ip, XFS_INEW);
  363. barrier();
  364. unlock_new_inode(VFS_I(ip));
  365. }
  366. static inline void xfs_setup_existing_inode(struct xfs_inode *ip)
  367. {
  368. xfs_setup_inode(ip);
  369. xfs_finish_inode_setup(ip);
  370. }
  371. #define IHOLD(ip) \
  372. do { \
  373. ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \
  374. ihold(VFS_I(ip)); \
  375. trace_xfs_ihold(ip, _THIS_IP_); \
  376. } while (0)
  377. #define IRELE(ip) \
  378. do { \
  379. trace_xfs_irele(ip, _THIS_IP_); \
  380. iput(VFS_I(ip)); \
  381. } while (0)
  382. extern struct kmem_zone *xfs_inode_zone;
  383. /*
  384. * Flags for read/write calls
  385. */
  386. #define XFS_IO_ISDIRECT 0x00001 /* bypass page cache */
  387. #define XFS_IO_INVIS 0x00002 /* don't update inode timestamps */
  388. #define XFS_IO_FLAGS \
  389. { XFS_IO_ISDIRECT, "DIRECT" }, \
  390. { XFS_IO_INVIS, "INVIS"}
  391. #endif /* __XFS_INODE_H__ */