Skip to content

Commit 9ae061c

Browse files
committed
btrfs: port device access to file
Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 9f2f767 commit 9ae061c

File tree

4 files changed

+63
-63
lines changed

4 files changed

+63
-63
lines changed

fs/btrfs/dev-replace.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
246246
{
247247
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
248248
struct btrfs_device *device;
249-
struct bdev_handle *bdev_handle;
249+
struct file *bdev_file;
250250
struct block_device *bdev;
251251
u64 devid = BTRFS_DEV_REPLACE_DEVID;
252252
int ret = 0;
@@ -257,13 +257,13 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
257257
return -EINVAL;
258258
}
259259

260-
bdev_handle = bdev_open_by_path(device_path, BLK_OPEN_WRITE,
260+
bdev_file = bdev_file_open_by_path(device_path, BLK_OPEN_WRITE,
261261
fs_info->bdev_holder, NULL);
262-
if (IS_ERR(bdev_handle)) {
262+
if (IS_ERR(bdev_file)) {
263263
btrfs_err(fs_info, "target device %s is invalid!", device_path);
264-
return PTR_ERR(bdev_handle);
264+
return PTR_ERR(bdev_file);
265265
}
266-
bdev = bdev_handle->bdev;
266+
bdev = file_bdev(bdev_file);
267267

268268
if (!btrfs_check_device_zone_type(fs_info, bdev)) {
269269
btrfs_err(fs_info,
@@ -314,7 +314,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
314314
device->commit_bytes_used = device->bytes_used;
315315
device->fs_info = fs_info;
316316
device->bdev = bdev;
317-
device->bdev_handle = bdev_handle;
317+
device->bdev_file = bdev_file;
318318
set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
319319
set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
320320
device->dev_stats_valid = 1;
@@ -335,7 +335,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
335335
return 0;
336336

337337
error:
338-
bdev_release(bdev_handle);
338+
fput(bdev_file);
339339
return ret;
340340
}
341341

fs/btrfs/ioctl.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
26912691
struct inode *inode = file_inode(file);
26922692
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
26932693
struct btrfs_ioctl_vol_args_v2 *vol_args;
2694-
struct bdev_handle *bdev_handle = NULL;
2694+
struct file *bdev_file = NULL;
26952695
int ret;
26962696
bool cancel = false;
26972697

@@ -2728,7 +2728,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
27282728
goto err_drop;
27292729

27302730
/* Exclusive operation is now claimed */
2731-
ret = btrfs_rm_device(fs_info, &args, &bdev_handle);
2731+
ret = btrfs_rm_device(fs_info, &args, &bdev_file);
27322732

27332733
btrfs_exclop_finish(fs_info);
27342734

@@ -2742,8 +2742,8 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
27422742
}
27432743
err_drop:
27442744
mnt_drop_write_file(file);
2745-
if (bdev_handle)
2746-
bdev_release(bdev_handle);
2745+
if (bdev_file)
2746+
fput(bdev_file);
27472747
out:
27482748
btrfs_put_dev_args_from_path(&args);
27492749
kfree(vol_args);
@@ -2756,7 +2756,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
27562756
struct inode *inode = file_inode(file);
27572757
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
27582758
struct btrfs_ioctl_vol_args *vol_args;
2759-
struct bdev_handle *bdev_handle = NULL;
2759+
struct file *bdev_file = NULL;
27602760
int ret;
27612761
bool cancel = false;
27622762

@@ -2783,15 +2783,15 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
27832783
ret = exclop_start_or_cancel_reloc(fs_info, BTRFS_EXCLOP_DEV_REMOVE,
27842784
cancel);
27852785
if (ret == 0) {
2786-
ret = btrfs_rm_device(fs_info, &args, &bdev_handle);
2786+
ret = btrfs_rm_device(fs_info, &args, &bdev_file);
27872787
if (!ret)
27882788
btrfs_info(fs_info, "disk deleted %s", vol_args->name);
27892789
btrfs_exclop_finish(fs_info);
27902790
}
27912791

27922792
mnt_drop_write_file(file);
2793-
if (bdev_handle)
2794-
bdev_release(bdev_handle);
2793+
if (bdev_file)
2794+
fput(bdev_file);
27952795
out:
27962796
btrfs_put_dev_args_from_path(&args);
27972797
kfree(vol_args);

fs/btrfs/volumes.c

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -468,39 +468,39 @@ static noinline struct btrfs_fs_devices *find_fsid(
468468

469469
static int
470470
btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
471-
int flush, struct bdev_handle **bdev_handle,
471+
int flush, struct file **bdev_file,
472472
struct btrfs_super_block **disk_super)
473473
{
474474
struct block_device *bdev;
475475
int ret;
476476

477-
*bdev_handle = bdev_open_by_path(device_path, flags, holder, NULL);
477+
*bdev_file = bdev_file_open_by_path(device_path, flags, holder, NULL);
478478

479-
if (IS_ERR(*bdev_handle)) {
480-
ret = PTR_ERR(*bdev_handle);
479+
if (IS_ERR(*bdev_file)) {
480+
ret = PTR_ERR(*bdev_file);
481481
goto error;
482482
}
483-
bdev = (*bdev_handle)->bdev;
483+
bdev = file_bdev(*bdev_file);
484484

485485
if (flush)
486486
sync_blockdev(bdev);
487487
ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE);
488488
if (ret) {
489-
bdev_release(*bdev_handle);
489+
fput(*bdev_file);
490490
goto error;
491491
}
492492
invalidate_bdev(bdev);
493493
*disk_super = btrfs_read_dev_super(bdev);
494494
if (IS_ERR(*disk_super)) {
495495
ret = PTR_ERR(*disk_super);
496-
bdev_release(*bdev_handle);
496+
fput(*bdev_file);
497497
goto error;
498498
}
499499

500500
return 0;
501501

502502
error:
503-
*bdev_handle = NULL;
503+
*bdev_file = NULL;
504504
return ret;
505505
}
506506

@@ -643,7 +643,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
643643
struct btrfs_device *device, blk_mode_t flags,
644644
void *holder)
645645
{
646-
struct bdev_handle *bdev_handle;
646+
struct file *bdev_file;
647647
struct btrfs_super_block *disk_super;
648648
u64 devid;
649649
int ret;
@@ -654,7 +654,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
654654
return -EINVAL;
655655

656656
ret = btrfs_get_bdev_and_sb(device->name->str, flags, holder, 1,
657-
&bdev_handle, &disk_super);
657+
&bdev_file, &disk_super);
658658
if (ret)
659659
return ret;
660660

@@ -678,20 +678,20 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
678678
clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
679679
fs_devices->seeding = true;
680680
} else {
681-
if (bdev_read_only(bdev_handle->bdev))
681+
if (bdev_read_only(file_bdev(bdev_file)))
682682
clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
683683
else
684684
set_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
685685
}
686686

