On 1/30/20 7:06 AM, Nikolay Borisov wrote:
On 30.01.20 г. 1:50 ч., Josef Bacik wrote:
We have btrfs_wait_ordered_roots() which takes a u64 for nr, but
btrfs_start_delalloc_roots() that takes an int for nr, which makes using
them in conjunction, especially for something like (u64)-1, annoying and
inconsistent. Fix btrfs_start_delalloc_roots() to take a u64 for nr and
adjust start_delalloc_inodes() and it's callers appropriately.
nit: You could include one more sentence to be explicit about the fact
that now 'nr' management is delegated to start_delalloc_inodes i.e you
pass it as a pointer to that function which in turn will control when
btrfs_Start_delalloc_roots breaks out of its own loop.
Part of adjusting the callers to this means changing
btrfs_writeback_inodes_sb_nr() to take a u64 for items. This may be
confusing because it seems unrelated, but the caller of
btrfs_writeback_inodes_sb_nr() already passes in a u64, it's just the
function variable that needs to be changed.
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
---
fs/btrfs/ctree.h | 2 +-
fs/btrfs/dev-replace.c | 2 +-
fs/btrfs/inode.c | 27 +++++++++++----------------
fs/btrfs/ioctl.c | 2 +-
fs/btrfs/space-info.c | 2 +-
5 files changed, 15 insertions(+), 20 deletions(-)
<snip>
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -9619,7 +9619,8 @@ static struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode
* some fairly slow code that needs optimization. This walks the list
* of all the inodes with pending delalloc and forces them to disk.
*/
-static int start_delalloc_inodes(struct btrfs_root *root, int nr, bool snapshot)
+static int start_delalloc_inodes(struct btrfs_root *root, u64 *nr,
+ bool snapshot)
{
struct btrfs_inode *binode;
struct inode *inode;
@@ -9659,9 +9660,11 @@ static int start_delalloc_inodes(struct btrfs_root *root, int nr, bool snapshot)
list_add_tail(&work->list, &works);
btrfs_queue_work(root->fs_info->flush_workers,
&work->work);
- ret++;
- if (nr != -1 && ret >= nr)
- goto out;
+ if (*nr != U64_MAX) {
+ (*nr)--;
+ if (*nr == 0)
+ goto out;
+ }
cond_resched();
spin_lock(&root->delalloc_lock);
}
@@ -9686,18 +9689,15 @@ static int start_delalloc_inodes(struct btrfs_root *root, int nr, bool snapshot)
int btrfs_start_delalloc_snapshot(struct btrfs_root *root)
{
struct btrfs_fs_info *fs_info = root->fs_info;
- int ret;
+ u64 nr = U64_MAX;
This var is never used past start_delalloc_snapshot so you can remove it
and simply pass U64_MAX to start_delalloc_inodes.
Except start_delalloc_inodes() is now taking a pointer, not the value itself.
Thanks,
Josef