Skip to content

Commit 0d0c71b

Browse files
committed
btrfs: obsolete and remove mount option alloc_start
The mount option alloc_start was used in the past for debugging and stressing the chunk allocator. Not meant to be used by users, so we're not breaking anybody's setup. There was some added complexity handling changes of the value and when it was not same as default. Such code has likely been untested and I think it's better to remove it. This patch kills all use of alloc_start, and by doing that also fixes a bug when alloc_size is set, potentially called from statfs: in btrfs_calc_avail_data_space, traversing the list in RCU, the RCU protection is temporarily dropped so btrfs_account_dev_extents_size can be called and then RCU is locked again! Doing that inside list_for_each_entry_rcu is just asking for trouble, but unlikely to be observed in practice. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent fac03c8 commit 0d0c71b

File tree

3 files changed

+7
-70
lines changed

3 files changed

+7
-70
lines changed

fs/btrfs/ctree.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -799,17 +799,7 @@ struct btrfs_fs_info {
799799
* so it is also safe.
800800
*/
801801
u64 max_inline;
802-
/*
803-
* Protected by ->chunk_mutex and sb->s_umount.
804-
*
805-
* The reason that we use two lock to protect it is because only
806-
* remount and mount operations can change it and these two operations
807-
* are under sb->s_umount, but the read side (chunk allocation) can not
808-
* acquire sb->s_umount or the deadlock would happen. So we use two
809-
* locks to protect it. On the write side, we must acquire two locks,
810-
* and on the read side, we just need acquire one of them.
811-
*/
812-
u64 alloc_start;
802+
813803
struct btrfs_transaction *running_transaction;
814804
wait_queue_head_t transaction_throttle;
815805
wait_queue_head_t transaction_wait;

fs/btrfs/super.c

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -601,18 +601,8 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
601601
}
602602
break;
603603
case Opt_alloc_start:
604-
num = match_strdup(&args[0]);
605-
if (num) {
606-
mutex_lock(&info->chunk_mutex);
607-
info->alloc_start = memparse(num, NULL);
608-
mutex_unlock(&info->chunk_mutex);
609-
kfree(num);
610-
btrfs_info(info, "allocations start at %llu",
611-
info->alloc_start);
612-
} else {
613-
ret = -ENOMEM;
614-
goto out;
615-
}
604+
btrfs_info(info,
605+
"option alloc_start is obsolete, ignored");
616606
break;
617607
case Opt_acl:
618608
#ifdef CONFIG_BTRFS_FS_POSIX_ACL
@@ -1232,8 +1222,6 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
12321222
seq_puts(seq, ",nobarrier");
12331223
if (info->max_inline != BTRFS_DEFAULT_MAX_INLINE)
12341224
seq_printf(seq, ",max_inline=%llu", info->max_inline);
1235-
if (info->alloc_start != 0)
1236-
seq_printf(seq, ",alloc_start=%llu", info->alloc_start);
12371225
if (info->thread_pool_size != min_t(unsigned long,
12381226
num_online_cpus() + 2, 8))
12391227
seq_printf(seq, ",thread_pool=%d", info->thread_pool_size);
@@ -1716,7 +1704,6 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
17161704
unsigned long old_opts = fs_info->mount_opt;
17171705
unsigned long old_compress_type = fs_info->compress_type;
17181706
u64 old_max_inline = fs_info->max_inline;
1719-
u64 old_alloc_start = fs_info->alloc_start;
17201707
int old_thread_pool_size = fs_info->thread_pool_size;
17211708
unsigned int old_metadata_ratio = fs_info->metadata_ratio;
17221709
int ret;
@@ -1855,9 +1842,6 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
18551842
fs_info->mount_opt = old_opts;
18561843
fs_info->compress_type = old_compress_type;
18571844
fs_info->max_inline = old_max_inline;
1858-
mutex_lock(&fs_info->chunk_mutex);
1859-
fs_info->alloc_start = old_alloc_start;
1860-
mutex_unlock(&fs_info->chunk_mutex);
18611845
btrfs_resize_thread_pool(fs_info,
18621846
old_thread_pool_size, fs_info->thread_pool_size);
18631847
fs_info->metadata_ratio = old_metadata_ratio;
@@ -1904,11 +1888,9 @@ static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
19041888
u64 skip_space;
19051889
u64 type;
19061890
u64 avail_space;
1907-
u64 used_space;
19081891
u64 min_stripe_size;
19091892
int min_stripes = 1, num_stripes = 1;
19101893
int i = 0, nr_devices;
1911-
int ret;
19121894