687-
if (!bdev_nonrot(bdev_handle->bdev))
687+
if (!bdev_nonrot(file_bdev(bdev_file)))
688688
fs_devices->rotating = true;
689689

690-
if (bdev_max_discard_sectors(bdev_handle->bdev))
690+
if (bdev_max_discard_sectors(file_bdev(bdev_file)))
691691
fs_devices->discardable = true;
692692

693-
device->bdev_handle = bdev_handle;
694-
device->bdev = bdev_handle->bdev;
693+
device->bdev_file = bdev_file;
694+
device->bdev = file_bdev(bdev_file);
695695
clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
696696

697697
fs_devices->open_devices++;
@@ -706,7 +706,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
706706

707707
error_free_page:
708708
btrfs_release_disk_super(disk_super);
709-
bdev_release(bdev_handle);
709+
fput(bdev_file);
710710

711711
return -EINVAL;
712712
}
@@ -1015,10 +1015,10 @@ static void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices,
10151015
if (device->devid == BTRFS_DEV_REPLACE_DEVID)
10161016
continue;
10171017

1018-
if (device->bdev_handle) {
1019-
bdev_release(device->bdev_handle);
1018+
if (device->bdev_file) {
1019+
fput(device->bdev_file);
10201020
device->bdev = NULL;
1021-
device->bdev_handle = NULL;
1021+
device->bdev_file = NULL;
10221022
fs_devices->open_devices--;
10231023
}
10241024
if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {
@@ -1063,7 +1063,7 @@ static void btrfs_close_bdev(struct btrfs_device *device)
10631063
invalidate_bdev(device->bdev);
10641064
}
10651065

1066-
bdev_release(device->bdev_handle);
1066+
fput(device->bdev_file);
10671067
}
10681068

