inode.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * inode.h
  4. *
  5. * Function prototypes
  6. *
  7. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  8. */
  9. #ifndef OCFS2_INODE_H
  10. #define OCFS2_INODE_H
  11. #include "extent_map.h"
  12. /* OCFS2 Inode Private Data */
  13. struct ocfs2_inode_info
  14. {
  15. u64 ip_blkno;
  16. struct ocfs2_lock_res ip_rw_lockres;
  17. struct ocfs2_lock_res ip_inode_lockres;
  18. struct ocfs2_lock_res ip_open_lockres;
  19. /* protects allocation changes on this inode. */
  20. struct rw_semaphore ip_alloc_sem;
  21. /* protects extended attribute changes on this inode */
  22. struct rw_semaphore ip_xattr_sem;
  23. /* These fields are protected by ip_lock */
  24. spinlock_t ip_lock;
  25. u32 ip_open_count;
  26. struct list_head ip_io_markers;
  27. u32 ip_clusters;
  28. u16 ip_dyn_features;
  29. struct mutex ip_io_mutex;
  30. u32 ip_flags; /* see below */
  31. u32 ip_attr; /* inode attributes */
  32. /* Record unwritten extents during direct io. */
  33. struct list_head ip_unwritten_list;
  34. /* protected by recovery_lock. */
  35. struct inode *ip_next_orphan;
  36. struct ocfs2_caching_info ip_metadata_cache;
  37. struct ocfs2_extent_map ip_extent_map;
  38. struct inode vfs_inode;
  39. struct jbd2_inode ip_jinode;
  40. u32 ip_dir_start_lookup;
  41. /* Only valid if the inode is the dir. */
  42. u32 ip_last_used_slot;
  43. u64 ip_last_used_group;
  44. u32 ip_dir_lock_gen;
  45. struct ocfs2_alloc_reservation ip_la_data_resv;
  46. /*
  47. * Transactions that contain inode's metadata needed to complete
  48. * fsync and fdatasync, respectively.
  49. */
  50. tid_t i_sync_tid;
  51. tid_t i_datasync_tid;
  52. struct dquot *i_dquot[MAXQUOTAS];
  53. };
  54. /*
  55. * Flags for the ip_flags field
  56. */
  57. /* System file inodes */
  58. #define OCFS2_INODE_SYSTEM_FILE 0x00000001
  59. #define OCFS2_INODE_JOURNAL 0x00000002
  60. #define OCFS2_INODE_BITMAP 0x00000004
  61. /* This inode has been wiped from disk */
  62. #define OCFS2_INODE_DELETED 0x00000008
  63. /* Has the inode been orphaned on another node?
  64. *
  65. * This hints to ocfs2_drop_inode that it should clear i_nlink before
  66. * continuing.
  67. *
  68. * We *only* set this on unlink vote from another node. If the inode
  69. * was locally orphaned, then we're sure of the state and don't need
  70. * to twiddle i_nlink later - it's either zero or not depending on
  71. * whether our unlink succeeded. Otherwise we got this from a node
  72. * whose intention was to orphan the inode, however he may have
  73. * crashed, failed etc, so we let ocfs2_drop_inode zero the value and
  74. * rely on ocfs2_delete_inode to sort things out under the proper
  75. * cluster locks.
  76. */
  77. #define OCFS2_INODE_MAYBE_ORPHANED 0x00000010
  78. /* Does someone have the file open O_DIRECT */
  79. #define OCFS2_INODE_OPEN_DIRECT 0x00000020
  80. /* Tell the inode wipe code it's not in orphan dir */
  81. #define OCFS2_INODE_SKIP_ORPHAN_DIR 0x00000040
  82. /* Entry in orphan dir with 'dio-' prefix */
  83. #define OCFS2_INODE_DIO_ORPHAN_ENTRY 0x00000080
  84. static inline struct ocfs2_inode_info *OCFS2_I(struct inode *inode)
  85. {
  86. return container_of(inode, struct ocfs2_inode_info, vfs_inode);
  87. }
  88. #define INODE_JOURNAL(i) (OCFS2_I(i)->ip_flags & OCFS2_INODE_JOURNAL)
  89. #define SET_INODE_JOURNAL(i) (OCFS2_I(i)->ip_flags |= OCFS2_INODE_JOURNAL)
  90. extern const struct address_space_operations ocfs2_aops;
  91. extern const struct ocfs2_caching_operations ocfs2_inode_caching_ops;
  92. static inline struct ocfs2_caching_info *INODE_CACHE(struct inode *inode)
  93. {
  94. return &OCFS2_I(inode)->ip_metadata_cache;
  95. }
  96. void ocfs2_evict_inode(struct inode *inode);
  97. int ocfs2_drop_inode(struct inode *inode);
  98. /* Flags for ocfs2_iget() */
  99. #define OCFS2_FI_FLAG_SYSFILE 0x1
  100. #define OCFS2_FI_FLAG_ORPHAN_RECOVERY 0x2
  101. #define OCFS2_FI_FLAG_FILECHECK_CHK 0x4
  102. #define OCFS2_FI_FLAG_FILECHECK_FIX 0x8
  103. struct inode *ocfs2_ilookup(struct super_block *sb, u64 feoff);
  104. struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 feoff, unsigned flags,
  105. int sysfile_type);
  106. int ocfs2_inode_revalidate(struct dentry *dentry);
  107. void ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
  108. int create_ino);
  109. void ocfs2_sync_blockdev(struct super_block *sb);
  110. void ocfs2_refresh_inode(struct inode *inode,
  111. struct ocfs2_dinode *fe);
  112. int ocfs2_mark_inode_dirty(handle_t *handle,
  113. struct inode *inode,
  114. struct buffer_head *bh);
  115. void ocfs2_set_inode_flags(struct inode *inode);
  116. void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
  117. static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
  118. {
  119. int c_to_s_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits - 9;
  120. return (blkcnt_t)OCFS2_I(inode)->ip_clusters << c_to_s_bits;
  121. }
  122. /* Validate that a bh contains a valid inode */
  123. int ocfs2_validate_inode_block(struct super_block *sb,
  124. struct buffer_head *bh);
  125. /*
  126. * Read an inode block into *bh. If *bh is NULL, a bh will be allocated.
  127. * This is a cached read. The inode will be validated with
  128. * ocfs2_validate_inode_block().
  129. */
  130. int ocfs2_read_inode_block(struct inode *inode, struct buffer_head **bh);
  131. /* The same, but can be passed OCFS2_BH_* flags */
  132. int ocfs2_read_inode_block_full(struct inode *inode, struct buffer_head **bh,
  133. int flags);
  134. static inline struct ocfs2_inode_info *cache_info_to_inode(struct ocfs2_caching_info *ci)
  135. {
  136. return container_of(ci, struct ocfs2_inode_info, ip_metadata_cache);
  137. }
  138. /* Does this inode have the reflink flag set? */
  139. static inline bool ocfs2_is_refcount_inode(struct inode *inode)
  140. {
  141. return (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL);
  142. }
  143. #endif /* OCFS2_INODE_H */