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