10691069
static void btrfs_close_one_device(struct btrfs_device *device)
@@ -1316,7 +1316,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags,
13161316
struct btrfs_super_block *disk_super;
13171317
bool new_device_added = false;
13181318
struct btrfs_device *device = NULL;
1319-
struct bdev_handle *bdev_handle;
1319+
struct file *bdev_file;
13201320
u64 bytenr, bytenr_orig;
13211321
int ret;
13221322

@@ -1339,18 +1339,18 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags,
13391339
* values temporarily, as the device paths of the fsid are the only
13401340
* required information for assembling the volume.
13411341
*/
1342-
bdev_handle = bdev_open_by_path(path, flags, NULL, NULL);
1343-
if (IS_ERR(bdev_handle))
1344-
return ERR_CAST(bdev_handle);
1342+
bdev_file = bdev_file_open_by_path(path, flags, NULL, NULL);
1343+
if (IS_ERR(bdev_file))
1344+
return ERR_CAST(bdev_file);
13451345

13461346
bytenr_orig = btrfs_sb_offset(0);
1347-
ret = btrfs_sb_log_location_bdev(bdev_handle->bdev, 0, READ, &bytenr);
1347+
ret = btrfs_sb_log_location_bdev(file_bdev(bdev_file), 0, READ, &bytenr);
13481348
if (ret) {
13491349
device = ERR_PTR(ret);
13501350
goto error_bdev_put;
13511351
}
13521352

