]> git.proxmox.com Git - qemu-server.git/commitdiff
fix #2344: ignore cloudinit in replication check
authorMira Limbeck <m.limbeck@proxmox.com>
Fri, 27 Sep 2019 14:22:01 +0000 (16:22 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 19:39:05 +0000 (21:39 +0200)
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 <m.limbeck@proxmox.com>
PVE/API2/Qemu.pm

index bebf07c2089524930fe1bf0ca561f30d524d036a..156ccab792822bf68751cf7b5019c5cd347eb39b 100644 (file)
@@ -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);