[pve-devel] [PATCH storage 1/3] Lock storage when calling volume_import

Fabian Ebner f.ebner at proxmox.com
Thu Dec 12 11:17:17 CET 2019


to avoid a potential race for two processes trying to allocate the same volume.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

This is conceptually independent from patches 2+3 (but patch 3 modfies the same
hunk as this one).

 PVE/Storage.pm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index bb3b874..ae2ea53 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1402,8 +1402,10 @@ sub volume_import {
     die "cannot import into volume '$volid'\n" if !$storeid;
     my $scfg = storage_config($cfg, $storeid);
     my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-    return $plugin->volume_import($scfg, $storeid, $fh, $volname, $format,
-                                  $base_snapshot, $with_snapshots);
+    return $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
+	return $plugin->volume_import($scfg, $storeid, $fh, $volname, $format,
+				      $base_snapshot, $with_snapshots);
+    });
 }
 
 sub volume_export_formats {
-- 
2.20.1





More information about the pve-devel mailing list