Skip to content

Commit

Permalink
ext4: return early for non-eligible fast_commit track events
Browse files Browse the repository at this point in the history
Currently ext4_fc_track_template() checks, whether the trace event
path belongs to replay or does sb has ineligible set, if yes it simply
returns. This patch pulls those checks before calling
ext4_fc_track_template() in the callers of ext4_fc_track_template().

[ Add checks to ext4_rename() which calls the __ext4_fc_track_*()
  functions directly. -- TYT ]

Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com>
Link: https://lore.kernel.org/r/3cd025d9c490218a92e6d8fb30b6123e693373e3.1647057583.git.riteshh@linux.ibm.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  • Loading branch information
Ritesh Harjani authored and Theodore Ts'o committed Mar 15, 2022
1 parent 7f14244 commit 78be047
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 14 deletions.
59 changes: 49 additions & 10 deletions fs/ext4/fast_commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,6 @@ static int ext4_fc_track_template(
tid_t tid = 0;
int ret;

if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) ||
(sbi->s_mount_state & EXT4_FC_REPLAY))
return -EOPNOTSUPP;

if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE))
return -EINVAL;

tid = handle->h_transaction->t_tid;
mutex_lock(&ei->i_fc_lock);
if (tid == ei->i_sync_tid) {
Expand Down Expand Up @@ -499,7 +492,17 @@ void __ext4_fc_track_unlink(handle_t *handle,

void ext4_fc_track_unlink(handle_t *handle, struct dentry *dentry)
{
__ext4_fc_track_unlink(handle, d_inode(dentry), dentry);
struct inode *inode = d_inode(dentry);
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);

if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) ||
(sbi->s_mount_state & EXT4_FC_REPLAY))
return;

if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE))
return;

__ext4_fc_track_unlink(handle, inode, dentry);
}

void __ext4_fc_track_link(handle_t *handle,
Expand All @@ -518,7 +521,17 @@ void __ext4_fc_track_link(handle_t *handle,

void ext4_fc_track_link(handle_t *handle, struct dentry *dentry)
{
__ext4_fc_track_link(handle, d_inode(dentry), dentry);
struct inode *inode = d_inode(dentry);
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);

if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) ||
(sbi->s_mount_state & EXT4_FC_REPLAY))
return;

if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE))
return;

__ext4_fc_track_link(handle, inode, dentry);
}

void __ext4_fc_track_create(handle_t *handle, struct inode *inode,
Expand All @@ -537,7 +550,17 @@ void __ext4_fc_track_create(handle_t *handle, struct inode *inode,

void ext4_fc_track_create(handle_t *handle, struct dentry *dentry)
{
__ext4_fc_track_create(handle, d_inode(dentry), dentry);
struct inode *inode = d_inode(dentry);
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);

if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) ||
(sbi->s_mount_state & EXT4_FC_REPLAY))
return;

if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE))
return;

__ext4_fc_track_create(handle, inode, dentry);
}

/* __track_fn for inode tracking */
Expand All @@ -553,6 +576,7 @@ static int __track_inode(struct inode *inode, void *arg, bool update)

void ext4_fc_track_inode(handle_t *handle, struct inode *inode)
{
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
int ret;

if (S_ISDIR(inode->i_mode))
Expand All @@ -564,6 +588,13 @@ void ext4_fc_track_inode(handle_t *handle, struct inode *inode)
return;
}

if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) ||
(sbi->s_mount_state & EXT4_FC_REPLAY))
return;

if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE))
return;

ret = ext4_fc_track_template(handle, inode, __track_inode, NULL, 1);
trace_ext4_fc_track_inode(inode, ret);
}
Expand Down Expand Up @@ -603,12 +634,20 @@ static int __track_range(struct inode *inode, void *arg, bool update)
void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t start,
ext4_lblk_t end)
{
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
struct __track_range_args args;
int ret;

if (S_ISDIR(inode->i_mode))
return;

if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) ||
(sbi->s_mount_state & EXT4_FC_REPLAY))
return;

if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE))
return;

args.start = start;
args.end = end;

Expand Down
15 changes: 11 additions & 4 deletions fs/ext4/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -3891,12 +3891,19 @@ static int ext4_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
ext4_fc_mark_ineligible(old.inode->i_sb,
EXT4_FC_REASON_RENAME_DIR, handle);
} else {
struct super_block *sb = old.inode->i_sb;

if (new.inode)
ext4_fc_track_unlink(handle, new.dentry);
__ext4_fc_track_link(handle, old.inode, new.dentry);
__ext4_fc_track_unlink(handle, old.inode, old.dentry);
if (whiteout)
__ext4_fc_track_create(handle, whiteout, old.dentry);
if (test_opt2(sb, JOURNAL_FAST_COMMIT) &&
!(EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY) &&
!(ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE))) {
__ext4_fc_track_link(handle, old.inode, new.dentry);
__ext4_fc_track_unlink(handle, old.inode, old.dentry);
if (whiteout)
__ext4_fc_track_create(handle, whiteout,
old.dentry);
}
}

if (new.inode) {
Expand Down

0 comments on commit 78be047

Please sign in to comment.