mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
Btrfs: rollback btrfs_device fields on umount
It turns out we don't properly rollback in-core btrfs_device state on umount. We zero out ->bdev, ->in_fs_metadata and that's about it. In particular, we don't zero out ->generation, and this can lead to us refusing a mount -- a non-NULL fs_devices->latest_bdev is essential, but btrfs_close_extra_devices will happily assign NULL to ->latest_bdev if the first device on the dev_list happens to be missing and consequently has no bdev attached. This happens because since commit a6b0d5c8 btrfs_close_extra_devices adjusts ->latest_bdev, and in doing that, relies on the ->generation. Fix this, and possibly other problems, by zeroing out everything except for what device_list_add sets, so that a mount right after insmod and 'btrfs dev scan' is no different from any later mount in this respect. Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
parent
2208a378f3
commit
a1e8780a89
@ -674,22 +674,19 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
|
|||||||
if (device->can_discard)
|
if (device->can_discard)
|
||||||
fs_devices->num_can_discard--;
|
fs_devices->num_can_discard--;
|
||||||
|
|
||||||
new_device = kmalloc(sizeof(*new_device), GFP_NOFS);
|
new_device = btrfs_alloc_device(NULL, &device->devid,
|
||||||
BUG_ON(!new_device); /* -ENOMEM */
|
device->uuid);
|
||||||
memcpy(new_device, device, sizeof(*new_device));
|
BUG_ON(IS_ERR(new_device)); /* -ENOMEM */
|
||||||
|
|
||||||
/* Safe because we are under uuid_mutex */
|
/* Safe because we are under uuid_mutex */
|
||||||
if (device->name) {
|
if (device->name) {
|
||||||
name = rcu_string_strdup(device->name->str, GFP_NOFS);
|
name = rcu_string_strdup(device->name->str, GFP_NOFS);
|
||||||
BUG_ON(device->name && !name); /* -ENOMEM */
|
BUG_ON(!name); /* -ENOMEM */
|
||||||
rcu_assign_pointer(new_device->name, name);
|
rcu_assign_pointer(new_device->name, name);
|
||||||
}
|
}
|
||||||
new_device->bdev = NULL;
|
|
||||||
new_device->writeable = 0;
|
|
||||||
new_device->in_fs_metadata = 0;
|
|
||||||
new_device->can_discard = 0;
|
|
||||||
spin_lock_init(&new_device->io_lock);
|
|
||||||
list_replace_rcu(&device->dev_list, &new_device->dev_list);
|
list_replace_rcu(&device->dev_list, &new_device->dev_list);
|
||||||
|
new_device->fs_devices = device->fs_devices;
|
||||||
|
|
||||||
call_rcu(&device->rcu, free_device);
|
call_rcu(&device->rcu, free_device);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user