]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/QemuServer.pm
replace remaining vm_destroy call-sites with destroy_vm
[qemu-server.git] / PVE / QemuServer.pm
index 169f920e31a3d1d9addee0f5488ec3ff1e95e228..bfe6662dd18d57cdcc70486ebc59acfc89575f93 100644 (file)
@@ -36,7 +36,7 @@ use PVE::SafeSyslog;
 use PVE::Storage;
 use PVE::SysFSTools;
 use PVE::Systemd;
-use PVE::Tools qw(run_command lock_file lock_file_full file_read_firstline dir_glob_foreach $IPV6RE);
+use PVE::Tools qw(run_command lock_file lock_file_full file_read_firstline dir_glob_foreach get_host_arch $IPV6RE);
 
 use PVE::QMPClient;
 use PVE::QemuConfig;
@@ -91,7 +91,7 @@ PVE::JSONSchema::register_standard_option('pve-qm-image-format', {
 PVE::JSONSchema::register_standard_option('pve-qemu-machine', {
        description => "Specifies the Qemu machine type.",
        type => 'string',
-       pattern => '(pc|pc(-i440fx)?-\d+\.\d+(\.pxe)?|q35|pc-q35-\d+\.\d+(\.pxe)?|virt(?:-\d+\.\d+)?)',
+       pattern => '(pc|pc(-i440fx)?-\d+(\.\d+)+(\.pxe)?|q35|pc-q35-\d+(\.\d+)+(\.pxe)?|virt(?:-\d+(\.\d+)+)?)',
        maxLength => 40,
        optional => 1,
 });
@@ -2548,13 +2548,6 @@ sub check_type {
     }
 }
 
-sub touch_config {
-    my ($vmid) = @_;
-
-    my $conf = PVE::QemuConfig->config_file($vmid);
-    utime undef, undef, $conf;
-}
-
 sub destroy_vm {
     my ($storecfg, $vmid, $keep_empty_config, $skiplock) = @_;
 
@@ -2599,12 +2592,6 @@ sub destroy_vm {
 
     });
 
-    if ($keep_empty_config) {
-       PVE::QemuConfig->write_config($vmid, { memory => 128 });
-    } else {
-       PVE::QemuConfig->destroy_config($vmid);
-    }
-
     # also remove unused disk
     eval {
        my $dl = PVE::Storage::vdisk_list($storecfg, undef, $vmid);
@@ -2619,6 +2606,12 @@ sub destroy_vm {
 
     };
     warn $@ if $@;
+
+    if ($keep_empty_config) {
+       PVE::QemuConfig->write_config($vmid, { memory => 128 });
+    } else {
+       PVE::QemuConfig->destroy_config($vmid);
+    }
 }
 
 sub parse_vm_config {
@@ -3139,8 +3132,7 @@ sub vmstatus {
     foreach my $vmid (keys %$list) {
        next if $opt_vmid && ($vmid ne $opt_vmid);
 
-       my $cfspath = PVE::QemuConfig->cfs_config_path($vmid);
-       my $conf = PVE::Cluster::cfs_read_file($cfspath) || {};
+       my $conf = PVE::QemuConfig->load_config($vmid);
 
        my $d = { vmid => $vmid };
        $d->{pid} = $list->{$vmid}->{pid};
@@ -3425,12 +3417,6 @@ sub vga_conf_has_spice {
     return $1 || 1;
 }
 
-my $host_arch; # FIXME: fix PVE::Tools::get_host_arch
-sub get_host_arch() {
-    $host_arch = (POSIX::uname())[4] if !$host_arch;
-    return $host_arch;
-}
-
 sub is_native($) {
     my ($arch) = @_;
     return get_host_arch() eq $arch;
@@ -4147,10 +4133,9 @@ sub spice_port {
 }
 
 sub qmp_socket {
-    my ($vmid, $qga, $name) = @_;
+    my ($vmid, $qga) = @_;
     my $sockettype = $qga ? 'qga' : 'qmp';
-    my $ext = $name ? '-'.$name : '';
-    return "${var_run_tmpdir}/$vmid$ext.$sockettype";
+    return "${var_run_tmpdir}/$vmid.$sockettype";
 }
 
 sub pidfile_name {
@@ -5952,21 +5937,6 @@ sub vm_sendkey {
     });
 }
 
-sub vm_destroy {
-    my ($storecfg, $vmid, $skiplock) = @_;
-
-    PVE::QemuConfig->lock_config($vmid, sub {
-
-       my $conf = PVE::QemuConfig->load_config($vmid);
-
-       if (!check_running($vmid)) {
-           destroy_vm($storecfg, $vmid, undef, $skiplock);
-       } else {
-           die "VM $vmid is running - destroy failed\n";
-       }
-    });
-}
-
 # vzdump restore implementaion
 
 sub tar_archive_read_firstfile {
@@ -7205,10 +7175,13 @@ sub version_cmp {
     return 0;
 }
 
+# dies if a) VM not running or not exisiting b) Version query failed
+# So, any defined return value is valid, any invalid state can be caught by eval
 sub runs_at_least_qemu_version {
     my ($vmid, $major, $minor, $extra) = @_;
 
-    my $v = eval { PVE::QemuServer::vm_qmp_command($vmid, { execute => 'query-version' }) } // {};
+    my $v = vm_qmp_command($vmid, { execute => 'query-version' });
+    die "could not query currently running version for VM $vmid\n" if !defined($v);
     $v = $v->{qemu};
 
     return version_cmp($v->{major}, $major, $v->{minor}, $minor, $v->{micro}, $extra) >= 0;