[pve-devel] [PATCH storage 1/2] add generic get_next_vm_diskname sub
Stoiko Ivanov
s.ivanov at proxmox.com
Wed Aug 22 15:41:59 CEST 2018
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
PVE/Storage/Plugin.pm | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 7db3a95..e9fe4ec 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -523,6 +523,37 @@ sub create_base {
return $newvolname;
}
+sub get_next_vm_diskname {
+ my ($disk_list, $storeid, $vmid, $fmt, $scfg, $add_fmt_suffix) = @_;
+
+ my $type = $scfg->{type};
+ my $plugindata = $defaultData->{plugindata}->{$type};
+
+ my $disk_regex = qr/(vm|base)-\Q$vmid\E-disk-(\d+)/;
+ $disk_regex = qr/(vm|base|subvol|basevol)-\Q$vmid\E-disk-(\d+)/
+ if $plugindata->{format}[0]->{subvol};
+
+ my $disk_ids = {};
+ foreach my $disk (@$disk_list) {
+ if ($disk =~ m/$disk_regex/){
+ $disk_ids->{$2} = 1;
+ }
+ }
+
+ $fmt //= '';
+ my $prefix = ($fmt eq 'subvol') ? 'subvol' : 'vm';
+ my $suffix = $add_fmt_suffix ? ".$fmt" : '';
+
+ my $next_disk;
+ for (my $i = 1; $i < 100; $i++) {
+ if (!$disk_ids->{$i}) {
+ return "$prefix-$vmid-disk-$i$suffix";
+ }
+ }
+
+ die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
+};
+
my $find_free_diskname = sub {
my ($imgdir, $vmid, $fmt) = @_;
--
2.11.0
More information about the pve-devel
mailing list