disk-io.c (a22285a6a32390195235171b89d157ed1a1fe932) | disk-io.c (8929ecfa50f266163832eeacfbc3642ed5eb83b6) |
---|---|
1/* 2 * Copyright (C) 2007 Oracle. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public 6 * License v2 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, --- 1449 unchanged lines hidden (view full) --- 1458 bio_endio(bio, error); 1459} 1460 1461static int cleaner_kthread(void *arg) 1462{ 1463 struct btrfs_root *root = arg; 1464 1465 do { | 1/* 2 * Copyright (C) 2007 Oracle. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public 6 * License v2 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, --- 1449 unchanged lines hidden (view full) --- 1458 bio_endio(bio, error); 1459} 1460 1461static int cleaner_kthread(void *arg) 1462{ 1463 struct btrfs_root *root = arg; 1464 1465 do { |
1466 smp_mb(); 1467 if (root->fs_info->closing) 1468 break; 1469 | |
1470 vfs_check_frozen(root->fs_info->sb, SB_FREEZE_WRITE); 1471 1472 if (!(root->fs_info->sb->s_flags & MS_RDONLY) && 1473 mutex_trylock(&root->fs_info->cleaner_mutex)) { 1474 btrfs_run_delayed_iputs(root); 1475 btrfs_clean_old_snapshots(root); 1476 mutex_unlock(&root->fs_info->cleaner_mutex); 1477 } 1478 1479 if (freezing(current)) { 1480 refrigerator(); 1481 } else { | 1466 vfs_check_frozen(root->fs_info->sb, SB_FREEZE_WRITE); 1467 1468 if (!(root->fs_info->sb->s_flags & MS_RDONLY) && 1469 mutex_trylock(&root->fs_info->cleaner_mutex)) { 1470 btrfs_run_delayed_iputs(root); 1471 btrfs_clean_old_snapshots(root); 1472 mutex_unlock(&root->fs_info->cleaner_mutex); 1473 } 1474 1475 if (freezing(current)) { 1476 refrigerator(); 1477 } else { |
1482 smp_mb(); 1483 if (root->fs_info->closing) 1484 break; | |
1485 set_current_state(TASK_INTERRUPTIBLE); | 1478 set_current_state(TASK_INTERRUPTIBLE); |
1486 schedule(); | 1479 if (!kthread_should_stop()) 1480 schedule(); |
1487 __set_current_state(TASK_RUNNING); 1488 } 1489 } while (!kthread_should_stop()); 1490 return 0; 1491} 1492 1493static int transaction_kthread(void *arg) 1494{ 1495 struct btrfs_root *root = arg; 1496 struct btrfs_trans_handle *trans; 1497 struct btrfs_transaction *cur; | 1481 __set_current_state(TASK_RUNNING); 1482 } 1483 } while (!kthread_should_stop()); 1484 return 0; 1485} 1486 1487static int transaction_kthread(void *arg) 1488{ 1489 struct btrfs_root *root = arg; 1490 struct btrfs_trans_handle *trans; 1491 struct btrfs_transaction *cur; |
1492 u64 transid; |
|
1498 unsigned long now; 1499 unsigned long delay; 1500 int ret; 1501 1502 do { | 1493 unsigned long now; 1494 unsigned long delay; 1495 int ret; 1496 1497 do { |
1503 smp_mb(); 1504 if (root->fs_info->closing) 1505 break; 1506 | |
1507 delay = HZ * 30; 1508 vfs_check_frozen(root->fs_info->sb, SB_FREEZE_WRITE); 1509 mutex_lock(&root->fs_info->transaction_kthread_mutex); 1510 | 1498 delay = HZ * 30; 1499 vfs_check_frozen(root->fs_info->sb, SB_FREEZE_WRITE); 1500 mutex_lock(&root->fs_info->transaction_kthread_mutex); 1501 |
1511 mutex_lock(&root->fs_info->trans_mutex); | 1502 spin_lock(&root->fs_info->new_trans_lock); |
1512 cur = root->fs_info->running_transaction; 1513 if (!cur) { | 1503 cur = root->fs_info->running_transaction; 1504 if (!cur) { |
1514 mutex_unlock(&root->fs_info->trans_mutex); | 1505 spin_unlock(&root->fs_info->new_trans_lock); |
1515 goto sleep; 1516 } 1517 1518 now = get_seconds(); | 1506 goto sleep; 1507 } 1508 1509 now = get_seconds(); |
1519 if (now < cur->start_time || now - cur->start_time < 30) { 1520 mutex_unlock(&root->fs_info->trans_mutex); | 1510 if (!cur->blocked && 1511 (now < cur->start_time || now - cur->start_time < 30)) { 1512 spin_unlock(&root->fs_info->new_trans_lock); |
1521 delay = HZ * 5; 1522 goto sleep; 1523 } | 1513 delay = HZ * 5; 1514 goto sleep; 1515 } |
1524 mutex_unlock(&root->fs_info->trans_mutex); 1525 trans = btrfs_join_transaction(root, 1); 1526 ret = btrfs_commit_transaction(trans, root); | 1516 transid = cur->transid; 1517 spin_unlock(&root->fs_info->new_trans_lock); |
1527 | 1518 |
1519 trans = btrfs_join_transaction(root, 1); 1520 if (transid == trans->transid) { 1521 ret = btrfs_commit_transaction(trans, root); 1522 BUG_ON(ret); 1523 } else { 1524 btrfs_end_transaction(trans, root); 1525 } |
|
1528sleep: 1529 wake_up_process(root->fs_info->cleaner_kthread); 1530 mutex_unlock(&root->fs_info->transaction_kthread_mutex); 1531 1532 if (freezing(current)) { 1533 refrigerator(); 1534 } else { | 1526sleep: 1527 wake_up_process(root->fs_info->cleaner_kthread); 1528 mutex_unlock(&root->fs_info->transaction_kthread_mutex); 1529 1530 if (freezing(current)) { 1531 refrigerator(); 1532 } else { |
1535 if (root->fs_info->closing) 1536 break; | |
1537 set_current_state(TASK_INTERRUPTIBLE); | 1533 set_current_state(TASK_INTERRUPTIBLE); |
1538 schedule_timeout(delay); | 1534 if (!kthread_should_stop() && 1535 !btrfs_transaction_blocked(root->fs_info)) 1536 schedule_timeout(delay); |
1539 __set_current_state(TASK_RUNNING); 1540 } 1541 } while (!kthread_should_stop()); 1542 return 0; 1543} 1544 1545struct btrfs_root *open_ctree(struct super_block *sb, 1546 struct btrfs_fs_devices *fs_devices, --- 365 unchanged lines hidden (view full) --- 1912 1913 ret = find_and_setup_root(tree_root, fs_info, 1914 BTRFS_CSUM_TREE_OBJECTID, csum_root); 1915 if (ret) 1916 goto fail_dev_root; 1917 1918 csum_root->track_dirty = 1; 1919 | 1537 __set_current_state(TASK_RUNNING); 1538 } 1539 } while (!kthread_should_stop()); 1540 return 0; 1541} 1542 1543struct btrfs_root *open_ctree(struct super_block *sb, 1544 struct btrfs_fs_devices *fs_devices, --- 365 unchanged lines hidden (view full) --- 1910 1911 ret = find_and_setup_root(tree_root, fs_info, 1912 BTRFS_CSUM_TREE_OBJECTID, csum_root); 1913 if (ret) 1914 goto fail_dev_root; 1915 1916 csum_root->track_dirty = 1; 1917 |
1918 fs_info->generation = generation; 1919 fs_info->last_trans_committed = generation; 1920 fs_info->data_alloc_profile = (u64)-1; 1921 fs_info->metadata_alloc_profile = (u64)-1; 1922 fs_info->system_alloc_profile = fs_info->metadata_alloc_profile; 1923 |
|
1920 ret = btrfs_read_block_groups(extent_root); 1921 if (ret) { 1922 printk(KERN_ERR "Failed to read block groups: %d\n", ret); 1923 goto fail_block_groups; 1924 } 1925 | 1924 ret = btrfs_read_block_groups(extent_root); 1925 if (ret) { 1926 printk(KERN_ERR "Failed to read block groups: %d\n", ret); 1927 goto fail_block_groups; 1928 } 1929 |
1926 fs_info->generation = generation; 1927 fs_info->last_trans_committed = generation; 1928 fs_info->data_alloc_profile = (u64)-1; 1929 fs_info->metadata_alloc_profile = (u64)-1; 1930 fs_info->system_alloc_profile = fs_info->metadata_alloc_profile; | |
1931 fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, 1932 "btrfs-cleaner"); 1933 if (IS_ERR(fs_info->cleaner_kthread)) 1934 goto fail_block_groups; 1935 1936 fs_info->transaction_kthread = kthread_run(transaction_kthread, 1937 tree_root, 1938 "btrfs-transaction"); --- 486 unchanged lines hidden (view full) --- 2425int close_ctree(struct btrfs_root *root) 2426{ 2427 struct btrfs_fs_info *fs_info = root->fs_info; 2428 int ret; 2429 2430 fs_info->closing = 1; 2431 smp_mb(); 2432 | 1930 fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, 1931 "btrfs-cleaner"); 1932 if (IS_ERR(fs_info->cleaner_kthread)) 1933 goto fail_block_groups; 1934 1935 fs_info->transaction_kthread = kthread_run(transaction_kthread, 1936 tree_root, 1937 "btrfs-transaction"); --- 486 unchanged lines hidden (view full) --- 2424int close_ctree(struct btrfs_root *root) 2425{ 2426 struct btrfs_fs_info *fs_info = root->fs_info; 2427 int ret; 2428 2429 fs_info->closing = 1; 2430 smp_mb(); 2431 |
2433 kthread_stop(root->fs_info->transaction_kthread); 2434 kthread_stop(root->fs_info->cleaner_kthread); 2435 | |
2436 if (!(fs_info->sb->s_flags & MS_RDONLY)) { 2437 ret = btrfs_commit_super(root); 2438 if (ret) 2439 printk(KERN_ERR "btrfs: commit super ret %d\n", ret); 2440 } 2441 | 2432 if (!(fs_info->sb->s_flags & MS_RDONLY)) { 2433 ret = btrfs_commit_super(root); 2434 if (ret) 2435 printk(KERN_ERR "btrfs: commit super ret %d\n", ret); 2436 } 2437 |
2438 kthread_stop(root->fs_info->transaction_kthread); 2439 kthread_stop(root->fs_info->cleaner_kthread); 2440 |
|
2442 fs_info->closing = 2; 2443 smp_mb(); 2444 2445 if (fs_info->delalloc_bytes) { 2446 printk(KERN_INFO "btrfs: at unmount delalloc count %llu\n", 2447 (unsigned long long)fs_info->delalloc_bytes); 2448 } 2449 if (fs_info->total_ref_cache_size) { --- 166 unchanged lines hidden --- | 2441 fs_info->closing = 2; 2442 smp_mb(); 2443 2444 if (fs_info->delalloc_bytes) { 2445 printk(KERN_INFO "btrfs: at unmount delalloc count %llu\n", 2446 (unsigned long long)fs_info->delalloc_bytes); 2447 } 2448 if (fs_info->total_ref_cache_size) { --- 166 unchanged lines hidden --- |