btrfs: add a BTRFS_FS_NEED_TRANS_COMMIT flag
authorJosef Bacik <josef@toxicpanda.com>
Wed, 19 Oct 2022 14:50:55 +0000 (10:50 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 5 Dec 2022 17:00:42 +0000 (18:00 +0100)
Currently we are only using fs_info->pending_changes to indicate that we
need a transaction commit.  The original users for this were removed
years ago and we don't have more usage in sight, so this is the only
remaining reason to have this field.  Add a flag so we can remove this
code.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/fs.h
fs/btrfs/super.c
fs/btrfs/sysfs.c
fs/btrfs/transaction.c

index 7337707d3939a9a48115d7a0ef13e48edc9cf165..bc5de4d598ad526bd29e7e958cf3893fd1a622b0 100644 (file)
@@ -90,6 +90,9 @@ enum {
        /* Indicate we have to finish a zone to do next allocation. */
        BTRFS_FS_NEED_ZONE_FINISH,
 
+       /* Indicate that we want to commit the transaction. */
+       BTRFS_FS_NEED_TRANS_COMMIT,
+
 #if BITS_PER_LONG == 32
        /* Indicate if we have error/warn message printed on 32bit systems */
        BTRFS_FS_32BIT_ERROR,
index 3aeb2106e1194e636801aa8b59b50986bd0902cb..0839e4a1cfac29cca53d716a3e3ac5cece7c004e 100644 (file)
@@ -1535,7 +1535,8 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
                         * Exit unless we have some pending changes
                         * that need to go through commit
                         */
-                       if (fs_info->pending_changes == 0)
+                       if (!test_bit(BTRFS_FS_NEED_TRANS_COMMIT,
+                                     &fs_info->flags))
                                return 0;
                        /*
                         * A non-blocking test if the fs is frozen. We must not
index 31fb6cb389b1f1dc943d44b8f1d9346dab4758f7..47b221372dcfe5f800393094327d4beb4da3b589 100644 (file)
@@ -249,7 +249,7 @@ static ssize_t btrfs_feature_attr_store(struct kobject *kobj,
        /*
         * We don't want to do full transaction commit from inside sysfs
         */
-       btrfs_set_pending(fs_info, COMMIT);
+       set_bit(BTRFS_FS_NEED_TRANS_COMMIT, &fs_info->flags);
        wake_up_process(fs_info->transaction_kthread);
 
        return count;
@@ -960,7 +960,7 @@ static ssize_t btrfs_label_store(struct kobject *kobj,
        /*
         * We don't want to do full transaction commit from inside sysfs
         */
-       btrfs_set_pending(fs_info, COMMIT);
+       set_bit(BTRFS_FS_NEED_TRANS_COMMIT, &fs_info->flags);
        wake_up_process(fs_info->transaction_kthread);
 
        return len;
index bae77fb05e2b65f0623421158c303dc21a78f769..7b6b68ab089ae6fc6fe1a36135f536c8efe62ef6 100644 (file)
@@ -2104,6 +2104,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
        ASSERT(refcount_read(&trans->use_count) == 1);
        btrfs_trans_state_lockdep_acquire(fs_info, BTRFS_LOCKDEP_TRANS_COMMIT_START);
 
+       clear_bit(BTRFS_FS_NEED_TRANS_COMMIT, &fs_info->flags);
+
        /* Stop the commit early if ->aborted is set */
        if (TRANS_ABORTED(cur_trans)) {
                ret = cur_trans->aborted;