Skip to content

Commit 228a73a

Browse files
asjkdave
authored andcommitted
btrfs: introduce new ioctl to unregister a btrfs device
Support for a new command that can be used eg. as a command $ btrfs device scan --forget [dev]' (the final name may change though) to undo the effects of 'btrfs device scan [dev]'. For this purpose this patch proposes to use ioctl raspberrypi#5 as it was empty and is next to the SCAN ioctl. The new ioctl BTRFS_IOC_FORGET_DEV works only on the control device (/dev/btrfs-control) to unregister one or all devices, devices that are not mounted. The argument is struct btrfs_ioctl_vol_args, ::name specifies the device path. To unregister all device, the path is an empty string. Again, the devices are removed only if they aren't part of a mounte filesystem. This new ioctl provides: - release of unwanted btrfs_fs_devices and btrfs_devices structures from memory if the device is not going to be mounted - ability to mount filesystem in degraded mode, when one devices is corrupted like in split brain raid1 - running test cases which would require reloading the kernel module but this is not possible eg. due to mounted filesystem or built-in Signed-off-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: David Sterba <dsterba@suse.com> [ update changelog ] Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 034f784 commit 228a73a

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎fs/btrfs/super.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,9 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
21902190
ret = PTR_ERR_OR_ZERO(device);
21912191
mutex_unlock(&uuid_mutex);
21922192
break;
2193+
case BTRFS_IOC_FORGET_DEV:
2194+
ret = btrfs_forget_devices(vol->name);
2195+
break;
21932196
case BTRFS_IOC_DEVICES_READY:
21942197
mutex_lock(&uuid_mutex);
21952198
device = btrfs_scan_one_device(vol->name, FMODE_READ,

‎fs/btrfs/volumes.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,17 @@ static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr,
14461446
return 0;
14471447
}
14481448

1449+
int btrfs_forget_devices(const char *path)
1450+
{
1451+
int ret;
1452+
1453+
mutex_lock(&uuid_mutex);
1454+
ret = btrfs_free_stale_devices(strlen(path) ? path : NULL, NULL);
1455+
mutex_unlock(&uuid_mutex);
1456+
1457+
return ret;
1458+
}
1459+
14491460
/*
14501461
* Look for a btrfs signature on a device. This may be called out of the mount path
14511462
* and we are not allowed to call set_blocksize during the scan. The superblock

‎fs/btrfs/volumes.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
416416
fmode_t flags, void *holder);
417417
struct btrfs_device *btrfs_scan_one_device(const char *path,
418418
fmode_t flags, void *holder);
419+
int btrfs_forget_devices(const char *path);
419420
int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
420421
void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step);
421422
void btrfs_assign_next_active_device(struct btrfs_device *device,

‎include/uapi/linux/btrfs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,8 @@ enum btrfs_err_code {
837837
struct btrfs_ioctl_vol_args)
838838
#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
839839
struct btrfs_ioctl_vol_args)
840+
#define BTRFS_IOC_FORGET_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \
841+
struct btrfs_ioctl_vol_args)
840842
/* trans start and trans end are dangerous, and only for
841843
* use by applications that know how to avoid the
842844
* resulting deadlocks

0 commit comments

Comments
 (0)