ext4: drop ineligible txn start stop APIs
authorHarshad Shirwadkar <harshadshirwadkar@gmail.com>
Thu, 23 Dec 2021 20:21:38 +0000 (12:21 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 23 Dec 2021 23:13:25 +0000 (18:13 -0500)
This patch drops ext4_fc_start_ineligible() and
ext4_fc_stop_ineligible() APIs. Fast commit ineligible transactions
should simply call ext4_fc_mark_ineligible() after starting the
trasaction.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Link: https://lore.kernel.org/r/20211223202140.2061101-3-harshads@google.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/ext4.h
fs/ext4/extents.c
fs/ext4/fast_commit.c
fs/ext4/ioctl.c
fs/ext4/super.c

index 404dd50856e5d294c38e746c97dd50183d650eb0..d71485d53050c0043eb0c595f5f5e5d853670ced 100644 (file)
@@ -1725,9 +1725,9 @@ struct ext4_sb_info {
         */
        struct work_struct s_error_work;
 
-       /* Ext4 fast commit stuff */
+       /* Ext4 fast commit sub transaction ID */
        atomic_t s_fc_subtid;
-       atomic_t s_fc_ineligible_updates;
+
        /*
         * After commit starts, the main queue gets locked, and the further
         * updates get added in the staging queue.
@@ -2926,8 +2926,6 @@ void __ext4_fc_track_create(handle_t *handle, struct inode *inode,
 void ext4_fc_track_create(handle_t *handle, struct dentry *dentry);
 void ext4_fc_track_inode(handle_t *handle, struct inode *inode);
 void ext4_fc_mark_ineligible(struct super_block *sb, int reason);
-void ext4_fc_start_ineligible(struct super_block *sb, int reason);
-void ext4_fc_stop_ineligible(struct super_block *sb);
 void ext4_fc_start_update(struct inode *inode);
 void ext4_fc_stop_update(struct inode *inode);
 void ext4_fc_del(struct inode *inode);
index 703feff8cb8c9dda11723b7c5783cd70618d928e..38111ea18ae18ac05266b390eb926f6743c87aee 100644 (file)
@@ -5341,7 +5341,7 @@ static int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
                ret = PTR_ERR(handle);
                goto out_mmap;
        }
-       ext4_fc_start_ineligible(sb, EXT4_FC_REASON_FALLOC_RANGE);
+       ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_FALLOC_RANGE);
 
        down_write(&EXT4_I(inode)->i_data_sem);
        ext4_discard_preallocations(inode, 0);
@@ -5380,7 +5380,6 @@ static int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
 
 out_stop:
        ext4_journal_stop(handle);
-       ext4_fc_stop_ineligible(sb);
 out_mmap:
        filemap_invalidate_unlock(mapping);
 out_mutex:
@@ -5482,7 +5481,7 @@ static int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len)
                ret = PTR_ERR(handle);
                goto out_mmap;
        }
-       ext4_fc_start_ineligible(sb, EXT4_FC_REASON_FALLOC_RANGE);
+       ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_FALLOC_RANGE);
 
        /* Expand file to avoid data loss if there is error while shifting */
        inode->i_size += len;
@@ -5557,7 +5556,6 @@ static int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len)
 
 out_stop:
        ext4_journal_stop(handle);
-       ext4_fc_stop_ineligible(sb);
 out_mmap:
        filemap_invalidate_unlock(mapping);
 out_mutex:
index 0f32b445582ab1ef3a04913bd3e38e226f13522a..2771adefdba041d51a58ab47a613b996171dc672 100644 (file)
  *
  * Fast Commit Ineligibility
  * -------------------------
- * Not all operations are supported by fast commits today (e.g extended
- * attributes). Fast commit ineligibility is marked by calling one of the
- * two following functions:
- *
- * - ext4_fc_mark_ineligible(): This makes next fast commit operation to fall
- *   back to full commit. This is useful in case of transient errors.
  *
- * - ext4_fc_start_ineligible() and ext4_fc_stop_ineligible() - This makes all
- *   the fast commits happening between ext4_fc_start_ineligible() and
- *   ext4_fc_stop_ineligible() and one fast commit after the call to
- *   ext4_fc_stop_ineligible() to fall back to full commits. It is important to
- *   make one more fast commit to fall back to full commit after stop call so
- *   that it guaranteed that the fast commit ineligible operation contained
- *   within ext4_fc_start_ineligible() and ext4_fc_stop_ineligible() is
- *   followed by at least 1 full commit.
+ * Not all operations are supported by fast commits today (e.g extended
+ * attributes). Fast commit ineligibility is marked by calling
+ * ext4_fc_mark_ineligible(): This makes next fast commit operation to fall back
+ * to full commit.
  *
  * Atomicity of commits
  * --------------------
@@ -328,44 +318,6 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason)
        sbi->s_fc_stats.fc_ineligible_reason_count[reason]++;
 }
 
