Skip to content

Commit b491213

Browse files
josefbacikkdave
authored andcommitted
btrfs: change nr to u64 in btrfs_start_delalloc_roots
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. This means we've adjusted start_delalloc_inodes() to take a pointer of nr since we want to preserve the ability for start-delalloc_inodes() to return an error, so simply make it do the nr adjusting as necessary. 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. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Tested-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 8e56008 commit b491213

5 files changed

Lines changed: 14 additions & 20 deletions

File tree

‎fs/btrfs/ctree.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2956,7 +2956,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
29562956
u32 min_type);
29572957

29582958
int btrfs_start_delalloc_snapshot(struct btrfs_root *root);
2959-
int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int nr);
2959+
int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, u64 nr);
29602960
int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
29612961
unsigned int extra_bits,
29622962
struct extent_state **cached_state);

‎fs/btrfs/dev-replace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
661661
* flush all outstanding I/O and inode extent mappings before the
662662
* copy operation is declared as being finished
663663
*/
664-
ret = btrfs_start_delalloc_roots(fs_info, -1);
664+
ret = btrfs_start_delalloc_roots(fs_info, U64_MAX);
665665
if (ret) {
666666
mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
667667
return ret;

‎fs/btrfs/inode.c‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9387,7 +9387,7 @@ static struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode
93879387
* some fairly slow code that needs optimization. This walks the list
93889388
* of all the inodes with pending delalloc and forces them to disk.
93899389
*/
9390-
static int start_delalloc_inodes(struct btrfs_root *root, int nr, bool snapshot)
9390+
static int start_delalloc_inodes(struct btrfs_root *root, u64 *nr, bool snapshot)
93919391
{
93929392
struct btrfs_inode *binode;
93939393
struct inode *inode;
@@ -9427,9 +9427,11 @@ static int start_delalloc_inodes(struct btrfs_root *root, int nr, bool snapshot)
94279427
list_add_tail(&work->list, &works);
94289428
btrfs_queue_work(root->fs_info->flush_workers,
94299429
&work->work);
9430-
ret++;
9431-
if (nr != -1 && ret >= nr)
9432-
goto out;
9430+
if (*nr != U64_MAX) {
9431+
(*nr)--;
9432+
if (*nr == 0)
9433+
goto out;
9434+
}
94339435
cond_resched();
94349436
spin_lock(&root->delalloc_lock);
94359437
}
@@ -9454,18 +9456,15 @@ static int start_delalloc_inodes(struct btrfs_root *root, int nr, bool snapshot)
94549456
int btrfs_start_delalloc_snapshot(struct btrfs_root *root)
94559457
{
94569458
struct btrfs_fs_info *fs_info = root->fs_info;
9457-
int ret;
9459+
u64 nr = U64_MAX;
94589460

94599461
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
94609462
return -EROFS;
94619463

9462-
ret = start_delalloc_inodes(root, -1, true);
9463-
if (ret > 0)
9464-
ret = 0;
9465-
return ret;
9464+
return start_delalloc_inodes(root, &nr, true);
94669465
}
94679466

9468-
int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int nr)
9467+
int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, u64 nr)
94699468
{
94709469
struct btrfs_root *root;
94719470
struct list_head splice;
@@ -9488,15 +9487,10 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int nr)
94889487
&fs_info->delalloc_roots);
94899488
spin_unlock(&fs_info->delalloc_root_lock);
94909489

9491-
ret = start_delalloc_inodes(root, nr, false);
9490+
ret = start_delalloc_inodes(root, &nr, false);
94929491
btrfs_put_root(root);
94939492
if (ret < 0)
94949493
goto out;
9495-
9496-
if (nr != -1) {
9497-
nr -= ret;
9498-
WARN_ON(nr < 0);
9499-
}
95009494
spin_lock(&fs_info->delalloc_root_lock);
95019495
}
95029496
spin_unlock(&fs_info->delalloc_root_lock);

‎fs/btrfs/ioctl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4897,7 +4897,7 @@ long btrfs_ioctl(struct file *file, unsigned int
48974897
case BTRFS_IOC_SYNC: {
48984898
int ret;
48994899

4900-
ret = btrfs_start_delalloc_roots(fs_info, -1);
4900+
ret = btrfs_start_delalloc_roots(fs_info, U64_MAX);
49014901
if (ret)
49024902
return ret;
49034903
ret = btrfs_sync_fs(inode->i_sb, 1);

‎fs/btrfs/space-info.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ void btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
477477
}
478478

479479
static void btrfs_writeback_inodes_sb_nr(struct btrfs_fs_info *fs_info,
480-
unsigned long nr_pages, int nr_items)
480+
unsigned long nr_pages, u64 nr_items)
481481
{
482482
struct super_block *sb = fs_info->sb;
483483

0 commit comments

Comments
 (0)