Signed-off-by: Thomas Lamprecht <t.lampre...@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


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to