struct btrfs_device *tgtdev;
struct mutex lock_finishing_cancel_unmount;
- rwlock_t lock;
+ struct rw_semaphore rwsem;
atomic_t blocking_readers;
wait_queue_head_t read_lock_wq;
void btrfs_dev_replace_read_lock(struct btrfs_dev_replace *dev_replace)
{
- read_lock(&dev_replace->lock);
+ down_read(&dev_replace->rwsem);
}
void btrfs_dev_replace_read_unlock(struct btrfs_dev_replace *dev_replace)
{
- read_unlock(&dev_replace->lock);
+ up_read(&dev_replace->rwsem);
}
void btrfs_dev_replace_write_lock(struct btrfs_dev_replace *dev_replace)
again:
wait_event(dev_replace->read_lock_wq,
atomic_read(&dev_replace->blocking_readers) == 0);
- write_lock(&dev_replace->lock);
+ down_write(&dev_replace->rwsem);
if (atomic_read(&dev_replace->blocking_readers)) {
- write_unlock(&dev_replace->lock);
+ up_write(&dev_replace->rwsem);
goto again;
}
}
void btrfs_dev_replace_write_unlock(struct btrfs_dev_replace *dev_replace)
{
- write_unlock(&dev_replace->lock);
+ up_write(&dev_replace->rwsem);
}
/* inc blocking cnt and release read lock */
{
/* only set blocking for read lock */
atomic_inc(&dev_replace->blocking_readers);
- read_unlock(&dev_replace->lock);
+ up_read(&dev_replace->rwsem);
}
void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info)
static void btrfs_init_dev_replace_locks(struct btrfs_fs_info *fs_info)
{
mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount);
- rwlock_init(&fs_info->dev_replace.lock);
+ init_rwsem(&fs_info->dev_replace.rwsem);
atomic_set(&fs_info->dev_replace.blocking_readers, 0);
init_waitqueue_head(&fs_info->dev_replace.replace_wait);
init_waitqueue_head(&fs_info->dev_replace.read_lock_wq);