]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/QemuServer.pm
fix #2862: properly backup (all) VM templates
[qemu-server.git] / PVE / QemuServer.pm
index 86e10be87bcbed383984ab0231b71b582c5229e1..a5ee8e2a390e746e53edefb42965222ae1961b43 100644 (file)
@@ -1648,6 +1648,11 @@ sub print_vga_device {
        $memory = ",ram_size=67108864,vram_size=33554432";
     }
 
+    my $edidoff = "";
+    if ($type eq 'VGA' && windows_version($conf->{ostype})) {
+       $edidoff=",edid=off" if (!defined($conf->{bios}) || $conf->{bios} ne 'ovmf');
+    }
+
     my $q35 = PVE::QemuServer::Machine::machine_type_is_q35($conf);
     my $vgaid = "vga" . ($id // '');
     my $pciaddr;
@@ -1659,7 +1664,7 @@ sub print_vga_device {
        $pciaddr = print_pci_addr($vgaid, $bridges, $arch, $machine);
     }
 
-    return "$type,id=${vgaid}${memory}${max_outputs}${pciaddr}";
+    return "$type,id=${vgaid}${memory}${max_outputs}${pciaddr}${edidoff}";
 }
 
 sub parse_number_sets {
@@ -3402,6 +3407,8 @@ sub config_to_command {
         }
 
        my $drive_cmd = print_drive_commandline_full($storecfg, $vmid, $drive);
+       $drive_cmd .= ',readonly' if PVE::QemuConfig->is_template($conf);
+
        push @$devices, '-drive',$drive_cmd;
        push @$devices, '-device', print_drivedevice_full($storecfg, $conf, $vmid, $drive, $bridges, $arch, $machine_type);
     });
@@ -4780,12 +4787,15 @@ sub vm_start {
     return PVE::QemuConfig->lock_config($vmid, sub {
        my $conf = PVE::QemuConfig->load_config($vmid, $migrate_opts->{migratedfrom});
 
-       die "you can't start a vm if it's a template\n" if PVE::QemuConfig->is_template($conf);
+       die "you can't start a vm if it's a template\n"
+           if !$params->{skiptemplate} && PVE::QemuConfig->is_template($conf);
 
-       $params->{resume} = PVE::QemuConfig->has_lock($conf, 'suspended');
+       my $has_suspended_lock = PVE::QemuConfig->has_lock($conf, 'suspended');
 
        PVE::QemuConfig->check_lock($conf)
-           if !($params->{skiplock} || $params->{resume});
+           if !($params->{skiplock} || $has_suspended_lock);
+
+       $params->{resume} = $has_suspended_lock || defined($conf->{vmstate});
 
        die "VM $vmid already running\n" if check_running($vmid, undef, $migrate_opts->{migratedfrom});
 
@@ -4807,6 +4817,7 @@ sub vm_start {
 # params:
 #   statefile => 'tcp', 'unix' for migration or path/volid for RAM state
 #   skiplock => 0/1, skip checking for config lock
+#   skiptemplate => 0/1, skip checking whether VM is template
 #   forcemachine => to force Qemu machine (rollback/migration)
 #   forcecpu => a QEMU '-cpu' argument string to override get_cpu_options
 #   timeout => in seconds
@@ -5935,6 +5946,7 @@ sub restore_proxmox_backup_archive {
     my $datastore = $scfg->{datastore};
     my $username = $scfg->{username} // 'root@pam';
     my $fingerprint = $scfg->{fingerprint};
+    my $keyfile = PVE::Storage::PBSPlugin::pbs_encryption_key_file_name($storecfg, $storeid);
 
     my $repo = "$username\@$server:$datastore";
 
@@ -6019,7 +6031,7 @@ sub restore_proxmox_backup_archive {
        }
 
        my $fh = IO::File->new($cfgfn, "r") ||
-           "unable to read qemu-server.conf - $!\n";
+           die "unable to read qemu-server.conf - $!\n";
 
        my $virtdev_hash = $parse_backup_hints->($rpcenv, $user, $storecfg, $fh, $devinfo, $options);
 
@@ -6052,6 +6064,7 @@ sub restore_proxmox_backup_archive {
                ];
 
            push @$pbs_restore_cmd, '--format', $d->{format} if $d->{format};
+           push @$pbs_restore_cmd, '--keyfile', $keyfile if -e $keyfile;
 
            if (PVE::Storage::volume_has_feature($storecfg, 'sparseinit', $volid)) {
                push @$pbs_restore_cmd, '--skip-zero';
@@ -6179,7 +6192,7 @@ sub restore_vma_archive {
 
        # we can read the config - that is already extracted
        my $fh = IO::File->new($cfgfn, "r") ||
-           "unable to read qemu-server.conf - $!\n";
+           die "unable to read qemu-server.conf - $!\n";
 
        my $fwcfgfn = "$tmpdir/qemu-server.fw";
        if (-f $fwcfgfn) {