Use a common interface for find_free_diskname

We can use 'list_images' to get the desired volume IDs in
'find_free_diskname' for most plugins. For the two LVM plugins, 'list_images'
potentially skips untagged volumes, so we keep the custom version. For the
RBD plugin, 'list_images' is much more costly than the custom version, so we
keep the custom version.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fabian Ebner
2019-12-11 10:25:49 +01:00
committed by Thomas Lamprecht
parent a573f66a2e
commit a44c0147bc
7 changed files with 30 additions and 50 deletions

View File

@ -240,7 +240,7 @@ sub alloc_image {
die "illegal name '$volname' - should be 'vm-$vmid-*'\n"
if $volname && $volname !~ m/^vm-$vmid-/;
$volname = $class->zfs_find_free_diskname($storeid, $scfg, $vmid, $fmt)
$volname = $class->find_free_diskname($storeid, $scfg, $vmid, $fmt)
if !$volname;
$class->zfs_create_zvol($scfg, $volname, $size);
@ -250,7 +250,7 @@ sub alloc_image {
die "illegal name '$volname' - should be 'subvol-$vmid-*'\n"
if $volname && $volname !~ m/^subvol-$vmid-/;
$volname = $class->zfs_find_free_diskname($storeid, $scfg, $vmid, $fmt)
$volname = $class->find_free_diskname($storeid, $scfg, $vmid, $fmt)
if !$volname;
die "illegal name '$volname' - should be 'subvol-$vmid-*'\n"
@ -423,16 +423,6 @@ sub zfs_list_zvol {
return $list;
}
sub zfs_find_free_diskname {
my ($class, $storeid, $scfg, $vmid, $format) = @_;
my $volumes = $class->zfs_list_zvol($scfg);
my $dat = $volumes->{$scfg->{pool}};
my $disk_list = [ keys %$dat ];
return PVE::Storage::Plugin::get_next_vm_diskname($disk_list, $storeid, $vmid, $format, $scfg);
}
sub zfs_get_latest_snapshot {
my ($class, $scfg, $volname) = @_;
@ -612,7 +602,7 @@ sub clone_image {
die "clone_image only works on base images\n" if !$isBase;
my $name = $class->zfs_find_free_diskname($storeid, $scfg, $vmid, $format);
my $name = $class->find_free_diskname($storeid, $scfg, $vmid, $format);
if ($format eq 'subvol') {
my $size = $class->zfs_request($scfg, undef, 'list', '-H', '-o', 'refquota', "$scfg->{pool}/$basename");