xfs_inode.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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_BIT 3 /* inode has just been allocated */
  184. #define XFS_INEW (1 << __XFS_INEW_BIT)
  185. #define XFS_ITRUNCATED (1 << 5) /* truncated down so flush-on-close */
  186. #define XFS_IDIRTY_RELEASE (1 << 6) /* dirty release already seen */
  187. #define __XFS_IFLOCK_BIT 7 /* inode is being flushed right now */
  188. #define XFS_IFLOCK (1 << __XFS_IFLOCK_BIT)
  189. #define __XFS_IPINNED_BIT 8 /* wakeup key for zero pin count */
  190. #define XFS_IPINNED (1 << __XFS_IPINNED_BIT)
  191. #define XFS_IDONTCACHE (1 << 9) /* don't cache the inode long term */
  192. /*
  193. * Per-lifetime flags need to be reset when re-using a reclaimable inode during
  194. * inode lookup. This prevents unintended behaviour on the new inode from
  195. * ocurring.
  196. */
  197. #define XFS_IRECLAIM_RESET_FLAGS \
  198. (XFS_IRECLAIMABLE | XFS_IRECLAIM | \
  199. XFS_IDIRTY_RELEASE | XFS_ITRUNCATED)
  200. /*
  201. * Synchronize processes attempting to flush the in-core inode back to disk.
  202. */
  203. extern void __xfs_iflock(struct xfs_inode *ip);
  204. static inline int xfs_iflock_nowait(struct xfs_inode *ip)
  205. {
  206. return !xfs_iflags_test_and_set(ip, XFS_IFLOCK);
  207. }
  208. static inline void xfs_iflock(struct xfs_inode *ip)
  209. {
  210. if (!xfs_iflock_nowait(ip))
  211. __xfs_iflock(ip);
  212. }
  213. static inline void xfs_ifunlock(struct xfs_inode *ip)
  214. {
  215. xfs_iflags_clear(ip, XFS_IFLOCK);
  216. smp_mb();
  217. wake_up_bit(&ip->i_flags, __XFS_IFLOCK_BIT);
  218. }
  219. static inline int xfs_isiflocked(struct xfs_inode *ip)
  220. {
  221. return xfs_iflags_test(ip, XFS_IFLOCK);
  222. }
  223. /*
  224. * Flags for inode locking.
  225. * Bit ranges: 1<<1 - 1<<16-1 -- iolock/ilock modes (bitfield)
  226. * 1<<16 - 1<<32-1 -- lockdep annotation (integers)
  227. */
  228. #define XFS_IOLOCK_EXCL (1<<0)
  229. #define XFS_IOLOCK_SHARED (1<<1)
  230. #define XFS_ILOCK_EXCL (1<<2)
  231. #define XFS_ILOCK_SHARED (1<<3)
  232. #define XFS_MMAPLOCK_EXCL (1<<4)
  233. #define XFS_MMAPLOCK_SHARED (1<<5)
  234. #define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
  235. | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \
  236. | XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED)
  237. #define XFS_LOCK_FLAGS \
  238. { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
  239. { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
  240. { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
  241. { XFS_ILOCK_SHARED, "ILOCK_SHARED" }, \
  242. { XFS_MMAPLOCK_EXCL, "MMAPLOCK_EXCL" }, \
  243. { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" }
  244. /*
  245. * Flags for lockdep annotations.
  246. *
  247. * XFS_LOCK_PARENT - for directory operations that require locking a
  248. * parent directory inode and a child entry inode. IOLOCK requires nesting,
  249. * MMAPLOCK does not support this class, ILOCK requires a single subclass
  250. * to differentiate parent from child.
  251. *
  252. * XFS_LOCK_RTBITMAP/XFS_LOCK_RTSUM - the realtime device bitmap and summary
  253. * inodes do not participate in the normal lock order, and thus have their
  254. * own subclasses.
  255. *
  256. * XFS_LOCK_INUMORDER - for locking several inodes at the some time
  257. * with xfs_lock_inodes(). This flag is used as the starting subclass
  258. * and each subsequent lock acquired will increment the subclass by one.
  259. * However, MAX_LOCKDEP_SUBCLASSES == 8, which means we are greatly
  260. * limited to the subclasses we can represent via nesting. We need at least
  261. * 5 inodes nest depth for the ILOCK through rename, and we also have to support
  262. * XFS_ILOCK_PARENT, which gives 6 subclasses. Then we have XFS_ILOCK_RTBITMAP
  263. * and XFS_ILOCK_RTSUM, which are another 2 unique subclasses, so that's all
  264. * 8 subclasses supported by lockdep.
  265. *
  266. * This also means we have to number the sub-classes in the lowest bits of
  267. * the mask we keep, and we have to ensure we never exceed 3 bits of lockdep
  268. * mask and we can't use bit-masking to build the subclasses. What a mess.
  269. *
  270. * Bit layout:
  271. *
  272. * Bit Lock Region
  273. * 16-19 XFS_IOLOCK_SHIFT dependencies
  274. * 20-23 XFS_MMAPLOCK_SHIFT dependencies
  275. * 24-31 XFS_ILOCK_SHIFT dependencies
  276. *
  277. * IOLOCK values
  278. *
  279. * 0-3 subclass value
  280. * 4-7 PARENT subclass values
  281. *
  282. * MMAPLOCK values
  283. *
  284. * 0-3 subclass value
  285. * 4-7 unused
  286. *
  287. * ILOCK values
  288. * 0-4 subclass values
  289. * 5 PARENT subclass (not nestable)
  290. * 6 RTBITMAP subclass (not nestable)
  291. * 7 RTSUM subclass (not nestable)
  292. *
  293. */
  294. #define XFS_IOLOCK_SHIFT 16
  295. #define XFS_IOLOCK_PARENT_VAL 4
  296. #define XFS_IOLOCK_MAX_SUBCLASS (XFS_IOLOCK_PARENT_VAL - 1)
  297. #define XFS_IOLOCK_DEP_MASK 0x000f0000
  298. #define XFS_IOLOCK_PARENT (XFS_IOLOCK_PARENT_VAL << XFS_IOLOCK_SHIFT)
  299. #define XFS_MMAPLOCK_SHIFT 20
  300. #define XFS_MMAPLOCK_NUMORDER 0
  301. #define XFS_MMAPLOCK_MAX_SUBCLASS 3
  302. #define XFS_MMAPLOCK_DEP_MASK 0x00f00000
  303. #define XFS_ILOCK_SHIFT 24
  304. #define XFS_ILOCK_PARENT_VAL 5
  305. #define XFS_ILOCK_MAX_SUBCLASS (XFS_ILOCK_PARENT_VAL - 1)
  306. #define XFS_ILOCK_RTBITMAP_VAL 6
  307. #define XFS_ILOCK_RTSUM_VAL 7
  308. #define XFS_ILOCK_DEP_MASK 0xff000000
  309. #define XFS_ILOCK_PARENT (XFS_ILOCK_PARENT_VAL << XFS_ILOCK_SHIFT)
  310. #define XFS_ILOCK_RTBITMAP (XFS_ILOCK_RTBITMAP_VAL << XFS_ILOCK_SHIFT)
  311. #define XFS_ILOCK_RTSUM (XFS_ILOCK_RTSUM_VAL << XFS_ILOCK_SHIFT)
  312. #define XFS_LOCK_SUBCLASS_MASK (XFS_IOLOCK_DEP_MASK | \
  313. XFS_MMAPLOCK_DEP_MASK | \
  314. XFS_ILOCK_DEP_MASK)
  315. #define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) \
  316. >> XFS_IOLOCK_SHIFT)
  317. #define XFS_MMAPLOCK_DEP(flags) (((flags) & XFS_MMAPLOCK_DEP_MASK) \
  318. >> XFS_MMAPLOCK_SHIFT)
  319. #define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) \
  320. >> XFS_ILOCK_SHIFT)
  321. /*
  322. * For multiple groups support: if S_ISGID bit is set in the parent
  323. * directory, group of new file is set to that of the parent, and
  324. * new subdirectory gets S_ISGID bit from parent.
  325. */
  326. #define XFS_INHERIT_GID(pip) \
  327. (((pip)->i_mount->m_flags & XFS_MOUNT_GRPID) || \
  328. ((pip)->i_d.di_mode & S_ISGID))
  329. int xfs_release(struct xfs_inode *ip);
  330. void xfs_inactive(struct xfs_inode *ip);
  331. int xfs_lookup(struct xfs_inode *dp, struct xfs_name *name,
  332. struct xfs_inode **ipp, struct xfs_name *ci_name);
  333. int xfs_create(struct xfs_inode *dp, struct xfs_name *name,
  334. umode_t mode, xfs_dev_t rdev, struct xfs_inode **ipp);
  335. int xfs_create_tmpfile(struct xfs_inode *dp, struct dentry *dentry,
  336. umode_t mode, struct xfs_inode **ipp);
  337. int xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
  338. struct xfs_inode *ip);
  339. int xfs_link(struct xfs_inode *tdp, struct xfs_inode *sip,
  340. struct xfs_name *target_name);
  341. int xfs_rename(struct xfs_inode *src_dp, struct xfs_name *src_name,
  342. struct xfs_inode *src_ip, struct xfs_inode *target_dp,
  343. struct xfs_name *target_name,
  344. struct xfs_inode *target_ip, unsigned int flags);
  345. void xfs_ilock(xfs_inode_t *, uint);
  346. int xfs_ilock_nowait(xfs_inode_t *, uint);
  347. void xfs_iunlock(xfs_inode_t *, uint);
  348. void xfs_ilock_demote(xfs_inode_t *, uint);
  349. int xfs_isilocked(xfs_inode_t *, uint);
  350. uint xfs_ilock_data_map_shared(struct xfs_inode *);
  351. uint xfs_ilock_attr_map_shared(struct xfs_inode *);
  352. int xfs_ialloc(struct xfs_trans *, xfs_inode_t *, umode_t,
  353. xfs_nlink_t, xfs_dev_t, prid_t, int,
  354. struct xfs_buf **, xfs_inode_t **);
  355. uint xfs_ip2xflags(struct xfs_inode *);
  356. uint xfs_dic2xflags(struct xfs_dinode *);
  357. int xfs_ifree(struct xfs_trans *, xfs_inode_t *,
  358. struct xfs_bmap_free *);
  359. int xfs_itruncate_extents(struct xfs_trans **, struct xfs_inode *,
  360. int, xfs_fsize_t);
  361. int xfs_iunlink(struct xfs_trans *, xfs_inode_t *);
  362. void xfs_iext_realloc(xfs_inode_t *, int, int);
  363. void xfs_iunpin_wait(xfs_inode_t *);
  364. #define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
  365. int xfs_iflush(struct xfs_inode *, struct xfs_buf **);
  366. void xfs_lock_inodes(xfs_inode_t **, int, uint);
  367. void xfs_lock_two_inodes(xfs_inode_t *, xfs_inode_t *, uint);
  368. xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);
  369. int xfs_dir_ialloc(struct xfs_trans **, struct xfs_inode *, umode_t,
  370. xfs_nlink_t, xfs_dev_t, prid_t, int,
  371. struct xfs_inode **, int *);
  372. int xfs_droplink(struct xfs_trans *, struct xfs_inode *);
  373. int xfs_bumplink(struct xfs_trans *, struct xfs_inode *);
  374. /* from xfs_file.c */
  375. enum xfs_prealloc_flags {
  376. XFS_PREALLOC_SET = (1 << 1),
  377. XFS_PREALLOC_CLEAR = (1 << 2),
  378. XFS_PREALLOC_SYNC = (1 << 3),
  379. XFS_PREALLOC_INVISIBLE = (1 << 4),
  380. };
  381. int xfs_update_prealloc_flags(struct xfs_inode *ip,
  382. enum xfs_prealloc_flags flags);
  383. int xfs_zero_eof(struct xfs_inode *ip, xfs_off_t offset,
  384. xfs_fsize_t isize, bool *did_zeroing);
  385. int xfs_iozero(struct xfs_inode *ip, loff_t pos, size_t count);
  386. /* from xfs_iops.c */
  387. /*
  388. * When setting up a newly allocated inode, we need to call
  389. * xfs_finish_inode_setup() once the inode is fully instantiated at
  390. * the VFS level to prevent the rest of the world seeing the inode
  391. * before we've completed instantiation. Otherwise we can do it
  392. * the moment the inode lookup is complete.
  393. */
  394. extern void xfs_setup_inode(struct xfs_inode *ip);
  395. static inline void xfs_finish_inode_setup(struct xfs_inode *ip)
  396. {
  397. xfs_iflags_clear(ip, XFS_INEW);
  398. barrier();
  399. unlock_new_inode(VFS_I(ip));
  400. wake_up_bit(&ip->i_flags, __XFS_INEW_BIT);
  401. }
  402. static inline void xfs_setup_existing_inode(struct xfs_inode *ip)
  403. {
  404. xfs_setup_inode(ip);
  405. xfs_finish_inode_setup(ip);
  406. }
  407. #define IHOLD(ip) \
  408. do { \
  409. ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \
  410. ihold(VFS_I(ip)); \
  411. trace_xfs_ihold(ip, _THIS_IP_); \
  412. } while (0)
  413. #define IRELE(ip) \
  414. do { \
  415. trace_xfs_irele(ip, _THIS_IP_); \
  416. iput(VFS_I(ip)); \
  417. } while (0)
  418. extern struct kmem_zone *xfs_inode_zone;
  419. /*
  420. * Flags for read/write calls
  421. */
  422. #define XFS_IO_ISDIRECT 0x00001 /* bypass page cache */
  423. #define XFS_IO_INVIS 0x00002 /* don't update inode timestamps */
  424. #define XFS_IO_FLAGS \
  425. { XFS_IO_ISDIRECT, "DIRECT" }, \
  426. { XFS_IO_INVIS, "INVIS"}
  427. #endif /* __XFS_INODE_H__ */