Commit e12c9621 authored by Anand Jain's avatar Anand Jain Committed by David Sterba

btrfs: cleanup device states define BTRFS_DEV_STATE_IN_FS_METADATA

Currently device state is being managed by each individual int
variable such as struct btrfs_device::in_fs_metadata. Instead of
that declare device state BTRFS_DEV_STATE_IN_FS_METADATA and use
the bit operations.
Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
[ whitespace adjustments ]
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent ebbede42
...@@ -3393,7 +3393,7 @@ static int barrier_all_devices(struct btrfs_fs_info *info) ...@@ -3393,7 +3393,7 @@ static int barrier_all_devices(struct btrfs_fs_info *info)
continue; continue;
if (!dev->bdev) if (!dev->bdev)
continue; continue;
if (!dev->in_fs_metadata || if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) ||
!test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) !test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state))
continue; continue;
...@@ -3409,7 +3409,7 @@ static int barrier_all_devices(struct btrfs_fs_info *info) ...@@ -3409,7 +3409,7 @@ static int barrier_all_devices(struct btrfs_fs_info *info)
errors_wait++; errors_wait++;
continue; continue;
} }
if (!dev->in_fs_metadata || if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) ||
!test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) !test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state))
continue; continue;
...@@ -3507,7 +3507,7 @@ int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) ...@@ -3507,7 +3507,7 @@ int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
total_errors++; total_errors++;
continue; continue;
} }
if (!dev->in_fs_metadata || if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) ||
!test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) !test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state))
continue; continue;
...@@ -3547,7 +3547,7 @@ int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) ...@@ -3547,7 +3547,7 @@ int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
list_for_each_entry(dev, head, dev_list) { list_for_each_entry(dev, head, dev_list) {
if (!dev->bdev) if (!dev->bdev)
continue; continue;
if (!dev->in_fs_metadata || if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) ||
!test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) !test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state))
continue; continue;
......
...@@ -4129,7 +4129,8 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, ...@@ -4129,7 +4129,8 @@ 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 (!dev->in_fs_metadata || dev->is_tgtdev_for_dev_replace) { if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) ||
dev->is_tgtdev_for_dev_replace) {
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;
......
...@@ -1972,8 +1972,9 @@ static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info, ...@@ -1972,8 +1972,9 @@ static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) { list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
if (!device->in_fs_metadata || !device->bdev || if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
device->is_tgtdev_for_dev_replace) &device->dev_state) ||
!device->bdev || device->is_tgtdev_for_dev_replace)
continue; continue;
if (i >= nr_devices) if (i >= nr_devices)
......
...@@ -705,7 +705,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, ...@@ -705,7 +705,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
fs_devices->rotating = 1; fs_devices->rotating = 1;
device->bdev = bdev; device->bdev = bdev;
device->in_fs_metadata = 0; clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
device->mode = flags; device->mode = flags;
fs_devices->open_devices++; fs_devices->open_devices++;
...@@ -909,7 +909,8 @@ void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step) ...@@ -909,7 +909,8 @@ void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step)
again: again:
/* This is the initialized path, it is safe to release the devices. */ /* This is the initialized path, it is safe to release the devices. */
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 (device->in_fs_metadata) { if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
&device->dev_state)) {
if (!device->is_tgtdev_for_dev_replace && if (!device->is_tgtdev_for_dev_replace &&
(!latest_dev || (!latest_dev ||
device->generation > latest_dev->generation)) { device->generation > latest_dev->generation)) {
...@@ -1634,7 +1635,7 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, ...@@ -1634,7 +1635,7 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_key key; struct btrfs_key key;
WARN_ON(!device->in_fs_metadata); WARN_ON(!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state));
WARN_ON(device->is_tgtdev_for_dev_replace); WARN_ON(device->is_tgtdev_for_dev_replace);
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
...@@ -1975,7 +1976,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path, ...@@ -1975,7 +1976,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
if (ret) if (ret)
goto error_undo; goto error_undo;
device->in_fs_metadata = 0; clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
btrfs_scrub_cancel_dev(fs_info, device); btrfs_scrub_cancel_dev(fs_info, device);
/* /*
...@@ -2195,7 +2196,8 @@ int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info, ...@@ -2195,7 +2196,8 @@ int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info,
* is held by the caller. * is held by the caller.
*/ */
list_for_each_entry(tmp, devices, dev_list) { list_for_each_entry(tmp, devices, dev_list) {
if (tmp->in_fs_metadata && !tmp->bdev) { if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
&tmp->dev_state) && !tmp->bdev) {
*device = tmp; *device = tmp;
break; break;
} }
...@@ -2447,7 +2449,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path ...@@ -2447,7 +2449,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
device->commit_total_bytes = device->total_bytes; device->commit_total_bytes = device->total_bytes;
device->fs_info = fs_info; device->fs_info = fs_info;
device->bdev = bdev; device->bdev = bdev;
device->in_fs_metadata = 1; set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
device->is_tgtdev_for_dev_replace = 0; device->is_tgtdev_for_dev_replace = 0;
device->mode = FMODE_EXCL; device->mode = FMODE_EXCL;
device->dev_stats_valid = 1; device->dev_stats_valid = 1;
...@@ -2656,7 +2658,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, ...@@ -2656,7 +2658,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
device->commit_bytes_used = device->bytes_used; device->commit_bytes_used = device->bytes_used;
device->fs_info = fs_info; device->fs_info = fs_info;
device->bdev = bdev; device->bdev = bdev;
device->in_fs_metadata = 1; set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
device->is_tgtdev_for_dev_replace = 1; device->is_tgtdev_for_dev_replace = 1;
device->mode = FMODE_EXCL; device->mode = FMODE_EXCL;
device->dev_stats_valid = 1; device->dev_stats_valid = 1;
...@@ -2685,7 +2687,7 @@ void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info, ...@@ -2685,7 +2687,7 @@ void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info,
tgtdev->io_align = sectorsize; tgtdev->io_align = sectorsize;
tgtdev->sector_size = sectorsize; tgtdev->sector_size = sectorsize;
tgtdev->fs_info = fs_info; tgtdev->fs_info = fs_info;
tgtdev->in_fs_metadata = 1; set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &tgtdev->dev_state);
} }
static noinline int btrfs_update_device(struct btrfs_trans_handle *trans, static noinline int btrfs_update_device(struct btrfs_trans_handle *trans,
...@@ -4737,8 +4739,9 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ...@@ -4737,8 +4739,9 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
continue; continue;
} }
if (!device->in_fs_metadata || if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
device->is_tgtdev_for_dev_replace) &device->dev_state) ||
device->is_tgtdev_for_dev_replace)
continue; continue;
if (device->total_bytes > device->bytes_used) if (device->total_bytes > device->bytes_used)
...@@ -6529,7 +6532,9 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key, ...@@ -6529,7 +6532,9 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
} }
btrfs_report_missing_device(fs_info, devid, uuid, false); btrfs_report_missing_device(fs_info, devid, uuid, false);
} }
map->stripes[i].dev->in_fs_metadata = 1; set_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
&(map->stripes[i].dev->dev_state));
} }
write_lock(&map_tree->map_tree.lock); write_lock(&map_tree->map_tree.lock);
...@@ -6704,7 +6709,7 @@ static int read_one_dev(struct btrfs_fs_info *fs_info, ...@@ -6704,7 +6709,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);
device->in_fs_metadata = 1; 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) { !device->is_tgtdev_for_dev_replace) {
device->fs_devices->total_rw_bytes += device->total_bytes; device->fs_devices->total_rw_bytes += device->total_bytes;
......
...@@ -48,6 +48,7 @@ struct btrfs_pending_bios { ...@@ -48,6 +48,7 @@ struct btrfs_pending_bios {
#endif #endif
#define BTRFS_DEV_STATE_WRITEABLE (0) #define BTRFS_DEV_STATE_WRITEABLE (0)
#define BTRFS_DEV_STATE_IN_FS_METADATA (1)
struct btrfs_device { struct btrfs_device {
struct list_head dev_list; struct list_head dev_list;
...@@ -72,7 +73,6 @@ struct btrfs_device { ...@@ -72,7 +73,6 @@ struct btrfs_device {
fmode_t mode; fmode_t mode;
unsigned long dev_state; unsigned long dev_state;
int in_fs_metadata;
int missing; int missing;
int is_tgtdev_for_dev_replace; int is_tgtdev_for_dev_replace;
blk_status_t last_flush_error; blk_status_t last_flush_error;
......
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