mirror of
git://git.proxmox.com/git/pve-storage.git
synced 2025-01-25 06:03:53 +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";
|
my $mountunitpath = "/etc/systemd/system/$mountunitname";
|
||||||
|
|
||||||
PVE::Diskmanage::locked_disk_action(sub {
|
PVE::Diskmanage::locked_disk_action(sub {
|
||||||
|
PVE::Diskmanage::assert_disk_unused($dev);
|
||||||
|
|
||||||
# create partition
|
# create partition
|
||||||
my $cmd = [$SGDISK, '-n1', '-t1:8300', $dev];
|
my $cmd = [$SGDISK, '-n1', '-t1:8300', $dev];
|
||||||
print "# ", join(' ', @$cmd), "\n";
|
print "# ", join(' ', @$cmd), "\n";
|
||||||
|
@ -154,6 +154,8 @@ __PACKAGE__->register_method ({
|
|||||||
|
|
||||||
my $worker = sub {
|
my $worker = sub {
|
||||||
PVE::Diskmanage::locked_disk_action(sub {
|
PVE::Diskmanage::locked_disk_action(sub {
|
||||||
|
PVE::Diskmanage::assert_disk_unused($dev);
|
||||||
|
|
||||||
PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name);
|
PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name);
|
||||||
|
|
||||||
if ($param->{add_storage}) {
|
if ($param->{add_storage}) {
|
||||||
|
@ -108,6 +108,8 @@ __PACKAGE__->register_method ({
|
|||||||
|
|
||||||
my $worker = sub {
|
my $worker = sub {
|
||||||
PVE::Diskmanage::locked_disk_action(sub {
|
PVE::Diskmanage::locked_disk_action(sub {
|
||||||
|
PVE::Diskmanage::assert_disk_unused($dev);
|
||||||
|
|
||||||
PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name);
|
PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name);
|
||||||
my $pv = PVE::Storage::LVMPlugin::lvm_pv_info($dev);
|
my $pv = PVE::Storage::LVMPlugin::lvm_pv_info($dev);
|
||||||
# keep some free space just in case
|
# keep some free space just in case
|
||||||
|
@ -345,9 +345,6 @@ __PACKAGE__->register_method ({
|
|||||||
foreach my $dev (@$devs) {
|
foreach my $dev (@$devs) {
|
||||||
$dev = PVE::Diskmanage::verify_blockdev_path($dev);
|
$dev = PVE::Diskmanage::verify_blockdev_path($dev);
|
||||||
PVE::Diskmanage::assert_disk_unused($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};
|
PVE::Storage::assert_sid_unused($name) if $param->{add_storage};
|
||||||
@ -374,6 +371,13 @@ __PACKAGE__->register_method ({
|
|||||||
|
|
||||||
my $worker = sub {
|
my $worker = sub {
|
||||||
PVE::Diskmanage::locked_disk_action(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
|
# create zpool with desired raidlevel
|
||||||
|
|
||||||
my $cmd = [$ZPOOL, 'create', '-o', "ashift=$ashift", $name];
|
my $cmd = [$ZPOOL, 'create', '-o', "ashift=$ashift", $name];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user