-/*
- * Start a fast commit ineligible update. Any commits that happen while
- * such an operation is in progress fall back to full commits.
- */
-void ext4_fc_start_ineligible(struct super_block *sb, int reason)
-{
-       struct ext4_sb_info *sbi = EXT4_SB(sb);
-
-       if (!test_opt2(sb, JOURNAL_FAST_COMMIT) ||
-           (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY))
-               return;
-
-       WARN_ON(reason >= EXT4_FC_REASON_MAX);
-       sbi->s_fc_stats.fc_ineligible_reason_count[reason]++;
-       atomic_inc(&sbi->s_fc_ineligible_updates);
-}
-
-/*
- * Stop a fast commit ineligible update. We set EXT4_MF_FC_INELIGIBLE flag here
- * to ensure that after stopping the ineligible update, at least one full
- * commit takes place.
- */
-void ext4_fc_stop_ineligible(struct super_block *sb)
-{
-       if (!test_opt2(sb, JOURNAL_FAST_COMMIT) ||
-           (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY))
-               return;
-
-       ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
-       atomic_dec(&EXT4_SB(sb)->s_fc_ineligible_updates);
-}
-
-static inline int ext4_fc_is_ineligible(struct super_block *sb)
-{
-       return (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE) ||
-               atomic_read(&EXT4_SB(sb)->s_fc_ineligible_updates));
-}
-
 /*
  * Generic fast commit tracking function. If this is the first time this we are
  * called after a full commit, we initialize fast commit fields and then call
@@ -391,7 +343,7 @@ static int ext4_fc_track_template(
            (sbi->s_mount_state & EXT4_FC_REPLAY))
                return -EOPNOTSUPP;
 
-       if (ext4_fc_is_ineligible(inode->i_sb))
+       if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE))
                return -EINVAL;
 
        tid = handle->h_transaction->t_tid;
@@ -1142,11 +1094,8 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
 
        start_time = ktime_get();
 
-       if (!test_opt2(sb, JOURNAL_FAST_COMMIT) ||
-               (ext4_fc_is_ineligible(sb))) {
-               reason = EXT4_FC_REASON_INELIGIBLE;
-               goto out;
-       }
+       if (!test_opt2(sb, JOURNAL_FAST_COMMIT))
+               return jbd2_complete_transaction(journal, commit_tid);
 
 restart_fc:
        ret = jbd2_fc_begin_commit(journal, commit_tid);
@@ -1162,6 +1111,14 @@ restart_fc:
                reason = EXT4_FC_REASON_FC_START_FAILED;
                goto out;
        }
+       /*
+        * After establishing journal barrier via jbd2_fc_begin_commit(), check
+        * if we are fast commit ineligible.
+        */
+       if (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE)) {
+               reason = EXT4_FC_REASON_INELIGIBLE;
+               goto out;
+       }
 
        fc_bufs_before = (sbi->s_fc_bytes + bsize - 1) / bsize;
        ret = ext4_fc_perform_commit(journal);
@@ -1180,12 +1137,6 @@ restart_fc:
        atomic_inc(&sbi->s_fc_subtid);
        jbd2_fc_end_commit(journal);
 out:
-       /* Has any ineligible update happened since we started? */
-       if (reason == EXT4_FC_REASON_OK && ext4_fc_is_ineligible(sb)) {
-               sbi->s_fc_stats.fc_ineligible_reason_count[EXT4_FC_COMMIT_FAILED]++;
-               reason = EXT4_FC_REASON_INELIGIBLE;
-       }
-
        spin_lock(&sbi->s_fc_lock);
        if (reason != EXT4_FC_REASON_OK &&
                reason != EXT4_FC_REASON_ALREADY_COMMITTED) {
index e64a12e1218a90615f2b7eccbdf47991cd3dd975..1366afb59fba2ac24562ab43e2252e173ee9012a 100644 (file)
@@ -169,7 +169,7 @@ static long swap_inode_boot_loader(struct super_block *sb,
                err = -EINVAL;
                goto err_out;
        }
-       ext4_fc_start_ineligible(sb, EXT4_FC_REASON_SWAP_BOOT);
+       ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_SWAP_BOOT);
 
        /* Protect extent tree against block allocations via delalloc */
        ext4_double_down_write_data_sem(inode, inode_bl);
@@ -252,7 +252,6 @@ revert:
 
 err_out1:
        ext4_journal_stop(handle);
-       ext4_fc_stop_ineligible(sb);
        ext4_double_up_write_data_sem(inode, inode_bl);
 
 err_out:
index 55be772f6374ed35117a6fdd7fd545791569851c..acdfd9c0d091095d9c309a33861e3c9dfb3fa573 100644 (file)
@@ -5074,7 +5074,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 
        /* Initialize fast commit stuff */
        atomic_set(&sbi->s_fc_subtid, 0);
-       atomic_set(&sbi->s_fc_ineligible_updates, 0);
        INIT_LIST_HEAD(&sbi->s_fc_q[FC_Q_MAIN]);
        INIT_LIST_HEAD(&sbi->s_fc_q[FC_Q_STAGING]);
        INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_MAIN]);