fast_commit.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __FAST_COMMIT_H__
  3. #define __FAST_COMMIT_H__
  4. /*
  5. * Note this file is present in e2fsprogs/lib/ext2fs/fast_commit.h and
  6. * linux/fs/ext4/fast_commit.h. These file should always be byte identical.
  7. */
  8. /* Fast commit tags */
  9. #define EXT4_FC_TAG_ADD_RANGE 0x0001
  10. #define EXT4_FC_TAG_DEL_RANGE 0x0002
  11. #define EXT4_FC_TAG_CREAT 0x0003
  12. #define EXT4_FC_TAG_LINK 0x0004
  13. #define EXT4_FC_TAG_UNLINK 0x0005
  14. #define EXT4_FC_TAG_INODE 0x0006
  15. #define EXT4_FC_TAG_PAD 0x0007
  16. #define EXT4_FC_TAG_TAIL 0x0008
  17. #define EXT4_FC_TAG_HEAD 0x0009
  18. #define EXT4_FC_SUPPORTED_FEATURES 0x0
  19. /* On disk fast commit tlv value structures */
  20. /* Fast commit on disk tag length structure */
  21. struct ext4_fc_tl {
  22. __le16 fc_tag;
  23. __le16 fc_len;
  24. };
  25. /* Value structure for tag EXT4_FC_TAG_HEAD. */
  26. struct ext4_fc_head {
  27. __le32 fc_features;
  28. __le32 fc_tid;
  29. };
  30. /* Value structure for EXT4_FC_TAG_ADD_RANGE. */
  31. struct ext4_fc_add_range {
  32. __le32 fc_ino;
  33. __u8 fc_ex[12];
  34. };
  35. /* Value structure for tag EXT4_FC_TAG_DEL_RANGE. */
  36. struct ext4_fc_del_range {
  37. __le32 fc_ino;
  38. __le32 fc_lblk;
  39. __le32 fc_len;
  40. };
  41. /*
  42. * This is the value structure for tags EXT4_FC_TAG_CREAT, EXT4_FC_TAG_LINK
  43. * and EXT4_FC_TAG_UNLINK.
  44. */
  45. struct ext4_fc_dentry_info {
  46. __le32 fc_parent_ino;
  47. __le32 fc_ino;
  48. __u8 fc_dname[];
  49. };
  50. /* Value structure for EXT4_FC_TAG_INODE. */
  51. struct ext4_fc_inode {
  52. __le32 fc_ino;
  53. __u8 fc_raw_inode[];
  54. };
  55. /* Value structure for tag EXT4_FC_TAG_TAIL. */
  56. struct ext4_fc_tail {
  57. __le32 fc_tid;
  58. __le32 fc_crc;
  59. };
  60. /* Tag base length */
  61. #define EXT4_FC_TAG_BASE_LEN (sizeof(struct ext4_fc_tl))
  62. /*
  63. * Fast commit status codes
  64. */
  65. enum {
  66. EXT4_FC_STATUS_OK = 0,
  67. EXT4_FC_STATUS_INELIGIBLE,
  68. EXT4_FC_STATUS_SKIPPED,
  69. EXT4_FC_STATUS_FAILED,
  70. };
  71. /*
  72. * Fast commit ineligiblity reasons:
  73. */
  74. enum {
  75. EXT4_FC_REASON_XATTR = 0,
  76. EXT4_FC_REASON_CROSS_RENAME,
  77. EXT4_FC_REASON_JOURNAL_FLAG_CHANGE,
  78. EXT4_FC_REASON_NOMEM,
  79. EXT4_FC_REASON_SWAP_BOOT,
  80. EXT4_FC_REASON_RESIZE,
  81. EXT4_FC_REASON_RENAME_DIR,
  82. EXT4_FC_REASON_FALLOC_RANGE,
  83. EXT4_FC_REASON_INODE_JOURNAL_DATA,
  84. EXT4_FC_REASON_ENCRYPTED_FILENAME,
  85. EXT4_FC_REASON_MIGRATE,
  86. EXT4_FC_REASON_VERITY,
  87. EXT4_FC_REASON_MOVE_EXT,
  88. EXT4_FC_REASON_MAX
  89. };
  90. #ifdef __KERNEL__
  91. /*
  92. * In memory list of dentry updates that are performed on the file
  93. * system used by fast commit code.
  94. */
  95. struct ext4_fc_dentry_update {
  96. int fcd_op; /* Type of update create / unlink / link */
  97. int fcd_parent; /* Parent inode number */
  98. int fcd_ino; /* Inode number */
  99. struct name_snapshot fcd_name; /* Dirent name */
  100. struct list_head fcd_list;
  101. struct list_head fcd_dilist;
  102. };
  103. struct ext4_fc_stats {
  104. unsigned int fc_ineligible_reason_count[EXT4_FC_REASON_MAX];
  105. unsigned long fc_num_commits;
  106. unsigned long fc_ineligible_commits;
  107. unsigned long fc_failed_commits;
  108. unsigned long fc_skipped_commits;
  109. unsigned long fc_numblks;
  110. u64 s_fc_avg_commit_time;
  111. };
  112. #define EXT4_FC_REPLAY_REALLOC_INCREMENT 4
  113. /*
  114. * Physical block regions added to different inodes due to fast commit
  115. * recovery. These are set during the SCAN phase. During the replay phase,
  116. * our allocator excludes these from its allocation. This ensures that
  117. * we don't accidentally allocating a block that is going to be used by
  118. * another inode.
  119. */
  120. struct ext4_fc_alloc_region {
  121. ext4_lblk_t lblk;
  122. ext4_fsblk_t pblk;
  123. int ino, len;
  124. };
  125. /*
  126. * Fast commit replay state.
  127. */
  128. struct ext4_fc_replay_state {
  129. int fc_replay_num_tags;
  130. int fc_replay_expected_off;
  131. int fc_current_pass;
  132. int fc_cur_tag;
  133. int fc_crc;
  134. struct ext4_fc_alloc_region *fc_regions;
  135. int fc_regions_size, fc_regions_used, fc_regions_valid;
  136. int *fc_modified_inodes;
  137. int fc_modified_inodes_used, fc_modified_inodes_size;
  138. };
  139. #define region_last(__region) (((__region)->lblk) + ((__region)->len) - 1)
  140. #endif
  141. static inline const char *tag2str(__u16 tag)
  142. {
  143. switch (tag) {
  144. case EXT4_FC_TAG_LINK:
  145. return "ADD_ENTRY";
  146. case EXT4_FC_TAG_UNLINK:
  147. return "DEL_ENTRY";
  148. case EXT4_FC_TAG_ADD_RANGE:
  149. return "ADD_RANGE";
  150. case EXT4_FC_TAG_CREAT:
  151. return "CREAT_DENTRY";
  152. case EXT4_FC_TAG_DEL_RANGE:
  153. return "DEL_RANGE";
  154. case EXT4_FC_TAG_INODE:
  155. return "INODE";
  156. case EXT4_FC_TAG_PAD:
  157. return "PAD";
  158. case EXT4_FC_TAG_TAIL:
  159. return "TAIL";
  160. case EXT4_FC_TAG_HEAD:
  161. return "HEAD";
  162. default:
  163. return "ERROR";
  164. }
  165. }
  166. #endif /* __FAST_COMMIT_H__ */