Skip to content

Commit

Permalink
ext4: make fast_commit.h byte identical with e2fsprogs/fast_commit.h
Browse files Browse the repository at this point in the history
This patch makes fast_commit.h byte by byte identical with
e2fsprogs/fast_commit.h. This will help us ensure that there are no
on-disk format inconsistencies between e2fsck and kernel ext4.

Signed-off-by: Harshad Shirwadkar <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
harshadjs authored and tytso committed Dec 17, 2020
1 parent 5a150bd commit 941ba12
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 55 deletions.
38 changes: 0 additions & 38 deletions fs/ext4/fast_commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,18 +1281,6 @@ static void ext4_fc_cleanup(journal_t *journal, int full)

/* Ext4 Replay Path Routines */

/* Get length of a particular tlv */
static inline int ext4_fc_tag_len(struct ext4_fc_tl *tl)
{
return le16_to_cpu(tl->fc_len);
}

/* Get a pointer to "value" of a tlv */
static inline u8 *ext4_fc_tag_val(struct ext4_fc_tl *tl)
{
return (u8 *)tl + sizeof(*tl);
}

/* Helper struct for dentry replay routines */
struct dentry_info_args {
int parent_ino, dname_len, ino, inode_len;
Expand Down Expand Up @@ -1831,32 +1819,6 @@ ext4_fc_replay_del_range(struct super_block *sb, struct ext4_fc_tl *tl)
return 0;
}

static inline const char *tag2str(u16 tag)
{
switch (tag) {
case EXT4_FC_TAG_LINK:
return "TAG_ADD_ENTRY";
case EXT4_FC_TAG_UNLINK:
return "TAG_DEL_ENTRY";
case EXT4_FC_TAG_ADD_RANGE:
return "TAG_ADD_RANGE";
case EXT4_FC_TAG_CREAT:
return "TAG_CREAT_DENTRY";
case EXT4_FC_TAG_DEL_RANGE:
return "TAG_DEL_RANGE";
case EXT4_FC_TAG_INODE:
return "TAG_INODE";
case EXT4_FC_TAG_PAD:
return "TAG_PAD";
case EXT4_FC_TAG_TAIL:
return "TAG_TAIL";
case EXT4_FC_TAG_HEAD:
return "TAG_HEAD";
default:
return "TAG_ERROR";
}
}

static void ext4_fc_set_bitmaps_and_counters(struct super_block *sb)
{
struct ext4_fc_replay_state *state;
Expand Down
78 changes: 61 additions & 17 deletions fs/ext4/fast_commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#ifndef __FAST_COMMIT_H__
#define __FAST_COMMIT_H__

/*
* Note this file is present in e2fsprogs/lib/ext2fs/fast_commit.h and
* linux/fs/ext4/fast_commit.h. These file should always be byte identical.
*/

/* Fast commit tags */
#define EXT4_FC_TAG_ADD_RANGE 0x0001
#define EXT4_FC_TAG_DEL_RANGE 0x0002
Expand Down Expand Up @@ -50,7 +55,7 @@ struct ext4_fc_del_range {
struct ext4_fc_dentry_info {
__le32 fc_parent_ino;
__le32 fc_ino;
u8 fc_dname[0];
__u8 fc_dname[0];
};

/* Value structure for EXT4_FC_TAG_INODE and EXT4_FC_TAG_INODE_PARTIAL. */
Expand All @@ -65,19 +70,6 @@ struct ext4_fc_tail {
__le32 fc_crc;
};

/*
* In memory list of dentry updates that are performed on the file
* system used by fast commit code.
*/
struct ext4_fc_dentry_update {
int fcd_op; /* Type of update create / unlink / link */
int fcd_parent; /* Parent inode number */
int fcd_ino; /* Inode number */
struct qstr fcd_name; /* Dirent name */
unsigned char fcd_iname[DNAME_INLINE_LEN]; /* Dirent name string */
struct list_head fcd_list;
};

/*
* Fast commit reason codes
*/
Expand Down Expand Up @@ -107,6 +99,20 @@ enum {
EXT4_FC_REASON_MAX
};

#ifdef __KERNEL__
/*
* In memory list of dentry updates that are performed on the file
* system used by fast commit code.
*/
struct ext4_fc_dentry_update {
int fcd_op; /* Type of update create / unlink / link */
int fcd_parent; /* Parent inode number */
int fcd_ino; /* Inode number */
struct qstr fcd_name; /* Dirent name */
unsigned char fcd_iname[DNAME_INLINE_LEN]; /* Dirent name string */
struct list_head fcd_list;
};

struct ext4_fc_stats {
unsigned int fc_ineligible_reason_count[EXT4_FC_REASON_MAX];
unsigned long fc_num_commits;
Expand Down Expand Up @@ -145,13 +151,51 @@ struct ext4_fc_replay_state {
};

#define region_last(__region) (((__region)->lblk) + ((__region)->len) - 1)
#endif

#define fc_for_each_tl(__start, __end, __tl) \
for (tl = (struct ext4_fc_tl *)start; \
(u8 *)tl < (u8 *)end; \
tl = (struct ext4_fc_tl *)((u8 *)tl + \
for (tl = (struct ext4_fc_tl *)(__start); \
(__u8 *)tl < (__u8 *)(__end); \
tl = (struct ext4_fc_tl *)((__u8 *)tl + \
sizeof(struct ext4_fc_tl) + \
+ le16_to_cpu(tl->fc_len)))

static inline const char *tag2str(__u16 tag)
{
switch (tag) {
case EXT4_FC_TAG_LINK:
return "ADD_ENTRY";
case EXT4_FC_TAG_UNLINK:
return "DEL_ENTRY";
case EXT4_FC_TAG_ADD_RANGE:
return "ADD_RANGE";
case EXT4_FC_TAG_CREAT:
return "CREAT_DENTRY";
case EXT4_FC_TAG_DEL_RANGE:
return "DEL_RANGE";
case EXT4_FC_TAG_INODE:
return "INODE";
case EXT4_FC_TAG_PAD:
return "PAD";
case EXT4_FC_TAG_TAIL:
return "TAIL";
case EXT4_FC_TAG_HEAD:
return "HEAD";
default:
return "ERROR";
}
}

/* Get length of a particular tlv */
static inline int ext4_fc_tag_len(struct ext4_fc_tl *tl)
{
return le16_to_cpu(tl->fc_len);
}

/* Get a pointer to "value" of a tlv */
static inline __u8 *ext4_fc_tag_val(struct ext4_fc_tl *tl)
{
return (__u8 *)tl + sizeof(*tl);
}

#endif /* __FAST_COMMIT_H__ */

0 comments on commit 941ba12

Please sign in to comment.