]> git.proxmox.com Git - pve-storage.git/commitdiff
refactor diskmanagement lock_file calls
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 8 Aug 2018 08:20:08 +0000 (10:20 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 8 Aug 2018 10:01:02 +0000 (12:01 +0200)
so that we only have one place where we reference the lockfile
and the timeout

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Disks/Directory.pm
PVE/API2/Disks/LVM.pm
PVE/API2/Disks/LVMThin.pm
PVE/API2/Disks/ZFS.pm
PVE/Diskmanage.pm

index 3c5ebc5d71e0c9d4dc0aac8fa5b64276bbb78405..8e6118abc091b937cea4d1f60cd0762869107d49 100644 (file)
@@ -214,7 +214,7 @@ __PACKAGE__->register_method ({
            my $mountunitname = "mnt-pve-$name.mount";
            my $mountunitpath = "/etc/systemd/system/$mountunitname";
 
-           lock_file('/run/lock/pve-diskmanage.lck', undef, sub {
+           PVE::Diskmanage::locked_disk_action(sub {
                # create partition
                my $cmd = [$SGDISK, '-n1', '-t1:8300', $dev];
                print "# ", join(' ', @$cmd), "\n";
@@ -279,11 +279,8 @@ __PACKAGE__->register_method ({
                    PVE::API2::Storage::Config->create($storage_params);
                }
            });
-
-           die $@ if $@;
        };
 
-
        return $rpcenv->fork_worker('dircreate', $name, $user, $worker);
     }});
 
index fef5c60b89689ea6d5904c14a8198aa7afa237f4..19fba07bf617bcd96e2d11bed188fd0cc52e3389 100644 (file)
@@ -152,7 +152,7 @@ __PACKAGE__->register_method ({
        die "device $dev is already in use\n" if PVE::Diskmanage::disk_is_used($dev);
 
        my $worker = sub {
-           my $res = lock_file('/run/lock/pve-diskmanage.lck', undef, sub {
+           PVE::Diskmanage::locked_disk_action(sub {
                PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name);
 
                if ($param->{add_storage}) {
@@ -168,8 +168,6 @@ __PACKAGE__->register_method ({
                    PVE::API2::Storage::Config->create($storage_params);
                }
            });
-
-           die $@ if $@;
        };
 
        return $rpcenv->fork_worker('lvmcreate', $name, $user, $worker);
index f776c3cf6d59f114433245dd73836f83d9a13587..5b72c8c478d233fb73a4478a0b526853a99a782c 100644 (file)
@@ -112,7 +112,7 @@ __PACKAGE__->register_method ({
        }
 
        my $worker = sub {
-           lock_file('/run/lock/pve-diskmanage.lck', undef, sub {
+           PVE::Diskmanage::locked_disk_action(sub {
                PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name);
 
                # create thinpool with size 100%, let lvm handle the metadata size
@@ -131,8 +131,6 @@ __PACKAGE__->register_method ({
                    PVE::API2::Storage::Config->create($storage_params);
                }
            });
-
-           die $@ if $@;
        };
 
        return $rpcenv->fork_worker('lvmthincreate', $name, $user, $worker);
index ad6da236c089984b62edcdc65e7f4f846f7c8b55..1690768168684eb74df572411f9ae2f4466ab857 100644 (file)
@@ -313,7 +313,7 @@ __PACKAGE__->register_method ({
            if $numdisks < $mindisks->{$raidlevel};
 
        my $worker = sub {
-           lock_file('/run/lock/pve-diskmanage.lck', 10, sub {
+           PVE::Diskmanage::locked_disk_action(sub {
                # create zpool with desired raidlevel
 
                my $cmd = [$ZPOOL, 'create', '-o', "ashift=$ashift", $name];
@@ -347,10 +347,8 @@ __PACKAGE__->register_method ({
                    PVE::API2::Storage::Config->create($storage_params);
                }
            });
-           die $@ if $@;
        };
 
-
        return $rpcenv->fork_worker('zfscreate', $name, $user, $worker);
     }});
 
index 23e5b13ecce0a1d1bd2104ebf26973f0f9822288..1938fa8ff52516f442e8a68c4cb5f73771d1270a 100644 (file)
@@ -595,4 +595,11 @@ sub get_blockdev {
     return $block_dev;
 }
 
+sub locked_disk_action {
+    my ($sub) = @_;
+    my $res = PVE::Tools::lock_file('/run/lock/pve-diskmanage.lck', undef, $sub);
+    die $@ if $@;
+    return $res;
+}
+
 1;