1353-
disk_super = btrfs_read_disk_super(bdev_handle->bdev, bytenr,
1353+
disk_super = btrfs_read_disk_super(file_bdev(bdev_file), bytenr,
13541354
bytenr_orig);
13551355
if (IS_ERR(disk_super)) {
13561356
device = ERR_CAST(disk_super);
@@ -1381,7 +1381,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags,
13811381
btrfs_release_disk_super(disk_super);
13821382

13831383
error_bdev_put:
1384-
bdev_release(bdev_handle);
1384+
fput(bdev_file);
13851385

13861386
return device;
13871387
}
@@ -2057,7 +2057,7 @@ void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
20572057

20582058
int btrfs_rm_device(struct btrfs_fs_info *fs_info,
20592059
struct btrfs_dev_lookup_args *args,
2060-
struct bdev_handle **bdev_handle)
2060+
struct file **bdev_file)
20612061
{
20622062
struct btrfs_trans_handle *trans;
20632063
struct btrfs_device *device;
@@ -2166,7 +2166,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,
21662166

21672167
btrfs_assign_next_active_device(device, NULL);
21682168

2169-
if (device->bdev_handle) {
2169+
if (device->bdev_file) {
21702170
cur_devices->open_devices--;
21712171
/* remove sysfs entry */
21722172
btrfs_sysfs_remove_device(device);
@@ -2182,9 +2182,9 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,
21822182
* free the device.
21832183
*
21842184
* We cannot call btrfs_close_bdev() here because we're holding the sb
2185-
* write lock, and bdev_release() will pull in the ->open_mutex on
2186-
* the block device and it's dependencies. Instead just flush the
2187-
* device and let the caller do the final bdev_release.
2185+
* write lock, and fput() on the block device will pull in the
2186+
* ->open_mutex on the block device and it's dependencies. Instead
2187+
* just flush the device and let the caller do the final bdev_release.
21882188
*/
21892189
if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {
21902190
btrfs_scratch_superblocks(fs_info, device->bdev,
@@ -2195,7 +2195,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,
21952195
}
21962196
}
21972197

2198-
*bdev_handle = device->bdev_handle;
2198+
*bdev_file = device->bdev_file;
21992199
synchronize_rcu();
22002200
btrfs_free_device(device);
22012201

@@ -2332,7 +2332,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info,
23322332
const char *path)
23332333
{
23342334
struct btrfs_super_block *disk_super;
2335-
struct bdev_handle *bdev_handle;
2335+
struct file *bdev_file;
23362336
int ret;
23372337

23382338
if (!path || !path[0])
@@ -2350,7 +2350,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info,
23502350
}
23512351

23522352
ret = btrfs_get_bdev_and_sb(path, BLK_OPEN_READ, NULL, 0,
2353-
&bdev_handle, &disk_super);
2353+
&bdev_file, &disk_super);
23542354
if (ret) {
23552355
btrfs_put_dev_args_from_path(args);
23562356
return ret;
@@ -2363,7 +2363,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info,
23632363
else
23642364
memcpy(args->fsid, disk_super->fsid, BTRFS_FSID_SIZE);
23652365
btrfs_release_disk_super(disk_super);
2366-
bdev_release(bdev_handle);
2366+
fput(bdev_file);
23672367
return 0;
23682368
}
23692369

@@ -2583,7 +2583,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
25832583
struct btrfs_root *root = fs_info->dev_root;
25842584
struct btrfs_trans_handle *trans;
25852585
struct btrfs_device *device;
2586-
struct bdev_handle *bdev_handle;
2586+
struct file *bdev_file;
25872587
struct super_block *sb = fs_info->sb;
25882588
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
25892589
struct btrfs_fs_devices *seed_devices = NULL;
@@ -2596,12 +2596,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
25962596
if (sb_rdonly(sb) && !fs_devices->seeding)
25972597
return -EROFS;
25982598

2599-
bdev_handle = bdev_open_by_path(device_path, BLK_OPEN_WRITE,
2599+
bdev_file = bdev_file_open_by_path(device_path, BLK_OPEN_WRITE,
26002600
fs_info->bdev_holder, NULL);
2601-
if (IS_ERR(bdev_handle))
2602-
return PTR_ERR(bdev_handle);
2601+
if (IS_ERR(bdev_file))
2602+
return PTR_ERR(bdev_file);
26032603

2604-
if (!btrfs_check_device_zone_type(fs_info, bdev_handle->bdev)) {
2604+
if (!btrfs_check_device_zone_type(fs_info, file_bdev(bdev_file))) {
26052605
ret = -EINVAL;
26062606
goto error;
26072607
}
@@ -2613,11 +2613,11 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
26132613
locked = true;
26142614
}
26152615

2616-
sync_blockdev(bdev_handle->bdev);
2616+
sync_blockdev(file_bdev(bdev_file));
26172617

26182618
rcu_read_lock();
26192619
list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
2620-
if (device->bdev == bdev_handle->bdev) {
2620+
if (device->bdev == file_bdev(bdev_file)) {
26212621
ret = -EEXIST;
26222622
rcu_read_unlock();
26232623
goto error;
@@ -2633,8 +2633,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
26332633
}
26342634

26352635
device->fs_info = fs_info;
2636-
device->bdev_handle = bdev_handle;
2637-
device->bdev = bdev_handle->bdev;
2636+
device->bdev_file = bdev_file;
2637+
device->bdev = file_bdev(bdev_file);
26382638
ret = lookup_bdev(device_path, &device->devt);
26392639
if (ret)
26402640
goto error_free_device;
@@ -2817,7 +2817,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
28172817
error_free_device:
28182818
btrfs_free_device(device);
28192819
error:
2820-
bdev_release(bdev_handle);
2820+
fput(bdev_file);
28212821
if (locked) {
28222822
mutex_unlock(&uuid_mutex);
28232823
up_write(&sb->s_umount);

0 commit comments

Comments
 (0)