19131895
/*
19141896
* We aren't under the device list lock, so this is racy-ish, but good
@@ -1948,8 +1930,6 @@ static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
19481930
else
19491931
min_stripe_size = BTRFS_STRIPE_LEN;
19501932

1951-
if (fs_info->alloc_start)
1952-
mutex_lock(&fs_devices->device_list_mutex);
19531933
rcu_read_lock();
19541934
list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
19551935
if (!device->in_fs_metadata || !device->bdev ||
@@ -1972,34 +1952,6 @@ static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
19721952
*/
19731953
skip_space = SZ_1M;
19741954

1975-
/* user can set the offset in fs_info->alloc_start. */
1976-
if (fs_info->alloc_start &&
1977-
fs_info->alloc_start + BTRFS_STRIPE_LEN <=
1978-
device->total_bytes) {
1979-
rcu_read_unlock();
1980-
skip_space = max(fs_info->alloc_start, skip_space);
1981-
1982-
/*
1983-
* btrfs can not use the free space in
1984-
* [0, skip_space - 1], we must subtract it from the
1985-
* total. In order to implement it, we account the used
1986-
* space in this range first.
1987-
*/
1988-
ret = btrfs_account_dev_extents_size(device, 0,
1989-
skip_space - 1,
1990-
&used_space);
1991-
if (ret) {
1992-
kfree(devices_info);
1993-
mutex_unlock(&fs_devices->device_list_mutex);
1994-
return ret;
1995-
}
1996-
1997-
rcu_read_lock();
1998-
1999-
/* calc the free space in [0, skip_space - 1] */
2000-
skip_space -= used_space;
2001-
}
2002-
20031955
/*
20041956
* we can use the free space in [0, skip_space - 1], subtract
20051957
* it from the total.
@@ -2018,8 +1970,6 @@ static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
20181970
i++;
20191971
}
20201972
rcu_read_unlock();
2021-
if (fs_info->alloc_start)
2022-
mutex_unlock(&fs_devices->device_list_mutex);
20231973

20241974
nr_devices = i;
20251975

@@ -2056,10 +2006,9 @@ static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
20562006
* multiplier to scale the sizes.
20572007
*
20582008
* Unused device space usage is based on simulating the chunk allocator
2059-
* algorithm that respects the device sizes, order of allocations and the
2060-
* 'alloc_start' value, this is a close approximation of the actual use but
2061-
* there are other factors that may change the result (like a new metadata
2062-
* chunk).
2009+
* algorithm that respects the device sizes and order of allocations. This is
2010+
* a close approximation of the actual use but there are other factors that may
2011+
* change the result (like a new metadata chunk).
20632012
*
20642013
* If metadata is exhausted, f_bavail will be 0.
20652014
*/

fs/btrfs/volumes.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,15 +1353,13 @@ int find_free_dev_extent_start(struct btrfs_transaction *transaction,
13531353
int ret;
13541354
int slot;
13551355
struct extent_buffer *l;
1356-
u64 min_search_start;
13571356

13581357
/*
13591358
* We don't want to overwrite the superblock on the drive nor any area
13601359
* used by the boot loader (grub for example), so we make sure to start
13611360
* at an offset of at least 1MB.
13621361
*/
1363-
min_search_start = max(fs_info->alloc_start, 1024ull * 1024);
1364-
search_start = max(search_start, min_search_start);
1362+
search_start = max_t(u64, search_start, SZ_1M);
13651363

13661364
path = btrfs_alloc_path();
13671365
if (!path)

0 commit comments

Comments
 (0)