Unmap volume before renaming it

PVE storage subsystem does not unmap disk before moving it to another guest.

Also added check to make sure the target volume (if specified) does not exist.
This commit is contained in:
amulet1
2025-01-15 16:37:26 -05:00
parent 829cf63e1f
commit 6474161796
+17 -7
View File
@@ -562,7 +562,7 @@ sub purestorage_resize_volume {
print "Info :: New size detected for volume \"$vgname/$volname\": $new_size bytes.\n";
return $new_size;
}
sleep $interval;
++$iteration;
}
@@ -777,7 +777,7 @@ sub alloc_image {
print "Info :: Size is too small ($size kb), adjusting to 1024 kb\n";
$size = 1024;
}
# Convert size from KB to bytes
my $sizeB = $size * 1024; # KB => B
@@ -822,14 +822,14 @@ sub status {
my $current_time = gettimeofday();
if ( $current_time - $cache->{ last_update } >= 60 ) {
print "Debug :: PVE::Storage::Custom::PureStoragePlugin::sub::status\n" if $DEBUG;
my $response = $class->purestorage_request( $scfg, "arrays/space", "GET" );
# Get storage capacity and used space from the response
$cache->{ total } = $response->{ content }->{ items }->[0]->{ capacity };
$cache->{ used } = $response->{ content }->{ items }->[0]->{ space }->{ total_physical };
# $cache->{ used } = $response->{ content }->{ items }->[0]->{ space }->{ total_used }; # Do not know what is correct
$cache->{ last_update } = $current_time;
} else {
print "Debug :: PVE::Storage::Custom::PureStoragePlugin::sub::status::cached\n" if $DEBUG;
@@ -955,7 +955,7 @@ sub unmap_volume {
print "Info :: Device \"$device_name\" removed from system.\n";
return 1;
}
return 0;
}
@@ -976,7 +976,7 @@ sub deactivate_volume {
my $vgname = $scfg->{ vgname } || die "Error :: Volume group name is not defined.\n";
$class->unmap_volume( $storeid, $scfg, $volname, $snapname );
$class->purestorage_volume_connection( $scfg, $volname, 'DELETE' );
print "Info :: Volume \"$vgname/$volname\" deactivated.\n";
@@ -999,9 +999,19 @@ sub volume_resize {
sub rename_volume {
my ( $class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname ) = @_;
print "Debug :: PVE::Storage::Custom::PureStoragePlugin::sub::rename_volume\n" if $DEBUG;
die "Error :: not implemented in storage plugin \"$class\".\n" if $class->can( 'api' ) && $class->api() < 10;
$target_volname = $class->find_free_diskname( $storeid, $scfg, $target_vmid ) if !$target_volname;
if ( $target_volname ) {
# See RBDPlugin.pm (note, currently PVE does not supply $target_volname parameter)
my $volume = $class->purestorage_get_volume_info( $scfg, $target_volname, $storeid );
die "target volume '$target_volname' already exists\n" if $volume;
} else {
$target_volname = $class->find_free_diskname( $storeid, $scfg, $target_vmid );
}
# we need to unmap source volume (see RBDPlugin.pm)
$class->unmap_volume( $storeid, $scfg, $source_volname );
$class->purestorage_rename_volume( $scfg, $source_volname, $target_volname );