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