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