transaction.c (1136fa0c07de570dc17858745af8be169d1440ba) transaction.c (b4be6aefa73c9a6899ef3ba9c5faaa8a66e333ef)
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>

--- 1306 unchanged lines hidden (view full) ---

1315 /* Update dev-replace pointer once everything is committed */
1316 fs_info->dev_replace.committed_cursor_left =
1317 fs_info->dev_replace.cursor_left_last_write_of_item;
1318
1319 return 0;
1320}
1321
1322/*
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>

--- 1306 unchanged lines hidden (view full) ---

1315 /* Update dev-replace pointer once everything is committed */
1316 fs_info->dev_replace.committed_cursor_left =
1317 fs_info->dev_replace.cursor_left_last_write_of_item;
1318
1319 return 0;
1320}
1321
1322/*
1323 * If we had a pending drop we need to see if there are any others left in our
1324 * dead roots list, and if not clear our bit and wake any waiters.
1325 */
1326void btrfs_maybe_wake_unfinished_drop(struct btrfs_fs_info *fs_info)
1327{
1328 /*
1329 * We put the drop in progress roots at the front of the list, so if the
1330 * first entry doesn't have UNFINISHED_DROP set we can wake everybody
1331 * up.
1332 */
1333 spin_lock(&fs_info->trans_lock);
1334 if (!list_empty(&fs_info->dead_roots)) {
1335 struct btrfs_root *root = list_first_entry(&fs_info->dead_roots,
1336 struct btrfs_root,
1337 root_list);
1338 if (test_bit(BTRFS_ROOT_UNFINISHED_DROP, &root->state)) {
1339 spin_unlock(&fs_info->trans_lock);
1340 return;
1341 }
1342 }
1343 spin_unlock(&fs_info->trans_lock);
1344
1345 btrfs_wake_unfinished_drop(fs_info);
1346}
1347
1348/*
1323 * dead roots are old snapshots that need to be deleted. This allocates
1324 * a dirty root struct and adds it into the list of dead roots that need to
1325 * be deleted
1326 */
1327void btrfs_add_dead_root(struct btrfs_root *root)
1328{
1329 struct btrfs_fs_info *fs_info = root->fs_info;
1330
1331 spin_lock(&fs_info->trans_lock);
1332 if (list_empty(&root->root_list)) {
1333 btrfs_grab_root(root);
1349 * dead roots are old snapshots that need to be deleted. This allocates
1350 * a dirty root struct and adds it into the list of dead roots that need to
1351 * be deleted
1352 */
1353void btrfs_add_dead_root(struct btrfs_root *root)
1354{
1355 struct btrfs_fs_info *fs_info = root->fs_info;
1356
1357 spin_lock(&fs_info->trans_lock);
1358 if (list_empty(&root->root_list)) {
1359 btrfs_grab_root(root);
1334 list_add_tail(&root->root_list, &fs_info->dead_roots);
1360
1361 /* We want to process the partially complete drops first. */
1362 if (test_bit(BTRFS_ROOT_UNFINISHED_DROP, &root->state))
1363 list_add(&root->root_list, &fs_info->dead_roots);
1364 else
1365 list_add_tail(&root->root_list, &fs_info->dead_roots);
1335 }
1336 spin_unlock(&fs_info->trans_lock);
1337}
1338
1339/*
1340 * Update each subvolume root and its relocation root, if it exists, in the tree
1341 * of tree roots. Also free log roots if they exist.
1342 */

--- 633 unchanged lines hidden (view full) ---

1976 btrfs_delayed_refs_rsv_release(fs_info, 1);
1977 list_del_init(&block_group->bg_list);
1978 }
1979}
1980
1981static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
1982{
1983 /*
1366 }
1367 spin_unlock(&fs_info->trans_lock);
1368}
1369
1370/*
1371 * Update each subvolume root and its relocation root, if it exists, in the tree
1372 * of tree roots. Also free log roots if they exist.
1373 */

--- 633 unchanged lines hidden (view full) ---

2007 btrfs_delayed_refs_rsv_release(fs_info, 1);
2008 list_del_init(&block_group->bg_list);
2009 }
2010}
2011
2012static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
2013{
2014 /*
1984 * We use writeback_inodes_sb here because if we used
2015 * We use try_to_writeback_inodes_sb() here because if we used
1985 * btrfs_start_delalloc_roots we would deadlock with fs freeze.
1986 * Currently are holding the fs freeze lock, if we do an async flush
1987 * we'll do btrfs_join_transaction() and deadlock because we need to
1988 * wait for the fs freeze lock. Using the direct flushing we benefit
1989 * from already being in a transaction and our join_transaction doesn't
1990 * have to re-take the fs freeze lock.
2016 * btrfs_start_delalloc_roots we would deadlock with fs freeze.
2017 * Currently are holding the fs freeze lock, if we do an async flush
2018 * we'll do btrfs_join_transaction() and deadlock because we need to
2019 * wait for the fs freeze lock. Using the direct flushing we benefit
2020 * from already being in a transaction and our join_transaction doesn't
2021 * have to re-take the fs freeze lock.
2022 *
2023 * Note that try_to_writeback_inodes_sb() will only trigger writeback
2024 * if it can read lock sb->s_umount. It will always be able to lock it,
2025 * except when the filesystem is being unmounted or being frozen, but in
2026 * those cases sync_filesystem() is called, which results in calling
2027 * writeback_inodes_sb() while holding a write lock on sb->s_umount.
2028 * Note that we don't call writeback_inodes_sb() directly, because it
2029 * will emit a warning if sb->s_umount is not locked.
1991 */
1992 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
2030 */
2031 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
1993 writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
2032 try_to_writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
1994 return 0;
1995}
1996
1997static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info)
1998{
1999 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
2000 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
2001}

--- 469 unchanged lines hidden ---
2033 return 0;
2034}
2035
2036static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info)
2037{
2038 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
2039 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
2040}

--- 469 unchanged lines hidden ---