From 21e1ee7b324554354f5a6623ad51858bb08e94ad Mon Sep 17 00:00:00 2001 From: Mira Limbeck Date: Fri, 27 Sep 2019 16:22:01 +0200 Subject: [PATCH] fix #2344: ignore cloudinit in replication check When adding a cloudinit disk it does not contain media=cdrom until it is actually created. This means the check in check_replication fails to detect cloudinit and it is recognized as normal disk. Then parse_volname fails because it does not match the vm-$vmid-XYZ format. To fix this we now check explicitly if the volname matches cloudinit and if so, return early. Additionally 2 small cleanups replacing cloudinit regexes with the same check for volname matches cloudinit. Signed-off-by: Mira Limbeck --- PVE/API2/Qemu.pm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index bebf07c2..156ccab7 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -65,10 +65,9 @@ my $check_storage_access = sub { my $isCDROM = PVE::QemuServer::drive_is_cdrom($drive); my $volid = $drive->{file}; + my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1); - if (!$volid || ($volid eq 'none' || $volid eq 'cloudinit')) { - # nothing to check - } elsif ($volid =~ m/^(([^:\s]+):)?(cloudinit)$/) { + if (!$volid || ($volid eq 'none' || $volid eq 'cloudinit' || $volname eq 'cloudinit')) { # nothing to check } elsif ($isCDROM && ($volid eq 'cdrom')) { $rpcenv->check($authuser, "/", ['Sys.Console']); @@ -141,12 +140,13 @@ my $create_disks = sub { my ($ds, $disk) = @_; my $volid = $disk->{file}; + my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1); if (!$volid || $volid eq 'none' || $volid eq 'cdrom') { delete $disk->{size}; $res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk); - } elsif ($volid =~ m!^(?:([^/:\s]+):)?cloudinit$!) { - my $storeid = $1 || $default_storage; + } elsif ($volname eq 'cloudinit') { + $storeid = $storeid // $default_storage; die "no storage ID specified (and no default storage)\n" if !$storeid; my $scfg = PVE::Storage::storage_config($storecfg, $storeid); my $name = "vm-$vmid-cloudinit"; @@ -199,8 +199,6 @@ my $create_disks = sub { if ($volid_is_new) { - my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1); - PVE::Storage::activate_volumes($storecfg, [ $volid ]) if $storeid; my $size = PVE::Storage::volume_size_info($storecfg, $volid); @@ -1044,12 +1042,15 @@ my $update_vm_api = sub { my $volid = $drive->{file}; return if !$volid || !($drive->{replicate}//1); return if PVE::QemuServer::drive_is_cdrom($drive); - my ($storeid, $format); + + my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1); + return if $volname eq 'cloudinit'; + + my $format; if ($volid =~ $NEW_DISK_RE) { $storeid = $2; $format = $drive->{format} || PVE::Storage::storage_default_format($storecfg, $storeid); } else { - ($storeid, undef) = PVE::Storage::parse_volume_id($volid, 1); $format = (PVE::Storage::parse_volname($storecfg, $volid))[6]; } return if PVE::Storage::storage_can_replicate($storecfg, $storeid, $format); -- 2.39.5