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