mirror of
git://git.proxmox.com/git/pve-storage.git
synced 2024-12-22 13:34:16 +03:00
api: disks: create: re-check disk after fork/lock
Because then it might not be unused anymore. If there really is a race, this prevents e.g. sgdisk creating a partition on a device already in use by LVM or LVM destroying a partitioned device. For ZFS, also get the latest udev info once inside the worker. Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
parent
dcd8f3a3dd
commit
e99bc248d4
@ -212,6 +212,8 @@ __PACKAGE__->register_method ({
|
||||
my $mountunitpath = "/etc/systemd/system/$mountunitname";
|
||||
|
||||
PVE::Diskmanage::locked_disk_action(sub {
|
||||
PVE::Diskmanage::assert_disk_unused($dev);
|
||||
|
||||
# create partition
|
||||
my $cmd = [$SGDISK, '-n1', '-t1:8300', $dev];
|
||||
print "# ", join(' ', @$cmd), "\n";
|
||||
|
@ -154,6 +154,8 @@ __PACKAGE__->register_method ({
|
||||
|
||||
my $worker = sub {
|
||||
PVE::Diskmanage::locked_disk_action(sub {
|
||||
PVE::Diskmanage::assert_disk_unused($dev);
|
||||
|
||||
PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name);
|
||||
|
||||
if ($param->{add_storage}) {
|
||||
|
@ -108,6 +108,8 @@ __PACKAGE__->register_method ({
|
||||
|
||||
my $worker = sub {
|
||||
PVE::Diskmanage::locked_disk_action(sub {
|
||||
PVE::Diskmanage::assert_disk_unused($dev);
|
||||
|
||||
PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name);
|
||||
my $pv = PVE::Storage::LVMPlugin::lvm_pv_info($dev);
|
||||
# keep some free space just in case
|
||||
|
@ -345,9 +345,6 @@ __PACKAGE__->register_method ({
|
||||
foreach my $dev (@$devs) {
|
||||
$dev = PVE::Diskmanage::verify_blockdev_path($dev);
|
||||
PVE::Diskmanage::assert_disk_unused($dev);
|
||||
my $sysfsdev = $dev =~ s!^/dev/!/sys/block/!r;
|
||||
my $udevinfo = PVE::Diskmanage::get_udev_info($sysfsdev);
|
||||
$dev = $udevinfo->{by_id_link} if defined($udevinfo->{by_id_link});
|
||||
}
|
||||
|
||||
PVE::Storage::assert_sid_unused($name) if $param->{add_storage};
|
||||
@ -374,6 +371,13 @@ __PACKAGE__->register_method ({
|
||||
|
||||
my $worker = sub {
|
||||
PVE::Diskmanage::locked_disk_action(sub {
|
||||
for my $dev (@$devs) {
|
||||
PVE::Diskmanage::assert_disk_unused($dev);
|
||||
my $sysfsdev = $dev =~ s!^/dev/!/sys/block/!r;
|
||||
my $udevinfo = PVE::Diskmanage::get_udev_info($sysfsdev);
|
||||
$dev = $udevinfo->{by_id_link} if defined($udevinfo->{by_id_link});
|
||||
}
|
||||
|
||||
# create zpool with desired raidlevel
|
||||
|
||||
my $cmd = [$ZPOOL, 'create', '-o', "ashift=$ashift", $name];
|
||||
|
Loading…
Reference in New Issue
Block a user