transaction.c (4083014e32699af04a8e6eaa4855b08dba36a47a) | transaction.c (609e804d771f59dc5d45a93e5ee0053c74bbe2bf) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2007 Oracle. All rights reserved. 4 */ 5 6#include <linux/fs.h> 7#include <linux/slab.h> 8#include <linux/sched.h> --- 108 unchanged lines hidden (view full) --- 117 list_for_each_entry_safe(root, tmp, &trans->switch_commits, 118 dirty_list) { 119 list_del_init(&root->dirty_list); 120 free_extent_buffer(root->commit_root); 121 root->commit_root = btrfs_root_node(root); 122 if (is_fstree(root->root_key.objectid)) 123 btrfs_unpin_free_ino(root); 124 clear_btree_io_tree(&root->dirty_log_pages); | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2007 Oracle. All rights reserved. 4 */ 5 6#include <linux/fs.h> 7#include <linux/slab.h> 8#include <linux/sched.h> --- 108 unchanged lines hidden (view full) --- 117 list_for_each_entry_safe(root, tmp, &trans->switch_commits, 118 dirty_list) { 119 list_del_init(&root->dirty_list); 120 free_extent_buffer(root->commit_root); 121 root->commit_root = btrfs_root_node(root); 122 if (is_fstree(root->root_key.objectid)) 123 btrfs_unpin_free_ino(root); 124 clear_btree_io_tree(&root->dirty_log_pages); |
125 btrfs_qgroup_clean_swapped_blocks(root); |
|
125 } 126 127 /* We can free old roots now. */ 128 spin_lock(&trans->dropped_roots_lock); 129 while (!list_empty(&trans->dropped_roots)) { 130 root = list_first_entry(&trans->dropped_roots, 131 struct btrfs_root, root_list); 132 list_del_init(&root->root_list); --- 707 unchanged lines hidden (view full) --- 840 refcount_dec(&trans->use_count); 841 trans->block_rsv = trans->orig_rsv; 842 return 0; 843 } 844 845 btrfs_trans_release_metadata(trans); 846 trans->block_rsv = NULL; 847 | 126 } 127 128 /* We can free old roots now. */ 129 spin_lock(&trans->dropped_roots_lock); 130 while (!list_empty(&trans->dropped_roots)) { 131 root = list_first_entry(&trans->dropped_roots, 132 struct btrfs_root, root_list); 133 list_del_init(&root->root_list); --- 707 unchanged lines hidden (view full) --- 841 refcount_dec(&trans->use_count); 842 trans->block_rsv = trans->orig_rsv; 843 return 0; 844 } 845 846 btrfs_trans_release_metadata(trans); 847 trans->block_rsv = NULL; 848 |
848 if (!list_empty(&trans->new_bgs)) 849 btrfs_create_pending_block_groups(trans); | 849 btrfs_create_pending_block_groups(trans); |
850 851 btrfs_trans_release_chunk_metadata(trans); 852 853 if (lock && READ_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) { 854 if (throttle) 855 return btrfs_commit_transaction(trans); 856 else 857 wake_up_process(info->transaction_kthread); --- 669 unchanged lines hidden (view full) --- 1527 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old); 1528 if (ret) { 1529 btrfs_tree_unlock(old); 1530 free_extent_buffer(old); 1531 btrfs_abort_transaction(trans, ret); 1532 goto fail; 1533 } 1534 | 850 851 btrfs_trans_release_chunk_metadata(trans); 852 853 if (lock && READ_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) { 854 if (throttle) 855 return btrfs_commit_transaction(trans); 856 else 857 wake_up_process(info->transaction_kthread); --- 669 unchanged lines hidden (view full) --- 1527 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old); 1528 if (ret) { 1529 btrfs_tree_unlock(old); 1530 free_extent_buffer(old); 1531 btrfs_abort_transaction(trans, ret); 1532 goto fail; 1533 } 1534 |
1535 btrfs_set_lock_blocking(old); | 1535 btrfs_set_lock_blocking_write(old); |
1536 1537 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); 1538 /* clean up in any case */ 1539 btrfs_tree_unlock(old); 1540 free_extent_buffer(old); 1541 if (ret) { 1542 btrfs_abort_transaction(trans, ret); 1543 goto fail; --- 337 unchanged lines hidden (view full) --- 1881 struct btrfs_block_group_cache *block_group, *tmp; 1882 1883 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { 1884 btrfs_delayed_refs_rsv_release(fs_info, 1); 1885 list_del_init(&block_group->bg_list); 1886 } 1887} 1888 | 1536 1537 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); 1538 /* clean up in any case */ 1539 btrfs_tree_unlock(old); 1540 free_extent_buffer(old); 1541 if (ret) { 1542 btrfs_abort_transaction(trans, ret); 1543 goto fail; --- 337 unchanged lines hidden (view full) --- 1881 struct btrfs_block_group_cache *block_group, *tmp; 1882 1883 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { 1884 btrfs_delayed_refs_rsv_release(fs_info, 1); 1885 list_del_init(&block_group->bg_list); 1886 } 1887} 1888 |
1889static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info) | 1889static inline int btrfs_start_delalloc_flush(struct btrfs_trans_handle *trans) |
1890{ | 1890{ |
1891 struct btrfs_fs_info *fs_info = trans->fs_info; 1892 |
|
1891 /* 1892 * We use writeback_inodes_sb here because if we used 1893 * btrfs_start_delalloc_roots we would deadlock with fs freeze. 1894 * Currently are holding the fs freeze lock, if we do an async flush 1895 * we'll do btrfs_join_transaction() and deadlock because we need to 1896 * wait for the fs freeze lock. Using the direct flushing we benefit 1897 * from already being in a transaction and our join_transaction doesn't 1898 * have to re-take the fs freeze lock. 1899 */ | 1893 /* 1894 * We use writeback_inodes_sb here because if we used 1895 * btrfs_start_delalloc_roots we would deadlock with fs freeze. 1896 * Currently are holding the fs freeze lock, if we do an async flush 1897 * we'll do btrfs_join_transaction() and deadlock because we need to 1898 * wait for the fs freeze lock. Using the direct flushing we benefit 1899 * from already being in a transaction and our join_transaction doesn't 1900 * have to re-take the fs freeze lock. 1901 */ |
1900 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) | 1902 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) { |
1901 writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC); | 1903 writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC); |
1904 } else { 1905 struct btrfs_pending_snapshot *pending; 1906 struct list_head *head = &trans->transaction->pending_snapshots; 1907 1908 /* 1909 * Flush dellaloc for any root that is going to be snapshotted. 1910 * This is done to avoid a corrupted version of files, in the 1911 * snapshots, that had both buffered and direct IO writes (even 1912 * if they were done sequentially) due to an unordered update of 1913 * the inode's size on disk. 1914 */ 1915 list_for_each_entry(pending, head, list) { 1916 int ret; 1917 1918 ret = btrfs_start_delalloc_snapshot(pending->root); 1919 if (ret) 1920 return ret; 1921 } 1922 } |
|
1902 return 0; 1903} 1904 | 1923 return 0; 1924} 1925 |
1905static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info) | 1926static inline void btrfs_wait_delalloc_flush(struct btrfs_trans_handle *trans) |
1906{ | 1927{ |
1907 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) | 1928 struct btrfs_fs_info *fs_info = trans->fs_info; 1929 1930 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) { |
1908 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); | 1931 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); |
1932 } else { 1933 struct btrfs_pending_snapshot *pending; 1934 struct list_head *head = &trans->transaction->pending_snapshots; 1935 1936 /* 1937 * Wait for any dellaloc that we started previously for the roots 1938 * that are going to be snapshotted. This is to avoid a corrupted 1939 * version of files in the snapshots that had both buffered and 1940 * direct IO writes (even if they were done sequentially). 1941 */ 1942 list_for_each_entry(pending, head, list) 1943 btrfs_wait_ordered_extents(pending->root, 1944 U64_MAX, 0, U64_MAX); 1945 } |
|
1909} 1910 1911int btrfs_commit_transaction(struct btrfs_trans_handle *trans) 1912{ 1913 struct btrfs_fs_info *fs_info = trans->fs_info; 1914 struct btrfs_transaction *cur_trans = trans->transaction; 1915 struct btrfs_transaction *prev_trans = NULL; 1916 int ret; --- 21 unchanged lines hidden (view full) --- 1938 1939 /* 1940 * set the flushing flag so procs in this transaction have to 1941 * start sending their work down. 1942 */ 1943 cur_trans->delayed_refs.flushing = 1; 1944 smp_wmb(); 1945 | 1946} 1947 1948int btrfs_commit_transaction(struct btrfs_trans_handle *trans) 1949{ 1950 struct btrfs_fs_info *fs_info = trans->fs_info; 1951 struct btrfs_transaction *cur_trans = trans->transaction; 1952 struct btrfs_transaction *prev_trans = NULL; 1953 int ret; --- 21 unchanged lines hidden (view full) --- 1975 1976 /* 1977 * set the flushing flag so procs in this transaction have to 1978 * start sending their work down. 1979 */ 1980 cur_trans->delayed_refs.flushing = 1; 1981 smp_wmb(); 1982 |
1946 if (!list_empty(&trans->new_bgs)) 1947 btrfs_create_pending_block_groups(trans); | 1983 btrfs_create_pending_block_groups(trans); |
1948 1949 ret = btrfs_run_delayed_refs(trans, 0); 1950 if (ret) { 1951 btrfs_end_transaction(trans); 1952 return ret; 1953 } 1954 1955 if (!test_bit(BTRFS_TRANS_DIRTY_BG_RUN, &cur_trans->flags)) { --- 63 unchanged lines hidden (view full) --- 2019 spin_unlock(&fs_info->trans_lock); 2020 } 2021 } else { 2022 spin_unlock(&fs_info->trans_lock); 2023 } 2024 2025 extwriter_counter_dec(cur_trans, trans->type); 2026 | 1984 1985 ret = btrfs_run_delayed_refs(trans, 0); 1986 if (ret) { 1987 btrfs_end_transaction(trans); 1988 return ret; 1989 } 1990 1991 if (!test_bit(BTRFS_TRANS_DIRTY_BG_RUN, &cur_trans->flags)) { --- 63 unchanged lines hidden (view full) --- 2055 spin_unlock(&fs_info->trans_lock); 2056 } 2057 } else { 2058 spin_unlock(&fs_info->trans_lock); 2059 } 2060 2061 extwriter_counter_dec(cur_trans, trans->type); 2062 |
2027 ret = btrfs_start_delalloc_flush(fs_info); | 2063 ret = btrfs_start_delalloc_flush(trans); |
2028 if (ret) 2029 goto cleanup_transaction; 2030 2031 ret = btrfs_run_delayed_items(trans); 2032 if (ret) 2033 goto cleanup_transaction; 2034 2035 wait_event(cur_trans->writer_wait, 2036 extwriter_counter_read(cur_trans) == 0); 2037 2038 /* some pending stuffs might be added after the previous flush. */ 2039 ret = btrfs_run_delayed_items(trans); 2040 if (ret) 2041 goto cleanup_transaction; 2042 | 2064 if (ret) 2065 goto cleanup_transaction; 2066 2067 ret = btrfs_run_delayed_items(trans); 2068 if (ret) 2069 goto cleanup_transaction; 2070 2071 wait_event(cur_trans->writer_wait, 2072 extwriter_counter_read(cur_trans) == 0); 2073 2074 /* some pending stuffs might be added after the previous flush. */ 2075 ret = btrfs_run_delayed_items(trans); 2076 if (ret) 2077 goto cleanup_transaction; 2078 |
2043 btrfs_wait_delalloc_flush(fs_info); | 2079 btrfs_wait_delalloc_flush(trans); |
2044 2045 btrfs_scrub_pause(fs_info); 2046 /* 2047 * Ok now we need to make sure to block out any other joins while we 2048 * commit the transaction. We could have started a join before setting 2049 * COMMIT_DOING so make sure to wait for num_writers to == 1 again. 2050 */ 2051 spin_lock(&fs_info->trans_lock); --- 305 unchanged lines hidden --- | 2080 2081 btrfs_scrub_pause(fs_info); 2082 /* 2083 * Ok now we need to make sure to block out any other joins while we 2084 * commit the transaction. We could have started a join before setting 2085 * COMMIT_DOING so make sure to wait for num_writers to == 1 again. 2086 */ 2087 spin_lock(&fs_info->trans_lock); --- 305 unchanged lines hidden --- |