5
0
mirror of git://git.proxmox.com/git/pve-storage.git synced 2024-12-22 13:34:16 +03:00

fix #4272: btrfs: add rename feature

Adds the ability to change the owner of a guest image.

Btrfs does not need special commands to rename a subvolume and this can
be achieved the same as in Storage/plugin.pm's rename_volume taking
special care of how the directory structure used by Btrfs.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
Tested-By: Aaron Lauterer <a.lauterer@proxmox.com>
Reviewed-By: Aaron Lauterer <a.lauterer@proxmox.com>
This commit is contained in:
Maximiliano Sandoval 2024-07-05 15:10:39 +02:00 committed by Thomas Lamprecht
parent ef9f955e7e
commit fe854c9658

View File

@ -618,6 +618,9 @@ sub volume_has_feature {
base => { qcow2 => 1, raw => 1, vmdk => 1 },
current => { qcow2 => 1, raw => 1, vmdk => 1 },
},
rename => {
current => { qcow2 => 1, raw => 1, vmdk => 1 },
},
};
my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = $class->parse_volname($volname);
@ -930,4 +933,34 @@ sub volume_import {
return "$storeid:$volname";
}
sub rename_volume {
my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname) = @_;
die "no path found\n" if !$scfg->{path};
my $format = ($class->parse_volname($source_volname))[6];
if ($format ne 'raw' && $format ne 'subvol') {
return $class->SUPER::rename_volume($scfg, $storeid, $source_volname, $target_vmid, $target_volname);
}
$target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format, 1)
if !$target_volname;
$target_volname = "$target_vmid/$target_volname";
my $basedir = $class->get_subdir($scfg, 'images');
mkpath "${basedir}/${target_vmid}";
my $source_dir = raw_name_to_dir($source_volname);
my $target_dir = raw_name_to_dir($target_volname);
my $old_path = "${basedir}/${source_dir}";
my $new_path = "${basedir}/${target_dir}";
die "target volume '${target_volname}' already exists\n" if -e $new_path;
rename $old_path, $new_path ||
die "rename '$old_path' to '$new_path' failed - $!\n";
return "${storeid}:$target_volname";
}
1