Skip to content

Commit 8e75fd8

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: Stop using call_rcu for device freeing
btrfs_device structs are freed from RCU context since device iteration is protected by RCU. Currently this is achieved by using call_rcu since no blocking functions are called within btrfs_free_device. Future refactoring of pending/pinned chunks will require calling sleeping functions. This patch is in preparation for these changes by simply switching from RCU callbacks to explicit calls of synchronize_rcu and calling btrfs_free_device directly. This is functionally equivalent, making sure that there are no readers at that time. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 4ca7365 commit 8e75fd8

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

‎fs/btrfs/volumes.c‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,14 +1231,6 @@ void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step)
12311231
mutex_unlock(&uuid_mutex);
12321232
}
12331233

1234-
static void free_device_rcu(struct rcu_head *head)
1235-
{
1236-
struct btrfs_device *device;
1237-
1238-
device = container_of(head, struct btrfs_device, rcu);
1239-
btrfs_free_device(device);
1240-
}
1241-
12421234
static void btrfs_close_bdev(struct btrfs_device *device)
12431235
{
12441236
if (!device->bdev)
@@ -1286,7 +1278,8 @@ static void btrfs_close_one_device(struct btrfs_device *device)
12861278
list_replace_rcu(&device->dev_list, &new_device->dev_list);
12871279
new_device->fs_devices = device->fs_devices;
12881280

1289-
call_rcu(&device->rcu, free_device_rcu);
1281+
synchronize_rcu();
1282+
btrfs_free_device(device);
12901283
}
12911284

12921285
static int close_fs_devices(struct btrfs_fs_devices *fs_devices)
@@ -2243,7 +2236,8 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
22432236
btrfs_scratch_superblocks(device->bdev, device->name->str);
22442237

22452238
btrfs_close_bdev(device);
2246-
call_rcu(&device->rcu, free_device_rcu);
2239+
synchronize_rcu();
2240+
btrfs_free_device(device);
22472241

22482242
if (cur_devices->open_devices == 0) {
22492243
while (fs_devices) {
@@ -2311,7 +2305,8 @@ void btrfs_rm_dev_replace_free_srcdev(struct btrfs_fs_info *fs_info,
23112305
}
23122306

23132307
btrfs_close_bdev(srcdev);
2314-
call_rcu(&srcdev->rcu, free_device_rcu);
2308+
synchronize_rcu();
2309+
btrfs_free_device(srcdev);
23152310

23162311
/* if this is no devs we rather delete the fs_devices */
23172312
if (!fs_devices->num_devices) {
@@ -2369,7 +2364,8 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)
23692364
btrfs_scratch_superblocks(tgtdev->bdev, tgtdev->name->str);
23702365

23712366
btrfs_close_bdev(tgtdev);
2372-
call_rcu(&tgtdev->rcu, free_device_rcu);
2367+
synchronize_rcu();
2368+
btrfs_free_device(tgtdev);
23732369
}
23742370

23752371
static struct btrfs_device *btrfs_find_device_by_path(

‎fs/btrfs/volumes.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ struct btrfs_device {
118118
struct scrub_ctx *scrub_ctx;
119119

120120
struct btrfs_work work;
121-
struct rcu_head rcu;
122121

123122
/* readahead state */
124123
atomic_t reada_in_flight;

0 commit comments

Comments
 (0)