[pve-devel] [PATCH guest-common] add create_and_lock_config

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Jun 1 16:37:38 CEST 2018


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 PVE/AbstractConfig.pm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/PVE/AbstractConfig.pm b/PVE/AbstractConfig.pm
index 3473988..11180df 100644
--- a/PVE/AbstractConfig.pm
+++ b/PVE/AbstractConfig.pm
@@ -82,6 +82,19 @@ sub lock_config_full {
     return $res;
 }
 
+sub create_and_lock_config {
+    my ($class, $vmid, $allow_existing) = @_;
+
+    $class->lock_config_full($vmid, 5, sub {
+	PVE::Cluster::check_vmid_unused($vmid, $allow_existing);
+
+	my $conf = eval { $class->load_config($vmid) } || {};
+	$class->check_lock($conf);
+	$conf->{lock} = 'create';
+	$class->write_config($vmid, $conf);
+    });
+}
+
 # Lock config file using flock, run $code with @param, unlock config file.
 # $timeout is the maximum time to aquire the flock
 # $shared eq 1 creates a non-exclusive ("read") flock
-- 
2.17.1





More information about the pve-devel mailing list