18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci#ifndef __FAST_COMMIT_H__
48c2ecf20Sopenharmony_ci#define __FAST_COMMIT_H__
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/* Fast commit tags */
78c2ecf20Sopenharmony_ci#define EXT4_FC_TAG_ADD_RANGE		0x0001
88c2ecf20Sopenharmony_ci#define EXT4_FC_TAG_DEL_RANGE		0x0002
98c2ecf20Sopenharmony_ci#define EXT4_FC_TAG_CREAT		0x0003
108c2ecf20Sopenharmony_ci#define EXT4_FC_TAG_LINK		0x0004
118c2ecf20Sopenharmony_ci#define EXT4_FC_TAG_UNLINK		0x0005
128c2ecf20Sopenharmony_ci#define EXT4_FC_TAG_INODE		0x0006
138c2ecf20Sopenharmony_ci#define EXT4_FC_TAG_PAD			0x0007
148c2ecf20Sopenharmony_ci#define EXT4_FC_TAG_TAIL		0x0008
158c2ecf20Sopenharmony_ci#define EXT4_FC_TAG_HEAD		0x0009
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define EXT4_FC_SUPPORTED_FEATURES	0x0
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/* On disk fast commit tlv value structures */
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* Fast commit on disk tag length structure */
228c2ecf20Sopenharmony_cistruct ext4_fc_tl {
238c2ecf20Sopenharmony_ci	__le16 fc_tag;
248c2ecf20Sopenharmony_ci	__le16 fc_len;
258c2ecf20Sopenharmony_ci};
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* Value structure for tag EXT4_FC_TAG_HEAD. */
288c2ecf20Sopenharmony_cistruct ext4_fc_head {
298c2ecf20Sopenharmony_ci	__le32 fc_features;
308c2ecf20Sopenharmony_ci	__le32 fc_tid;
318c2ecf20Sopenharmony_ci};
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/* Value structure for EXT4_FC_TAG_ADD_RANGE. */
348c2ecf20Sopenharmony_cistruct ext4_fc_add_range {
358c2ecf20Sopenharmony_ci	__le32 fc_ino;
368c2ecf20Sopenharmony_ci	__u8 fc_ex[12];
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* Value structure for tag EXT4_FC_TAG_DEL_RANGE. */
408c2ecf20Sopenharmony_cistruct ext4_fc_del_range {
418c2ecf20Sopenharmony_ci	__le32 fc_ino;
428c2ecf20Sopenharmony_ci	__le32 fc_lblk;
438c2ecf20Sopenharmony_ci	__le32 fc_len;
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/*
478c2ecf20Sopenharmony_ci * This is the value structure for tags EXT4_FC_TAG_CREAT, EXT4_FC_TAG_LINK
488c2ecf20Sopenharmony_ci * and EXT4_FC_TAG_UNLINK.
498c2ecf20Sopenharmony_ci */
508c2ecf20Sopenharmony_cistruct ext4_fc_dentry_info {
518c2ecf20Sopenharmony_ci	__le32 fc_parent_ino;
528c2ecf20Sopenharmony_ci	__le32 fc_ino;
538c2ecf20Sopenharmony_ci	u8 fc_dname[0];
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* Value structure for EXT4_FC_TAG_INODE and EXT4_FC_TAG_INODE_PARTIAL. */
578c2ecf20Sopenharmony_cistruct ext4_fc_inode {
588c2ecf20Sopenharmony_ci	__le32 fc_ino;
598c2ecf20Sopenharmony_ci	__u8 fc_raw_inode[0];
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci/* Value structure for tag EXT4_FC_TAG_TAIL. */
638c2ecf20Sopenharmony_cistruct ext4_fc_tail {
648c2ecf20Sopenharmony_ci	__le32 fc_tid;
658c2ecf20Sopenharmony_ci	__le32 fc_crc;
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/*
698c2ecf20Sopenharmony_ci * In memory list of dentry updates that are performed on the file
708c2ecf20Sopenharmony_ci * system used by fast commit code.
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_cistruct ext4_fc_dentry_update {
738c2ecf20Sopenharmony_ci	int fcd_op;		/* Type of update create / unlink / link */
748c2ecf20Sopenharmony_ci	int fcd_parent;		/* Parent inode number */
758c2ecf20Sopenharmony_ci	int fcd_ino;		/* Inode number */
768c2ecf20Sopenharmony_ci	struct qstr fcd_name;	/* Dirent name */
778c2ecf20Sopenharmony_ci	unsigned char fcd_iname[DNAME_INLINE_LEN];	/* Dirent name string */
788c2ecf20Sopenharmony_ci	struct list_head fcd_list;
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/*
828c2ecf20Sopenharmony_ci * Fast commit reason codes
838c2ecf20Sopenharmony_ci */
848c2ecf20Sopenharmony_cienum {
858c2ecf20Sopenharmony_ci	/*
868c2ecf20Sopenharmony_ci	 * Commit status codes:
878c2ecf20Sopenharmony_ci	 */
888c2ecf20Sopenharmony_ci	EXT4_FC_REASON_OK = 0,
898c2ecf20Sopenharmony_ci	EXT4_FC_REASON_INELIGIBLE,
908c2ecf20Sopenharmony_ci	EXT4_FC_REASON_ALREADY_COMMITTED,
918c2ecf20Sopenharmony_ci	EXT4_FC_REASON_FC_START_FAILED,
928c2ecf20Sopenharmony_ci	EXT4_FC_REASON_FC_FAILED,
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	/*
958c2ecf20Sopenharmony_ci	 * Fast commit ineligiblity reasons:
968c2ecf20Sopenharmony_ci	 */
978c2ecf20Sopenharmony_ci	EXT4_FC_REASON_XATTR = 0,
988c2ecf20Sopenharmony_ci	EXT4_FC_REASON_CROSS_RENAME,
998c2ecf20Sopenharmony_ci	EXT4_FC_REASON_JOURNAL_FLAG_CHANGE,
1008c2ecf20Sopenharmony_ci	EXT4_FC_REASON_NOMEM,
1018c2ecf20Sopenharmony_ci	EXT4_FC_REASON_SWAP_BOOT,
1028c2ecf20Sopenharmony_ci	EXT4_FC_REASON_RESIZE,
1038c2ecf20Sopenharmony_ci	EXT4_FC_REASON_RENAME_DIR,
1048c2ecf20Sopenharmony_ci	EXT4_FC_REASON_FALLOC_RANGE,
1058c2ecf20Sopenharmony_ci	EXT4_FC_REASON_INODE_JOURNAL_DATA,
1068c2ecf20Sopenharmony_ci	EXT4_FC_COMMIT_FAILED,
1078c2ecf20Sopenharmony_ci	EXT4_FC_REASON_ENCRYPTED_FILENAME,
1088c2ecf20Sopenharmony_ci	EXT4_FC_REASON_MAX
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistruct ext4_fc_stats {
1128c2ecf20Sopenharmony_ci	unsigned int fc_ineligible_reason_count[EXT4_FC_REASON_MAX];
1138c2ecf20Sopenharmony_ci	unsigned long fc_num_commits;
1148c2ecf20Sopenharmony_ci	unsigned long fc_ineligible_commits;
1158c2ecf20Sopenharmony_ci	unsigned long fc_numblks;
1168c2ecf20Sopenharmony_ci};
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#define EXT4_FC_REPLAY_REALLOC_INCREMENT	4
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/*
1218c2ecf20Sopenharmony_ci * Physical block regions added to different inodes due to fast commit
1228c2ecf20Sopenharmony_ci * recovery. These are set during the SCAN phase. During the replay phase,
1238c2ecf20Sopenharmony_ci * our allocator excludes these from its allocation. This ensures that
1248c2ecf20Sopenharmony_ci * we don't accidentally allocating a block that is going to be used by
1258c2ecf20Sopenharmony_ci * another inode.
1268c2ecf20Sopenharmony_ci */
1278c2ecf20Sopenharmony_cistruct ext4_fc_alloc_region {
1288c2ecf20Sopenharmony_ci	ext4_lblk_t lblk;
1298c2ecf20Sopenharmony_ci	ext4_fsblk_t pblk;
1308c2ecf20Sopenharmony_ci	int ino, len;
1318c2ecf20Sopenharmony_ci};
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/*
1348c2ecf20Sopenharmony_ci * Fast commit replay state.
1358c2ecf20Sopenharmony_ci */
1368c2ecf20Sopenharmony_cistruct ext4_fc_replay_state {
1378c2ecf20Sopenharmony_ci	int fc_replay_num_tags;
1388c2ecf20Sopenharmony_ci	int fc_replay_expected_off;
1398c2ecf20Sopenharmony_ci	int fc_current_pass;
1408c2ecf20Sopenharmony_ci	int fc_cur_tag;
1418c2ecf20Sopenharmony_ci	int fc_crc;
1428c2ecf20Sopenharmony_ci	struct ext4_fc_alloc_region *fc_regions;
1438c2ecf20Sopenharmony_ci	int fc_regions_size, fc_regions_used, fc_regions_valid;
1448c2ecf20Sopenharmony_ci	int *fc_modified_inodes;
1458c2ecf20Sopenharmony_ci	int fc_modified_inodes_used, fc_modified_inodes_size;
1468c2ecf20Sopenharmony_ci};
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#define region_last(__region) (((__region)->lblk) + ((__region)->len) - 1)
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#endif /* __FAST_COMMIT_H__ */
152