inode.c (41bd9ca459a007cc5588563bb08de9677c8d23fd) inode.c (6c255e67cec1c38a0569c7f823eba63f9449ccf8)
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,

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

8432 wait_for_completion(&work->completion);
8433 kmem_cache_free(btrfs_delalloc_work_cachep, work);
8434}
8435
8436/*
8437 * some fairly slow code that needs optimization. This walks the list
8438 * of all the inodes with pending delalloc and forces them to disk.
8439 */
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,

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

8432 wait_for_completion(&work->completion);
8433 kmem_cache_free(btrfs_delalloc_work_cachep, work);
8434}
8435
8436/*
8437 * some fairly slow code that needs optimization. This walks the list
8438 * of all the inodes with pending delalloc and forces them to disk.
8439 */
8440static int __start_delalloc_inodes(struct btrfs_root *root, int delay_iput)
8440static int __start_delalloc_inodes(struct btrfs_root *root, int delay_iput,
8441 int nr)
8441{
8442 struct btrfs_inode *binode;
8443 struct inode *inode;
8444 struct btrfs_delalloc_work *work, *next;
8445 struct list_head works;
8446 struct list_head splice;
8447 int ret = 0;
8448

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

8466
8467 work = btrfs_alloc_delalloc_work(inode, 0, delay_iput);
8468 if (unlikely(!work)) {
8469 if (delay_iput)
8470 btrfs_add_delayed_iput(inode);
8471 else
8472 iput(inode);
8473 ret = -ENOMEM;
8442{
8443 struct btrfs_inode *binode;
8444 struct inode *inode;
8445 struct btrfs_delalloc_work *work, *next;
8446 struct list_head works;
8447 struct list_head splice;
8448 int ret = 0;
8449

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

8467
8468 work = btrfs_alloc_delalloc_work(inode, 0, delay_iput);
8469 if (unlikely(!work)) {
8470 if (delay_iput)
8471 btrfs_add_delayed_iput(inode);
8472 else
8473 iput(inode);
8474 ret = -ENOMEM;
8474 goto out;
8475 break;
8475 }
8476 list_add_tail(&work->list, &works);
8477 btrfs_queue_work(root->fs_info->flush_workers,
8478 &work->work);
8476 }
8477 list_add_tail(&work->list, &works);
8478 btrfs_queue_work(root->fs_info->flush_workers,
8479 &work->work);
8479
8480 ret++;
8481 if (nr != -1 && ret >= nr)
8482 break;
8480 cond_resched();
8481 spin_lock(&root->delalloc_lock);
8482 }
8483 spin_unlock(&root->delalloc_lock);
8484
8485 list_for_each_entry_safe(work, next, &works, list) {
8486 list_del_init(&work->list);
8487 btrfs_wait_and_free_delalloc_work(work);
8488 }
8483 cond_resched();
8484 spin_lock(&root->delalloc_lock);
8485 }
8486 spin_unlock(&root->delalloc_lock);
8487
8488 list_for_each_entry_safe(work, next, &works, list) {
8489 list_del_init(&work->list);
8490 btrfs_wait_and_free_delalloc_work(work);
8491 }
8489 return 0;
8490out:
8491 list_for_each_entry_safe(work, next, &works, list) {
8492 list_del_init(&work->list);
8493 btrfs_wait_and_free_delalloc_work(work);
8494 }
8495
8496 if (!list_empty_careful(&splice)) {
8497 spin_lock(&root->delalloc_lock);
8498 list_splice_tail(&splice, &root->delalloc_inodes);
8499 spin_unlock(&root->delalloc_lock);
8500 }
8501 return ret;
8502}
8503
8504int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput)
8505{
8506 int ret;
8507
8508 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state))
8509 return -EROFS;
8510
8492
8493 if (!list_empty_careful(&splice)) {
8494 spin_lock(&root->delalloc_lock);
8495 list_splice_tail(&splice, &root->delalloc_inodes);
8496 spin_unlock(&root->delalloc_lock);
8497 }
8498 return ret;
8499}
8500
8501int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput)
8502{
8503 int ret;
8504
8505 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state))
8506 return -EROFS;
8507
8511 ret = __start_delalloc_inodes(root, delay_iput);
8508 ret = __start_delalloc_inodes(root, delay_iput, -1);
8509 if (ret > 0)
8510 ret = 0;
8512 /*
8513 * the filemap_flush will queue IO into the worker threads, but
8514 * we have to make sure the IO is actually started and that
8515 * ordered extents get created before we return
8516 */
8517 atomic_inc(&root->fs_info->async_submit_draining);
8518 while (atomic_read(&root->fs_info->nr_async_submits) ||
8519 atomic_read(&root->fs_info->async_delalloc_pages)) {
8520 wait_event(root->fs_info->async_submit_wait,
8521 (atomic_read(&root->fs_info->nr_async_submits) == 0 &&
8522 atomic_read(&root->fs_info->async_delalloc_pages) == 0));
8523 }
8524 atomic_dec(&root->fs_info->async_submit_draining);
8525 return ret;
8526}
8527
8511 /*
8512 * the filemap_flush will queue IO into the worker threads, but
8513 * we have to make sure the IO is actually started and that
8514 * ordered extents get created before we return
8515 */
8516 atomic_inc(&root->fs_info->async_submit_draining);
8517 while (atomic_read(&root->fs_info->nr_async_submits) ||
8518 atomic_read(&root->fs_info->async_delalloc_pages)) {
8519 wait_event(root->fs_info->async_submit_wait,
8520 (atomic_read(&root->fs_info->nr_async_submits) == 0 &&
8521 atomic_read(&root->fs_info->async_delalloc_pages) == 0));
8522 }
8523 atomic_dec(&root->fs_info->async_submit_draining);
8524 return ret;
8525}
8526
8528int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int delay_iput)
8527int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int delay_iput,
8528 int nr)
8529{
8530 struct btrfs_root *root;
8531 struct list_head splice;
8532 int ret;
8533
8534 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
8535 return -EROFS;
8536
8537 INIT_LIST_HEAD(&splice);
8538
8539 spin_lock(&fs_info->delalloc_root_lock);
8540 list_splice_init(&fs_info->delalloc_roots, &splice);
8529{
8530 struct btrfs_root *root;
8531 struct list_head splice;
8532 int ret;
8533
8534 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
8535 return -EROFS;
8536
8537 INIT_LIST_HEAD(&splice);
8538
8539 spin_lock(&fs_info->delalloc_root_lock);
8540 list_splice_init(&fs_info->delalloc_roots, &splice);
8541 while (!list_empty(&splice)) {
8541 while (!list_empty(&splice) && nr) {
8542 root = list_first_entry(&splice, struct btrfs_root,
8543 delalloc_root);
8544 root = btrfs_grab_fs_root(root);
8545 BUG_ON(!root);
8546 list_move_tail(&root->delalloc_root,
8547 &fs_info->delalloc_roots);
8548 spin_unlock(&fs_info->delalloc_root_lock);
8549
8542 root = list_first_entry(&splice, struct btrfs_root,
8543 delalloc_root);
8544 root = btrfs_grab_fs_root(root);
8545 BUG_ON(!root);
8546 list_move_tail(&root->delalloc_root,
8547 &fs_info->delalloc_roots);
8548 spin_unlock(&fs_info->delalloc_root_lock);
8549
8550 ret = __start_delalloc_inodes(root, delay_iput);
8550 ret = __start_delalloc_inodes(root, delay_iput, nr);
8551 btrfs_put_fs_root(root);
8551 btrfs_put_fs_root(root);
8552 if (ret)
8552 if (ret < 0)
8553 goto out;
8554
8553 goto out;
8554
8555 if (nr != -1) {
8556 nr -= ret;
8557 WARN_ON(nr < 0);
8558 }
8555 spin_lock(&fs_info->delalloc_root_lock);
8556 }
8557 spin_unlock(&fs_info->delalloc_root_lock);
8558
8559 spin_lock(&fs_info->delalloc_root_lock);
8560 }
8561 spin_unlock(&fs_info->delalloc_root_lock);
8562
8563 ret = 0;
8559 atomic_inc(&fs_info->async_submit_draining);
8560 while (atomic_read(&fs_info->nr_async_submits) ||
8561 atomic_read(&fs_info->async_delalloc_pages)) {
8562 wait_event(fs_info->async_submit_wait,
8563 (atomic_read(&fs_info->nr_async_submits) == 0 &&
8564 atomic_read(&fs_info->async_delalloc_pages) == 0));
8565 }
8566 atomic_dec(&fs_info->async_submit_draining);
8564 atomic_inc(&fs_info->async_submit_draining);
8565 while (atomic_read(&fs_info->nr_async_submits) ||
8566 atomic_read(&fs_info->async_delalloc_pages)) {
8567 wait_event(fs_info->async_submit_wait,
8568 (atomic_read(&fs_info->nr_async_submits) == 0 &&
8569 atomic_read(&fs_info->async_delalloc_pages) == 0));
8570 }
8571 atomic_dec(&fs_info->async_submit_draining);
8567 return 0;
8568out:
8569 if (!list_empty_careful(&splice)) {
8570 spin_lock(&fs_info->delalloc_root_lock);
8571 list_splice_tail(&splice, &fs_info->delalloc_roots);
8572 spin_unlock(&fs_info->delalloc_root_lock);
8573 }
8574 return ret;
8575}

--- 402 unchanged lines hidden ---
8572out:
8573 if (!list_empty_careful(&splice)) {
8574 spin_lock(&fs_info->delalloc_root_lock);
8575 list_splice_tail(&splice, &fs_info->delalloc_roots);
8576 spin_unlock(&fs_info->delalloc_root_lock);
8577 }
8578 return ret;
8579}

--- 402 unchanged lines hidden ---