fast_commit.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_MAX
  86. };
  87. #ifdef __KERNEL__
  88. /*
  89. * In memory list of dentry updates that are performed on the file
  90. * system used by fast commit code.
  91. */
  92. struct ext4_fc_dentry_update {
  93. int fcd_op; /* Type of update create / unlink / link */
  94. int fcd_parent; /* Parent inode number */
  95. int fcd_ino; /* Inode number */
  96. struct qstr fcd_name; /* Dirent name */
  97. unsigned char fcd_iname[DNAME_INLINE_LEN]; /* Dirent name string */
  98. struct list_head fcd_list;
  99. struct list_head fcd_dilist;
  100. };
  101. struct ext4_fc_stats {
  102. unsigned int fc_ineligible_reason_count[EXT4_FC_REASON_MAX];
  103. unsigned long fc_num_commits;
  104. unsigned long fc_ineligible_commits;
  105. unsigned long fc_failed_commits;
  106. unsigned long fc_skipped_commits;
  107. unsigned long fc_numblks;
  108. u64 s_fc_avg_commit_time;
  109. };
  110. #define EXT4_FC_REPLAY_REALLOC_INCREMENT 4
  111. /*
  112. * Physical block regions added to different inodes due to fast commit
  113. * recovery. These are set during the SCAN phase. During the replay phase,
  114. * our allocator excludes these from its allocation. This ensures that
  115. * we don't accidentally allocating a block that is going to be used by
  116. * another inode.
  117. */
  118. struct ext4_fc_alloc_region {
  119. ext4_lblk_t lblk;
  120. ext4_fsblk_t pblk;
  121. int ino, len;
  122. };
  123. /*
  124. * Fast commit replay state.
  125. */
  126. struct ext4_fc_replay_state {
  127. int fc_replay_num_tags;
  128. int fc_replay_expected_off;
  129. int fc_current_pass;
  130. int fc_cur_tag;
  131. int fc_crc;
  132. struct ext4_fc_alloc_region *fc_regions;
  133. int fc_regions_size, fc_regions_used, fc_regions_valid;
  134. int *fc_modified_inodes;
  135. int fc_modified_inodes_used, fc_modified_inodes_size;
  136. };
  137. #define region_last(__region) (((__region)->lblk) + ((__region)->len) - 1)
  138. #endif
  139. static inline const char *tag2str(__u16 tag)
  140. {
  141. switch (tag) {
  142. case EXT4_FC_TAG_LINK:
  143. return "ADD_ENTRY";
  144. case EXT4_FC_TAG_UNLINK:
  145. return "DEL_ENTRY";
  146. case EXT4_FC_TAG_ADD_RANGE:
  147. return "ADD_RANGE";
  148. case EXT4_FC_TAG_CREAT:
  149. return "CREAT_DENTRY";
  150. case EXT4_FC_TAG_DEL_RANGE:
  151. return "DEL_RANGE";
  152. case EXT4_FC_TAG_INODE:
  153. return "INODE";
  154. case EXT4_FC_TAG_PAD:
  155. return "PAD";
  156. case EXT4_FC_TAG_TAIL:
  157. return "TAIL";
  158. case EXT4_FC_TAG_HEAD:
  159. return "HEAD";
  160. default:
  161. return "ERROR";
  162. }
  163. }
  164. #endif /* __FAST_COMMIT_H__ */