Harshad Shirwadkar | 6866d7b | 2020-10-15 13:37:55 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | |
| 3 | #ifndef __FAST_COMMIT_H__ |
| 4 | #define __FAST_COMMIT_H__ |
| 5 | |
Harshad Shirwadkar | aa75f4d | 2020-10-15 13:37:57 -0700 | [diff] [blame] | 6 | /* Fast commit tags */ |
| 7 | #define EXT4_FC_TAG_ADD_RANGE 0x0001 |
| 8 | #define EXT4_FC_TAG_DEL_RANGE 0x0002 |
| 9 | #define EXT4_FC_TAG_CREAT 0x0003 |
| 10 | #define EXT4_FC_TAG_LINK 0x0004 |
| 11 | #define EXT4_FC_TAG_UNLINK 0x0005 |
| 12 | #define EXT4_FC_TAG_INODE 0x0006 |
| 13 | #define EXT4_FC_TAG_PAD 0x0007 |
| 14 | #define EXT4_FC_TAG_TAIL 0x0008 |
| 15 | #define EXT4_FC_TAG_HEAD 0x0009 |
| 16 | |
| 17 | #define EXT4_FC_SUPPORTED_FEATURES 0x0 |
| 18 | |
| 19 | /* On disk fast commit tlv value structures */ |
| 20 | |
| 21 | /* Fast commit on disk tag length structure */ |
| 22 | struct ext4_fc_tl { |
| 23 | __le16 fc_tag; |
| 24 | __le16 fc_len; |
| 25 | }; |
| 26 | |
| 27 | /* Value structure for tag EXT4_FC_TAG_HEAD. */ |
| 28 | struct ext4_fc_head { |
| 29 | __le32 fc_features; |
| 30 | __le32 fc_tid; |
| 31 | }; |
| 32 | |
| 33 | /* Value structure for EXT4_FC_TAG_ADD_RANGE. */ |
| 34 | struct ext4_fc_add_range { |
| 35 | __le32 fc_ino; |
| 36 | __u8 fc_ex[12]; |
| 37 | }; |
| 38 | |
| 39 | /* Value structure for tag EXT4_FC_TAG_DEL_RANGE. */ |
| 40 | struct ext4_fc_del_range { |
| 41 | __le32 fc_ino; |
| 42 | __le32 fc_lblk; |
| 43 | __le32 fc_len; |
| 44 | }; |
| 45 | |
| 46 | /* |
| 47 | * This is the value structure for tags EXT4_FC_TAG_CREAT, EXT4_FC_TAG_LINK |
| 48 | * and EXT4_FC_TAG_UNLINK. |
| 49 | */ |
| 50 | struct ext4_fc_dentry_info { |
| 51 | __le32 fc_parent_ino; |
| 52 | __le32 fc_ino; |
| 53 | u8 fc_dname[0]; |
| 54 | }; |
| 55 | |
| 56 | /* Value structure for EXT4_FC_TAG_INODE and EXT4_FC_TAG_INODE_PARTIAL. */ |
| 57 | struct ext4_fc_inode { |
| 58 | __le32 fc_ino; |
| 59 | __u8 fc_raw_inode[0]; |
| 60 | }; |
| 61 | |
| 62 | /* Value structure for tag EXT4_FC_TAG_TAIL. */ |
| 63 | struct ext4_fc_tail { |
| 64 | __le32 fc_tid; |
| 65 | __le32 fc_crc; |
| 66 | }; |
| 67 | |
| 68 | /* |
| 69 | * In memory list of dentry updates that are performed on the file |
| 70 | * system used by fast commit code. |
| 71 | */ |
| 72 | struct ext4_fc_dentry_update { |
| 73 | int fcd_op; /* Type of update create / unlink / link */ |
| 74 | int fcd_parent; /* Parent inode number */ |
| 75 | int fcd_ino; /* Inode number */ |
| 76 | struct qstr fcd_name; /* Dirent name */ |
| 77 | unsigned char fcd_iname[DNAME_INLINE_LEN]; /* Dirent name string */ |
| 78 | struct list_head fcd_list; |
| 79 | }; |
| 80 | |
| 81 | /* |
| 82 | * Fast commit reason codes |
| 83 | */ |
| 84 | enum { |
| 85 | /* |
| 86 | * Commit status codes: |
| 87 | */ |
| 88 | EXT4_FC_REASON_OK = 0, |
| 89 | EXT4_FC_REASON_INELIGIBLE, |
| 90 | EXT4_FC_REASON_ALREADY_COMMITTED, |
| 91 | EXT4_FC_REASON_FC_START_FAILED, |
| 92 | EXT4_FC_REASON_FC_FAILED, |
| 93 | |
| 94 | /* |
| 95 | * Fast commit ineligiblity reasons: |
| 96 | */ |
| 97 | EXT4_FC_REASON_XATTR = 0, |
| 98 | EXT4_FC_REASON_CROSS_RENAME, |
| 99 | EXT4_FC_REASON_JOURNAL_FLAG_CHANGE, |
Harshad Shirwadkar | b21ebf1 | 2020-11-05 19:58:51 -0800 | [diff] [blame] | 100 | EXT4_FC_REASON_NOMEM, |
Harshad Shirwadkar | aa75f4d | 2020-10-15 13:37:57 -0700 | [diff] [blame] | 101 | EXT4_FC_REASON_SWAP_BOOT, |
| 102 | EXT4_FC_REASON_RESIZE, |
| 103 | EXT4_FC_REASON_RENAME_DIR, |
| 104 | EXT4_FC_REASON_FALLOC_RANGE, |
Harshad Shirwadkar | 556e031 | 2020-11-05 19:59:07 -0800 | [diff] [blame] | 105 | EXT4_FC_REASON_INODE_JOURNAL_DATA, |
Harshad Shirwadkar | aa75f4d | 2020-10-15 13:37:57 -0700 | [diff] [blame] | 106 | EXT4_FC_COMMIT_FAILED, |
| 107 | EXT4_FC_REASON_MAX |
| 108 | }; |
| 109 | |
| 110 | struct ext4_fc_stats { |
| 111 | unsigned int fc_ineligible_reason_count[EXT4_FC_REASON_MAX]; |
| 112 | unsigned long fc_num_commits; |
| 113 | unsigned long fc_ineligible_commits; |
| 114 | unsigned long fc_numblks; |
| 115 | }; |
| 116 | |
Harshad Shirwadkar | 8016e29 | 2020-10-15 13:37:59 -0700 | [diff] [blame] | 117 | #define EXT4_FC_REPLAY_REALLOC_INCREMENT 4 |
| 118 | |
| 119 | /* |
| 120 | * Physical block regions added to different inodes due to fast commit |
| 121 | * recovery. These are set during the SCAN phase. During the replay phase, |
| 122 | * our allocator excludes these from its allocation. This ensures that |
| 123 | * we don't accidentally allocating a block that is going to be used by |
| 124 | * another inode. |
| 125 | */ |
| 126 | struct ext4_fc_alloc_region { |
| 127 | ext4_lblk_t lblk; |
| 128 | ext4_fsblk_t pblk; |
| 129 | int ino, len; |
| 130 | }; |
| 131 | |
| 132 | /* |
| 133 | * Fast commit replay state. |
| 134 | */ |
| 135 | struct ext4_fc_replay_state { |
| 136 | int fc_replay_num_tags; |
| 137 | int fc_replay_expected_off; |
| 138 | int fc_current_pass; |
| 139 | int fc_cur_tag; |
| 140 | int fc_crc; |
| 141 | struct ext4_fc_alloc_region *fc_regions; |
| 142 | int fc_regions_size, fc_regions_used, fc_regions_valid; |
| 143 | int *fc_modified_inodes; |
| 144 | int fc_modified_inodes_used, fc_modified_inodes_size; |
| 145 | }; |
| 146 | |
| 147 | #define region_last(__region) (((__region)->lblk) + ((__region)->len) - 1) |
| 148 | |
Harshad Shirwadkar | 8016e29 | 2020-10-15 13:37:59 -0700 | [diff] [blame] | 149 | |
Harshad Shirwadkar | 6866d7b | 2020-10-15 13:37:55 -0700 | [diff] [blame] | 150 | #endif /* __FAST_COMMIT_H__ */ |