Commit 401e29c1 authored by Anand Jain's avatar Anand Jain Committed by David Sterba

btrfs: cleanup device states define BTRFS_DEV_STATE_REPLACE_TGT

Currently device state is being managed by each individual int
variable such as struct btrfs_device::is_tgtdev_for_dev_replace.
Instead of that declare btrfs_device::dev_state
BTRFS_DEV_STATE_MISSING and use the bit operations.
Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
[ whitespace adjustments ]
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent e6e674bd
...@@ -172,7 +172,8 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info) ...@@ -172,7 +172,8 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
dev_replace->tgtdev->commit_bytes_used = dev_replace->tgtdev->commit_bytes_used =
dev_replace->srcdev->commit_bytes_used; dev_replace->srcdev->commit_bytes_used;
} }
dev_replace->tgtdev->is_tgtdev_for_dev_replace = 1; set_bit(BTRFS_DEV_STATE_REPLACE_TGT,
&dev_replace->tgtdev->dev_state);
btrfs_init_dev_replace_tgtdev_for_resume(fs_info, btrfs_init_dev_replace_tgtdev_for_resume(fs_info,
dev_replace->tgtdev); dev_replace->tgtdev);
} }
...@@ -566,7 +567,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, ...@@ -566,7 +567,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
btrfs_dev_name(src_device), btrfs_dev_name(src_device),
src_device->devid, src_device->devid,
rcu_str_deref(tgt_device->name)); rcu_str_deref(tgt_device->name));
tgt_device->is_tgtdev_for_dev_replace = 0; clear_bit(BTRFS_DEV_STATE_REPLACE_TGT, &tgt_device->dev_state);
tgt_device->devid = src_device->devid; tgt_device->devid = src_device->devid;
src_device->devid = BTRFS_DEV_REPLACE_DEVID; src_device->devid = BTRFS_DEV_REPLACE_DEVID;
memcpy(uuid_tmp, tgt_device->uuid, sizeof(uuid_tmp)); memcpy(uuid_tmp, tgt_device->uuid, sizeof(uuid_tmp));
......
...@@ -9693,7 +9693,7 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr) ...@@ -9693,7 +9693,7 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr)
* space to fit our block group in. * space to fit our block group in.
*/ */
if (device->total_bytes > device->bytes_used + min_free && if (device->total_bytes > device->bytes_used + min_free &&
!device->is_tgtdev_for_dev_replace) { !test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {
ret = find_free_dev_extent(trans, device, min_free, ret = find_free_dev_extent(trans, device, min_free,
&dev_offset, NULL); &dev_offset, NULL);
if (!ret) if (!ret)
......
...@@ -1528,7 +1528,7 @@ static noinline int btrfs_ioctl_resize(struct file *file, ...@@ -1528,7 +1528,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
} }
} }
if (device->is_tgtdev_for_dev_replace) { if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {
ret = -EPERM; ret = -EPERM;
goto out_free; goto out_free;
} }
......
...@@ -4131,7 +4131,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, ...@@ -4131,7 +4131,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
mutex_lock(&fs_info->scrub_lock); mutex_lock(&fs_info->scrub_lock);
if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) || if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) ||
dev->is_tgtdev_for_dev_replace) { test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &dev->dev_state)) {
mutex_unlock(&fs_info->scrub_lock); mutex_unlock(&fs_info->scrub_lock);
mutex_unlock(&fs_info->fs_devices->device_list_mutex); mutex_unlock(&fs_info->fs_devices->device_list_mutex);
return -EIO; return -EIO;
......
...@@ -1974,7 +1974,8 @@ static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info, ...@@ -1974,7 +1974,8 @@ static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) { list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
&device->dev_state) || &device->dev_state) ||
!device->bdev || device->is_tgtdev_for_dev_replace) !device->bdev ||
test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
continue; continue;
if (i >= nr_devices) if (i >= nr_devices)
......
...@@ -911,7 +911,8 @@ void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step) ...@@ -911,7 +911,8 @@ void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step)
list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) { list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) {
if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
&device->dev_state)) { &device->dev_state)) {
if (!device->is_tgtdev_for_dev_replace && if (!test_bit(BTRFS_DEV_STATE_REPLACE_TGT,
&device->dev_state) &&
(!latest_dev || (!latest_dev ||
device->generation > latest_dev->generation)) { device->generation > latest_dev->generation)) {
latest_dev = device; latest_dev = device;
...@@ -930,7 +931,8 @@ void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step) ...@@ -930,7 +931,8 @@ void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step)
* not, which means whether this device is * not, which means whether this device is
* used or whether it should be removed. * used or whether it should be removed.
*/ */
if (step == 0 || device->is_tgtdev_for_dev_replace) { if (step == 0 || test_bit(BTRFS_DEV_STATE_REPLACE_TGT,
&device->dev_state)) {
continue; continue;
} }
} }
...@@ -942,7 +944,8 @@ void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step) ...@@ -942,7 +944,8 @@ void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step)
if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) { if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {
list_del_init(&device->dev_alloc_list); list_del_init(&device->dev_alloc_list);
clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state); clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
if (!device->is_tgtdev_for_dev_replace) if (!test_bit(BTRFS_DEV_STATE_REPLACE_TGT,
&device->dev_state))
fs_devices->rw_devices--; fs_devices->rw_devices--;
} }
list_del_init(&device->dev_list); list_del_init(&device->dev_list);
...@@ -1250,7 +1253,8 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start, ...@@ -1250,7 +1253,8 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start,
*length = 0; *length = 0;
if (start >= device->total_bytes || device->is_tgtdev_for_dev_replace) if (start >= device->total_bytes ||
test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
return 0; return 0;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
...@@ -1428,7 +1432,8 @@ int find_free_dev_extent_start(struct btrfs_transaction *transaction, ...@@ -1428,7 +1432,8 @@ int find_free_dev_extent_start(struct btrfs_transaction *transaction,
max_hole_size = 0; max_hole_size = 0;
again: again:
if (search_start >= search_end || device->is_tgtdev_for_dev_replace) { if (search_start >= search_end ||
test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {
ret = -ENOSPC; ret = -ENOSPC;
goto out; goto out;
} }
...@@ -1636,7 +1641,7 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, ...@@ -1636,7 +1641,7 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
struct btrfs_key key; struct btrfs_key key;
WARN_ON(!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state)); WARN_ON(!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state));
WARN_ON(device->is_tgtdev_for_dev_replace); WARN_ON(test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state));
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
...@@ -1944,7 +1949,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path, ...@@ -1944,7 +1949,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
if (ret) if (ret)
goto out; goto out;
if (device->is_tgtdev_for_dev_replace) { if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {
ret = BTRFS_ERROR_DEV_TGT_REPLACE; ret = BTRFS_ERROR_DEV_TGT_REPLACE;
goto out; goto out;
} }
...@@ -2451,7 +2456,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path ...@@ -2451,7 +2456,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
device->fs_info = fs_info; device->fs_info = fs_info;
device->bdev = bdev; device->bdev = bdev;
set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
device->is_tgtdev_for_dev_replace = 0; clear_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
device->mode = FMODE_EXCL; device->mode = FMODE_EXCL;
device->dev_stats_valid = 1; device->dev_stats_valid = 1;
set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE); set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE);
...@@ -2660,7 +2665,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, ...@@ -2660,7 +2665,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
device->fs_info = fs_info; device->fs_info = fs_info;
device->bdev = bdev; device->bdev = bdev;
set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
device->is_tgtdev_for_dev_replace = 1; set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
device->mode = FMODE_EXCL; device->mode = FMODE_EXCL;
device->dev_stats_valid = 1; device->dev_stats_valid = 1;
set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE); set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE);
...@@ -2756,7 +2761,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans, ...@@ -2756,7 +2761,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
diff = round_down(new_size - device->total_bytes, fs_info->sectorsize); diff = round_down(new_size - device->total_bytes, fs_info->sectorsize);
if (new_size <= device->total_bytes || if (new_size <= device->total_bytes ||
device->is_tgtdev_for_dev_replace) { test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {
mutex_unlock(&fs_info->chunk_mutex); mutex_unlock(&fs_info->chunk_mutex);
return -EINVAL; return -EINVAL;
} }
...@@ -3569,7 +3574,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) ...@@ -3569,7 +3574,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) || if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) ||
btrfs_device_get_total_bytes(device) - btrfs_device_get_total_bytes(device) -
btrfs_device_get_bytes_used(device) > size_to_free || btrfs_device_get_bytes_used(device) > size_to_free ||
device->is_tgtdev_for_dev_replace) test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
continue; continue;
ret = btrfs_shrink_device(device, old_size - size_to_free); ret = btrfs_shrink_device(device, old_size - size_to_free);
...@@ -4437,7 +4442,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4437,7 +4442,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
new_size = round_down(new_size, fs_info->sectorsize); new_size = round_down(new_size, fs_info->sectorsize);
diff = round_down(old_size - new_size, fs_info->sectorsize); diff = round_down(old_size - new_size, fs_info->sectorsize);
if (device->is_tgtdev_for_dev_replace) if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
return -EINVAL; return -EINVAL;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
...@@ -4742,7 +4747,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ...@@ -4742,7 +4747,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
&device->dev_state) || &device->dev_state) ||
device->is_tgtdev_for_dev_replace) test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
continue; continue;
if (device->total_bytes > device->bytes_used) if (device->total_bytes > device->bytes_used)
...@@ -6566,7 +6571,7 @@ static void fill_device_from_item(struct extent_buffer *leaf, ...@@ -6566,7 +6571,7 @@ static void fill_device_from_item(struct extent_buffer *leaf,
device->io_width = btrfs_device_io_width(leaf, dev_item); device->io_width = btrfs_device_io_width(leaf, dev_item);
device->sector_size = btrfs_device_sector_size(leaf, dev_item); device->sector_size = btrfs_device_sector_size(leaf, dev_item);
WARN_ON(device->devid == BTRFS_DEV_REPLACE_DEVID); WARN_ON(device->devid == BTRFS_DEV_REPLACE_DEVID);
device->is_tgtdev_for_dev_replace = 0; clear_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
ptr = btrfs_device_uuid(dev_item); ptr = btrfs_device_uuid(dev_item);
read_extent_buffer(leaf, device->uuid, ptr, BTRFS_UUID_SIZE); read_extent_buffer(leaf, device->uuid, ptr, BTRFS_UUID_SIZE);
...@@ -6716,7 +6721,7 @@ static int read_one_dev(struct btrfs_fs_info *fs_info, ...@@ -6716,7 +6721,7 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
fill_device_from_item(leaf, dev_item, device); fill_device_from_item(leaf, dev_item, device);
set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) && if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) &&
!device->is_tgtdev_for_dev_replace) { !test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {
device->fs_devices->total_rw_bytes += device->total_bytes; device->fs_devices->total_rw_bytes += device->total_bytes;
atomic64_add(device->total_bytes - device->bytes_used, atomic64_add(device->total_bytes - device->bytes_used,
&fs_info->free_chunk_space); &fs_info->free_chunk_space);
......
...@@ -50,6 +50,7 @@ struct btrfs_pending_bios { ...@@ -50,6 +50,7 @@ struct btrfs_pending_bios {
#define BTRFS_DEV_STATE_WRITEABLE (0) #define BTRFS_DEV_STATE_WRITEABLE (0)
#define BTRFS_DEV_STATE_IN_FS_METADATA (1) #define BTRFS_DEV_STATE_IN_FS_METADATA (1)
#define BTRFS_DEV_STATE_MISSING (2) #define BTRFS_DEV_STATE_MISSING (2)
#define BTRFS_DEV_STATE_REPLACE_TGT (3)
struct btrfs_device { struct btrfs_device {
struct list_head dev_list; struct list_head dev_list;
...@@ -74,7 +75,6 @@ struct btrfs_device { ...@@ -74,7 +75,6 @@ struct btrfs_device {
fmode_t mode; fmode_t mode;
unsigned long dev_state; unsigned long dev_state;
int is_tgtdev_for_dev_replace;
blk_status_t last_flush_error; blk_status_t last_flush_error;
int flush_bio_sent; int flush_bio_sent;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment